diff --git a/.babelrc b/.babelrc deleted file mode 100644 index d49848aa62..0000000000 --- a/.babelrc +++ /dev/null @@ -1,28 +0,0 @@ -{ - "presets": [ - [ - "@babel/env", - { - "targets": { - "node": "current" - } - } - ] - ], - "plugins": [ - "@babel/plugin-proposal-class-properties", - "@babel/plugin-proposal-object-rest-spread", - "transform-es2015-modules-commonjs", - "babel-plugin-dynamic-import-node" - ], - "sourceMaps": "inline", - "retainLines": true, - "env": { - "development": { - "plugins": ["transform-es2015-modules-commonjs"] - }, - "test": { - "plugins": ["transform-es2015-modules-commonjs"] - } - } -} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 693606c3dd..1860aa5953 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -10,13 +10,13 @@ on: default: 'master' permissions: - id-token: write # Required for OIDC contents: read - + jobs: release: permissions: - contents: write + contents: write # Required to push dist files and create the GitHub release + id-token: write # Required for npm trusted publishing (OIDC) runs-on: ubuntu-latest steps: - name: Checkout branch @@ -28,9 +28,8 @@ jobs: - name: Setup Node uses: actions/setup-node@v4 with: - node-version: '22.x' + node-version: '24.x' registry-url: 'https://registry.npmjs.org' - always-auth: true - name: Install dependencies run: npm ci diff --git a/.github/workflows/visual-tests.yaml b/.github/workflows/visual-tests.yaml index 37718dae45..09728a8200 100644 --- a/.github/workflows/visual-tests.yaml +++ b/.github/workflows/visual-tests.yaml @@ -21,7 +21,7 @@ jobs: - name: Setup Node uses: actions/setup-node@v4 with: - node-version: '20' + node-version: '24.x' - name: Install dependencies run: npm ci diff --git a/README.md b/README.md index 68db0be83c..4d2d0298e6 100644 --- a/README.md +++ b/README.md @@ -106,9 +106,11 @@ and [OBJ](https://xeokit.github.io/xeokit-sdk/docs/class/src/plugins/OBJLoaderPl ```` --- -## Deprecation Notice: ES5 and CJS Builds +## ES5 and CJS Builds Removed -Starting from **September 2026**, the ES5/UMD and CommonJS builds will no longer be included in the npm package. Maintaining ES5 compatibility requires extensive transpilation and polyfilling that is increasingly difficult to sustain as the codebase evolves. Going forward, only the ES module builds (`xeokit-sdk.es.js` and `xeokit-sdk.min.es.js`) will be provided, which are compatible with all modern browsers and bundlers. +The npm package no longer includes the ES5/UMD and CommonJS builds (`xeokit-sdk.es5.js`, `xeokit-sdk.min.es5.js`, `xeokit-sdk.cjs.js` and `xeokit-sdk.min.cjs.js`). ES5 compatibility needs a large amount of transpilation and polyfills, and this work became too difficult to maintain as the codebase changes. The package contains only the ES module builds, `xeokit-sdk.es.js` and `xeokit-sdk.min.es.js`. These builds work in all modern browsers and bundlers. + +If your project loads xeokit SDK with `require()`, change it to an `import` statement. --- ## 📜 Licensing & Commercial Use diff --git a/dist/xeokit-sdk.cjs.js b/dist/xeokit-sdk.cjs.js deleted file mode 100644 index 1d02ddf1bc..0000000000 --- a/dist/xeokit-sdk.cjs.js +++ /dev/null @@ -1,136675 +0,0 @@ -/** - * xeokit-sdk v2.6.114 - * Commit: d4f9ada4083667c96090c473a6a48c704eb1971f - * Built: 2026-09-02T16:07:07.747Z - */ - -if (typeof window !== 'undefined') { - window.__XEOKIT__ = { version: '2.6.114', commit: 'd4f9ada4083667c96090c473a6a48c704eb1971f', built: '2026-09-02T16:07:07.747Z' }; -} - -'use strict'; - -Object.defineProperty(exports, '__esModule', { value: true }); - -/** @private */ -class Map$1 { - - constructor(items, baseId) { - this.items = items || []; - this._lastUniqueId = (baseId || 0) + 1; - } - - /** - * Usage: - * - * id = myMap.addItem("foo") // ID internally generated - * id = myMap.addItem("foo", "bar") // ID is "foo" - */ - addItem() { - let item; - if (arguments.length === 2) { - const id = arguments[0]; - item = arguments[1]; - if (this.items[id]) { // Won't happen if given ID is string - throw "ID clash: '" + id + "'"; - } - this.items[id] = item; - return id; - - } else { - item = arguments[0] || {}; - while (true) { - const findId = this._lastUniqueId++; - if (!this.items[findId]) { - this.items[findId] = item; - return findId; - } - } - } - } - - removeItem(id) { - const item = this.items[id]; - delete this.items[id]; - return item; - } -} - -const idMap = new Map$1(); - -/** - * Internal data class that represents the state of a menu or a submenu. - * @private - */ -class Menu { - constructor(id) { - this.id = id; - this.parentItem = null; // Set to an Item when this Menu is a submenu - this.groups = []; - this.menuElement = null; - this.shown = false; - this.mouseOver = 0; - } -} - -/** - * Internal data class that represents a group of Items in a Menu. - * @private - */ -class Group { - constructor() { - this.items = []; - } -} - -/** - * Internal data class that represents the state of a menu item. - * @private - */ -class Item { - constructor(id, getTitle, doAction, getEnabled, getShown) { - this.id = id; - this.getTitle = getTitle; - this.doAction = doAction; - this.getEnabled = getEnabled; - this.getShown = getShown; - this.itemElement = null; - this.subMenu = null; - this.enabled = true; - } -} - -/** - * @desc A customizable HTML context menu. - * - * [](https://xeokit.github.io/xeokit-sdk/examples/index.html#ContextMenu_Canvas_TreeViewPlugin_Custom) - * - * * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/index.html#ContextMenu_Canvas_TreeViewPlugin_Custom)] - * - * ## Overview - * - * * A pure JavaScript, lightweight context menu - * * Dynamically configure menu items - * * Dynamically enable or disable items - * * Dynamically show or hide items - * * Supports cascading sub-menus - * * Configure custom style with CSS (see examples above) - * - * ## Usage - * - * In the example below we'll create a ````ContextMenu```` that pops up whenever we right-click on an {@link Entity} within - * our {@link Scene}. - * - * First, we'll create the ````ContextMenu````, configuring it with a list of menu items. - * - * Each item has: - * - * * a ````title```` for the item, - * * a ````doAction()```` callback to fire when the item's title is clicked, - * * an optional ````getShown()```` callback that indicates if the item should shown in the menu or not, and - * * an optional ````getEnabled()```` callback that indicates if the item should be shown enabled in the menu or not. - * - *
- * - * The ````getShown()```` and ````getEnabled()```` callbacks are invoked whenever the menu is shown. - * - * When an item's ````getShown()```` callback - * returns ````true````, then the item is shown. When it returns ````false````, then the item is hidden. An item without - * a ````getShown()```` callback is always shown. - * - * When an item's ````getEnabled()```` callback returns ````true````, then the item is enabled and clickable (as long as it's also shown). When it - * returns ````false````, then the item is disabled and cannot be clicked. An item without a ````getEnabled()```` - * callback is always enabled and clickable. - * - * Note how the ````doAction()````, ````getShown()```` and ````getEnabled()```` callbacks accept a ````context```` - * object. That must be set on the ````ContextMenu```` before we're able to we show it. The context object can be anything. In this example, - * we'll use the context object to provide the callbacks with the Entity that we right-clicked. - * - * We'll also initially enable the ````ContextMenu````. - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/index.html#ContextMenu_Canvas_Custom)] - * - * ````javascript - * const canvasContextMenu = new ContextMenu({ - * - * enabled: true, - * - * items: [ - * [ - * { - * title: "Hide Object", - * getEnabled: (context) => { - * return context.entity.visible; // Can't hide entity if already hidden - * }, - * doAction: function (context) { - * context.entity.visible = false; - * } - * } - * ], - * [ - * { - * title: "Select Object", - * getEnabled: (context) => { - * return (!context.entity.selected); // Can't select an entity that's already selected - * }, - * doAction: function (context) { - * context.entity.selected = true; - * } - * } - * ], - * [ - * { - * title: "X-Ray Object", - * getEnabled: (context) => { - * return (!context.entity.xrayed); // Can't X-ray an entity that's already X-rayed - * }, - * doAction: (context) => { - * context.entity.xrayed = true; - * } - * } - * ] - * ] - * }); - * ```` - * - * Next, we'll make the ````ContextMenu```` appear whenever we right-click on an Entity. Whenever we right-click - * on the canvas, we'll attempt to pick the Entity at those mouse coordinates. If we succeed, we'll feed the - * Entity into ````ContextMenu```` via the context object, then show the ````ContextMenu````. - * - * From there, each ````ContextMenu```` item's ````getEnabled()```` callback will be invoked (if provided), to determine if the item should - * be enabled. If we click an item, its ````doAction()```` callback will be invoked with our context object. - * - * Remember that we must set the context on our ````ContextMenu```` before we show it, otherwise it will log an error to the console, - * and ignore our attempt to show it. - * - * ````javascript* - * viewer.scene.canvas.canvas.oncontextmenu = (e) => { // Right-clicked on the canvas - * - * if (!objectContextMenu.enabled) { - * return; - * } - * - * var hit = viewer.scene.pick({ // Try to pick an Entity at the coordinates - * canvasPos: [e.pageX, e.pageY] - * }); - * - * if (hit) { // Picked an Entity - * - * objectContextMenu.context = { // Feed entity to ContextMenu - * entity: hit.entity - * }; - * - * objectContextMenu.show(e.pageX, e.pageY); // Show the ContextMenu - * } - * - * e.preventDefault(); - * }); - * ```` - * - * Note how we only show the ````ContextMenu```` if it's enabled. We can use that mechanism to switch between multiple - * ````ContextMenu```` instances depending on what we clicked. - * - * ## Dynamic Item Titles - * - * To make an item dynamically regenerate its title text whenever we show the ````ContextMenu````, provide its title with a - * ````getTitle()```` callback. The callback will fire each time you show ````ContextMenu````, which will dynamically - * set the item title text. - * - * In the example below, we'll create a simple ````ContextMenu```` that allows us to toggle the selection of an object - * via its first item, which changes text depending on whether we are selecting or deselecting the object. - * - * [[Run an example](https://xeokit.github.io/xeokit-sdk/examples/index.html#ContextMenu_dynamicItemTitles)] - * - * ````javascript - * const canvasContextMenu = new ContextMenu({ - * - * enabled: true, - * - * items: [ - * [ - * { - * getTitle: (context) => { - * return (!context.entity.selected) ? "Select" : "Undo Select"; - * }, - * doAction: function (context) { - * context.entity.selected = !context.entity.selected; - * } - * }, - * { - * title: "Clear Selection", - * getEnabled: function (context) { - * return (context.viewer.scene.numSelectedObjects > 0); - * }, - * doAction: function (context) { - * context.viewer.scene.setObjectsSelected(context.viewer.scene.selectedObjectIds, false); - * } - * } - * ] - * ] - * }); - * ```` - * - * ## Sub-menus - * - * Each menu item can optionally have a sub-menu, which will appear when we hover over the item. - * - * In the example below, we'll create a much simpler ````ContextMenu```` that has only one item, called "Effects", which - * will open a cascading sub-menu whenever we hover over that item. - * - * Note that our "Effects" item has no ````doAction```` callback, because an item with a sub-menu performs no - * action of its own. - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/index.html#ContextMenu_subMenus)] - * - * ````javascript - * const canvasContextMenu = new ContextMenu({ - * items: [ // Top level items - * [ - * { - * getTitle: (context) => { - * return "Effects"; - * }, - * - * items: [ // Sub-menu - * [ - * { - * getTitle: (context) => { - * return (!context.entity.visible) ? "Show" : "Hide"; - * }, - * doAction: function (context) { - * context.entity.visible = !context.entity.visible; - * } - * }, - * { - * getTitle: (context) => { - * return (!context.entity.selected) ? "Select" : "Undo Select"; - * }, - * doAction: function (context) { - * context.entity.selected = !context.entity.selected; - * } - * }, - * { - * getTitle: (context) => { - * return (!context.entity.highlighted) ? "Highlight" : "Undo Highlight"; - * }, - * doAction: function (context) { - * context.entity.highlighted = !context.entity.highlighted; - * } - * } - * ] - * ] - * } - * ] - * ] - * }); - * ```` - */ -class ContextMenu { - - /** - * Creates a ````ContextMenu````. - * - * The ````ContextMenu```` will be initially hidden. - * - * @param {Object} [cfg] ````ContextMenu```` configuration. - * @param {Object} [cfg.items] The context menu items. These can also be dynamically set on {@link ContextMenu#items}. See the class documentation for an example. - * @param {Object} [cfg.context] The context, which is passed into the item callbacks. This can also be dynamically set on {@link ContextMenu#context}. This must be set before calling {@link ContextMenu#show}. - * @param {Boolean} [cfg.enabled=true] Whether this ````ContextMenu```` is initially enabled. {@link ContextMenu#show} does nothing while this is ````false````. - * @param {Boolean} [cfg.hideOnMouseDown=true] Whether this ````ContextMenu```` automatically hides whenever we mouse-down or tap anywhere in the page. - * @param {Boolean} [cfg.hideOnAction=true] Whether this ````ContextMenu```` automatically hides after we select a menu item. Se false if we want the menu to remain shown and show any updates to its item titles, after we've selected an item. - * @param {Node | undefined} [cfg.parentNode] Optional reference to an existing DOM Node (e.g. ShadowRoot), to which the menu's HTML element will be appended, defaults to ````document.body````. - */ - constructor(cfg = {}) { - - this._id = idMap.addItem(); - this._context = null; - this._enabled = false; // True when the ContextMenu is enabled - this._itemsCfg = []; // Items as given as configs - this._rootMenu = null; // The root Menu in the tree - this._menuList = []; // List of Menus - this._menuMap = {}; // Menus mapped to their IDs - this._itemList = []; // List of Items - this._itemMap = {}; // Items mapped to their IDs - this._shown = false; // True when the ContextMenu is visible - this._nextId = 0; - this._parentNode = cfg.parentNode || document.body; - this._offsetParent = (this._parentNode instanceof ShadowRoot) ? this._parentNode.host : this._parentNode; - - /** - * Subscriptions to events fired at this ContextMenu. - * @private - */ - this._eventSubs = {}; - - if (cfg.hideOnMouseDown !== false) { - this._parentNode.addEventListener("mousedown", (event) => { - if (!event.target.classList.contains("xeokit-context-menu-item")) { - this.hide(); - } - }); - this._parentNode.addEventListener("touchstart", this._canvasTouchStartHandler = (event) => { - if (!event.target.classList.contains("xeokit-context-menu-item")) { - this.hide(); - } - }); - } - - if (cfg.items) { - this.items = cfg.items; - } - - this._hideOnAction = (cfg.hideOnAction !== false); - - this.context = cfg.context; - this.enabled = cfg.enabled !== false; - this.hide(); - } - - - /** - Subscribes to an event fired at this ````ContextMenu````. - - @param {String} event The event - @param {Function} callback Callback fired on the event - */ - on(event, callback) { - let subs = this._eventSubs[event]; - if (!subs) { - subs = []; - this._eventSubs[event] = subs; - } - subs.push(callback); - } - - /** - Fires an event at this ````ContextMenu````. - - @param {String} event The event type name - @param {Object} value The event parameters - */ - fire(event, value) { - const subs = this._eventSubs[event]; - if (subs) { - for (let i = 0, len = subs.length; i < len; i++) { - subs[i](value); - } - } - } - - /** - * Sets the ````ContextMenu```` items. - * - * These can be updated dynamically at any time. - * - * See class documentation for an example. - * - * @type {Object[]} - */ - set items(itemsCfg) { - this._clear(); - this._itemsCfg = itemsCfg || []; - this._parseItems(itemsCfg); - this._createUI(); - } - - /** - * Gets the ````ContextMenu```` items. - * - * @type {Object[]} - */ - get items() { - return this._itemsCfg; - } - - /** - * Sets whether this ````ContextMenu```` is enabled. - * - * Hides the menu when disabling. - * - * @type {Boolean} - */ - set enabled(enabled) { - enabled = (!!enabled); - if (enabled === this._enabled) { - return; - } - this._enabled = enabled; - if (!this._enabled) { - this.hide(); - } - } - - /** - * Gets whether this ````ContextMenu```` is enabled. - * - * {@link ContextMenu#show} does nothing while this is ````false````. - * - * @type {Boolean} - */ - get enabled() { - return this._enabled; - } - - /** - * Sets the ````ContextMenu```` context. - * - * The context can be any object that you need to be provides to the callbacks configured on {@link ContextMenu#items}. - * - * This must be set before calling {@link ContextMenu#show}. - * - * @type {Object} - */ - set context(context) { - this._context = context; - } - - /** - * Gets the ````ContextMenu```` context. - * - * @type {Object} - */ - get context() { - return this._context; - } - - /** - * Shows this ````ContextMenu```` at the given page coordinates. - * - * Does nothing when {@link ContextMenu#enabled} is ````false````. - * - * Logs error to console and does nothing if {@link ContextMenu#context} has not been set. - * - * Fires a "shown" event when shown. - * - * @param {Number} pageX Page X-coordinate. - * @param {Number} pageY Page Y-coordinate. - */ - show(pageX, pageY) { - if (!this._context) { - console.error("ContextMenu cannot be shown without a context - set context first"); - return; - } - if (!this._enabled) { - return; - } - if (this._shown) { - return; - } - this._hideAllMenus(); - this._updateItemsTitles(); - this._updateItemsEnabledStatus(); - this._showMenu(this._rootMenu.id, pageX, pageY); - this._updateSubMenuInfo(); - this._shown = true; - this.fire("shown", {}); - } - - /** - * Gets whether this ````ContextMenu```` is currently shown or not. - * - * @returns {Boolean} Whether this ````ContextMenu```` is shown. - */ - get shown() { - return this._shown; - } - - /** - * Hides this ````ContextMenu````. - * - * Fires a "hidden" event when hidden. - */ - hide() { - if (!this._enabled) { - return; - } - if (!this._shown) { - return; - } - this._hideAllMenus(); - this._shown = false; - this.fire("hidden", {}); - } - - /** - * Destroys this ````ContextMenu````. - */ - destroy() { - this._context = null; - this._clear(); - if (this._id !== null) { - idMap.removeItem(this._id); - this._id = null; - } - } - - _clear() { // Destroys DOM elements, clears menu data - for (let i = 0, len = this._menuList.length; i < len; i++) { - const menu = this._menuList[i]; - const menuElement = menu.menuElement; - menuElement.remove(); - } - this._itemsCfg = []; - this._rootMenu = null; - this._menuList = []; - this._menuMap = {}; - this._itemList = []; - this._itemMap = {}; - } - - _parseItems(itemsCfg) { // Parses "items" config into menu data - - const visitItems = (itemsCfg) => { - - const menuId = this._getNextId(); - const menu = new Menu(menuId); - - for (let i = 0, len = itemsCfg.length; i < len; i++) { - - const itemsGroupCfg = itemsCfg[i]; - - const group = new Group(); - - menu.groups.push(group); - - for (let j = 0, lenj = itemsGroupCfg.length; j < lenj; j++) { - - const itemCfg = itemsGroupCfg[j]; - const subItemsCfg = itemCfg.items; - const hasSubItems = (subItemsCfg && (subItemsCfg.length > 0)); - const itemId = this._getNextId(); - - const getTitle = itemCfg.getTitle || (() => { - return (itemCfg.title || ""); - }); - - const doAction = itemCfg.doAction || itemCfg.callback || (() => { - }); - - const getEnabled = itemCfg.getEnabled || (() => { - return true; - }); - - const getShown = itemCfg.getShown || (() => { - return true; - }); - - const item = new Item(itemId, getTitle, doAction, getEnabled, getShown); - - item.parentMenu = menu; - - group.items.push(item); - - if (hasSubItems) { - const subMenu = visitItems(subItemsCfg); - item.subMenu = subMenu; - subMenu.parentItem = item; - } - - this._itemList.push(item); - this._itemMap[item.id] = item; - } - } - - this._menuList.push(menu); - this._menuMap[menu.id] = menu; - - return menu; - }; - - this._rootMenu = visitItems(itemsCfg); - } - - _getNextId() { // Returns a unique ID - return "ContextMenu_" + this._id + "_" + this._nextId++; // Start ID with alpha chars to make a valid DOM element selector - } - - _createUI() { // Builds DOM elements for the entire menu tree - - const visitMenu = (menu) => { - - this._createMenuUI(menu); - - const groups = menu.groups; - for (let i = 0, len = groups.length; i < len; i++) { - const group = groups[i]; - const groupItems = group.items; - for (let j = 0, lenj = groupItems.length; j < lenj; j++) { - const item = groupItems[j]; - const subMenu = item.subMenu; - if (subMenu) { - visitMenu(subMenu); - } - } - } - }; - - visitMenu(this._rootMenu); - } - - _createMenuUI(menu) { // Builds DOM elements for a menu - - const groups = menu.groups; - const html = []; - - const menuElement= document.createElement("div"); - menuElement.classList.add("xeokit-context-menu", menu.id); - menuElement.style.zIndex = 300000; - menuElement.style.position = "absolute"; - - html.push(''); - - const htmlString = html.join(""); - menuElement.innerHTML = htmlString; - this._parentNode.appendChild(menuElement); - - menu.menuElement = menuElement; - - menuElement.style["border-radius"] = 4 + "px"; - menuElement.style.display = 'none'; - menuElement.style["z-index"] = 300000; - menuElement.style.background = "white"; - menuElement.style.border = "1px solid black"; - menuElement.style["box-shadow"] = "0 4px 5px 0 gray"; - menuElement.oncontextmenu = (e) => { - e.preventDefault(); - }; - - // Bind event handlers - - const self = this; - - let lastSubMenu = null; - - if (groups) { - - for (let i = 0, len = groups.length; i < len; i++) { - - const group = groups[i]; - const groupItems = group.items; - - if (groupItems) { - - for (let j = 0, lenj = groupItems.length; j < lenj; j++) { - - const item = groupItems[j]; - const itemSubMenu = item.subMenu; - - item.itemElement = this._parentNode.querySelector(`#${item.id}`); - - if (!item.itemElement) { - console.error("ContextMenu item element not found: " + item.id); - continue; - } - - item.itemElement.addEventListener("mouseenter", (event) => { - event.preventDefault(); - - const subMenu = item.subMenu; - if (!subMenu) { - if (lastSubMenu) { - self._hideMenu(lastSubMenu.id); - lastSubMenu = null; - } - return; - } - if (lastSubMenu && (lastSubMenu.id !== subMenu.id)) { - self._hideMenu(lastSubMenu.id); - lastSubMenu = null; - } - - if (item.enabled === false) { - return; - } - - const itemElement = item.itemElement; - const subMenuElement = subMenu.menuElement; - - const itemRect = itemElement.getBoundingClientRect(); - subMenuElement.getBoundingClientRect(); - const offsetRect = self._offsetParent.getBoundingClientRect(); - - const subMenuWidth = 200; // TODO - const showOnRight = (itemRect.right + subMenuWidth) < offsetRect.right; - const showOnLeft = (itemRect.left - subMenuWidth) > offsetRect.left; - - if(showOnRight) - self._showMenu(subMenu.id, itemRect.right + window.scrollX - 5, itemRect.top + window.scrollY - 1); - else if (showOnLeft) - self._showMenu(subMenu.id, itemRect.left - subMenuWidth + window.scrollX, itemRect.top + window.scrollY - 1); - else { - const spaceOnLeft = itemRect.left - offsetRect.left, spaceOnRight = offsetRect.right - itemRect.right; - if(spaceOnRight > spaceOnLeft) - self._showMenu(subMenu.id, itemRect.right - 5 - (subMenuWidth - spaceOnRight), itemRect.top + window.scrollY - 1); - else - self._showMenu(subMenu.id, itemRect.left - spaceOnLeft, itemRect.top + window.scrollY - 1); - } - - lastSubMenu = subMenu; - }); - - if (!itemSubMenu) { - - // Item without sub-menu - // clicking item fires the item's action callback - - item.itemElement.addEventListener("click", (event) => { - event.preventDefault(); - if (!self._context) { - return; - } - if (item.enabled === false) { - return; - } - if (item.doAction) { - item.doAction(self._context); - } - if (this._hideOnAction) { - self.hide(); - } else { - self._updateItemsTitles(); - self._updateItemsEnabledStatus(); - } - }); - item.itemElement.addEventListener("mouseup", (event) => { - if (event.which !== 3) { - return; - } - event.preventDefault(); - if (!self._context) { - return; - } - if (item.enabled === false) { - return; - } - if (item.doAction) { - item.doAction(self._context); - } - if (this._hideOnAction) { - self.hide(); - } else { - self._updateItemsTitles(); - self._updateItemsEnabledStatus(); - } - }); - item.itemElement.addEventListener("mouseenter", (event) => { - event.preventDefault(); - if (item.enabled === false) { - return; - } - if (item.doHover) { - item.doHover(self._context); - } - }); - - } - } - } - } - } - } - - _updateItemsTitles() { // Dynamically updates the title of each Item to the result of Item#getTitle() - if (!this._context) { - return; - } - for (let i = 0, len = this._itemList.length; i < len; i++) { - const item = this._itemList[i]; - const itemElement = item.itemElement; - if (!itemElement) { - continue; - } - const getShown = item.getShown; - if (!getShown || !getShown(this._context)) { - continue; - } - const title = item.getTitle(this._context); - if (item.subMenu) { - itemElement.innerText = title; - } else { - itemElement.innerText = title; - } - } - } - - _updateItemsEnabledStatus() { // Enables or disables each Item, depending on the result of Item#getEnabled() - if (!this._context) { - return; - } - for (let i = 0, len = this._itemList.length; i < len; i++) { - const item = this._itemList[i]; - const itemElement = item.itemElement; - if (!itemElement) { - continue; - } - const getEnabled = item.getEnabled; - if (!getEnabled) { - continue; - } - const getShown = item.getShown; - if (!getShown) { - continue; - } - const shown = getShown(this._context); - item.shown = shown; - if (!shown) { - itemElement.style.display = "none"; - continue; - } else { - itemElement.style.display = ""; - - } - const enabled = getEnabled(this._context); - item.enabled = enabled; - if (!enabled) { - itemElement.classList.add("disabled"); - } else { - itemElement.classList.remove("disabled"); - } - } - } - - _updateSubMenuInfo() { - if (!this._context) return; - let itemElement, itemRect, subMenuElement, initialStyles, showOnLeft, subMenuWidth; - this._itemList.forEach((item) => { - if (item.subMenu) { - itemElement = item.itemElement; - itemRect = itemElement.getBoundingClientRect(); - subMenuElement = item.subMenu.menuElement; - initialStyles = { - visibility: subMenuElement.style.visibility, - display: subMenuElement.style.display, - }; - subMenuElement.style.display = "block"; - subMenuElement.style.visibility = "hidden"; - subMenuWidth = item.subMenu.menuElement.getBoundingClientRect().width; - subMenuElement.style.visibility = initialStyles.visibility; - subMenuElement.style.display = initialStyles.display; - showOnLeft = ((itemRect.right + subMenuWidth) > window.innerWidth); - itemElement.setAttribute("data-submenuposition", showOnLeft ? "left" : "right"); - } - }); - } - - _showMenu(menuId, pageX, pageY) { // Shows the given menu, at the specified page coordinates - const menu = this._menuMap[menuId]; - if (!menu) { - console.error("Menu not found: " + menuId); - return; - } - if (menu.shown) { - return; - } - const menuElement = menu.menuElement; - if (menuElement) { - this._showMenuElement(menuElement, pageX, pageY); - menu.shown = true; - } - } - - _hideMenu(menuId) { // Hides the given menu - const menu = this._menuMap[menuId]; - if (!menu) { - console.error("Menu not found: " + menuId); - return; - } - if (!menu.shown) { - return; - } - const menuElement = menu.menuElement; - if (menuElement) { - this._hideMenuElement(menuElement); - menu.shown = false; - } - } - - _hideAllMenus() { - for (let i = 0, len = this._menuList.length; i < len; i++) { - const menu = this._menuList[i]; - this._hideMenu(menu.id); - } - } - - _showMenuElement(menuElement, pageX, pageY) { // Shows the given menu element, at the specified page coordinates - menuElement.style.display = 'block'; - const menuHeight = menuElement.offsetHeight; - const menuWidth = menuElement.offsetWidth; - - const offsetRect = this._offsetParent.getBoundingClientRect(); - - // A regression occurred, that positions the menu horizontally above the client viewport - // at 6188de17ddca5c069b75a7673c1cda1aa1e74d07 when window.innerHeight has been replaced by offsetRect.bottom - // Reported originally at XCD-332 - // Reproducible with examples/measurement/distance_createWithMouse_snapping.html - // Dirty hack introduced as XEOK-306, to be improved in the future to a more general solution - const bottomContainerBorder = ((this._offsetParent === window.document.body) && (offsetRect.bottom === 0)) ? window.innerHeight : (offsetRect.bottom + window.scrollY); - const rightContainerBorder = offsetRect.right + window.scrollX; - if ((pageY + menuHeight) > bottomContainerBorder) { - pageY = bottomContainerBorder- menuHeight; - } - if ((pageX + menuWidth) > rightContainerBorder) { - pageX = rightContainerBorder - menuWidth; - } - - - menuElement.style.left = pageX - offsetRect.left - window.scrollX + 'px'; - menuElement.style.top = pageY - offsetRect.top - window.scrollY + 'px'; - } - - _hideMenuElement(menuElement) { - menuElement.style.display = 'none'; - } -} - -/** - * A PointerLens shows a magnified view of a {@link Viewer}'s canvas, centered at the position of the - * mouse or touch pointer. - * - * This component is used by {@link DistanceMeasurementsControl} and {@link AngleMeasurementsControl} - * to help position the pointer when snap-to-vertex or snap-toedge is enabled. - * - * [[Run an example](https://xeokit.github.io/xeokit-sdk/examples/measurement/#distance_createWithMouse_snapping)] - * - * ````JavaScript - * - * import {Viewer, XKTLoaderPlugin, AngleMeasurementsPlugin, AngleMeasurementsMouseControl, PointerLens} from "../../dist/xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * dtxEnabled: true - * }); - * - * viewer.camera.eye = [-3.93, 2.85, 27.01]; - * viewer.camera.look = [4.40, 3.72, 8.89]; - * viewer.camera.up = [-0.01, 0.99, 0.039]; - * - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * const sceneModel = xktLoader.load({ - * id: "myModel", - * src: "../../assets/models/xkt/v10/glTF-Embedded/Duplex_A_20110505.glTFEmbedded.xkt", - * edges: true - * }); - * - * const angleMeasurements = new AngleMeasurementsPlugin(viewer); - * - * const angleMeasurementsMouseControl = new AngleMeasurementsMouseControl(angleMeasurements, { - * pointerLens : new PointerLens(viewer, { - * zoomFactor: 2 - * }) - * }) - * - * angleMeasurementsMouseControl.activate(); - * ```` - */ -class PointerLens { - - /** - * Constructs a new PointerLens. - * @param viewer The Viewer - * @param [cfg] PointerLens configuration. - * @param [cfg.active=true] Whether PointerLens is active. The PointerLens can only be shown when this is `true` (default). - */ - constructor(viewer, cfg={}) { - - this.viewer = viewer; - this.scene = this.viewer.scene; - - this._lensCursorDiv = document.createElement('div'); - this._lensParams = { canvasSize: 300, cursorBorder: 2, cursorSize: 10 }; - this._lensCursorDiv.style.borderRadius = "50%"; - this._lensCursorDiv.style.width = this._lensParams.cursorSize + "px"; - this._lensCursorDiv.style.height = this._lensParams.cursorSize + "px"; - this._lensCursorDiv.style.zIndex = "100000"; - this._lensCursorDiv.style.position = "absolute"; - this._lensCursorDiv.style.pointerEvents = "none"; - - this._lensContainer = document.createElement('div'); - this._lensContainerId = cfg.containerId || 'xeokit-lens'; - this._lensContainer.setAttribute("id", this._lensContainerId); - - this._lensContainer.style.border = "1px solid black"; - this._lensContainer.style.background = "white"; - // this._lensContainer.style.opacity = "0"; - this._lensContainer.style.borderRadius = "50%"; - this._lensContainer.style.width = this._lensParams.canvasSize + "px"; - this._lensContainer.style.height = this._lensParams.canvasSize + "px"; - - this._lensContainer.style.zIndex = "15000"; - this._lensContainer.style.position = "absolute"; - this._lensContainer.style.pointerEvents = "none"; - this._lensContainer.style.visibility = "hidden"; - - this._lensCanvas = document.createElement('canvas'); - this._lensCanvas.id = `${this._lensContainerId}-canvas`; - // this._lensCanvas.style.background = "darkblue"; - this._lensCanvas.style.borderRadius = "50%"; - - this._lensCanvas.style.width = this._lensParams.canvasSize + "px"; - this._lensCanvas.style.height = this._lensParams.canvasSize + "px"; - this._lensCanvas.style.zIndex = "15000"; - this._lensCanvas.style.pointerEvents = "none"; - - document.body.appendChild(this._lensContainer); - this._lensContainer.appendChild(this._lensCanvas); - this._lensContainer.appendChild(this._lensCursorDiv); - - this._lensCanvasContext = this._lensCanvas.getContext('2d'); - this._canvasElement = this.viewer.scene.canvas.canvas; - - this._canvasPos = null; - this._snappedCanvasPos = null; - this._lensPosToggle = cfg.lensPosToggle || true; - this._lensPosToggleAmount = cfg.lensPosToggleAmount || 85; - this._lensPosMarginLeft = cfg.lensPosMarginLeft || 85; - this._lensPosMarginTop = cfg.lensPosMarginTop || 25; - this._lensContainer.style.marginTop = `${this._lensPosMarginTop}px`; - this._lensContainer.style.marginLeft = `${this._lensPosMarginLeft}px`; - - this._zoomLevel = cfg.zoomLevel || 2; - - this._active = (cfg.active !== false); - this._visible = false; - this.snapped = false; - - this._onViewerRendering = this.viewer.scene.on("rendering", () => { - if (this._active && this._visible) { - this.update(); - } - }); - } - - /** - * Updates this PointerLens. - */ - update() { - if (!this._active || !this._visible) { - return; - } - if (!this._canvasPos) { - return; - } - const lensRect = this._lensContainer.getBoundingClientRect(); - const canvasRect = this._canvasElement.getBoundingClientRect(); - const pointerOnLens = - this._canvasPos[0] < lensRect.right && this._canvasPos[0] > lensRect.left && - this._canvasPos[1] < lensRect.bottom && this._canvasPos[1] > lensRect.top; - this._lensContainer.style.marginLeft = `${this._lensPosMarginLeft}px`; - if (pointerOnLens) { - if (this._lensPosToggle) { - this._lensContainer.style.marginTop = `${canvasRect.bottom - canvasRect.top - this._lensCanvas.height - this._lensPosToggleAmount}px`; - } else { - this._lensContainer.style.marginTop = `${this._lensPosMarginTop}px`; - } - this._lensPosToggle = !this._lensPosToggle; - } - this._lensCanvasContext.clearRect(0, 0, this._lensCanvas.width, this._lensCanvas.height); - const size = Math.max(this._lensCanvas.width, this._lensCanvas.height) / this._zoomLevel; - this._lensCanvasContext.drawImage( - this._canvasElement, // source canvas - this._canvasPos[0] - size / 2, // source x (zoom center) - this._canvasPos[1] - size / 2, // source y (zoom center) - size, // source width - size, // source height - 0, // destination x - 0, // destination y - this._lensCanvas.width, // destination width - this._lensCanvas.height // destination height - ); - - const middle = this._lensParams.canvasSize / 2 - this._lensParams.cursorSize / 2 - this._lensParams.cursorBorder; - - const deltaX = this._snappedCanvasPos ? (this._snappedCanvasPos[0] - this._canvasPos[0]) : 0; - const deltaY = this._snappedCanvasPos ? (this._snappedCanvasPos[1] - this._canvasPos[1]) : 0; - - this._lensCursorDiv.style.left = `${middle + deltaX * this._zoomLevel}px`; - this._lensCursorDiv.style.top = `${middle + deltaY * this._zoomLevel}px`; - } - - - /** - * Sets the zoom factor for the lens. - * - * This is `2` by default. - * - * @param zoomFactor - */ - set zoomFactor(zoomFactor) { - this._zoomFactor = zoomFactor; - this.update(); - } - - /** - * Gets the zoom factor for the lens. - * - * This is `2` by default. - * - * @returns Number - */ - get zoomFactor() { - return this._zoomFactor; - } - - /** - * Sets the canvas central position of the lens. - * @param canvasPos - */ - set canvasPos(canvasPos) { - this._canvasPos = canvasPos; - this.update(); - } - - /** - * Gets the canvas central position of the lens. - * @returns {Number[]} - */ - get canvasPos() { - return this._canvasPos; - } - - /** - * Sets the canvas coordinates of the pointer. - * @param snappedCanvasPos - */ - set snappedCanvasPos(snappedCanvasPos) { - this._snappedCanvasPos = snappedCanvasPos; - this.update(); - } - - /** - * Gets the canvas coordinates of the snapped pointer. - * @returns {Number[]} - */ - get snappedCanvasPos() { - return this._snappedCanvasPos; - } - - /** - * Sets if the cursor has snapped to anything. - * This is set by plugins. - * @param snapped - * @private - */ - set snapped(snapped) { - this._snapped = snapped; - const [ bg, border ] = snapped ? [ "greenyellow", "green" ] : [ "pink", "red" ]; - this._lensCursorDiv.style.background = bg; - this._lensCursorDiv.style.border = this._lensParams.cursorBorder + "px solid " + border; - } - - /** - * Gets if the cursor has snapped to anything. - * This is called by plugins. - * @returns {Boolean} - * @private - */ - get snapped() { - return this._snapped; - } - - _updateActiveVisible() { - this._lensContainer.style.visibility = (this._active && this._visible) ? "visible" : "hidden"; - this.update(); - } - - /** - * Sets if this PointerLens is active. - * @param active - */ - set active(active) { - this._active = active; - this._updateActiveVisible(); - } - - /** - * Gets if this PointerLens is active. - * @returns {Boolean} - */ - get active() { - return this._active; - } - - /** - * Sets if this PointerLens is visible. - * This is set by plugins. - * @param visible - * @private - */ - set visible(visible) { - this._visible = visible; - this._updateActiveVisible(); - } - - /** - * Gets if this PointerLens is visible. - * This is called by plugins. - * @returns {Boolean} - * @private - */ - get visible() { - return this._visible; - } - - /** - * Destroys this PointerLens. - */ - destroy() { - if (!this._destroyed) { - this.viewer.scene.off(this._onViewerRendering); - this._lensContainer.removeChild(this._lensCanvas); - document.body.removeChild(this._lensContainer); - this._destroyed = true; - } - } -} - -function earcut(data, holeIndices, dim = 2) { - - const hasHoles = holeIndices && holeIndices.length; - const outerLen = hasHoles ? holeIndices[0] * dim : data.length; - let outerNode = linkedList(data, 0, outerLen, dim, true); - const triangles = []; - - if (!outerNode || outerNode.next === outerNode.prev) return triangles; - - let minX, minY, invSize; - - if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim); - - // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox - if (data.length > 80 * dim) { - minX = Infinity; - minY = Infinity; - let maxX = -Infinity; - let maxY = -Infinity; - - for (let i = dim; i < outerLen; i += dim) { - const x = data[i]; - const y = data[i + 1]; - if (x < minX) minX = x; - if (y < minY) minY = y; - if (x > maxX) maxX = x; - if (y > maxY) maxY = y; - } - - // minX, minY and invSize are later used to transform coords into integers for z-order calculation - invSize = Math.max(maxX - minX, maxY - minY); - invSize = invSize !== 0 ? 32767 / invSize : 0; - } - - earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0); - - return triangles; -} - -// create a circular doubly linked list from polygon points in the specified winding order -function linkedList(data, start, end, dim, clockwise) { - let last; - - if (clockwise === (signedArea(data, start, end, dim) > 0)) { - for (let i = start; i < end; i += dim) last = insertNode(i / dim | 0, data[i], data[i + 1], last); - } else { - for (let i = end - dim; i >= start; i -= dim) last = insertNode(i / dim | 0, data[i], data[i + 1], last); - } - - if (last && equals$1(last, last.next)) { - removeNode(last); - last = last.next; - } - - return last; -} - -// eliminate colinear or duplicate points -function filterPoints(start, end) { - if (!start) return start; - if (!end) end = start; - - let p = start, - again; - do { - again = false; - - if (!p.steiner && (equals$1(p, p.next) || area(p.prev, p, p.next) === 0)) { - removeNode(p); - p = end = p.prev; - if (p === p.next) break; - again = true; - - } else { - p = p.next; - } - } while (again || p !== end); - - return end; -} - -// main ear slicing loop which triangulates a polygon (given as a linked list) -function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) { - if (!ear) return; - - // interlink polygon nodes in z-order - if (!pass && invSize) indexCurve(ear, minX, minY, invSize); - - let stop = ear; - - // iterate through ears, slicing them one by one - while (ear.prev !== ear.next) { - const prev = ear.prev; - const next = ear.next; - - if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) { - triangles.push(prev.i, ear.i, next.i); // cut off the triangle - - removeNode(ear); - - // skipping the next vertex leads to less sliver triangles - ear = next.next; - stop = next.next; - - continue; - } - - ear = next; - - // if we looped through the whole remaining polygon and can't find any more ears - if (ear === stop) { - // try filtering points and slicing again - if (!pass) { - earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); - - // if this didn't work, try curing all small self-intersections locally - } else if (pass === 1) { - ear = cureLocalIntersections(filterPoints(ear), triangles); - earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); - - // as a last resort, try splitting the remaining polygon into two - } else if (pass === 2) { - splitEarcut(ear, triangles, dim, minX, minY, invSize); - } - - break; - } - } -} - -// check whether a polygon node forms a valid ear with adjacent nodes -function isEar(ear) { - const a = ear.prev, - b = ear, - c = ear.next; - - if (area(a, b, c) >= 0) return false; // reflex, can't be an ear - - // now make sure we don't have other points inside the potential ear - const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y; - - // triangle bbox - const x0 = Math.min(ax, bx, cx), - y0 = Math.min(ay, by, cy), - x1 = Math.max(ax, bx, cx), - y1 = Math.max(ay, by, cy); - - let p = c.next; - while (p !== a) { - if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && - pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, p.x, p.y) && - area(p.prev, p, p.next) >= 0) return false; - p = p.next; - } - - return true; -} - -function isEarHashed(ear, minX, minY, invSize) { - const a = ear.prev, - b = ear, - c = ear.next; - - if (area(a, b, c) >= 0) return false; // reflex, can't be an ear - - const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y; - - // triangle bbox - const x0 = Math.min(ax, bx, cx), - y0 = Math.min(ay, by, cy), - x1 = Math.max(ax, bx, cx), - y1 = Math.max(ay, by, cy); - - // z-order range for the current triangle bbox; - const minZ = zOrder(x0, y0, minX, minY, invSize), - maxZ = zOrder(x1, y1, minX, minY, invSize); - - let p = ear.prevZ, - n = ear.nextZ; - - // look for points inside the triangle in both directions - while (p && p.z >= minZ && n && n.z <= maxZ) { - if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && - pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false; - p = p.prevZ; - - if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && - pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false; - n = n.nextZ; - } - - // look for remaining points in decreasing z-order - while (p && p.z >= minZ) { - if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && - pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false; - p = p.prevZ; - } - - // look for remaining points in increasing z-order - while (n && n.z <= maxZ) { - if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && - pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false; - n = n.nextZ; - } - - return true; -} - -// go through all polygon nodes and cure small local self-intersections -function cureLocalIntersections(start, triangles) { - let p = start; - do { - const a = p.prev, - b = p.next.next; - - if (!equals$1(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) { - - triangles.push(a.i, p.i, b.i); - - // remove two nodes involved - removeNode(p); - removeNode(p.next); - - p = start = b; - } - p = p.next; - } while (p !== start); - - return filterPoints(p); -} - -// try splitting polygon into two and triangulate them independently -function splitEarcut(start, triangles, dim, minX, minY, invSize) { - // look for a valid diagonal that divides the polygon into two - let a = start; - do { - let b = a.next.next; - while (b !== a.prev) { - if (a.i !== b.i && isValidDiagonal(a, b)) { - // split the polygon in two by the diagonal - let c = splitPolygon(a, b); - - // filter colinear points around the cuts - a = filterPoints(a, a.next); - c = filterPoints(c, c.next); - - // run earcut on each half - earcutLinked(a, triangles, dim, minX, minY, invSize, 0); - earcutLinked(c, triangles, dim, minX, minY, invSize, 0); - return; - } - b = b.next; - } - a = a.next; - } while (a !== start); -} - -// link every hole into the outer loop, producing a single-ring polygon without holes -function eliminateHoles(data, holeIndices, outerNode, dim) { - const queue = []; - - for (let i = 0, len = holeIndices.length; i < len; i++) { - const start = holeIndices[i] * dim; - const end = i < len - 1 ? holeIndices[i + 1] * dim : data.length; - const list = linkedList(data, start, end, dim, false); - if (list === list.next) list.steiner = true; - queue.push(getLeftmost(list)); - } - - queue.sort(compareXYSlope); - - // process holes from left to right - for (let i = 0; i < queue.length; i++) { - outerNode = eliminateHole(queue[i], outerNode); - } - - return outerNode; -} - -function compareXYSlope(a, b) { - let result = a.x - b.x; - // when the left-most point of 2 holes meet at a vertex, sort the holes counterclockwise so that when we find - // the bridge to the outer shell is always the point that they meet at. - if (result === 0) { - result = a.y - b.y; - if (result === 0) { - const aSlope = (a.next.y - a.y) / (a.next.x - a.x); - const bSlope = (b.next.y - b.y) / (b.next.x - b.x); - result = aSlope - bSlope; - } - } - return result; -} - -// find a bridge between vertices that connects hole with an outer ring and and link it -function eliminateHole(hole, outerNode) { - const bridge = findHoleBridge(hole, outerNode); - if (!bridge) { - return outerNode; - } - - const bridgeReverse = splitPolygon(bridge, hole); - - // filter collinear points around the cuts - filterPoints(bridgeReverse, bridgeReverse.next); - return filterPoints(bridge, bridge.next); -} - -// David Eberly's algorithm for finding a bridge between hole and outer polygon -function findHoleBridge(hole, outerNode) { - let p = outerNode; - const hx = hole.x; - const hy = hole.y; - let qx = -Infinity; - let m; - - // find a segment intersected by a ray from the hole's leftmost point to the left; - // segment's endpoint with lesser x will be potential connection point - // unless they intersect at a vertex, then choose the vertex - if (equals$1(hole, p)) return p; - do { - if (equals$1(hole, p.next)) return p.next; - else if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) { - const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y); - if (x <= hx && x > qx) { - qx = x; - m = p.x < p.next.x ? p : p.next; - if (x === hx) return m; // hole touches outer segment; pick leftmost endpoint - } - } - p = p.next; - } while (p !== outerNode); - - if (!m) return null; - - // look for points inside the triangle of hole point, segment intersection and endpoint; - // if there are no points found, we have a valid connection; - // otherwise choose the point of the minimum angle with the ray as connection point - - const stop = m; - const mx = m.x; - const my = m.y; - let tanMin = Infinity; - - p = m; - - do { - if (hx >= p.x && p.x >= mx && hx !== p.x && - pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) { - - const tan = Math.abs(hy - p.y) / (hx - p.x); // tangential - - if (locallyInside(p, hole) && - (tan < tanMin || (tan === tanMin && (p.x > m.x || (p.x === m.x && sectorContainsSector(m, p)))))) { - m = p; - tanMin = tan; - } - } - - p = p.next; - } while (p !== stop); - - return m; -} - -// whether sector in vertex m contains sector in vertex p in the same coordinates -function sectorContainsSector(m, p) { - return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0; -} - -// interlink polygon nodes in z-order -function indexCurve(start, minX, minY, invSize) { - let p = start; - do { - if (p.z === 0) p.z = zOrder(p.x, p.y, minX, minY, invSize); - p.prevZ = p.prev; - p.nextZ = p.next; - p = p.next; - } while (p !== start); - - p.prevZ.nextZ = null; - p.prevZ = null; - - sortLinked(p); -} - -// Simon Tatham's linked list merge sort algorithm -// http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html -function sortLinked(list) { - let numMerges; - let inSize = 1; - - do { - let p = list; - let e; - list = null; - let tail = null; - numMerges = 0; - - while (p) { - numMerges++; - let q = p; - let pSize = 0; - for (let i = 0; i < inSize; i++) { - pSize++; - q = q.nextZ; - if (!q) break; - } - let qSize = inSize; - - while (pSize > 0 || (qSize > 0 && q)) { - - if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) { - e = p; - p = p.nextZ; - pSize--; - } else { - e = q; - q = q.nextZ; - qSize--; - } - - if (tail) tail.nextZ = e; - else list = e; - - e.prevZ = tail; - tail = e; - } - - p = q; - } - - tail.nextZ = null; - inSize *= 2; - - } while (numMerges > 1); - - return list; -} - -// z-order of a point given coords and inverse of the longer side of data bbox -function zOrder(x, y, minX, minY, invSize) { - // coords are transformed into non-negative 15-bit integer range - x = (x - minX) * invSize | 0; - y = (y - minY) * invSize | 0; - - x = (x | (x << 8)) & 0x00FF00FF; - x = (x | (x << 4)) & 0x0F0F0F0F; - x = (x | (x << 2)) & 0x33333333; - x = (x | (x << 1)) & 0x55555555; - - y = (y | (y << 8)) & 0x00FF00FF; - y = (y | (y << 4)) & 0x0F0F0F0F; - y = (y | (y << 2)) & 0x33333333; - y = (y | (y << 1)) & 0x55555555; - - return x | (y << 1); -} - -// find the leftmost node of a polygon ring -function getLeftmost(start) { - let p = start, - leftmost = start; - do { - if (p.x < leftmost.x || (p.x === leftmost.x && p.y < leftmost.y)) leftmost = p; - p = p.next; - } while (p !== start); - - return leftmost; -} - -// check if a point lies within a convex triangle -function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) { - return (cx - px) * (ay - py) >= (ax - px) * (cy - py) && - (ax - px) * (by - py) >= (bx - px) * (ay - py) && - (bx - px) * (cy - py) >= (cx - px) * (by - py); -} - -// check if a point lies within a convex triangle but false if its equal to the first point of the triangle -function pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, px, py) { - return !(ax === px && ay === py) && pointInTriangle(ax, ay, bx, by, cx, cy, px, py); -} - -// check if a diagonal between two polygon nodes is valid (lies in polygon interior) -function isValidDiagonal(a, b) { - return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && // dones't intersect other edges - (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && // locally visible - (area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors - equals$1(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case -} - -// signed area of a triangle -function area(p, q, r) { - return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y); -} - -// check if two points are equal -function equals$1(p1, p2) { - return p1.x === p2.x && p1.y === p2.y; -} - -// check if two segments intersect -function intersects(p1, q1, p2, q2) { - const o1 = sign(area(p1, q1, p2)); - const o2 = sign(area(p1, q1, q2)); - const o3 = sign(area(p2, q2, p1)); - const o4 = sign(area(p2, q2, q1)); - - if (o1 !== o2 && o3 !== o4) return true; // general case - - if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1 - if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1 - if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2 - if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2 - - return false; -} - -// for collinear points p, q, r, check if point q lies on segment pr -function onSegment(p, q, r) { - return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y); -} - -function sign(num) { - return num > 0 ? 1 : num < 0 ? -1 : 0; -} - -// check if a polygon diagonal intersects any polygon segments -function intersectsPolygon(a, b) { - let p = a; - do { - if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && - intersects(p, p.next, a, b)) return true; - p = p.next; - } while (p !== a); - - return false; -} - -// check if a polygon diagonal is locally inside the polygon -function locallyInside(a, b) { - return area(a.prev, a, a.next) < 0 ? - area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : - area(a, b, a.prev) < 0 || area(a, a.next, b) < 0; -} - -// check if the middle point of a polygon diagonal is inside the polygon -function middleInside(a, b) { - let p = a; - let inside = false; - const px = (a.x + b.x) / 2; - const py = (a.y + b.y) / 2; - do { - if (((p.y > py) !== (p.next.y > py)) && p.next.y !== p.y && - (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)) - inside = !inside; - p = p.next; - } while (p !== a); - - return inside; -} - -// link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two; -// if one belongs to the outer ring and another to a hole, it merges it into a single ring -function splitPolygon(a, b) { - const a2 = createNode(a.i, a.x, a.y), - b2 = createNode(b.i, b.x, b.y), - an = a.next, - bp = b.prev; - - a.next = b; - b.prev = a; - - a2.next = an; - an.prev = a2; - - b2.next = a2; - a2.prev = b2; - - bp.next = b2; - b2.prev = bp; - - return b2; -} - -// create a node and optionally link it with previous one (in a circular doubly linked list) -function insertNode(i, x, y, last) { - const p = createNode(i, x, y); - - if (!last) { - p.prev = p; - p.next = p; - - } else { - p.next = last.next; - p.prev = last; - last.next.prev = p; - last.next = p; - } - return p; -} - -function removeNode(p) { - p.next.prev = p.prev; - p.prev.next = p.next; - - if (p.prevZ) p.prevZ.nextZ = p.nextZ; - if (p.nextZ) p.nextZ.prevZ = p.prevZ; -} - -function createNode(i, x, y) { - return { - i, // vertex index in coordinates array - x, y, // vertex coordinates - prev: null, // previous and next vertex nodes in a polygon ring - next: null, - z: 0, // z-order curve value - prevZ: null, // previous and next nodes in z-order - nextZ: null, - steiner: false // indicates whether this is a steiner point - }; -} - -function signedArea(data, start, end, dim) { - let sum = 0; - for (let i = start, j = end - dim; i < end; i += dim) { - sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]); - j = i; - } - return sum; -} - -// Some temporary vars to help avoid garbage collection - -let doublePrecision = true; -let FloatArrayType = doublePrecision ? Float64Array : Float32Array; - -const tempVec3a$j = new FloatArrayType(3); - -const tempMat1 = new FloatArrayType(16); -const tempMat2 = new FloatArrayType(16); -const tempVec4$4 = new FloatArrayType(4); - - -/** - * @private - */ -const math = { - - setDoublePrecisionEnabled(enable) { - doublePrecision = enable; - FloatArrayType = doublePrecision ? Float64Array : Float32Array; - }, - - getDoublePrecisionEnabled() { - return doublePrecision; - }, - - MIN_DOUBLE: -Number.MAX_SAFE_INTEGER, - MAX_DOUBLE: Number.MAX_SAFE_INTEGER, - - MAX_INT: 10000000, - - /** - * The number of radiians in a degree (0.0174532925). - * @property DEGTORAD - * @type {Number} - */ - DEGTORAD: 0.0174532925, - - /** - * The number of degrees in a radian. - * @property RADTODEG - * @type {Number} - */ - RADTODEG: 57.295779513, - - unglobalizeObjectId(modelId, globalId) { - const idx = globalId.indexOf("#"); - return (idx === modelId.length && globalId.startsWith(modelId)) ? globalId.substring(idx + 1) : globalId; - }, - - globalizeObjectId(modelId, objectId) { - return (modelId + "#" + objectId) - }, - - /** - * Returns: - * - x != 0 => 1/x, - * - x == 1 => 1 - * - * @param {number} x - */ - safeInv(x) { - const retVal = 1 / x; - if (isNaN(retVal) || !isFinite(retVal)) { - return 1; - } - return retVal; - }, - - /** - * Returns a new, uninitialized two-element vector. - * @method vec2 - * @param [values] Initial values. - * @static - * @returns {Number[]} - */ - vec2(values) { - return new FloatArrayType(values || 2); - }, - - /** - * Returns a new, uninitialized three-element vector. - * @method vec3 - * @param [values] Initial values. - * @static - * @returns {Number[]} - */ - vec3(values) { - return new FloatArrayType(values || 3); - }, - - /** - * Returns a new, uninitialized four-element vector. - * @method vec4 - * @param [values] Initial values. - * @static - * @returns {Number[]} - */ - vec4(values) { - return new FloatArrayType(values || 4); - }, - - /** - * Returns a new, uninitialized 3x3 matrix. - * @method mat3 - * @param [values] Initial values. - * @static - * @returns {Number[]} - */ - mat3(values) { - return new FloatArrayType(values || 9); - }, - - /** - * Converts a 3x3 matrix to 4x4 - * @method mat3ToMat4 - * @param mat3 3x3 matrix. - * @param mat4 4x4 matrix - * @static - * @returns {Number[]} - */ - mat3ToMat4(mat3, mat4 = new FloatArrayType(16)) { - mat4[0] = mat3[0]; - mat4[1] = mat3[1]; - mat4[2] = mat3[2]; - mat4[3] = 0; - mat4[4] = mat3[3]; - mat4[5] = mat3[4]; - mat4[6] = mat3[5]; - mat4[7] = 0; - mat4[8] = mat3[6]; - mat4[9] = mat3[7]; - mat4[10] = mat3[8]; - mat4[11] = 0; - mat4[12] = 0; - mat4[13] = 0; - mat4[14] = 0; - mat4[15] = 1; - return mat4; - }, - - /** - * Returns a new, uninitialized 4x4 matrix. - * @method mat4 - * @param [values] Initial values. - * @static - * @returns {Number[]} - */ - mat4(values) { - return new FloatArrayType(values || 16); - }, - - /** - * Converts a 4x4 matrix to 3x3 - * @method mat4ToMat3 - * @param mat4 4x4 matrix. - * @param mat3 3x3 matrix - * @static - * @returns {Number[]} - */ - mat4ToMat3(mat4, mat3 = new FloatArrayType(9)) { - mat3[0] = mat4[0]; - mat3[1] = mat4[1]; - mat3[2] = mat4[2]; - - mat3[3] = mat4[4]; - mat3[4] = mat4[5]; - mat3[5] = mat4[6]; - - mat3[6] = mat4[8]; - mat3[7] = mat4[9]; - mat3[8] = mat4[10]; - - return mat3; - }, - - /** - * Converts a list of double-precision values to a list of high-part floats and a list of low-part floats. - * @param doubleVals - * @param floatValsHigh - * @param floatValsLow - */ - doublesToFloats(doubleVals, floatValsHigh, floatValsLow) { - const floatPair = new FloatArrayType(2); - for (let i = 0, len = doubleVals.length; i < len; i++) { - math.splitDouble(doubleVals[i], floatPair); - floatValsHigh[i] = floatPair[0]; - floatValsLow[i] = floatPair[1]; - } - }, - - /** - * Splits a double value into two floats. - * @param value - * @param floatPair - */ - splitDouble(value, floatPair) { - const hi = FloatArrayType.from([value])[0]; - const low = value - hi; - floatPair[0] = hi; - floatPair[1] = low; - }, - - /** - * Returns a new UUID. - * @method createUUID - * @static - * @return string The new UUID - */ - createUUID: ((() => { - const lut = []; - for (let i = 0; i < 256; i++) { - lut[i] = (i < 16 ? '0' : '') + (i).toString(16); - } - return () => { - const d0 = Math.random() * 0xffffffff | 0; - const d1 = Math.random() * 0xffffffff | 0; - const d2 = Math.random() * 0xffffffff | 0; - const d3 = Math.random() * 0xffffffff | 0; - return `${lut[d0 & 0xff] + lut[d0 >> 8 & 0xff] + lut[d0 >> 16 & 0xff] + lut[d0 >> 24 & 0xff]}-${lut[d1 & 0xff]}${lut[d1 >> 8 & 0xff]}-${lut[d1 >> 16 & 0x0f | 0x40]}${lut[d1 >> 24 & 0xff]}-${lut[d2 & 0x3f | 0x80]}${lut[d2 >> 8 & 0xff]}-${lut[d2 >> 16 & 0xff]}${lut[d2 >> 24 & 0xff]}${lut[d3 & 0xff]}${lut[d3 >> 8 & 0xff]}${lut[d3 >> 16 & 0xff]}${lut[d3 >> 24 & 0xff]}`; - }; - }))(), - - /** - * Clamps a value to the given range. - * @param {Number} value Value to clamp. - * @param {Number} min Lower bound. - * @param {Number} max Upper bound. - * @returns {Number} Clamped result. - */ - clamp(value, min, max) { - return Math.max(min, Math.min(max, value)); - }, - - /** - * Floating-point modulus - * @method fmod - * @static - * @param {Number} a - * @param {Number} b - * @returns {*} - */ - fmod(a, b) { - if (a < b) { - console.error("math.fmod : Attempting to find modulus within negative range - would be infinite loop - ignoring"); - return a; - } - while (b <= a) { - a -= b; - } - return a; - }, - - /** - * Returns true if the two 2-element vectors are the same. - * @param v1 - * @param v2 - * @returns {Boolean} - */ - compareVec2(v1, v2) { - return (v1[0] === v2[0] && v1[1] === v2[1]); - }, - - /** - * Returns true if the two 3-element vectors are the same. - * @param v1 - * @param v2 - * @returns {Boolean} - */ - compareVec3(v1, v2) { - return (v1[0] === v2[0] && v1[1] === v2[1] && v1[2] === v2[2]); - }, - - /** - * Returns true if the two 4-element vectors are the same. - * @param v1 - * @param v2 - * @returns {Boolean} - */ - compareVec4(v1, v2) { - return (v1[0] === v2[0] && v1[1] === v2[1] && v1[2] === v2[2] && v1[3] === v2[3]); - }, - - /** - * Negates a three-element vector. - * @method negateVec3 - * @static - * @param {Array(Number)} v Vector to negate - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, v otherwise - */ - negateVec3(v, dest) { - if (!dest) { - dest = v; - } - dest[0] = -v[0]; - dest[1] = -v[1]; - dest[2] = -v[2]; - return dest; - }, - - /** - * Negates a four-element vector. - * @method negateVec4 - * @static - * @param {Array(Number)} v Vector to negate - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, v otherwise - */ - negateVec4(v, dest) { - if (!dest) { - dest = v; - } - dest[0] = -v[0]; - dest[1] = -v[1]; - dest[2] = -v[2]; - dest[3] = -v[3]; - return dest; - }, - - /** - * Adds one four-element vector to another. - * @method addVec4 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Second vector - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, u otherwise - */ - addVec4(u, v, dest) { - if (!dest) { - dest = u; - } - dest[0] = u[0] + v[0]; - dest[1] = u[1] + v[1]; - dest[2] = u[2] + v[2]; - dest[3] = u[3] + v[3]; - return dest; - }, - - /** - * Adds a scalar value to each element of a four-element vector. - * @method addVec4Scalar - * @static - * @param {Array(Number)} v The vector - * @param {Number} s The scalar - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, v otherwise - */ - addVec4Scalar(v, s, dest) { - if (!dest) { - dest = v; - } - dest[0] = v[0] + s; - dest[1] = v[1] + s; - dest[2] = v[2] + s; - dest[3] = v[3] + s; - return dest; - }, - - /** - * Adds one two-element vector to another. - * @method addVec3 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Second vector - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, u otherwise - */ - addVec2(u, v, dest) { - if (!dest) { - dest = u; - } - dest[0] = u[0] + v[0]; - dest[1] = u[1] + v[1]; - return dest; - }, - - /** - * Adds one three-element vector to another. - * @method addVec3 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Second vector - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, u otherwise - */ - addVec3(u, v, dest) { - if (!dest) { - dest = u; - } - dest[0] = u[0] + v[0]; - dest[1] = u[1] + v[1]; - dest[2] = u[2] + v[2]; - return dest; - }, - - /** - * Adds a scalar value to each element of a three-element vector. - * @method addVec4Scalar - * @static - * @param {Array(Number)} v The vector - * @param {Number} s The scalar - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, v otherwise - */ - addVec3Scalar(v, s, dest) { - if (!dest) { - dest = v; - } - dest[0] = v[0] + s; - dest[1] = v[1] + s; - dest[2] = v[2] + s; - return dest; - }, - - /** - * Subtracts one four-element vector from another. - * @method subVec4 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Vector to subtract - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, u otherwise - */ - subVec4(u, v, dest) { - if (!dest) { - dest = u; - } - dest[0] = u[0] - v[0]; - dest[1] = u[1] - v[1]; - dest[2] = u[2] - v[2]; - dest[3] = u[3] - v[3]; - return dest; - }, - - /** - * Subtracts one three-element vector from another. - * @method subVec3 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Vector to subtract - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, u otherwise - */ - subVec3(u, v, dest) { - if (!dest) { - dest = u; - } - dest[0] = u[0] - v[0]; - dest[1] = u[1] - v[1]; - dest[2] = u[2] - v[2]; - return dest; - }, - - /** - * Subtracts one two-element vector from another. - * @method subVec2 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Vector to subtract - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, u otherwise - */ - subVec2(u, v, dest) { - if (!dest) { - dest = u; - } - dest[0] = u[0] - v[0]; - dest[1] = u[1] - v[1]; - return dest; - }, - - /** - * Get the geometric mean of the vectors. - * @method geometricMeanVec2 - * @static - * @param {...Array(Number)} vectors Vec2 to mean - * @return {Array(Number)} The geometric mean vec2 - */ - geometricMeanVec2(...vectors) { - const geometricMean = new FloatArrayType(vectors[0]); - for (let i = 1; i < vectors.length; i++) { - geometricMean[0] += vectors[i][0]; - geometricMean[1] += vectors[i][1]; - } - geometricMean[0] /= vectors.length; - geometricMean[1] /= vectors.length; - return geometricMean; - }, - - /** - * Subtracts a scalar value from each element of a four-element vector. - * @method subVec4Scalar - * @static - * @param {Array(Number)} v The vector - * @param {Number} s The scalar - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, v otherwise - */ - subVec4Scalar(v, s, dest) { - if (!dest) { - dest = v; - } - dest[0] = v[0] - s; - dest[1] = v[1] - s; - dest[2] = v[2] - s; - dest[3] = v[3] - s; - return dest; - }, - - /** - * Sets each element of a 4-element vector to a scalar value minus the value of that element. - * @method subScalarVec4 - * @static - * @param {Array(Number)} v The vector - * @param {Number} s The scalar - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, v otherwise - */ - subScalarVec4(v, s, dest) { - if (!dest) { - dest = v; - } - dest[0] = s - v[0]; - dest[1] = s - v[1]; - dest[2] = s - v[2]; - dest[3] = s - v[3]; - return dest; - }, - - /** - * Multiplies one two-element vector by another. - * @method mulVec2 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Second vector - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, u otherwise - */ - mulVec2(u, v, dest) { - if (!dest) { - dest = u; - } - dest[0] = u[0] * v[0]; - dest[1] = u[1] * v[1]; - return dest; - }, - - /** - * Multiplies one three-element vector by another. - * @method mulVec3 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Second vector - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, u otherwise - */ - mulVec3(u, v, dest) { - if (!dest) { - dest = u; - } - dest[0] = u[0] * v[0]; - dest[1] = u[1] * v[1]; - dest[2] = u[2] * v[2]; - return dest; - }, - - /** - * Multiplies one four-element vector by another. - * @method mulVec4 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Second vector - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, u otherwise - */ - mulVec4(u, v, dest) { - if (!dest) { - dest = u; - } - dest[0] = u[0] * v[0]; - dest[1] = u[1] * v[1]; - dest[2] = u[2] * v[2]; - dest[3] = u[3] * v[3]; - return dest; - }, - - /** - * Multiplies each element of a four-element vector by a scalar. - * @method mulVec34calar - * @static - * @param {Array(Number)} v The vector - * @param {Number} s The scalar - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, v otherwise - */ - mulVec4Scalar(v, s, dest) { - if (!dest) { - dest = v; - } - dest[0] = v[0] * s; - dest[1] = v[1] * s; - dest[2] = v[2] * s; - dest[3] = v[3] * s; - return dest; - }, - - /** - * Multiplies each element of a three-element vector by a scalar. - * @method mulVec3Scalar - * @static - * @param {Array(Number)} v The vector - * @param {Number} s The scalar - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, v otherwise - */ - mulVec3Scalar(v, s, dest) { - if (!dest) { - dest = v; - } - dest[0] = v[0] * s; - dest[1] = v[1] * s; - dest[2] = v[2] * s; - return dest; - }, - - /** - * Multiplies each element of a two-element vector by a scalar. - * @method mulVec2Scalar - * @static - * @param {Array(Number)} v The vector - * @param {Number} s The scalar - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, v otherwise - */ - mulVec2Scalar(v, s, dest) { - if (!dest) { - dest = v; - } - dest[0] = v[0] * s; - dest[1] = v[1] * s; - return dest; - }, - - /** - * Divides one three-element vector by another. - * @method divVec3 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Second vector - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, u otherwise - */ - divVec3(u, v, dest) { - if (!dest) { - dest = u; - } - dest[0] = u[0] / v[0]; - dest[1] = u[1] / v[1]; - dest[2] = u[2] / v[2]; - return dest; - }, - - /** - * Divides one four-element vector by another. - * @method divVec4 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Second vector - * @param {Array(Number)} [dest] Destination vector - * @return {Array(Number)} dest if specified, u otherwise - */ - divVec4(u, v, dest) { - if (!dest) { - dest = u; - } - dest[0] = u[0] / v[0]; - dest[1] = u[1] / v[1]; - dest[2] = u[2] / v[2]; - dest[3] = u[3] / v[3]; - return dest; - }, - - /** - * Divides a scalar by a three-element vector, returning a new vector. - * @method divScalarVec3 - * @static - * @param v vec3 - * @param s scalar - * @param dest vec3 - optional destination - * @return [] dest if specified, v otherwise - */ - divScalarVec3(s, v, dest) { - if (!dest) { - dest = v; - } - dest[0] = s / v[0]; - dest[1] = s / v[1]; - dest[2] = s / v[2]; - return dest; - }, - - /** - * Divides a three-element vector by a scalar. - * @method divVec3Scalar - * @static - * @param v vec3 - * @param s scalar - * @param dest vec3 - optional destination - * @return [] dest if specified, v otherwise - */ - divVec3Scalar(v, s, dest) { - if (!dest) { - dest = v; - } - dest[0] = v[0] / s; - dest[1] = v[1] / s; - dest[2] = v[2] / s; - return dest; - }, - - /** - * Divides a four-element vector by a scalar. - * @method divVec4Scalar - * @static - * @param v vec4 - * @param s scalar - * @param dest vec4 - optional destination - * @return [] dest if specified, v otherwise - */ - divVec4Scalar(v, s, dest) { - if (!dest) { - dest = v; - } - dest[0] = v[0] / s; - dest[1] = v[1] / s; - dest[2] = v[2] / s; - dest[3] = v[3] / s; - return dest; - }, - - - /** - * Divides a scalar by a four-element vector, returning a new vector. - * @method divScalarVec4 - * @static - * @param s scalar - * @param v vec4 - * @param dest vec4 - optional destination - * @return [] dest if specified, v otherwise - */ - divScalarVec4(s, v, dest) { - if (!dest) { - dest = v; - } - dest[0] = s / v[0]; - dest[1] = s / v[1]; - dest[2] = s / v[2]; - dest[3] = s / v[3]; - return dest; - }, - - /** - * Returns the dot product of two four-element vectors. - * @method dotVec4 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Second vector - * @return The dot product - */ - dotVec4(u, v) { - return (u[0] * v[0] + u[1] * v[1] + u[2] * v[2] + u[3] * v[3]); - }, - - /** - * Returns the cross product of two four-element vectors. - * @method cross3Vec4 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Second vector - * @return The cross product - */ - cross3Vec4(u, v) { - const u0 = u[0]; - const u1 = u[1]; - const u2 = u[2]; - const v0 = v[0]; - const v1 = v[1]; - const v2 = v[2]; - return [ - u1 * v2 - u2 * v1, - u2 * v0 - u0 * v2, - u0 * v1 - u1 * v0, - 0.0]; - }, - - /** - * Returns the cross product of two three-element vectors. - * @method cross3Vec3 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Second vector - * @return The cross product - */ - cross3Vec3(u, v, dest) { - if (!dest) { - dest = u; - } - const x = u[0]; - const y = u[1]; - const z = u[2]; - const x2 = v[0]; - const y2 = v[1]; - const z2 = v[2]; - dest[0] = y * z2 - z * y2; - dest[1] = z * x2 - x * z2; - dest[2] = x * y2 - y * x2; - return dest; - }, - - - sqLenVec4(v) { // TODO - return math.dotVec4(v, v); - }, - - /** - * Returns the length of a four-element vector. - * @method lenVec4 - * @static - * @param {Array(Number)} v The vector - * @return The length - */ - lenVec4(v) { - return Math.sqrt(math.sqLenVec4(v)); - }, - - /** - * Returns the dot product of two three-element vectors. - * @method dotVec3 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Second vector - * @return The dot product - */ - dotVec3(u, v) { - return (u[0] * v[0] + u[1] * v[1] + u[2] * v[2]); - }, - - /** - * Returns the dot product of two two-element vectors. - * @method dotVec4 - * @static - * @param {Array(Number)} u First vector - * @param {Array(Number)} v Second vector - * @return The dot product - */ - dotVec2(u, v) { - return (u[0] * v[0] + u[1] * v[1]); - }, - - - sqLenVec3(v) { - return math.dotVec3(v, v); - }, - - - sqLenVec2(v) { - return math.dotVec2(v, v); - }, - - /** - * Returns the length of a three-element vector. - * @method lenVec3 - * @static - * @param {Array(Number)} v The vector - * @return The length - */ - lenVec3(v) { - return Math.sqrt(math.sqLenVec3(v)); - }, - - distVec3: ((() => { - const vec = new FloatArrayType(3); - return (v, w) => math.lenVec3(math.subVec3(v, w, vec)); - }))(), - - /** - * Returns the length of a two-element vector. - * @method lenVec2 - * @static - * @param {Array(Number)} v The vector - * @return The length - */ - lenVec2(v) { - return Math.sqrt(math.sqLenVec2(v)); - }, - - distVec2: ((() => { - const vec = new FloatArrayType(2); - return (v, w) => math.lenVec2(math.subVec2(v, w, vec)); - }))(), - - /** - * @method rcpVec3 - * @static - * @param v vec3 - * @param dest vec3 - optional destination - * @return [] dest if specified, v otherwise - * - */ - rcpVec3(v, dest) { - return math.divScalarVec3(1.0, v, dest); - }, - - /** - * Normalizes a four-element vector - * @method normalizeVec4 - * @static - * @param v vec4 - * @param dest vec4 - optional destination - * @return [] dest if specified, v otherwise - * - */ - normalizeVec4(v, dest) { - const f = 1.0 / math.lenVec4(v); - return math.mulVec4Scalar(v, f, dest); - }, - - /** - * Normalizes a three-element vector - * @method normalizeVec4 - * @static - */ - normalizeVec3(v, dest) { - const f = 1.0 / math.lenVec3(v); - return math.mulVec3Scalar(v, f, dest); - }, - - /** - * Normalizes a two-element vector - * @method normalizeVec2 - * @static - */ - normalizeVec2(v, dest) { - const f = 1.0 / math.lenVec2(v); - return math.mulVec2Scalar(v, f, dest); - }, - - /** - * Gets the angle between two vectors - * @method angleVec3 - * @param v - * @param w - * @returns {number} - */ - angleVec3(v, w) { - let theta = math.dotVec3(v, w) / (Math.sqrt(math.sqLenVec3(v) * math.sqLenVec3(w))); - theta = theta < -1 ? -1 : (theta > 1 ? 1 : theta); // Clamp to handle numerical problems - return Math.acos(theta); - }, - - /** - * Creates a three-element vector from the rotation part of a sixteen-element matrix. - * @param m - * @param dest - */ - vec3FromMat4Scale: ((() => { - - const tempVec3 = new FloatArrayType(3); - - return (m, dest) => { - - tempVec3[0] = m[0]; - tempVec3[1] = m[1]; - tempVec3[2] = m[2]; - - dest[0] = math.lenVec3(tempVec3); - - tempVec3[0] = m[4]; - tempVec3[1] = m[5]; - tempVec3[2] = m[6]; - - dest[1] = math.lenVec3(tempVec3); - - tempVec3[0] = m[8]; - tempVec3[1] = m[9]; - tempVec3[2] = m[10]; - - dest[2] = math.lenVec3(tempVec3); - - return dest; - }; - }))(), - - /** - * Converts an n-element vector to a JSON-serializable - * array with values rounded to two decimal places. - */ - vecToArray: ((() => { - function trunc(v) { - return Math.round(v * 100000) / 100000 - } - - return v => { - v = Array.prototype.slice.call(v); - for (let i = 0, len = v.length; i < len; i++) { - v[i] = trunc(v[i]); - } - return v; - }; - }))(), - - /** - * Converts a 3-element vector from an array to an object of the form ````{x:999, y:999, z:999}````. - * @param arr - * @returns {{x: *, y: *, z: *}} - */ - xyzArrayToObject(arr) { - return {"x": arr[0], "y": arr[1], "z": arr[2]}; - }, - - /** - * Converts a 3-element vector object of the form ````{x:999, y:999, z:999}```` to an array. - * @param xyz - * @param [arry] - * @returns {*[]} - */ - xyzObjectToArray(xyz, arry) { - arry = arry || math.vec3(); - arry[0] = xyz.x; - arry[1] = xyz.y; - arry[2] = xyz.z; - return arry; - }, - - /** - * Duplicates a 4x4 identity matrix. - * @method dupMat4 - * @static - */ - dupMat4(m) { - return m.slice(0, 16); - }, - - /** - * Extracts a 3x3 matrix from a 4x4 matrix. - * @method mat4To3 - * @static - */ - mat4To3(m) { - return [ - m[0], m[1], m[2], - m[4], m[5], m[6], - m[8], m[9], m[10] - ]; - }, - - /** - * Returns a 4x4 matrix with each element set to the given scalar value. - * @method m4s - * @static - */ - m4s(s) { - return [ - s, s, s, s, - s, s, s, s, - s, s, s, s, - s, s, s, s - ]; - }, - - /** - * Returns a 4x4 matrix with each element set to zero. - * @method setMat4ToZeroes - * @static - */ - setMat4ToZeroes() { - return math.m4s(0.0); - }, - - /** - * Returns a 4x4 matrix with each element set to 1.0. - * @method setMat4ToOnes - * @static - */ - setMat4ToOnes() { - return math.m4s(1.0); - }, - - /** - * Returns a 4x4 matrix with each element set to 1.0. - * @method setMat4ToOnes - * @static - */ - diagonalMat4v(v) { - return new FloatArrayType([ - v[0], 0.0, 0.0, 0.0, - 0.0, v[1], 0.0, 0.0, - 0.0, 0.0, v[2], 0.0, - 0.0, 0.0, 0.0, v[3] - ]); - }, - - /** - * Returns a 4x4 matrix with diagonal elements set to the given vector. - * @method diagonalMat4c - * @static - */ - diagonalMat4c(x, y, z, w) { - return math.diagonalMat4v([x, y, z, w]); - }, - - /** - * Returns a 4x4 matrix with diagonal elements set to the given scalar. - * @method diagonalMat4s - * @static - */ - diagonalMat4s(s) { - return math.diagonalMat4c(s, s, s, s); - }, - - /** - * Returns a 4x4 identity matrix. - * @method identityMat4 - * @static - */ - identityMat4(mat = new FloatArrayType(16)) { - mat[0] = 1.0; - mat[1] = 0.0; - mat[2] = 0.0; - mat[3] = 0.0; - - mat[4] = 0.0; - mat[5] = 1.0; - mat[6] = 0.0; - mat[7] = 0.0; - - mat[8] = 0.0; - mat[9] = 0.0; - mat[10] = 1.0; - mat[11] = 0.0; - - mat[12] = 0.0; - mat[13] = 0.0; - mat[14] = 0.0; - mat[15] = 1.0; - - return mat; - }, - - /** - * Returns a 3x3 identity matrix. - * @method identityMat3 - * @static - */ - identityMat3(mat = new FloatArrayType(9)) { - mat[0] = 1.0; - mat[1] = 0.0; - mat[2] = 0.0; - - mat[3] = 0.0; - mat[4] = 1.0; - mat[5] = 0.0; - - mat[6] = 0.0; - mat[7] = 0.0; - mat[8] = 1.0; - - return mat; - }, - - /** - * Tests if the given 4x4 matrix is the identity matrix. - * @method isIdentityMat4 - * @static - */ - isIdentityMat4(m) { - if (m[0] !== 1.0 || m[1] !== 0.0 || m[2] !== 0.0 || m[3] !== 0.0 || - m[4] !== 0.0 || m[5] !== 1.0 || m[6] !== 0.0 || m[7] !== 0.0 || - m[8] !== 0.0 || m[9] !== 0.0 || m[10] !== 1.0 || m[11] !== 0.0 || - m[12] !== 0.0 || m[13] !== 0.0 || m[14] !== 0.0 || m[15] !== 1.0) { - return false; - } - return true; - }, - - /** - * Negates the given 4x4 matrix. - * @method negateMat4 - * @static - */ - negateMat4(m, dest) { - if (!dest) { - dest = m; - } - dest[0] = -m[0]; - dest[1] = -m[1]; - dest[2] = -m[2]; - dest[3] = -m[3]; - dest[4] = -m[4]; - dest[5] = -m[5]; - dest[6] = -m[6]; - dest[7] = -m[7]; - dest[8] = -m[8]; - dest[9] = -m[9]; - dest[10] = -m[10]; - dest[11] = -m[11]; - dest[12] = -m[12]; - dest[13] = -m[13]; - dest[14] = -m[14]; - dest[15] = -m[15]; - return dest; - }, - - /** - * Adds the given 4x4 matrices together. - * @method addMat4 - * @static - */ - addMat4(a, b, dest) { - if (!dest) { - dest = a; - } - dest[0] = a[0] + b[0]; - dest[1] = a[1] + b[1]; - dest[2] = a[2] + b[2]; - dest[3] = a[3] + b[3]; - dest[4] = a[4] + b[4]; - dest[5] = a[5] + b[5]; - dest[6] = a[6] + b[6]; - dest[7] = a[7] + b[7]; - dest[8] = a[8] + b[8]; - dest[9] = a[9] + b[9]; - dest[10] = a[10] + b[10]; - dest[11] = a[11] + b[11]; - dest[12] = a[12] + b[12]; - dest[13] = a[13] + b[13]; - dest[14] = a[14] + b[14]; - dest[15] = a[15] + b[15]; - return dest; - }, - - /** - * Adds the given scalar to each element of the given 4x4 matrix. - * @method addMat4Scalar - * @static - */ - addMat4Scalar(m, s, dest) { - if (!dest) { - dest = m; - } - dest[0] = m[0] + s; - dest[1] = m[1] + s; - dest[2] = m[2] + s; - dest[3] = m[3] + s; - dest[4] = m[4] + s; - dest[5] = m[5] + s; - dest[6] = m[6] + s; - dest[7] = m[7] + s; - dest[8] = m[8] + s; - dest[9] = m[9] + s; - dest[10] = m[10] + s; - dest[11] = m[11] + s; - dest[12] = m[12] + s; - dest[13] = m[13] + s; - dest[14] = m[14] + s; - dest[15] = m[15] + s; - return dest; - }, - - /** - * Adds the given scalar to each element of the given 4x4 matrix. - * @method addScalarMat4 - * @static - */ - addScalarMat4(s, m, dest) { - return math.addMat4Scalar(m, s, dest); - }, - - /** - * Subtracts the second 4x4 matrix from the first. - * @method subMat4 - * @static - */ - subMat4(a, b, dest) { - if (!dest) { - dest = a; - } - dest[0] = a[0] - b[0]; - dest[1] = a[1] - b[1]; - dest[2] = a[2] - b[2]; - dest[3] = a[3] - b[3]; - dest[4] = a[4] - b[4]; - dest[5] = a[5] - b[5]; - dest[6] = a[6] - b[6]; - dest[7] = a[7] - b[7]; - dest[8] = a[8] - b[8]; - dest[9] = a[9] - b[9]; - dest[10] = a[10] - b[10]; - dest[11] = a[11] - b[11]; - dest[12] = a[12] - b[12]; - dest[13] = a[13] - b[13]; - dest[14] = a[14] - b[14]; - dest[15] = a[15] - b[15]; - return dest; - }, - - /** - * Subtracts the given scalar from each element of the given 4x4 matrix. - * @method subMat4Scalar - * @static - */ - subMat4Scalar(m, s, dest) { - if (!dest) { - dest = m; - } - dest[0] = m[0] - s; - dest[1] = m[1] - s; - dest[2] = m[2] - s; - dest[3] = m[3] - s; - dest[4] = m[4] - s; - dest[5] = m[5] - s; - dest[6] = m[6] - s; - dest[7] = m[7] - s; - dest[8] = m[8] - s; - dest[9] = m[9] - s; - dest[10] = m[10] - s; - dest[11] = m[11] - s; - dest[12] = m[12] - s; - dest[13] = m[13] - s; - dest[14] = m[14] - s; - dest[15] = m[15] - s; - return dest; - }, - - /** - * Subtracts the given scalar from each element of the given 4x4 matrix. - * @method subScalarMat4 - * @static - */ - subScalarMat4(s, m, dest) { - if (!dest) { - dest = m; - } - dest[0] = s - m[0]; - dest[1] = s - m[1]; - dest[2] = s - m[2]; - dest[3] = s - m[3]; - dest[4] = s - m[4]; - dest[5] = s - m[5]; - dest[6] = s - m[6]; - dest[7] = s - m[7]; - dest[8] = s - m[8]; - dest[9] = s - m[9]; - dest[10] = s - m[10]; - dest[11] = s - m[11]; - dest[12] = s - m[12]; - dest[13] = s - m[13]; - dest[14] = s - m[14]; - dest[15] = s - m[15]; - return dest; - }, - - /** - * Multiplies the two given 4x4 matrix by each other. - * @method mulMat4 - * @static - */ - mulMat4(a, b, dest) { - if (!dest) { - dest = a; - } - - // Cache the matrix values (makes for huge speed increases!) - const a00 = a[0]; - - const a01 = a[1]; - const a02 = a[2]; - const a03 = a[3]; - const a10 = a[4]; - const a11 = a[5]; - const a12 = a[6]; - const a13 = a[7]; - const a20 = a[8]; - const a21 = a[9]; - const a22 = a[10]; - const a23 = a[11]; - const a30 = a[12]; - const a31 = a[13]; - const a32 = a[14]; - const a33 = a[15]; - const b00 = b[0]; - const b01 = b[1]; - const b02 = b[2]; - const b03 = b[3]; - const b10 = b[4]; - const b11 = b[5]; - const b12 = b[6]; - const b13 = b[7]; - const b20 = b[8]; - const b21 = b[9]; - const b22 = b[10]; - const b23 = b[11]; - const b30 = b[12]; - const b31 = b[13]; - const b32 = b[14]; - const b33 = b[15]; - - dest[0] = b00 * a00 + b01 * a10 + b02 * a20 + b03 * a30; - dest[1] = b00 * a01 + b01 * a11 + b02 * a21 + b03 * a31; - dest[2] = b00 * a02 + b01 * a12 + b02 * a22 + b03 * a32; - dest[3] = b00 * a03 + b01 * a13 + b02 * a23 + b03 * a33; - dest[4] = b10 * a00 + b11 * a10 + b12 * a20 + b13 * a30; - dest[5] = b10 * a01 + b11 * a11 + b12 * a21 + b13 * a31; - dest[6] = b10 * a02 + b11 * a12 + b12 * a22 + b13 * a32; - dest[7] = b10 * a03 + b11 * a13 + b12 * a23 + b13 * a33; - dest[8] = b20 * a00 + b21 * a10 + b22 * a20 + b23 * a30; - dest[9] = b20 * a01 + b21 * a11 + b22 * a21 + b23 * a31; - dest[10] = b20 * a02 + b21 * a12 + b22 * a22 + b23 * a32; - dest[11] = b20 * a03 + b21 * a13 + b22 * a23 + b23 * a33; - dest[12] = b30 * a00 + b31 * a10 + b32 * a20 + b33 * a30; - dest[13] = b30 * a01 + b31 * a11 + b32 * a21 + b33 * a31; - dest[14] = b30 * a02 + b31 * a12 + b32 * a22 + b33 * a32; - dest[15] = b30 * a03 + b31 * a13 + b32 * a23 + b33 * a33; - - return dest; - }, - - /** - * Multiplies the two given 3x3 matrices by each other. - * @method mulMat4 - * @static - */ - mulMat3(a, b, dest) { - if (!dest) { - dest = new FloatArrayType(9); - } - - const a11 = a[0]; - const a12 = a[3]; - const a13 = a[6]; - const a21 = a[1]; - const a22 = a[4]; - const a23 = a[7]; - const a31 = a[2]; - const a32 = a[5]; - const a33 = a[8]; - const b11 = b[0]; - const b12 = b[3]; - const b13 = b[6]; - const b21 = b[1]; - const b22 = b[4]; - const b23 = b[7]; - const b31 = b[2]; - const b32 = b[5]; - const b33 = b[8]; - - dest[0] = a11 * b11 + a12 * b21 + a13 * b31; - dest[3] = a11 * b12 + a12 * b22 + a13 * b32; - dest[6] = a11 * b13 + a12 * b23 + a13 * b33; - - dest[1] = a21 * b11 + a22 * b21 + a23 * b31; - dest[4] = a21 * b12 + a22 * b22 + a23 * b32; - dest[7] = a21 * b13 + a22 * b23 + a23 * b33; - - dest[2] = a31 * b11 + a32 * b21 + a33 * b31; - dest[5] = a31 * b12 + a32 * b22 + a33 * b32; - dest[8] = a31 * b13 + a32 * b23 + a33 * b33; - - return dest; - }, - - /** - * Multiplies each element of the given 4x4 matrix by the given scalar. - * @method mulMat4Scalar - * @static - */ - mulMat4Scalar(m, s, dest) { - if (!dest) { - dest = m; - } - dest[0] = m[0] * s; - dest[1] = m[1] * s; - dest[2] = m[2] * s; - dest[3] = m[3] * s; - dest[4] = m[4] * s; - dest[5] = m[5] * s; - dest[6] = m[6] * s; - dest[7] = m[7] * s; - dest[8] = m[8] * s; - dest[9] = m[9] * s; - dest[10] = m[10] * s; - dest[11] = m[11] * s; - dest[12] = m[12] * s; - dest[13] = m[13] * s; - dest[14] = m[14] * s; - dest[15] = m[15] * s; - return dest; - }, - - /** - * Multiplies the given 4x4 matrix by the given four-element vector. - * @method mulMat4v4 - * @static - */ - mulMat4v4(m, v, dest = math.vec4()) { - const v0 = v[0]; - const v1 = v[1]; - const v2 = v[2]; - const v3 = v[3]; - dest[0] = m[0] * v0 + m[4] * v1 + m[8] * v2 + m[12] * v3; - dest[1] = m[1] * v0 + m[5] * v1 + m[9] * v2 + m[13] * v3; - dest[2] = m[2] * v0 + m[6] * v1 + m[10] * v2 + m[14] * v3; - dest[3] = m[3] * v0 + m[7] * v1 + m[11] * v2 + m[15] * v3; - return dest; - }, - - /** - * Transposes the given 4x4 matrix. - * @method transposeMat4 - * @static - */ - transposeMat4(mat, dest) { - // If we are transposing ourselves we can skip a few steps but have to cache some values - const m4 = mat[4]; - - const m14 = mat[14]; - const m8 = mat[8]; - const m13 = mat[13]; - const m12 = mat[12]; - const m9 = mat[9]; - if (!dest || mat === dest) { - const a01 = mat[1]; - const a02 = mat[2]; - const a03 = mat[3]; - const a12 = mat[6]; - const a13 = mat[7]; - const a23 = mat[11]; - mat[1] = m4; - mat[2] = m8; - mat[3] = m12; - mat[4] = a01; - mat[6] = m9; - mat[7] = m13; - mat[8] = a02; - mat[9] = a12; - mat[11] = m14; - mat[12] = a03; - mat[13] = a13; - mat[14] = a23; - return mat; - } - dest[0] = mat[0]; - dest[1] = m4; - dest[2] = m8; - dest[3] = m12; - dest[4] = mat[1]; - dest[5] = mat[5]; - dest[6] = m9; - dest[7] = m13; - dest[8] = mat[2]; - dest[9] = mat[6]; - dest[10] = mat[10]; - dest[11] = m14; - dest[12] = mat[3]; - dest[13] = mat[7]; - dest[14] = mat[11]; - dest[15] = mat[15]; - return dest; - }, - - /** - * Transposes the given 3x3 matrix. - * - * @method transposeMat3 - * @static - */ - transposeMat3(mat, dest) { - if (dest === mat) { - const a01 = mat[1]; - const a02 = mat[2]; - const a12 = mat[5]; - dest[1] = mat[3]; - dest[2] = mat[6]; - dest[3] = a01; - dest[5] = mat[7]; - dest[6] = a02; - dest[7] = a12; - } else { - dest[0] = mat[0]; - dest[1] = mat[3]; - dest[2] = mat[6]; - dest[3] = mat[1]; - dest[4] = mat[4]; - dest[5] = mat[7]; - dest[6] = mat[2]; - dest[7] = mat[5]; - dest[8] = mat[8]; - } - return dest; - }, - - /** - * Returns the determinant of the given 4x4 matrix. - * @method determinantMat4 - * @static - */ - determinantMat4(mat) { - // Cache the matrix values (makes for huge speed increases!) - const a00 = mat[0]; - - const a01 = mat[1]; - const a02 = mat[2]; - const a03 = mat[3]; - const a10 = mat[4]; - const a11 = mat[5]; - const a12 = mat[6]; - const a13 = mat[7]; - const a20 = mat[8]; - const a21 = mat[9]; - const a22 = mat[10]; - const a23 = mat[11]; - const a30 = mat[12]; - const a31 = mat[13]; - const a32 = mat[14]; - const a33 = mat[15]; - return a30 * a21 * a12 * a03 - a20 * a31 * a12 * a03 - a30 * a11 * a22 * a03 + a10 * a31 * a22 * a03 + - a20 * a11 * a32 * a03 - a10 * a21 * a32 * a03 - a30 * a21 * a02 * a13 + a20 * a31 * a02 * a13 + - a30 * a01 * a22 * a13 - a00 * a31 * a22 * a13 - a20 * a01 * a32 * a13 + a00 * a21 * a32 * a13 + - a30 * a11 * a02 * a23 - a10 * a31 * a02 * a23 - a30 * a01 * a12 * a23 + a00 * a31 * a12 * a23 + - a10 * a01 * a32 * a23 - a00 * a11 * a32 * a23 - a20 * a11 * a02 * a33 + a10 * a21 * a02 * a33 + - a20 * a01 * a12 * a33 - a00 * a21 * a12 * a33 - a10 * a01 * a22 * a33 + a00 * a11 * a22 * a33; - }, - - /** - * Returns the inverse of the given 4x4 matrix. - * @method inverseMat4 - * @static - */ - inverseMat4(mat, dest) { - if (!dest) { - dest = mat; - } - - // Cache the matrix values (makes for huge speed increases!) - const a00 = mat[0]; - - const a01 = mat[1]; - const a02 = mat[2]; - const a03 = mat[3]; - const a10 = mat[4]; - const a11 = mat[5]; - const a12 = mat[6]; - const a13 = mat[7]; - const a20 = mat[8]; - const a21 = mat[9]; - const a22 = mat[10]; - const a23 = mat[11]; - const a30 = mat[12]; - const a31 = mat[13]; - const a32 = mat[14]; - const a33 = mat[15]; - const b00 = a00 * a11 - a01 * a10; - const b01 = a00 * a12 - a02 * a10; - const b02 = a00 * a13 - a03 * a10; - const b03 = a01 * a12 - a02 * a11; - const b04 = a01 * a13 - a03 * a11; - const b05 = a02 * a13 - a03 * a12; - const b06 = a20 * a31 - a21 * a30; - const b07 = a20 * a32 - a22 * a30; - const b08 = a20 * a33 - a23 * a30; - const b09 = a21 * a32 - a22 * a31; - const b10 = a21 * a33 - a23 * a31; - const b11 = a22 * a33 - a23 * a32; - - // Calculate the determinant (inlined to avoid double-caching) - const invDet = 1 / (b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06); - - dest[0] = (a11 * b11 - a12 * b10 + a13 * b09) * invDet; - dest[1] = (-a01 * b11 + a02 * b10 - a03 * b09) * invDet; - dest[2] = (a31 * b05 - a32 * b04 + a33 * b03) * invDet; - dest[3] = (-a21 * b05 + a22 * b04 - a23 * b03) * invDet; - dest[4] = (-a10 * b11 + a12 * b08 - a13 * b07) * invDet; - dest[5] = (a00 * b11 - a02 * b08 + a03 * b07) * invDet; - dest[6] = (-a30 * b05 + a32 * b02 - a33 * b01) * invDet; - dest[7] = (a20 * b05 - a22 * b02 + a23 * b01) * invDet; - dest[8] = (a10 * b10 - a11 * b08 + a13 * b06) * invDet; - dest[9] = (-a00 * b10 + a01 * b08 - a03 * b06) * invDet; - dest[10] = (a30 * b04 - a31 * b02 + a33 * b00) * invDet; - dest[11] = (-a20 * b04 + a21 * b02 - a23 * b00) * invDet; - dest[12] = (-a10 * b09 + a11 * b07 - a12 * b06) * invDet; - dest[13] = (a00 * b09 - a01 * b07 + a02 * b06) * invDet; - dest[14] = (-a30 * b03 + a31 * b01 - a32 * b00) * invDet; - dest[15] = (a20 * b03 - a21 * b01 + a22 * b00) * invDet; - - return dest; - }, - - /** - * Returns the trace of the given 4x4 matrix. - * @method traceMat4 - * @static - */ - traceMat4(m) { - return (m[0] + m[5] + m[10] + m[15]); - }, - - /** - * Returns 4x4 translation matrix. - * @method translationMat4 - * @static - */ - translationMat4v(v, dest) { - const m = dest || math.identityMat4(); - m[12] = v[0]; - m[13] = v[1]; - m[14] = v[2]; - return m; - }, - - /** - * Returns 3x3 translation matrix. - * @method translationMat3 - * @static - */ - translationMat3v(v, dest) { - const m = dest || math.identityMat3(); - m[6] = v[0]; - m[7] = v[1]; - return m; - }, - - /** - * Returns 4x4 translation matrix. - * @method translationMat4c - * @static - */ - translationMat4c: ((() => { - const xyz = new FloatArrayType(3); - return (x, y, z, dest) => { - xyz[0] = x; - xyz[1] = y; - xyz[2] = z; - return math.translationMat4v(xyz, dest); - }; - }))(), - - /** - * Returns 4x4 translation matrix. - * @method translationMat4s - * @static - */ - translationMat4s(s, dest) { - return math.translationMat4c(s, s, s, dest); - }, - - /** - * Efficiently post-concatenates a translation to the given matrix. - * @param v - * @param m - */ - translateMat4v(xyz, m) { - return math.translateMat4c(xyz[0], xyz[1], xyz[2], m); - }, - - /** - * Efficiently post-concatenates a translation to the given matrix. - * @param x - * @param y - * @param z - * @param m - */ - - translateMat4c(x, y, z, m) { - - const m3 = m[3]; - m[0] += m3 * x; - m[1] += m3 * y; - m[2] += m3 * z; - - const m7 = m[7]; - m[4] += m7 * x; - m[5] += m7 * y; - m[6] += m7 * z; - - const m11 = m[11]; - m[8] += m11 * x; - m[9] += m11 * y; - m[10] += m11 * z; - - const m15 = m[15]; - m[12] += m15 * x; - m[13] += m15 * y; - m[14] += m15 * z; - - return m; - }, - - /** - * Creates a new matrix that replaces the translation in the rightmost column of the given - * affine matrix with the given translation. - * @param m - * @param translation - * @param dest - * @returns {*} - */ - setMat4Translation(m, translation, dest) { - - dest[0] = m[0]; - dest[1] = m[1]; - dest[2] = m[2]; - dest[3] = m[3]; - - dest[4] = m[4]; - dest[5] = m[5]; - dest[6] = m[6]; - dest[7] = m[7]; - - dest[8] = m[8]; - dest[9] = m[9]; - dest[10] = m[10]; - dest[11] = m[11]; - - dest[12] = translation[0]; - dest[13] = translation[1]; - dest[14] = translation[2]; - dest[15] = m[15]; - - return dest; - }, - - /** - * Returns 4x4 rotation matrix. - * @method rotationMat4v - * @static - */ - rotationMat4v(anglerad, axis, m) { - const ax = math.normalizeVec4([axis[0], axis[1], axis[2], 0.0], []); - const s = Math.sin(anglerad); - const c = Math.cos(anglerad); - const q = 1.0 - c; - - const x = ax[0]; - const y = ax[1]; - const z = ax[2]; - - let xy; - let yz; - let zx; - let xs; - let ys; - let zs; - - //xx = x * x; used once - //yy = y * y; used once - //zz = z * z; used once - xy = x * y; - yz = y * z; - zx = z * x; - xs = x * s; - ys = y * s; - zs = z * s; - - m = m || math.mat4(); - - m[0] = (q * x * x) + c; - m[1] = (q * xy) + zs; - m[2] = (q * zx) - ys; - m[3] = 0.0; - - m[4] = (q * xy) - zs; - m[5] = (q * y * y) + c; - m[6] = (q * yz) + xs; - m[7] = 0.0; - - m[8] = (q * zx) + ys; - m[9] = (q * yz) - xs; - m[10] = (q * z * z) + c; - m[11] = 0.0; - - m[12] = 0.0; - m[13] = 0.0; - m[14] = 0.0; - m[15] = 1.0; - - return m; - }, - - /** - * Returns 4x4 rotation matrix. - * @method rotationMat4c - * @static - */ - rotationMat4c(anglerad, x, y, z, mat) { - return math.rotationMat4v(anglerad, [x, y, z], mat); - }, - - /** - * Returns 4x4 scale matrix. - * @method scalingMat4v - * @static - */ - scalingMat4v(v, m = math.identityMat4()) { - m[0] = v[0]; - m[5] = v[1]; - m[10] = v[2]; - return m; - }, - - /** - * Returns 3x3 scale matrix. - * @method scalingMat3v - * @static - */ - scalingMat3v(v, m = math.identityMat3()) { - m[0] = v[0]; - m[4] = v[1]; - return m; - }, - - /** - * Returns 4x4 scale matrix. - * @method scalingMat4c - * @static - */ - scalingMat4c: ((() => { - const xyz = new FloatArrayType(3); - return (x, y, z, dest) => { - xyz[0] = x; - xyz[1] = y; - xyz[2] = z; - return math.scalingMat4v(xyz, dest); - }; - }))(), - - /** - * Efficiently post-concatenates a scaling to the given matrix. - * @method scaleMat4c - * @param x - * @param y - * @param z - * @param m - */ - scaleMat4c(x, y, z, m) { - - m[0] *= x; - m[4] *= y; - m[8] *= z; - - m[1] *= x; - m[5] *= y; - m[9] *= z; - - m[2] *= x; - m[6] *= y; - m[10] *= z; - - m[3] *= x; - m[7] *= y; - m[11] *= z; - return m; - }, - - /** - * Efficiently post-concatenates a scaling to the given matrix. - * @method scaleMat4c - * @param xyz - * @param m - */ - scaleMat4v(xyz, m) { - - const x = xyz[0]; - const y = xyz[1]; - const z = xyz[2]; - - m[0] *= x; - m[4] *= y; - m[8] *= z; - m[1] *= x; - m[5] *= y; - m[9] *= z; - m[2] *= x; - m[6] *= y; - m[10] *= z; - m[3] *= x; - m[7] *= y; - m[11] *= z; - - return m; - }, - - /** - * Returns 4x4 scale matrix. - * @method scalingMat4s - * @static - */ - scalingMat4s(s) { - return math.scalingMat4c(s, s, s); - }, - - /** - * Creates a matrix from a quaternion rotation and vector translation - * - * @param {Number[]} q Rotation quaternion - * @param {Number[]} v Translation vector - * @param {Number[]} dest Destination matrix - * @returns {Number[]} dest - */ - rotationTranslationMat4(q, v, dest = math.mat4()) { - const x = q[0]; - const y = q[1]; - const z = q[2]; - const w = q[3]; - - const x2 = x + x; - const y2 = y + y; - const z2 = z + z; - const xx = x * x2; - const xy = x * y2; - const xz = x * z2; - const yy = y * y2; - const yz = y * z2; - const zz = z * z2; - const wx = w * x2; - const wy = w * y2; - const wz = w * z2; - - dest[0] = 1 - (yy + zz); - dest[1] = xy + wz; - dest[2] = xz - wy; - dest[3] = 0; - dest[4] = xy - wz; - dest[5] = 1 - (xx + zz); - dest[6] = yz + wx; - dest[7] = 0; - dest[8] = xz + wy; - dest[9] = yz - wx; - dest[10] = 1 - (xx + yy); - dest[11] = 0; - dest[12] = v[0]; - dest[13] = v[1]; - dest[14] = v[2]; - dest[15] = 1; - - return dest; - }, - - /** - * Gets Euler angles from a 4x4 matrix. - * - * @param {Number[]} mat The 4x4 matrix. - * @param {String} order Desired Euler angle order: "XYZ", "YXZ", "ZXY" etc. - * @param {Number[]} [dest] Destination Euler angles, created by default. - * @returns {Number[]} The Euler angles (in degrees). - */ - mat4ToEuler(mat, order, dest = math.vec4()) { - const clamp = math.clamp; - - // Assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled) - - const m11 = mat[0]; - - const m12 = mat[4]; - const m13 = mat[8]; - const m21 = mat[1]; - const m22 = mat[5]; - const m23 = mat[9]; - const m31 = mat[2]; - const m32 = mat[6]; - const m33 = mat[10]; - - if (order === 'XYZ') { - - dest[1] = Math.asin(clamp(m13, -1, 1)); - - if (Math.abs(m13) < 0.99999) { - dest[0] = Math.atan2(-m23, m33); - dest[2] = Math.atan2(-m12, m11); - } else { - dest[0] = Math.atan2(m32, m22); - dest[2] = 0; - - } - - } else if (order === 'YXZ') { - - dest[0] = Math.asin(-clamp(m23, -1, 1)); - - if (Math.abs(m23) < 0.99999) { - dest[1] = Math.atan2(m13, m33); - dest[2] = Math.atan2(m21, m22); - } else { - dest[1] = Math.atan2(-m31, m11); - dest[2] = 0; - } - - } else if (order === 'ZXY') { - - dest[0] = Math.asin(clamp(m32, -1, 1)); - - if (Math.abs(m32) < 0.99999) { - dest[1] = Math.atan2(-m31, m33); - dest[2] = Math.atan2(-m12, m22); - } else { - dest[1] = 0; - dest[2] = Math.atan2(m21, m11); - } - - } else if (order === 'ZYX') { - - dest[1] = Math.asin(-clamp(m31, -1, 1)); - - if (Math.abs(m31) < 0.99999) { - dest[0] = Math.atan2(m32, m33); - dest[2] = Math.atan2(m21, m11); - } else { - dest[0] = 0; - dest[2] = Math.atan2(-m12, m22); - } - - } else if (order === 'YZX') { - - dest[2] = Math.asin(clamp(m21, -1, 1)); - - if (Math.abs(m21) < 0.99999) { - dest[0] = Math.atan2(-m23, m22); - dest[1] = Math.atan2(-m31, m11); - } else { - dest[0] = 0; - dest[1] = Math.atan2(m13, m33); - } - - } else if (order === 'XZY') { - - dest[2] = Math.asin(-clamp(m12, -1, 1)); - - if (Math.abs(m12) < 0.99999) { - dest[0] = Math.atan2(m32, m22); - dest[1] = Math.atan2(m13, m11); - } else { - dest[0] = Math.atan2(-m23, m33); - dest[1] = 0; - } - } - - dest[0] *= math.RADTODEG; - dest[1] *= math.RADTODEG; - dest[2] *= math.RADTODEG; - - return dest; - }, - - composeMat4(position, quaternion, scale, mat = math.mat4()) { - math.quaternionToRotationMat4(quaternion, mat); - math.scaleMat4v(scale, mat); - math.translateMat4v(position, mat); - - return mat; - }, - - decomposeMat4: (() => { - - const vec = new FloatArrayType(3); - const matrix = new FloatArrayType(16); - - return function decompose(mat, position, quaternion, scale) { - - vec[0] = mat[0]; - vec[1] = mat[1]; - vec[2] = mat[2]; - - let sx = math.lenVec3(vec); - - vec[0] = mat[4]; - vec[1] = mat[5]; - vec[2] = mat[6]; - - const sy = math.lenVec3(vec); - - vec[0] = mat[8]; - vec[1] = mat[9]; - vec[2] = mat[10]; - - const sz = math.lenVec3(vec); - - // if determine is negative, we need to invert one scale - const det = math.determinantMat4(mat); - - if (det < 0) { - sx = -sx; - } - - position[0] = mat[12]; - position[1] = mat[13]; - position[2] = mat[14]; - - // scale the rotation part - matrix.set(mat); - - const invSX = 1 / sx; - const invSY = 1 / sy; - const invSZ = 1 / sz; - - matrix[0] *= invSX; - matrix[1] *= invSX; - matrix[2] *= invSX; - - matrix[4] *= invSY; - matrix[5] *= invSY; - matrix[6] *= invSY; - - matrix[8] *= invSZ; - matrix[9] *= invSZ; - matrix[10] *= invSZ; - - math.mat4ToQuaternion(matrix, quaternion); - - scale[0] = sx; - scale[1] = sy; - scale[2] = sz; - - return this; - - }; - - })(), - - /** @private */ - getColMat4(mat, c) { - const i = c * 4; - return [mat[i], mat[i + 1], mat[i + 2], mat[i + 3]]; - }, - - /** @private */ - setRowMat4(mat, r, v) { - mat[r] = v[0]; - mat[r + 4] = v[1]; - mat[r + 8] = v[2]; - mat[r + 12] = v[3]; - }, - - /** - * Returns a 4x4 'lookat' viewing transform matrix. - * @method lookAtMat4v - * @param pos vec3 position of the viewer - * @param target vec3 point the viewer is looking at - * @param up vec3 pointing "up" - * @param dest mat4 Optional, mat4 matrix will be written into - * - * @return {mat4} dest if specified, a new mat4 otherwise - */ - lookAtMat4v(pos, target, up, dest) { - if (!dest) { - dest = math.mat4(); - } - - const posx = pos[0]; - const posy = pos[1]; - const posz = pos[2]; - const upx = up[0]; - const upy = up[1]; - const upz = up[2]; - const targetx = target[0]; - const targety = target[1]; - const targetz = target[2]; - - if (posx === targetx && posy === targety && posz === targetz) { - return math.identityMat4(); - } - - let z0; - let z1; - let z2; - let x0; - let x1; - let x2; - let y0; - let y1; - let y2; - let len; - - //vec3.direction(eye, center, z); - z0 = posx - targetx; - z1 = posy - targety; - z2 = posz - targetz; - - // normalize (no check needed for 0 because of early return) - len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2); - z0 *= len; - z1 *= len; - z2 *= len; - - //vec3.normalize(vec3.cross(up, z, x)); - x0 = upy * z2 - upz * z1; - x1 = upz * z0 - upx * z2; - x2 = upx * z1 - upy * z0; - len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2); - if (!len) { - x0 = 0; - x1 = 0; - x2 = 0; - } else { - len = 1 / len; - x0 *= len; - x1 *= len; - x2 *= len; - } - - //vec3.normalize(vec3.cross(z, x, y)); - y0 = z1 * x2 - z2 * x1; - y1 = z2 * x0 - z0 * x2; - y2 = z0 * x1 - z1 * x0; - - len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2); - if (!len) { - y0 = 0; - y1 = 0; - y2 = 0; - } else { - len = 1 / len; - y0 *= len; - y1 *= len; - y2 *= len; - } - - dest[0] = x0; - dest[1] = y0; - dest[2] = z0; - dest[3] = 0; - dest[4] = x1; - dest[5] = y1; - dest[6] = z1; - dest[7] = 0; - dest[8] = x2; - dest[9] = y2; - dest[10] = z2; - dest[11] = 0; - dest[12] = -(x0 * posx + x1 * posy + x2 * posz); - dest[13] = -(y0 * posx + y1 * posy + y2 * posz); - dest[14] = -(z0 * posx + z1 * posy + z2 * posz); - dest[15] = 1; - - return dest; - }, - - /** - * Returns a 4x4 'lookat' viewing transform matrix. - * @method lookAtMat4c - * @static - */ - lookAtMat4c(posx, posy, posz, targetx, targety, targetz, upx, upy, upz) { - return math.lookAtMat4v([posx, posy, posz], [targetx, targety, targetz], [upx, upy, upz], []); - }, - - /** - * Returns a 4x4 orthographic projection matrix. - * @method orthoMat4c - * @static - */ - orthoMat4c(left, right, bottom, top, near, far, dest) { - if (!dest) { - dest = math.mat4(); - } - const rl = (right - left); - const tb = (top - bottom); - const fn = (far - near); - - dest[0] = 2.0 / rl; - dest[1] = 0.0; - dest[2] = 0.0; - dest[3] = 0.0; - - dest[4] = 0.0; - dest[5] = 2.0 / tb; - dest[6] = 0.0; - dest[7] = 0.0; - - dest[8] = 0.0; - dest[9] = 0.0; - dest[10] = -2.0 / fn; - dest[11] = 0.0; - - dest[12] = -(left + right) / rl; - dest[13] = -(top + bottom) / tb; - dest[14] = -(far + near) / fn; - dest[15] = 1.0; - - return dest; - }, - - /** - * Returns a 4x4 perspective projection matrix. - * @method frustumMat4v - * @static - */ - frustumMat4v(fmin, fmax, m) { - if (!m) { - m = math.mat4(); - } - - const fmin4 = [fmin[0], fmin[1], fmin[2], 0.0]; - const fmax4 = [fmax[0], fmax[1], fmax[2], 0.0]; - - math.addVec4(fmax4, fmin4, tempMat1); - math.subVec4(fmax4, fmin4, tempMat2); - - const t = 2.0 * fmin4[2]; - - const tempMat20 = tempMat2[0]; - const tempMat21 = tempMat2[1]; - const tempMat22 = tempMat2[2]; - - m[0] = t / tempMat20; - m[1] = 0.0; - m[2] = 0.0; - m[3] = 0.0; - - m[4] = 0.0; - m[5] = t / tempMat21; - m[6] = 0.0; - m[7] = 0.0; - - m[8] = tempMat1[0] / tempMat20; - m[9] = tempMat1[1] / tempMat21; - m[10] = -tempMat1[2] / tempMat22; - m[11] = -1.0; - - m[12] = 0.0; - m[13] = 0.0; - m[14] = -t * fmax4[2] / tempMat22; - m[15] = 0.0; - - return m; - }, - - /** - * Returns a 4x4 perspective projection matrix. - * @method frustumMat4v - * @static - */ - frustumMat4(left, right, bottom, top, near, far, dest) { - if (!dest) { - dest = math.mat4(); - } - const rl = (right - left); - const tb = (top - bottom); - const fn = (far - near); - dest[0] = (near * 2) / rl; - dest[1] = 0; - dest[2] = 0; - dest[3] = 0; - dest[4] = 0; - dest[5] = (near * 2) / tb; - dest[6] = 0; - dest[7] = 0; - dest[8] = (right + left) / rl; - dest[9] = (top + bottom) / tb; - dest[10] = -(far + near) / fn; - dest[11] = -1; - dest[12] = 0; - dest[13] = 0; - dest[14] = -(far * near * 2) / fn; - dest[15] = 0; - return dest; - }, - - /** - * Returns a 4x4 perspective projection matrix. - * @method perspectiveMat4v - * @static - */ - perspectiveMat4(fovyrad, aspectratio, znear, zfar, m) { - const pmin = []; - const pmax = []; - - pmin[2] = znear; - pmax[2] = zfar; - - pmax[1] = pmin[2] * Math.tan(fovyrad / 2.0); - pmin[1] = -pmax[1]; - - pmax[0] = pmax[1] * aspectratio; - pmin[0] = -pmax[0]; - - return math.frustumMat4v(pmin, pmax, m); - }, - - /** - * Returns true if the two 4x4 matrices are the same. - * @param m1 - * @param m2 - * @returns {Boolean} - */ - compareMat4(m1, m2) { - return m1[0] === m2[0] && - m1[1] === m2[1] && - m1[2] === m2[2] && - m1[3] === m2[3] && - m1[4] === m2[4] && - m1[5] === m2[5] && - m1[6] === m2[6] && - m1[7] === m2[7] && - m1[8] === m2[8] && - m1[9] === m2[9] && - m1[10] === m2[10] && - m1[11] === m2[11] && - m1[12] === m2[12] && - m1[13] === m2[13] && - m1[14] === m2[14] && - m1[15] === m2[15]; - }, - - /** - * Transforms a three-element position by a 4x4 matrix. - * @method transformPoint3 - * @static - */ - transformPoint3(m, p, dest = math.vec3()) { - - const x = p[0]; - const y = p[1]; - const z = p[2]; - - dest[0] = (m[0] * x) + (m[4] * y) + (m[8] * z) + m[12]; - dest[1] = (m[1] * x) + (m[5] * y) + (m[9] * z) + m[13]; - dest[2] = (m[2] * x) + (m[6] * y) + (m[10] * z) + m[14]; - - return dest; - }, - - /** - * Transforms a homogeneous coordinate by a 4x4 matrix. - * @method transformPoint3 - * @static - */ - transformPoint4(m, v, dest = math.vec4()) { - dest[0] = m[0] * v[0] + m[4] * v[1] + m[8] * v[2] + m[12] * v[3]; - dest[1] = m[1] * v[0] + m[5] * v[1] + m[9] * v[2] + m[13] * v[3]; - dest[2] = m[2] * v[0] + m[6] * v[1] + m[10] * v[2] + m[14] * v[3]; - dest[3] = m[3] * v[0] + m[7] * v[1] + m[11] * v[2] + m[15] * v[3]; - - return dest; - }, - - - /** - * Transforms an array of three-element positions by a 4x4 matrix. - * @method transformPoints3 - * @static - */ - transformPoints3(m, points, points2) { - const result = points2 || []; - const len = points.length; - let p0; - let p1; - let p2; - let pi; - - // cache values - const m0 = m[0]; - - const m1 = m[1]; - const m2 = m[2]; - const m3 = m[3]; - const m4 = m[4]; - const m5 = m[5]; - const m6 = m[6]; - const m7 = m[7]; - const m8 = m[8]; - const m9 = m[9]; - const m10 = m[10]; - const m11 = m[11]; - const m12 = m[12]; - const m13 = m[13]; - const m14 = m[14]; - const m15 = m[15]; - - let r; - - for (let i = 0; i < len; ++i) { - - // cache values - pi = points[i]; - - p0 = pi[0]; - p1 = pi[1]; - p2 = pi[2]; - - r = result[i] || (result[i] = [0, 0, 0]); - - r[0] = (m0 * p0) + (m4 * p1) + (m8 * p2) + m12; - r[1] = (m1 * p0) + (m5 * p1) + (m9 * p2) + m13; - r[2] = (m2 * p0) + (m6 * p1) + (m10 * p2) + m14; - r[3] = (m3 * p0) + (m7 * p1) + (m11 * p2) + m15; - } - - result.length = len; - - return result; - }, - - /** - * Transforms an array of positions by a 4x4 matrix. - * @method transformPositions3 - * @static - */ - transformPositions3(m, p, p2 = p) { - let i; - const len = p.length; - - let x; - let y; - let z; - - const m0 = m[0]; - const m1 = m[1]; - const m2 = m[2]; - m[3]; - const m4 = m[4]; - const m5 = m[5]; - const m6 = m[6]; - m[7]; - const m8 = m[8]; - const m9 = m[9]; - const m10 = m[10]; - m[11]; - const m12 = m[12]; - const m13 = m[13]; - const m14 = m[14]; - m[15]; - - for (i = 0; i < len; i += 3) { - - x = p[i + 0]; - y = p[i + 1]; - z = p[i + 2]; - - p2[i + 0] = (m0 * x) + (m4 * y) + (m8 * z) + m12; - p2[i + 1] = (m1 * x) + (m5 * y) + (m9 * z) + m13; - p2[i + 2] = (m2 * x) + (m6 * y) + (m10 * z) + m14; - } - - return p2; - }, - - /** - * Transforms an array of positions by a 4x4 matrix. - * @method transformPositions4 - * @static - */ - transformPositions4(m, p, p2 = p) { - let i; - const len = p.length; - - let x; - let y; - let z; - - const m0 = m[0]; - const m1 = m[1]; - const m2 = m[2]; - const m3 = m[3]; - const m4 = m[4]; - const m5 = m[5]; - const m6 = m[6]; - const m7 = m[7]; - const m8 = m[8]; - const m9 = m[9]; - const m10 = m[10]; - const m11 = m[11]; - const m12 = m[12]; - const m13 = m[13]; - const m14 = m[14]; - const m15 = m[15]; - - for (i = 0; i < len; i += 4) { - - x = p[i + 0]; - y = p[i + 1]; - z = p[i + 2]; - - p2[i + 0] = (m0 * x) + (m4 * y) + (m8 * z) + m12; - p2[i + 1] = (m1 * x) + (m5 * y) + (m9 * z) + m13; - p2[i + 2] = (m2 * x) + (m6 * y) + (m10 * z) + m14; - p2[i + 3] = (m3 * x) + (m7 * y) + (m11 * z) + m15; - } - - return p2; - }, - - /** - * Transforms a three-element vector by a 4x4 matrix. - * @method transformVec3 - * @static - */ - transformVec3(m, v, dest) { - const v0 = v[0]; - const v1 = v[1]; - const v2 = v[2]; - dest = dest || this.vec3(); - dest[0] = (m[0] * v0) + (m[4] * v1) + (m[8] * v2); - dest[1] = (m[1] * v0) + (m[5] * v1) + (m[9] * v2); - dest[2] = (m[2] * v0) + (m[6] * v1) + (m[10] * v2); - return dest; - }, - - /** - * Transforms a four-element vector by a 4x4 matrix. - * @method transformVec4 - * @static - */ - transformVec4(m, v, dest) { - const v0 = v[0]; - const v1 = v[1]; - const v2 = v[2]; - const v3 = v[3]; - dest = dest || math.vec4(); - dest[0] = m[0] * v0 + m[4] * v1 + m[8] * v2 + m[12] * v3; - dest[1] = m[1] * v0 + m[5] * v1 + m[9] * v2 + m[13] * v3; - dest[2] = m[2] * v0 + m[6] * v1 + m[10] * v2 + m[14] * v3; - dest[3] = m[3] * v0 + m[7] * v1 + m[11] * v2 + m[15] * v3; - return dest; - }, - - /** - * Rotate a 2D vector around a center point. - * - * @param a - * @param center - * @param angle - * @returns {math} - */ - rotateVec2(a, center, angle, dest = a) { - const c = Math.cos(angle); - const s = Math.sin(angle); - const x = a[0] - center[0]; - const y = a[1] - center[1]; - dest[0] = x * c - y * s + center[0]; - dest[1] = x * s + y * c + center[1]; - return a; - }, - - /** - * Rotate a 3D vector around the x-axis - * - * @method rotateVec3X - * @param {Number[]} a The vec3 point to rotate - * @param {Number[]} b The origin of the rotation - * @param {Number} c The angle of rotation - * @param {Number[]} dest The receiving vec3 - * @returns {Number[]} dest - * @static - */ - rotateVec3X(a, b, c, dest) { - const p = []; - const r = []; - - //Translate point to the origin - p[0] = a[0] - b[0]; - p[1] = a[1] - b[1]; - p[2] = a[2] - b[2]; - - //perform rotation - r[0] = p[0]; - r[1] = p[1] * Math.cos(c) - p[2] * Math.sin(c); - r[2] = p[1] * Math.sin(c) + p[2] * Math.cos(c); - - //translate to correct position - dest[0] = r[0] + b[0]; - dest[1] = r[1] + b[1]; - dest[2] = r[2] + b[2]; - - return dest; - }, - - /** - * Rotate a 3D vector around the y-axis - * - * @method rotateVec3Y - * @param {Number[]} a The vec3 point to rotate - * @param {Number[]} b The origin of the rotation - * @param {Number} c The angle of rotation - * @param {Number[]} dest The receiving vec3 - * @returns {Number[]} dest - * @static - */ - rotateVec3Y(a, b, c, dest) { - const p = []; - const r = []; - - //Translate point to the origin - p[0] = a[0] - b[0]; - p[1] = a[1] - b[1]; - p[2] = a[2] - b[2]; - - //perform rotation - r[0] = p[2] * Math.sin(c) + p[0] * Math.cos(c); - r[1] = p[1]; - r[2] = p[2] * Math.cos(c) - p[0] * Math.sin(c); - - //translate to correct position - dest[0] = r[0] + b[0]; - dest[1] = r[1] + b[1]; - dest[2] = r[2] + b[2]; - - return dest; - }, - - /** - * Rotate a 3D vector around the z-axis - * - * @method rotateVec3Z - * @param {Number[]} a The vec3 point to rotate - * @param {Number[]} b The origin of the rotation - * @param {Number} c The angle of rotation - * @param {Number[]} dest The receiving vec3 - * @returns {Number[]} dest - * @static - */ - rotateVec3Z(a, b, c, dest) { - const p = []; - const r = []; - - //Translate point to the origin - p[0] = a[0] - b[0]; - p[1] = a[1] - b[1]; - p[2] = a[2] - b[2]; - - //perform rotation - r[0] = p[0] * Math.cos(c) - p[1] * Math.sin(c); - r[1] = p[0] * Math.sin(c) + p[1] * Math.cos(c); - r[2] = p[2]; - - //translate to correct position - dest[0] = r[0] + b[0]; - dest[1] = r[1] + b[1]; - dest[2] = r[2] + b[2]; - - return dest; - }, - - /** - * Transforms a four-element vector by a 4x4 projection matrix. - * - * @method projectVec4 - * @param {Number[]} p 3D View-space coordinate - * @param {Number[]} q 2D Projected coordinate - * @returns {Number[]} 2D Projected coordinate - * @static - */ - projectVec4(p, q) { - const f = 1.0 / p[3]; - q = q || math.vec2(); - q[0] = p[0] * f; - q[1] = p[1] * f; - return q; - }, - - /** - * Unprojects a three-element vector. - * - * @method unprojectVec3 - * @param {Number[]} p 3D Projected coordinate - * @param {Number[]} viewMat View matrix - * @returns {Number[]} projMat Projection matrix - * @static - */ - unprojectVec3: ((() => { - const mat = new FloatArrayType(16); - const mat2 = new FloatArrayType(16); - const mat3 = new FloatArrayType(16); - return function (p, viewMat, projMat, q) { - return this.transformVec3(this.mulMat4(this.inverseMat4(viewMat, mat), this.inverseMat4(projMat, mat2), mat3), p, q) - }; - }))(), - - /** - * Linearly interpolates between two 3D vectors. - * @method lerpVec3 - * @static - */ - lerpVec3(t, t1, t2, p1, p2, dest) { - const result = dest || math.vec3(); - const f = (t - t1) / (t2 - t1); - result[0] = p1[0] + (f * (p2[0] - p1[0])); - result[1] = p1[1] + (f * (p2[1] - p1[1])); - result[2] = p1[2] + (f * (p2[2] - p1[2])); - return result; - }, - - /** - * Linearly interpolates between two 4x4 matrices. - * @method lerpMat4 - * @static - */ - lerpMat4(t, t1, t2, m1, m2, dest) { - const result = dest || math.mat4(); - const f = (t - t1) / (t2 - t1); - result[0] = m1[0] + (f * (m2[0] - m1[0])); - result[1] = m1[1] + (f * (m2[1] - m1[1])); - result[2] = m1[2] + (f * (m2[2] - m1[2])); - result[3] = m1[3] + (f * (m2[3] - m1[3])); - result[4] = m1[4] + (f * (m2[4] - m1[4])); - result[5] = m1[5] + (f * (m2[5] - m1[5])); - result[6] = m1[6] + (f * (m2[6] - m1[6])); - result[7] = m1[7] + (f * (m2[7] - m1[7])); - result[8] = m1[8] + (f * (m2[8] - m1[8])); - result[9] = m1[9] + (f * (m2[9] - m1[9])); - result[10] = m1[10] + (f * (m2[10] - m1[10])); - result[11] = m1[11] + (f * (m2[11] - m1[11])); - result[12] = m1[12] + (f * (m2[12] - m1[12])); - result[13] = m1[13] + (f * (m2[13] - m1[13])); - result[14] = m1[14] + (f * (m2[14] - m1[14])); - result[15] = m1[15] + (f * (m2[15] - m1[15])); - return result; - }, - - - /** - * Flattens a two-dimensional array into a one-dimensional array. - * - * @method flatten - * @static - * @param {Array of Arrays} a A 2D array - * @returns Flattened 1D array - */ - flatten(a) { - - const result = []; - - let i; - let leni; - let j; - let lenj; - let item; - - for (i = 0, leni = a.length; i < leni; i++) { - item = a[i]; - for (j = 0, lenj = item.length; j < lenj; j++) { - result.push(item[j]); - } - } - - return result; - }, - - - identityQuaternion(dest = math.vec4()) { - dest[0] = 0.0; - dest[1] = 0.0; - dest[2] = 0.0; - dest[3] = 1.0; - return dest; - }, - - /** - * Initializes a quaternion from Euler angles. - * - * @param {Number[]} euler The Euler angles (in degrees). - * @param {String} order Euler angle order: "XYZ", "YXZ", "ZXY" etc. - * @param {Number[]} [dest] Destination quaternion, created by default. - * @returns {Number[]} The quaternion. - */ - eulerToQuaternion(euler, order, dest = math.vec4()) { - // http://www.mathworks.com/matlabcentral/fileexchange/ - // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/ - // content/SpinCalc.m - - const a = (euler[0] * math.DEGTORAD) / 2; - const b = (euler[1] * math.DEGTORAD) / 2; - const c = (euler[2] * math.DEGTORAD) / 2; - - const c1 = Math.cos(a); - const c2 = Math.cos(b); - const c3 = Math.cos(c); - const s1 = Math.sin(a); - const s2 = Math.sin(b); - const s3 = Math.sin(c); - - if (order === 'XYZ') { - - dest[0] = s1 * c2 * c3 + c1 * s2 * s3; - dest[1] = c1 * s2 * c3 - s1 * c2 * s3; - dest[2] = c1 * c2 * s3 + s1 * s2 * c3; - dest[3] = c1 * c2 * c3 - s1 * s2 * s3; - - } else if (order === 'YXZ') { - - dest[0] = s1 * c2 * c3 + c1 * s2 * s3; - dest[1] = c1 * s2 * c3 - s1 * c2 * s3; - dest[2] = c1 * c2 * s3 - s1 * s2 * c3; - dest[3] = c1 * c2 * c3 + s1 * s2 * s3; - - } else if (order === 'ZXY') { - - dest[0] = s1 * c2 * c3 - c1 * s2 * s3; - dest[1] = c1 * s2 * c3 + s1 * c2 * s3; - dest[2] = c1 * c2 * s3 + s1 * s2 * c3; - dest[3] = c1 * c2 * c3 - s1 * s2 * s3; - - } else if (order === 'ZYX') { - - dest[0] = s1 * c2 * c3 - c1 * s2 * s3; - dest[1] = c1 * s2 * c3 + s1 * c2 * s3; - dest[2] = c1 * c2 * s3 - s1 * s2 * c3; - dest[3] = c1 * c2 * c3 + s1 * s2 * s3; - - } else if (order === 'YZX') { - - dest[0] = s1 * c2 * c3 + c1 * s2 * s3; - dest[1] = c1 * s2 * c3 + s1 * c2 * s3; - dest[2] = c1 * c2 * s3 - s1 * s2 * c3; - dest[3] = c1 * c2 * c3 - s1 * s2 * s3; - - } else if (order === 'XZY') { - - dest[0] = s1 * c2 * c3 - c1 * s2 * s3; - dest[1] = c1 * s2 * c3 - s1 * c2 * s3; - dest[2] = c1 * c2 * s3 + s1 * s2 * c3; - dest[3] = c1 * c2 * c3 + s1 * s2 * s3; - } - - return dest; - }, - - mat4ToQuaternion(m, dest = math.vec4()) { - // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm - - // Assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled) - - const m11 = m[0]; - const m12 = m[4]; - const m13 = m[8]; - const m21 = m[1]; - const m22 = m[5]; - const m23 = m[9]; - const m31 = m[2]; - const m32 = m[6]; - const m33 = m[10]; - let s; - - const trace = m11 + m22 + m33; - - if (trace > 0) { - - s = 0.5 / Math.sqrt(trace + 1.0); - - dest[3] = 0.25 / s; - dest[0] = (m32 - m23) * s; - dest[1] = (m13 - m31) * s; - dest[2] = (m21 - m12) * s; - - } else if (m11 > m22 && m11 > m33) { - - s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33); - - dest[3] = (m32 - m23) / s; - dest[0] = 0.25 * s; - dest[1] = (m12 + m21) / s; - dest[2] = (m13 + m31) / s; - - } else if (m22 > m33) { - - s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33); - - dest[3] = (m13 - m31) / s; - dest[0] = (m12 + m21) / s; - dest[1] = 0.25 * s; - dest[2] = (m23 + m32) / s; - - } else { - - s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22); - - dest[3] = (m21 - m12) / s; - dest[0] = (m13 + m31) / s; - dest[1] = (m23 + m32) / s; - dest[2] = 0.25 * s; - } - - return dest; - }, - - vec3PairToQuaternion(u, v, dest = math.vec4()) { - const norm_u_norm_v = Math.sqrt(math.dotVec3(u, u) * math.dotVec3(v, v)); - let real_part = norm_u_norm_v + math.dotVec3(u, v); - - if (real_part < 0.00000001 * norm_u_norm_v) { - - // If u and v are exactly opposite, rotate 180 degrees - // around an arbitrary orthogonal axis. Axis normalisation - // can happen later, when we normalise the quaternion. - - real_part = 0.0; - - if (Math.abs(u[0]) > Math.abs(u[2])) { - - dest[0] = -u[1]; - dest[1] = u[0]; - dest[2] = 0; - - } else { - dest[0] = 0; - dest[1] = -u[2]; - dest[2] = u[1]; - } - - } else { - - // Otherwise, build quaternion the standard way. - math.cross3Vec3(u, v, dest); - } - - dest[3] = real_part; - - return math.normalizeQuaternion(dest); - }, - - angleAxisToQuaternion(angleAxis, dest = math.vec4()) { - const halfAngle = angleAxis[3] / 2.0; - const fsin = Math.sin(halfAngle); - dest[0] = fsin * angleAxis[0]; - dest[1] = fsin * angleAxis[1]; - dest[2] = fsin * angleAxis[2]; - dest[3] = Math.cos(halfAngle); - return dest; - }, - - quaternionToEuler: ((() => { - const mat = new FloatArrayType(16); - return (q, order, dest) => { - dest = dest || math.vec3(); - math.quaternionToRotationMat4(q, mat); - math.mat4ToEuler(mat, order, dest); - return dest; - }; - }))(), - - mulQuaternions(p, q, dest = math.vec4()) { - const p0 = p[0]; - const p1 = p[1]; - const p2 = p[2]; - const p3 = p[3]; - const q0 = q[0]; - const q1 = q[1]; - const q2 = q[2]; - const q3 = q[3]; - dest[0] = p3 * q0 + p0 * q3 + p1 * q2 - p2 * q1; - dest[1] = p3 * q1 + p1 * q3 + p2 * q0 - p0 * q2; - dest[2] = p3 * q2 + p2 * q3 + p0 * q1 - p1 * q0; - dest[3] = p3 * q3 - p0 * q0 - p1 * q1 - p2 * q2; - return dest; - }, - - vec3ApplyQuaternion(q, vec, dest = math.vec3()) { - const x = vec[0]; - const y = vec[1]; - const z = vec[2]; - - const qx = q[0]; - const qy = q[1]; - const qz = q[2]; - const qw = q[3]; - - // calculate quat * vector - - const ix = qw * x + qy * z - qz * y; - const iy = qw * y + qz * x - qx * z; - const iz = qw * z + qx * y - qy * x; - const iw = -qx * x - qy * y - qz * z; - - // calculate result * inverse quat - - dest[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; - dest[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; - dest[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; - - return dest; - }, - - quaternionToMat4(q, dest) { - - dest = math.identityMat4(dest); - - const q0 = q[0]; //x - const q1 = q[1]; //y - const q2 = q[2]; //z - const q3 = q[3]; //w - - const tx = 2.0 * q0; - const ty = 2.0 * q1; - const tz = 2.0 * q2; - - const twx = tx * q3; - const twy = ty * q3; - const twz = tz * q3; - - const txx = tx * q0; - const txy = ty * q0; - const txz = tz * q0; - - const tyy = ty * q1; - const tyz = tz * q1; - const tzz = tz * q2; - - dest[0] = 1.0 - (tyy + tzz); - dest[1] = txy + twz; - dest[2] = txz - twy; - - dest[4] = txy - twz; - dest[5] = 1.0 - (txx + tzz); - dest[6] = tyz + twx; - - dest[8] = txz + twy; - dest[9] = tyz - twx; - - dest[10] = 1.0 - (txx + tyy); - - return dest; - }, - - quaternionToRotationMat4(q, m) { - const x = q[0]; - const y = q[1]; - const z = q[2]; - const w = q[3]; - - const x2 = x + x; - const y2 = y + y; - const z2 = z + z; - const xx = x * x2; - const xy = x * y2; - const xz = x * z2; - const yy = y * y2; - const yz = y * z2; - const zz = z * z2; - const wx = w * x2; - const wy = w * y2; - const wz = w * z2; - - m[0] = 1 - (yy + zz); - m[4] = xy - wz; - m[8] = xz + wy; - - m[1] = xy + wz; - m[5] = 1 - (xx + zz); - m[9] = yz - wx; - - m[2] = xz - wy; - m[6] = yz + wx; - m[10] = 1 - (xx + yy); - - // last column - m[3] = 0; - m[7] = 0; - m[11] = 0; - - // bottom row - m[12] = 0; - m[13] = 0; - m[14] = 0; - m[15] = 1; - - return m; - }, - - normalizeQuaternion(q, dest = q) { - const len = math.lenVec4([q[0], q[1], q[2], q[3]]); - dest[0] = q[0] / len; - dest[1] = q[1] / len; - dest[2] = q[2] / len; - dest[3] = q[3] / len; - return dest; - }, - - conjugateQuaternion(q, dest = q) { - dest[0] = -q[0]; - dest[1] = -q[1]; - dest[2] = -q[2]; - dest[3] = q[3]; - return dest; - }, - - inverseQuaternion(q, dest) { - return math.normalizeQuaternion(math.conjugateQuaternion(q, dest)); - }, - - quaternionToAngleAxis(q, angleAxis = math.vec4()) { - q = math.normalizeQuaternion(q, tempVec4$4); - const q3 = q[3]; - const angle = 2 * Math.acos(q3); - const s = Math.sqrt(1 - q3 * q3); - if (s < 0.001) { // test to avoid divide by zero, s is always positive due to sqrt - angleAxis[0] = q[0]; - angleAxis[1] = q[1]; - angleAxis[2] = q[2]; - } else { - angleAxis[0] = q[0] / s; - angleAxis[1] = q[1] / s; - angleAxis[2] = q[2] / s; - } - angleAxis[3] = angle; // * 57.295779579; - return angleAxis; - }, - - //------------------------------------------------------------------------------------------------------------------ - // Boundaries - //------------------------------------------------------------------------------------------------------------------ - - /** - * Returns a new, uninitialized 3D axis-aligned bounding box. - * - * @private - */ - AABB3(values) { - return new FloatArrayType(values || 6); - }, - - /** - * Returns a new, uninitialized 2D axis-aligned bounding box. - * - * @private - */ - AABB2(values) { - return new FloatArrayType(values || 4); - }, - - /** - * Returns a new, uninitialized 3D oriented bounding box (OBB). - * - * @private - */ - OBB3(values) { - return new FloatArrayType(values || 32); - }, - - /** - * Returns a new, uninitialized 2D oriented bounding box (OBB). - * - * @private - */ - OBB2(values) { - return new FloatArrayType(values || 16); - }, - - /** Returns a new 3D bounding sphere */ - Sphere3(x, y, z, r) { - return new FloatArrayType([x, y, z, r]); - }, - - /** - * Transforms an OBB3 by a 4x4 matrix. - * - * @private - */ - transformOBB3(m, p, p2 = p) { - let i; - const len = p.length; - - let x; - let y; - let z; - - const m0 = m[0]; - const m1 = m[1]; - const m2 = m[2]; - const m3 = m[3]; - const m4 = m[4]; - const m5 = m[5]; - const m6 = m[6]; - const m7 = m[7]; - const m8 = m[8]; - const m9 = m[9]; - const m10 = m[10]; - const m11 = m[11]; - const m12 = m[12]; - const m13 = m[13]; - const m14 = m[14]; - const m15 = m[15]; - - for (i = 0; i < len; i += 4) { - - x = p[i + 0]; - y = p[i + 1]; - z = p[i + 2]; - - p2[i + 0] = (m0 * x) + (m4 * y) + (m8 * z) + m12; - p2[i + 1] = (m1 * x) + (m5 * y) + (m9 * z) + m13; - p2[i + 2] = (m2 * x) + (m6 * y) + (m10 * z) + m14; - p2[i + 3] = (m3 * x) + (m7 * y) + (m11 * z) + m15; - } - - return p2; - }, - - /** Returns true if the first AABB contains the second AABB. - * @param aabb1 - * @param aabb2 - * @returns {Boolean} - */ - containsAABB3: function (aabb1, aabb2) { - const result = ( - aabb1[0] <= aabb2[0] && aabb2[3] <= aabb1[3] && - aabb1[1] <= aabb2[1] && aabb2[4] <= aabb1[4] && - aabb1[2] <= aabb2[2] && aabb2[5] <= aabb1[5]); - return result; - }, - - - /** - * Gets the diagonal size of an AABB3 given as minima and maxima. - * - * @private - */ - getAABB3Diag: ((() => { - - const min = new FloatArrayType(3); - const max = new FloatArrayType(3); - const tempVec3 = new FloatArrayType(3); - - return aabb => { - - min[0] = aabb[0]; - min[1] = aabb[1]; - min[2] = aabb[2]; - - max[0] = aabb[3]; - max[1] = aabb[4]; - max[2] = aabb[5]; - - math.subVec3(max, min, tempVec3); - - return Math.abs(math.lenVec3(tempVec3)); - }; - }))(), - - /** - * Get a diagonal boundary size that is symmetrical about the given point. - * - * @private - */ - getAABB3DiagPoint: ((() => { - - const min = new FloatArrayType(3); - const max = new FloatArrayType(3); - const tempVec3 = new FloatArrayType(3); - - return (aabb, p) => { - - min[0] = aabb[0]; - min[1] = aabb[1]; - min[2] = aabb[2]; - - max[0] = aabb[3]; - max[1] = aabb[4]; - max[2] = aabb[5]; - - const diagVec = math.subVec3(max, min, tempVec3); - - const xneg = p[0] - aabb[0]; - const xpos = aabb[3] - p[0]; - const yneg = p[1] - aabb[1]; - const ypos = aabb[4] - p[1]; - const zneg = p[2] - aabb[2]; - const zpos = aabb[5] - p[2]; - - diagVec[0] += (xneg > xpos) ? xneg : xpos; - diagVec[1] += (yneg > ypos) ? yneg : ypos; - diagVec[2] += (zneg > zpos) ? zneg : zpos; - - return Math.abs(math.lenVec3(diagVec)); - }; - }))(), - - /** - * Gets the area of an AABB. - * - * @private - */ - getAABB3Area(aabb) { - const width = (aabb[3] - aabb[0]); - const height = (aabb[4] - aabb[1]); - const depth = (aabb[5] - aabb[2]); - return (width * height * depth); - }, - - /** - * Gets the center of an AABB. - * - * @private - */ - getAABB3Center(aabb, dest) { - const r = dest || math.vec3(); - - r[0] = (aabb[0] + aabb[3]) / 2; - r[1] = (aabb[1] + aabb[4]) / 2; - r[2] = (aabb[2] + aabb[5]) / 2; - - return r; - }, - - /** - * Gets the center of a 2D AABB. - * - * @private - */ - getAABB2Center(aabb, dest) { - const r = dest || math.vec2(); - - r[0] = (aabb[2] + aabb[0]) / 2; - r[1] = (aabb[3] + aabb[1]) / 2; - - return r; - }, - - /** - * Collapses a 3D axis-aligned boundary, ready to expand to fit 3D points. - * Creates new AABB if none supplied. - * - * @private - */ - collapseAABB3(aabb = math.AABB3()) { - aabb[0] = math.MAX_DOUBLE; - aabb[1] = math.MAX_DOUBLE; - aabb[2] = math.MAX_DOUBLE; - aabb[3] = math.MIN_DOUBLE; - aabb[4] = math.MIN_DOUBLE; - aabb[5] = math.MIN_DOUBLE; - - return aabb; - }, - - /** - * Converts an axis-aligned 3D boundary into an oriented boundary consisting of - * an array of eight 3D positions, one for each corner of the boundary. - * - * @private - */ - AABB3ToOBB3(aabb, obb = math.OBB3()) { - obb[0] = aabb[0]; - obb[1] = aabb[1]; - obb[2] = aabb[2]; - obb[3] = 1; - - obb[4] = aabb[3]; - obb[5] = aabb[1]; - obb[6] = aabb[2]; - obb[7] = 1; - - obb[8] = aabb[3]; - obb[9] = aabb[4]; - obb[10] = aabb[2]; - obb[11] = 1; - - obb[12] = aabb[0]; - obb[13] = aabb[4]; - obb[14] = aabb[2]; - obb[15] = 1; - - obb[16] = aabb[0]; - obb[17] = aabb[1]; - obb[18] = aabb[5]; - obb[19] = 1; - - obb[20] = aabb[3]; - obb[21] = aabb[1]; - obb[22] = aabb[5]; - obb[23] = 1; - - obb[24] = aabb[3]; - obb[25] = aabb[4]; - obb[26] = aabb[5]; - obb[27] = 1; - - obb[28] = aabb[0]; - obb[29] = aabb[4]; - obb[30] = aabb[5]; - obb[31] = 1; - - return obb; - }, - - /** - * Finds the minimum axis-aligned 3D boundary enclosing the homogeneous 3D points (x,y,z,w) given in a flattened array. - * - * @private - */ - positions3ToAABB3: ((() => { - - const p = new FloatArrayType(3); - - return (positions, aabb, positionsDecodeMatrix) => { - aabb = aabb || math.AABB3(); - - let xmin = math.MAX_DOUBLE; - let ymin = math.MAX_DOUBLE; - let zmin = math.MAX_DOUBLE; - let xmax = math.MIN_DOUBLE; - let ymax = math.MIN_DOUBLE; - let zmax = math.MIN_DOUBLE; - - let x; - let y; - let z; - - for (let i = 0, len = positions.length; i < len; i += 3) { - - if (positionsDecodeMatrix) { - - p[0] = positions[i + 0]; - p[1] = positions[i + 1]; - p[2] = positions[i + 2]; - - math.decompressPosition(p, positionsDecodeMatrix, p); - - x = p[0]; - y = p[1]; - z = p[2]; - - } else { - x = positions[i + 0]; - y = positions[i + 1]; - z = positions[i + 2]; - } - - if (x < xmin) { - xmin = x; - } - - if (y < ymin) { - ymin = y; - } - - if (z < zmin) { - zmin = z; - } - - if (x > xmax) { - xmax = x; - } - - if (y > ymax) { - ymax = y; - } - - if (z > zmax) { - zmax = z; - } - } - - aabb[0] = xmin; - aabb[1] = ymin; - aabb[2] = zmin; - aabb[3] = xmax; - aabb[4] = ymax; - aabb[5] = zmax; - - return aabb; - }; - }))(), - - /** - * Finds the minimum axis-aligned 3D boundary enclosing the homogeneous 3D points (x,y,z,w) given in a flattened array. - * - * @private - */ - OBB3ToAABB3(obb, aabb = math.AABB3()) { - let xmin = math.MAX_DOUBLE; - let ymin = math.MAX_DOUBLE; - let zmin = math.MAX_DOUBLE; - let xmax = math.MIN_DOUBLE; - let ymax = math.MIN_DOUBLE; - let zmax = math.MIN_DOUBLE; - - let x; - let y; - let z; - - for (let i = 0, len = obb.length; i < len; i += 4) { - - x = obb[i + 0]; - y = obb[i + 1]; - z = obb[i + 2]; - - if (x < xmin) { - xmin = x; - } - - if (y < ymin) { - ymin = y; - } - - if (z < zmin) { - zmin = z; - } - - if (x > xmax) { - xmax = x; - } - - if (y > ymax) { - ymax = y; - } - - if (z > zmax) { - zmax = z; - } - } - - aabb[0] = xmin; - aabb[1] = ymin; - aabb[2] = zmin; - aabb[3] = xmax; - aabb[4] = ymax; - aabb[5] = zmax; - - return aabb; - }, - - /** - * Finds the minimum axis-aligned 3D boundary enclosing the given 3D points. - * - * @private - */ - points3ToAABB3(points, aabb = math.AABB3()) { - let xmin = math.MAX_DOUBLE; - let ymin = math.MAX_DOUBLE; - let zmin = math.MAX_DOUBLE; - let xmax = math.MIN_DOUBLE; - let ymax = math.MIN_DOUBLE; - let zmax = math.MIN_DOUBLE; - - let x; - let y; - let z; - - for (let i = 0, len = points.length; i < len; i++) { - - x = points[i][0]; - y = points[i][1]; - z = points[i][2]; - - if (x < xmin) { - xmin = x; - } - - if (y < ymin) { - ymin = y; - } - - if (z < zmin) { - zmin = z; - } - - if (x > xmax) { - xmax = x; - } - - if (y > ymax) { - ymax = y; - } - - if (z > zmax) { - zmax = z; - } - } - - aabb[0] = xmin; - aabb[1] = ymin; - aabb[2] = zmin; - aabb[3] = xmax; - aabb[4] = ymax; - aabb[5] = zmax; - - return aabb; - }, - - /** - * Finds the minimum boundary sphere enclosing the given 3D points. - * - * @private - */ - points3ToSphere3: ((() => { - - const tempVec3 = new FloatArrayType(3); - - return (points, sphere) => { - - sphere = sphere || math.vec4(); - - let x = 0; - let y = 0; - let z = 0; - - let i; - const numPoints = points.length; - - for (i = 0; i < numPoints; i++) { - x += points[i][0]; - y += points[i][1]; - z += points[i][2]; - } - - sphere[0] = x / numPoints; - sphere[1] = y / numPoints; - sphere[2] = z / numPoints; - - let radius = 0; - let dist; - - for (i = 0; i < numPoints; i++) { - - dist = Math.abs(math.lenVec3(math.subVec3(points[i], sphere, tempVec3))); - - if (dist > radius) { - radius = dist; - } - } - - sphere[3] = radius; - - return sphere; - }; - }))(), - - /** - * Finds the minimum boundary sphere enclosing the given 3D positions. - * - * @private - */ - positions3ToSphere3: ((() => { - - const tempVec3a = new FloatArrayType(3); - const tempVec3b = new FloatArrayType(3); - - return (positions, sphere) => { - - sphere = sphere || math.vec4(); - - let x = 0; - let y = 0; - let z = 0; - - let i; - const lenPositions = positions.length; - let radius = 0; - - for (i = 0; i < lenPositions; i += 3) { - x += positions[i]; - y += positions[i + 1]; - z += positions[i + 2]; - } - - const numPositions = lenPositions / 3; - - sphere[0] = x / numPositions; - sphere[1] = y / numPositions; - sphere[2] = z / numPositions; - - let dist; - - for (i = 0; i < lenPositions; i += 3) { - - tempVec3a[0] = positions[i]; - tempVec3a[1] = positions[i + 1]; - tempVec3a[2] = positions[i + 2]; - - dist = Math.abs(math.lenVec3(math.subVec3(tempVec3a, sphere, tempVec3b))); - - if (dist > radius) { - radius = dist; - } - } - - sphere[3] = radius; - - return sphere; - }; - }))(), - - /** - * Finds the minimum boundary sphere enclosing the given 3D points. - * - * @private - */ - OBB3ToSphere3: ((() => { - - const point = new FloatArrayType(3); - const tempVec3 = new FloatArrayType(3); - - return (points, sphere) => { - - sphere = sphere || math.vec4(); - - let x = 0; - let y = 0; - let z = 0; - - let i; - const lenPoints = points.length; - const numPoints = lenPoints / 4; - - for (i = 0; i < lenPoints; i += 4) { - x += points[i + 0]; - y += points[i + 1]; - z += points[i + 2]; - } - - sphere[0] = x / numPoints; - sphere[1] = y / numPoints; - sphere[2] = z / numPoints; - - let radius = 0; - let dist; - - for (i = 0; i < lenPoints; i += 4) { - - point[0] = points[i + 0]; - point[1] = points[i + 1]; - point[2] = points[i + 2]; - - dist = Math.abs(math.lenVec3(math.subVec3(point, sphere, tempVec3))); - - if (dist > radius) { - radius = dist; - } - } - - sphere[3] = radius; - - return sphere; - }; - }))(), - - /** - * Gets the center of a bounding sphere. - * - * @private - */ - getSphere3Center(sphere, dest = math.vec3()) { - dest[0] = sphere[0]; - dest[1] = sphere[1]; - dest[2] = sphere[2]; - - return dest; - }, - - /** - * Gets the 3D center of the given flat array of 3D positions. - * - * @private - */ - getPositionsCenter(positions, center = math.vec3()) { - let xCenter = 0; - let yCenter = 0; - let zCenter = 0; - for (var i = 0, len = positions.length; i < len; i += 3) { - xCenter += positions[i + 0]; - yCenter += positions[i + 1]; - zCenter += positions[i + 2]; - } - const numPositions = positions.length / 3; - center[0] = xCenter / numPositions; - center[1] = yCenter / numPositions; - center[2] = zCenter / numPositions; - return center; - }, - - /** - * Expands the first axis-aligned 3D boundary to enclose the second, if required. - * - * @private - */ - expandAABB3(aabb1, aabb2) { - - if (aabb1[0] > aabb2[0]) { - aabb1[0] = aabb2[0]; - } - - if (aabb1[1] > aabb2[1]) { - aabb1[1] = aabb2[1]; - } - - if (aabb1[2] > aabb2[2]) { - aabb1[2] = aabb2[2]; - } - - if (aabb1[3] < aabb2[3]) { - aabb1[3] = aabb2[3]; - } - - if (aabb1[4] < aabb2[4]) { - aabb1[4] = aabb2[4]; - } - - if (aabb1[5] < aabb2[5]) { - aabb1[5] = aabb2[5]; - } - - return aabb1; - }, - - /** - * Expands an axis-aligned 3D boundary to enclose the given point, if needed. - * - * @private - */ - expandAABB3Point3(aabb, p) { - - if (aabb[0] > p[0]) { - aabb[0] = p[0]; - } - - if (aabb[1] > p[1]) { - aabb[1] = p[1]; - } - - if (aabb[2] > p[2]) { - aabb[2] = p[2]; - } - - if (aabb[3] < p[0]) { - aabb[3] = p[0]; - } - - if (aabb[4] < p[1]) { - aabb[4] = p[1]; - } - - if (aabb[5] < p[2]) { - aabb[5] = p[2]; - } - - return aabb; - }, - - /** - * Expands an axis-aligned 3D boundary to enclose the given points, if needed. - * - * @private - */ - expandAABB3Points3(aabb, positions) { - var x; - var y; - var z; - for (var i = 0, len = positions.length; i < len; i += 3) { - x = positions[i]; - y = positions[i + 1]; - z = positions[i + 2]; - if (aabb[0] > x) { - aabb[0] = x; - } - if (aabb[1] > y) { - aabb[1] = y; - } - if (aabb[2] > z) { - aabb[2] = z; - } - if (aabb[3] < x) { - aabb[3] = x; - } - if (aabb[4] < y) { - aabb[4] = y; - } - if (aabb[5] < z) { - aabb[5] = z; - } - } - return aabb; - }, - - /** - * Collapses a 2D axis-aligned boundary, ready to expand to fit 2D points. - * Creates new AABB if none supplied. - * - * @private - */ - collapseAABB2(aabb = math.AABB2()) { - aabb[0] = math.MAX_DOUBLE; - aabb[1] = math.MAX_DOUBLE; - aabb[2] = math.MIN_DOUBLE; - aabb[3] = math.MIN_DOUBLE; - - return aabb; - }, - - point3AABB3Intersect(aabb, p) { - return aabb[0] > p[0] || aabb[3] < p[0] || aabb[1] > p[1] || aabb[4] < p[1] || aabb[2] > p[2] || aabb[5] < p[2]; - }, - - point3AABB3AbsoluteIntersect(aabb, p) { - return ( - aabb[0] <= p[0] && aabb[3] >= p[0] && - aabb[1] <= p[1] && aabb[4] >= p[1] && - aabb[2] <= p[2] && aabb[5] >= p[2] - ); - }, - - /** - * - * @param dir - * @param constant - * @param aabb - * @returns {number} - */ - planeAABB3Intersect(dir, constant, aabb) { - let min, max; - if (dir[0] > 0) { - min = dir[0] * aabb[0]; - max = dir[0] * aabb[3]; - } else { - min = dir[0] * aabb[3]; - max = dir[0] * aabb[0]; - } - if (dir[1] > 0) { - min += dir[1] * aabb[1]; - max += dir[1] * aabb[4]; - } else { - min += dir[1] * aabb[4]; - max += dir[1] * aabb[1]; - } - if (dir[2] > 0) { - min += dir[2] * aabb[2]; - max += dir[2] * aabb[5]; - } else { - min += dir[2] * aabb[5]; - max += dir[2] * aabb[2]; - } - const outside = (min <= -constant) && (max <= -constant); - if (outside) { - return -1; - } - - const inside = (min >= -constant) && (max >= -constant); - if (inside) { - return 1; - } - - return 0; - }, - - /** - * Finds the minimum 2D projected axis-aligned boundary enclosing the given 3D points. - * - * @private - */ - OBB3ToAABB2(points, aabb = math.AABB2()) { - let xmin = math.MAX_DOUBLE; - let ymin = math.MAX_DOUBLE; - let xmax = math.MIN_DOUBLE; - let ymax = math.MIN_DOUBLE; - - let x; - let y; - let w; - let f; - - for (let i = 0, len = points.length; i < len; i += 4) { - - x = points[i + 0]; - y = points[i + 1]; - w = points[i + 3] || 1.0; - - f = 1.0 / w; - - x *= f; - y *= f; - - if (x < xmin) { - xmin = x; - } - - if (y < ymin) { - ymin = y; - } - - if (x > xmax) { - xmax = x; - } - - if (y > ymax) { - ymax = y; - } - } - - aabb[0] = xmin; - aabb[1] = ymin; - aabb[2] = xmax; - aabb[3] = ymax; - - return aabb; - }, - - /** - * Expands the first axis-aligned 2D boundary to enclose the second, if required. - * - * @private - */ - expandAABB2(aabb1, aabb2) { - - if (aabb1[0] > aabb2[0]) { - aabb1[0] = aabb2[0]; - } - - if (aabb1[1] > aabb2[1]) { - aabb1[1] = aabb2[1]; - } - - if (aabb1[2] < aabb2[2]) { - aabb1[2] = aabb2[2]; - } - - if (aabb1[3] < aabb2[3]) { - aabb1[3] = aabb2[3]; - } - - return aabb1; - }, - - /** - * Expands an axis-aligned 2D boundary to enclose the given point, if required. - * - * @private - */ - expandAABB2Point2(aabb, p) { - - if (aabb[0] > p[0]) { - aabb[0] = p[0]; - } - - if (aabb[1] > p[1]) { - aabb[1] = p[1]; - } - - if (aabb[2] < p[0]) { - aabb[2] = p[0]; - } - - if (aabb[3] < p[1]) { - aabb[3] = p[1]; - } - - return aabb; - }, - - AABB2ToCanvas(aabb, canvasWidth, canvasHeight, aabb2 = aabb) { - const xmin = (aabb[0] + 1.0) * 0.5; - const ymin = (aabb[1] + 1.0) * 0.5; - const xmax = (aabb[2] + 1.0) * 0.5; - const ymax = (aabb[3] + 1.0) * 0.5; - - aabb2[0] = Math.floor(xmin * canvasWidth); - aabb2[1] = canvasHeight - Math.floor(ymax * canvasHeight); - aabb2[2] = Math.floor(xmax * canvasWidth); - aabb2[3] = canvasHeight - Math.floor(ymin * canvasHeight); - - return aabb2; - }, - - //------------------------------------------------------------------------------------------------------------------ - // Curves - //------------------------------------------------------------------------------------------------------------------ - - tangentQuadraticBezier(t, p0, p1, p2) { - return 2 * (1 - t) * (p1 - p0) + 2 * t * (p2 - p1); - }, - - tangentQuadraticBezier3(t, p0, p1, p2, p3) { - return -3 * p0 * (1 - t) * (1 - t) + - 3 * p1 * (1 - t) * (1 - t) - 6 * t * p1 * (1 - t) + - 6 * t * p2 * (1 - t) - 3 * t * t * p2 + - 3 * t * t * p3; - }, - - tangentSpline(t) { - const h00 = 6 * t * t - 6 * t; - const h10 = 3 * t * t - 4 * t + 1; - const h01 = -6 * t * t + 6 * t; - const h11 = 3 * t * t - 2 * t; - return h00 + h10 + h01 + h11; - }, - - catmullRomInterpolate(p0, p1, p2, p3, t) { - 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; - }, - -// Bezier Curve formulii from http://en.wikipedia.org/wiki/B%C3%A9zier_curve - -// Quad Bezier Functions - - b2p0(t, p) { - const k = 1 - t; - return k * k * p; - - }, - - b2p1(t, p) { - return 2 * (1 - t) * t * p; - }, - - b2p2(t, p) { - return t * t * p; - }, - - b2(t, p0, p1, p2) { - return this.b2p0(t, p0) + this.b2p1(t, p1) + this.b2p2(t, p2); - }, - -// Cubic Bezier Functions - - b3p0(t, p) { - const k = 1 - t; - return k * k * k * p; - }, - - b3p1(t, p) { - const k = 1 - t; - return 3 * k * k * t * p; - }, - - b3p2(t, p) { - const k = 1 - t; - return 3 * k * t * t * p; - }, - - b3p3(t, p) { - return t * t * t * p; - }, - - b3(t, p0, p1, p2, p3) { - return this.b3p0(t, p0) + this.b3p1(t, p1) + this.b3p2(t, p2) + this.b3p3(t, p3); - }, - - //------------------------------------------------------------------------------------------------------------------ - // Geometry - //------------------------------------------------------------------------------------------------------------------ - - /** - * Calculates the normal vector of a triangle. - * - * @private - */ - triangleNormal(a, b, c, normal = math.vec3()) { - const p1x = b[0] - a[0]; - const p1y = b[1] - a[1]; - const p1z = b[2] - a[2]; - - const p2x = c[0] - a[0]; - const p2y = c[1] - a[1]; - const p2z = c[2] - a[2]; - - const p3x = p1y * p2z - p1z * p2y; - const p3y = p1z * p2x - p1x * p2z; - const p3z = p1x * p2y - p1y * p2x; - - const mag = Math.sqrt(p3x * p3x + p3y * p3y + p3z * p3z); - if (mag === 0) { - normal[0] = 0; - normal[1] = 0; - normal[2] = 0; - } else { - normal[0] = p3x / mag; - normal[1] = p3y / mag; - normal[2] = p3z / mag; - } - - return normal - }, - - /** - * Finds the intersection of a 3D ray with a 3D triangle. - * - * @private - */ - rayTriangleIntersect: ((() => { - - const tempVec3 = new FloatArrayType(3); - const tempVec3b = new FloatArrayType(3); - const tempVec3c = new FloatArrayType(3); - const tempVec3d = new FloatArrayType(3); - const tempVec3e = new FloatArrayType(3); - - return (origin, dir, a, b, c, isect) => { - - isect = isect || math.vec3(); - - const EPSILON = 0.000001; - - const edge1 = math.subVec3(b, a, tempVec3); - const edge2 = math.subVec3(c, a, tempVec3b); - - const pvec = math.cross3Vec3(dir, edge2, tempVec3c); - const det = math.dotVec3(edge1, pvec); - if (det < EPSILON) { - return null; - } - - const tvec = math.subVec3(origin, a, tempVec3d); - const u = math.dotVec3(tvec, pvec); - if (u < 0 || u > det) { - return null; - } - - const qvec = math.cross3Vec3(tvec, edge1, tempVec3e); - const v = math.dotVec3(dir, qvec); - if (v < 0 || u + v > det) { - return null; - } - - const t = math.dotVec3(edge2, qvec) / det; - isect[0] = origin[0] + t * dir[0]; - isect[1] = origin[1] + t * dir[1]; - isect[2] = origin[2] + t * dir[2]; - - return isect; - }; - }))(), - - /** - * Finds the intersection of a 3D ray with a plane defined by 3 points. - * - * @private - */ - rayPlaneIntersect: ((() => { - - const tempVec3 = new FloatArrayType(3); - const tempVec3b = new FloatArrayType(3); - const tempVec3c = new FloatArrayType(3); - const tempVec3d = new FloatArrayType(3); - - return (origin, dir, a, b, c, isect) => { - - isect = isect || math.vec3(); - - dir = math.normalizeVec3(dir, tempVec3); - - const edge1 = math.subVec3(b, a, tempVec3b); - const edge2 = math.subVec3(c, a, tempVec3c); - - const n = math.cross3Vec3(edge1, edge2, tempVec3d); - math.normalizeVec3(n, n); - - const d = -math.dotVec3(a, n); - - const t = -(math.dotVec3(origin, n) + d) / math.dotVec3(dir, n); - - isect[0] = origin[0] + t * dir[0]; - isect[1] = origin[1] + t * dir[1]; - isect[2] = origin[2] + t * dir[2]; - - return isect; - }; - }))(), - - /** - * Gets barycentric coordinates from cartesian coordinates within a triangle. - * Gets barycentric coordinates from cartesian coordinates within a triangle. - * - * @private - */ - cartesianToBarycentric: ((() => { - - const tempVec3 = new FloatArrayType(3); - const tempVec3b = new FloatArrayType(3); - const tempVec3c = new FloatArrayType(3); - - return (cartesian, a, b, c, dest) => { - - const v0 = math.subVec3(c, a, tempVec3); - const v1 = math.subVec3(b, a, tempVec3b); - const v2 = math.subVec3(cartesian, a, tempVec3c); - - const dot00 = math.dotVec3(v0, v0); - const dot01 = math.dotVec3(v0, v1); - const dot02 = math.dotVec3(v0, v2); - const dot11 = math.dotVec3(v1, v1); - const dot12 = math.dotVec3(v1, v2); - - const denom = (dot00 * dot11 - dot01 * dot01); - - // Colinear or singular triangle - - if (denom === 0) { - - // Arbitrary location outside of triangle - - return null; - } - - const invDenom = 1 / denom; - - const u = (dot11 * dot02 - dot01 * dot12) * invDenom; - const v = (dot00 * dot12 - dot01 * dot02) * invDenom; - - dest[0] = 1 - u - v; - dest[1] = v; - dest[2] = u; - - return dest; - }; - }))(), - - /** - * Returns true if the given barycentric coordinates are within their triangle. - * - * @private - */ - barycentricInsideTriangle(bary) { - - const v = bary[1]; - const u = bary[2]; - - return (u >= 0) && (v >= 0) && (u + v < 1); - }, - - /** - * Gets cartesian coordinates from barycentric coordinates within a triangle. - * - * @private - */ - barycentricToCartesian(bary, a, b, c, cartesian = math.vec3()) { - const u = bary[0]; - const v = bary[1]; - const w = bary[2]; - - cartesian[0] = a[0] * u + b[0] * v + c[0] * w; - cartesian[1] = a[1] * u + b[1] * v + c[1] * w; - cartesian[2] = a[2] * u + b[2] * v + c[2] * w; - - return cartesian; - }, - - - /** - * Given geometry defined as an array of positions, optional normals, option uv and an array of indices, returns - * modified arrays that have duplicate vertices removed. - * - * Note: does not work well when co-incident vertices have same positions but different normals and UVs. - * - * @param positions - * @param normals - * @param uv - * @param indices - * @returns {{positions: Array, indices: Array}} - * @private - */ - mergeVertices(positions, normals, uv, indices) { - const positionsMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique) - const indicesLookup = []; - const uniquePositions = []; - const uniqueNormals = normals ? [] : null; - const uniqueUV = uv ? [] : null; - const indices2 = []; - let vx; - let vy; - let vz; - let key; - const precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001 - const precision = 10 ** precisionPoints; - let i; - let len; - let uvi = 0; - for (i = 0, len = positions.length; i < len; i += 3) { - vx = positions[i]; - vy = positions[i + 1]; - vz = positions[i + 2]; - key = `${Math.round(vx * precision)}_${Math.round(vy * precision)}_${Math.round(vz * precision)}`; - if (positionsMap[key] === undefined) { - positionsMap[key] = uniquePositions.length / 3; - uniquePositions.push(vx); - uniquePositions.push(vy); - uniquePositions.push(vz); - if (normals) { - uniqueNormals.push(normals[i]); - uniqueNormals.push(normals[i + 1]); - uniqueNormals.push(normals[i + 2]); - } - if (uv) { - uniqueUV.push(uv[uvi]); - uniqueUV.push(uv[uvi + 1]); - } - } - indicesLookup[i / 3] = positionsMap[key]; - uvi += 2; - } - for (i = 0, len = indices.length; i < len; i++) { - indices2[i] = indicesLookup[indices[i]]; - } - const result = { - positions: uniquePositions, - indices: indices2 - }; - if (uniqueNormals) { - result.normals = uniqueNormals; - } - if (uniqueUV) { - result.uv = uniqueUV; - - } - return result; - }, - - /** - * Builds normal vectors from positions and indices. - * - * @private - */ - buildNormals: ((() => { - - const a = new FloatArrayType(3); - const b = new FloatArrayType(3); - const c = new FloatArrayType(3); - const ab = new FloatArrayType(3); - const ac = new FloatArrayType(3); - const crossVec = new FloatArrayType(3); - - return (positions, indices, normals) => { - - let i; - let len; - const nvecs = new Array(positions.length / 3); - let j0; - let j1; - let j2; - - for (i = 0, len = indices.length; i < len; i += 3) { - - j0 = indices[i]; - j1 = indices[i + 1]; - j2 = indices[i + 2]; - - a[0] = positions[j0 * 3]; - a[1] = positions[j0 * 3 + 1]; - a[2] = positions[j0 * 3 + 2]; - - b[0] = positions[j1 * 3]; - b[1] = positions[j1 * 3 + 1]; - b[2] = positions[j1 * 3 + 2]; - - c[0] = positions[j2 * 3]; - c[1] = positions[j2 * 3 + 1]; - c[2] = positions[j2 * 3 + 2]; - - math.subVec3(b, a, ab); - math.subVec3(c, a, ac); - - const normVec = math.vec3(); - - math.normalizeVec3(math.cross3Vec3(ab, ac, crossVec), normVec); - - if (!nvecs[j0]) { - nvecs[j0] = []; - } - if (!nvecs[j1]) { - nvecs[j1] = []; - } - if (!nvecs[j2]) { - nvecs[j2] = []; - } - - nvecs[j0].push(normVec); - nvecs[j1].push(normVec); - nvecs[j2].push(normVec); - } - - normals = (normals && normals.length === positions.length) ? normals : new Float32Array(positions.length); - - let count; - let x; - let y; - let z; - - for (i = 0, len = nvecs.length; i < len; i++) { // Now go through and average out everything - - count = nvecs[i].length; - - x = 0; - y = 0; - z = 0; - - for (let j = 0; j < count; j++) { - x += nvecs[i][j][0]; - y += nvecs[i][j][1]; - z += nvecs[i][j][2]; - } - - normals[i * 3] = (x / count); - normals[i * 3 + 1] = (y / count); - normals[i * 3 + 2] = (z / count); - } - - return normals; - }; - }))(), - - /** - * Builds vertex tangent vectors from positions, UVs and indices. - * - * @private - */ - buildTangents: ((() => { - - const tempVec3 = new FloatArrayType(3); - const tempVec3b = new FloatArrayType(3); - const tempVec3c = new FloatArrayType(3); - const tempVec3d = new FloatArrayType(3); - const tempVec3e = new FloatArrayType(3); - const tempVec3f = new FloatArrayType(3); - const tempVec3g = new FloatArrayType(3); - - return (positions, indices, uv) => { - - const tangents = new Float32Array(positions.length); - - // The vertex arrays needs to be calculated - // before the calculation of the tangents - - for (let location = 0; location < indices.length; location += 3) { - - // Recontructing each vertex and UV coordinate into the respective vectors - - let index = indices[location]; - - const v0 = positions.subarray(index * 3, index * 3 + 3); - const uv0 = uv.subarray(index * 2, index * 2 + 2); - - index = indices[location + 1]; - - const v1 = positions.subarray(index * 3, index * 3 + 3); - const uv1 = uv.subarray(index * 2, index * 2 + 2); - - index = indices[location + 2]; - - const v2 = positions.subarray(index * 3, index * 3 + 3); - const uv2 = uv.subarray(index * 2, index * 2 + 2); - - const deltaPos1 = math.subVec3(v1, v0, tempVec3); - const deltaPos2 = math.subVec3(v2, v0, tempVec3b); - - const deltaUV1 = math.subVec2(uv1, uv0, tempVec3c); - const deltaUV2 = math.subVec2(uv2, uv0, tempVec3d); - - const r = 1 / ((deltaUV1[0] * deltaUV2[1]) - (deltaUV1[1] * deltaUV2[0])); - - const tangent = math.mulVec3Scalar( - math.subVec3( - math.mulVec3Scalar(deltaPos1, deltaUV2[1], tempVec3e), - math.mulVec3Scalar(deltaPos2, deltaUV1[1], tempVec3f), - tempVec3g - ), - r, - tempVec3f - ); - - // Average the value of the vectors - - let addTo; - - for (let v = 0; v < 3; v++) { - addTo = indices[location + v] * 3; - tangents[addTo] += tangent[0]; - tangents[addTo + 1] += tangent[1]; - tangents[addTo + 2] += tangent[2]; - } - } - - return tangents; - }; - }))(), - - /** - * Builds vertex and index arrays needed by color-indexed triangle picking. - * - * @private - */ - buildPickTriangles(positions, indices, compressGeometry) { - - const numIndices = indices.length; - const pickPositions = compressGeometry ? new Uint16Array(numIndices * 9) : new Float32Array(numIndices * 9); - const pickColors = new Uint8Array(numIndices * 12); - let primIndex = 0; - let vi;// Positions array index - let pvi = 0;// Picking positions array index - let pci = 0; // Picking color array index - - // Triangle indices - let i; - let r; - let g; - let b; - let a; - - for (let location = 0; location < numIndices; location += 3) { - - // Primitive-indexed triangle pick color - - a = (primIndex >> 24 & 0xFF); - b = (primIndex >> 16 & 0xFF); - g = (primIndex >> 8 & 0xFF); - r = (primIndex & 0xFF); - - // A - - i = indices[location]; - vi = i * 3; - - pickPositions[pvi++] = positions[vi]; - pickPositions[pvi++] = positions[vi + 1]; - pickPositions[pvi++] = positions[vi + 2]; - - pickColors[pci++] = r; - pickColors[pci++] = g; - pickColors[pci++] = b; - pickColors[pci++] = a; - - // B - - i = indices[location + 1]; - vi = i * 3; - - pickPositions[pvi++] = positions[vi]; - pickPositions[pvi++] = positions[vi + 1]; - pickPositions[pvi++] = positions[vi + 2]; - - pickColors[pci++] = r; - pickColors[pci++] = g; - pickColors[pci++] = b; - pickColors[pci++] = a; - - // C - - i = indices[location + 2]; - vi = i * 3; - - pickPositions[pvi++] = positions[vi]; - pickPositions[pvi++] = positions[vi + 1]; - pickPositions[pvi++] = positions[vi + 2]; - - pickColors[pci++] = r; - pickColors[pci++] = g; - pickColors[pci++] = b; - pickColors[pci++] = a; - - primIndex++; - } - - return { - positions: pickPositions, - colors: pickColors - }; - }, - - /** - * Converts surface-perpendicular face normals to vertex normals. Assumes that the mesh contains disjoint triangles - * that don't share vertex array elements. Works by finding groups of vertices that have the same location and - * averaging their normal vectors. - * - * @returns {{positions: Array, normals: *}} - */ - faceToVertexNormals(positions, normals, options = {}) { - const smoothNormalsAngleThreshold = options.smoothNormalsAngleThreshold || 20; - const vertexMap = {}; - const vertexNormals = []; - const vertexNormalAccum = {}; - let acc; - let vx; - let vy; - let vz; - let key; - const precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001 - const precision = 10 ** precisionPoints; - let posi; - let i; - let j; - let len; - let a; - let b; - - for (i = 0, len = positions.length; i < len; i += 3) { - - posi = i / 3; - - vx = positions[i]; - vy = positions[i + 1]; - vz = positions[i + 2]; - - key = `${Math.round(vx * precision)}_${Math.round(vy * precision)}_${Math.round(vz * precision)}`; - - if (vertexMap[key] === undefined) { - vertexMap[key] = [posi]; - } else { - vertexMap[key].push(posi); - } - - const normal = math.normalizeVec3([normals[i], normals[i + 1], normals[i + 2]]); - - vertexNormals[posi] = normal; - - acc = math.vec4([normal[0], normal[1], normal[2], 1]); - - vertexNormalAccum[posi] = acc; - } - - for (key in vertexMap) { - - if (vertexMap.hasOwnProperty(key)) { - - const vertices = vertexMap[key]; - const numVerts = vertices.length; - - for (i = 0; i < numVerts; i++) { - - const ii = vertices[i]; - - acc = vertexNormalAccum[ii]; - - for (j = 0; j < numVerts; j++) { - - if (i === j) { - continue; - } - - const jj = vertices[j]; - - a = vertexNormals[ii]; - b = vertexNormals[jj]; - - const angle = Math.abs(math.angleVec3(a, b) / math.DEGTORAD); - - if (angle < smoothNormalsAngleThreshold) { - - acc[0] += b[0]; - acc[1] += b[1]; - acc[2] += b[2]; - acc[3] += 1.0; - } - } - } - } - } - - for (i = 0, len = normals.length; i < len; i += 3) { - - acc = vertexNormalAccum[i / 3]; - - normals[i + 0] = acc[0] / acc[3]; - normals[i + 1] = acc[1] / acc[3]; - normals[i + 2] = acc[2] / acc[3]; - - } - }, - - //------------------------------------------------------------------------------------------------------------------ - // Ray casting - //------------------------------------------------------------------------------------------------------------------ - - /** - Transforms a ray by a matrix. - @method transformRay - @static - @param {Number[]} matrix 4x4 matrix - @param {Number[]} rayOrigin The ray origin - @param {Number[]} rayDir The ray direction - @param {Number[]} rayOriginDest The transformed ray origin - @param {Number[]} rayDirDest The transformed ray direction - */ - transformRay: ((() => { - - const tempVec4a = new FloatArrayType(4); - const tempVec4b = new FloatArrayType(4); - - return (matrix, rayOrigin, rayDir, rayOriginDest, rayDirDest) => { - - tempVec4a[0] = rayOrigin[0]; - tempVec4a[1] = rayOrigin[1]; - tempVec4a[2] = rayOrigin[2]; - tempVec4a[3] = 1; - - math.transformVec4(matrix, tempVec4a, tempVec4b); - - rayOriginDest[0] = tempVec4b[0]; - rayOriginDest[1] = tempVec4b[1]; - rayOriginDest[2] = tempVec4b[2]; - - tempVec4a[0] = rayDir[0]; - tempVec4a[1] = rayDir[1]; - tempVec4a[2] = rayDir[2]; - - math.transformVec3(matrix, tempVec4a, tempVec4b); - - math.normalizeVec3(tempVec4b); - - rayDirDest[0] = tempVec4b[0]; - rayDirDest[1] = tempVec4b[1]; - rayDirDest[2] = tempVec4b[2]; - }; - }))(), - - /** - Transforms a Canvas-space position into a World-space ray, in the context of a Camera. - @method canvasPosToWorldRay - @static - @param {Number[]} viewMatrix View matrix - @param {Number[]} projMatrix Projection matrix - @param {String} projection Projection type (e.g. "ortho") - @param {Number[]} canvasPos The Canvas-space position. - @param {Number[]} worldRayOrigin The World-space ray origin. - @param {Number[]} worldRayDir The World-space ray direction. - */ - canvasPosToWorldRay: ((() => { - - const pvMatInv = new FloatArrayType(16); - const vec4Near = new FloatArrayType(4); - const vec4Far = new FloatArrayType(4); - - const clipToWorld = (clipX, clipY, clipZ, isOrtho, outVec4) => { - outVec4[0] = clipX; - outVec4[1] = clipY; - outVec4[2] = clipZ; - outVec4[3] = 1; - - math.transformVec4(pvMatInv, outVec4, outVec4); - if (! isOrtho) - math.mulVec4Scalar(outVec4, 1 / outVec4[3]); - }; - - return (canvas, viewMatrix, projMatrix, projection, canvasPos, worldRayOrigin, worldRayDir) => { - const isOrtho = projection === "ortho"; - - math.mulMat4(projMatrix, viewMatrix, pvMatInv); - math.inverseMat4(pvMatInv, pvMatInv); - - // Calculate clip space coordinates, which will be in range - // of x=[-1..1] and y=[-1..1], with y=(+1) at top - // clientWidth/Height needs to be used in case canvas.width/height is scaled down, - // but not reflecting client dimensions (e.g. when using FastNavPlugin) - const clipX = 2 * canvasPos[0] / canvas.clientWidth - 1; // Calculate clip space coordinates - const clipY = 1 - 2 * canvasPos[1] / canvas.clientHeight; - - clipToWorld(clipX, clipY, -1, isOrtho, vec4Near); - - clipToWorld(clipX, clipY, 1, isOrtho, vec4Far); - - worldRayOrigin[0] = vec4Near[0]; - worldRayOrigin[1] = vec4Near[1]; - worldRayOrigin[2] = vec4Near[2]; - - math.subVec3(vec4Far, vec4Near, worldRayDir); - - math.normalizeVec3(worldRayDir); - }; - }))(), - - /** - Transforms a Canvas-space position to a Mesh's Local-space coordinate system, in the context of a Camera. - @method canvasPosToLocalRay - @static - @param {Camera} camera The Camera. - @param {Mesh} mesh The Mesh. - @param {Number[]} viewMatrix View matrix - @param {Number[]} projMatrix Projection matrix - @param {Number[]} worldMatrix Modeling matrix - @param {Number[]} canvasPos The Canvas-space position. - @param {Number[]} localRayOrigin The Local-space ray origin. - @param {Number[]} localRayDir The Local-space ray direction. - */ - canvasPosToLocalRay: ((() => { - - const worldRayOrigin = new FloatArrayType(3); - const worldRayDir = new FloatArrayType(3); - - return (canvas, viewMatrix, projMatrix, projection, worldMatrix, canvasPos, localRayOrigin, localRayDir) => { - math.canvasPosToWorldRay(canvas, viewMatrix, projMatrix, projection, canvasPos, worldRayOrigin, worldRayDir); - math.worldRayToLocalRay(worldMatrix, worldRayOrigin, worldRayDir, localRayOrigin, localRayDir); - }; - }))(), - - /** - Transforms a ray from World-space to a Mesh's Local-space coordinate system. - @method worldRayToLocalRay - @static - @param {Number[]} worldMatrix The World transform matrix - @param {Number[]} worldRayOrigin The World-space ray origin. - @param {Number[]} worldRayDir The World-space ray direction. - @param {Number[]} localRayOrigin The Local-space ray origin. - @param {Number[]} localRayDir The Local-space ray direction. - */ - worldRayToLocalRay: ((() => { - - const tempMat4 = new FloatArrayType(16); - const tempVec4a = new FloatArrayType(4); - const tempVec4b = new FloatArrayType(4); - - return (worldMatrix, worldRayOrigin, worldRayDir, localRayOrigin, localRayDir) => { - - const modelMatInverse = math.inverseMat4(worldMatrix, tempMat4); - - tempVec4a[0] = worldRayOrigin[0]; - tempVec4a[1] = worldRayOrigin[1]; - tempVec4a[2] = worldRayOrigin[2]; - tempVec4a[3] = 1; - - math.transformVec4(modelMatInverse, tempVec4a, tempVec4b); - - localRayOrigin[0] = tempVec4b[0]; - localRayOrigin[1] = tempVec4b[1]; - localRayOrigin[2] = tempVec4b[2]; - - math.transformVec3(modelMatInverse, worldRayDir, localRayDir); - }; - }))(), - - buildKDTree: ((() => { - - const KD_TREE_MAX_DEPTH = 10; - const KD_TREE_MIN_TRIANGLES = 20; - - const dimLength = new Float32Array(); - - function buildNode(triangles, indices, positions, depth) { - const aabb = new FloatArrayType(6); - - const node = { - triangles: null, - left: null, - right: null, - leaf: false, - splitDim: 0, - aabb - }; - - aabb[0] = aabb[1] = aabb[2] = Number.POSITIVE_INFINITY; - aabb[3] = aabb[4] = aabb[5] = Number.NEGATIVE_INFINITY; - - let t; - let len; - - for (t = 0, len = triangles.length; t < len; ++t) { - var ii = triangles[t] * 3; - for (let j = 0; j < 3; ++j) { - const pi = indices[ii + j] * 3; - if (positions[pi] < aabb[0]) { - aabb[0] = positions[pi]; - } - if (positions[pi] > aabb[3]) { - aabb[3] = positions[pi]; - } - if (positions[pi + 1] < aabb[1]) { - aabb[1] = positions[pi + 1]; - } - if (positions[pi + 1] > aabb[4]) { - aabb[4] = positions[pi + 1]; - } - if (positions[pi + 2] < aabb[2]) { - aabb[2] = positions[pi + 2]; - } - if (positions[pi + 2] > aabb[5]) { - aabb[5] = positions[pi + 2]; - } - } - } - - if (triangles.length < KD_TREE_MIN_TRIANGLES || depth > KD_TREE_MAX_DEPTH) { - node.triangles = triangles; - node.leaf = true; - return node; - } - - dimLength[0] = aabb[3] - aabb[0]; - dimLength[1] = aabb[4] - aabb[1]; - dimLength[2] = aabb[5] - aabb[2]; - - let dim = 0; - - if (dimLength[1] > dimLength[dim]) { - dim = 1; - } - - if (dimLength[2] > dimLength[dim]) { - dim = 2; - } - - node.splitDim = dim; - - const mid = (aabb[dim] + aabb[dim + 3]) / 2; - const left = new Array(triangles.length); - let numLeft = 0; - const right = new Array(triangles.length); - let numRight = 0; - - for (t = 0, len = triangles.length; t < len; ++t) { - - var ii = triangles[t] * 3; - const i0 = indices[ii]; - const i1 = indices[ii + 1]; - const i2 = indices[ii + 2]; - - const pi0 = i0 * 3; - const pi1 = i1 * 3; - const pi2 = i2 * 3; - - if (positions[pi0 + dim] <= mid || positions[pi1 + dim] <= mid || positions[pi2 + dim] <= mid) { - left[numLeft++] = triangles[t]; - } else { - right[numRight++] = triangles[t]; - } - } - - left.length = numLeft; - right.length = numRight; - - node.left = buildNode(left, indices, positions, depth + 1); - node.right = buildNode(right, indices, positions, depth + 1); - - return node; - } - - return (indices, positions) => { - const numTris = indices.length / 3; - const triangles = new Array(numTris); - for (let i = 0; i < numTris; ++i) { - triangles[i] = i; - } - return buildNode(triangles, indices, positions, 0); - }; - }))(), - - - decompressPosition(position, decodeMatrix, dest) { - dest = dest || position; - dest[0] = position[0] * decodeMatrix[0] + decodeMatrix[12]; - dest[1] = position[1] * decodeMatrix[5] + decodeMatrix[13]; - dest[2] = position[2] * decodeMatrix[10] + decodeMatrix[14]; - }, - - decompressPositions(positions, decodeMatrix, dest = new Float32Array(positions.length)) { - for (let i = 0, len = positions.length; i < len; i += 3) { - dest[i + 0] = positions[i + 0] * decodeMatrix[0] + decodeMatrix[12]; - dest[i + 1] = positions[i + 1] * decodeMatrix[5] + decodeMatrix[13]; - dest[i + 2] = positions[i + 2] * decodeMatrix[10] + decodeMatrix[14]; - } - return dest; - }, - - decompressUV(uv, decodeMatrix, dest) { - dest[0] = uv[0] * decodeMatrix[0] + decodeMatrix[6]; - dest[1] = uv[1] * decodeMatrix[4] + decodeMatrix[7]; - }, - - decompressUVs(uvs, decodeMatrix, dest = new Float32Array(uvs.length)) { - for (let i = 0, len = uvs.length; i < len; i += 3) { - dest[i + 0] = uvs[i + 0] * decodeMatrix[0] + decodeMatrix[6]; - dest[i + 1] = uvs[i + 1] * decodeMatrix[4] + decodeMatrix[7]; - } - return dest; - }, - - octDecodeVec2(oct, result) { - let x = oct[0]; - let y = oct[1]; - x = (2 * x + 1) / 255; - y = (2 * y + 1) / 255; - const z = 1 - Math.abs(x) - Math.abs(y); - if (z < 0) { - x = (1 - Math.abs(y)) * (x >= 0 ? 1 : -1); - y = (1 - Math.abs(x)) * (y >= 0 ? 1 : -1); - } - const length = Math.sqrt(x * x + y * y + z * z); - result[0] = x / length; - result[1] = y / length; - result[2] = z / length; - return result; - }, - - octDecodeVec2s(octs, result) { - for (let i = 0, j = 0, len = octs.length; i < len; i += 2) { - let x = octs[i + 0]; - let y = octs[i + 1]; - x = (2 * x + 1) / 255; - y = (2 * y + 1) / 255; - const z = 1 - Math.abs(x) - Math.abs(y); - if (z < 0) { - x = (1 - Math.abs(y)) * (x >= 0 ? 1 : -1); - y = (1 - Math.abs(x)) * (y >= 0 ? 1 : -1); - } - const length = Math.sqrt(x * x + y * y + z * z); - result[j + 0] = x / length; - result[j + 1] = y / length; - result[j + 2] = z / length; - j += 3; - } - return result; - } -}; - -math.buildEdgeIndices = (function () { - - const uniquePositions = []; - const indicesLookup = []; - const indicesReverseLookup = []; - const weldedIndices = []; - - // TODO: Optimize with caching, but need to cater to both compressed and uncompressed positions - - const faces = []; - let numFaces = 0; - const compa = new Uint16Array(3); - const compb = new Uint16Array(3); - const compc = new Uint16Array(3); - const a = math.vec3(); - const b = math.vec3(); - const c = math.vec3(); - const cb = math.vec3(); - const ab = math.vec3(); - const cross = math.vec3(); - const normal = math.vec3(); - - function weldVertices(positions, indices) { - const positionsMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique) - let vx; - let vy; - let vz; - let key; - const precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001 - const precision = Math.pow(10, precisionPoints); - let i; - let len; - let lenUniquePositions = 0; - for (i = 0, len = positions.length; i < len; i += 3) { - vx = positions[i]; - vy = positions[i + 1]; - vz = positions[i + 2]; - key = Math.round(vx * precision) + '_' + Math.round(vy * precision) + '_' + Math.round(vz * precision); - if (positionsMap[key] === undefined) { - positionsMap[key] = lenUniquePositions / 3; - uniquePositions[lenUniquePositions++] = vx; - uniquePositions[lenUniquePositions++] = vy; - uniquePositions[lenUniquePositions++] = vz; - } - indicesLookup[i / 3] = positionsMap[key]; - } - for (i = 0, len = indices.length; i < len; i++) { - weldedIndices[i] = indicesLookup[indices[i]]; - indicesReverseLookup[weldedIndices[i]] = indices[i]; - } - } - - function buildFaces(numIndices, positionsDecodeMatrix) { - numFaces = 0; - for (let i = 0, len = numIndices; i < len; i += 3) { - const ia = ((weldedIndices[i]) * 3); - const ib = ((weldedIndices[i + 1]) * 3); - const ic = ((weldedIndices[i + 2]) * 3); - if (positionsDecodeMatrix) { - compa[0] = uniquePositions[ia]; - compa[1] = uniquePositions[ia + 1]; - compa[2] = uniquePositions[ia + 2]; - compb[0] = uniquePositions[ib]; - compb[1] = uniquePositions[ib + 1]; - compb[2] = uniquePositions[ib + 2]; - compc[0] = uniquePositions[ic]; - compc[1] = uniquePositions[ic + 1]; - compc[2] = uniquePositions[ic + 2]; - // Decode - math.decompressPosition(compa, positionsDecodeMatrix, a); - math.decompressPosition(compb, positionsDecodeMatrix, b); - math.decompressPosition(compc, positionsDecodeMatrix, c); - } else { - a[0] = uniquePositions[ia]; - a[1] = uniquePositions[ia + 1]; - a[2] = uniquePositions[ia + 2]; - b[0] = uniquePositions[ib]; - b[1] = uniquePositions[ib + 1]; - b[2] = uniquePositions[ib + 2]; - c[0] = uniquePositions[ic]; - c[1] = uniquePositions[ic + 1]; - c[2] = uniquePositions[ic + 2]; - } - math.subVec3(c, b, cb); - math.subVec3(a, b, ab); - math.cross3Vec3(cb, ab, cross); - math.normalizeVec3(cross, normal); - const face = faces[numFaces] || (faces[numFaces] = {normal: math.vec3()}); - face.normal[0] = normal[0]; - face.normal[1] = normal[1]; - face.normal[2] = normal[2]; - numFaces++; - } - } - - return function (positions, indices, positionsDecodeMatrix, edgeThreshold) { - weldVertices(positions, indices); - buildFaces(indices.length, positionsDecodeMatrix); - const edgeIndices = []; - const thresholdDot = Math.cos(math.DEGTORAD * edgeThreshold); - const edges = {}; - let edge1; - let edge2; - let index1; - let index2; - let key; - let largeIndex = false; - let edge; - let normal1; - let normal2; - let dot; - let ia; - let ib; - for (let i = 0, len = indices.length; i < len; i += 3) { - const faceIndex = i / 3; - for (let j = 0; j < 3; j++) { - edge1 = weldedIndices[i + j]; - edge2 = weldedIndices[i + ((j + 1) % 3)]; - index1 = Math.min(edge1, edge2); - index2 = Math.max(edge1, edge2); - key = index1 + "," + index2; - if (edges[key] === undefined) { - edges[key] = { - index1: index1, - index2: index2, - face1: faceIndex, - face2: undefined - }; - } else { - edges[key].face2 = faceIndex; - } - } - } - for (key in edges) { - edge = edges[key]; - // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree. - if (edge.face2 !== undefined) { - normal1 = faces[edge.face1].normal; - normal2 = faces[edge.face2].normal; - dot = math.dotVec3(normal1, normal2); - if (dot > thresholdDot) { - continue; - } - } - ia = indicesReverseLookup[edge.index1]; - ib = indicesReverseLookup[edge.index2]; - if (!largeIndex && ia > 65535 || ib > 65535) { - largeIndex = true; - } - edgeIndices.push(ia); - edgeIndices.push(ib); - } - return (largeIndex) ? new Uint32Array(edgeIndices) : new Uint16Array(edgeIndices); - }; -})(); - - -/** - * Returns `true` if a plane clips the given 3D positions. - * @param {Number[]} pos Position in plane - * @param {Number[]} dir Direction of plane - * @param {number} positions Flat array of 3D positions. - * @param {number} numElementsPerPosition Number of elements perposition - usually either 3 or 4. - * @returns {boolean} - */ -math.planeClipsPositions3 = function (pos, dir, positions, numElementsPerPosition = 3) { - for (let i = 0, len = positions.length; i < len; i += numElementsPerPosition) { - tempVec3a$j[0] = positions[i + 0] - pos[0]; - tempVec3a$j[1] = positions[i + 1] - pos[1]; - tempVec3a$j[2] = positions[i + 2] - pos[2]; - let dotProduct = tempVec3a$j[0] * dir[0] + tempVec3a$j[1] * dir[1] + tempVec3a$j[2] * dir[2]; - if (dotProduct < 0) { - return true; - } - } - return false; -}; - -/** - * Tests whether a plane intersects a bouding box. - * @param plane SectionPlane - * @param aabb Bounding box - * @returns {boolean} - */ -math.planeIntersectsAABB3 = (plane, aabb) => { - const min = [aabb[0], aabb[1], aabb[2]]; - const max = [aabb[3], aabb[4], aabb[5]]; - - const corners = [ - [min[0], min[1], min[2]], // 000 - [max[0], min[1], min[2]], // 100 - [min[0], max[1], min[2]], // 010 - [max[0], max[1], min[2]], // 110 - [min[0], min[1], max[2]], // 001 - [max[0], min[1], max[2]], // 101 - [min[0], max[1], max[2]], // 011 - [max[0], max[1], max[2]] // 111 - ]; - - // Calculate distance from each corner to the plane - let hasPositive = false; - let hasNegative = false; - - for (const corner of corners) { - const distance = plane.dist + math.dotVec3(plane.dir, corner); - - if (distance > 0) hasPositive = true; - if (distance < 0) hasNegative = true; - - // If we found points on both sides, the plane intersects the box - if (hasPositive && hasNegative) return true; - } - - // If all points are on the same side, no intersection - return false; -}; - -/** - * makeSectionPlaneSlicer returns a function that slices a given geometry with a given SectionPlane - * The implementation finds segments where the SectionPlane intersects with the geometry's surface. - * These segments form loops that are triangulated using the Earcut algorithm, taking internal holes into account. - * @param {Number[]} pos SectionPlane position 3D vector - * @param {Number[]} dir SectionPlane rotation quaternion - * @returns {function} - */ -math.makeSectionPlaneSlicer = (function() { - - const tempVec2a = math.vec2(); - const tempVec2b = math.vec2(); - const tempVec2c = math.vec2(); - const tempVec2d = math.vec2(); - - const tempVec3a = math.vec3(); - const tempVec3b = math.vec3(); - const tempVec3c = math.vec3(); - math.vec3(); - - const triangle = [ math.vec3(), math.vec3(), math.vec3() ]; - const tmpIntersections = [ null, null, null ]; - const tmpPositions = [ null, null, null ]; - const tmpReferences = [ null, null, null ]; - - const worldRight = [1, 0, 0]; - const worldUp = [0, 1, 0]; - const worldForward = [0, 0, 1]; - - const sqDistVec3 = (function() { - const tmp = math.vec3(); - return (a, b) => math.sqLenVec3(math.subVec3(a, b, tmp)); - })(); - - const iota = n => { - const ret = [ ]; - for (let i = 0; i < n; ++i) - ret.push(i); - return ret; - }; - - const ccw = (a, b, c) => ((c[1] - a[1]) * (b[0] - a[0])) > ((b[1] - a[1]) * (c[0] - a[0])); - - return function(plane) { - const planeU = math.vec3ApplyQuaternion(plane.quaternion, worldRight, math.vec3()); - const planeV = math.vec3ApplyQuaternion(plane.quaternion, worldUp, math.vec3()); - const planeN = math.vec3ApplyQuaternion(plane.quaternion, worldForward, math.vec3()); - - return function(mesh, cfg = { }) { - const planeToMesh = math.subVec3(mesh.origin, plane.pos, math.vec3()); - const planeDist = math.dotVec3(planeN, planeToMesh); - - const unsortedSegment = [ ]; - const indexedPositions = [ null ]; // to never return 0 from addPosition, so its result can be used as a predicate - const addPosition = (p, addUV) => { - const idx = indexedPositions.length; - const P = new Float64Array(5); - P.set(p); - if (addUV) { - math.addVec3(planeToMesh, p, tempVec3a); - P[3] = -math.dotVec3(planeU, tempVec3a); - P[4] = math.dotVec3(planeV, tempVec3a); - } - indexedPositions.push(P); - return idx; - }; - - const getCoord2D = (idx, dst) => { const P = indexedPositions[idx]; dst[0] = P[3]; dst[1] = P[4]; return dst; }; - - const isLoopInside = (inner, outer) => { - const bbI = inner.boundingBox; - const bbO = outer.boundingBox; - if ((bbI[0] < bbO[0]) || (bbI[1] < bbO[1]) || (bbI[2] > bbO[2]) || (bbI[3] > bbO[3])) { - return false; - } - - const innerEndpoints = inner.endPoints; - const outerEndpoints = outer.endPoints; - for (let ii = 0, ij = innerEndpoints.length - 1; ii < innerEndpoints.length; ij = ii++) { - const i0 = getCoord2D(innerEndpoints[ii], tempVec2a); - const [i0x, i0y] = i0; - const i1 = getCoord2D(innerEndpoints[ij], tempVec2b); - - let inside = false; - for (let i = 0, j = outerEndpoints.length - 1; i < outerEndpoints.length; j = i++) { - const o0 = getCoord2D(outerEndpoints[i], tempVec2c); - const o1 = getCoord2D(outerEndpoints[j], tempVec2d); - - if ((ccw(i0, o0, o1) !== ccw(i1, o0, o1)) && (ccw(i0, i1, o0) !== ccw(i0, i1, o1))) { - return false; // segments intersect - } - - const [o0x, o0y] = o0; - const [o1x, o1y] = o1; - - const dx = i0x - o0x; - const dy = i0y - o0y; - - const oDx = o1x - o0x; - const oDy = o1y - o0y; - - const dot = (((oDx !== 0) || (oDy !== 0)) && (Math.abs(oDx * dy - oDy * dx) < 1e-10)) ? (dx * oDx + dy * oDy) : -1; - if ((dot >= 0) && (dot <= (Math.pow(oDx, 2) + Math.pow(oDy, 2)))) { - return false; // on edge - } - - if (((o0y > i0y) !== (o1y > i0y)) && (dx < (dy * oDx / oDy))) { - inside = !inside; - } - } - if (! inside) { - return false; - } - } - - return true; - }; - - const pos = { indices: [ ], normals: [ ] }; - const neg = (! cfg.onlyPosSliceWithUV) && { indices: [ ], normals: [ ] }; - - const appendOnSide = (dst, indices, normal) => { - if (dst) { - const p0 = indexedPositions[indices[0]]; - normal ||= math.normalizeVec3(math.cross3Vec3(math.subVec3(indexedPositions[indices[1]], p0, tempVec3a), - math.subVec3(indexedPositions[indices[2]], p0, tempVec3b), - tempVec3a), - tempVec3a); - - for (let i = 0; i < 3; ++i) { - dst.indices.push(indices[i]); - dst.normals.push(normal[0], normal[1], normal[2]); - } - } - }; - - const setVertex = (i, dst) => { - const idx = mesh.indices[i] * 3; - dst[0] = mesh.positions[idx + 0]; - dst[1] = mesh.positions[idx + 1]; - dst[2] = mesh.positions[idx + 2]; - return dst; - }; - - for (let faceIdx = 0; faceIdx < mesh.indices.length; faceIdx += 3) { - const p0 = setVertex(faceIdx + 0, triangle[0]); - const p1 = setVertex(faceIdx + 1, triangle[1]); - const p2 = setVertex(faceIdx + 2, triangle[2]); - - if (math.compareVec3(p0, p1) || math.compareVec3(p1, p2) || math.compareVec3(p2, p0)) { - continue; // skip degenerate triangle - } - - const d0 = planeDist + math.dotVec3(planeN, p0); - const d1 = planeDist + math.dotVec3(planeN, p1); - const d2 = planeDist + math.dotVec3(planeN, p2); - - if ((d0 !== 0) || (d1 !== 0) || (d2 !== 0)) { - const i0 = (d0 * d1 <= 0) && addPosition(math.lerpVec3(d0 / (d0 - d1), 0, 1, p0, p1, tempVec3a), true); - const i1 = (d1 * d2 <= 0) && addPosition(math.lerpVec3(d1 / (d1 - d2), 0, 1, p1, p2, tempVec3a), true); - const i2 = (d2 * d0 <= 0) && addPosition(math.lerpVec3(d2 / (d2 - d0), 0, 1, p2, p0, tempVec3a), true); - - const p = (! cfg.onlyPosSliceWithUV) && tmpPositions; - if (p) { - p[0] = addPosition(p0); - p[1] = addPosition(p1); - p[2] = addPosition(p2); - } - - if (i0 ? (i1 || i2) : (i1 && i2)) { // triangle intersected by the section plane - unsortedSegment.push(i0 ? [ i0, i1 || i2 ] : [ i1, i2 ]); - - if (p) { - if ((d0 === 0) && (d1 === 0)) { - appendOnSide((d2 > 0) ? pos : neg, p); - } else if ((d0 === 0) && (d2 === 0)) { - appendOnSide((d1 > 0) ? pos : neg, p); - } else if ((d1 === 0) && (d2 === 0)) { - appendOnSide((d0 > 0) ? pos : neg, p); - } else { - const isPos = (i0 ? d0 : d1) > 0; - const dst0 = isPos ? pos : neg; - const dst1 = isPos ? neg : pos; - const i = tmpIntersections; - i[0] = i0; - i[1] = i1; - i[2] = i2; - const ref = tmpReferences; - if (i0) { - ref[0] = 0; ref[1] = 1; ref[2] = 2; - } else { - ref[0] = 1; ref[1] = 2; ref[2] = 0; - } - if (i[ref[1]]) { - appendOnSide(dst0, [ p[ref[0]], i[ref[0]], p[ref[2]] ]); - appendOnSide(dst0, [ i[ref[0]], i[ref[1]], p[ref[2]] ]); - appendOnSide(dst1, [ i[ref[0]], p[ref[1]], i[ref[1]] ]); - } else { - appendOnSide(dst0, [ p[ref[0]], i[ref[0]], i[ref[2]] ]); - appendOnSide(dst1, [ i[ref[0]], p[ref[1]], p[ref[2]] ]); - appendOnSide(dst1, [ i[ref[0]], p[ref[2]], i[ref[2]] ]); - } - } - } - } else if (p) { - if ((d0 >= 0) && (d1 >= 0) && (d2 >= 0)) { - appendOnSide(pos, p); - } else if ((d0 <= 0) && (d1 <= 0) && (d2 <= 0)) { - appendOnSide(neg, p); - } else { - debugger; - } - } - } - } - - const endpointLoops = [ ]; - while (unsortedSegment.length > 0) { - endpointLoops.push([ unsortedSegment[0][0], unsortedSegment[0][1] ]); - const curEndpoints = endpointLoops[endpointLoops.length - 1]; - unsortedSegment.splice(0, 1); - while (unsortedSegment.length > 0) { - const lastPoint = indexedPositions[curEndpoints[curEndpoints.length - 1]]; - const closest = { distSq: sqDistVec3(indexedPositions[curEndpoints[0]], lastPoint), idx: -1, side: -1 }; - unsortedSegment.forEach((seg, i) => { - const distSq0 = sqDistVec3(indexedPositions[seg[0]], lastPoint); - const distSq1 = sqDistVec3(indexedPositions[seg[1]], lastPoint); - const distSq = Math.min(distSq0, distSq1); - if (closest.distSq > distSq) { - closest.distSq = distSq; - closest.idx = i; - closest.side = (distSq1 < distSq0) ? 1 : 0; - } - }); - - if (closest.distSq < 1e-20) { - const nextSegment = (closest.idx >= 0) && unsortedSegment[closest.idx]; - indexedPositions[nextSegment ? nextSegment[closest.side] : curEndpoints[0]] = lastPoint; // move the split face's (above) vertex to lastPoint, to not introduce gaps - if (nextSegment) { - unsortedSegment.splice(closest.idx, 1); - const nextEnd = nextSegment[1 - closest.side]; - if (sqDistVec3(indexedPositions[nextEnd], indexedPositions[curEndpoints[0]]) > 1e-20) { - curEndpoints.push(nextEnd); - } else { - break; - } - } else { - break; - } - } else { - endpointLoops.pop(); // Could not find a matching segment. Discard a loop that cannot be closed. - break; - } - } - } - - const loops = endpointLoops.filter(endPoints => endPoints.length > 2).map((endPoints, idx) => { - let doubleArea = 0; - const aabb = math.collapseAABB2(math.AABB2()); - for (let i = 0; i < endPoints.length; i++) { - getCoord2D(endPoints[i], tempVec2a); - math.expandAABB2Point2(aabb, tempVec2a); - getCoord2D(endPoints[(i + 1) % endPoints.length], tempVec2b); - doubleArea += (tempVec2a[0] * tempVec2b[1] - tempVec2b[0] * tempVec2a[1]); - } - return { - boundingBox: aabb, - doubleArea: Math.abs(doubleArea), - endPoints: endPoints - }; - }).sort((a, b) => b.doubleArea - a.doubleArea); - - while (loops.length > 0) { - const vertices2D = [ ]; - const vertices3D = [ ]; - - const appendLoopVertices = loop => loop.endPoints.forEach(endpoint2D => { - getCoord2D(endpoint2D, tempVec2a); - vertices2D.push(tempVec2a[0], tempVec2a[1]); - vertices3D.push(endpoint2D); - }); - - const outerLoop = loops.shift(); - appendLoopVertices(outerLoop); - - const innerLoops = [ ]; - let innerLoopIdx = 0; - while (innerLoopIdx < loops.length) { - const loop = loops[innerLoopIdx]; - if (isLoopInside(loop, outerLoop) && innerLoops.every(inner => !isLoopInside(loop, inner))) { - loop.index = vertices2D.length / 2; - appendLoopVertices(loop); - innerLoops.push(loop); - loops.splice(innerLoopIdx, 1); - } else { - ++innerLoopIdx; - } - } - - // Triangulate - const triangles = earcut(vertices2D, innerLoops.map(loop => loop.index)); - - for (let i = 0; i < triangles.length; i += 3) { - const ti = tmpIntersections; - ti[0] = vertices3D[triangles[i + 0]]; - ti[1] = vertices3D[triangles[i + 1]]; - ti[2] = vertices3D[triangles[i + 2]]; - const v0 = indexedPositions[ti[0]]; - math.subVec3(indexedPositions[ti[1]], v0, tempVec3b); - math.subVec3(indexedPositions[ti[2]], v0, tempVec3c); - math.normalizeVec3(math.cross3Vec3(tempVec3b, tempVec3c, tempVec3c), tempVec3c); - const facedPositively = math.dotVec3(tempVec3c, planeN) <= 0; - appendOnSide(facedPositively ? pos : neg, ti, tempVec3c); - const tmp = ti[0]; ti[0] = ti[2]; ti[2] = tmp; - appendOnSide(facedPositively ? neg : pos, ti, math.negateVec3(tempVec3c, tempVec3c)); - } - } - - const side = src => src && (src.indices.length > 0) && (function() { - const positions = [ ]; - const uv = cfg.onlyPosSliceWithUV && [ ]; - src.indices.forEach(idx => { - const P = indexedPositions[idx]; - positions.push(P[0], P[1], P[2]); - uv && uv.push(P[3], P[4]); - }); - return { indices: iota(src.indices.length), positions: positions, normals: src.normals, uv: uv }; - })(); - return { pos: side(pos), neg: side(neg) }; - }; - }; -})(); - -const MAX_KD_TREE_DEPTH$1 = 15; // Increase if greater precision needed -const kdTreeDimLength$1 = new Float32Array(3); - -/** - * Automatically indexes a {@link Viewer}'s {@link Entity}s in a 3D k-d tree - * to support fast collision detection with 3D World-space axis-aligned boundaries (AABBs) and frustums. - * - * See {@link MarqueePicker} for usage example. - * - * An ObjectsKdTree3 is configured with a Viewer, and will then automatically - * keep itself populated with k-d nodes that contain the Viewer's Entitys. - * - * We can then traverse the k-d nodes, starting at {@link ObjectsKdTree3#root}, to find - * the contained Entities. - */ -class ObjectsKdTree3 { - - /** - * Creates an ObjectsKdTree3. - * - * @param {*} cfg Configuration - * @param {Viewer} cfg.viewer The Viewer that provides the {@link Entity}s in this ObjectsKdTree3. - * @param {number} [cfg.maxTreeDepth=15] Optional maximum depth for the k-d tree. - */ - constructor(cfg) { - - if (!cfg) { - throw "Parameter expected: cfg"; - } - - if (!cfg.viewer) { - throw "Parameter expected: cfg.viewer"; - } - - this.viewer = cfg.viewer; - - this._maxTreeDepth = cfg.maxTreeDepth || MAX_KD_TREE_DEPTH$1; - this._root = null; - this._needsRebuild = true; - - this._onModelLoaded = this.viewer.scene.on("modelLoaded", (modelId) => { - this._needsRebuild = true; - }); - - this._onModelUnloaded = this.viewer.scene.on("modelUnloaded", (modelId) => { - this._needsRebuild = true; - }); - } - - /** - * Gets the root ObjectsKdTree3 node. - * - * Each time this accessor is accessed, it will lazy-rebuild the ObjectsKdTree3 - * if {@link Entity}s have been created or removed in the {@link Viewer} since the last time it was accessed. - */ - get root() { - if (this._needsRebuild) { - this._rebuild(); - } - return this._root; - } - - _rebuild() { - const viewer = this.viewer; - const scene = viewer.scene; - const depth = 0; - this._root = { - aabb: scene.getAABB() - }; - for (let objectId in scene.objects) { - const entity = scene.objects[objectId]; - this._insertEntity(this._root, entity, depth + 1); - } - this._needsRebuild = false; - } - - _insertEntity(node, entity, depth) { - - const entityAABB = entity.aabb; - - if (depth >= this._maxTreeDepth) { - node.entities = node.entities || []; - node.entities.push(entity); - return; - } - if (node.left) { - if (math.containsAABB3(node.left.aabb, entityAABB)) { - this._insertEntity(node.left, entity, depth + 1); - return; - } - } - if (node.right) { - if (math.containsAABB3(node.right.aabb, entityAABB)) { - this._insertEntity(node.right, entity, depth + 1); - return; - } - } - const nodeAABB = node.aabb; - kdTreeDimLength$1[0] = nodeAABB[3] - nodeAABB[0]; - kdTreeDimLength$1[1] = nodeAABB[4] - nodeAABB[1]; - kdTreeDimLength$1[2] = nodeAABB[5] - nodeAABB[2]; - let dim = 0; - if (kdTreeDimLength$1[1] > kdTreeDimLength$1[dim]) { - dim = 1; - } - if (kdTreeDimLength$1[2] > kdTreeDimLength$1[dim]) { - dim = 2; - } - if (!node.left) { - const aabbLeft = nodeAABB.slice(); - aabbLeft[dim + 3] = ((nodeAABB[dim] + nodeAABB[dim + 3]) / 2.0); - node.left = { - aabb: aabbLeft - }; - if (math.containsAABB3(aabbLeft, entityAABB)) { - this._insertEntity(node.left, entity, depth + 1); - return; - } - } - if (!node.right) { - const aabbRight = nodeAABB.slice(); - aabbRight[dim] = ((nodeAABB[dim] + nodeAABB[dim + 3]) / 2.0); - node.right = { - aabb: aabbRight - }; - if (math.containsAABB3(aabbRight, entityAABB)) { - this._insertEntity(node.right, entity, depth + 1); - return; - } - } - node.entities = node.entities || []; - node.entities.push(entity); - } - - /** - * Destroys this ObjectsKdTree3. - * - * Does not destroy the {@link Viewer} given to the constructor of the ObjectsKdTree3. - */ - destroy() { - const scene = this.viewer.scene; - scene.off(this._onModelLoaded); - scene.off(this._onModelUnloaded); - this._root = null; - this._needsRebuild = true; - } -} - -// Fast queue that avoids using potentially inefficient array .shift() calls -// Based on https://github.com/creationix/fastqueue - -/** @private */ -class Queue { - - constructor() { - - this._head = []; - this._headLength = 0; - this._tail = []; - this._index = 0; - this._length = 0; - } - - get length() { - return this._length; - } - - shift() { - if (this._index >= this._headLength) { - const t = this._head; - t.length = 0; - this._head = this._tail; - this._tail = t; - this._index = 0; - this._headLength = this._head.length; - if (!this._headLength) { - return; - } - } - const value = this._head[this._index]; - if (this._index < 0) { - delete this._head[this._index++]; - } - else { - this._head[this._index++] = undefined; - } - this._length--; - return value; - } - - push(item) { - this._length++; - this._tail.push(item); - return this; - }; - - unshift(item) { - this._head[--this._index] = item; - this._length++; - return this; - } -} - -/** - * xeokit runtime statistics. - * @type {{components: {models: number, objects: number, scenes: number, meshes: number}, memory: {indices: number, uvs: number, textures: number, materials: number, transforms: number, positions: number, programs: number, normals: number, meshes: number, colors: number}, build: {version: string}, client: {browser: string}, frame: {frameCount: number, useProgram: number, bindTexture: number, drawElements: number, bindArray: number, tasksRun: number, fps: number, drawArrays: number, tasksScheduled: number}}} - */ -const stats = { - build: { - version: "0.8" - }, - client: { - browser: (navigator && navigator.userAgent) ? navigator.userAgent : "n/a" - }, - - components: { - scenes: 0, - models: 0, - meshes: 0, - objects: 0 - }, - memory: { - meshes: 0, - positions: 0, - colors: 0, - normals: 0, - uvs: 0, - indices: 0, - textures: 0, - transforms: 0, - materials: 0, - programs: 0 - }, - frame: { - frameCount: 0, - fps: 0, - useProgram: 0, - bindTexture: 0, - bindArray: 0, - drawElements: 0, - drawArrays: 0, - tasksRun: 0, - tasksScheduled: 0 - } -}; - -/** - * @private - */ - -function xmlToJson(node, attributeRenamer) { - if (node.nodeType === node.TEXT_NODE) { - var v = node.nodeValue; - if (v.match(/^\s+$/) === null) { - return v; - } - } else if (node.nodeType === node.ELEMENT_NODE || - node.nodeType === node.DOCUMENT_NODE) { - var json = {type: node.nodeName, children: []}; - - if (node.nodeType === node.ELEMENT_NODE) { - for (var j = 0; j < node.attributes.length; j++) { - var attribute = node.attributes[j]; - var nm = attributeRenamer[attribute.nodeName] || attribute.nodeName; - json[nm] = attribute.nodeValue; - } - } - - for (var i = 0; i < node.childNodes.length; i++) { - var item = node.childNodes[i]; - var j = xmlToJson(item, attributeRenamer); - if (j) json.children.push(j); - } - - return json; - } -} - -/** - * @private - */ -function clone(ob) { - return JSON.parse(JSON.stringify(ob)); -} - -/** - * @private - */ -var guidChars = [["0", 10], ["A", 26], ["a", 26], ["_", 1], ["$", 1]].map(function (a) { - var li = []; - var st = a[0].charCodeAt(0); - var en = st + a[1]; - for (var i = st; i < en; ++i) { - li.push(i); - } - return String.fromCharCode.apply(null, li); -}).join(""); - -/** - * @private - */ -function b64(v, len) { - var r = (!len || len === 4) ? [0, 6, 12, 18] : [0, 6]; - return r.map(function (i) { - return guidChars.substr(parseInt(v / (1 << i)) % 64, 1) - }).reverse().join(""); -} - -/** - * @private - */ -function compressGuid(g) { - var bs = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30].map(function (i) { - return parseInt(g.substr(i, 2), 16); - }); - return b64(bs[0], 2) + [1, 4, 7, 10, 13].map(function (i) { - return b64((bs[i] << 16) + (bs[i + 1] << 8) + bs[i + 2]); - }).join(""); -} - -/** - * @private - */ -function findNodeOfType(m, t) { - var li = []; - var _ = function (n) { - if (n.type === t) li.push(n); - (n.children || []).forEach(function (c) { - _(c); - }); - }; - _(m); - return li; -} - -/** - * @private - */ -function timeout(dt) { - return new Promise(function (resolve, reject) { - setTimeout(resolve, dt); - }); -} - -/** - * @private - */ -function httpRequest(args) { - return new Promise(function (resolve, reject) { - var xhr = new XMLHttpRequest(); - xhr.open(args.method || "GET", args.url, true); - xhr.onload = function (e) { - if (xhr.readyState === 4) { - if (xhr.status === 200) { - resolve(xhr.responseXML); - } else { - reject(xhr.statusText); - } - } - }; - xhr.send(null); - }); -} - -/** - * @private - */ -const queryString = function () { - // This function is anonymous, is executed immediately and - // the return value is assigned to QueryString! - var query_string = {}; - var query = window.location.search.substring(1); - var vars = query.split("&"); - for (var i = 0; i < vars.length; i++) { - var pair = vars[i].split("="); - // If first entry with this name - if (typeof query_string[pair[0]] === "undefined") { - query_string[pair[0]] = decodeURIComponent(pair[1]); - // If second entry with this name - } else if (typeof query_string[pair[0]] === "string") { - var arr = [query_string[pair[0]], decodeURIComponent(pair[1])]; - query_string[pair[0]] = arr; - // If third or later entry with this name - } else { - query_string[pair[0]].push(decodeURIComponent(pair[1])); - } - } - return query_string; -}(); - -/** - * @private - */ -function loadJSON(url, ok, err) { - // Avoid checking ok and err on each use. - var defaultCallback = (_value) => undefined; - ok = ok || defaultCallback; - err = err || defaultCallback; - - var request = new XMLHttpRequest(); - request.overrideMimeType("application/json"); - request.open('GET', url, true); - request.addEventListener('load', function (event) { - var response = event.target.response; - if (this.status === 200) { - var json; - try { - json = JSON.parse(response); - } catch (e) { - err(`utils.loadJSON(): Failed to parse JSON response - ${e}`); - } - ok(json); - } else if (this.status === 0) { - // Some browsers return HTTP Status 0 when using non-http protocol - // e.g. 'file://' or 'data://'. Handle as success. - console.warn('loadFile: HTTP Status 0 received.'); - try { - ok(JSON.parse(response)); - } catch (e) { - err(`utils.loadJSON(): Failed to parse JSON response - ${e}`); - } - } else { - err(event); - } - }, false); - - request.addEventListener('error', function (event) { - err(event); - }, false); - request.send(null); -} - -/** - * @private - */ -function loadArraybuffer$1(url, ok, err) { - // Check for data: URI - var defaultCallback = (_value) => undefined; - ok = ok || defaultCallback; - err = err || defaultCallback; - const dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/; - const dataUriRegexResult = url.match(dataUriRegex); - if (dataUriRegexResult) { // Safari can't handle data URIs through XMLHttpRequest - const isBase64 = !!dataUriRegexResult[2]; - var data = dataUriRegexResult[3]; - data = window.decodeURIComponent(data); - if (isBase64) { - data = window.atob(data); - } - try { - const buffer = new ArrayBuffer(data.length); - const view = new Uint8Array(buffer); - for (var i = 0; i < data.length; i++) { - view[i] = data.charCodeAt(i); - } - core.scheduleTask(() => { - ok(buffer); - }); - } catch (error) { - core.scheduleTask(() => { - err(error); - }); - } - } else { - const request = new XMLHttpRequest(); - request.open('GET', url, true); - request.responseType = 'arraybuffer'; - request.onreadystatechange = function () { - if (request.readyState === 4) { - if (request.status === 200) { - ok(request.response); - } else { - err('loadArrayBuffer error : ' + request.response); - } - } - }; - request.send(null); - } -} - -/** - Tests if the given object is an array - @private - */ -function isArray$1(value) { - return value && !(value.propertyIsEnumerable('length')) && typeof value === 'object' && typeof value.length === 'number'; -} - -/** - Tests if the given value is a string - @param value - @returns {Boolean} - @private - */ -function isString(value) { - return (typeof value === 'string' || value instanceof String); -} - -/** - Tests if the given value is a number - @param value - @returns {Boolean} - @private - */ -function isNumeric(value) { - return !isNaN(parseFloat(value)) && isFinite(value); -} - -/** - Tests if the given value is an ID - @param value - @returns {Boolean} - @private - */ -function isID(value) { - return utils.isString(value) || utils.isNumeric(value); -} - -/** - Tests if the given components are the same, where the components can be either IDs or instances. - @param c1 - @param c2 - @returns {Boolean} - @private - */ -function isSameComponent(c1, c2) { - if (!c1 || !c2) { - return false; - } - const id1 = (utils.isNumeric(c1) || utils.isString(c1)) ? `${c1}` : c1.id; - const id2 = (utils.isNumeric(c2) || utils.isString(c2)) ? `${c2}` : c2.id; - return id1 === id2; -} - -/** - Tests if the given value is a function - @param value - @returns {Boolean} - @private - */ -function isFunction$1(value) { - return (typeof value === "function"); -} - -/** - Tests if the given value is a JavaScript JSON object, eg, ````{ foo: "bar" }````. - @param value - @returns {Boolean} - @private - */ -function isObject$1(value) { - const objectConstructor = {}.constructor; - return (!!value && value.constructor === objectConstructor); -} - -/** Returns a shallow copy - */ -function copy(o) { - return utils.apply(o, {}); -} - -/** Add properties of o to o2, overwriting them on o2 if already there - */ -function apply(o, o2) { - for (const name in o) { - if (o.hasOwnProperty(name)) { - o2[name] = o[name]; - } - } - return o2; -} - -/** - Add non-null/defined properties of o to o2 - @private - */ -function apply2(o, o2) { - for (const name in o) { - if (o.hasOwnProperty(name)) { - if (o[name] !== undefined && o[name] !== null) { - o2[name] = o[name]; - } - } - } - return o2; -} - -/** - Add properties of o to o2 where undefined or null on o2 - @private - */ -function applyIf(o, o2) { - for (const name in o) { - if (o.hasOwnProperty(name)) { - if (o2[name] === undefined || o2[name] === null) { - o2[name] = o[name]; - } - } - } - return o2; -} - -/** - Returns true if the given map is empty. - @param obj - @returns {Boolean} - @private - */ -function isEmptyObject$1(obj) { - for (const name in obj) { - if (obj.hasOwnProperty(name)) { - return false; - } - } - return true; -} - -/** - Returns the given ID as a string, in quotes if the ID was a string to begin with. - - This is useful for logging IDs. - - @param {Number| String} id The ID - @returns {String} - @private - */ -function inQuotes(id) { - return utils.isNumeric(id) ? (`${id}`) : (`'${id}'`); -} - -/** - Returns the concatenation of two typed arrays. - @param a - @param b - @returns {*|a} - @private - */ -function concat(a, b) { - const c = new a.constructor(a.length + b.length); - c.set(a); - c.set(b, a.length); - return c; -} - -function flattenParentChildHierarchy(root) { - var list = []; - - function visit(node) { - node.id = node.uuid; - delete node.oid; - list.push(node); - var children = node.children; - - if (children) { - for (var i = 0, len = children.length; i < len; i++) { - const child = children[i]; - child.parent = node.id; - visit(children[i]); - } - } - node.children = []; - } - - visit(root); - return list; -} - -/** - * @private - */ -const utils = { - xmlToJson: xmlToJson, - clone: clone, - compressGuid: compressGuid, - findNodeOfType: findNodeOfType, - timeout: timeout, - httpRequest: httpRequest, - loadJSON: loadJSON, - loadArraybuffer: loadArraybuffer$1, - queryString: queryString, - isArray: isArray$1, - isString: isString, - isNumeric: isNumeric, - isID: isID, - isSameComponent: isSameComponent, - isFunction: isFunction$1, - isObject: isObject$1, - copy: copy, - apply: apply, - apply2: apply2, - applyIf: applyIf, - isEmptyObject: isEmptyObject$1, - inQuotes: inQuotes, - concat: concat, - flattenParentChildHierarchy: flattenParentChildHierarchy -}; - -const scenesRenderInfo = {}; // Used for throttling FPS for each Scene -const sceneIDMap = new Map$1(); // Ensures unique scene IDs -const taskQueue = new Queue(); // Task queue, which is pumped on each frame; tasks are pushed to it with calls to xeokit.schedule -const tickEvent = {sceneId: null, time: null, startTime: null, prevTime: null, deltaTime: null}; -const taskBudget = 10; // Millisecs we're allowed to spend on tasks in each frame -const fpsSamples = []; -const numFPSSamples = 30; - -let lastTime = 0; -let elapsedTime; -let totalFPS = 0; - - -/** - * @private - */ -function Core() { - - /** - Semantic version number. The value for this is set by an expression that's concatenated to - the end of the built binary by the xeokit build script. - @property version - @namespace xeokit - @type {String} - */ - this.version = "1.0.0"; - - /** - Existing {@link Scene}s , mapped to their IDs - @property scenes - @namespace xeokit - @type {Scene} - */ - this.scenes = {}; - - this._superTypes = {}; // For each component type, a list of its supertypes, ordered upwards in the hierarchy. - - /** - * Registers a scene on xeokit. - * This is called within the xeokit.Scene constructor. - * @private - */ - this._addScene = function (scene) { - if (scene.id) { // User-supplied ID - if (core.scenes[scene.id]) { - console.error(`[ERROR] Scene ${utils.inQuotes(scene.id)} already exists`); - return; - } - } else { // Auto-generated ID - scene.id = sceneIDMap.addItem({}); - } - core.scenes[scene.id] = scene; - const ticksPerOcclusionTest = scene.ticksPerOcclusionTest; - const ticksPerRender = scene.ticksPerRender; - scenesRenderInfo[scene.id] = { - ticksPerOcclusionTest: ticksPerOcclusionTest, - ticksPerRender: ticksPerRender, - renderCountdown: ticksPerRender - }; - stats.components.scenes++; - scene.once("destroyed", () => { // Unregister destroyed scenes - sceneIDMap.removeItem(scene.id); - delete core.scenes[scene.id]; - delete scenesRenderInfo[scene.id]; - stats.components.scenes--; - }); - }; - - /** - * @private - */ - this.clear = function () { - let scene; - for (const id in core.scenes) { - if (core.scenes.hasOwnProperty(id)) { - scene = core.scenes[id]; - // Only clear the default Scene - // but destroy all the others - if (id === "default.scene") { - scene.clear(); - } else { - scene.destroy(); - delete core.scenes[scene.id]; - } - } - } - }; - - /** - * Schedule a task to run at the next frame. - * - * Internally, this pushes the task to a FIFO queue. Within each frame interval, xeokit processes the queue - * for a certain period of time, popping tasks and running them. After each frame interval, tasks that did not - * get a chance to run during the task are left in the queue to be run next time. - * - * @param {Function} callback Callback that runs the task. - * @param {Object} [scope] Scope for the callback. - */ - this.scheduleTask = function (callback, scope = null) { - taskQueue.push(callback); - taskQueue.push(scope); - }; - - this.runTasks = function (until = -1) { // Pops and processes tasks in the queue, until the given number of milliseconds has elapsed. - let time = (new Date()).getTime(); - let callback; - let scope; - let tasksRun = 0; - while (taskQueue.length > 0 && (until < 0 || time < until)) { - callback = taskQueue.shift(); - scope = taskQueue.shift(); - if (scope) { - callback.call(scope); - } else { - callback(); - } - time = (new Date()).getTime(); - tasksRun++; - } - return tasksRun; - }; - - this.getNumTasks = function () { - return taskQueue.length; - }; -} - -/** - * @private - * @type {Core} - */ -const core = new Core(); - -const frame = function () { - let time = Date.now(); - elapsedTime = time - lastTime; - if (lastTime > 0 && elapsedTime > 0) { // Log FPS stats - var newFPS = 1000 / elapsedTime; // Moving average of FPS - totalFPS += newFPS; - fpsSamples.push(newFPS); - if (fpsSamples.length >= numFPSSamples) { - totalFPS -= fpsSamples.shift(); - } - stats.frame.fps = Math.round(totalFPS / fpsSamples.length); - } - for (let id in core.scenes) { - core.scenes[id].compile(); - } - runTasks(time); - lastTime = time; -}; - -function customSetInterval(callback, interval) { - let expected = Date.now() + interval; - function loop() { - const elapsed = Date.now() - expected; - callback(); - expected += interval; - setTimeout(loop, Math.max(0, interval - elapsed)); - } - loop(); - return { - cancel: function() { - // No need to do anything, setTimeout cannot be directly cancelled - } - }; -} - -customSetInterval(() => { - frame(); -}, 100); - -const renderFrame = function () { - let time = Date.now(); - elapsedTime = time - lastTime; - if (lastTime > 0 && elapsedTime > 0) { // Log FPS stats - var newFPS = 1000 / elapsedTime; // Moving average of FPS - totalFPS += newFPS; - fpsSamples.push(newFPS); - if (fpsSamples.length >= numFPSSamples) { - totalFPS -= fpsSamples.shift(); - } - stats.frame.fps = Math.round(totalFPS / fpsSamples.length); - } - runTasks(time); - fireTickEvents(time); - renderScenes(); - (window.requestPostAnimationFrame !== undefined) ? window.requestPostAnimationFrame(frame) : requestAnimationFrame(renderFrame); -}; - -renderFrame(); - -function runTasks(time) { // Process as many enqueued tasks as we can within the per-frame task budget - const tasksRun = core.runTasks(time + taskBudget); - const tasksScheduled = core.getNumTasks(); - stats.frame.tasksRun = tasksRun; - stats.frame.tasksScheduled = tasksScheduled; - stats.frame.tasksBudget = taskBudget; -} - -function fireTickEvents(time) { // Fire tick event on each Scene - tickEvent.time = time; - for (var id in core.scenes) { - if (core.scenes.hasOwnProperty(id)) { - var scene = core.scenes[id]; - tickEvent.sceneId = id; - tickEvent.startTime = scene.startTime; - tickEvent.deltaTime = tickEvent.prevTime != null ? tickEvent.time - tickEvent.prevTime : 0; - /** - * Fired on each game loop iteration. - * - * @event tick - * @param {String} sceneID The ID of this Scene. - * @param {Number} startTime The time in seconds since 1970 that this Scene was instantiated. - * @param {Number} time The time in seconds since 1970 of this "tick" event. - * @param {Number} prevTime The time of the previous "tick" event from this Scene. - * @param {Number} deltaTime The time in seconds since the previous "tick" event from this Scene. - */ - scene.fire("tick", tickEvent, true); - } - } - tickEvent.prevTime = time; -} - -function renderScenes() { - const scenes = core.scenes; - const forceRender = false; - let scene; - let renderInfo; - let ticksPerOcclusionTest; - let ticksPerRender; - let id; - for (id in scenes) { - if (scenes.hasOwnProperty(id)) { - - scene = scenes[id]; - renderInfo = scenesRenderInfo[id]; - - if (!renderInfo) { - renderInfo = scenesRenderInfo[id] = {}; // FIXME - } - - ticksPerOcclusionTest = scene.ticksPerOcclusionTest; - if (renderInfo.ticksPerOcclusionTest !== ticksPerOcclusionTest) { - renderInfo.ticksPerOcclusionTest = ticksPerOcclusionTest; - renderInfo.renderCountdown = ticksPerOcclusionTest; - } - if (--scene.occlusionTestCountdown <= 0) { - scene.doOcclusionTest(); - scene.occlusionTestCountdown = ticksPerOcclusionTest; - } - - ticksPerRender = scene.ticksPerRender; - if (renderInfo.ticksPerRender !== ticksPerRender) { - renderInfo.ticksPerRender = ticksPerRender; - renderInfo.renderCountdown = ticksPerRender; - } - if (--renderInfo.renderCountdown === 0) { - scene.render(forceRender); - renderInfo.renderCountdown = ticksPerRender; - } - } - } -} - -/** - * @desc Base class for all xeokit components. - * - * ## Component IDs - * - * Every Component has an ID that's unique within the parent {@link Scene}. xeokit generates - * the IDs automatically by default, however you can also specify them yourself. In the example below, we're creating a - * scene comprised of {@link Scene}, {@link Material}, {@link ReadableGeometry} and - * {@link Mesh} components, while letting xeokit generate its own ID for - * the {@link ReadableGeometry}: - * - *````JavaScript - * import {Viewer, Mesh, buildTorusGeometry, ReadableGeometry, PhongMaterial, Texture, Fresnel} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [0, 0, 5]; - * viewer.scene.camera.look = [0, 0, 0]; - * viewer.scene.camera.up = [0, 1, 0]; - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildTorusGeometry({ - * center: [0, 0, 0], - * radius: 1.5, - * tube: 0.5, - * radialSegments: 32, - * tubeSegments: 24, - * arc: Math.PI * 2.0 - * }), - * material: new PhongMaterial(viewer.scene, { - * id: "myMaterial", - * ambient: [0.9, 0.3, 0.9], - * shininess: 30, - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }), - * specularFresnel: new Fresnel(viewer.scene, { - * leftColor: [1.0, 1.0, 1.0], - * rightColor: [0.0, 0.0, 0.0], - * power: 4 - * }) - * }) - * }); - *```` - * - * We can then find those components like this: - * - * ````javascript - * // Find the Material - * var material = viewer.scene.components["myMaterial"]; - * - * // Find all PhongMaterials in the Scene - * var phongMaterials = viewer.scene.types["PhongMaterial"]; - * - * // Find our Material within the PhongMaterials - * var materialAgain = phongMaterials["myMaterial"]; - * ```` - * - * ## Restriction on IDs - * - * Auto-generated IDs are of the form ````"__0"````, ````"__1"````, ````"__2"```` ... and so on. - * - * Scene maintains a map of these IDs, along with a counter that it increments each time it generates a new ID. - * - * If Scene has created the IDs listed above, and we then destroy the ````Component```` with ID ````"__1"````, - * Scene will mark that ID as available, and will reuse it for the next default ID. - * - * Therefore, two restrictions your on IDs: - * - * * don't use IDs that begin with two underscores, and - * * don't reuse auto-generated IDs of destroyed Components. - * - * ## Logging - * - * Components have methods to log ID-prefixed messages to the JavaScript console: - * - * ````javascript - * material.log("Everything is fine, situation normal."); - * material.warn("Wait, whats that red light?"); - * material.error("Aw, snap!"); - * ```` - * - * The logged messages will look like this in the console: - * - * ````text - * [LOG] myMaterial: Everything is fine, situation normal. - * [WARN] myMaterial: Wait, whats that red light.. - * [ERROR] myMaterial: Aw, snap! - * ```` - * - * ## Destruction - * - * Get notification of destruction of Components: - * - * ````javascript - * material.once("destroyed", function() { - * this.log("Component was destroyed: " + this.id); - * }); - * ```` - * - * Or get notification of destruction of any Component within its {@link Scene}: - * - * ````javascript - * scene.on("componentDestroyed", function(component) { - * this.log("Component was destroyed: " + component.id); - * }); - * ```` - * - * Then destroy a component like this: - * - * ````javascript - * material.destroy(); - * ```` - */ -class Component { - - /** - @private - */ - get type() { - return "Component"; - } - - /** - * @private - */ - get isComponent() { - return true; - } - - constructor(owner = null, cfg = {}) { - - /** - * The parent {@link Scene} that contains this Component. - * - * @property scene - * @type {Scene} - * @final - */ - this.scene = null; - - if (this.type === "Scene") { - this.scene = this; - /** - * The viewer that contains this Scene. - * @property viewer - * @type {Viewer} - */ - this.viewer = cfg.viewer; - } else { - if (owner.type === "Scene") { - this.scene = owner; - } else if (owner instanceof Component) { - this.scene = owner.scene; - } else { - throw "Invalid param: owner must be a Component" - } - this._owner = owner; - } - - this._dontClear = !!cfg.dontClear; // Prevent Scene#clear from destroying this component - - this._renderer = this.scene._renderer; - - /** - Arbitrary, user-defined metadata on this component. - - @property metadata - @type Object - */ - this.meta = cfg.meta || {}; - - - /** - * ID of this Component, unique within the {@link Scene}. - * - * Components are mapped by this ID in {@link Scene#components}. - * - * @property id - * @type {String|Number} - */ - this.id = cfg.id; // Auto-generated by Scene by default - - /** - True as soon as this Component has been destroyed - - @property destroyed - @type {Boolean} - */ - this.destroyed = false; - - this._attached = {}; // Attached components with names. - this._attachments = null; // Attached components keyed to IDs - lazy-instantiated - this._subIdMap = null; // Subscription subId pool - this._subIdEvents = null; // Subscription subIds mapped to event names - this._eventSubs = null; // Event names mapped to subscribers - this._eventSubsNum = null; - this._events = null; // Maps names to events - this._eventCallDepth = 0; // Helps us catch stack overflows from recursive events - this._ownedComponents = null; // // Components created with #create - lazy-instantiated - - if (this !== this.scene) { // Don't add scene to itself - this.scene._addComponent(this); // Assigns this component an automatic ID if not yet assigned - } - - this._updateScheduled = false; // True when #_update will be called on next tick - - if (owner) { - owner._own(this); - } - } - - // /** - // * Unique ID for this Component within its {@link Scene}. - // * - // * @property - // * @type {String} - // */ - // get id() { - // return this._id; - // } - - /** - Indicates that we need to redraw the scene. - - This is called by certain subclasses after they have made some sort of state update that requires the - renderer to perform a redraw. - - For example: a {@link Mesh} calls this on itself whenever you update its - {@link Mesh#layer} property, which manually controls its render order in - relation to other Meshes. - - If this component has a ````castsShadow```` property that's set ````true````, then this will also indicate - that the renderer needs to redraw shadow map associated with this component. Components like - {@link DirLight} have that property set when they produce light that creates shadows, while - components like {@link Mesh"}}layer{{/crossLink}} have that property set when they cast shadows. - - @protected - */ - glRedraw() { - if (!this._renderer) { // Called from a constructor - return; - } - this._renderer.imageDirty(); - if (this.castsShadow) { // Light source or object - this._renderer.shadowsDirty(); - } - } - - /** - Indicates that we need to re-sort the renderer's state-ordered drawables list. - - For efficiency, the renderer keeps its list of drawables ordered so that runs of the same state updates can be - combined. This method is called by certain subclasses after they have made some sort of state update that would - require re-ordering of the drawables list. - - For example: a {@link DirLight} calls this on itself whenever you update {@link DirLight#dir}. - - @protected - */ - glResort() { - if (!this._renderer) { // Called from a constructor - return; - } - this._renderer.needStateSort(); - } - - /** - * The {@link Component} that owns the lifecycle of this Component, if any. - * - * When that component is destroyed, this component will be automatically destroyed also. - * - * Will be null if this Component has no owner. - * - * @property owner - * @type {Component} - */ - get owner() { - return this._owner; - } - - /** - * Tests if this component is of the given type, or is a subclass of the given type. - * @type {Boolean} - */ - isType(type) { - return this.type === type; - } - - /** - * Fires an event on this component. - * - * Notifies existing subscribers to the event, optionally retains the event to give to - * any subsequent notifications on the event as they are made. - * - * @param {String} event The event type name - * @param {Object} value The event parameters - * @param {Boolean} [forget=false] When true, does not retain for subsequent subscribers - */ - fire(event, value, forget) { - if (!this._events) { - this._events = {}; - } - if (!this._eventSubs) { - this._eventSubs = {}; - this._eventSubsNum = {}; - } - if (forget !== true) { - this._events[event] = value || true; // Save notification - } - const subs = this._eventSubs[event]; - let sub; - if (subs) { // Notify subscriptions - for (const subId in subs) { - if (subs.hasOwnProperty(subId)) { - sub = subs[subId]; - this._eventCallDepth++; - if (this._eventCallDepth < 300) { - sub.callback.call(sub.scope, value); - } else { - this.error("fire: potential stack overflow from recursive event '" + event + "' - dropping this event"); - } - this._eventCallDepth--; - } - } - } - } - - /** - * Subscribes to an event on this component. - * - * The callback is be called with this component as scope. - * - * @param {String} event The event - * @param {Function} callback Called fired on the event - * @param {Object} [scope=this] Scope for the callback - * @return {String} Handle to the subscription, which may be used to unsubscribe with {@link #off}. - */ - on(event, callback, scope) { - if (!this._events) { - this._events = {}; - } - if (!this._subIdMap) { - this._subIdMap = new Map$1(); // Subscription subId pool - } - if (!this._subIdEvents) { - this._subIdEvents = {}; - } - if (!this._eventSubs) { - this._eventSubs = {}; - } - if (!this._eventSubsNum) { - this._eventSubsNum = {}; - } - let subs = this._eventSubs[event]; - if (!subs) { - subs = {}; - this._eventSubs[event] = subs; - this._eventSubsNum[event] = 1; - } else { - this._eventSubsNum[event]++; - } - const subId = this._subIdMap.addItem(); // Create unique subId - subs[subId] = { - callback: callback, - scope: scope || this - }; - this._subIdEvents[subId] = event; - const value = this._events[event]; - if (value !== undefined) { // A publication exists, notify callback immediately - callback.call(scope || this, value); - } - return subId; - } - - /** - * Cancels an event subscription that was previously made with {@link Component#on} or {@link Component#once}. - * - * @param {String} subId Subscription ID - */ - off(subId) { - if (subId === undefined || subId === null) { - return; - } - if (!this._subIdEvents) { - return; - } - const event = this._subIdEvents[subId]; - if (event) { - delete this._subIdEvents[subId]; - const subs = this._eventSubs[event]; - if (subs) { - delete subs[subId]; - this._eventSubsNum[event]--; - } - this._subIdMap.removeItem(subId); // Release subId - } - } - - /** - * Subscribes to the next occurrence of the given event, then un-subscribes as soon as the event is subIdd. - * - * This is equivalent to calling {@link Component#on}, and then calling {@link Component#off} inside the callback function. - * - * @param {String} event Data event to listen to - * @param {Function} callback Called when fresh data is available at the event - * @param {Object} [scope=this] Scope for the callback - */ - once(event, callback, scope) { - const self = this; - const subId = this.on(event, - function (value) { - self.off(subId); - callback.call(scope || this, value); - }, - scope); - } - - /** - * Returns true if there are any subscribers to the given event on this component. - * - * @param {String} event The event - * @return {Boolean} True if there are any subscribers to the given event on this component. - */ - hasSubs(event) { - return (this._eventSubsNum && (this._eventSubsNum[event] > 0)); - } - - /** - * Logs a console debugging message for this component. - * - * The console message will have this format: *````[LOG] [ : ````* - * - * Also fires the message as a "log" event on the parent {@link Scene}. - * - * @param {String} message The message to log - */ - log(message) { - message = "[LOG]" + this._message(message); - window.console.log(message); - this.scene.fire("log", message); - } - - _message(message) { - return " [" + this.type + " " + utils.inQuotes(this.id) + "]: " + message; - } - - /** - * Logs a warning for this component to the JavaScript console. - * - * The console message will have this format: *````[WARN] [ =: ````* - * - * Also fires the message as a "warn" event on the parent {@link Scene}. - * - * @param {String} message The message to log - */ - warn(message) { - message = "[WARN]" + this._message(message); - window.console.warn(message); - this.scene.fire("warn", message); - } - - /** - * Logs an error for this component to the JavaScript console. - * - * The console message will have this format: *````[ERROR] [ =: ````* - * - * Also fires the message as an "error" event on the parent {@link Scene}. - * - * @param {String} message The message to log - */ - error(message) { - message = "[ERROR]" + this._message(message); - window.console.error(message); - this.scene.fire("error", message); - } - - /** - * Adds a child component to this. - * - * When component not given, attaches the scene's default instance for the given name (if any). - * Publishes the new child component on this component, keyed to the given name. - * - * @param {*} params - * @param {String} params.name component name - * @param {Component} [params.component] The component - * @param {String} [params.type] Optional expected type of base type of the child; when supplied, will - * cause an exception if the given child is not the same type or a subtype of this. - * @param {Boolean} [params.sceneDefault=false] - * @param {Boolean} [params.sceneSingleton=false] - * @param {Function} [params.onAttached] Optional callback called when component attached - * @param {Function} [params.onAttached.callback] Callback function - * @param {Function} [params.onAttached.scope] Optional scope for callback - * @param {Function} [params.onDetached] Optional callback called when component is detached - * @param {Function} [params.onDetached.callback] Callback function - * @param {Function} [params.onDetached.scope] Optional scope for callback - * @param {{String:Function}} [params.on] Callbacks to subscribe to properties on component - * @param {Boolean} [params.recompiles=true] When true, fires "dirty" events on this component - * @private - */ - _attach(params) { - - const name = params.name; - - if (!name) { - this.error("Component 'name' expected"); - return; - } - - let component = params.component; - const sceneDefault = params.sceneDefault; - const sceneSingleton = params.sceneSingleton; - const type = params.type; - const on = params.on; - const recompiles = params.recompiles !== false; - - // True when child given as config object, where parent manages its instantiation and destruction - let managingLifecycle = false; - - if (component) { - - if (utils.isNumeric(component) || utils.isString(component)) { - - // Component ID given - // Both numeric and string IDs are supported - - const id = component; - - component = this.scene.components[id]; - - if (!component) { - - // Quote string IDs in errors - - this.error("Component not found: " + utils.inQuotes(id)); - return; - } - } - } - - if (!component) { - - if (sceneSingleton === true) { - - // Using the first instance of the component type we find - - const instances = this.scene.types[type]; - for (const id2 in instances) { - if (instances.hasOwnProperty) { - component = instances[id2]; - break; - } - } - - if (!component) { - this.error("Scene has no default component for '" + name + "'"); - return null; - } - - } else if (sceneDefault === true) { - - // Using a default scene component - - component = this.scene[name]; - - if (!component) { - this.error("Scene has no default component for '" + name + "'"); - return null; - } - } - } - - if (component) { - - if (component.scene.id !== this.scene.id) { - this.error("Not in same scene: " + component.type + " " + utils.inQuotes(component.id)); - return; - } - - if (type) { - - if (!component.isType(type)) { - this.error("Expected a " + type + " type or subtype: " + component.type + " " + utils.inQuotes(component.id)); - return; - } - } - } - - if (!this._attachments) { - this._attachments = {}; - } - - const oldComponent = this._attached[name]; - let subs; - let i; - let len; - - if (oldComponent) { - - if (component && oldComponent.id === component.id) { - - // Reject attempt to reattach same component - return; - } - - const oldAttachment = this._attachments[oldComponent.id]; - - // Unsubscribe from events on old component - - subs = oldAttachment.subs; - - for (i = 0, len = subs.length; i < len; i++) { - oldComponent.off(subs[i]); - } - - delete this._attached[name]; - delete this._attachments[oldComponent.id]; - - const onDetached = oldAttachment.params.onDetached; - if (onDetached) { - if (utils.isFunction(onDetached)) { - onDetached(oldComponent); - } else { - onDetached.scope ? onDetached.callback.call(onDetached.scope, oldComponent) : onDetached.callback(oldComponent); - } - } - - if (oldAttachment.managingLifecycle) { - - // Note that we just unsubscribed from all events fired by the child - // component, so destroying it won't fire events back at us now. - - oldComponent.destroy(); - } - } - - if (component) { - - // Set and publish the new component on this component - - const attachment = { - params: params, - component: component, - subs: [], - managingLifecycle: managingLifecycle - }; - - attachment.subs.push( - component.once("destroyed", - function () { - attachment.params.component = null; - this._attach(attachment.params); - }, - this)); - - if (recompiles) { - attachment.subs.push( - component.on("dirty", - function () { - this.fire("dirty", this); - }, - this)); - } - - this._attached[name] = component; - this._attachments[component.id] = attachment; - - // Bind destruct listener to new component to remove it - // from this component when destroyed - - const onAttached = params.onAttached; - if (onAttached) { - if (utils.isFunction(onAttached)) { - onAttached(component); - } else { - onAttached.scope ? onAttached.callback.call(onAttached.scope, component) : onAttached.callback(component); - } - } - - if (on) { - - let event; - let subIdr; - let callback; - let scope; - - for (event in on) { - if (on.hasOwnProperty(event)) { - - subIdr = on[event]; - - if (utils.isFunction(subIdr)) { - callback = subIdr; - scope = null; - } else { - callback = subIdr.callback; - scope = subIdr.scope; - } - - if (!callback) { - continue; - } - - attachment.subs.push(component.on(event, callback, scope)); - } - } - } - } - - if (recompiles) { - this.fire("dirty", this); // FIXME: May trigger spurous mesh recompilations unless able to limit with param? - } - - this.fire(name, component); // Component can be null - - return component; - } - - _checkComponent(expectedType, component) { - if (!component.isComponent) { - if (utils.isID(component)) { - const id = component; - component = this.scene.components[id]; - if (!component) { - this.error("Component not found: " + id); - return; - } - } else { - this.error("Expected a Component or ID"); - return; - } - } - if (expectedType !== component.type) { - this.error("Expected a " + expectedType + " Component"); - return; - } - if (component.scene.id !== this.scene.id) { - this.error("Not in same scene: " + component.type); - return; - } - return component; - } - - _checkComponent2(expectedTypes, component) { - if (!component.isComponent) { - if (utils.isID(component)) { - const id = component; - component = this.scene.components[id]; - if (!component) { - this.error("Component not found: " + id); - return; - } - } else { - this.error("Expected a Component or ID"); - return; - } - } - if (component.scene.id !== this.scene.id) { - this.error("Not in same scene: " + component.type); - return; - } - for (var i = 0, len = expectedTypes.length; i < len; i++) { - if (expectedTypes[i] === component.type) { - return component; - } - } - this.error("Expected component types: " + expectedTypes); - return null; - } - - _own(component) { - if (!this._ownedComponents) { - this._ownedComponents = {}; - } - if (!this._ownedComponents[component.id]) { - this._ownedComponents[component.id] = component; - } - component.once("destroyed", () => { - delete this._ownedComponents[component.id]; - }, this); - } - - /** - * Protected method, called by sub-classes to queue a call to _update(). - * @protected - * @param {Number} [priority=1] - */ - _needUpdate(priority) { - if (!this._updateScheduled) { - this._updateScheduled = true; - if (priority === 0) { - this._doUpdate(); - } else { - core.scheduleTask(this._doUpdate, this); - } - } - } - - /** - * @private - */ - _doUpdate() { - if (this._updateScheduled) { - this._updateScheduled = false; - if (this._update) { - this._update(); - } - } - } - - /** - * Schedule a task to perform on the next browser interval - * @param task - */ - scheduleTask(task) { - core.scheduleTask(task, null); - } - - /** - * Protected virtual template method, optionally implemented - * by sub-classes to perform a scheduled task. - * - * @protected - */ - _update() { - } - - /** - * Destroys all {@link Component}s that are owned by this. These are Components that were instantiated with - * this Component as their first constructor argument. - */ - clear() { - if (this._ownedComponents) { - for (var id in this._ownedComponents) { - if (this._ownedComponents.hasOwnProperty(id)) { - const component = this._ownedComponents[id]; - component.destroy(); - delete this._ownedComponents[id]; - } - } - } - } - - /** - * Destroys this component. - */ - destroy() { - - if (this.destroyed) { - return; - } - - /** - * Fired when this Component is destroyed. - * @event destroyed - */ - this.fire("destroyed", this.destroyed = true); // Must fire before we blow away subscription maps, below - - // Unsubscribe from child components and destroy then - - let id; - let attachment; - let component; - let subs; - let i; - let len; - - if (this._attachments) { - for (id in this._attachments) { - if (this._attachments.hasOwnProperty(id)) { - attachment = this._attachments[id]; - component = attachment.component; - subs = attachment.subs; - for (i = 0, len = subs.length; i < len; i++) { - component.off(subs[i]); - } - if (attachment.managingLifecycle) { - component.destroy(); - } - } - } - } - - if (this._ownedComponents) { - for (id in this._ownedComponents) { - if (this._ownedComponents.hasOwnProperty(id)) { - component = this._ownedComponents[id]; - component.destroy(); - delete this._ownedComponents[id]; - } - } - } - - this.scene._removeComponent(this); - - // Memory leak avoidance - this._attached = {}; - this._attachments = null; - this._subIdMap = null; - this._subIdEvents = null; - this._eventSubs = null; - this._events = null; - this._eventCallDepth = 0; - this._ownedComponents = null; - this._updateScheduled = false; - this._renderer = null; - } -} - -const tempVec3a$i = math.vec3(); -const tempVec3b$b = math.vec3(); -const tempMat4a$1 = math.mat4(); - -/** - * @private - */ -class FrustumPlane { - - constructor() { - this.normal = math.vec3(); - this.offset = 0; - this.testVertex = math.vec3(); - } - - set(nx, ny, nz, offset) { - const s = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz); - this.normal[0] = nx * s; - this.normal[1] = ny * s; - this.normal[2] = nz * s; - this.offset = offset * s; - this.testVertex[0] = (this.normal[0] >= 0.0) ? 1 : 0; - this.testVertex[1] = (this.normal[1] >= 0.0) ? 1 : 0; - this.testVertex[2] = (this.normal[2] >= 0.0) ? 1 : 0; - } -} - -/** - * @private - */ -class Frustum$1 { - constructor() { - this.planes = [ - new FrustumPlane(), new FrustumPlane(), new FrustumPlane(), - new FrustumPlane(), new FrustumPlane(), new FrustumPlane() - ]; - } -} - -Frustum$1.INSIDE = 0; -Frustum$1.INTERSECT = 1; -Frustum$1.OUTSIDE = 2; - -/** @private */ -function setFrustum(frustum, viewMat, projMat) { - - const m = math.mulMat4(projMat, viewMat, tempMat4a$1); - - const m0 = m[0]; - const m1 = m[1]; - const m2 = m[2]; - const m3 = m[3]; - const m4 = m[4]; - const m5 = m[5]; - const m6 = m[6]; - const m7 = m[7]; - const m8 = m[8]; - const m9 = m[9]; - const m10 = m[10]; - const m11 = m[11]; - const m12 = m[12]; - const m13 = m[13]; - const m14 = m[14]; - const m15 = m[15]; - - frustum.planes[0].set(m3 - m0, m7 - m4, m11 - m8, m15 - m12); - frustum.planes[1].set(m3 + m0, m7 + m4, m11 + m8, m15 + m12); - frustum.planes[2].set(m3 - m1, m7 - m5, m11 - m9, m15 - m13); - frustum.planes[3].set(m3 + m1, m7 + m5, m11 + m9, m15 + m13); - frustum.planes[4].set(m3 - m2, m7 - m6, m11 - m10, m15 - m14); - frustum.planes[5].set(m3 + m2, m7 + m6, m11 + m10, m15 + m14); -} - -/** @private */ -function frustumIntersectsAABB3(frustum, aabb) { - - let ret = Frustum$1.INSIDE; - - const min = tempVec3a$i; - const max = tempVec3b$b; - - min[0] = aabb[0]; - min[1] = aabb[1]; - min[2] = aabb[2]; - max[0] = aabb[3]; - max[1] = aabb[4]; - max[2] = aabb[5]; - - const bminmax = [min, max]; - - for (let i = 0; i < 6; ++i) { - const plane = frustum.planes[i]; - if (((plane.normal[0] * bminmax[plane.testVertex[0]][0]) + - (plane.normal[1] * bminmax[plane.testVertex[1]][1]) + - (plane.normal[2] * bminmax[plane.testVertex[2]][2]) + - (plane.offset)) < 0.0) { - return Frustum$1.OUTSIDE; - } - - if (((plane.normal[0] * bminmax[1 - plane.testVertex[0]][0]) + - (plane.normal[1] * bminmax[1 - plane.testVertex[1]][1]) + - (plane.normal[2] * bminmax[1 - plane.testVertex[2]][2]) + - (plane.offset)) < 0.0) { - ret = Frustum$1.INTERSECT; - } - } - - return ret; -} - -/** - * Picks a {@link Viewer}'s {@link Entity}s with a canvas-space 2D marquee box. - * - * [](https://xeokit.github.io/xeokit-sdk/examples/picking/#marqueePick_select) - * - * * [[Example 1: Select Objects with Marquee](https://xeokit.github.io/xeokit-sdk/examples/picking/#marqueePick_select)] - * * [[Example 2: View-Fit Objects with Marquee](https://xeokit.github.io/xeokit-sdk/examples/picking/#marqueePick_viewFit)] - * - * # Usage - * - * In the example below, we - * - * 1. Create a {@link Viewer}, arrange the {@link Camera} - * 2. Use an {@link XKTLoaderPlugin} to load a BIM model, - * 3. Create a {@link ObjectsKdTree3} to automatically index the `Viewer's` {@link Entity}s for fast spatial lookup, - * 4. Create a `MarqueePicker` to pick {@link Entity}s in the {@link Viewer}, using the {@link ObjectsKdTree3} to accelerate picking - * 5. Create a {@link MarqueePickerMouseControl} to perform the marquee-picking with the `MarqueePicker`, using mouse input to draw the marquee box on the `Viewer's` canvas. - * - * When the {@link MarqueePickerMouseControl} is active: - * - * * Long-click, drag and release on the canvas to define a marque box that picks {@link Entity}s. - * * Drag left-to-right to pick {@link Entity}s that intersect the box. - * * Drag right-to-left to pick {@link Entity}s that are fully inside the box. - * * On release, the `MarqueePicker` will fire a "picked" event with IDs of the picked {@link Entity}s, if any. - * * Handling that event, we mark the {@link Entity}s as selected. - * * Hold down CTRL to multi-pick. - * - * ````javascript - * import { - * Viewer, - * XKTLoaderPlugin, - * ObjectsKdTree3, - * MarqueePicker, - * MarqueePickerMouseControl - * } from "xeokit-sdk.es.js"; - * - * // 1 - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [14.9, 14.3, 5.4]; - * viewer.scene.camera.look = [6.5, 8.3, -4.1]; - * viewer.scene.camera.up = [-0.28, 0.9, -0.3]; - * - * // 2 - * - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * const sceneModel = xktLoader.load({ - * id: "myModel", - * src: "../../assets/models/xkt/v8/ifc/HolterTower.ifc.xkt" - * }); - * - * // 3 - * - * const objectsKdTree3 = new ObjectsKdTree3({viewer}); - * - * // 4 - * - * const marqueePicker = new MarqueePicker({viewer, objectsKdTree3}); - * - * // 5 - * - * const marqueePickerMouseControl = new MarqueePickerMouseControl({marqueePicker}); - * - * marqueePicker.on("clear", () => { - * viewer.scene.setObjectsSelected(viewer.scene.selectedObjectIds, false); - * }); - * - * marqueePicker.on("picked", (objectIds) => { - * viewer.scene.setObjectsSelected(objectIds, true); - * }); - * - * marqueePickerMouseControl.setActive(true); - * ```` - * - * # Design Notes - * - * * The {@link ObjectsKdTree3} can be shared with any other components that want to use it to spatially search for {@link Entity}s. - * * The {@link MarqueePickerMouseControl} can be replaced with other types of controllers (i.e. touch), or used alongside them. - * * The `MarqueePicker` has no input handlers of its own, and provides an API through which to programmatically control marquee picking. By firing the "picked" events, `MarqueePicker` implements the *Blackboard Pattern*. - */ -class MarqueePicker extends Component { - - /** - * Creates a MarqueePicker. - * - * @param {*} cfg Configuration - * @param {Viewer} cfg.viewer The Viewer to pick Entities from. - * @param {ObjectsKdTree3} cfg.objectsKdTree3 A k-d tree that indexes the Entities in the Viewer for fast spatial lookup. - */ - constructor(cfg = {}) { - - if (!cfg.viewer) { - throw "[MarqueePicker] Missing config: viewer"; - } - - if (!cfg.objectsKdTree3) { - throw "[MarqueePicker] Missing config: objectsKdTree3"; - } - - super(cfg.viewer.scene, cfg); - - this.viewer = cfg.viewer; - this._objectsKdTree3 = cfg.objectsKdTree3; - this._canvasMarqueeCorner1 = math.vec2(); - this._canvasMarqueeCorner2 = math.vec2(); - this._canvasMarquee = math.AABB2(); - this._marqueeFrustum = new Frustum$1(); - this._marqueeFrustumProjMat = math.mat4(); - this._pickMode = false; - - this._marqueeElement = document.createElement('div'); - document.body.appendChild(this._marqueeElement); - - this._marqueeElement.style.position = "absolute"; - this._marqueeElement.style["z-index"] = "40000005"; - this._marqueeElement.style.width = 8 + "px"; - this._marqueeElement.style.height = 8 + "px"; - this._marqueeElement.style.visibility = "hidden"; - this._marqueeElement.style.top = 0 + "px"; - this._marqueeElement.style.left = 0 + "px"; - this._marqueeElement.style["box-shadow"] = "0 2px 5px 0 #182A3D;"; - this._marqueeElement.style["opacity"] = 1.0; - this._marqueeElement.style["pointer-events"] = "none"; - } - - /** - * Sets the canvas-space position of the first marquee box corner. - * - * @param corner1 - */ - setMarqueeCorner1(corner1) { - this._canvasMarqueeCorner1.set(corner1); - this._canvasMarqueeCorner2.set(corner1); - this._updateMarquee(); - } - - /** - * Sets the canvas-space position of the second marquee box corner. - * - * @param corner2 - */ - setMarqueeCorner2(corner2) { - this._canvasMarqueeCorner2.set(corner2); - this._updateMarquee(); - } - - /** - * Sets both canvas-space corner positions of the marquee box. - * - * @param corner1 - * @param corner2 - */ - setMarquee(corner1, corner2) { - this._canvasMarqueeCorner1.set(corner1); - this._canvasMarqueeCorner2.set(corner2); - this._updateMarquee(); - } - - /** - * Sets if the marquee box is visible. - * - * @param {boolean} visible True if the marquee box is to be visible, else false. - */ - setMarqueeVisible(visible) { - this._marqueVisible = visible; - this._marqueeElement.style.visibility = visible ? "visible" : "hidden"; - } - - /** - * Gets if the marquee box is visible. - * - * @returns {boolean} True if the marquee box is visible, else false. - */ - getMarqueeVisible() { - return this._marqueVisible; - } - - /** - * Sets the pick mode. - * - * Supported pick modes are: - * - * * MarqueePicker.PICK_MODE_INSIDE - picks {@link Entity}s that are completely inside the marquee box. - * * MarqueePicker.PICK_MODE_INTERSECTS - picks {@link Entity}s that intersect the marquee box. - * - * @param {number} pickMode The pick mode. - */ - setPickMode(pickMode) { - if (pickMode !== MarqueePicker.PICK_MODE_INSIDE && pickMode !== MarqueePicker.PICK_MODE_INTERSECTS) { - throw "Illegal MarqueePicker pickMode: must be MarqueePicker.PICK_MODE_INSIDE or MarqueePicker.PICK_MODE_INTERSECTS"; - } - if (pickMode !== this._pickMode) { - this._marqueeElement.style["background-image"] = - pickMode === MarqueePicker.PICK_MODE_INSIDE - /* Solid */ ? "url(\"data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='6' ry='6' stroke='%23333' stroke-width='4'/%3e%3c/svg%3e\")" - /* Dashed */ : "url(\"data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='6' ry='6' stroke='%23333' stroke-width='4' stroke-dasharray='6%2c 14' stroke-dashoffset='0' stroke-linecap='square'/%3e%3c/svg%3e\")"; - this._pickMode = pickMode; - } - } - - /** - * Gets the pick mode. - * - * Supported pick modes are: - * - * * MarqueePicker.PICK_MODE_INSIDE - picks {@link Entity}s that are completely inside the marquee box. - * * MarqueePicker.PICK_MODE_INTERSECTS - picks {@link Entity}s that intersect the marquee box. - * - * @returns {number} The pick mode. - */ - getPickMode() { - return this._pickMode; - } - - /** - * Fires a "clear" event on this MarqueePicker. - */ - clear() { - this.fire("clear", {}); - } - - /** - * Attempts to pick {@link Entity}s, using the current MarquePicker settings. - * - * Fires a "picked" event with the IDs of the {@link Entity}s that were picked, if any. - * - * @returns {string[]} IDs of the {@link Entity}s that were picked, if any - */ - pick() { - this._updateMarquee(); - this._buildMarqueeFrustum(); - const entityIds = []; - const visitNode = (node, intersects = Frustum$1.INTERSECT) => { - if (intersects === Frustum$1.INTERSECT) { - intersects = frustumIntersectsAABB3(this._marqueeFrustum, node.aabb); - } - if (intersects === Frustum$1.OUTSIDE) { - return; - } - if (node.entities) { - const entities = node.entities; - for (let i = 0, len = entities.length; i < len; i++) { - const entity = entities[i]; - if (!entity.visible) { - continue; - } - const entityAABB = entity.aabb; - if (this._pickMode === MarqueePicker.PICK_MODE_INSIDE) { - // Select entities that are completely inside marquee - const intersection = frustumIntersectsAABB3(this._marqueeFrustum, entityAABB); - if (intersection === Frustum$1.INSIDE) { - entityIds.push(entity.id); - } - } else { - // Select entities that are partially inside marquee - const intersection = frustumIntersectsAABB3(this._marqueeFrustum, entityAABB); - if (intersection !== Frustum$1.OUTSIDE) { - entityIds.push(entity.id); - } - } - } - } - if (node.left) { - visitNode(node.left, intersects); - } - if (node.right) { - visitNode(node.right, intersects); - } - }; - if (this._canvasMarquee[2] - this._canvasMarquee[0] > 3 || this._canvasMarquee[3] - this._canvasMarquee[1] > 3) { // Marquee pick if rectangle big enough - visitNode(this._objectsKdTree3.root); - } - this.fire("picked", entityIds); - return entityIds; - } - - _updateMarquee() { - this._canvasMarquee[0] = Math.min(this._canvasMarqueeCorner1[0], this._canvasMarqueeCorner2[0]); - this._canvasMarquee[1] = Math.min(this._canvasMarqueeCorner1[1], this._canvasMarqueeCorner2[1]); - this._canvasMarquee[2] = Math.max(this._canvasMarqueeCorner1[0], this._canvasMarqueeCorner2[0]); - this._canvasMarquee[3] = Math.max(this._canvasMarqueeCorner1[1], this._canvasMarqueeCorner2[1]); - this._marqueeElement.style.width = `${this._canvasMarquee[2] - this._canvasMarquee[0]}px`; - this._marqueeElement.style.height = `${this._canvasMarquee[3] - this._canvasMarquee[1]}px`; - this._marqueeElement.style.left = `${this._canvasMarquee[0]}px`; - this._marqueeElement.style.top = `${this._canvasMarquee[1]}px`; - } - - _buildMarqueeFrustum() { // https://github.com/xeokit/xeokit-sdk/issues/869#issuecomment-1165375770 - const canvas = this.viewer.scene.canvas.canvas; - const canvasWidth = canvas.clientWidth; - const canvasHeight = canvas.clientHeight; - const canvasLeft = canvas.clientLeft; - const canvasTop = canvas.clientTop; - const xCanvasToClip = 2.0 / canvasWidth; - const yCanvasToClip = 2.0 / canvasHeight; - const NEAR_SCALING = 17; - const ratio = canvas.clientHeight / canvas.clientWidth; - const FAR_PLANE = 10000; - const left = (this._canvasMarquee[0] - canvasLeft) * xCanvasToClip + -1; - const right = (this._canvasMarquee[2] - canvasLeft) * xCanvasToClip + -1; - const bottom = -(this._canvasMarquee[3] - canvasTop) * yCanvasToClip + 1; - const top = -(this._canvasMarquee[1] - canvasTop) * yCanvasToClip + 1; - const near = this.viewer.scene.camera.frustum.near * (NEAR_SCALING * ratio); - const far = FAR_PLANE; - math.frustumMat4( - left, - right, - bottom * ratio, - top * ratio, - near, - far, - this._marqueeFrustumProjMat, - ); - setFrustum(this._marqueeFrustum, this.viewer.scene.camera.viewMatrix, this._marqueeFrustumProjMat); - } - - /** - * Destroys this MarqueePicker. - * - * Does not destroy the {@link Viewer} or the {@link ObjectsKdTree3} provided to the constructor of this MarqueePicker. - */ - destroy() { - super.destroy(); - if (this._marqueeElement.parentElement) { - this._marqueeElement.parentElement.removeChild(this._marqueeElement); - this._marqueeElement = null; - this._objectsKdTree3 = null; - } - } -} - -/** - * Pick mode that picks {@link Entity}s that intersect the marquee box. - * - * @type {number} - */ -MarqueePicker.PICK_MODE_INTERSECTS = 0; - -/** - * Pick mode that picks {@link Entity}s that are completely inside the marquee box. - * - * @type {number} - */ -MarqueePicker.PICK_MODE_INSIDE = 1; - -/** - * Controls a {@link MarqueePicker} with mouse input. - * - * See {@link MarqueePicker} for usage example. - * - * When the MarqueePickerMouseControl is active: - * - * * Long-click, drag and release on the canvas to define a marque box that picks {@link Entity}s. - * * Drag left-to-right to pick Entities that intersect the box. - * * Drag right-to-left to pick Entities that are fully inside the box. - * * On release, the MarqueePicker will fire a "picked" event with IDs of the picked Entities , if any. - */ -class MarqueePickerMouseControl extends Component { - - /** - * Creates a new MarqueePickerMouseControl. - * - * @param {*} cfg Configuration - * @param {MarqueePicker} cfg.marqueePicker The MarqueePicker to control. - */ - constructor(cfg) { - - super(cfg.marqueePicker, cfg); - - const marqueePicker = cfg.marqueePicker; - const scene = marqueePicker.viewer.scene; - const canvas = scene.canvas.canvas; - - let pageStartX; - let pageStartY; - let pageEndX; - let pageEndY; - - let canvasStartX; - let canvasEndX; - - let isMouseDragging = false; - let isMouseDown = false; - let mouseWasUpOffCanvas = false; - let mouseDownTimer; - - canvas.addEventListener("mousedown", (e) => { - if (!this.getActive()) { - return; - } - if (e.button !== 0) { // Left button only - return; - } - mouseDownTimer = setTimeout(function () { - const input = marqueePicker.viewer.scene.input; - if (!input.keyDown[input.KEY_CTRL]) { // Clear selection unless CTRL down - marqueePicker.clear(); - } - pageStartX = e.pageX; - pageStartY = e.pageY; - canvasStartX = e.offsetX; - marqueePicker.setMarqueeCorner1([pageStartX, pageStartY]); - isMouseDragging = true; - marqueePicker.viewer.cameraControl.pointerEnabled = false; // Disable camera rotation - marqueePicker.setMarqueeVisible(true); - canvas.style.cursor = "crosshair"; - }, 400); - - isMouseDown = true; - }); - - canvas.addEventListener("mouseup", (e) => { - if (!this.getActive()) { - return; - } - if (!isMouseDragging && !mouseWasUpOffCanvas) { - return - } - if (e.button !== 0) { - return; - } - clearTimeout(mouseDownTimer); - pageEndX = e.pageX; - pageEndY = e.pageY; - const width = Math.abs(pageEndX - pageStartX); - const height = Math.abs(pageEndY - pageStartY); - isMouseDragging = false; - marqueePicker.viewer.cameraControl.pointerEnabled = true; // Enable camera rotation - if (mouseWasUpOffCanvas) { - mouseWasUpOffCanvas = false; - } - if (width > 3 || height > 3) { // Marquee pick if rectangle big enough - marqueePicker.pick(); - } - }); // Bubbling - - document.addEventListener("mouseup", (e) => { - if (!this.getActive()) { - return; - } - if (e.button !== 0) { // check if left button was clicked - return; - } - clearTimeout(mouseDownTimer); - if (!isMouseDragging) { - return - } - marqueePicker.setMarqueeVisible(false); - isMouseDragging = false; - isMouseDown = false; - mouseWasUpOffCanvas = true; - marqueePicker.viewer.cameraControl.pointerEnabled = true; - }, true); // Capturing - - canvas.addEventListener("mousemove", (e) => { - if (!this.getActive()) { - return; - } - if (e.button !== 0) { // check if left button was clicked - return; - } - - if (!isMouseDown) { - return; - } - - clearTimeout(mouseDownTimer); - - if (!isMouseDragging) { - return - } - - pageEndX = e.pageX; - pageEndY = e.pageY; - canvasEndX = e.offsetX; - - marqueePicker.setMarqueeVisible(true); - marqueePicker.setMarqueeCorner2([pageEndX, pageEndY]); - marqueePicker.setPickMode((canvasStartX < canvasEndX) ? MarqueePicker.PICK_MODE_INSIDE : MarqueePicker.PICK_MODE_INTERSECTS); - - }); - } - - /** - * Activates or deactivates this MarqueePickerMouseControl. - * - * @param {boolean} active Whether or not to activate. - */ - setActive(active) { - if (this._active === active) { - return; - } - this._active = active; - this.fire("active", this._active); - } - - /** - * Gets if this MarqueePickerMouseControl is active. - * - * @returns {boolean} - */ - getActive() { - return this._active; - } - - /** - * - */ - destroy() { - - } -} - -/** - * A PointerCircle shows a circle, centered at the position of the - * mouse or touch pointer. - */ -class PointerCircle { - - /** - * Constructs a new PointerCircle. - * @param viewer The Viewer - * @param [cfg] PointerCircle configuration. - * @param [cfg.active=true] Whether PointerCircle is active. The PointerCircle can only be shown when this is `true` (default). - */ - constructor(viewer, cfg = {}) { - - this.viewer = viewer; - this.scene = this.viewer.scene; - this._circleDiv = document.createElement('div'); - this.viewer.scene.canvas.canvas.parentNode.insertBefore(this._circleDiv, this.viewer.scene.canvas.canvas); - this._circleDiv.style.backgroundColor = "transparent"; - this._circleDiv.style.border = "2px solid green"; - this._circleDiv.style.borderRadius = "50px"; - this._circleDiv.style.width = "50px"; - this._circleDiv.style.height = "50px"; - this._circleDiv.style.margin = "-200px -200px"; - this._circleDiv.style.zIndex = "100000"; - this._circleDiv.style.position = "absolute"; - this._circleDiv.style.pointerEvents = "none"; - - this._circlePos = null; - - this._circleMaxRadius = 200; - this._circleMinRadius = 2; - - this._active = (cfg.active !== false); - this._visible = false; - - this._running = false; - this._destroyed = false; - } - - /** - * Show the circle at the given canvas coordinates and begin shrinking it. - */ - start(circlePos) { - if (this._destroyed) { - return; - } - this._circlePos = circlePos; - this._running = false; - this._circleRadius = this._circleMaxRadius; - this._circleDiv.style.borderRadius = `${this._circleRadius}px`; - this._circleDiv.style.marginLeft = `${this._circlePos[0] - this._circleRadius}px`; - this._circleDiv.style.marginTop = `${this._circlePos[1] - this._circleRadius}px`; - - const startValue = this._circleMaxRadius; - const endValue = 2; - let startTime; - const duration = 300; - - const animateCircle = (currentTime) => { - if (!this._running) { - return; - } - if (!startTime) { - startTime = currentTime; - } - - const elapsedTime = currentTime - startTime; - const progress = Math.min(elapsedTime / duration, 1); - const interpolatedValue = startValue + (endValue - startValue) * progress; - - this._circleRadius = interpolatedValue; - this._circleDiv.style.width = `${this._circleRadius}px`; - this._circleDiv.style.height = `${this._circleRadius}px`; - this._circleDiv.style.marginLeft = `${this._circlePos[0] - this._circleRadius / 2}px`; - this._circleDiv.style.marginTop = `${this._circlePos[1] - this._circleRadius / 2}px`; - - if (progress < 1) { - requestAnimationFrame(animateCircle); - } - }; - this._running = true; - requestAnimationFrame(animateCircle); - this._circleDiv.style.visibility = "visible"; - } - - /** - * Stop the shrinking circle and hide it. - */ - stop() { - if (this._destroyed) { - return; - } - this._running = false; - this._circleRadius = this._circleMaxRadius; - this._circleDiv.style.borderRadius = `${this._circleRadius}px`; - this._circleDiv.style.visibility = "hidden"; - } - - /** - * Sets the zoom factor for the lens. - * - * This is `2` by default. - * - * @param durationMs - */ - set durationMs(durationMs) { - this.stop(); - this._durationMs = durationMs; - } - - /** - * Gets the zoom factor for the lens. - * - * This is `2` by default. - * - * @returns Number - */ - get durationMs() { - return this._durationMs; - } - - /** - * Destroys this PointerCircle. - */ - destroy() { - if (!this._destroyed) { - this.stop(); - this._circleDiv.parentElement.removeChild(this._circleDiv); - this._destroyed = true; - } - } -} - -/** - * @desc Localization service for a {@link Viewer}. - * - * * A LocaleService is a container of string translations ("messages") for various locales. - * * A {@link Viewer} has its own default LocaleService at {@link Viewer#localeService}. - * * We can replace that with our own LocaleService, or a custom subclass, via the Viewer's constructor. - * * Viewer plugins that need localized translations will attempt to them for the currently active locale from the LocaleService. - * * Whenever we switch the LocaleService to a different locale, plugins will automatically refresh their translations for that locale. - * - * ## Usage - * - * In the example below, we'll create a {@link Viewer} that uses an {@link XKTLoaderPlugin} to load a BIM model, and a - * {@link NavCubePlugin}, which shows a camera navigation cube in the corner of the canvas. - * - * We'll also configure our Viewer with our own LocaleService instance, configured with English, Māori and French - * translations for our NavCubePlugin. - * - * We could instead have just used the Viewer's default LocaleService, but this example demonstrates how we might - * configure the Viewer our own custom LocaleService subclass. - * - * The translations fetched by our NavCubePlugin will be: - * - * * "NavCube.front" - * * "NavCube.back" - * * "NavCube.top" - * * "NavCube.bottom" - * * "NavCube.left" - * * "NavCube.right" - * - *
- * These are paths that resolve to our translations for the currently active locale, and are hard-coded within - * the NavCubePlugin. - * - * For example, if the LocaleService's locale is set to "fr", then the path "NavCube.back" will drill down - * into ````messages->fr->NavCube->front```` and fetch "Arrière". - * - * If we didn't provide that particular translation in our LocaleService, or any translations for that locale, - * then the NavCubePlugin will just fall back on its own default hard-coded translation, which in this case is "BACK". - * - * [[Run example](https://xeokit.github.io/xeokit-sdk/examples/index.html#localization_NavCubePlugin)] - * - * ````javascript - * import {Viewer, LocaleService, NavCubePlugin, XKTLoaderPlugin} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * - * canvasId: "myCanvas", - * - * localeService: new LocaleService({ - * messages: { - * "en": { // English - * "NavCube": { - * "front": "Front", - * "back": "Back", - * "top": "Top", - * "bottom": "Bottom", - * "left": "Left", - * "right": "Right" - * } - * }, - * "mi": { // Māori - * "NavCube": { - * "front": "Mua", - * "back": "Tuarā", - * "top": "Runga", - * "bottom": "Raro", - * "left": "Mauī", - * "right": "Tika" - * } - * }, - * "fr": { // Francais - * "NavCube": { - * "front": "Avant", - * "back": "Arrière", - * "top": "Supérieur", - * "bottom": "Inférieur", - * "left": "Gauche", - * "right": "Droit" - * } - * } - * }, - * locale: "en" - * }) - * }); - * - * viewer.camera.eye = [-3.93, 2.85, 27.01]; - * viewer.camera.look = [4.40, 3.72, 8.89]; - * viewer.camera.up = [-0.01, 0.99, 0.03]; - * - * const navCubePlugin = new NavCubePlugin(viewer, { - * canvasID: "myNavCubeCanvas" - * }); - * - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * const model = xktLoader.load({ - * id: "myModel", - * src: "./models/xkt/Duplex.ifc.xkt", - * edges: true - * }); - * ```` - * - * We can dynamically switch our Viewer to a different locale at any time, which will update the text on the - * faces of our NavCube: - * - * ````javascript - * viewer.localeService.locale = "mi"; // Switch to Māori - * ```` - * - * We can load new translations at any time: - * - * ````javascript - * viewer.localeService.loadMessages({ - * "jp": { // Japanese - * "NavCube": { - * "front": "前部", - * "back": "裏", - * "top": "上", - * "bottom": "底", - * "left": "左", - * "right": "右" - * } - * } - * }); - * ```` - * - * And we can clear the translations if needed: - * - * ````javascript - * viewer.localeService.clearMessages(); - * ```` - * - * We can get an "updated" event from the LocaleService whenever we switch locales or load messages, which is useful - * for triggering UI elements to refresh themselves with updated translations. Internally, our {@link NavCubePlugin} - * subscribes to this event, fetching new strings for itself via {@link LocaleService#translate} each time the - * event is fired. - * - * ````javascript - * viewer.localeService.on("updated", () => { - * console.log( viewer.localeService.translate("NavCube.left") ); - * }); - * ```` - * @since 2.0 - */ -class LocaleService { - - /** - * Constructs a LocaleService. - * - * @param {*} [params={}] - * @param {JSON} [params.messages] - * @param {String} [params.locale] - */ - constructor(params = {}) { - - this._eventSubIDMap = null; - this._eventSubEvents = null; - this._eventSubs = null; - this._events = null; - - this._locale = "en"; - this._messages = {}; - this._locales = []; - this._locale = "en"; - - this.messages = params.messages; - this.locale = params.locale; - } - - /** - * Replaces the current set of locale translations. - * - * * Fires an "updated" event when done. - * * Automatically refreshes any plugins that depend on the translations. - * * Does not change the current locale. - * - * ## Usage - * - * ````javascript - * viewer.localeService.setMessages({ - * messages: { - * "en": { // English - * "NavCube": { - * "front": "Front", - * "back": "Back", - * "top": "Top", - * "bottom": "Bottom", - * "left": "Left", - * "right": "Right" - * } - * }, - * "mi": { // Māori - * "NavCube": { - * "front": "Mua", - * "back": "Tuarā", - * "top": "Runga", - * "bottom": "Raro", - * "left": "Mauī", - * "right": "Tika" - * } - * } - * } - * }); - * ```` - * - * @param {*} messages The new translations. - */ - set messages(messages) { - this._messages = messages || {}; - this._locales = Object.keys(this._messages); - this.fire("updated", this); - } - - /** - * Loads a new set of locale translations, adding them to the existing translations. - * - * * Fires an "updated" event when done. - * * Automatically refreshes any plugins that depend on the translations. - * * Does not change the current locale. - * - * ## Usage - * - * ````javascript - * viewer.localeService.loadMessages({ - * "jp": { // Japanese - * "NavCube": { - * "front": "前部", - * "back": "裏", - * "top": "上", - * "bottom": "底", - * "left": "左", - * "right": "右" - * } - * } - * }); - * ```` - * - * @param {*} messages The new translations. - */ - loadMessages(messages = {}) { - for (let locale in messages) { - this._messages[locale] = messages[locale]; - } - this.messages = this._messages; - } - - /** - * Clears all locale translations. - * - * * Fires an "updated" event when done. - * * Does not change the current locale. - * * Automatically refreshes any plugins that depend on the translations, which will cause those - * plugins to fall back on their internal hard-coded text values, since this method removes all - * our translations. - */ - clearMessages() { - this.messages = {}; - } - - /** - * Gets the list of available locales. - * - * These are derived from the currently configured set of translations. - * - * @returns {String[]} The list of available locales. - */ - get locales() { - return this._locales; - } - - /** - * Sets the current locale. - * - * * Fires an "updated" event when done. - * * The given locale does not need to be in the list of available locales returned by {@link LocaleService#locales}, since - * this method assumes that you may want to load the locales at a later point. - * * Automatically refreshes any plugins that depend on the translations. - * * We can then get translations for the locale, if translations have been loaded for it, via {@link LocaleService#translate} and {@link LocaleService#translatePlurals}. - * - * @param {String} locale The new current locale. - */ - set locale(locale) { - locale = locale || "de"; - if (this._locale === locale) { - return; - } - this._locale = locale; - this.fire("updated", locale); - } - - /** - * Gets the current locale. - * - * @returns {String} The current locale. - */ - get locale() { - return this._locale; - } - - /** - * Translates the given string according to the current locale. - * - * Returns null if no translation can be found. - * - * @param {String} msg String to translate. - * @param {*} [args] Extra parameters. - * @returns {String|null} Translated string if found, else null. - */ - translate(msg, args) { - const localeMessages = this._messages[this._locale]; - if (!localeMessages) { - return null; - } - const localeMessage = resolvePath$1(msg, localeMessages); - if (localeMessage) { - if (args) { - return vsprintf(localeMessage, args); - } - return localeMessage; - } - return null; - } - - /** - * Translates the given phrase according to the current locale. - * - * Returns null if no translation can be found. - * - * @param {String} msg Phrase to translate. - * @param {Number} count The plural number. - * @param {*} [args] Extra parameters. - * @returns {String|null} Translated string if found, else null. - */ - translatePlurals(msg, count, args) { - const localeMessages = this._messages[this._locale]; - if (!localeMessages) { - return null; - } - let localeMessage = resolvePath$1(msg, localeMessages); - count = parseInt("" + count, 10); - if (count === 0) { - localeMessage = localeMessage.zero; - } else { - localeMessage = (count > 1) ? localeMessage.other : localeMessage.one; - } - if (!localeMessage) { - return null; - } - localeMessage = vsprintf(localeMessage, [count]); - if (args) { - localeMessage = vsprintf(localeMessage, args); - } - return localeMessage; - } - - /** - * Fires an event on this LocaleService. - * - * Notifies existing subscribers to the event, optionally retains the event to give to - * any subsequent notifications on the event as they are made. - * - * @param {String} event The event type name. - * @param {Object} value The event parameters. - * @param {Boolean} [forget=false] When true, does not retain for subsequent subscribers. - */ - fire(event, value, forget) { - if (!this._events) { - this._events = {}; - } - if (!this._eventSubs) { - this._eventSubs = {}; - } - if (forget !== true) { - this._events[event] = value || true; // Save notification - } - const subs = this._eventSubs[event]; - if (subs) { - for (const subId in subs) { - if (subs.hasOwnProperty(subId)) { - const sub = subs[subId]; - sub.callback(value); - } - } - } - } - - /** - * Subscribes to an event on this LocaleService. - * - * @param {String} event The event - * @param {Function} callback Callback fired on the event - * @return {String} Handle to the subscription, which may be used to unsubscribe with {@link #off}. - */ - on(event, callback) { - if (!this._events) { - this._events = {}; - } - if (!this._eventSubIDMap) { - this._eventSubIDMap = new Map$1(); // Subscription subId pool - } - if (!this._eventSubEvents) { - this._eventSubEvents = {}; - } - if (!this._eventSubs) { - this._eventSubs = {}; - } - let subs = this._eventSubs[event]; - if (!subs) { - subs = {}; - this._eventSubs[event] = subs; - } - const subId = this._eventSubIDMap.addItem(); // Create unique subId - subs[subId] = { - callback: callback - }; - this._eventSubEvents[subId] = event; - const value = this._events[event]; - if (value !== undefined) { - callback(value); - } - return subId; - } - - /** - * Cancels an event subscription that was previously made with {@link LocaleService#on}. - * - * @param {String} subId Subscription ID - */ - off(subId) { - if (subId === undefined || subId === null) { - return; - } - if (!this._eventSubEvents) { - return; - } - const event = this._eventSubEvents[subId]; - if (event) { - delete this._eventSubEvents[subId]; - const subs = this._eventSubs[event]; - if (subs) { - delete subs[subId]; - } - this._eventSubIDMap.removeItem(subId); // Release subId - } - } -} - -function resolvePath$1(key, json) { - if (json[key]) { - return json[key]; - } - const parts = key.split("."); - let obj = json; - for (let i = 0, len = parts.length; obj && (i < len); i++) { - const part = parts[i]; - obj = obj[part]; - } - return obj; -} - -function vsprintf(msg, args = []) { - return msg.replace(/\{\{|\}\}|\{(\d+)\}/g, function (m, n) { - if (m === "{{") { - return "{"; - } - if (m === "}}") { - return "}"; - } - return args[n]; - }); -} - -/** - * @desc Abstract base class for curve classes. - */ -class Curve extends Component { - - /** - * @constructor - * @param {Component} [owner] Owner component. When destroyed, the owner will destroy this Curve as well. - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Curve}, generated automatically when omitted. - * @param {Object} [cfg] Configs for this Curve. - * @param {Number} [cfg.t=0] Current position on this Curve, in range between ````0..1````. - */ - constructor(owner, cfg = {}) { - super(owner, cfg); - this.t = cfg.t; - } - - /** - * Sets the progress along this Curve. - * - * Automatically clamps to range ````[0..1]````. - * - * Default value is ````0````. - * - * @param {Number} value The progress value. - */ - set t(value) { - value = value || 0; - this._t = value < 0.0 ? 0.0 : (value > 1.0 ? 1.0 : value); - } - - /** - * Gets the progress along this Curve. - * - * @returns {Number} The progress value. - */ - get t() { - return this._t; - } - - /** - * Gets the tangent on this Curve at position {@link Curve#t}. - * - * @returns {Number[]} The tangent. - */ - get tangent() { - return this.getTangent(this._t); - } - - /** - * Gets the approximate length of this Curve. - * - * This method calculates the length by discretizing Curve into hardcoded number of straight segments. Then it sums - * lengths of these straight segments. - * - * If you need more control over the precision of the length calculation, we strongly encourage you to build - * your own custom function. - * - * @returns {Number} The approximate Curve length. - */ - get length() { - var lengths = this._getLengths(); - return lengths[lengths.length - 1]; - } - - /** - * Returns a normalized tangent vector on this Curve at the given position. - * - * @param {Number} t Position to get tangent at. - * @returns {Number[]} Normalized tangent vector - */ - getTangent(t) { - var delta = 0.0001; - if (t === undefined) { - t = this._t; - } - var t1 = t - delta; - var t2 = t + delta; - if (t1 < 0) { - t1 = 0; - } - if (t2 > 1) { - t2 = 1; - } - var pt1 = this.getPoint(t1); - var pt2 = this.getPoint(t2); - var vec = math.subVec3(pt2, pt1, []); - return math.normalizeVec3(vec, []); - } - - getPointAt(u) { - var t = this.getUToTMapping(u); - return this.getPoint(t); - } - - /** - * Samples points on this Curve, at the given number of equally-spaced divisions. - * - * @param {Number} divisions The number of divisions. - * @returns {{Array of Array}} Array of sampled 3D points. - */ - getPoints(divisions) { - if (!divisions) { - divisions = 5; - } - var d, pts = []; - for (d = 0; d <= divisions; d++) { - pts.push(this.getPoint(d / divisions)); - } - return pts; - } - - _getLengths(divisions) { - if (!divisions) { - divisions = (this.__arcLengthDivisions) ? (this.__arcLengthDivisions) : 200; - } - if (this.cacheArcLengths && (this.cacheArcLengths.length === divisions + 1) && !this.needsUpdate) { - return this.cacheArcLengths; - - } - this.needsUpdate = false; - var cache = []; - var current; - var last = this.getPoint(0); - var p; - var sum = 0; - cache.push(0); - for (p = 1; p <= divisions; p++) { - current = this.getPoint(p / divisions); - sum += math.lenVec3(math.subVec3(current, last, [])); - cache.push(sum); - last = current; - } - this.cacheArcLengths = cache; - return cache; // { sums: cache, sum:sum }, Sum is in the last element. - } - - _updateArcLengths() { - this.needsUpdate = true; - this._getLengths(); - } - - // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equi distance - - getUToTMapping(u, distance) { - var arcLengths = this._getLengths(); - var i = 0; - var il = arcLengths.length; - var t; - var targetArcLength; // The targeted u distance value to get - if (distance) { - targetArcLength = distance; - } else { - targetArcLength = u * arcLengths[il - 1]; - } - //var time = Date.now(); - var low = 0, high = il - 1, comparison; - while (low <= high) { - i = Math.floor(low + (high - low) / 2); // less likely to overflow, though probably not issue here, JS doesn't really have integers, all numbers are floats - comparison = arcLengths[i] - targetArcLength; - if (comparison < 0) { - low = i + 1; - } else if (comparison > 0) { - high = i - 1; - } else { - high = i; - break; - // DONE - } - } - i = high; - if (arcLengths[i] === targetArcLength) { - t = i / (il - 1); - return t; - } - var lengthBefore = arcLengths[i]; - var lengthAfter = arcLengths[i + 1]; - var segmentLength = lengthAfter - lengthBefore; - var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; - t = (i + segmentFraction) / (il - 1); - return t; - } -} - -/** - * @desc A {@link Curve} along which a 3D position can be animated. - * - * * As shown in the diagram below, a SplineCurve is defined by three or more control points. - * * You can sample a {@link SplineCurve#point} and a {@link Curve#tangent} vector on a SplineCurve for any given value of {@link SplineCurve#t} in the range ````[0..1]````. - * * When you set {@link SplineCurve#t} on a SplineCurve, its {@link SplineCurve#point} and {@link Curve#tangent} will update accordingly. - * * To build a complex path, you can combine an unlimited combination of SplineCurves, {@link CubicBezierCurve} and {@link QuadraticBezierCurve} into a {@link Path}. - *
- *
- * - * * Spline Curve from Wikipedia* - */ -class SplineCurve extends Curve { - - /** - * @constructor - * @param {Component} [owner] Owner component. When destroyed, the owner will destroy this SplineCurve as well. - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Array} [cfg.points=[]] Control points on this SplineCurve. - * @param {Number} [cfg.t=0] Current position on this SplineCurve, in range between 0..1. - * @param {Number} [cfg.t=0] Current position on this CubicBezierCurve, in range between 0..1. - */ - constructor(owner, cfg = {}) { - super(owner, cfg); - this.points = cfg.points; - this.t = cfg.t; - } - - /** - * Sets the control points on this SplineCurve. - * - * Default value is ````[]````. - * - * @param {Number[]} value New control points. - */ - set points(value) { - this._points = value || []; - } - - /** - * Gets the control points on this SplineCurve. - * - * Default value is ````[]````. - * - * @returns {Number[]} The control points. - */ - get points() { - return this._points; - } - - /** - * Sets the progress along this SplineCurve. - * - * Automatically clamps to range ````[0..1]````. - * - * Default value is ````0````. - * - * @param {Number} value The new progress. - */ - set t(value) { - value = value || 0; - this._t = value < 0.0 ? 0.0 : (value > 1.0 ? 1.0 : value); - } - - /** - * Gets the progress along this SplineCurve. - * - * Automatically clamps to range ````[0..1]````. - * - * Default value is ````0````. - * - * @returns {Number} The new progress. - */ - get t() { - return this._t; - } - - /** - * Gets the point on this SplineCurve at position {@link SplineCurve#t}. - * - * @returns {Number[]} The point at {@link SplineCurve#t}. - */ - get point() { - return this.getPoint(this._t); - } - - /** - * Returns point on this SplineCurve at the given position. - * - * @param {Number} t Position to get point at. - * @returns {Number[]} Point at the given position. - */ - getPoint(t) { - - var points = this.points; - - if (points.length < 3) { - this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0]."); - return; - } - - var point = (points.length - 1) * t; - - var intPoint = Math.floor(point); - var weight = point - intPoint; - - var point0 = points[intPoint === 0 ? intPoint : intPoint - 1]; - var point1 = points[intPoint]; - var point2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1]; - var point3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2]; - - var vector = math.vec3(); - - vector[0] = math.catmullRomInterpolate(point0[0], point1[0], point2[0], point3[0], weight); - vector[1] = math.catmullRomInterpolate(point0[1], point1[1], point2[1], point3[1], weight); - vector[2] = math.catmullRomInterpolate(point0[2], point1[2], point2[2], point3[2], weight); - - return vector; - } - - getJSON() { - return { - points: points, - t: this._t - }; - } -} - -const tempVec3a$h = math.vec3(); - -/** - * @desc Defines a sequence of frames along which a {@link CameraPathAnimation} can animate a {@link Camera}. - * - * See {@link CameraPathAnimation} for usage. - */ -class CameraPath extends Component { - - /** - * Returns "CameraPath". - * - * @private - * - * @returns {string} "CameraPath" - */ - get type() { - return "CameraPath" - } - - /** - * @constructor - * @param {Component} [owner] Owner component. When destroyed, the owner will destroy this CameraPath as well. - * @param [cfg] {*} Configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {{t:Number, eye:Object, look:Object, up: Object}[]} [cfg.frames] Initial sequence of frames. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._frames = []; - - this._eyeCurve = new SplineCurve(this); - this._lookCurve = new SplineCurve(this); - this._upCurve = new SplineCurve(this); - - if (cfg.frames) { - this.addFrames(cfg.frames); - this.smoothFrameTimes(1); - } - } - - /** - * Gets the camera frames in this CameraPath. - * - * @returns {{t:Number, eye:Object, look:Object, up: Object}[]} The frames on this CameraPath. - */ - get frames() { - return this._frames; - } - - /** - * Gets the {@link SplineCurve} along which {@link Camera#eye} travels. - * @returns {SplineCurve} The SplineCurve for {@link Camera#eye}. - */ - get eyeCurve() { - return this._eyeCurve; - } - - /** - * Gets the {@link SplineCurve} along which {@link Camera#look} travels. - * @returns {SplineCurve} The SplineCurve for {@link Camera#look}. - */ - get lookCurve() { - return this._lookCurve; - } - - /** - * Gets the {@link SplineCurve} along which {@link Camera#up} travels. - * @returns {SplineCurve} The SplineCurve for {@link Camera#up}. - */ - get upCurve() { - return this._upCurve; - } - - /** - * Adds a frame to this CameraPath, given as the current position of the {@link Camera}. - * - * @param {Number} t Time instant for the new frame. - */ - saveFrame(t) { - const camera = this.scene.camera; - this.addFrame(t, camera.eye, camera.look, camera.up); - } - - /** - * Adds a frame to this CameraPath, specified as values for eye, look and up vectors at a given time instant. - * - * @param {Number} t Time instant for the new frame. - * @param {Number[]} eye A three-element vector specifying the eye position for the new frame. - * @param {Number[]} look A three-element vector specifying the look position for the new frame. - * @param {Number[]} up A three-element vector specifying the up vector for the new frame. - */ - addFrame(t, eye, look, up) { - const frame = { - t: t, - eye: eye.slice(0), - look: look.slice(0), - up: up.slice(0) - }; - this._frames.push(frame); - this._eyeCurve.points.push(frame.eye); - this._lookCurve.points.push(frame.look); - this._upCurve.points.push(frame.up); - } - - /** - * Adds multiple frames to this CameraPath, each frame specified as a set of values for eye, look and up vectors at a given time instant. - * - * @param {{t:Number, eye:Object, look:Object, up: Object}[]} frames Frames to add to this CameraPath. - */ - addFrames(frames) { - let frame; - for (let i = 0, len = frames.length; i < len; i++) { - frame = frames[i]; - this.addFrame(frame.t || 0, frame.eye, frame.look, frame.up); - } - } - - /** - * Sets the position of the {@link Camera} to a position interpolated within this CameraPath at the given time instant. - * - * @param {Number} t Time instant. - */ - loadFrame(t) { - - const camera = this.scene.camera; - - t = t / (this._frames[this._frames.length - 1].t - this._frames[0].t); - t = t < 0.0 ? 0.0 : (t > 1.0 ? 1.0 : t); - - camera.eye = this._eyeCurve.getPoint(t, tempVec3a$h); - camera.look = this._lookCurve.getPoint(t, tempVec3a$h); - camera.up = this._upCurve.getPoint(t, tempVec3a$h); - } - - /** - * Gets eye, look and up vectors on this CameraPath at a given instant. - * - * @param {Number} t Time instant. - * @param {Number[]} eye The eye position to update. - * @param {Number[]} look The look position to update. - * @param {Number[]} up The up vector to update. - */ - sampleFrame(t, eye, look, up) { - t = t < 0.0 ? 0.0 : (t > 1.0 ? 1.0 : t); - this._eyeCurve.getPoint(t, eye); - this._lookCurve.getPoint(t, look); - this._upCurve.getPoint(t, up); - } - - /** - * Given a total duration (in seconds) for this CameraPath, recomputes the time instant at each frame so that, - * when animated by {@link CameraPathAnimation}, the {@link Camera} will move along the path at a constant rate. - * - * @param {Number} duration The total duration for this CameraPath. - */ - smoothFrameTimes(duration) { - const numFrames = this._frames.length; - if (numFrames === 0) { - return; - } - const vec = math.vec3(); - var totalLen = 0; - this._frames[0].t = 0; - const lens = []; - for (let i = 1, len = this._frames.length; i < len; i++) { - var lenVec = math.lenVec3(math.subVec3(this._frames[i].eye, this._frames[i - 1].eye, vec)); - lens[i] = lenVec; - totalLen += lenVec; - } - for (let i = 1, len = this._frames.length; i < len; i++) { - const interFrameRate = (lens[i] / totalLen) * duration; - this._frames[i].t = this._frames[i-1].t + interFrameRate; - } - } - - /** - * Removes all frames from this CameraPath. - */ - clearFrames() { - this._frames = []; - this._eyeCurve.points = []; - this._lookCurve.points = []; - this._upCurve.points = []; - } -} - -const tempVec3$8 = math.vec3(); -const newLook = math.vec3(); -const newEye = math.vec3(); -const newUp = math.vec3(); -const newLookEyeVec = math.vec3(); - -/** - * @desc Jumps or flies the {@link Scene}'s {@link Camera} to a given target. - * - * * Located at {@link Viewer#cameraFlight} - * * Can fly or jump to its target. - * * While flying, can be stopped, or redirected to a different target. - * * Can also smoothly transition between ortho and perspective projections. - * - * - * A CameraFlightAnimation's target can be: - * - * * specific ````eye````, ````look```` and ````up```` positions, - * * an axis-aligned World-space bounding box (AABB), or - * * an instance or ID of any {@link Component} subtype that provides a World-space AABB. - * - * A target can also contain a ````projection```` type to transition into. For example, if your {@link Camera#projection} is - * currently ````"perspective"```` and you supply {@link CameraFlightAnimation#flyTo} with a ````projection```` property - * equal to "ortho", then CameraFlightAnimation will smoothly transition the Camera into an orthographic projection. - * - * Configure {@link CameraFlightAnimation#fit} and {@link CameraFlightAnimation#fitFOV} to make it stop at the point - * where the target occupies a certain amount of the field-of-view. - * - * ## Flying to an Entity - * - * Flying to an {@link Entity}: - * - * ````Javascript - * var entity = new Mesh(viewer.scene); - * - * // Fly to the Entity's World-space AABB - * viewer.cameraFlight.flyTo(entity); - * ```` - * ## Flying to a Position - * - * Flying the CameraFlightAnimation from the previous example to specified eye, look and up positions: - * - * ````Javascript - * viewer.cameraFlight.flyTo({ - * eye: [-5,-5,-5], - * look: [0,0,0] - * up: [0,1,0], - * duration: 1 // Default, seconds - * },() => { - * // Done - * }); - * ```` - * - * ## Flying to an AABB - * - * Flying the CameraFlightAnimation from the previous two examples explicitly to the {@link Boundary3D"}}Boundary3D's{{/crossLink}} - * axis-aligned bounding box: - * - * ````Javascript - * viewer.cameraFlight.flyTo(entity.aabb); - * ```` - * - * ## Transitioning Between Projections - * - * CameraFlightAnimation also allows us to smoothly transition between Camera projections. We can do that by itself, or - * in addition to flying the Camera to a target. - * - * Let's transition the Camera to orthographic projection: - * - * [[Run example](/examples/index.html#camera_CameraFlightAnimation_projection)] - * - * ````Javascript - * viewer.cameraFlight.flyTo({ projection: "ortho", () => { - * // Done - * }); - * ```` - * - * Now let's transition the Camera back to perspective projection: - * - * ````Javascript - * viewer.cameraFlight.flyTo({ projection: "perspective"}, () => { - * // Done - * }); - * ```` - * - * Fly Camera to a position, while transitioning to orthographic projection: - * - * ````Javascript - * viewer.cameraFlight.flyTo({ - * eye: [-100,20,2], - * look: [0,0,-40], - * up: [0,1,0], - * projection: "ortho", () => { - * // Done - * }); - * ```` - */ -class CameraFlightAnimation extends Component { - - /** - * @private - */ - get type() { - return "CameraFlightAnimation"; - } - - /** - @constructor - @private - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._look1 = math.vec3(); - this._eye1 = math.vec3(); - this._up1 = math.vec3(); - this._look2 = math.vec3(); - this._eye2 = math.vec3(); - this._up2 = math.vec3(); - this._orthoScale1 = 1; - this._orthoScale2 = 1; - this._flying = false; - this._flyEyeLookUp = false; - this._flyingEye = false; - this._flyingLook = false; - this._callback = null; - this._callbackScope = null; - this._time1 = null; - this._time2 = null; - this.easing = cfg.easing !== false; - - this.duration = cfg.duration; - this.fit = cfg.fit; - this.fitFOV = cfg.fitFOV; - this.trail = cfg.trail; - } - - /** - * Flies the {@link Camera} to a target. - * - * * When the target is a boundary, the {@link Camera} will fly towards the target and stop when the target fills most of the canvas. - * * When the target is an explicit {@link Camera} position, given as ````eye````, ````look```` and ````up````, then CameraFlightAnimation will interpolate the {@link Camera} to that target and stop there. - * - * @param {Object|Component} [params=Scene] Either a parameters object or a {@link Component} subtype that has - * an AABB. Defaults to the {@link Scene}, which causes the {@link Camera} to fit the Scene in view. - * @param {Number} [params.arc=0] Factor in range ````[0..1]```` indicating how much the {@link Camera#eye} position - * will swing away from its {@link Camera#look} position as it flies to the target. - * @param {Number|String|Component} [params.component] ID or instance of a component to fly to. Defaults to the entire {@link Scene}. - * @param {Number[]} [params.aabb] World-space axis-aligned bounding box (AABB) target to fly to. - * @param {Number[]} [params.eye] Position to fly the eye position to. - * @param {Number[]} [params.look] Position to fly the look position to. - * @param {Number[]} [params.up] Position to fly the up vector to. - * @param {String} [params.projection] Projection type to transition into as we fly. Can be any of the values of {@link Camera.projection}. - * @param {Boolean} [params.fit=true] Whether to fit the target to the view volume. Overrides {@link CameraFlightAnimation#fit}. - * @param {Number} [params.fitFOV] How much of field-of-view, in degrees, that a target {@link Entity} or its AABB should - * fill the canvas on arrival. Overrides {@link CameraFlightAnimation#fitFOV}. - * @param {Number} [params.duration] Flight duration in seconds. Overrides {@link CameraFlightAnimation#duration}. - * @param {Number} [params.orthoScale] Animate the Camera's orthographic scale to this target value. See {@link Ortho#scale}. - * @param {Function} [callback] Callback fired on arrival. - * @param {Object} [scope] Optional scope for callback. - */ - flyTo(params, callback, scope) { - - params = params || this.scene; - - if (this._flying) { - this.stop(); - } - - this._flying = false; - this._flyingEye = false; - this._flyingLook = false; - this._flyingEyeLookUp = false; - - this._callback = callback; - this._callbackScope = scope; - - const camera = this.scene.camera; - const flyToProjection = (!!params.projection) && (params.projection !== camera.projection); - - this._eye1[0] = camera.eye[0]; - this._eye1[1] = camera.eye[1]; - this._eye1[2] = camera.eye[2]; - - this._look1[0] = camera.look[0]; - this._look1[1] = camera.look[1]; - this._look1[2] = camera.look[2]; - - this._up1[0] = camera.up[0]; - this._up1[1] = camera.up[1]; - this._up1[2] = camera.up[2]; - - this._orthoScale1 = camera.ortho.scale; - this._orthoScale2 = params.orthoScale || this._orthoScale1; - - let aabb; - let eye; - let look; - let up; - let componentId; - - if (params.aabb) { - aabb = params.aabb; - - } else if (params.length === 6) { - aabb = params; - - } else if ((params.eye && params.look) || params.up) { - eye = params.eye; - look = params.look; - up = params.up; - - } else if (params.eye) { - eye = params.eye; - - } else if (params.look) { - look = params.look; - - } else { // Argument must be an instance or ID of a Component (subtype) - - let component = params; - - if (utils.isNumeric(component) || utils.isString(component)) { - - componentId = component; - component = this.scene.components[componentId]; - - if (!component) { - this.error("Component not found: " + utils.inQuotes(componentId)); - if (callback) { - if (scope) { - callback.call(scope); - } else { - callback(); - } - } - return; - } - } - if (!flyToProjection) { - aabb = component.aabb || this.scene.aabb; - } - } - - const poi = params.poi; - - if (aabb) { - - if (aabb[3] < aabb[0] || aabb[4] < aabb[1] || aabb[5] < aabb[2]) { // Don't fly to an inverted boundary - return; - } - - if (aabb[3] === aabb[0] && aabb[4] === aabb[1] && aabb[5] === aabb[2]) { // Don't fly to an empty boundary - return; - } - - aabb = aabb.slice(); - const aabbCenter = math.getAABB3Center(aabb); - - this._look2 = poi || aabbCenter; - - const eyeLookVec = math.subVec3(this._eye1, this._look1, tempVec3$8); - const eyeLookVecNorm = math.normalizeVec3(eyeLookVec); - const diag = poi ? math.getAABB3DiagPoint(aabb, poi) : math.getAABB3Diag(aabb); - const fitFOV = params.fitFOV || this._fitFOV; - const sca = Math.abs(diag / Math.tan(fitFOV * math.DEGTORAD)); - - this._orthoScale2 = diag * 1.1; - - this._eye2[0] = this._look2[0] + (eyeLookVecNorm[0] * sca); - this._eye2[1] = this._look2[1] + (eyeLookVecNorm[1] * sca); - this._eye2[2] = this._look2[2] + (eyeLookVecNorm[2] * sca); - - this._up2[0] = this._up1[0]; - this._up2[1] = this._up1[1]; - this._up2[2] = this._up1[2]; - - this._flyingEyeLookUp = true; - - } else if (eye || look || up) { - - this._flyingEyeLookUp = !!eye && !!look && !!up; - this._flyingEye = !!eye && !look; - this._flyingLook = !!look && !eye; - - if (eye) { - this._eye2[0] = eye[0]; - this._eye2[1] = eye[1]; - this._eye2[2] = eye[2]; - } - - if (look) { - this._look2[0] = look[0]; - this._look2[1] = look[1]; - this._look2[2] = look[2]; - } - - if (up) { - this._up2[0] = up[0]; - this._up2[1] = up[1]; - this._up2[2] = up[2]; - } - } - - if (flyToProjection) { - - if (params.projection === "ortho" && camera.projection !== "ortho") { - this._projection2 = "ortho"; - this._projMatrix1 = camera.projMatrix.slice(); - this._projMatrix2 = camera.ortho.matrix.slice(); - camera.projection = "customProjection"; - } - - if (params.projection === "perspective" && camera.projection !== "perspective") { - this._projection2 = "perspective"; - this._projMatrix1 = camera.projMatrix.slice(); - this._projMatrix2 = camera.perspective.matrix.slice(); - camera.projection = "customProjection"; - } - } else { - this._projection2 = null; - } - - this.fire("started", params, true); - - this._time1 = Date.now(); - this._time2 = this._time1 + (Number.isFinite(params.duration) ? params.duration * 1000 : this._duration); - - this._flying = true; // False as soon as we stop - - core.scheduleTask(this._update, this); - } - - /** - * Jumps the {@link Scene}'s {@link Camera} to the given target. - * - * * When the target is a boundary, this CameraFlightAnimation will position the {@link Camera} at where the target fills most of the canvas. - * * When the target is an explicit {@link Camera} position, given as ````eye````, ````look```` and ````up```` vectors, then this CameraFlightAnimation will jump the {@link Camera} to that target. - * - * @param {*|Component} params Either a parameters object or a {@link Component} subtype that has a World-space AABB. - * @param {Number} [params.arc=0] Factor in range [0..1] indicating how much the {@link Camera#eye} will swing away from its {@link Camera#look} as it flies to the target. - * @param {Number|String|Component} [params.component] ID or instance of a component to fly to. - * @param {Number[]} [params.aabb] World-space axis-aligned bounding box (AABB) target to fly to. - * @param {Number[]} [params.eye] Position to fly the eye position to. - * @param {Number[]} [params.look] Position to fly the look position to. - * @param {Number[]} [params.up] Position to fly the up vector to. - * @param {String} [params.projection] Projection type to transition into. Can be any of the values of {@link Camera.projection}. - * @param {Number} [params.fitFOV] How much of field-of-view, in degrees, that a target {@link Entity} or its AABB should fill the canvas on arrival. Overrides {@link CameraFlightAnimation#fitFOV}. - * @param {Boolean} [params.fit] Whether to fit the target to the view volume. Overrides {@link CameraFlightAnimation#fit}. - */ - jumpTo(params) { - this._jumpTo(params); - } - - _jumpTo(params) { - - if (this._flying) { - this.stop(); - } - - const camera = this.scene.camera; - - var aabb; - var componentId; - var newEye; - var newLook; - var newUp; - - if (params.aabb) { // Boundary3D - aabb = params.aabb; - - } else if (params.length === 6) { // AABB - aabb = params; - - } else if (params.eye || params.look || params.up) { // Camera pose - newEye = params.eye; - newLook = params.look; - newUp = params.up; - - } else { // Argument must be an instance or ID of a Component (subtype) - - let component = params; - - if (utils.isNumeric(component) || utils.isString(component)) { - componentId = component; - component = this.scene.components[componentId]; - if (!component) { - this.error("Component not found: " + utils.inQuotes(componentId)); - return; - } - } - aabb = component.aabb || this.scene.aabb; - } - - const poi = params.poi; - - if (aabb) { - - if (aabb[3] <= aabb[0] || aabb[4] <= aabb[1] || aabb[5] <= aabb[2]) { // Don't fly to an empty boundary - return; - } - - var diag = poi ? math.getAABB3DiagPoint(aabb, poi) : math.getAABB3Diag(aabb); - - newLook = poi || math.getAABB3Center(aabb, newLook); - - if (this._trail) { - math.subVec3(camera.look, newLook, newLookEyeVec); - } else { - math.subVec3(camera.eye, camera.look, newLookEyeVec); - } - - math.normalizeVec3(newLookEyeVec); - let dist; - const fit = (params.fit !== undefined) ? params.fit : this._fit; - - if (fit) { - dist = Math.abs((diag) / Math.tan((params.fitFOV || this._fitFOV) * math.DEGTORAD)); - - } else { - dist = math.lenVec3(math.subVec3(camera.eye, camera.look, tempVec3$8)); - } - - math.mulVec3Scalar(newLookEyeVec, dist); - - camera.eye = math.addVec3(newLook, newLookEyeVec, tempVec3$8); - camera.look = newLook; - - this.scene.camera.ortho.scale = diag * 1.1; - - } else if (newEye || newLook || newUp) { - - if (newEye) { - camera.eye = newEye; - } - if (newLook) { - camera.look = newLook; - } - if (newUp) { - camera.up = newUp; - } - } - - if (params.projection) { - camera.projection = params.projection; - } - } - - _update() { - if (!this._flying) { - return; - } - const time = Date.now(); - let t = (time - this._time1) / (this._time2 - this._time1); - const stopping = (t >= 1); - - if (t > 1) { - t = 1; - } - - const tFlight = this.easing ? CameraFlightAnimation._ease(t, 0, 1, 1) : t; - const camera = this.scene.camera; - - if (this._flyingEye || this._flyingLook) { - - if (this._flyingEye) { - math.subVec3(camera.eye, camera.look, newLookEyeVec); - camera.eye = math.lerpVec3(tFlight, 0, 1, this._eye1, this._eye2, newEye); - camera.look = math.subVec3(newEye, newLookEyeVec, newLook); - } else if (this._flyingLook) { - camera.look = math.lerpVec3(tFlight, 0, 1, this._look1, this._look2, newLook); - camera.up = math.lerpVec3(tFlight, 0, 1, this._up1, this._up2, newUp); - } - - } else if (this._flyingEyeLookUp) { - - camera.eye = math.lerpVec3(tFlight, 0, 1, this._eye1, this._eye2, newEye); - camera.look = math.lerpVec3(tFlight, 0, 1, this._look1, this._look2, newLook); - camera.up = math.lerpVec3(tFlight, 0, 1, this._up1, this._up2, newUp); - } - - if (this._projection2) { - const tProj = (this._projection2 === "ortho") ? CameraFlightAnimation._easeOutExpo(t, 0, 1, 1) : CameraFlightAnimation._easeInCubic(t, 0, 1, 1); - camera.customProjection.matrix = math.lerpMat4(tProj, 0, 1, this._projMatrix1, this._projMatrix2); - - } else { - camera.ortho.scale = this._orthoScale1 + (t * (this._orthoScale2 - this._orthoScale1)); - } - - if (stopping) { - camera.ortho.scale = this._orthoScale2; - this.stop(); - return; - } - core.scheduleTask(this._update, this); // Keep flying - } - - static _ease(t, b, c, d) { // Quadratic easing out - decelerating to zero velocity http://gizma.com/easing - t /= d; - return -c * t * (t - 2) + b; - } - - static _easeInCubic(t, b, c, d) { - t /= d; - return c * t * t * t + b; - } - - static _easeOutExpo(t, b, c, d) { - return c * (-Math.pow(2, -10 * t / d) + 1) + b; - } - - /** - * Stops an earlier flyTo, fires arrival callback. - */ - stop() { - if (!this._flying) { - return; - } - this._flying = false; - this._time1 = null; - this._time2 = null; - if (this._projection2) { - this.scene.camera.projection = this._projection2; - } - const callback = this._callback; - if (callback) { - this._callback = null; - if (this._callbackScope) { - callback.call(this._callbackScope); - } else { - callback(); - } - } - this.fire("stopped", true, true); - } - - /** - * Cancels an earlier flyTo without calling the arrival callback. - */ - cancel() { - if (!this._flying) { - return; - } - this._flying = false; - this._time1 = null; - this._time2 = null; - if (this._callback) { - this._callback = null; - } - this.fire("canceled", true, true); - } - - /** - * Sets the flight duration, in seconds, when calling {@link CameraFlightAnimation#flyTo}. - * - * Stops any flight currently in progress. - * - * default value is ````0.5````. - * - * @param {Number} value New duration value. - */ - set duration(value) { - this._duration = Number.isFinite(value) ? (value * 1000.0) : 500; - this.stop(); - } - - /** - * Gets the flight duration, in seconds, when calling {@link CameraFlightAnimation#flyTo}. - * - * default value is ````0.5````. - * - * @returns {Number} New duration value. - */ - get duration() { - return this._duration / 1000.0; - } - - /** - * Sets if, when CameraFlightAnimation is flying to a boundary, it will always adjust the distance between the - * {@link Camera#eye} and {@link Camera#look} so as to ensure that the target boundary is always filling the view volume. - * - * When false, the eye will remain at its current distance from the look position. - * - * Default value is ````true````. - * - * @param {Boolean} value Set ````true```` to activate this behaviour. - */ - set fit(value) { - this._fit = value !== false; - } - - /** - * Gets if, when CameraFlightAnimation is flying to a boundary, it will always adjust the distance between the - * {@link Camera#eye} and {@link Camera#look} so as to ensure that the target boundary is always filling the view volume. - * - * When false, the eye will remain at its current distance from the look position. - * - * Default value is ````true````. - * - * @returns {Boolean} value Set ````true```` to activate this behaviour. - */ - get fit() { - return this._fit; - } - - /** - * Sets how much of the perspective field-of-view, in degrees, that a target {@link Entity#aabb} should - * fill the canvas when calling {@link CameraFlightAnimation#flyTo} or {@link CameraFlightAnimation#jumpTo}. - * - * Default value is ````45````. - * - * @param {Number} value New FOV value. - */ - set fitFOV(value) { - this._fitFOV = value || 45; - } - - /** - * Gets how much of the perspective field-of-view, in degrees, that a target {@link Entity#aabb} should - * fill the canvas when calling {@link CameraFlightAnimation#flyTo} or {@link CameraFlightAnimation#jumpTo}. - * - * Default value is ````45````. - * - * @returns {Number} Current FOV value. - */ - get fitFOV() { - return this._fitFOV; - } - - /** - * Sets if this CameraFlightAnimation to point the {@link Camera} - * in the direction that it is travelling when flying to a target after calling {@link CameraFlightAnimation#flyTo}. - * - * Default value is ````true````. - * - * @param {Boolean} value Set ````true```` to activate trailing behaviour. - */ - set trail(value) { - this._trail = !!value; - } - - /** - * Gets if this CameraFlightAnimation points the {@link Camera} - * in the direction that it is travelling when flying to a target after calling {@link CameraFlightAnimation#flyTo}. - * - * Default value is ````true````. - * - * @returns {Boolean} True if trailing behaviour is active. - */ - get trail() { - return this._trail; - } - - /** - * @private - */ - destroy() { - this.stop(); - super.destroy(); - } -} - -/** - * @desc Animates the {@link Scene}'s's {@link Camera} along a {@link CameraPath}. - * - * ## Usage - * - * In the example below, we'll load a model using a {@link GLTFLoaderPlugin}, then animate a {@link Camera} - * through the frames in a {@link CameraPath}. - * - * * [[Run this example](/examples/index.html#camera_CameraPathAnimation)] - * - * ````Javascript - * import {Viewer, GLTFLoaderPlugin, CameraPath, CameraPathAnimation} from "xeokit-sdk.es.js"; - * - * // Create a Viewer and arrange camera - * - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.camera.eye = [124.86756896972656, -93.50288391113281, 173.2632598876953]; - * viewer.camera.look = [102.14186096191406, -90.24193572998047, 173.4224395751953]; - * viewer.camera.up = [0.23516440391540527, 0.9719591736793518, -0.0016466031083837152]; - * - * // Load model - * - * const gltfLoader = new GLTFLoaderPlugin(viewer); - * - * const model = gltfLoader.load({ - * id: "myModel", - * src: "./models/gltf/modern_office/scene.gltf", - * edges: true, - * edgeThreshold: 20, - * xrayed: false - * }); - * - * // Create a CameraPath - * - * var cameraPath = new CameraPath(viewer.scene, { - * frames: [ - * { - * t: 0, - * eye: [124.86, -93.50, 173.26], - * look: [102.14, -90.24, 173.42], - * up: [0.23, 0.97, -0.00] - * }, - * { - * t: 1, - * eye: [79.75, -85.98, 226.57], - * look: [99.24, -84.11, 238.56], - * up: [-0.14, 0.98, -0.09] - * }, - * // Rest of the frames omitted for brevity - * ] - * }); - * - * // Create a CameraPathAnimation to play our CameraPath - * - * var cameraPathAnimation = new CameraPathAnimation(viewer.scene, { - * cameraPath: cameraPath, - * playingRate: 0.2 // Playing 0.2 time units per second - * }); - * - * // Once model loaded, start playing after a couple of seconds delay - * - * model.on("loaded", function () { - * setTimeout(function () { - * cameraPathAnimation.play(0); // Play from the beginning of the CameraPath - * }, 2000); - * }); - * ```` - */ -class CameraPathAnimation extends Component { - - /** - * Returns "CameraPathAnimation". - * - * @private - * @returns {string} "CameraPathAnimation" - */ - get type() { - return "CameraPathAnimation" - } - - /** - * @constructor - * @param {Component} [owner] Owner component. When destroyed, the owner will destroy this CameraPathAnimation as well. - * @param {*} [cfg] Configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {CameraPath} [cfg.eyeCurve] A {@link CameraPath} that defines the path of a {@link Camera}. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._cameraFlightAnimation = new CameraFlightAnimation(this); - this._t = 0; - this.state = CameraPathAnimation.SCRUBBING; - this._playingFromT = 0; - this._playingToT = 0; - this._playingRate = cfg.playingRate || 1.0; - this._playingDir = 1.0; - this._lastTime = null; - - this.cameraPath = cfg.cameraPath; - - this._tick = this.scene.on("tick", this._updateT, this); - } - - _updateT() { - const cameraPath = this._cameraPath; - if (!cameraPath) { - return; - } - let numFrames; - let t; - const time = performance.now(); - const elapsedSecs = (this._lastTime) ? (time - this._lastTime) * 0.001 : 0; - this._lastTime = time; - if (elapsedSecs === 0) { - return; - } - switch (this.state) { - case CameraPathAnimation.SCRUBBING: - return; - case CameraPathAnimation.PLAYING: - this._t += this._playingRate * elapsedSecs; - numFrames = this._cameraPath.frames.length; - if (numFrames === 0 || (this._playingDir < 0 && this._t <= 0) || (this._playingDir > 0 && this._t >= this._cameraPath.frames[numFrames - 1].t)) { - this.state = CameraPathAnimation.SCRUBBING; - this._t = this._cameraPath.frames[numFrames - 1].t; - this.fire("stopped"); - return; - } - cameraPath.loadFrame(this._t); - break; - case CameraPathAnimation.PLAYING_TO: - t = this._t + (this._playingRate * elapsedSecs * this._playingDir); - if ((this._playingDir < 0 && t <= this._playingToT) || (this._playingDir > 0 && t >= this._playingToT)) { - t = this._playingToT; - this.state = CameraPathAnimation.SCRUBBING; - this.fire("stopped"); - } - this._t = t; - cameraPath.loadFrame(this._t); - break; - } - } - - /* - * @private - */ - _ease(t, b, c, d) { - t /= d; - return -c * t * (t - 2) + b; - } - - /** - * Sets the {@link CameraPath} animated by this CameraPathAnimation. - * - @param {CameraPath} value The new CameraPath. - */ - set cameraPath(value) { - this._cameraPath = value; - } - - /** - * Gets the {@link CameraPath} animated by this CameraPathAnimation. - * - @returns {CameraPath} The CameraPath. - */ - get cameraPath() { - return this._cameraPath; - } - - /** - * Sets the rate at which the CameraPathAnimation animates the {@link Camera} along the {@link CameraPath}. - * - * @param {Number} value The amount of progress per second. - */ - set rate(value) { - this._playingRate = value; - } - - /** - * Gets the rate at which the CameraPathAnimation animates the {@link Camera} along the {@link CameraPath}. - * - * @returns {*|number} The current playing rate. - */ - get rate() { - return this._playingRate; - } - - /** - * Begins animating the {@link Camera} along CameraPathAnimation's {@link CameraPath} from the beginning. - */ - play() { - if (!this._cameraPath) { - return; - } - this._lastTime = null; - this.state = CameraPathAnimation.PLAYING; - } - - /** - * Begins animating the {@link Camera} along CameraPathAnimation's {@link CameraPath} from the given time. - * - * @param {Number} t Time instant. - */ - playToT(t) { - const cameraPath = this._cameraPath; - if (!cameraPath) { - return; - } - this._playingFromT = this._t; - this._playingToT = t; - this._playingDir = (this._playingToT - this._playingFromT) < 0 ? -1 : 1; - this._lastTime = null; - this.state = CameraPathAnimation.PLAYING_TO; - } - - /** - * Animates the {@link Camera} along CameraPathAnimation's {@link CameraPath} to the given frame. - * - * @param {Number} frameIdx Index of the frame to play to. - */ - playToFrame(frameIdx) { - const cameraPath = this._cameraPath; - if (!cameraPath) { - return; - } - const frame = cameraPath.frames[frameIdx]; - if (!frame) { - this.error("playToFrame - frame index out of range: " + frameIdx); - return; - } - this.playToT(frame.t); - } - - /** - * Flies the {@link Camera} directly to the given frame on the CameraPathAnimation's {@link CameraPath}. - * - * @param {Number} frameIdx Index of the frame to play to. - * @param {Function} [ok] Callback to fire when playing is complete. - */ - flyToFrame(frameIdx, ok) { - const cameraPath = this._cameraPath; - if (!cameraPath) { - return; - } - const frame = cameraPath.frames[frameIdx]; - if (!frame) { - this.error("flyToFrame - frame index out of range: " + frameIdx); - return; - } - this.state = CameraPathAnimation.SCRUBBING; - this._cameraFlightAnimation.flyTo(frame, ok); - } - - /** - * Scrubs the {@link Camera} to the given time on the CameraPathAnimation's {@link CameraPath}. - * - * @param {Number} t Time instant. - */ - scrubToT(t) { - const cameraPath = this._cameraPath; - if (!cameraPath) { - return; - } - const camera = this.scene.camera; - if (!camera) { - return; - } - this._t = t; - cameraPath.loadFrame(this._t); - this.state = CameraPathAnimation.SCRUBBING; - } - - /** - * Scrubs the {@link Camera} to the given frame on the CameraPathAnimation's {@link CameraPath}. - * - * @param {Number} frameIdx Index of the frame to scrub to. - */ - scrubToFrame(frameIdx) { - const cameraPath = this._cameraPath; - if (!cameraPath) { - return; - } - const camera = this.scene.camera; - if (!camera) { - return; - } - const frame = cameraPath.frames[frameIdx]; - if (!frame) { - this.error("playToFrame - frame index out of range: " + frameIdx); - return; - } - cameraPath.loadFrame(this._t); - this.state = CameraPathAnimation.SCRUBBING; - } - - /** - * Stops playing this CameraPathAnimation. - */ - stop() { - this.state = CameraPathAnimation.SCRUBBING; - this.fire("stopped"); - } - - destroy() { - super.destroy(); - this.scene.off(this._tick); - } -} - -CameraPathAnimation.STOPPED = 0; -CameraPathAnimation.SCRUBBING = 1; -CameraPathAnimation.PLAYING = 2; -CameraPathAnimation.PLAYING_TO = 3; - -/** - * @desc Defines a shape for one or more {@link Mesh}es. - * - * * {@link ReadableGeometry} is a subclass that stores its data in both browser and GPU memory. Use ReadableGeometry when you need to keep the geometry arrays in browser memory. - * * {@link VBOGeometry} is a subclass that stores its data solely in GPU memory. Use VBOGeometry when you need a lower memory footprint and don't need to keep the geometry data in browser memory. - */ -class Geometry extends Component { - - /** @private */ - get type() { - return "Geometry"; - } - - /** @private */ - get isGeometry() { - return true; - } - - constructor(owner, cfg = {}) { - super(owner, cfg); - stats.memory.meshes++; - } - - destroy() { - super.destroy(); - stats.memory.meshes--; - } -} - -const ids$2 = new Map$1({}); - -/** - * @desc Represents a chunk of state changes applied by the {@link Scene}'s renderer while it renders a frame. - * - * * Contains properties that represent the state changes. - * * Has a unique automatically-generated numeric ID, which the renderer can use to sort these, in order to avoid applying redundant state changes for each frame. - * * Initialize your own properties on a RenderState via its constructor. - * - * @private - */ -class RenderState { - - constructor(cfg) { - - /** - The RenderState's ID, unique within the renderer. - @property id - @type {Number} - @final - */ - this.id = ids$2.addItem({}); - for (const key in cfg) { - if (cfg.hasOwnProperty(key)) { - this[key] = cfg[key]; - } - } - } - - /** - Destroys this RenderState. - */ - destroy() { - ids$2.removeItem(this.id); - } -} - -/** - * @desc Represents a WebGL ArrayBuffer. - * - * @private - */ -class ArrayBuf { - - constructor(gl, type, data, numItems, itemSize, usage, normalized, stride, offset) { - - this._gl = gl; - this.type = type; - this.allocated = false; - - switch (data.constructor) { - - case Uint8Array: - this.itemType = gl.UNSIGNED_BYTE; - this.itemByteSize = 1; - break; - - case Int8Array: - this.itemType = gl.BYTE; - this.itemByteSize = 1; - break; - - case Uint16Array: - this.itemType = gl.UNSIGNED_SHORT; - this.itemByteSize = 2; - break; - - case Int16Array: - this.itemType = gl.SHORT; - this.itemByteSize = 2; - break; - - case Uint32Array: - this.itemType = gl.UNSIGNED_INT; - this.itemByteSize = 4; - break; - - case Int32Array: - this.itemType = gl.INT; - this.itemByteSize = 4; - break; - - default: - this.itemType = gl.FLOAT; - this.itemByteSize = 4; - } - - this.usage = usage; - this.length = 0; - this.dataLength = numItems; - this.numItems = 0; - this.itemSize = itemSize; - this.normalized = !!normalized; - this.stride = stride || 0; - this.offset = offset || 0; - - this._allocate(data); - } - - _allocate(data) { - this.allocated = false; - this._handle = this._gl.createBuffer(); - if (!this._handle) { - throw "Failed to allocate WebGL ArrayBuffer"; - } - if (this._handle) { - this._gl.bindBuffer(this.type, this._handle); - this._gl.bufferData(this.type, data.length > this.dataLength ? data.slice(0, this.dataLength) : data, this.usage); - this._gl.bindBuffer(this.type, null); - this.length = data.length; - this.numItems = this.length / this.itemSize; - this.allocated = true; - } - } - - setData(data, offset) { - if (!this.allocated) { - return; - } - if (data.length + (offset || 0) > this.length) { // Needs reallocation - this.destroy(); - this._allocate(data); - } else { // No reallocation needed - this._gl.bindBuffer(this.type, this._handle); - if (offset || offset === 0) { - this._gl.bufferSubData(this.type, offset * this.itemByteSize, data); - } else { - this._gl.bufferData(this.type, data, this.usage); - } - this._gl.bindBuffer(this.type, null); - } - } - - bind() { - if (!this.allocated) { - return; - } - this._gl.bindBuffer(this.type, this._handle); - } - - unbind() { - if (!this.allocated) { - return; - } - this._gl.bindBuffer(this.type, null); - } - - bindAtLocation(location) { - this.bind(); - this._gl.vertexAttribPointer(location, this.itemSize, this.itemType, this.normalized, 0, 0); - } - - destroy() { - if (!this.allocated) { - return; - } - this._gl.deleteBuffer(this._handle); - this._handle = null; - this.allocated = false; - } -} - -/** - * @private - */ -var buildEdgeIndices = (function () { - - const uniquePositions = []; - const indicesLookup = []; - const indicesReverseLookup = []; - const weldedIndices = []; - -// TODO: Optimize with caching, but need to cater to both compressed and uncompressed positions - - const faces = []; - let numFaces = 0; - const compa = new Uint16Array(3); - const compb = new Uint16Array(3); - const compc = new Uint16Array(3); - const a = math.vec3(); - const b = math.vec3(); - const c = math.vec3(); - const cb = math.vec3(); - const ab = math.vec3(); - const cross = math.vec3(); - const normal = math.vec3(); - - function weldVertices(positions, indices) { - const positionsMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique) - let vx; - let vy; - let vz; - let key; - const precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001 - const precision = Math.pow(10, precisionPoints); - let i; - let len; - let lenUniquePositions = 0; - for (i = 0, len = positions.length; i < len; i += 3) { - vx = positions[i]; - vy = positions[i + 1]; - vz = positions[i + 2]; - key = Math.round(vx * precision) + '_' + Math.round(vy * precision) + '_' + Math.round(vz * precision); - if (positionsMap[key] === undefined) { - positionsMap[key] = lenUniquePositions / 3; - uniquePositions[lenUniquePositions++] = vx; - uniquePositions[lenUniquePositions++] = vy; - uniquePositions[lenUniquePositions++] = vz; - } - indicesLookup[i / 3] = positionsMap[key]; - } - for (i = 0, len = indices.length; i < len; i++) { - weldedIndices[i] = indicesLookup[indices[i]]; - indicesReverseLookup[weldedIndices[i]] = indices[i]; - } - } - - function buildFaces(numIndices, positionsDecodeMatrix) { - numFaces = 0; - for (let i = 0, len = numIndices; i < len; i += 3) { - const ia = ((weldedIndices[i]) * 3); - const ib = ((weldedIndices[i + 1]) * 3); - const ic = ((weldedIndices[i + 2]) * 3); - if (positionsDecodeMatrix) { - compa[0] = uniquePositions[ia]; - compa[1] = uniquePositions[ia + 1]; - compa[2] = uniquePositions[ia + 2]; - compb[0] = uniquePositions[ib]; - compb[1] = uniquePositions[ib + 1]; - compb[2] = uniquePositions[ib + 2]; - compc[0] = uniquePositions[ic]; - compc[1] = uniquePositions[ic + 1]; - compc[2] = uniquePositions[ic + 2]; - // Decode - math.decompressPosition(compa, positionsDecodeMatrix, a); - math.decompressPosition(compb, positionsDecodeMatrix, b); - math.decompressPosition(compc, positionsDecodeMatrix, c); - } else { - a[0] = uniquePositions[ia]; - a[1] = uniquePositions[ia + 1]; - a[2] = uniquePositions[ia + 2]; - b[0] = uniquePositions[ib]; - b[1] = uniquePositions[ib + 1]; - b[2] = uniquePositions[ib + 2]; - c[0] = uniquePositions[ic]; - c[1] = uniquePositions[ic + 1]; - c[2] = uniquePositions[ic + 2]; - } - math.subVec3(c, b, cb); - math.subVec3(a, b, ab); - math.cross3Vec3(cb, ab, cross); - math.normalizeVec3(cross, normal); - const face = faces[numFaces] || (faces[numFaces] = {normal: math.vec3()}); - face.normal[0] = normal[0]; - face.normal[1] = normal[1]; - face.normal[2] = normal[2]; - numFaces++; - } - } - - return function (positions, indices, positionsDecodeMatrix, edgeThreshold) { - weldVertices(positions, indices); - buildFaces(indices.length, positionsDecodeMatrix); - const edgeIndices = []; - const thresholdDot = Math.cos(math.DEGTORAD * edgeThreshold); - const edges = {}; - let edge1; - let edge2; - let index1; - let index2; - let key; - let largeIndex = false; - let edge; - let normal1; - let normal2; - let dot; - let ia; - let ib; - for (let i = 0, len = indices.length; i < len; i += 3) { - const faceIndex = i / 3; - for (let j = 0; j < 3; j++) { - edge1 = weldedIndices[i + j]; - edge2 = weldedIndices[i + ((j + 1) % 3)]; - index1 = Math.min(edge1, edge2); - index2 = Math.max(edge1, edge2); - key = index1 + "," + index2; - if (edges[key] === undefined) { - edges[key] = { - index1: index1, - index2: index2, - face1: faceIndex, - face2: undefined - }; - } else { - edges[key].face2 = faceIndex; - } - } - } - for (key in edges) { - edge = edges[key]; - // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree. - if (edge.face2 !== undefined) { - normal1 = faces[edge.face1].normal; - normal2 = faces[edge.face2].normal; - dot = math.dotVec3(normal1, normal2); - if (dot > thresholdDot) { - continue; - } - } - ia = indicesReverseLookup[edge.index1]; - ib = indicesReverseLookup[edge.index2]; - if (!largeIndex && ia > 65535 || ib > 65535) { - largeIndex = true; - } - edgeIndices.push(ia); - edgeIndices.push(ib); - } - return (largeIndex) ? new Uint32Array(edgeIndices) : new Uint16Array(edgeIndices); - }; -})(); - -/** - * Private geometry compression and decompression utilities. - */ - -/** - * @private - * @param array - * @returns {{min: Float32Array, max: Float32Array}} - */ -function getPositionsBounds(array) { - const min = new Float32Array(3); - const max = new Float32Array(3); - let i, j; - for (i = 0; i < 3; i++) { - min[i] = Number.MAX_VALUE; - max[i] = -Number.MAX_VALUE; - } - for (i = 0; i < array.length; i += 3) { - for (j = 0; j < 3; j++) { - min[j] = Math.min(min[j], array[i + j]); - max[j] = Math.max(max[j], array[i + j]); - } - } - return { - min: min, - max: max - }; -} - -const createPositionsDecodeMatrix$1 = (function () { - const translate = math.mat4(); - const scale = math.mat4(); - return function (aabb, positionsDecodeMatrix) { - positionsDecodeMatrix = positionsDecodeMatrix || math.mat4(); - const xmin = aabb[0]; - const ymin = aabb[1]; - const zmin = aabb[2]; - const xwid = (aabb[3] - xmin) || 1; - const ywid = (aabb[4] - ymin) || 1; - const zwid = (aabb[5] - zmin) || 1; - const maxInt = 65535; - math.identityMat4(translate); - math.translationMat4v(aabb, translate); - math.identityMat4(scale); - math.scalingMat4v([xwid / maxInt, ywid / maxInt, zwid / maxInt], scale); - math.mulMat4(translate, scale, positionsDecodeMatrix); - return positionsDecodeMatrix; - }; -})(); - -/** - * @private - */ -var compressPositions = (function () { // http://cg.postech.ac.kr/research/mesh_comp_mobile/mesh_comp_mobile_conference.pdf - const translate = math.mat4(); - const scale = math.mat4(); - return function (array, min, max) { - const quantized = new Uint16Array(array.length); - const multiplier = new Float32Array([ - max[0] !== min[0] ? 65535 / (max[0] - min[0]) : 0, - max[1] !== min[1] ? 65535 / (max[1] - min[1]) : 0, - max[2] !== min[2] ? 65535 / (max[2] - min[2]) : 0 - ]); - let i; - for (i = 0; i < array.length; i += 3) { - quantized[i + 0] = Math.max(0, Math.min(65535, Math.floor((array[i + 0] - min[0]) * multiplier[0]))); - quantized[i + 1] = Math.max(0, Math.min(65535, Math.floor((array[i + 1] - min[1]) * multiplier[1]))); - quantized[i + 2] = Math.max(0, Math.min(65535, Math.floor((array[i + 2] - min[2]) * multiplier[2]))); - } - math.identityMat4(translate); - math.translationMat4v(min, translate); - math.identityMat4(scale); - math.scalingMat4v([ - (max[0] - min[0]) / 65535, - (max[1] - min[1]) / 65535, - (max[2] - min[2]) / 65535 - ], scale); - const decodeMat = math.mulMat4(translate, scale, math.identityMat4()); - return { - quantized: quantized, - decodeMatrix: decodeMat - }; - }; -})(); - -function compressPosition(p, aabb, q) { - const multiplier = new Float32Array([ - aabb[3] !== aabb[0] ? 65535 / (aabb[3] - aabb[0]) : 0, - aabb[4] !== aabb[1] ? 65535 / (aabb[4] - aabb[1]) : 0, - aabb[5] !== aabb[2] ? 65535 / (aabb[5] - aabb[2]) : 0 - ]); - q[0] = Math.max(0, Math.min(65535, Math.floor((p[0] - aabb[0]) * multiplier[0]))); - q[1] = Math.max(0, Math.min(65535, Math.floor((p[1] - aabb[1]) * multiplier[1]))); - q[2] = Math.max(0, Math.min(65535, Math.floor((p[2] - aabb[2]) * multiplier[2]))); -} - -function decompressPosition(position, decodeMatrix, dest) { - dest[0] = position[0] * decodeMatrix[0] + decodeMatrix[12]; - dest[1] = position[1] * decodeMatrix[5] + decodeMatrix[13]; - dest[2] = position[2] * decodeMatrix[10] + decodeMatrix[14]; - return dest; -} - -function decompressAABB(aabb, decodeMatrix, dest = aabb) { - dest[0] = aabb[0] * decodeMatrix[0] + decodeMatrix[12]; - dest[1] = aabb[1] * decodeMatrix[5] + decodeMatrix[13]; - dest[2] = aabb[2] * decodeMatrix[10] + decodeMatrix[14]; - dest[3] = aabb[3] * decodeMatrix[0] + decodeMatrix[12]; - dest[4] = aabb[4] * decodeMatrix[5] + decodeMatrix[13]; - dest[5] = aabb[5] * decodeMatrix[10] + decodeMatrix[14]; - return dest; -} - -/** - * @private - */ -function decompressPositions(positions, decodeMatrix, dest = new Float32Array(positions.length)) { - for (let i = 0, len = positions.length; i < len; i += 3) { - dest[i + 0] = positions[i + 0] * decodeMatrix[0] + decodeMatrix[12]; - dest[i + 1] = positions[i + 1] * decodeMatrix[5] + decodeMatrix[13]; - dest[i + 2] = positions[i + 2] * decodeMatrix[10] + decodeMatrix[14]; - } - return dest; -} - -//--------------- UVs -------------------------------------------------------------------------------------------------- - -/** - * @private - * @param array - * @returns {{min: Float32Array, max: Float32Array}} - */ -function getUVBounds(array) { - const min = new Float32Array(2); - const max = new Float32Array(2); - let i, j; - for (i = 0; i < 2; i++) { - min[i] = Number.MAX_VALUE; - max[i] = -Number.MAX_VALUE; - } - for (i = 0; i < array.length; i += 2) { - for (j = 0; j < 2; j++) { - min[j] = Math.min(min[j], array[i + j]); - max[j] = Math.max(max[j], array[i + j]); - } - } - return { - min: min, - max: max - }; -} - -/** - * @private - */ -var compressUVs = (function () { - const translate = math.mat3(); - const scale = math.mat3(); - return function (array, min, max) { - const quantized = new Uint16Array(array.length); - const multiplier = new Float32Array([ - 65535 / (max[0] - min[0]), - 65535 / (max[1] - min[1]) - ]); - let i; - for (i = 0; i < array.length; i += 2) { - quantized[i + 0] = Math.max(0, Math.min(65535, Math.floor((array[i + 0] - min[0]) * multiplier[0]))); - quantized[i + 1] = Math.max(0, Math.min(65535, Math.floor((array[i + 1] - min[1]) * multiplier[1]))); - } - math.identityMat3(translate); - math.translationMat3v(min, translate); - math.identityMat3(scale); - math.scalingMat3v([ - (max[0] - min[0]) / 65535, - (max[1] - min[1]) / 65535 - ], scale); - const decodeMat = math.mulMat3(translate, scale, math.identityMat3()); - return { - quantized: quantized, - decodeMatrix: decodeMat - }; - }; -})(); - - -//--------------- Normals ---------------------------------------------------------------------------------------------- - -/** - * @private - */ -function compressNormals(array) { // http://jcgt.org/published/0003/02/01/ - - // Note: three elements for each encoded normal, in which the last element in each triplet is redundant. - // This is to work around a mysterious WebGL issue where 2-element normals just wouldn't work in the shader :/ - - const encoded = new Int8Array(array.length); - let oct, dec, best, currentCos, bestCos; - for (let i = 0; i < array.length; i += 3) { - // Test various combinations of ceil and floor - // to minimize rounding errors - best = oct = octEncodeVec3$1(array, i, "floor", "floor"); - dec = octDecodeVec2$1(oct); - currentCos = bestCos = dot$1(array, i, dec); - oct = octEncodeVec3$1(array, i, "ceil", "floor"); - dec = octDecodeVec2$1(oct); - currentCos = dot$1(array, i, dec); - if (currentCos > bestCos) { - best = oct; - bestCos = currentCos; - } - oct = octEncodeVec3$1(array, i, "floor", "ceil"); - dec = octDecodeVec2$1(oct); - currentCos = dot$1(array, i, dec); - if (currentCos > bestCos) { - best = oct; - bestCos = currentCos; - } - oct = octEncodeVec3$1(array, i, "ceil", "ceil"); - dec = octDecodeVec2$1(oct); - currentCos = dot$1(array, i, dec); - if (currentCos > bestCos) { - best = oct; - bestCos = currentCos; - } - encoded[i] = best[0]; - encoded[i + 1] = best[1]; - } - return encoded; -} - -/** - * @private - */ -function octEncodeVec3$1(array, i, xfunc, yfunc) { // Oct-encode single normal vector in 2 bytes - let x = array[i] / (Math.abs(array[i]) + Math.abs(array[i + 1]) + Math.abs(array[i + 2])); - let y = array[i + 1] / (Math.abs(array[i]) + Math.abs(array[i + 1]) + Math.abs(array[i + 2])); - if (array[i + 2] < 0) { - let tempx = (1 - Math.abs(y)) * (x >= 0 ? 1 : -1); - let tempy = (1 - Math.abs(x)) * (y >= 0 ? 1 : -1); - x = tempx; - y = tempy; - } - return new Int8Array([ - Math[xfunc](x * 127.5 + (x < 0 ? -1 : 0)), - Math[yfunc](y * 127.5 + (y < 0 ? -1 : 0)) - ]); -} - -/** - * Decode an oct-encoded normal - */ -function octDecodeVec2$1(oct) { - let x = oct[0]; - let y = oct[1]; - x /= x < 0 ? 127 : 128; - y /= y < 0 ? 127 : 128; - const z = 1 - Math.abs(x) - Math.abs(y); - if (z < 0) { - x = (1 - Math.abs(y)) * (x >= 0 ? 1 : -1); - y = (1 - Math.abs(x)) * (y >= 0 ? 1 : -1); - } - const length = Math.sqrt(x * x + y * y + z * z); - return [ - x / length, - y / length, - z / length - ]; -} - -/** - * Dot product of a normal in an array against a candidate decoding - * @private - */ -function dot$1(array, i, vec3) { - return array[i] * vec3[0] + array[i + 1] * vec3[1] + array[i + 2] * vec3[2]; -} - -/** - * @private - */ -function decompressUV(uv, decodeMatrix, dest) { - dest[0] = uv[0] * decodeMatrix[0] + decodeMatrix[6]; - dest[1] = uv[1] * decodeMatrix[4] + decodeMatrix[7]; -} - -/** - * @private - */ -function decompressUVs(uvs, decodeMatrix, dest = new Float32Array(uvs.length)) { - for (let i = 0, len = uvs.length; i < len; i += 3) { - dest[i + 0] = uvs[i + 0] * decodeMatrix[0] + decodeMatrix[6]; - dest[i + 1] = uvs[i + 1] * decodeMatrix[4] + decodeMatrix[7]; - } - return dest; -} - -/** - * @private - */ -function decompressNormal(oct, result) { - let x = oct[0]; - let y = oct[1]; - x = (2 * x + 1) / 255; - y = (2 * y + 1) / 255; - const z = 1 - Math.abs(x) - Math.abs(y); - if (z < 0) { - x = (1 - Math.abs(y)) * (x >= 0 ? 1 : -1); - y = (1 - Math.abs(x)) * (y >= 0 ? 1 : -1); - } - const length = Math.sqrt(x * x + y * y + z * z); - result[0] = x / length; - result[1] = y / length; - result[2] = z / length; - return result; -} - -/** - * @private - */ -function decompressNormals(octs, result) { - for (let i = 0, j = 0, len = octs.length; i < len; i += 2) { - let x = octs[i + 0]; - let y = octs[i + 1]; - x = (2 * x + 1) / 255; - y = (2 * y + 1) / 255; - const z = 1 - Math.abs(x) - Math.abs(y); - if (z < 0) { - x = (1 - Math.abs(y)) * (x >= 0 ? 1 : -1); - y = (1 - Math.abs(x)) * (y >= 0 ? 1 : -1); - } - const length = Math.sqrt(x * x + y * y + z * z); - result[j + 0] = x / length; - result[j + 1] = y / length; - result[j + 2] = z / length; - j += 3; - } - return result; -} - -/** - * @private - */ -const geometryCompressionUtils = { - - getPositionsBounds: getPositionsBounds, - createPositionsDecodeMatrix: createPositionsDecodeMatrix$1, - compressPositions: compressPositions, - compressPosition:compressPosition, - decompressPositions: decompressPositions, - decompressPosition: decompressPosition, - decompressAABB: decompressAABB, - - getUVBounds: getUVBounds, - compressUVs: compressUVs, - decompressUVs: decompressUVs, - decompressUV: decompressUV, - - compressNormals: compressNormals, - decompressNormals: decompressNormals, - decompressNormal: decompressNormal -}; - -const memoryStats$1 = stats.memory; -const tempAABB$3 = math.AABB3(); - -/** - * @desc A {@link Geometry} that keeps its geometry data in both browser and GPU memory. - * - * ReadableGeometry uses more memory than {@link VBOGeometry}, which only stores its geometry data in GPU memory. - * - * ## Usage - * - * Creating a {@link Mesh} with a ReadableGeometry that defines a single triangle, plus a {@link PhongMaterial} with diffuse {@link Texture}: - * - * [[Run this example](/examples/index.html#geometry_ReadableGeometry)] - * - * ````javascript - * import {Viewer, Mesh, ReadableGeometry, PhongMaterial, Texture} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * const myMesh = new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, { - * primitive: "triangles", - * positions: [0.0, 3, 0.0, -3, -3, 0.0, 3, -3, 0.0], - * normals: [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0], - * uv: [0.0, 0.0, 0.5, 1.0, 1.0, 0.0], - * indices: [0, 1, 2] - * }), - * material: new PhongMaterial(viewer.scene, { - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }), - * backfaces: true - * }) - * }); - * - * // Get geometry data from browser memory: - * - * const positions = myMesh.geometry.positions; // Flat arrays - * const normals = myMesh.geometry.normals; - * const uv = myMesh.geometry.uv; - * const indices = myMesh.geometry.indices; - * - * ```` - */ -class ReadableGeometry extends Geometry { - - /** - @private - */ - get type() { - return "ReadableGeometry"; - } - - /** - * @private - * @returns {Boolean} - */ - get isReadableGeometry() { - return true; - } - - /** - * - @class ReadableGeometry - @module xeokit - @submodule geometry - @constructor - @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - @param {*} [cfg] Configs - @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, - generated automatically when omitted. - @param {String:Object} [cfg.meta] Optional map of user-defined metadata to attach to this Geometry. - @param [cfg.primitive="triangles"] {String} The primitive type. Accepted values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. - @param [cfg.positions] {Number[]} Positions array. - @param [cfg.normals] {Number[]} Vertex normal vectors array. - @param [cfg.uv] {Number[]} UVs array. - @param [cfg.colors] {Number[]} Vertex colors. - @param [cfg.indices] {Number[]} Indices array. - @param [cfg.autoVertexNormals=false] {Boolean} Set true to automatically generate normal vectors from the positions and - indices, if those are supplied. - @param [cfg.compressGeometry=false] {Boolean} Stores positions, colors, normals and UVs in compressGeometry and oct-encoded formats - for reduced memory footprint and GPU bus usage. - @param [cfg.edgeThreshold=10] {Number} When a {@link Mesh} renders this Geometry as wireframe, - this indicates the threshold angle (in degrees) between the face normals of adjacent triangles below which the edge is discarded. - @extends Component - * @param owner - * @param cfg - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._state = new RenderState({ // Arrays for emphasis effects are got from xeokit.Geometry friend methods - compressGeometry: !!cfg.compressGeometry, - primitive: null, // WebGL enum - primitiveName: null, // String - positions: null, // Uint16Array when compressGeometry == true, else Float32Array - normals: null, // Uint8Array when compressGeometry == true, else Float32Array - colors: null, - uv: null, // Uint8Array when compressGeometry == true, else Float32Array - indices: null, - positionsDecodeMatrix: null, // Set when compressGeometry == true - uvDecodeMatrix: null, // Set when compressGeometry == true - positionsBuf: null, - normalsBuf: null, - colorsbuf: null, - uvBuf: null, - indicesBuf: null, - hash: "" - }); - - this._numTriangles = 0; - - this._edgeThreshold = cfg.edgeThreshold || 10.0; - - // Lazy-generated VBOs - - this._edgeIndicesBuf = null; - this._pickTrianglePositionsBuf = null; - this._pickTriangleColorsBuf = null; - - // Local-space Boundary3D - - this._aabbDirty = true; - - this._boundingSphere = true; - this._aabb = null; - this._aabbDirty = true; - - this._obb = null; - this._obbDirty = true; - - const state = this._state; - const gl = this.scene.canvas.gl; - - // Primitive type - - cfg.primitive = cfg.primitive || "triangles"; - switch (cfg.primitive) { - case "points": - state.primitive = gl.POINTS; - state.primitiveName = cfg.primitive; - break; - case "lines": - state.primitive = gl.LINES; - state.primitiveName = cfg.primitive; - break; - case "line-loop": - state.primitive = gl.LINE_LOOP; - state.primitiveName = cfg.primitive; - break; - case "line-strip": - state.primitive = gl.LINE_STRIP; - state.primitiveName = cfg.primitive; - break; - case "triangles": - state.primitive = gl.TRIANGLES; - state.primitiveName = cfg.primitive; - break; - case "triangle-strip": - state.primitive = gl.TRIANGLE_STRIP; - state.primitiveName = cfg.primitive; - break; - case "triangle-fan": - state.primitive = gl.TRIANGLE_FAN; - state.primitiveName = cfg.primitive; - break; - default: - this.error("Unsupported value for 'primitive': '" + cfg.primitive + - "' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', " + - "'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."); - state.primitive = gl.TRIANGLES; - state.primitiveName = cfg.primitive; - } - - if (cfg.positions) { - if (this._state.compressGeometry) { - const bounds = geometryCompressionUtils.getPositionsBounds(cfg.positions); - const result = geometryCompressionUtils.compressPositions(cfg.positions, bounds.min, bounds.max); - state.positions = result.quantized; - state.positionsDecodeMatrix = result.decodeMatrix; - } else { - state.positions = cfg.positions.constructor === Float32Array ? cfg.positions : new Float32Array(cfg.positions); - } - } - if (cfg.colors) { - state.colors = cfg.colors.constructor === Float32Array ? cfg.colors : new Float32Array(cfg.colors); - } - if (cfg.uv) { - if (this._state.compressGeometry) { - const bounds = geometryCompressionUtils.getUVBounds(cfg.uv); - const result = geometryCompressionUtils.compressUVs(cfg.uv, bounds.min, bounds.max); - state.uv = result.quantized; - state.uvDecodeMatrix = result.decodeMatrix; - } else { - state.uv = cfg.uv.constructor === Float32Array ? cfg.uv : new Float32Array(cfg.uv); - } - } - if (cfg.normals) { - if (this._state.compressGeometry) { - state.normals = geometryCompressionUtils.compressNormals(cfg.normals); - } else { - state.normals = cfg.normals.constructor === Float32Array ? cfg.normals : new Float32Array(cfg.normals); - } - } - if (cfg.indices) { - state.indices = (cfg.indices.constructor === Uint32Array || cfg.indices.constructor === Uint16Array) ? cfg.indices : new Uint32Array(cfg.indices); - if (this._state.primitiveName === "triangles") { - this._numTriangles = (cfg.indices.length / 3); - } - } - - this._buildHash(); - - memoryStats$1.meshes++; - - if (state.indices) { - state.indicesBuf = new ArrayBuf(gl, gl.ELEMENT_ARRAY_BUFFER, state.indices, state.indices.length, 1, gl.STATIC_DRAW); - memoryStats$1.indices += state.indicesBuf.numItems; - } - if (state.positions) { - state.positionsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, state.positions, state.positions.length, 3, gl.STATIC_DRAW); - memoryStats$1.positions += state.positionsBuf.numItems; - } - if (state.normals) { - let normalized = state.compressGeometry; - state.normalsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, state.normals, state.normals.length, 3, gl.STATIC_DRAW, normalized); - memoryStats$1.normals += state.normalsBuf.numItems; - } - if (state.colors) { - state.colorsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, state.colors, state.colors.length, 4, gl.STATIC_DRAW); - memoryStats$1.colors += state.colorsBuf.numItems; - } - if (state.uv) { - state.uvBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, state.uv, state.uv.length, 2, gl.STATIC_DRAW); - memoryStats$1.uvs += state.uvBuf.numItems; - } - } - - _buildHash() { - const state = this._state; - const hash = ["/g"]; - hash.push("/" + state.primitive + ";"); - if (state.positions) { - hash.push("p"); - } - if (state.colors) { - hash.push("c"); - } - if (state.normals || state.autoVertexNormals) { - hash.push("n"); - } - if (state.uv) { - hash.push("u"); - } - if (state.compressGeometry) { - hash.push("cp"); - } - hash.push(";"); - state.hash = hash.join(""); - } - - _getEdgeIndices() { - if (!this._edgeIndicesBuf) { - this._buildEdgeIndices(); - } - return this._edgeIndicesBuf; - } - - _getPickTrianglePositions() { - if (!this._pickTrianglePositionsBuf) { - this._buildPickTriangleVBOs(); - } - return this._pickTrianglePositionsBuf; - } - - _getPickTriangleColors() { - if (!this._pickTriangleColorsBuf) { - this._buildPickTriangleVBOs(); - } - return this._pickTriangleColorsBuf; - } - - _buildEdgeIndices() { // FIXME: Does not adjust indices after other objects are deleted from vertex buffer!! - const state = this._state; - if (!state.positions || !state.indices) { - return; - } - const gl = this.scene.canvas.gl; - const edgeIndices = buildEdgeIndices(state.positions, state.indices, state.positionsDecodeMatrix, this._edgeThreshold); - this._edgeIndicesBuf = new ArrayBuf(gl, gl.ELEMENT_ARRAY_BUFFER, edgeIndices, edgeIndices.length, 1, gl.STATIC_DRAW); - memoryStats$1.indices += this._edgeIndicesBuf.numItems; - } - - _buildPickTriangleVBOs() { // Builds positions and indices arrays that allow each triangle to have a unique color - const state = this._state; - if (!state.positions || !state.indices) { - return; - } - const gl = this.scene.canvas.gl; - const arrays = math.buildPickTriangles(state.positions, state.indices, state.compressGeometry); - const positions = arrays.positions; - const colors = arrays.colors; - this._pickTrianglePositionsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, positions, positions.length, 3, gl.STATIC_DRAW); - this._pickTriangleColorsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, colors, colors.length, 4, gl.STATIC_DRAW, true); - memoryStats$1.positions += this._pickTrianglePositionsBuf.numItems; - memoryStats$1.colors += this._pickTriangleColorsBuf.numItems; - } - - _buildPickVertexVBOs() { - // var state = this._state; - // if (!state.positions || !state.indices) { - // return; - // } - // var gl = this.scene.canvas.gl; - // var arrays = math.buildPickVertices(state.positions, state.indices, state.compressGeometry); - // var pickVertexPositions = arrays.positions; - // var pickColors = arrays.colors; - // this._pickVertexPositionsBuf = new xeokit.renderer.ArrayBuf(gl, gl.ARRAY_BUFFER, pickVertexPositions, pickVertexPositions.length, 3, gl.STATIC_DRAW); - // this._pickVertexColorsBuf = new xeokit.renderer.ArrayBuf(gl, gl.ARRAY_BUFFER, pickColors, pickColors.length, 4, gl.STATIC_DRAW, true); - // memoryStats.positions += this._pickVertexPositionsBuf.numItems; - // memoryStats.colors += this._pickVertexColorsBuf.numItems; - } - - /** - * Gets the Geometry's primitive type. - - Valid types are: 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. - - @property primitive - @default "triangles" - @type {String} - */ - get primitive() { - return this._state.primitiveName; - } - - /** - Indicates if this Geometry is quantized. - - Compression is an internally-performed optimization which stores positions, colors, normals and UVs - in quantized and oct-encoded formats for reduced memory footprint and GPU bus usage. - - Quantized geometry may not be updated. - - @property compressGeometry - @default false - @type {Boolean} - @final - */ - get compressGeometry() { - return this._state.compressGeometry; - } - - /** - The Geometry's vertex positions. - - @property positions - @default null - @type {Number[]} - */ - get positions() { - if (!this._state.positions) { - return null; - } - if (!this._state.compressGeometry) { - return this._state.positions; - } - if (!this._decompressedPositions) { - this._decompressedPositions = new Float32Array(this._state.positions.length); - geometryCompressionUtils.decompressPositions(this._state.positions, this._state.positionsDecodeMatrix, this._decompressedPositions); - } - return this._decompressedPositions; - } - - set positions(newPositions) { - const state = this._state; - const positions = state.positions; - if (!positions) { - this.error("can't update geometry positions - geometry has no positions"); - return; - } - if (positions.length !== newPositions.length) { - this.error("can't update geometry positions - new positions are wrong length"); - return; - } - if (this._state.compressGeometry) { - const bounds = geometryCompressionUtils.getPositionsBounds(newPositions); - const result = geometryCompressionUtils.compressPositions(newPositions, bounds.min, bounds.max); - newPositions = result.quantized; // TODO: Copy in-place - state.positionsDecodeMatrix = result.decodeMatrix; - } - positions.set(newPositions); - if (state.positionsBuf) { - state.positionsBuf.setData(positions); - } - this._setAABBDirty(); - this.glRedraw(); - } - - /** - The Geometry's vertex normals. - - @property normals - @default null - @type {Number[]} - */ - get normals() { - if (!this._state.normals) { - return; - } - if (!this._state.compressGeometry) { - return this._state.normals; - } - if (!this._decompressedNormals) { - const lenCompressed = this._state.normals.length; - const lenDecompressed = lenCompressed + (lenCompressed / 2); // 2 -> 3 - this._decompressedNormals = new Float32Array(lenDecompressed); - geometryCompressionUtils.decompressNormals(this._state.normals, this._decompressedNormals); - } - return this._decompressedNormals; - } - - set normals(newNormals) { - if (this._state.compressGeometry) { - this.error("can't update geometry normals - quantized geometry is immutable"); // But will be eventually - return; - } - const state = this._state; - const normals = state.normals; - if (!normals) { - this.error("can't update geometry normals - geometry has no normals"); - return; - } - if (normals.length !== newNormals.length) { - this.error("can't update geometry normals - new normals are wrong length"); - return; - } - normals.set(newNormals); - if (state.normalsBuf) { - state.normalsBuf.setData(normals); - } - this.glRedraw(); - } - - - /** - The Geometry's UV coordinates. - - @property uv - @default null - @type {Number[]} - */ - get uv() { - if (!this._state.uv) { - return null; - } - if (!this._state.compressGeometry) { - return this._state.uv; - } - if (!this._decompressedUV) { - this._decompressedUV = new Float32Array(this._state.uv.length); - geometryCompressionUtils.decompressUVs(this._state.uv, this._state.uvDecodeMatrix, this._decompressedUV); - } - return this._decompressedUV; - } - - set uv(newUV) { - if (this._state.compressGeometry) { - this.error("can't update geometry UVs - quantized geometry is immutable"); // But will be eventually - return; - } - const state = this._state; - const uv = state.uv; - if (!uv) { - this.error("can't update geometry UVs - geometry has no UVs"); - return; - } - if (uv.length !== newUV.length) { - this.error("can't update geometry UVs - new UVs are wrong length"); - return; - } - uv.set(newUV); - if (state.uvBuf) { - state.uvBuf.setData(uv); - } - this.glRedraw(); - } - - /** - The Geometry's vertex colors. - - @property colors - @default null - @type {Number[]} - */ - get colors() { - return this._state.colors; - } - - set colors(newColors) { - if (this._state.compressGeometry) { - this.error("can't update geometry colors - quantized geometry is immutable"); // But will be eventually - return; - } - const state = this._state; - const colors = state.colors; - if (!colors) { - this.error("can't update geometry colors - geometry has no colors"); - return; - } - if (colors.length !== newColors.length) { - this.error("can't update geometry colors - new colors are wrong length"); - return; - } - colors.set(newColors); - if (state.colorsBuf) { - state.colorsBuf.setData(colors); - } - this.glRedraw(); - } - - /** - The Geometry's indices. - - If ````xeokit.WEBGL_INFO.SUPPORTED_EXTENSIONS["OES_element_index_uint"]```` is true, then this can be - a ````Uint32Array````, otherwise it needs to be a ````Uint16Array````. - - @property indices - @default null - @type Uint16Array | Uint32Array - @final - */ - get indices() { - return this._state.indices; - } - - /** - * Local-space axis-aligned 3D boundary (AABB) of this geometry. - * - * The AABB is represented by a six-element Float64Array containing the min/max extents of the - * axis-aligned volume, ie. ````[xmin, ymin,zmin,xmax,ymax, zmax]````. - * - * @property aabb - * @final - * @type {Number[]} - */ - get aabb() { - if (this._aabbDirty) { - if (!this._aabb) { - this._aabb = math.AABB3(); - } - math.positions3ToAABB3(this._state.positions, this._aabb, this._state.positionsDecodeMatrix); - this._aabbDirty = false; - } - return this._aabb; - } - - /** - * Local-space oriented 3D boundary (OBB) of this geometry. - * - * The OBB is represented by a 32-element Float64Array containing the eight vertices of the box, - * where each vertex is a homogeneous coordinate having [x,y,z,w] elements. - * - * @property obb - * @final - * @type {Number[]} - */ - get obb() { - if (this._obbDirty) { - if (!this._obb) { - this._obb = math.OBB3(); - } - math.positions3ToAABB3(this._state.positions, tempAABB$3, this._state.positionsDecodeMatrix); - math.AABB3ToOBB3(tempAABB$3, this._obb); - this._obbDirty = false; - } - return this._obb; - } - - _getMetrics() { - if (! ("_metrics" in this)) { - switch (this._state.primitiveName) { - case "solid": - case "surface": - case "triangles": { - const indices = this._state.indices; - const positions = this._state.positions; - const getPos = (i, out) => { - const idx = indices[i] * 3; - for (let j = 0; j < 3; ++j) { - out[j] = positions[idx + j]; - } return out; - }; - const tmp = [ math.vec3(), math.vec3(), math.vec3(), math.vec3() ]; - let totalArea = 0; - const centroid = math.vec3([ 0, 0, 0 ]); - for (let i = 0; i < indices.length; i += 3) { - const v0 = getPos(i, tmp[0]); - const v1 = getPos(i+1, tmp[1]); - const v2 = getPos(i+2, tmp[2]); - math.addVec3(v0, v1, tmp[3]); - math.addVec3(v2, tmp[3], tmp[3]); - const faceArea = math.lenVec3( - math.cross3Vec3( - math.subVec3(v1, v0, tmp[1]), - math.subVec3(v2, v0, tmp[2]), - tmp[0])) / 2; - totalArea += faceArea; - math.mulVec3Scalar(tmp[3], faceArea, tmp[3]); - math.addVec3(centroid, tmp[3], centroid); - } - this._metrics = { surfaceArea: totalArea, centroid: math.mulVec3Scalar(centroid, 1 / totalArea / 3, centroid) }; - break; - } - default: - this._metrics = { surfaceArea: 0 }; - break; - } - } - return this._metrics; - } - - /** - * Returns the surface area of this Mesh. - * @returns {number} - */ - get surfaceArea() { - return this._getMetrics().surfaceArea; - } - - /** - * Returns the centroid of this Mesh. - * @returns {number} - */ - get centroid() { - return this._getMetrics().centroid; - } - - /** - * Approximate number of triangles in this ReadableGeometry. - * - * Will be zero if {@link ReadableGeometry#primitive} is not 'triangles', 'triangle-strip' or 'triangle-fan'. - * - * @type {Number} - */ - get numTriangles() { - return this._numTriangles; - } - - _setAABBDirty() { - if (this._aabbDirty) { - return; - } - this._aabbDirty = true; - this._aabbDirty = true; - this._obbDirty = true; - } - - _getState() { - return this._state; - } - - /** - * Destroys this ReadableGeometry - */ - destroy() { - super.destroy(); - const state = this._state; - if (state.indicesBuf) { - state.indicesBuf.destroy(); - } - if (state.positionsBuf) { - state.positionsBuf.destroy(); - } - if (state.normalsBuf) { - state.normalsBuf.destroy(); - } - if (state.uvBuf) { - state.uvBuf.destroy(); - } - if (state.colorsBuf) { - state.colorsBuf.destroy(); - } - if (this._edgeIndicesBuf) { - this._edgeIndicesBuf.destroy(); - } - if (this._pickTrianglePositionsBuf) { - this._pickTrianglePositionsBuf.destroy(); - } - if (this._pickTriangleColorsBuf) { - this._pickTriangleColorsBuf.destroy(); - } - if (this._pickVertexPositionsBuf) { - this._pickVertexPositionsBuf.destroy(); - } - if (this._pickVertexColorsBuf) { - this._pickVertexColorsBuf.destroy(); - } - state.destroy(); - memoryStats$1.meshes--; - } -} - -const memoryStats = stats.memory; -const tempAABB$2 = math.AABB3(); - -/** - * @desc A {@link Geometry} that keeps its geometry data solely in GPU memory, without retaining it in browser memory. - * - * VBOGeometry uses less memory than {@link ReadableGeometry}, which keeps its geometry data in both browser and GPU memory. - * - * ## Usage - * - * Creating a {@link Mesh} with a VBOGeometry that defines a single triangle, plus a {@link PhongMaterial} with diffuse {@link Texture}: - * - * [[Run this example](/examples/index.html#geometry_VBOGeometry)] - * - * ````javascript - * import {Viewer, Mesh, VBOGeometry, PhongMaterial, Texture} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * new Mesh(viewer.scene, { - * geometry: new VBOGeometry(viewer.scene, { - * primitive: "triangles", - * positions: [0.0, 3, 0.0, -3, -3, 0.0, 3, -3, 0.0], - * normals: [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0], - * uv: [0.0, 0.0, 0.5, 1.0, 1.0, 0.0], - * indices: [0, 1, 2] - * }), - * material: new PhongMaterial(viewer.scene, { - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }), - * backfaces: true - * }) - * }); - * ```` - */ -class VBOGeometry extends Geometry { - - /** - @private - */ - get type() { - return "VBOGeometry"; - } - - /** - * @private - * @returns {Boolean} - */ - get isVBOGeometry() { - return true; - } - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {String} [cfg.primitive="triangles"] The primitive type. Accepted values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. - * @param {Number[]} [cfg.positions] Positions array. - * @param {Number[]} [cfg.normals] Vertex normal vectors array. - * @param {Number[]} [cfg.uv] UVs array. - * @param {Number[]} [cfg.colors] Vertex colors. - * @param {Number[]} [cfg.indices] Indices array. - * @param {Number} [cfg.edgeThreshold=10] When autogenerating edges for supporting {@link Drawable#edges}, this indicates the threshold angle (in degrees) between the face normals of adjacent triangles below which the edge is discarded. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._state = new RenderState({ // Arrays for emphasis effects are got from xeokit.GeometryLite friend methods - compressGeometry: true, - primitive: null, // WebGL enum - primitiveName: null, // String - positionsDecodeMatrix: null, // Set when compressGeometry == true - uvDecodeMatrix: null, // Set when compressGeometry == true - positionsBuf: null, - normalsBuf: null, - colorsbuf: null, - uvBuf: null, - indicesBuf: null, - hash: "" - }); - - this._numTriangles = 0; - - this._edgeThreshold = cfg.edgeThreshold || 10.0; - this._aabb = null; - this._obb = math.OBB3(); - - const state = this._state; - const gl = this.scene.canvas.gl; - - cfg.primitive = cfg.primitive || "triangles"; - switch (cfg.primitive) { - case "points": - state.primitive = gl.POINTS; - state.primitiveName = cfg.primitive; - break; - case "lines": - state.primitive = gl.LINES; - state.primitiveName = cfg.primitive; - break; - case "line-loop": - state.primitive = gl.LINE_LOOP; - state.primitiveName = cfg.primitive; - break; - case "line-strip": - state.primitive = gl.LINE_STRIP; - state.primitiveName = cfg.primitive; - break; - case "triangles": - state.primitive = gl.TRIANGLES; - state.primitiveName = cfg.primitive; - break; - case "triangle-strip": - state.primitive = gl.TRIANGLE_STRIP; - state.primitiveName = cfg.primitive; - break; - case "triangle-fan": - state.primitive = gl.TRIANGLE_FAN; - state.primitiveName = cfg.primitive; - break; - default: - this.error("Unsupported value for 'primitive': '" + cfg.primitive + - "' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', " + - "'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."); - state.primitive = gl.TRIANGLES; - state.primitiveName = cfg.primitive; - } - - if (!cfg.positions) { - this.error("Config expected: positions"); - return; // TODO: Recover? - } - - if (!cfg.indices) { - this.error("Config expected: indices"); - return; // TODO: Recover? - } - - var positions; - - { - const positionsDecodeMatrix = cfg.positionsDecodeMatrix; - - if (positionsDecodeMatrix) ; else { - - // Uncompressed positions - - const bounds = geometryCompressionUtils.getPositionsBounds(cfg.positions); - const result = geometryCompressionUtils.compressPositions(cfg.positions, bounds.min, bounds.max); - positions = result.quantized; - state.positionsDecodeMatrix = result.decodeMatrix; - state.positionsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, positions, positions.length, 3, gl.STATIC_DRAW); - memoryStats.positions += state.positionsBuf.numItems; - math.positions3ToAABB3(cfg.positions, this._aabb); - math.positions3ToAABB3(positions, tempAABB$2, state.positionsDecodeMatrix); - math.AABB3ToOBB3(tempAABB$2, this._obb); - } - } - - if (cfg.colors) { - const colors = cfg.colors.constructor === Float32Array ? cfg.colors : new Float32Array(cfg.colors); - state.colorsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, colors, colors.length, 4, gl.STATIC_DRAW); - memoryStats.colors += state.colorsBuf.numItems; - } - - if (cfg.uv) { - const bounds = geometryCompressionUtils.getUVBounds(cfg.uv); - const result = geometryCompressionUtils.compressUVs(cfg.uv, bounds.min, bounds.max); - const uv = result.quantized; - state.uvDecodeMatrix = result.decodeMatrix; - state.uvBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, uv, uv.length, 2, gl.STATIC_DRAW); - memoryStats.uvs += state.uvBuf.numItems; - } - - if (cfg.normals) { - const normals = geometryCompressionUtils.compressNormals(cfg.normals); - let normalized = state.compressGeometry; - state.normalsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, normals, normals.length, 3, gl.STATIC_DRAW, normalized); - memoryStats.normals += state.normalsBuf.numItems; - } - - { - const indices = (cfg.indices.constructor === Uint32Array || cfg.indices.constructor === Uint16Array) ? cfg.indices : new Uint32Array(cfg.indices); - state.indicesBuf = new ArrayBuf(gl, gl.ELEMENT_ARRAY_BUFFER, indices, indices.length, 1, gl.STATIC_DRAW); - memoryStats.indices += state.indicesBuf.numItems; - const edgeIndices = buildEdgeIndices(positions, indices, state.positionsDecodeMatrix, this._edgeThreshold); - this._edgeIndicesBuf = new ArrayBuf(gl, gl.ELEMENT_ARRAY_BUFFER, edgeIndices, edgeIndices.length, 1, gl.STATIC_DRAW); - - if (this._state.primitiveName === "triangles") { - this._numTriangles = (cfg.indices.length / 3); - } - } - - this._buildHash(); - - memoryStats.meshes++; - } - - _buildHash() { - const state = this._state; - const hash = ["/g"]; - hash.push("/" + state.primitive + ";"); - if (state.positionsBuf) { - hash.push("p"); - } - if (state.colorsBuf) { - hash.push("c"); - } - if (state.normalsBuf || state.autoVertexNormals) { - hash.push("n"); - } - if (state.uvBuf) { - hash.push("u"); - } - hash.push("cp"); // Always compressed - hash.push(";"); - state.hash = hash.join(""); - } - - _getEdgeIndices() { - return this._edgeIndicesBuf; - } - - /** - * Gets the primitive type. - * - * Possible types are: 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. - * - * @type {String} - */ - get primitive() { - return this._state.primitiveName; - } - - /** - * Gets the local-space axis-aligned 3D boundary (AABB). - * - * The AABB is represented by a six-element Float64Array containing the min/max extents of the axis-aligned volume, ie. ````[xmin, ymin,zmin,xmax,ymax, zmax]````. - * - * @type {Number[]} - */ - get aabb() { - return this._aabb; - } - - /** - * Gets the local-space oriented 3D boundary (OBB). - * - * The OBB is represented by a 32-element Float64Array containing the eight vertices of the box, where each vertex is a homogeneous coordinate having [x,y,z,w] elements. - * - * @type {Number[]} - */ - get obb() { - return this._obb; - } - - /** - * Approximate number of triangles in this VBOGeometry. - * - * Will be zero if {@link VBOGeometry#primitive} is not 'triangles', 'triangle-strip' or 'triangle-fan'. - * - * @type {Number} - */ - get numTriangles() { - return this._numTriangles; - } - - /** @private */ - _getState() { - return this._state; - } - - /** - * Destroys this component. - */ - destroy() { - super.destroy(); - const state = this._state; - if (state.indicesBuf) { - state.indicesBuf.destroy(); - } - if (state.positionsBuf) { - state.positionsBuf.destroy(); - } - if (state.normalsBuf) { - state.normalsBuf.destroy(); - } - if (state.uvBuf) { - state.uvBuf.destroy(); - } - if (state.colorsBuf) { - state.colorsBuf.destroy(); - } - if (this._edgeIndicesBuf) { - this._edgeIndicesBuf.destroy(); - } - state.destroy(); - memoryStats.meshes--; - } -} - -/** - * @private - */ -var K3D = {}; - -K3D.load = function(path, resp) -{ - var request = new XMLHttpRequest(); - request.open("GET", path, true); - request.responseType = "arraybuffer"; - request.onload = function(e){resp(e.target.response);}; - request.send(); -}; - -K3D.save = function(buff, path) -{ - var dataURI = "data:application/octet-stream;base64," + btoa(K3D.parse._buffToStr(buff)); - window.location.href = dataURI; -}; - -K3D.clone = function(o) -{ - return JSON.parse(JSON.stringify(o)); -}; - - - -K3D.bin = {}; - -K3D.bin.f = new Float32Array(1); -K3D.bin.fb = new Uint8Array(K3D.bin.f.buffer); - -K3D.bin.rf = function(buff, off) { var f = K3D.bin.f, fb = K3D.bin.fb; for(var i=0; i<4; i++) fb[i] = buff[off+i]; return f[0]; }; -K3D.bin.rsl = function(buff, off) { return buff[off] | buff[off+1]<<8; }; -K3D.bin.ril = function(buff, off) { return buff[off] | buff[off+1]<<8 | buff[off+2]<<16 | buff[off+3]<<24; }; -K3D.bin.rASCII0 = function(buff, off) { var s = ""; while(buff[off]!=0) s += String.fromCharCode(buff[off++]); return s; }; - - -K3D.bin.wf = function(buff, off, v) { var f=new Float32Array(buff.buffer, off, 1); f[0]=v; }; -K3D.bin.wsl = function(buff, off, v) { buff[off]=v; buff[off+1]=v>>8; }; -K3D.bin.wil = function(buff, off, v) { buff[off]=v; buff[off+1]=v>>8; buff[off+2]=v>>16; buff[off+3]>>24; }; -K3D.parse = {}; - -K3D.parse._buffToStr = function(buff) -{ - var a = new Uint8Array(buff); - var s = ""; - for(var i=0; imaxx) maxx = vx; - if(vymaxy) maxy = vy; - if(vzmaxz) maxz = vz; - } - return {min:{x:minx, y:miny, z:minz}, max:{x:maxx, y:maxy, z:maxz}}; -}; - -/** - * @desc Loads {@link Geometry} from 3DS. - * - * ## Usage - * - * In the example below we'll create a {@link Mesh} with {@link PhongMaterial}, {@link Texture} and a {@link ReadableGeometry} loaded from 3DS. - * - * ````javascript - * import {Viewer, Mesh, load3DSGeometry, ReadableGeometry, PhongMaterial, Texture} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [40.04, 23.46, 79.06]; - * viewer.scene.camera.look = [-6.48, 13.92, -0.56]; - * viewer.scene.camera.up = [-0.04, 0.98, -0.08]; - * - * load3DSGeometry(viewer.scene, { - * src: "models/3ds/lexus.3ds", - * compressGeometry: false - * - * }).then(function (geometryCfg) { - * - * // Success - * - * new Mesh(viewer.scene, { - * - * geometry: new ReadableGeometry(viewer.scene, geometryCfg), - * - * material: new PhongMaterial(viewer.scene, { - * - * emissive: [1, 1, 1], - * emissiveMap: new Texture({ // .3DS has no normals so relies on emissive illumination - * src: "models/3ds/lexus.jpg" - * }) - * }), - * - * rotation: [-90, 0, 0] // +Z is up for this particular 3DS - * }); - * }, function () { - * // Error - * }); - * ```` - * - * @function load3DSGeometry - * @param {Scene} scene Scene we're loading the geometry for. - * @param {*} cfg Configs, also added to the result object. - * @param {String} [cfg.src] Path to 3DS file. - * @returns {Object} Configuration to pass into a {@link Geometry} constructor, containing geometry arrays loaded from the OBJ file. - */ -function load3DSGeometry(scene, cfg = {}) { - - return new Promise(function (resolve, reject) { - - if (!cfg.src) { - console.error("load3DSGeometry: Parameter expected: src"); - reject(); - } - - var spinner = scene.canvas.spinner; - spinner.processes++; - - utils.loadArraybuffer(cfg.src, function (data) { - - if (!data.byteLength) { - console.error("load3DSGeometry: no data loaded"); - spinner.processes--; - reject(); - } - - var m = K3D.parse.from3DS(data); // done ! - - var mesh = m.edit.objects[0].mesh; - var positions = mesh.vertices; - var uv = mesh.uvt; - var indices = mesh.indices; - - spinner.processes--; - - resolve(utils.apply(cfg, { - primitive: "triangles", - positions: positions, - normals: null, - uv: uv, - indices: indices - })); - }, - - function (msg) { - console.error("load3DSGeometry: " + msg); - spinner.processes--; - reject(); - }); - }); -} - -/** - * @desc Loads {@link Geometry} from OBJ. - * - * ## Usage - * - * In the example below we'll create a {@link Mesh} with {@link MetallicMaterial} and {@link ReadableGeometry} loaded from OBJ. - * - * ````javascript - * import {Viewer, Mesh, loadOBJGeometry, ReadableGeometry, - * MetallicMaterial, Texture} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [0.57, 1.37, 1.14]; - * viewer.scene.camera.look = [0.04, 0.58, 0.00]; - * viewer.scene.camera.up = [-0.22, 0.84, -0.48]; - * - * loadOBJGeometry(viewer.scene, { - * - * src: "models/obj/fireHydrant/FireHydrantMesh.obj", - * compressGeometry: false - * - * }).then(function (geometryCfg) { - * - * // Success - * - * new Mesh(viewer.scene, { - * - * geometry: new ReadableGeometry(viewer.scene, geometryCfg), - * - * material: new MetallicMaterial(viewer.scene, { - * - * baseColor: [1, 1, 1], - * metallic: 1.0, - * roughness: 1.0, - * - * baseColorMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Base_Color.png", - * encoding: "sRGB" - * }), - * normalMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Normal_OpenGL.png" - * }), - * roughnessMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Roughness.png" - * }), - * metallicMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Metallic.png" - * }), - * occlusionMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Mixed_AO.png" - * }), - * - * specularF0: 0.7 - * }) - * }); - * }, function () { - * // Error - * }); - * ```` - * - * @function loadOBJGeometry - * @param {Scene} scene Scene we're loading the geometry for. - * @param {*} [cfg] Configs, also added to the result object. - * @param {String} [cfg.src] Path to OBJ file. - * @returns {Object} Configuration to pass into a {@link Geometry} constructor, containing geometry arrays loaded from the OBJ file. - */ -function loadOBJGeometry(scene, cfg = {}) { - - return new Promise(function (resolve, reject) { - - if (!cfg.src) { - console.error("loadOBJGeometry: Parameter expected: src"); - reject(); - } - - var spinner = scene.canvas.spinner; - spinner.processes++; - - utils.loadArraybuffer(cfg.src, function (data) { - - if (!data.byteLength) { - console.error("loadOBJGeometry: no data loaded"); - spinner.processes--; - reject(); - } - - var m = K3D.parse.fromOBJ(data); // done ! - - // unwrap simply duplicates some values, so they can be indexed with indices [0,1,2,3 ... ] - // In some rendering engines, you can have only one index value for vertices, UVs, normals ..., - // so "unwrapping" is a simple solution. - - var positions = K3D.edit.unwrap(m.i_verts, m.c_verts, 3); - var normals = K3D.edit.unwrap(m.i_norms, m.c_norms, 3); - var uv = K3D.edit.unwrap(m.i_uvt, m.c_uvt, 2); - var indices = new Int32Array(m.i_verts.length); - - for (var i = 0; i < m.i_verts.length; i++) { - indices[i] = i; - } - - spinner.processes--; - - resolve(utils.apply(cfg, { - primitive: "triangles", - positions: positions, - normals: normals.length > 0 ? normals : null, - autoNormals: normals.length === 0, - uv: uv, - indices: indices - })); - }, - - function (msg) { - console.error("loadOBJGeometry: " + msg); - spinner.processes--; - reject(); - }); - }); -} - -/** - * @desc Creates box-shaped {@link Geometry}. - * - * ## Usage - * - * In the example below we'll create a {@link Mesh} with a box-shaped {@link ReadableGeometry}. - * - * [[Run this example](/examples/index.html#geometry_builders_buildBoxGeometry)] - * - * ````javascript - * import {Viewer, Mesh, buildBoxGeometry, ReadableGeometry, PhongMaterial, Texture} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [0, 0, 5]; - * viewer.scene.camera.look = [0, 0, 0]; - * viewer.scene.camera.up = [0, 1, 0]; - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildBoxGeometry({ - * center: [0,0,0], - * xSize: 1, // Half-size on each axis - * ySize: 1, - * zSize: 1 - * }), - * material: new PhongMaterial(viewer.scene, { - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }) - * }) - * }); - * ```` - * - * @function buildBoxGeometry - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.center] 3D point indicating the center position. - * @param {Number} [cfg.xSize=1.0] Half-size on the X-axis. - * @param {Number} [cfg.ySize=1.0] Half-size on the Y-axis. - * @param {Number} [cfg.zSize=1.0] Half-size on the Z-axis. - * @returns {Object} Configuration for a {@link Geometry} subtype. - */ -function buildBoxGeometry(cfg = {}) { - - let xSize = cfg.xSize || 1; - if (xSize < 0) { - console.error("negative xSize not allowed - will invert"); - xSize *= -1; - } - - let ySize = cfg.ySize || 1; - if (ySize < 0) { - console.error("negative ySize not allowed - will invert"); - ySize *= -1; - } - - let zSize = cfg.zSize || 1; - if (zSize < 0) { - console.error("negative zSize not allowed - will invert"); - zSize *= -1; - } - - const center = cfg.center; - const centerX = center ? center[0] : 0; - const centerY = center ? center[1] : 0; - const centerZ = center ? center[2] : 0; - - const xmin = -xSize + centerX; - const ymin = -ySize + centerY; - const zmin = -zSize + centerZ; - const xmax = xSize + centerX; - const ymax = ySize + centerY; - const zmax = zSize + centerZ; - - return utils.apply(cfg, { - - // The vertices - eight for our cube, each - // one spanning three array elements for X,Y and Z - positions: [ - - // v0-v1-v2-v3 front - xmax, ymax, zmax, - xmin, ymax, zmax, - xmin, ymin, zmax, - xmax, ymin, zmax, - - // v0-v3-v4-v1 right - xmax, ymax, zmax, - xmax, ymin, zmax, - xmax, ymin, zmin, - xmax, ymax, zmin, - - // v0-v1-v6-v1 top - xmax, ymax, zmax, - xmax, ymax, zmin, - xmin, ymax, zmin, - xmin, ymax, zmax, - - // v1-v6-v7-v2 left - xmin, ymax, zmax, - xmin, ymax, zmin, - xmin, ymin, zmin, - xmin, ymin, zmax, - - // v7-v4-v3-v2 bottom - xmin, ymin, zmin, - xmax, ymin, zmin, - xmax, ymin, zmax, - xmin, ymin, zmax, - - // v4-v7-v6-v1 back - xmax, ymin, zmin, - xmin, ymin, zmin, - xmin, ymax, zmin, - xmax, ymax, zmin - ], - - // Normal vectors, one for each vertex - normals: [ - - // v0-v1-v2-v3 front - 0, 0, 1, - 0, 0, 1, - 0, 0, 1, - 0, 0, 1, - - // v0-v3-v4-v5 right - 1, 0, 0, - 1, 0, 0, - 1, 0, 0, - 1, 0, 0, - - // v0-v5-v6-v1 top - 0, 1, 0, - 0, 1, 0, - 0, 1, 0, - 0, 1, 0, - - // v1-v6-v7-v2 left - -1, 0, 0, - -1, 0, 0, - -1, 0, 0, - -1, 0, 0, - - // v7-v4-v3-v2 bottom - 0, -1, 0, - 0, -1, 0, - 0, -1, 0, - 0, -1, 0, - - // v4-v7-v6-v5 back - 0, 0, -1, - 0, 0, -1, - 0, 0, -1, - 0, 0, -1 - ], - - // UV coords - uv: [ - - // v0-v1-v2-v3 front - 1, 0, - 0, 0, - 0, 1, - 1, 1, - - // v0-v3-v4-v1 right - 0, 0, - 0, 1, - 1, 1, - 1, 0, - - // v0-v1-v6-v1 top - 1, 1, - 1, 0, - 0, 0, - 0, 1, - - // v1-v6-v7-v2 left - 1, 0, - 0, 0, - 0, 1, - 1, 1, - - // v7-v4-v3-v2 bottom - 0, 1, - 1, 1, - 1, 0, - 0, 0, - - // v4-v7-v6-v1 back - 0, 1, - 1, 1, - 1, 0, - 0, 0 - ], - - // Indices - these organise the - // positions and uv texture coordinates - // into geometric primitives in accordance - // with the "primitive" parameter, - // in this case a set of three indices - // for each triangle. - // - // Note that each triangle is specified - // in counter-clockwise winding order. - // - // You can specify them in clockwise - // order if you configure the Modes - // node's frontFace flag as "cw", instead of - // the default "ccw". - indices: [ - 0, 1, 2, - 0, 2, 3, - // front - 4, 5, 6, - 4, 6, 7, - // right - 8, 9, 10, - 8, 10, 11, - // top - 12, 13, 14, - 12, 14, 15, - // left - 16, 17, 18, - 16, 18, 19, - // bottom - 20, 21, 22, - 20, 22, 23 - ] - }); -} - -/** - * @desc Creates a box-shaped lines {@link Geometry}. - * - * ## Usage - * - * In the example below we'll create a {@link Mesh} with a box-shaped {@link ReadableGeometry} that has lines primitives. - * - * [[Run this example](/examples/index.html#geometry_builders_buildBoxLinesGeometry)] - * - * ````javascript - * import {Viewer, Mesh, buildBoxLinesGeometry, ReadableGeometry, PhongMaterial} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [0, 0, 5]; - * viewer.scene.camera.look = [0, 0, 0]; - * viewer.scene.camera.up = [0, 1, 0]; - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildBoxLinesGeometry({ - * center: [0,0,0], - * xSize: 1, // Half-size on each axis - * ySize: 1, - * zSize: 1 - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [0,1,0] - * }) - * }); - * ```` - * - * @function buildBoxLinesGeometry - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.center] 3D point indicating the center position. - * @param {Number} [cfg.xSize=1.0] Half-size on the X-axis. - * @param {Number} [cfg.ySize=1.0] Half-size on the Y-axis. - * @param {Number} [cfg.zSize=1.0] Half-size on the Z-axis. - * @returns {Object} Configuration for a {@link Geometry} subtype. - */ -function buildBoxLinesGeometry(cfg = {}) { - - let xSize = cfg.xSize || 1; - if (xSize < 0) { - console.error("negative xSize not allowed - will invert"); - xSize *= -1; - } - - let ySize = cfg.ySize || 1; - if (ySize < 0) { - console.error("negative ySize not allowed - will invert"); - ySize *= -1; - } - - let zSize = cfg.zSize || 1; - if (zSize < 0) { - console.error("negative zSize not allowed - will invert"); - zSize *= -1; - } - - const center = cfg.center; - const centerX = center ? center[0] : 0; - const centerY = center ? center[1] : 0; - const centerZ = center ? center[2] : 0; - - const xmin = -xSize + centerX; - const ymin = -ySize + centerY; - const zmin = -zSize + centerZ; - const xmax = xSize + centerX; - const ymax = ySize + centerY; - const zmax = zSize + centerZ; - - return utils.apply(cfg, { - primitive: "lines", - positions: [ - xmin, ymin, zmin, - xmin, ymin, zmax, - xmin, ymax, zmin, - xmin, ymax, zmax, - xmax, ymin, zmin, - xmax, ymin, zmax, - xmax, ymax, zmin, - xmax, ymax, zmax - ], - indices: [ - 0, 1, - 1, 3, - 3, 2, - 2, 0, - 4, 5, - 5, 7, - 7, 6, - 6, 4, - 0, 4, - 1, 5, - 2, 6, - 3, 7 - ] - }); -} - -/** - * @desc Creates a box-shaped lines {@link Geometry} from AABB. - * - * ## Usage - * - * In the example below we'll create a {@link Mesh} with a box-shaped {@link ReadableGeometry} that has lines primitives. - * This box will be created from AABB of a model. - * - * [[Run this example](/examples/index.html#geometry_builders_buildBoxLinesGeometryFromAABB)] - * - * ````javascript - * import {Viewer, Mesh, Node, buildBoxGeometry, buildBoxLinesGeometryFromAABB, ReadableGeometry, PhongMaterial} from "../../dist/xeokit-sdk.min.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [-21.80, 4.01, 6.56]; - * viewer.scene.camera.look = [0, -5.75, 0]; - * viewer.scene.camera.up = [0.37, 0.91, -0.11]; - * - * const boxGeometry = new ReadableGeometry(viewer.scene, buildBoxGeometry({ - * xSize: 1, - * ySize: 1, - * zSize: 1 - * })); - * - * new Node(viewer.scene, { - * id: "table", - * isModel: true, // <--------------------- Node represents a model - * rotation: [0, 50, 0], - * position: [0, 0, 0], - * scale: [1, 1, 1], - * - * children: [ - * - * new Mesh(viewer.scene, { // Red table leg - * id: "redLeg", - * isObject: true, // <---------- Node represents an object - * position: [-4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * geometry: boxGeometry, - * material: new PhongMaterial(viewer.scene, { - * diffuse: [1, 0.3, 0.3] - * }) - * }), - * - * new Mesh(viewer.scene, { // Green table leg - * id: "greenLeg", - * isObject: true, // <---------- Node represents an object - * position: [4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * geometry: boxGeometry, - * material: new PhongMaterial(viewer.scene, { - * diffuse: [0.3, 1.0, 0.3] - * }) - * }), - * - * new Mesh(viewer.scene, {// Blue table leg - * id: "blueLeg", - * isObject: true, // <---------- Node represents an object - * position: [4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * geometry: boxGeometry, - * material: new PhongMaterial(viewer.scene, { - * diffuse: [0.3, 0.3, 1.0] - * }) - * }), - * - * new Mesh(viewer.scene, { // Yellow table leg - * id: "yellowLeg", - * isObject: true, // <---------- Node represents an object - * position: [-4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * geometry: boxGeometry, - * material: new PhongMaterial(viewer.scene, { - * diffuse: [1.0, 1.0, 0.0] - * }) - * }), - * - * new Mesh(viewer.scene, { // Purple table top - * id: "tableTop", - * isObject: true, // <---------- Node represents an object - * position: [0, -3, 0], - * scale: [6, 0.5, 6], - * rotation: [0, 0, 0], - * geometry: boxGeometry, - * material: new PhongMaterial(viewer.scene, { - * diffuse: [1.0, 0.3, 1.0] - * }) - * }) - * ] - * }); - * - * let aabb = viewer.scene.aabb; - * console.log(aabb); - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildBoxLinesGeometryFromAABB({ - * id: "aabb", - * aabb: aabb, - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [0, 1,] - * }) - * }); - * ```` - * - * @function buildBoxLinesGeometryFromAABB - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.aabb] AABB for which box will be created. - * @returns {Object} Configuration for a {@link Geometry} subtype. - */ -function buildBoxLinesGeometryFromAABB(cfg = {}){ - return buildBoxLinesGeometry({ - id: cfg.id, - center: [ - (cfg.aabb[0] + cfg.aabb[3]) / 2.0, - (cfg.aabb[1] + cfg.aabb[4]) / 2.0, - (cfg.aabb[2] + cfg.aabb[5]) / 2.0, - ], - xSize: (Math.abs(cfg.aabb[3] - cfg.aabb[0])) / 2.0, - ySize: (Math.abs(cfg.aabb[4] - cfg.aabb[1])) / 2.0, - zSize: (Math.abs(cfg.aabb[5] - cfg.aabb[2])) / 2.0, - }); -} - -/** - * @desc Creates a cylinder-shaped {@link Geometry}. - * - * ## Usage - * - * Creating a {@link Mesh} with a cylinder-shaped {@link ReadableGeometry} : - * - * [[Run this example](/examples/index.html#geometry_builders_buildCylinderGeometry)] - * - * ````javascript - * - * import {Viewer, Mesh, buildCylinderGeometry, ReadableGeometry, PhongMaterial, Texture} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.camera.eye = [0, 0, 5]; - * viewer.camera.look = [0, 0, 0]; - * viewer.camera.up = [0, 1, 0]; - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildCylinderGeometry({ - * center: [0,0,0], - * radiusTop: 2.0, - * radiusBottom: 2.0, - * height: 5.0, - * radialSegments: 20, - * heightSegments: 1, - * openEnded: false - * }), - * material: new PhongMaterial(viewer.scene, { - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }) - * }) - * }); - * ```` - * - * @function buildCylinderGeometry - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID for the {@link Geometry}, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.center] 3D point indicating the center position. - * @param {Number} [cfg.radiusTop=1] Radius of top. - * @param {Number} [cfg.radiusBottom=1] Radius of bottom. - * @param {Number} [cfg.height=1] Height. - * @param {Number} [cfg.radialSegments=60] Number of horizontal segments. - * @param {Number} [cfg.heightSegments=1] Number of vertical segments. - * @param {Boolean} [cfg.openEnded=false] Whether or not the cylinder has solid caps on the ends. - * @returns {Object} Configuration for a {@link Geometry} subtype. - */ -function buildCylinderGeometry(cfg = {}) { - - let radiusTop = cfg.radiusTop || 1; - if (radiusTop < 0) { - console.error("negative radiusTop not allowed - will invert"); - radiusTop *= -1; - } - - let radiusBottom = cfg.radiusBottom || 1; - if (radiusBottom < 0) { - console.error("negative radiusBottom not allowed - will invert"); - radiusBottom *= -1; - } - - let height = cfg.height || 1; - if (height < 0) { - console.error("negative height not allowed - will invert"); - height *= -1; - } - - let radialSegments = cfg.radialSegments || 32; - if (radialSegments < 0) { - console.error("negative radialSegments not allowed - will invert"); - radialSegments *= -1; - } - if (radialSegments < 3) { - radialSegments = 3; - } - - let heightSegments = cfg.heightSegments || 1; - if (heightSegments < 0) { - console.error("negative heightSegments not allowed - will invert"); - heightSegments *= -1; - } - if (heightSegments < 1) { - heightSegments = 1; - } - - const openEnded = !!cfg.openEnded; - - let center = cfg.center; - const centerX = center ? center[0] : 0; - const centerY = center ? center[1] : 0; - const centerZ = center ? center[2] : 0; - - const heightHalf = height / 2; - const heightLength = height / heightSegments; - const radialAngle = (2.0 * Math.PI / radialSegments); - const radialLength = 1.0 / radialSegments; - //var nextRadius = this._radiusBottom; - const radiusChange = (radiusTop - radiusBottom) / heightSegments; - - const positions = []; - const normals = []; - const uvs = []; - const indices = []; - - let h; - let i; - - let x; - let z; - - let currentRadius; - let currentHeight; - - let first; - let second; - - let startIndex; - let tu; - let tv; - - // create vertices - const normalY = (90.0 - (Math.atan(height / (radiusBottom - radiusTop))) * 180 / Math.PI) / 90.0; - - for (h = 0; h <= heightSegments; h++) { - currentRadius = radiusTop - h * radiusChange; - currentHeight = heightHalf - h * heightLength; - - for (i = 0; i <= radialSegments; i++) { - x = Math.sin(i * radialAngle); - z = Math.cos(i * radialAngle); - - normals.push(currentRadius * x); - normals.push(normalY); //todo - normals.push(currentRadius * z); - - uvs.push((i * radialLength)); - uvs.push(h * 1 / heightSegments); - - positions.push((currentRadius * x) + centerX); - positions.push((currentHeight) + centerY); - positions.push((currentRadius * z) + centerZ); - } - } - - // create faces - for (h = 0; h < heightSegments; h++) { - for (i = 0; i <= radialSegments; i++) { - - first = h * (radialSegments + 1) + i; - second = first + radialSegments; - - indices.push(first); - indices.push(second); - indices.push(second + 1); - - indices.push(first); - indices.push(second + 1); - indices.push(first + 1); - } - } - - // create top cap - if (!openEnded && radiusTop > 0) { - startIndex = (positions.length / 3); - - // top center - normals.push(0.0); - normals.push(1.0); - normals.push(0.0); - - uvs.push(0.5); - uvs.push(0.5); - - positions.push(0 + centerX); - positions.push(heightHalf + centerY); - positions.push(0 + centerZ); - - // top triangle fan - for (i = 0; i <= radialSegments; i++) { - x = Math.sin(i * radialAngle); - z = Math.cos(i * radialAngle); - tu = (0.5 * Math.sin(i * radialAngle)) + 0.5; - tv = (0.5 * Math.cos(i * radialAngle)) + 0.5; - - normals.push(radiusTop * x); - normals.push(1.0); - normals.push(radiusTop * z); - - uvs.push(tu); - uvs.push(tv); - - positions.push((radiusTop * x) + centerX); - positions.push((heightHalf) + centerY); - positions.push((radiusTop * z) + centerZ); - } - - for (i = 0; i < radialSegments; i++) { - center = startIndex; - first = startIndex + 1 + i; - - indices.push(first); - indices.push(first + 1); - indices.push(center); - } - } - - // create bottom cap - if (!openEnded && radiusBottom > 0) { - - startIndex = (positions.length / 3); - - // top center - normals.push(0.0); - normals.push(-1.0); - normals.push(0.0); - - uvs.push(0.5); - uvs.push(0.5); - - positions.push(0 + centerX); - positions.push(0 - heightHalf + centerY); - positions.push(0 + centerZ); - - // top triangle fan - for (i = 0; i <= radialSegments; i++) { - - x = Math.sin(i * radialAngle); - z = Math.cos(i * radialAngle); - - tu = (0.5 * Math.sin(i * radialAngle)) + 0.5; - tv = (0.5 * Math.cos(i * radialAngle)) + 0.5; - - normals.push(radiusBottom * x); - normals.push(-1.0); - normals.push(radiusBottom * z); - - uvs.push(tu); - uvs.push(tv); - - positions.push((radiusBottom * x) + centerX); - positions.push((0 - heightHalf) + centerY); - positions.push((radiusBottom * z) + centerZ); - } - - for (i = 0; i < radialSegments; i++) { - - center = startIndex; - first = startIndex + 1 + i; - - indices.push(center); - indices.push(first + 1); - indices.push(first); - } - } - - return utils.apply(cfg, { - positions: positions, - normals: normals, - uv: uvs, - indices: indices - }); -} - -/** - * @desc Creates a grid-shaped {@link Geometry}. - * - * ## Usage - * - * Creating a {@link Mesh} with a GridGeometry and a {@link PhongMaterial}: - * - * [[Run this example](/examples/index.html#geometry_builders_buildGridGeometry)] - * - * ````javascript - * import {Viewer, Mesh, buildGridGeometry, VBOGeometry, PhongMaterial, Texture} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.camera.eye = [0, 0, 5]; - * viewer.camera.look = [0, 0, 0]; - * viewer.camera.up = [0, 1, 0]; - * - * new Mesh(viewer.scene, { - * geometry: new VBOGeometry(viewer.scene, buildGridGeometry({ - * size: 1000, - * divisions: 500 - * })), - * material: new PhongMaterial(viewer.scene, { - * color: [0.0, 0.0, 0.0], - * emissive: [0.4, 0.4, 0.4] - * }), - * position: [0, -1.6, 0] - * }); - * ```` - * - * @function buildGridGeometry - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID for the {@link Geometry}, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number} [cfg.size=1] Dimension on the X and Z-axis. - * @param {Number} [cfg.divisions=1] Number of divisions on X and Z axis.. - * @returns {Object} Configuration for a {@link Geometry} subtype. - */ -function buildGridGeometry(cfg = {}) { - - let size = cfg.size || 1; - if (size < 0) { - console.error("negative size not allowed - will invert"); - size *= -1; - } - - let divisions = cfg.divisions || 1; - if (divisions < 0) { - console.error("negative divisions not allowed - will invert"); - divisions *= -1; - } - if (divisions < 1) { - divisions = 1; - } - - size = size || 10; - divisions = divisions || 10; - - const step = size / divisions; - const halfSize = size / 2; - - const positions = []; - const indices = []; - let l = 0; - - for (let i = 0, k = -halfSize; i <= divisions; i++, k += step) { - - positions.push(-halfSize); - positions.push(0); - positions.push(k); - - positions.push(halfSize); - positions.push(0); - positions.push(k); - - positions.push(k); - positions.push(0); - positions.push(-halfSize); - - positions.push(k); - positions.push(0); - positions.push(halfSize); - - indices.push(l++); - indices.push(l++); - indices.push(l++); - indices.push(l++); - } - - return utils.apply(cfg, { - primitive: "lines", - positions: positions, - indices: indices - }); -} - -/** - * @desc Creates a plane-shaped {@link Geometry}. - * - * ## Usage - * - * Creating a {@link Mesh} with a PlaneGeometry and a {@link PhongMaterial} with diffuse {@link Texture}: - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/scenegraph/#buildPlaneGeometry)] - * - * ````javascript - * import {Viewer, Mesh, buildPlaneGeometry, ReadableGeometry, PhongMaterial, Texture} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.camera.eye = [0, 0, 5]; - * viewer.camera.look = [0, 0, 0]; - * viewer.camera.up = [0, 1, 0]; - - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildPlaneGeometry({ - * center: [0,0,0], - * xSize: 2, - * zSize: 2, - * xSegments: 10, - * zSegments: 10 - * }), - * material: new PhongMaterial(viewer.scene, { - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }) - * }) - * }); - * ```` - * - * @function buildPlaneGeometry - * @param {*} [cfg] Configs - * @param {Number[]} [cfg.center] 3D point indicating the center position. - * @param {String} [cfg.id] Optional ID for the {@link Geometry}, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number} [cfg.xSize=1] Dimension on the X-axis. - * @param {Number} [cfg.zSize=1] Dimension on the Z-axis. - * @param {Number} [cfg.xSegments=1] Number of segments on the X-axis. - * @param {Number} [cfg.zSegments=1] Number of segments on the Z-axis. - * @returns {Object} Configuration for a {@link Geometry} subtype. - */ -function buildPlaneGeometry(cfg = {}) { - - let xSize = cfg.xSize || 1; - if (xSize < 0) { - console.error("negative xSize not allowed - will invert"); - xSize *= -1; - } - - let zSize = cfg.zSize || 1; - if (zSize < 0) { - console.error("negative zSize not allowed - will invert"); - zSize *= -1; - } - - let xSegments = cfg.xSegments || 1; - if (xSegments < 0) { - console.error("negative xSegments not allowed - will invert"); - xSegments *= -1; - } - if (xSegments < 1) { - xSegments = 1; - } - - let zSegments = cfg.xSegments || 1; - if (zSegments < 0) { - console.error("negative zSegments not allowed - will invert"); - zSegments *= -1; - } - if (zSegments < 1) { - zSegments = 1; - } - - const center = cfg.center; - const centerX = center ? center[0] : 0; - const centerY = center ? center[1] : 0; - const centerZ = center ? center[2] : 0; - - const halfWidth = xSize / 2; - const halfHeight = zSize / 2; - - const planeX = Math.floor(xSegments) || 1; - const planeZ = Math.floor(zSegments) || 1; - - const planeX1 = planeX + 1; - const planeZ1 = planeZ + 1; - - const segmentWidth = xSize / planeX; - const segmentHeight = zSize / planeZ; - - const positions = new Float32Array(planeX1 * planeZ1 * 3); - const normals = new Float32Array(planeX1 * planeZ1 * 3); - const uvs = new Float32Array(planeX1 * planeZ1 * 2); - - let offset = 0; - let offset2 = 0; - - let iz; - let ix; - let x; - let a; - let b; - let c; - let d; - - for (iz = 0; iz < planeZ1; iz++) { - - const z = iz * segmentHeight - halfHeight; - - for (ix = 0; ix < planeX1; ix++) { - - x = ix * segmentWidth - halfWidth; - - positions[offset] = x + centerX; - positions[offset + 1] = centerY; - positions[offset + 2] = -z + centerZ; - - normals[offset + 1] = 1; - - uvs[offset2] = (ix) / planeX; - uvs[offset2 + 1] = ((planeZ - iz) / planeZ); - - offset += 3; - offset2 += 2; - } - } - - offset = 0; - - const indices = new ((positions.length / 3) > 65535 ? Uint32Array : Uint16Array)(planeX * planeZ * 6); - - for (iz = 0; iz < planeZ; iz++) { - - for (ix = 0; ix < planeX; ix++) { - - a = ix + planeX1 * iz; - b = ix + planeX1 * (iz + 1); - c = (ix + 1) + planeX1 * (iz + 1); - d = (ix + 1) + planeX1 * iz; - - indices[offset] = d; - indices[offset + 1] = b; - indices[offset + 2] = a; - - indices[offset + 3] = d; - indices[offset + 4] = c; - indices[offset + 5] = b; - - offset += 6; - } - } - - return utils.apply(cfg, { - positions: positions, - normals: normals, - uv: uvs, - indices: indices - }); -} - -/** - * @desc Creates a sphere-shaped {@link Geometry}. - * - * ## Usage - * - * Creating a {@link Mesh} with a sphere-shaped {@link ReadableGeometry} : - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/scenegraph/#buildSphereGeometry)] - * - * ````javascript - * import {Viewer, Mesh, buildSphereGeometry, ReadableGeometry, PhongMaterial, Texture} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.camera.eye = [0, 0, 5]; - * viewer.camera.look = [0, 0, 0]; - * viewer.camera.up = [0, 1, 0]; - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildSphereGeometry({ - * center: [0,0,0], - * radius: 1.5, - * heightSegments: 60, - * widthSegments: 60 - * }), - * material: new PhongMaterial(viewer.scene, { - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }) - * }) - * }); - * ```` - * - * @function buildSphereGeometry - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID for the {@link Geometry}, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.center] 3D point indicating the center position. - * @param {Number} [cfg.radius=1] Radius. - * @param {Number} [cfg.heightSegments=24] Number of latitudinal bands. - * @param {Number} [cfg.widthSegments=18] Number of longitudinal bands. - * @returns {Object} Configuration for a {@link Geometry} subtype. - */ -function buildSphereGeometry(cfg = {}) { - - const lod = cfg.lod || 1; - - const centerX = cfg.center ? cfg.center[0] : 0; - const centerY = cfg.center ? cfg.center[1] : 0; - const centerZ = cfg.center ? cfg.center[2] : 0; - - let radius = cfg.radius || 1; - if (radius < 0) { - console.error("negative radius not allowed - will invert"); - radius *= -1; - } - - let heightSegments = cfg.heightSegments || 18; - if (heightSegments < 0) { - console.error("negative heightSegments not allowed - will invert"); - heightSegments *= -1; - } - heightSegments = Math.floor(lod * heightSegments); - if (heightSegments < 18) { - heightSegments = 18; - } - - let widthSegments = cfg.widthSegments || 18; - if (widthSegments < 0) { - console.error("negative widthSegments not allowed - will invert"); - widthSegments *= -1; - } - widthSegments = Math.floor(lod * widthSegments); - if (widthSegments < 18) { - widthSegments = 18; - } - - const positions = []; - const normals = []; - const uvs = []; - const indices = []; - - let i; - let j; - - let theta; - let sinTheta; - let cosTheta; - - let phi; - let sinPhi; - let cosPhi; - - let x; - let y; - let z; - - let u; - let v; - - let first; - let second; - - for (i = 0; i <= heightSegments; i++) { - - theta = i * Math.PI / heightSegments; - sinTheta = Math.sin(theta); - cosTheta = Math.cos(theta); - - for (j = 0; j <= widthSegments; j++) { - - phi = j * 2 * Math.PI / widthSegments; - sinPhi = Math.sin(phi); - cosPhi = Math.cos(phi); - - x = cosPhi * sinTheta; - y = cosTheta; - z = sinPhi * sinTheta; - u = 1.0 - j / widthSegments; - v = i / heightSegments; - - normals.push(x); - normals.push(y); - normals.push(z); - - uvs.push(u); - uvs.push(v); - - positions.push(centerX + radius * x); - positions.push(centerY + radius * y); - positions.push(centerZ + radius * z); - } - } - - for (i = 0; i < heightSegments; i++) { - for (j = 0; j < widthSegments; j++) { - - first = (i * (widthSegments + 1)) + j; - second = first + widthSegments + 1; - - indices.push(first + 1); - indices.push(second + 1); - indices.push(second); - indices.push(first + 1); - indices.push(second); - indices.push(first); - } - } - - return utils.apply(cfg, { - positions: positions, - normals: normals, - uv: uvs, - indices: indices - }); -} - -/** - * @desc Creates a torus-shaped {@link Geometry}. - * - * ## Usage - * Creating a {@link Mesh} with a torus-shaped {@link ReadableGeometry} : - * - * [[Run this example](/examples/index.html#geometry_builders_buildTorusGeometry)] - * - * ````javascript - * import {Viewer, Mesh, buildTorusGeometry, ReadableGeometry, PhongMaterial, Texture} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.camera.eye = [0, 0, 5]; - * viewer.camera.look = [0, 0, 0]; - * viewer.camera.up = [0, 1, 0]; - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildTorusGeometry({ - * center: [0,0,0], - * radius: 1.0, - * tube: 0.5, - * radialSegments: 32, - * tubeSegments: 24, - * arc: Math.PI * 2.0 - * }), - * material: new PhongMaterial(viewer.scene, { - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }) - * }) - * }); - * ```` - * - * @function buildTorusGeometry - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID for the {@link Geometry}, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.center] 3D point indicating the center position. - * @param {Number} [cfg.radius=1] The overall radius. - * @param {Number} [cfg.tube=0.3] The tube radius. - * @param {Number} [cfg.radialSegments=32] The number of radial segments. - * @param {Number} [cfg.tubeSegments=24] The number of tubular segments. - * @param {Number} [cfg.arc=Math.PI*0.5] The length of the arc in radians, where Math.PI*2 is a closed torus. - * @returns {Object} Configuration for a {@link Geometry} subtype. - */ -function buildTorusGeometry(cfg = {}) { - - let radius = cfg.radius || 1; - if (radius < 0) { - console.error("negative radius not allowed - will invert"); - radius *= -1; - } - radius *= 0.5; - - let tube = cfg.tube || 0.3; - if (tube < 0) { - console.error("negative tube not allowed - will invert"); - tube *= -1; - } - - let radialSegments = cfg.radialSegments || 32; - if (radialSegments < 0) { - console.error("negative radialSegments not allowed - will invert"); - radialSegments *= -1; - } - if (radialSegments < 4) { - radialSegments = 4; - } - - let tubeSegments = cfg.tubeSegments || 24; - if (tubeSegments < 0) { - console.error("negative tubeSegments not allowed - will invert"); - tubeSegments *= -1; - } - if (tubeSegments < 4) { - tubeSegments = 4; - } - - let arc = cfg.arc || Math.PI * 2; - if (arc < 0) { - console.warn("negative arc not allowed - will invert"); - arc *= -1; - } - if (arc > 360) { - arc = 360; - } - - const center = cfg.center; - let centerX = center ? center[0] : 0; - let centerY = center ? center[1] : 0; - const centerZ = center ? center[2] : 0; - - const positions = []; - const normals = []; - const uvs = []; - const indices = []; - - let u; - let v; - let x; - let y; - let z; - let vec; - - let i; - let j; - - for (j = 0; j <= tubeSegments; j++) { - for (i = 0; i <= radialSegments; i++) { - - u = i / radialSegments * arc; - v = 0.785398 + (j / tubeSegments * Math.PI * 2); - - centerX = radius * Math.cos(u); - centerY = radius * Math.sin(u); - - x = (radius + tube * Math.cos(v)) * Math.cos(u); - y = (radius + tube * Math.cos(v)) * Math.sin(u); - z = tube * Math.sin(v); - - positions.push(x + centerX); - positions.push(y + centerY); - positions.push(z + centerZ); - - uvs.push(1 - (i / radialSegments)); - uvs.push((j / tubeSegments)); - - vec = math.normalizeVec3(math.subVec3([x, y, z], [centerX, centerY, centerZ], []), []); - - normals.push(vec[0]); - normals.push(vec[1]); - normals.push(vec[2]); - } - } - - let a; - let b; - let c; - let d; - - for (j = 1; j <= tubeSegments; j++) { - for (i = 1; i <= radialSegments; i++) { - - a = (radialSegments + 1) * j + i - 1; - b = (radialSegments + 1) * (j - 1) + i - 1; - c = (radialSegments + 1) * (j - 1) + i; - d = (radialSegments + 1) * j + i; - - indices.push(a); - indices.push(b); - indices.push(c); - - indices.push(c); - indices.push(d); - indices.push(a); - } - } - - return utils.apply(cfg, { - positions: positions, - normals: normals, - uv: uvs, - indices: indices - }); -} - -const letters = { - ' ': {width: 16, points: []}, - '!': { - width: 10, points: [ - [5, 21], - [5, 7], - [-1, -1], - [5, 2], - [4, 1], - [5, 0], - [6, 1], - [5, 2] - ] - }, - '"': { - width: 16, points: [ - [4, 21], - [4, 14], - [-1, -1], - [12, 21], - [12, 14] - ] - }, - '#': { - width: 21, points: [ - [11, 25], - [4, -7], - [-1, -1], - [17, 25], - [10, -7], - [-1, -1], - [4, 12], - [18, 12], - [-1, -1], - [3, 6], - [17, 6] - ] - }, - '$': { - width: 20, points: [ - [8, 25], - [8, -4], - [-1, -1], - [12, 25], - [12, -4], - [-1, -1], - [17, 18], - [15, 20], - [12, 21], - [8, 21], - [5, 20], - [3, 18], - [3, 16], - [4, 14], - [5, 13], - [7, 12], - [13, 10], - [15, 9], - [16, 8], - [17, 6], - [17, 3], - [15, 1], - [12, 0], - [8, 0], - [5, 1], - [3, 3] - ] - }, - '%': { - width: 24, points: [ - [21, 21], - [3, 0], - [-1, -1], - [8, 21], - [10, 19], - [10, 17], - [9, 15], - [7, 14], - [5, 14], - [3, 16], - [3, 18], - [4, 20], - [6, 21], - [8, 21], - [10, 20], - [13, 19], - [16, 19], - [19, 20], - [21, 21], - [-1, -1], - [17, 7], - [15, 6], - [14, 4], - [14, 2], - [16, 0], - [18, 0], - [20, 1], - [21, 3], - [21, 5], - [19, 7], - [17, 7] - ] - }, - '&': { - width: 26, points: [ - [23, 12], - [23, 13], - [22, 14], - [21, 14], - [20, 13], - [19, 11], - [17, 6], - [15, 3], - [13, 1], - [11, 0], - [7, 0], - [5, 1], - [4, 2], - [3, 4], - [3, 6], - [4, 8], - [5, 9], - [12, 13], - [13, 14], - [14, 16], - [14, 18], - [13, 20], - [11, 21], - [9, 20], - [8, 18], - [8, 16], - [9, 13], - [11, 10], - [16, 3], - [18, 1], - [20, 0], - [22, 0], - [23, 1], - [23, 2] - ] - }, - '\'': { - width: 10, points: [ - [5, 19], - [4, 20], - [5, 21], - [6, 20], - [6, 18], - [5, 16], - [4, 15] - ] - }, - '(': { - width: 14, points: [ - [11, 25], - [9, 23], - [7, 20], - [5, 16], - [4, 11], - [4, 7], - [5, 2], - [7, -2], - [9, -5], - [11, -7] - ] - }, - ')': { - width: 14, points: [ - [3, 25], - [5, 23], - [7, 20], - [9, 16], - [10, 11], - [10, 7], - [9, 2], - [7, -2], - [5, -5], - [3, -7] - ] - }, - '*': { - width: 16, points: [ - [8, 21], - [8, 9], - [-1, -1], - [3, 18], - [13, 12], - [-1, -1], - [13, 18], - [3, 12] - ] - }, - '+': { - width: 26, points: [ - [13, 18], - [13, 0], - [-1, -1], - [4, 9], - [22, 9] - ] - }, - ',': { - width: 10, points: [ - [6, 1], - [5, 0], - [4, 1], - [5, 2], - [6, 1], - [6, -1], - [5, -3], - [4, -4] - ] - }, - '-': { - width: 26, points: [ - [4, 9], - [22, 9] - ] - }, - '.': { - width: 10, points: [ - [5, 2], - [4, 1], - [5, 0], - [6, 1], - [5, 2] - ] - }, - '/': { - width: 22, points: [ - [20, 25], - [2, -7] - ] - }, - '0': { - width: 20, points: [ - [9, 21], - [6, 20], - [4, 17], - [3, 12], - [3, 9], - [4, 4], - [6, 1], - [9, 0], - [11, 0], - [14, 1], - [16, 4], - [17, 9], - [17, 12], - [16, 17], - [14, 20], - [11, 21], - [9, 21] - ] - }, - '1': { - width: 20, points: [ - [6, 17], - [8, 18], - [11, 21], - [11, 0] - ] - }, - '2': { - width: 20, points: [ - [4, 16], - [4, 17], - [5, 19], - [6, 20], - [8, 21], - [12, 21], - [14, 20], - [15, 19], - [16, 17], - [16, 15], - [15, 13], - [13, 10], - [3, 0], - [17, 0] - ] - }, - '3': { - width: 20, points: [ - [5, 21], - [16, 21], - [10, 13], - [13, 13], - [15, 12], - [16, 11], - [17, 8], - [17, 6], - [16, 3], - [14, 1], - [11, 0], - [8, 0], - [5, 1], - [4, 2], - [3, 4] - ] - }, - '4': { - width: 20, points: [ - [13, 21], - [3, 7], - [18, 7], - [-1, -1], - [13, 21], - [13, 0] - ] - }, - '5': { - width: 20, points: [ - [15, 21], - [5, 21], - [4, 12], - [5, 13], - [8, 14], - [11, 14], - [14, 13], - [16, 11], - [17, 8], - [17, 6], - [16, 3], - [14, 1], - [11, 0], - [8, 0], - [5, 1], - [4, 2], - [3, 4] - ] - }, - '6': { - width: 20, points: [ - [16, 18], - [15, 20], - [12, 21], - [10, 21], - [7, 20], - [5, 17], - [4, 12], - [4, 7], - [5, 3], - [7, 1], - [10, 0], - [11, 0], - [14, 1], - [16, 3], - [17, 6], - [17, 7], - [16, 10], - [14, 12], - [11, 13], - [10, 13], - [7, 12], - [5, 10], - [4, 7] - ] - }, - '7': { - width: 20, points: [ - [17, 21], - [7, 0], - [-1, -1], - [3, 21], - [17, 21] - ] - }, - '8': { - width: 20, points: [ - [8, 21], - [5, 20], - [4, 18], - [4, 16], - [5, 14], - [7, 13], - [11, 12], - [14, 11], - [16, 9], - [17, 7], - [17, 4], - [16, 2], - [15, 1], - [12, 0], - [8, 0], - [5, 1], - [4, 2], - [3, 4], - [3, 7], - [4, 9], - [6, 11], - [9, 12], - [13, 13], - [15, 14], - [16, 16], - [16, 18], - [15, 20], - [12, 21], - [8, 21] - ] - }, - '9': { - width: 20, points: [ - [16, 14], - [15, 11], - [13, 9], - [10, 8], - [9, 8], - [6, 9], - [4, 11], - [3, 14], - [3, 15], - [4, 18], - [6, 20], - [9, 21], - [10, 21], - [13, 20], - [15, 18], - [16, 14], - [16, 9], - [15, 4], - [13, 1], - [10, 0], - [8, 0], - [5, 1], - [4, 3] - ] - }, - ':': { - width: 10, points: [ - [5, 14], - [4, 13], - [5, 12], - [6, 13], - [5, 14], - [-1, -1], - [5, 2], - [4, 1], - [5, 0], - [6, 1], - [5, 2] - ] - }, - ';': { - width: 10, points: [ - [5, 14], - [4, 13], - [5, 12], - [6, 13], - [5, 14], - [-1, -1], - [6, 1], - [5, 0], - [4, 1], - [5, 2], - [6, 1], - [6, -1], - [5, -3], - [4, -4] - ] - }, - '<': { - width: 24, points: [ - [20, 18], - [4, 9], - [20, 0] - ] - }, - '=': { - width: 26, points: [ - [4, 12], - [22, 12], - [-1, -1], - [4, 6], - [22, 6] - ] - }, - '>': { - width: 24, points: [ - [4, 18], - [20, 9], - [4, 0] - ] - }, - '?': { - width: 18, points: [ - [3, 16], - [3, 17], - [4, 19], - [5, 20], - [7, 21], - [11, 21], - [13, 20], - [14, 19], - [15, 17], - [15, 15], - [14, 13], - [13, 12], - [9, 10], - [9, 7], - [-1, -1], - [9, 2], - [8, 1], - [9, 0], - [10, 1], - [9, 2] - ] - }, - '@': { - width: 27, points: [ - [18, 13], - [17, 15], - [15, 16], - [12, 16], - [10, 15], - [9, 14], - [8, 11], - [8, 8], - [9, 6], - [11, 5], - [14, 5], - [16, 6], - [17, 8], - [-1, -1], - [12, 16], - [10, 14], - [9, 11], - [9, 8], - [10, 6], - [11, 5], - [-1, -1], - [18, 16], - [17, 8], - [17, 6], - [19, 5], - [21, 5], - [23, 7], - [24, 10], - [24, 12], - [23, 15], - [22, 17], - [20, 19], - [18, 20], - [15, 21], - [12, 21], - [9, 20], - [7, 19], - [5, 17], - [4, 15], - [3, 12], - [3, 9], - [4, 6], - [5, 4], - [7, 2], - [9, 1], - [12, 0], - [15, 0], - [18, 1], - [20, 2], - [21, 3], - [-1, -1], - [19, 16], - [18, 8], - [18, 6], - [19, 5] - ] - }, - 'A': { - width: 18, points: [ - [9, 21], - [1, 0], - [-1, -1], - [9, 21], - [17, 0], - [-1, -1], - [4, 7], - [14, 7] - ] - }, - 'B': { - width: 21, points: [ - [4, 21], - [4, 0], - [-1, -1], - [4, 21], - [13, 21], - [16, 20], - [17, 19], - [18, 17], - [18, 15], - [17, 13], - [16, 12], - [13, 11], - [-1, -1], - [4, 11], - [13, 11], - [16, 10], - [17, 9], - [18, 7], - [18, 4], - [17, 2], - [16, 1], - [13, 0], - [4, 0] - ] - }, - 'C': { - width: 21, points: [ - [18, 16], - [17, 18], - [15, 20], - [13, 21], - [9, 21], - [7, 20], - [5, 18], - [4, 16], - [3, 13], - [3, 8], - [4, 5], - [5, 3], - [7, 1], - [9, 0], - [13, 0], - [15, 1], - [17, 3], - [18, 5] - ] - }, - 'D': { - width: 21, points: [ - [4, 21], - [4, 0], - [-1, -1], - [4, 21], - [11, 21], - [14, 20], - [16, 18], - [17, 16], - [18, 13], - [18, 8], - [17, 5], - [16, 3], - [14, 1], - [11, 0], - [4, 0] - ] - }, - 'E': { - width: 19, points: [ - [4, 21], - [4, 0], - [-1, -1], - [4, 21], - [17, 21], - [-1, -1], - [4, 11], - [12, 11], - [-1, -1], - [4, 0], - [17, 0] - ] - }, - 'F': { - width: 18, points: [ - [4, 21], - [4, 0], - [-1, -1], - [4, 21], - [17, 21], - [-1, -1], - [4, 11], - [12, 11] - ] - }, - 'G': { - width: 21, points: [ - [18, 16], - [17, 18], - [15, 20], - [13, 21], - [9, 21], - [7, 20], - [5, 18], - [4, 16], - [3, 13], - [3, 8], - [4, 5], - [5, 3], - [7, 1], - [9, 0], - [13, 0], - [15, 1], - [17, 3], - [18, 5], - [18, 8], - [-1, -1], - [13, 8], - [18, 8] - ] - }, - 'H': { - width: 22, points: [ - [4, 21], - [4, 0], - [-1, -1], - [18, 21], - [18, 0], - [-1, -1], - [4, 11], - [18, 11] - ] - }, - 'I': { - width: 8, points: [ - [4, 21], - [4, 0] - ] - }, - 'J': { - width: 16, points: [ - [12, 21], - [12, 5], - [11, 2], - [10, 1], - [8, 0], - [6, 0], - [4, 1], - [3, 2], - [2, 5], - [2, 7] - ] - }, - 'K': { - width: 21, points: [ - [4, 21], - [4, 0], - [-1, -1], - [18, 21], - [4, 7], - [-1, -1], - [9, 12], - [18, 0] - ] - }, - 'L': { - width: 17, points: [ - [4, 21], - [4, 0], - [-1, -1], - [4, 0], - [16, 0] - ] - }, - 'M': { - width: 24, points: [ - [4, 21], - [4, 0], - [-1, -1], - [4, 21], - [12, 0], - [-1, -1], - [20, 21], - [12, 0], - [-1, -1], - [20, 21], - [20, 0] - ] - }, - 'N': { - width: 22, points: [ - [4, 21], - [4, 0], - [-1, -1], - [4, 21], - [18, 0], - [-1, -1], - [18, 21], - [18, 0] - ] - }, - 'O': { - width: 22, points: [ - [9, 21], - [7, 20], - [5, 18], - [4, 16], - [3, 13], - [3, 8], - [4, 5], - [5, 3], - [7, 1], - [9, 0], - [13, 0], - [15, 1], - [17, 3], - [18, 5], - [19, 8], - [19, 13], - [18, 16], - [17, 18], - [15, 20], - [13, 21], - [9, 21] - ] - }, - 'P': { - width: 21, points: [ - [4, 21], - [4, 0], - [-1, -1], - [4, 21], - [13, 21], - [16, 20], - [17, 19], - [18, 17], - [18, 14], - [17, 12], - [16, 11], - [13, 10], - [4, 10] - ] - }, - 'Q': { - width: 22, points: [ - [9, 21], - [7, 20], - [5, 18], - [4, 16], - [3, 13], - [3, 8], - [4, 5], - [5, 3], - [7, 1], - [9, 0], - [13, 0], - [15, 1], - [17, 3], - [18, 5], - [19, 8], - [19, 13], - [18, 16], - [17, 18], - [15, 20], - [13, 21], - [9, 21], - [-1, -1], - [12, 4], - [18, -2] - ] - }, - 'R': { - width: 21, points: [ - [4, 21], - [4, 0], - [-1, -1], - [4, 21], - [13, 21], - [16, 20], - [17, 19], - [18, 17], - [18, 15], - [17, 13], - [16, 12], - [13, 11], - [4, 11], - [-1, -1], - [11, 11], - [18, 0] - ] - }, - 'S': { - width: 20, points: [ - [17, 18], - [15, 20], - [12, 21], - [8, 21], - [5, 20], - [3, 18], - [3, 16], - [4, 14], - [5, 13], - [7, 12], - [13, 10], - [15, 9], - [16, 8], - [17, 6], - [17, 3], - [15, 1], - [12, 0], - [8, 0], - [5, 1], - [3, 3] - ] - }, - 'T': { - width: 16, points: [ - [8, 21], - [8, 0], - [-1, -1], - [1, 21], - [15, 21] - ] - }, - 'U': { - width: 22, points: [ - [4, 21], - [4, 6], - [5, 3], - [7, 1], - [10, 0], - [12, 0], - [15, 1], - [17, 3], - [18, 6], - [18, 21] - ] - }, - 'V': { - width: 18, points: [ - [1, 21], - [9, 0], - [-1, -1], - [17, 21], - [9, 0] - ] - }, - 'W': { - width: 24, points: [ - [2, 21], - [7, 0], - [-1, -1], - [12, 21], - [7, 0], - [-1, -1], - [12, 21], - [17, 0], - [-1, -1], - [22, 21], - [17, 0] - ] - }, - 'X': { - width: 20, points: [ - [3, 21], - [17, 0], - [-1, -1], - [17, 21], - [3, 0] - ] - }, - 'Y': { - width: 18, points: [ - [1, 21], - [9, 11], - [9, 0], - [-1, -1], - [17, 21], - [9, 11] - ] - }, - 'Z': { - width: 20, points: [ - [17, 21], - [3, 0], - [-1, -1], - [3, 21], - [17, 21], - [-1, -1], - [3, 0], - [17, 0] - ] - }, - '[': { - width: 14, points: [ - [4, 25], - [4, -7], - [-1, -1], - [5, 25], - [5, -7], - [-1, -1], - [4, 25], - [11, 25], - [-1, -1], - [4, -7], - [11, -7] - ] - }, - '\\': { - width: 14, points: [ - [0, 21], - [14, -3] - ] - }, - ']': { - width: 14, points: [ - [9, 25], - [9, -7], - [-1, -1], - [10, 25], - [10, -7], - [-1, -1], - [3, 25], - [10, 25], - [-1, -1], - [3, -7], - [10, -7] - ] - }, - '^': { - width: 16, points: [ - [6, 15], - [8, 18], - [10, 15], - [-1, -1], - [3, 12], - [8, 17], - [13, 12], - [-1, -1], - [8, 17], - [8, 0] - ] - }, - '_': { - width: 16, points: [ - [0, -2], - [16, -2] - ] - }, - '`': { - width: 10, points: [ - [6, 21], - [5, 20], - [4, 18], - [4, 16], - [5, 15], - [6, 16], - [5, 17] - ] - }, - 'a': { - width: 19, points: [ - [15, 14], - [15, 0], - [-1, -1], - [15, 11], - [13, 13], - [11, 14], - [8, 14], - [6, 13], - [4, 11], - [3, 8], - [3, 6], - [4, 3], - [6, 1], - [8, 0], - [11, 0], - [13, 1], - [15, 3] - ] - }, - 'b': { - width: 19, points: [ - [4, 21], - [4, 0], - [-1, -1], - [4, 11], - [6, 13], - [8, 14], - [11, 14], - [13, 13], - [15, 11], - [16, 8], - [16, 6], - [15, 3], - [13, 1], - [11, 0], - [8, 0], - [6, 1], - [4, 3] - ] - }, - 'c': { - width: 18, points: [ - [15, 11], - [13, 13], - [11, 14], - [8, 14], - [6, 13], - [4, 11], - [3, 8], - [3, 6], - [4, 3], - [6, 1], - [8, 0], - [11, 0], - [13, 1], - [15, 3] - ] - }, - 'd': { - width: 19, points: [ - [15, 21], - [15, 0], - [-1, -1], - [15, 11], - [13, 13], - [11, 14], - [8, 14], - [6, 13], - [4, 11], - [3, 8], - [3, 6], - [4, 3], - [6, 1], - [8, 0], - [11, 0], - [13, 1], - [15, 3] - ] - }, - 'e': { - width: 18, points: [ - [3, 8], - [15, 8], - [15, 10], - [14, 12], - [13, 13], - [11, 14], - [8, 14], - [6, 13], - [4, 11], - [3, 8], - [3, 6], - [4, 3], - [6, 1], - [8, 0], - [11, 0], - [13, 1], - [15, 3] - ] - }, - 'f': { - width: 12, points: [ - [10, 21], - [8, 21], - [6, 20], - [5, 17], - [5, 0], - [-1, -1], - [2, 14], - [9, 14] - ] - }, - 'g': { - width: 19, points: [ - [15, 14], - [15, -2], - [14, -5], - [13, -6], - [11, -7], - [8, -7], - [6, -6], - [-1, -1], - [15, 11], - [13, 13], - [11, 14], - [8, 14], - [6, 13], - [4, 11], - [3, 8], - [3, 6], - [4, 3], - [6, 1], - [8, 0], - [11, 0], - [13, 1], - [15, 3] - ] - }, - 'h': { - width: 19, points: [ - [4, 21], - [4, 0], - [-1, -1], - [4, 10], - [7, 13], - [9, 14], - [12, 14], - [14, 13], - [15, 10], - [15, 0] - ] - }, - 'i': { - width: 8, points: [ - [3, 21], - [4, 20], - [5, 21], - [4, 22], - [3, 21], - [-1, -1], - [4, 14], - [4, 0] - ] - }, - 'j': { - width: 10, points: [ - [5, 21], - [6, 20], - [7, 21], - [6, 22], - [5, 21], - [-1, -1], - [6, 14], - [6, -3], - [5, -6], - [3, -7], - [1, -7] - ] - }, - 'k': { - width: 17, points: [ - [4, 21], - [4, 0], - [-1, -1], - [14, 14], - [4, 4], - [-1, -1], - [8, 8], - [15, 0] - ] - }, - 'l': { - width: 8, points: [ - [4, 21], - [4, 0] - ] - }, - 'm': { - width: 30, points: [ - [4, 14], - [4, 0], - [-1, -1], - [4, 10], - [7, 13], - [9, 14], - [12, 14], - [14, 13], - [15, 10], - [15, 0], - [-1, -1], - [15, 10], - [18, 13], - [20, 14], - [23, 14], - [25, 13], - [26, 10], - [26, 0] - ] - }, - 'n': { - width: 19, points: [ - [4, 14], - [4, 0], - [-1, -1], - [4, 10], - [7, 13], - [9, 14], - [12, 14], - [14, 13], - [15, 10], - [15, 0] - ] - }, - 'o': { - width: 19, points: [ - [8, 14], - [6, 13], - [4, 11], - [3, 8], - [3, 6], - [4, 3], - [6, 1], - [8, 0], - [11, 0], - [13, 1], - [15, 3], - [16, 6], - [16, 8], - [15, 11], - [13, 13], - [11, 14], - [8, 14] - ] - }, - 'p': { - width: 19, points: [ - [4, 14], - [4, -7], - [-1, -1], - [4, 11], - [6, 13], - [8, 14], - [11, 14], - [13, 13], - [15, 11], - [16, 8], - [16, 6], - [15, 3], - [13, 1], - [11, 0], - [8, 0], - [6, 1], - [4, 3] - ] - }, - 'q': { - width: 19, points: [ - [15, 14], - [15, -7], - [-1, -1], - [15, 11], - [13, 13], - [11, 14], - [8, 14], - [6, 13], - [4, 11], - [3, 8], - [3, 6], - [4, 3], - [6, 1], - [8, 0], - [11, 0], - [13, 1], - [15, 3] - ] - }, - 'r': { - width: 13, points: [ - [4, 14], - [4, 0], - [-1, -1], - [4, 8], - [5, 11], - [7, 13], - [9, 14], - [12, 14] - ] - }, - 's': { - width: 17, points: [ - [14, 11], - [13, 13], - [10, 14], - [7, 14], - [4, 13], - [3, 11], - [4, 9], - [6, 8], - [11, 7], - [13, 6], - [14, 4], - [14, 3], - [13, 1], - [10, 0], - [7, 0], - [4, 1], - [3, 3] - ] - }, - 't': { - width: 12, points: [ - [5, 21], - [5, 4], - [6, 1], - [8, 0], - [10, 0], - [-1, -1], - [2, 14], - [9, 14] - ] - }, - 'u': { - width: 19, points: [ - [4, 14], - [4, 4], - [5, 1], - [7, 0], - [10, 0], - [12, 1], - [15, 4], - [-1, -1], - [15, 14], - [15, 0] - ] - }, - 'v': { - width: 16, points: [ - [2, 14], - [8, 0], - [-1, -1], - [14, 14], - [8, 0] - ] - }, - 'w': { - width: 22, points: [ - [3, 14], - [7, 0], - [-1, -1], - [11, 14], - [7, 0], - [-1, -1], - [11, 14], - [15, 0], - [-1, -1], - [19, 14], - [15, 0] - ] - }, - 'x': { - width: 17, points: [ - [3, 14], - [14, 0], - [-1, -1], - [14, 14], - [3, 0] - ] - }, - 'y': { - width: 16, points: [ - [2, 14], - [8, 0], - [-1, -1], - [14, 14], - [8, 0], - [6, -4], - [4, -6], - [2, -7], - [1, -7] - ] - }, - 'z': { - width: 17, points: [ - [14, 14], - [3, 0], - [-1, -1], - [3, 14], - [14, 14], - [-1, -1], - [3, 0], - [14, 0] - ] - }, - '{': { - width: 14, points: [ - [9, 25], - [7, 24], - [6, 23], - [5, 21], - [5, 19], - [6, 17], - [7, 16], - [8, 14], - [8, 12], - [6, 10], - [-1, -1], - [7, 24], - [6, 22], - [6, 20], - [7, 18], - [8, 17], - [9, 15], - [9, 13], - [8, 11], - [4, 9], - [8, 7], - [9, 5], - [9, 3], - [8, 1], - [7, 0], - [6, -2], - [6, -4], - [7, -6], - [-1, -1], - [6, 8], - [8, 6], - [8, 4], - [7, 2], - [6, 1], - [5, -1], - [5, -3], - [6, -5], - [7, -6], - [9, -7] - ] - }, - '|': { - width: 8, points: [ - [4, 25], - [4, -7] - ] - }, - '}': { - width: 14, points: [ - [5, 25], - [7, 24], - [8, 23], - [9, 21], - [9, 19], - [8, 17], - [7, 16], - [6, 14], - [6, 12], - [8, 10], - [-1, -1], - [7, 24], - [8, 22], - [8, 20], - [7, 18], - [6, 17], - [5, 15], - [5, 13], - [6, 11], - [10, 9], - [6, 7], - [5, 5], - [5, 3], - [6, 1], - [7, 0], - [8, -2], - [8, -4], - [7, -6], - [-1, -1], - [8, 8], - [6, 6], - [6, 4], - [7, 2], - [8, 1], - [9, -1], - [9, -3], - [8, -5], - [7, -6], - [5, -7] - ] - }, - '~': { - width: 24, points: [ - [3, 6], - [3, 8], - [4, 11], - [6, 12], - [8, 12], - [10, 11], - [14, 8], - [16, 7], - [18, 7], - [20, 8], - [21, 10], - [-1, -1], - [3, 8], - [4, 10], - [6, 11], - [8, 11], - [10, 10], - [14, 7], - [16, 6], - [18, 6], - [20, 7], - [21, 10], - [21, 12] - ] - } -}; - -/** - * @desc Creates wireframe vector text {@link Geometry}. - * - * ## Usage - * - * Creating a {@link Mesh} with vector text {@link ReadableGeometry} : - * - * [[Run this example](/examples/index.html#geometry_builders_buildVectorTextGeometry)] - * - * ````javascript - * - * import {Viewer, Mesh, buildVectorTextGeometry, ReadableGeometry, PhongMaterial} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.camera.eye = [0, 0, 100]; - * viewer.camera.look = [0, 0, 0]; - * viewer.camera.up = [0, 1, 0]; - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildVectorTextGeometry({ - * origin: [0,0,0], - * text: "On the other side of the screen, it all looked so easy" - * }), - * material: new PhongMaterial(viewer.scene, { - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }) - * }) - * }); - * ```` - * - * @function buildVectorTextGeometry - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.center] 3D point indicating the center position. - * @param {Number[]} [cfg.origin] 3D point indicating the top left corner. - * @param {Number} [cfg.size=1] Size of each character. - * @param {String} [cfg.text=""] The text. - * @returns {Object} Configuration for a {@link Geometry} subtype. - */ -function buildVectorTextGeometry(cfg = {}) { - - var origin = cfg.origin || [0, 0, 0]; - var xOrigin = origin[0]; - var yOrigin = origin[1]; - var zOrigin = origin[2]; - var size = cfg.size || 1; - - var positions = []; - var indices = []; - var text = cfg.text; - if (utils.isNumeric(text)) { - text = "" + text; - } - var lines = (text || "").split("\n"); - var countVerts = 0; - var y = 0; - var x; - var str; - var len; - var c; - var mag = 1.0 / 25.0; - var penUp; - var p1; - var p2; - var pointsLen; - var a; - - for (var iLine = 0; iLine < lines.length; iLine++) { - - x = 0; - str = lines[iLine]; - len = str.length; - - for (var i = 0; i < len; i++) { - - c = letters[str.charAt(i)]; - - if (!c) { - continue; - } - - penUp = 1; - p1 = -1; - p2 = -1; - - pointsLen = c.points.length; - - for (var j = 0; j < pointsLen; j++) { - a = c.points[j]; - - if (a[0] === -1 && a[1] === -1) { - penUp = 1; - continue; - } - - positions.push((x + (a[0] * size) * mag) + xOrigin); - positions.push((y + (a[1] * size) * mag) + yOrigin); - positions.push(0 + zOrigin); - - if (p1 === -1) { - p1 = countVerts; - } else if (p2 === -1) { - p2 = countVerts; - } else { - p1 = p2; - p2 = countVerts; - } - countVerts++; - - if (penUp) { - penUp = false; - - } else { - indices.push(p1); - indices.push(p2); - } - } - x += c.width * mag * size; - - } - y -= 35 * mag * size; - } - - return utils.apply(cfg, { - primitive: "lines", - positions: positions, - indices: indices - }); -} - -/** - * @desc Creates a 3D polyline {@link Geometry}. - * - * ## Usage - * - * In the example below we'll create a {@link Mesh} with a polyline {@link ReadableGeometry} that has lines primitives. - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/scenegraph/#buildPolylineGeometry)] - * - * ````javascript - * //------------------------------------------------------------------------------------------------------------------ - * // Import the modules we need for this example - * //------------------------------------------------------------------------------------------------------------------ - * - * import {buildPolylineGeometry, Viewer, Mesh, ReadableGeometry, PhongMaterial} from "../../dist/xeokit-sdk.min.es.js"; - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a Viewer and arrange the camera - * //------------------------------------------------------------------------------------------------------------------ - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.camera.eye = [0, 0, 8]; - * viewer.camera.look = [0, 0, 0]; - * viewer.camera.up = [0, 1, 0]; - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a mesh with polyline shape - * //------------------------------------------------------------------------------------------------------------------ - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildPolylineGeometry({ - * points: [ - * 0, 2.83654, 0, - * -0.665144, 1.152063, 0, - * -2.456516, 1.41827, 0, - * -1.330288, 0, 0, - * -2.456516, -1.41827, 0, - * -0.665144, -1.152063, 0, - * 0, -2.83654, 0, - * 0.665144, -1.152063, 0, - * 2.456516, -1.41827, 0, - * 1.330288, 0, 0, - * 2.456516, 1.41827, 0, - * 0.665144, 1.152063, 0, - * 0, 2.83654, 0, - * ] - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [0, 1,] - * }) - * }); - * ```` - * - * @function buildPolylineGeometry - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.points] 3D points indicating vertices position. - * @returns {Object} Configuration for a {@link Geometry} subtype. - */ -function buildPolylineGeometry(cfg = {}) { - - if (cfg.points.length % 3 !== 0) { - throw "Size of points array for given polyline should be divisible by 3"; - } - let numberOfPoints = cfg.points.length / 3; - if (numberOfPoints < 2) { - throw "There should be at least 2 points to create a polyline"; - } - let indices = []; - for (let i = 0; i < numberOfPoints - 1; i++) { - indices.push(i); - indices.push(i + 1); - } - - return utils.apply(cfg, { - primitive: "lines", - positions: cfg.points, - indices: indices, - }); -} - -/** - * @desc Creates a 3D polyline from curve {@link Geometry}. - * - * ## Usage - * - * In the example below we'll create a {@link Mesh} with a polyline {@link ReadableGeometry} created from curves. - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/scenegraph/#buildPolylineGeometryFromCurve)] - * - * ````javascript - * //------------------------------------------------------------------------------------------------------------------ - * // Import the modules we need for this example - * //------------------------------------------------------------------------------------------------------------------ - * - * import {buildPolylineGeometryFromCurve, Viewer, Mesh, PhongMaterial, NavCubePlugin, CubicBezierCurve, SplineCurve, QuadraticBezierCurve, ReadableGeometry} from "../../dist/xeokit-sdk.min.es.js"; - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a Viewer and arrange the camera - * //------------------------------------------------------------------------------------------------------------------ - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * new NavCubePlugin(viewer, { - * canvasId: "myNavCubeCanvas", - * visible: true, - * size: 250, - * alignment: "bottomRight", - * bottomMargin: 100, - * rightMargin: 10 - * }); - * - * viewer.camera.eye = [0, -250, 1]; - * viewer.camera.look = [0, 0, 0]; - * viewer.camera.up = [0, 1, 0]; - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a mesh with polyline shape from Spline - * //------------------------------------------------------------------------------------------------------------------ - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildPolylineGeometryFromCurve({ - * id: "SplineCurve", - * curve: new SplineCurve(viewer.scene, { - * points: [ - * [-65.77614, 0, -88.881992], - * [90.020852, 0, -61.589088], - * [-67.766247, 0, -22.071238], - * [93.148164, 0, -13.826507], - * [-14.033343, 0, 3.231558], - * [32.592034, 0, 9.20188], - * [3.309023, 0, 22.848332], - * [23.210098, 0, 28.818655], - * ], - * }), - * divisions: 100, - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [1, 0, 0] - * }) - * }); - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a mesh with polyline shape from CubicBezier - * //------------------------------------------------------------------------------------------------------------------ - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildPolylineGeometryFromCurve({ - * id: "CubicBezierCurve", - * curve: new CubicBezierCurve(viewer.scene, { - * v0: [120, 0, 100], - * v1: [120, 0, 0], - * v2: [80, 0, 100], - * v3: [80, 0, 0], - * }), - * divisions: 50, - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [0, 1, 0] - * }) - * }); - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a mesh with polyline shape from QuadraticBezier - * //------------------------------------------------------------------------------------------------------------------ - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildPolylineGeometryFromCurve({ - * id: "QuadraticBezierCurve", - * curve: new QuadraticBezierCurve(viewer.scene, { - * v0: [-100, 0, 100], - * v1: [-50, 0, 150], - * v2: [-50, 0, 0], - * }), - * divisions: 20, - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [0, 0, 1] - * }) - * }); - * ```` - * - * @function buildPolylineGeometryFromCurve - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Object} [cfg.curve] Curve for which polyline will be created. - * @param {Number} [cfg.divisions] The number of divisions. - * @returns {Object} Configuration for a {@link Geometry} subtype. - */ -function buildPolylineGeometryFromCurve(cfg = {}) { - - let polylinePoints = cfg.curve.getPoints(cfg.divisions).map(a => [...a]).flat(); - return buildPolylineGeometry({ - id: cfg.id, - points: polylinePoints - }); -} - -/** - * @desc Creates a 3D line {@link Geometry}. - * - * ## Usage - * - * In the example below we'll create a {@link Mesh} with a line {@link ReadableGeometry}. - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/scenegraph/#buildLineGeometry)] - * - * ````javascript - * //------------------------------------------------------------------------------------------------------------------ - * // Import the modules we need for this example - * //------------------------------------------------------------------------------------------------------------------ - * - * import {buildLineGeometry, Viewer, Mesh, ReadableGeometry, PhongMaterial} from "../../dist/xeokit-sdk.min.es.js"; - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a Viewer and arrange the camera - * //------------------------------------------------------------------------------------------------------------------ - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.camera.eye = [0, 0, 8]; - * viewer.camera.look = [0, 0, 0]; - * viewer.camera.up = [0, 1, 0]; - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a mesh with simple 2d line shape - * //------------------------------------------------------------------------------------------------------------------ - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildLineGeometry({ - * startPoint: [-5,-2,0], - * endPoint: [-5,2,0], - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [0, 1,] - * }) - * }); - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a mesh with simple 2d line shape with black color - * //------------------------------------------------------------------------------------------------------------------ - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildLineGeometry({ - * startPoint: [-4,-2,0], - * endPoint: [-4,2,0], - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [0, 0, 0] - * }) - * }); - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a mesh with simple 2d line shape with black color and simple pattern - * //------------------------------------------------------------------------------------------------------------------ - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildLineGeometry({ - * startPoint: [-3,-2,0], - * endPoint: [-3,2,0], - * pattern: [0.10], - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [0, 0, 0] - * }) - * }); - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a mesh with simple 2d line shape with blue color and simple pattern extended to end - * //------------------------------------------------------------------------------------------------------------------ - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildLineGeometry({ - * startPoint: [-2,-2,0], - * endPoint: [-2,2,0], - * pattern: [0.10], - * extendToEnd: true, - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [0, 0, 1] - * }) - * }); - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a mesh with simple 2d line shape with black color and more complex pattern - * //------------------------------------------------------------------------------------------------------------------ - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildLineGeometry({ - * startPoint: [-1,-2,0], - * endPoint: [-1,2,0], - * pattern: [0.15, 0.05], - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [0, 0, 0] - * }) - * }); - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a mesh with simple 2d line shape with blue color and more complex pattern extended to end - * //------------------------------------------------------------------------------------------------------------------ - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildLineGeometry({ - * startPoint: [0,-2,0], - * endPoint: [0,2,0], - * pattern: [0.15, 0.05], - * extendToEnd: true, - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [0, 0, 1] - * }) - * }); - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a mesh with simple 2d line shape with black color and complex pattern - * //------------------------------------------------------------------------------------------------------------------ - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildLineGeometry({ - * startPoint: [1,-2,0], - * endPoint: [1,2,0], - * pattern: [0.15, 0.05, 0.50], - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [0, 0, 0] - * }) - * }); - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a mesh with simple 2d line shape with blue color and complex pattern extended to end - * //------------------------------------------------------------------------------------------------------------------ - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildLineGeometry({ - * startPoint: [2,-2,0], - * endPoint: [2,2,0], - * pattern: [0.15, 0.05, 0.50], - * extendToEnd: true, - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [0, 0, 1] - * }) - * }); - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a mesh with simple 3d line shape with white color and simple pattern - * //------------------------------------------------------------------------------------------------------------------ - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildLineGeometry({ - * startPoint: [3,-2,-1], - * endPoint: [5,2,1], - * pattern: [0.10], - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [1, 1, 1] - * }) - * }); - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a mesh with simple 3d line shape with black color and simple dot pattern - * //------------------------------------------------------------------------------------------------------------------ - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildLineGeometry({ - * startPoint: [5,-2,-1], - * endPoint: [7,2,1], - * pattern: [0.03], - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [0, 0, 0] - * }) - * }); - * ```` - * - * @function buildLineGeometry - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.startPoint] 3D start point (x0, y0, z0). - * @param {Number[]} [cfg.endPoint] 3D end point (x1, y1, z1). - * @param {Number[]} [cfg.pattern] Lengths of segments that describe a pattern. - * @param {Bool} [cfg.extendToEnd] If true: it will try to make sure the line doesn't end up with a gap, as it will - * extend the last segment. - * @returns {Object} Configuration for a {@link Geometry} subtype. - */ -function buildLineGeometry(cfg = {}) { - - if (cfg.startPoint.length !== 3) { - throw "Start point should contain 3 elements in array: x, y and z"; - } - if (cfg.endPoint.length !== 3) { - throw "End point should contain 3 elements in array: x, y and z"; - } - let indices = []; - let points = []; - let x0 = cfg.startPoint[0]; let y0 = cfg.startPoint[1]; let z0 = cfg.startPoint[2]; - let x1 = cfg.endPoint[0]; let y1 = cfg.endPoint[1]; let z1 = cfg.endPoint[2]; - let lineLength = Math.sqrt((x1- x0)**2 + (y1 - y0)**2 + (z1 - z0)**2); - let normalizedDirectionVectorOfLine = [(x1-x0)/lineLength, (y1-y0)/lineLength, (z1-z0)/lineLength]; - - if (!cfg.pattern) { - indices.push(0); - indices.push(1); - points.push(x0, y0, z0, x1, y1, z1); - } - else { - let patternsNumber = cfg.pattern.length; - let gap = false; - let segmentFilled = 0.0; - let idOfCurrentPatternLength = 0; - let pointIndicesCounter = 0; - let currentStartPoint = [x0, y0, z0]; - let currentPatternLength = cfg.pattern[idOfCurrentPatternLength]; - points.push(currentStartPoint[0], currentStartPoint[1], currentStartPoint[2]); - - while (currentPatternLength <= (lineLength - segmentFilled)) { - let vectorFromCurrentStartPointToCurrentEndPoint = [ - normalizedDirectionVectorOfLine[0] * currentPatternLength, - normalizedDirectionVectorOfLine[1] * currentPatternLength, - normalizedDirectionVectorOfLine[2] * currentPatternLength, - ]; - let currentEndPoint = [ - currentStartPoint[0] + vectorFromCurrentStartPointToCurrentEndPoint[0], - currentStartPoint[1] + vectorFromCurrentStartPointToCurrentEndPoint[1], - currentStartPoint[2] + vectorFromCurrentStartPointToCurrentEndPoint[2], - ]; - - points.push(currentEndPoint[0], currentEndPoint[1], currentEndPoint[2]); - - if (!gap) { - indices.push(pointIndicesCounter); - indices.push(pointIndicesCounter + 1); - } - gap = !gap; - - pointIndicesCounter += 1; - currentStartPoint = currentEndPoint; - idOfCurrentPatternLength += 1; - if (idOfCurrentPatternLength >= patternsNumber) { - idOfCurrentPatternLength = 0; - } - segmentFilled += currentPatternLength; - currentPatternLength = cfg.pattern[idOfCurrentPatternLength]; - } - - if (cfg.extendToEnd) { - points.push(x1, y1, z1); - indices.push(indices.length - 2); - indices.push(indices.length - 1); - } - } - - return utils.apply(cfg, { - primitive: "lines", - positions: points, - indices: indices, - }); -} - -const angleAxis$2 = math.vec4(4); -const q1$2 = math.vec4(); -const q2$2 = math.vec4(); -const xAxis$2 = math.vec3([1, 0, 0]); -const yAxis$2 = math.vec3([0, 1, 0]); -const zAxis$2 = math.vec3([0, 0, 1]); - -const veca$1 = math.vec3(3); -const vecb$1 = math.vec3(3); - -const identityMat$2 = math.identityMat4(); - -/** - * @desc An {@link Entity} that is a scene graph node that can have child Nodes and {@link Mesh}es. - * - * ## Usage - * - * The example below is the same as the one given for {@link Mesh}, since the two classes work together. In this example, - * we'll create a scene graph in which a root Node represents a group and the {@link Mesh}s are leaves. Since Node - * implements {@link Entity}, we can designate the root Node as a model, causing it to be registered by its ID in {@link Scene#models}. - * - * Since {@link Mesh} also implements {@link Entity}, we can designate the leaf {@link Mesh}es as objects, causing them to - * be registered by their IDs in {@link Scene#objects}. - * - * We can then find those {@link Entity} types in {@link Scene#models} and {@link Scene#objects}. - * - * We can also update properties of our object-Meshes via calls to {@link Scene#setObjectsHighlighted} etc. - * - * [[Run this example](/examples/index.html#sceneRepresentation_SceneGraph)] - * - * ````javascript - * import {Viewer, Mesh, Node, PhongMaterial} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [-21.80, 4.01, 6.56]; - * viewer.scene.camera.look = [0, -5.75, 0]; - * viewer.scene.camera.up = [0.37, 0.91, -0.11]; - * - * new Node(viewer.scene, { - * id: "table", - * isModel: true, // <---------- Node represents a model, so is registered by ID in viewer.scene.models - * rotation: [0, 50, 0], - * position: [0, 0, 0], - * scale: [1, 1, 1], - * - * children: [ - * - * new Mesh(viewer.scene, { // Red table leg - * id: "redLeg", - * isObject: true, // <------ Node represents an object, so is registered by ID in viewer.scene.objects - * position: [-4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * material: new PhongMaterial(viewer.scene, { - * diffuse: [1, 0.3, 0.3] - * }) - * }), - * - * new Mesh(viewer.scene, { // Green table leg - * id: "greenLeg", - * isObject: true, // <------ Node represents an object, so is registered by ID in viewer.scene.objects - * position: [4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * material: new PhongMaterial(viewer.scene, { - * diffuse: [0.3, 1.0, 0.3] - * }) - * }), - * - * new Mesh(viewer.scene, {// Blue table leg - * id: "blueLeg", - * isObject: true, // <------ Node represents an object, so is registered by ID in viewer.scene.objects - * position: [4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * material: new PhongMaterial(viewer.scene, { - * diffuse: [0.3, 0.3, 1.0] - * }) - * }), - * - * new Mesh(viewer.scene, { // Yellow table leg - * id: "yellowLeg", - * isObject: true, // <------ Node represents an object, so is registered by ID in viewer.scene.objects - * position: [-4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * material: new PhongMaterial(viewer.scene, { - * diffuse: [1.0, 1.0, 0.0] - * }) - * }), - * - * new Mesh(viewer.scene, { // Purple table top - * id: "tableTop", - * isObject: true, // <------ Node represents an object, so is registered by ID in viewer.scene.objects - * position: [0, -3, 0], - * scale: [6, 0.5, 6], - * rotation: [0, 0, 0], - * material: new PhongMaterial(viewer.scene, { - * diffuse: [1.0, 0.3, 1.0] - * }) - * }) - * ] - * }); - * - * // Find Nodes and Meshes by their IDs - * - * var table = viewer.scene.models["table"]; // Since table Node has isModel == true - * - * var redLeg = viewer.scene.objects["redLeg"]; // Since the Meshes have isObject == true - * var greenLeg = viewer.scene.objects["greenLeg"]; - * var blueLeg = viewer.scene.objects["blueLeg"]; - * - * // Highlight one of the table leg Meshes - * - * viewer.scene.setObjectsHighlighted(["redLeg"], true); // Since the Meshes have isObject == true - * - * // Periodically update transforms on our Nodes and Meshes - * - * viewer.scene.on("tick", function () { - * - * // Rotate legs - * redLeg.rotateY(0.5); - * greenLeg.rotateY(0.5); - * blueLeg.rotateY(0.5); - * - * // Rotate table - * table.rotateY(0.5); - * table.rotateX(0.3); - * }); - * ```` - * - * ## Metadata - * - * As mentioned, we can also associate {@link MetaModel}s and {@link MetaObject}s with our Nodes and {@link Mesh}es, - * within a {@link MetaScene}. See {@link MetaScene} for an example. - * - * @implements {Entity} - */ -class Node$1 extends Component { - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID, unique among all components in the parent scene, generated automatically when omitted. - * @param {Boolean} [cfg.isModel] Specify ````true```` if this Mesh represents a model, in which case the Mesh will be registered by {@link Mesh#id} in {@link Scene#models} and may also have a corresponding {@link MetaModel} with matching {@link MetaModel#id}, registered by that ID in {@link MetaScene#metaModels}. - * @param {Boolean} [cfg.isObject] Specify ````true```` if this Mesh represents an object, in which case the Mesh will be registered by {@link Mesh#id} in {@link Scene#objects} and may also have a corresponding {@link MetaObject} with matching {@link MetaObject#id}, registered by that ID in {@link MetaScene#metaObjects}. - * @param {Node} [cfg.parent] The parent Node. - * @param {Number[]} [cfg.origin] World-space origin for this Node. - * @param {Number[]} [cfg.rtcCenter] Deprecated - renamed to ````origin````. - * @param {Number[]} [cfg.position=[0,0,0]] Local 3D position. - * @param {Number[]} [cfg.scale=[1,1,1]] Local scale. - * @param {Number[]} [cfg.rotation=[0,0,0]] Local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis. - * @param {Number[]} [cfg.matrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1] Local modelling transform matrix. Overrides the position, scale and rotation parameters. - * @param {Number[]} [cfg.offset=[0,0,0]] World-space 3D translation offset. Translates the Node in World space, after modelling transforms. - * @param {Boolean} [cfg.visible=true] Indicates if the Node is initially visible. - * @param {Boolean} [cfg.culled=false] Indicates if the Node is initially culled from view. - * @param {Boolean} [cfg.pickable=true] Indicates if the Node is initially pickable. - * @param {Boolean} [cfg.clippable=true] Indicates if the Node is initially clippable. - * @param {Boolean} [cfg.collidable=true] Indicates if the Node is initially included in boundary calculations. - * @param {Boolean} [cfg.castsShadow=true] Indicates if the Node initially casts shadows. - * @param {Boolean} [cfg.receivesShadow=true] Indicates if the Node initially receives shadows. - * @param {Boolean} [cfg.xrayed=false] Indicates if the Node is initially xrayed. - * @param {Boolean} [cfg.highlighted=false] Indicates if the Node is initially highlighted. - * @param {Boolean} [cfg.selected=false] Indicates if the Mesh is initially selected. - * @param {Boolean} [cfg.edges=false] Indicates if the Node's edges are initially emphasized. - * @param {Number[]} [cfg.colorize=[1.0,1.0,1.0]] Node's initial RGB colorize color, multiplies by the rendered fragment colors. - * @param {Number} [cfg.opacity=1.0] Node's initial opacity factor, multiplies by the rendered fragment alpha. - * @param {Array} [cfg.children] Child Nodes or {@link Mesh}es to add initially. Children must be in the same {@link Scene} and will be removed first from whatever parents they may already have. - * @param {Boolean} [cfg.inheritStates=true] Indicates if children given to this constructor should inherit rendering state from this parent as they are added. Rendering state includes {@link Node#visible}, {@link Node#culled}, {@link Node#pickable}, {@link Node#clippable}, {@link Node#castsShadow}, {@link Node#receivesShadow}, {@link Node#selected}, {@link Node#highlighted}, {@link Node#colorize} and {@link Node#opacity}. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._parentNode = null; - this._children = []; - - this._aabb = null; - this._aabbDirty = true; - - this.scene._aabbDirty = true; - - this._numTriangles = 0; - - this._scale = math.vec3(); - this._quaternion = math.identityQuaternion(); - this._rotation = math.vec3(); - this._position = math.vec3(); - this._offset = math.vec3(); - - this._localMatrix = math.identityMat4(); - this._worldMatrix = math.identityMat4(); - - this._localMatrixDirty = true; - this._worldMatrixDirty = true; - - if (cfg.matrix) { - this.matrix = cfg.matrix; - } else { - this.scale = cfg.scale; - this.position = cfg.position; - if (cfg.quaternion) ; else { - this.rotation = cfg.rotation; - } - } - - this._isModel = cfg.isModel; - if (this._isModel) { - this.scene._registerModel(this); - } - - this._isObject = cfg.isObject; - if (this._isObject) { - this.scene._registerObject(this); - } - - this.origin = cfg.origin; - this.visible = cfg.visible; - this.culled = cfg.culled; - this.pickable = cfg.pickable; - this.clippable = cfg.clippable; - this.collidable = cfg.collidable; - this.castsShadow = cfg.castsShadow; - this.receivesShadow = cfg.receivesShadow; - this.xrayed = cfg.xrayed; - this.highlighted = cfg.highlighted; - this.selected = cfg.selected; - this.edges = cfg.edges; - this.colorize = cfg.colorize; - this.opacity = cfg.opacity; - this.offset = cfg.offset; - - // Add children, which inherit state from this Node - - if (cfg.children) { - const children = cfg.children; - for (let i = 0, len = children.length; i < len; i++) { - this.addChild(children[i], cfg.inheritStates); - } - } - - if (cfg.parentId) { - const parentNode = this.scene.components[cfg.parentId]; - if (!parentNode) { - this.error("Parent not found: '" + cfg.parentId + "'"); - } else if (!parentNode.isNode) { - this.error("Parent is not a Node: '" + cfg.parentId + "'"); - } else { - parentNode.addChild(this); - } - } else if (cfg.parent) { - if (!cfg.parent.isNode) { - this.error("Parent is not a Node"); - } - cfg.parent.addChild(this); - } - } - - //------------------------------------------------------------------------------------------------------------------ - // Entity members - //------------------------------------------------------------------------------------------------------------------ - - /** - * Returns true to indicate that this Component is an Entity. - * @type {Boolean} - */ - get isEntity() { - return true; - } - - /** - * Returns ````true```` if this Mesh represents a model. - * - * When this returns ````true````, the Mesh will be registered by {@link Mesh#id} in {@link Scene#models} and - * may also have a corresponding {@link MetaModel}. - * - * @type {Boolean} - */ - get isModel() { - return this._isModel; - } - - /** - * Returns ````true```` if this Node represents an object. - * - * When ````true```` the Node will be registered by {@link Node#id} in - * {@link Scene#objects} and may also have a {@link MetaObject} with matching {@link MetaObject#id}. - * - * @type {Boolean} - * @abstract - */ - get isObject() { - return this._isObject; - } - - /** - * Gets the Node's World-space 3D axis-aligned bounding box. - * - * Represented by a six-element Float64Array containing the min/max extents of the - * axis-aligned volume, ie. ````[xmin, ymin,zmin,xmax,ymax, zmax]````. - * - * @type {Number[]} - */ - get aabb() { - if (this._aabbDirty) { - this._updateAABB(); - } - return this._aabb; - } - - /** - * Sets the World-space origin for this Node. - * - * @type {Float64Array} - */ - set origin(origin) { - if (origin) { - if (!this._origin) { - this._origin = math.vec3(); - } - this._origin.set(origin); - } else { - if (this._origin) { - this._origin = null; - } - } - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i].origin = origin; - } - this.glRedraw(); - } - - /** - * Gets the World-space origin for this Node. - * - * @type {Float64Array} - */ - get origin() { - return this._origin; - } - - /** - * Sets the World-space origin for this Node. - * - * Deprecated and replaced by {@link Node#origin}. - * - * @deprecated - * @type {Float64Array} - */ - set rtcCenter(rtcCenter) { - this.origin = rtcCenter; - } - - /** - * Gets the World-space origin for this Node. - * - * Deprecated and replaced by {@link Node#origin}. - * - * @deprecated - * @type {Float64Array} - */ - get rtcCenter() { - return this.origin; - } - - /** - * The number of triangles in this Node. - * - * @type {Number} - */ - get numTriangles() { - return this._numTriangles; - } - - /** - * Sets if this Node and all child Nodes and {@link Mesh}es are visible. - * - * Only rendered both {@link Node#visible} is ````true```` and {@link Node#culled} is ````false````. - * - * When {@link Node#isObject} and {@link Node#visible} are both ````true```` the Node will be - * registered by {@link Node#id} in {@link Scene#visibleObjects}. - * - * @type {Boolean} - */ - set visible(visible) { - visible = visible !== false; - this._visible = visible; - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i].visible = visible; - } - if (this._isObject) { - this.scene._objectVisibilityUpdated(this, visible); - } - } - - /** - * Gets if this Node is visible. - * - * Child Nodes and {@link Mesh}es may have different values for this property. - * - * When {@link Node#isObject} and {@link Node#visible} are both ````true```` the Node will be - * registered by {@link Node#id} in {@link Scene#visibleObjects}. - * - * @type {Boolean} - */ - get visible() { - return this._visible; - } - - /** - * Sets if this Node and all child Nodes and {@link Mesh}es are xrayed. - * - * When {@link Node#isObject} and {@link Node#xrayed} are both ````true```` the Node will be - * registered by {@link Node#id} in {@link Scene#xrayedObjects}. - * - * @type {Boolean} - */ - set xrayed(xrayed) { - xrayed = !!xrayed; - this._xrayed = xrayed; - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i].xrayed = xrayed; - } - if (this._isObject) { - this.scene._objectXRayedUpdated(this, xrayed); - } - } - - /** - * Gets if this Node is xrayed. - * - * When {@link Node#isObject} and {@link Node#xrayed} are both ````true```` the Node will be - * registered by {@link Node#id} in {@link Scene#xrayedObjects}. - * - * Child Nodes and {@link Mesh}es may have different values for this property. - * - * @type {Boolean} - */ - get xrayed() { - return this._xrayed; - } - - /** - * Sets if this Node and all child Nodes and {@link Mesh}es are highlighted. - * - * When {@link Node#isObject} and {@link Node#highlighted} are both ````true```` the Node will be - * registered by {@link Node#id} in {@link Scene#highlightedObjects}. - * - * @type {Boolean} - */ - set highlighted(highlighted) { - highlighted = !!highlighted; - this._highlighted = highlighted; - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i].highlighted = highlighted; - } - if (this._isObject) { - this.scene._objectHighlightedUpdated(this, highlighted); - } - } - - /** - * Gets if this Node is highlighted. - * - * When {@link Node#isObject} and {@link Node#highlighted} are both ````true```` the Node will be - * registered by {@link Node#id} in {@link Scene#highlightedObjects}. - * - * Child Nodes and {@link Mesh}es may have different values for this property. - * - * @type {Boolean} - */ - get highlighted() { - return this._highlighted; - } - - /** - * Sets if this Node and all child Nodes and {@link Mesh}es are selected. - * - * When {@link Node#isObject} and {@link Node#selected} are both ````true```` the Node will be - * registered by {@link Node#id} in {@link Scene#selectedObjects}. - * - * @type {Boolean} - */ - set selected(selected) { - selected = !!selected; - this._selected = selected; - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i].selected = selected; - } - if (this._isObject) { - this.scene._objectSelectedUpdated(this, selected); - } - } - - /** - * Gets if this Node is selected. - * - * When {@link Node#isObject} and {@link Node#selected} are both ````true```` the Node will be - * registered by {@link Node#id} in {@link Scene#selectedObjects}. - * - * Child Nodes and {@link Mesh}es may have different values for this property. - * - * @type {Boolean} - */ - get selected() { - return this._selected; - } - - /** - * Sets if this Node and all child Nodes and {@link Mesh}es are edge-enhanced. - * - * @type {Boolean} - */ - set edges(edges) { - edges = !!edges; - this._edges = edges; - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i].edges = edges; - } - } - - /** - * Gets if this Node's edges are enhanced. - * - * Child Nodes and {@link Mesh}es may have different values for this property. - * - * @type {Boolean} - */ - get edges() { - return this._edges; - } - - /** - * Sets if this Node and all child Nodes and {@link Mesh}es are culled. - * - * @type {Boolean} - */ - set culled(culled) { - culled = !!culled; - this._culled = culled; - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i].culled = culled; - } - } - - /** - * Gets if this Node is culled. - * - * @type {Boolean} - */ - get culled() { - return this._culled; - } - - /** - * Sets if this Node and all child Nodes and {@link Mesh}es are clippable. - * - * Clipping is done by the {@link SectionPlane}s in {@link Scene#clips}. - * - * @type {Boolean} - */ - set clippable(clippable) { - clippable = clippable !== false; - this._clippable = clippable; - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i].clippable = clippable; - } - } - - /** - * Gets if this Node is clippable. - * - * Clipping is done by the {@link SectionPlane}s in {@link Scene#clips}. - * - * Child Nodes and {@link Mesh}es may have different values for this property. - * - * @type {Boolean} - */ - get clippable() { - return this._clippable; - } - - /** - * Sets if this Node and all child Nodes and {@link Mesh}es are included in boundary calculations. - * - * @type {Boolean} - */ - set collidable(collidable) { - collidable = collidable !== false; - this._collidable = collidable; - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i].collidable = collidable; - } - } - - /** - * Gets if this Node is included in boundary calculations. - * - * Child Nodes and {@link Mesh}es may have different values for this property. - * - * @type {Boolean} - */ - get collidable() { - return this._collidable; - } - - /** - * Sets if this Node and all child Nodes and {@link Mesh}es are pickable. - * - * Picking is done via calls to {@link Scene#pick}. - * - * @type {Boolean} - */ - set pickable(pickable) { - pickable = pickable !== false; - this._pickable = pickable; - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i].pickable = pickable; - } - } - - /** - * Gets if to this Node is pickable. - * - * Picking is done via calls to {@link Scene#pick}. - * - * Child Nodes and {@link Mesh}es may have different values for this property. - * - * @type {Boolean} - */ - get pickable() { - return this._pickable; - } - - /** - * Sets the RGB colorize color for this Node and all child Nodes and {@link Mesh}es}. - * - * Multiplies by rendered fragment colors. - * - * Each element of the color is in range ````[0..1]````. - * - * @type {Number[]} - */ - set colorize(rgb) { - let colorize = this._colorize; - if (!colorize) { - colorize = this._colorize = new Float32Array(4); - colorize[3] = 1.0; - } - if (rgb) { - colorize[0] = rgb[0]; - colorize[1] = rgb[1]; - colorize[2] = rgb[2]; - } else { - colorize[0] = 1; - colorize[1] = 1; - colorize[2] = 1; - } - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i].colorize = colorize; - } - if (this._isObject) { - const colorized = (!!rgb); - this.scene._objectColorizeUpdated(this, colorized); - } - } - - /** - * Gets the RGB colorize color for this Node. - * - * Each element of the color is in range ````[0..1]````. - * - * Child Nodes and {@link Mesh}es may have different values for this property. - * - * @type {Number[]} - */ - get colorize() { - return this._colorize.slice(0, 3); - } - - /** - * Sets the opacity factor for this Node and all child Nodes and {@link Mesh}es. - * - * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas. - * - * @type {Number} - */ - set opacity(opacity) { - let colorize = this._colorize; - if (!colorize) { - colorize = this._colorize = new Float32Array(4); - colorize[0] = 1; - colorize[1] = 1; - colorize[2] = 1; - } - colorize[3] = opacity !== null && opacity !== undefined ? opacity : 1.0; - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i].opacity = opacity; - } - if (this._isObject) { - const opacityUpdated = (opacity !== null && opacity !== undefined); - this.scene._objectOpacityUpdated(this, opacityUpdated); - } - } - - /** - * Gets this Node's opacity factor. - * - * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas. - * - * Child Nodes and {@link Mesh}es may have different values for this property. - * - * @type {Number} - */ - get opacity() { - return this._colorize[3]; - } - - /** - * Sets if this Node and all child Nodes and {@link Mesh}es cast shadows. - * - * @type {Boolean} - */ - set castsShadow(castsShadow) { - castsShadow = !!castsShadow; - this._castsShadow = castsShadow; - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i].castsShadow = castsShadow; - } - } - - /** - * Gets if this Node casts shadows. - * - * Child Nodes and {@link Mesh}es may have different values for this property. - * - * @type {Boolean} - */ - get castsShadow() { - return this._castsShadow; - } - - /** - * Sets if this Node and all child Nodes and {@link Mesh}es can have shadows cast upon them. - * - * @type {Boolean} - */ - set receivesShadow(receivesShadow) { - receivesShadow = !!receivesShadow; - this._receivesShadow = receivesShadow; - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i].receivesShadow = receivesShadow; - } - } - - /** - * Whether or not to this Node can have shadows cast upon it. - * - * Child Nodes and {@link Mesh}es may have different values for this property. - * - * @type {Boolean} - */ - get receivesShadow() { - return this._receivesShadow; - } - - /** - * Gets if this Node can have Scalable Ambient Obscurance (SAO) applied to it. - * - * SAO is configured by {@link SAO}. - * - * @type {Boolean} - * @abstract - */ - get saoEnabled() { - return false; // TODO: Support SAO on Nodes - } - - - /** - * Sets the 3D World-space offset for this Node and all child Nodes and {@link Mesh}es}. - * - * The offset dynamically translates those components in World-space. - * - * Default value is ````[0, 0, 0]````. - * - * Note that child Nodes and {@link Mesh}es may subsequently be given different values for this property. - * - * @type {Number[]} - */ - set offset(offset) { - if (offset) { - this._offset[0] = offset[0]; - this._offset[1] = offset[1]; - this._offset[2] = offset[2]; - } else { - this._offset[0] = 0; - this._offset[1] = 0; - this._offset[2] = 0; - } - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i].offset = this._offset; - } - if (this._isObject) { - this.scene._objectOffsetUpdated(this, offset); - } - } - - /** - * Gets the Node's 3D World-space offset. - * - * Default value is ````[0, 0, 0]````. - * - * Child Nodes and {@link Mesh}es may have different values for this property. - * - * @type {Number[]} - */ - get offset() { - return this._offset; - } - - - //------------------------------------------------------------------------------------------------------------------ - // Node members - //------------------------------------------------------------------------------------------------------------------ - - /** - * Returns true to indicate that this Component is a Node. - * @type {Boolean} - */ - get isNode() { - return true; - } - - _setLocalMatrixDirty() { - this._localMatrixDirty = true; - this._setWorldMatrixDirty(); - } - - _setWorldMatrixDirty() { - this._worldMatrixDirty = true; - for (let i = 0, len = this._children.length; i < len; i++) { - this._children[i]._setWorldMatrixDirty(); - } - } - - _buildWorldMatrix() { - const localMatrix = this.matrix; - if (!this._parentNode) { - for (let i = 0, len = localMatrix.length; i < len; i++) { - this._worldMatrix[i] = localMatrix[i]; - } - } else { - math.mulMat4(this._parentNode.worldMatrix, localMatrix, this._worldMatrix); - } - this._worldMatrixDirty = false; - } - - _setSubtreeAABBsDirty(node) { - node._aabbDirty = true; - if (node._children) { - for (let i = 0, len = node._children.length; i < len; i++) { - this._setSubtreeAABBsDirty(node._children[i]); - } - } - } - - _setAABBDirty() { - this._setSubtreeAABBsDirty(this); - if (this.collidable) { - for (let node = this; node; node = node._parentNode) { - node._aabbDirty = true; - } - } - } - - _updateAABB() { - this.scene._aabbDirty = true; - if (!this._aabb) { - this._aabb = math.AABB3(); - } - if (this._buildAABB) { - this._buildAABB(this.worldMatrix, this._aabb); // Mesh or VBOSceneModel - } else { // Node | Node | Model - math.collapseAABB3(this._aabb); - let node; - for (let i = 0, len = this._children.length; i < len; i++) { - node = this._children[i]; - if (!node.collidable) { - continue; - } - math.expandAABB3(this._aabb, node.aabb); - } - } - this._aabbDirty = false; - } - - /** - * Adds a child Node or {@link Mesh}. - * - * The child must be a Node or {@link Mesh} in the same {@link Scene}. - * - * If the child already has a parent, will be removed from that parent first. - * - * Does nothing if already a child. - * - * @param {Node|Mesh|String} child Instance or ID of the child to add. - * @param [inheritStates=false] Indicates if the child should inherit rendering states from this parent as it is added. Rendering state includes {@link Node#visible}, {@link Node#culled}, {@link Node#pickable}, {@link Node#clippable}, {@link Node#castsShadow}, {@link Node#receivesShadow}, {@link Node#selected}, {@link Node#highlighted}, {@link Node#colorize} and {@link Node#opacity}. - * @returns {Node|Mesh} The child. - */ - addChild(child, inheritStates) { - if (utils.isNumeric(child) || utils.isString(child)) { - const nodeId = child; - child = this.scene.component[nodeId]; - if (!child) { - this.warn("Component not found: " + utils.inQuotes(nodeId)); - return; - } - if (!child.isNode && !child.isMesh) { - this.error("Not a Node or Mesh: " + nodeId); - return; - } - } else { - if (!child.isNode && !child.isMesh) { - this.error("Not a Node or Mesh: " + child.id); - return; - } - if (child._parentNode) { - if (child._parentNode.id === this.id) { - this.warn("Already a child: " + child.id); - return; - } - child._parentNode.removeChild(child); - } - } - child.id; - if (child.scene.id !== this.scene.id) { - this.error("Child not in same Scene: " + child.id); - return; - } - this._children.push(child); - child._parentNode = this; - if (!!inheritStates) { - child.visible = this.visible; - child.culled = this.culled; - child.xrayed = this.xrayed; - child.highlited = this.highlighted; - child.selected = this.selected; - child.edges = this.edges; - child.clippable = this.clippable; - child.pickable = this.pickable; - child.collidable = this.collidable; - child.castsShadow = this.castsShadow; - child.receivesShadow = this.receivesShadow; - child.colorize = this.colorize; - child.opacity = this.opacity; - child.offset = this.offset; - } - child._setWorldMatrixDirty(); - child._setAABBDirty(); - this._numTriangles += child.numTriangles; - return child; - } - - /** - * Removes the given child Node or {@link Mesh}. - * - * @param {Node|Mesh} child Child to remove. - */ - removeChild(child) { - for (let i = 0, len = this._children.length; i < len; i++) { - if (this._children[i].id === child.id) { - child._parentNode = null; - this._children = this._children.splice(i, 1); - child._setWorldMatrixDirty(); - child._setAABBDirty(); - this._setAABBDirty(); - this._numTriangles -= child.numTriangles; - return; - } - } - } - - /** - * Removes all child Nodes and {@link Mesh}es. - */ - removeChildren() { - let child; - for (let i = 0, len = this._children.length; i < len; i++) { - child = this._children[i]; - child._parentNode = null; - child._setWorldMatrixDirty(); - child._setAABBDirty(); - this._numTriangles -= child.numTriangles; - } - this._children = []; - this._setAABBDirty(); - } - - /** - * Number of child Nodes or {@link Mesh}es. - * - * @type {Number} - */ - get numChildren() { - return this._children.length; - } - - /** - * Array of child Nodes or {@link Mesh}es. - * - * @type {Array} - */ - get children() { - return this._children; - } - - /** - * The parent Node. - * - * The parent Node may also be set by passing the Node to the parent's {@link Node#addChild} method. - * - * @type {Node} - */ - set parent(node) { - if (utils.isNumeric(node) || utils.isString(node)) { - const nodeId = node; - node = this.scene.components[nodeId]; - if (!node) { - this.warn("Node not found: " + utils.inQuotes(nodeId)); - return; - } - if (!node.isNode) { - this.error("Not a Node: " + node.id); - return; - } - } - if (node.scene.id !== this.scene.id) { - this.error("Node not in same Scene: " + node.id); - return; - } - if (this._parentNode && this._parentNode.id === node.id) { - this.warn("Already a child of Node: " + node.id); - return; - } - node.addChild(this); - } - - /** - * The parent Node. - * - * @type {Node} - */ - get parent() { - return this._parentNode; - } - - /** - * Sets the Node's local translation. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - set position(value) { - this._position.set(value || [0, 0, 0]); - this._setLocalMatrixDirty(); - this._setAABBDirty(); - this.glRedraw(); - } - - /** - * Gets the Node's local translation. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - get position() { - return this._position; - } - - /** - * Sets the Node's local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - set rotation(value) { - this._rotation.set(value || [0, 0, 0]); - math.eulerToQuaternion(this._rotation, "XYZ", this._quaternion); - this._setLocalMatrixDirty(); - this._setAABBDirty(); - this.glRedraw(); - } - - /** - * Gets the Node's local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - get rotation() { - return this._rotation; - } - - /** - * Sets the Node's local rotation quaternion. - * - * Default value is ````[0,0,0,1]````. - * - * @type {Number[]} - */ - set quaternion(value) { - this._quaternion.set(value || [0, 0, 0, 1]); - math.quaternionToEuler(this._quaternion, "XYZ", this._rotation); - this._setLocalMatrixDirty(); - this._setAABBDirty(); - this.glRedraw(); - } - - /** - * Gets the Node's local rotation quaternion. - * - * Default value is ````[0,0,0,1]````. - * - * @type {Number[]} - */ - get quaternion() { - return this._quaternion; - } - - /** - * Sets the Node's local scale. - * - * Default value is ````[1,1,1]````. - * - * @type {Number[]} - */ - set scale(value) { - this._scale.set(value || [1, 1, 1]); - this._setLocalMatrixDirty(); - this._setAABBDirty(); - this.glRedraw(); - } - - /** - * Gets the Node's local scale. - * - * Default value is ````[1,1,1]````. - * - * @type {Number[]} - */ - get scale() { - return this._scale; - } - - /** - * Sets the Node's local modeling transform matrix. - * - * Default value is ````[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]````. - * - * @type {Number[]} - */ - set matrix(value) { - if (!this._localMatrix) { - this._localMatrix = math.identityMat4(); - } - this._localMatrix.set(value || identityMat$2); - math.decomposeMat4(this._localMatrix, this._position, this._quaternion, this._scale); - this._localMatrixDirty = false; - this._setWorldMatrixDirty(); - this._setAABBDirty(); - this.glRedraw(); - } - - /** - * Gets the Node's local modeling transform matrix. - * - * Default value is ````[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]````. - * - * @type {Number[]} - */ - get matrix() { - if (this._localMatrixDirty) { - if (!this._localMatrix) { - this._localMatrix = math.identityMat4(); - } - math.composeMat4(this._position, this._quaternion, this._scale, this._localMatrix); - this._localMatrixDirty = false; - } - return this._localMatrix; - } - - /** - * Gets the Node's World matrix. - * - * @property worldMatrix - * @type {Number[]} - */ - get worldMatrix() { - if (this._worldMatrixDirty) { - this._buildWorldMatrix(); - } - return this._worldMatrix; - } - - /** - * Rotates the Node about the given local axis by the given increment. - * - * @param {Number[]} axis Local axis about which to rotate. - * @param {Number} angle Angle increment in degrees. - */ - rotate(axis, angle) { - angleAxis$2[0] = axis[0]; - angleAxis$2[1] = axis[1]; - angleAxis$2[2] = axis[2]; - angleAxis$2[3] = angle * math.DEGTORAD; - math.angleAxisToQuaternion(angleAxis$2, q1$2); - math.mulQuaternions(this.quaternion, q1$2, q2$2); - this.quaternion = q2$2; - this._setLocalMatrixDirty(); - this._setAABBDirty(); - this.glRedraw(); - return this; - } - - /** - * Rotates the Node about the given World-space axis by the given increment. - * - * @param {Number[]} axis Local axis about which to rotate. - * @param {Number} angle Angle increment in degrees. - */ - rotateOnWorldAxis(axis, angle) { - angleAxis$2[0] = axis[0]; - angleAxis$2[1] = axis[1]; - angleAxis$2[2] = axis[2]; - angleAxis$2[3] = angle * math.DEGTORAD; - math.angleAxisToQuaternion(angleAxis$2, q1$2); - math.mulQuaternions(q1$2, this.quaternion, q1$2); - //this.quaternion.premultiply(q1); - return this; - } - - /** - * Rotates the Node about the local X-axis by the given increment. - * - * @param {Number} angle Angle increment in degrees. - */ - rotateX(angle) { - return this.rotate(xAxis$2, angle); - } - - /** - * Rotates the Node about the local Y-axis by the given increment. - * - * @param {Number} angle Angle increment in degrees. - */ - rotateY(angle) { - return this.rotate(yAxis$2, angle); - } - - /** - * Rotates the Node about the local Z-axis by the given increment. - * - * @param {Number} angle Angle increment in degrees. - */ - rotateZ(angle) { - return this.rotate(zAxis$2, angle); - } - - /** - * Translates the Node along local space vector by the given increment. - * - * @param {Number[]} axis Normalized local space 3D vector along which to translate. - * @param {Number} distance Distance to translate along the vector. - */ - translate(axis, distance) { - math.vec3ApplyQuaternion(this.quaternion, axis, veca$1); - math.mulVec3Scalar(veca$1, distance, vecb$1); - math.addVec3(this.position, vecb$1, this.position); - this._setLocalMatrixDirty(); - this._setAABBDirty(); - this.glRedraw(); - return this; - } - - /** - * Translates the Node along the local X-axis by the given increment. - * - * @param {Number} distance Distance to translate along the X-axis. - */ - translateX(distance) { - return this.translate(xAxis$2, distance); - } - - /** - * Translates the Node along the local Y-axis by the given increment. - * - * @param {Number} distance Distance to translate along the Y-axis. - */ - translateY(distance) { - return this.translate(yAxis$2, distance); - } - - /** - * Translates the Node along the local Z-axis by the given increment. - * - * @param {Number} distance Distance to translate along the Z-axis. - */ - translateZ(distance) { - return this.translate(zAxis$2, distance); - } - - //------------------------------------------------------------------------------------------------------------------ - // Component members - //------------------------------------------------------------------------------------------------------------------ - - /** - @private - */ - get type() { - return "Node"; - } - - /** - * Destroys this Node. - */ - destroy() { - super.destroy(); - if (this._parentNode) { - this._parentNode.removeChild(this); - } - if (this._isObject) { - this.scene._deregisterObject(this); - if (this._visible) { - this.scene._objectVisibilityUpdated(this, false, false); - } - if (this._xrayed) { - this.scene._objectXRayedUpdated(this, false, false); - } - if (this._selected) { - this.scene._objectSelectedUpdated(this, false, false); - } - if (this._highlighted) { - this.scene._objectHighlightedUpdated(this, false, false); - } - this.scene._objectColorizeUpdated(this, false); - this.scene._objectOpacityUpdated(this, false); - if (this.offset.some((v) => v !== 0)) - this.scene._objectOffsetUpdated(this, false); - } - if (this._isModel) { - this.scene._deregisterModel(this); - } - if (this._children.length) { - // Clone the _children before iterating, so our children don't mess us up when calling removeChild(). - const tempChildList = this._children.splice(0); - let child; - for (let i = 0, len = tempChildList.length; i < len; i++) { - child = tempChildList[i]; - child.destroy(); - } - } - this._children = []; - this._setAABBDirty(); - this.scene._aabbDirty = true; - } - -} - -const tempVec3a$g = math.vec3(); - -/** - * Given a view matrix and a relative-to-center (RTC) coordinate origin, returns a view matrix - * to transform RTC coordinates to View-space. - * - * The returned view matrix is - * - * @private - */ -const createRTCViewMat = (function () { - - const tempMat = new Float64Array(16); - const rtcCenterWorld = new Float64Array(4); - const rtcCenterView = new Float64Array(4); - - return function (viewMat, rtcCenter, rtcViewMat) { - rtcViewMat = rtcViewMat || tempMat; - rtcCenterWorld[0] = rtcCenter[0]; - rtcCenterWorld[1] = rtcCenter[1]; - rtcCenterWorld[2] = rtcCenter[2]; - rtcCenterWorld[3] = 1; - math.transformVec4(viewMat, rtcCenterWorld, rtcCenterView); - math.setMat4Translation(viewMat, rtcCenterView, rtcViewMat); - return rtcViewMat.slice (); - } -}()); - -/** - * Converts a World-space 3D position to RTC. - * - * Given a double-precision World-space position, returns a double-precision relative-to-center (RTC) center pos - * and a single-precision offset fom that center. - * @private - * @param {Float64Array} worldPos The World-space position. - * @param {Float64Array} rtcCenter Double-precision relative-to-center (RTC) center pos. - * @param {Float32Array} rtcPos Single-precision offset fom that center. - */ -function worldToRTCPos(worldPos, rtcCenter, rtcPos) { - - const xHigh = Float32Array.from([worldPos[0]])[0]; - const xLow = worldPos[0] - xHigh; - - const yHigh = Float32Array.from([worldPos[1]])[0]; - const yLow = worldPos[1] - yHigh; - - const zHigh = Float32Array.from([worldPos[2]])[0]; - const zLow = worldPos[2] - zHigh; - - rtcCenter[0] = xHigh; - rtcCenter[1] = yHigh; - rtcCenter[2] = zHigh; - - rtcPos[0] = xLow; - rtcPos[1] = yLow; - rtcPos[2] = zLow; -} - - -/** - * Converts a flat array of double-precision positions to RTC positions, if necessary. - * - * Conversion is necessary if the coordinates have values larger than can be expressed at single-precision. When - * that's the case, then this function will compute the RTC coordinates and RTC center and return true. Otherwise - * this function does nothing and returns false. - * - * When computing the RTC position, this function uses a modulus operation to ensure that, whenever possible, - * identical RTC centers are reused for different positions arrays. - * - * @private - * @param {Float64Array} worldPositions Flat array of World-space 3D positions. - * @param {Float64Array} rtcPositions Outputs the computed flat array of 3D RTC positions. - * @param {Float64Array} rtcCenter Outputs the computed double-precision relative-to-center (RTC) center pos. - * @param {Number} [cellSize=10000000] The size of each coordinate cell within the RTC coordinate system. - * @returns {Boolean} ````True```` if the positions actually needed conversion to RTC, else ````false````. When - * ````false````, we can safely ignore the data returned in ````rtcPositions```` and ````rtcCenter````, - * since ````rtcCenter```` will equal ````[0,0,0]````, and ````rtcPositions```` will contain identical values to ````positions````. - */ -function worldToRTCPositions(worldPositions, rtcPositions, rtcCenter, cellSize = 1000) { - - const center = math.getPositionsCenter(worldPositions, tempVec3a$g); - - const rtcCenterX = Math.round(center[0] / cellSize) * cellSize; - const rtcCenterY = Math.round(center[1] / cellSize) * cellSize; - const rtcCenterZ = Math.round(center[2] / cellSize) * cellSize; - - rtcCenter[0] = rtcCenterX; - rtcCenter[1] = rtcCenterY; - rtcCenter[2] = rtcCenterZ; - - const rtcNeeded = (rtcCenter[0] !== 0 || rtcCenter[1] !== 0 || rtcCenter[2] !== 0); - - if (rtcNeeded) { - for (let i = 0, len = worldPositions.length; i < len; i += 3) { - rtcPositions[i + 0] = worldPositions[i + 0] - rtcCenterX; - rtcPositions[i + 1] = worldPositions[i + 1] - rtcCenterY; - rtcPositions[i + 2] = worldPositions[i + 2] - rtcCenterZ; - } - } - - return rtcNeeded; -} - -/** - * Texture wrapping mode in which the texture repeats to infinity. - */ -const RepeatWrapping = 1000; - -/** - * Texture wrapping mode in which the last pixel of the texture stretches to the edge of the mesh. - */ -const ClampToEdgeWrapping = 1001; - -/** - * Texture wrapping mode in which the texture repeats to infinity, mirroring on each repeat. - */ -const MirroredRepeatWrapping = 1002; - -/** - * Texture magnification and minification filter that returns the nearest texel to the given sample coordinates. - */ -const NearestFilter = 1003; - -/** - * Texture minification filter that chooses the mipmap that most closely matches the size of the pixel being textured and returns the nearest texel to the given sample coordinates. - */ -const NearestMipMapNearestFilter = 1004; - -/** - * Texture minification filter that chooses the mipmap that most closely matches the size of the pixel being textured - * and returns the nearest texel to the given sample coordinates. - */ -const NearestMipmapNearestFilter = 1004; - -/** - * Texture minification filter that chooses two mipmaps that most closely match the size of the pixel being textured - * and returns the nearest texel to the center of the pixel at the given sample coordinates. - */ -const NearestMipmapLinearFilter = 1005; - -/** - * Texture minification filter that chooses two mipmaps that most closely match the size of the pixel being textured - * and returns the nearest texel to the center of the pixel at the given sample coordinates. - */ -const NearestMipMapLinearFilter = 1005; - -/** - * Texture magnification and minification filter that returns the weighted average of the four nearest texels to the given sample coordinates. - */ -const LinearFilter = 1006; - -/** - * Texture minification filter that chooses the mipmap that most closely matches the size of the pixel being textured and - * returns the weighted average of the four nearest texels to the given sample coordinates. - */ -const LinearMipmapNearestFilter = 1007; - -/** - * Texture minification filter that chooses the mipmap that most closely matches the size of the pixel being textured and - * returns the weighted average of the four nearest texels to the given sample coordinates. - */ -const LinearMipMapNearestFilter = 1007; - -/** - * Texture minification filter that chooses two mipmaps that most closely match the size of the pixel being textured, - * finds within each mipmap the weighted average of the nearest texel to the center of the pixel, then returns the - * weighted average of those two values. - */ -const LinearMipmapLinearFilter = 1008; - -/** - * Texture minification filter that chooses two mipmaps that most closely match the size of the pixel being textured, - * finds within each mipmap the weighted average of the nearest texel to the center of the pixel, then returns the - * weighted average of those two values. - */ -const LinearMipMapLinearFilter = 1008; - -/** - * Unsigned 8-bit integer type. - */ -const UnsignedByteType = 1009; - -/** - * Signed 8-bit integer type. - */ -const ByteType = 1010; - -/** - * Signed 16-bit integer type. - */ -const ShortType = 1011; - -/** - * Unsigned 16-bit integer type. - */ -const UnsignedShortType = 1012; - -/** - * Signed 32-bit integer type. - */ -const IntType = 1013; - -/** - * Unsigned 32-bit integer type. - */ -const UnsignedIntType = 1014; - -/** - * Signed 32-bit floating-point type. - */ -const FloatType = 1015; - -/** - * Signed 16-bit half-precision floating-point type. - */ -const HalfFloatType = 1016; - -/** - * Texture packing mode in which each ````RGBA```` channel is packed into 4 bits, for a combined total of 16 bits. - */ -const UnsignedShort4444Type = 1017; - -/** - * Texture packing mode in which the ````RGB```` channels are each packed into 5 bits, and the ````A```` channel is packed into 1 bit, for a combined total of 16 bits. - */ -const UnsignedShort5551Type = 1018; - -/** - * Unsigned integer type for 24-bit depth texture data. - */ -const UnsignedInt248Type = 1020; - -/** - * Texture sampling mode that discards the ````RGBA```` components and just reads the ````A```` component. - */ -const AlphaFormat = 1021; - -/** - * Texture sampling mode that discards the ````A```` component and reads the ````RGB```` components. - */ -const RGBFormat = 1022; - -/** - * Texture sampling mode that reads the ````RGBA```` components. - */ -const RGBAFormat = 1023; - -/** - * Texture sampling mode that reads each ````RGB```` texture component as a luminance value, converted to a float and clamped - * to ````[0,1]````, while always reading the ````A```` channel as ````1.0````. - */ -const LuminanceFormat = 1024; - -/** - * Texture sampling mode that reads each of the ````RGBA```` texture components as a luminance/alpha value, converted to a float and clamped to ````[0,1]````. - */ -const LuminanceAlphaFormat = 1025; - -/** - * Texture sampling mode that reads each element as a single depth value, converts it to a float and clamps to ````[0,1]````. - */ -const DepthFormat = 1026; - -/** - * Texture sampling mode that - */ -const DepthStencilFormat = 1027; - -/** - * Texture sampling mode that discards the ````GBA```` components and just reads the ````R```` component. - */ -const RedFormat = 1028; - -/** - * Texture sampling mode that discards the ````GBA```` components and just reads the ````R```` component, as an integer instead of as a float. - */ -const RedIntegerFormat = 1029; - -/** - * Texture sampling mode that discards the ````A```` and ````B```` components and just reads the ````R```` and ````G```` components. - */ -const RGFormat = 1030; - -/** - * Texture sampling mode that discards the ````A```` and ````B```` components and just reads the ````R```` and ````G```` components, as integers instead of floats. - */ -const RGIntegerFormat = 1031; - -/** - * Texture sampling mode that reads the ````RGBA```` components as integers instead of floats. - */ -const RGBAIntegerFormat = 1033; - -/** - * Texture format mode in which the texture is formatted as a DXT1 compressed ````RGB```` image. - */ -const RGB_S3TC_DXT1_Format = 33776; - -/** - * Texture format mode in which the texture is formatted as a DXT1 compressed ````RGBA```` image. - */ -const RGBA_S3TC_DXT1_Format = 33777; - -/** - * Texture format mode in which the texture is formatted as a DXT3 compressed ````RGBA```` image. - */ -const RGBA_S3TC_DXT3_Format = 33778; - -/** - * Texture format mode in which the texture is formatted as a DXT5 compressed ````RGBA```` image. - */ -const RGBA_S3TC_DXT5_Format = 33779; - -/** - * Texture format mode in which the texture is formatted as a PVRTC compressed - * image, with ````RGB```` compression in 4-bit mode and one block for each 4×4 pixels. - */ -const RGB_PVRTC_4BPPV1_Format = 35840; - -/** - * Texture format mode in which the texture is formatted as a PVRTC compressed - * image, with ````RGB```` compression in 2-bit mode and one block for each 8×4 pixels. - */ -const RGB_PVRTC_2BPPV1_Format = 35841; - -/** - * Texture format mode in which the texture is formatted as a PVRTC compressed - * image, with ````RGBA```` compression in 4-bit mode and one block for each 4×4 pixels. - */ -const RGBA_PVRTC_4BPPV1_Format = 35842; - -/** - * Texture format mode in which the texture is formatted as a PVRTC compressed - * image, with ````RGBA```` compression in 2-bit mode and one block for each 8×4 pixels. - */ -const RGBA_PVRTC_2BPPV1_Format = 35843; - -/** - * Texture format mode in which the texture is formatted as an ETC1 compressed - * ````RGB```` image. - */ -const RGB_ETC1_Format = 36196; - -/** - * Texture format mode in which the texture is formatted as an ETC2 compressed - * ````RGB```` image. - */ -const RGB_ETC2_Format = 37492; - -/** - * Texture format mode in which the texture is formatted as an ETC2 compressed - * ````RGBA```` image. - */ -const RGBA_ETC2_EAC_Format = 37496; - -/** - * Texture format mode in which the texture is formatted as an ATSC compressed - * ````RGBA```` image. - */ -const RGBA_ASTC_4x4_Format = 37808; - -/** - * Texture format mode in which the texture is formatted as an ATSC compressed - * ````RGBA```` image. - */ -const RGBA_ASTC_5x4_Format = 37809; - -/** - * Texture format mode in which the texture is formatted as an ATSC compressed - * ````RGBA```` image. - */ -const RGBA_ASTC_5x5_Format = 37810; - -/** - * Texture format mode in which the texture is formatted as an ATSC compressed - * ````RGBA```` image. - */ -const RGBA_ASTC_6x5_Format = 37811; - -/** - * Texture format mode in which the texture is formatted as an ATSC compressed - * ````RGBA```` image. - */ -const RGBA_ASTC_6x6_Format = 37812; - -/** - * Texture format mode in which the texture is formatted as an ATSC compressed - * ````RGBA```` image. - */ -const RGBA_ASTC_8x5_Format = 37813; - -/** - * Texture format mode in which the texture is formatted as an ATSC compressed - * ````RGBA```` image. - */ -const RGBA_ASTC_8x6_Format = 37814; - -/** - * Texture format mode in which the texture is formatted as an ATSC compressed - * ````RGBA```` image. - */ -const RGBA_ASTC_8x8_Format = 37815; - -/** - * Texture format mode in which the texture is formatted as an ATSC compressed - * ````RGBA```` image. - */ -const RGBA_ASTC_10x5_Format = 37816; - -/** - * Texture format mode in which the texture is formatted as an ATSC compressed - * ````RGBA```` image. - */ -const RGBA_ASTC_10x6_Format = 37817; - -/** - * Texture format mode in which the texture is formatted as an ATSC compressed - * ````RGBA```` image. - */ -const RGBA_ASTC_10x8_Format = 37818; - -/** - * Texture format mode in which the texture is formatted as an ATSC compressed - * ````RGBA```` image. - */ -const RGBA_ASTC_10x10_Format = 37819; - -/** - * Texture format mode in which the texture is formatted as an ATSC compressed - * ````RGBA```` image. - */ -const RGBA_ASTC_12x10_Format = 37820; - -/** - * Texture format mode in which the texture is formatted as an ATSC compressed - * ````RGBA```` image. - */ -const RGBA_ASTC_12x12_Format = 37821; - -/** - * Texture format mode in which the texture is formatted as an BPTC compressed - * ````RGBA```` image. - */ -const RGBA_BPTC_Format = 36492; - -/** - * Texture encoding mode in which the texture image is in linear color space. - */ -const LinearEncoding = 3000; - -/** - * Texture encoding mode in which the texture image is in sRGB color space. - */ -const sRGBEncoding = 3001; - -/** - * Media type for GIF images. - */ -const GIFMediaType = 10000; - -/** - * Media type for JPEG images. - */ -const JPEGMediaType = 10001; - -/** - * Media type for PNG images. - */ -const PNGMediaType = 10002; - -/** - * Media type for compressed texture data. - */ -const CompressedMediaType = 10003; - -const ids$1 = new Map$1({}); -const tempVec3a$f = math.vec3(); -const tempVec4$3 = math.vec4(); -const TEXTURE_DECODE_FUNCS = { [sRGBEncoding]: "sRGBToLinear" }; - -const iota$4 = function(n) { - const ret = [ ]; - for (let i = 0; i < n; ++i) ret.push(i); - return ret; -}; - -const createProgramVariablesState = function() { - const vertAppenders = [ ]; - const vOutAppenders = [ ]; - const fragAppenders = [ ]; - const fragDefAppenders = [ ]; - const attrSetters = [ ]; - const attrHahes = [ ]; - const unifSetters = [ ]; - const createVertexDefinition = (name, appendDefinition) => { - let needed = false; - vertAppenders.push((src) => needed && appendDefinition(name, src)); - return { - toString: () => { - needed = true; - return name; - } - }; - }; - const programVariables = { - createAttribute: function(type, name) { - let needed = false; - vertAppenders.push((src) => needed && src.push(`in ${type} ${name};`)); - const ret = { - toString: () => { - needed = true; - return name; - } - }; - attrSetters.push((getInputSetter) => { - const setValue = needed && getInputSetter(name); - setValue && attrHahes.push(setValue.attributeHash); - ret.setInputValue = setValue; - return null; - }); - return ret; - }, - createFragmentDefinition: (name, appendDefinition) => { - let needed = false; - fragDefAppenders.push((src) => needed && appendDefinition(name, src)); - return { - toString: () => { - needed = true; - return name; - } - }; - }, - createOutput: (type, name, location) => { - let needed = false; - fragAppenders.push((src) => needed && src.push(`layout(location = ${location || 0}) out ${type} ${name};`)); - return { - toString: () => { - needed = true; - return name; - } - }; - }, - createUniform: (type, name, valueSetter) => { - let needed = false; - const append = (src) => needed && src.push(`uniform ${type} ${name};`); - vertAppenders.push(append); - fragAppenders.push(append); - const ret = { - toString: () => { - needed = true; - return name; - } - }; - unifSetters.push((getInputSetter) => { - const setValue = needed && getInputSetter(name); - if (valueSetter) { - return setValue && ((state) => valueSetter(setValue, state)); - } else { - ret.setInputValue = setValue; - return null; - } - }); - return ret; - }, - createUniformArray: (type, name, length) => { - let needed = false; - const append = (src) => needed && src.push(`uniform ${type} ${name}[${length}];`); - vertAppenders.push(append); - fragAppenders.push(append); - const ret = { - toString: () => { - needed = true; - return name; - } - }; - unifSetters.push((getInputSetter) => { - ret.setInputValue = needed && getInputSetter(name); - return null; - }); - return ret; - }, - createUniformBlock: (name, types, valueSetter) => { - let needed = false; - const keys = Object.keys(types); - const append = (src) => { - if (needed) { - src.push(`uniform ${name} {`); - keys.forEach(k => src.push(` ${types[k]} ${k};`)); - src.push(`};`); - } - }; - vertAppenders.push(append); - fragAppenders.push(append); - const ret = { }; - keys.forEach(k => ret[k] = { - toString: () => { - needed = true; - return k; - } - }); - unifSetters.push((getInputSetter) => { - const setValue = needed && getInputSetter(name); - if (valueSetter) { - return setValue && ((state) => valueSetter(setValue, state)); - } else { - ret.setInputValue = setValue; - return null; - } - }); - return ret; - }, - createVarying: (type, name, genValueCode, interpolationQualifier) => { - let needed = false; - const intp = interpolationQualifier ? (interpolationQualifier + " ") : ""; - vertAppenders.push((src) => needed && src.push(`${intp}out ${type} ${name};`)); - vOutAppenders.push((src) => needed && src.push(`${name} = ${genValueCode()};`)); - fragAppenders.push((src) => needed && src.push(`${intp}in ${type} ${name};`)); - return { - toString: () => { - needed = true; - return name; - } - }; - }, - createVertexDefinition: createVertexDefinition, - commonLibrary: { - octDecode: createVertexDefinition( - "octDecode", - (name, src) => { - src.push(`vec3 ${name}(vec2 oct) {`); - src.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"); - src.push(" if (v.z < 0.0) {"); - src.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);"); - src.push(" }"); - src.push(" return normalize(v);"); - src.push("}"); - }) - } - }; - return { - programVariables: programVariables, - buildProgram: (gl, programName, cfg) => { - const getLogDepth = cfg.getLogDepth; - - const clipPos = cfg.clipPos; - const clipTransformSetup = cfg.usePickClipPos && (function() { - const pickClipPos = programVariables.createUniform("vec2", "pickClipPos"); - const pickClipPosInv = programVariables.createUniform("vec2", "pickClipPosInv"); - return { - setClipPosInputValue: frameCtx => { - pickClipPos.setInputValue(frameCtx.pickClipPos); - pickClipPosInv.setInputValue(frameCtx.pickClipPosInv); - }, - transformedClipPos: () => `vec4((${clipPos}.xy / ${clipPos}.w - ${pickClipPos}) * ${pickClipPosInv} * ${clipPos}.w, ${clipPos}.zw)` - }; - })(); - - const vertexClipPosition = clipTransformSetup ? clipTransformSetup.transformedClipPos() : clipPos; - - const fragmentOutputs = [ ]; - const isPerspective = programVariables.createVarying("float", "isPerspective", () => `(${cfg.projMatrix}[2][3] == -1.0) ? 1.0 : 0.0`); - const logDepthBufFC = programVariables.createUniform("float", "logDepthBufFC", (set, state) => set(2.0 / (Math.log(state.view.far + 1.0) / Math.LN2))); - const vFragDepth = programVariables.createVarying("float", "vFragDepth", () => "1.0 + clipPos.w"); - if (getLogDepth) { - fragmentOutputs.push(`gl_FragDepth = ${cfg.testPerspectiveForGl_FragDepth ? `${isPerspective} == 0.0 ? gl_FragCoord.z : ` : ""}log2(${getLogDepth(vFragDepth)}) * ${logDepthBufFC} * 0.5;`); - } else if (cfg.cleanerEdges) { - fragmentOutputs.push(`gl_FragDepth = gl_FragCoord.z + length(vec2(dFdx(gl_FragCoord.z), dFdy(gl_FragCoord.z)));`); - } - - const linearToGamma = programVariables.createFragmentDefinition( - "linearToGamma", - (name, src) => { - src.push(`vec4 ${name}(in vec4 value, in float gammaFactor) {`); - src.push(" return vec4(pow(value.xyz, vec3(1.0 / gammaFactor)), value.w);"); - src.push("}"); - }); - - const sectionPlanesState = cfg.sectionPlanesState; - const getClippingDistance = sectionPlanesState && (function() { - const allocatedUniforms = iota$4(sectionPlanesState.getNumAllocatedSectionPlanes()).map(i => { - const sectionPlaneUniform = (type, postfix, getValue) => { - return programVariables.createUniform(type, `sectionPlane${postfix}${i}`, (set, state) => { - const sectionPlanes = sectionPlanesState.sectionPlanes; - const numSectionPlanes = sectionPlanes.length; - const baseIndex = (state.mesh.layerIndex || 0) * numSectionPlanes; - const active = (i < numSectionPlanes) && state.mesh.renderFlags.sectionPlanesActivePerLayer[baseIndex + i]; - return getValue(set, active, sectionPlanes[i], state.mesh.origin); - }); - }; - return { - act: sectionPlaneUniform("bool", "Active", (set, active) => set(active ? 1 : 0)), - dir: sectionPlaneUniform("vec3", "Dir", (set, active, plane) => active && set(plane.dir)), - pos: sectionPlaneUniform("vec3", "Pos", (set, active, plane, orig) => { - return active && set(orig - ? math.mulVec3Scalar(math.normalizeVec3(plane.dir, tempVec3a$f), -(math.dotVec3(plane.dir, orig) + plane.dist), tempVec3a$f) // getPlaneRTCPos - : plane.pos); - }) - }; - }); - return (allocatedUniforms.length > 0) && ((worldPosition) => allocatedUniforms.map(a => `(${a.act} ? clamp(dot(-${a.dir}, ${worldPosition} - ${a.pos}), 0.0, 1000.0) : 0.0)`).join(" + ")); - })(); - - const crossSections = cfg.crossSections; - const sliceColorOr = (getClippingDistance - ? (function() { - const sliceColor = programVariables.createUniform("vec4", "sliceColor", (set) => set(crossSections.sliceColor)); - const sliceColorOr = color => { - sliceColorOr.needed = true; - return `(sliced ? ${sliceColor} : ${color})`; - }; - return sliceColorOr; - })() - : (color => color)); - - const getGammaFactor = cfg.getGammaFactor; - const gammaFactor = programVariables.createUniform("float", "gammaFactor", (set) => set(getGammaFactor())); - cfg.appendFragmentOutputs(fragmentOutputs, getGammaFactor && ((color) => `${linearToGamma}(${color}, ${gammaFactor})`), "gl_FragCoord", sliceColorOr); - - const fragmentClippingLines = (function() { - const src = [ ]; - const sliceThickness = programVariables.createUniform("float", "sliceThickness", (set) => set(crossSections.sliceThickness)); - - if (getClippingDistance) { - if (sliceColorOr.needed) { - src.push(" bool sliced = false;"); - } - src.push(` if (${cfg.clippableTest()}) {`); - const fragWorldPosition = programVariables.createVarying("highp vec3", "vHighpWorldPosition", () => `${cfg.worldPositionAttribute}.xyz`); - src.push(` float dist = ${getClippingDistance(fragWorldPosition)};`); - if (cfg.clippingCaps) { - const vClipPositionW = programVariables.createVarying("float", "vClipPositionW", () => "gl_Position.w"); - src.push(` if (dist > (0.002 * ${vClipPositionW})) { discard; }`); - src.push(" if (dist > 0.0) { "); - src.push(` ${cfg.clippingCaps} = vec4(1.0, 0.0, 0.0, 1.0);`); - getLogDepth && src.push(` gl_FragDepth = log2(${getLogDepth(vFragDepth)}) * ${logDepthBufFC} * 0.5;`); - src.push(" return;"); - src.push(" }"); - } else { - src.push(` if (dist > ${sliceColorOr.needed ? sliceThickness : "0.0"}) { discard; }`); - } - if (sliceColorOr.needed) { - src.push(" sliced = dist > 0.0;"); - } - src.push(" }"); - } - - return src; - })(); - - const fragDefinitions = (function() { const src = [ ]; fragDefAppenders.forEach(a => a(src)); return src; })(); - const fragmentShader = [ - ...(function() { const src = [ ]; fragAppenders.forEach(a => a(src)); return src; })(), - ...fragDefinitions, - "void main(void) {", - ...(cfg.discardPoints - ? [ - " vec2 cxy = 2.0 * gl_PointCoord - 1.0;", - " if (dot(cxy, cxy) > 1.0) { discard; }" - ] - : [ ]), - ...fragmentClippingLines, - ...fragmentOutputs, - "}" - ]; - - const vertexOutputs = [ - `gl_Position = ${vertexClipPosition};`, - ...(cfg.getPointSize ? [ `gl_PointSize = ${cfg.getPointSize()};` ] : [ ]), - ...(function() { const src = [ ]; vOutAppenders.forEach(a => a(src)); return src; })() - ]; - - const vertexData = cfg.getVertexData ? cfg.getVertexData() : [ ]; - - const vertexShader = [ - ...(function() { const src = [ ]; vertAppenders.forEach(a => a(src)); return src; })(), - "void main(void) {", - ...vertexData, - ...vertexOutputs, - "}" - ]; - - const preamble = (type) => [ - "#version 300 es", - "// " + programName + " " + type + " shader", - "#ifdef GL_FRAGMENT_PRECISION_HIGH", - "precision highp float;", - "precision highp int;", - "precision highp usampler2D;", - "precision highp isampler2D;", - "precision highp sampler2D;", - "#else", - "precision mediump float;", - "precision mediump int;", - "precision mediump usampler2D;", - "precision mediump isampler2D;", - "precision mediump sampler2D;", - "#endif", - ]; - - const vertSrc = preamble("vertex" ).concat(vertexShader); - const fragSrc = preamble("fragment").concat([ - // Not the best place to define here, TODO: Move somewhere more appropriate after refactors - "vec4 sRGBToLinear(in vec4 value) {", - " return vec4(mix(pow(value.rgb * 0.9478672986 + 0.0521327014, vec3(2.4)), value.rgb * 0.0773993808, vec3(lessThanEqual(value.rgb, vec3(0.04045)))), value.w);", - "}" - ]).concat(fragmentShader); - - const makeShader = (type, srcLines) => { - const src = srcLines.join("\n"); - const shader = gl.createShader(type); - gl.shaderSource(shader, src); - gl.compileShader(shader); - if (gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { - return [ shader ]; - } else { - return [ null, - [ - "Failed to compile", - gl.getShaderInfoLog(shader), - src.split("\n").map((line, i) => (i + 1) + ": " + line + "\n").join("") - ] - ]; - } - }; - - const [vertShader, vertErrors] = makeShader(gl.VERTEX_SHADER, vertSrc); - const [fragShader, fragErrors] = makeShader(gl.FRAGMENT_SHADER, fragSrc); - - const errorObj = errors => { - console.error(errors.join("\n")); - return [ null, errors ]; - }; - - if (vertErrors) { - return errorObj(["Vertex shader error"].concat(vertErrors)); - } else if (fragErrors) { - return errorObj(["Fragment shader error"].concat(fragErrors)); - } else { - const program = gl.createProgram(); - if (! program) { - return errorObj(["Failed to allocate program"]); - } else { - gl.attachShader(program, vertShader); - gl.attachShader(program, fragShader); - gl.linkProgram(program); - // HACK: Disable validation temporarily - // Perhaps we should defer validation until render-time, when the program has values set for all inputs? - if (! gl.getProgramParameter(program, gl.LINK_STATUS)) { - return errorObj([ - "", - gl.getProgramInfoLog(this.program), - "", - "Vertex shader:", - "", - ...vertSrc, - "", - "Fragment shader:", - "", - ...fragSrc - ]); - } else { - const getInputSetter = makeInputSetters(gl, program); - attrSetters.forEach(i => i(getInputSetter)); - const uSetters = unifSetters.map(i => i(getInputSetter)).filter(s => s); - const id = ids$1.addItem({}); - return [ { - id: id, - bind: () => gl.useProgram(program), - inputSetters: { - attributesHash: attrHahes.sort().join(", "), - setUniforms: (frameCtx, state) => { - clipTransformSetup && clipTransformSetup.setClipPosInputValue(frameCtx); - uSetters.forEach(s => s(state)); - } - }, - destroy: () => { - ids$1.removeItem(id); - gl.deleteProgram(program); - gl.deleteShader(vertShader); - gl.deleteShader(fragShader); - } - } ]; - } - } - } - } - }; -}; - -const createLightSetup = function(programVariables, lightsState) { - const lightAmbient = programVariables.createUniform("vec4", "lightAmbient", (set) => set(lightsState.getAmbientColorAndIntensity())); - - const lights = lightsState.lights; - const directionals = lights.map((light, i) => { - const lightUniforms = { - color: programVariables.createUniform("vec4", `lightColor${i}`, (set) => { - const light = lights[i]; // in case it changed - tempVec4$3[0] = light.color[0]; - tempVec4$3[1] = light.color[1]; - tempVec4$3[2] = light.color[2]; - tempVec4$3[3] = light.intensity; - set(tempVec4$3); - }), - position: programVariables.createUniform("vec3", `lightPos${i}`, (set) => set(lights[i].pos)), - direction: programVariables.createUniform("vec3", `lightDir${i}`, (set) => set(lights[i].dir)), - - shadowProjMatrix: programVariables.createUniform("mat4", `shadowProjMatrix${i}`, (set) => set(lights[i].getShadowViewMatrix())), - shadowViewMatrix: programVariables.createUniform("mat4", `shadowViewMatrix${i}`, (set) => set(lights[i].getShadowViewMatrix())), - shadowMap: programVariables.createUniform("sampler2D", `shadowMap${i}`, (set) => set(lights[i].getShadowRenderBuf().colorTextures[0])) - }; - - const withViewLightDir = getDirection => { - return { - glslLight: { - isViewSpace: light.space === "view", - getColor: () => `${lightUniforms.color}.rgb * ${lightUniforms.color}.a`, - getDirection: (viewMatrix, viewPosition) => `normalize(${getDirection(viewMatrix, viewPosition)})`, - shadowParameters: light.castsShadow && { - getShadowProjMatrix: () => lightUniforms.shadowProjMatrix, - getShadowViewMatrix: () => lightUniforms.shadowViewMatrix, - getShadowMap: () => lightUniforms.shadowMap - } - }, - setupLightsInputs: () => { - const setters = Object.values(lightUniforms).map(u => u.setupLightsInputs()).filter(v => v); - return () => setters.forEach(setState => setState()); - } - }; - }; - - if (light.type === "dir") { - if (light.space === "view") { - return withViewLightDir((viewMatrix, viewPosition) => `-${lightUniforms.direction}`); - } else { - // If normal mapping, the fragment->light vector will be in tangent space - return withViewLightDir((viewMatrix, viewPosition) => `-(${viewMatrix} * vec4(${lightUniforms.direction}, 0.0)).xyz`); - } - } else if (light.type === "point") { - if (light.space === "view") { - return withViewLightDir((viewMatrix, viewPosition) => `${lightUniforms.position} - ${viewPosition}`); - } else { - // If normal mapping, the fragment->light vector will be in tangent space - return withViewLightDir((viewMatrix, viewPosition) => `(${viewMatrix} * vec4(${lightUniforms.position}, 1.0)).xyz - ${viewPosition}`); - } - } else { - return null; - } - }).filter(v => v); - - const setupCubeTexture = (name, getMaps) => { - const getValue = () => { const m = getMaps(); return (m.length > 0) && m[0]; }; - const initMap = getValue(); - return initMap && setupTexture(programVariables, "samplerCube", name, initMap.encoding, (set) => { const v = getValue(); v && set(v.texture); }); - }; - - const lightMap = setupCubeTexture("light", () => lightsState.lightMaps); - const reflectionMap = setupCubeTexture("reflection", () => lightsState.reflectionMaps); - - return { - getHash: () => lightsState.getHash(), - getAmbientColor: () => `${lightAmbient}.rgb * ${lightAmbient}.a`, - directionalLights: directionals.map(light => light.glslLight), - getIrradiance: lightMap && ((worldNormal) => `${lightMap(worldNormal)}.rgb`), - getReflection: reflectionMap && ((reflectVec, mipLevel) => `${reflectionMap(reflectVec, mipLevel)}.rgb`) - }; -}; - -const setupTexture = (programVariables, type, name, encoding, getTexture) => { - const map = programVariables.createUniform(type, name + "Map", getTexture); - return (texturePos, bias) => { - const texel = (bias - ? `texture(${map}, ${texturePos}, ${bias})` - : `texture(${map}, ${texturePos})`); - return (encoding !== LinearEncoding) ? `${TEXTURE_DECODE_FUNCS[encoding]}(${texel})` : texel; - }; -}; - -const makeInputSetters = function(gl, handle) { - const activeInputs = { }; - - const numAttributes = gl.getProgramParameter(handle, gl.ACTIVE_ATTRIBUTES); - for (let i = 0; i < numAttributes; ++i) { - const attribute = gl.getActiveAttrib(handle, i); - const location = gl.getAttribLocation(handle, attribute.name); - activeInputs[attribute.name] = function(arrayBuf) { - arrayBuf.bindAtLocation(location); - gl.enableVertexAttribArray(location); - const divisor = arrayBuf.attributeDivisor; - if (divisor) { - gl.vertexAttribDivisor(location, divisor); - } - }; - activeInputs[attribute.name].attributeHash = `${location.toString().padStart(1+Math.floor(Math.log10(numAttributes)), "0")}:${attribute.name}`; - } - - const numBlocks = gl.getProgramParameter(handle, gl.ACTIVE_UNIFORM_BLOCKS); - for (let i = 0; i < numBlocks; ++i) { - const blockName = gl.getActiveUniformBlockName(handle, i); - const uniformBlockIndex = gl.getUniformBlockIndex(handle, blockName); - const uniformBlockBinding = i; - gl.uniformBlockBinding(handle, uniformBlockIndex, uniformBlockBinding); - const buffer = gl.createBuffer(); - activeInputs[blockName] = function(data) { - gl.bindBuffer(gl.UNIFORM_BUFFER, buffer); - gl.bufferData(gl.UNIFORM_BUFFER, data, gl.DYNAMIC_DRAW); - gl.bindBufferBase(gl.UNIFORM_BUFFER, uniformBlockBinding, buffer); - }; - } - - const numUniforms = gl.getProgramParameter(handle, gl.ACTIVE_UNIFORMS); - let nextUnit = 0; - for (let i = 0; i < numUniforms; ++i) { - const u = gl.getActiveUniform(handle, i); - let uName = u.name; - if (uName.endsWith("[0]")) { - uName = uName.substr(0, uName.length - 3); - } - if (uName[uName.length - 1] === "\u0000") { - uName = uName.substr(0, uName.length - 1); - } - const location = gl.getUniformLocation(handle, uName); - ((function() { - for (let k in gl) { - if (u.type === gl[k]) - return k; - } - return null; - }))(); - - if ((u.type === gl.SAMPLER_2D) - || - (u.type === gl.SAMPLER_CUBE) - || - (u.type === gl.SAMPLER_2D_SHADOW) - || - ((gl instanceof window.WebGL2RenderingContext) - && - ((u.type === gl.UNSIGNED_INT_SAMPLER_2D) - || - (u.type === gl.INT_SAMPLER_2D)))) { - const unit = nextUnit++; - activeInputs[uName] = function(texture) { - const bound = texture.bind(unit); - if (bound) { - gl.uniform1i(location, unit); - } - return bound; - }; - } else { - activeInputs[uName] = (function() { - if (u.size === 1) { - switch (u.type) { - case gl.BOOL: return value => gl.uniform1i(location, value); - case gl.INT: return value => gl.uniform1i(location, value); - case gl.FLOAT: return value => gl.uniform1f(location, value); - case gl.FLOAT_VEC2: return value => gl.uniform2fv(location, value); - case gl.FLOAT_VEC3: return value => gl.uniform3fv(location, value); - case gl.FLOAT_VEC4: return value => gl.uniform4fv(location, value); - case gl.FLOAT_MAT3: return value => gl.uniformMatrix3fv(location, false, value); - case gl.FLOAT_MAT4: return value => gl.uniformMatrix4fv(location, false, value); - } - } else if (u.size > 1) { - switch (u.type) { - case gl.FLOAT: return value => gl.uniform1fv(location, value); - case gl.FLOAT_VEC2: return value => gl.uniform2fv(location, value); - case gl.FLOAT_VEC3: return value => gl.uniform3fv(location, value); - case gl.FLOAT_VEC4: return value => gl.uniform4fv(location, value); - } - } - throw `Unhandled uniform ${uName}`; - })(); - } - } - - return function(name) { - const u = activeInputs[name]; - if (! u) { - throw `Missing input "${name}"`; - } - return u; - }; -}; - -const tempVec4$2 = math.vec4(); - -const DrawShaderSource = function(meshDrawHash, programVariables, geometry, material, scene) { - const materialState = material._state; - const phongMaterial = (materialState.type === "PhongMaterial"); - const metallicMaterial = (materialState.type === "MetallicMaterial"); - const specularMaterial = (materialState.type === "SpecularMaterial"); - - const attributes = geometry.attributes; - const lightSetup = createLightSetup(programVariables, scene._lightsState); - - const colorize = programVariables.createUniform("vec4", "colorize", (set, state) => set(state.meshColorize)); - - const fresnel = programVariables.createFragmentDefinition( - "fresnel", - (name, src) => { - src.push(`float ${name}(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {`); - src.push(" float fr = abs(dot(eyeDir, normal));"); - src.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"); - src.push(" return pow(finalFr, power);"); - src.push("}"); - }); - - const setupFresnel = (name, colorSwizzle, getMaterialValue) => { - const fresnelUniform = (type, namePostfix, getParameterValue) => { - return programVariables.createUniform(type, name + "Fresnel" + namePostfix, (set, state) => set(getParameterValue(getMaterialValue(state.material)))); - }; - const edgeBias = fresnelUniform("float", "EdgeBias", (fresnelValue => fresnelValue.edgeBias)); - const centerBias = fresnelUniform("float", "CenterBias", (fresnelValue => fresnelValue.centerBias)); - const power = fresnelUniform("float", "Power", (fresnelValue => fresnelValue.power)); - const edgeColor = fresnelUniform("vec3", "EdgeColor", (fresnelValue => fresnelValue.edgeColor)); - const centerColor = fresnelUniform("vec3", "CenterColor", (fresnelValue => fresnelValue.centerColor)); - - return getMaterialValue(material) && ((viewEyeDir, viewNormal) => { - const f = `${fresnel}(${viewEyeDir}, ${viewNormal}, ${edgeBias}, ${centerBias}, ${power})`; - return `mix(${edgeColor + colorSwizzle}, ${centerColor + colorSwizzle}, ${f})`; - }); - }; - - const diffuseFresnel = setupFresnel("diffuse", "", mtl => mtl._diffuseFresnel); - const specularFresnel = setupFresnel("specular", "", mtl => mtl._specularFresnel); - const emissiveFresnel = setupFresnel("emissive", "", mtl => mtl._emissiveFresnel); - const alphaFresnel = setupFresnel("alpha", ".r", mtl => mtl._alphaFresnel); - - - const setup2dTexture = (name, getMaterialValue) => { - const initTex = attributes.uv && getMaterialValue(material); - const tex = initTex && setupTexture(programVariables, "sampler2D", name, initTex.encoding, (set, state) => set(getMaterialValue(state.material)._state.texture)); - return tex && (function() { - const matrix = initTex._state.matrix && programVariables.createUniform("mat4", name + "MapMatrix", (set, state) => set(getMaterialValue(state.material)._state.matrix)); - const getTexCoordExpression = matrix ? (texPos => `(${matrix} * ${texPos}).st`) : (texPos => `${texPos}.st`); - const sample = (texturePos, bias) => tex(getTexCoordExpression(texturePos)); - sample.getTexCoordExpression = getTexCoordExpression; - return sample; - })(); - }; - - const ambientMap = setup2dTexture("ambient", mtl => mtl._ambientMap); - const baseColorMap = setup2dTexture("baseColor", mtl => mtl._baseColorMap); - const diffuseMap = setup2dTexture("diffuse", mtl => mtl._diffuseMap); - const emissiveMap = setup2dTexture("emissive", mtl => mtl._emissiveMap); - const occlusionMap = setup2dTexture("occlusion", mtl => mtl._occlusionMap); - const alphaMap = setup2dTexture("alpha", mtl => mtl._alphaMap); - const metallicMap = setup2dTexture("metallic", mtl => mtl._metallicMap); - const roughnessMap = setup2dTexture("roughness", mtl => mtl._roughnessMap); - const metallicRoughnessMap = setup2dTexture("metallicRoughness", mtl => mtl._metallicRoughnessMap); - const specularMap = setup2dTexture("specular", mtl => mtl._specularMap); - const glossinessMap = setup2dTexture("glossiness", mtl => mtl._glossinessMap); - const specularGlossinessMap = setup2dTexture("specularGlossiness", mtl => mtl._specularGlossinessMap); - const normalMap = setup2dTexture("normal", mtl => mtl._normalMap); - - - const setupUniform = (name, type, getMaterialValue) => { - const initValue = getMaterialValue(material); - const isDefined = (type === "float") ? ((initValue !== undefined) && (initValue !== null)) : initValue; - return isDefined && programVariables.createUniform(type, name, (set, state) => set(getMaterialValue(state.material))); - }; - - const materialAmbient = setupUniform("materialAmbient", "vec3", mtl => mtl.ambient); - const materialDiffuse = setupUniform("materialDiffuse", "vec3", mtl => mtl.diffuse); - const materialBaseColor = setupUniform("materialBaseColor", "vec3", mtl => mtl.baseColor); - const materialEmissive = setupUniform("materialEmissive", "vec3", mtl => mtl.emissive); - const materialSpecular = setupUniform("materialSpecular", "vec3", mtl => mtl.specular); - const materialGlossiness = setupUniform("materialGlossiness", "float", mtl => mtl.glossiness); - const materialMetallic = setupUniform("materialMetallic", "float", mtl => mtl.metallic); - const materialRoughness = setupUniform("materialRoughness", "float", mtl => mtl.roughness); - const materialShininess = setupUniform("materialShininess", "float", mtl => mtl.shininess); - const materialSpecularF0 = setupUniform("materialSpecularF0", "float", mtl => mtl.specularF0); - const materialAlphaModeCutoff = setupUniform("materialAlphaModeCutoff", "vec4", mtl => { - const alpha = mtl.alpha; - if ((alpha !== undefined) && (alpha !== null)) { - tempVec4$2[0] = alpha; - tempVec4$2[1] = (mtl.alphaMode === 1 ? 1 : 0); - tempVec4$2[2] = mtl.alphaCutoff; - return tempVec4$2; - } else { - return null; - } - }); - - const vViewPosition = programVariables.createVarying("vec3", "vViewPosition", () => `${attributes.position.view}.xyz`); - const texturePos = programVariables.createVarying("vec4", "texturePos", () => `vec4(${attributes.uv}, 1.0, 1.0)`); - const vColor = attributes.color && programVariables.createVarying("vec4", "vColor", () => attributes.color); - - const vViewNormal = programVariables.createVarying("vec3", "vViewNormal", () => attributes.normal.view); - const texUnitConverter = `mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0)`; - const vDirectionals = lightSetup.directionalLights.map((light, i) => ({ - vViewLightReverseDir: programVariables.createVarying("vec3", `vViewLightReverseDir${i}`, () => light.getDirection(geometry.viewMatrix, null)), - vShadowPosFromLight: programVariables.createVarying("vec3", `vShadowPosFromLight${i}`, () => `(${texUnitConverter} * ${light.shadowParameters.getShadowProjMatrix()} * (${light.shadowParameters.getShadowViewMatrix()} * ${attributes.position.world})).xyz`) - })); - const vWorldNormal = programVariables.createVarying("vec3", "vWorldNormal", () => attributes.normal.world); - - const outColor = programVariables.createOutput("vec4", "outColor"); - - const saturate = programVariables.createFragmentDefinition( - "saturate", - (name, src) => src.push(`float ${name}(const in float a) { return clamp(a, 0.0, 1.0); }`)); - - const BRDF_Specular_GGX = programVariables.createFragmentDefinition( - "BRDF_Specular_GGX", - (name, src) => { - src.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"); - src.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"); - src.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"); - src.push("}"); - - src.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"); - src.push(" float a2 = ( alpha * alpha );"); - src.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"); - src.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"); - src.push(" return 1.0 / ( gl * gv );"); - src.push("}"); - - src.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"); - src.push(" float a2 = ( alpha * alpha );"); - src.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"); - src.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"); - src.push(" return 0.5 / max( gv + gl, 1e-6 );"); - src.push("}"); - - src.push("float D_GGX(const in float alpha, const in float dotNH) {"); - src.push(" float a2 = ( alpha * alpha );"); - src.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"); - src.push(" return 0.31830988618 * a2 / ( denom * denom);"); // 1/PI - src.push("}"); - - src.push(`vec3 ${name}(const in vec3 incidentLightDirection, const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`); - src.push(" float alpha = ( roughness * roughness );"); - src.push(" vec3 halfDir = normalize( incidentLightDirection + viewEyeDir );"); - src.push(` float dotNL = ${saturate}( dot( viewNormal, incidentLightDirection ) );`); - src.push(` float dotNV = ${saturate}( dot( viewNormal, viewEyeDir ) );`); - src.push(` float dotNH = ${saturate}( dot( viewNormal, halfDir ) );`); - src.push(` float dotLH = ${saturate}( dot( incidentLightDirection, halfDir ) );`); - src.push(" vec3 F = F_Schlick( specularColor, dotLH );"); - src.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"); - src.push(" float D = D_GGX( alpha, dotNH );"); - src.push(" return F * (G * D);"); - src.push("}"); - }); - - const BRDF_Specular_GGX_Environment = programVariables.createFragmentDefinition( - "BRDF_Specular_GGX_Environment", - (name, src) => { - src.push(`vec3 ${name}(const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`); - src.push(` float dotNV = ${saturate}(dot(viewNormal, viewEyeDir));`); - src.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"); - src.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"); - src.push(" vec4 r = roughness * c0 + c1;"); - src.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"); - src.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"); - src.push(" return specularColor * AB.x + AB.y;"); - src.push("}"); - }); - - const perturbNormal2Arb = programVariables.createFragmentDefinition( - "perturbNormal2Arb", - (name, src) => { - src.push(`vec3 ${name}( vec3 eye_pos, vec3 surf_norm, vec2 uv, vec4 texel ) {`); - src.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"); - src.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"); - src.push(" vec2 st0 = dFdx( uv.st );"); - src.push(" vec2 st1 = dFdy( uv.st );"); - src.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"); - src.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"); - src.push(" vec3 N = normalize( surf_norm );"); - src.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"); - src.push(" mat3 tsn = mat3( S, T, N );"); - // src.push(" mapN *= 3.0;"); - src.push(" return normalize( tsn * mapN );"); - src.push("}"); - }); - - return { - getHash: () => [ - meshDrawHash, - scene.gammaOutput ? "go" : "", - lightSetup.getHash(), - material._state.hash - ], - programName: "Draw", - canActAsBackground: true, - discardPoints: true, - setupPointSize: true, - setsLineWidth: true, - appendFragmentOutputs: (src, getGammaOutputExpression, gl_FragCoord) => { - const hasNonAmbientLighting = attributes.normal && ((lightSetup.directionalLights.length > 0) || lightSetup.getIrradiance || lightSetup.getReflection); - src.push(`vec3 diffuseColor = ${(hasNonAmbientLighting && (phongMaterial || specularMaterial) && materialDiffuse) || (metallicMaterial && materialBaseColor) || "vec3(1.0)"};`); - src.push(`vec4 alphaModeCutoff = ${((phongMaterial || metallicMaterial || specularMaterial) && materialAlphaModeCutoff) || "vec4(1.0, 0.0, 0.0, 0.0)"};`); - src.push("float alpha = alphaModeCutoff[0];"); - (phongMaterial || metallicMaterial || specularMaterial) && alphaMap && src.push(`alpha *= ${alphaMap(texturePos)}.r;`); - - if (vColor) { - src.push(`diffuseColor *= ${vColor}.rgb;`); - src.push(`alpha *= ${vColor}.a;`); - } - if (metallicMaterial && baseColorMap) { - src.push("vec4 baseColorTexel = " + baseColorMap(texturePos) + ";"); - src.push("diffuseColor *= baseColorTexel.rgb;"); - src.push("alpha *= baseColorTexel.a;"); - } - if ((phongMaterial || specularMaterial) && diffuseMap) { - src.push("vec4 diffuseTexel = " + diffuseMap(texturePos) + ";"); - src.push("diffuseColor *= diffuseTexel.rgb;"); - src.push("alpha *= diffuseTexel.a;"); - } - - src.push(`vec3 emissiveColor = ${((phongMaterial || metallicMaterial || specularMaterial) && materialEmissive) || "vec3(0.0)"};`); - (phongMaterial || metallicMaterial || specularMaterial) && emissiveMap && src.push(`emissiveColor = ${emissiveMap(texturePos)}.rgb;`); - - if (hasNonAmbientLighting) { - - src.push(`vec3 specular = ${((phongMaterial || specularMaterial) && materialSpecular) || "vec3(1.0)"};`); - src.push(`float glossiness = ${(specularMaterial && materialGlossiness) || "1.0"};`); - src.push(`float metallic = ${(metallicMaterial && materialMetallic) || "1.0"};`); - src.push(`float roughness = ${((metallicMaterial || specularMaterial) && materialRoughness) || "1.0"};`); - src.push(`float shininess = ${(phongMaterial && materialShininess)|| "1.0"};`); - src.push(`float specularF0 = ${(metallicMaterial && materialSpecularF0) || "1.0"};`); - src.push(`float occlusion = ${((phongMaterial || metallicMaterial || specularMaterial) && occlusionMap) ? `${occlusionMap(texturePos)}.r` : "1.0"};`); - - //-------------------------------------------------------------------------------- - // SHADING - //-------------------------------------------------------------------------------- - - metallicMaterial && metallicMap && src.push(`metallic *= ${metallicMap(texturePos)}.r;`); - metallicMaterial && roughnessMap && src.push(`roughness *= ${roughnessMap(texturePos)}.r;`); - - if (metallicMaterial && metallicRoughnessMap) { - src.push("vec4 metalRoughTexel = " + metallicRoughnessMap(texturePos) + ";"); - src.push("metallic *= metalRoughTexel.b;"); - src.push("roughness *= metalRoughTexel.g;"); - } - - (phongMaterial || specularMaterial) && specularMap && src.push(`specular *= ${specularMap(texturePos)}.rgb;`); - specularMaterial && glossinessMap && src.push(`glossiness *= ${glossinessMap(texturePos)}.r;`); - - if (specularMaterial && specularGlossinessMap) { - src.push("vec4 specGlossTexel = " + specularGlossinessMap(texturePos) + ";"); // TODO: what if only RGB texture? - src.push("specular *= specGlossTexel.rgb;"); - src.push("glossiness *= specGlossTexel.a;"); - } - - const vViewNormalized = `normalize(${vViewNormal})`; - const viewNormal = (((phongMaterial || metallicMaterial || specularMaterial) && normalMap) - ? `${perturbNormal2Arb}(${vViewPosition}, ${vViewNormalized}, ${normalMap.getTexCoordExpression(texturePos)}, ${normalMap(texturePos)})` - : vViewNormalized); - src.push(`vec3 viewNormal = ${viewNormal};`); - - src.push(`vec3 viewEyeDir = normalize(-${vViewPosition});`); - - diffuseFresnel && src.push(`diffuseColor *= ${diffuseFresnel ("viewEyeDir", "viewNormal")};`); - specularFresnel && src.push(`specular *= ${specularFresnel("viewEyeDir", "viewNormal")};`); - emissiveFresnel && src.push(`emissiveColor *= ${emissiveFresnel("viewEyeDir", "viewNormal")};`); - alphaFresnel && src.push(`alpha *= ${alphaFresnel ("viewEyeDir", "viewNormal")};`); - - src.push("if (alphaModeCutoff[1] == 1.0 && alpha < alphaModeCutoff[2]) {"); // ie. (alphaMode == "mask" && alpha < alphaCutoff) - src.push(" discard;"); // TODO: Discard earlier within this shader? - src.push("}"); - - src.push("vec3 material_diffuseColor;"); - - if (phongMaterial) { - src.push("material_diffuseColor = diffuseColor;"); - src.push("roughness = 0.0;"); - } - - if (specularMaterial) { - src.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"); // Energy conservation - src.push("material_diffuseColor = diffuseColor * oneMinusSpecularStrength;"); - src.push("roughness = clamp(1.0 - glossiness, 0.04, 1.0);"); - } - - if (metallicMaterial) { - src.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"); - src.push("material_diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"); - src.push("roughness = clamp(roughness, 0.04, 1.0);"); - src.push("specular = mix(vec3(dielectricSpecular), diffuseColor, metallic);"); - } - - // ENVIRONMENT AND REFLECTION MAP SHADING - - if (phongMaterial || metallicMaterial || specularMaterial) { - src.push("const float PI = 3.14159265359;"); - src.push("vec3 reflDiff = vec3(0.0);"); - src.push("vec3 reflSpec = vec3(0.0);"); - - lightSetup.getIrradiance && src.push(`reflDiff += ${lightSetup.getIrradiance(`normalize(${vWorldNormal})`)};`); - - if (lightSetup.getReflection) { - const reflectVec = `reflect(-viewEyeDir, viewNormal)`; - const spec = (phongMaterial - ? `0.2 * PI * ${lightSetup.getReflection(reflectVec)}` - : (function() { - const blinnExpFromRoughness = `2.0 / pow(roughness + 0.0001, 2.0) - 2.0`; - const specularBRDFContrib = `${BRDF_Specular_GGX_Environment}(viewNormal, viewEyeDir, specular, roughness)`; - - const viewReflectVec = `normalize((vec4(${reflectVec}, 0.0) * ${geometry.viewMatrix}).xyz)`; - const maxMIPLevelScalar = "4.0"; - const desiredMIPLevel = `${maxMIPLevelScalar} - 0.39624 - 0.25 * log2(pow(${blinnExpFromRoughness}, 2.0) + 1.0)`; - const mipLevel = `clamp(${desiredMIPLevel}, 0.0, ${maxMIPLevelScalar})`; //TODO: a random factor - fix this - return `${specularBRDFContrib} * ${lightSetup.getReflection(viewReflectVec, mipLevel)}`; - })()); - src.push(`reflSpec += ${spec};`); - } - if (lightSetup.directionalLights.some(ligth => ligth.shadowParameters)) { - src.push("const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0 * 256.0), 1.0/(256.0*256.0*256.0));"); - src.push("const float texelSize = 1.0 / 1024.0;"); - src.push("float shadow;"); - src.push("float fragmentDepth;"); - } - lightSetup.directionalLights.forEach((light, i) => { - if (light.shadowParameters) { - const shadowAcneRemover = "0.007"; - src.push(`fragmentDepth = ${vDirectionals[i].vShadowPosFromLight}.z - ${shadowAcneRemover};`); - src.push("shadow = 0.0;"); - src.push("for (int x = -3; x <= 3; x++) {"); - src.push(" for (int y = -3; y <= 3; y++) {"); - src.push(` float texelDepth = dot(texture(${light.getShadowMap()}, ${vDirectionals[i].vShadowPosFromLight}.xy + vec2(x, y) * texelSize), bitShift);`); - src.push(` if (fragmentDepth < texelDepth) {`); - src.push(" shadow += 1.0;"); - src.push(" }"); - src.push(" }"); - src.push("}"); - src.push("shadow /= 9.0;"); - } - src.push(`vec3 lightColor${i} = ${light.getColor()}${light.shadowParameters ? (" * " + "shadow") : ""};`); - src.push(`vec3 lightDirection${i} = ${light.isViewSpace ? light.getDirection(null, vViewPosition) : vDirectionals[i].vViewLightReverseDir};`); - const dotNL = `${saturate}(dot(viewNormal, lightDirection${i}))`; - src.push(`vec3 irradiance${i} = ${dotNL} * lightColor${i};`); - src.push(`reflDiff += irradiance${i};`); - const spec = (phongMaterial - ? `lightColor${i} * specular * pow(max(dot(reflect(-lightDirection${i}, -viewNormal), viewEyeDir), 0.0), shininess)` - : `irradiance${i} * PI * ${BRDF_Specular_GGX}(lightDirection${i}, viewNormal, viewEyeDir, specular, roughness)`); - src.push(`reflSpec += ${spec};`); - }); - } - - const ambient = phongMaterial && `${lightSetup.getAmbientColor()} * diffuseColor`; - src.push("vec3 outgoingLight = emissiveColor + occlusion * (reflDiff * material_diffuseColor + reflSpec)" + (ambient ? (" + " + ambient) : "") + ";"); - } else { - src.push(`vec3 ambientColor = ${(phongMaterial && materialAmbient) || "vec3(1.0)"};`); - phongMaterial && ambientMap && src.push(`ambientColor *= ${ambientMap(texturePos)}.rgb;`); - src.push(`ambientColor *= ${lightSetup.getAmbientColor()};`); - src.push("vec3 outgoingLight = emissiveColor + ambientColor;"); - } - - src.push(`vec4 fragColor = ${colorize} * vec4(outgoingLight, alpha);`); - - src.push(`${outColor} = ${getGammaOutputExpression ? getGammaOutputExpression("fragColor") : "fragColor"};`); - } - }; -}; - -const LambertShaderSource = function(meshDrawHash, programVariables, geometry, material, scene) { - const lightSetup = createLightSetup(programVariables, scene._lightsState); - const colorize = programVariables.createUniform("vec4", "colorize", (set, state) => set(state.meshColorize)); - const materialAlpha = programVariables.createUniform("float", "materialAlpha", (set, state) => set(state.material.alpha)); - const materialColor = programVariables.createUniform("vec3", "materialColor", (set, state) => set(state.material.color)); - const materialEmissive = programVariables.createUniform("vec3", "materialEmissive", (set, state) => set(state.material.emissive)); - const vColor = programVariables.createVarying("vec4", "vColor", () => { - const attributes = geometry.attributes; - const lightComponents = [ - lightSetup.getAmbientColor() - ].concat(attributes.normal - ? lightSetup.directionalLights.map( - light => `(max(dot(${attributes.normal.view}, ${light.getDirection(geometry.viewMatrix, attributes.position.view)}), 0.0) * ${light.getColor()})`) - : [ ]); - return `${colorize} * vec4((${lightComponents.join(" + ")}) * ${materialColor} + ${materialEmissive}, ${materialAlpha});`; // TODO: How to have ambient bright enough for canvas BG but not too bright for scene? - }); - const outColor = programVariables.createOutput("vec4", "outColor"); - - return { - getHash: () => [ - meshDrawHash, - scene.gammaOutput ? "go" : "", - lightSetup.getHash(), - material._state.hash - ], - programName: "Lambert", - canActAsBackground: true, - discardPoints: true, - setupPointSize: true, - setsLineWidth: true, - appendFragmentOutputs: (src, getGammaOutputExpression) => src.push(`${outColor} = ${getGammaOutputExpression ? getGammaOutputExpression(vColor) : vColor};`) - }; -}; - -const EmphasisShaderSource = function(meshHash, programVariables, geometry, scene, isFill) { - const lightSetup = isFill && createLightSetup(programVariables, scene._lightsState); - const uColor = programVariables.createUniform("vec3", "uColor", (set, state) => set(isFill ? state.material.fillColor : state.material.edgeColor)); - const uAlpha = programVariables.createUniform("float", "uAlpha", (set, state) => set(isFill ? state.material.fillAlpha : state.material.edgeAlpha)); - const vColor = programVariables.createVarying("vec4", "vColor", () => { - const attributes = geometry.attributes; - const lightComponents = isFill && [ - lightSetup.getAmbientColor() - ].concat(attributes.normal - ? lightSetup.directionalLights.map( - light => `(max(dot(${attributes.normal.view}, ${light.getDirection(geometry.viewMatrix, attributes.position.view)}), 0.0) * ${light.getColor()})`) - : [ ]); - // TODO: A blending mode for emphasis materials, to select add/multiply/mix - // `vec4((mix(reflectedColor, ${uColor}, 0.7)), ${uAlpha})` - return `vec4(${uColor}${lightComponents ? ` * (${lightComponents.join(" + ")})` : ""}, ${uAlpha})`; - // `${vColor} = vec4(reflectedColor + ${uColor}, ${uAlpha})` - }); - - const outColor = programVariables.createOutput("vec4", "outColor"); - return { - getHash: () => [ - meshHash, - scene.gammaOutput ? "go" : "", // Gamma input not needed - lightSetup && lightSetup.getHash() - ], - programName: isFill ? "EmphasisFill" : "EmphasisEdges", - dontSetFrontFace: true, - discardPoints: isFill, - drawEdges: ! isFill, - appendFragmentOutputs: (src, getGammaOutputExpression) => src.push(`${outColor} = ${getGammaOutputExpression ? getGammaOutputExpression(vColor) : vColor};`) - }; -}; - -const tmpVec4 = math.vec4(); - -const PickMeshShaderSource = function(meshHash, programVariables) { - const pickColor = programVariables.createUniform("vec4", "pickColor", (set, state) => { - var pickID = state.meshPickID; // Mesh-indexed color - tmpVec4[0] = pickID & 0xFF; - tmpVec4[1] = pickID >> 8 & 0xFF; - tmpVec4[2] = pickID >> 16 & 0xFF; - tmpVec4[3] = pickID >> 24 & 0xFF; - math.mulVec4Scalar(tmpVec4, 1 / 255, tmpVec4); - set(tmpVec4); - }); - const outColor = programVariables.createOutput("vec4", "outColor"); - return { - getHash: () => [ meshHash ], - programName: "PickMesh", - isPick: true, - appendFragmentOutputs: (src) => src.push(`${outColor} = ${pickColor};`) - }; -}; - -const PickTriangleShaderSource = function(meshHash, programVariables, geometry) { - const vColor = programVariables.createVarying("vec4", "vColor", () => geometry.attributes.pickColor); - const outColor = programVariables.createOutput("vec4", "outColor"); - return { - getHash: () => [ meshHash ], - programName: "PickTriangle", - isPick: true, - trianglePick: true, - appendFragmentOutputs: (src) => src.push(`${outColor} = ${vColor};`) - }; -}; - -const OcclusionShaderSource = function(meshPickOcclusionHash, programVariables) { - const outColor = programVariables.createOutput("vec4", "outColor"); - return { - getHash: () => [ meshPickOcclusionHash ], - programName: "Occlusion", - skipIfTransparent: true, - appendFragmentOutputs: (src) => src.push(`${outColor} = vec4(0.0, 0.0, 1.0, 1.0);`) - }; -}; - -const ShadowShaderSource = function(meshHash, programVariables) { - const encodeFloat = programVariables.createFragmentDefinition( - "encodeFloat", - (name, src) => { - src.push(`vec4 ${name}( const in float depth ) {`); - src.push(" const vec4 bitShift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);"); - src.push(" const vec4 bitMask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);"); - src.push(" vec4 comp = fract(depth * bitShift);"); - src.push(" comp -= comp.xxyz * bitMask;"); - src.push(" return comp;"); - src.push("}"); - }); - const outColor = programVariables.createOutput("vec4", "outColor"); - return { - getHash: () => [ meshHash ], - programName: "Shadow", - setsLineWidth: true, - useShadowView: true, - dontGetLogDepth: true, - appendFragmentOutputs: (src, getGammaOutputExpression, gl_FragCoord) => src.push(`${outColor} = ${encodeFloat}(${gl_FragCoord}.z);`) - }; -}; - -/** - * Indicates what rendering needs to be done for the layers within a {@link Drawable}. - * - * Each Drawable has a RenderFlags in {@link Drawable#renderFlags}. - * - * Before rendering each frame, {@link Renderer} will call {@link Drawable#rebuildRenderFlags} on each {@link Drawable}. - * - * Then, when rendering a frame, Renderer will apply rendering passes to each Drawable according on what flags are set in {@link Drawable#renderFlags}. - * - * @private - */ -class RenderFlags { - - /** - * @private - */ - constructor() { - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate which layers are visible within the {@link Drawable}. - * - * This is a list of IDs of visible layers within the {@link Drawable}. The IDs will be whatever the - * {@link Drawable} uses to identify its layers, usually integers. - * - * @property visibleLayers - * @type {Number[]} - */ - this.visibleLayers = []; - - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate which {@link SectionPlane}s are active within each layer of the {@link Drawable}. - * - * Layout is as follows: - * - * ````[ - * false, false, true, // Layer 0, SectionPlanes 0, 1, 2 - * false, true, true, // Layer 1, SectionPlanes 0, 1, 2 - * true, false, true // Layer 2, SectionPlanes 0, 1, 2 - * ]```` - * - * @property sectionPlanesActivePerLayer - * @type {Boolean[]} - */ - this.sectionPlanesActivePerLayer = []; - - this.reset(); - } - - /** - * @private - */ - reset() { - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate whether the {@link Drawable} is culled. - * - * When this is ````false````, then all of the other properties on ````RenderFlags```` will remain at their default values. - * - * @property culled - * @type {Boolean} - */ - this.culled = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate whether the {@link Drawable} is sliced by any {@link SectionPlane}s. - * - * @property sectioned - * @type {Boolean} - */ - this.sectioned = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the number of layers within the {@link Drawable}. - * - * @property numLayers - * @type {Number} - */ - this.numLayers = 0; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the number of visible layers within the {@link Drawable}. - * - * @property numVisibleLayers - * @type {Number} - */ - this.numVisibleLayers = 0; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs {@link Drawable#drawColorOpaque}. - * @property colorOpaque - * @type {boolean} - */ - this.colorOpaque = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs {@link Drawable#drawColorTransparent}. - * @property colorTransparent - * @type {boolean} - */ - this.colorTransparent = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs {@link Drawable#drawEdgesColorOpaque}. - * @property edgesOpaque - * @type {boolean} - */ - this.edgesOpaque = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs {@link Drawable#drawEdgesColorTransparent}. - * @property edgesTransparent - * @type {boolean} - */ - this.edgesTransparent = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs an opaque {@link Drawable#drawSilhouetteXRayed}. - * @property xrayedSilhouetteOpaque - * @type {boolean} - */ - this.xrayedSilhouetteOpaque = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs an opaque {@link Drawable#drawEdgesXRayed}. - * @property xrayedEdgesOpaque - * @type {boolean} - */ - this.xrayedEdgesOpaque = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs a transparent {@link Drawable#drawSilhouetteXRayed}. - * @property xrayedSilhouetteTransparent - * @type {boolean} - */ - this.xrayedSilhouetteTransparent = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs a transparent {@link Drawable#drawEdgesXRayed}. - * @property xrayedEdgesTransparent - * @type {boolean} - */ - this.xrayedEdgesTransparent = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs an opaque {@link Drawable#drawSilhouetteHighlighted}. - * @property highlightedSilhouetteOpaque - * @type {boolean} - */ - this.highlightedSilhouetteOpaque = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs an opaque {@link Drawable#drawEdgesHighlighted}. - * @property highlightedEdgesOpaque - * @type {boolean} - */ - this.highlightedEdgesOpaque = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs a transparent {@link Drawable#drawSilhouetteHighlighted}. - * @property highlightedSilhouetteTransparent - * @type {boolean} - */ - this.highlightedSilhouetteTransparent = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs a transparent {@link Drawable#drawEdgesHighlighted}. - * @property highlightedEdgesTransparent - * @type {boolean} - */ - this.highlightedEdgesTransparent = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs an opaque {@link Drawable#drawSilhouetteSelected}. - * @property selectedSilhouetteOpaque - * @type {boolean} - */ - this.selectedSilhouetteOpaque = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs an opaque {@link Drawable#drawEdgesSelected}. - * @property selectedEdgesOpaque - * @type {boolean} - */ - this.selectedEdgesOpaque = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs a transparent {@link Drawable#drawSilhouetteSelected}. - * @property selectedSilhouetteTransparent - * @type {boolean} - */ - this.selectedSilhouetteTransparent = false; - - /** - * Set by {@link Drawable#rebuildRenderFlags} to indicate the {@link Drawable} needs a transparent {@link Drawable#drawEdgesSelected}. - * @property selectedEdgesTransparent - * @type {boolean} - */ - this.selectedEdgesTransparent = false; - } -} - -/** - Fired when this Mesh is picked via a call to {@link Scene/pick:method"}}Scene#pick(){{/crossLink}}. - - The event parameters will be the hit result returned by the {@link Scene/pick:method"}}Scene#pick(){{/crossLink}} method. - @event picked - */ - -const obb = math.OBB3(); -const angleAxis$1 = math.vec4(); -const q1$1 = math.vec4(); -const q2$1 = math.vec4(); -const xAxis$1 = math.vec3([1, 0, 0]); -const yAxis$1 = math.vec3([0, 1, 0]); -const zAxis$1 = math.vec3([0, 0, 1]); - -const veca = math.vec3(3); -const vecb = math.vec3(3); - -const identityMat$1 = math.identityMat4(); - -const ids = new Map$1({}); -const renderersCache = { }; - -/** - * @desc An {@link Entity} that is a drawable element, with a {@link Geometry} and a {@link Material}, that can be - * connected into a scene graph using {@link Node}s. - * - * ## Usage - * - * The example below is the same as the one given for {@link Node}, since the two classes work together. In this example, - * we'll create a scene graph in which a root {@link Node} represents a group and the Meshes are leaves. - * - * Since {@link Node} implements {@link Entity}, we can designate the root {@link Node} as a model, causing it to be registered by its - * ID in {@link Scene#models}. - * - * Since Mesh also implements {@link Entity}, we can designate the leaf Meshes as objects, causing them to - * be registered by their IDs in {@link Scene#objects}. - * - * We can then find those {@link Entity} types in {@link Scene#models} and {@link Scene#objects}. - * - * We can also update properties of our object-Meshes via calls to {@link Scene#setObjectsHighlighted} etc. - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/scenegraph/#sceneGraph)] - * - * ````javascript - * import {Viewer, Mesh, Node, PhongMaterial, buildBoxGeometry, ReadableGeometry} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [-21.80, 4.01, 6.56]; - * viewer.scene.camera.look = [0, -5.75, 0]; - * viewer.scene.camera.up = [0.37, 0.91, -0.11]; - * - * const boxGeometry = new ReadableGeometry(viewer.scene, buildBoxGeometry({ - * xSize: 1, - * ySize: 1, - * zSize: 1 - * })); - * - * new Node(viewer.scene, { - * id: "table", - * isModel: true, // <---------- Node represents a model, so is registered by ID in viewer.scene.models - * rotation: [0, 50, 0], - * position: [0, 0, 0], - * scale: [1, 1, 1], - * - * children: [ - * - * new Mesh(viewer.scene, { // Red table leg - * id: "redLeg", - * isObject: true, // <------ Node represents an object, so is registered by ID in viewer.scene.objects - * position: [-4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * material: new PhongMaterial(viewer.scene, { - * diffuse: [1, 0.3, 0.3] - * }), - * geometry: boxGeometry - * }), - * - * new Mesh(viewer.scene, { // Green table leg - * id: "greenLeg", - * isObject: true, // <------ Node represents an object, so is registered by ID in viewer.scene.objects - * position: [4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * material: new PhongMaterial(viewer.scene, { - * diffuse: [0.3, 1.0, 0.3] - * }), - * geometry: boxGeometry - * }), - * - * new Mesh(viewer.scene, {// Blue table leg - * id: "blueLeg", - * isObject: true, // <------ Node represents an object, so is registered by ID in viewer.scene.objects - * position: [4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * material: new PhongMaterial(viewer.scene, { - * diffuse: [0.3, 0.3, 1.0] - * }), - * geometry: boxGeometry - * }), - * - * new Mesh(viewer.scene, { // Yellow table leg - * id: "yellowLeg", - * isObject: true, // <------ Node represents an object, so is registered by ID in viewer.scene.objects - * position: [-4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * material: new PhongMaterial(viewer.scene, { - * diffuse: [1.0, 1.0, 0.0] - * }), - * geometry: boxGeometry - * }), - * - * new Mesh(viewer.scene, { // Purple table top - * id: "tableTop", - * isObject: true, // <------ Node represents an object, so is registered by ID in viewer.scene.objects - * position: [0, -3, 0], - * scale: [6, 0.5, 6], - * rotation: [0, 0, 0], - * material: new PhongMaterial(viewer.scene, { - * diffuse: [1.0, 0.3, 1.0] - * }), - * geometry: boxGeometry - * }) - * ] - * }); - * - * // Find Nodes and Meshes by their IDs - * - * var table = viewer.scene.models["table"]; // Since table Node has isModel == true - * - * var redLeg = viewer.scene.objects["redLeg"]; // Since the Meshes have isObject == true - * var greenLeg = viewer.scene.objects["greenLeg"]; - * var blueLeg = viewer.scene.objects["blueLeg"]; - * - * // Highlight one of the table leg Meshes - * - * viewer.scene.setObjectsHighlighted(["redLeg"], true); // Since the Meshes have isObject == true - * - * // Periodically update transforms on our Nodes and Meshes - * - * viewer.scene.on("tick", function () { - * - * // Rotate legs - * redLeg.rotateY(0.5); - * greenLeg.rotateY(0.5); - * blueLeg.rotateY(0.5); - * - * // Rotate table - * table.rotateY(0.5); - * table.rotateX(0.3); - * }); - * ```` - * - * ## Metadata - * - * As mentioned, we can also associate {@link MetaModel}s and {@link MetaObject}s with our {@link Node}s and Meshes, - * within a {@link MetaScene}. See {@link MetaScene} for an example. - * - * @implements {Entity} - * @implements {Drawable} - */ -class Mesh extends Component { - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID, unique among all components in the parent scene, generated automatically when omitted. - * @param {String} [cfg.originalSystemId] ID of the corresponding object within the originating system, if any. - * @param {Boolean} [cfg.isModel] Specify ````true```` if this Mesh represents a model, in which case the Mesh will be registered by {@link Mesh#id} in {@link Scene#models} and may also have a corresponding {@link MetaModel} with matching {@link MetaModel#id}, registered by that ID in {@link MetaScene#metaModels}. - * @param {Boolean} [cfg.isObject] Specify ````true```` if this Mesh represents an object, in which case the Mesh will be registered by {@link Mesh#id} in {@link Scene#objects} and may also have a corresponding {@link MetaObject} with matching {@link MetaObject#id}, registered by that ID in {@link MetaScene#metaObjects}. - * @param {Node} [cfg.parent] The parent Node. - * @param {Number[]} [cfg.origin] World-space origin for this Mesh. When this is given, then ````matrix````, ````position```` and ````geometry```` are all assumed to be relative to this center. - * @param {Number[]} [cfg.rtcCenter] Deprecated - renamed to ````origin````. - * @param {Number[]} [cfg.position=[0,0,0]] 3D position of this Mesh, relative to ````origin````. - * @param {Number[]} [cfg.scale=[1,1,1]] Local scale. - * @param {Number[]} [cfg.rotation=[0,0,0]] Local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis. - * @param {Number[]} [cfg.matrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]] Local modelling transform matrix. Overrides the position, scale and rotation parameters. - * @param {Number[]} [cfg.offset=[0,0,0]] World-space 3D translation offset. Translates the Mesh in World space, after modelling transforms. - * @param {Boolean} [cfg.occluder=true] Indicates if the Mesh is able to occlude {@link Marker}s. - * @param {Boolean} [cfg.visible=true] Indicates if the Mesh is initially visible. - * @param {Boolean} [cfg.culled=false] Indicates if the Mesh is initially culled from view. - * @param {Boolean} [cfg.pickable=true] Indicates if the Mesh is initially pickable. - * @param {Boolean} [cfg.clippable=true] Indicates if the Mesh is initially clippable. - * @param {Boolean} [cfg.collidable=true] Indicates if the Mesh is initially included in boundary calculations. - * @param {Boolean} [cfg.castsShadow=true] Indicates if the Mesh initially casts shadows. - * @param {Boolean} [cfg.receivesShadow=true] Indicates if the Mesh initially receives shadows. - * @param {Boolean} [cfg.xrayed=false] Indicates if the Mesh is initially xrayed. - * @param {Boolean} [cfg.highlighted=false] Indicates if the Mesh is initially highlighted. - * @param {Boolean} [cfg.selected=false] Indicates if the Mesh is initially selected. - * @param {Boolean} [cfg.edges=false] Indicates if the Mesh's edges are initially emphasized. - * @param {Boolean} [cfg.background=false] Indicates if the Mesh should act as background, e.g., it can be used for a skybox. - * @param {Number[]} [cfg.colorize=[1.0,1.0,1.0]] Mesh's initial RGB colorize color, multiplies by the rendered fragment colors. - * @param {Number} [cfg.opacity=1.0] Mesh's initial opacity factor, multiplies by the rendered fragment alpha. - * @param {String} [cfg.billboard="none"] Mesh's billboarding behaviour. Options are "none" for no billboarding, "spherical" to always directly face {@link Camera.eye}, rotating both vertically and horizontally, or "cylindrical" to face the {@link Camera#eye} while rotating only about its vertically axis (use that mode for things like trees on a landscape). - * @param {Geometry} [cfg.geometry] {@link Geometry} to define the shape of this Mesh. Inherits {@link Scene#geometry} by default. - * @param {Material} [cfg.material] {@link Material} to define the normal rendered appearance for this Mesh. Inherits {@link Scene#material} by default. - * @param {EmphasisMaterial} [cfg.xrayMaterial] {@link EmphasisMaterial} to define the xrayed appearance for this Mesh. Inherits {@link Scene#xrayMaterial} by default. - * @param {EmphasisMaterial} [cfg.highlightMaterial] {@link EmphasisMaterial} to define the xrayed appearance for this Mesh. Inherits {@link Scene#highlightMaterial} by default. - * @param {EmphasisMaterial} [cfg.selectedMaterial] {@link EmphasisMaterial} to define the selected appearance for this Mesh. Inherits {@link Scene#selectedMaterial} by default. - * @param {EmphasisMaterial} [cfg.edgeMaterial] {@link EdgeMaterial} to define the appearance of enhanced edges for this Mesh. Inherits {@link Scene#edgeMaterial} by default. - * @param {Number} [cfg.renderOrder=0] Specifies the rendering order for this mESH. This is used to control the order in which - * mESHES are drawn when they have transparent objects, to give control over the order in which those objects are blended within the transparent - * render pass. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this.renderOrder = cfg.renderOrder || 0; - - /** - * ID of the corresponding object within the originating system, if any. - * - * @type {String} - * @abstract - */ - this.originalSystemId = (cfg.originalSystemId || this.id); - - /** @private **/ - this.renderFlags = new RenderFlags(); - - this._state = new RenderState({ // NOTE: Renderer gets modeling and normal matrices from Mesh#matrix and Mesh.#normalWorldMatrix - visible: true, - culled: false, - pickable: null, - clippable: null, - collidable: null, - occluder: (cfg.occluder !== false), - castsShadow: null, - receivesShadow: null, - xrayed: false, - highlighted: false, - selected: false, - edges: false, - stationary: !!cfg.stationary, - background: !!cfg.background, - billboard: this._checkBillboard(cfg.billboard), - layer: null, - colorize: null, - pickID: this.scene._renderer.getPickID(this), - drawHash: "", - pickOcclusionHash: "", - offset: math.vec3(), - origin: null, - originHash: null, - isUI: cfg.isUI - }); - - const material = cfg.material ? this._checkComponent2(["PhongMaterial", "MetallicMaterial", "SpecularMaterial", "LambertMaterial"], cfg.material) : this.scene.material; - - const mesh = this; - - const wrapRenderer = (getProgramSetup) => { - let instance = null; - const ensureInstance = () => { - if (! instance) { - const programVariablesState = createProgramVariablesState(); - const createAttribute = programVariablesState.programVariables.createAttribute; - const geometryState = mesh._geometry._state; - const attributes = { - position: createAttribute("vec3", "position"), - color: geometryState.colorsBuf && createAttribute("vec4", "color"), - pickColor: createAttribute("vec4", "pickColor"), - uv: geometryState.uvBuf && createAttribute("vec2", "uv"), - normal: (geometryState.autoVertexNormals || geometryState.normalsBuf) && [ "triangles", "triangle-strip", "triangle-fan" ].includes(geometryState.primitiveName) && createAttribute("vec3", "normal") - }; - - const lazyShaderVariable = function(name) { - const variable = { - toString: () => { - variable.needed = true; - return name; - } - }; - return variable; - }; - const worldNormal = attributes.normal && lazyShaderVariable("worldNormal"); - const viewNormal = worldNormal && lazyShaderVariable("viewNormal"); - const decodedUv = attributes.uv && lazyShaderVariable("decodedUv"); - - const programSetup = getProgramSetup( - programVariablesState.programVariables, - { - attributes: { - position: { - world: "worldPosition", - view: "viewPosition" - }, - color: attributes.color, - pickColor: attributes.pickColor, - uv: decodedUv, - normal: attributes.normal && { - world: worldNormal, - view: viewNormal - } - }, - viewMatrix: "viewMatrix2" - }); - const hash = [ - programSetup.programName, - mesh.scene.canvas.canvas.id, - mesh.scene._sectionPlanesState.getHash(), - mesh._geometry._state.hash - ].concat(programSetup.getHash()).join(";"); - if (! (hash in renderersCache)) { - const renderer = instantiateMeshRenderer(mesh, attributes, { decodedUv: decodedUv, worldNormal: worldNormal, viewNormal: viewNormal }, programSetup, programVariablesState); - if (renderer.errors) { - console.log(renderer.errors.join("\n")); - return; - } - const id = ids.addItem({}); - renderersCache[hash] = { - drawMesh: renderer.drawMesh, - id: id, - useCount: 0, - delete: () => { - ids.removeItem(id); - renderer.destroy(); - delete renderersCache[hash]; - stats.memory.programs--; - } - }; - stats.memory.programs++; - } - instance = renderersCache[hash]; - instance.useCount++; - } - }; - return { - get: ensureInstance, - getId: () => instance.id, - put: () => { if (instance) { if (--instance.useCount === 0) { instance.delete(); } instance = null; } }, - drawMesh: (frameCtx, mesh, material) => { - ensureInstance(); - instance && instance.drawMesh(frameCtx, mesh, material); - } - }; - }; - - const scene = mesh.scene; - const emphasisShaderSourceMaker = isFill => (vars, geo) => EmphasisShaderSource(mesh._state.hash, vars, geo, scene, isFill); - this._renderers = { - _drawRenderer: wrapRenderer((vars, geo) => ((material.type === "LambertMaterial") - ? LambertShaderSource(mesh._state.drawHash, vars, geo, material, scene) - : DrawShaderSource (mesh._state.drawHash, vars, geo, material, scene))), - _shadowRenderer: wrapRenderer((vars) => ShadowShaderSource(mesh._state.hash, vars)), - _emphasisEdgesRenderer: wrapRenderer(emphasisShaderSourceMaker(false)), - _emphasisFillRenderer: wrapRenderer(emphasisShaderSourceMaker(true)), - _pickMeshRenderer: wrapRenderer((vars) => PickMeshShaderSource(mesh._state.hash, vars)), - _pickTriangleRenderer: wrapRenderer((vars, geo) => PickTriangleShaderSource(mesh._state.hash, vars, geo)), - _occlusionRenderer: wrapRenderer((vars) => OcclusionShaderSource(mesh._state.pickOcclusionHash, vars)) - }; - - this._geometry = cfg.geometry ? this._checkComponent2(["ReadableGeometry", "VBOGeometry"], cfg.geometry) : this.scene.geometry; - this._material = material; - this._xrayMaterial = cfg.xrayMaterial ? this._checkComponent("EmphasisMaterial", cfg.xrayMaterial) : this.scene.xrayMaterial; - this._highlightMaterial = cfg.highlightMaterial ? this._checkComponent("EmphasisMaterial", cfg.highlightMaterial) : this.scene.highlightMaterial; - this._selectedMaterial = cfg.selectedMaterial ? this._checkComponent("EmphasisMaterial", cfg.selectedMaterial) : this.scene.selectedMaterial; - this._edgeMaterial = cfg.edgeMaterial ? this._checkComponent("EdgeMaterial", cfg.edgeMaterial) : this.scene.edgeMaterial; - - this._parentNode = null; - - this._aabb = null; - this._aabbDirty = true; - - this._numTriangles = (this._geometry ? this._geometry.numTriangles : 0); - - this.scene._aabbDirty = true; - - this._scale = math.vec3(); - this._quaternion = math.identityQuaternion(); - this._rotation = math.vec3(); - this._position = math.vec3(); - - this._worldMatrix = math.identityMat4(); - this._worldNormalMatrix = math.identityMat4(); - - this._localMatrixDirty = true; - this._worldMatrixDirty = true; - this._worldNormalMatrixDirty = true; - - const origin = cfg.origin || cfg.rtcCenter; - if (origin) { - this._state.origin = math.vec3(origin); - this._state.originHash = origin.join(); - } - - if (cfg.matrix) { - this.matrix = cfg.matrix; - } else { - this.scale = cfg.scale; - this.position = cfg.position; - if (cfg.quaternion) ; else { - this.rotation = cfg.rotation; - } - } - - this._isObject = cfg.isObject; - if (this._isObject) { - this.scene._registerObject(this); - } - - this._isModel = cfg.isModel; - if (this._isModel) { - this.scene._registerModel(this); - } - - this.visible = cfg.visible; - this.culled = cfg.culled; - this.pickable = cfg.pickable; - this.clippable = cfg.clippable; - this.collidable = cfg.collidable; - this.castsShadow = cfg.castsShadow; - this.receivesShadow = cfg.receivesShadow; - this.xrayed = cfg.xrayed; - this.highlighted = cfg.highlighted; - this.selected = cfg.selected; - this.edges = cfg.edges; - this.layer = cfg.layer; - this.colorize = cfg.colorize; - this.opacity = cfg.opacity; - this.offset = cfg.offset; - - if (cfg.parentId) { - const parentNode = this.scene.components[cfg.parentId]; - if (!parentNode) { - this.error("Parent not found: '" + cfg.parentId + "'"); - } else if (!parentNode.isNode) { - this.error("Parent is not a Node: '" + cfg.parentId + "'"); - } else { - parentNode.addChild(this); - } - this._parentNode = parentNode; - } else if (cfg.parent) { - if (!cfg.parent.isNode) { - this.error("Parent is not a Node"); - } - cfg.parent.addChild(this); - this._parentNode = cfg.parent; - } - - this.compile(); - } - - /** - @private - */ - get type() { - return "Mesh"; - } - - //------------------------------------------------------------------------------------------------------------------ - // Mesh members - //------------------------------------------------------------------------------------------------------------------ - - /** - * Returns true to indicate that this Component is a Mesh. - * @final - * @type {Boolean} - */ - get isMesh() { - return true; - } - - /** - * The parent Node. - * - * The parent Node may also be set by passing the Mesh to the parent's {@link Node#addChild} method. - * - * @type {Node} - */ - get parent() { - return this._parentNode; - } - - /** - * Defines the shape of this Mesh. - * - * Set to {@link Scene#geometry} by default. - * - * @type {Geometry} - */ - get geometry() { - return this._geometry; - } - - /** - * Defines the appearance of this Mesh when rendering normally, ie. when not xrayed, highlighted or selected. - * - * Set to {@link Scene#material} by default. - * - * @type {Material} - */ - get material() { - return this._material; - } - - /** - * Gets the Mesh's local translation. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - get position() { - return this._position; - } - - /** - * Sets the Mesh's local translation. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - set position(value) { - this._position.set(value || [0, 0, 0]); - this._setLocalMatrixDirty(); - this._setAABBDirty(); - this.glRedraw(); - } - - /** - * Gets the Mesh's local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - get rotation() { - return this._rotation; - } - - /** - * Sets the Mesh's local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - set rotation(value) { - this._rotation.set(value || [0, 0, 0]); - math.eulerToQuaternion(this._rotation, "XYZ", this._quaternion); - this._setLocalMatrixDirty(); - this._setAABBDirty(); - this.glRedraw(); - } - - /** - * Gets the Mesh's local rotation quaternion. - * - * Default value is ````[0,0,0,1]````. - * - * @type {Number[]} - */ - get quaternion() { - return this._quaternion; - } - - /** - * Sets the Mesh's local rotation quaternion. - * - * Default value is ````[0,0,0,1]````. - * - * @type {Number[]} - */ - set quaternion(value) { - this._quaternion.set(value || [0, 0, 0, 1]); - math.quaternionToEuler(this._quaternion, "XYZ", this._rotation); - this._setLocalMatrixDirty(); - this._setAABBDirty(); - this.glRedraw(); - } - - /** - * Gets the Mesh's local scale. - * - * Default value is ````[1,1,1]````. - * - * @type {Number[]} - */ - get scale() { - return this._scale; - } - - /** - * Sets the Mesh's local scale. - * - * Default value is ````[1,1,1]````. - * - * @type {Number[]} - */ - set scale(value) { - this._scale.set(value || [1, 1, 1]); - this._setLocalMatrixDirty(); - this._setAABBDirty(); - this.glRedraw(); - } - - /** - * Gets the Mesh's local modeling transform matrix. - * - * Default value is ````[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]````. - * - * @type {Number[]} - */ - get matrix() { - if (this._localMatrixDirty) { - if (!this.__localMatrix) { - this.__localMatrix = math.identityMat4(); - } - math.composeMat4(this._position, this._quaternion, this._scale, this.__localMatrix); - this._localMatrixDirty = false; - } - return this.__localMatrix; - } - - /** - * Sets the Mesh's local modeling transform matrix. - * - * Default value is ````[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]````. - * - * @type {Number[]} - */ - set matrix(value) { - if (!this.__localMatrix) { - this.__localMatrix = math.identityMat4(); - } - this.__localMatrix.set(value || identityMat$1); - math.decomposeMat4(this.__localMatrix, this._position, this._quaternion, this._scale); - this._localMatrixDirty = false; - this._setWorldMatrixDirty(); - this._setAABBDirty(); - this.glRedraw(); - } - - /** - * Gets the Mesh's World matrix. - * - * @property worldMatrix - * @type {Number[]} - */ - get worldMatrix() { - if (this._worldMatrixDirty) { - this._buildWorldMatrix(); - } - return this._worldMatrix; - } - - /** - * Gets the Mesh's World normal matrix. - * - * @type {Number[]} - */ - get worldNormalMatrix() { - if (this._worldNormalMatrixDirty) { - this._buildWorldNormalMatrix(); - } - return this._worldNormalMatrix; - } - - /** - * Returns true to indicate that Mesh implements {@link Entity}. - * - * @returns {Boolean} - */ - get isEntity() { - return true; - } - - /** - * Returns ````true```` if this Mesh represents a model. - * - * When this returns ````true````, the Mesh will be registered by {@link Mesh#id} in {@link Scene#models} and - * may also have a corresponding {@link MetaModel}. - * - * @type {Boolean} - */ - get isModel() { - return this._isModel; - } - - /** - * Returns ````true```` if this Mesh represents an object. - * - * When this returns ````true````, the Mesh will be registered by {@link Mesh#id} in {@link Scene#objects} and - * may also have a corresponding {@link MetaObject}. - * - * @type {Boolean} - */ - get isObject() { - return this._isObject; - } - - /** - * Returns ````true```` if this Mesh is an UI object. - * - * @type {Boolean} - */ - get isUI() { - return this._state.isUI; - } - - /** - * Gets the Mesh's World-space 3D axis-aligned bounding box. - * - * Represented by a six-element Float64Array containing the min/max extents of the - * axis-aligned volume, ie. ````[xmin, ymin,zmin,xmax,ymax, zmax]````. - * - * @type {Number[]} - */ - get aabb() { - if (this._aabbDirty) { - this._updateAABB(); - } - return this._aabb; - } - - /** - * Gets the 3D origin of the Mesh's {@link Geometry}'s vertex positions. - * - * When this is given, then {@link Mesh#matrix}, {@link Mesh#position} and {@link Mesh#geometry} are all assumed to be relative to this center position. - * - * @type {Float64Array} - */ - get origin() { - return this._state.origin; - } - - /** - * Sets the 3D origin of the Mesh's {@link Geometry}'s vertex positions. - * - * When this is given, then {@link Mesh#matrix}, {@link Mesh#position} and {@link Mesh#geometry} are all assumed to be relative to this center position. - * - * @type {Float64Array} - */ - set origin(origin) { - if (origin) { - if (!this._state.origin) { - this._state.origin = math.vec3(); - } - this._state.origin.set(origin); - this._state.originHash = origin.join(); - this._setAABBDirty(); - this.scene._aabbDirty = true; - } else { - if (this._state.origin) { - this._state.origin = null; - this._state.originHash = null; - this._setAABBDirty(); - this.scene._aabbDirty = true; - } - } - } - - /** - * Gets the World-space origin for this Mesh. - * - * Deprecated and replaced by {@link Mesh#origin}. - * - * @deprecated - * @type {Float64Array} - */ - get rtcCenter() { - return this.origin; - } - - /** - * Sets the World-space origin for this Mesh. - * - * Deprecated and replaced by {@link Mesh#origin}. - * - * @deprecated - * @type {Float64Array} - */ - set rtcCenter(rtcCenter) { - this.origin = rtcCenter; - } - - /** - * The approximate number of triangles in this Mesh. - * - * @type {Number} - */ - get numTriangles() { - return this._numTriangles; - } - - /** - * Gets if this Mesh is visible. - * - * Only rendered when {@link Mesh#visible} is ````true```` and {@link Mesh#culled} is ````false````. - * - * When {@link Mesh#isObject} and {@link Mesh#visible} are both ````true```` the Mesh will be - * registered by {@link Mesh#id} in {@link Scene#visibleObjects}. - * - * @type {Boolean} - */ - get visible() { - return this._state.visible; - } - - /** - * Sets if this Mesh is visible. - * - * Only rendered when {@link Mesh#visible} is ````true```` and {@link Mesh#culled} is ````false````. - * - * When {@link Mesh#isObject} and {@link Mesh#visible} are both ````true```` the Mesh will be - * registered by {@link Mesh#id} in {@link Scene#visibleObjects}. - * - * @type {Boolean} - */ - set visible(visible) { - visible = visible !== false; - this._state.visible = visible; - if (this._isObject) { - this.scene._objectVisibilityUpdated(this, visible); - } - this.glRedraw(); - } - - /** - * Gets if this Mesh is xrayed. - * - * XRayed appearance is configured by the {@link EmphasisMaterial} referenced by {@link Mesh#xrayMaterial}. - * - * When {@link Mesh#isObject} and {@link Mesh#xrayed} are both ````true``` the Mesh will be - * registered by {@link Mesh#id} in {@link Scene#xrayedObjects}. - * - * @type {Boolean} - */ - get xrayed() { - return this._state.xrayed; - } - - /** - * Sets if this Mesh is xrayed. - * - * XRayed appearance is configured by the {@link EmphasisMaterial} referenced by {@link Mesh#xrayMaterial}. - * - * When {@link Mesh#isObject} and {@link Mesh#xrayed} are both ````true``` the Mesh will be - * registered by {@link Mesh#id} in {@link Scene#xrayedObjects}. - * - * @type {Boolean} - */ - set xrayed(xrayed) { - xrayed = !!xrayed; - if (this._state.xrayed === xrayed) { - return; - } - this._state.xrayed = xrayed; - if (this._isObject) { - this.scene._objectXRayedUpdated(this, xrayed); - } - this.glRedraw(); - } - - /** - * Gets if this Mesh is highlighted. - * - * Highlighted appearance is configured by the {@link EmphasisMaterial} referenced by {@link Mesh#highlightMaterial}. - * - * When {@link Mesh#isObject} and {@link Mesh#highlighted} are both ````true```` the Mesh will be - * registered by {@link Mesh#id} in {@link Scene#highlightedObjects}. - * - * @type {Boolean} - */ - get highlighted() { - return this._state.highlighted; - } - - /** - * Sets if this Mesh is highlighted. - * - * Highlighted appearance is configured by the {@link EmphasisMaterial} referenced by {@link Mesh#highlightMaterial}. - * - * When {@link Mesh#isObject} and {@link Mesh#highlighted} are both ````true```` the Mesh will be - * registered by {@link Mesh#id} in {@link Scene#highlightedObjects}. - * - * @type {Boolean} - */ - set highlighted(highlighted) { - highlighted = !!highlighted; - if (highlighted === this._state.highlighted) { - return; - } - this._state.highlighted = highlighted; - if (this._isObject) { - this.scene._objectHighlightedUpdated(this, highlighted); - } - this.glRedraw(); - } - - /** - * Gets if this Mesh is selected. - * - * Selected appearance is configured by the {@link EmphasisMaterial} referenced by {@link Mesh#selectedMaterial}. - * - * When {@link Mesh#isObject} and {@link Mesh#selected} are both ````true``` the Mesh will be - * registered by {@link Mesh#id} in {@link Scene#selectedObjects}. - * - * @type {Boolean} - */ - get selected() { - return this._state.selected; - } - - /** - * Sets if this Mesh is selected. - * - * Selected appearance is configured by the {@link EmphasisMaterial} referenced by {@link Mesh#selectedMaterial}. - * - * When {@link Mesh#isObject} and {@link Mesh#selected} are both ````true``` the Mesh will be - * registered by {@link Mesh#id} in {@link Scene#selectedObjects}. - * - * @type {Boolean} - */ - set selected(selected) { - selected = !!selected; - if (selected === this._state.selected) { - return; - } - this._state.selected = selected; - if (this._isObject) { - this.scene._objectSelectedUpdated(this, selected); - } - this.glRedraw(); - } - - /** - * Gets if this Mesh is edge-enhanced. - * - * Edge appearance is configured by the {@link EdgeMaterial} referenced by {@link Mesh#edgeMaterial}. - * - * @type {Boolean} - */ - get edges() { - return this._state.edges; - } - - /** - * Sets if this Mesh is edge-enhanced. - * - * Edge appearance is configured by the {@link EdgeMaterial} referenced by {@link Mesh#edgeMaterial}. - * - * @type {Boolean} - */ - set edges(edges) { - edges = !!edges; - if (edges === this._state.edges) { - return; - } - this._state.edges = edges; - this.glRedraw(); - } - - /** - * Gets if this Mesh is culled. - * - * Only rendered when {@link Mesh#visible} is ````true```` and {@link Mesh#culled} is ````false````. - * - * @type {Boolean} - */ - get culled() { - return this._state.culled; - } - - /** - * Sets if this Mesh is culled. - * - * Only rendered when {@link Mesh#visible} is ````true```` and {@link Mesh#culled} is ````false````. - * - * @type {Boolean} - */ - set culled(value) { - this._state.culled = !!value; - this.glRedraw(); - } - - /** - * Gets if this Mesh is clippable. - * - * Clipping is done by the {@link SectionPlane}s in {@link Scene#sectionPlanes}. - * - * @type {Boolean} - */ - get clippable() { - return this._state.clippable; - } - - /** - * Sets if this Mesh is clippable. - * - * Clipping is done by the {@link SectionPlane}s in {@link Scene#sectionPlanes}. - * - * @type {Boolean} - */ - set clippable(value) { - value = value !== false; - if (this._state.clippable === value) { - return; - } - this._state.clippable = value; - this.glRedraw(); - } - - /** - * Gets if this Mesh included in boundary calculations. - * - * @type {Boolean} - */ - get collidable() { - return this._state.collidable; - } - - /** - * Sets if this Mesh included in boundary calculations. - * - * @type {Boolean} - */ - set collidable(value) { - value = value !== false; - if (value === this._state.collidable) { - return; - } - this._state.collidable = value; - this._setAABBDirty(); - this.scene._aabbDirty = true; - - } - - //------------------------------------------------------------------------------------------------------------------ - // Entity members - //------------------------------------------------------------------------------------------------------------------ - - /** - * Gets if this Mesh is pickable. - * - * Picking is done via calls to {@link Scene#pick}. - * - * @type {Boolean} - */ - get pickable() { - return this._state.pickable; - } - - /** - * Sets if this Mesh is pickable. - * - * Picking is done via calls to {@link Scene#pick}. - * - * @type {Boolean} - */ - set pickable(value) { - value = value !== false; - if (this._state.pickable === value) { - return; - } - this._state.pickable = value; - // No need to trigger a render; - // state is only used when picking - } - - /** - * Gets if this Mesh casts shadows. - * - * @type {Boolean} - */ - get castsShadow() { - return this._state.castsShadow; - } - - /** - * Sets if this Mesh casts shadows. - * - * @type {Boolean} - */ - set castsShadow(value) { - value = value !== false; - if (value === this._state.castsShadow) { - return; - } - this._state.castsShadow = value; - this.glRedraw(); - } - - /** - * Gets if this Mesh can have shadows cast upon it. - * - * @type {Boolean} - */ - get receivesShadow() { - return this._state.receivesShadow; - } - - /** - * Sets if this Mesh can have shadows cast upon it. - * - * @type {Boolean} - */ - set receivesShadow(value) { - value = value !== false; - if (value === this._state.receivesShadow) { - return; - } - this._state.receivesShadow = value; - this._state.hash = value ? "/mod/rs;" : "/mod;"; - this.fire("dirty", this); // Now need to (re)compile objectRenderers to include/exclude shadow mapping - } - - /** - * Gets if this Mesh can have Scalable Ambient Obscurance (SAO) applied to it. - * - * SAO is configured by {@link SAO}. - * - * @type {Boolean} - * @abstract - */ - get saoEnabled() { - return false; // TODO: Support SAO on Meshes - } - - /** - * Gets the RGB colorize color for this Mesh. - * - * Multiplies by rendered fragment colors. - * - * Each element of the color is in range ````[0..1]````. - * - * @type {Number[]} - */ - get colorize() { - return this._state.colorize; - } - - /** - * Sets the RGB colorize color for this Mesh. - * - * Multiplies by rendered fragment colors. - * - * Each element of the color is in range ````[0..1]````. - * - * @type {Number[]} - */ - set colorize(value) { - let colorize = this._state.colorize; - if (!colorize) { - colorize = this._state.colorize = new Float32Array(4); - colorize[3] = 1; - } - if (value) { - colorize[0] = value[0]; - colorize[1] = value[1]; - colorize[2] = value[2]; - } else { - colorize[0] = 1; - colorize[1] = 1; - colorize[2] = 1; - } - const colorized = (!!value); - this.scene._objectColorizeUpdated(this, colorized); - this.glRedraw(); - } - - /** - * Gets the opacity factor for this Mesh. - * - * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas. - * - * @type {Number} - */ - get opacity() { - return this._state.colorize[3]; - } - - /** - * Sets the opacity factor for this Mesh. - * - * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas. - * - * @type {Number} - */ - set opacity(opacity) { - let colorize = this._state.colorize; - if (!colorize) { - colorize = this._state.colorize = new Float32Array(4); - colorize[0] = 1; - colorize[1] = 1; - colorize[2] = 1; - } - const opacityUpdated = (opacity !== null && opacity !== undefined); - colorize[3] = opacityUpdated ? opacity : 1.0; - this.scene._objectOpacityUpdated(this, opacityUpdated); - this.glRedraw(); - } - - /** - * Gets if this Mesh is transparent. - * @returns {Boolean} - */ - get transparent() { - return this._material.alphaMode === 2 /* blend */ || this._state.colorize[3] < 1 - } - - /** - * Gets the Mesh's rendering order relative to other Meshes. - * - * Default value is ````0````. - * - * This can be set on multiple transparent Meshes, to make them render in a specific order for correct alpha blending. - * - * @type {Number} - */ - get layer() { - return this._state.layer; - } - - /** - * Sets the Mesh's rendering order relative to other Meshes. - * - * Default value is ````0````. - * - * This can be set on multiple transparent Meshes, to make them render in a specific order for correct alpha blending. - * - * @type {Number} - */ - set layer(value) { - // TODO: Only accept rendering layer in range [0...MAX_layer] - value = value || 0; - value = Math.round(value); - if (value === this._state.layer) { - return; - } - this._state.layer = value; - this._renderer.needStateSort(); - } - - /** - * Gets if the Node's position is stationary. - * - * When true, will disable the effect of {@link Camera} translations for this Mesh, while still allowing it to rotate. This is useful for skyboxes. - * - * @type {Boolean} - */ - get stationary() { - return this._state.stationary; - } - - /** - * Gets the Node's billboarding behaviour. - * - * Options are: - * * ````"none"```` - (default) - No billboarding. - * * ````"spherical"```` - Mesh is billboarded to face the viewpoint, rotating both vertically and horizontally. - * * ````"cylindrical"```` - Mesh is billboarded to face the viewpoint, rotating only about its vertically axis. Use this mode for things like trees on a landscape. - * @type {String} - */ - get billboard() { - return this._state.billboard; - } - - /** - * Gets the Mesh's 3D World-space offset. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - get offset() { - return this._state.offset; - } - - /** - * Sets the Mesh's 3D World-space offset. - * - * The offset dynamically translates the Mesh in World-space. - * - * Default value is ````[0, 0, 0]````. - * - * Provide a null or undefined value to reset to the default value. - * - * @type {Number[]} - */ - set offset(value) { - this._state.offset.set(value || [0, 0, 0]); - this._setAABBDirty(); - this.glRedraw(); - } - - /** - * Returns true to indicate that Mesh implements {@link Drawable}. - * @final - * @type {Boolean} - */ - get isDrawable() { - return true; - } - - /** - * Property with final value ````true```` to indicate that xeokit should render this Mesh in sorted order, relative to other Meshes. - * - * The sort order is determined by {@link Mesh#stateSortCompare}. - * - * Sorting is essential for rendering performance, so that xeokit is able to avoid applying runs of the same state changes to the GPU, ie. can collapse them. - * - * @type {Boolean} - */ - get isStateSortable() { - return true; - } - - /** - * Defines the appearance of this Mesh when xrayed. - * - * Mesh is xrayed when {@link Mesh#xrayed} is ````true````. - * - * Set to {@link Scene#xrayMaterial} by default. - * - * @type {EmphasisMaterial} - */ - get xrayMaterial() { - return this._xrayMaterial; - } - - /** - * Defines the appearance of this Mesh when highlighted. - * - * Mesh is xrayed when {@link Mesh#highlighted} is ````true````. - * - * Set to {@link Scene#highlightMaterial} by default. - * - * @type {EmphasisMaterial} - */ - get highlightMaterial() { - return this._highlightMaterial; - } - - /** - * Defines the appearance of this Mesh when selected. - * - * Mesh is xrayed when {@link Mesh#selected} is ````true````. - * - * Set to {@link Scene#selectedMaterial} by default. - * - * @type {EmphasisMaterial} - */ - get selectedMaterial() { - return this._selectedMaterial; - } - - /** - * Defines the appearance of this Mesh when edges are enhanced. - * - * Mesh is xrayed when {@link Mesh#edges} is ````true````. - * - * Set to {@link Scene#edgeMaterial} by default. - * - * @type {EdgeMaterial} - */ - get edgeMaterial() { - return this._edgeMaterial; - } - - _checkBillboard(value) { - value = value || "none"; - if (value !== "spherical" && value !== "cylindrical" && value !== "none") { - this.error("Unsupported value for 'billboard': " + value + " - accepted values are " + - "'spherical', 'cylindrical' and 'none' - defaulting to 'none'."); - value = "none"; - } - return value; - } - - /** - * Called by xeokit to compile shaders for this Mesh. - * @private - */ - compile() { - const scene = this.scene; - const state = this._state; - const hash = [ - scene.canvas.canvas.id, - scene._sectionPlanesState.getHash() - ]; - if (state.stationary) { - hash.push("/s"); - } - if (state.billboard === "none") { - hash.push("/n"); - } else if (state.billboard === "spherical") { - hash.push("/s"); - } else if (state.billboard === "cylindrical") { - hash.push("/c"); - } - hash.push(";"); - - const drawHash = hash.concat([ - scene.gammaOutput ? "go" : "", - scene._lightsState.getHash(), - state.receivesShadow ? "/rs" : "" - ]).join(""); - if (this._state.drawHash !== drawHash) { - this._state.drawHash = drawHash; - this._renderers._drawRenderer.put(); - this._renderers._shadowRenderer.put(); - this._renderers._emphasisFillRenderer.put(); - this._renderers._emphasisEdgesRenderer.put(); - this._renderers._drawRenderer.get(); - // this._renderers._shadowRenderer.get(); - this._renderers._emphasisFillRenderer.get(); - this._renderers._emphasisEdgesRenderer.get(); - } - const pickOcclusionHash = hash.join(""); - if (this._state.pickOcclusionHash !== pickOcclusionHash) { - this._state.pickOcclusionHash = pickOcclusionHash; - this._renderers._pickMeshRenderer.put(); - this._renderers._pickTriangleRenderer.put(); - this._renderers._pickMeshRenderer.get(); - if (this._state.occluder) { - this._renderers._occlusionRenderer.put(); - this._renderers._occlusionRenderer.get(); - } - } - } - - _setLocalMatrixDirty() { - this._localMatrixDirty = true; - this._setWorldMatrixDirty(); - } - - _setWorldMatrixDirty() { - this._worldMatrixDirty = true; - this._worldNormalMatrixDirty = true; - } - - _buildWorldMatrix() { - const localMatrix = this.matrix; - if (!this._parentNode) { - for (let i = 0, len = localMatrix.length; i < len; i++) { - this._worldMatrix[i] = localMatrix[i]; - } - } else { - math.mulMat4(this._parentNode.worldMatrix, localMatrix, this._worldMatrix); - } - this._worldMatrixDirty = false; - } - - _buildWorldNormalMatrix() { - if (this._worldMatrixDirty) { - this._buildWorldMatrix(); - } - if (!this._worldNormalMatrix) { - this._worldNormalMatrix = math.mat4(); - } - // Note: order of inverse and transpose doesn't matter - math.transposeMat4(this._worldMatrix, this._worldNormalMatrix); - math.inverseMat4(this._worldNormalMatrix); - this._worldNormalMatrixDirty = false; - } - - _setAABBDirty() { - if (this.collidable) { - for (let node = this; node; node = node._parentNode) { - node._aabbDirty = true; - } - } - } - - _updateAABB() { - this.scene._aabbDirty = true; - if (!this._aabb) { - this._aabb = math.AABB3(); - } - this._buildAABB(this.worldMatrix, this._aabb); // Mesh or VBOSceneModel - this._aabbDirty = false; - } - - _buildAABB(worldMatrix, aabb) { - - math.transformOBB3(worldMatrix, this._geometry.obb, obb); - math.OBB3ToAABB3(obb, aabb); - - const offset = this._state.offset; - - aabb[0] += offset[0]; - aabb[1] += offset[1]; - aabb[2] += offset[2]; - aabb[3] += offset[0]; - aabb[4] += offset[1]; - aabb[5] += offset[2]; - - if (this._state.origin) { - const origin = this._state.origin; - aabb[0] += origin[0]; - aabb[1] += origin[1]; - aabb[2] += origin[2]; - aabb[3] += origin[0]; - aabb[4] += origin[1]; - aabb[5] += origin[2]; - } - } - - /** - * Rotates the Mesh about the given local axis by the given increment. - * - * @param {Number[]} axis Local axis about which to rotate. - * @param {Number} angle Angle increment in degrees. - */ - rotate(axis, angle) { - angleAxis$1[0] = axis[0]; - angleAxis$1[1] = axis[1]; - angleAxis$1[2] = axis[2]; - angleAxis$1[3] = angle * math.DEGTORAD; - math.angleAxisToQuaternion(angleAxis$1, q1$1); - math.mulQuaternions(this.quaternion, q1$1, q2$1); - this.quaternion = q2$1; - this._setLocalMatrixDirty(); - this._setAABBDirty(); - this.glRedraw(); - return this; - } - - /** - * Rotates the Mesh about the given World-space axis by the given increment. - * - * @param {Number[]} axis Local axis about which to rotate. - * @param {Number} angle Angle increment in degrees. - */ - rotateOnWorldAxis(axis, angle) { - angleAxis$1[0] = axis[0]; - angleAxis$1[1] = axis[1]; - angleAxis$1[2] = axis[2]; - angleAxis$1[3] = angle * math.DEGTORAD; - math.angleAxisToQuaternion(angleAxis$1, q1$1); - math.mulQuaternions(q1$1, this.quaternion, q1$1); - //this.quaternion.premultiply(q1); - return this; - } - - /** - * Rotates the Mesh about the local X-axis by the given increment. - * - * @param {Number} angle Angle increment in degrees. - */ - rotateX(angle) { - return this.rotate(xAxis$1, angle); - } - - /** - * Rotates the Mesh about the local Y-axis by the given increment. - * - * @param {Number} angle Angle increment in degrees. - */ - rotateY(angle) { - return this.rotate(yAxis$1, angle); - } - - /** - * Rotates the Mesh about the local Z-axis by the given increment. - * - * @param {Number} angle Angle increment in degrees. - */ - rotateZ(angle) { - return this.rotate(zAxis$1, angle); - } - - /** - * Translates the Mesh along local space vector by the given increment. - * - * @param {Number[]} axis Normalized local space 3D vector along which to translate. - * @param {Number} distance Distance to translate along the vector. - */ - translate(axis, distance) { - math.vec3ApplyQuaternion(this.quaternion, axis, veca); - math.mulVec3Scalar(veca, distance, vecb); - math.addVec3(this.position, vecb, this.position); - this._setLocalMatrixDirty(); - this._setAABBDirty(); - this.glRedraw(); - return this; - } - - //------------------------------------------------------------------------------------------------------------------ - // Drawable members - //------------------------------------------------------------------------------------------------------------------ - - /** - * Translates the Mesh along the local X-axis by the given increment. - * - * @param {Number} distance Distance to translate along the X-axis. - */ - translateX(distance) { - return this.translate(xAxis$1, distance); - } - - /** - * Translates the Mesh along the local Y-axis by the given increment. - * - * @param {Number} distance Distance to translate along the Y-axis. - */ - translateY(distance) { - return this.translate(yAxis$1, distance); - } - - /** - * Translates the Mesh along the local Z-axis by the given increment. - * - * @param {Number} distance Distance to translate along the Z-axis. - */ - translateZ(distance) { - return this.translate(zAxis$1, distance); - } - - /** - * Comparison function used by the renderer to determine the order in which xeokit should render the Mesh, relative to to other Meshes. - * - * xeokit requires this method because Mesh implements {@link Drawable}. - * - * Sorting is essential for rendering performance, so that xeokit is able to avoid needlessly applying runs of the same rendering state changes to the GPU, ie. can collapse them. - * - * @param {Mesh} mesh1 - * @param {Mesh} mesh2 - * @returns {number} - */ - stateSortCompare(mesh1, mesh2) { - return (mesh1._state.layer - mesh2._state.layer) - || (mesh1._renderers._drawRenderer.getId() - mesh2._renderers._drawRenderer.getId()) // Program state - || (mesh1._material._state.id - mesh2._material._state.id) // Material state - || (mesh1._geometry._state.id - mesh2._geometry._state.id); // Geometry state - } - - /** @private */ - rebuildRenderFlags() { - this.renderFlags.reset(); - if (!this._getActiveSectionPlanes()) { - this.renderFlags.culled = true; - return; - } - this.renderFlags.numLayers = 1; - this.renderFlags.numVisibleLayers = 1; - this.renderFlags.visibleLayers[0] = 0; - this._updateRenderFlags(); - } - - /** - * @private - */ - _updateRenderFlags() { - - const renderFlags = this.renderFlags; - const state = this._state; - - if (state.xrayed) { - const xrayMaterial = this._xrayMaterial._state; - if (xrayMaterial.fill) { - if (xrayMaterial.fillAlpha < 1.0) { - renderFlags.xrayedSilhouetteTransparent = true; - } else { - renderFlags.xrayedSilhouetteOpaque = true; - } - } - if (xrayMaterial.edges) { - if (xrayMaterial.edgeAlpha < 1.0) { - renderFlags.xrayedEdgesTransparent = true; - } else { - renderFlags.xrayedEdgesOpaque = true; - } - } - } else { - const normalMaterial = this._material._state; - if (normalMaterial.alpha < 1.0 || state.colorize[3] < 1.0) { - renderFlags.colorTransparent = true; - } else { - renderFlags.colorOpaque = true; - } - if (state.edges) { - const edgeMaterial = this._edgeMaterial._state; - if (edgeMaterial.alpha < 1.0) { - renderFlags.edgesTransparent = true; - } else { - renderFlags.edgesOpaque = true; - } - } - if (state.selected) { - const selectedMaterial = this._selectedMaterial._state; - if (selectedMaterial.fill) { - if (selectedMaterial.fillAlpha < 1.0) { - renderFlags.selectedSilhouetteTransparent = true; - } else { - renderFlags.selectedSilhouetteOpaque = true; - } - } - if (selectedMaterial.edges) { - if (selectedMaterial.edgeAlpha < 1.0) { - renderFlags.selectedEdgesTransparent = true; - } else { - renderFlags.selectedEdgesOpaque = true; - } - } - } else if (state.highlighted) { - const highlightMaterial = this._highlightMaterial._state; - if (highlightMaterial.fill) { - if (highlightMaterial.fillAlpha < 1.0) { - renderFlags.highlightedSilhouetteTransparent = true; - } else { - renderFlags.highlightedSilhouetteOpaque = true; - } - } - if (highlightMaterial.edges) { - if (highlightMaterial.edgeAlpha < 1.0) { - renderFlags.highlightedEdgesTransparent = true; - } else { - renderFlags.highlightedEdgesOpaque = true; - } - } - } - } - } - - _getActiveSectionPlanes() { - - if (this._state.clippable) { - - const sectionPlanes = this.scene._sectionPlanesState.sectionPlanes; - const numSectionPlanes = sectionPlanes.length; - - if (numSectionPlanes > 0) { - for (let i = 0; i < numSectionPlanes; i++) { - - const sectionPlane = sectionPlanes[i]; - const renderFlags = this.renderFlags; - - if (!sectionPlane.active) { - renderFlags.sectionPlanesActivePerLayer[i] = false; - - } else { - - if (this._state.origin) { - - const intersect = math.planeAABB3Intersect(sectionPlane.dir, sectionPlane.dist, this.aabb); - const outside = (intersect === -1); - - if (outside) { - return false; - } - - const intersecting = (intersect === 0); - renderFlags.sectionPlanesActivePerLayer[i] = intersecting; - - } else { - renderFlags.sectionPlanesActivePerLayer[i] = true; - } - } - } - } - } - - return true; - } - - // ---------------------- NORMAL RENDERING ----------------------------------- - - /** @private */ - drawColorOpaque(frameCtx) { - this._renderers._drawRenderer.drawMesh(frameCtx, this, this._material); - } - - /** @private */ - drawColorTransparent(frameCtx) { - this._renderers._drawRenderer.drawMesh(frameCtx, this, this._material); - } - - // ---------------------- RENDERING SAO POST EFFECT TARGETS -------------- - - // TODO - - // ---------------------- EMPHASIS RENDERING ----------------------------------- - - /** @private */ - drawSilhouetteXRayed(frameCtx) { - this._renderers._emphasisFillRenderer.drawMesh(frameCtx, this, this._xrayMaterial); - } - - /** @private */ - drawSilhouetteHighlighted(frameCtx) { - this._renderers._emphasisFillRenderer.drawMesh(frameCtx, this, this._highlightMaterial); - } - - /** @private */ - drawSilhouetteSelected(frameCtx) { - this._renderers._emphasisFillRenderer.drawMesh(frameCtx, this, this._selectedMaterial); - } - - // ---------------------- EDGES RENDERING ----------------------------------- - - /** @private */ - drawEdgesColorOpaque(frameCtx) { - this._renderers._emphasisEdgesRenderer.drawMesh(frameCtx, this, this._edgeMaterial); - } - - /** @private */ - drawEdgesColorTransparent(frameCtx) { - this._renderers._emphasisEdgesRenderer.drawMesh(frameCtx, this, this._edgeMaterial); - } - - /** @private */ - drawEdgesXRayed(frameCtx) { - this._renderers._emphasisEdgesRenderer.drawMesh(frameCtx, this, this._xrayMaterial); - } - - /** @private */ - drawEdgesHighlighted(frameCtx) { - this._renderers._emphasisEdgesRenderer.drawMesh(frameCtx, this, this._highlightMaterial); - } - - /** @private */ - drawEdgesSelected(frameCtx) { - this._renderers._emphasisEdgesRenderer.drawMesh(frameCtx, this, this._selectedMaterial); - } - - // ---------------------- OCCLUSION CULL RENDERING ----------------------------------- - - /** @private */ - drawOcclusion(frameCtx) { - this._renderers._occlusionRenderer.drawMesh(frameCtx, this, this._material); - } - - // ---------------------- SHADOW BUFFER RENDERING ----------------------------------- - - /** @private */ - drawShadow(frameCtx) { - this._renderers._shadowRenderer.drawMesh(frameCtx, this, this._material); - } - - // ---------------------- PICKING RENDERING ---------------------------------- - - /** @private */ - drawPickMesh(frameCtx) { - this._renderers._pickMeshRenderer.drawMesh(frameCtx, this, this._material); - } - - /** @private - */ - canPickTriangle() { - return this._geometry.isReadableGeometry; // VBOGeometry does not support surface picking because it has no geometry data in browser memory - } - - /** @private */ - drawPickTriangles(frameCtx) { - this._renderers._pickTriangleRenderer.drawMesh(frameCtx, this, this._material); - } - - /** @private */ - pickTriangleSurface(pickViewMatrix, pickProjMatrix, projection, pickResult) { - pickTriangleSurface(this, pickViewMatrix, pickProjMatrix, projection, pickResult); - } - - /** @private */ - drawPickVertices(frameCtx) { - - } - - /** - * @private - * @returns {PerformanceNode} - */ - delegatePickedEntity() { - return this; - } - - //------------------------------------------------------------------------------------------------------------------ - // Component members - //------------------------------------------------------------------------------------------------------------------ - - /** - * Destroys this Mesh. - */ - destroy() { - super.destroy(); // xeokit.Object - Object.values(this._renderers).forEach(r => r.put()); - - this.scene._renderer.putPickID(this._state.pickID); // TODO: somehow puch this down into xeokit framework? - if (this._isObject) { - this.scene._deregisterObject(this); - if (this._visible) { - this.scene._objectVisibilityUpdated(this, false, false); - } - if (this._xrayed) { - this.scene._objectXRayedUpdated(this, false, false); - } - if (this._selected) { - this.scene._objectSelectedUpdated(this, false, false); - } - if (this._highlighted) { - this.scene._objectHighlightedUpdated(this, false, false); - } - this.scene._objectColorizeUpdated(this, false); - this.scene._objectOpacityUpdated(this, false); - if (this.offset.some((v) => v !== 0)) - this.scene._objectOffsetUpdated(this, false); - } - if (this._isModel) { - this.scene._deregisterModel(this); - } - this.glRedraw(); - } - -} - - -const pickTriangleSurface = (function () { - - // Cached vars to avoid garbage collection - - const localRayOrigin = math.vec3(); - const localRayDir = math.vec3(); - const positionA = math.vec3(); - const positionB = math.vec3(); - const positionC = math.vec3(); - const triangleVertices = math.vec3(); - const position = math.vec4(); - const worldPos = math.vec3(); - const viewPos = math.vec3(); - const bary = math.vec3(); - const normalA = math.vec3(); - const normalB = math.vec3(); - const normalC = math.vec3(); - const uva = math.vec3(); - const uvb = math.vec3(); - const uvc = math.vec3(); - const tempVec4a = math.vec4(); - const tempVec4b = math.vec4(); - const tempVec4c = math.vec4(); - const tempVec3 = math.vec3(); - const tempVec3b = math.vec3(); - const tempVec3c = math.vec3(); - const tempVec3d = math.vec3(); - const tempVec3e = math.vec3(); - const tempVec3f = math.vec3(); - const tempVec3g = math.vec3(); - const tempVec3h = math.vec3(); - const tempVec3i = math.vec3(); - const tempVec3j = math.vec3(); - const tempVec3k = math.vec3(); - - return function (mesh, pickViewMatrix, pickProjMatrix, projection, pickResult) { - - var primIndex = pickResult.primIndex; - - if (primIndex !== undefined && primIndex !== null && primIndex > -1) { - - const geometry = mesh.geometry._state; - const scene = mesh.scene; - const camera = scene.camera; - const canvas = scene.canvas; - - if (geometry.primitiveName === "triangles") { - - // Triangle picked; this only happens when the - // Mesh has a Geometry that has primitives of type "triangle" - - pickResult.primitive = "triangle"; - - // Get the World-space positions of the triangle's vertices - - const i = primIndex; // Indicates the first triangle index in the indices array - - const indices = geometry.indices; // Indices into geometry arrays, not into shared VertexBufs - const positions = geometry.positions; - - let ia3; - let ib3; - let ic3; - - if (indices) { - - var ia = indices[i + 0]; - var ib = indices[i + 1]; - var ic = indices[i + 2]; - - triangleVertices[0] = ia; - triangleVertices[1] = ib; - triangleVertices[2] = ic; - - pickResult.indices = triangleVertices; - - ia3 = ia * 3; - ib3 = ib * 3; - ic3 = ic * 3; - - } else { - - ia3 = i * 3; - ib3 = ia3 + 3; - ic3 = ib3 + 3; - } - - positionA[0] = positions[ia3 + 0]; - positionA[1] = positions[ia3 + 1]; - positionA[2] = positions[ia3 + 2]; - - positionB[0] = positions[ib3 + 0]; - positionB[1] = positions[ib3 + 1]; - positionB[2] = positions[ib3 + 2]; - - positionC[0] = positions[ic3 + 0]; - positionC[1] = positions[ic3 + 1]; - positionC[2] = positions[ic3 + 2]; - - if (geometry.compressGeometry) { - - // Decompress vertex positions - - const positionsDecodeMatrix = geometry.positionsDecodeMatrix; - if (positionsDecodeMatrix) { - geometryCompressionUtils.decompressPosition(positionA, positionsDecodeMatrix, positionA); - geometryCompressionUtils.decompressPosition(positionB, positionsDecodeMatrix, positionB); - geometryCompressionUtils.decompressPosition(positionC, positionsDecodeMatrix, positionC); - } - } - - // Attempt to ray-pick the triangle in local space - - if (pickResult.canvasPos) { - math.canvasPosToLocalRay(canvas.canvas, mesh.origin ? createRTCViewMat(pickViewMatrix, mesh.origin) : pickViewMatrix, pickProjMatrix, projection, mesh.worldMatrix, pickResult.canvasPos, localRayOrigin, localRayDir); - - } else if (pickResult.origin && pickResult.direction) { - math.worldRayToLocalRay(mesh.worldMatrix, pickResult.origin, pickResult.direction, localRayOrigin, localRayDir); - } - - math.normalizeVec3(localRayDir); - math.rayPlaneIntersect(localRayOrigin, localRayDir, positionA, positionB, positionC, position); - - // Get Local-space cartesian coordinates of the ray-triangle intersection - - pickResult.localPos = position; - pickResult.position = position; - - // Get interpolated World-space coordinates - - // Need to transform homogeneous coords - - tempVec4a[0] = position[0]; - tempVec4a[1] = position[1]; - tempVec4a[2] = position[2]; - tempVec4a[3] = 1; - - // Get World-space cartesian coordinates of the ray-triangle intersection - - math.transformVec4(mesh.worldMatrix, tempVec4a, tempVec4b); - - worldPos[0] = tempVec4b[0]; - worldPos[1] = tempVec4b[1]; - worldPos[2] = tempVec4b[2]; - - if (pickResult.canvasPos && mesh.origin) { - worldPos[0] += mesh.origin[0]; - worldPos[1] += mesh.origin[1]; - worldPos[2] += mesh.origin[2]; - } - - pickResult.worldPos = worldPos; - - // Get View-space cartesian coordinates of the ray-triangle intersection - - math.transformVec4(camera.matrix, tempVec4b, tempVec4c); - - viewPos[0] = tempVec4c[0]; - viewPos[1] = tempVec4c[1]; - viewPos[2] = tempVec4c[2]; - - pickResult.viewPos = viewPos; - - // Get barycentric coordinates of the ray-triangle intersection - - math.cartesianToBarycentric(position, positionA, positionB, positionC, bary); - - pickResult.bary = bary; - - // Get interpolated normal vector - - const normals = geometry.normals; - - if (normals) { - - if (geometry.compressGeometry) { - - // Decompress vertex normals - - const ia2 = ia * 3; - const ib2 = ib * 3; - const ic2 = ic * 3; - - geometryCompressionUtils.decompressNormal(normals.subarray(ia2, ia2 + 2), normalA); - geometryCompressionUtils.decompressNormal(normals.subarray(ib2, ib2 + 2), normalB); - geometryCompressionUtils.decompressNormal(normals.subarray(ic2, ic2 + 2), normalC); - - } else { - - normalA[0] = normals[ia3]; - normalA[1] = normals[ia3 + 1]; - normalA[2] = normals[ia3 + 2]; - - normalB[0] = normals[ib3]; - normalB[1] = normals[ib3 + 1]; - normalB[2] = normals[ib3 + 2]; - - normalC[0] = normals[ic3]; - normalC[1] = normals[ic3 + 1]; - normalC[2] = normals[ic3 + 2]; - } - - const normal = math.addVec3(math.addVec3( - math.mulVec3Scalar(normalA, bary[0], tempVec3), - math.mulVec3Scalar(normalB, bary[1], tempVec3b), tempVec3c), - math.mulVec3Scalar(normalC, bary[2], tempVec3d), tempVec3e); - - pickResult.worldNormal = math.normalizeVec3(math.transformVec3(mesh.worldNormalMatrix, normal, tempVec3f)); - } - - // Get interpolated UV coordinates - - const uvs = geometry.uv; - - if (uvs) { - - uva[0] = uvs[(ia * 2)]; - uva[1] = uvs[(ia * 2) + 1]; - - uvb[0] = uvs[(ib * 2)]; - uvb[1] = uvs[(ib * 2) + 1]; - - uvc[0] = uvs[(ic * 2)]; - uvc[1] = uvs[(ic * 2) + 1]; - - if (geometry.compressGeometry) { - - // Decompress vertex UVs - - const uvDecodeMatrix = geometry.uvDecodeMatrix; - if (uvDecodeMatrix) { - geometryCompressionUtils.decompressUV(uva, uvDecodeMatrix, uva); - geometryCompressionUtils.decompressUV(uvb, uvDecodeMatrix, uvb); - geometryCompressionUtils.decompressUV(uvc, uvDecodeMatrix, uvc); - } - } - - pickResult.uv = math.addVec3( - math.addVec3( - math.mulVec2Scalar(uva, bary[0], tempVec3g), - math.mulVec2Scalar(uvb, bary[1], tempVec3h), tempVec3i), - math.mulVec2Scalar(uvc, bary[2], tempVec3j), tempVec3k); - } - } - } - } -})(); - -const instantiateMeshRenderer = (mesh, attributes, auxVariables, programSetup, programVariablesState) => { - const programVariables = programVariablesState.programVariables; - const decodedUv = auxVariables.decodedUv; - const worldNormal = auxVariables.worldNormal; - const viewNormal = auxVariables.viewNormal; - const scene = mesh.scene; - const gl = scene.canvas.gl; - const meshStateBackground = mesh._state.background; - const geometryState = mesh._geometry._state; - const quantizedGeometry = geometryState.compressGeometry; - const isPoints = geometryState.primitiveName === "points"; - - const pointSize = programVariables.createUniform("float", "pointSize"); - const modelMatrix = programVariables.createUniform("mat4", "modelMatrix"); - const modelNormalMatrix = programVariables.createUniform("mat4", "modelNormalMatrix"); - const offset = programVariables.createUniform("vec3", "offset"); - const scale = programVariables.createUniform("vec3", "scale"); - const positionsDecodeMatrix = programVariables.createUniform("mat4", "positionsDecodeMatrix"); - const uvDecodeMatrix = programVariables.createUniform("mat3", "uvDecodeMatrix"); - const viewMatrix = programVariables.createUniform("mat4", "viewMatrix"); - const viewNormalMatrix = programVariables.createUniform("mat4", "viewNormalMatrix"); - const projMatrix = programVariables.createUniform("mat4", "projMatrix"); - - const billboard = mesh.billboard; - const isBillboard = (billboard === "spherical") || (billboard === "cylindrical"); - const stationary = mesh.stationary; - const defineBillboard = isBillboard && ((name, src) => [ - `mat4 ${name}(in mat4 matIn) {`, - " mat4 mat = matIn;", - ` mat[0].xyz = vec3(${scale}[0], 0.0, 0.0);`, - ...((billboard === "spherical") ? [ ` mat[1].xyz = vec3(0.0, ${scale}[1], 0.0);` ] : [ ]), - " mat[2].xyz = vec3(0.0, 0.0, 1.0);", - " return mat;", - "}", - ].forEach(l => src.push(l))); - - const billboardIfApplicable = (function() { - const billboardVert = defineBillboard && programVariables.createVertexDefinition("billboard", defineBillboard); - return v => billboardVert ? `${billboardVert}(${v})` : v; - })(); - - const billboardIfApplicableFrag = (function() { - const billboardFrag = defineBillboard && programVariables.createFragmentDefinition("billboard", defineBillboard); - return v => billboardFrag ? `${billboardFrag}(${v})` : v; - })(); - - const fragmentOutputsSetup = [ ]; - fragmentOutputsSetup.push(`mat4 viewMatrix1 = ${viewMatrix};`); - if (stationary) { - fragmentOutputsSetup.push("viewMatrix1[3].xyz = vec3(0.0, 0.0, 0.0);"); - } else if (meshStateBackground) { - fragmentOutputsSetup.push("viewMatrix1[3] = vec4(0.0, 0.0, 0.0, 1.0);"); - } - fragmentOutputsSetup.push(`mat4 viewMatrix2 = ${billboardIfApplicableFrag("viewMatrix1")};`); - - const clipPos = "clipPos"; - const getVertexData = function() { - const viewNormalDefinition = viewNormal && viewNormal.needed && `vec3 ${viewNormal} = normalize((${billboardIfApplicable(viewNormalMatrix)} * vec4(${worldNormal}, 0.0)).xyz);`; - const src = [ ]; - src.push(`vec4 localPosition = vec4(${attributes.position}, 1.0);`); - if (quantizedGeometry) { - src.push(`localPosition = ${positionsDecodeMatrix} * localPosition;`); - } - src.push(`vec4 worldPosition = ${billboardIfApplicable(modelMatrix)} * localPosition;`); - src.push(`worldPosition.xyz = worldPosition.xyz + ${offset};`); - src.push(`mat4 viewMatrix1 = ${viewMatrix};`); - if (stationary) { - src.push("viewMatrix1[3].xyz = vec3(0.0, 0.0, 0.0);"); - } else if (meshStateBackground) { - src.push("viewMatrix1[3] = vec4(0.0, 0.0, 0.0, 1.0);"); - } - src.push(`mat4 viewMatrix2 = ${billboardIfApplicable("viewMatrix1")};`); - src.push(`vec4 viewPosition = ${(isBillboard - ? `${billboardIfApplicable(`viewMatrix1 * ${modelMatrix}`)} * localPosition` - : "viewMatrix2 * worldPosition")};`); - decodedUv && decodedUv.needed && src.push(`vec2 ${decodedUv} = ${quantizedGeometry ? `(${uvDecodeMatrix} * vec3(${attributes.uv}, 1.0)).xy` : attributes.uv};`); - if (worldNormal && worldNormal.needed) { - const localNormal = quantizedGeometry ? `${programVariables.commonLibrary.octDecode}(${attributes.normal}.xy)` : attributes.normal; - src.push(`vec3 ${worldNormal} = (${billboardIfApplicable(modelNormalMatrix)} * vec4(${localNormal}, 0.0)).xyz;`); - } - viewNormalDefinition && src.push(viewNormalDefinition); - src.push(`vec4 ${clipPos} = ${projMatrix} * viewPosition;`); - return src; - }; - - const clippable = programVariables.createUniform("bool", "clippable"); - - const [ program, errors ] = programVariablesState.buildProgram( - gl, - programSetup.programName, - { - appendFragmentOutputs: (src, getGammaOutputExpression, gl_FragCoord, sliceColorOr) => { - fragmentOutputsSetup.forEach(line => src.push(line)); - programSetup.appendFragmentOutputs(src, getGammaOutputExpression, gl_FragCoord, sliceColorOr); - }, - clippableTest: () => clippable, - clippingCaps: programSetup.clippingCaps, - clipPos: meshStateBackground ? `${clipPos}.xyww` : clipPos, - crossSections: scene.crossSections, - discardPoints: isPoints && programSetup.discardPoints, - getGammaFactor: scene.gammaOutput && (() => scene.gammaFactor), - getLogDepth: (! programSetup.dontGetLogDepth) && scene.logarithmicDepthBufferEnabled && (vFragDepth => vFragDepth), - getPointSize: programSetup.setupPointSize && isPoints && (() => pointSize), - getVertexData: getVertexData, - projMatrix: projMatrix, - sectionPlanesState: scene._sectionPlanesState, - testPerspectiveForGl_FragDepth: true, - usePickClipPos: programSetup.isPick, - worldPositionAttribute: "worldPosition" - }); - - if (errors) { - return { errors: errors }; - } else { - const inputSetters = program.inputSetters; - - let lastMaterialId = null; - let lastGeometryId = null; - - return { - destroy: () => program.destroy(), - drawMesh: (frameCtx, mesh, material) => { - if (programSetup.skipIfTransparent && (material.alpha < 1.0)) { - return; - } - - const materialState = material._state; - const meshState = mesh._state; - const geometry = mesh._geometry; - const geometryState = geometry._state; - const viewParams = frameCtx.viewParams; - const actsAsBackground = programSetup.canActAsBackground && meshStateBackground; - - if (frameCtx.lastProgramId !== program.id) { - frameCtx.lastProgramId = program.id; - program.bind(); - frameCtx.useProgram++; - lastMaterialId = null; - lastGeometryId = null; - if (actsAsBackground) { - gl.depthFunc(gl.LEQUAL); - } - } - - if (materialState.id !== lastMaterialId) { - if (frameCtx.backfaces !== materialState.backfaces) { - if (materialState.backfaces) { - gl.disable(gl.CULL_FACE); - } else { - gl.enable(gl.CULL_FACE); - } - frameCtx.backfaces = materialState.backfaces; - } - - if ((! programSetup.dontSetFrontFace) && (frameCtx.frontface !== materialState.frontface)) { - gl.frontFace(materialState.frontface ? gl.CCW : gl.CW); - frameCtx.frontface = materialState.frontface; - } - - if (programSetup.drawEdges && (frameCtx.lineWidth !== materialState.edgeWidth)) { - gl.lineWidth(materialState.edgeWidth); - frameCtx.lineWidth = materialState.edgeWidth; - } - - if (programSetup.setsLineWidth && (frameCtx.lineWidth !== materialState.lineWidth)) { - gl.lineWidth(materialState.lineWidth); - frameCtx.lineWidth = materialState.lineWidth; - } - - lastMaterialId = materialState.id; - } - - const setUniforms = (projMat, viewMat) => { - const setUni = (u, v) => (u.setInputValue && u.setInputValue(v)); - setUni(pointSize, material.pointSize); - setUni(modelMatrix, mesh.worldMatrix); - setUni(modelNormalMatrix, mesh.worldNormalMatrix); - setUni(offset, mesh.offset); - setUni(scale, mesh.scale); - setUni(positionsDecodeMatrix, geometryState.positionsDecodeMatrix); - setUni(uvDecodeMatrix, geometryState.uvDecodeMatrix); - setUni(viewMatrix, viewMat); - setUni(viewNormalMatrix, viewParams.viewNormalMatrix); - setUni(projMatrix, projMat); - setUni(clippable, mesh.clippable); - - inputSetters.setUniforms(frameCtx, { - material: material, - meshColorize: mesh.colorize, - meshPickID: mesh._state.pickID, - mesh: { - origin: mesh.origin, - renderFlags: { sectionPlanesActivePerLayer: mesh.renderFlags.sectionPlanesActivePerLayer } - }, - view: { far: viewParams.far } - }); - }; - - const origin = (! programSetup.useShadowView) && mesh.origin; - setUniforms(viewParams.projMatrix, origin ? frameCtx.getRTCViewMatrix(meshState.originHash, origin) : viewParams.viewMatrix); - - const setAttributes = (triangleGeometry) => { - const setAttr = (a, b) => { - if (a && a.setInputValue && b) { - a.setInputValue(b); - frameCtx.bindArray++; - } - }; - setAttr(attributes.position, (triangleGeometry || geometryState).positionsBuf); - setAttr(attributes.color, geometryState.colorsBuf); - setAttr(attributes.pickColor, triangleGeometry && triangleGeometry.pickColorsBuf); - setAttr(attributes.uv, geometryState.uvBuf); - setAttr(attributes.normal, geometryState.normalsBuf); - }; - - if (programSetup.trianglePick) { - const positionsBuf = geometry._getPickTrianglePositions(); - if (geometryState.id !== lastGeometryId) { - setAttributes({ positionsBuf: positionsBuf, pickColorsBuf: geometry._getPickTriangleColors() }); - lastGeometryId = geometryState.id; - } - - gl.drawArrays(geometryState.primitive, 0, positionsBuf.numItems / 3); - } else if (programSetup.drawEdges) { - const indicesBuf = ((geometryState.primitive === gl.TRIANGLES) - ? geometry._getEdgeIndices() - : ((geometryState.primitive === gl.LINES) && geometryState.indicesBuf)); - - if (indicesBuf) { - if (geometryState.id !== lastGeometryId) { - setAttributes(); - - indicesBuf.bind(); - frameCtx.bindArray++; - lastGeometryId = geometryState.id; - } - - gl.drawElements(gl.LINES, indicesBuf.numItems, indicesBuf.itemType, 0); - - frameCtx.drawElements++; - } - } else { - if (geometryState.id !== lastGeometryId) { - setAttributes(); - - if (geometryState.indicesBuf) { - geometryState.indicesBuf.bind(); - frameCtx.bindArray++; - } - lastGeometryId = geometryState.id; - } - - if (geometryState.indicesBuf) { - gl.drawElements(geometryState.primitive, geometryState.indicesBuf.numItems, geometryState.indicesBuf.itemType, 0); - frameCtx.drawElements++; - } else if (geometryState.positionsBuf) { - gl.drawArrays(gl.TRIANGLES, 0, geometryState.positionsBuf.numItems); - frameCtx.drawArrays++; - } - } - - if (actsAsBackground) { - gl.depthFunc(gl.LESS); - } - } - }; - } -}; - -/** - * @desc A **Material** defines the surface appearance of attached {@link Mesh}es. - * - * Material is the base class for: - * - * * {@link MetallicMaterial} - physically-based material for metallic surfaces. Use this one for things made of metal. - * * {@link SpecularMaterial} - physically-based material for non-metallic (dielectric) surfaces. Use this one for insulators, such as ceramics, plastics, wood etc. - * * {@link PhongMaterial} - material for classic Blinn-Phong shading. This is less demanding of graphics hardware than the physically-based materials. - * * {@link LambertMaterial} - material for fast, flat-shaded CAD rendering without textures. Use this for navigating huge CAD or BIM models interactively. This material gives the best rendering performance and uses the least memory. - * * {@link EmphasisMaterial} - defines the appearance of Meshes when "xrayed" or "highlighted". - * * {@link EdgeMaterial} - defines the appearance of Meshes when edges are emphasized. - * - * A {@link Scene} is allowed to contain a mixture of these material types. - * - */ - -class Material extends Component { - - /** - @private - */ - get type() { - return "Material"; - } - - constructor(owner, cfg={}) { - super(owner, cfg); - stats.memory.materials++; - } - - destroy() { - super.destroy(); - stats.memory.materials--; - } -} - -const alphaModes$1 = {"opaque": 0, "mask": 1, "blend": 2}; -const alphaModeNames$1 = ["opaque", "mask", "blend"]; - -/** - * @desc Configures the normal rendered appearance of {@link Mesh}es using the non-physically-correct Blinn-Phong shading model. - * - * * Useful for non-realistic objects like gizmos. - * * {@link SpecularMaterial} is best for insulators, such as wood, ceramics and plastic. - * * {@link MetallicMaterial} is best for conductive materials, such as metal. - * * {@link LambertMaterial} is appropriate for high-detail models that need to render as efficiently as possible. - * - * ## Usage - * - * In the example below, we'll create a {@link Mesh} with a PhongMaterial with a diffuse {@link Texture} and a specular {@link Fresnel}, using a {@link buildTorusGeometry} to create the {@link Geometry}. - * - * [[Run this example](/examples/index.html#materials_PhongMaterial)] - * - * ```` javascript - * import {Viewer, Mesh, buildTorusGeometry, - * ReadableGeometry, PhongMaterial, Texture, Fresnel} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [0, 0, 5]; - * viewer.scene.camera.look = [0, 0, 0]; - * viewer.scene.camera.up = [0, 1, 0]; - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildTorusGeometry({ - * center: [0, 0, 0], - * radius: 1.5, - * tube: 0.5, - * radialSegments: 32, - * tubeSegments: 24, - * arc: Math.PI * 2.0 - * }), - * material: new PhongMaterial(viewer.scene, { - * ambient: [0.9, 0.3, 0.9], - * shininess: 30, - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }), - * specularFresnel: new Fresnel(viewer.scene, { - * leftColor: [1.0, 1.0, 1.0], - * rightColor: [0.0, 0.0, 0.0], - * power: 4 - * }) - * }) - * }); - * ```` - * - * ## PhongMaterial Properties - * - * The following table summarizes PhongMaterial properties: - * - * | Property | Type | Range | Default Value | Space | Description | - * |:--------:|:----:|:-----:|:-------------:|:-----:|:-----------:| - * | {@link PhongMaterial#ambient} | Array | [0, 1] for all components | [1,1,1,1] | linear | The RGB components of the ambient light reflected by the material. | - * | {@link PhongMaterial#diffuse} | Array | [0, 1] for all components | [1,1,1,1] | linear | The RGB components of the diffuse light reflected by the material. | - * | {@link PhongMaterial#specular} | Array | [0, 1] for all components | [1,1,1,1] | linear | The RGB components of the specular light reflected by the material. | - * | {@link PhongMaterial#emissive} | Array | [0, 1] for all components | [0,0,0] | linear | The RGB components of the light emitted by the material. | - * | {@link PhongMaterial#alpha} | Number | [0, 1] | 1 | linear | The transparency of the material surface (0 fully transparent, 1 fully opaque). | - * | {@link PhongMaterial#shininess} | Number | [0, 128] | 80 | linear | Determines the size and sharpness of specular highlights. | - * | {@link PhongMaterial#reflectivity} | Number | [0, 1] | 1 | linear | Determines the amount of reflectivity. | - * | {@link PhongMaterial#diffuseMap} | {@link Texture} | | null | sRGB | Texture RGB components multiplying by {@link PhongMaterial#diffuse}. If the fourth component (A) is present, it multiplies by {@link PhongMaterial#alpha}. | - * | {@link PhongMaterial#specularMap} | {@link Texture} | | null | sRGB | Texture RGB components multiplying by {@link PhongMaterial#specular}. If the fourth component (A) is present, it multiplies by {@link PhongMaterial#alpha}. | - * | {@link PhongMaterial#emissiveMap} | {@link Texture} | | null | linear | Texture with RGB components multiplying by {@link PhongMaterial#emissive}. | - * | {@link PhongMaterial#alphaMap} | {@link Texture} | | null | linear | Texture with first component multiplying by {@link PhongMaterial#alpha}. | - * | {@link PhongMaterial#occlusionMap} | {@link Texture} | | null | linear | Ambient occlusion texture multiplying by {@link PhongMaterial#ambient}, {@link PhongMaterial#diffuse} and {@link PhongMaterial#specular}. | - * | {@link PhongMaterial#normalMap} | {@link Texture} | | null | linear | Tangent-space normal map. | - * | {@link PhongMaterial#diffuseFresnel} | {@link Fresnel} | | null | | Fresnel term applied to {@link PhongMaterial#diffuse}. | - * | {@link PhongMaterial#specularFresnel} | {@link Fresnel} | | null | | Fresnel term applied to {@link PhongMaterial#specular}. | - * | {@link PhongMaterial#emissiveFresnel} | {@link Fresnel} | | null | | Fresnel term applied to {@link PhongMaterial#emissive}. | - * | {@link PhongMaterial#reflectivityFresnel} | {@link Fresnel} | | null | | Fresnel term applied to {@link PhongMaterial#reflectivity}. | - * | {@link PhongMaterial#alphaFresnel} | {@link Fresnel} | | null | | Fresnel term applied to {@link PhongMaterial#alpha}. | - * | {@link PhongMaterial#lineWidth} | Number | [0..100] | 1 | | Line width in pixels. | - * | {@link PhongMaterial#pointSize} | Number | [0..100] | 1 | | Point size in pixels. | - * | {@link PhongMaterial#alphaMode} | String | "opaque", "blend", "mask" | "blend" | | Alpha blend mode. | - * | {@link PhongMaterial#alphaCutoff} | Number | [0..1] | 0.5 | | Alpha cutoff value. | - * | {@link PhongMaterial#backfaces} | Boolean | | false | | Whether to render geometry backfaces. | - * | {@link PhongMaterial#frontface} | String | "ccw", "cw" | "ccw" | | The winding order for geometry frontfaces - "cw" for clockwise, or "ccw" for counter-clockwise. | - */ -class PhongMaterial extends Material { - - /** - @private - */ - get type() { - return "PhongMaterial"; - } - - /** - * @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - * @param {*} [cfg] The PhongMaterial configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.ambient=[1.0, 1.0, 1.0 ]] PhongMaterial ambient color. - * @param {Number[]} [cfg.diffuse=[ 1.0, 1.0, 1.0 ]] PhongMaterial diffuse color. - * @param {Number[]} [cfg.specular=[ 1.0, 1.0, 1.0 ]] PhongMaterial specular color. - * @param {Number[]} [cfg.emissive=[ 0.0, 0.0, 0.0 ]] PhongMaterial emissive color. - * @param {Number} [cfg.alpha=1] Scalar in range 0-1 that controls alpha, where 0 is completely transparent and 1 is completely opaque. - * @param {Number} [cfg.shininess=80] Scalar in range 0-128 that determines the size and sharpness of specular highlights. - * @param {Number} [cfg.reflectivity=1] Scalar in range 0-1 that controls how much {@link ReflectionMap} is reflected. - * @param {Number} [cfg.lineWidth=1] Scalar that controls the width of lines. - * @param {Number} [cfg.pointSize=1] Scalar that controls the size of points. - * @param {Texture} [cfg.ambientMap=null] A ambient map {@link Texture}, which will multiply by the diffuse property. Must be within the same {@link Scene} as this PhongMaterial. - * @param {Texture} [cfg.diffuseMap=null] A diffuse map {@link Texture}, which will override the effect of the diffuse property. Must be within the same {@link Scene} as this PhongMaterial. - * @param {Texture} [cfg.specularMap=null] A specular map {@link Texture}, which will override the effect of the specular property. Must be within the same {@link Scene} as this PhongMaterial. - * @param {Texture} [cfg.emissiveMap=undefined] An emissive map {@link Texture}, which will override the effect of the emissive property. Must be within the same {@link Scene} as this PhongMaterial. - * @param {Texture} [cfg.normalMap=undefined] A normal map {@link Texture}. Must be within the same {@link Scene} as this PhongMaterial. - * @param {Texture} [cfg.alphaMap=undefined] An alpha map {@link Texture}, which will override the effect of the alpha property. Must be within the same {@link Scene} as this PhongMaterial. - * @param {Texture} [cfg.reflectivityMap=undefined] A reflectivity control map {@link Texture}, which will override the effect of the reflectivity property. Must be within the same {@link Scene} as this PhongMaterial. - * @param {Texture} [cfg.occlusionMap=null] An occlusion map {@link Texture}. Must be within the same {@link Scene} as this PhongMaterial. - * @param {Fresnel} [cfg.diffuseFresnel=undefined] A diffuse {@link Fresnel"}}Fresnel{{/crossLink}}. Must be within the same {@link Scene} as this PhongMaterial. - * @param {Fresnel} [cfg.specularFresnel=undefined] A specular {@link Fresnel"}}Fresnel{{/crossLink}}. Must be within the same {@link Scene} as this PhongMaterial. - * @param {Fresnel} [cfg.emissiveFresnel=undefined] An emissive {@link Fresnel"}}Fresnel{{/crossLink}}. Must be within the same {@link Scene} as this PhongMaterial. - * @param {Fresnel} [cfg.alphaFresnel=undefined] An alpha {@link Fresnel"}}Fresnel{{/crossLink}}. Must be within the same {@link Scene} as this PhongMaterial. - * @param {Fresnel} [cfg.reflectivityFresnel=undefined] A reflectivity {@link Fresnel"}}Fresnel{{/crossLink}}. Must be within the same {@link Scene} as this PhongMaterial. - * @param {String} [cfg.alphaMode="opaque"] The alpha blend mode - accepted values are "opaque", "blend" and "mask". See the {@link PhongMaterial#alphaMode} property for more info. - * @param {Number} [cfg.alphaCutoff=0.5] The alpha cutoff value. See the {@link PhongMaterial#alphaCutoff} property for more info. - * @param {Boolean} [cfg.backfaces=false] Whether to render geometry backfaces. - * @param {Boolean} [cfg.frontface="ccw"] The winding order for geometry front faces - "cw" for clockwise, or "ccw" for counter-clockwise. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._state = new RenderState({ - type: "PhongMaterial", - ambient: math.vec3([1.0, 1.0, 1.0]), - diffuse: math.vec3([1.0, 1.0, 1.0]), - specular: math.vec3([1.0, 1.0, 1.0]), - emissive: math.vec3([0.0, 0.0, 0.0]), - alpha: null, - shininess: null, - reflectivity: null, - alphaMode: null, - alphaCutoff: null, - lineWidth: null, - pointSize: null, - backfaces: null, - frontface: null, // Boolean for speed; true == "ccw", false == "cw" - hash: null - }); - - this.ambient = cfg.ambient; - this.diffuse = cfg.diffuse; - this.specular = cfg.specular; - this.emissive = cfg.emissive; - this.alpha = cfg.alpha; - this.shininess = cfg.shininess; - this.reflectivity = cfg.reflectivity; - this.lineWidth = cfg.lineWidth; - this.pointSize = cfg.pointSize; - - if (cfg.ambientMap) { - this._ambientMap = this._checkComponent("Texture", cfg.ambientMap); - } - if (cfg.diffuseMap) { - this._diffuseMap = this._checkComponent("Texture", cfg.diffuseMap); - } - if (cfg.specularMap) { - this._specularMap = this._checkComponent("Texture", cfg.specularMap); - } - if (cfg.emissiveMap) { - this._emissiveMap = this._checkComponent("Texture", cfg.emissiveMap); - } - if (cfg.alphaMap) { - this._alphaMap = this._checkComponent("Texture", cfg.alphaMap); - } - if (cfg.reflectivityMap) { - this._reflectivityMap = this._checkComponent("Texture", cfg.reflectivityMap); - } - if (cfg.normalMap) { - this._normalMap = this._checkComponent("Texture", cfg.normalMap); - } - if (cfg.occlusionMap) { - this._occlusionMap = this._checkComponent("Texture", cfg.occlusionMap); - } - if (cfg.diffuseFresnel) { - this._diffuseFresnel = this._checkComponent("Fresnel", cfg.diffuseFresnel); - } - if (cfg.specularFresnel) { - this._specularFresnel = this._checkComponent("Fresnel", cfg.specularFresnel); - } - if (cfg.emissiveFresnel) { - this._emissiveFresnel = this._checkComponent("Fresnel", cfg.emissiveFresnel); - } - if (cfg.alphaFresnel) { - this._alphaFresnel = this._checkComponent("Fresnel", cfg.alphaFresnel); - } - if (cfg.reflectivityFresnel) { - this._reflectivityFresnel = this._checkComponent("Fresnel", cfg.reflectivityFresnel); - } - - this.alphaMode = cfg.alphaMode; - this.alphaCutoff = cfg.alphaCutoff; - this.backfaces = cfg.backfaces; - this.frontface = cfg.frontface; - - this._makeHash(); - } - - _makeHash() { - const state = this._state; - const hash = ["/p"]; // 'P' for Phong - if (this._normalMap) { - hash.push("/nm"); - if (this._normalMap.hasMatrix) { - hash.push("/mat"); - } - } - if (this._ambientMap) { - hash.push("/am"); - if (this._ambientMap.hasMatrix) { - hash.push("/mat"); - } - hash.push("/" + this._ambientMap.encoding); - } - if (this._diffuseMap) { - hash.push("/dm"); - if (this._diffuseMap.hasMatrix) { - hash.push("/mat"); - } - hash.push("/" + this._diffuseMap.encoding); - } - if (this._specularMap) { - hash.push("/sm"); - if (this._specularMap.hasMatrix) { - hash.push("/mat"); - } - } - if (this._emissiveMap) { - hash.push("/em"); - if (this._emissiveMap.hasMatrix) { - hash.push("/mat"); - } - hash.push("/" + this._emissiveMap.encoding); - } - if (this._alphaMap) { - hash.push("/opm"); - if (this._alphaMap.hasMatrix) { - hash.push("/mat"); - } - } - if (this._reflectivityMap) { - hash.push("/rm"); - if (this._reflectivityMap.hasMatrix) { - hash.push("/mat"); - } - } - if (this._occlusionMap) { - hash.push("/ocm"); - if (this._occlusionMap.hasMatrix) { - hash.push("/mat"); - } - } - if (this._diffuseFresnel) { - hash.push("/df"); - } - if (this._specularFresnel) { - hash.push("/sf"); - } - if (this._emissiveFresnel) { - hash.push("/ef"); - } - if (this._alphaFresnel) { - hash.push("/of"); - } - if (this._reflectivityFresnel) { - hash.push("/rf"); - } - hash.push(";"); - state.hash = hash.join(""); - } - - /** - * Sets the PhongMaterial's ambient color. - * - * Default value is ````[0.3, 0.3, 0.3]````. - * - * @type {Number[]} - */ - set ambient(value) { - let ambient = this._state.ambient; - if (!ambient) { - ambient = this._state.ambient = new Float32Array(3); - } else if (value && ambient[0] === value[0] && ambient[1] === value[1] && ambient[2] === value[2]) { - return; - } - if (value) { - ambient[0] = value[0]; - ambient[1] = value[1]; - ambient[2] = value[2]; - } else { - ambient[0] = .2; - ambient[1] = .2; - ambient[2] = .2; - } - this.glRedraw(); - } - - /** - * Gets the PhongMaterial's ambient color. - * - * Default value is ````[0.3, 0.3, 0.3]````. - * - * @type {Number[]} - */ - get ambient() { - return this._state.ambient; - } - - /** - * Sets the PhongMaterial's diffuse color. - * - * Multiplies by {@link PhongMaterial#diffuseMap}. - * - * Default value is ````[1.0, 1.0, 1.0]````. - * - * @type {Number[]} - */ - set diffuse(value) { - let diffuse = this._state.diffuse; - if (!diffuse) { - diffuse = this._state.diffuse = new Float32Array(3); - } else if (value && diffuse[0] === value[0] && diffuse[1] === value[1] && diffuse[2] === value[2]) { - return; - } - if (value) { - diffuse[0] = value[0]; - diffuse[1] = value[1]; - diffuse[2] = value[2]; - } else { - diffuse[0] = 1; - diffuse[1] = 1; - diffuse[2] = 1; - } - this.glRedraw(); - } - - /** - * Sets the PhongMaterial's diffuse color. - * - * Multiplies by {@link PhongMaterial#diffuseMap}. - * - * Default value is ````[1.0, 1.0, 1.0]````. - * - * @type {Number[]} - */ - get diffuse() { - return this._state.diffuse; - } - - /** - * Sets the PhongMaterial's specular color. - * - * Multiplies by {@link PhongMaterial#specularMap}. - * Default value is ````[1.0, 1.0, 1.0]````. - * @type {Number[]} - */ - set specular(value) { - let specular = this._state.specular; - if (!specular) { - specular = this._state.specular = new Float32Array(3); - } else if (value && specular[0] === value[0] && specular[1] === value[1] && specular[2] === value[2]) { - return; - } - if (value) { - specular[0] = value[0]; - specular[1] = value[1]; - specular[2] = value[2]; - } else { - specular[0] = 1; - specular[1] = 1; - specular[2] = 1; - } - this.glRedraw(); - } - - /** - * Gets the PhongMaterial's specular color. - * - * Multiplies by {@link PhongMaterial#specularMap}. - * Default value is ````[1.0, 1.0, 1.0]````. - * @type {Number[]} - */ - get specular() { - return this._state.specular; - } - - /** - * Sets the PhongMaterial's emissive color. - * - * Multiplies by {@link PhongMaterial#emissiveMap}. - * - * Default value is ````[0.0, 0.0, 0.0]````. - * @type {Number[]} - */ - set emissive(value) { - let emissive = this._state.emissive; - if (!emissive) { - emissive = this._state.emissive = new Float32Array(3); - } else if (value && emissive[0] === value[0] && emissive[1] === value[1] && emissive[2] === value[2]) { - return; - } - if (value) { - emissive[0] = value[0]; - emissive[1] = value[1]; - emissive[2] = value[2]; - } else { - emissive[0] = 0; - emissive[1] = 0; - emissive[2] = 0; - } - this.glRedraw(); - } - - /** - * Gets the PhongMaterial's emissive color. - * - * Multiplies by {@link PhongMaterial#emissiveMap}. - * - * Default value is ````[0.0, 0.0, 0.0]````. - * @type {Number[]} - */ - get emissive() { - return this._state.emissive; - } - - /** - * Sets the PhongMaterial alpha. - * - * This is a factor in the range [0..1] indicating how transparent the PhongMaterial is. - * - * A value of 0.0 indicates fully transparent, 1.0 is fully opaque. - * - * Multiplies by {@link PhongMaterial#alphaMap}. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - set alpha(value) { - value = (value !== undefined && value !== null) ? value : 1.0; - if (this._state.alpha === value) { - return; - } - this._state.alpha = value; - this.glRedraw(); - } - - /** - * Gets the PhongMaterial alpha. - * - * This is a factor in the range [0..1] indicating how transparent the PhongMaterial is. - * - * A value of 0.0 indicates fully transparent, 1.0 is fully opaque. - * - * Multiplies by {@link PhongMaterial#alphaMap}. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - get alpha() { - return this._state.alpha; - } - - /** - * Sets the PhongMaterial shininess. - * - * This is a factor in range [0..128] that determines the size and sharpness of the specular highlights create by this PhongMaterial. - * - * Larger values produce smaller, sharper highlights. A value of 0.0 gives very large highlights that are almost never - * desirable. Try values close to 10 for a larger, fuzzier highlight and values of 100 or more for a small, sharp - * highlight. - * - * Default value is ```` 80.0````. - * - * @type {Number} - */ - set shininess(value) { - this._state.shininess = value !== undefined ? value : 80; - this.glRedraw(); - } - - /** - * Gets the PhongMaterial shininess. - * - * This is a factor in range [0..128] that determines the size and sharpness of the specular highlights create by this PhongMaterial. - * - * Larger values produce smaller, sharper highlights. A value of 0.0 gives very large highlights that are almost never - * desirable. Try values close to 10 for a larger, fuzzier highlight and values of 100 or more for a small, sharp - * highlight. - * - * Default value is ```` 80.0````. - * - * @type {Number} - */ - get shininess() { - return this._state.shininess; - } - - /** - * Sets the PhongMaterial's line width. - * - * This is not supported by WebGL implementations based on DirectX [2019]. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - set lineWidth(value) { - this._state.lineWidth = value || 1.0; - this.glRedraw(); - } - - /** - * Gets the PhongMaterial's line width. - * - * This is not supported by WebGL implementations based on DirectX [2019]. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - get lineWidth() { - return this._state.lineWidth; - } - - /** - * Sets the PhongMaterial's point size. - * - * Default value is 1.0. - * - * @type {Number} - */ - set pointSize(value) { - this._state.pointSize = value || 1.0; - this.glRedraw(); - } - - /** - * Gets the PhongMaterial's point size. - * - * Default value is 1.0. - * - * @type {Number} - */ - get pointSize() { - return this._state.pointSize; - } - - /** - * Sets how much {@link ReflectionMap} is reflected by this PhongMaterial. - * - * This is a scalar in range ````[0-1]````. Default value is ````1.0````. - * - * The surface will be non-reflective when this is ````0````, and completely mirror-like when it is ````1.0````. - * - * Multiplies by {@link PhongMaterial#reflectivityMap}. - * - * @type {Number} - */ - set reflectivity(value) { - this._state.reflectivity = value !== undefined ? value : 1.0; - this.glRedraw(); - } - - /** - * Gets how much {@link ReflectionMap} is reflected by this PhongMaterial. - * - * This is a scalar in range ````[0-1]````. Default value is ````1.0````. - * - * The surface will be non-reflective when this is ````0````, and completely mirror-like when it is ````1.0````. - * - * Multiplies by {@link PhongMaterial#reflectivityMap}. - * - * @type {Number} - */ - get reflectivity() { - return this._state.reflectivity; - } - - /** - * Gets the PhongMaterials's normal map {@link Texture}. - * - * @type {Texture} - */ - get normalMap() { - return this._normalMap; - } - - /** - * Gets the PhongMaterials's ambient {@link Texture}. - * - * Multiplies by {@link PhongMaterial#ambient}. - * - * @type {Texture} - */ - get ambientMap() { - return this._ambientMap; - } - - /** - * Gets the PhongMaterials's diffuse {@link Texture}. - * - * Multiplies by {@link PhongMaterial#diffuse}. - * - * @type {Texture} - */ - get diffuseMap() { - return this._diffuseMap; - } - - /** - * Gets the PhongMaterials's specular {@link Texture}. - * - * Multiplies by {@link PhongMaterial#specular}. - * - * @type {Texture} - */ - get specularMap() { - return this._specularMap; - } - - /** - * Gets the PhongMaterials's emissive {@link Texture}. - * - * Multiplies by {@link PhongMaterial#emissive}. - * - * @type {Texture} - */ - get emissiveMap() { - return this._emissiveMap; - } - - /** - * Gets the PhongMaterials's alpha {@link Texture}. - * - * Multiplies by {@link PhongMaterial#alpha}. - * - * @type {Texture} - */ - get alphaMap() { - return this._alphaMap; - } - - /** - * Gets the PhongMaterials's reflectivity {@link Texture}. - * - * Multiplies by {@link PhongMaterial#reflectivity}. - * - * @type {Texture} - */ - get reflectivityMap() { - return this._reflectivityMap; - } - - /** - * Gets the PhongMaterials's ambient occlusion {@link Texture}. - * - * @type {Texture} - */ - get occlusionMap() { - return this._occlusionMap; - } - - /** - * Gets the PhongMaterials's diffuse {@link Fresnel}. - * - * Applies to {@link PhongMaterial#diffuse}. - * - * @type {Fresnel} - */ - get diffuseFresnel() { - return this._diffuseFresnel; - } - - /** - * Gets the PhongMaterials's specular {@link Fresnel}. - * - * Applies to {@link PhongMaterial#specular}. - * - * @type {Fresnel} - */ - get specularFresnel() { - return this._specularFresnel; - } - - /** - * Gets the PhongMaterials's emissive {@link Fresnel}. - * - * Applies to {@link PhongMaterial#emissive}. - * - * @type {Fresnel} - */ - get emissiveFresnel() { - return this._emissiveFresnel; - } - - /** - * Gets the PhongMaterials's alpha {@link Fresnel}. - * - * Applies to {@link PhongMaterial#alpha}. - * - * @type {Fresnel} - */ - get alphaFresnel() { - return this._alphaFresnel; - } - - /** - * Gets the PhongMaterials's reflectivity {@link Fresnel}. - * - * Applies to {@link PhongMaterial#reflectivity}. - * - * @type {Fresnel} - */ - get reflectivityFresnel() { - return this._reflectivityFresnel; - } - - /** - * Sets the PhongMaterial's alpha rendering mode. - * - * This governs how alpha is treated. Alpha is the combined result of {@link PhongMaterial#alpha} and {@link PhongMaterial#alphaMap}. - * - * Supported values are: - * - * * "opaque" - The alpha value is ignored and the rendered output is fully opaque (default). - * * "mask" - The rendered output is either fully opaque or fully transparent depending on the alpha value and the specified alpha cutoff value. - * * "blend" - The alpha value is used to composite the source and destination areas. The rendered output is combined with the background using the normal painting operation (i.e. the Porter and Duff over operator). - * - *@type {String} - */ - set alphaMode(alphaMode) { - alphaMode = alphaMode || "opaque"; - let value = alphaModes$1[alphaMode]; - if (value === undefined) { - this.error("Unsupported value for 'alphaMode': " + alphaMode + " - defaulting to 'opaque'"); - value = "opaque"; - } - if (this._state.alphaMode === value) { - return; - } - this._state.alphaMode = value; - this.glRedraw(); - } - - /** - * Gets the PhongMaterial's alpha rendering mode. - * - *@type {String} - */ - get alphaMode() { - return alphaModeNames$1[this._state.alphaMode]; - } - - /** - * Sets the PhongMaterial's alpha cutoff value. - * - * This specifies the cutoff threshold when {@link PhongMaterial#alphaMode} equals "mask". If the alpha is greater than or equal to this value then it is rendered as fully - * opaque, otherwise, it is rendered as fully transparent. A value greater than 1.0 will render the entire material as fully transparent. This value is ignored for other modes. - * - * Alpha is the combined result of {@link PhongMaterial#alpha} and {@link PhongMaterial#alphaMap}. - * - * Default value is ````0.5````. - * - * @type {Number} - */ - set alphaCutoff(alphaCutoff) { - if (alphaCutoff === null || alphaCutoff === undefined) { - alphaCutoff = 0.5; - } - if (this._state.alphaCutoff === alphaCutoff) { - return; - } - this._state.alphaCutoff = alphaCutoff; - } - - /** - * Gets the PhongMaterial's alpha cutoff value. - * - * @type {Number} - */ - get alphaCutoff() { - return this._state.alphaCutoff; - } - - /** - * Sets whether backfaces are visible on attached {@link Mesh}es. - * - * The backfaces will belong to {@link Geometry} compoents that are also attached to the {@link Mesh}es. - * - * Default is ````false````. - * - * @type {Boolean} - */ - set backfaces(value) { - value = !!value; - if (this._state.backfaces === value) { - return; - } - this._state.backfaces = value; - this.glRedraw(); - } - - /** - * Gets whether backfaces are visible on attached {@link Mesh}es. - * - * Default is ````false````. - * - * @type {Boolean} - */ - get backfaces() { - return this._state.backfaces; - } - - /** - * Sets the winding direction of geometry front faces. - * - * Default is ````"ccw"````. - * @type {String} - */ - set frontface(value) { - value = value !== "cw"; - if (this._state.frontface === value) { - return; - } - this._state.frontface = value; - this.glRedraw(); - } - - /** - * Gets the winding direction of front faces on attached {@link Mesh}es. - * - * Default is ````"ccw"````. - * @type {String} - */ - get frontface() { - return this._state.frontface ? "ccw" : "cw"; - } - - /** - * Destroys this PhongMaterial. - */ - destroy() { - super.destroy(); - this._state.destroy(); - } -} - -/** - * @private - */ -function getExtension (gl, name) { - if (gl._cachedExtensions === undefined) { - gl._cachedExtensions = {}; - } - if (gl._cachedExtensions[name] !== undefined) { - return gl._cachedExtensions[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); - } - gl._cachedExtensions[name] = extension; - return extension; -} - -/** - * @private - */ -function convertConstant(gl, constantVal, encoding = null) { - - let extension; - const p = constantVal; - - if (p === UnsignedByteType) return gl.UNSIGNED_BYTE; - if (p === UnsignedShort4444Type) return gl.UNSIGNED_SHORT_4_4_4_4; - if (p === UnsignedShort5551Type) return gl.UNSIGNED_SHORT_5_5_5_1; - - if (p === ByteType) return gl.BYTE; - if (p === ShortType) return gl.SHORT; - if (p === UnsignedShortType) return gl.UNSIGNED_SHORT; - if (p === IntType) return gl.INT; - if (p === UnsignedIntType) return gl.UNSIGNED_INT; - if (p === FloatType) return gl.FLOAT; - - if (p === HalfFloatType) { - return gl.HALF_FLOAT; - } - - if (p === AlphaFormat) return gl.ALPHA; - if (p === RGBAFormat) return gl.RGBA; - if (p === LuminanceFormat) return gl.LUMINANCE; - if (p === LuminanceAlphaFormat) return gl.LUMINANCE_ALPHA; - if (p === DepthFormat) return gl.DEPTH_COMPONENT; - if (p === DepthStencilFormat) return gl.DEPTH_STENCIL; - if (p === RedFormat) return gl.RED; - - if (p === RGBFormat) { - return gl.RGBA; - } - - // WebGL2 formats. - - if (p === RedIntegerFormat) return gl.RED_INTEGER; - if (p === RGFormat) return gl.RG; - if (p === RGIntegerFormat) return gl.RG_INTEGER; - if (p === RGBAIntegerFormat) return gl.RGBA_INTEGER; - - // S3TC - - if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) { - if (encoding === sRGBEncoding) { - const extension = getExtension(gl, '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 = getExtension(gl, '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; - } - } - } - - // PVRTC - - if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) { - const extension = getExtension(gl, '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; - } - } - - // ETC1 - - if (p === RGB_ETC1_Format) { - const extension = getExtension(gl, 'WEBGL_compressed_texture_etc1'); - if (extension !== null) { - return extension.COMPRESSED_RGB_ETC1_WEBGL; - } else { - return null; - } - } - - // ETC2 - - if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) { - const extension = getExtension(gl, '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; - } - } - - // ASTC - - 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) { - const extension = getExtension(gl, '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; - } - } - - // BPTC - - if (p === RGBA_BPTC_Format) { - const extension = getExtension(gl, '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) { - return gl.UNSIGNED_INT_24_8; - } - if (p === RepeatWrapping) { - return gl.REPEAT; - } - if (p === ClampToEdgeWrapping) { - return gl.CLAMP_TO_EDGE; - } - if (p === NearestMipMapNearestFilter) { - return gl.NEAREST_MIPMAP_LINEAR; - } - if (p === NearestMipMapLinearFilter) { - return gl.NEAREST_MIPMAP_LINEAR; - } - if (p === LinearMipMapNearestFilter) { - return gl.LINEAR_MIPMAP_NEAREST; - } - if (p === LinearMipMapLinearFilter) { - return gl.LINEAR_MIPMAP_LINEAR; - } - if (p === NearestFilter) { - return gl.NEAREST; - } - if (p === LinearFilter) { - return gl.LINEAR; - } - - return null; -} - -const color$4 = new Uint8Array([0, 0, 0, 1]); - -/** - * @desc A low-level component that represents a 2D WebGL texture. - * - * @private - */ -class Texture2D { - - constructor({gl, target, format, type, wrapS, wrapT, wrapR, encoding, preloadColor, premultiplyAlpha, flipY}) { - - this.gl = gl; - - this.target = target || gl.TEXTURE_2D; - this.format = format || RGBAFormat; - this.type = type || UnsignedByteType; - this.internalFormat = null; - this.premultiplyAlpha = !!premultiplyAlpha; - this.flipY = !!flipY; - this.unpackAlignment = 4; - this.wrapS = wrapS || RepeatWrapping; - this.wrapT = wrapT || RepeatWrapping; - this.wrapR = wrapR || RepeatWrapping; - this.encoding = encoding || sRGBEncoding; - this.texture = gl.createTexture(); - - if (preloadColor) { - this.setPreloadColor(preloadColor); // Prevents "there is no texture bound to the unit 0" error - } - - this.allocated = true; - } - - setPreloadColor(value) { - if (!value) { - color$4[0] = 0; - color$4[1] = 0; - color$4[2] = 0; - color$4[3] = 255; - } else { - color$4[0] = Math.floor(value[0] * 255); - color$4[1] = Math.floor(value[1] * 255); - color$4[2] = Math.floor(value[2] * 255); - color$4[3] = Math.floor((value[3] !== undefined ? value[3] : 1) * 255); - } - const gl = this.gl; - gl.bindTexture(this.target, this.texture); - if (this.target === gl.TEXTURE_CUBE_MAP) { - const faces = [ - gl.TEXTURE_CUBE_MAP_POSITIVE_X, - gl.TEXTURE_CUBE_MAP_NEGATIVE_X, - gl.TEXTURE_CUBE_MAP_POSITIVE_Y, - gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, - gl.TEXTURE_CUBE_MAP_POSITIVE_Z, - gl.TEXTURE_CUBE_MAP_NEGATIVE_Z - ]; - for (let i = 0, len = faces.length; i < len; i++) { - gl.texImage2D(faces[i], 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, color$4); - } - } else { - gl.texImage2D(this.target, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, color$4); - } - gl.bindTexture(this.target, null); - } - - setTarget(target) { - this.target = target || this.gl.TEXTURE_2D; - } - - setImage(image, props = {}) { - - const gl = this.gl; - - if (props.format !== undefined) { - this.format = props.format; - } - if (props.internalFormat !== undefined) { - this.internalFormat = props.internalFormat; - } - if (props.encoding !== undefined) { - this.encoding = props.encoding; - } - if (props.type !== undefined) { - this.type = props.type; - } - if (props.flipY !== undefined) { - this.flipY = props.flipY; - } - if (props.premultiplyAlpha !== undefined) { - this.premultiplyAlpha = props.premultiplyAlpha; - } - if (props.unpackAlignment !== undefined) { - this.unpackAlignment = props.unpackAlignment; - } - this.maxAnisotropy = props.maxAnisotropy; - if (props.minFilter !== undefined) { - this.minFilter = props.minFilter; - } - if (props.magFilter !== undefined) { - this.magFilter = props.magFilter; - } - if (props.wrapS !== undefined) { - this.wrapS = props.wrapS; - } - if (props.wrapT !== undefined) { - this.wrapT = props.wrapT; - } - if (props.wrapR !== undefined) { - this.wrapR = props.wrapR; - } - - let generateMipMap = false; - - gl.bindTexture(this.target, this.texture); - - const bak1 = gl.getParameter(gl.UNPACK_FLIP_Y_WEBGL); - gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this.flipY); - - const bak2 = gl.getParameter(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha); - - const bak3 = gl.getParameter(gl.UNPACK_ALIGNMENT); - gl.pixelStorei(gl.UNPACK_ALIGNMENT, this.unpackAlignment); - - const bak4 = gl.getParameter(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL); gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE); - - const anisoExt = this.maxAnisotropy && getExtension(gl, "EXT_texture_filter_anisotropic"); - if (anisoExt) { - const max = gl.getParameter(anisoExt.MAX_TEXTURE_MAX_ANISOTROPY_EXT); - gl.texParameterf(gl.TEXTURE_2D, anisoExt.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(max, this.maxAnisotropy)); - } - - const minFilter = convertConstant(gl, this.minFilter); - gl.texParameteri(this.target, gl.TEXTURE_MIN_FILTER, minFilter); - - if (minFilter === gl.NEAREST_MIPMAP_NEAREST - || minFilter === gl.LINEAR_MIPMAP_NEAREST - || minFilter === gl.NEAREST_MIPMAP_LINEAR - || minFilter === gl.LINEAR_MIPMAP_LINEAR) { - generateMipMap = true; - } - - const magFilter = convertConstant(gl, this.magFilter); - if (magFilter) { - gl.texParameteri(this.target, gl.TEXTURE_MAG_FILTER, magFilter); - } - - const wrapS = convertConstant(gl, this.wrapS); - if (wrapS) { - gl.texParameteri(this.target, gl.TEXTURE_WRAP_S, wrapS); - } - - const wrapT = convertConstant(gl, this.wrapT); - if (wrapT) { - gl.texParameteri(this.target, gl.TEXTURE_WRAP_T, wrapT); - } - - const glFormat = convertConstant(gl, this.format, this.encoding); - const glType = convertConstant(gl, this.type); - const glInternalFormat = getInternalFormat(gl, this.internalFormat, glFormat, glType, this.encoding, false); - - if (this.target === gl.TEXTURE_CUBE_MAP) { - if (utils.isArray(image)) { - const images = image; - const faces = [ - gl.TEXTURE_CUBE_MAP_POSITIVE_X, - gl.TEXTURE_CUBE_MAP_NEGATIVE_X, - gl.TEXTURE_CUBE_MAP_POSITIVE_Y, - gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, - gl.TEXTURE_CUBE_MAP_POSITIVE_Z, - gl.TEXTURE_CUBE_MAP_NEGATIVE_Z - ]; - for (let i = 0, len = faces.length; i < len; i++) { - gl.texImage2D(faces[i], 0, glInternalFormat, glFormat, glType, images[i]); - } - } - } else { - gl.texImage2D(gl.TEXTURE_2D, 0, glInternalFormat, glFormat, glType, image); - } - - if (generateMipMap) { - gl.generateMipmap(this.target); - } - - gl.bindTexture(this.target, null); - - gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, bak1); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, bak2); - gl.pixelStorei(gl.UNPACK_ALIGNMENT, bak3); - gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, bak4); - } - - setCompressedData({mipmaps, props = {}}) { - - const gl = this.gl; - const levels = mipmaps.length; - - // Cache props - - if (props.format !== undefined) { - this.format = props.format; - } - if (props.internalFormat !== undefined) { - this.internalFormat = props.internalFormat; - } - if (props.encoding !== undefined) { - this.encoding = props.encoding; - } - if (props.type !== undefined) { - this.type = props.type; - } - if (props.flipY !== undefined) { - this.flipY = props.flipY; - } - if (props.premultiplyAlpha !== undefined) { - this.premultiplyAlpha = props.premultiplyAlpha; - } - if (props.unpackAlignment !== undefined) { - this.unpackAlignment = props.unpackAlignment; - } - if (props.minFilter !== undefined) { - this.minFilter = props.minFilter; - } - if (props.magFilter !== undefined) { - this.magFilter = props.magFilter; - } - if (props.wrapS !== undefined) { - this.wrapS = props.wrapS; - } - if (props.wrapT !== undefined) { - this.wrapT = props.wrapT; - } - if (props.wrapR !== undefined) { - this.wrapR = props.wrapR; - } - - gl.activeTexture(gl.TEXTURE0 + 0); - gl.bindTexture(this.target, this.texture); - - let supportsMips = mipmaps.length > 1; - - gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this.flipY); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha); - gl.pixelStorei(gl.UNPACK_ALIGNMENT, this.unpackAlignment); - gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE); - - const wrapS = convertConstant(gl, this.wrapS); - if (wrapS) { - gl.texParameteri(this.target, gl.TEXTURE_WRAP_S, wrapS); - } - - const wrapT = convertConstant(gl, this.wrapT); - if (wrapT) { - gl.texParameteri(this.target, gl.TEXTURE_WRAP_T, wrapT); - } - - if (this.type === gl.TEXTURE_3D || this.type === gl.TEXTURE_2D_ARRAY) { - const wrapR = convertConstant(gl, this.wrapR); - if (wrapR) { - gl.texParameteri(this.target, gl.TEXTURE_WRAP_R, wrapR); - } - gl.texParameteri(this.type, gl.TEXTURE_WRAP_R, wrapR); - } - - if (supportsMips) { - gl.texParameteri(this.target, gl.TEXTURE_MIN_FILTER, filterFallback(gl, this.minFilter)); - gl.texParameteri(this.target, gl.TEXTURE_MAG_FILTER, filterFallback(gl, this.magFilter)); - - } else { - gl.texParameteri(this.target, gl.TEXTURE_MIN_FILTER, convertConstant(gl, this.minFilter)); - gl.texParameteri(this.target, gl.TEXTURE_MAG_FILTER, convertConstant(gl, this.magFilter)); - } - - const glFormat = convertConstant(gl, this.format, this.encoding); - const glType = convertConstant(gl, this.type); - const glInternalFormat = getInternalFormat(gl, this.internalFormat, glFormat, glType, this.encoding, false); - - gl.texStorage2D(gl.TEXTURE_2D, levels, glInternalFormat, mipmaps[0].width, mipmaps[0].height); - - for (let i = 0, len = mipmaps.length; i < len; i++) { - - const mipmap = mipmaps[i]; - - if (this.format !== RGBAFormat) { - if (glFormat !== null) { - gl.compressedTexSubImage2D(gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data); - } else { - console.warn('Attempt to load unsupported compressed texture format in .setCompressedData()'); - } - } else { - gl.texSubImage2D(gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data); - } - } - - // if (generateMipMap) { - // // gl.generateMipmap(this.target); // Only for roughness textures? - // } - - gl.bindTexture(this.target, null); - } - - setProps(props) { - const gl = this.gl; - gl.bindTexture(this.target, this.texture); - this._uploadProps(props); - gl.bindTexture(this.target, null); - } - - _uploadProps(props) { - const gl = this.gl; - if (props.format !== undefined) { - this.format = props.format; - } - if (props.internalFormat !== undefined) { - this.internalFormat = props.internalFormat; - } - if (props.encoding !== undefined) { - this.encoding = props.encoding; - } - if (props.type !== undefined) { - this.type = props.type; - } - if (props.minFilter !== undefined) { - const minFilter = convertConstant(gl, props.minFilter); - if (minFilter) { - this.minFilter = props.minFilter; - gl.texParameteri(this.target, gl.TEXTURE_MIN_FILTER, minFilter); - if (minFilter === gl.NEAREST_MIPMAP_NEAREST || minFilter === gl.LINEAR_MIPMAP_NEAREST || minFilter === gl.NEAREST_MIPMAP_LINEAR || minFilter === gl.LINEAR_MIPMAP_LINEAR) { - gl.generateMipmap(this.target); - } - } - } - if (props.magFilter !== undefined) { - const magFilter = convertConstant(gl, props.magFilter); - if (magFilter) { - this.magFilter = props.magFilter; - gl.texParameteri(this.target, gl.TEXTURE_MAG_FILTER, magFilter); - } - } - if (props.wrapS !== undefined) { - const wrapS = convertConstant(gl, props.wrapS); - if (wrapS) { - this.wrapS = props.wrapS; - gl.texParameteri(this.target, gl.TEXTURE_WRAP_S, wrapS); - } - } - if (props.wrapT !== undefined) { - const wrapT = convertConstant(gl, props.wrapT); - if (wrapT) { - this.wrapT = props.wrapT; - gl.texParameteri(this.target, gl.TEXTURE_WRAP_T, wrapT); - } - } - } - - bind(unit) { - if (!this.allocated) { - return; - } - if (this.texture) { - const gl = this.gl; - gl.activeTexture(gl["TEXTURE" + unit]); - gl.bindTexture(this.target, this.texture); - return true; - } - return false; - } - - unbind(unit) { - if (!this.allocated) { - return; - } - if (this.texture) { - const gl = this.gl; - gl.activeTexture(gl["TEXTURE" + unit]); - gl.bindTexture(this.target, null); - } - } - - destroy() { - if (!this.allocated) { - return; - } - if (this.texture) { - this.gl.deleteTexture(this.texture); - this.texture = null; - } - } -} - -function getInternalFormat(gl, internalFormatName, glFormat, glType, encoding, isVideoTexture = false) { - if (internalFormatName !== null) { - if (gl[internalFormatName] !== undefined) { - return gl[internalFormatName]; - } - console.warn('Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\''); - } - let internalFormat = glFormat; - if (glFormat === gl.RED) { - if (glType === gl.FLOAT) internalFormat = gl.R32F; - if (glType === gl.HALF_FLOAT) internalFormat = gl.R16F; - if (glType === gl.UNSIGNED_BYTE) internalFormat = gl.R8; - } - if (glFormat === gl.RG) { - if (glType === gl.FLOAT) internalFormat = gl.RG32F; - if (glType === gl.HALF_FLOAT) internalFormat = gl.RG16F; - if (glType === gl.UNSIGNED_BYTE) internalFormat = gl.RG8; - } - if (glFormat === gl.RGBA) { - if (glType === gl.FLOAT) internalFormat = gl.RGBA32F; - if (glType === gl.HALF_FLOAT) internalFormat = gl.RGBA16F; - if (glType === gl.UNSIGNED_BYTE) internalFormat = (encoding === sRGBEncoding && isVideoTexture === false) ? gl.SRGB8_ALPHA8 : gl.RGBA8; - if (glType === gl.UNSIGNED_SHORT_4_4_4_4) internalFormat = gl.RGBA4; - if (glType === gl.UNSIGNED_SHORT_5_5_5_1) internalFormat = gl.RGB5_A1; - } - if (internalFormat === gl.R16F || internalFormat === gl.R32F || - internalFormat === gl.RG16F || internalFormat === gl.RG32F || - internalFormat === gl.RGBA16F || internalFormat === gl.RGBA32F) { - getExtension(gl, 'EXT_color_buffer_float'); - } - return internalFormat; -} - -function filterFallback(gl, f) { - if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) { - return gl.NEAREST; - } - return gl.LINEAR; - -} - -function ensureImageSizePowerOfTwo$1(image) { - if (!isPowerOfTwo$1(image.width) || !isPowerOfTwo$1(image.height)) { - const canvas = document.createElement("canvas"); - canvas.width = nextHighestPowerOfTwo$1(image.width); - canvas.height = nextHighestPowerOfTwo$1(image.height); - const ctx = canvas.getContext("2d"); - ctx.drawImage(image, - 0, 0, image.width, image.height, - 0, 0, canvas.width, canvas.height); - image = canvas; - } - return image; -} - -function isPowerOfTwo$1(x) { - return (x & (x - 1)) === 0; -} - -function nextHighestPowerOfTwo$1(x) { - --x; - for (let i = 1; i < 32; i <<= 1) { - x = x | x >> i; - } - return x + 1; -} - -/** - * @desc A 2D texture map. - * - * * Textures are attached to {@link Material}s, which are attached to {@link Mesh}es. - * * To create a Texture from an image file, set {@link Texture#src} to the image file path. - * * To create a Texture from an HTMLImageElement, set the Texture's {@link Texture#image} to the HTMLImageElement. - * - * ## Usage - * - * In this example we have a Mesh with a {@link PhongMaterial} which applies diffuse {@link Texture}, and a {@link buildTorusGeometry} which builds a {@link ReadableGeometry}. - * - * Note that xeokit will ignore {@link PhongMaterial#diffuse} and {@link PhongMaterial#specular}, since we override those - * with {@link PhongMaterial#diffuseMap} and {@link PhongMaterial#specularMap}. The {@link Texture} pixel colors directly - * provide the diffuse and specular components for each fragment across the {@link ReadableGeometry} surface. - * - * [[Run this example](/examples/index.html#materials_Texture)] - * - * ```` javascript - * import {Viewer, Mesh, buildTorusGeometry, - * ReadableGeometry, PhongMaterial, Texture} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.camera.eye = [0, 0, 5]; - * viewer.camera.look = [0, 0, 0]; - * viewer.camera.up = [0, 1, 0]; - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildTorusGeometry({ - * center: [0, 0, 0], - * radius: 1.5, - * tube: 0.5, - * radialSegments: 32, - * tubeSegments: 24, - * arc: Math.PI * 2.0 - * }), - * material: new PhongMaterial(viewer.scene, { - * ambient: [0.9, 0.3, 0.9], - * shininess: 30, - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }) - * }) - * }); - *```` - */ -class Texture extends Component { - - /** - @private - */ - get type() { - return "Texture"; - } - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this Texture as well. - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID for this Texture, unique among all components in the parent scene, generated automatically when omitted. - * @param {String} [cfg.src=null] Path to image file to load into this Texture. See the {@link Texture#src} property for more info. - * @param {HTMLImageElement} [cfg.image=null] HTML Image object to load into this Texture. See the {@link Texture#image} property for more info. - * @param {Number} [cfg.minFilter=LinearMipmapLinearFilter] How the texture is sampled when a texel covers less than one pixel. - * Supported values are {@link LinearMipmapLinearFilter}, {@link LinearMipMapNearestFilter}, {@link NearestMipMapNearestFilter}, {@link NearestMipMapLinearFilter} and {@link LinearMipMapLinearFilter}. - * @param {Number} [cfg.maxAnisotropy=false] Max anisotropy to use for texture filtering (see EXT_texture_filter_anisotropic). - * @param {Number} [cfg.magFilter=LinearFilter] How the texture is sampled when a texel covers more than one pixel. Supported values are {@link LinearFilter} and {@link NearestFilter}. - * @param {Number} [cfg.wrapS=RepeatWrapping] Wrap parameter for texture coordinate *S*. Supported values are {@link ClampToEdgeWrapping}, {@link MirroredRepeatWrapping} and {@link RepeatWrapping}. - * @param {Number} [cfg.wrapT=RepeatWrapping] Wrap parameter for texture coordinate *T*. Supported values are {@link ClampToEdgeWrapping}, {@link MirroredRepeatWrapping} and {@link RepeatWrapping}.. - * @param {Boolean} [cfg.flipY=false] Flips this Texture's source data along its vertical axis when ````true````. - * @param {Number} [cfg.encoding=LinearEncoding] Encoding format. Supported values are {@link LinearEncoding} and {@link sRGBEncoding}. - * @param {Number[]} [cfg.translate=[0,0]] 2D translation vector that will be added to texture's *S* and *T* coordinates. - * @param {Number[]} [cfg.scale=[1,1]] 2D scaling vector that will be applied to texture's *S* and *T* coordinates. - * @param {Number} [cfg.rotate=0] Rotation, in degrees, that will be applied to texture's *S* and *T* coordinates. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._state = new RenderState({ - texture: new Texture2D({gl: this.scene.canvas.gl}), - matrix: math.identityMat4(), - hasMatrix: (cfg.translate && (cfg.translate[0] !== 0 || cfg.translate[1] !== 0)) || (!!cfg.rotate) || (cfg.scale && (cfg.scale[0] !== 0 || cfg.scale[1] !== 0)), - maxAnisotropy: cfg.maxAnisotropy, - minFilter: this._checkMinFilter(cfg.minFilter), - magFilter: this._checkMagFilter(cfg.magFilter), - wrapS: this._checkWrapS(cfg.wrapS), - wrapT: this._checkWrapT(cfg.wrapT), - flipY: this._checkFlipY(cfg.flipY), - encoding: this._checkEncoding(cfg.encoding) - }); - - // Data source - - this._src = null; - this._image = null; - - // Transformation - - this._translate = math.vec2([0, 0]); - this._scale = math.vec2([1, 1]); - this._rotate = math.vec2([0, 0]); - - this._matrixDirty = false; - - // Transform - - this.translate = cfg.translate; - this.scale = cfg.scale; - this.rotate = cfg.rotate; - - // Data source - - if (cfg.src) { - this.src = cfg.src; // Image file - } else if (cfg.image) { - this.image = cfg.image; // Image object - } - - stats.memory.textures++; - } - - _checkMinFilter(value) { - value = value || LinearMipMapLinearFilter; - if (value !== LinearFilter && - value !== LinearMipMapNearestFilter && - value !== LinearMipMapLinearFilter && - value !== NearestMipMapLinearFilter && - value !== NearestMipMapNearestFilter) { - this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, " + - "NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."); - value = LinearMipMapLinearFilter; - } - return value; - } - - _checkMagFilter(value) { - value = value || LinearFilter; - if (value !== LinearFilter && value !== NearestFilter) { - this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."); - value = LinearFilter; - } - return value; - } - - _checkWrapS(value) { - value = value || RepeatWrapping; - if (value !== ClampToEdgeWrapping && value !== MirroredRepeatWrapping && value !== RepeatWrapping) { - this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."); - value = RepeatWrapping; - } - return value; - } - - _checkWrapT(value) { - value = value || RepeatWrapping; - if (value !== ClampToEdgeWrapping && value !== MirroredRepeatWrapping && value !== RepeatWrapping) { - this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."); - value = RepeatWrapping; - } - return value; - } - - _checkFlipY(value) { - return !!value; - } - - _checkEncoding(value) { - value = value || LinearEncoding; - if (value !== LinearEncoding && value !== sRGBEncoding) { - this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."); - value = LinearEncoding; - } - return value; - } - - _update() { - const state = this._state; - if (this._matrixDirty) { - let matrix; - let t; - if (this._translate[0] !== 0 || this._translate[1] !== 0) { - matrix = math.translationMat4v([this._translate[0], this._translate[1], 0], this._state.matrix); - } - if (this._scale[0] !== 1 || this._scale[1] !== 1) { - t = math.scalingMat4v([this._scale[0], this._scale[1], 1]); - matrix = matrix ? math.mulMat4(matrix, t) : t; - } - if (this._rotate !== 0) { - t = math.rotationMat4v(this._rotate * 0.0174532925, [0, 0, 1]); - matrix = matrix ? math.mulMat4(matrix, t) : t; - } - if (matrix) { - state.matrix = matrix; - } - this._matrixDirty = false; - } - this.glRedraw(); - } - - - /** - * Sets an HTML DOM Image object to source this Texture from. - * - * Sets {@link Texture#src} null. - * - * @type {HTMLImageElement} - */ - set image(value) { - this._image = ensureImageSizePowerOfTwo$1(value); - this._image.crossOrigin = "Anonymous"; - this._state.texture.setImage(this._image, this._state); - this._src = null; - this.glRedraw(); - } - - /** - * Gets HTML DOM Image object this Texture is sourced from, if any. - * - * Returns null if not set. - * - * @type {HTMLImageElement} - */ - get image() { - return this._image; - } - - /** - * Sets path to an image file to source this Texture from. - * - * Sets {@link Texture#image} null. - * - * @type {String} - */ - set src(src) { - this.scene.loading++; - this.scene.canvas.spinner.processes++; - const self = this; - let image = new Image(); - image.onload = function () { - image = ensureImageSizePowerOfTwo$1(image); - self._state.texture.setImage(image, self._state); - self.scene.loading--; - self.glRedraw(); - self.scene.canvas.spinner.processes--; - }; - image.src = src; - this._src = src; - this._image = null; - } - - /** - * Gets path to the image file this Texture from, if any. - * - * Returns null if not set. - * - * @type {String} - */ - get src() { - return this._src; - } - - /** - * Sets the 2D translation vector added to this Texture's *S* and *T* UV coordinates. - * - * Default value is ````[0, 0]````. - * - * @type {Number[]} - */ - set translate(value) { - this._translate.set(value || [0, 0]); - this._matrixDirty = true; - this._needUpdate(); - } - - /** - * Gets the 2D translation vector added to this Texture's *S* and *T* UV coordinates. - * - * Default value is ````[0, 0]````. - * - * @type {Number[]} - */ - get translate() { - return this._translate; - } - - /** - * Sets the 2D scaling vector that will be applied to this Texture's *S* and *T* UV coordinates. - * - * Default value is ````[1, 1]````. - * - * @type {Number[]} - */ - set scale(value) { - this._scale.set(value || [1, 1]); - this._matrixDirty = true; - this._needUpdate(); - } - - /** - * Gets the 2D scaling vector that will be applied to this Texture's *S* and *T* UV coordinates. - * - * Default value is ````[1, 1]````. - * - * @type {Number[]} - */ - get scale() { - return this._scale; - } - - /** - * Sets the rotation angles, in degrees, that will be applied to this Texture's *S* and *T* UV coordinates. - * - * Default value is ````0````. - * - * @type {Number} - */ - set rotate(value) { - value = value || 0; - if (this._rotate === value) { - return; - } - this._rotate = value; - this._matrixDirty = true; - this._needUpdate(); - } - - /** - * Gets the rotation angles, in degrees, that will be applied to this Texture's *S* and *T* UV coordinates. - * - * Default value is ````0````. - * - * @type {Number} - */ - get rotate() { - return this._rotate; - } - - /** - * Gets how this Texture is sampled when a texel covers less than one pixel. - * - * Options are: - * - * * NearestFilter - Uses the value of the texture element that is nearest - * (in Manhattan distance) to the center of the pixel being textured. - * - * * LinearFilter - Uses the weighted average of the four texture elements that are - * closest to the center of the pixel being textured. - * - * * NearestMipMapNearestFilter - Chooses the mipmap that most closely matches the - * size of the pixel being textured and uses the "nearest" criterion (the texture - * element nearest to the center of the pixel) to produce a texture value. - * - * * LinearMipMapNearestFilter - Chooses the mipmap that most closely matches the size of - * the pixel being textured and uses the "linear" criterion (a weighted average of the - * four texture elements that are closest to the center of the pixel) to produce a - * texture value. - * - * * NearestMipMapLinearFilter - Chooses the two mipmaps that most closely - * match the size of the pixel being textured and uses the "nearest" criterion - * (the texture element nearest to the center of the pixel) to produce a texture - * value from each mipmap. The final texture value is a weighted average of those two - * values. - * - * * LinearMipMapLinearFilter - (default) - Chooses the two mipmaps that most closely match the size - * of the pixel being textured and uses the "linear" criterion (a weighted average - * of the four texture elements that are closest to the center of the pixel) to - * produce a texture value from each mipmap. The final texture value is a weighted - * average of those two values. - * - * Default value is LinearMipMapLinearFilter. - * - * @type {Number} - */ - get minFilter() { - return this._state.minFilter; - } - - /** - * Gets how this Texture is sampled when a texel covers more than one pixel. - * - * * NearestFilter - Uses the value of the texture element that is nearest - * (in Manhattan distance) to the center of the pixel being textured. - * * LinearFilter - (default) - Uses the weighted average of the four texture elements that are - * closest to the center of the pixel being textured. - * - * Default value is LinearMipMapLinearFilter. - * - * @type {Number} - */ - get magFilter() { - return this._state.magFilter; - } - - /** - * Gets the wrap parameter for this Texture's *S* coordinate. - * - * Values can be: - * - * * ClampToEdgeWrapping - causes *S* coordinates to be clamped to the size of the texture. - * * MirroredRepeatWrapping - causes the *S* coordinate to be set to the fractional part of the texture coordinate - * if the integer part of *S* is even; if the integer part of *S* is odd, then the *S* texture coordinate is - * set to *1 - frac ⁡ S* , where *frac ⁡ S* represents the fractional part of *S*. - * * RepeatWrapping - (default) - causes the integer part of the *S* coordinate to be ignored; xeokit uses only the - * fractional part, thereby creating a repeating pattern. - * - * Default value is RepeatWrapping. - * - * @type {Number} - */ - get wrapS() { - return this._state.wrapS; - } - - /** - * Gets the wrap parameter for this Texture's *T* coordinate. - * - * Values can be: - * - * * ClampToEdgeWrapping - causes *S* coordinates to be clamped to the size of the texture. - * * MirroredRepeatWrapping - causes the *S* coordinate to be set to the fractional part of the texture coordinate - * if the integer part of *S* is even; if the integer part of *S* is odd, then the *S* texture coordinate is - * set to *1 - frac ⁡ S* , where *frac ⁡ S* represents the fractional part of *S*. - * * RepeatWrapping - (default) - causes the integer part of the *S* coordinate to be ignored; xeokit uses only the - * fractional part, thereby creating a repeating pattern. - * - * Default value is RepeatWrapping. - * - * @type {Number} - */ - get wrapT() { - return this._state.wrapT; - } - - /** - * Gets if this Texture's source data is flipped along its vertical axis. - * - * @type {Number} - */ - get flipY() { - return this._state.flipY; - } - - /** - * Gets the Texture's encoding format. - * - * @type {Number} - */ - get encoding() { - return this._state.encoding; - } - - /** - * Destroys this Texture - */ - destroy() { - super.destroy(); - if (this._state.texture) { - this._state.texture.destroy(); - } - this._state.destroy(); - stats.memory.textures--; - } -} - -const tempVec3$7 = math.vec3(); -const tempVec3b$a = math.vec3(); -math.vec3(); -const zeroVec$1 = math.vec3([0, -1, 0]); -const tempQuat = math.vec4([0, 0, 0, 1]); - -/** - * @desc A plane-shaped 3D object containing a bitmap image. - * - * Use ````ImagePlane```` to embed bitmap images in your scenes. - * - * As shown in the examples below, ````ImagePlane```` is useful for creating ground planes from satellite maps and embedding 2D plan - * view images in cross-section slicing planes. - * - * # Example 1: Create a ground plane from a satellite image - * - * In our first example, we'll load the Schependomlaan model, then use - * an ````ImagePlane```` to create a ground plane, which will contain - * a satellite image sourced from Google Maps. - * - * - * - * [](https://xeokit.github.io/xeokit-sdk/examples/scenegraph/#ImagePlane_groundPlane) - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/scenegraph/#ImagePlane_groundPlane)] - * - * ````javascript - * import {Viewer, ImagePlane, XKTLoaderPlugin} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.camera.eye = [-8.31, 42.21, 54.30]; - * viewer.camera.look = [-0.86, 15.40, 14.90]; - * viewer.camera.up = [0.10, 0.83, -0.54]; - * - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * xktLoader.load({ // Load IFC model - * id: "myModel", - * src: "./models/xkt/Schependomlaan.xkt", - * edges: true, - * - * rotation: [0, 22, 0], // Rotate, position and scale the model to align it correctly with the ImagePlane - * position: [-8, 0, 15], - * scale: [1.1, 1.1, 1.1] - * }); - * - * new ImagePlane(viewer.scene, { - * src: "./images/schependomlaanSatMap.png", // Google satellite image; accepted file types are PNG and JPEG - * visible: true, // Show the ImagePlane - * gridVisible: true, // Show the grid - grid is only visible when ImagePlane is also visible - * size: 190, // Size of ImagePlane's longest edge - * position: [0, -1, 0], // World-space position of ImagePlane's center - * rotation: [0, 0, 0], // Euler angles for X, Y and Z - * opacity: 1.0, // Fully opaque - * collidable: false, // ImagePlane does not contribute to Scene boundary - * clippable: true, // ImagePlane can be clipped by SectionPlanes - * pickable: true // Allow the ground plane to be picked - * }); - * ```` - *
- * - * # Example 2: Embed an image in a cross-section plane - * - * In our second example, we'll load the Schependomlaan model again, then slice it in half with - * a {@link SectionPlanesPlugin}, then use an ````ImagePlane```` to embed a 2D plan view image in the slicing plane. - * - * - * - * [](https://xeokit.github.io/xeokit-sdk/examples/scenegraph/#ImagePlane_imageInSectionPlane) - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/scenegraph/#ImagePlane_imageInSectionPlane)] - * - * ````javascript - * import {Viewer, XKTLoaderPlugin, SectionPlanesPlugin, ImagePlane} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.camera.eye = [-9.11, 20.01, 5.13]; - * viewer.camera.look = [9.07, 0.77, -9.78]; - * viewer.camera.up = [0.47, 0.76, -0.38]; - * - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * const sectionPlanes = new SectionPlanesPlugin(viewer, { - * overviewVisible: false - * }); - * - * model = xktLoader.load({ - * id: "myModel", - * src: "./models/xkt/schependomlaan/schependomlaan.xkt", - * metaModelSrc: "./metaModels/schependomlaan/metaModel.json", - * edges: true, - * }); - * - * const sectionPlane = sectionPlanes.createSectionPlane({ - * id: "mySectionPlane", - * pos: [10.95, 1.95, -10.35], - * dir: [0.0, -1.0, 0.0] - * }); - * - * const imagePlane = new ImagePlane(viewer.scene, { - * src: "./images/schependomlaanPlanView.png", // Plan view image; accepted file types are PNG and JPEG - * visible: true, - * gridVisible: true, - * size: 23.95, - * position: sectionPlane.pos, - * dir: sectionPlane.dir, - * collidable: false, - * opacity: 0.75, - * clippable: false, // Don't allow ImagePlane to be clipped by the SectionPlane - * pickable: false // Don't allow ImagePlane to be picked - * }); - * ```` - */ -class ImagePlane extends Component { - - /** - * @constructor - * @param {Component} [owner] Owner component. When destroyed, the owner will destroy this ````ImagePlane```` as well. - * @param {*} [cfg] ````ImagePlane```` configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Boolean} [cfg.visible=true] Indicates whether or not this ````ImagePlane```` is visible. - * @param {Boolean} [cfg.gridVisible=true] Indicates whether or not the grid is visible. Grid is only visible when ````ImagePlane```` is also visible. - * @param {Number[]} [cfg.position=[0,0,0]] World-space position of the ````ImagePlane````. - * @param {Number[]} [cfg.size=1] World-space size of the longest edge of the ````ImagePlane````. Note that - * ````ImagePlane```` sets its aspect ratio to match its image. If we set a value of ````1000````, and the image - * has size ````400x300````, then the ````ImagePlane```` will then have size ````1000 x 750````. - * @param {Number[]} [cfg.rotation=[0,0,0]] Local rotation of the ````ImagePlane````, as Euler angles given in degrees, for each of the X, Y and Z axis. - * @param {Number[]} [cfg.matrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]] Modelling transform matrix for the ````ImagePlane````. Overrides the ````position````, ````size```, ````rotation```` and ````dir```` parameters. - * @param {Boolean} [cfg.collidable=true] Indicates if the ````ImagePlane```` is initially included in boundary calculations. - * @param {Boolean} [cfg.clippable=true] Indicates if the ````ImagePlane```` is initially clippable. - * @param {Boolean} [cfg.pickable=true] Indicates if the ````ImagePlane```` is initially pickable. - * @param {Number} [cfg.opacity=1.0] ````ImagePlane````'s initial opacity factor, multiplies by the rendered fragment alpha. - * @param {String} [cfg.src] URL of image. Accepted file types are PNG and JPEG. - * @param {HTMLImageElement} [cfg.image] An ````HTMLImageElement```` to source the image from. Overrides ````src````. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._src = null; - this._image = null; - this._pos = math.vec3(); - this._origin = math.vec3(); - this._rtcPos = math.vec3(); - this._dir = math.vec3(); - this._size = 1.0; - this._imageSize = math.vec2(); - - this._texture = new Texture(this); - - this._plane = new Mesh(this, { - - geometry: new ReadableGeometry(this, buildPlaneGeometry({ - center: [0, 0, 0], - xSize: 1, - zSize: 1, - xSegments: 10, - zSegments: 10 - })), - - material: new PhongMaterial(this, { - diffuse: [0, 0, 0], - ambient: [0, 0, 0], - specular: [0, 0, 0], - diffuseMap: this._texture, - emissiveMap: this._texture, - backfaces: true - }), - clippable: cfg.clippable - }); - - this._grid = new Mesh(this, { - geometry: new ReadableGeometry(this, buildGridGeometry({ - size: 1, - divisions: 10 - })), - material: new PhongMaterial(this, { - diffuse: [0.0, 0.0, 0.0], - ambient: [0.0, 0.0, 0.0], - emissive: [0.2, 0.8, 0.2] - }), - position: [0, 0.001, 0.0], - clippable: cfg.clippable - }); - - this._node = new Node$1(this, { - rotation: [0, 0, 0], - position: [0, 0, 0], - scale: [1, 1, 1], - clippable: false, - children: [ - this._plane, - this._grid - ] - }); - - this._gridVisible = false; - - this.visible = true; - this.gridVisible = cfg.gridVisible; - this.position = cfg.position; - this.rotation = cfg.rotation; - this.dir = cfg.dir; - this.size = cfg.size; - this.collidable = cfg.collidable; - this.clippable = cfg.clippable; - this.pickable = cfg.pickable; - this.opacity = cfg.opacity; - - if (cfg.image) { - this.image = cfg.image; - } else { - this.src = cfg.src; - } - } - - /** - * Sets if this ````ImagePlane```` is visible or not. - * - * Default value is ````true````. - * - * @param {Boolean} visible Set ````true```` to make this ````ImagePlane```` visible. - */ - set visible(visible) { - this._plane.visible = visible; - this._grid.visible = (this._gridVisible && visible); - } - - /** - * Gets if this ````ImagePlane```` is visible or not. - * - * Default value is ````true````. - * - * @returns {Boolean} Returns ````true```` if visible. - */ - get visible() { - return this._plane.visible; - } - - /** - * Sets if this ````ImagePlane````'s grid is visible or not. - * - * Default value is ````false````. - * - * Grid is only visible when ````ImagePlane```` is also visible. - * - * @param {Boolean} visible Set ````true```` to make this ````ImagePlane````'s grid visible. - */ - set gridVisible(visible) { - visible = (visible !== false); - this._gridVisible = visible; - this._grid.visible = (this._gridVisible && this.visible); - } - - /** - * Gets if this ````ImagePlane````'s grid is visible or not. - * - * Default value is ````false````. - * - * @returns {Boolean} Returns ````true```` if visible. - */ - get gridVisible() { - return this._gridVisible; - } - - /** - * Sets an ````HTMLImageElement```` to source the image from. - * - * Sets {@link Texture#src} null. - * - * @type {HTMLImageElement} - */ - set image(image) { - this._image = image; - if (this._image) { - this._imageSize[0] = image.width; - this._imageSize[1] = image.height; - this._updatePlaneSizeFromImage(); - this._src = null; - this._texture.image = this._image; - } - } - - /** - * Gets the ````HTMLImageElement```` the ````ImagePlane````'s image is sourced from, if set. - * - * Returns null if not set. - * - * @type {HTMLImageElement} - */ - get image() { - return this._image; - } - - /** - * Sets an image file path that the ````ImagePlane````'s image is sourced from. - * - * Accepted file types are PNG and JPEG. - * - * Sets {@link Texture#image} null. - * - * @type {String} - */ - set src(src) { - this._src = src; - if (this._src) { - this._image = null; - const image = new Image(); - image.onload = () => { - this._texture.image = image; - this._imageSize[0] = image.width; - this._imageSize[1] = image.height; - this._updatePlaneSizeFromImage(); - }; - image.src = this._src; - } - } - - /** - * Gets the image file path that the ````ImagePlane````'s image is sourced from, if set. - * - * Returns null if not set. - * - * @type {String} - */ - get src() { - return this._src; - } - - /** - * Sets the World-space position of this ````ImagePlane````. - * - * Default value is ````[0, 0, 0]````. - * - * @param {Number[]} value New position. - */ - set position(value) { - this._pos.set(value || [0, 0, 0]); - worldToRTCPos(this._pos, this._origin, this._rtcPos); - this._node.origin = this._origin; - this._node.position = this._rtcPos; - } - - /** - * Gets the World-space position of this ````ImagePlane````. - * - * Default value is ````[0, 0, 0]````. - * - * @returns {Number[]} Current position. - */ - get position() { - return this._pos; - } - - /** - * Sets the direction of this ````ImagePlane```` using Euler angles. - * - * Default value is ````[0, 0, 0]````. - * - * @param {Number[]} value Euler angles for ````X````, ````Y```` and ````Z```` axis rotations. - */ - set rotation(value) { - this._node.rotation = value; - } - - /** - * Gets the direction of this ````ImagePlane```` as Euler angles. - * - * @returns {Number[]} Euler angles for ````X````, ````Y```` and ````Z```` axis rotations. - */ - get rotation() { - return this._node.rotation; - } - - /** - * Sets the World-space size of the longest edge of the ````ImagePlane````. - * - * Note that ````ImagePlane```` sets its aspect ratio to match its image. If we set a value of ````1000````, and - * the image has size ````400x300````, then the ````ImagePlane```` will then have size ````1000 x 750````. - * - * Default value is ````1.0````. - * - * @param {Number} size New World-space size of the ````ImagePlane````. - */ - set size(size) { - this._size = (size === undefined || size === null) ? 1.0 : size; - if (this._image) { - this._updatePlaneSizeFromImage(); - } - } - - /** - * Gets the World-space size of the longest edge of the ````ImagePlane````. - * - * Returns {Number} World-space size of the ````ImagePlane````. - */ - get size() { - return this._size; - } - - /** - * Sets the direction of this ````ImagePlane```` as a direction vector. - * - * Default value is ````[0, 0, -1]````. - * - * @param {Number[]} dir New direction vector. - */ - set dir(dir) { - - this._dir.set(dir || [0, 0, -1]); - - if (dir) { - - const origin = this.scene.center; - const negDir = [-this._dir[0], -this._dir[1], -this._dir[2]]; - - math.subVec3(origin, this.position, tempVec3$7); - - const dist = -math.dotVec3(negDir, tempVec3$7); - - math.normalizeVec3(negDir); - math.mulVec3Scalar(negDir, dist, tempVec3b$a); - math.vec3PairToQuaternion(zeroVec$1, dir, tempQuat); - - this._node.quaternion = tempQuat; - } - } - - /** - * Gets the direction of this ````ImagePlane```` as a direction vector. - * - * @returns {Number[]} value Current direction. - */ - get dir() { - return this._dir; - } - - /** - * Sets if this ````ImagePlane```` is included in boundary calculations. - * - * Default is ````true````. - * - * @type {Boolean} - */ - set collidable(value) { - this._node.collidable = (value !== false); - } - - /** - * Gets if this ````ImagePlane```` is included in boundary calculations. - * - * Default is ````true````. - * - * @type {Boolean} - */ - get collidable() { - return this._node.collidable; - } - - /** - * Sets if this ````ImagePlane```` is clippable. - * - * Clipping is done by the {@link SectionPlane}s in {@link Scene#sectionPlanes}. - * - * Default is ````true````. - * - * @type {Boolean} - */ - set clippable(value) { - this._node.clippable = (value !== false); - } - - /** - * Gets if this ````ImagePlane```` is clippable. - * - * Clipping is done by the {@link SectionPlane}s in {@link Scene#sectionPlanes}. - * - * Default is ````true````. - * - * @type {Boolean} - */ - get clippable() { - return this._node.clippable; - } - - /** - * Sets if this ````ImagePlane```` is pickable. - * - * Default is ````true````. - * - * @type {Boolean} - */ - set pickable(value) { - this._node.pickable = (value !== false); - } - - /** - * Gets if this ````ImagePlane```` is pickable. - * - * Default is ````true````. - * - * @type {Boolean} - */ - get pickable() { - return this._node.pickable; - } - - /** - * Sets the opacity factor for this ````ImagePlane````. - * - * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas. - * - * @type {Number} - */ - set opacity(opacity) { - this._node.opacity = opacity; - } - - /** - * Gets this ````ImagePlane````'s opacity factor. - * - * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas. - * - * @type {Number} - */ - get opacity() { - return this._node.opacity; - } - - /** - * @destroy - */ - destroy() { - super.destroy(); - } - - _updatePlaneSizeFromImage() { - const size = this._size; - const width = this._imageSize[0]; - const height = this._imageSize[1]; - if (width > height) { - const aspect = height / width; - this._node.scale = [size, 1.0, size * aspect]; - } else { - const aspect = width / height; - this._node.scale = [size * aspect, 1.0, size]; - } - } -} - -/** - * @desc Configures the normal rendered appearance of {@link Mesh}es using the non-realistic but GPU-efficient Lambertian flat shading model for calculating reflectance. - * - * * Useful for efficiently rendering non-realistic objects for high-detail CAD. - * * Use {@link PhongMaterial} when you need specular highlights. - * * Use the physically-based {@link MetallicMaterial} or {@link SpecularMaterial} when you need more realism. - * * For LambertMaterial, the illumination calculation is performed at each triangle vertex, and the resulting color is interpolated across the face of the triangle. For {@link PhongMaterial}, {@link MetallicMaterial} and - * {@link SpecularMaterial}, vertex normals are interpolated across the surface of the triangle, and the illumination calculation is performed at each texel. - * - * ## Usage - * - * [[Run this example](/examples/index.html#materials_LambertMaterial)] - * - * In the example below we'll create a {@link Mesh} with a shape defined by a {@link buildTorusGeometry} and normal rendering appearance configured with a LambertMaterial. - * - * ```` javascript - * import {Viewer, Mesh, buildTorusGeometry, ReadableGeometry, LambertMaterial} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [0, 0, 5]; - * viewer.scene.camera.look = [0, 0, 0]; - * viewer.scene.camera.up = [0, 1, 0]; - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildTorusGeometry({ - * center: [0, 0, 0], - * radius: 1.5, - * tube: 0.5, - * radialSegments: 12, - * tubeSegments: 8, - * arc: Math.PI * 2.0 - * }), - * material: new LambertMaterial(viewer.scene, { - * ambient: [0.3, 0.3, 0.3], - * color: [0.5, 0.5, 0.0], - * alpha: 1.0, // Default - * lineWidth: 1, - * pointSize: 1, - * backfaces: false, - * frontFace: "ccw" - * }) - * }); - * ```` - * - * ## LambertMaterial Properties - * - * The following table summarizes LambertMaterial properties: - * - * | Property | Type | Range | Default Value | Space | Description | - * |:--------:|:----:|:-----:|:-------------:|:-----:|:-----------:| - * | {@link LambertMaterial#ambient} | Array | [0, 1] for all components | [1,1,1,1] | linear | The RGB components of the ambient light reflected by the material. | - * | {@link LambertMaterial#color} | Array | [0, 1] for all components | [1,1,1,1] | linear | The RGB components of the diffuse light reflected by the material. | - * | {@link LambertMaterial#emissive} | Array | [0, 1] for all components | [0,0,0] | linear | The RGB components of the light emitted by the material. | - * | {@link LambertMaterial#alpha} | Number | [0, 1] | 1 | linear | The transparency of the material surface (0 fully transparent, 1 fully opaque). | - * | {@link LambertMaterial#lineWidth} | Number | [0..100] | 1 | | Line width in pixels. | - * | {@link LambertMaterial#pointSize} | Number | [0..100] | 1 | | Point size in pixels. | - * | {@link LambertMaterial#backfaces} | Boolean | | false | | Whether to render {@link Geometry} backfaces. | - * | {@link LambertMaterial#frontface} | String | "ccw", "cw" | "ccw" | | The winding order for {@link Geometry} frontfaces - "cw" for clockwise, or "ccw" for counter-clockwise. | - * - */ -class LambertMaterial extends Material { - - /** - @private - */ - get type() { - return "LambertMaterial"; - } - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - * @param {*} [cfg] The LambertMaterial configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {String:Object} [cfg.meta=null] Metadata to attach to this LambertMaterial. - * @param {Number[]} [cfg.ambient=[1.0, 1.0, 1.0 ]] LambertMaterial ambient color. - * @param {Number[]} [cfg.color=[ 1.0, 1.0, 1.0 ]] LambertMaterial diffuse color. - * @param {Number[]} [cfg.emissive=[ 0.0, 0.0, 0.0 ]] LambertMaterial emissive color. - * @param {Number} [cfg.alpha=1]Scalar in range 0-1 that controls alpha, where 0 is completely transparent and 1 is completely opaque. - * @param {Number} [cfg.reflectivity=1]Scalar in range 0-1 that controls how much {@link ReflectionMap} is reflected. - * @param {Number} [cfg.lineWidth=1] Scalar that controls the width of {@link Geometry} lines. - * @param {Number} [cfg.pointSize=1] Scalar that controls the size of points for {@link Geometry} with {@link Geometry#primitive} set to "points". - * @param {Boolean} [cfg.backfaces=false] Whether to render {@link Geometry} backfaces. - * @param {Boolean} [cfg.frontface="ccw"] The winding order for {@link Geometry} front faces - "cw" for clockwise, or "ccw" for counter-clockwise. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._state = new RenderState({ - type: "LambertMaterial", - ambient: math.vec3([1.0, 1.0, 1.0]), - color: math.vec3([1.0, 1.0, 1.0]), - emissive: math.vec3([0.0, 0.0, 0.0]), - alpha: null, - alphaMode: 0, // 2 ("blend") when transparent, so renderer knows when to add to transparency bin - lineWidth: null, - pointSize: null, - backfaces: null, - frontface: null, // Boolean for speed; true == "ccw", false == "cw" - hash: "/lam;" - }); - - this.ambient = cfg.ambient; - this.color = cfg.color; - this.emissive = cfg.emissive; - this.alpha = cfg.alpha; - this.lineWidth = cfg.lineWidth; - this.pointSize = cfg.pointSize; - this.backfaces = cfg.backfaces; - this.frontface = cfg.frontface; - } - - /** - * Sets the LambertMaterial's ambient color. - * - * Default value is ````[0.3, 0.3, 0.3]````. - * - * @type {Number[]} - */ - set ambient(value) { - let ambient = this._state.ambient; - if (!ambient) { - ambient = this._state.ambient = new Float32Array(3); - } else if (value && ambient[0] === value[0] && ambient[1] === value[1] && ambient[2] === value[2]) { - return; - } - if (value) { - ambient[0] = value[0]; - ambient[1] = value[1]; - ambient[2] = value[2]; - } else { - ambient[0] = .2; - ambient[1] = .2; - ambient[2] = .2; - } - this.glRedraw(); - } - - /** - * Gets the LambertMaterial's ambient color. - * - * Default value is ````[0.3, 0.3, 0.3]````. - * - * @type {Number[]} - */ - get ambient() { - return this._state.ambient; - } - - /** - * Sets the LambertMaterial's diffuse color. - * - * Default value is ````[1.0, 1.0, 1.0]````. - * - * @type {Number[]} - */ - set color(value) { - let color = this._state.color; - if (!color) { - color = this._state.color = new Float32Array(3); - } else if (value && color[0] === value[0] && color[1] === value[1] && color[2] === value[2]) { - return; - } - if (value) { - color[0] = value[0]; - color[1] = value[1]; - color[2] = value[2]; - } else { - color[0] = 1; - color[1] = 1; - color[2] = 1; - } - this.glRedraw(); - } - - /** - * Gets the LambertMaterial's diffuse color. - * - * Default value is ````[1.0, 1.0, 1.0]````. - * - * @type {Number[]} - */ - get color() { - return this._state.color; - } - - /** - * Sets the LambertMaterial's emissive color. - * - * Default value is ````[0.0, 0.0, 0.0]````. - * - * @type {Number[]} - */ - set emissive(value) { - let emissive = this._state.emissive; - if (!emissive) { - emissive = this._state.emissive = new Float32Array(3); - } else if (value && emissive[0] === value[0] && emissive[1] === value[1] && emissive[2] === value[2]) { - return; - } - if (value) { - emissive[0] = value[0]; - emissive[1] = value[1]; - emissive[2] = value[2]; - } else { - emissive[0] = 0; - emissive[1] = 0; - emissive[2] = 0; - } - this.glRedraw(); - } - - /** - * Gets the LambertMaterial's emissive color. - * - * Default value is ````[0.0, 0.0, 0.0]````. - * - * @type {Number[]} - */ - get emissive() { - return this._state.emissive; - } - - /** - * Sets factor in the range ````[0..1]```` indicating how transparent the LambertMaterial is. - * - * A value of ````0.0```` indicates fully transparent, ````1.0```` is fully opaque. - * - * Default value is ````1.0```` - * - * @type {Number} - */ - set alpha(value) { - value = (value !== undefined && value !== null) ? value : 1.0; - if (this._state.alpha === value) { - return; - } - this._state.alpha = value; - this._state.alphaMode = value < 1.0 ? 2 /* blend */ : 0; - /* opaque */ - this.glRedraw(); - } - - /** - * Gets factor in the range ````[0..1]```` indicating how transparent the LambertMaterial is. - * - * A value of ````0.0```` indicates fully transparent, ````1.0```` is fully opaque. - * - * Default value is ````1.0```` - * - * @type {Number} - */ - get alpha() { - return this._state.alpha; - } - - /** - * Sets the LambertMaterial's line width. - * - * This is not supported by WebGL implementations based on DirectX [2019]. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - set lineWidth(value) { - this._state.lineWidth = value || 1.0; - this.glRedraw(); - } - - /** - * Gets the LambertMaterial's line width. - * - * This is not supported by WebGL implementations based on DirectX [2019]. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - get lineWidth() { - return this._state.lineWidth; - } - - /** - * Sets the LambertMaterial's point size. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - set pointSize(value) { - this._state.pointSize = value || 1.0; - this.glRedraw(); - } - - /** - * Gets the LambertMaterial's point size. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - get pointSize() { - return this._state.pointSize; - } - - /** - * Sets whether backfaces are visible on attached {@link Mesh}es. - * - * @type {Boolean} - */ - set backfaces(value) { - value = !!value; - if (this._state.backfaces === value) { - return; - } - this._state.backfaces = value; - this.glRedraw(); - } - - /** - * Gets whether backfaces are visible on attached {@link Mesh}es. - * - * @type {Boolean} - */ - get backfaces() { - return this._state.backfaces; - } - - /** - * Sets the winding direction of front faces of {@link Geometry} of attached {@link Mesh}es. - * - * Default value is ````"ccw"````. - * - * @type {String} - */ - set frontface(value) { - value = value !== "cw"; - if (this._state.frontface === value) { - return; - } - this._state.frontface = value; - this.glRedraw(); - } - - /** - * Gets the winding direction of front faces of {@link Geometry} of attached {@link Mesh}es. - * - * Default value is ````"ccw"````. - * - * @type {String} - */ - get frontface() { - return this._state.frontface ? "ccw" : "cw"; - } - - _getState() { - return this._state; - } - - /** - * Destroys this LambertMaterial. - */ - destroy() { - super.destroy(); - this._state.destroy(); - } -} - -const modes = {"opaque": 0, "mask": 1, "blend": 2}; -const modeNames = ["opaque", "mask", "blend"]; - -/** - * @desc Configures the normal rendered appearance of {@link Mesh}es using the physically-accurate *metallic-roughness* shading model. - * - * * Useful for conductive materials, such as metal, but also appropriate for insulators. - * * {@link SpecularMaterial} is best for insulators, such as wood, ceramics and plastic. - * * {@link PhongMaterial} is appropriate for non-realistic objects. - * * {@link LambertMaterial} is appropriate for high-detail models that need to render as efficiently as possible. - * - * ## Usage - * - * In the example below we'll create a {@link Mesh} with {@link MetallicMaterial} and {@link ReadableGeometry} loaded from OBJ. - * - * Note that in this example we're providing separate {@link Texture} for the {@link MetallicMaterial#metallic} and {@link MetallicMaterial#roughness} - * channels, which allows us a little creative flexibility. Then, in the next example further down, we'll combine those channels - * within the same {@link Texture} for efficiency. - * - * [[Run this example](/examples/index.html#materials_MetallicMaterial)] - * - * ````javascript - * import {Viewer, Mesh, loadOBJGeometry, ReadableGeometry, MetallicMaterial, Texture} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [0.57, 1.37, 1.14]; - * viewer.scene.camera.look = [0.04, 0.58, 0.00]; - * viewer.scene.camera.up = [-0.22, 0.84, -0.48]; - * - * loadOBJGeometry(viewer.scene, { - * src: "models/obj/fireHydrant/FireHydrantMesh.obj" - * }) - * .then(function (geometry) { - * - * // Success - * - * new Mesh(viewer.scene, { - * - * geometry: new ReadableGeometry(viewer.scene, geometry), - * - * material: new MetallicMaterial(viewer.scene, { - * - * baseColor: [1, 1, 1], - * metallic: 1.0, - * roughness: 1.0, - * - * baseColorMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Base_Color.png", - * encoding: "sRGB" - * }), - * normalMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Normal_OpenGL.png" - * }), - * roughnessMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Roughness.png" - * }), - * metallicMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Metallic.png" - * }), - * occlusionMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Mixed_AO.png" - * }), - * - * specularF0: 0.7 - * }) - * }); - * }, function () { - * // Error - * }); - * ```` - * - * ## Background Theory - * - * For an introduction to physically-based rendering (PBR) concepts, try these articles: - * - * * Joe Wilson's [Basic Theory of Physically-Based Rendering](https://www.marmoset.co/posts/basic-theory-of-physically-based-rendering/) - * * Jeff Russel's [Physically-based Rendering, and you can too!](https://www.marmoset.co/posts/physically-based-rendering-and-you-can-too/) - * * Sebastien Legarde's [Adapting a physically-based shading model](http://seblagarde.wordpress.com/tag/physically-based-rendering/) - * - * ## MetallicMaterial Properties - * - * The following table summarizes MetallicMaterial properties: - * - * | Property | Type | Range | Default Value | Space | Description | - * |:--------:|:----:|:-----:|:-------------:|:-----:|:-----------:| - * | {@link MetallicMaterial#baseColor} | Array | [0, 1] for all components | [1,1,1,1] | linear | The RGB components of the base color of the material. | - * | {@link MetallicMaterial#metallic} | Number | [0, 1] | 1 | linear | The metallic-ness the material (1 for metals, 0 for non-metals). | - * | {@link MetallicMaterial#roughness} | Number | [0, 1] | 1 | linear | The roughness of the material surface. | - * | {@link MetallicMaterial#specularF0} | Number | [0, 1] | 1 | linear | The specular Fresnel of the material surface. | - * | {@link MetallicMaterial#emissive} | Array | [0, 1] for all components | [0,0,0] | linear | The RGB components of the emissive color of the material. | - * | {@link MetallicMaterial#alpha} | Number | [0, 1] | 1 | linear | The transparency of the material surface (0 fully transparent, 1 fully opaque). | - * | {@link MetallicMaterial#baseColorMap} | {@link Texture} | | null | sRGB | Texture RGB components multiplying by {@link MetallicMaterial#baseColor}. If the fourth component (A) is present, it multiplies by {@link MetallicMaterial#alpha}. | - * | {@link MetallicMaterial#metallicMap} | {@link Texture} | | null | linear | Texture with first component multiplying by {@link MetallicMaterial#metallic}. | - * | {@link MetallicMaterial#roughnessMap} | {@link Texture} | | null | linear | Texture with first component multiplying by {@link MetallicMaterial#roughness}. | - * | {@link MetallicMaterial#metallicRoughnessMap} | {@link Texture} | | null | linear | Texture with first component multiplying by {@link MetallicMaterial#metallic} and second component multiplying by {@link MetallicMaterial#roughness}. | - * | {@link MetallicMaterial#emissiveMap} | {@link Texture} | | null | linear | Texture with RGB components multiplying by {@link MetallicMaterial#emissive}. | - * | {@link MetallicMaterial#alphaMap} | {@link Texture} | | null | linear | Texture with first component multiplying by {@link MetallicMaterial#alpha}. | - * | {@link MetallicMaterial#occlusionMap} | {@link Texture} | | null | linear | Ambient occlusion texture multiplying by surface's reflected diffuse and specular light. | - * | {@link MetallicMaterial#normalMap} | {@link Texture} | | null | linear | Tangent-space normal map. | - * | {@link MetallicMaterial#alphaMode} | String | "opaque", "blend", "mask" | "blend" | | Alpha blend mode. | - * | {@link MetallicMaterial#alphaCutoff} | Number | [0..1] | 0.5 | | Alpha cutoff value. | - * | {@link MetallicMaterial#backfaces} | Boolean | | false | | Whether to render {@link ReadableGeometry} backfaces. | - * | {@link MetallicMaterial#frontface} | String | "ccw", "cw" | "ccw" | | The winding order for {@link ReadableGeometry} frontfaces - "cw" for clockwise, or "ccw" for counter-clockwise. | - * - * - * ## Combining Channels Within the Same Textures - * - * In the previous example we provided separate {@link Texture} for the {@link MetallicMaterial#metallic} and - * {@link MetallicMaterial#roughness} channels, but we can combine those channels into the same {@link Texture} to - * reduce download time, memory footprint and rendering time (and also for glTF compatibility). - * - * Here's the {@link Mesh} again, with our MetallicMaterial with those channels combined in the {@link MetallicMaterial#metallicRoughnessMap} - * {@link Texture}, where the *R* component multiplies by {@link MetallicMaterial#metallic} and *G* multiplies - * by {@link MetallicMaterial#roughness}. - * - * ````javascript - * new Mesh(viewer.scene, { - * - * geometry: geometry, - * - * material: new MetallicMaterial(viewer.scene, { - * - * baseColor: [1, 1, 1], - * metallic: 1.0, - * roughness: 1.0, - * - * baseColorMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Base_Color.png", - * encoding: "sRGB" - * }), - * normalMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Normal_OpenGL.png" - * }), - * metallicRoughnessMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_MetallicRoughness.png" - * }), - * metallicRoughnessMap : new Texture(viewer.scene, { // <<----------- Added - * src: "models/obj/fireHydrant/fire_hydrant_MetallicRoughness.png" // R component multiplies by metallic - * }), // G component multiplies by roughness - * occlusionMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Mixed_AO.png" - * }), - * - * specularF0: 0.7 - * }) - * ```` - * - * Although not shown in this example, we can also texture {@link MetallicMaterial#alpha} with the *A* component of - * {@link MetallicMaterial#baseColorMap}'s {@link Texture}, if required. - * - * ## Alpha Blending - * - * Let's make our {@link Mesh} transparent. - * - * We'll update the {@link MetallicMaterial#alpha} and {@link MetallicMaterial#alphaMode}, causing it to blend 50% - * with the background: - * - * ````javascript - * hydrant.material.alpha = 0.5; - * hydrant.material.alphaMode = "blend"; - * ```` - * - * ## Alpha Masking - * - * Let's apply an alpha mask to our {@link Mesh}. - * - * We'll configure an {@link MetallicMaterial#alphaMap} to multiply by {@link MetallicMaterial#alpha}, - * with {@link MetallicMaterial#alphaMode} and {@link MetallicMaterial#alphaCutoff} to treat it as an alpha mask: - * - * ````javascript - * new Mesh(viewer.scene, { - * - * geometry: geometry, - * - * material: new MetallicMaterial(viewer.scene, { - * - * baseColor: [1, 1, 1], - * metallic: 1.0, - * roughness: 1.0, - * alpha: 1.0, - * alphaMode : "mask", // <<---------------- Added - * alphaCutoff : 0.2, // <<---------------- Added - * - * alphaMap : new Texture(viewer.scene{ // <<---------------- Added - * src: "textures/alphaMap.jpg" - * }), - * baseColorMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Base_Color.png", - * encoding: "sRGB" - * }), - * normalMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Normal_OpenGL.png" - * }), - * metallicRoughnessMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_MetallicRoughness.png" - * }), - * metallicRoughnessMap : new Texture(viewer.scene, { // <<----------- Added - * src: "models/obj/fireHydrant/fire_hydrant_MetallicRoughness.png" // R component multiplies by metallic - * }), // G component multiplies by roughness - * occlusionMap: new Texture(viewer.scene, { - * src: "models/obj/fireHydrant/fire_hydrant_Mixed_AO.png" - * }), - * - * specularF0: 0.7 - * }) - * ```` - */ -class MetallicMaterial extends Material { - - /** - @private - */ - get type() { - return "MetallicMaterial"; - } - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this MetallicMaterial as well. - * @param {*} [cfg] The MetallicMaterial configuration. - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.baseColor=[1,1,1]] RGB diffuse color of this MetallicMaterial. Multiplies by the RGB components of {@link MetallicMaterial#baseColorMap}. - * @param {Number} [cfg.metallic=1.0] Factor in the range ````[0..1]```` indicating how metallic this MetallicMaterial is. ````1```` is metal, ````0```` is non-metal. Multiplies by the *R* component of {@link MetallicMaterial#metallicMap} and the *A* component of {@link MetallicMaterial#metallicRoughnessMap}. - * @param {Number} [cfg.roughness=1.0] Factor in the range ````[0..1]```` indicating the roughness of this MetallicMaterial. ````0```` is fully smooth, ````1```` is fully rough. Multiplies by the *R* component of {@link MetallicMaterial#roughnessMap}. - * @param {Number} [cfg.specularF0=0.0] Factor in the range ````[0..1]```` indicating specular Fresnel. - * @param {Number[]} [cfg.emissive=[0,0,0]] RGB emissive color of this MetallicMaterial. Multiplies by the RGB components of {@link MetallicMaterial#emissiveMap}. - * @param {Number} [cfg.alpha=1.0] Factor in the range ````[0..1]```` indicating the alpha of this MetallicMaterial. Multiplies by the *R* component of {@link MetallicMaterial#alphaMap} and the *A* component, if present, of {@link MetallicMaterial#baseColorMap}. The value of {@link MetallicMaterial#alphaMode} indicates how alpha is interpreted when rendering. - * @param {Texture} [cfg.baseColorMap=undefined] RGBA {@link Texture} containing the diffuse color of this MetallicMaterial, with optional *A* component for alpha. The RGB components multiply by the {@link MetallicMaterial#baseColor} property, while the *A* component, if present, multiplies by the {@link MetallicMaterial#alpha} property. - * @param {Texture} [cfg.alphaMap=undefined] RGB {@link Texture} containing this MetallicMaterial's alpha in its *R* component. The *R* component multiplies by the {@link MetallicMaterial#alpha} property. Must be within the same {@link Scene} as this MetallicMaterial. - * @param {Texture} [cfg.metallicMap=undefined] RGB {@link Texture} containing this MetallicMaterial's metallic factor in its *R* component. The *R* component multiplies by the {@link MetallicMaterial#metallic} property. Must be within the same {@link Scene} as this MetallicMaterial. - * @param {Texture} [cfg.roughnessMap=undefined] RGB {@link Texture} containing this MetallicMaterial's roughness factor in its *R* component. The *R* component multiplies by the {@link MetallicMaterial#roughness} property. Must be within the same {@link Scene} as this MetallicMaterial. - * @param {Texture} [cfg.metallicRoughnessMap=undefined] RGB {@link Texture} containing this MetallicMaterial's metalness in its *R* component and roughness in its *G* component. Its *R* component multiplies by the {@link MetallicMaterial#metallic} property, while its *G* component multiplies by the {@link MetallicMaterial#roughness} property. Must be within the same {@link Scene} as this MetallicMaterial. - * @param {Texture} [cfg.emissiveMap=undefined] RGB {@link Texture} containing the emissive color of this MetallicMaterial. Multiplies by the {@link MetallicMaterial#emissive} property. Must be within the same {@link Scene} as this MetallicMaterial. - * @param {Texture} [cfg.occlusionMap=undefined] RGB ambient occlusion {@link Texture}. Within shaders, multiplies by the specular and diffuse light reflected by surfaces. Must be within the same {@link Scene} as this MetallicMaterial. - * @param {Texture} [cfg.normalMap=undefined] RGB tangent-space normal {@link Texture}. Must be within the same {@link Scene} as this MetallicMaterial. - * @param {String} [cfg.alphaMode="opaque"] The alpha blend mode, which specifies how alpha is to be interpreted. Accepted values are "opaque", "blend" and "mask". See the {@link MetallicMaterial#alphaMode} property for more info. - * @param {Number} [cfg.alphaCutoff=0.5] The alpha cutoff value. See the {@link MetallicMaterial#alphaCutoff} property for more info. - * @param {Boolean} [cfg.backfaces=false] Whether to render {@link ReadableGeometry} backfaces. - * @param {Boolean} [cfg.frontface="ccw"] The winding order for {@link ReadableGeometry} front faces - ````"cw"```` for clockwise, or ````"ccw"```` for counter-clockwise. - * @param {Number} [cfg.lineWidth=1] Scalar that controls the width of lines for {@link ReadableGeometry} with {@link ReadableGeometry#primitive} set to "lines". - * @param {Number} [cfg.pointSize=1] Scalar that controls the size of points for {@link ReadableGeometry} with {@link ReadableGeometry#primitive} set to "points". - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._state = new RenderState({ - type: "MetallicMaterial", - baseColor: math.vec4([1.0, 1.0, 1.0]), - emissive: math.vec4([0.0, 0.0, 0.0]), - metallic: null, - roughness: null, - specularF0: null, - alpha: null, - alphaMode: null, // "opaque" - alphaCutoff: null, - lineWidth: null, - pointSize: null, - backfaces: null, - frontface: null, // Boolean for speed; true == "ccw", false == "cw" - hash: null - }); - - this.baseColor = cfg.baseColor; - this.metallic = cfg.metallic; - this.roughness = cfg.roughness; - this.specularF0 = cfg.specularF0; - this.emissive = cfg.emissive; - this.alpha = cfg.alpha; - - if (cfg.baseColorMap) { - this._baseColorMap = this._checkComponent("Texture", cfg.baseColorMap); - } - if (cfg.metallicMap) { - this._metallicMap = this._checkComponent("Texture", cfg.metallicMap); - - } - if (cfg.roughnessMap) { - this._roughnessMap = this._checkComponent("Texture", cfg.roughnessMap); - } - if (cfg.metallicRoughnessMap) { - this._metallicRoughnessMap = this._checkComponent("Texture", cfg.metallicRoughnessMap); - } - if (cfg.emissiveMap) { - this._emissiveMap = this._checkComponent("Texture", cfg.emissiveMap); - } - if (cfg.occlusionMap) { - this._occlusionMap = this._checkComponent("Texture", cfg.occlusionMap); - } - if (cfg.alphaMap) { - this._alphaMap = this._checkComponent("Texture", cfg.alphaMap); - } - if (cfg.normalMap) { - this._normalMap = this._checkComponent("Texture", cfg.normalMap); - } - - this.alphaMode = cfg.alphaMode; - this.alphaCutoff = cfg.alphaCutoff; - this.backfaces = cfg.backfaces; - this.frontface = cfg.frontface; - this.lineWidth = cfg.lineWidth; - this.pointSize = cfg.pointSize; - - this._makeHash(); - } - - _makeHash() { - const state = this._state; - const hash = ["/met"]; - if (this._baseColorMap) { - hash.push("/bm"); - if (this._baseColorMap._state.hasMatrix) { - hash.push("/mat"); - } - hash.push("/" + this._baseColorMap._state.encoding); - } - if (this._metallicMap) { - hash.push("/mm"); - if (this._metallicMap._state.hasMatrix) { - hash.push("/mat"); - } - } - if (this._roughnessMap) { - hash.push("/rm"); - if (this._roughnessMap._state.hasMatrix) { - hash.push("/mat"); - } - } - if (this._metallicRoughnessMap) { - hash.push("/mrm"); - if (this._metallicRoughnessMap._state.hasMatrix) { - hash.push("/mat"); - } - } - if (this._emissiveMap) { - hash.push("/em"); - if (this._emissiveMap._state.hasMatrix) { - hash.push("/mat"); - } - } - if (this._occlusionMap) { - hash.push("/ocm"); - if (this._occlusionMap._state.hasMatrix) { - hash.push("/mat"); - } - } - if (this._alphaMap) { - hash.push("/am"); - if (this._alphaMap._state.hasMatrix) { - hash.push("/mat"); - } - } - if (this._normalMap) { - hash.push("/nm"); - if (this._normalMap._state.hasMatrix) { - hash.push("/mat"); - } - } - hash.push(";"); - state.hash = hash.join(""); - } - - - /** - * Sets the RGB diffuse color. - * - * Multiplies by the RGB components of {@link MetallicMaterial#baseColorMap}. - * - * Default value is ````[1.0, 1.0, 1.0]````. - * @type {Number[]} - */ - set baseColor(value) { - let baseColor = this._state.baseColor; - if (!baseColor) { - baseColor = this._state.baseColor = new Float32Array(3); - } else if (value && baseColor[0] === value[0] && baseColor[1] === value[1] && baseColor[2] === value[2]) { - return; - } - if (value) { - baseColor[0] = value[0]; - baseColor[1] = value[1]; - baseColor[2] = value[2]; - } else { - baseColor[0] = 1; - baseColor[1] = 1; - baseColor[2] = 1; - } - this.glRedraw(); - } - - /** - * Gets the RGB diffuse color. - * - * Multiplies by the RGB components of {@link MetallicMaterial#baseColorMap}. - * - * Default value is ````[1.0, 1.0, 1.0]````. - * @type {Number[]} - */ - get baseColor() { - return this._state.baseColor; - } - - - /** - * Gets the RGB {@link Texture} containing the diffuse color of this MetallicMaterial, with optional *A* component for alpha. - * - * The RGB components multiply by {@link MetallicMaterial#baseColor}, while the *A* component, if present, multiplies by {@link MetallicMaterial#alpha}. - * - * @type {Texture} - */ - get baseColorMap() { - return this._baseColorMap; - } - - /** - * Sets the metallic factor. - * - * This is in the range ````[0..1]```` and indicates how metallic this MetallicMaterial is. - * - * ````1```` is metal, ````0```` is non-metal. - * - * Multiplies by the *R* component of {@link MetallicMaterial#metallicMap} and the *A* component of {@link MetallicMaterial#metallicRoughnessMap}. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - set metallic(value) { - value = (value !== undefined && value !== null) ? value : 1.0; - if (this._state.metallic === value) { - return; - } - this._state.metallic = value; - this.glRedraw(); - } - - /** - * Gets the metallic factor. - * - * @type {Number} - */ - get metallic() { - return this._state.metallic; - } - - /** - * Gets the RGB {@link Texture} containing this MetallicMaterial's metallic factor in its *R* component. - * - * The *R* component multiplies by {@link MetallicMaterial#metallic}. - * - * @type {Texture} - */ - get metallicMap() { - return this._attached.metallicMap; - } - - /** - * Sets the roughness factor. - * - * This factor is in the range ````[0..1]````, where ````0```` is fully smooth,````1```` is fully rough. - * - * Multiplies by the *R* component of {@link MetallicMaterial#roughnessMap}. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - set roughness(value) { - value = (value !== undefined && value !== null) ? value : 1.0; - if (this._state.roughness === value) { - return; - } - this._state.roughness = value; - this.glRedraw(); - } - - /** - * Gets the roughness factor. - * - * @type {Number} - */ - get roughness() { - return this._state.roughness; - } - - /** - * Gets the RGB {@link Texture} containing this MetallicMaterial's roughness factor in its *R* component. - * - * The *R* component multiplies by {@link MetallicMaterial#roughness}. - * - * @type {Texture} - */ - get roughnessMap() { - return this._attached.roughnessMap; - } - - /** - * Gets the RGB {@link Texture} containing this MetallicMaterial's metalness in its *R* component and roughness in its *G* component. - * - * Its *B* component multiplies by the {@link MetallicMaterial#metallic} property, while its *G* component multiplies by the {@link MetallicMaterial#roughness} property. - * - * @type {Texture} - */ - get metallicRoughnessMap() { - return this._attached.metallicRoughnessMap; - } - - /** - * Sets the factor in the range [0..1] indicating specular Fresnel value. - * - * Default value is ````0.0````. - * - * @type {Number} - */ - set specularF0(value) { - value = (value !== undefined && value !== null) ? value : 0.0; - if (this._state.specularF0 === value) { - return; - } - this._state.specularF0 = value; - this.glRedraw(); - } - - /** - * Gets the factor in the range [0..1] indicating specular Fresnel value. - * - * @type {Number} - */ - get specularF0() { - return this._state.specularF0; - } - - /** - * Sets the RGB emissive color. - * - * Multiplies by {@link MetallicMaterial#emissiveMap}. - * - * Default value is ````[0.0, 0.0, 0.0]````. - * - * @type {Number[]} - */ - set emissive(value) { - let emissive = this._state.emissive; - if (!emissive) { - emissive = this._state.emissive = new Float32Array(3); - } else if (value && emissive[0] === value[0] && emissive[1] === value[1] && emissive[2] === value[2]) { - return; - } - if (value) { - emissive[0] = value[0]; - emissive[1] = value[1]; - emissive[2] = value[2]; - } else { - emissive[0] = 0; - emissive[1] = 0; - emissive[2] = 0; - } - this.glRedraw(); - } - - /** - * Gets the RGB emissive color. - * - * @type {Number[]} - */ - get emissive() { - return this._state.emissive; - } - - /** - * Gets the RGB emissive map. - * - * Multiplies by {@link MetallicMaterial#emissive}. - * - * @type {Texture} - */ - get emissiveMap() { - return this._attached.emissiveMap; - } - - /** - * Gets the RGB ambient occlusion map. - * - * Multiplies by the specular and diffuse light reflected by surfaces. - * - * @type {Texture} - */ - get occlusionMap() { - return this._attached.occlusionMap; - } - - /** - * Sets factor in the range ````[0..1]```` that indicates the alpha value. - * - * Multiplies by the *R* component of {@link MetallicMaterial#alphaMap} and the *A* component, if present, of {@link MetallicMaterial#baseColorMap}. - * - * The value of {@link MetallicMaterial#alphaMode} indicates how alpha is interpreted when rendering. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - set alpha(value) { - value = (value !== undefined && value !== null) ? value : 1.0; - if (this._state.alpha === value) { - return; - } - this._state.alpha = value; - this.glRedraw(); - } - - /** - * Gets factor in the range ````[0..1]```` that indicates the alpha value. - * - * @type {Number} - */ - get alpha() { - return this._state.alpha; - } - - /** - * Gets the RGB {@link Texture} containing this MetallicMaterial's alpha in its *R* component. - * - * The *R* component multiplies by the {@link MetallicMaterial#alpha} property. - * - * @type {Texture} - */ - get alphaMap() { - return this._attached.alphaMap; - } - - /** - * Gets the RGB tangent-space normal map {@link Texture}. - * - * @type {Texture} - */ - get normalMap() { - return this._attached.normalMap; - } - - /** - * Sets the alpha rendering mode. - * - * This specifies how alpha is interpreted. Alpha is the combined result of the {@link MetallicMaterial#alpha} and {@link MetallicMaterial#alphaMap} properties. - * - * Accepted values are: - * - * * "opaque" - The alpha value is ignored and the rendered output is fully opaque (default). - * * "mask" - The rendered output is either fully opaque or fully transparent depending on the alpha and {@link MetallicMaterial#alphaCutoff}. - * * "blend" - The alpha value is used to composite the source and destination areas. The rendered output is combined with the background using the normal painting operation (i.e. the Porter and Duff over operator). - * - * @type {String} - */ - set alphaMode(alphaMode) { - alphaMode = alphaMode || "opaque"; - let value = modes[alphaMode]; - if (value === undefined) { - this.error("Unsupported value for 'alphaMode': " + alphaMode + " defaulting to 'opaque'"); - value = "opaque"; - } - if (this._state.alphaMode === value) { - return; - } - this._state.alphaMode = value; - this.glRedraw(); - } - - /** - * Gets the alpha rendering mode. - * - * @type {String} - */ - get alphaMode() { - return modeNames[this._state.alphaMode]; - } - - /** - * Sets the alpha cutoff value. - * - * Specifies the cutoff threshold when {@link MetallicMaterial#alphaMode} equals "mask". If the alpha is greater than or equal to this value then it is rendered as fully opaque, otherwise, it is rendered as fully transparent. A value greater than 1.0 will render the entire - * material as fully transparent. This value is ignored for other modes. - * - * Alpha is the combined result of the {@link MetallicMaterial#alpha} and {@link MetallicMaterial#alphaMap} properties. - * - * Default value is ````0.5````. - * - * @type {Number} - */ - set alphaCutoff(alphaCutoff) { - if (alphaCutoff === null || alphaCutoff === undefined) { - alphaCutoff = 0.5; - } - if (this._state.alphaCutoff === alphaCutoff) { - return; - } - this._state.alphaCutoff = alphaCutoff; - } - - /** - * Gets the alpha cutoff value. - * - * @type {Number} - */ - get alphaCutoff() { - return this._state.alphaCutoff; - } - - /** - * Sets whether backfaces are visible on attached {@link Mesh}es. - * - * The backfaces will belong to {@link ReadableGeometry} compoents that are also attached to the {@link Mesh}es. - * - * Default is ````false````. - * - * @type {Boolean} - */ - set backfaces(value) { - value = !!value; - if (this._state.backfaces === value) { - return; - } - this._state.backfaces = value; - this.glRedraw(); - } - - /** - * Gets whether backfaces are visible on attached {@link Mesh}es. - * - * @type {Boolean} - */ - get backfaces() { - return this._state.backfaces; - } - - /** - * Sets the winding direction of front faces of {@link Geometry} of attached {@link Mesh}es. - * - * Default value is ````"ccw"````. - * - * @type {String} - */ - set frontface(value) { - value = value !== "cw"; - if (this._state.frontface === value) { - return; - } - this._state.frontface = value; - this.glRedraw(); - } - - /** - * Gets the winding direction of front faces of {@link Geometry} of attached {@link Mesh}es. -* - * @type {String} - */ - get frontface() { - return this._state.frontface ? "ccw" : "cw"; - } - - /** - * Sets the MetallicMaterial's line width. - * - * This is not supported by WebGL implementations based on DirectX [2019]. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - set lineWidth(value) { - this._state.lineWidth = value || 1.0; - this.glRedraw(); - } - - /** - * Gets the MetallicMaterial's line width. - * - * @type {Number} - */ - get lineWidth() { - return this._state.lineWidth; - } - - /** - * Sets the MetallicMaterial's point size. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - set pointSize(value) { - this._state.pointSize = value || 1.0; - this.glRedraw(); - } - - /** - * Gets the MetallicMaterial's point size. - * - * @type {Number} - */ - get pointSize() { - return this._state.pointSize; - } - - /** - * Destroys this MetallicMaterial. - */ - destroy() { - super.destroy(); - this._state.destroy(); - } -} - -const alphaModes = {"opaque": 0, "mask": 1, "blend": 2}; -const alphaModeNames = ["opaque", "mask", "blend"]; - -/** - * @desc Configures the normal rendered appearance of {@link Mesh}es using the physically-accurate *specular-glossiness* shading model. - * - * * Useful for insulators, such as wood, ceramics and plastic. - * * {@link MetallicMaterial} is best for conductive materials, such as metal. - * * {@link PhongMaterial} is appropriate for non-realistic objects. - * * {@link LambertMaterial} is appropriate for high-detail models that need to render as efficiently as possible. - * - * ## Usage - * - * In the example below we'll create a {@link Mesh} with a {@link buildTorusGeometry} and a SpecularMaterial. - * - * Note that in this example we're providing separate {@link Texture} for the {@link SpecularMaterial#specular} and {@link SpecularMaterial#glossiness} - * channels, which allows us a little creative flexibility. Then, in the next example further down, we'll combine those channels - * within the same {@link Texture} for efficiency. - * - * ````javascript - * import {Viewer, Mesh, buildTorusGeometry, SpecularMaterial, Texture} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ canvasId: "myCanvas" }); - * - * const myMesh = new Mesh(viewer.scene,{ - * - * geometry: new ReadableGeometry(viewer.scene, buildTorusGeometry()), - * - * material: new SpecularMaterial(viewer.scene,{ - * - * // Channels with default values, just to show them - * - * diffuse: [1.0, 1.0, 1.0], - * specular: [1.0, 1.0, 1.0], - * glossiness: 1.0, - * emissive: [0.0, 0.0, 0.0] - * alpha: 1.0, - * - * // Textures to multiply some of the channels - * - * diffuseMap: new Texture(viewer.scene, { // RGB components multiply by diffuse - * src: "textures/diffuse.jpg" - * }), - * specularMap: new Texture(viewer.scene, { // RGB component multiplies by specular - * src: "textures/specular.jpg" - * }), - * glossinessMap: new Texture(viewer.scene, { // R component multiplies by glossiness - * src: "textures/glossiness.jpg" - * }), - * normalMap: new Texture(viewer.scene, { - * src: "textures/normalMap.jpg" - * }) - * }) - * }); - * ```` - * - * ## Combining Channels Within the Same Textures - * - * In the previous example we provided separate {@link Texture} for the {@link SpecularMaterial#specular} and - * {@link SpecularMaterial#glossiness} channels, but we can combine those channels into the same {@link Texture} to reduce - * download time, memory footprint and rendering time (and also for glTF compatibility). - * - * Here's our SpecularMaterial again with those channels combined in the {@link SpecularMaterial#specularGlossinessMap} - * {@link Texture}, where the *RGB* component multiplies by {@link SpecularMaterial#specular} and *A* multiplies by {@link SpecularMaterial#glossiness}. - * - * ````javascript - * const myMesh = new Mesh(viewer.scene,{ - * - * geometry: new ReadableGeometry(viewer.scene, buildTorusGeometry()), - * - * material: new SpecularMaterial(viewer.scene,{ - * - * // Channels with default values, just to show them - * - * diffuse: [1.0, 1.0, 1.0], - * specular: [1.0, 1.0, 1.0], - * glossiness: 1.0, - * emissive: [0.0, 0.0, 0.0] - * alpha: 1.0, - * - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse.jpg" - * }), - * specularGlossinessMap: new Texture(viewer.scene, { // RGB multiplies by specular, A by glossiness - * src: "textures/specularGlossiness.jpg" - * }), - * normalMap: new Texture(viewer.scene, { - * src: "textures/normalMap.jpg" - * }) - * }) - * }); - * ```` - * - * Although not shown in this example, we can also texture {@link SpecularMaterial#alpha} with - * the *A* component of {@link SpecularMaterial#diffuseMap}'s {@link Texture}, if required. - * - * ## Alpha Blending - * - * Let's make our {@link Mesh} transparent. We'll redefine {@link SpecularMaterial#alpha} - * and {@link SpecularMaterial#alphaMode}, causing it to blend 50% with the background: - * - * ````javascript - * const myMesh = new Mesh(viewer.scene,{ - * - * geometry: new ReadableGeometry(viewer.scene, buildTorusGeometry()), - * - * material: new SpecularMaterial(viewer.scene,{ - * - * // Channels with default values, just to show them - * - * diffuse: [1.0, 1.0, 1.0], - * specular: [1.0, 1.0, 1.0], - * glossiness: 1.0, - * emissive: [0.0, 0.0, 0.0] - * alpha: 0.5, // <<----------- Changed - * alphaMode: "blend", // <<----------- Added - * - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse.jpg" - * }), - * specularGlossinessMap: new Texture(viewer.scene, { // RGB multiplies by specular, A by glossiness - * src: "textures/specularGlossiness.jpg" - * }), - * normalMap: new Texture(viewer.scene, { - * src: "textures/normalMap.jpg" - * }) - * }) - * }); - * ```` - * - * ## Alpha Masking - * - * Now let's make holes in our {@link Mesh}. We'll give its SpecularMaterial an {@link SpecularMaterial#alphaMap} - * and configure {@link SpecularMaterial#alpha}, {@link SpecularMaterial#alphaMode}, - * and {@link SpecularMaterial#alphaCutoff} to treat it as an alpha mask: - * - * ````javascript - * const myMesh = new Mesh(viewer.scene,{ - * - * geometry: buildTorusGeometry(viewer.scene, ReadableGeometry, {}), - * - * material: new SpecularMaterial(viewer.scene, { - * - * // Channels with default values, just to show them - * - * diffuse: [1.0, 1.0, 1.0], - * specular: [1.0, 1.0, 1.0], - * glossiness: 1.0, - * emissive: [0.0, 0.0, 0.0] - * alpha: 1.0, // <<----------- Changed - * alphaMode: "mask", // <<----------- Changed - * alphaCutoff: 0.2, // <<----------- Added - * - * alphaMap: new Texture(viewer.scene, { // <<---------- Added - * src: "textures/diffuse/crossGridColorMap.jpg" - * }), - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse.jpg" - * }), - * specularGlossinessMap: new Texture(viewer.scene, { // RGB multiplies by specular, A by glossiness - * src: "textures/specularGlossiness.jpg" - * }), - * normalMap: new Texture(viewer.scene, { - * src: "textures/normalMap.jpg" - * }) - * }) - * }); - * ```` - * - * ## Background Theory - * - * For an introduction to physically-based rendering (PBR) concepts, try these articles: - * - * * Joe Wilson's [Basic Theory of Physically-Based Rendering](https://www.marmoset.co/posts/basic-theory-of-physically-based-rendering/) - * * Jeff Russel's [Physically-based Rendering, and you can too!](https://www.marmoset.co/posts/physically-based-rendering-and-you-can-too/) - * * Sebastien Legarde's [Adapting a physically-based shading model](http://seblagarde.wordpress.com/tag/physically-based-rendering/) - * - * ## SpecularMaterial Properties - * - * The following table summarizes SpecularMaterial properties: - * - * | Property | Type | Range | Default Value | Space | Description | - * |:--------:|:----:|:-----:|:-------------:|:-----:|:-----------:| - * | {@link SpecularMaterial#diffuse} | Array | [0, 1] for all components | [1,1,1,1] | linear | The RGB components of the diffuse color of the material. | - * | {@link SpecularMaterial#specular} | Array | [0, 1] for all components | [1,1,1,1] | linear | The RGB components of the specular color of the material. | - * | {@link SpecularMaterial#glossiness} | Number | [0, 1] | 1 | linear | The glossiness the material. | - * | {@link SpecularMaterial#specularF0} | Number | [0, 1] | 1 | linear | The specularF0 of the material surface. | - * | {@link SpecularMaterial#emissive} | Array | [0, 1] for all components | [0,0,0] | linear | The RGB components of the emissive color of the material. | - * | {@link SpecularMaterial#alpha} | Number | [0, 1] | 1 | linear | The transparency of the material surface (0 fully transparent, 1 fully opaque). | - * | {@link SpecularMaterial#diffuseMap} | {@link Texture} | | null | sRGB | Texture RGB components multiplying by {@link SpecularMaterial#diffuse}. If the fourth component (A) is present, it multiplies by {@link SpecularMaterial#alpha}. | - * | {@link SpecularMaterial#specularMap} | {@link Texture} | | null | sRGB | Texture RGB components multiplying by {@link SpecularMaterial#specular}. If the fourth component (A) is present, it multiplies by {@link SpecularMaterial#alpha}. | - * | {@link SpecularMaterial#glossinessMap} | {@link Texture} | | null | linear | Texture with first component multiplying by {@link SpecularMaterial#glossiness}. | - * | {@link SpecularMaterial#specularGlossinessMap} | {@link Texture} | | null | linear | Texture with first three components multiplying by {@link SpecularMaterial#specular} and fourth component multiplying by {@link SpecularMaterial#glossiness}. | - * | {@link SpecularMaterial#emissiveMap} | {@link Texture} | | null | linear | Texture with RGB components multiplying by {@link SpecularMaterial#emissive}. | - * | {@link SpecularMaterial#alphaMap} | {@link Texture} | | null | linear | Texture with first component multiplying by {@link SpecularMaterial#alpha}. | - * | {@link SpecularMaterial#occlusionMap} | {@link Texture} | | null | linear | Ambient occlusion texture multiplying by surface's reflected diffuse and specular light. | - * | {@link SpecularMaterial#normalMap} | {@link Texture} | | null | linear | Tangent-space normal map. | - * | {@link SpecularMaterial#alphaMode} | String | "opaque", "blend", "mask" | "blend" | | Alpha blend mode. | - * | {@link SpecularMaterial#alphaCutoff} | Number | [0..1] | 0.5 | | Alpha cutoff value. | - * | {@link SpecularMaterial#backfaces} | Boolean | | false | | Whether to render {@link Geometry} backfaces. | - * | {@link SpecularMaterial#frontface} | String | "ccw", "cw" | "ccw" | | The winding order for {@link Geometry} frontfaces - "cw" for clockwise, or "ccw" for counter-clockwise. | - * - */ -class SpecularMaterial extends Material { - - /** - @private - */ - get type() { - return "SpecularMaterial"; - } - - /** - * - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - * @param {*} [cfg] The SpecularMaterial configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.diffuse=[1,1,1]] RGB diffuse color of this SpecularMaterial. Multiplies by the RGB components of {@link SpecularMaterial#diffuseMap}. - * @param {Texture} [cfg.diffuseMap=undefined] RGBA {@link Texture} containing the diffuse color of this SpecularMaterial, with optional *A* component for alpha. The RGB components multiply by {@link SpecularMaterial#diffuse}, while the *A* component, if present, multiplies by {@link SpecularMaterial#alpha}. - * @param {Number} [cfg.specular=[1,1,1]] RGB specular color of this SpecularMaterial. Multiplies by the {@link SpecularMaterial#specularMap} and the *RGB* components of {@link SpecularMaterial#specularGlossinessMap}. - * @param {Texture} [cfg.specularMap=undefined] RGB texture containing the specular color of this SpecularMaterial. Multiplies by the {@link SpecularMaterial#specular} property. Must be within the same {@link Scene} as this SpecularMaterial. - * @param {Number} [cfg.glossiness=1.0] Factor in the range [0..1] indicating how glossy this SpecularMaterial is. 0 is no glossiness, 1 is full glossiness. Multiplies by the *R* component of {@link SpecularMaterial#glossinessMap} and the *A* component of {@link SpecularMaterial#specularGlossinessMap}. - * @param {Texture} [cfg.specularGlossinessMap=undefined] RGBA {@link Texture} containing this SpecularMaterial's specular color in its *RGB* component and glossiness in its *A* component. Its *RGB* components multiply by {@link SpecularMaterial#specular}, while its *A* component multiplies by {@link SpecularMaterial#glossiness}. Must be within the same {@link Scene} as this SpecularMaterial. - * @param {Number} [cfg.specularF0=0.0] Factor in the range 0..1 indicating how reflective this SpecularMaterial is. - * @param {Number[]} [cfg.emissive=[0,0,0]] RGB emissive color of this SpecularMaterial. Multiplies by the RGB components of {@link SpecularMaterial#emissiveMap}. - * @param {Texture} [cfg.emissiveMap=undefined] RGB {@link Texture} containing the emissive color of this SpecularMaterial. Multiplies by the {@link SpecularMaterial#emissive} property. Must be within the same {@link Scene} as this SpecularMaterial. - * @param {Texture} [cfg.occlusionMap=undefined] RGB ambient occlusion {@link Texture}. Within shaders, multiplies by the specular and diffuse light reflected by surfaces. Must be within the same {@link Scene} as this SpecularMaterial. - * @param {Texture} [cfg.normalMap=undefined] {Texture} RGB tangent-space normal {@link Texture}. Must be within the same {@link Scene} as this SpecularMaterial. - * @param {Number} [cfg.alpha=1.0] Factor in the range 0..1 indicating how transparent this SpecularMaterial is. A value of 0.0 indicates fully transparent, 1.0 is fully opaque. Multiplies by the *R* component of {@link SpecularMaterial#alphaMap} and the *A* component, if present, of {@link SpecularMaterial#diffuseMap}. - * @param {Texture} [cfg.alphaMap=undefined] RGB {@link Texture} containing this SpecularMaterial's alpha in its *R* component. The *R* component multiplies by the {@link SpecularMaterial#alpha} property. Must be within the same {@link Scene} as this SpecularMaterial. - * @param {String} [cfg.alphaMode="opaque"] The alpha blend mode - accepted values are "opaque", "blend" and "mask". See the {@link SpecularMaterial#alphaMode} property for more info. - * @param {Number} [cfg.alphaCutoff=0.5] The alpha cutoff value. See the {@link SpecularMaterial#alphaCutoff} property for more info. - * @param {Boolean} [cfg.backfaces=false] Whether to render {@link Geometry} backfaces. - * @param {Boolean} [cfg.frontface="ccw"] The winding order for {@link Geometry} front faces - "cw" for clockwise, or "ccw" for counter-clockwise. - * @param {Number} [cfg.lineWidth=1] Scalar that controls the width of {@link Geometry lines. - * @param {Number} [cfg.pointSize=1] Scalar that controls the size of {@link Geometry} points. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._state = new RenderState({ - type: "SpecularMaterial", - diffuse: math.vec3([1.0, 1.0, 1.0]), - emissive: math.vec3([0.0, 0.0, 0.0]), - specular: math.vec3([1.0, 1.0, 1.0]), - glossiness: null, - specularF0: null, - alpha: null, - alphaMode: null, - alphaCutoff: null, - lineWidth: null, - pointSize: null, - backfaces: null, - frontface: null, // Boolean for speed; true == "ccw", false == "cw" - hash: null - }); - - this.diffuse = cfg.diffuse; - this.specular = cfg.specular; - this.glossiness = cfg.glossiness; - this.specularF0 = cfg.specularF0; - this.emissive = cfg.emissive; - this.alpha = cfg.alpha; - - if (cfg.diffuseMap) { - this._diffuseMap = this._checkComponent("Texture", cfg.diffuseMap); - } - if (cfg.emissiveMap) { - this._emissiveMap = this._checkComponent("Texture", cfg.emissiveMap); - } - if (cfg.specularMap) { - this._specularMap = this._checkComponent("Texture", cfg.specularMap); - } - if (cfg.glossinessMap) { - this._glossinessMap = this._checkComponent("Texture", cfg.glossinessMap); - } - if (cfg.specularGlossinessMap) { - this._specularGlossinessMap = this._checkComponent("Texture", cfg.specularGlossinessMap); - } - if (cfg.occlusionMap) { - this._occlusionMap = this._checkComponent("Texture", cfg.occlusionMap); - } - if (cfg.alphaMap) { - this._alphaMap = this._checkComponent("Texture", cfg.alphaMap); - } - if (cfg.normalMap) { - this._normalMap = this._checkComponent("Texture", cfg.normalMap); - } - - this.alphaMode = cfg.alphaMode; - this.alphaCutoff = cfg.alphaCutoff; - this.backfaces = cfg.backfaces; - this.frontface = cfg.frontface; - - this.lineWidth = cfg.lineWidth; - this.pointSize = cfg.pointSize; - - this._makeHash(); - } - - _makeHash() { - const state = this._state; - const hash = ["/spe"]; - if (this._diffuseMap) { - hash.push("/dm"); - if (this._diffuseMap.hasMatrix) { - hash.push("/mat"); - } - hash.push("/" + this._diffuseMap.encoding); - } - if (this._emissiveMap) { - hash.push("/em"); - if (this._emissiveMap.hasMatrix) { - hash.push("/mat"); - } - } - if (this._glossinessMap) { - hash.push("/gm"); - if (this._glossinessMap.hasMatrix) { - hash.push("/mat"); - } - } - if (this._specularMap) { - hash.push("/sm"); - if (this._specularMap.hasMatrix) { - hash.push("/mat"); - } - } - if (this._specularGlossinessMap) { - hash.push("/sgm"); - if (this._specularGlossinessMap.hasMatrix) { - hash.push("/mat"); - } - } - if (this._occlusionMap) { - hash.push("/ocm"); - if (this._occlusionMap.hasMatrix) { - hash.push("/mat"); - } - } - if (this._normalMap) { - hash.push("/nm"); - if (this._normalMap.hasMatrix) { - hash.push("/mat"); - } - } - if (this._alphaMap) { - hash.push("/opm"); - if (this._alphaMap.hasMatrix) { - hash.push("/mat"); - } - } - hash.push(";"); - state.hash = hash.join(""); - } - - /** - * Sets the RGB diffuse color of this SpecularMaterial. - * - * Multiplies by the *RGB* components of {@link SpecularMaterial#diffuseMap}. - * - * Default value is ````[1.0, 1.0, 1.0]````. - * @type {Number[]} - */ - set diffuse(value) { - let diffuse = this._state.diffuse; - if (!diffuse) { - diffuse = this._state.diffuse = new Float32Array(3); - } else if (value && diffuse[0] === value[0] && diffuse[1] === value[1] && diffuse[2] === value[2]) { - return; - } - if (value) { - diffuse[0] = value[0]; - diffuse[1] = value[1]; - diffuse[2] = value[2]; - } else { - diffuse[0] = 1; - diffuse[1] = 1; - diffuse[2] = 1; - } - this.glRedraw(); - } - - /** - * Gets the RGB diffuse color of this SpecularMaterial. - * - * @type {Number[]} - */ - get diffuse() { - return this._state.diffuse; - } - - /** - * Gets the RGB {@link Texture} containing the diffuse color of this SpecularMaterial, with optional *A* component for alpha. - * - * The *RGB* components multipliues by the {@link SpecularMaterial#diffuse} property, while the *A* component, if present, multiplies by the {@link SpecularMaterial#alpha} property. - * - * @type {Texture} - */ - get diffuseMap() { - return this._diffuseMap; - } - - /** - * Sets the RGB specular color of this SpecularMaterial. - * - * Multiplies by {@link SpecularMaterial#specularMap} and the *A* component of {@link SpecularMaterial#specularGlossinessMap}. - * - * Default value is ````[1.0, 1.0, 1.0]````. - * - * @type {Number[]} - */ - set specular(value) { - let specular = this._state.specular; - if (!specular) { - specular = this._state.specular = new Float32Array(3); - } else if (value && specular[0] === value[0] && specular[1] === value[1] && specular[2] === value[2]) { - return; - } - if (value) { - specular[0] = value[0]; - specular[1] = value[1]; - specular[2] = value[2]; - } else { - specular[0] = 1; - specular[1] = 1; - specular[2] = 1; - } - this.glRedraw(); - } - - /** - * Gets the RGB specular color of this SpecularMaterial. - * - * @type {Number[]} - */ - get specular() { - return this._state.specular; - } - - /** - * Gets the RGB texture containing the specular color of this SpecularMaterial. - * - * Multiplies by {@link SpecularMaterial#specular}. - * - * @type {Texture} - */ - get specularMap() { - return this._specularMap; - } - - /** - * Gets the RGBA texture containing this SpecularMaterial's specular color in its *RGB* components and glossiness in its *A* component. - * - * The *RGB* components multiplies {@link SpecularMaterial#specular}, while the *A* component multiplies by {@link SpecularMaterial#glossiness}. - * - * @type {Texture} - */ - get specularGlossinessMap() { - return this._specularGlossinessMap; - } - - /** - * Sets the Factor in the range [0..1] indicating how glossy this SpecularMaterial is. - * - * ````0```` is no glossiness, ````1```` is full glossiness. - * - * Multiplies by the *R* component of {@link SpecularMaterial#glossinessMap} and the *A* component of {@link SpecularMaterial#specularGlossinessMap}. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - set glossiness(value) { - value = (value !== undefined && value !== null) ? value : 1.0; - if (this._state.glossiness === value) { - return; - } - this._state.glossiness = value; - this.glRedraw(); - } - - /** - * Gets the Factor in the range ````[0..1]```` indicating how glossy this SpecularMaterial is. - - * @type {Number} - */ - get glossiness() { - return this._state.glossiness; - } - - /** - * Gets the RGB texture containing this SpecularMaterial's glossiness in its *R* component. - * - * The *R* component multiplies by {@link SpecularMaterial#glossiness}. - ** @type {Texture} - */ - get glossinessMap() { - return this._glossinessMap; - } - - /** - * Sets the factor in the range ````[0..1]```` indicating amount of specular Fresnel. - * - * Default value is ````0.0````. - * - * @type {Number} - */ - set specularF0(value) { - value = (value !== undefined && value !== null) ? value : 0.0; - if (this._state.specularF0 === value) { - return; - } - this._state.specularF0 = value; - this.glRedraw(); - } - - /** - * Gets the factor in the range ````[0..1]```` indicating amount of specular Fresnel. - * - * @type {Number} - */ - get specularF0() { - return this._state.specularF0; - } - - /** - * Sets the RGB emissive color of this SpecularMaterial. - * - * Multiplies by {@link SpecularMaterial#emissiveMap}. - - * Default value is ````[0.0, 0.0, 0.0]````. - * - * @type {Number[]} - */ - set emissive(value) { - let emissive = this._state.emissive; - if (!emissive) { - emissive = this._state.emissive = new Float32Array(3); - } else if (value && emissive[0] === value[0] && emissive[1] === value[1] && emissive[2] === value[2]) { - return; - } - if (value) { - emissive[0] = value[0]; - emissive[1] = value[1]; - emissive[2] = value[2]; - } else { - emissive[0] = 0; - emissive[1] = 0; - emissive[2] = 0; - } - this.glRedraw(); - } - - /** - * Gets the RGB emissive color of this SpecularMaterial. - * - * @type {Number[]} - */ - get emissive() { - return this._state.emissive; - } - - /** - * Gets the RGB texture containing the emissive color of this SpecularMaterial. - * - * Multiplies by {@link SpecularMaterial#emissive}. - * - * @type {Texture} - */ - get emissiveMap() { - return this._emissiveMap; - } - - /** - * Sets the factor in the range [0..1] indicating how transparent this SpecularMaterial is. - * - * A value of ````0.0```` is fully transparent, while ````1.0```` is fully opaque. - * - * Multiplies by the *R* component of {@link SpecularMaterial#alphaMap} and the *A* component, if present, of {@link SpecularMaterial#diffuseMap}. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - set alpha(value) { - value = (value !== undefined && value !== null) ? value : 1.0; - if (this._state.alpha === value) { - return; - } - this._state.alpha = value; - this.glRedraw(); - } - - /** - * Gets the factor in the range [0..1] indicating how transparent this SpecularMaterial is. - * - * @type {Number} - */ - get alpha() { - return this._state.alpha; - } - - /** - * Gets the RGB {@link Texture} with alpha in its *R* component. - * - * The *R* component multiplies by the {@link SpecularMaterial#alpha} property. - * - * @type {Texture} - */ - get alphaMap() { - return this._alphaMap; - } - - /** - * Gets the RGB tangent-space normal {@link Texture} attached to this SpecularMaterial. - * - * @type {Texture} - */ - get normalMap() { - return this._normalMap; - } - - /** - * Gets the RGB ambient occlusion {@link Texture} attached to this SpecularMaterial. - * - * Multiplies by the specular and diffuse light reflected by surfaces. - * - * @type {Texture} - */ - get occlusionMap() { - return this._occlusionMap; - } - - /** - * Sets the alpha rendering mode. - * - * This governs how alpha is treated. Alpha is the combined result of the {@link SpecularMaterial#alpha} and {@link SpecularMaterial#alphaMap} properties. - * - * Accepted values are: - * - * * "opaque" - The alpha value is ignored and the rendered output is fully opaque (default). - * * "mask" - The rendered output is either fully opaque or fully transparent depending on the alpha value and the specified alpha cutoff value. - * * "blend" - The alpha value is used to composite the source and destination areas. The rendered output is combined with the background using the normal painting operation (i.e. the Porter and Duff over operator) - * - * @type {String} - */ - set alphaMode(alphaMode) { - alphaMode = alphaMode || "opaque"; - let value = alphaModes[alphaMode]; - if (value === undefined) { - this.error("Unsupported value for 'alphaMode': " + alphaMode + " defaulting to 'opaque'"); - value = "opaque"; - } - if (this._state.alphaMode === value) { - return; - } - this._state.alphaMode = value; - this.glRedraw(); - } - - get alphaMode() { - return alphaModeNames[this._state.alphaMode]; - } - - /** - * Sets the alpha cutoff value. - * - * Specifies the cutoff threshold when {@link SpecularMaterial#alphaMode} equals "mask". If the alpha is greater than or equal to this value then it is rendered as fully opaque, otherwise, it is rendered as fully transparent. A value greater than 1.0 will render the entire material as fully transparent. This value is ignored for other modes. - * - * Alpha is the combined result of the {@link SpecularMaterial#alpha} and {@link SpecularMaterial#alphaMap} properties. - * - * Default value is ````0.5````. - * - * @type {Number} - */ - set alphaCutoff(alphaCutoff) { - if (alphaCutoff === null || alphaCutoff === undefined) { - alphaCutoff = 0.5; - } - if (this._state.alphaCutoff === alphaCutoff) { - return; - } - this._state.alphaCutoff = alphaCutoff; - } - - /** - * Gets the alpha cutoff value. - - * @type {Number} - */ - get alphaCutoff() { - return this._state.alphaCutoff; - } - - /** - * Sets whether backfaces are visible on attached {@link Mesh}es. - * - * The backfaces will belong to {@link ReadableGeometry} compoents that are also attached to the {@link Mesh}es. - * - * Default is ````false````. - * - * @type {Boolean} - */ - set backfaces(value) { - value = !!value; - if (this._state.backfaces === value) { - return; - } - this._state.backfaces = value; - this.glRedraw(); - } - - /** - * Gets whether backfaces are visible on attached {@link Mesh}es. - * - * @type {Boolean} - */ - get backfaces() { - return this._state.backfaces; - } - - /** - * Sets the winding direction of front faces of {@link Geometry} of attached {@link Mesh}es. - * - * Default value is ````"ccw"````. - * - * @type {String} - */ - set frontface(value) { - value = value !== "cw"; - if (this._state.frontface === value) { - return; - } - this._state.frontface = value; - this.glRedraw(); - } - - /** - * Gets the winding direction of front faces of {@link Geometry} of attached {@link Mesh}es. - * - * @type {String} - */ - get frontface() { - return this._state.frontface ? "ccw" : "cw"; - } - - /** - * Sets the SpecularMaterial's line width. - * - * This is not supported by WebGL implementations based on DirectX [2019]. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - set lineWidth(value) { - this._state.lineWidth = value || 1.0; - this.glRedraw(); - } - - /** - * Gets the SpecularMaterial's line width. - * - * @type {Number} - */ - get lineWidth() { - return this._state.lineWidth; - } - - /** - * Sets the SpecularMaterial's point size. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - set pointSize(value) { - this._state.pointSize = value || 1; - this.glRedraw(); - } - - /** - * Sets the SpecularMaterial's point size. - * - * @type {Number} - */ - get pointSize() { - return this._state.pointSize; - } - - /** - * Destroys this SpecularMaterial. - */ - destroy() { - super.destroy(); - this._state.destroy(); - } -} - -const PRESETS$3 = { - "default": { - fill: true, - fillColor: [0.4, 0.4, 0.4], - fillAlpha: 0.2, - edges: true, - edgeColor: [0.2, 0.2, 0.2], - edgeAlpha: 0.5, - edgeWidth: 1 - }, - "defaultWhiteBG": { - fill: true, - fillColor: [1, 1, 1], - fillAlpha: 0.6, - edgeColor: [0.2, 0.2, 0.2], - edgeAlpha: 1.0, - edgeWidth: 1 - }, - "defaultLightBG": { - fill: true, - fillColor: [0.4, 0.4, 0.4], - fillAlpha: 0.2, - edges: true, - edgeColor: [0.2, 0.2, 0.2], - edgeAlpha: 0.5, - edgeWidth: 1 - }, - "defaultDarkBG": { - fill: true, - fillColor: [0.4, 0.4, 0.4], - fillAlpha: 0.2, - edges: true, - edgeColor: [0.5, 0.5, 0.5], - edgeAlpha: 0.5, - edgeWidth: 1 - }, - "phosphorous": { - fill: true, - fillColor: [0.0, 0.0, 0.0], - fillAlpha: 0.4, - edges: true, - edgeColor: [0.9, 0.9, 0.9], - edgeAlpha: 0.5, - edgeWidth: 2 - }, - "sunset": { - fill: true, - fillColor: [0.9, 0.9, 0.6], - fillAlpha: 0.2, - edges: true, - edgeColor: [0.9, 0.9, 0.9], - edgeAlpha: 0.5, - edgeWidth: 1 - }, - "vectorscope": { - fill: true, - fillColor: [0.0, 0.0, 0.0], - fillAlpha: 0.7, - edges: true, - edgeColor: [0.2, 1.0, 0.2], - edgeAlpha: 1, - edgeWidth: 2 - }, - "battlezone": { - fill: true, - fillColor: [0.0, 0.0, 0.0], - fillAlpha: 1.0, - edges: true, - edgeColor: [0.2, 1.0, 0.2], - edgeAlpha: 1, - edgeWidth: 3 - }, - "sepia": { - fill: true, - fillColor: [0.970588207244873, 0.7965892553329468, 0.6660899519920349], - fillAlpha: 0.4, - edges: true, - edgeColor: [0.529411792755127, 0.4577854573726654, 0.4100345969200134], - edgeAlpha: 1.0, - edgeWidth: 1 - }, - "yellowHighlight": { - fill: true, - fillColor: [1.0, 1.0, 0.0], - fillAlpha: 0.5, - edges: true, - edgeColor: [1.0, 1.0, 1.0], - edgeAlpha: 1.0, - edgeWidth: 1 - }, - "greenSelected": { - fill: true, - fillColor: [0.0, 1.0, 0.0], - fillAlpha: 0.5, - edges: true, - edgeColor: [1.0, 1.0, 1.0], - edgeAlpha: 1.0, - edgeWidth: 1 - }, - "gamegrid": { - fill: true, - fillColor: [0.2, 0.2, 0.7], - fillAlpha: 0.9, - edges: true, - edgeColor: [0.4, 0.4, 1.6], - edgeAlpha: 0.8, - edgeWidth: 3 - } -}; - -/** - * Configures the appearance of {@link Entity}s when they are xrayed, highlighted or selected. - * - * * XRay an {@link Entity} by setting {@link Entity#xrayed} ````true````. - * * Highlight an {@link Entity} by setting {@link Entity#highlighted} ````true````. - * * Select an {@link Entity} by setting {@link Entity#selected} ````true````. - * * When {@link Entity}s are within the subtree of a root {@link Entity}, then setting {@link Entity#xrayed}, {@link Entity#highlighted} or {@link Entity#selected} - * on the root will collectively set those properties on all sub-{@link Entity}s. - * * EmphasisMaterial provides several presets. Select a preset by setting {@link EmphasisMaterial#preset} to the ID of a preset in {@link EmphasisMaterial#presets}. - * * By default, a {@link Mesh} uses the default EmphasisMaterials in {@link Scene#xrayMaterial}, {@link Scene#highlightMaterial} and {@link Scene#selectedMaterial} - * but you can assign each {@link Mesh#xrayMaterial}, {@link Mesh#highlightMaterial} or {@link Mesh#selectedMaterial} to a custom EmphasisMaterial, if required. - * - * ## Usage - * - * In the example below, we'll create a {@link Mesh} with its own XRayMaterial and set {@link Mesh#xrayed} ````true```` to xray it. - * - * Recall that {@link Mesh} is a concrete subtype of the abstract {@link Entity} base class. - * - * ````javascript - * new Mesh(viewer.scene, { - * geometry: new BoxGeometry(viewer.scene, { - * edgeThreshold: 1 - * }), - * material: new PhongMaterial(viewer.scene, { - * diffuse: [0.2, 0.2, 1.0] - * }), - * xrayMaterial: new EmphasisMaterial(viewer.scene, { - * fill: true, - * fillColor: [0, 0, 0], - * fillAlpha: 0.7, - * edges: true, - * edgeColor: [0.2, 1.0, 0.2], - * edgeAlpha: 1.0, - * edgeWidth: 2 - * }), - * xrayed: true - * }); - * ```` - * - * Note the ````edgeThreshold```` configuration for the {@link ReadableGeometry} on our {@link Mesh}. EmphasisMaterial configures - * a wireframe representation of the {@link ReadableGeometry} for the selected emphasis mode, which will have inner edges (those edges between - * adjacent co-planar triangles) removed for visual clarity. The ````edgeThreshold```` indicates that, for - * this particular {@link ReadableGeometry}, an inner edge is one where the angle between the surface normals of adjacent triangles - * is not greater than ````5```` degrees. That's set to ````2```` by default, but we can override it to tweak the effect - * as needed for particular Geometries. - * - * Here's the example again, this time implicitly defaulting to the {@link Scene#edgeMaterial}. We'll also modify that EdgeMaterial - * to customize the effect. - * - * ````javascript - * new Mesh({ - * geometry: new TeapotGeometry(viewer.scene, { - * edgeThreshold: 5 - * }), - * material: new PhongMaterial(viewer.scene, { - * diffuse: [0.2, 0.2, 1.0] - * }), - * xrayed: true - * }); - * - * var xrayMaterial = viewer.scene.xrayMaterial; - * - * xrayMaterial.fillColor = [0.2, 1.0, 0.2]; - * xrayMaterial.fillAlpha = 1.0; - * ```` - * - * ## Presets - * - * Let's switch the {@link Scene#xrayMaterial} to one of the presets in {@link EmphasisMaterial#presets}: - * - * ````javascript - * viewer.xrayMaterial.preset = EmphasisMaterial.presets["sepia"]; - * ```` - * - * We can also create an EmphasisMaterial from a preset, while overriding properties of the preset as required: - * - * ````javascript - * var myEmphasisMaterial = new EMphasisMaterial(viewer.scene, { - * preset: "sepia", - * fillColor = [1.0, 0.5, 0.5] - * }); - * ```` - */ -class EmphasisMaterial extends Material { - - /** - @private - */ - get type() { - return "EmphasisMaterial"; - } - - /** - * Gets available EmphasisMaterial presets. - * - * @type {Object} - */ - get presets() { - return PRESETS$3; - }; - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - * @param {*} [cfg] The EmphasisMaterial configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Boolean} [cfg.fill=true] Indicates if xray surfaces are filled with color. - * @param {Number[]} [cfg.fillColor=[0.4,0.4,0.4]] EmphasisMaterial fill color. - * @param {Number} [cfg.fillAlpha=0.2] Transparency of filled xray faces. A value of ````0.0```` indicates fully transparent, ````1.0```` is fully opaque. - * @param {Boolean} [cfg.edges=true] Indicates if xray edges are visible. - * @param {Number[]} [cfg.edgeColor=[0.2,0.2,0.2]] RGB color of xray edges. - * @param {Number} [cfg.edgeAlpha=0.5] Transparency of xray edges. A value of ````0.0```` indicates fully transparent, ````1.0```` is fully opaque. - * @param {Number} [cfg.edgeWidth=1] Width of xray edges, in pixels. - * @param {String} [cfg.preset] Deprecated - will be removed in future releases - Selects a preset EmphasisMaterial configuration - see {@link EmphasisMaterial#presets}. - * @param {Boolean} [cfg.backfaces=false] Whether to render geometry backfaces when emphasising. - * @param {Boolean} [cfg.glowThrough=true] Whether to make the emphasized object appear to float on top of other objects, as if it were "glowing through" them. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._state = new RenderState({ - type: "EmphasisMaterial", - fill: null, - fillColor: null, - fillAlpha: null, - edges: null, - edgeColor: null, - edgeAlpha: null, - edgeWidth: null, - backfaces: true, - glowThrough: true - }); - - this._preset = "default"; - - if (cfg.preset) { // Apply preset then override with configs where provided - this.preset = cfg.preset; - if (cfg.fill !== undefined) { - this.fill = cfg.fill; - } - if (cfg.fillColor) { - this.fillColor = cfg.fillColor; - } - if (cfg.fillAlpha !== undefined) { - this.fillAlpha = cfg.fillAlpha; - } - if (cfg.edges !== undefined) { - this.edges = cfg.edges; - } - if (cfg.edgeColor) { - this.edgeColor = cfg.edgeColor; - } - if (cfg.edgeAlpha !== undefined) { - this.edgeAlpha = cfg.edgeAlpha; - } - if (cfg.edgeWidth !== undefined) { - this.edgeWidth = cfg.edgeWidth; - } - if (cfg.backfaces !== undefined) { - this.backfaces = cfg.backfaces; - } - if (cfg.glowThrough !== undefined) { - this.glowThrough = cfg.glowThrough; - } - } else { - this.fill = cfg.fill; - this.fillColor = cfg.fillColor; - this.fillAlpha = cfg.fillAlpha; - this.edges = cfg.edges; - this.edgeColor = cfg.edgeColor; - this.edgeAlpha = cfg.edgeAlpha; - this.edgeWidth = cfg.edgeWidth; - this.backfaces = cfg.backfaces; - this.glowThrough = cfg.glowThrough; - } - } - - /** - * Sets if surfaces are filled with color. - * - * Default is ````true````. - * - * @type {Boolean} - */ - set fill(value) { - value = value !== false; - if (this._state.fill === value) { - return; - } - this._state.fill = value; - this.glRedraw(); - } - - /** - * Gets if surfaces are filled with color. - * - * Default is ````true````. - * - * @type {Boolean} - */ - get fill() { - return this._state.fill; - } - - /** - * Sets the RGB color of filled faces. - * - * Default is ````[0.4, 0.4, 0.4]````. - * - * @type {Number[]} - */ - set fillColor(value) { - let fillColor = this._state.fillColor; - if (!fillColor) { - fillColor = this._state.fillColor = new Float32Array(3); - } else if (value && fillColor[0] === value[0] && fillColor[1] === value[1] && fillColor[2] === value[2]) { - return; - } - if (value) { - fillColor[0] = value[0]; - fillColor[1] = value[1]; - fillColor[2] = value[2]; - } else { - fillColor[0] = 0.4; - fillColor[1] = 0.4; - fillColor[2] = 0.4; - } - this.glRedraw(); - } - - /** - * Gets the RGB color of filled faces. - * - * Default is ````[0.4, 0.4, 0.4]````. - * - * @type {Number[]} - */ - get fillColor() { - return this._state.fillColor; - } - - /** - * Sets the transparency of filled faces. - * - * A value of ````0.0```` indicates fully transparent, ````1.0```` is fully opaque. - * - * Default is ````0.2````. - * - * @type {Number} - */ - set fillAlpha(value) { - value = (value !== undefined && value !== null) ? value : 0.2; - if (this._state.fillAlpha === value) { - return; - } - this._state.fillAlpha = value; - this.glRedraw(); - } - - /** - * Gets the transparency of filled faces. - * - * A value of ````0.0```` indicates fully transparent, ````1.0```` is fully opaque. - * - * Default is ````0.2````. - * - * @type {Number} - */ - get fillAlpha() { - return this._state.fillAlpha; - } - - /** - * Sets if edges are visible. - * - * Default is ````true````. - * - * @type {Boolean} - */ - set edges(value) { - value = value !== false; - if (this._state.edges === value) { - return; - } - this._state.edges = value; - this.glRedraw(); - } - - /** - * Gets if edges are visible. - * - * Default is ````true````. - * - * @type {Boolean} - */ - get edges() { - return this._state.edges; - } - - /** - * Sets the RGB color of edges. - * - * Default is ```` [0.2, 0.2, 0.2]````. - * - * @type {Number[]} - */ - set edgeColor(value) { - let edgeColor = this._state.edgeColor; - if (!edgeColor) { - edgeColor = this._state.edgeColor = new Float32Array(3); - } else if (value && edgeColor[0] === value[0] && edgeColor[1] === value[1] && edgeColor[2] === value[2]) { - return; - } - if (value) { - edgeColor[0] = value[0]; - edgeColor[1] = value[1]; - edgeColor[2] = value[2]; - } else { - edgeColor[0] = 0.2; - edgeColor[1] = 0.2; - edgeColor[2] = 0.2; - } - this.glRedraw(); - } - - /** - * Gets the RGB color of edges. - * - * Default is ```` [0.2, 0.2, 0.2]````. - * - * @type {Number[]} - */ - get edgeColor() { - return this._state.edgeColor; - } - - /** - * Sets the transparency of edges. - * - * A value of ````0.0```` indicates fully transparent, ````1.0```` is fully opaque. - * - * Default is ````0.2````. - * - * @type {Number} - */ - set edgeAlpha(value) { - value = (value !== undefined && value !== null) ? value : 0.5; - if (this._state.edgeAlpha === value) { - return; - } - this._state.edgeAlpha = value; - this.glRedraw(); - } - - /** - * Gets the transparency of edges. - * - * A value of ````0.0```` indicates fully transparent, ````1.0```` is fully opaque. - * - * Default is ````0.2````. - * - * @type {Number} - */ - get edgeAlpha() { - return this._state.edgeAlpha; - } - - /** - * Sets edge width. - * - * This is not supported by WebGL implementations based on DirectX [2019]. - * - * Default value is ````1.0```` pixels. - * - * @type {Number} - */ - set edgeWidth(value) { - this._state.edgeWidth = value || 1.0; - this.glRedraw(); - } - - /** - * Gets edge width. - * - * This is not supported by WebGL implementations based on DirectX [2019]. - * - * Default value is ````1.0```` pixels. - * - * @type {Number} - */ - get edgeWidth() { - return this._state.edgeWidth; - } - - /** - * Sets whether to render backfaces when {@link EmphasisMaterial#fill} is ````true````. - * - * Default is ````false````. - * - * @type {Boolean} - */ - set backfaces(value) { - value = !!value; - if (this._state.backfaces === value) { - return; - } - this._state.backfaces = value; - this.glRedraw(); - } - - /** - * Gets whether to render backfaces when {@link EmphasisMaterial#fill} is ````true````. - * - * Default is ````true````. - * - * @type {Boolean} - */ - get backfaces() { - return this._state.backfaces; - } - - /** - * Sets whether to render emphasized objects over the top of other objects, as if they were "glowing through". - * - * Default is ````true````. - * - * Note: updating this property will not affect the appearance of objects that are already emphasized. - * - * @type {Boolean} - */ - set glowThrough(value) { - value = (value !== false); - if (this._state.glowThrough === value) { - return; - } - this._state.glowThrough = value; - this.glRedraw(); - } - - /** - * Sets whether to render emphasized objects over the top of other objects, as if they were "glowing through". - * - * Default is ````true````. - * - * @type {Boolean} - */ - get glowThrough() { - return this._state.glowThrough; - } - - /** - * @deprecated - * Selects a preset EmphasisMaterial configuration. - * - * Default value is "default". - * - * @type {String} - */ - set preset(value) { - console.warn("EmphasisMaterial.preset is deprecated and will be removed in future versions."); - value = value || "default"; - if (this._preset === value) { - return; - } - const preset = PRESETS$3[value]; - if (!preset) { - this.error("unsupported preset: '" + value + "' - supported values are " + Object.keys(PRESETS$3).join(", ")); - return; - } - this.fill = preset.fill; - this.fillColor = preset.fillColor; - this.fillAlpha = preset.fillAlpha; - this.edges = preset.edges; - this.edgeColor = preset.edgeColor; - this.edgeAlpha = preset.edgeAlpha; - this.edgeWidth = preset.edgeWidth; - this.glowThrough = preset.glowThrough; - this._preset = value; - } - - /** - * @deprecated - * Gets the current preset EmphasisMaterial configuration. - * - * Default value is "default". - * - * @type {String} - */ - get preset() { - console.warn("EmphasisMaterial.preset is deprecated and will be removed in future versions."); - return this._preset; - } - - /** - * Destroys this EmphasisMaterial. - */ - destroy() { - super.destroy(); - this._state.destroy(); - } -} - -const PRESETS$2 = { - "default": { - edgeColor: [0.0, 0.0, 0.0], - edgeAlpha: 1.0, - edgeWidth: 1 - }, - "defaultWhiteBG": { - edgeColor: [0.2, 0.2, 0.2], - edgeAlpha: 1.0, - edgeWidth: 1 - }, - "defaultLightBG": { - edgeColor: [0.2, 0.2, 0.2], - edgeAlpha: 1.0, - edgeWidth: 1 - }, - "defaultDarkBG": { - edgeColor: [0.5, 0.5, 0.5], - edgeAlpha: 1.0, - edgeWidth: 1 - } -}; - -/** - * @desc Configures the appearance of {@link Entity}s when their edges are emphasised. - * - * * Emphasise edges of an {@link Entity} by setting {@link Entity#edges} ````true````. - * * When {@link Entity}s are within the subtree of a root {@link Entity}, then setting {@link Entity#edges} on the root - * will collectively set that property on all sub-{@link Entity}s. - * * EdgeMaterial provides several presets. Select a preset by setting {@link EdgeMaterial#preset} to the ID of a preset in {@link EdgeMaterial#presets}. - * * By default, a {@link Mesh} uses the default EdgeMaterial in {@link Scene#edgeMaterial}, but you can assign each {@link Mesh#edgeMaterial} to a custom EdgeMaterial if required. - * - * ## Usage - * - * In the example below, we'll create a {@link Mesh} with its own EdgeMaterial and set {@link Mesh#edges} ````true```` to emphasise its edges. - * - * Recall that {@link Mesh} is a concrete subtype of the abstract {@link Entity} base class. - * - * [[Run this example](/examples/index.html#materials_EdgeMaterial)] - * - * ````javascript - * import {Viewer, Mesh, buildSphereGeometry, - * ReadableGeometry, PhongMaterial, EdgeMaterial} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.scene.camera.eye = [0, 0, 5]; - * viewer.scene.camera.look = [0, 0, 0]; - * viewer.scene.camera.up = [0, 1, 0]; - * - * new Mesh(viewer.scene, { - * - * geometry: new ReadableGeometry(viewer.scene, buildSphereGeometry({ - * radius: 1.5, - * heightSegments: 24, - * widthSegments: 16, - * edgeThreshold: 2 // Default is 10 - * })), - * - * material: new PhongMaterial(viewer.scene, { - * diffuse: [0.4, 0.4, 1.0], - * ambient: [0.9, 0.3, 0.9], - * shininess: 30, - * alpha: 0.5, - * alphaMode: "blend" - * }), - * - * edgeMaterial: new EdgeMaterial(viewer.scene, { - * edgeColor: [0.0, 0.0, 1.0] - * edgeAlpha: 1.0, - * edgeWidth: 2 - * }), - * - * edges: true - * }); - * ```` - * - * Note the ````edgeThreshold```` configuration for the {@link ReadableGeometry} on our {@link Mesh}. EdgeMaterial configures - * a wireframe representation of the {@link ReadableGeometry}, which will have inner edges (those edges between - * adjacent co-planar triangles) removed for visual clarity. The ````edgeThreshold```` indicates that, for - * this particular {@link ReadableGeometry}, an inner edge is one where the angle between the surface normals of adjacent triangles - * is not greater than ````5```` degrees. That's set to ````2```` by default, but we can override it to tweak the effect - * as needed for particular Geometries. - * - * Here's the example again, this time implicitly defaulting to the {@link Scene#edgeMaterial}. We'll also modify that EdgeMaterial - * to customize the effect. - * - * ````javascript - * new Mesh({ - * geometry: new ReadableGeometry(viewer.scene, buildSphereGeometry({ - * radius: 1.5, - * heightSegments: 24, - * widthSegments: 16, - * edgeThreshold: 2 // Default is 10 - * })), - * material: new PhongMaterial(viewer.scene, { - * diffuse: [0.2, 0.2, 1.0] - * }), - * edges: true - * }); - * - * var edgeMaterial = viewer.scene.edgeMaterial; - * - * edgeMaterial.edgeColor = [0.2, 1.0, 0.2]; - * edgeMaterial.edgeAlpha = 1.0; - * edgeMaterial.edgeWidth = 2; - * ```` - * - * ## Presets - * - * Let's switch the {@link Scene#edgeMaterial} to one of the presets in {@link EdgeMaterial#presets}: - * - * ````javascript - * viewer.edgeMaterial.preset = EdgeMaterial.presets["sepia"]; - * ```` - * - * We can also create an EdgeMaterial from a preset, while overriding properties of the preset as required: - * - * ````javascript - * var myEdgeMaterial = new EdgeMaterial(viewer.scene, { - * preset: "sepia", - * edgeColor = [1.0, 0.5, 0.5] - * }); - * ```` - */ -class EdgeMaterial extends Material { - - /** - @private - */ - get type() { - return "EdgeMaterial"; - } - - /** - * Gets available EdgeMaterial presets. - * - * @type {Object} - */ - get presets() { - return PRESETS$2; - }; - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - * @param {*} [cfg] The EdgeMaterial configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.edgeColor=[0.2,0.2,0.2]] RGB edge color. - * @param {Number} [cfg.edgeAlpha=1.0] Edge transparency. A value of ````0.0```` indicates fully transparent, ````1.0```` is fully opaque. - * @param {Number} [cfg.edgeWidth=1] Edge width in pixels. - * @param {String} [cfg.preset] Selects a preset EdgeMaterial configuration - see {@link EdgeMaterial#presets}. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._state = new RenderState({ - type: "EdgeMaterial", - edges: null, - edgeColor: null, - edgeAlpha: null, - edgeWidth: null - }); - - this._preset = "default"; - - if (cfg.preset) { // Apply preset then override with configs where provided - this.preset = cfg.preset; - if (cfg.edgeColor) { - this.edgeColor = cfg.edgeColor; - } - if (cfg.edgeAlpha !== undefined) { - this.edgeAlpha = cfg.edgeAlpha; - } - if (cfg.edgeWidth !== undefined) { - this.edgeWidth = cfg.edgeWidth; - } - } else { - this.edgeColor = cfg.edgeColor; - this.edgeAlpha = cfg.edgeAlpha; - this.edgeWidth = cfg.edgeWidth; - } - this.edges = (cfg.edges !== false); - } - - - /** - * Sets if edges are visible. - * - * Default is ````true````. - * - * @type {Boolean} - */ - set edges(value) { - value = value !== false; - if (this._state.edges === value) { - return; - } - this._state.edges = value; - this.glRedraw(); - } - - /** - * Gets if edges are visible. - * - * Default is ````true````. - * - * @type {Boolean} - */ - get edges() { - return this._state.edges; - } - - /** - * Sets RGB edge color. - * - * Default value is ````[0.2, 0.2, 0.2]````. - * - * @type {Number[]} - */ - set edgeColor(value) { - let edgeColor = this._state.edgeColor; - if (!edgeColor) { - edgeColor = this._state.edgeColor = new Float32Array(3); - } else if (value && edgeColor[0] === value[0] && edgeColor[1] === value[1] && edgeColor[2] === value[2]) { - return; - } - if (value) { - edgeColor[0] = value[0]; - edgeColor[1] = value[1]; - edgeColor[2] = value[2]; - } else { - edgeColor[0] = 0.2; - edgeColor[1] = 0.2; - edgeColor[2] = 0.2; - } - this.glRedraw(); - } - - /** - * Gets RGB edge color. - * - * Default value is ````[0.2, 0.2, 0.2]````. - * - * @type {Number[]} - */ - get edgeColor() { - return this._state.edgeColor; - } - - /** - * Sets edge transparency. - * - * A value of ````0.0```` indicates fully transparent, ````1.0```` is fully opaque. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - set edgeAlpha(value) { - value = (value !== undefined && value !== null) ? value : 1.0; - if (this._state.edgeAlpha === value) { - return; - } - this._state.edgeAlpha = value; - this.glRedraw(); - } - - /** - * Gets edge transparency. - * - * A value of ````0.0```` indicates fully transparent, ````1.0```` is fully opaque. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - get edgeAlpha() { - return this._state.edgeAlpha; - } - - /** - * Sets edge width. - * - * This is not supported by WebGL implementations based on DirectX [2019]. - * - * Default value is ````1.0```` pixels. - * - * @type {Number} - */ - set edgeWidth(value) { - this._state.edgeWidth = value || 1.0; - this.glRedraw(); - } - - /** - * Gets edge width. - * - * This is not supported by WebGL implementations based on DirectX [2019]. - * - * Default value is ````1.0```` pixels. - * - * @type {Number} - */ - get edgeWidth() { - return this._state.edgeWidth; - } - - /** - * Selects a preset EdgeMaterial configuration. - * - * Default value is ````"default"````. - * - * @type {String} - */ - set preset(value) { - value = value || "default"; - if (this._preset === value) { - return; - } - const preset = PRESETS$2[value]; - if (!preset) { - this.error("unsupported preset: '" + value + "' - supported values are " + Object.keys(PRESETS$2).join(", ")); - return; - } - this.edgeColor = preset.edgeColor; - this.edgeAlpha = preset.edgeAlpha; - this.edgeWidth = preset.edgeWidth; - this._preset = value; - } - - /** - * The current preset EdgeMaterial configuration. - * - * Default value is ````"default"````. - * - * @type {String} - */ - get preset() { - return this._preset; - } - - /** - * Destroys this EdgeMaterial. - */ - destroy() { - super.destroy(); - this._state.destroy(); - } -} - -/** - * @desc Configures Fresnel effects for {@link PhongMaterial}s. - * - * Fresnels are attached to {@link PhongMaterial}s, which are attached to {@link Mesh}es. - * - * ## Usage - * - * In the example below we'll create a {@link Mesh} with a {@link PhongMaterial} that applies a Fresnel to its alpha channel to give a glasss-like effect. - * - * [[Run this example](/examples/index.html#materials_Fresnel)] - * - * ````javascript - * import {Viewer, Mesh, buildTorusGeometry, - * ReadableGeometry, PhongMaterial, Texture, Fresnel} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.scene.camera.eye = [0, 0, 5]; - * viewer.scene.camera.look = [0, 0, 0]; - * viewer.scene.camera.up = [0, 1, 0]; - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildTorusGeometry({ - * center: [0, 0, 0], - * radius: 1.5, - * tube: 0.5, - * radialSegments: 32, - * tubeSegments: 24, - * arc: Math.PI * 2.0 - * }), - * material: new PhongMaterial(viewer.scene, { - * alpha: 0.9, - * alphaMode: "blend", - * ambient: [0.0, 0.0, 0.0], - * shininess: 30, - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }), - * alphaFresnel: new Fresnel(viewer.scene, { -v edgeBias: 0.2, - * centerBias: 0.8, - * edgeColor: [1.0, 1.0, 1.0], - * centerColor: [0.0, 0.0, 0.0], - * power: 2 - * }) - * }) - * }); - * ```` - */ -class Fresnel extends Component { - - /** - * JavaScript class name for this Component. - * - * @type {String} - */ - get type() { - return "Fresnel"; - } - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this Fresnel as well. - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID, unique among all components in the parent scene, generated automatically when omitted. - * @param {Number[]} [cfg.edgeColor=[ 0.0, 0.0, 0.0 ]] Color used on edges. - * @param {Number[]} [cfg.centerColor=[ 1.0, 1.0, 1.0 ]] Color used on center. - * @param {Number} [cfg.edgeBias=0] Bias at the edge. - * @param {Number} [cfg.centerBias=1] Bias at the center. - * @param {Number} [cfg.power=0] The power. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._state = new RenderState({ - edgeColor: math.vec3([0, 0, 0]), - centerColor: math.vec3([1, 1, 1]), - edgeBias: 0, - centerBias: 1, - power: 1 - }); - - this.edgeColor = cfg.edgeColor; - this.centerColor = cfg.centerColor; - this.edgeBias = cfg.edgeBias; - this.centerBias = cfg.centerBias; - this.power = cfg.power; - } - - /** - * Sets the Fresnel's edge color. - * - * Default value is ````[0.0, 0.0, 0.0]````. - * - * @type {Number[]} - */ - set edgeColor(value) { - this._state.edgeColor.set(value || [0.0, 0.0, 0.0]); - this.glRedraw(); - } - - /** - * Gets the Fresnel's edge color. - * - * Default value is ````[0.0, 0.0, 0.0]````. - * - * @type {Number[]} - */ - get edgeColor() { - return this._state.edgeColor; - } - - /** - * Sets the Fresnel's center color. - * - * Default value is ````[1.0, 1.0, 1.0]````. - * - * @type {Number[]} - */ - set centerColor(value) { - this._state.centerColor.set(value || [1.0, 1.0, 1.0]); - this.glRedraw(); - } - - /** - * Gets the Fresnel's center color. - * - * Default value is ````[1.0, 1.0, 1.0]````. - * - * @type {Number[]} - */ - get centerColor() { - return this._state.centerColor; - } - - /** - * Sets the Fresnel's edge bias. - * - * Default value is ````0````. - * - * @type {Number} - */ - set edgeBias(value) { - this._state.edgeBias = value || 0; - this.glRedraw(); - } - - /** - * Gets the Fresnel's edge bias. - * - * Default value is ````0````. - * - * @type {Number} - */ - get edgeBias() { - return this._state.edgeBias; - } - - /** - * Sets the Fresnel's center bias. - * - * Default value is ````1````. - * - * @type {Number} - */ - set centerBias(value) { - this._state.centerBias = (value !== undefined && value !== null) ? value : 1; - this.glRedraw(); - } - - /** - * Gets the Fresnel's center bias. - * - * Default value is ````1````. - * - * @type {Number} - */ - get centerBias() { - return this._state.centerBias; - } - - /** - * Sets the Fresnel's power. - * - * Default value is ````1````. - * - * @type {Number} - */ - set power(value) { - this._state.power = (value !== undefined && value !== null) ? value : 1; - this.glRedraw(); - } - - /** - * Gets the Fresnel's power. - * - * Default value is ````1````. - * - * @type {Number} - */ - get power() { - return this._state.power; - } - - /** - * Destroys this Fresnel. - */ - destroy() { - super.destroy(); - this._state.destroy(); - } -} - -/** - * A plane-shaped 3D object containing a bitmap image. - * - * * Creates a 3D quad containing our bitmap, located and oriented using ````pos````, ````normal```` and ````up```` vectors. - * * Registered by {@link Bitmap#id} in {@link Scene#bitmaps}. - * * {@link BCFViewpointsPlugin} will save and load Bitmaps in BCF viewpoints. - * - * ## Usage - * - * In the example below, we'll load the Schependomlaan model, then use - * an ````Bitmap```` to show a storey plan next to the model. - * - * [](https://xeokit.github.io/xeokit-sdk/examples/scenegraph/#ImagePlane_imageInSectionPlane) - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/scenegraph/#ImagePlane_imageInSectionPlane)] - * - * ````javascript - * import {Viewer, Bitmap, XKTLoaderPlugin} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.camera.eye = [-24.65, 21.69, 8.16]; - * viewer.camera.look = [-14.62, 2.16, -1.38]; - * viewer.camera.up = [0.59, 0.57, -0.56]; - * - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * xktLoader.load({ - * id: "myModel", - * src: "./models/xkt/Schependomlaan.xkt", - * edges: true - * }); - * - * new Bitmap(viewer.scene, { - * src: "./images/schependomlaanPlanView.png", - * visible: true, // Show the Bitmap - * height: 24.0, // Height of Bitmap - * pos: [-15, 0, -10], // World-space position of Bitmap's center - * normal: [0, -1, 0], // Vector perpendicular to Bitmap - * up: [0, 0, 1], // Direction of Bitmap "up" - * collidable: false, // Bitmap does not contribute to Scene boundary - * clippable: true, // Bitmap can be clipped by SectionPlanes - * pickable: true // Allow the ground plane to be picked - * }); - * ```` - */ -class Bitmap extends Component { - - /** - * Creates a new Bitmap. - * - * Registers the Bitmap in {@link Scene#bitmaps}; causes Scene to fire a "bitmapCreated" event. - * - * @constructor - * @param {Component} [owner] Owner component. When destroyed, the owner will destroy this ````Bitmap```` as well. - * @param {*} [cfg] ````Bitmap```` configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Boolean} [cfg.visible=true] Indicates whether or not this ````Bitmap```` is visible. - * @param {Number[]} [cfg.pos=[0,0,0]] World-space position of the ````Bitmap````. - * @param {Number[]} [cfg.normal=[0,0,1]] Normal vector indicating the direction the ````Bitmap```` faces. - * @param {Number[]} [cfg.up=[0,1,0]] Direction of "up" for the ````Bitmap````. - * @param {Number[]} [cfg.height=1] World-space height of the ````Bitmap````. - * @param {Number[]} [cfg.matrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]] Modelling transform matrix for the ````Bitmap````. Overrides the ````position````, ````height```, ````rotation```` and ````normal```` parameters. - * @param {Boolean} [cfg.collidable=true] Indicates if the ````Bitmap```` is initially included in boundary calculations. - * @param {Boolean} [cfg.clippable=true] Indicates if the ````Bitmap```` is initially clippable. - * @param {Boolean} [cfg.pickable=true] Indicates if the ````Bitmap```` is initially pickable. - * @param {Number} [cfg.opacity=1.0] ````Bitmap````'s initial opacity factor, multiplies by the rendered fragment alpha. - * @param {String} [cfg.src] URL of image. Accepted file types are PNG and JPEG. - * @param {HTMLImageElement} [cfg.image] An ````HTMLImageElement```` to source the image from. Overrides ````src````. - * @param {String} [cfg.imageData] Image data as a base64 encoded string. - * @param {String} [cfg.type="jpg"] Image MIME type. Accepted values are "jpg" and "png". Default is "jpg". Normally only needed with ````image```` or ````imageData````. Automatically inferred from file extension of ````src````, if the file has a recognized extension. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._type = cfg.type || (cfg.src ? cfg.src.split('.').pop() : null) || "jpg"; - this._pos = math.vec3(cfg.pos || [0, 0, 0]); - this._up = math.vec3(cfg.up || [0, 1, 0]); - this._normal = math.vec3(cfg.normal || [0, 0, 1]); - this._height = cfg.height || 1.0; - - this._origin = math.vec3(); - this._rtcPos = math.vec3(); - this._imageSize = math.vec2(); - - this._texture = new Texture(this, { - flipY: true - }); - - this._image = new Image(); - - if (this._type !== "jpg" && this._type !== "png") { - this.error(`Unsupported type - defaulting to "jpg"`); - this._type = "jpg"; - } - - this._node = new Node$1(this, { - matrix: math.inverseMat4( - math.lookAtMat4v(this._pos, math.subVec3(this._pos, this._normal, math.mat4()), - this._up, - math.mat4())), - children: [ - - this._bitmapMesh = new Mesh(this, { - scale: [1, 1, 1], - rotation: [-90, 0, 0], - collidable: cfg.collidable, - pickable: cfg.pickable, - opacity: cfg.opacity, - clippable: cfg.clippable, - - geometry: new ReadableGeometry(this, buildPlaneGeometry({ - center: [0, 0, 0], - xSize: 1, - zSize: 1, - xSegments: 2, - zSegments: 2 - })), - - material: new PhongMaterial(this, { - diffuse: [0, 0, 0], - ambient: [0, 0, 0], - specular: [0, 0, 0], - diffuseMap: this._texture, - emissiveMap: this._texture, - backfaces: true - }) - }) - ] - }); - - if (cfg.image) { - this.image = cfg.image; - } else if (cfg.src) { - this.src = cfg.src; - } else if (cfg.imageData) { - this.imageData = cfg.imageData; - } - - this.scene._bitmapCreated(this); - } - - /** - * Sets if this ````Bitmap```` is visible or not. - * - * Default value is ````true````. - * - * @param {Boolean} visible Set ````true```` to make this ````Bitmap```` visible. - */ - set visible(visible) { - this._bitmapMesh.visible = visible; - } - - /** - * Gets if this ````Bitmap```` is visible or not. - * - * Default value is ````true````. - * - * @returns {Boolean} Returns ````true```` if visible. - */ - get visible() { - return this._bitmapMesh.visible; - } - - /** - * Sets an ````HTMLImageElement```` to source the image from. - * - * Sets {@link Texture#src} null. - * - * You may also need to set {@link Bitmap#type}, if you want to read the image data with {@link Bitmap#imageData}. - * - * @type {HTMLImageElement} - */ - set image(image) { - this._image = image; - if (this._image) { - this._texture.image = this._image; - this._imageSize[0] = this._image.width; - this._imageSize[1] = this._image.height; - this._updateBitmapMeshScale(); - } - } - - /** - * Gets the ````HTMLImageElement```` the ````Bitmap````'s image is sourced from, if set. - * - * Returns null if not set. - * - * @type {HTMLImageElement} - */ - get image() { - return this._image; - } - - /** - * Sets an image file path that the ````Bitmap````'s image is sourced from. - * - * If the file extension is a recognized MIME type, also sets {@link Bitmap#type} to that MIME type. - * - * Accepted file types are PNG and JPEG. - * - * @type {String} - */ - set src(src) { - if (src) { - this._image.onload = () => { - this._texture.image = this._image; - this._imageSize[0] = this._image.width; - this._imageSize[1] = this._image.height; - this._updateBitmapMeshScale(); - }; - this._image.src = src; - const ext = src.split('.').pop(); - switch (ext) { - case "jpeg": - case "jpg": - this._type = "jpg"; - break; - case "png": - this._type = "png"; - } - } - } - - /** - * Gets the image file path that the ````Bitmap````'s image is sourced from, if set. - * - * Returns null if not set. - * - * @type {String} - */ - get src() { - return this._image.src; - } - - /** - * Sets an image file path that the ````Bitmap````'s image is sourced from. - * - * Accepted file types are PNG and JPEG. - * - * Sets {@link Texture#image} null. - * - * You may also need to set {@link Bitmap#type}, if you want to read the image data with {@link Bitmap#imageData}. - * - * @type {String} - */ - set imageData(imageData) { - this._image.onload = () => { - this._texture.image = image; - this._imageSize[0] = image.width; - this._imageSize[1] = image.height; - this._updateBitmapMeshScale(); - }; - this._image.src = imageData; - } - - /** - * Gets the image file path that the ````Bitmap````'s image is sourced from, if set. - * - * Returns null if not set. - * - * @type {String} - */ - get imageData() { - const canvas = document.createElement('canvas'); - const context = canvas.getContext('2d'); - canvas.width = this._image.width; - canvas.height = this._image.height; - context.drawImage(this._image, 0, 0); - return canvas.toDataURL(this._type === "jpg" ? 'image/jpeg' : 'image/png'); - } - - /** - * Sets the MIME type of this Bitmap. - * - * This is used by ````Bitmap```` when getting image data with {@link Bitmap#imageData}. - * - * Supported values are "jpg" and "png", - * - * Default is "jpg". - * - * @type {String} - */ - set type(type) { - type = type || "jpg"; - if (type !== "png" || type !== "jpg") { - this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"); - type = "jpg"; - } - this._type = type; - } - - /** - * Gets the MIME type of this Bitmap. - * - * @type {String} - */ - get type() { - return this._type; - } - - /** - * Gets the World-space position of this ````Bitmap````. - * - * Default value is ````[0, 0, 0]````. - * - * @returns {Number[]} Current position. - */ - get pos() { - return this._pos; - } - - /** - * Gets the direction of the normal vector that is perpendicular to this ````Bitmap````. - * - * @returns {Number[]} value Current normal direction. - */ - get normal() { - return this._normal; - } - - /** - * Gets the "up" direction of this ````Bitmap````. - * - * @returns {Number[]} value Current "up" direction. - */ - get up() { - return this._up; - } - - /** - * Sets the World-space height of the ````Bitmap````. - * - * Default value is ````1.0````. - * - * @param {Number} height New World-space height of the ````Bitmap````. - */ - set height(height) { - this._height = (height === undefined || height === null) ? 1.0 : height; - if (this._image) { - this._updateBitmapMeshScale(); - } - } - - /** - * Gets the World-space height of the ````Bitmap````. - * - * Returns {Number} World-space height of the ````Bitmap````. - */ - get height() { - return this._height; - } - - /** - * Sets if this ````Bitmap```` is included in boundary calculations. - * - * Default is ````true````. - * - * @type {Boolean} - */ - set collidable(value) { - this._bitmapMesh.collidable = (value !== false); - } - - /** - * Gets if this ````Bitmap```` is included in boundary calculations. - * - * Default is ````true````. - * - * @type {Boolean} - */ - get collidable() { - return this._bitmapMesh.collidable; - } - - /** - * Sets if this ````Bitmap```` is clippable. - * - * Clipping is done by the {@link SectionPlane}s in {@link Scene#sectionPlanes}. - * - * Default is ````true````. - * - * @type {Boolean} - */ - set clippable(value) { - this._bitmapMesh.clippable = (value !== false); - } - - /** - * Gets if this ````Bitmap```` is clippable. - * - * Clipping is done by the {@link SectionPlane}s in {@link Scene#sectionPlanes}. - * - * Default is ````true````. - * - * @type {Boolean} - */ - get clippable() { - return this._bitmapMesh.clippable; - } - - /** - * Sets if this ````Bitmap```` is pickable. - * - * Default is ````true````. - * - * @type {Boolean} - */ - set pickable(value) { - this._bitmapMesh.pickable = (value !== false); - } - - /** - * Gets if this ````Bitmap```` is pickable. - * - * Default is ````true````. - * - * @type {Boolean} - */ - get pickable() { - return this._bitmapMesh.pickable; - } - - /** - * Sets the opacity factor for this ````Bitmap````. - * - * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas. - * - * @type {Number} - */ - set opacity(opacity) { - this._bitmapMesh.opacity = opacity; - } - - /** - * Gets this ````Bitmap````'s opacity factor. - * - * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas. - * - * @type {Number} - */ - get opacity() { - return this._bitmapMesh.opacity; - } - - /** - * Destroys this ````Bitmap````. - * - * Removes the ```Bitmap```` from {@link Scene#bitmaps}; causes Scene to fire a "bitmapDestroyed" event. - */ - destroy() { - super.destroy(); - this.scene._bitmapDestroyed(this); - } - - _updateBitmapMeshScale() { - const aspect = this._imageSize[1] / this._imageSize[0]; - this._bitmapMesh.scale = [this._height / aspect, 1.0, this._height]; - } -} - -/** - * Uses edge adjacency counts to identify if the given triangle mesh can be rendered with backface culling enabled. - * - * If all edges are connected to exactly two triangles, then the mesh will likely be a closed solid, and we can safely - * render it with backface culling enabled. - * - * Otherwise, the mesh is a surface, and we must render it with backface culling disabled. - * - * @private - */ -const isTriangleMeshSolid = (indices, positions) => { - - const vertexIndexMapping = []; - let edges = []; - - function compareIndexPositions(a, b) { - let posA, posB; - - for (let i = 0; i < 3; i++) { - posA = positions [a * 3 + i]; - posB = positions [b * 3 + i]; - - if (posA !== posB) { - return posB - posA; - } - } - - return 0; - } - // Group together indices corresponding to same position coordinates - let newIndices = indices.slice().sort(compareIndexPositions); - - // Calculate the mapping: - // - from original index in indices array - // - to indices-for-unique-positions - let uniqueVertexIndex = null; - - for (let i = 0, len = newIndices.length; i < len; i++) { - if (i === 0 || 0 !== compareIndexPositions( - newIndices[i], - newIndices[i - 1], - )) { - // different position - uniqueVertexIndex = newIndices [i]; - } - - vertexIndexMapping [ - newIndices[i] - ] = uniqueVertexIndex; - } - - // Generate the list of edges - for (let i = 0, len = indices.length; i < len; i += 3) { - - const a = vertexIndexMapping[indices[i]]; - const b = vertexIndexMapping[indices[i + 1]]; - const c = vertexIndexMapping[indices[i + 2]]; - - let a2 = a; - let b2 = b; - let c2 = c; - - if (a > b && a > c) { - if (b > c) { - a2 = a; - b2 = b; - c2 = c; - } else { - a2 = a; - b2 = c; - c2 = b; - } - } else if (b > a && b > c) { - if (a > c) { - a2 = b; - b2 = a; - c2 = c; - } else { - a2 = b; - b2 = c; - c2 = a; - } - } else if (c > a && c > b) { - if (a > b) { - a2 = c; - b2 = a; - c2 = b; - } else { - a2 = c; - b2 = b; - c2 = a; - } - } - - edges[i + 0] = [ - a2, b2 - ]; - edges[i + 1] = [ - b2, c2 - ]; - - if (a2 > c2) { - const temp = c2; - c2 = a2; - a2 = temp; - } - - edges[i + 2] = [ - c2, a2 - ]; - } - - // Group semantically equivalent edgdes together - function compareEdges(e1, e2) { - let a, b; - - for (let i = 0; i < 2; i++) { - a = e1[i]; - b = e2[i]; - - if (b !== a) { - return b - a; - } - } - - return 0; - } - - edges = edges.slice(0, indices.length); - - edges.sort(compareEdges); - - // Make sure each edge is used exactly twice - let sameEdgeCount = 0; - - for (let i = 0; i < edges.length; i++) { - if (i === 0 || 0 !== compareEdges( - edges[i], edges[i - 1] - )) { - // different edge - if (0 !== i && sameEdgeCount !== 2) { - return false; - } - - sameEdgeCount = 1; - } else { - // same edge - sameEdgeCount++; - } - } - - if (edges.length > 0 && sameEdgeCount !== 2) { - return false; - } - - // Each edge is used exactly twice, this is a - // watertight surface and hence a solid geometry. - return true; -}; - -const v1$1 = math.vec3(); -const v2$1 = math.vec3(); -const v3$1 = math.vec3(); - -/** - * Calculates the volume of triangle meshes. - */ -class MeshVolume { - constructor() { - this.vertices = []; - this.indices = []; - this.reset(); - } - - /** - * Resets, ready to add vertices and indices for a new mesh. - */ - reset() { - this.lenVertices = 0; - this.lenIndices = 0; - this.primitive = null; - } - - setPrimitive(primitive) { - this.primitive = primitive; - } - - /** - * Adds a vertex. - * @param vertex - */ - addVertex(vertex) { - this.vertices[this.lenVertices++] = vertex[0]; - this.vertices[this.lenVertices++] = vertex[1]; - this.vertices[this.lenVertices++] = vertex[2]; - } - - /** - * Adds an index. - * @param index - */ - addIndex(index) { - this.indices[this.lenIndices++] = index; - } - - /** - * Gets the volume of the mesh. - * - * The mesh must be a closed solid. - * - * @returns {number} The volume of the mesh, or -1 if the mesh is not solid, in which case volume cannot be determined. - */ - get volume() { - - const vertices = this.vertices; - const indices = this.indices; - - if (this.primitive !== "solid" && this.primitive !== "surface" && this.primitive !== "triangles") { - return -1; - } - - if (this.primitive !== "solid" && !isTriangleMeshSolid(indices, vertices)) { - return -1; - } - - let volume = 0; - - for (let i = 0; i < this.lenIndices; i += 3) { - - const index1 = indices[i] * 3; - const index2 = indices[i + 1] * 3; - const index3 = indices[i + 2] * 3; - - v1$1[0] = vertices[index1]; - v1$1[1] = vertices[index1 + 1]; - v1$1[2] = vertices[index1 + 2]; - - v2$1[0] = vertices[index2]; - v2$1[1] = vertices[index2 + 1]; - v2$1[2] = vertices[index2 + 2]; - - v3$1[0] = vertices[index3]; - v3$1[1] = vertices[index3 + 1]; - v3$1[2] = vertices[index3 + 2]; - - math.cross3Vec3(v1$1, v2$1, v1$1); - - volume += math.dotVec3(v1$1, v3$1); - } - - return volume / 6; - } -} - -/** - * Singleton instance of {@link MeshVolume}. - * @type {MeshVolume} - */ -const meshVolume = new MeshVolume(); - -const v1 = math.vec3(); -const v2 = math.vec3(); -const v3 = math.vec3(); -const v4 = math.vec3(); -const v5 = math.vec3(); -const v6 = math.vec3(); - -/** - * Calculates the surface area of triangle meshes. - */ -class MeshSurfaceArea { - constructor() { - this.vertices = []; - this.indices = []; - this.reset(); - } - - /** - * Resets, ready to add vertices and indices for a new mesh. - */ - reset() { - this.lenVertices = 0; - this.lenIndices = 0; - } - - /** - * Adds a vertex. - * @param vertex - */ - addVertex(vertex) { - this.vertices[this.lenVertices++] = vertex[0]; - this.vertices[this.lenVertices++] = vertex[1]; - this.vertices[this.lenVertices++] = vertex[2]; - } - - /** - * Adds an index. - * @param index - */ - addIndex(index) { - this.indices[this.lenIndices++] = index; - } - - /** - * Gets the surface area of the mesh. - * - * @returns {number} - */ - get surfaceArea() { - - const vertices = this.vertices; - const indices = this.indices; - - let surfaceArea = 0; - - for (let i = 0; i < this.lenIndices; i += 3) { - - const index1 = indices[i] * 3; - const index2 = indices[i + 1] * 3; - const index3 = indices[i + 2] * 3; - - v1[0] = vertices[index1]; - v1[1] = vertices[index1 + 1]; - v1[2] = vertices[index1 + 2]; - - v2[0] = vertices[index2]; - v2[1] = vertices[index2 + 1]; - v2[2] = vertices[index2 + 2]; - - v3[0] = vertices[index3]; - v3[1] = vertices[index3 + 1]; - v3[2] = vertices[index3 + 2]; - - math.subVec3(v1, v2, v4); - math.subVec3(v3, v2, v5); - - surfaceArea += math.lenVec3(math.cross3Vec3(v4, v5, v6)) * 0.5; - } - - return surfaceArea; - } -} - -/** - * Singleton instance of {@link MeshSurfaceArea}. - * @type {MeshSurfaceArea} - */ -const meshSurfaceArea = new MeshSurfaceArea(); - -const tempOBB3$1 = math.OBB3(); -const tempOBB3b = math.OBB3(); -const tempOBB3c = math.OBB3(); - - -/** - * A mesh within a {@link SceneModel}. - * - * * Created with {@link SceneModel#createMesh} - * * Belongs to exactly one {@link SceneModelEntity} - * * Stored by ID in {@link SceneModel#meshes} - * * Referenced by {@link SceneModelEntity#meshes} - * * Can have a {@link SceneModelTransform} to dynamically scale, rotate and translate it. - */ -class SceneModelMesh { - - /** - * @private - */ - constructor(model, id, color, opacity, transform, textureSet, layer = null, portionId = 0) { - - /** - * The {@link SceneModel} that owns this SceneModelMesh. - * - * @type {SceneModel} - */ - this.model = model; - - /** - * The {@link SceneModelEntity} that owns this SceneModelMesh. - * - * @type {SceneModelEntity} - */ - this.object = null; - - /** - * @private - */ - this.parent = null; - - /** - * The {@link SceneModelTransform} that transforms this SceneModelMesh. - * - * * This only exists when the SceneModelMesh is instancing its geometry. - * * These are created with {@link SceneModel#createTransform} - * * Each of these is also registered in {@link SceneModel#transforms}. - * - * @type {SceneModelTransform} - */ - this.transform = transform; - - /** - * The {@link SceneModelTextureSet} that optionally textures this SceneModelMesh. - * - * * This only exists when the SceneModelMesh has texture. - * * These are created with {@link SceneModel#createTextureSet} - * * Each of these is also registered in {@link SceneModel#textureSets}. - * - * @type {SceneModelTextureSet} - */ - this.textureSet = textureSet; - - this._matrixDirty = false; - this._matrixUpdateScheduled = false; - - /** - * Unique ID of this SceneModelMesh. - * - * The SceneModelMesh is registered against this ID in {@link SceneModel#meshes}. - */ - this.id = id; - - /** - * @private - */ - this.obb = null; - - this._aabbLocal = null; - this._aabbWorld = math.AABB3(); - this._aabbWorldDirty = false; - - /** - * @private - */ - this.layer = layer; - - /** - * @private - */ - this.portionId = portionId; - - this._color = new Uint8Array([color[0], color[1], color[2], opacity]); // [0..255] - this._colorize = new Uint8Array([color[0], color[1], color[2], opacity]); // [0..255] - this._colorizing = false; - this._transparent = (opacity < 255); - - /** - * @private - */ - this.numTriangles = 0; - - /** - * @private - * @type {null} - */ - this.origin = null; // Set By SceneModel - - /** - * The {@link SceneModelEntity} that owns this SceneModelMesh. - * - * @type {SceneModelEntity} - */ - this.entity = null; - - if (transform) { - transform._addMesh(this); - } - - this._volume = null; - this._surfaceArea = null; - } - - _sceneModelDirty() { - this._aabbWorldDirty = true; - this.layer.aabbChanged(); - } - - _transformDirty() { - if (!this._matrixDirty && !this._matrixUpdateScheduled) { - this.model._meshMatrixDirty(this); - this._matrixDirty = true; - this._matrixUpdateScheduled = true; - } - this._aabbWorldDirty = true; - this.layer.aabbChanged(); - if (this.entity) { - this.entity._transformDirty(); - } - } - - _updateMatrix() { - if (this.transform && this._matrixDirty) { - this.layer.setMatrix(this.portionId, this.transform.worldMatrix); - } - this._matrixDirty = false; - this._matrixUpdateScheduled = false; - } - - _finalize(entityFlags) { - this.layer.initFlags(this.portionId, entityFlags, this._transparent); - } - - _finalize2() { - if (this.layer.flushInitFlags) { - this.layer.flushInitFlags(); - } - } - - _setVisible(entityFlags) { - this.layer.setVisible(this.portionId, entityFlags, this._transparent); - } - - _setColor(color) { - this._color[0] = color[0]; - this._color[1] = color[1]; - this._color[2] = color[2]; - if (!this._colorizing) { - this.layer.setColor(this.portionId, this._color, false); - } - } - - _setColorize(colorize) { - const setOpacity = false; - if (colorize) { - this._colorize[0] = colorize[0]; - this._colorize[1] = colorize[1]; - this._colorize[2] = colorize[2]; - this.layer.setColor(this.portionId, this._colorize, setOpacity); - this._colorizing = true; - } else { - this.layer.setColor(this.portionId, this._color, setOpacity); - this._colorizing = false; - } - } - - _setOpacity(opacity, entityFlags) { - const newTransparent = (opacity < 255); - const lastTransparent = this._transparent; - const changingTransparency = (lastTransparent !== newTransparent); - this._color[3] = opacity; - this._colorize[3] = opacity; - this._transparent = newTransparent; - if (this._colorizing) { - this.layer.setColor(this.portionId, this._colorize); - } else { - this.layer.setColor(this.portionId, this._color); - } - if (changingTransparency) { - this.layer.setTransparent(this.portionId, entityFlags, newTransparent); - } - } - - _setOffset(offset) { - this.layer.setOffset(this.portionId, offset); - } - - _setHighlighted(entityFlags) { - this.layer.setHighlighted(this.portionId, entityFlags, this._transparent); - } - - _setXRayed(entityFlags) { - this.layer.setXRayed(this.portionId, entityFlags, this._transparent); - } - - _setSelected(entityFlags) { - this.layer.setSelected(this.portionId, entityFlags, this._transparent); - } - - _setEdges(entityFlags) { - this.layer.setEdges(this.portionId, entityFlags, this._transparent); - } - - _setClippable(entityFlags) { - this.layer.setClippable(this.portionId, entityFlags, this._transparent); - } - - _setCollidable(entityFlags) { - this.layer.setCollidable(this.portionId, entityFlags); - } - - _setPickable(flags) { - this.layer.setPickable(this.portionId, flags, this._transparent); - } - - _setCulled(flags) { - this.layer.setCulled(this.portionId, flags, this._transparent); - } - - /** - * @private - */ - canPickTriangle() { - return false; - } - - /** - * @private - */ - drawPickTriangles(renderFlags, frameCtx) { - // NOP - } - - /** - * @private - */ - pickTriangleSurface(pickResult) { - // NOP - } - - /** - * @private - */ - precisionRayPickSurface(worldRayOrigin, worldRayDir, worldSurfacePos, worldSurfaceNormal) { - return this.layer.precisionRayPickSurface(this.portionId, worldRayOrigin, worldRayDir, worldSurfacePos, worldSurfaceNormal); - } - - /** - * @private - */ - canPickWorldPos() { - return true; - } - - /** - * @private - */ - drawPickDepths(frameCtx) { - this.model.drawPickDepths(frameCtx); - } - - /** - * @private - */ - drawPickNormals(frameCtx) { - this.model.drawPickNormals(frameCtx); - } - - /** - * @private - */ - delegatePickedEntity() { - return this.parent; - } - - /** - * @private - */ - getEachVertex(callback) { - if (this.layer.getEachVertex) { - this.layer.getEachVertex(this.portionId, callback); - } - } - - /** - * @private - */ - getEachIndex(callback) { - if (this.layer.getEachIndex ) { - this.layer.getEachIndex(this.portionId, callback); - } - } - - isSolid() { - return this.layer.solid; - } - - /** - * Returns the volume of this SceneModelMesh. - * @returns {number} - */ - get volume() { - if (this._volume !== null) { - return this._volume; - } - switch (this.layer.primitive) { - case "solid": - case "surface": - case "triangles": - meshVolume.reset(); - meshVolume.setPrimitive(this.layer.primitive); - this.getEachVertex((vertex) =>{ - meshVolume.addVertex(vertex); - }); - this.getEachIndex((index)=>{ - meshVolume.addIndex(index); - }); - this._volume = meshVolume.volume; - break; - default: - this._volume = 0; - break; - } - return this._volume; - } - - /** - * Returns the surface area of this SceneModelMesh. - * @returns {number} - */ - get surfaceArea() { - if (this._surfaceArea !== null) { - return this._surfaceArea; - } - switch (this.layer.primitive) { - case "solid": - case "surface": - case "triangles": - meshSurfaceArea.reset(); - this.getEachVertex((vertex) =>{ - meshSurfaceArea.addVertex(vertex); - }); - this.getEachIndex((index)=>{ - meshSurfaceArea.addIndex(index); - }); - this._surfaceArea = meshSurfaceArea.surfaceArea; - break; - default: - this._surfaceArea = 0; - break; - } - return this._surfaceArea; - } - - /** - * @private - */ - set aabb(aabb) { // Called by SceneModel - this._aabbLocal = aabb; - if (this.origin) { - this._aabbLocal = aabb.slice(0); - const origin = this.origin; - this._aabbLocal[0] += origin[0]; - this._aabbLocal[1] += origin[1]; - this._aabbLocal[2] += origin[2]; - this._aabbLocal[3] += origin[0]; - this._aabbLocal[4] += origin[1]; - this._aabbLocal[5] += origin[2]; - } - } - - /** - * @private - */ - get aabb() { // called by SceneModelEntity - if (this._aabbWorldDirty) { - math.AABB3ToOBB3(this._aabbLocal, tempOBB3$1); - if (this.transform) { - math.transformOBB3(this.transform.worldMatrix, tempOBB3$1, tempOBB3b); - math.transformOBB3(this.model.worldMatrix, tempOBB3b, tempOBB3c); - math.OBB3ToAABB3(tempOBB3c, this._aabbWorld); - } else { - math.transformOBB3(this.model.worldMatrix, tempOBB3$1, tempOBB3b); - math.OBB3ToAABB3(tempOBB3b, this._aabbWorld); - } - this._aabbWorldDirty = false; - } - return this._aabbWorld; - } - - /** - * @private - */ - _destroy() { - this.model.scene._renderer.putPickID(this.pickId); - - this.layer = null; - } -} - -/** - * @private - * @type {{PICKABLE: number, CLIPPABLE: number, BACKFACES: number, VISIBLE: number, SELECTED: number, OUTLINED: number, CULLED: number, RECEIVE_SHADOW: number, COLLIDABLE: number, XRAYED: number, CAST_SHADOW: number, EDGES: number, HIGHLIGHTED: number}} - */ -const ENTITY_FLAGS = { - VISIBLE: 1, - CULLED: 1 << 2, - PICKABLE: 1 << 3, - CLIPPABLE: 1 << 4, - COLLIDABLE: 1 << 5, - CAST_SHADOW: 1 << 6, - RECEIVE_SHADOW: 1 << 7, - XRAYED: 1 << 8, - HIGHLIGHTED: 1 << 9, - SELECTED: 1 << 10, - EDGES: 1 << 11, - BACKFACES: 1 << 12, - TRANSPARENT: 1 << 13 -}; - -const ColorProgram = function(programVariables, geometry, logarithmicDepthBufferEnabled, lightSetup, sao, primitive) { - const vColor = programVariables.createVarying("vec4", "vColor", () => { - const attributes = geometry.attributes; - const color = (primitive === "points") ? `vec4(${attributes.color}.rgb, 1.0)` : `${attributes.color}`; - if (lightSetup) { - const lightComponents = [ - lightSetup.getAmbientColor() - ].concat( - lightSetup.directionalLights.map( - light => `max(dot(${attributes.normal.view}, ${light.getDirection(geometry.viewMatrix, attributes.position.view)}), 0.0) * ${light.getColor()}`)); - return `vec4(${lightComponents.join(" + ")}, 1) * ${color}`; - } else { - return color; - } - }); - const outColor = programVariables.createOutput("vec4", "outColor"); - return { - programName: "Color", - getHash: () => [lightSetup ? lightSetup.getHash() : "-", sao ? "sao" : "nosao"], - cleanerEdges: true, - getLogDepth: logarithmicDepthBufferEnabled && (vFragDepth => ((primitive !== "points") && (primitive !== "lines")) ? `${vFragDepth} + length(vec2(dFdx(${vFragDepth}), dFdy(${vFragDepth})))` : vFragDepth), - renderPassFlag: 0, // COLOR_OPAQUE | COLOR_TRANSPARENT - appendFragmentOutputs: (src, getGammaOutputExpression, gl_FragCoord, sliceColorOr) => { - if ((primitive === "points") || (primitive === "lines")) { - src.push(`${outColor} = ${vColor};`); - } else { - src.push(`vec4 fragColor = ${sliceColorOr(vColor)};`); - src.push(`${outColor} = ${(sao ? (`vec4(fragColor.rgb * ${sao.getAmbient(gl_FragCoord)}, fragColor.a)`) : "fragColor")};`); - } - }, - - filterIntensityRange: true, - incrementDrawState: true - }; -}; - -const ColorTextureProgram = function(programVariables, geometry, scene, lightSetup, sao, useAlphaCutoff, gammaOutput) { - const colorTexture = setupTexture(programVariables, "sampler2D", "uColorMap", sRGBEncoding, (set, state) => { - const texture = state.layerTextureSet.colorTexture; - texture && set(texture.texture); - }); - const materialAlphaCutoff = useAlphaCutoff && programVariables.createUniform("float", "materialAlphaCutoff", (set, state) => set(state.layerTextureSet.alphaCutoff)); - - const attributes = geometry.attributes; - const vViewPosition = programVariables.createVarying("vec3", "vViewPosition", () => `${attributes.position.view}.xyz`); - const vUV = programVariables.createVarying("vec2", "vUV", () => attributes.uv); - const vColor = programVariables.createVarying("vec4", "vColor", () => attributes.color); - - const outColor = programVariables.createOutput("vec4", "outColor"); - - return { - programName: "ColorTexture", - getHash: () => [lightSetup.getHash(), sao ? "sao" : "nosao", !!gammaOutput, useAlphaCutoff ? "alphaCutoffYes" : "alphaCutoffNo"], - getLogDepth: scene.logarithmicDepthBufferEnabled && (vFragDepth => vFragDepth), - renderPassFlag: 0, // COLOR_OPAQUE | COLOR_TRANSPARENT - appendFragmentOutputs: (src, getGammaOutputExpression, gl_FragCoord, sliceColorOr) => { - src.push(`vec3 viewNormal = normalize(cross(dFdx(${vViewPosition}), dFdy(${vViewPosition})));`); - src.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"); - lightSetup.directionalLights.forEach(light => { - src.push(`reflectedColor += max(dot(viewNormal, ${light.getDirection(geometry.viewMatrix, vViewPosition)}), 0.0) * ${light.getColor()};`); - }); - - src.push(`vec4 color = vec4(${lightSetup.getAmbientColor()} + reflectedColor, 1) * ${sliceColorOr(vColor)};`); - - src.push(`vec4 sampleColor = ${colorTexture(vUV)};`); - - if (materialAlphaCutoff) { - src.push(`if (sampleColor.a < ${materialAlphaCutoff}) { discard; }`); - } - - src.push("vec4 colorTexel = color * sampleColor;"); - src.push(`${outColor} = vec4(colorTexel.rgb${(sao ? (" * " + sao.getAmbient(gl_FragCoord)) : "")}, color.a);`); - - getGammaOutputExpression && src.push(`${outColor} = ${getGammaOutputExpression(outColor)};`); - }, - - incrementDrawState: true - }; -}; - -const DepthProgram = function(programVariables, geometry, logarithmicDepthBufferEnabled) { - const vHighPrecisionZW = programVariables.createVarying("highp vec2", "vHighPrecisionZW", () => `${geometry.attributes.position.clip}.zw`); - const outColor = programVariables.createOutput("vec4", "outColor"); - return { - programName: "Depth", - getLogDepth: logarithmicDepthBufferEnabled && (vFragDepth => vFragDepth), - renderPassFlag: 0, // COLOR_OPAQUE | COLOR_TRANSPARENT - // isn't it the same as vec4(vec3(1.0 - gl_FragCoord.z), 1.0) ? - appendFragmentOutputs: (src) => src.push(`${outColor} = vec4(vec3((1.0 - ${vHighPrecisionZW}[0] / ${vHighPrecisionZW}[1]) / 2.0), 1.0);`) - }; -}; - -const EdgesProgram = function(programVariables, geometry, logarithmicDepthBufferEnabled, colorUniform) { - const edgeColorUniform = colorUniform && programVariables.createUniform("vec4", "edgeColor", (set, state) => set(state.legacyFrameCtx.programColor)); - const color = geometry.attributes.color; - const vColor = (!colorUniform) && programVariables.createVarying("vec4", "vColor", () => `vec4(${color}.rgb * 0.5, ${color}.a)`); - const outColor = programVariables.createOutput("vec4", "outColor"); - return { - programName: colorUniform ? "Edges" : "EdgesColor", - getLogDepth: logarithmicDepthBufferEnabled && (vFragDepth => vFragDepth), - renderPassFlag: 2, // EDGES_COLOR_OPAQUE | EDGES_COLOR_TRANSPARENT | EDGES_HIGHLIGHTED | EDGES_XRAYED | EDGES_SELECTED - appendFragmentOutputs: (src) => src.push(`${outColor} = ${edgeColorUniform || vColor};`) - }; -}; - -const FlatColorProgram = function(programVariables, geometry, logarithmicDepthBufferEnabled, lightSetup, sao) { - const attributes = geometry.attributes; - const vViewPosition = programVariables.createVarying("vec3", "vViewPosition", () => `${attributes.position.view}.xyz`); - const vColor = programVariables.createVarying("vec4", "vColor", () => attributes.color); - const outColor = programVariables.createOutput("vec4", "outColor"); - return { - programName: "FlatColor", - getHash: () => [lightSetup.getHash(), sao ? "sao" : "nosao"], - cleanerEdges: true, - getLogDepth: logarithmicDepthBufferEnabled && (vFragDepth => vFragDepth), - renderPassFlag: 0, // COLOR_OPAQUE | COLOR_TRANSPARENT - appendFragmentOutputs: (src, getGammaOutputExpression, gl_FragCoord, sliceColorOr) => { - src.push(`vec3 viewNormal = normalize(cross(dFdx(${vViewPosition}), dFdy(${vViewPosition})));`); - const lightComponents = [ - lightSetup.getAmbientColor() - ].concat( - lightSetup.directionalLights.map( - light => `max(dot(viewNormal, ${light.getDirection(geometry.viewMatrix, vViewPosition)}), 0.0) * ${light.getColor()}`)); - - src.push(`vec4 fragColor = vec4(${lightComponents.join(" + ")}, 1) * ${sliceColorOr(vColor)};`); - src.push(`${outColor} = ${sao ? `vec4(fragColor.rgb * ${sao.getAmbient(gl_FragCoord)}, fragColor.a)` : "fragColor"};`); - } - }; -}; - -const OcclusionProgram = function(programVariables) { - const outColor = programVariables.createOutput("vec4", "outColor"); - return { - programName: "Occlusion", - renderPassFlag: 0, // COLOR_OPAQUE // Only opaque objects can be occluders - appendFragmentOutputs: (src) => src.push(`${outColor} = vec4(0.0, 0.0, 1.0, 1.0);`) // Occluders are blue - }; -}; - -const PBRProgram = function(programVariables, geometry, scene, lightSetup, sao) { - const setup2dTexture = (name, isSrgb, getTexture) => { - return setupTexture(programVariables, "sampler2D", name, isSrgb ? sRGBEncoding : LinearEncoding, (set, state) => { - const texture = getTexture(state.layerTextureSet); - texture && set(texture.texture); - }); - }; - - const attributes = geometry.attributes; - const getIrradiance = lightSetup.getIrradiance; - - const colorMap = setup2dTexture("uColorMap", true, textureSet => textureSet.colorTexture); - const metallicRoughMap = setup2dTexture("uMetallicRoughMap", false, textureSet => textureSet.metallicRoughnessTexture); - const emissiveMap = setup2dTexture("uEmissiveMap", true, textureSet => textureSet.emissiveTexture); - const normalMap = setup2dTexture("uNormalMap", false, textureSet => textureSet.normalsTexture); - const aOMap = setup2dTexture("uAOMap", false, textureSet => textureSet.occlusionTexture); - - const vViewPosition = programVariables.createVarying("vec3", "vViewPosition", () => `${attributes.position.view}.xyz`); - const vViewNormal = programVariables.createVarying("vec3", "vViewNormal", () => attributes.normal.view); - const vColor = programVariables.createVarying("vec4", "vColor", () => attributes.color); - const vUV = programVariables.createVarying("vec2", "vUV", () => attributes.uv); - const vMetallicRoughness = programVariables.createVarying("vec2", "vMetallicRoughness", () => attributes.metallicRoughness); - const vWorldNormal = programVariables.createVarying("vec3", "vWorldNormal", () => `${attributes.normal.world}.xyz`); - - const outColor = programVariables.createOutput("vec4", "outColor"); - - const saturate = programVariables.createFragmentDefinition( - "saturate", - (name, src) => src.push(`float ${name}(const in float a) { return clamp(a, 0.0, 1.0); }`)); - - const BRDF_Specular_GGX = programVariables.createFragmentDefinition( - "BRDF_Specular_GGX", - (name, src) => { - src.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"); - src.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"); - src.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"); - src.push("}"); - - src.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"); - src.push(" float a2 = ( alpha * alpha );"); - src.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"); - src.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"); - src.push(" return 1.0 / ( gl * gv );"); - src.push("}"); - - src.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"); - src.push(" float a2 = ( alpha * alpha );"); - src.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"); - src.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"); - src.push(" return 0.5 / max( gv + gl, 1e-6 );"); - src.push("}"); - - src.push("float D_GGX(const in float alpha, const in float dotNH) {"); - src.push(" float a2 = ( alpha * alpha );"); - src.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"); - src.push(" return 0.31830988618 * a2 / ( denom * denom);"); // 1/PI - src.push("}"); - - src.push(`vec3 ${name}(const in vec3 incidentLightDirection, const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`); - src.push(" float alpha = ( roughness * roughness );"); - src.push(" vec3 halfDir = normalize( incidentLightDirection + viewEyeDir );"); - src.push(` float dotNL = ${saturate}( dot( viewNormal, incidentLightDirection ) );`); - src.push(` float dotNV = ${saturate}( dot( viewNormal, viewEyeDir ) );`); - src.push(` float dotNH = ${saturate}( dot( viewNormal, halfDir ) );`); - src.push(` float dotLH = ${saturate}( dot( incidentLightDirection, halfDir ) );`); - src.push(" vec3 F = F_Schlick( specularColor, dotLH );"); - src.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"); - src.push(" float D = D_GGX( alpha, dotNH );"); - src.push(" return F * (G * D);"); - src.push("}"); - }); - - const BRDF_Specular_GGX_Environment = programVariables.createFragmentDefinition( - "BRDF_Specular_GGX_Environment", - (name, src) => { - src.push(`vec3 ${name}(const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`); - src.push(` float dotNV = ${saturate}(dot(viewNormal, viewEyeDir));`); - src.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"); - src.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"); - src.push(" vec4 r = roughness * c0 + c1;"); - src.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"); - src.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"); - src.push(" return specularColor * AB.x + AB.y;"); - src.push("}"); - }); - - const perturbNormal2Arb = programVariables.createFragmentDefinition( - "perturbNormal2Arb", - (name, src) => { - src.push(`vec3 ${name}( vec3 eye_pos, vec3 surf_norm, vec2 uv, vec4 texel ) {`); - src.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"); - src.push(" return surf_norm;"); - src.push(" }"); - src.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"); - src.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"); - src.push(" vec2 st0 = dFdx( uv.st );"); - src.push(" vec2 st1 = dFdy( uv.st );"); - src.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"); - src.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"); - src.push(" vec3 N = normalize( surf_norm );"); - src.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"); - src.push(" mat3 tsn = mat3( S, T, N );"); - // src.push(" mapN *= 3.0;"); - src.push(" return normalize( tsn * mapN );"); - src.push("}"); - }); - - return { - programName: "PBR", - getHash: () => [lightSetup.getHash(), sao ? "sao" : "nosao", !!scene.gammaOutput], - getLogDepth: scene.logarithmicDepthBufferEnabled && (vFragDepth => vFragDepth), - renderPassFlag: 0, // COLOR_OPAQUE | COLOR_TRANSPARENT - clippingCaps: scene._sectionPlanesState.clippingCaps && outColor, - incrementDrawState: true, - appendFragmentOutputs: (src, getGammaOutputExpression, gl_FragCoord) => { - src.push("const float PI = 3.14159265359;"); - src.push("vec3 reflDiff = vec3(0.0);"); - src.push("vec3 reflSpec = vec3(0.0);"); - - src.push(`vec3 rgb = ${vColor}.rgb;`); - src.push(`float opacity = ${vColor}.a;`); - - src.push("vec3 baseColor = rgb;"); - src.push("float specularF0 = 1.0;"); - src.push(`float metallic = float(${vMetallicRoughness}.r) / 255.0;`); - src.push(`float roughness = float(${vMetallicRoughness}.g) / 255.0;`); - src.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"); - - src.push(`vec4 colorTexel = ${colorMap(vUV)};`); - src.push("baseColor *= colorTexel.rgb;"); - // src.push("opacity *=/= colorTexel.a;"); // batching had "*=", instancing had "=" - - src.push(`vec3 metalRoughTexel = ${metallicRoughMap(vUV)}.rgb;`); - src.push("metallic *= metalRoughTexel.b;"); - src.push("roughness *= metalRoughTexel.g;"); - - src.push("vec3 diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"); - src.push("float specularRoughness = clamp(roughness, 0.04, 1.0);"); - src.push("vec3 specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"); - - src.push(`vec3 viewNormal = -${perturbNormal2Arb}(${vViewPosition}, normalize(${vViewNormal}), ${vUV}, ${normalMap(vUV)});`); - src.push(`vec3 viewEyeDir = normalize(${vViewPosition});`); - - getIrradiance && src.push(`reflDiff += ${getIrradiance(`normalize(${vWorldNormal})`)};`); - - if (lightSetup.getReflection) { - const reflectVec = `reflect(viewEyeDir, viewNormal)`; - const viewReflectVec = `normalize((vec4(${reflectVec}, 0.0) * ${geometry.viewMatrix}).xyz)`; - const maxMIPLevel = "8.0"; - const blinnExpFromRoughness = `(2.0 / pow(specularRoughness + 0.0001, 2.0) - 2.0)`; - const desiredMIPLevel = `${maxMIPLevel} - 0.79248 - 0.5 * log2(pow(${blinnExpFromRoughness}, 2.0) + 1.0)`; - const specularMIPLevel = `0.5 * clamp(${desiredMIPLevel}, 0.0, ${maxMIPLevel})`; // TODO: a random factor - fix this - const radiance = lightSetup.getReflection(viewReflectVec, specularMIPLevel); - const specularBRDFContrib = `${BRDF_Specular_GGX_Environment}(viewNormal, viewEyeDir, specularColor, specularRoughness)`; - src.push(`reflSpec += ${radiance} * ${specularBRDFContrib};`); - } - - lightSetup.directionalLights.forEach((light, i) => { - src.push(`vec3 lightDirection${i} = -${light.getDirection(geometry.viewMatrix, vViewPosition)};`); // This "-" might be wrong, but it used to be like that - const dotNL = `${saturate}(dot(viewNormal, lightDirection${i}))`; - src.push(`vec3 irradiance${i} = ${dotNL} * ${light.getColor()};`); - src.push(`reflDiff += irradiance${i};`); - src.push(`reflSpec += irradiance${i} * PI * ${BRDF_Specular_GGX}(lightDirection${i}, viewNormal, viewEyeDir, specularColor, specularRoughness);`); - }); - - src.push(`vec3 emissiveColor = ${emissiveMap(vUV)}.rgb;`); // TODO: correct gamma function - src.push(`float aoFactor = ${aOMap(vUV)}.r;`); - - const ambient = `${lightSetup.getAmbientColor()} * baseColor * opacity * rgb`; - src.push(`vec3 outgoingLight = emissiveColor + reflDiff * diffuseColor + reflSpec + ${ambient};`); - - src.push(`${outColor} = vec4(outgoingLight * aoFactor${sao ? ` * ${sao.getAmbient(gl_FragCoord)}` : ""}, opacity);`); - - getGammaOutputExpression && src.push(`${outColor} = ${getGammaOutputExpression(outColor)};`); - } - }; -}; - -const PickDepthProgram = function(programVariables, geometry, logarithmicDepthBufferEnabled) { - const far = programVariables.createUniform("float", "far", (set, state) => set(state.legacyFrameCtx.viewParams.far)); - const near = programVariables.createUniform("float", "near", (set, state) => set(state.legacyFrameCtx.viewParams.near)); - const vViewPosition = programVariables.createVarying("vec3", "vViewPosition", () => `${geometry.attributes.position.view}.xyz`); - const outPackedDepth = programVariables.createOutput("vec4", "outPackedDepth"); - const packDepth = programVariables.createFragmentDefinition( - "packDepth", - (name, src) => { - src.push(`vec4 ${name}(const in float depth) {`); - src.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"); - src.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"); - src.push(" vec4 res = fract(depth * bitShift);"); - src.push(" res -= res.xxyz * bitMask;"); - src.push(" return res;"); - src.push("}"); - }); - - return { - programName: "PickDepth", - getLogDepth: logarithmicDepthBufferEnabled && (vFragDepth => vFragDepth), - renderPassFlag: 3, // PICK - incPointSizeBy10: true, - appendFragmentOutputs: (src) => { - src.push(`float zNormalizedDepth = abs((${near} + ${vViewPosition}.z) / (${far} - ${near}));`); - // isn't zNormalizedDepth the same as gl_FragDepth or gl_FragCoord.z? - src.push(`${outPackedDepth} = ${packDepth}(zNormalizedDepth);`); // Must be linear depth - // try: src.push(" outPackedDepth = vec4(zNormalizedDepth, fract(zNormalizedDepth * vec3(256.0, 256.0*256.0, 256.0*256.0*256.0)));"); - } - }; -}; - -const PickMeshProgram = function(programVariables, geometry, logarithmicDepthBufferEnabled) { - const vPickColor = programVariables.createVarying("vec4", "vPickColor", () => `${geometry.attributes.pickColor} / 255.0`); - const outPickColor = programVariables.createOutput("vec4", "outPickColor"); - return { - programName: "PickMesh", - getLogDepth: logarithmicDepthBufferEnabled && (vFragDepth => vFragDepth), - renderPassFlag: 3, // PICK - incPointSizeBy10: true, - dontCullOnAlphaZero: true, // should be false? - appendFragmentOutputs: (src) => src.push(`${outPickColor} = ${vPickColor};`) - }; -}; - -const PickNormalsProgram = function(programVariables, geometry, logarithmicDepthBufferEnabled, isFlat) { - const vWorldPosition = programVariables.createVarying("vec3", "vWorldPosition", () => `${geometry.attributes.position.world}.xyz`); - const vWorldNormal = programVariables.createVarying("vec3", "vWorldNormal", () => geometry.attributes.normal.world); - const outNormal = programVariables.createOutput("highp ivec4", "outNormal"); - return { - programName: isFlat ? "PickNormalsFlat" : "PickNormals", - getLogDepth: logarithmicDepthBufferEnabled && (vFragDepth => vFragDepth), - renderPassFlag: 3, // PICK - appendFragmentOutputs: (src) => { - const worldNormal = (isFlat - ? `normalize(cross(dFdx(${vWorldPosition}), dFdy(${vWorldPosition})))` - : vWorldNormal); - src.push(`${outNormal} = ivec4(${worldNormal} * float(${math.MAX_INT}), 1.0);`); - } - }; -}; - -const ShadowProgram = function(programVariables, logarithmicDepthBufferEnabled) { - // VBOBatchingPointsShadowRenderer has been implemented by 14e973df6268369b00baef60e468939e062ac320, - // but never used (and probably not maintained), as opposed to VBOInstancingPointsShadowRenderer in the same commit - const outColor = programVariables.createOutput("vec4", "outColor"); - const encodeFloat = programVariables.createFragmentDefinition( - "encodeFloat", - (name, src) => { - src.push(`vec4 ${name}(const in float v) {`); - src.push(" const vec4 bitShift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);"); - src.push(" const vec4 bitMask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);"); - src.push(" vec4 comp = fract(v * bitShift);"); - src.push(" comp -= comp.xxyz * bitMask;"); - src.push(" return comp;"); - src.push("}"); - }); - return { - programName: "Shadow", - getLogDepth: logarithmicDepthBufferEnabled && (vFragDepth => vFragDepth), - renderPassFlag: 0, - isShadowProgram: true, - appendFragmentOutputs: (src, getGammaOutputExpression, gl_FragCoord) => src.push(`${outColor} = ${encodeFloat}(${gl_FragCoord}.z);`) - }; -}; - -const SilhouetteProgram = function(programVariables, geometry, logarithmicDepthBufferEnabled, isPointsOrLines) { - const silhouetteColor = programVariables.createUniform("vec4", "silhouetteColor", (set, state) => set(state.legacyFrameCtx.programColor)); - const vAlpha = programVariables.createVarying("float", "vAlpha", () => `${geometry.attributes.color}.a`); - const outColor = programVariables.createOutput("vec4", "outColor"); - return { - programName: "Silhouette", - getLogDepth: logarithmicDepthBufferEnabled && (vFragDepth => vFragDepth), - renderPassFlag: 1, // SILHOUETTE_HIGHLIGHTED | SILHOUETTE_SELECTED | SILHOUETTE_XRAYED - appendFragmentOutputs: (src, getGammaOutputExpression, gl_FragCoord, sliceColorOr) => { - src.push(`${outColor} = ${isPointsOrLines - ? silhouetteColor - : sliceColorOr(`vec4(${silhouetteColor}.rgb, min(${silhouetteColor}.a, ${vAlpha}))`)};`); - } - }; -}; - -const SnapProgram = function(programVariables, geometry, isSnapInit, isPoints) { - const layerNumber = programVariables.createUniform("int", "layerNumber", (set, state) => set(state.legacyFrameCtx.snapPickLayerParams.length)); - const coordinateScaler = programVariables.createUniform("vec3", "coordinateScaler", (set, state) => set(state.legacyFrameCtx.snapPickCoordinateScale)); - - const vWorldPosition = programVariables.createVarying("vec3", "vWorldPosition", () => `${geometry.attributes.position.world}.xyz`); - const vPickColor = programVariables.createVarying("vec4", "vPickColor", () => geometry.attributes.pickColor); // Using `flat` causes an instability - see XEOK-385 and XEOK-401 - - const outCoords = programVariables.createOutput("highp ivec4", "outCoords", 0); - const outNormal = programVariables.createOutput("highp ivec4", "outNormal", 1); - const outPickColor = programVariables.createOutput("lowp uvec4", "outPickColor", 2); - - return { - programName: isSnapInit ? "SnapInit" : "Snap", - // Improves occlusion accuracy at distance - getLogDepth: (vFragDepth => (isSnapInit ? `${vFragDepth} + length(vec2(dFdx(${vFragDepth}), dFdy(${vFragDepth})))` : vFragDepth)), - renderPassFlag: 3, // PICK - vertexCullX: (!isSnapInit) && "2.0", - dontCullOnAlphaZero: !isSnapInit, - appendFragmentOutputs: (src) => { - src.push(`${outCoords} = ivec4(${vWorldPosition} * ${coordinateScaler}.xyz, ${isSnapInit ? "-" : ""}${layerNumber});`); - if (isSnapInit) { - src.push(`${outNormal} = ${isPoints ? "ivec4(1.0)" : `ivec4(normalize(cross(dFdx(${vWorldPosition}), dFdy(${vWorldPosition}))) * float(${math.MAX_INT}), 1.0)`};`); - src.push(`${outPickColor} = uvec4(${vPickColor});`); - } - } - }; -}; - -const tempVec2 = math.vec2(); -const tempVec3$6 = math.vec3(); -const tempVec4$1 = math.vec4(); -const tempMat4$2 = math.mat4(); -const vec3zero = math.vec3([0,0,0]); - -const RENDER_PASSES = { - // Skipped - suppress rendering - NOT_RENDERED: 0, - - // Normal rendering - mutually exclusive modes - COLOR_OPAQUE: 1, - COLOR_TRANSPARENT: 2, - - // Emphasis silhouette rendering - mutually exclusive modes - SILHOUETTE_HIGHLIGHTED: 3, - SILHOUETTE_SELECTED: 4, - SILHOUETTE_XRAYED: 5, - - // Edges rendering - mutually exclusive modes - EDGES_COLOR_OPAQUE: 6, - EDGES_COLOR_TRANSPARENT: 7, - EDGES_HIGHLIGHTED: 8, - EDGES_SELECTED: 9, - EDGES_XRAYED: 10, - - // Picking - PICK: 11 -}; - -const safeInvVec3 = v => [ math.safeInv(v[0]), math.safeInv(v[1]), math.safeInv(v[2]) ]; - -const isPerspectiveMatrix = (m) => `(${m}[2][3] == - 1.0)`; - -const getColSilhEdgePickFlags = (flags, transparent, hasEdges, scene, dst) => { - const visible = !!(flags & ENTITY_FLAGS.VISIBLE); - const xrayed = !!(flags & ENTITY_FLAGS.XRAYED); - const highlighted = !!(flags & ENTITY_FLAGS.HIGHLIGHTED); - const selected = !!(flags & ENTITY_FLAGS.SELECTED); - const edges = !!(flags & ENTITY_FLAGS.EDGES); - const pickable = !!(flags & ENTITY_FLAGS.PICKABLE); - const culled = !!(flags & ENTITY_FLAGS.CULLED); - - let colorFlag; - if (!visible || culled || xrayed - || (highlighted && !scene.highlightMaterial.glowThrough) - || (selected && !scene.selectedMaterial.glowThrough)) { - colorFlag = RENDER_PASSES.NOT_RENDERED; - } else { - if (transparent) { - colorFlag = RENDER_PASSES.COLOR_TRANSPARENT; - } else { - colorFlag = RENDER_PASSES.COLOR_OPAQUE; - } - } - - let silhouetteFlag; - if (!visible || culled) { - silhouetteFlag = RENDER_PASSES.NOT_RENDERED; - } else if (selected) { - silhouetteFlag = RENDER_PASSES.SILHOUETTE_SELECTED; - } else if (highlighted) { - silhouetteFlag = RENDER_PASSES.SILHOUETTE_HIGHLIGHTED; - } else if (xrayed) { - silhouetteFlag = RENDER_PASSES.SILHOUETTE_XRAYED; - } else { - silhouetteFlag = RENDER_PASSES.NOT_RENDERED; - } - - let edgeFlag = 0; - if ((!hasEdges) || (!visible) || culled) { - edgeFlag = RENDER_PASSES.NOT_RENDERED; - } else if (selected) { - edgeFlag = RENDER_PASSES.EDGES_SELECTED; - } else if (highlighted) { - edgeFlag = RENDER_PASSES.EDGES_HIGHLIGHTED; - } else if (xrayed) { - edgeFlag = RENDER_PASSES.EDGES_XRAYED; - } else if (edges) { - if (transparent) { - edgeFlag = RENDER_PASSES.EDGES_COLOR_TRANSPARENT; - } else { - edgeFlag = RENDER_PASSES.EDGES_COLOR_OPAQUE; - } - } else { - edgeFlag = RENDER_PASSES.NOT_RENDERED; - } - - const pickFlag = (visible && !culled && pickable) ? RENDER_PASSES.PICK : RENDER_PASSES.NOT_RENDERED; - - dst[0] = colorFlag; - dst[1] = silhouetteFlag; - dst[2] = edgeFlag; - dst[3] = pickFlag; -}; - -const getRenderers = (function() { - const cachedRenderers = { }; - - return function(scene, layerType, primitive, saoEnabled, pbrSupported, colorTextureSupported, surfaceHasNormals, makeRenderingAttributes) { - const primKey = ((primitive === "points") || (primitive === "lines")) ? primitive : "triangles"; - const cacheKey = [ layerType, primKey, !!saoEnabled, !!pbrSupported, !!colorTextureSupported, !!surfaceHasNormals ].join(":"); - if (! (cacheKey in cachedRenderers)) { - cachedRenderers[cacheKey] = { }; - } - const cache = cachedRenderers[cacheKey]; - const sceneId = scene.id; - if (! (sceneId in cache)) { - const gl = scene.canvas.gl; - const wrapRenderer = function(createProgramSetup, subGeometry, isEager) { - const instantiate = function() { - const programVariablesState = createProgramVariablesState(); - const programVariables = programVariablesState.programVariables; - const renderingAttributes = makeRenderingAttributes(programVariables, subGeometry); - return createProgramSetup( - programVariables, - renderingAttributes.geometryParameters, - function(programSetup, usePickClipPos) { - const pointsMaterial = scene.pointsMaterial; - const setupPoints = (primitive === "points") && (! subGeometry); - - const getHash = () => [ scene._sectionPlanesState.getHash() ].concat(setupPoints ? [ pointsMaterial.hash ] : [ ]).concat(programSetup.getHash ? programSetup.getHash() : [ ]).join(";"); - const hash = getHash(); - const getValid = () => hash === getHash(); - - const geometryParameters = renderingAttributes.geometryParameters; - const incrementDrawState = programSetup.incrementDrawState; - const isShadowProgram = programSetup.isShadowProgram; - const attributes = geometryParameters.attributes; - const worldPositionAttribute = attributes.position.world; - const clipPos = "clipPos"; - - const [ program, errors ] = programVariablesState.buildProgram( - gl, - layerType + " " + primitive + " " + programSetup.programName, - { - appendFragmentOutputs: programSetup.appendFragmentOutputs, - cleanerEdges: programSetup.cleanerEdges, - clipPos: clipPos, - clippableTest: renderingAttributes.clippableTest, - clippingCaps: programSetup.clippingCaps, - crossSections: scene.crossSections, - discardPoints: setupPoints && pointsMaterial.roundPoints, - getGammaFactor: scene.gammaOutput && (() => scene.gammaFactor), - getLogDepth: programSetup.getLogDepth, - getPointSize: (function() { - const addends = [ ]; - if (setupPoints) { - const pointSize = programVariables.createUniform("float", "pointSize", (set) => set(pointsMaterial.pointSize)); - if (pointsMaterial.perspectivePoints) { - const nearPlaneHeight = programVariables.createUniform("float", "nearPlaneHeight", (set, state) => set(state.legacyFrameCtx.nearPlaneHeight)); - const minVal = `${Math.floor(pointsMaterial.minPerspectivePointSize)}.0`; - const maxVal = `${Math.floor(pointsMaterial.maxPerspectivePointSize)}.0`; - addends.push(`clamp((${nearPlaneHeight} * ${pointSize}) / gl_Position.w, ${minVal}, ${maxVal})`); - } else { - addends.push(pointSize); - } - } else if (subGeometry && subGeometry.vertices) { - addends.push("1.0"); - } - programSetup.incPointSizeBy10 && (primitive === "points") && addends.push("10.0"); - return (addends.length > 0) && (() => addends.join(" + ")); - })(), - getVertexData: () => { - const colorA = attributes.color; - const flag = attributes.flags[programSetup.renderPassFlag]; - const renderPass = programVariables.createUniform("int", "renderPass", (set, state) => set(state.renderPass)); - const flagTest = (isShadowProgram - ? `(${flag} <= 0) || (${colorA}.a < 1.0)` - : `${flag} != ${renderPass}`); - - const afterFlagsColorLines = [ - `if (${flagTest}) {`, - ` gl_Position = vec4(${programSetup.vertexCullX || 0.0}, 0.0, 0.0, 0.0);`, // Cull vertex - " return;", - "}" - ].concat( - ((! renderingAttributes.dontCullOnAlphaZero) && (! programSetup.dontCullOnAlphaZero)) - ? [ - `if (${colorA}.a == 0.0) {`, - " gl_Position = vec4(3.0, 3.0, 3.0, 1.0);", // Cull vertex - " return;", - "}" - ] - : [ ] - ).concat( - (programSetup.filterIntensityRange && (primitive === "points") && pointsMaterial.filterIntensity) - ? (function () { - const intensityRange = programVariables.createUniform("vec2", "intensityRange", (set) => { - tempVec2[0] = pointsMaterial.minIntensity; - tempVec2[1] = pointsMaterial.maxIntensity; - set(tempVec2); - }); - return [ - `if ((${colorA}.a < ${intensityRange}[0]) || (${colorA}.a > ${intensityRange}[1])) {`, - " gl_Position = vec4(0.0, 0.0, 0.0, 0.0);", // Cull vertex - " return;", - "}" - ]; - })() - : [ ]); - - const vertexData = [ ]; - renderingAttributes.ensureColorAndFlagAvailable && renderingAttributes.ensureColorAndFlagAvailable(vertexData); - afterFlagsColorLines.forEach(line => vertexData.push(line)); - renderingAttributes.appendVertexData(vertexData); - const viewPosition = geometryParameters.attributes.position.view; - vertexData.push(`vec4 ${viewPosition} = ${geometryParameters.viewMatrix} * ${worldPositionAttribute};`); - vertexData.push(`vec4 ${clipPos} = ${geometryParameters.projMatrix} * ${viewPosition};`); - return vertexData; - }, - projMatrix: geometryParameters.projMatrix, - sectionPlanesState: scene._sectionPlanesState, - testPerspectiveForGl_FragDepth: ((primitive !== "points") && (primitive !== "lines")) || subGeometry, - usePickClipPos: usePickClipPos, - worldPositionAttribute: worldPositionAttribute - }); - - if (errors) { - console.error(errors); - return { - getValid: getValid, - destroy: () => { }, - drawLayer: (frameCtx, layer, renderPass) => { } - }; - } else { - return { - getValid: getValid, - destroy: () => program.destroy(), - drawLayer: (frameCtx, layer, renderPass) => { - if (frameCtx.lastProgramId !== program.id) { - frameCtx.lastProgramId = program.id; - program.bind(); - } - - const origin = layer.origin; - const model = layer.model; - const viewParams = frameCtx.viewParams; - const rtcOrigin = tempVec3$6; - math.transformPoint3(model.matrix, origin, rtcOrigin); - - const viewMatrix = viewParams.viewMatrix; - const projMatrix = viewParams.projMatrix; - - if (frameCtx.snapPickOrigin) { - frameCtx.snapPickOrigin[0] = rtcOrigin[0]; - frameCtx.snapPickOrigin[1] = rtcOrigin[1]; - frameCtx.snapPickOrigin[2] = rtcOrigin[2]; - } - - const state = { - legacyFrameCtx: frameCtx, - layerTextureSet: layer.layerTextureSet, - mesh: { - layerIndex: layer.layerIndex, - origin: rtcOrigin, - renderFlags: { sectionPlanesActivePerLayer: model.renderFlags.sectionPlanesActivePerLayer }, - }, - renderPass: renderPass, - view: { - eye: viewParams.eye, - far: viewParams.far, - projMatrix: projMatrix, - viewMatrix: math.compareVec3(rtcOrigin, vec3zero) ? viewMatrix : createRTCViewMat(viewMatrix, rtcOrigin, tempMat4$2), - viewNormalMatrix: viewParams.viewNormalMatrix - } - }; - - program.inputSetters.setUniforms(frameCtx, state); - - layer.drawCalls[subGeometry ? (subGeometry.vertices ? "drawVertices" : "drawEdges") : "drawSurface"]( - program.inputSetters.attributesHash, - renderingAttributes.layerTypeInputs, - { - projMatrix: projMatrix, - viewMatrix: math.compareVec3(rtcOrigin, vec3zero) ? viewMatrix : createRTCViewMat(viewMatrix, rtcOrigin, tempMat4$2), - viewNormalMatrix: viewParams.viewNormalMatrix, - eye: viewParams.eye - }); - - if (incrementDrawState) { - frameCtx.drawElements++; - } - } - }; - } - }); - }; - let renderer = isEager && instantiate(); - return { - drawLayer: (frameCtx, layer, renderPass) => { - if (! renderer) { - renderer = instantiate(); - } - renderer.drawLayer(frameCtx, layer, renderPass); - }, - revalidate: force => { - if (renderer && (force || (! renderer.getValid()))) { - renderer.destroy(); - renderer = isEager && instantiate(); - } - } - }; - }; - - // Pre-initialize certain renderers that would otherwise be lazy-initialised on user interaction, - // such as picking or emphasis, so that there is no delay when user first begins interacting with the viewer. - const eager = (createProgramSetup, subGeometry) => wrapRenderer(createProgramSetup, subGeometry, true); - const lazy = (createProgramSetup, subGeometry) => wrapRenderer(createProgramSetup, subGeometry, false); - - const makeColorProgram = (vars, geo, lights, sao) => ColorProgram(vars, geo, scene.logarithmicDepthBufferEnabled, lights, sao, primitive); - - const makePickDepthProgram = (vars, geo, c) => c(PickDepthProgram(vars, geo, scene.logarithmicDepthBufferEnabled), true); - const makePickMeshProgram = (vars, geo, c) => c(PickMeshProgram(vars, geo, scene.logarithmicDepthBufferEnabled), true); - const makePickNormalsProgram = (vars, geo, c, isFlat) => c(PickNormalsProgram(vars, geo, scene.logarithmicDepthBufferEnabled, isFlat), true); - - const makeSnapProgram = (vars, geo, c, isSnapInit, isPoints) => c(SnapProgram(vars, geo, isSnapInit, isPoints), true); - - if (primitive === "points") { - cache[sceneId] = { - colorRenderers: { "sao-": { "vertex": lazy((vars, geo, c) => c(makeColorProgram(vars, geo, null, null))) } }, - occlusionRenderer: lazy((vars, geo, c) => c(OcclusionProgram(vars))), - pickDepthRenderer: lazy(makePickDepthProgram), - pickMeshRenderer: lazy(makePickMeshProgram), - // VBOBatchingPointsShadowRenderer has been implemented by 14e973df6268369b00baef60e468939e062ac320, - // but never used (and probably not maintained), as opposed to VBOInstancingPointsShadowRenderer in the same commit - // drawShadow has been nop in VBO point layers - // shadowRenderer: instancing && lazy((vars, geo, c) => c(ShadowProgram(scene.logarithmicDepthBufferEnabled))), - silhouetteRenderer: lazy((vars, geo, c) => c(SilhouetteProgram(vars, geo, scene.logarithmicDepthBufferEnabled, true))), - snapInitRenderer: lazy((vars, geo, c) => makeSnapProgram(vars, geo, c, true, true)), - snapVertexRenderer: lazy((vars, geo, c) => makeSnapProgram(vars, geo, c, false, true), { vertices: true }) - }; - } else if (primitive === "lines") { - cache[sceneId] = { - colorRenderers: { "sao-": { "vertex": lazy((vars, geo, c) => c(makeColorProgram(vars, geo, null, null))) } }, - silhouetteRenderer: lazy((vars, geo, c) => c(SilhouetteProgram(vars, geo, scene.logarithmicDepthBufferEnabled, true))), - snapInitRenderer: lazy((vars, geo, c) => makeSnapProgram(vars, geo, c, true, false)), - snapEdgeRenderer: lazy((vars, geo, c) => makeSnapProgram(vars, geo, c, false, false), { vertices: false }), - snapVertexRenderer: lazy((vars, geo, c) => makeSnapProgram(vars, geo, c, false, false), { vertices: true }) - }; - } else { - cache[sceneId] = { - colorRenderers: (function() { - // WARNING: Changing `useMaps' to `true' for DTX might have unexpected consequences while binding textures, as the DTX texture binding mechanism doesn't rely on `frameCtx.textureUnit` the way VBO does (see setSAORenderState); - const createLights = vars => createLightSetup(vars, scene._lightsState); - const createSAO = vars => { - const uSAOParams = vars.createUniform("vec4", "uSAOParams", (set, state) => set(state.legacyFrameCtx.saoParams)); - const uOcclusionTexture = setupTexture(vars, "sampler2D", "uOcclusionTexture", LinearEncoding, (set, state) => set(state.legacyFrameCtx.occlusionTexture)); - return { - getAmbient: (gl_FragCoord) => { - // Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top - // Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject - const uv = `${gl_FragCoord}.xy / ${uSAOParams}.xy`; // / viewportWH - const blendCutoff = `${uSAOParams}.z`; - const blendFactor = `${uSAOParams}.w`; - const unPackFactors = "(255. / 256.) / vec4(256. * 256. * 256., 256. * 256., 256., 1.)"; - return `(smoothstep(${blendCutoff}, 1.0, dot(${uOcclusionTexture(uv)}, ${unPackFactors})) * ${blendFactor})`; - } - }; - }; - const saoRenderers = function(useSao) { - const makeColorTextureProgram = (vars, geo, useAlphaCutoff) => ColorTextureProgram(vars, geo, scene, createLights(vars), useSao && createSAO(vars), useAlphaCutoff, scene.gammaOutput); // If gammaOutput set, then it expects that all textures and colors need to be outputted in premultiplied gamma. Default is false. - return { - "PBR": pbrSupported && lazy((vars, geo, c) => c(PBRProgram(vars, geo, scene, createLights(vars), useSao && createSAO(vars)))), - "texture": colorTextureSupported && { - "alphaCutoff-": lazy((vars, geo, c) => c(makeColorTextureProgram(vars, geo, false))), - "alphaCutoff+": lazy((vars, geo, c) => c(makeColorTextureProgram(vars, geo, true))) - }, - "vertex": (surfaceHasNormals - ? lazy((vars, geo, c) => c(makeColorProgram(vars, geo, createLights(vars), useSao && createSAO(vars)))) - : lazy((vars, geo, c) => c(FlatColorProgram(vars, geo, scene.logarithmicDepthBufferEnabled, createLights(vars), useSao && createSAO(vars))))) - }; - }; - return { - "sao-": saoRenderers(false), - "sao+": saoEnabled && saoRenderers(true) - }; - })(), - depthRenderer: lazy((vars, geo, c) => c(DepthProgram(vars, geo, scene.logarithmicDepthBufferEnabled))), - edgesRenderers: { - uniform: lazy((vars, geo, c) => c(EdgesProgram(vars, geo, scene.logarithmicDepthBufferEnabled, true)), { vertices: false }), - vertex: lazy((vars, geo, c) => c(EdgesProgram(vars, geo, scene.logarithmicDepthBufferEnabled, false)), { vertices: false }) - }, - occlusionRenderer: lazy((vars, geo, c) => c(OcclusionProgram(vars))), - pickDepthRenderer: eager(makePickDepthProgram), - pickMeshRenderer: eager(makePickMeshProgram), - pickNormalsFlatRenderer: eager((vars, geo, c) => makePickNormalsProgram(vars, geo, c, true)), - pickNormalsRenderer: eager((vars, geo, c) => makePickNormalsProgram(vars, geo, c, false)), - shadowRenderer: lazy((vars, geo, c) => c(ShadowProgram(vars, scene))), - silhouetteRenderer: eager((vars, geo, c) => c(SilhouetteProgram(vars, geo, scene.logarithmicDepthBufferEnabled, false))), - snapInitRenderer: eager((vars, geo, c) => makeSnapProgram(vars, geo, c, true, false)), - snapEdgeRenderer: eager((vars, geo, c) => makeSnapProgram(vars, geo, c, false, false), { vertices: false }), - snapVertexRenderer: eager((vars, geo, c) => makeSnapProgram(vars, geo, c, false, false), { vertices: true }) - }; - } - - const revalidateAll = force => { - (function rec(obj) { - if (obj.revalidate) { - obj.revalidate(force); - } else { - Object.values(obj).forEach(v => v && rec(v)); - } - })(cache[sceneId]); - }; - const compile = () => revalidateAll(false); - compile(); - scene.on("compile", compile); - scene.on("destroyed", () => { - delete cache[sceneId]; - }); - } - return cache[sceneId]; - }; -})(); - -class Layer { - - constructor(model, primitive, origin) { - - this.model = model; - this.primitive = primitive; - this.origin = origin; - - this._meshes = []; - // The axis-aligned World-space boundary of this Layer's positions. - this._aabb = math.collapseAABB3(); - this._aabbDirty = true; - } - - finalize() { - if (! this._compiledPortions) { - this._compiledPortions = this.compilePortions(); - this.solid = this._compiledPortions.solid; - this.sortId = this._compiledPortions.sortId; - this.layerTextureSet = this._compiledPortions.layerTextureSet; - this.drawCalls = this._compiledPortions.drawCalls; - this._renderers = this._compiledPortions.renderers; - this._setFlags = this._compiledPortions.setFlags; - - this.setColor = this._compiledPortions.setColor; - this.setMatrix = this._compiledPortions.setMatrix; - this.setOffset = this._compiledPortions.setOffset; - - this.getEachIndex = this._compiledPortions.getEachIndex; - this.getEachVertex = this._compiledPortions.getEachVertex; - this.readGeometryData = this._compiledPortions.readGeometryData; - this.precisionRayPickSurface = this._compiledPortions.precisionRayPickSurface; - - // These counts are used to avoid unnecessary render passes - this._countsByFlag = { }; - const setupFlagCount = (entityFlag, modelCountProperty) => { - const cnt = { - count: 0, - fromFlags: (flags, onlyIncrement) => { - if (flags & entityFlag) { - cnt.count++; - this.model[modelCountProperty]++; - } else if (! onlyIncrement) { - cnt.count--; - this.model[modelCountProperty]--; - } - } - }; - this._countsByFlag[entityFlag] = cnt; - }; - setupFlagCount(ENTITY_FLAGS.VISIBLE, "numVisibleLayerPortions"); - setupFlagCount(ENTITY_FLAGS.CULLED, "numCulledLayerPortions"); - setupFlagCount(ENTITY_FLAGS.PICKABLE, "numPickableLayerPortions"); - setupFlagCount(ENTITY_FLAGS.CLIPPABLE, "numClippableLayerPortions"); - setupFlagCount(ENTITY_FLAGS.XRAYED, "numXRayedLayerPortions"); - setupFlagCount(ENTITY_FLAGS.HIGHLIGHTED, "numHighlightedLayerPortions"); - setupFlagCount(ENTITY_FLAGS.SELECTED, "numSelectedLayerPortions"); - if (this._renderers.edgesRenderers) { - setupFlagCount(ENTITY_FLAGS.EDGES, "numEdgesLayerPortions"); - } - - // Optimize initFlags to not require Object.values call each time (adds up a lot) - this._countsByFlagArr = Object.values(this._countsByFlag); - this._numTransparentLayerPortions = 0; - } - } - - aabbChanged() { this._aabbDirty = true; } - - getAABB() { - if (this._aabbDirty) { // Per-layer AABB for best RTC accuracy - math.collapseAABB3(this._aabb); - this._meshes.forEach(m => math.expandAABB3(this._aabb, m.aabb)); - this._aabbDirty = false; - } - return this._aabb; - } - - __drawLayer(renderFlags, frameCtx, renderer, pass) { - if ((this._countsByFlag[ENTITY_FLAGS.CULLED].count < this._portions.length) && (this._countsByFlag[ENTITY_FLAGS.VISIBLE].count > 0)) { - const backfacePasses = (this.primitive !== "points") && (this.primitive !== "lines") && [ - RENDER_PASSES.COLOR_OPAQUE, - RENDER_PASSES.COLOR_TRANSPARENT, - RENDER_PASSES.PICK, - RENDER_PASSES.SILHOUETTE_HIGHLIGHTED, - RENDER_PASSES.SILHOUETTE_SELECTED, - RENDER_PASSES.SILHOUETTE_XRAYED, - ]; - if (backfacePasses && backfacePasses.includes(pass)) { - // _updateBackfaceCull - const backfaces = true; // See XCD-230 - if (frameCtx.backfaces !== backfaces) { - const gl = this.model.scene.canvas.gl; - { - gl.disable(gl.CULL_FACE); - } - frameCtx.backfaces = backfaces; - } - } - frameCtx.textureUnit = 0; // WIP Maybe only for (! snap)? - renderer.drawLayer(frameCtx, this, pass); - } - } - - __setVec4FromMaterialColorAlpha(color, alpha, dst) { - dst[0] = color[0]; - dst[1] = color[1]; - dst[2] = color[2]; - dst[3] = alpha; - return dst; - } - - // ---------------------- COLOR RENDERING ----------------------------------- - - __drawColor(renderFlags, frameCtx, renderOpaque) { - if ((renderOpaque ? (this._numTransparentLayerPortions < this._portions.length) : (this._numTransparentLayerPortions > 0)) - && - (this._countsByFlag[ENTITY_FLAGS.XRAYED].count < this._portions.length)) { - const saoRenderer = (renderOpaque && frameCtx.withSAO && this._renderers.colorRenderers["sao+"]) || this._renderers.colorRenderers["sao-"]; - const renderer = ((frameCtx.pbrEnabled && saoRenderer["PBR"]) - ? saoRenderer["PBR"] - : ((frameCtx.colorTextureEnabled && saoRenderer["texture"]) - ? saoRenderer["texture"][(this.layerTextureSet && (typeof(this.layerTextureSet.alphaCutoff) === "number")) ? "alphaCutoff+" : "alphaCutoff-"] - : saoRenderer["vertex"])); - const pass = renderOpaque ? RENDER_PASSES.COLOR_OPAQUE : RENDER_PASSES.COLOR_TRANSPARENT; - this.__drawLayer(renderFlags, frameCtx, renderer, pass); - } - } - - drawColorOpaque(renderFlags, frameCtx) { - this.__drawColor(renderFlags, frameCtx, true); - } - - drawColorTransparent(renderFlags, frameCtx) { - this.__drawColor(renderFlags, frameCtx, false); - } - - // ---------------------- RENDERING SAO POST EFFECT TARGETS -------------- - - drawDepth(renderFlags, frameCtx) { - // Assume whatever post-effect uses depth (eg SAO) does not apply to transparent objects - const renderer = this._renderers.depthRenderer; - if (renderer && (this._numTransparentLayerPortions < this._portions.length) && (this._countsByFlag[ENTITY_FLAGS.XRAYED].count < this._portions.length)) { - this.__drawLayer(renderFlags, frameCtx, renderer, RENDER_PASSES.COLOR_OPAQUE); - } - } - - // ---------------------- SILHOUETTE RENDERING ----------------------------------- - - __drawSilhouette(renderFlags, frameCtx, material, renderPass) { - frameCtx.programColor = this.__setVec4FromMaterialColorAlpha(material.fillColor, material.fillAlpha, tempVec4$1); - this.__drawLayer(renderFlags, frameCtx, this._renderers.silhouetteRenderer, renderPass); - } - - drawSilhouetteXRayed(renderFlags, frameCtx) { - if (this._countsByFlag[ENTITY_FLAGS.XRAYED].count > 0) { - this.__drawSilhouette(renderFlags, frameCtx, this.model.scene.xrayMaterial, RENDER_PASSES.SILHOUETTE_XRAYED); - } - } - - drawSilhouetteHighlighted(renderFlags, frameCtx) { - if (this._countsByFlag[ENTITY_FLAGS.HIGHLIGHTED].count > 0) { - this.__drawSilhouette(renderFlags, frameCtx, this.model.scene.highlightMaterial, RENDER_PASSES.SILHOUETTE_HIGHLIGHTED); - } - } - - drawSilhouetteSelected(renderFlags, frameCtx) { - if (this._countsByFlag[ENTITY_FLAGS.SELECTED].count > 0) { - this.__drawSilhouette(renderFlags, frameCtx, this.model.scene.selectedMaterial, RENDER_PASSES.SILHOUETTE_SELECTED); - } - } - - // ---------------------- EDGES RENDERING ----------------------------------- - - __drawVertexEdges(renderFlags, frameCtx, renderPass) { - const renderer = this._renderers.edgesRenderers && this._renderers.edgesRenderers.vertex; - if (renderer && (this._countsByFlag[ENTITY_FLAGS.EDGES].count > 0)) { - this.__drawLayer(renderFlags, frameCtx, renderer, renderPass); - } - } - - drawEdgesColorOpaque(renderFlags, frameCtx) { - this.__drawVertexEdges(renderFlags, frameCtx, RENDER_PASSES.EDGES_COLOR_OPAQUE); - } - - drawEdgesColorTransparent(renderFlags, frameCtx) { - if (this._numTransparentLayerPortions > 0) { - this.__drawVertexEdges(renderFlags, frameCtx, RENDER_PASSES.EDGES_COLOR_TRANSPARENT); - } - } - - __drawUniformEdges(renderFlags, frameCtx, material, renderPass) { - const renderer = this._renderers.edgesRenderers && this._renderers.edgesRenderers.uniform; - if (renderer) { - frameCtx.programColor = this.__setVec4FromMaterialColorAlpha(material.edgeColor, material.edgeAlpha, tempVec4$1); - this.__drawLayer(renderFlags, frameCtx, renderer, renderPass); - } - } - - drawEdgesHighlighted(renderFlags, frameCtx) { - if (this._countsByFlag[ENTITY_FLAGS.HIGHLIGHTED].count > 0) { - this.__drawUniformEdges(renderFlags, frameCtx, this.model.scene.highlightMaterial, RENDER_PASSES.EDGES_HIGHLIGHTED); - } - } - - drawEdgesSelected(renderFlags, frameCtx) { - if (this._countsByFlag[ENTITY_FLAGS.SELECTED].count > 0) { - this.__drawUniformEdges(renderFlags, frameCtx, this.model.scene.selectedMaterial, RENDER_PASSES.EDGES_SELECTED); - } - } - - drawEdgesXRayed(renderFlags, frameCtx) { - if (this._countsByFlag[ENTITY_FLAGS.XRAYED].count > 0) { - this.__drawUniformEdges(renderFlags, frameCtx, this.model.scene.xrayMaterial, RENDER_PASSES.EDGES_XRAYED); - } - } - - //---- PICKING ---------------------------------------------------------------------------------------------------- - - __drawPick(renderFlags, frameCtx, renderer) { - if (renderer) { - this.__drawLayer(renderFlags, frameCtx, renderer, RENDER_PASSES.PICK); - } - } - - drawPickMesh(renderFlags, frameCtx) { - this.__drawPick(renderFlags, frameCtx, this._renderers.pickMeshRenderer); - } - - drawPickDepths(renderFlags, frameCtx) { - this.__drawPick(renderFlags, frameCtx, this._renderers.pickDepthRenderer); - } - - drawPickNormals(renderFlags, frameCtx) { - const renderer = (this._renderers.pickNormalsFlatRenderer); - this.__drawPick(renderFlags, frameCtx, renderer); - } - - drawSnap(renderFlags, frameCtx, isSnapInit) { - frameCtx.snapPickOrigin = [0, 0, 0]; - - const aabb = this.getAABB(); - frameCtx.snapPickCoordinateScale = math.mulVec3Scalar( - safeInvVec3([ aabb[3] - aabb[0], aabb[4] - aabb[1], aabb[5] - aabb[2] ]), - math.MAX_INT); - - const renderer = isSnapInit ? this._renderers.snapInitRenderer : ((frameCtx.snapMode === "edge") ? this._renderers.snapEdgeRenderer : this._renderers.snapVertexRenderer); - this.__drawPick(renderFlags, frameCtx, renderer); - - frameCtx.snapPickLayerParams.push({ - origin: frameCtx.snapPickOrigin.slice(), - coordinateScale: safeInvVec3(frameCtx.snapPickCoordinateScale) - }); - } - - - drawOcclusion(renderFlags, frameCtx) { - const renderer = this._renderers.occlusionRenderer; - if (renderer) { - this.__drawLayer(renderFlags, frameCtx, renderer, RENDER_PASSES.COLOR_OPAQUE); - } - } - - drawShadow(renderFlags, frameCtx) { - const renderer = this._renderers.shadowRenderer; - if (renderer) { - this.__drawLayer(renderFlags, frameCtx, renderer, RENDER_PASSES.COLOR_OPAQUE); - } - } - - - initFlags(portionId, flags, transparent) { - this._countsByFlagArr.forEach(cnt => cnt.fromFlags(flags, true)); - - if (transparent) { - this._numTransparentLayerPortions++; - this.model.numTransparentLayerPortions++; - } - const deferred = (this.primitive !== "points"); - this._setFlags(portionId, flags, transparent, deferred); - this._compiledPortions.setFlags2(portionId, flags, deferred); - } - - flushInitFlags() { - this._compiledPortions.setDeferredFlags(); - } - - setVisible(portionId, flags, transparent) { - this._countsByFlag[ENTITY_FLAGS.VISIBLE].fromFlags(flags); - this._setFlags(portionId, flags, transparent); - } - - setCulled(portionId, flags, transparent) { - this._countsByFlag[ENTITY_FLAGS.CULLED].fromFlags(flags); - this._setFlags(portionId, flags, transparent); - } - - setPickable(portionId, flags, transparent) { - this._countsByFlag[ENTITY_FLAGS.PICKABLE].fromFlags(flags); - this._setFlags(portionId, flags, transparent); - } - - setClippable(portionId, flags) { - this._countsByFlag[ENTITY_FLAGS.CLIPPABLE].fromFlags(flags); - this._compiledPortions.setClippableFlags(portionId, flags); - } - - setCollidable(portionId, flags) { - } - - setXRayed(portionId, flags, transparent) { - this._countsByFlag[ENTITY_FLAGS.XRAYED].fromFlags(flags); - this._setFlags(portionId, flags, transparent); - } - - setHighlighted(portionId, flags, transparent) { - this._countsByFlag[ENTITY_FLAGS.HIGHLIGHTED].fromFlags(flags); - this._setFlags(portionId, flags, transparent); - } - - setSelected(portionId, flags, transparent) { - this._countsByFlag[ENTITY_FLAGS.SELECTED].fromFlags(flags); - this._setFlags(portionId, flags, transparent); - } - - setEdges(portionId, flags, transparent) { - if (this._countsByFlag[ENTITY_FLAGS.EDGES]) { - this._countsByFlag[ENTITY_FLAGS.EDGES].fromFlags(flags); - this._setFlags(portionId, flags, transparent); - } - } - - setTransparent(portionId, flags, transparent) { - if (transparent) { - this._numTransparentLayerPortions++; - this.model.numTransparentLayerPortions++; - } else { - this._numTransparentLayerPortions--; - this.model.numTransparentLayerPortions--; - } - this._setFlags(portionId, flags, transparent); - } - - destroy() { - this._compiledPortions && this._compiledPortions.destroy(); - } -} - -let maxDataTextureHeight = 1 << 16; -let maxGeometryBatchSize = 5000000; - -/** - * Manages global configurations for all {@link Viewer}s. - * - * ## Example - * - * In the example below, we'll disable xeokit's double-precision support, which gives a performance and memory boost - * on low-power devices, but also means that we can no longer render double-precision models without jittering. - * - * That's OK if we know that we're not going to view models that are geographically vast, or offset far from the World coordinate origin. - * - * [[Run this example](/examples/index.html#Configs_disableDoublePrecisionAndRAF)] - * - * ````javascript - * import {Configs, Viewer, XKTLoaderPlugin} from "https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/xeokit-sdk.es.min.js"; - * - * // Access xeoit-sdk global configs. - * // We typically set configs only before we create any Viewers. - * const configs = new Configs(); - * - * // Disable 64-bit precision for extra speed. - * // Only set this config once, before you create any Viewers. - * configs.doublePrecisionEnabled = false; - * - * // Create a Viewer, to which our configs apply - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.camera.eye = [-3.933, 2.855, 27.018]; - * viewer.camera.look = [4.400, 3.724, 8.899]; - * viewer.camera.up = [-0.018, 0.999, 0.039]; - * - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * const model = xktLoader.load({ - * src: "../assets/models/xkt/v8/ifc/Duplex.ifc.xkt" - * }); - * ```` - */ -class Configs { - - /** - * Creates a Configs. - */ - constructor() { - - } - - /** - * Sets whether double precision mode is enabled for Viewers. - * - * When double precision mode is enabled (default), Viewers will accurately render models that contain - * double-precision coordinates, without jittering. - * - * Internally, double precision incurs extra performance and memory overhead, so if we're certain that - * we're not going to render models that rely on double-precision coordinates, then it's a good idea to disable - * it, especially on low-power devices. - * - * This should only be set once, before creating any Viewers. - * - * @returns {Boolean} - */ - set doublePrecisionEnabled(doublePrecision) { - math.setDoublePrecisionEnabled(doublePrecision); - } - - /** - * Gets whether double precision mode is enabled for all Viewers. - * - * @returns {Boolean} - */ - get doublePrecisionEnabled() { - return math.getDoublePrecisionEnabled(); - } - - /** - * Sets the maximum data texture height. - * - * Should be a multiple of 1024. Default is 4096, which is the maximum allowed value. - */ - set maxDataTextureHeight(value) { - value = Math.ceil(value / 1024) * 1024; - if (value > 4096) { - value = 4096; - } else if (value < 1024) { - value = 1024; - } - maxDataTextureHeight = value; - } - - /** - * Sets maximum data texture height. - * @returns {*|number} - */ - get maxDataTextureHeight() { - return maxDataTextureHeight; - } - - /** - * Sets the maximum batched geometry VBO size. - * - * Default value is 5000000, which is the maximum size. - * - * Minimum size is 100000. - */ - set maxGeometryBatchSize(value) { - if (value < 100000) { - value = 100000; - } else if (value > 5000000) { - value = 5000000; - } - maxGeometryBatchSize = value; - } - - /** - * Gets the maximum batched geometry VBO size. - */ - get maxGeometryBatchSize() { - return maxGeometryBatchSize; - } -} - -const iota$3 = (n) => { const ret = [ ]; for (let i = 0; i < n; ++i) ret.push(i); return ret; }; - -const dataTextureRamStats = { - sizeDataColorsAndFlags: 0, - sizeDataInstancesMatrices: 0, - sizeDataPositionDecodeMatrices: 0, - sizeDataTextureOffsets: 0, - sizeDataTexturePositions: 0, - sizeDataTextureIndices: 0, - sizeDataTextureEdgeIndices: 0, - sizeDataTexturePortionIds: 0, - numberOfGeometries: 0, - numberOfPortions: 0, - numberOfLayers: 0, - numberOfTextures: 0, - totalPolygons: 0, - totalPolygons8Bits: 0, - totalPolygons16Bits: 0, - totalPolygons32Bits: 0, - totalEdges: 0, - totalEdges8Bits: 0, - totalEdges16Bits: 0, - totalEdges32Bits: 0, - cannotCreatePortion: { - because10BitsObjectId: 0, - becauseTextureSize: 0, - }, - overheadSizeAlignementIndices: 0, - overheadSizeAlignementEdgeIndices: 0, -}; - -window.printDataTextureRamStats = function () { - - console.log(JSON.stringify(dataTextureRamStats, null, 4)); - - let totalRamSize = 0; - - Object.keys(dataTextureRamStats).forEach(key => { - if (key.startsWith("size")) { - totalRamSize += dataTextureRamStats[key]; - } - }); - - console.log(`Total size ${totalRamSize} bytes (${(totalRamSize / 1000 / 1000).toFixed(2)} MB)`); - console.log(`Avg bytes / triangle: ${(totalRamSize / dataTextureRamStats.totalPolygons).toFixed(2)}`); - - let percentualRamStats = {}; - - Object.keys(dataTextureRamStats).forEach(key => { - if (key.startsWith("size")) { - percentualRamStats[key] = - `${(dataTextureRamStats[key] / totalRamSize * 100).toFixed(2)} % of total`; - } - }); - - console.log(JSON.stringify({percentualRamUsage: percentualRamStats}, null, 4)); -}; - -const configs = new Configs(); - -/** - * 12-bits allowed for object ids. - * Limits the per-object texture height in the layer. - */ -const MAX_NUMBER_OF_OBJECTS_IN_LAYER = (1 << 16); - -/** - * 4096 is max data texture height. - * Limits the aggregated geometry texture height in the layer. - */ -const MAX_DATA_TEXTURE_HEIGHT = configs.maxDataTextureHeight; - -/** - * Align `indices` and `edgeIndices` memory layout to 8 elements. - * - * Used as an optimization for the `...portionIds...` texture, so it - * can just be stored 1 out of 8 `portionIds` corresponding to a given - * `triangle-index` or `edge-index`. - */ -const INDICES_EDGE_INDICES_ALIGNEMENT_SIZE = 8; - -/** - * Number of maximum allowed per-object flags update per render frame - * before switching to batch update mode. - */ -const MAX_OBJECT_UPDATES_IN_FRAME_WITHOUT_BATCHED_UPDATE = 10; - -const tempVec3$5 = math.vec3(); -const tempVec3a$e = math.vec3(); -const tempVec4a$b = math.vec4(); -math.vec4(); -const tempMat4a = new Float32Array(16); -const tempUint8Array4$1 = new Uint8Array(4); - -const DEFAULT_MATRIX$1 = math.identityMat4(); - -/** - * @private - */ -class DTXLayer extends Layer { - - constructor(model, primitive, origin) { - - super(model, primitive, origin); - - dataTextureRamStats.numberOfLayers++; - - this._sortId = `TriDTX-${dataTextureRamStats.numberOfLayers}`; - - const gl = model.scene.canvas.gl; - - const geometryData = (indicesStatsProp, edgesStatsProp) => { - const indicesBuffer = [ ]; - let lenIndices = 0; - const perTriangleNumberPortionId = [ ]; - let numIndices = 0; - - const edgeIndicesBuffer = [ ]; - let lenEdgeIndices = 0; - const perEdgeNumberPortionId = [ ]; - let numEdgeIndices = 0; - - return { - len: () => numIndices, - - accumulateIndices: (indices, edgeIndices) => { - const accIndicesSubPortion = (indices && (indices.length > 0)) && (function() { - const indicesBase = lenIndices / 3; - lenIndices += indices.length; - indicesBuffer.push(indices); - const numTriangles = indices.length / 3; - return (subPortionId) => { - const currentNumIndices = numIndices; - numIndices += numTriangles * 3; - buffer.perObjectIndexBaseOffsets.push(currentNumIndices / 3 - indicesBase); - for (let i = 0; i < numTriangles; i += INDICES_EDGE_INDICES_ALIGNEMENT_SIZE) { - perTriangleNumberPortionId.push(subPortionId); - } - dataTextureRamStats[indicesStatsProp] += numTriangles; - dataTextureRamStats.totalPolygons += numTriangles; - }; - })(); - - const accEdgesSubPortion = edgeIndices && (function() { - const edgeIndicesBase = lenEdgeIndices / 2; - lenEdgeIndices += edgeIndices.length; - edgeIndicesBuffer.push(edgeIndices); - const numEdges = edgeIndices.length / 2; - return subPortionId => { - const currentNumEdgeIndices = numEdgeIndices; - numEdgeIndices += numEdges * 2; - buffer.perObjectEdgeIndexBaseOffsets.push(currentNumEdgeIndices / 2 - edgeIndicesBase); - for (let i = 0; i < numEdges; i += INDICES_EDGE_INDICES_ALIGNEMENT_SIZE) { - perEdgeNumberPortionId.push(subPortionId); - } - dataTextureRamStats[edgesStatsProp] += numEdges; - dataTextureRamStats.totalEdges += numEdges; - }; - })(); - - dataTextureRamStats.numberOfGeometries++; - - return { - numTriangles: indices ? (indices.length / 3) : 0, - accumulateSubPortionId: subPortionId => { - accIndicesSubPortion && accIndicesSubPortion(subPortionId); - accEdgesSubPortion && accEdgesSubPortion(subPortionId); - } - }; - }, - - createDrawers: (createTextureForSingleItems, indicesType) => { - const createTextureForPackedPortionIds = function(portionIdsArray, defaultIfEmpty) { - return (portionIdsArray.length > 0) ? createTextureForSingleItems([ portionIdsArray ], portionIdsArray.length, 1, gl.UNSIGNED_SHORT, "sizeDataTexturePortionIds") : defaultIfEmpty; - }; - - // Texture that holds the PortionId that corresponds to a given polygon-id. - const portionIdsTexture = createTextureForPackedPortionIds(perTriangleNumberPortionId, { texture: null }); - - // Texture that holds the unique-vertex-indices. - const indicesTexture = (lenIndices > 0) && createTextureForSingleItems(indicesBuffer, lenIndices, 3, indicesType, "sizeDataTextureIndices"); - - // Texture that holds the PortionId that corresponds to a given edge-id. - const portionEdgeIdsTexture = createTextureForPackedPortionIds(perEdgeNumberPortionId); - - // Texture that holds the unique-vertex-indices for 8-bit based edge indices. - const edgeIndicesTexture = (lenEdgeIndices > 0) && createTextureForSingleItems(edgeIndicesBuffer, lenEdgeIndices, 2, indicesType, "sizeDataTextureEdgeIndices"); - - return { - indices: function(layerTypeInputs, glMode) { - if (numIndices > 0) { - layerTypeInputs.perPrimIndices.setInputValue(indicesTexture); - layerTypeInputs.perPrimIdPorIds.setInputValue(portionIdsTexture); - gl.drawArrays(glMode, 0, numIndices); - } - }, - edges: function(layerTypeInputs, glMode) { - if (numEdgeIndices > 0) { - layerTypeInputs.perPrimIndices.setInputValue(edgeIndicesTexture); - layerTypeInputs.perPrimIdPorIds.setInputValue(portionEdgeIdsTexture); - gl.drawArrays(glMode, 0, numEdgeIndices); - } - } - }; - }, - - _clearToOptimizeGC: () => { indicesBuffer.length = edgeIndicesBuffer.length = 0; } - }; - }; - - const buffer = this._buffer = { - positionsCompressed: [], - lenPositionsCompressed: 0, - - geometry8Bits: geometryData("totalPolygons8Bits", "totalEdges8Bits"), - geometry16Bits: geometryData("totalPolygons16Bits", "totalEdges16Bits"), - geometry32Bits: geometryData("totalPolygons32Bits", "totalEdges32Bits"), - - perObjectColors: [], - perObjectPickColors: [], - perObjectSolid: [], - perObjectPositionsDecodeMatrices: [], - perObjectInstancePositioningMatrices: [], - perObjectVertexBases: [], - perObjectIndexBaseOffsets: [], - perObjectEdgeIndexBaseOffsets: [] - }; - - this._numVertices = 0; - - this._portions = []; // These counts are used to avoid unnecessary render passes - - this._subPortionReadableGeometries = this.model.scene.readableGeometryEnabled && {}; - - /** - * Due to `index rebucketting` process in ```prepareMeshGeometry``` function, it's possible that a single - * portion is expanded to more than 1 real sub-portion. - * - * This Array tracks the mapping between: - * - * - external `portionIds` as seen by consumers of this class. - * - internal `sub-portionIds` actually managed by this class. - * - * The outer index of this array is the externally seen `portionId`. - * The inner value of the array, are `sub-portionIds` corresponding to the `portionId`. - */ - this._portionToSubPortionsMap = []; - - this._bucketGeometries = {}; - - this._primitive = primitive; - } - - /** - * Returns whether the ```TrianglesDataTextureLayer``` has room for more portions. - * - * @param {object} portionCfg An object containing the geometrical data (`positions`, `indices`, `edgeIndices`) for the portion. - * @returns {Boolean} Wheter the requested portion can be created - */ - canCreatePortion(portionCfg) { - const numNewPortions = portionCfg.buckets.length; - if ((this._portions.length + numNewPortions) > MAX_NUMBER_OF_OBJECTS_IN_LAYER) { - dataTextureRamStats.cannotCreatePortion.because10BitsObjectId++; - } - let retVal = (this._portions.length + numNewPortions) <= MAX_NUMBER_OF_OBJECTS_IN_LAYER; - const bucketIndex = 0; // TODO: Is this a bug? - const bucketGeometryId = portionCfg.geometryId !== undefined && portionCfg.geometryId !== null - ? `${portionCfg.geometryId}#${bucketIndex}` - : `${portionCfg.id}#${bucketIndex}`; - const alreadyHasPortionGeometry = this._bucketGeometries[bucketGeometryId]; - if (!alreadyHasPortionGeometry) { - const buffer = this._buffer; - const maxIndicesOfAnyBits = Math.max(buffer.geometry8Bits.len(), buffer.geometry16Bits.len(), buffer.geometry32Bits.len()); - let numVertices = 0; - let numIndices = 0; - portionCfg.buckets.forEach(bucket => { - numVertices += bucket.positionsCompressed.length / 3; - numIndices += bucket.indices.length / 3; - }); - if ((this._numVertices + numVertices) > MAX_DATA_TEXTURE_HEIGHT * 4096 || - (maxIndicesOfAnyBits + numIndices) > MAX_DATA_TEXTURE_HEIGHT * 4096) { - dataTextureRamStats.cannotCreatePortion.becauseTextureSize++; - } - retVal &&= - (this._numVertices + numVertices) <= MAX_DATA_TEXTURE_HEIGHT * 4096 && - (maxIndicesOfAnyBits + numIndices) <= MAX_DATA_TEXTURE_HEIGHT * 4096; - } - return retVal; - } - - /** - * Creates a new portion within this TrianglesDataTextureLayer, returns the new portion ID. - * - * Gives the portion the specified geometry, color and matrix. - * - * @param mesh The SceneModelMesh that owns the portion - * @param portionCfg.positionsCompressed Flat float Local-space positionsCompressed array. - * @param [portionCfg.normals] Flat float normals array. - * @param [portionCfg.colors] Flat float colors array. - * @param portionCfg.indices Flat int indices array. - * @param [portionCfg.edgeIndices] Flat int edges indices array. - * @param portionCfg.color Quantized RGB color [0..255,0..255,0..255,0..255] - * @param portionCfg.opacity Opacity [0..255] - * @param [portionCfg.meshMatrix] Flat float 4x4 matrix - transforms the portion within the coordinate system that's local to the SceneModel - * @param portionCfg.worldAABB Flat float AABB World-space AABB - * @param portionCfg.pickColor Quantized pick color - * @returns {number} Portion ID - */ - createPortion(mesh, portionCfg) { - const buffer = this._buffer; - // const portionAABB = portionCfg.worldAABB; - const subPortionIds = portionCfg.buckets.map((bucket, bucketIndex) => { - const bucketGeometryId = (portionCfg.geometryId ?? portionCfg.id) + "#" + bucketIndex; - // const subPortionAABB = math.collapseAABB3(tempAABB3b); - if (! (bucketGeometryId in this._bucketGeometries)) { - const aligned = (indices, elementSize, statsProp) => { - // Indices and EdgeIndices alignement - // This will make every mesh consume a multiple of INDICES_EDGE_INDICES_ALIGNEMENT_SIZE - // array items for storing the triangles and edges of the mesh, and it supports: - // - a memory optimization of factor INDICES_EDGE_INDICES_ALIGNEMENT_SIZE - // - in exchange for a small RAM overhead - // (by adding some padding until a size that is multiple of INDICES_EDGE_INDICES_ALIGNEMENT_SIZE) - if (indices) { - const alignedLen = Math.ceil((indices.length / elementSize) / INDICES_EDGE_INDICES_ALIGNEMENT_SIZE) * INDICES_EDGE_INDICES_ALIGNEMENT_SIZE * elementSize; - const alignedArray = new Uint32Array(alignedLen); - alignedArray.set(indices); - dataTextureRamStats[statsProp] += 2 * (alignedArray.length - indices.length); - return alignedArray; - } else { - return indices; - } - }; - - bucket.indices = aligned(bucket.indices, 3, "overheadSizeAlignementIndices"); - bucket.edgeIndices = aligned(bucket.edgeIndices, 2, "overheadSizeAlignementEdgeIndices"); - - const positionsCompressed = bucket.positionsCompressed; - buffer.positionsCompressed.push(positionsCompressed); - const numVertices = positionsCompressed.length / 3; - this._numVertices += numVertices; - const vertexBase = buffer.lenPositionsCompressed / 3; - buffer.lenPositionsCompressed += positionsCompressed.length; - - this._bucketGeometries[bucketGeometryId] = { - vertexBase: vertexBase, - geometryData: (function() { - const indices = bucket.indices; - const edgeIndices = bucket.edgeIndices; - if (numVertices <= (1 << 8)) { - return buffer.geometry8Bits.accumulateIndices( indices, edgeIndices); - } else if (numVertices <= (1 << 16)) { - return buffer.geometry16Bits.accumulateIndices(indices, edgeIndices); - } else { - return buffer.geometry32Bits.accumulateIndices(indices, edgeIndices); - } - })() - }; - } - - //math.expandAABB3(portionAABB, subPortionAABB); - const bucketGeometry = this._bucketGeometries[bucketGeometryId]; - buffer.perObjectPositionsDecodeMatrices.push(portionCfg.positionsDecodeMatrix); - buffer.perObjectInstancePositioningMatrices.push(portionCfg.meshMatrix || DEFAULT_MATRIX$1); - buffer.perObjectSolid.push(!!portionCfg.solid); - buffer.perObjectPickColors.push(portionCfg.pickColor); - buffer.perObjectVertexBases.push(bucketGeometry.vertexBase); - - const colors = portionCfg.colors; - const color = portionCfg.color; // Color is pre-quantized by SceneModel - buffer.perObjectColors.push(colors - ? [ colors[0] * 255, colors[1] * 255, colors[2] * 255, 255 ] - : [ color[0], color[1], color[2], portionCfg.opacity ]); - - const subPortionId = this._portions.length; - this._portions.push({ }); - bucketGeometry.geometryData.accumulateSubPortionId(subPortionId); - - if (this._subPortionReadableGeometries) { - this._subPortionReadableGeometries[subPortionId] = { - indices: bucket.indices, - positionsCompressed: bucket.positionsCompressed, - positionsDecodeMatrix: portionCfg.positionsDecodeMatrix - }; - } - - dataTextureRamStats.numberOfPortions++; - - return subPortionId; - }); - const portionId = this._portionToSubPortionsMap.length; - this._portionToSubPortionsMap.push(subPortionIds); - this.model.numPortions++; - this._meshes.push(mesh); - return portionId; - } - - /** - * Builds data textures from the appended geometries and loads them into the GPU. - * - * No more portions can then be created. - */ - compilePortions() { - const buffer = this._buffer; - const model = this.model; - const numPortions = this._portions.length; - const origin = this.origin; - const portionToSubPortionsMap = this._portionToSubPortionsMap; - const primitive = this._primitive; - const sortId = this._sortId; - const subPortionReadableGeometries = this._subPortionReadableGeometries; - - const scene = model.scene; - const gl = scene.canvas.gl; - - /* - * Texture that holds colors/pickColors/flags/flags2 per-object: - * - columns: one concept per column => color / pick-color / ... - * - row: the object Id - * The texture will have: - * - 4 RGBA columns per row: for each object (pick) color and flags(2) - * - N rows where N is the number of objects - */ - const populateTexArray = texArray => { - const pack32as4x8 = ui32 => [ - (ui32 >> 24) & 255, - (ui32 >> 16) & 255, - (ui32 >> 8) & 255, - (ui32) & 255 - ]; - for (let i = 0; i < numPortions; i++) { - // 8 columns per texture row: - texArray.set(buffer.perObjectColors[i], i * 32 + 0); // (RGBA) - texArray.set(buffer.perObjectPickColors[i], i * 32 + 4); // (packed Uint32 as RGBA) - texArray.set([0, 0, 0, 0], /* flags */ i * 32 + 8); // (packed 4 bytes as RGBA) - texArray.set([0, 0, 0, 0], /* flags2 */ i * 32 + 12); // (packed 4 bytes as RGBA) - texArray.set(pack32as4x8(buffer.perObjectVertexBases[i]), i * 32 + 16); // (packed Uint32 bytes as RGBA) - texArray.set(pack32as4x8(buffer.perObjectIndexBaseOffsets[i]), i * 32 + 20); // (packed Uint32 bytes as RGBA) - texArray.set(pack32as4x8(buffer.perObjectEdgeIndexBaseOffsets[i]), i * 32 + 24); // (packed Uint32 bytes as RGBA) - texArray.set([buffer.perObjectSolid[i] ? 1 : 0, 0, 0, 0], i * 32 + 28); // (packed 4 bytes as RGBA) - } - }; - - // The number of rows in the texture is the number of objects in the layer. - const texturePerObjectColorsAndFlags = createBindableDataTexture(gl, numPortions, 32, gl.UNSIGNED_BYTE, 512, populateTexArray, "sizeDataColorsAndFlags", true); - const texturePerObjectColorsAndFlagsData = texturePerObjectColorsAndFlags.textureData; - - const createDataTexture = function(dataArrays, entitiesCnt, entitySize, type, entitiesPerRow, statsProp, exposeData) { - const populateTexArray = texArray => { - for (let i = 0, j = 0, len = dataArrays.length; i < len; i++) { - const pc = dataArrays[i]; - texArray.set(pc, j); - j += pc.length; - } - }; - return createBindableDataTexture(gl, entitiesCnt, entitySize, type, entitiesPerRow, populateTexArray, statsProp, exposeData); - }; - - const createTextureForMatrices = function(matrices, statsProp, exposeData) { - const numMatrices = matrices.length; - if (numMatrices === 0) { - throw "num " + statsProp + " matrices===0"; - } - // in one row we can fit 512 matrices - return createDataTexture(matrices, numMatrices, 16, gl.FLOAT, 512, statsProp, exposeData); - }; - - /** - * This will generate a texture for all positions decode matrices in the layer. - * The texture will have: - * - 4 RGBA columns per row (each column will contain 4 packed half-float (16 bits) components). - * Thus, each row will contain 16 packed half-floats corresponding to a complete positions decode matrix) - * - N rows where N is the number of objects - */ - const texturePerObjectInstanceMatrices = createTextureForMatrices(buffer.perObjectInstancePositioningMatrices, "sizeDataInstancesMatrices", true); - const texturePerObjectInstanceMatricesData = texturePerObjectInstanceMatrices.textureData; - - /* - * Texture that holds the objectDecodeAndInstanceMatrix per-object: - * - columns: each column is one column of the matrix - * - row: the object Id - * The texture will have: - * - 4 RGBA columns per row (each column will contain 4 packed half-float (16 bits) components). - * Thus, each row will contain 16 packed half-floats corresponding to a complete positions decode matrix) - * - N rows where N is the number of objects - */ - const texturePerObjectPositionsDecodeMatrix = createTextureForMatrices(buffer.perObjectPositionsDecodeMatrices, "sizeDataPositionDecodeMatrices", false); - - - const createTextureForSingleItems = function(dataArrays, dataCnt, entitySize, type, statsProp) { - return createDataTexture(dataArrays, dataCnt / entitySize, entitySize, type, 4096, statsProp, false); - }; - - /* - * Texture that holds all the `different-vertices` used by the layer. - * This will generate a texture for positions in the layer. - * - * The texture will have: - * - 1024 columns, where each pixel will be a 16-bit-per-component RGB texture, corresponding to the XYZ of the position - * - a number of rows R where R*1024 is just >= than the number of vertices (positions / 3) - */ - const texturePerVertexIdCoordinates = createTextureForSingleItems( - buffer.positionsCompressed, buffer.lenPositionsCompressed, 3, gl.UNSIGNED_SHORT, "sizeDataTexturePositions"); - - const draw8 = buffer.geometry8Bits.createDrawers( createTextureForSingleItems, gl.UNSIGNED_BYTE); - const draw16 = buffer.geometry16Bits.createDrawers(createTextureForSingleItems, gl.UNSIGNED_SHORT); - const draw32 = buffer.geometry32Bits.createDrawers(createTextureForSingleItems, gl.UNSIGNED_INT); - - // Optimization to free up memory (XCD-408 and XCD-424). - // The following lines were added to assist GC in cleaning up some of the data. See also the `texArray = null`. - // A Chrome test with Lyon[1-9].xkt models loaded simultaneously showed a decrease of 596MB to 158MB. - this._bucketGeometries = null; - this._buffer.geometry8Bits._clearToOptimizeGC(); - this._buffer.geometry16Bits._clearToOptimizeGC(); - this._buffer.geometry32Bits._clearToOptimizeGC(); - Object.keys(this._buffer).forEach(k => this._buffer[k] = null); - this._buffer = null; - - let deferredSetFlagsActive = false; - let deferredSetFlagsDirty = false; - let destroyed = false; - let numUpdatesInFrame = 0; - - - /** - * This will _start_ a "set-flags transaction". - * - * After invoking this method, calling setFlags/setFlags2 will not update - * the colors+flags texture but only store the new flags/flag2 in the - * colors+flags texture data array. - * - * After invoking this method, and when all desired setFlags/setFlags2 have - * been called on needed portions of the layer, invoke `uploadDeferredFlags` - * to actually upload the data array into the texture. - * - * In massive "set-flags" scenarios like VFC or LOD mechanisms, the combination of - * `beginDeferredFlags` + `uploadDeferredFlags`brings a speed-up of - * up to 80x when e.g. objects are massively (un)culled 🚀. - */ - const beginDeferredFlags = () => { deferredSetFlagsActive = true; }; - - const onSceneRendering = scene.on("rendering", () => { - if (deferredSetFlagsDirty) { - // uploadDeferredFlags - /** - * This will _commit_ a "set-flags transaction". - * Invoking this method will update the colors+flags texture data with new - * flags/flags2 set since the previous invocation of `beginDeferredFlags`. - */ - deferredSetFlagsActive = false; - deferredSetFlagsDirty = false; - texturePerObjectColorsAndFlagsData.reloadData(); - } - numUpdatesInFrame = 0; - }); - - const forEachSubPortionId = (portionId, cb) => { - const subPortionIds = portionToSubPortionsMap[portionId]; - if (!subPortionIds) { - model.error("portion not found: " + portionId); - } else { - for (let i = 0, len = subPortionIds.length; i < len; i++) { - cb(subPortionIds[i]); - } - } - }; - - const setPortionColorsAndFlags = (subPortionId, offset, data, deferred) => { - const defer = deferredSetFlagsActive || deferred; - if (defer) { - deferredSetFlagsDirty = true; - } else if (++numUpdatesInFrame >= MAX_OBJECT_UPDATES_IN_FRAME_WITHOUT_BATCHED_UPDATE) { - beginDeferredFlags(); // Subsequent flags updates now deferred - } - texturePerObjectColorsAndFlagsData.setData(data, subPortionId, offset, !defer); - }; - - const setFlags2 = (portionId, flags, deferred = false) => { - tempUint8Array4$1.set([ (flags & ENTITY_FLAGS.CLIPPABLE) ? 255 : 0, 0, 1, 2 ]); - forEachSubPortionId(portionId, subPortionId => setPortionColorsAndFlags(subPortionId, 3, tempUint8Array4$1, deferred)); - }; - - return { - sortId: sortId, - setClippableFlags: setFlags2, - setFlags: (portionId, flags, transparent, deferred = false) => { - getColSilhEdgePickFlags(flags, transparent, true, scene, tempUint8Array4$1); - forEachSubPortionId(portionId, subPortionId => setPortionColorsAndFlags(subPortionId, 2, tempUint8Array4$1, deferred)); - }, - setFlags2: setFlags2, - setDeferredFlags: () => { }, - - setColor: (portionId, color) => { - tempUint8Array4$1.set(color); - forEachSubPortionId(portionId, subPortionId => setPortionColorsAndFlags(subPortionId, 0, tempUint8Array4$1, false)); - }, - setMatrix: (portionId, matrix) => { - forEachSubPortionId(portionId, subPortionId => { - const defer = deferredSetFlagsActive; - if (defer) { - deferredSetFlagsDirty = true; - } else if (++numUpdatesInFrame >= MAX_OBJECT_UPDATES_IN_FRAME_WITHOUT_BATCHED_UPDATE) { - beginDeferredFlags(); // Subsequent flags updates now deferred - } - tempMat4a.set(matrix); - texturePerObjectInstanceMatricesData.setData(tempMat4a, subPortionId, 0, !defer); - }); - }, - setOffset: (portionId, offset) => { /* NOT COMPLETE */ }, - - getEachIndex: (portionId, callback) => { - if (subPortionReadableGeometries) { - forEachSubPortionId( - portionId, - subPortionId => subPortionReadableGeometries[subPortionId].indices.forEach(i => callback(i))); - } - }, - getEachVertex: (portionId, callback) => { - if (subPortionReadableGeometries) { - forEachSubPortionId(portionId, subPortionId => { - const subPortionReadableGeometry = subPortionReadableGeometries[subPortionId]; - const positions = subPortionReadableGeometry.positionsCompressed; - const positionsDecodeMatrix = subPortionReadableGeometry.positionsDecodeMatrix; - const worldPos = tempVec4a$b; - for (let i = 0, len = positions.length; i < len; i += 3) { - worldPos[0] = positions[i]; - worldPos[1] = positions[i + 1]; - worldPos[2] = positions[i + 2]; - worldPos[3] = 1.0; - math.decompressPosition(worldPos, positionsDecodeMatrix); - math.mulMat4v4(model.worldMatrix, worldPos, worldPos); - math.addVec3(origin, worldPos, worldPos); - callback(worldPos); - } - }); - } - }, - precisionRayPickSurface: (portionId, worldRayOrigin, worldRayDir, worldSurfacePos, worldNormal) => false, - - renderers: getRenderers(scene, "dtx", primitive, model.saoEnabled, false, false, true, - (programVariables, subGeometry) => makeDTXRenderingAttributes(programVariables, !subGeometry)), - drawCalls: (function() { - const drawer = function(drawCall) { - const setInputValue = (input, value) => (input.setInputValue && input.setInputValue(value)); - return (attributesHash, layerTypeInputs, viewState) => { - setInputValue(layerTypeInputs.worldMatrix, model.rotationMatrix); - setInputValue(layerTypeInputs.viewMatrix, viewState.viewMatrix); - setInputValue(layerTypeInputs.projMatrix, viewState.projMatrix); - const rtcOrigin = math.transformPoint3(model.matrix, origin, tempVec3$5); - setInputValue(layerTypeInputs.uCameraEyeRtc, math.subVec3(viewState.eye, rtcOrigin, tempVec3a$e)); - setInputValue(layerTypeInputs.perObjPosDecode, texturePerObjectPositionsDecodeMatrix); - setInputValue(layerTypeInputs.perVertIdCoords, texturePerVertexIdCoordinates); - setInputValue(layerTypeInputs.perObjColsFlags, texturePerObjectColorsAndFlags); - setInputValue(layerTypeInputs.perObjectMatrix, texturePerObjectInstanceMatrices); - drawCall(layerTypeInputs); - }; - }; - - const vertEdgesDrawer = function(glMode) { - return drawer((layerTypeInputs) => { - draw8.edges( layerTypeInputs, glMode); - draw16.edges(layerTypeInputs, glMode); - draw32.edges(layerTypeInputs, glMode); - }); - }; - - return { - drawVertices: vertEdgesDrawer(gl.POINTS), - drawEdges: vertEdgesDrawer(gl.LINES), - drawSurface: drawer((layerTypeInputs) => { - const glMode = gl.TRIANGLES; - draw8.indices( layerTypeInputs, glMode); - draw16.indices(layerTypeInputs, glMode); - draw32.indices(layerTypeInputs, glMode); - }) - }; - })(), - - destroy: () => { - if (! destroyed) { - scene.off(onSceneRendering); - destroyed = true; - } - } - }; - } -} - -const createBindableDataTexture = function(gl, entitiesCnt, entitySize, type, entitiesPerRow, populateTexArray, statsProp, exposeData) { - if ((entitySize > 4) && ((entitySize % 4) > 0)) { - throw "Unhandled data size " + entitySize; - } - const pixelsPerEntity = Math.ceil(entitySize / 4); - const pixelWidth = entitySize / pixelsPerEntity; - - const [ arrayType, internalFormat, format ] = (function() { - switch(type) { - case gl.UNSIGNED_BYTE: - return [ Uint8Array, ...((pixelWidth === 1) ? [ gl.R8UI, gl.RED_INTEGER ] : ((pixelWidth === 2) ? [ gl.RG8UI, gl.RG_INTEGER ] : ((pixelWidth === 3) ? [ gl.RGB8UI, gl.RGB_INTEGER ] : [ gl.RGBA8UI, gl.RGBA_INTEGER ]))) ]; - case gl.UNSIGNED_SHORT: - return [ Uint16Array, ...((pixelWidth === 1) ? [ gl.R16UI, gl.RED_INTEGER ] : ((pixelWidth === 2) ? [ gl.RG16UI, gl.RG_INTEGER ] : ((pixelWidth === 3) ? [ gl.RGB16UI, gl.RGB_INTEGER ] : [ gl.RGBA16UI, gl.RGBA_INTEGER ]))) ]; - case gl.UNSIGNED_INT: - return [ Uint32Array, ...((pixelWidth === 1) ? [ gl.R32UI, gl.RED_INTEGER ] : ((pixelWidth === 2) ? [ gl.RG32UI, gl.RG_INTEGER ] : ((pixelWidth === 3) ? [ gl.RGB32UI, gl.RGB_INTEGER ] : [ gl.RGBA32UI, gl.RGBA_INTEGER ]))) ]; - case gl.FLOAT: - return [ Float32Array, ...((pixelWidth === 1) ? [ gl.R32F, gl.RED ] : ((pixelWidth === 2) ? [ gl.RG32F, gl.RG ] : ((pixelWidth === 3) ? [ gl.RGB32F, gl.RGB ] : [ gl.RGBA32F, gl.RGBA ]))) ]; - default: - throw "Unhandled data type " + type; - } - })(); - - const textureWidth = entitiesPerRow * pixelsPerEntity; - const textureHeight = Math.ceil(entitiesCnt / entitiesPerRow); - if (textureHeight === 0) { - throw "texture height===0"; - } - let texArray = new arrayType(textureWidth * textureHeight * pixelWidth); - dataTextureRamStats[statsProp] += texArray.byteLength; - dataTextureRamStats.numberOfTextures++; - - populateTexArray(texArray); - - const texture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, texture); - gl.texStorage2D(gl.TEXTURE_2D, 1, internalFormat, textureWidth, textureHeight); - gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, textureWidth, textureHeight, format, type, texArray); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.bindTexture(gl.TEXTURE_2D, null); - - if (! exposeData) { - texArray = null; // See the comment related to XCD-408 and XCD-424 above. - } - - return { - // called by createSampler::bindTexture - bind(unit) { - gl.activeTexture(gl["TEXTURE" + unit]); - gl.bindTexture(gl.TEXTURE_2D, texture); - return true; - }, - - unbind(unit) { - // This `unbind` method is ignored at the moment to allow avoiding - // to rebind same texture already bound to a texture unit. - - // this._gl.activeTexture(gl["TEXTURE" + unit]); - // this._gl.bindTexture(gl.TEXTURE_2D, null); - }, - - textureData: exposeData && { - setData(data, subPortionId, offset = 0, load = false) { - texArray.set(data, subPortionId * entitySize + offset * pixelWidth); - if (load) { - gl.bindTexture(gl.TEXTURE_2D, texture); - const xoffset = (subPortionId % entitiesPerRow) * pixelsPerEntity + offset; - const yoffset = Math.floor(subPortionId / entitiesPerRow); - const width = data.length / pixelWidth; - gl.texSubImage2D(gl.TEXTURE_2D, 0, xoffset, yoffset, width, 1, format, type, data); - // gl.bindTexture (gl.TEXTURE_2D, null); - } - }, - - reloadData() { - gl.bindTexture(gl.TEXTURE_2D, texture); - gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, textureWidth, textureHeight, format, type, texArray); - } - } - }; -}; - -const makeDTXRenderingAttributes = function(programVariables, isTriangle) { - const setupTex = (type, name) => { - const map = programVariables.createUniform(type, name); - const texelFetch = (P) => `texelFetch(${map}, ${P}, 0)`; - texelFetch.map = map; - return texelFetch; - }; - - const perPrimIndices = setupTex("highp usampler2D", "perPrimIndices"); - const perPrimIdPorIds = setupTex("mediump usampler2D", "perPrimIdPorIds"); - - const perObjPosDecode = setupTex("highp sampler2D", "perObjPosDecode"); - const perVertIdCoords = setupTex("mediump usampler2D", "perVertIdCoords"); - const perObjColsFlags = setupTex("lowp usampler2D", "perObjColsFlags"); - const perObjectMatrix = setupTex("highp sampler2D", "perObjectMatrix"); - - const worldMatrix = programVariables.createUniform("mat4", "worldMatrix"); - const viewMatrix = programVariables.createUniform("mat4", "viewMatrix"); - const projMatrix = programVariables.createUniform("mat4", "projMatrix"); - const uCameraEyeRtc = programVariables.createUniform("vec3", "uCameraEyeRtc"); - - const lazyShaderVariable = function(name) { - const variable = { - toString: () => { - variable.needed = true; - return name; - } - }; - return variable; - }; - - const colorA = lazyShaderVariable("colorA"); - const pickColorA = lazyShaderVariable("pickColor"); - const worldNormal = lazyShaderVariable("worldNormal"); - const viewNormal = lazyShaderVariable("viewNormal"); - - const colorsAndFlags = (offset) => perObjColsFlags(`ivec2(objectIndexCoords.x*8+${offset}, objectIndexCoords.y)`); - - return { - clippableTest: (function() { - const vClippable = programVariables.createVarying("uint", "vClippable", () => "flags2.r", "flat"); - return () => `${vClippable} > 0u`; - })(), - - geometryParameters: { - attributes: { - color: colorA, - flags: iota$3(4).map(i => `int(flags[${i}])`), - metallicRoughness: null, - normal: { - view: viewNormal, - world: worldNormal - }, - pickColor: pickColorA, - position: { - clip: "gl_Position", - view: "viewPosition", - world: "worldPosition" - }, - uv: null - }, - projMatrix: projMatrix, - viewMatrix: viewMatrix - }, - - ensureColorAndFlagAvailable: (src) => { - // constants - src.push("int primitiveIndex = gl_VertexID / " + (isTriangle ? 3 : 2) + ";"); - - // get packed object-id - src.push("int h_packed_object_id_index = (primitiveIndex >> 3) & 4095;"); - src.push("int v_packed_object_id_index = (primitiveIndex >> 3) >> 12;"); - - src.push(`int objectIndex = int(${perPrimIdPorIds("ivec2(h_packed_object_id_index, v_packed_object_id_index)")}.r);`); - src.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"); - - // get flags & flags2 - src.push(`uvec4 flags = ${colorsAndFlags(2)};`); - src.push(`uvec4 flags2 = ${colorsAndFlags(3)};`); - - colorA.needed && src.push(`vec4 ${colorA} = vec4(${colorsAndFlags(0)}) / 255.0;`); - }, - - appendVertexData: (src) => { - const objMatrix = (offset) => perObjectMatrix(`ivec2(objectIndexCoords.x*4+${offset}, objectIndexCoords.y)`); - src.push(`mat4 objectInstanceMatrix = mat4(${objMatrix(0)}, ${objMatrix(1)}, ${objMatrix(2)}, ${objMatrix(3)});`); - - const posMatrix = (offset) => perObjPosDecode(`ivec2(objectIndexCoords.x*4+${offset}, objectIndexCoords.y)`); - src.push(`mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4(${posMatrix(0)}, ${posMatrix(1)}, ${posMatrix(2)}, ${posMatrix(3)});`); - - src.push(`ivec4 packedVertexBase = ivec4(${colorsAndFlags(4)});`); - src.push(`ivec4 packedIndexBaseOffset = ivec4(${colorsAndFlags(isTriangle ? 5 : 6)});`); - src.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"); - - src.push("int h_index = (primitiveIndex - indexBaseOffset) & 4095;"); - src.push("int v_index = (primitiveIndex - indexBaseOffset) >> 12;"); - - src.push(`ivec3 vertexIndices = ivec3(${perPrimIndices("ivec2(h_index, v_index)")});`); - src.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"); - - if (isTriangle) { - src.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"); - src.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"); - src.push(`uint solid = ${colorsAndFlags(7)}.r;`); - const vertIdCoords = (idx) => `vec3(${perVertIdCoords(`ivec2(indexPositionH[${idx}], indexPositionV[${idx}])`)})`; - src.push(`vec3 positions[] = vec3[](${vertIdCoords(0)}, ${vertIdCoords(1)}, ${vertIdCoords(2)});`); - src.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"); - src.push("vec3 position = positions[gl_VertexID % 3];"); - if (worldNormal.needed) { // WARNING: Not thoroughly tested, as not being used at the moment - src.push(`vec3 worldNormal = -normalize((transpose(inverse(${worldMatrix} * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);`); - } - if (viewNormal.needed) { - src.push(`vec3 viewNormal = -normalize((transpose(inverse(${viewMatrix} * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);`); - } - // when the geometry is not solid, if needed, flip the triangle winding - src.push("if (solid != 1u) {"); - src.push(` if (${isPerspectiveMatrix(projMatrix)}) {`); - src.push(` vec3 uCameraEyeRtcInQuantizedSpace = (inverse(${worldMatrix} * objectDecodeAndInstanceMatrix) * vec4(${uCameraEyeRtc}, 1)).xyz;`); - src.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"); - src.push(" position = positions[2 - (gl_VertexID % 3)];"); - if (worldNormal.needed) { - src.push(" worldNormal = -worldNormal;"); - } - if (viewNormal.needed) { - src.push(" viewNormal = -viewNormal;"); - } - src.push(" }"); - src.push(" } else {"); - if (!viewNormal.needed) { - src.push(` vec3 viewNormal = -normalize((transpose(inverse(${viewMatrix} * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);`); - } - src.push(" if (viewNormal.z < 0.0) {"); - src.push(" position = positions[2 - (gl_VertexID % 3)];"); - if (worldNormal.needed) { - src.push(" worldNormal = -worldNormal;"); - } - if (viewNormal.needed) { - src.push(" viewNormal = -viewNormal;"); - } - src.push(" }"); - src.push(" }"); - src.push("}"); - } else { - src.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"); - src.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"); - src.push(`vec3 position = vec3(${perVertIdCoords("ivec2(indexPositionH, indexPositionV)")});`); - } - - pickColorA.needed && src.push(`vec4 pickColor = vec4(${colorsAndFlags(1)});`); // TODO: Normalize color "/ 255.0"? - - src.push(`vec4 worldPosition = ${worldMatrix} * (objectDecodeAndInstanceMatrix * vec4(position, 1.0));`); - }, - - layerTypeInputs: { - perPrimIndices: perPrimIndices.map, - perPrimIdPorIds: perPrimIdPorIds.map, - - perObjPosDecode: perObjPosDecode.map, - perVertIdCoords: perVertIdCoords.map, - perObjColsFlags: perObjColsFlags.map, - perObjectMatrix: perObjectMatrix.map, - - worldMatrix: worldMatrix, - viewMatrix: viewMatrix, - projMatrix: projMatrix, - uCameraEyeRtc: uCameraEyeRtc - } - }; -}; - -const translate$1 = math.mat4(); -const scale$1 = math.mat4(); - -/** - * @private - */ -function quantizePositions(positions, aabb, positionsDecodeMatrix) { // http://cg.postech.ac.kr/research/mesh_comp_mobile/mesh_comp_mobile_conference.pdf - const lenPositions = positions.length; - const quantizedPositions = new Uint16Array(lenPositions); - const xmin = aabb[0]; - const ymin = aabb[1]; - const zmin = aabb[2]; - const xwid = (aabb[3] - xmin) || 1; - const ywid = (aabb[4] - ymin) || 1; - const zwid = (aabb[5] - zmin) || 1; - const maxInt = 65525; - const xMultiplier = maxInt / xwid; - const yMultiplier = maxInt / ywid; - const zMultiplier = maxInt / zwid; - const verify = (num) => num >= 0 ? num : 0; - for (let i = 0; i < lenPositions; i += 3) { - quantizedPositions[i + 0] = Math.floor(verify(positions[i + 0] - xmin) * xMultiplier); - quantizedPositions[i + 1] = Math.floor(verify(positions[i + 1] - ymin) * yMultiplier); - quantizedPositions[i + 2] = Math.floor(verify(positions[i + 2] - zmin) * zMultiplier); - } - math.identityMat4(translate$1); - math.translationMat4v(aabb, translate$1); - math.identityMat4(scale$1); - math.scalingMat4v([xwid / maxInt, ywid / maxInt, zwid / maxInt], scale$1); - math.mulMat4(translate$1, scale$1, positionsDecodeMatrix); - return quantizedPositions; -} - -/** - * @private - * @param aabb - * @param positionsDecodeMatrix - * @returns {*} - */ -function createPositionsDecodeMatrix(aabb, positionsDecodeMatrix) { // http://cg.postech.ac.kr/research/mesh_comp_mobile/mesh_comp_mobile_conference.pdf - const xmin = aabb[0]; - const ymin = aabb[1]; - const zmin = aabb[2]; - const xwid = (aabb[3] - xmin) || 1; - const ywid = (aabb[4] - ymin) || 1; - const zwid = (aabb[5] - zmin) || 1; - const maxInt = 65525; - math.identityMat4(translate$1); - math.translationMat4v(aabb, translate$1); - math.identityMat4(scale$1); - math.scalingMat4v([xwid / maxInt, ywid / maxInt, zwid / maxInt], scale$1); - math.mulMat4(translate$1, scale$1, positionsDecodeMatrix); - return positionsDecodeMatrix; -} - -/** - * @private - */ -function transformAndOctEncodeNormals(worldNormalMatrix, normals, lenNormals, compressedNormals, lenCompressedNormals) { - // http://jcgt.org/published/0003/02/01/ - - function dot(array, vec3) { - return array[0] * vec3[0] + array[1] * vec3[1] + array[2] * vec3[2]; - } - - let oct, dec, best, currentCos, bestCos; - let i; - let localNormal = new Float32Array([0, 0, 0, 0]); - let worldNormal = new Float32Array([0, 0, 0, 0]); - for (i = 0; i < lenNormals; i += 3) { - localNormal[0] = normals[i]; - localNormal[1] = normals[i + 1]; - localNormal[2] = normals[i + 2]; - - math.transformVec3(worldNormalMatrix, localNormal, worldNormal); - math.normalizeVec3(worldNormal, worldNormal); - - // Test various combinations of ceil and floor to minimize rounding errors - best = oct = octEncodeVec3(worldNormal, "floor", "floor"); - dec = octDecodeVec2(oct); - currentCos = bestCos = dot(worldNormal, dec); - oct = octEncodeVec3(worldNormal, "ceil", "floor"); - dec = octDecodeVec2(oct); - currentCos = dot(worldNormal, dec); - if (currentCos > bestCos) { - best = oct; - bestCos = currentCos; - } - oct = octEncodeVec3(worldNormal, "floor", "ceil"); - dec = octDecodeVec2(oct); - currentCos = dot(worldNormal, dec); - if (currentCos > bestCos) { - best = oct; - bestCos = currentCos; - } - oct = octEncodeVec3(worldNormal, "ceil", "ceil"); - dec = octDecodeVec2(oct); - currentCos = dot(worldNormal, dec); - if (currentCos > bestCos) { - best = oct; - bestCos = currentCos; - } - compressedNormals[lenCompressedNormals + i + 0] = best[0]; - compressedNormals[lenCompressedNormals + i + 1] = best[1]; - compressedNormals[lenCompressedNormals + i + 2] = 0.0; // Unused - } - lenCompressedNormals += lenNormals; - return lenCompressedNormals; -} - -/** - * @private - */ -function octEncodeVec3(p, xfunc, yfunc) { // Oct-encode single normal vector in 2 bytes - let x = p[0] / (Math.abs(p[0]) + Math.abs(p[1]) + Math.abs(p[2])); - let y = p[1] / (Math.abs(p[0]) + Math.abs(p[1]) + Math.abs(p[2])); - if (p[2] < 0) { - let tempx = x; - let tempy = y; - tempx = (1 - Math.abs(y)) * (x >= 0 ? 1 : -1); - tempy = (1 - Math.abs(x)) * (y >= 0 ? 1 : -1); - x = tempx; - y = tempy; - } - return new Int8Array([ - Math[xfunc](x * 127.5 + (x < 0 ? -1 : 0)), - Math[yfunc](y * 127.5 + (y < 0 ? -1 : 0)) - ]); -} - -/** - * @private - */ -function octDecodeVec2(oct) { // Decode an oct-encoded normal - let x = oct[0]; - let y = oct[1]; - x /= x < 0 ? 127 : 128; - y /= y < 0 ? 127 : 128; - const z = 1 - Math.abs(x) - Math.abs(y); - if (z < 0) { - x = (1 - Math.abs(y)) * (x >= 0 ? 1 : -1); - y = (1 - Math.abs(x)) * (y >= 0 ? 1 : -1); - } - const length = Math.sqrt(x * x + y * y + z * z); - return [ - x / length, - y / length, - z / length - ]; -} - -const tempFloat32 = new Float32Array(1); -const tempFloat32Vec4 = new Float32Array(4); -const tempVec3fa = new Float32Array(3); -const tempMat4$1 = math.mat4(); -const tempVec4a$a = math.vec4([0, 0, 0, 1]); -const tempVec4b$9 = math.vec4(); - -const tempVec3a$d = math.vec3(); -const tempVec3b$9 = math.vec3(); -const tempVec3c$7 = math.vec3(); -const tempVec3d$2 = math.vec3(); -const tempVec3e$1 = math.vec3(); -const tempVec3f$1 = math.vec3(); -const tempVec3g = math.vec3(); - -const tempUint8Array4 = new Uint8Array(4); -const matricesUniformBlockBufferData = new Float32Array(4 * 4 * 6); // there is 6 mat4 - -const iota$2 = function(n) { - const ret = [ ]; - for (let i = 0; i < n; ++i) ret.push(i); - return ret; -}; - -// fills the whole dst array with src copies -const fillArray = function(dst, src) { - dst.set(src); - let soFar = src.length; - const allDataLen = dst.length; - while (soFar < allDataLen) { - const toCopy = Math.min(soFar, allDataLen - soFar); - dst.set(dst.subarray(0, toCopy), soFar); - soFar += toCopy; - } -}; - -const scratchMemory = (function() { - /** - * Provides scratch memory for methods like TrianglesBatchingLayer setFlags() and setColors(), - * so they don't need to allocate temporary arrays that need garbage collection. - */ - let cnt = 0; - const arrays = new Map(); - return { - acquire: () => cnt++, - release: () => { - cnt--; - if (cnt === 0) { - arrays.clear(); - } - }, - getTypeArray: function(type, len) { - if (! arrays.has(type)) { - arrays.set(type, { }); - } - const typeArrays = arrays.get(type); - if (! (len in typeArrays)) { - typeArrays[len] = new type(len); - } - return typeArrays[len]; - } - }; -})(); - -/** - * @private - */ -class VBOLayer extends Layer { - - /** - * @param model - * @param primitive - * @param origin - * - * @param cfg - * @param cfg.textureSet - * - * batching: - * @param cfg.positionsDecodeMatrix - * @param cfg.uvDecodeMatrix - * @param cfg.maxGeometryBatchSize - * - * instancing: - * @param cfg.geometry - */ - constructor(model, primitive, origin, cfg) { - - super(model, primitive, origin); - - const instancing = !! cfg.geometry; - - this._maxVerts = cfg.maxGeometryBatchSize; - - const positionsDecodeMatrix = instancing ? cfg.geometry.positionsDecodeMatrix : cfg.positionsDecodeMatrix; - this._positionsDecodeMatrix = positionsDecodeMatrix && math.mat4(positionsDecodeMatrix); - - this._cfgUvDecodeMatrix = cfg.uvDecodeMatrix && math.mat3(cfg.uvDecodeMatrix); - this._instancedGeometry = cfg.geometry; - this._textureSet = cfg.textureSet; - - this._modelAABB = (! instancing) && math.collapseAABB3(); // Model-space AABB - this._portions = [ ]; - - const attribute = function() { - let length = 0; - const portions = [ ]; - - return { - length: () => length, - append: function(data, times = 1, denormalizeScale = 1.0, increment = 0.0) { - length += times * data.length; - portions.push({ data: data, times: times, denormalizeScale: denormalizeScale, increment: increment }); - }, - compileBuffer: function(type) { - let len = 0; - portions.forEach(p => { len += p.times * p.data.length; }); - const buf = new type(len); - - let begin = 0; - portions.forEach(p => { - const data = p.data; - const dScale = p.denormalizeScale; - const increment = p.increment; - const subBuf = buf.subarray(begin); - - if ((dScale === 1.0) && (increment === 0.0)) { - subBuf.set(data); - } else { - for (let i = 0; i < data.length; ++i) { - subBuf[i] = increment + data[i] * dScale; - } - } - - let soFar = data.length; - const allDataLen = p.times * data.length; - while (soFar < allDataLen) { - const toCopy = Math.min(soFar, allDataLen - soFar); - subBuf.set(subBuf.subarray(0, toCopy), soFar); - soFar += toCopy; - } - - begin += soFar; - }); - - return buf; - }, - _clearToOptimizeGC: () => { portions.length = 0; } - }; - }; - - this._buffer = { - colors: attribute(), // in instancing used only for non-points - metallicRoughness: attribute(), // used for triangulated - pickColors: attribute(), // used for non-lines - ...(instancing - ? { - // Modeling matrix per instance, array for each column - modelMatrixCol: [ attribute(), attribute(), attribute() ], - modelNormalMatrixCol: [ attribute(), attribute(), attribute() ] - } - : { - positions: attribute(), - indices: attribute(), // used for non-points - uv: attribute(), // used for triangulated - normals: attribute(), // used for triangulated - edgeIndices: attribute(), // used for triangulated - }) - }; - } - - /** - * Tests if there is room for another portion in this Layer. - * - * @param lenPositions Number of positions we'd like to create in the portion. - * @param lenIndices Number of indices we'd like to create in this portion. - * @returns {Boolean} True if OK to create another portion. - */ - canCreatePortion(lenPositions, lenIndices) { - return this._instancedGeometry || (((this._buffer.positions.length() + lenPositions) <= (this._maxVerts * 3)) && ((this._buffer.indices.length() + lenIndices) <= (this._maxVerts * 3))); - } - - /** - * Creates a new portion within this Layer, returns the new portion ID. - * - * @param mesh The SceneModelMesh that owns the portion - * @param cfg Portion params - * @param cfg.metallic Metalness factor [0..255] (triangulated) - * @param cfg.roughness Roughness factor [0..255] (triangulated) - * @param cfg.pickColor Quantized pick color (non-lines) - * @param cfg.meshMatrix Flat float 4x4 matrix (optional in batching) - * batching: - * @param cfg.positionsCompressed Flat quantized positions array - decompressed with positionsDecodeMatrix - * @param cfg.positions Flat float Local-space positions array. - * @param cfg.indices Flat int indices array. - * @param [cfg.normalsCompressed] - * @param [cfg.normals] Flat float normals array (triangulated) - * @param [cfg.colors] Flat float colors array (non-lines) - * @param [cfg.colorsCompressed] Quantized RGB colors [0..255,0..255,0..255,0..255] (non-lines) - * @param cfg.color Float RGB color [0..1,0..1,0..1] (points) or Quantized RGB color [0..255,0..255,0..255,0..255] (non-points) - * @param cfg.opacity Opacity [0..255] (non-points) - * @param [cfg.uv] Flat UVs array (triangulated) - * @param [cfg.uvCompressed] (triangulated) - * @param [cfg.edgeIndices] Flat int edges indices array (triangulated) - * @param cfg.aabb Flat float AABB World-space AABB - * instancing: - * @param cfg.color Color [0..255,0..255,0..255] - * @param cfg.opacity Opacity [0..255]. - * @returns {number} Portion ID - */ - createPortion(mesh, cfg) { - const buffer = this._buffer; - const instancedGeometry = this._instancedGeometry; - const model = this.model; - const portionId = this._portions.length; - const primitive = this.primitive; - const useCompressed = !! this._positionsDecodeMatrix; - const scene = model.scene; - const meshMatrix = cfg.meshMatrix; - - const appendPortion = (portionBase, portionSize, indices, quantizedPositions, meshMatrix) => { - const prevPortion = (this._portions.length > 0) && this._portions[this._portions.length - 1]; - const portion = { - indicesBaseIndex: prevPortion ? (prevPortion.indicesBaseIndex + prevPortion.numIndices) : 0, - numIndices: indices ? indices.length : 0, - portionBase: portionBase, - portionSize: portionSize, - retainedGeometry: scene.readableGeometryEnabled && (primitive !== "points") && (primitive !== "lines") && { - indices: indices, - quantizedPositions: quantizedPositions, - offset: scene.entityOffsetsEnabled && math.vec3(), - matrix: meshMatrix && meshMatrix.slice(), - inverseMatrix: null, // Lazy-computed for instancing in precisionRayPickSurface - normalMatrix: null, // Lazy-computed for instancing in precisionRayPickSurface - } - }; - - if ((primitive !== "points") && (primitive !== "lines")) { - buffer.metallicRoughness.append([ cfg.metallic ?? 0, cfg.roughness ?? 255 ], portionSize); - } - - if (primitive !== "lines") { - buffer.pickColors.append(cfg.pickColor.slice(0, 4), portionSize); - } - - this._portions.push(portion); - model.numPortions++; - this._meshes.push(mesh); - return portionId; - }; - - if (instancedGeometry) { - buffer.modelMatrixCol.forEach((b, i) => b.append([ meshMatrix[i+0], meshMatrix[i+4], meshMatrix[i+8], meshMatrix[i+12] ])); - - if (primitive !== "points") { - const color = cfg.color; // Color is pre-quantized by SceneModel - buffer.colors.append([ color[0], color[1], color[2], cfg.opacity ?? 255 ]); - } - - if ((primitive !== "points") && (primitive !== "lines")) { - if (instancedGeometry.normals) { - // Note: order of inverse and transpose doesn't matter - const normalMatrix = math.inverseMat4(math.transposeMat4(meshMatrix, math.mat4())); - buffer.modelNormalMatrixCol.forEach((b, i) => b.append([ normalMatrix[i+0], normalMatrix[i+4], normalMatrix[i+8], normalMatrix[i+12] ])); - } - } - - return appendPortion(portionId, 1, instancedGeometry.indices, instancedGeometry.positionsCompressed, meshMatrix); - } else { - const vertsBaseIndex = buffer.positions.length() / 3; - - const positions = useCompressed ? cfg.positionsCompressed : cfg.positions; - if (! positions) { - throw ((useCompressed ? "positionsCompressed" : "positions") + " expected"); - } - - buffer.positions.append(positions); - - const numVerts = positions.length / 3; - - const indices = cfg.indices; - if (indices) { - buffer.indices.append(indices, 1, 1.0, vertsBaseIndex); - } - - const normalsCompressed = cfg.normalsCompressed; - const normals = cfg.normals; - if (normalsCompressed && normalsCompressed.length > 0) { - buffer.normals.append(normalsCompressed); - } else if (normals && normals.length > 0) { - const worldNormalMatrix = tempMat4$1; - if (meshMatrix) { - math.transposeMat4(meshMatrix, worldNormalMatrix); - math.inverseMat4(worldNormalMatrix, worldNormalMatrix); // Note: order of inverse and transpose doesn't matter - } else { - math.identityMat4(worldNormalMatrix); - } - const normalsData = [ ]; - transformAndOctEncodeNormals(worldNormalMatrix, normals, normals.length, normalsData, 0); - buffer.normals.append(normalsData); - } - - const colors = cfg.colors; - const colorsCompressed = cfg.colorsCompressed; - const color = cfg.color; - if (colors) { - if (primitive === "points") { - buffer.colors.append(colors, 1, 255.0); - } else { // triangulated - const colorsData = [ ]; - for (let i = 0, len = colors.length; i < len; i += 3) { - colorsData.push(colors[i] * 255); - colorsData.push(colors[i + 1] * 255); - colorsData.push(colors[i + 2] * 255); - colorsData.push(255); - } - buffer.colors.append(colorsData); - } - } else if (colorsCompressed) { - if (primitive === "points") { - buffer.colors.append(colorsCompressed); - } else { // triangulated - const colorsData = [ ]; - for (let i = 0, len = colorsCompressed.length; i < len; i += 3) { - colorsData.push(colorsCompressed[i]); - colorsData.push(colorsCompressed[i + 1]); - colorsData.push(colorsCompressed[i + 2]); - colorsData.push(255); - } - buffer.colors.append(colorsData); - } - } else if (color) { - // Color is pre-quantized by VBOSceneModel - buffer.colors.append([ color[0], color[1], color[2], (primitive === "points") ? 1.0 : cfg.opacity ], numVerts); - } - - const nonEmpty = v => v && (v.length > 0) && v; - const uv = nonEmpty(cfg.uv) || nonEmpty(cfg.uvCompressed); - if (uv) { - buffer.uv.append(uv); - } - - const edgeIndices = cfg.edgeIndices; - if (edgeIndices) { - buffer.edgeIndices.append(edgeIndices, 1, 1.0, vertsBaseIndex); - } - - math.expandAABB3(this._modelAABB, cfg.aabb); - - // quantizedPositions are initialized in finalize() - return appendPortion(vertsBaseIndex, numVerts, indices); - } - } - - compilePortions() { - const buffer = this._buffer; - const instancedGeometry = this._instancedGeometry; - const model = this.model; - const modelAABB = this._modelAABB; - const origin = this.origin; - const portions = this._portions; - const primitive = this.primitive; - const textureSet = this._textureSet; - let positionsDecodeMatrix = this._positionsDecodeMatrix; - const cfgUvDecodeMatrix = this._cfgUvDecodeMatrix; - - const scene = model.scene; - const gl = scene.canvas.gl; - const instancing = !! instancedGeometry; - - const cleanups = [ ]; - - const createGlBuffer = (target, srcData, size, usage) => { - if (srcData.length > 0) { - const srcDataConstructor = srcData.constructor; - const [byteSize, type] = ({ - [Uint8Array]: [1, gl.UNSIGNED_BYTE], - [Int8Array]: [1, gl.BYTE], - [Uint16Array]: [2, gl.UNSIGNED_SHORT], - [Int16Array]: [2, gl.SHORT], - [Uint32Array]: [4, gl.UNSIGNED_INT], - [Int32Array]: [4, gl.INT], - [Float32Array]: [4, gl.FLOAT] - })[srcDataConstructor]; - - const buffer = gl.createBuffer(); - cleanups.push(() => gl.deleteBuffer(buffer)); - - const bindBuffer = () => gl.bindBuffer(target, buffer); - const setData = data => { - bindBuffer(); - gl.bufferData(target, data, usage); - }; - setData(srcData); - - const bytesPerElement = srcData.BYTES_PER_ELEMENT; - const numItems = srcData.length / size; - return { - bindBuffer: bindBuffer, - getData: (baseIndex = 0, length = numItems - baseIndex) => { - bindBuffer(); - const array = new srcDataConstructor(length * size); - gl.getBufferSubData(target, baseIndex * byteSize * size, array, 0, length * size); - return array; - }, - numItems: numItems, - setData: setData, - setSubData: (data, offset) => { - bindBuffer(); - gl.bufferSubData(target, offset * bytesPerElement, data); - }, - type: type - }; - } else { - return null; - } - }; - - const maybeCreateBuffer = (srcData, size, usage, setDivisor = false, normalized = false) => { - const buf = createGlBuffer(gl.ARRAY_BUFFER, srcData, size, usage); - return buf && { - getData: buf.getData, - numItems: buf.numItems, - setData: buf.setData, - setSubData: buf.setSubData, - attributeDivisor: setDivisor && 1, - bindAtLocation: location => { - buf.bindBuffer(); - gl.vertexAttribPointer(location, size, buf.type, !!normalized, 0, 0); - } - }; - }; - - const maybeCreateIndicesBuffer = srcData => { - const buf = createGlBuffer(gl.ELEMENT_ARRAY_BUFFER, srcData, 1, gl.STATIC_DRAW); - return buf && { - getData: buf.getData, - bindIndicesBuffer: buf.bindBuffer, - indicesCount: srcData.length, - indicesType: buf.type - }; - }; - - const attributesCnt = portions.reduce((acc,p) => acc + p.portionSize, 0); - - const flagsBuf = maybeCreateBuffer(new Float32Array(attributesCnt), 1, gl.DYNAMIC_DRAW, instancing); - - const createColorsBuf = (srcData, usage) => maybeCreateBuffer(srcData, 4, usage, instancing && (primitive !== "points"), true); - const colorsBuf = ((instancing && instancedGeometry.colorsCompressed) - ? createColorsBuf(new Uint8Array(instancedGeometry.colorsCompressed), gl.STATIC_DRAW) - : createColorsBuf(buffer.colors.compileBuffer(Uint8Array), gl.DYNAMIC_DRAW)); - - const offsetsBuf = scene.entityOffsetsEnabled && maybeCreateBuffer(new Float32Array(attributesCnt * 3), 3, gl.DYNAMIC_DRAW, instancing); - - const metallicRoughnessBuf = maybeCreateBuffer(buffer.metallicRoughness.compileBuffer(Uint8Array), 2, gl.STATIC_DRAW, instancing); - - const pickColorsBuf = maybeCreateBuffer(buffer.pickColors.compileBuffer(Uint8Array), 4, gl.STATIC_DRAW, instancing); - - const edgeIndicesBuf = maybeCreateIndicesBuffer(instancing - ? new Uint32Array(instancedGeometry.edgeIndices) - : buffer.edgeIndices.compileBuffer(Uint32Array)); - - const indices = (instancing - ? ((primitive !== "points") && instancedGeometry.indices && new Uint32Array(instancedGeometry.indices)) - : buffer.indices.compileBuffer(Uint32Array)); - const indicesBuf = indices && maybeCreateIndicesBuffer(indices); - - const positions = (instancing - ? instancedGeometry.positionsCompressed - : (positionsDecodeMatrix - ? buffer.positions.compileBuffer(Uint16Array) - : (quantizePositions(buffer.positions.compileBuffer(Float64Array), modelAABB, positionsDecodeMatrix = math.mat4())))); - const positionsBuf = positions && maybeCreateBuffer(positions, 3, gl.STATIC_DRAW); - if (! instancing) { - for (let i = 0; i < portions.length; ++i) { // WARNING: Replacing this for-loop by forEach increases memory consumption - const portion = portions[i]; // by not GCing `positions` arr, even if portion.retainedGeometry is false. - if (portion.retainedGeometry) { // See the comment related to XCD-408 and XCD-424 below. - const start = 3 * portion.portionBase; - portion.retainedGeometry.quantizedPositions = positions.subarray(start, start + 3 * portion.portionSize); - } - } - } - - const modelMatrixColBufs = instancing && buffer.modelMatrixCol.map(b => maybeCreateBuffer(b.compileBuffer(Float32Array), 4, gl.STATIC_DRAW, true)); - - const normals = (instancing - ? false // (primitive !== "points") && (primitive !== "lines") && instancedGeometry.normalsCompressed - : buffer.normals.compileBuffer(Int8Array)); - // Normals are already oct-encoded, so `normalized = true` for oct encoded UInts - const normalsBuf = normals && maybeCreateBuffer(normals, 3, gl.STATIC_DRAW, false, true); - - // WARNING: modelMatrixColBufs and normalsBuf are never simultaneously defined at the moment (when instancing=true) - const modelNormalMatrixColBufs = modelMatrixColBufs && normalsBuf && buffer.modelNormalMatrixCol.map(b => maybeCreateBuffer(b.compileBuffer(Float32Array), 4, gl.STATIC_DRAW, true)); - - const uvSetup = (instancing - ? ((primitive !== "points") && (primitive !== "lines") && instancedGeometry.uvCompressed && { - buf: maybeCreateBuffer(instancedGeometry.uvCompressed, 2, gl.STATIC_DRAW), - mat: instancedGeometry.uvDecodeMatrix - }) - : (function() { - const uvs = buffer.uv.compileBuffer(Float32Array); - if (uvs.length === 0) { - return null; - } else if (cfgUvDecodeMatrix) { - return { - buf: maybeCreateBuffer(uvs, 2, gl.STATIC_DRAW), - mat: cfgUvDecodeMatrix - }; - } else { - const bounds = geometryCompressionUtils.getUVBounds(uvs); - const result = geometryCompressionUtils.compressUVs(uvs, bounds.min, bounds.max); - return { - buf: maybeCreateBuffer(result.quantized, 2, gl.STATIC_DRAW), - mat: math.mat3(result.decodeMatrix) - }; - } - })()); - - // Free up memory - // Optimization to free up memory (XCD-408 and XCD-424) - // The following line was added to assist GC in cleaning up some of the data. See also the `portions` loop above. - // A Chrome test with Lyon[1-9].xkt models loaded simultaneously showed a decrease of 538MB to 143MB. - Object.values(this._buffer).forEach(a => a._clearToOptimizeGC ? a._clearToOptimizeGC() : a.forEach(a => a._clearToOptimizeGC())); - this._buffer = null; - - scratchMemory.acquire(); - cleanups.push(() => scratchMemory.release()); - - let deferredFlagValues = null; - - /** - * flags are 4bits values encoded on a 32bit base. color flag on the first 4 bits, silhouette flag on the next 4 bits and so on for edge, pick and clippable. - */ - const setFlags = (portionId, flags, transparent, deferred = false) => { - getColSilhEdgePickFlags(flags, transparent, (primitive !== "points") && (primitive !== "lines"), scene, tempUint8Array4); - - const clippableFlag = !!(flags & ENTITY_FLAGS.CLIPPABLE) ? 1 : 0; - - let vertFlag = 0; - vertFlag |= tempUint8Array4[0]; - vertFlag |= tempUint8Array4[1] << 4; - vertFlag |= tempUint8Array4[2] << 8; - vertFlag |= tempUint8Array4[3] << 12; - vertFlag |= clippableFlag << 16; - - tempFloat32[0] = vertFlag; - - const portion = portions[portionId]; - const firstFlag = portion.portionBase; - const lenFlags = portion.portionSize; - - if (deferred && (! instancedGeometry)) { - // Avoid zillions of individual WebGL bufferSubData calls - buffer them to apply in one shot - if (!deferredFlagValues) { - deferredFlagValues = new Float32Array(attributesCnt); - } - fillArray(deferredFlagValues.subarray(firstFlag, firstFlag + lenFlags), tempFloat32); - } else if (flagsBuf) { - const tempArray = scratchMemory.getTypeArray(Float32Array, lenFlags); - fillArray(tempArray, tempFloat32); - flagsBuf.setSubData(tempArray, firstFlag); - } - }; - - const solid = (primitive === "solid"); - return { - solid: solid, - sortId: (((primitive === "points") ? "Points" : ((primitive === "lines") ? "Lines" : "Triangles")) - + (instancing ? "Instancing" : "Batching") + "Layer" + - (((primitive !== "points") && (primitive !== "lines")) - ? ((solid ? "-solid" : "-surface") - + "-autoNormals" - + (instancing - ? "" - // TODO: These two parts need to be IDs (ie. unique): - : ((textureSet && textureSet.colorTexture ? "-colorTexture" : "") - + - (textureSet && textureSet.metallicRoughnessTexture ? "-metallicRoughnessTexture" : "")))) - : "")), - setClippableFlags: setFlags, - setFlags: setFlags, - setFlags2: (portionId, flags, deferred) => { }, - setDeferredFlags: () => { - if (deferredFlagValues) { - flagsBuf.setData(deferredFlagValues); - deferredFlagValues = null; - } - }, - - setColor: (portionId, color) => { // RGBA color is normalized as ints - if (colorsBuf) { - const portion = portions[portionId]; - const tempArray = scratchMemory.getTypeArray(Uint8Array, portion.portionSize * 4); - // alpha used to be unset for points, so effectively random (from last use) - fillArray(tempArray, color.slice(0, 4)); - colorsBuf.setSubData(tempArray, portion.portionBase * 4); - } - }, - setMatrix: (portionId, matrix) => { - if (modelMatrixColBufs) { - modelMatrixColBufs.forEach((b, i) => { - tempFloat32Vec4[0] = matrix[i+0]; - tempFloat32Vec4[1] = matrix[i+4]; - tempFloat32Vec4[2] = matrix[i+8]; - tempFloat32Vec4[3] = matrix[i+12]; - b.setSubData(tempFloat32Vec4, portionId * 4); - }); - } - }, - setOffset: (portionId, offset) => { - if (!scene.entityOffsetsEnabled) { - model.error("Entity#offset not enabled for this Viewer"); // See Viewer entityOffsetsEnabled - } else { - const portion = portions[portionId]; - if (offsetsBuf) { - tempVec3fa.set(offset); - const tempArray = scratchMemory.getTypeArray(Float32Array, portion.portionSize * 3); - fillArray(tempArray, tempVec3fa); - offsetsBuf.setSubData(tempArray, portion.portionBase * 3); - } - if (portion.retainedGeometry) { - portion.retainedGeometry.offset.set(offset); - } - } - }, - - getEachIndex: (portionId, callback) => { - const retainedGeometry = portions[portionId].retainedGeometry; - if (retainedGeometry) { - retainedGeometry.indices.forEach(i => callback(i)); - } - }, - getEachVertex: (portionId, callback) => { - const retainedGeometry = portions[portionId].retainedGeometry; - if (retainedGeometry) { - const origVec = tempVec4b$9; - if (origin) { - origVec.set(origin, 0); - } else { - origVec[0] = origVec[1] = origVec[2] = 0; - } - origVec[3] = 1; - const sceneModelMatrix = model.matrix; - const positions = retainedGeometry.quantizedPositions; - const worldPos = tempVec4a$a; - for (let i = 0, len = positions.length; i < len; i += 3) { - worldPos[0] = positions[i]; - worldPos[1] = positions[i + 1]; - worldPos[2] = positions[i + 2]; - math.decompressPosition(worldPos, positionsDecodeMatrix); - if (retainedGeometry.matrix) { - math.transformPoint3(retainedGeometry.matrix, worldPos, worldPos); - } - worldPos[3] = 1; - math.addVec3(origVec, worldPos, worldPos); - math.mulMat4v4(sceneModelMatrix, worldPos, worldPos); - callback(worldPos); - } - } - }, - readGeometryData: (primitive !== "points") && (primitive !== "lines") && ((portionId) => { - const portion = (! instancing) && portions[portionId]; - const indices = (portion - ? indicesBuf.getData(portion.indicesBaseIndex, portion.numIndices).map(i => i - portion.portionBase) - : indicesBuf.getData()); - - const sceneModelMatrix = model.matrix; - - const origin4 = math.vec4(); - origin4.set(origin, 0); origin4[3] = 1; - math.mulMat4v4(sceneModelMatrix, origin4, origin4); - - const instanceMatrix = modelMatrixColBufs && math.mat4(); - if (instanceMatrix) { - const col0 = modelMatrixColBufs[0].getData(portionId, 1); - const col1 = modelMatrixColBufs[1].getData(portionId, 1); - const col2 = modelMatrixColBufs[2].getData(portionId, 1); - instanceMatrix.set([ - col0[0], col1[0], col2[0], 0, - col0[1], col1[1], col2[1], 0, - col0[2], col1[2], col2[2], 0, - col0[3], col1[3], col2[3], 1, - ]); - } - - const matrix = math.mat4(); - math.mulMat4(sceneModelMatrix, instanceMatrix ? math.mulMat4(instanceMatrix, positionsDecodeMatrix, matrix) : positionsDecodeMatrix, matrix); - - matrix[12] += origin4[0]; - matrix[13] += origin4[1]; - matrix[14] += origin4[2]; - - const positionsQuantized = portion ? positionsBuf.getData(portion.portionBase, portion.portionSize) : positionsBuf.getData(); - - const positions = math.transformPositions3( - matrix, - positionsQuantized, - new Float64Array(positionsQuantized.length)); - - return { indices, positions }; - }), - precisionRayPickSurface: (portionId, worldRayOrigin, worldRayDir, worldSurfacePos, worldNormal) => { - const retainedGeometry = portions[portionId].retainedGeometry; - if (! retainedGeometry) { - return false; - } else { - if (retainedGeometry.matrix && (! retainedGeometry.inverseMatrix)) { - retainedGeometry.inverseMatrix = math.inverseMat4(retainedGeometry.matrix, math.mat4()); - } - - if (worldNormal && retainedGeometry.inverseMatrix && (! retainedGeometry.normalMatrix)) { - retainedGeometry.normalMatrix = math.transposeMat4(retainedGeometry.inverseMatrix, math.mat4()); - } - - const positions = retainedGeometry.quantizedPositions; - const indices = retainedGeometry.indices; - const offset = retainedGeometry.offset; - - const rtcRayOrigin = tempVec3a$d; - const rtcRayDir = tempVec3b$9; - - rtcRayOrigin.set(origin ? math.subVec3(worldRayOrigin, origin, tempVec3c$7) : worldRayOrigin); // World -> RTC - rtcRayDir.set(worldRayDir); - - if (offset) { - math.subVec3(rtcRayOrigin, offset); - } - - math.transformRay(model.worldNormalMatrix, rtcRayOrigin, rtcRayDir, rtcRayOrigin, rtcRayDir); // RTC -> local - - if (retainedGeometry.inverseMatrix) { - math.transformRay(retainedGeometry.inverseMatrix, rtcRayOrigin, rtcRayDir, rtcRayOrigin, rtcRayDir); - } - - const a = tempVec3d$2; - const b = tempVec3e$1; - const c = tempVec3f$1; - - let gotIntersect = false; - let closestDist = 0; - const closestIntersectPos = tempVec3g; - - for (let i = 0, len = indices.length; i < len; i += 3) { - - const ia = indices[i] * 3; - const ib = indices[i + 1] * 3; - const ic = indices[i + 2] * 3; - - a[0] = positions[ia]; - a[1] = positions[ia + 1]; - a[2] = positions[ia + 2]; - - b[0] = positions[ib]; - b[1] = positions[ib + 1]; - b[2] = positions[ib + 2]; - - c[0] = positions[ic]; - c[1] = positions[ic + 1]; - c[2] = positions[ic + 2]; - - math.decompressPosition(a, positionsDecodeMatrix); - math.decompressPosition(b, positionsDecodeMatrix); - math.decompressPosition(c, positionsDecodeMatrix); - - if (math.rayTriangleIntersect(rtcRayOrigin, rtcRayDir, a, b, c, closestIntersectPos)) { - - if (retainedGeometry.matrix) { - math.transformPoint3(retainedGeometry.matrix, closestIntersectPos, closestIntersectPos); - } - - math.transformPoint3(model.worldMatrix, closestIntersectPos, closestIntersectPos); - - if (offset) { - math.addVec3(closestIntersectPos, offset); - } - - if (origin) { - math.addVec3(closestIntersectPos, origin); - } - - const dist = Math.abs(math.lenVec3(math.subVec3(closestIntersectPos, worldRayOrigin, []))); - - if (!gotIntersect || dist > closestDist) { - closestDist = dist; - worldSurfacePos.set(closestIntersectPos); - if (worldNormal) { // Not that wasteful to eagerly compute - unlikely to hit >2 surfaces on most geometry - math.triangleNormal(a, b, c, worldNormal); - } - gotIntersect = true; - } - } - } - - if (gotIntersect && worldNormal) { - if (retainedGeometry.normalMatrix) { - math.transformVec3(retainedGeometry.normalMatrix, worldNormal, worldNormal); - } - math.transformVec3(model.worldNormalMatrix, worldNormal, worldNormal); - math.normalizeVec3(worldNormal); - } - - return gotIntersect; - } - }, - - layerTextureSet: textureSet, - - renderers: getRenderers(scene, instancing ? "instancing" : "batching", primitive, - model.saoEnabled, - model.pbrEnabled && uvSetup && textureSet && textureSet.colorTexture && normalsBuf && metallicRoughnessBuf && textureSet.metallicRoughnessTexture, - model.colorTextureEnabled && uvSetup && textureSet && textureSet.colorTexture, - !!normalsBuf, - (programVariables) => makeVBORenderingAttributes(programVariables, instancing && { hasModelNormalMat: !!modelNormalMatrixColBufs }, scene.entityOffsetsEnabled)), - drawCalls: (function() { - const drawCallCache = { }; - const makeDrawer = (subGeometry) => (attributesHash, layerTypeInputs, viewState) => { - let offset = 0; - const mat4Size = 4 * 4; - matricesUniformBlockBufferData.set(model.rotationMatrix, 0); - matricesUniformBlockBufferData.set(viewState.viewMatrix, offset += mat4Size); - matricesUniformBlockBufferData.set(viewState.projMatrix, offset += mat4Size); - matricesUniformBlockBufferData.set(positionsDecodeMatrix, offset += mat4Size); - if (layerTypeInputs.needNormal()) { - matricesUniformBlockBufferData.set(model.worldNormalMatrix, offset += mat4Size); - matricesUniformBlockBufferData.set(viewState.viewNormalMatrix, offset += mat4Size); - } - layerTypeInputs.matrices.setInputValue(matricesUniformBlockBufferData); - - layerTypeInputs.uvDecodeMatrix.setInputValue && layerTypeInputs.uvDecodeMatrix.setInputValue(uvSetup.mat); - - if (! (attributesHash in drawCallCache)) { - drawCallCache[attributesHash] = [ null, null, null ]; - } - const inputsCache = drawCallCache[attributesHash]; - const cacheKey = subGeometry ? (subGeometry.vertices ? 0 : 1) : 2; - if (! inputsCache[cacheKey]) { - const vao = gl.createVertexArray(); - gl.bindVertexArray(vao); - - const setAttr = (a, b) => { if (a && a.setInputValue && b) { a.setInputValue(b); } }; - const attrs = layerTypeInputs.attributes; - setAttr(attrs.position, positionsBuf); - setAttr(attrs.normal, normalsBuf); - setAttr(attrs.color, colorsBuf); - setAttr(attrs.pickColor, pickColorsBuf); - setAttr(attrs.uV, uvSetup && uvSetup.buf); - setAttr(attrs.metallicRoughness, metallicRoughnessBuf); - setAttr(attrs.flags, flagsBuf); - setAttr(attrs.offset, offsetsBuf); - attrs.modelMatrixCol && attrs.modelMatrixCol.forEach((a, i) => setAttr(a, modelMatrixColBufs[i])); - attrs.modelNormalMatrixCol && attrs.modelNormalMatrixCol.forEach((a, i) => setAttr(a, modelNormalMatrixColBufs[i])); - - const drawer = (function() { - // TODO: Use drawElements count and offset to draw only one entity - - const drawPoints = () => { - if (instancing) { - gl.drawArraysInstanced(gl.POINTS, 0, positionsBuf.numItems, portions.length); - } else { - gl.drawArrays(gl.POINTS, 0, positionsBuf.numItems); - } - }; - - const elementsDrawer = (mode, indicesBuf) => { - indicesBuf.bindIndicesBuffer(); - const count = indicesBuf.indicesCount; - const type = indicesBuf.indicesType; - return () => { - if (instancing) { - gl.drawElementsInstanced(mode, count, type, 0, portions.length); - } else { - gl.drawElements(mode, count, type, 0); - } - }; - }; - - if (primitive === "points") { - return drawPoints; - } else if (primitive === "lines") { - if (subGeometry && subGeometry.vertices) { - return drawPoints; - } else { - return elementsDrawer(gl.LINES, indicesBuf); - } - } else { // triangles - if (subGeometry && subGeometry.vertices) { - return drawPoints; - } else if (subGeometry) { - return edgeIndicesBuf ? elementsDrawer(gl.LINES, edgeIndicesBuf) : (() => { }); - } else { - return elementsDrawer(gl.TRIANGLES, indicesBuf); - } - } - })(); - - gl.bindVertexArray(null); - - cleanups.push(() => gl.deleteVertexArray(vao)); - - inputsCache[cacheKey] = () => { - gl.bindVertexArray(vao); - drawer(); - gl.bindVertexArray(null); - }; - } - - inputsCache[cacheKey](); - }; - - return { - drawVertices: makeDrawer({ vertices: true }), - drawEdges: makeDrawer({ }), - drawSurface: makeDrawer(null) - }; - })(), - - destroy: () => { - cleanups.forEach(c => c()); - cleanups.length = 0; - } - }; - } -} - -const lazyShaderVariable = function(name) { - const variable = { - toString: () => { - variable.needed = true; - return name; - } - }; - return variable; -}; - -const makeVBORenderingAttributes = function(programVariables, instancing, entityOffsetsEnabled) { - const createAttribute = programVariables.createAttribute; - - const attributes = { - position: createAttribute("vec3", "positionA"), - normal: createAttribute("vec3", "normalA"), - color: createAttribute("vec4", "colorA"), - pickColor: createAttribute("vec4", "pickColor"), - uV: createAttribute("vec2", "uvApremul"), - metallicRoughness: createAttribute("vec2", "metallicRoughness"), - flags: createAttribute("float", "flagsA"), - offset: entityOffsetsEnabled && createAttribute("vec3", "offset"), - modelMatrixCol: instancing && iota$2(3).map(i => createAttribute("vec4", "modelMatrixCol" + i)), - modelNormalMatrixCol: instancing && instancing.hasModelNormalMat && iota$2(3).map(i => createAttribute("vec4", "modelNormalMatrixCol" + i)) - }; - - const uvA = lazyShaderVariable("aUv"); - const viewNormal = lazyShaderVariable("viewNormal"); - const worldNormal = lazyShaderVariable("worldNormal"); - const uvDecodeMatrix = programVariables.createUniform("mat3", "uvDecodeMatrix"); - - const needNormal = () => (viewNormal.needed || worldNormal.needed); - const matrices = programVariables.createUniformBlock( - "Matrices", - { - worldMatrix: "mat4", - viewMatrix: "mat4", - projMatrix: "mat4", - positionsDecodeMatrix: "mat4", - worldNormalMatrix: "mat4", - viewNormalMatrix: "mat4" - }); - - return { - dontCullOnAlphaZero: true, - - clippableTest: (function() { - const vClippable = programVariables.createVarying("float", "vClippable", () => `${`((int(${attributes.flags}) >> 16 & 0xF) == 1)`} ? 1.0 : 0.0`); // Using `flat uint` for vClippable causes an instability - see XEOK-385 - return () => `${vClippable} != 0.0`; - })(), - - geometryParameters: { - attributes: { - color: attributes.color, - flags: iota$2(4).map(i => ({ toString: () => `(int(${attributes.flags}) >> ${i * 4} & 0xF)` })), - metallicRoughness: attributes.metallicRoughness, - normal: { - view: viewNormal, - world: worldNormal - }, - pickColor: attributes.pickColor, - position: { - clip: "gl_Position", - view: "viewPosition", - world: "worldPosition" - }, - uv: uvA - }, - projMatrix: matrices.projMatrix, - viewMatrix: matrices.viewMatrix - }, - - appendVertexData: (src) => { - uvA.needed && src.push(`vec2 ${uvA} = (${uvDecodeMatrix} * vec3(${attributes.uV}, 1.0)).xy;`); - - const modelMatrixTransposed = attributes.modelMatrixCol && `mat4(${attributes.modelMatrixCol[0]}, ${attributes.modelMatrixCol[1]}, ${attributes.modelMatrixCol[2]}, vec4(0.0,0.0,0.0,1.0))`; - src.push(`vec4 worldPosition = ${matrices.worldMatrix} * (${matrices.positionsDecodeMatrix} * vec4(${attributes.position}, 1.0)${modelMatrixTransposed ? (" * " + modelMatrixTransposed) : ""});`); - attributes.offset && src.push(`worldPosition.xyz = worldPosition.xyz + ${attributes.offset};`); - - if (needNormal()) { - const timesModelNormalMatrixT = attributes.modelNormalMatrixCol && `* mat4(${attributes.modelNormalMatrixCol[0]}, ${attributes.modelNormalMatrixCol[1]}, ${attributes.modelNormalMatrixCol[2]}, vec4(0.0,0.0,0.0,1.0))`; - src.push(`vec4 modelNormal = vec4(${programVariables.commonLibrary.octDecode}(${attributes.normal}.xy), 0.0)${timesModelNormalMatrixT || ""};`); - src.push(`vec3 ${worldNormal} = (${matrices.worldNormalMatrix} * modelNormal).xyz;`); - if (viewNormal.needed) { - src.push(`vec3 ${viewNormal} = normalize((${matrices.viewNormalMatrix} * vec4(${worldNormal}, 0.0)).xyz);`); - } - } - }, - - layerTypeInputs: { - attributes: attributes, - matrices: matrices, - uvDecodeMatrix: uvDecodeMatrix, - needNormal: needNormal - } - }; -}; - -/** - * A texture set within a {@link SceneModel}. - * - * * Created with {@link SceneModel#createTextureSet} - * * Belongs to many {@link SceneModelMesh}es - * * Stored by ID in {@link SceneModel#textureSets} - * * Referenced by {@link SceneModelMesh#textureSet} - */ -class SceneModelTextureSet { - - /** - * @private - */ - constructor(cfg) { - - /** - * Unique ID of this SceneModelTextureSet. - * - * The SceneModelTextureSet is registered against this ID in {@link SceneModel#textureSets}. - */ - this.id = cfg.id; - - /** - * The color texture. - * @type {SceneModelTexture|*} - */ - this.colorTexture = cfg.colorTexture; - - /** - * The alpha cutoff [float] - */ - this.alphaCutoff = cfg.alphaCutoff; - - /** - * The metallic-roughness texture. - * @type {SceneModelTexture|*} - */ - this.metallicRoughnessTexture = cfg.metallicRoughnessTexture; - - /** - * The normal map texture. - * @type {SceneModelTexture|*} - */ - this.normalsTexture = cfg.normalsTexture; - - /** - * The emissive color texture. - * @type {SceneModelTexture|*} - */ - this.emissiveTexture = cfg.emissiveTexture; - - /** - * The ambient occlusion texture. - * @type {SceneModelTexture|*} - */ - this.occlusionTexture = cfg.occlusionTexture; - } - - /** - * @private - */ - destroy() { - } -} - -/** - * A texture within a {@link SceneModelTextureSet}. - * - * * Created with {@link SceneModel#createTexture} - * * Belongs to many {@link SceneModelTextureSet}s - * * Stored by ID in {@link SceneModel#textures}} - */ -class SceneModelTexture { - - /** - * @private - * @param cfg - */ - constructor(cfg) { - - /** - * Unique ID of this SceneModelTexture. - * - * The SceneModelTexture is registered against this ID in {@link SceneModel#textures}. - */ - this.id = cfg.id; - - /** - * @private - */ - this.texture = cfg.texture; - } - - /** - * @private - */ - destroy() { - if (this.texture) { - this.texture.destroy(); - this.texture = null; - } - } -} - -const Cache$1 = { - - 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 = {}; - } -}; - -class LoadingManager { - - constructor(onLoad, onProgress, onError) { - - this.isLoading = false; - this.itemsLoaded = 0; - this.itemsTotal = 0; - this.urlModifier = undefined; - this.handlers = []; - - this.onStart = undefined; - this.onLoad = onLoad; - this.onProgress = onProgress; - this.onError = onError; - } - - itemStart(url) { - this.itemsTotal++; - if (this.isLoading === false) { - if (this.onStart !== undefined) { - this.onStart(url, this.itemsLoaded, this.itemsTotal); - } - } - this.isLoading = true; - } - - itemEnd(url) { - this.itemsLoaded++; - if (this.onProgress !== undefined) { - this.onProgress(url, this.itemsLoaded, this.itemsTotal); - } - if (this.itemsLoaded === this.itemsTotal) { - this.isLoading = false; - if (this.onLoad !== undefined) { - this.onLoad(); - } - } - } - - itemError(url) { - if (this.onError !== undefined) { - this.onError(url); - } - } - - resolveURL(url) { - if (this.urlModifier) { - return this.urlModifier(url); - } - return url; - } - - setURLModifier(transform) { - this.urlModifier = transform; - return this; - } - - addHandler(regex, loader) { - this.handlers.push(regex, loader); - return this; - } - - removeHandler(regex) { - const index = this.handlers.indexOf(regex); - if (index !== -1) { - this.handlers.splice(index, 2); - } - return this; - } - - getHandler(file) { - for (let i = 0, l = this.handlers.length; i < l; i += 2) { - const regex = this.handlers[i]; - const loader = this.handlers[i + 1]; - if (regex.global) regex.lastIndex = 0; // see #17920 - if (regex.test(file)) { - return loader; - } - } - return null; - } -} - -const DefaultLoadingManager = new LoadingManager(); - -class Loader { - - constructor(manager) { - - this.manager = (manager !== undefined) ? manager : DefaultLoadingManager; - - this.crossOrigin = 'anonymous'; - this.withCredentials = false; - this.path = ''; - this.resourcePath = ''; - this.requestHeader = {}; - } - - load( /* url, onLoad, onProgress, onError */) { - } - - loadAsync(url, onProgress) { - const scope = this; - return new Promise(function (resolve, reject) { - scope.load(url, resolve, onProgress, reject); - }); - } - - parse( /* data */) { - } - - 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; - } -} - -const loading = {}; - -class FileLoader extends Loader { - - constructor(manager) { - super(manager); - } - - load(url, onLoad, onProgress, onError) { - if (url === undefined) { - url = ''; - } - if (this.path !== undefined) { - url = this.path + url; - } - url = this.manager.resolveURL(url); - const cached = Cache$1.get(url); - if (cached !== undefined) { - this.manager.itemStart(url); - core.scheduleTask(() => { - if (onLoad) { - onLoad(cached); - } - this.manager.itemEnd(url); - }, 0); - return cached; - } - if (loading[url] !== undefined) { - loading[url].push({onLoad, onProgress, onError}); - return; - } - loading[url] = []; - loading[url].push({onLoad, onProgress, onError}); - const req = new Request(url, { - headers: new Headers(this.requestHeader), - credentials: this.withCredentials ? 'include' : 'same-origin' - }); - const mimeType = this.mimeType; - const responseType = this.responseType; - fetch(req).then(response => { - if (response.status === 200 || response.status === 0) { - // Some browsers return HTTP Status 0 when using non-http protocol - // e.g. 'file://' or 'data://'. Handle as success. - if (response.status === 0) { - console.warn('FileLoader: HTTP Status 0 received.'); - } - if (typeof ReadableStream === 'undefined' || response.body.getReader === undefined) { - return response; - } - const callbacks = loading[url]; - const reader = response.body.getReader(); - const contentLength = response.headers.get('Content-Length'); - const total = contentLength ? parseInt(contentLength) : 0; - const lengthComputable = total !== 0; - let loaded = 0; - const stream = new ReadableStream({ - start(controller) { - readData(); - - function readData() { - reader.read().then(({done, value}) => { - if (done) { - controller.close(); - } else { - loaded += value.byteLength; - const event = new ProgressEvent('progress', {lengthComputable, loaded, total}); - for (let i = 0, il = callbacks.length; i < il; i++) { - const callback = callbacks[i]; - if (callback.onProgress) { - callback.onProgress(event); - } - } - controller.enqueue(value); - readData(); - } - }); - } - } - }); - return new Response(stream); - } else { - throw Error(`fetch for "${response.url}" responded with ${response.status}: ${response.statusText}`); - } - }).then(response => { - switch (responseType) { - case 'arraybuffer': - return response.arrayBuffer(); - case 'blob': - return response.blob(); - case 'document': - return response.text() - .then(text => { - const parser = new DOMParser(); - return parser.parseFromString(text, mimeType); - }); - case 'json': - return response.json(); - default: - if (mimeType === undefined) { - return response.text(); - } else { - // sniff encoding - const re = /charset="?([^;"\s]*)"?/i; - const exec = re.exec(mimeType); - const label = exec && exec[1] ? exec[1].toLowerCase() : undefined; - const decoder = new TextDecoder(label); - return response.arrayBuffer().then(ab => decoder.decode(ab)); - } - } - }).then(data => { - // Add to cache only on HTTP success, so that we do not cache - // error response bodies as proper responses to requests. - Cache$1.add(url, data); - const callbacks = loading[url]; - delete loading[url]; - for (let i = 0, il = callbacks.length; i < il; i++) { - const callback = callbacks[i]; - if (callback.onLoad) { - callback.onLoad(data); - } - } - }).catch(err => { - // Abort errors and other errors are handled the same - const callbacks = loading[url]; - if (callbacks === undefined) { - // When onLoad was called and url was deleted in `loading` - this.manager.itemError(url); - throw err; - - } - delete loading[url]; - for (let i = 0, il = callbacks.length; i < il; i++) { - const callback = callbacks[i]; - if (callback.onError) { - callback.onError(err); - } - } - this.manager.itemError(url); - }).finally(() => { - this.manager.itemEnd(url); - }); - this.manager.itemStart(url); - } - - setResponseType(value) { - this.responseType = value; - return this; - } - - setMimeType(value) { - this.mimeType = value; - return this; - } -} - -/** - * @author Deepkolos / https://github.com/deepkolos - */ - -class WorkerPool$1 { - - constructor(pool = 4) { - this.pool = pool; - this.queue = []; - this.workers = []; - this.workersResolve = []; - this.workerStatus = 0; - } - - _initWorker(workerId) { - if (!this.workers[workerId]) { - const worker = this.workerCreator(); - worker.addEventListener('message', this._onMessage.bind(this, workerId)); - this.workers[workerId] = worker; - } - } - - _getIdleWorker() { - for (let i = 0; i < this.pool; i++) - if (!(this.workerStatus & (1 << i))) return i; - return -1; - } - - _onMessage(workerId, msg) { - const resolve = this.workersResolve[workerId]; - resolve && resolve(msg); - if (this.queue.length) { - const {resolve, msg, transfer} = this.queue.shift(); - this.workersResolve[workerId] = resolve; - this.workers[workerId].postMessage(msg, transfer); - } else { - this.workerStatus ^= 1 << workerId; - } - } - - setWorkerCreator(workerCreator) { - this.workerCreator = workerCreator; - } - - setWorkerLimit(pool) { - this.pool = pool; - } - - postMessage(msg, transfer) { - return new Promise((resolve) => { - const workerId = this._getIdleWorker(); - if (workerId !== -1) { - this._initWorker(workerId); - this.workerStatus |= 1 << workerId; - this.workersResolve[workerId] = resolve; - this.workers[workerId].postMessage(msg, transfer); - } else { - this.queue.push({resolve, msg, transfer}); - } - }); - } - - destroy() { - - this.workers.forEach((worker) => worker.terminate()); - this.workersResolve.length = 0; - this.workers.length = 0; - this.queue.length = 0; - this.workerStatus = 0; - - } - -} - -const KTX2TransferSRGB = 2; -const KTX2_ALPHA_PREMULTIPLIED = 1; - -let activeTranscoders = 0; - -/** - * Transcodes texture data from KTX2. - * - * ## Overview - * - * * Uses the [Basis Universal GPU Texture Codec](https://github.com/BinomialLLC/basis_universal) to - * transcode [KTX2](https://github.khronos.org/KTX-Specification/) textures. - * * {@link XKTLoaderPlugin} uses a KTX2TextureTranscoder to load textures in XKT files. - * * {@link VBOSceneModel} uses a KTX2TextureTranscoder to enable us to add KTX2-encoded textures. - * * Loads the Basis Codec from [CDN](https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/) by default, but can - * also be configured to load the Codec from local files. - * * We also bundle the Basis Codec with the xeokit-sdk npm package, and in the [repository](https://github.com/xeokit/xeokit-sdk/tree/master/dist/basis). - * - * ## What is KTX2? - * - * A [KTX2](https://github.khronos.org/KTX-Specification/) file stores GPU texture data in the Khronos Texture 2.0 (KTX2) container format. It contains image data for - * a texture asset compressed with Basis Universal (BasisU) supercompression that can be transcoded to different formats - * depending on the support provided by the target devices. KTX2 provides a lightweight format for distributing texture - * assets to GPUs. Due to BasisU compression, KTX2 files can store any image format supported by GPUs. - * - * ## Loading XKT files containing KTX2 textures - * - * {@link XKTLoaderPlugin} uses a KTX2TextureTranscoder to load textures in XKT files. An XKTLoaderPlugin has its own - * default KTX2TextureTranscoder, configured to load the Basis Codec from the [CDN](https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/). If we wish, we can override that with our own - * KTX2TextureTranscoder, configured to load the Codec locally. - * - * In the example below, we'll create a {@link Viewer} and add an {@link XKTLoaderPlugin} - * configured with a KTX2TextureTranscoder. Then we'll use the XKTLoaderPlugin to load an - * XKT file that contains KTX2 textures, which the plugin will transcode using - * its KTX2TextureTranscoder. - * - * We'll configure our KTX2TextureTranscoder to load the Basis Codec from a local directory. If we were happy with loading the - * Codec from our [CDN](https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/) (ie. our app will always have an Internet connection) then we could just leave out the - * KTX2TextureTranscoder altogether, and let the XKTLoaderPlugin use its internal default KTX2TextureTranscoder, which is configured to - * load the Codec from the CDN. We'll stick with loading our own Codec, in case we want to run our app without an Internet connection. - * - * - * - * * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/buildings/#xkt_vbo_textures_HousePlan)] - * - * ````javascript - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.camera.eye = [-2.56, 8.38, 8.27]; - * viewer.camera.look = [13.44, 3.31, -14.83]; - * viewer.camera.up = [0.10, 0.98, -0.14]; - * - * const textureTranscoder = new KTX2TextureTranscoder({ - * viewer, - * transcoderPath: "https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/" // <------ Path to Basis Universal transcoder - * }); - * - * const xktLoader = new XKTLoaderPlugin(viewer, { - * textureTranscoder // <<------------- Transcodes KTX2 textures in XKT files - * }); - * - * const sceneModel = xktLoader.load({ - * id: "myModel", - * src: "./HousePlan.xkt" // <<------ XKT file with KTX2 textures - * }); - * ```` - * - * ## Loading KTX2 files into a VBOSceneModel - * - * A {@link SceneModel} that is configured with a KTX2TextureTranscoder will - * allow us to load textures into it from KTX2-transcoded buffers or files. - * - * In the example below, we'll create a {@link Viewer}, containing a {@link VBOSceneModel} configured with a - * KTX2TextureTranscoder. - * - * We'll then programmatically create a simple object within the VBOSceneModel, consisting of - * a single box mesh with a texture loaded from a KTX2 file, which our VBOSceneModel internally transcodes, using - * its KTX2TextureTranscoder. - * - * As in the previous example, we'll configure our KTX2TextureTranscoder to load the Basis Codec from a local directory. - * - * * [Run a similar example](https://xeokit.github.io/xeokit-sdk/examples/scenemodel/#vbo_batching_autocompressed_triangles_textures_ktx2) - * - * ````javascript - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.scene.camera.eye = [-21.80, 4.01, 6.56]; - * viewer.scene.camera.look = [0, -5.75, 0]; - * viewer.scene.camera.up = [0.37, 0.91, -0.11]; - * - * const textureTranscoder = new KTX2TextureTranscoder({ - * viewer, - * transcoderPath: "https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/" // <------ Path to BasisU transcoder module - * }); - * - * const vboSceneModel = new VBOSceneModel(viewer.scene, { - * id: "myModel", - * textureTranscoder // <<-------------------- Configure model with our transcoder - * }); - * - * vboSceneModel.createTexture({ - * id: "myColorTexture", - * src: "../assets/textures/compressed/sample_uastc_zstd.ktx2" // <<----- KTX2 texture asset - * }); - * - * vboSceneModel.createTexture({ - * id: "myMetallicRoughnessTexture", - * src: "../assets/textures/alpha/crosshatchAlphaMap.jpg" // <<----- JPEG texture asset - * }); - * - * vboSceneModel.createTextureSet({ - * id: "myTextureSet", - * colorTextureId: "myColorTexture", - * metallicRoughnessTextureId: "myMetallicRoughnessTexture" - * }); - * - * vboSceneModel.createMesh({ - * id: "myMesh", - * textureSetId: "myTextureSet", - * primitive: "triangles", - * positions: [1, 1, 1, ...], - * normals: [0, 0, 1, 0, ...], - * uv: [1, 0, 0, ...], - * indices: [0, 1, 2, ...], - * }); - * - * vboSceneModel.createEntity({ - * id: "myEntity", - * meshIds: ["myMesh"] - * }); - * - * vboSceneModel.finalize(); - * ```` - * - * ## Loading KTX2 ArrayBuffers into a VBOSceneModel - * - * A {@link SceneModel} that is configured with a KTX2TextureTranscoder will also allow us to load textures into - * it from KTX2 ArrayBuffers. - * - * In the example below, we'll create a {@link Viewer}, containing a {@link VBOSceneModel} configured with a - * KTX2TextureTranscoder. - * - * We'll then programmatically create a simple object within the VBOSceneModel, consisting of - * a single mesh with a texture loaded from a KTX2 ArrayBuffer, which our VBOSceneModel internally transcodes, using - * its KTX2TextureTranscoder. - * - * ````javascript - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.scene.camera.eye = [-21.80, 4.01, 6.56]; - * viewer.scene.camera.look = [0, -5.75, 0]; - * viewer.scene.camera.up = [0.37, 0.91, -0.11]; - * - * const textureTranscoder = new KTX2TextureTranscoder({ - * viewer, - * transcoderPath: "https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/" // <------ Path to BasisU transcoder module - * }); - * - * const vboSceneModel = new VBOSceneModel(viewer.scene, { - * id: "myModel", - * textureTranscoder // <<-------------------- Configure model with our transcoder - * }); - * - * utils.loadArraybuffer("../assets/textures/compressed/sample_uastc_zstd.ktx2",(arrayBuffer) => { - * - * vboSceneModel.createTexture({ - * id: "myColorTexture", - * buffers: [arrayBuffer] // <<----- KTX2 texture asset - * }); - * - * vboSceneModel.createTexture({ - * id: "myMetallicRoughnessTexture", - * src: "../assets/textures/alpha/crosshatchAlphaMap.jpg" // <<----- JPEG texture asset - * }); - * - * vboSceneModel.createTextureSet({ - * id: "myTextureSet", - * colorTextureId: "myColorTexture", - * metallicRoughnessTextureId: "myMetallicRoughnessTexture" - * }); - * - * vboSceneModel.createMesh({ - * id: "myMesh", - * textureSetId: "myTextureSet", - * primitive: "triangles", - * positions: [1, 1, 1, ...], - * normals: [0, 0, 1, 0, ...], - * uv: [1, 0, 0, ...], - * indices: [0, 1, 2, ...], - * }); - * - * vboSceneModel.createEntity({ - * id: "myEntity", - * meshIds: ["myMesh"] - * }); - * - * vboSceneModel.finalize(); - * }); - * ```` - * - * @implements {TextureTranscoder} - */ -class KTX2TextureTranscoder { - - /** - * Creates a new KTX2TextureTranscoder. - * - * @param {Viewer} viewer The Viewer that our KTX2TextureTranscoder will be used with. This KTX2TextureTranscoder - * must only be used to transcode textures for this Viewer. This is because the Viewer's capabilities will decide - * what target GPU formats this KTX2TextureTranscoder will transcode to. - * @param {String} [transcoderPath="https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/"] Path to the Basis - * transcoder module that internally does the heavy lifting for our KTX2TextureTranscoder. If we omit this configuration, - * then our KTX2TextureTranscoder will load it from ````https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/```` by - * default. Therefore, make sure your application is connected to the internet if you wish to use the default transcoder path. - * @param {Number} [workerLimit] The maximum number of Workers to use for transcoding. - */ - constructor({viewer, transcoderPath, workerLimit}) { - - this._transcoderPath = transcoderPath || "https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/"; - this._transcoderBinary = null; - this._transcoderPending = null; - this._workerPool = new WorkerPool$1(); - this._workerSourceURL = ''; - - if (workerLimit) { - this._workerPool.setWorkerLimit(workerLimit); - } - - const viewerCapabilities = viewer.capabilities; - - this._workerConfig = { - astcSupported: viewerCapabilities.astcSupported, - etc1Supported: viewerCapabilities.etc1Supported, - etc2Supported: viewerCapabilities.etc2Supported, - dxtSupported: viewerCapabilities.dxtSupported, - bptcSupported: viewerCapabilities.bptcSupported, - pvrtcSupported: viewerCapabilities.pvrtcSupported - }; - - this._supportedFileTypes = ["xkt2"]; - } - - _init() { - if (!this._transcoderPending) { - const jsLoader = new FileLoader(); - jsLoader.setPath(this._transcoderPath); - jsLoader.setWithCredentials(this.withCredentials); - const jsContent = jsLoader.loadAsync('basis_transcoder.js'); - const binaryLoader = new FileLoader(); - binaryLoader.setPath(this._transcoderPath); - binaryLoader.setResponseType('arraybuffer'); - binaryLoader.setWithCredentials(this.withCredentials); - const binaryContent = binaryLoader.loadAsync('basis_transcoder.wasm'); - this._transcoderPending = Promise.all([jsContent, binaryContent]) - .then(([jsContent, binaryContent]) => { - const fn = KTX2TextureTranscoder.BasisWorker.toString(); - const body = [ - '/* constants */', - 'let _EngineFormat = ' + JSON.stringify(KTX2TextureTranscoder.EngineFormat), - 'let _TranscoderFormat = ' + JSON.stringify(KTX2TextureTranscoder.TranscoderFormat), - 'let _BasisFormat = ' + JSON.stringify(KTX2TextureTranscoder.BasisFormat), - '/* basis_transcoder.js */', - jsContent, - '/* worker */', - fn.substring(fn.indexOf('{') + 1, fn.lastIndexOf('}')) - ].join('\n'); - this._workerSourceURL = URL.createObjectURL(new Blob([body])); - this._transcoderBinary = binaryContent; - this._workerPool.setWorkerCreator(() => { - const worker = new Worker(this._workerSourceURL); - const transcoderBinary = this._transcoderBinary.slice(0); - worker.postMessage({ - type: 'init', - config: this._workerConfig, - transcoderBinary - }, [transcoderBinary]); - return worker; - }); - }); - if (activeTranscoders > 0) { - console.warn('KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues.' + ' Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances.'); - } - activeTranscoders++; - } - return this._transcoderPending; - } - - /** - * Transcodes texture data from transcoded buffers into a {@link Texture2D}. - * - * @param {ArrayBuffer[]} buffers Transcoded texture data. Given as an array of buffers so that we can support multi-image textures, such as cube maps. - * @param {*} config Transcoding options. - * @param {Texture2D} texture The texture to load. - * @returns {Promise} Resolves when the texture has loaded. - */ - transcode(buffers, texture, config = {}) { - return new Promise((resolve, reject) => { - const taskConfig = config; - this._init().then(() => { - return this._workerPool.postMessage({ - type: 'transcode', - buffers, - taskConfig: taskConfig - }, buffers); - }).then((e) => { - const transcodeResult = e.data; - const {mipmaps, width, height, format, type, error, dfdTransferFn, dfdFlags} = transcodeResult; - if (type === 'error') { - return reject(error); - } - texture.setCompressedData({ - mipmaps, - props: { - format: format, - minFilter: mipmaps.length === 1 ? LinearFilter : LinearMipmapLinearFilter, - magFilter: mipmaps.length === 1 ? LinearFilter : LinearMipmapLinearFilter, - encoding: dfdTransferFn === KTX2TransferSRGB ? sRGBEncoding : LinearEncoding, - premultiplyAlpha: !!(dfdFlags & KTX2_ALPHA_PREMULTIPLIED) - } - }); - resolve(); - }); - }); - } - - /** - * Destroys this KTX2TextureTranscoder - */ - destroy() { - URL.revokeObjectURL(this._workerSourceURL); - this._workerPool.destroy(); - activeTranscoders--; - } -} - -/** - * @private - */ -KTX2TextureTranscoder.BasisFormat = { - ETC1S: 0, - UASTC_4x4: 1 -}; - -/** - * @private - */ -KTX2TextureTranscoder.TranscoderFormat = { - ETC1: 0, - ETC2: 1, - BC1: 2, - BC3: 3, - BC4: 4, - BC5: 5, - BC7_M6_OPAQUE_ONLY: 6, - BC7_M5: 7, - PVRTC1_4_RGB: 8, - PVRTC1_4_RGBA: 9, - ASTC_4x4: 10, - ATC_RGB: 11, - ATC_RGBA_INTERPOLATED_ALPHA: 12, - RGBA32: 13, - RGB565: 14, - BGR565: 15, - RGBA4444: 16 -}; - -/** - * @private - */ -KTX2TextureTranscoder.EngineFormat = { - RGBAFormat: RGBAFormat, - RGBA_ASTC_4x4_Format: RGBA_ASTC_4x4_Format, - RGBA_BPTC_Format: RGBA_BPTC_Format, - RGBA_ETC2_EAC_Format: RGBA_ETC2_EAC_Format, - RGBA_PVRTC_4BPPV1_Format: RGBA_PVRTC_4BPPV1_Format, - RGBA_S3TC_DXT5_Format: RGBA_S3TC_DXT5_Format, - RGB_ETC1_Format: RGB_ETC1_Format, - RGB_ETC2_Format: RGB_ETC2_Format, - RGB_PVRTC_4BPPV1_Format: RGB_PVRTC_4BPPV1_Format, - RGB_S3TC_DXT1_Format: RGB_S3TC_DXT1_Format -}; - -/* WEB WORKER */ - -/** - * @private - * @constructor - */ -KTX2TextureTranscoder.BasisWorker = function () { - - let config; - let transcoderPending; - let BasisModule; - - const EngineFormat = _EngineFormat; // eslint-disable-line no-undef - const TranscoderFormat = _TranscoderFormat; // eslint-disable-line no-undef - const BasisFormat = _BasisFormat; // eslint-disable-line no-undef - - self.addEventListener('message', function (e) { - const message = e.data; - switch (message.type) { - case 'init': - config = message.config; - init(message.transcoderBinary); - break; - case 'transcode': - transcoderPending.then(() => { - try { - const { - width, - height, - hasAlpha, - mipmaps, - format, - dfdTransferFn, - dfdFlags - } = transcode(message.buffers[0]); - const buffers = []; - for (let i = 0; i < mipmaps.length; ++i) { - buffers.push(mipmaps[i].data.buffer); - } - self.postMessage({ - type: 'transcode', - id: message.id, - width, - height, - hasAlpha, - mipmaps, - format, - dfdTransferFn, - dfdFlags - }, buffers); - } catch (error) { - console.error(`[KTX2TextureTranscoder.BasisWorker]: ${error}`); - self.postMessage({type: 'error', id: message.id, error: error.message}); - } - }); - break; - } - }); - - function init(wasmBinary) { - transcoderPending = new Promise(resolve => { - BasisModule = { - wasmBinary, - onRuntimeInitialized: resolve - }; - BASIS(BasisModule); // eslint-disable-line no-undef - }).then(() => { - BasisModule.initializeBasis(); - if (BasisModule.KTX2File === undefined) { - console.warn('KTX2TextureTranscoder: Please update Basis Universal transcoder.'); - } - }); - } - - function transcode(buffer) { - const ktx2File = new BasisModule.KTX2File(new Uint8Array(buffer)); - - function cleanup() { - ktx2File.close(); - ktx2File.delete(); - } - - if (!ktx2File.isValid()) { - cleanup(); - throw new Error('KTX2TextureTranscoder: Invalid or unsupported .ktx2 file'); - } - const basisFormat = ktx2File.isUASTC() ? BasisFormat.UASTC_4x4 : BasisFormat.ETC1S; - const width = ktx2File.getWidth(); - const height = ktx2File.getHeight(); - const levels = ktx2File.getLevels(); - const hasAlpha = ktx2File.getHasAlpha(); - const dfdTransferFn = ktx2File.getDFDTransferFunc(); - const dfdFlags = ktx2File.getDFDFlags(); - const {transcoderFormat, engineFormat} = getTranscoderFormat(basisFormat, width, height, hasAlpha); - if (!width || !height || !levels) { - cleanup(); - throw new Error('KTX2TextureTranscoder: Invalid texture'); - } - if (!ktx2File.startTranscoding()) { - cleanup(); - throw new Error('KTX2TextureTranscoder: .startTranscoding failed'); - } - const mipmaps = []; - for (let mip = 0; mip < levels; mip++) { - const levelInfo = ktx2File.getImageLevelInfo(mip, 0, 0); - const mipWidth = levelInfo.origWidth; - const mipHeight = levelInfo.origHeight; - const dst = new Uint8Array(ktx2File.getImageTranscodedSizeInBytes(mip, 0, 0, transcoderFormat)); - const status = ktx2File.transcodeImage(dst, mip, 0, 0, transcoderFormat, 0, -1, -1); - if (!status) { - cleanup(); - throw new Error('KTX2TextureTranscoder: .transcodeImage failed.'); - } - mipmaps.push({data: dst, width: mipWidth, height: mipHeight}); - } - cleanup(); - return {width, height, hasAlpha, mipmaps, format: engineFormat, dfdTransferFn, dfdFlags}; - } - - // Optimal choice of a transcoder target format depends on the Basis format (ETC1S or UASTC), - // device capabilities, and texture dimensions. The list below ranks the formats separately - // for ETC1S and UASTC. - // - // In some cases, transcoding UASTC to RGBA32 might be preferred for higher quality (at - // significant memory cost) compared to ETC1/2, BC1/3, and PVRTC. The transcoder currently - // chooses RGBA32 only as a last resort and does not expose that option to the caller. - - const FORMAT_OPTIONS = [{ - if: 'astcSupported', - basisFormat: [BasisFormat.UASTC_4x4], - transcoderFormat: [TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4], - engineFormat: [EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format], - priorityETC1S: Infinity, - priorityUASTC: 1, - needsPowerOfTwo: false - }, { - if: 'bptcSupported', - basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4], - transcoderFormat: [TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5], - engineFormat: [EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format], - priorityETC1S: 3, - priorityUASTC: 2, - needsPowerOfTwo: false - }, { - if: 'dxtSupported', - basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4], - transcoderFormat: [TranscoderFormat.BC1, TranscoderFormat.BC3], - engineFormat: [EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format], - priorityETC1S: 4, - priorityUASTC: 5, - needsPowerOfTwo: false - }, { - if: 'etc2Supported', - basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4], - transcoderFormat: [TranscoderFormat.ETC1, TranscoderFormat.ETC2], - engineFormat: [EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format], - priorityETC1S: 1, - priorityUASTC: 3, - needsPowerOfTwo: false - }, { - if: 'etc1Supported', - basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4], - transcoderFormat: [TranscoderFormat.ETC1], - engineFormat: [EngineFormat.RGB_ETC1_Format], - priorityETC1S: 2, - priorityUASTC: 4, - needsPowerOfTwo: false - }, { - if: 'pvrtcSupported', - basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4], - transcoderFormat: [TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA], - engineFormat: [EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format], - priorityETC1S: 5, - priorityUASTC: 6, - needsPowerOfTwo: true - }]; - const ETC1S_OPTIONS = FORMAT_OPTIONS.sort(function (a, b) { - return a.priorityETC1S - b.priorityETC1S; - }); - const UASTC_OPTIONS = FORMAT_OPTIONS.sort(function (a, b) { - return a.priorityUASTC - b.priorityUASTC; - }); - - function getTranscoderFormat(basisFormat, width, height, hasAlpha) { - let transcoderFormat; - let engineFormat; - const options = basisFormat === BasisFormat.ETC1S ? ETC1S_OPTIONS : UASTC_OPTIONS; - for (let i = 0; i < options.length; i++) { - const opt = options[i]; - if (!config[opt.if]) continue; - if (!opt.basisFormat.includes(basisFormat)) continue; - if (hasAlpha && opt.transcoderFormat.length < 2) continue; - if (opt.needsPowerOfTwo && !(isPowerOfTwo(width) && isPowerOfTwo(height))) continue; - transcoderFormat = opt.transcoderFormat[hasAlpha ? 1 : 0]; - engineFormat = opt.engineFormat[hasAlpha ? 1 : 0]; - return { - transcoderFormat, - engineFormat - }; - } - console.warn('KTX2TextureTranscoder: No suitable compressed texture format found. Decoding to RGBA32.'); - transcoderFormat = TranscoderFormat.RGBA32; - engineFormat = EngineFormat.RGBAFormat; - return { - transcoderFormat, - engineFormat - }; - } - - function isPowerOfTwo(value) { - if (value <= 2) return true; - return (value & value - 1) === 0 && value !== 0; - } -}; - -const cachedTranscoders = {}; - -/** - * Returns a new {@link KTX2TextureTranscoder}. - * - * The ````transcoderPath```` config will be set to: "https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/" - * - * @private - */ -function getKTX2TextureTranscoder(viewer) { - const sceneId = viewer.scene.id; - let transcoder = cachedTranscoders[sceneId]; - if (!transcoder) { - transcoder = new KTX2TextureTranscoder({viewer}); - cachedTranscoders[sceneId] = transcoder; - viewer.scene.on("destroyed", () => { - delete cachedTranscoders[sceneId]; - transcoder.destroy(); - }); - } - return transcoder; -} - -/** - * @author https://github.com/tmarti, with support from https://tribia.com/ - * @license MIT - * - * This file takes a geometry given by { positionsCompressed, indices }, and returns - * equivalent { positionsCompressed, indices } arrays but which only contain unique - * positionsCompressed. - * - * The time is O(N logN) with the number of positionsCompressed due to a pre-sorting - * step, but is much more GC-friendly and actually faster than the classic O(N) - * approach based in keeping a hash-based LUT to identify unique positionsCompressed. - */ -let comparePositions = null; - -function compareVertex(a, b) { - let res; - for (let i = 0; i < 3; i++) { - if (0 !== (res = comparePositions[a * 3 + i] - comparePositions[b * 3 + i])) { - return res; - } - } - return 0; -} - -let seqInit = null; - -function setMaxNumberOfPositions(maxPositions) { - if (seqInit !== null && seqInit.length >= maxPositions) { - return; - } - seqInit = new Uint32Array(maxPositions); - for (let i = 0; i < maxPositions; i++) { - seqInit[i] = i; - } -} - -/** - * This function obtains unique positionsCompressed in the provided object - * .positionsCompressed array and calculates an index mapping, which is then - * applied to the provided object .indices and .edgeindices. - * - * The input object items are not modified, and instead new set - * of positionsCompressed, indices and edgeIndices with the applied optimization - * are returned. - * - * The algorithm, instead of being based in a hash-like LUT for - * identifying unique positionsCompressed, is based in pre-sorting the input - * positionsCompressed... - * - * (it's possible to define a _"consistent ordering"_ for the positionsCompressed - * as positionsCompressed are quantized and thus not suffer from float number - * comparison artifacts) - * - * ... so same positionsCompressed are adjacent in the sorted array, and then - * it's easy to scan linearly the sorted array. During the linear run, - * we will know that we found a different position because the comparison - * function will return != 0 between current and previous element. - * - * During this linear traversal of the array, a `unique counter` is used - * in order to calculate the mapping between original indices and unique - * indices. - * - * @param {{positionsCompressed: number[],indices: number[], edgeIndices: number[]}} mesh The input mesh to process, with `positionsCompressed`, `indices` and `edgeIndices` keys. - * - * @returns {[Uint16Array, Uint32Array, Uint32Array]} An array with 3 elements: 0 => the uniquified positionsCompressed; 1 and 2 => the remapped edges and edgeIndices arrays - */ -function uniquifyPositions(mesh) { - const _positions = mesh.positionsCompressed; - const _indices = mesh.indices; - const _edgeIndices = mesh.edgeIndices; - - setMaxNumberOfPositions(_positions.length / 3); - - const seq = seqInit.slice(0, _positions.length / 3); - const remappings = seqInit.slice(0, _positions.length / 3); - - comparePositions = _positions; - - seq.sort(compareVertex); - - let uniqueIdx = 0; - - remappings[seq[0]] = 0; - - for (let i = 1, len = seq.length; i < len; i++) { - if (0 !== compareVertex(seq[i], seq[i - 1])) { - uniqueIdx++; - } - remappings[seq[i]] = uniqueIdx; - } - - const numUniquePositions = uniqueIdx + 1; - const newPositions = new Uint16Array(numUniquePositions * 3); - - uniqueIdx = 0; - - newPositions [uniqueIdx * 3 + 0] = _positions [seq[0] * 3 + 0]; - newPositions [uniqueIdx * 3 + 1] = _positions [seq[0] * 3 + 1]; - newPositions [uniqueIdx * 3 + 2] = _positions [seq[0] * 3 + 2]; - - for (let i = 1, len = seq.length; i < len; i++) { - if (0 !== compareVertex(seq[i], seq[i - 1])) { - uniqueIdx++; - newPositions [uniqueIdx * 3 + 0] = _positions [seq[i] * 3 + 0]; - newPositions [uniqueIdx * 3 + 1] = _positions [seq[i] * 3 + 1]; - newPositions [uniqueIdx * 3 + 2] = _positions [seq[i] * 3 + 2]; - } - remappings[seq[i]] = uniqueIdx; - } - - comparePositions = null; - - const newIndices = new Uint32Array(_indices.length); - - for (let i = 0, len = _indices.length; i < len; i++) { - newIndices[i] = remappings [_indices[i]]; - } - - const newEdgeIndices = new Uint32Array(_edgeIndices.length); - - for (let i = 0, len = _edgeIndices.length; i < len; i++) { - newEdgeIndices[i] = remappings [_edgeIndices[i]]; - } - - return [newPositions, newIndices, newEdgeIndices]; -} - -/** - * @author https://github.com/tmarti, with support from https://tribia.com/ - * @license MIT - **/ - -const MAX_RE_BUCKET_FAN_OUT = 8; - -let bucketsForIndices = null; - -function compareBuckets(a, b) { - const aa = a * 3; - const bb = b * 3; - let aa1, aa2, aa3, bb1, bb2, bb3; - const minBucketA = Math.min( - aa1 = bucketsForIndices[aa], - aa2 = bucketsForIndices[aa + 1], - aa3 = bucketsForIndices[aa + 2] - ); - const minBucketB = Math.min( - bb1 = bucketsForIndices[bb], - bb2 = bucketsForIndices[bb + 1], - bb3 = bucketsForIndices[bb + 2] - ); - if (minBucketA !== minBucketB) { - return minBucketA - minBucketB; - } - const maxBucketA = Math.max(aa1, aa2, aa3); - const maxBucketB = Math.max(bb1, bb2, bb3,); - if (maxBucketA !== maxBucketB) { - return maxBucketA - maxBucketB; - } - return 0; -} - -function preSortIndices(indices, bitsPerBucket) { - const seq = new Int32Array(indices.length / 3); - for (let i = 0, len = seq.length; i < len; i++) { - seq[i] = i; - } - bucketsForIndices = new Int32Array(indices.length); - for (let i = 0, len = indices.length; i < len; i++) { - bucketsForIndices[i] = indices[i] >> bitsPerBucket; - } - seq.sort(compareBuckets); - const sortedIndices = new Int32Array(indices.length); - for (let i = 0, len = seq.length; i < len; i++) { - sortedIndices[i * 3 + 0] = indices[seq[i] * 3 + 0]; - sortedIndices[i * 3 + 1] = indices[seq[i] * 3 + 1]; - sortedIndices[i * 3 + 2] = indices[seq[i] * 3 + 2]; - } - return sortedIndices; -} - -let compareEdgeIndices = null; - -function compareIndices(a, b) { - let retVal = compareEdgeIndices[a * 2] - compareEdgeIndices[b * 2]; - if (retVal !== 0) { - return retVal; - } - return compareEdgeIndices[a * 2 + 1] - compareEdgeIndices[b * 2 + 1]; -} - -function preSortEdgeIndices(edgeIndices) { - if ((edgeIndices || []).length === 0) { - return []; - } - let seq = new Int32Array(edgeIndices.length / 2); - for (let i = 0, len = seq.length; i < len; i++) { - seq[i] = i; - } - for (let i = 0, len = edgeIndices.length; i < len; i += 2) { - if (edgeIndices[i] > edgeIndices[i + 1]) { - let tmp = edgeIndices[i]; - edgeIndices[i] = edgeIndices[i + 1]; - edgeIndices[i + 1] = tmp; - } - } - compareEdgeIndices = new Int32Array(edgeIndices); - seq.sort(compareIndices); - const sortedEdgeIndices = new Int32Array(edgeIndices.length); - for (let i = 0, len = seq.length; i < len; i++) { - sortedEdgeIndices[i * 2 + 0] = edgeIndices[seq[i] * 2 + 0]; - sortedEdgeIndices[i * 2 + 1] = edgeIndices[seq[i] * 2 + 1]; - } - return sortedEdgeIndices; -} - -/** - * @param {{positionsCompressed: number[], indices: number[], edgeIndices: number[]}} mesh - * @param {number} bitsPerBucket - * @param {boolean} checkResult - * - * @returns {{positionsCompressed: number[], indices: number[], edgeIndices: number[]}[]} - */ -function rebucketPositions(mesh, bitsPerBucket, checkResult = false) { - const positionsCompressed = (mesh.positionsCompressed || []); - const indices = preSortIndices(mesh.indices || [], bitsPerBucket); - const edgeIndices = preSortEdgeIndices(mesh.edgeIndices || []); - - function edgeSearch(el0, el1) { // Code adapted from https://stackoverflow.com/questions/22697936/binary-search-in-javascript - if (el0 > el1) { - let tmp = el0; - el0 = el1; - el1 = tmp; - } - - function compare_fn(a, b) { - if (a !== el0) { - return el0 - a; - } - if (b !== el1) { - return el1 - b; - } - return 0; - } - - let m = 0; - let n = (edgeIndices.length >> 1) - 1; - while (m <= n) { - const k = (n + m) >> 1; - const cmp = compare_fn(edgeIndices[k * 2], edgeIndices[k * 2 + 1]); - if (cmp > 0) { - m = k + 1; - } else if (cmp < 0) { - n = k - 1; - } else { - return k; - } - } - return -m - 1; - } - - const alreadyOutputEdgeIndices = new Int32Array(edgeIndices.length / 2); - alreadyOutputEdgeIndices.fill(0); - - const numPositions = positionsCompressed.length / 3; - - if (numPositions > ((1 << bitsPerBucket) * MAX_RE_BUCKET_FAN_OUT)) { - return [mesh]; - } - - const bucketIndicesRemap = new Int32Array(numPositions); - bucketIndicesRemap.fill(-1); - - const buckets = []; - - function addEmptyBucket() { - bucketIndicesRemap.fill(-1); - - const newBucket = { - positionsCompressed: [], - indices: [], - edgeIndices: [], - maxNumPositions: (1 << bitsPerBucket) - bitsPerBucket, - numPositions: 0, - bucketNumber: buckets.length, - }; - - buckets.push(newBucket); - - return newBucket; - } - - let currentBucket = addEmptyBucket(); - - for (let i = 0, len = indices.length; i < len; i += 3) { - let additonalPositionsInBucket = 0; - - const ii0 = indices[i]; - const ii1 = indices[i + 1]; - const ii2 = indices[i + 2]; - - if (bucketIndicesRemap[ii0] === -1) { - additonalPositionsInBucket++; - } - - if (bucketIndicesRemap[ii1] === -1) { - additonalPositionsInBucket++; - } - - if (bucketIndicesRemap[ii2] === -1) { - additonalPositionsInBucket++; - } - - if ((additonalPositionsInBucket + currentBucket.numPositions) > currentBucket.maxNumPositions) { - currentBucket = addEmptyBucket(); - } - - if (currentBucket.bucketNumber > MAX_RE_BUCKET_FAN_OUT) { - return [mesh]; - } - - if (bucketIndicesRemap[ii0] === -1) { - bucketIndicesRemap[ii0] = currentBucket.numPositions++; - currentBucket.positionsCompressed.push(positionsCompressed[ii0 * 3]); - currentBucket.positionsCompressed.push(positionsCompressed[ii0 * 3 + 1]); - currentBucket.positionsCompressed.push(positionsCompressed[ii0 * 3 + 2]); - } - - if (bucketIndicesRemap[ii1] === -1) { - bucketIndicesRemap[ii1] = currentBucket.numPositions++; - currentBucket.positionsCompressed.push(positionsCompressed[ii1 * 3]); - currentBucket.positionsCompressed.push(positionsCompressed[ii1 * 3 + 1]); - currentBucket.positionsCompressed.push(positionsCompressed[ii1 * 3 + 2]); - } - - if (bucketIndicesRemap[ii2] === -1) { - bucketIndicesRemap[ii2] = currentBucket.numPositions++; - currentBucket.positionsCompressed.push(positionsCompressed[ii2 * 3]); - currentBucket.positionsCompressed.push(positionsCompressed[ii2 * 3 + 1]); - currentBucket.positionsCompressed.push(positionsCompressed[ii2 * 3 + 2]); - } - - currentBucket.indices.push(bucketIndicesRemap[ii0]); - currentBucket.indices.push(bucketIndicesRemap[ii1]); - currentBucket.indices.push(bucketIndicesRemap[ii2]); - - // Check possible edge1 - let edgeIndex; - - if ((edgeIndex = edgeSearch(ii0, ii1)) >= 0) { - if (alreadyOutputEdgeIndices[edgeIndex] === 0) { - alreadyOutputEdgeIndices[edgeIndex] = 1; - - currentBucket.edgeIndices.push(bucketIndicesRemap[edgeIndices[edgeIndex * 2]]); - currentBucket.edgeIndices.push(bucketIndicesRemap[edgeIndices[edgeIndex * 2 + 1]]); - } - } - - if ((edgeIndex = edgeSearch(ii0, ii2)) >= 0) { - if (alreadyOutputEdgeIndices[edgeIndex] === 0) { - alreadyOutputEdgeIndices[edgeIndex] = 1; - - currentBucket.edgeIndices.push(bucketIndicesRemap[edgeIndices[edgeIndex * 2]]); - currentBucket.edgeIndices.push(bucketIndicesRemap[edgeIndices[edgeIndex * 2 + 1]]); - } - } - - if ((edgeIndex = edgeSearch(ii1, ii2)) >= 0) { - if (alreadyOutputEdgeIndices[edgeIndex] === 0) { - alreadyOutputEdgeIndices[edgeIndex] = 1; - - currentBucket.edgeIndices.push(bucketIndicesRemap[edgeIndices[edgeIndex * 2]]); - currentBucket.edgeIndices.push(bucketIndicesRemap[edgeIndices[edgeIndex * 2 + 1]]); - } - } - } - - const prevBytesPerIndex = bitsPerBucket / 8 * 2; - const newBytesPerIndex = bitsPerBucket / 8; - - const originalSize = positionsCompressed.length * 2 + (indices.length + edgeIndices.length) * prevBytesPerIndex; - - let newSize = 0; - let newPositions = -positionsCompressed.length / 3; - - buckets.forEach(bucket => { - newSize += bucket.positionsCompressed.length * 2 + (bucket.indices.length + bucket.edgeIndices.length) * newBytesPerIndex; - newPositions += bucket.positionsCompressed.length / 3; - }); - if (newSize > originalSize) { - return [mesh]; - } - if (checkResult) { - doCheckResult(buckets, mesh); - } - return buckets; -} - -function doCheckResult(buckets, mesh) { - const meshDict = {}; - const edgesDict = {}; - - let edgeIndicesCount = 0; - - buckets.forEach(bucket => { - const indices = bucket.indices; - const edgeIndices = bucket.edgeIndices; - const positionsCompressed = bucket.positionsCompressed; - - for (let i = 0, len = indices.length; i < len; i += 3) { - const key = positionsCompressed[indices[i] * 3] + "_" + positionsCompressed[indices[i] * 3 + 1] + "_" + positionsCompressed[indices[i] * 3 + 2] + "/" + - positionsCompressed[indices[i + 1] * 3] + "_" + positionsCompressed[indices[i + 1] * 3 + 1] + "_" + positionsCompressed[indices[i + 1] * 3 + 2] + "/" + - positionsCompressed[indices[i + 2] * 3] + "_" + positionsCompressed[indices[i + 2] * 3 + 1] + "_" + positionsCompressed[indices[i + 2] * 3 + 2]; - meshDict[key] = true; - } - - edgeIndicesCount += bucket.edgeIndices.length / 2; - - for (let i = 0, len = edgeIndices.length; i < len; i += 2) { - const key = positionsCompressed[edgeIndices[i] * 3] + "_" + positionsCompressed[edgeIndices[i] * 3 + 1] + "_" + positionsCompressed[edgeIndices[i] * 3 + 2] + "/" + - positionsCompressed[edgeIndices[i + 1] * 3] + "_" + positionsCompressed[edgeIndices[i + 1] * 3 + 1] + "_" + positionsCompressed[edgeIndices[i + 1] * 3 + 2] + "/"; - edgesDict[key] = true; - } - }); - - { - const indices = mesh.indices; - mesh.edgeIndices; - const positionsCompressed = mesh.positionsCompressed; - - for (let i = 0, len = indices.length; i < len; i += 3) { - const key = positionsCompressed[indices[i] * 3] + "_" + positionsCompressed[indices[i] * 3 + 1] + "_" + positionsCompressed[indices[i] * 3 + 2] + "/" + - positionsCompressed[indices[i + 1] * 3] + "_" + positionsCompressed[indices[i + 1] * 3 + 1] + "_" + positionsCompressed[indices[i + 1] * 3 + 2] + "/" + - positionsCompressed[indices[i + 2] * 3] + "_" + positionsCompressed[indices[i + 2] * 3 + 1] + "_" + positionsCompressed[indices[i + 2] * 3 + 2]; - - if (!(key in meshDict)) { - console.log("Not found " + key); - throw "Ohhhh!"; - } - } - - // for (var i = 0, len = edgeIndices.length; i < len; i+=2) - // { - // var key = positionsCompressed[edgeIndices[i]*3] + "_" + positionsCompressed[edgeIndices[i]*3+1] + "_" + positionsCompressed[edgeIndices[i]*3+2] + "/" + - // positionsCompressed[edgeIndices[i+1]*3] + "_" + positionsCompressed[edgeIndices[i+1]*3+1] + "_" + positionsCompressed[edgeIndices[i+1]*3+2] + "/"; - - // if (!(key in edgesDict)) { - // var key2 = edgeIndices[i] + "_" + edgeIndices[i+1]; - - // console.log (" - Not found " + key); - // console.log (" - Not found " + key2); - // // throw "Ohhhh2!"; - // } - // } - } -} - -const tempFloatRGB = new Float32Array([0, 0, 0]); -const tempIntRGB = new Uint16Array([0, 0, 0]); - -math.OBB3(); - -/** - * An entity within a {@link SceneModel} - * - * * Created with {@link SceneModel#createEntity} - * * Stored by ID in {@link SceneModel#entities} - * * Has one or more {@link SceneModelMesh}es - * - * @implements {Entity} - */ -class SceneModelEntity { - - /** - * @private - */ - constructor(model, isObject, id, meshes, flags, lodCullable) { - - this._isObject = isObject; - - /** - * The {@link Scene} to which this SceneModelEntity belongs. - */ - this.scene = model.scene; - - /** - * The {@link SceneModel} to which this SceneModelEntity belongs. - */ - this.model = model; - - /** - * Identifies if it's a SceneModelEntity - */ - this.isSceneModelEntity = true; - - /** - * The {@link SceneModelMesh}es belonging to this SceneModelEntity. - * - * * These are created with {@link SceneModel#createMesh} and registered in {@ilnk SceneModel#meshes} - * * Each SceneModelMesh belongs to one SceneModelEntity - */ - this.meshes = meshes; - - this._numPrimitives = 0; - this._capMaterial = null; - - for (let i = 0, len = this.meshes.length; i < len; i++) { // TODO: tidier way? Refactor? - const mesh = this.meshes[i]; - mesh.parent = this; - mesh.entity = this; - this._numPrimitives += mesh.numPrimitives; - } - - /** - * The unique ID of this SceneModelEntity. - */ - this.id = id; - - /** - * The original system ID of this SceneModelEntity. - */ - this.originalSystemId = math.unglobalizeObjectId(model.id, id); - - this._flags = flags; - this._aabb = math.AABB3(); - this._aabbDirty = true; - - this._offset = math.vec3(); - this._colorizeUpdated = false; - this._opacityUpdated = false; - - this._lodCullable = (!!lodCullable); - this._culled = false; - this._culledVFC = false; - this._culledLOD = false; - - if (this._isObject) { - model.scene._registerObject(this); - } - } - - _transformDirty() { - this._aabbDirty = true; - this.model._transformDirty(); - - } - - _sceneModelDirty() { // Called by SceneModel when SceneModel's matrix is updated - this._aabbDirty = true; - for (let i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._sceneModelDirty(); - } - } - - /** - * World-space 3D axis-aligned bounding box (AABB) of this SceneModelEntity. - * - * Represented by a six-element Float64Array containing the min/max extents of the - * axis-aligned volume, ie. ````[xmin, ymin, zmin, xmax, ymax, zmax]````. - * - * @type {Float64Array} - */ - get aabb() { - if (this._aabbDirty) { - math.collapseAABB3(this._aabb); - for (let i = 0, len = this.meshes.length; i < len; i++) { - math.expandAABB3(this._aabb, this.meshes[i].aabb); - } - this._aabbDirty = false; - } - // if (this._aabbDirty) { - // math.AABB3ToOBB3(this._aabb, tempOBB3a); - // math.transformOBB3(this.model.matrix, tempOBB3a); - // math.OBB3ToAABB3(tempOBB3a, this._worldAABB); - // this._worldAABB[0] += this._offset[0]; - // this._worldAABB[1] += this._offset[1]; - // this._worldAABB[2] += this._offset[2]; - // this._worldAABB[3] += this._offset[0]; - // this._worldAABB[4] += this._offset[1]; - // this._worldAABB[5] += this._offset[2]; - // this._aabbDirty = false; - // } - return this._aabb; - } - - get isEntity() { - return true; - } - - /** - * Returns false to indicate that this Entity subtype is not a model. - * @returns {boolean} - */ - get isModel() { - return false; - } - - /** - * Returns ````true```` if this SceneModelEntity represents an object. - * - * When this is ````true````, the SceneModelEntity will be registered by {@link SceneModelEntity#id} - * in {@link Scene#objects} and may also have a corresponding {@link MetaObject}. - * - * @type {Boolean} - */ - get isObject() { - return this._isObject; - } - - get numPrimitives() { - return this._numPrimitives; - } - - /** - * The approximate number of triangles in this SceneModelEntity. - * - * @type {Number} - */ - get numTriangles() { - return this._numPrimitives; - } - - /** - * Gets if this SceneModelEntity is visible. - * - * Only rendered when {@link SceneModelEntity#visible} is ````true```` - * and {@link SceneModelEntity#culled} is ````false````. - * - * When {@link SceneModelEntity#isObject} and {@link SceneModelEntity#visible} are - * both ````true```` the SceneModelEntity will be registered - * by {@link SceneModelEntity#id} in {@link Scene#visibleObjects}. - * - * @type {Boolean} - */ - get visible() { - return this._getFlag(ENTITY_FLAGS.VISIBLE); - } - - /** - * Sets if this SceneModelEntity is visible. - * - * Only rendered when {@link SceneModelEntity#visible} is ````true```` and {@link SceneModelEntity#culled} is ````false````. - * - * When {@link SceneModelEntity#isObject} and {@link SceneModelEntity#visible} are - * both ````true```` the SceneModelEntity will be - * registered by {@link SceneModelEntity#id} in {@link Scene#visibleObjects}. - * - * @type {Boolean} - */ - set visible(visible) { - if (!!(this._flags & ENTITY_FLAGS.VISIBLE) === visible) { - return; // Redundant update - } - if (visible) { - this._flags = this._flags | ENTITY_FLAGS.VISIBLE; - } else { - this._flags = this._flags & ~ENTITY_FLAGS.VISIBLE; - } - for (let i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._setVisible(this._flags); - } - if (this._isObject) { - this.model.scene._objectVisibilityUpdated(this); - } - this.model.glRedraw(); - } - - /** - * Gets if this SceneModelEntity is highlighted. - * - * When {@link SceneModelEntity#isObject} and {@link SceneModelEntity#highlighted} are both ````true```` the SceneModelEntity will be - * registered by {@link SceneModelEntity#id} in {@link Scene#highlightedObjects}. - * - * @type {Boolean} - */ - get highlighted() { - return this._getFlag(ENTITY_FLAGS.HIGHLIGHTED); - } - - /** - * Sets if this SceneModelEntity is highlighted. - * - * When {@link SceneModelEntity#isObject} and {@link SceneModelEntity#highlighted} are both ````true```` the SceneModelEntity will be - * registered by {@link SceneModelEntity#id} in {@link Scene#highlightedObjects}. - * - * @type {Boolean} - */ - set highlighted(highlighted) { - if (!!(this._flags & ENTITY_FLAGS.HIGHLIGHTED) === highlighted) { - return; // Redundant update - } - - if (highlighted) { - this._flags = this._flags | ENTITY_FLAGS.HIGHLIGHTED; - } else { - this._flags = this._flags & ~ENTITY_FLAGS.HIGHLIGHTED; - } - for (var i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._setHighlighted(this._flags); - } - if (this._isObject) { - this.model.scene._objectHighlightedUpdated(this); - } - this.model.glRedraw(); - } - - /** - * Gets if this SceneModelEntity is xrayed. - * - * When {@link SceneModelEntity#isObject} and {@link SceneModelEntity#xrayed} are both ````true``` the SceneModelEntity will be - * registered by {@link SceneModelEntity#id} in {@link Scene#xrayedObjects}. - * - * @type {Boolean} - */ - get xrayed() { - return this._getFlag(ENTITY_FLAGS.XRAYED); - } - - /** - * Sets if this SceneModelEntity is xrayed. - * - * When {@link SceneModelEntity#isObject} and {@link SceneModelEntity#xrayed} are both ````true``` the SceneModelEntity will be - * registered by {@link SceneModelEntity#id} in {@link Scene#xrayedObjects}. - * - * @type {Boolean} - */ - set xrayed(xrayed) { - if (!!(this._flags & ENTITY_FLAGS.XRAYED) === xrayed) { - return; // Redundant update - } - if (xrayed) { - this._flags = this._flags | ENTITY_FLAGS.XRAYED; - } else { - this._flags = this._flags & ~ENTITY_FLAGS.XRAYED; - } - for (let i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._setXRayed(this._flags); - } - if (this._isObject) { - this.model.scene._objectXRayedUpdated(this); - } - this.model.glRedraw(); - } - - /** - * Gets if this SceneModelEntity is selected. - * - * When {@link SceneModelEntity#isObject} and {@link SceneModelEntity#selected} are both ````true``` the SceneModelEntity will be - * registered by {@link SceneModelEntity#id} in {@link Scene#selectedObjects}. - * - * @type {Boolean} - */ - get selected() { - return this._getFlag(ENTITY_FLAGS.SELECTED); - } - - /** - * Gets if this SceneModelEntity is selected. - * - * When {@link SceneModelEntity#isObject} and {@link SceneModelEntity#selected} are both ````true``` the SceneModelEntity will be - * registered by {@link SceneModelEntity#id} in {@link Scene#selectedObjects}. - * - * @type {Boolean} - */ - set selected(selected) { - if (!!(this._flags & ENTITY_FLAGS.SELECTED) === selected) { - return; // Redundant update - } - if (selected) { - this._flags = this._flags | ENTITY_FLAGS.SELECTED; - } else { - this._flags = this._flags & ~ENTITY_FLAGS.SELECTED; - } - for (let i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._setSelected(this._flags); - } - if (this._isObject) { - this.model.scene._objectSelectedUpdated(this); - } - this.model.glRedraw(); - } - - /** - * Gets if this SceneModelEntity's edges are enhanced. - * - * @type {Boolean} - */ - get edges() { - return this._getFlag(ENTITY_FLAGS.EDGES); - } - - /** - * Sets if this SceneModelEntity's edges are enhanced. - * - * @type {Boolean} - */ - set edges(edges) { - if (!!(this._flags & ENTITY_FLAGS.EDGES) === edges) { - return; // Redundant update - } - if (edges) { - this._flags = this._flags | ENTITY_FLAGS.EDGES; - } else { - this._flags = this._flags & ~ENTITY_FLAGS.EDGES; - } - for (var i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._setEdges(this._flags); - } - this.model.glRedraw(); - } - - - get culledVFC() { - return !!(this._culledVFC); - } - - set culledVFC(culled) { - this._culledVFC = culled; - this._setCulled(); - } - - get culledLOD() { - return !!(this._culledLOD); - } - - set culledLOD(culled) { - this._culledLOD = culled; - this._setCulled(); - } - - /** - * Gets if this SceneModelEntity is culled. - * - * Only rendered when {@link SceneModelEntity#visible} is ````true```` and {@link SceneModelEntity#culled} is ````false````. - * - * @type {Boolean} - */ - get culled() { - return !!(this._culled); - // return this._getFlag(ENTITY_FLAGS.CULLED); - } - - /** - * Sets if this SceneModelEntity is culled. - * - * Only rendered when {@link SceneModelEntity#visible} is ````true```` and {@link SceneModelEntity#culled} is ````false````. - * - * @type {Boolean} - */ - set culled(culled) { - this._culled = culled; - this._setCulled(); - } - - _setCulled() { - let culled = !!(this._culled) || !!(this._culledLOD && this._lodCullable) || !!(this._culledVFC); - if (!!(this._flags & ENTITY_FLAGS.CULLED) === culled) { - return; // Redundant update - } - if (culled) { - this._flags = this._flags | ENTITY_FLAGS.CULLED; - } else { - this._flags = this._flags & ~ENTITY_FLAGS.CULLED; - } - for (var i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._setCulled(this._flags); - } - this.model.glRedraw(); - } - - /** - * Gets if this SceneModelEntity is clippable. - * - * Clipping is done by the {@link SectionPlane}s in {@link Scene#sectionPlanes}. - * - * @type {Boolean} - */ - get clippable() { - return this._getFlag(ENTITY_FLAGS.CLIPPABLE); - } - - /** - * Sets if this SceneModelEntity is clippable. - * - * Clipping is done by the {@link SectionPlane}s in {@link Scene#sectionPlanes}. - * - * @type {Boolean} - */ - set clippable(clippable) { - if ((!!(this._flags & ENTITY_FLAGS.CLIPPABLE)) === clippable) { - return; // Redundant update - } - if (clippable) { - this._flags = this._flags | ENTITY_FLAGS.CLIPPABLE; - } else { - this._flags = this._flags & ~ENTITY_FLAGS.CLIPPABLE; - } - for (var i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._setClippable(this._flags); - } - this.model.glRedraw(); - } - - /** - * Gets if this SceneModelEntity is included in boundary calculations. - * - * @type {Boolean} - */ - get collidable() { - return this._getFlag(ENTITY_FLAGS.COLLIDABLE); - } - - /** - * Sets if this SceneModelEntity is included in boundary calculations. - * - * @type {Boolean} - */ - set collidable(collidable) { - if (!!(this._flags & ENTITY_FLAGS.COLLIDABLE) === collidable) { - return; // Redundant update - } - if (collidable) { - this._flags = this._flags | ENTITY_FLAGS.COLLIDABLE; - } else { - this._flags = this._flags & ~ENTITY_FLAGS.COLLIDABLE; - } - for (var i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._setCollidable(this._flags); - } - } - - /** - * Gets if this SceneModelEntity is pickable. - * - * Picking is done via calls to {@link Scene#pick}. - * - * @type {Boolean} - */ - get pickable() { - return this._getFlag(ENTITY_FLAGS.PICKABLE); - } - - /** - * Sets if this SceneModelEntity is pickable. - * - * Picking is done via calls to {@link Scene#pick}. - * - * @type {Boolean} - */ - set pickable(pickable) { - if (!!(this._flags & ENTITY_FLAGS.PICKABLE) === pickable) { - return; // Redundant update - } - if (pickable) { - this._flags = this._flags | ENTITY_FLAGS.PICKABLE; - } else { - this._flags = this._flags & ~ENTITY_FLAGS.PICKABLE; - } - for (var i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._setPickable(this._flags); - } - } - - /** - * Gets the SceneModelEntity's RGB colorize color, multiplies by the SceneModelEntity's rendered fragment colors. - * - * Each element of the color is in range ````[0..1]````. - * - * @type {Number[]} - */ - get colorize() { // [0..1, 0..1, 0..1] - if (this.meshes.length === 0) { - return null; - } - const colorize = this.meshes[0]._colorize; - tempFloatRGB[0] = colorize[0] / 255.0; // Unquantize - tempFloatRGB[1] = colorize[1] / 255.0; - tempFloatRGB[2] = colorize[2] / 255.0; - return tempFloatRGB; - } - - /** - * Sets the SceneModelEntity's RGB colorize color, multiplies by the SceneModelEntity's rendered fragment colors. - * - * Each element of the color is in range ````[0..1]````. - * - * @type {Number[]} - */ - set colorize(color) { // [0..1, 0..1, 0..1] - if (color) { - tempIntRGB[0] = Math.floor(color[0] * 255.0); // Quantize - tempIntRGB[1] = Math.floor(color[1] * 255.0); - tempIntRGB[2] = Math.floor(color[2] * 255.0); - for (let i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._setColorize(tempIntRGB); - } - } else { - for (let i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._setColorize(null); - } - } - if (this._isObject) { - const colorized = (!!color); - this.scene._objectColorizeUpdated(this, colorized); - this._colorizeUpdated = colorized; - } - this.model.glRedraw(); - } - - /** - * Gets the SceneModelEntity's opacity factor. - * - * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas. - * - * @type {Number} - */ - get opacity() { - if (this.meshes.length > 0) { - return (this.meshes[0]._colorize[3] / 255.0); - } else { - return 1.0; - } - } - - /** - * Sets the SceneModelEntity's opacity factor. - * - * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas. - * - * @type {Number} - */ - set opacity(opacity) { - if (this.meshes.length === 0) { - return; - } - const opacityUpdated = (opacity !== null && opacity !== undefined); - const lastOpacityQuantized = this.meshes[0]._colorize[3]; - let opacityQuantized = 255; - if (opacityUpdated) { - if (opacity < 0) { - opacity = 0; - } else if (opacity > 1) { - opacity = 1; - } - opacityQuantized = Math.floor(opacity * 255.0); // Quantize - if (lastOpacityQuantized === opacityQuantized) { - return; - } - } else { - opacityQuantized = 255.0; - if (lastOpacityQuantized === opacityQuantized) { - return; - } - } - for (let i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._setOpacity(opacityQuantized, this._flags); - } - if (this._isObject) { - this.scene._objectOpacityUpdated(this, opacityUpdated); - this._opacityUpdated = opacityUpdated; - } - this.model.glRedraw(); - } - - /** - * Gets the SceneModelEntity's 3D World-space offset. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - get offset() { - return this._offset; - } - - /** - * Sets the SceneModelEntity's 3D World-space offset. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - set offset(offset) { - if (offset) { - this._offset[0] = offset[0]; - this._offset[1] = offset[1]; - this._offset[2] = offset[2]; - } else { - this._offset[0] = 0; - this._offset[1] = 0; - this._offset[2] = 0; - } - for (let i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._setOffset(this._offset); - } - this._aabbDirty = true; - this.model._aabbDirty = true; - this.scene._aabbDirty = true; - this.scene._objectOffsetUpdated(this, offset); - this.model.glRedraw(); - } - - get saoEnabled() { - return this.model.saoEnabled; - } - - /** - * Sets the SceneModelEntity's capMaterial that will be used on the caps generated when this entity is sliced - * - * Default value is ````null````. - * - * @type {Material} - */ - set capMaterial(value) { - if (this.scene.readableGeometryEnabled) { - this._capMaterial = value; - this.scene._sectionCaps._onCapMaterialUpdated(this); - } else { - throw "The `capMaterial` assignment requires `Viewer::readableGeometryEnabled` to be `true`"; - } - } - - /** - * Gets the SceneModelEntity's capMaterial. - * - * Default value is ````null````. - * - * @type {Material} - */ - get capMaterial() { - return this._capMaterial; - } - - getEachVertex(callback) { - for (let i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i].getEachVertex(callback); - } - } - - getEachIndex(callback) { - for (let i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i].getEachIndex(callback); - } - } - - getGeometryData() { - let positionsBase = 0; - const positions = []; - const indices = []; - - for (let i = 0, len = this.meshes.length; i < len; i++) { - const mesh = this.meshes[i]; - - if (mesh.layer.readGeometryData) { - const meshGeom = mesh.layer.readGeometryData(mesh.portionId); - - for (let j = 0, len = meshGeom.indices.length; j < len; j++) { - indices.push(meshGeom.indices[j]+positionsBase); - } - - for (let j = 0, len = meshGeom.positions.length; j < len; j++) { - positions.push(meshGeom.positions[j]); - } - - positionsBase += meshGeom.positions.length / 3; - } - } - - return { indices, positions }; - } - - /** - * Returns the volume of this SceneModelEntity. - * - * Only works when {@link Scene.readableGeometryEnabled | Scene.readableGeometryEnabled} is `true` and the - * SceneModelEntity contains solid triangle meshes; returns `0` otherwise. - * - * @returns {number} - */ - get volume() { - let volume = 0; - for (let i = 0, len = this.meshes.length; i < len; i++) { - const meshVolume = this.meshes[i].volume; - if (meshVolume < 0) { - return -1; - } - volume += meshVolume; - } - return volume; - } - - /** - * Returns the surface area of this SceneModelEntity. - * - * Only works when {@link Scene.readableGeometryEnabled | Scene.readableGeometryEnabled} is `true` and the - * SceneModelEntity contains triangle meshes; returns `0` otherwise. - * - * @returns {number} - */ - get surfaceArea() { - let surfaceArea = 0; - for (let i = 0, len = this.meshes.length; i < len; i++) { - const meshSurfaceArea = this.meshes[i].surfaceArea; - if (meshSurfaceArea >= 0) { - surfaceArea += meshSurfaceArea; - } - } - return surfaceArea > 0 ? surfaceArea : -1; - } - - _getFlag(flag) { - return !!(this._flags & flag); - } - - _finalize() { - const scene = this.model.scene; - if (this._isObject) { - if (this.visible) { - scene._objectVisibilityUpdated(this); - } - if (this.highlighted) { - scene._objectHighlightedUpdated(this); - } - if (this.xrayed) { - scene._objectXRayedUpdated(this); - } - if (this.selected) { - scene._objectSelectedUpdated(this); - } - } - for (let i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._finalize(this._flags); - } - } - - _finalize2() { - for (let i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._finalize2(); - } - } - - _destroy() { - const scene = this.model.scene; - if (this._isObject) { - scene._deregisterObject(this); - if (this.visible) { - scene._deRegisterVisibleObject(this); - } - if (this.xrayed) { - scene._deRegisterXRayedObject(this); - } - if (this.selected) { - scene._deRegisterSelectedObject(this); - } - if (this.highlighted) { - scene._deRegisterHighlightedObject(this); - } - if (this._colorizeUpdated) { - this.scene._deRegisterColorizedObject(this); - } - if (this._opacityUpdated) { - this.scene._deRegisterOpacityObject(this); - } - if (this._offset && (this._offset[0] !== 0 || this._offset[1] !== 0 || this._offset[2] !== 0)) { - this.scene._deRegisterOffsetObject(this); - } - } - for (let i = 0, len = this.meshes.length; i < len; i++) { - this.meshes[i]._destroy(); - } - scene._aabbDirty = true; - } -} - -const angleAxis = math.vec4(4); -const q1 = math.vec4(); -const q2 = math.vec4(); -const xAxis = math.vec3([1, 0, 0]); -const yAxis = math.vec3([0, 1, 0]); -const zAxis = math.vec3([0, 0, 1]); - -math.vec3(3); -math.vec3(3); - -const identityMat = math.identityMat4(); - -/** - * A dynamically-updatable transform within a {@link SceneModel}. - * - * * Can be composed into hierarchies - * * Shared by multiple {@link SceneModelMesh}es - * * Created with {@link SceneModel#createTransform} - * * Stored by ID in {@link SceneModel#transforms} - * * Referenced by {@link SceneModelMesh#transform} - */ -class SceneModelTransform { - - /** - * @private - */ - constructor(cfg) { - this._model = cfg.model; - - /** - * Unique ID of this SceneModelTransform. - * - * The SceneModelTransform is registered against this ID in {@link SceneModel#transforms}. - */ - this.id = cfg.id; - - this._parentTransform = cfg.parent; - this._childTransforms = []; - this._meshes = []; - this._scale = new Float32Array([1,1,1]); - this._quaternion = math.identityQuaternion(new Float32Array(4)); - this._rotation = new Float32Array(3); - this._position = new Float32Array(3); - this._localMatrix = math.identityMat4(new Float32Array(16)); - this._worldMatrix = math.identityMat4(new Float32Array(16)); - this._localMatrixDirty = true; - this._worldMatrixDirty = true; - - if (cfg.matrix) { - this.matrix = cfg.matrix; - } else { - this.scale = cfg.scale; - this.position = cfg.position; - if (cfg.quaternion) ; else { - this.rotation = cfg.rotation; - } - } - if (cfg.parent) { - cfg.parent._addChildTransform(this); - } - } - - _addChildTransform(childTransform) { - this._childTransforms.push(childTransform); - childTransform._parentTransform = this; - childTransform._transformDirty(); - childTransform._setSubtreeAABBsDirty(this); - } - - _addMesh(mesh) { - this._meshes.push(mesh); - mesh.transform = this; - // childTransform._setWorldMatrixDirty(); - // childTransform._setAABBDirty(); - } - - /** - * The optional parent SceneModelTransform. - * - * @type {SceneModelTransform} - */ - get parentTransform() { - return this._parentTransform; - } - - /** - * The {@link SceneModelMesh}es transformed by this SceneModelTransform. - * - * @returns {[]} - */ - get meshes() { - return this._meshes; - } - - /** - * Sets the SceneModelTransform's local translation. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - set position(value) { - this._position.set(value || [0, 0, 0]); - this._setLocalMatrixDirty(); - this._model.glRedraw(); - } - - /** - * Gets the SceneModelTransform's translation. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - get position() { - return this._position; - } - - /** - * Sets the SceneModelTransform's rotation, as Euler angles given in degrees, for each of the X, Y and Z axis. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - set rotation(value) { - this._rotation.set(value || [0, 0, 0]); - math.eulerToQuaternion(this._rotation, "XYZ", this._quaternion); - this._setLocalMatrixDirty(); - this._model.glRedraw(); - } - - /** - * Gets the SceneModelTransform's rotation, as Euler angles given in degrees, for each of the X, Y and Z axis. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - get rotation() { - return this._rotation; - } - - /** - * Sets the SceneModelTransform's rotation quaternion. - * - * Default value is ````[0,0,0,1]````. - * - * @type {Number[]} - */ - set quaternion(value) { - this._quaternion.set(value || [0, 0, 0, 1]); - math.quaternionToEuler(this._quaternion, "XYZ", this._rotation); - this._setLocalMatrixDirty(); - this._model.glRedraw(); - } - - /** - * Gets the SceneModelTransform's rotation quaternion. - * - * Default value is ````[0,0,0,1]````. - * - * @type {Number[]} - */ - get quaternion() { - return this._quaternion; - } - - /** - * Sets the SceneModelTransform's scale. - * - * Default value is ````[1,1,1]````. - * - * @type {Number[]} - */ - set scale(value) { - this._scale.set(value || [1, 1, 1]); - this._setLocalMatrixDirty(); - this._model.glRedraw(); - } - - /** - * Gets the SceneModelTransform's scale. - * - * Default value is ````[1,1,1]````. - * - * @type {Number[]} - */ - get scale() { - return this._scale; - } - - /** - * Sets the SceneModelTransform's transform matrix. - * - * Default value is ````[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]````. - * - * @type {Number[]} - */ - set matrix(value) { - if (!this._localMatrix) { - this._localMatrix = math.identityMat4(); - } - this._localMatrix.set(value || identityMat); - math.decomposeMat4(this._localMatrix, this._position, this._quaternion, this._scale); - this._localMatrixDirty = false; - this._transformDirty(); - this._model.glRedraw(); - } - - /** - * Gets the SceneModelTransform's transform matrix. - * - * Default value is ````[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]````. - * - * @type {Number[]} - */ - get matrix() { - if (this._localMatrixDirty) { - if (!this._localMatrix) { - this._localMatrix = math.identityMat4(); - } - math.composeMat4(this._position, this._quaternion, this._scale, this._localMatrix); - this._localMatrixDirty = false; - } - return this._localMatrix; - } - - /** - * Gets the SceneModelTransform's World matrix. - * - * @property worldMatrix - * @type {Number[]} - */ - get worldMatrix() { - if (this._worldMatrixDirty) { - this._buildWorldMatrix(); - } - return this._worldMatrix; - } - - /** - * Rotates the SceneModelTransform about the given axis by the given increment. - * - * @param {Number[]} axis Local axis about which to rotate. - * @param {Number} angle Angle increment in degrees. - */ - rotate(axis, angle) { - angleAxis[0] = axis[0]; - angleAxis[1] = axis[1]; - angleAxis[2] = axis[2]; - angleAxis[3] = angle * math.DEGTORAD; - math.angleAxisToQuaternion(angleAxis, q1); - math.mulQuaternions(this.quaternion, q1, q2); - this.quaternion = q2; - this._setLocalMatrixDirty(); - this._model.glRedraw(); - return this; - } - - /** - * Rotates the SceneModelTransform about the given World-space axis by the given increment. - * - * @param {Number[]} axis Local axis about which to rotate. - * @param {Number} angle Angle increment in degrees. - */ - rotateOnWorldAxis(axis, angle) { - angleAxis[0] = axis[0]; - angleAxis[1] = axis[1]; - angleAxis[2] = axis[2]; - angleAxis[3] = angle * math.DEGTORAD; - math.angleAxisToQuaternion(angleAxis, q1); - math.mulQuaternions(q1, this.quaternion, q1); - //this.quaternion.premultiply(q1); - return this; - } - - /** - * Rotates the SceneModelTransform about the local X-axis by the given increment. - * - * @param {Number} angle Angle increment in degrees. - */ - rotateX(angle) { - return this.rotate(xAxis, angle); - } - - /** - * Rotates the SceneModelTransform about the local Y-axis by the given increment. - * - * @param {Number} angle Angle increment in degrees. - */ - rotateY(angle) { - return this.rotate(yAxis, angle); - } - - /** - * Rotates the SceneModelTransform about the local Z-axis by the given increment. - * - * @param {Number} angle Angle increment in degrees. - */ - rotateZ(angle) { - return this.rotate(zAxis, angle); - } - - /** - * Translates the SceneModelTransform along the local axis by the given increment. - * - * @param {Number[]} axis Normalized local space 3D vector along which to translate. - * @param {Number} distance Distance to translate along the vector. - */ - translate(axis) { - this._position[0] += axis[0]; - this._position[1] += axis[1]; - this._position[2] += axis[2]; - this._setLocalMatrixDirty(); - this._model.glRedraw(); - return this; - } - - /** - * Translates the SceneModelTransform along the local X-axis by the given increment. - * - * @param {Number} distance Distance to translate along the X-axis. - */ - translateX(distance) { - this._position[0] += distance; - this._setLocalMatrixDirty(); - this._model.glRedraw(); - return this; - } - - /** - * Translates the SceneModelTransform along the local Y-axis by the given increment. - * - * @param {Number} distance Distance to translate along the Y-axis. - */ - translateY(distance) { - this._position[1] += distance; - this._setLocalMatrixDirty(); - this._model.glRedraw(); - return this; - } - - /** - * Translates the SceneModelTransform along the local Z-axis by the given increment. - * - * @param {Number} distance Distance to translate along the Z-axis. - */ - translateZ(distance) { - this._position[2] += distance; - this._setLocalMatrixDirty(); - this._model.glRedraw(); - return this; - } - - _setLocalMatrixDirty() { - this._localMatrixDirty = true; - this._transformDirty(); - } - - _transformDirty() { - this._worldMatrixDirty = true; - for (let i = 0, len = this._childTransforms.length; i < len; i++) { - const childTransform = this._childTransforms[i]; - childTransform._transformDirty(); - if (childTransform._meshes && childTransform._meshes.length > 0) { - const meshes = childTransform._meshes; - for (let j =0, lenj = meshes.length; j < lenj; j++) { - meshes[j]._transformDirty(); - } - } - } - if (this._meshes && this._meshes.length > 0) { - const meshes = this._meshes; - for (let j =0, lenj = meshes.length; j < lenj; j++) { - meshes[j]._transformDirty(); - } - } - } - - _buildWorldMatrix() { - const localMatrix = this.matrix; - if (!this._parentTransform) { - for (let i = 0, len = localMatrix.length; i < len; i++) { - this._worldMatrix[i] = localMatrix[i]; - } - } else { - math.mulMat4(this._parentTransform.worldMatrix, localMatrix, this._worldMatrix); - } - this._worldMatrixDirty = false; - } - - _setSubtreeAABBsDirty(sceneTransform) { - sceneTransform._aabbDirty = true; - if (sceneTransform._childTransforms) { - for (let i = 0, len = sceneTransform._childTransforms.length; i < len; i++) { - this._setSubtreeAABBsDirty(sceneTransform._childTransforms[i]); - } - } - } -} - -const tempVec3a$c = math.vec3(); - -const tempOBB3 = math.OBB3(); -const tempQuaternion = math.vec4(); - -const DEFAULT_SCALE = math.vec3([1, 1, 1]); -const DEFAULT_POSITION = math.vec3([0, 0, 0]); -math.vec3([0, 0, 0]); -const DEFAULT_QUATERNION = math.identityQuaternion(); -const DEFAULT_MATRIX = math.identityMat4(); - -const DEFAULT_COLOR_TEXTURE_ID = "defaultColorTexture"; -const DEFAULT_METAL_ROUGH_TEXTURE_ID = "defaultMetalRoughTexture"; -const DEFAULT_NORMALS_TEXTURE_ID = "defaultNormalsTexture"; -const DEFAULT_EMISSIVE_TEXTURE_ID = "defaultEmissiveTexture"; -const DEFAULT_OCCLUSION_TEXTURE_ID = "defaultOcclusionTexture"; -const DEFAULT_TEXTURE_SET_ID = "defaultTextureSet"; - -const defaultCompressedColor = new Uint8Array([255, 255, 255]); - -const VBO_INSTANCED = 0; -const VBO_BATCHED = 1; -const DTX = 2; - -/** - * @desc A high-performance model representation for efficient rendering and low memory usage. - * - * # Examples - * - * Internally, SceneModel uses a combination of several different techniques to render and represent - * the different parts of a typical model. Each of the live examples at these links is designed to "unit test" one of these - * techniques, in isolation. If some bug occurs in SceneModel, we use these tests to debug, but they also - * serve to demonstrate how to use the capabilities of SceneModel programmatically. - * - * * [Loading building models into SceneModels](/examples/buildings) - * * [Loading city models into SceneModels](/examples/cities) - * * [Loading LiDAR scans into SceneModels](/examples/lidar) - * * [Loading CAD models into SceneModels](/examples/cad) - * * [SceneModel feature tests](/examples/scenemodel) - * - * # Overview - * - * While xeokit's standard [scene graph](https://github.com/xeokit/xeokit-sdk/wiki/Scene-Graphs) is great for gizmos and medium-sized models, it doesn't scale up to millions of objects in terms of memory and rendering efficiency. - * - * For huge models, we have the ````SceneModel```` representation, which is optimized to pack large amounts of geometry into memory and render it efficiently using WebGL. - * - * ````SceneModel```` is the default model representation loaded by (at least) {@link GLTFLoaderPlugin}, {@link XKTLoaderPlugin} and {@link WebIFCLoaderPlugin}. - * - * In this tutorial you'll learn how to use ````SceneModel```` to create high-detail content programmatically. Ordinarily you'd be learning about ````SceneModel```` if you were writing your own model loader plugins. - * - * # Contents - * - * - [SceneModel](#DataTextureSceneModel) - * - [GPU-Resident Geometry](#gpu-resident-geometry) - * - [Picking](#picking) - * - [Example 1: Geometry Instancing](#example-1--geometry-instancing) - * - [Finalizing a SceneModel](#finalizing-a-DataTextureSceneModel) - * - [Finding Entities](#finding-entities) - * - [Example 2: Geometry Batching](#example-2--geometry-batching) - * - [Classifying with Metadata](#classifying-with-metadata) - * - [Querying Metadata](#querying-metadata) - * - [Metadata Structure](#metadata-structure) - * - [RTC Coordinates](#rtc-coordinates-for-double-precision) - * - [Example 3: RTC Coordinates with Geometry Instancing](#example-2--rtc-coordinates-with-geometry-instancing) - * - [Example 4: RTC Coordinates with Geometry Batching](#example-2--rtc-coordinates-with-geometry-batching) - * - * ## SceneModel - * - * ````SceneModel```` uses two rendering techniques internally: - * - * 1. ***Geometry batching*** for unique geometries, combining those into a single WebGL geometry buffer, to render in one draw call, and - * 2. ***geometry instancing*** for geometries that are shared by multiple meshes, rendering all instances of each shared geometry in one draw call. - * - *
- * These techniques come with certain limitations: - * - * * Non-realistic rendering - while scene graphs can use xeokit's full set of material workflows, ````SceneModel```` uses simple Lambertian shading without textures. - * * Static transforms - transforms within a ````SceneModel```` are static and cannot be dynamically translated, rotated and scaled the way {@link Node}s and {@link Mesh}es in scene graphs can. - * * Immutable model representation - while scene graph {@link Node}s and - * {@link Mesh}es can be dynamically plugged together, ````SceneModel```` is immutable, - * since it packs its geometries into buffers and instanced arrays. - * - * ````SceneModel````'s API allows us to exploit batching and instancing, while exposing its elements as - * abstract {@link Entity} types. - * - * {@link Entity} is the abstract base class for - * the various xeokit components that represent models, objects, or anonymous visible elements. An Entity has a unique ID and can be - * individually shown, hidden, selected, highlighted, ghosted, culled, picked and clipped, and has its own World-space boundary. - * - * * A ````SceneModel```` is an {@link Entity} that represents a model. - * * A ````SceneModel```` represents each of its objects with an {@link Entity}. - * * Each {@link Entity} has one or more meshes that define its shape. - * * Each mesh has either its own unique geometry, or shares a geometry with other meshes. - * - * ## GPU-Resident Geometry - * - * For a low memory footprint, ````SceneModel```` stores its geometries in GPU memory only, compressed (quantized) as integers. Unfortunately, GPU-resident geometry is - * not readable by JavaScript. - * - * - * ## Example 1: Geometry Instancing - * - * In the example below, we'll use a ````SceneModel```` - * to build a simple table model using geometry instancing. - * - * We'll start by adding a reusable box-shaped geometry to our ````SceneModel````. - * - * Then, for each object in our model we'll add an {@link Entity} - * that has a mesh that instances our box geometry, transforming and coloring the instance. - * - * [![](http://xeokit.io/img/docs/sceneGraph.png)](https://xeokit.github.io/xeokit-sdk/examples/index.html#sceneRepresentation_SceneModel_instancing) - * - * ````javascript - * import {Viewer, SceneModel} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.scene.camera.eye = [-21.80, 4.01, 6.56]; - * viewer.scene.camera.look = [0, -5.75, 0]; - * viewer.scene.camera.up = [0.37, 0.91, -0.11]; - * - * // Build a SceneModel representing a table - * // with four legs, using geometry instancing - * - * const sceneModel = new SceneModel(viewer.scene, { - * id: "table", - * isModel: true, // <--- Registers SceneModel in viewer.scene.models - * position: [0, 0, 0], - * scale: [1, 1, 1], - * rotation: [0, 0, 0] - * }); - * - * // Create a reusable geometry within the SceneModel - * // We'll instance this geometry by five meshes - * - * sceneModel.createGeometry({ - * - * id: "myBoxGeometry", - * - * // The primitive type - allowed values are "points", "lines" and "triangles". - * // See the OpenGL/WebGL specification docs - * // for how the coordinate arrays are supposed to be laid out. - * primitive: "triangles", - * - * // The vertices - eight for our cube, each - * // one spanning three array elements for X,Y and Z - * positions: [ - * 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, // v0-v1-v2-v3 front - * 1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, // v0-v3-v4-v1 right - * 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1, // v0-v1-v6-v1 top - * -1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, // v1-v6-v7-v2 left - * -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, // v7-v4-v3-v2 bottom - * 1, -1, -1, -1, -1, -1, -1, 1, -1, 1, 1, -1 // v4-v7-v6-v1 back - * ], - * - * // Normal vectors, one for each vertex - * normals: [ - * 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0-v1-v2-v3 front - * 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v0-v3-v4-v5 right - * 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v0-v5-v6-v1 top - * -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // v1-v6-v7-v2 left - * 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, // v7-v4-v3-v2 bottom - * 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1 // v4-v7-v6-v5 back - * ], - * - * // Indices - these organise the positions and and normals - * // into geometric primitives in accordance with the "primitive" parameter, - * // in this case a set of three indices for each triangle. - * // - * // Note that each triangle is specified in counter-clockwise winding order. - * // - * indices: [ - * 0, 1, 2, 0, 2, 3, // front - * 4, 5, 6, 4, 6, 7, // right - * 8, 9, 10, 8, 10, 11, // top - * 12, 13, 14, 12, 14, 15, // left - * 16, 17, 18, 16, 18, 19, // bottom - * 20, 21, 22, 20, 22, 23 - * ] - * }); - * - * // Red table leg - * - * sceneModel.createMesh({ - * id: "redLegMesh", - * geometryId: "myBoxGeometry", - * position: [-4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [1, 0.3, 0.3] - * }); - * - * sceneModel.createEntity({ - * id: "redLeg", - * meshIds: ["redLegMesh"], - * isObject: true // <---- Registers Entity by ID on viewer.scene.objects - * }); - * - * // Green table leg - * - * sceneModel.createMesh({ - * id: "greenLegMesh", - * geometryId: "myBoxGeometry", - * position: [4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [0.3, 1.0, 0.3] - * }); - * - * sceneModel.createEntity({ - * id: "greenLeg", - * meshIds: ["greenLegMesh"], - * isObject: true // <---- Registers Entity by ID on viewer.scene.objects - * }); - * - * // Blue table leg - * - * sceneModel.createMesh({ - * id: "blueLegMesh", - * geometryId: "myBoxGeometry", - * position: [4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [0.3, 0.3, 1.0] - * }); - * - * sceneModel.createEntity({ - * id: "blueLeg", - * meshIds: ["blueLegMesh"], - * isObject: true // <---- Registers Entity by ID on viewer.scene.objects - * }); - * - * // Yellow table leg - * - * sceneModel.createMesh({ - * id: "yellowLegMesh", - * geometryId: "myBoxGeometry", - * position: [-4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [1.0, 1.0, 0.0] - * }); - * - * sceneModel.createEntity({ - * id: "yellowLeg", - * meshIds: ["yellowLegMesh"], - * isObject: true // <---- Registers Entity by ID on viewer.scene.objects - * }); - * - * // Purple table top - * - * sceneModel.createMesh({ - * id: "purpleTableTopMesh", - * geometryId: "myBoxGeometry", - * position: [0, -3, 0], - * scale: [6, 0.5, 6], - * rotation: [0, 0, 0], - * color: [1.0, 0.3, 1.0] - * }); - * - * sceneModel.createEntity({ - * id: "purpleTableTop", - * meshIds: ["purpleTableTopMesh"], - * isObject: true // <---- Registers Entity by ID on viewer.scene.objects - * }); - * ```` - * - * ## Finalizing a SceneModel - * - * Before we can view and interact with our ````SceneModel````, we need to **finalize** it. Internally, this causes the ````SceneModel```` to build the - * vertex buffer objects (VBOs) that support our geometry instances. When using geometry batching (see next example), - * this causes ````SceneModel```` to build the VBOs that combine the batched geometries. Note that you can do both instancing and - * batching within the same ````SceneModel````. - * - * Once finalized, we can't add anything more to our ````SceneModel````. - * - * ```` javascript - * SceneModel.finalize(); - * ```` - * - * ## Finding Entities - * - * As mentioned earlier, {@link Entity} is - * the abstract base class for components that represent models, objects, or just - * anonymous visible elements. - * - * Since we created configured our ````SceneModel```` with ````isModel: true````, - * we're able to find it as an Entity by ID in ````viewer.scene.models````. Likewise, since - * we configured each of its Entities with ````isObject: true````, we're able to - * find them in ````viewer.scene.objects````. - * - * - * ````javascript - * // Get the whole table model Entity - * const table = viewer.scene.models["table"]; - * - * // Get some leg object Entities - * const redLeg = viewer.scene.objects["redLeg"]; - * const greenLeg = viewer.scene.objects["greenLeg"]; - * const blueLeg = viewer.scene.objects["blueLeg"]; - * ```` - * - * ## Example 2: Geometry Batching - * - * Let's once more use a ````SceneModel```` - * to build the simple table model, this time exploiting geometry batching. - * - * [![](http://xeokit.io/img/docs/sceneGraph.png)](https://xeokit.github.io/xeokit-sdk/examples/index.html#sceneRepresentation_SceneModel_batching) - * - * ````javascript - * import {Viewer, SceneModel} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.scene.camera.eye = [-21.80, 4.01, 6.56]; - * viewer.scene.camera.look = [0, -5.75, 0]; - * viewer.scene.camera.up = [0.37, 0.91, -0.11]; - * - * // Create a SceneModel representing a table with four legs, using geometry batching - * const sceneModel = new SceneModel(viewer.scene, { - * id: "table", - * isModel: true, // <--- Registers SceneModel in viewer.scene.models - * position: [0, 0, 0], - * scale: [1, 1, 1], - * rotation: [0, 0, 0] - * }); - * - * // Red table leg - * - * sceneModel.createMesh({ - * id: "redLegMesh", - * - * // Geometry arrays are same as for the earlier batching example - * primitive: "triangles", - * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ], - * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ], - * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ], - * position: [-4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [1, 0.3, 0.3] - * }); - * - * sceneModel.createEntity({ - * id: "redLeg", - * meshIds: ["redLegMesh"], - * isObject: true // <---- Registers Entity by ID on viewer.scene.objects - * }); - * - * // Green table leg - * - * sceneModel.createMesh({ - * id: "greenLegMesh", - * primitive: "triangles", - * primitive: "triangles", - * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ], - * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ], - * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ], - * position: [4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [0.3, 1.0, 0.3] - * }); - * - * sceneModel.createEntity({ - * id: "greenLeg", - * meshIds: ["greenLegMesh"], - * isObject: true // <---- Registers Entity by ID on viewer.scene.objects - * }); - * - * // Blue table leg - * - * sceneModel.createMesh({ - * id: "blueLegMesh", - * primitive: "triangles", - * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ], - * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ], - * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ], - * position: [4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [0.3, 0.3, 1.0] - * }); - * - * sceneModel.createEntity({ - * id: "blueLeg", - * meshIds: ["blueLegMesh"], - * isObject: true // <---- Registers Entity by ID on viewer.scene.objects - * }); - * - * // Yellow table leg object - * - * sceneModel.createMesh({ - * id: "yellowLegMesh", - * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ], - * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ], - * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ], - * position: [-4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [1.0, 1.0, 0.0] - * }); - * - * sceneModel.createEntity({ - * id: "yellowLeg", - * meshIds: ["yellowLegMesh"], - * isObject: true // <---- Registers Entity by ID on viewer.scene.objects - * }); - * - * // Purple table top - * - * sceneModel.createMesh({ - * id: "purpleTableTopMesh", - * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ], - * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ], - * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ], - * position: [0, -3, 0], - * scale: [6, 0.5, 6], - * rotation: [0, 0, 0], - * color: [1.0, 0.3, 1.0] - * }); - * - * sceneModel.createEntity({ - * id: "purpleTableTop", - * meshIds: ["purpleTableTopMesh"], - * isObject: true // <---- Registers Entity by ID on viewer.scene.objects - * }); - * - * // Finalize the SceneModel. - * - * SceneModel.finalize(); - * - * // Find BigModelNodes by their model and object IDs - * - * // Get the whole table model - * const table = viewer.scene.models["table"]; - * - * // Get some leg objects - * const redLeg = viewer.scene.objects["redLeg"]; - * const greenLeg = viewer.scene.objects["greenLeg"]; - * const blueLeg = viewer.scene.objects["blueLeg"]; - * ```` - * - * ## Classifying with Metadata - * - * In the previous examples, we used ````SceneModel```` to build - * two versions of the same table model, to demonstrate geometry batching and geometry instancing. - * - * We'll now classify our {@link Entity}s with metadata. This metadata - * will work the same for both our examples, since they create the exact same structure of {@link Entity}s - * to represent their models and objects. The abstract Entity type is, after all, intended to provide an abstract interface through which differently-implemented scene content can be accessed uniformly. - * - * To create the metadata, we'll create a {@link MetaModel} for our model, - * with a {@link MetaObject} for each of it's objects. The MetaModel and MetaObjects - * get the same IDs as the {@link Entity}s that represent their model and objects within our scene. - * - * ```` javascript - * const furnitureMetaModel = viewer.metaScene.createMetaModel("furniture", { // Creates a MetaModel in the MetaScene - * - * "projectId": "myTableProject", - * "revisionId": "V1.0", - * - * "metaObjects": [ - * { // Creates a MetaObject in the MetaModel - * "id": "table", - * "name": "Table", // Same ID as an object Entity - * "type": "furniture", // Arbitrary type, could be IFC type - * "properties": { // Arbitrary properties, could be IfcPropertySet - * "cost": "200" - * } - * }, - * { - * "id": "redLeg", - * "name": "Red table Leg", - * "type": "leg", - * "parent": "table", // References first MetaObject as parent - * "properties": { - * "material": "wood" - * } - * }, - * { - * "id": "greenLeg", // Node with corresponding id does not need to exist - * "name": "Green table leg", // and MetaObject does not need to exist for Node with an id - * "type": "leg", - * "parent": "table", - * "properties": { - * "material": "wood" - * } - * }, - * { - * "id": "blueLeg", - * "name": "Blue table leg", - * "type": "leg", - * "parent": "table", - * "properties": { - * "material": "wood" - * } - * }, - * { - * "id": "yellowLeg", - * "name": "Yellow table leg", - * "type": "leg", - * "parent": "table", - * "properties": { - * "material": "wood" - * } - * }, - * { - * "id": "tableTop", - * "name": "Purple table top", - * "type": "surface", - * "parent": "table", - * "properties": { - * "material": "formica", - * "width": "60", - * "depth": "60", - * "thickness": "5" - * } - * } - * ] - * }); - * ```` - * - * ## Querying Metadata - * - * Having created and classified our model (either the instancing or batching example), we can now find the {@link MetaModel} - * and {@link MetaObject}s using the IDs of their - * corresponding {@link Entity}s. - * - * ````JavaScript - * const furnitureMetaModel = scene.metaScene.metaModels["furniture"]; - * - * const redLegMetaObject = scene.metaScene.metaObjects["redLeg"]; - * ```` - * - * In the snippet below, we'll log metadata on each {@link Entity} we click on: - * - * ````JavaScript - * viewer.scene.input.on("mouseclicked", function (coords) { - * - * const hit = viewer.scene.pick({ - * canvasPos: coords - * }); - * - * if (hit) { - * const entity = hit.entity; - * const metaObject = viewer.metaScene.metaObjects[entity.id]; - * if (metaObject) { - * console.log(JSON.stringify(metaObject.getJSON(), null, "\t")); - * } - * } - * }); - * ```` - * - * ## Metadata Structure - * - * The {@link MetaModel} - * organizes its {@link MetaObject}s in - * a tree that describes their structural composition: - * - * ````JavaScript - * // Get metadata on the root object - * const tableMetaObject = furnitureMetaModel.rootMetaObject; - * - * // Get metadata on the leg objects - * const redLegMetaObject = tableMetaObject.children[0]; - * const greenLegMetaObject = tableMetaObject.children[1]; - * const blueLegMetaObject = tableMetaObject.children[2]; - * const yellowLegMetaObject = tableMetaObject.children[3]; - * ```` - * - * Given an {@link Entity}, we can find the object or model of which it is a part, or the objects that comprise it. We can also generate UI - * components from the metadata, such as the tree view demonstrated in [this demo](https://xeokit.github.io/xeokit-sdk/examples/index.html#BIMOffline_glTF_OTCConferenceCenter). - * - * This hierarchy allows us to express the hierarchical structure of a model while representing it in - * various ways in the 3D scene (such as with ````SceneModel````, which - * has a non-hierarchical scene representation). - * - * Note also that a {@link MetaObject} does not need to have a corresponding - * {@link Entity} and vice-versa. - * - * # RTC Coordinates for Double Precision - * - * ````SceneModel```` can emulate 64-bit precision on GPUs using relative-to-center (RTC) coordinates. - * - * Consider a model that contains many small objects, but with such large spatial extents that 32 bits of GPU precision (accurate to ~7 digits) will not be sufficient to render all of the the objects without jittering. - * - * To prevent jittering, we could spatially subdivide the objects into "tiles". Each tile would have a center position, and the positions of the objects within the tile would be relative to that center ("RTC coordinates"). - * - * While the center positions of the tiles would be 64-bit values, the object positions only need to be 32-bit. - * - * Internally, when rendering an object with RTC coordinates, xeokit first temporarily translates the camera viewing matrix by the object's tile's RTC center, on the CPU, using 64-bit math. - * - * Then xeokit loads the viewing matrix into its WebGL shaders, where math happens at 32-bit precision. Within the shaders, the matrix is effectively down-cast to 32-bit precision, and the object's 32-bit vertex positions are transformed by the matrix. - * - * We see no jittering, because with RTC a detectable loss of GPU accuracy only starts happening to objects as they become very distant from the camera viewpoint, at which point they are too small to be discernible anyway. - * - * ## RTC Coordinates with Geometry Instancing - * - * To use RTC with ````SceneModel```` geometry instancing, we specify an RTC center for the geometry via its ````origin```` parameter. Then ````SceneModel```` assumes that all meshes that instance that geometry are within the same RTC coordinate system, ie. the meshes ````position```` and ````rotation```` properties are assumed to be relative to the geometry's ````origin````. - * - * For simplicity, our example's meshes all instance the same geometry. Therefore, our example model has only one RTC center. - * - * Note that the axis-aligned World-space boundary (AABB) of our model is ````[ -6, -9, -6, 1000000006, -2.5, 1000000006]````. - * - * [![](http://xeokit.io/img/docs/sceneGraph.png)](https://xeokit.github.io/xeokit-sdk/examples/index.html#sceneRepresentation_SceneModel_batching) - * - * ````javascript - * const origin = [100000000, 0, 100000000]; - * - * sceneModel.createGeometry({ - * id: "box", - * primitive: "triangles", - * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ], - * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ], - * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ], - * }); - * - * sceneModel.createMesh({ - * id: "leg1", - * geometryId: "box", - * position: [-4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [1, 0.3, 0.3], - * origin: origin - * }); - * - * sceneModel.createEntity({ - * meshIds: ["leg1"], - * isObject: true - * }); - * - * sceneModel.createMesh({ - * id: "leg2", - * geometryId: "box", - * position: [4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [0.3, 1.0, 0.3], - * origin: origin - * }); - * - * sceneModel.createEntity({ - * meshIds: ["leg2"], - * isObject: true - * }); - * - * sceneModel.createMesh({ - * id: "leg3", - * geometryId: "box", - * position: [4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [0.3, 0.3, 1.0], - * origin: origin - * }); - * - * sceneModel.createEntity({ - * meshIds: ["leg3"], - * isObject: true - * }); - * - * sceneModel.createMesh({ - * id: "leg4", - * geometryId: "box", - * position: [-4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [1.0, 1.0, 0.0], - * origin: origin - * }); - * - * sceneModel.createEntity({ - * meshIds: ["leg4"], - * isObject: true - * }); - * - * sceneModel.createMesh({ - * id: "top", - * geometryId: "box", - * position: [0, -3, 0], - * scale: [6, 0.5, 6], - * rotation: [0, 0, 0], - * color: [1.0, 0.3, 1.0], - * origin: origin - * }); - * - * sceneModel.createEntity({ - * meshIds: ["top"], - * isObject: true - * }); - * ```` - * - * ## RTC Coordinates with Geometry Batching - * - * To use RTC with ````SceneModel```` geometry batching, we specify an RTC center (````origin````) for each mesh. For performance, we try to have as many meshes share the same value for ````origin```` as possible. Each mesh's ````positions````, ````position```` and ````rotation```` properties are assumed to be relative to ````origin````. - * - * For simplicity, the meshes in our example all share the same RTC center. - * - * The axis-aligned World-space boundary (AABB) of our model is ````[ -6, -9, -6, 1000000006, -2.5, 1000000006]````. - * - * [![](http://xeokit.io/img/docs/sceneGraph.png)](https://xeokit.github.io/xeokit-sdk/examples/index.html#sceneRepresentation_SceneModel_batching) - * - * ````javascript - * const origin = [100000000, 0, 100000000]; - * - * sceneModel.createMesh({ - * id: "leg1", - * origin: origin, // This mesh's positions and transforms are relative to the RTC center - * primitive: "triangles", - * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ], - * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ], - * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ], - * position: [-4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [1, 0.3, 0.3] - * }); - * - * sceneModel.createEntity({ - * meshIds: ["leg1"], - * isObject: true - * }); - * - * sceneModel.createMesh({ - * id: "leg2", - * origin: origin, // This mesh's positions and transforms are relative to the RTC center - * primitive: "triangles", - * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ], - * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ], - * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ], - * position: [4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [0.3, 1.0, 0.3] - * }); - * - * sceneModel.createEntity({ - * meshIds: ["leg2"], - * isObject: true - * }); - * - * sceneModel.createMesh({ - * id: "leg3", - * origin: origin, // This mesh's positions and transforms are relative to the RTC center - * primitive: "triangles", - * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ], - * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ], - * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ], - * position: [4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [0.3, 0.3, 1.0] - * }); - * - * sceneModel.createEntity({ - * meshIds: ["leg3"], - * isObject: true - * }); - * - * sceneModel.createMesh({ - * id: "leg4", - * origin: origin, // This mesh's positions and transforms are relative to the RTC center - * primitive: "triangles", - * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ], - * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ], - * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ], - * position: [-4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [1.0, 1.0, 0.0] - * }); - * - * sceneModel.createEntity({ - * meshIds: ["leg4"], - * isObject: true - * }); - * - * sceneModel.createMesh({ - * id: "top", - * origin: origin, // This mesh's positions and transforms are relative to the RTC center - * primitive: "triangles", - * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ], - * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ], - * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ], - * position: [0, -3, 0], - * scale: [6, 0.5, 6], - * rotation: [0, 0, 0], - * color: [1.0, 0.3, 1.0] - * }); - * - * sceneModel.createEntity({ - * meshIds: ["top"], - * isObject: true - * }); - * ```` - * - * ## Positioning at World-space coordinates - * - * To position a SceneModel at given double-precision World coordinates, we can - * configure the ````origin```` of the SceneModel itself. The ````origin```` is a double-precision - * 3D World-space position at which the SceneModel will be located. - * - * Note that ````position```` is a single-precision offset relative to ````origin````. - * - * ````javascript - * const origin = [100000000, 0, 100000000]; - * - * const sceneModel = new SceneModel(viewer.scene, { - * id: "table", - * isModel: true, - * origin: origin, // Everything in this SceneModel is relative to this RTC center - * position: [0, 0, 0], - * scale: [1, 1, 1], - * rotation: [0, 0, 0] - * }); - * - * sceneModel.createGeometry({ - * id: "box", - * primitive: "triangles", - * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ], - * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ], - * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ], - * }); - * - * sceneModel.createMesh({ - * id: "leg1", - * geometryId: "box", - * position: [-4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [1, 0.3, 0.3] - * }); - * - * sceneModel.createEntity({ - * meshIds: ["leg1"], - * isObject: true - * }); - * - * sceneModel.createMesh({ - * id: "leg2", - * geometryId: "box", - * position: [4, -6, -4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [0.3, 1.0, 0.3] - * }); - * - * sceneModel.createEntity({ - * meshIds: ["leg2"], - * isObject: true - * }); - * - * sceneModel.createMesh({ - * id: "leg3", - * geometryId: "box", - * position: [4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [0.3, 0.3, 1.0] - * }); - * - * sceneModel.createEntity({ - * meshIds: ["leg3"], - * isObject: true - * }); - * - * sceneModel.createMesh({ - * id: "leg4", - * geometryId: "box", - * position: [-4, -6, 4], - * scale: [1, 3, 1], - * rotation: [0, 0, 0], - * color: [1.0, 1.0, 0.0] - * }); - * - * sceneModel.createEntity({ - * meshIds: ["leg4"], - * isObject: true - * }); - * - * sceneModel.createMesh({ - * id: "top", - * geometryId: "box", - * position: [0, -3, 0], - * scale: [6, 0.5, 6], - * rotation: [0, 0, 0], - * color: [1.0, 0.3, 1.0] - * }); - * - * sceneModel.createEntity({ - * meshIds: ["top"], - * isObject: true - * }); - * ```` - * - * # Textures - * - * ## Loading KTX2 Texture Files into a SceneModel - * - * A {@link SceneModel} that is configured with a {@link KTX2TextureTranscoder} will - * allow us to load textures into it from KTX2 buffers or files. - * - * In the example below, we'll create a {@link Viewer}, containing a {@link SceneModel} configured with a - * {@link KTX2TextureTranscoder}. We'll then programmatically create a simple object within the SceneModel, consisting of - * a single mesh with a texture loaded from a KTX2 file, which our SceneModel internally transcodes, using - * its {@link KTX2TextureTranscoder}. Note how we configure our {@link KTX2TextureTranscoder} with a path to the Basis Universal - * transcoder WASM module. - * - * ````javascript - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.scene.camera.eye = [-21.80, 4.01, 6.56]; - * viewer.scene.camera.look = [0, -5.75, 0]; - * viewer.scene.camera.up = [0.37, 0.91, -0.11]; - * - * const textureTranscoder = new KTX2TextureTranscoder({ - * viewer, - * transcoderPath: "https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/" // <------ Path to BasisU transcoder module - * }); - * - * const sceneModel = new SceneModel(viewer.scene, { - * id: "myModel", - * textureTranscoder // <<-------------------- Configure model with our transcoder - * }); - * - * sceneModel.createTexture({ - * id: "myColorTexture", - * src: "../assets/textures/compressed/sample_uastc_zstd.ktx2" // <<----- KTX2 texture asset - * }); - * - * sceneModel.createTexture({ - * id: "myMetallicRoughnessTexture", - * src: "../assets/textures/alpha/crosshatchAlphaMap.jpg" // <<----- JPEG texture asset - * }); - * - * sceneModel.createTextureSet({ - * id: "myTextureSet", - * colorTextureId: "myColorTexture", - * metallicRoughnessTextureId: "myMetallicRoughnessTexture" - * }); - * - * sceneModel.createMesh({ - * id: "myMesh", - * textureSetId: "myTextureSet", - * primitive: "triangles", - * positions: [1, 1, 1, ...], - * normals: [0, 0, 1, 0, ...], - * uv: [1, 0, 0, ...], - * indices: [0, 1, 2, ...], - * }); - * - * sceneModel.createEntity({ - * id: "myEntity", - * meshIds: ["myMesh"] - * }); - * - * sceneModel.finalize(); - * ```` - * - * ## Loading KTX2 Textures from ArrayBuffers into a SceneModel - * - * A SceneModel that is configured with a {@link KTX2TextureTranscoder} will allow us to load textures into - * it from KTX2 ArrayBuffers. - * - * In the example below, we'll create a {@link Viewer}, containing a {@link SceneModel} configured with a - * {@link KTX2TextureTranscoder}. We'll then programmatically create a simple object within the SceneModel, consisting of - * a single mesh with a texture loaded from a KTX2 ArrayBuffer, which our SceneModel internally transcodes, using - * its {@link KTX2TextureTranscoder}. - * - * ````javascript - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.scene.camera.eye = [-21.80, 4.01, 6.56]; - * viewer.scene.camera.look = [0, -5.75, 0]; - * viewer.scene.camera.up = [0.37, 0.91, -0.11]; - * - * const textureTranscoder = new KTX2TextureTranscoder({ - * viewer, - * transcoderPath: "https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/" // <------ Path to BasisU transcoder module - * }); - * - * const sceneModel = new SceneModel(viewer.scene, { - * id: "myModel", - * textureTranscoder // <<-------------------- Configure model with our transcoder - * }); - * - * utils.loadArraybuffer("../assets/textures/compressed/sample_uastc_zstd.ktx2",(arrayBuffer) => { - * - * sceneModel.createTexture({ - * id: "myColorTexture", - * buffers: [arrayBuffer] // <<----- KTX2 texture asset - * }); - * - * sceneModel.createTexture({ - * id: "myMetallicRoughnessTexture", - * src: "../assets/textures/alpha/crosshatchAlphaMap.jpg" // <<----- JPEG texture asset - * }); - * - * sceneModel.createTextureSet({ - * id: "myTextureSet", - * colorTextureId: "myColorTexture", - * metallicRoughnessTextureId: "myMetallicRoughnessTexture" - * }); - * - * sceneModel.createMesh({ - * id: "myMesh", - * textureSetId: "myTextureSet", - * primitive: "triangles", - * positions: [1, 1, 1, ...], - * normals: [0, 0, 1, 0, ...], - * uv: [1, 0, 0, ...], - * indices: [0, 1, 2, ...], - * }); - * - * sceneModel.createEntity({ - * id: "myEntity", - * meshIds: ["myMesh"] - * }); - * - * sceneModel.finalize(); - * }); - * ```` - * - * @implements {Entity} - */ -class SceneModel extends Component { - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID, unique among all components in the parent scene, generated automatically when omitted. - * @param {Boolean} [cfg.isModel] Specify ````true```` if this SceneModel represents a model, in which case the SceneModel will be registered by {@link SceneModel#id} in {@link Scene#models} and may also have a corresponding {@link MetaModel} with matching {@link MetaModel#id}, registered by that ID in {@link MetaScene#metaModels}. - * @param {Number[]} [cfg.origin=[0,0,0]] World-space double-precision 3D origin. - * @param {Number[]} [cfg.position=[0,0,0]] Local, single-precision 3D position, relative to the origin parameter. - * @param {Number[]} [cfg.scale=[1,1,1]] Local scale. - * @param {Number[]} [cfg.rotation=[0,0,0]] Local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis. - * @param {Number[]} [cfg.matrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1] Local modelling transform matrix. Overrides the position, scale and rotation parameters. - * @param {Boolean} [cfg.visible=true] Indicates if the SceneModel is initially visible. - * @param {Boolean} [cfg.culled=false] Indicates if the SceneModel is initially culled from view. - * @param {Boolean} [cfg.pickable=true] Indicates if the SceneModel is initially pickable. - * @param {Boolean} [cfg.clippable=true] Indicates if the SceneModel is initially clippable. - * @param {Boolean} [cfg.collidable=true] Indicates if the SceneModel is initially included in boundary calculations. - * @param {Boolean} [cfg.xrayed=false] Indicates if the SceneModel is initially xrayed. - * @param {Boolean} [cfg.highlighted=false] Indicates if the SceneModel is initially highlighted. - * @param {Boolean} [cfg.selected=false] Indicates if the SceneModel is initially selected. - * @param {Boolean} [cfg.edges=false] Indicates if the SceneModel's edges are initially emphasized. - * @param {Number[]} [cfg.colorize=[1.0,1.0,1.0]] SceneModel's initial RGB colorize color, multiplies by the rendered fragment colors. - * @param {Number} [cfg.opacity=1.0] SceneModel's initial opacity factor, multiplies by the rendered fragment alpha. - * @param {Number} [cfg.backfaces=false] When we set this ````true````, then we force rendering of backfaces for this SceneModel. When - * we leave this ````false````, then we allow the Viewer to decide when to render backfaces. In that case, the - * Viewer will hide backfaces on watertight meshes, show backfaces on open meshes, and always show backfaces on meshes when we slice them open with {@link SectionPlane}s. - * @param {Boolean} [cfg.saoEnabled=true] Indicates if Scalable Ambient Obscurance (SAO) will apply to this SceneModel. SAO is configured by the Scene's {@link SAO} component. - * @param {Boolean} [cfg.pbrEnabled=true] Indicates if physically-based rendering (PBR) will apply to the SceneModel when {@link Scene#pbrEnabled} is ````true````. - * @param {Boolean} [cfg.colorTextureEnabled=true] Indicates if base color textures will be rendered for the SceneModel when {@link Scene#colorTextureEnabled} is ````true````. - * @param {Number} [cfg.edgeThreshold=10] When xraying, highlighting, selecting or edging, this is the threshold angle between normals of adjacent triangles, below which their shared wireframe edge is not drawn. - * @param {Number} [cfg.maxGeometryBatchSize=50000000] Maximum geometry batch size, as number of vertices. This is optionally supplied - * to limit the size of the batched geometry arrays that SceneModel internally creates for batched geometries. - * A lower value means less heap allocation/de-allocation while creating/loading batched geometries, but more draw calls and - * slower rendering speed. A high value means larger heap allocation/de-allocation while creating/loading, but less draw calls - * and faster rendering speed. It's recommended to keep this somewhere roughly between ````50000```` and ````50000000```. - * @param {TextureTranscoder} [cfg.textureTranscoder] Transcoder that will be used internally by {@link SceneModel#createTexture} - * to convert transcoded texture data. Only required when we'll be providing transcoded data - * to {@link SceneModel#createTexture}. We assume that all transcoded texture data added to a ````SceneModel```` - * will then in a format supported by this transcoder. - * @param {Boolean} [cfg.dtxEnabled=true] When ````true```` (default) use data textures (DTX), where appropriate, to - * represent the returned model. Set false to always use vertex buffer objects (VBOs). Note that DTX is only applicable - * to non-textured triangle meshes, and that VBOs are always used for meshes that have textures, line segments, or point - * primitives. Only works while {@link DTX#enabled} is also ````true````. - * @param {Number} [cfg.renderOrder=0] Specifies the rendering order for this SceneModel. This is used to control the order in which - * SceneModels are drawn when they have transparent objects, to give control over the order in which those objects are blended within the transparent - * render pass. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this.renderOrder = cfg.renderOrder || 0; - - this._dtxEnabled = this.scene.dtxEnabled && (cfg.dtxEnabled !== false); - - this._enableVertexWelding = false; // Not needed for most objects, and very expensive, so disabled - this._enableIndexBucketing = false; // Until fixed: https://github.com/xeokit/xeokit-sdk/issues/1204 - - this._textureTranscoder = cfg.textureTranscoder || getKTX2TextureTranscoder(this.scene.viewer); - - this._maxGeometryBatchSize = cfg.maxGeometryBatchSize ?? 5000000; - - this._aabb = math.collapseAABB3(); - this._aabbDirty = true; - - this._quantizationRanges = {}; - - this._vboLayers = {}; - this._dtxLayers = {}; - - this._meshList = []; - - this.layerList = []; // For GL state efficiency when drawing, InstancingLayers are in first part, BatchingLayers are in second - this._layersToFinalize = []; - - this._entityList = []; - this._entitiesToFinalize = []; - - this._geometries = {}; - this._dtxBuckets = {}; // Geometries with optimizations used for data texture representation - this._textures = {}; - this._textureSets = {}; - this._transforms = {}; - this._meshes = {}; - this._unusedMeshes = {}; - this._entities = {}; - - /** @private **/ - this.renderFlags = new RenderFlags(); - - /** - * @private - */ - this.numGeometries = 0; // Number of geometries created with createGeometry() - - // These counts are used to avoid unnecessary render passes - // They are incremented or decremented exclusively by BatchingLayer and InstancingLayer - - /** - * @private - */ - this.numPortions = 0; - - /** - * @private - */ - this.numVisibleLayerPortions = 0; - - /** - * @private - */ - this.numTransparentLayerPortions = 0; - - /** - * @private - */ - this.numXRayedLayerPortions = 0; - - /** - * @private - */ - this.numHighlightedLayerPortions = 0; - - /** - * @private - */ - this.numSelectedLayerPortions = 0; - - /** - * @private - */ - this.numEdgesLayerPortions = 0; - - /** - * @private - */ - this.numPickableLayerPortions = 0; - - /** - * @private - */ - this.numClippableLayerPortions = 0; - - /** - * @private - */ - this.numCulledLayerPortions = 0; - - this.numEntities = 0; - this._numTriangles = 0; - this._numLines = 0; - this._numPoints = 0; - this._layersFinalized = false; - - this._edgeThreshold = cfg.edgeThreshold || 10; - - // Build static matrix - - this._origin = math.vec3(cfg.origin || [0, 0, 0]); - this._position = math.vec3(cfg.position || [0, 0, 0]); - this._rotation = math.vec3(cfg.rotation || [0, 0, 0]); - this._quaternion = math.vec4(cfg.quaternion || [0, 0, 0, 1]); - this._conjugateQuaternion = math.vec4(cfg.quaternion || [0, 0, 0, 1]); - - if (cfg.rotation) { - math.eulerToQuaternion(this._rotation, "XYZ", this._quaternion); - } - this._scale = math.vec3(cfg.scale || [1, 1, 1]); - - this._worldRotationMatrix = math.mat4(); - this._worldRotationMatrixConjugate = math.mat4(); - this._matrix = math.mat4(); - this._matrixDirty = true; - - this._rebuildMatrices(); - - this._worldNormalMatrix = math.mat4(); - math.inverseMat4(this._matrix, this._worldNormalMatrix); - math.transposeMat4(this._worldNormalMatrix); - - if (cfg.matrix || cfg.position || cfg.rotation || cfg.scale || cfg.quaternion) { - this._viewMatrix = math.mat4(); - this._viewNormalMatrix = math.mat4(); - this._viewMatrixDirty = true; - this._matrixNonIdentity = true; - } - - this._opacity = 1.0; - this._colorize = [1, 1, 1]; - - this._saoEnabled = (cfg.saoEnabled !== false); - this._pbrEnabled = (cfg.pbrEnabled !== false); - this._colorTextureEnabled = (cfg.colorTextureEnabled !== false); - - this._isModel = cfg.isModel; - if (this._isModel) { - this.scene._registerModel(this); - } - - this._onCameraViewMatrix = this.scene.camera.on("matrix", () => { - this._viewMatrixDirty = true; - }); - - this._meshesWithDirtyMatrices = []; - this._numMeshesWithDirtyMatrices = 0; - - this._onTick = this.scene.on("tick", () => { - while (this._numMeshesWithDirtyMatrices > 0) { - this._meshesWithDirtyMatrices[--this._numMeshesWithDirtyMatrices]._updateMatrix(); - } - }); - - // Every SceneModelMesh gets at least the default TextureSet, - // which contains empty default textures filled with color - const defineTex = (texId, preloadColor) => { - return this._textures[texId] = new SceneModelTexture({ - id: texId, - texture: new Texture2D({ - gl: this.scene.canvas.gl, - preloadColor: preloadColor - }) - }); - }; - - this._textureSets[DEFAULT_TEXTURE_SET_ID] = new SceneModelTextureSet({ - id: DEFAULT_TEXTURE_SET_ID, - colorTexture: defineTex(DEFAULT_COLOR_TEXTURE_ID, [1, 1, 1, 1]), // [r, g, b, a]}), - metallicRoughnessTexture: defineTex(DEFAULT_METAL_ROUGH_TEXTURE_ID, [0, 1, 1, 1]), // [_, roughness, metalness, _], - normalsTexture: defineTex(DEFAULT_NORMALS_TEXTURE_ID, [0, 0, 0, 0]), // [x, y, z, _] - these must be zeros - emissiveTexture: defineTex(DEFAULT_EMISSIVE_TEXTURE_ID, [0, 0, 0, 1]), // [x, y, z, _] - occlusionTexture: defineTex(DEFAULT_OCCLUSION_TEXTURE_ID, [1, 1, 1, 1]) // [x, y, z, _] - }); - - this.visible = cfg.visible; - this.culled = cfg.culled; - this.pickable = cfg.pickable; - this.clippable = cfg.clippable; - this.collidable = cfg.collidable; - this.castsShadow = cfg.castsShadow; - this.receivesShadow = cfg.receivesShadow; - this.xrayed = cfg.xrayed; - this.highlighted = cfg.highlighted; - this.selected = cfg.selected; - this.edges = cfg.edges; - this.colorize = cfg.colorize; - this.opacity = cfg.opacity; - this.backfaces = cfg.backfaces; - } - - _meshMatrixDirty(mesh) { - this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++] = mesh; - } - - //------------------------------------------------------------------------------------------------------------------ - // SceneModel members - //------------------------------------------------------------------------------------------------------------------ - - /** - * Returns true to indicate that this Component is a SceneModel. - * @type {Boolean} - */ - get isPerformanceModel() { - return true; - } - - /** - * The {@link SceneModelTransform}s in this SceneModel. - * - * Each {#link SceneModelTransform} is stored here against its {@link SceneModelTransform.id}. - * - * @returns {*|{}} - */ - get transforms() { - return this._transforms; - } - - /** - * The {@link SceneModelTexture}s in this SceneModel. - * - * * Each {@link SceneModelTexture} is created with {@link SceneModel.createTexture}. - * * Each {@link SceneModelTexture} is stored here against its {@link SceneModelTexture.id}. - * - * @returns {*|{}} - */ - get textures() { - return this._textures; - } - - /** - * The {@link SceneModelTextureSet}s in this SceneModel. - * - * Each {@link SceneModelTextureSet} is stored here against its {@link SceneModelTextureSet.id}. - * - * @returns {*|{}} - */ - get textureSets() { - return this._textureSets; - } - - /** - * The {@link SceneModelMesh}es in this SceneModel. - * - * Each {@SceneModelMesh} is stored here against its {@link SceneModelMesh.id}. - * - * @returns {*|{}} - */ - get meshes() { - return this._meshes; - } - - /** - * The {@link SceneModelEntity}s in this SceneModel. - * - * Each {#link SceneModelEntity} in this SceneModel that represents an object is - * stored here against its {@link SceneModelTransform.id}. - * - * @returns {*|{}} - */ - get objects() { - return this._entities; - } - - /** - * Gets the 3D World-space origin for this SceneModel. - * - * Each {@link SceneModelMesh.origin}, if supplied, is relative to this origin. - * - * Default value is ````[0,0,0]````. - * - * @type {Float64Array} - */ - get origin() { - return this._origin; - } - - /** - * Sets the SceneModel's local translation. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - set position(value) { - this._position.set(value || [0, 0, 0]); - this._setWorldMatrixDirty(); - this._sceneModelDirty(); - this.glRedraw(); - } - - /** - * Gets the SceneModel's local translation. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - get position() { - return this._position; - } - - /** - * Sets the SceneModel's local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - set rotation(value) { - this._rotation.set(value || [0, 0, 0]); - math.eulerToQuaternion(this._rotation, "XYZ", this._quaternion); - this._setWorldMatrixDirty(); - this._sceneModelDirty(); - this.glRedraw(); - } - - /** - * Gets the SceneModel's local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis. - * - * Default value is ````[0,0,0]````. - * - * @type {Number[]} - */ - get rotation() { - return this._rotation; - } - - /** - * Sets the SceneModel's local rotation quaternion. - * - * Default value is ````[0,0,0,1]````. - * - * @type {Number[]} - */ - set quaternion(value) { - this._quaternion.set(value || [0, 0, 0, 1]); - math.quaternionToEuler(this._quaternion, "XYZ", this._rotation); - this._setWorldMatrixDirty(); - this._sceneModelDirty(); - this.glRedraw(); - } - - /** - * Gets the SceneModel's local rotation quaternion. - * - * Default value is ````[0,0,0,1]````. - * - * @type {Number[]} - */ - get quaternion() { - return this._quaternion; - } - - /** - * Sets the SceneModel's local scale. - * - * Default value is ````[1,1,1]````. - * - * @type {Number[]} - * @deprecated - */ - set scale(value) { - // NOP - deprecated - } - - /** - * Gets the SceneModel's local scale. - * - * Default value is ````[1,1,1]````. - * - * @type {Number[]} - * @deprecated - */ - get scale() { - return this._scale; - } - - /** - * Sets the SceneModel's local modeling transform matrix. - * - * Default value is ````[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]````. - * - * @type {Number[]} - */ - set matrix(value) { - this._matrix.set(value || DEFAULT_MATRIX); - math.decomposeMat4(this._matrix, this._position, this._quaternion, this._scale); - math.quaternionToEuler(this._quaternion, "XYZ", this._rotation); - this._matrixDirty = false; - this._setWorldMatrixDirty(); - this._sceneModelDirty(); - this.glRedraw(); - } - - /** - * Gets the SceneModel's local modeling transform matrix. - * - * Default value is ````[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]````. - * - * @type {Number[]} - */ - get matrix() { - this._rebuildMatrices(); - return this._matrix; - } - - /** - * Gets the SceneModel's local modeling rotation transform matrix. - * - * @type {Number[]} - */ - get rotationMatrix() { - this._rebuildMatrices(); - return this._worldRotationMatrix; - } - - _rebuildMatrices() { - if (this._matrixDirty) { - math.quaternionToRotationMat4(this._quaternion, this._worldRotationMatrix); - math.conjugateQuaternion(this._quaternion, this._conjugateQuaternion); - math.quaternionToRotationMat4(this._conjugateQuaternion, this._worldRotationMatrixConjugate); - math.scaleMat4v(this._scale, this._worldRotationMatrix); - math.scaleMat4v(this._scale, this._worldRotationMatrixConjugate); - this._matrix.set(this._worldRotationMatrix); - math.translateMat4v(this._position, this._matrix); - this._matrixDirty = false; - this._viewMatrixDirty = true; - } - } - - /** - * Gets the conjugate of the SceneModel's local modeling rotation transform matrix. - * - * This is used for RTC view matrix management in renderers. - * - * @type {Number[]} - */ - get rotationMatrixConjugate() { - this._rebuildMatrices(); - return this._worldRotationMatrixConjugate; - } - - _setWorldMatrixDirty() { - this._matrixDirty = true; - this._aabbDirty = true; - } - - _transformDirty() { - this._matrixDirty = true; - this._aabbDirty = true; - this.scene._aabbDirty = true; - } - - _sceneModelDirty() { - this.scene._aabbDirty = true; - this._aabbDirty = true; - this.scene._aabbDirty = true; - this._matrixDirty = true; - for (let i = 0, len = this._entityList.length; i < len; i++) { - this._entityList[i]._sceneModelDirty(); // Entities need to retransform their World AABBs by SceneModel's worldMatrix - } - } - - /** - * Gets the SceneModel's World matrix. - * - * @property worldMatrix - * @type {Number[]} - */ - get worldMatrix() { - return this.matrix; - } - - /** - * Gets the SceneModel's World normal matrix. - * - * @type {Number[]} - */ - get worldNormalMatrix() { - return this._worldNormalMatrix; - } - - _rebuildViewMatrices() { - this._rebuildMatrices(); - if (this._viewMatrixDirty) { - math.mulMat4(this.scene.camera.viewMatrix, this._matrix, this._viewMatrix); - math.inverseMat4(this._viewMatrix, this._viewNormalMatrix); - math.transposeMat4(this._viewNormalMatrix); - this._viewMatrixDirty = false; - } - } - - /** - * Called by private renderers in ./lib, returns the view matrix with which to - * render this SceneModel. The view matrix is the concatenation of the - * Camera view matrix with the Performance model's world (modeling) matrix. - * - * @private - */ - get viewMatrix() { - if (!this._viewMatrix) { - return this.scene.camera.viewMatrix; - } - this._rebuildViewMatrices(); - return this._viewMatrix; - } - - /** - * Called by private renderers in ./lib, returns the view normal matrix with which to render this SceneModel. - * - * @private - */ - get viewNormalMatrix() { - if (!this._viewNormalMatrix) { - return this.scene.camera.viewNormalMatrix; - } - this._rebuildViewMatrices(); - return this._viewNormalMatrix; - } - - /** - * Sets if backfaces are rendered for this SceneModel. - * - * Default is ````false````. - * - * @type {Boolean} - */ - get backfaces() { - return this._backfaces; - } - - /** - * Sets if backfaces are rendered for this SceneModel. - * - * Default is ````false````. - * - * When we set this ````true````, then backfaces are always rendered for this SceneModel. - * - * When we set this ````false````, then we allow the Viewer to decide whether to render backfaces. In this case, - * the Viewer will: - * - * * hide backfaces on watertight meshes, - * * show backfaces on open meshes, and - * * always show backfaces on meshes when we slice them open with {@link SectionPlane}s. - * - * @type {Boolean} - */ - set backfaces(backfaces) { - backfaces = !!backfaces; - this._backfaces = backfaces; - this.glRedraw(); - } - - /** - * Gets the list of {@link SceneModelEntity}s within this SceneModel. - * - * @returns {SceneModelEntity[]} - */ - get entityList() { - return this._entityList; - } - - /** - * Returns true to indicate that SceneModel is an {@link Entity}. - * @type {Boolean} - */ - get isEntity() { - return true; - } - - /** - * Returns ````true```` if this SceneModel represents a model. - * - * When ````true```` the SceneModel will be registered by {@link SceneModel#id} in - * {@link Scene#models} and may also have a {@link MetaObject} with matching {@link MetaObject#id}. - * - * @type {Boolean} - */ - get isModel() { - return this._isModel; - } - - //------------------------------------------------------------------------------------------------------------------ - // SceneModel members - //------------------------------------------------------------------------------------------------------------------ - - /** - * Returns ````false```` to indicate that SceneModel never represents an object. - * - * @type {Boolean} - */ - get isObject() { - return false; - } - - /** - * Gets the SceneModel's World-space 3D axis-aligned bounding box. - * - * Represented by a six-element Float64Array containing the min/max extents of the - * axis-aligned volume, ie. ````[xmin, ymin,zmin,xmax,ymax, zmax]````. - * - * @type {Number[]} - */ - get aabb() { - if (this._aabbDirty) { - math.collapseAABB3(this._aabb); - for (let i = 0, len = this._entityList.length; i < len; i++) { - math.expandAABB3(this._aabb, this._entityList[i].aabb); - } - this._aabbDirty = false; - } - return this._aabb; - } - - /** - * The approximate number of triangle primitives in this SceneModel. - * - * @type {Number} - */ - get numTriangles() { - return this._numTriangles; - } - - //------------------------------------------------------------------------------------------------------------------ - // Entity members - //------------------------------------------------------------------------------------------------------------------ - - /** - * The approximate number of line primitives in this SceneModel. - * - * @type {Number} - */ - get numLines() { - return this._numLines; - } - - /** - * The approximate number of point primitives in this SceneModel. - * - * @type {Number} - */ - get numPoints() { - return this._numPoints; - } - - /** - * Gets if any {@link SceneModelEntity}s in this SceneModel are visible. - * - * The SceneModel is only rendered when {@link SceneModel#visible} is ````true```` and {@link SceneModel#culled} is ````false````. - * - * @type {Boolean} - */ - get visible() { - return (this.numVisibleLayerPortions > 0); - } - - /** - * Sets if this SceneModel is visible. - * - * The SceneModel is only rendered when {@link SceneModel#visible} is ````true```` and {@link SceneModel#culled} is ````false````. - ** - * @type {Boolean} - */ - set visible(visible) { - visible = visible !== false; - this._visible = visible; - for (let i = 0, len = this._entityList.length; i < len; i++) { - this._entityList[i].visible = visible; - } - this.glRedraw(); - } - - /** - * Gets if any {@link SceneModelEntity}s in this SceneModel are xrayed. - * - * @type {Boolean} - */ - get xrayed() { - return (this.numXRayedLayerPortions > 0); - } - - /** - * Sets if all {@link SceneModelEntity}s in this SceneModel are xrayed. - * - * @type {Boolean} - */ - set xrayed(xrayed) { - xrayed = !!xrayed; - this._xrayed = xrayed; - for (let i = 0, len = this._entityList.length; i < len; i++) { - this._entityList[i].xrayed = xrayed; - } - this.glRedraw(); - } - - /** - * Gets if any {@link SceneModelEntity}s in this SceneModel are highlighted. - * - * @type {Boolean} - */ - get highlighted() { - return (this.numHighlightedLayerPortions > 0); - } - - /** - * Sets if all {@link SceneModelEntity}s in this SceneModel are highlighted. - * - * @type {Boolean} - */ - set highlighted(highlighted) { - highlighted = !!highlighted; - this._highlighted = highlighted; - for (let i = 0, len = this._entityList.length; i < len; i++) { - this._entityList[i].highlighted = highlighted; - } - this.glRedraw(); - } - - /** - * Gets if any {@link SceneModelEntity}s in this SceneModel are selected. - * - * @type {Boolean} - */ - get selected() { - return (this.numSelectedLayerPortions > 0); - } - - /** - * Sets if all {@link SceneModelEntity}s in this SceneModel are selected. - * - * @type {Boolean} - */ - set selected(selected) { - selected = !!selected; - this._selected = selected; - for (let i = 0, len = this._entityList.length; i < len; i++) { - this._entityList[i].selected = selected; - } - this.glRedraw(); - } - - /** - * Gets if any {@link SceneModelEntity}s in this SceneModel have edges emphasised. - * - * @type {Boolean} - */ - get edges() { - return (this.numEdgesLayerPortions > 0); - } - - /** - * Sets if all {@link SceneModelEntity}s in this SceneModel have edges emphasised. - * - * @type {Boolean} - */ - set edges(edges) { - edges = !!edges; - this._edges = edges; - for (let i = 0, len = this._entityList.length; i < len; i++) { - this._entityList[i].edges = edges; - } - this.glRedraw(); - } - - /** - * Gets if this SceneModel is culled from view. - * - * The SceneModel is only rendered when {@link SceneModel#visible} is true and {@link SceneModel#culled} is false. - * - * @type {Boolean} - */ - get culled() { - return this._culled; - } - - /** - * Sets if this SceneModel is culled from view. - * - * The SceneModel is only rendered when {@link SceneModel#visible} is true and {@link SceneModel#culled} is false. - * - * @type {Boolean} - */ - set culled(culled) { - culled = !!culled; - this._culled = culled; - for (let i = 0, len = this._entityList.length; i < len; i++) { - this._entityList[i].culled = culled; - } - this.glRedraw(); - } - - /** - * Gets if {@link SceneModelEntity}s in this SceneModel are clippable. - * - * Clipping is done by the {@link SectionPlane}s in {@link Scene#sectionPlanes}. - * - * @type {Boolean} - */ - get clippable() { - return this._clippable; - } - - /** - * Sets if {@link SceneModelEntity}s in this SceneModel are clippable. - * - * Clipping is done by the {@link SectionPlane}s in {@link Scene#sectionPlanes}. - * - * @type {Boolean} - */ - set clippable(clippable) { - clippable = clippable !== false; - this._clippable = clippable; - for (let i = 0, len = this._entityList.length; i < len; i++) { - this._entityList[i].clippable = clippable; - } - this.glRedraw(); - } - - /** - * Gets if this SceneModel is collidable. - * - * @type {Boolean} - */ - get collidable() { - return this._collidable; - } - - /** - * Sets if {@link SceneModelEntity}s in this SceneModel are collidable. - * - * @type {Boolean} - */ - set collidable(collidable) { - collidable = collidable !== false; - this._collidable = collidable; - for (let i = 0, len = this._entityList.length; i < len; i++) { - this._entityList[i].collidable = collidable; - } - } - - /** - * Gets if this SceneModel is pickable. - * - * Picking is done via calls to {@link Scene#pick}. - * - * @type {Boolean} - */ - get pickable() { - return (this.numPickableLayerPortions > 0); - } - - /** - * Sets if {@link SceneModelEntity}s in this SceneModel are pickable. - * - * Picking is done via calls to {@link Scene#pick}. - * - * @type {Boolean} - */ - set pickable(pickable) { - pickable = pickable !== false; - this._pickable = pickable; - for (let i = 0, len = this._entityList.length; i < len; i++) { - this._entityList[i].pickable = pickable; - } - } - - /** - * Gets the RGB colorize color for this SceneModel. - * - * Each element of the color is in range ````[0..1]````. - * - * @type {Number[]} - */ - get colorize() { - return this._colorize; - } - - /** - * Sets the RGB colorize color for this SceneModel. - * - * Multiplies by rendered fragment colors. - * - * Each element of the color is in range ````[0..1]````. - * - * @type {Number[]} - */ - set colorize(colorize) { - this._colorize = colorize; - for (let i = 0, len = this._entityList.length; i < len; i++) { - this._entityList[i].colorize = colorize; - } - } - - /** - * Gets this SceneModel's opacity factor. - * - * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas. - * - * @type {Number} - */ - get opacity() { - return this._opacity; - } - - /** - * Sets the opacity factor for this SceneModel. - * - * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas. - * - * @type {Number} - */ - set opacity(opacity) { - this._opacity = opacity; - for (let i = 0, len = this._entityList.length; i < len; i++) { - this._entityList[i].opacity = opacity; - } - } - - /** - * Gets if this SceneModel casts a shadow. - * - * @type {Boolean} - */ - get castsShadow() { - return this._castsShadow; - } - - /** - * Sets if this SceneModel casts a shadow. - * - * @type {Boolean} - */ - set castsShadow(castsShadow) { - castsShadow = (castsShadow !== false); - if (castsShadow !== this._castsShadow) { - this._castsShadow = castsShadow; - this.glRedraw(); - } - } - - /** - * Sets if this SceneModel can have shadow cast upon it. - * - * @type {Boolean} - */ - get receivesShadow() { - return this._receivesShadow; - } - - /** - * Sets if this SceneModel can have shadow cast upon it. - * - * @type {Boolean} - */ - set receivesShadow(receivesShadow) { - receivesShadow = (receivesShadow !== false); - if (receivesShadow !== this._receivesShadow) { - this._receivesShadow = receivesShadow; - this.glRedraw(); - } - } - - /** - * Gets if Scalable Ambient Obscurance (SAO) will apply to this SceneModel. - * - * SAO is configured by the Scene's {@link SAO} component. - * - * Only works when {@link SAO#enabled} is also true. - * - * @type {Boolean} - */ - get saoEnabled() { - return this._saoEnabled; - } - - /** - * Gets if physically-based rendering (PBR) is enabled for this SceneModel. - * - * Only works when {@link Scene#pbrEnabled} is also true. - * - * @type {Boolean} - */ - get pbrEnabled() { - return this._pbrEnabled; - } - - /** - * Gets if color textures are enabled for this SceneModel. - * - * Only works when {@link Scene#colorTextureEnabled} is also true. - * - * @type {Boolean} - */ - get colorTextureEnabled() { - return this._colorTextureEnabled; - } - - /** - * Returns true to indicate that SceneModel is implements {@link Drawable}. - * - * @type {Boolean} - */ - get isDrawable() { - return true; - } - - /** @private */ - get isStateSortable() { - return false - } - - /** - * Configures the appearance of xrayed {@link SceneModelEntity}s within this SceneModel. - * - * This is the {@link Scene#xrayMaterial}. - * - * @type {EmphasisMaterial} - */ - get xrayMaterial() { - return this.scene.xrayMaterial; - } - - /** - * Configures the appearance of highlighted {@link SceneModelEntity}s within this SceneModel. - * - * This is the {@link Scene#highlightMaterial}. - * - * @type {EmphasisMaterial} - */ - get highlightMaterial() { - return this.scene.highlightMaterial; - } - - /** - * Configures the appearance of selected {@link SceneModelEntity}s within this SceneModel. - * - * This is the {@link Scene#selectedMaterial}. - * - * @type {EmphasisMaterial} - */ - get selectedMaterial() { - return this.scene.selectedMaterial; - } - - /** - * Configures the appearance of edges of {@link SceneModelEntity}s within this SceneModel. - * - * This is the {@link Scene#edgeMaterial}. - * - * @type {EdgeMaterial} - */ - get edgeMaterial() { - return this.scene.edgeMaterial; - } - - //------------------------------------------------------------------------------------------------------------------ - // Drawable members - //------------------------------------------------------------------------------------------------------------------ - - /** - * Called by private renderers in ./lib, returns the picking view matrix with which to - * ray-pick on this SceneModel. - * - * @private - */ - getPickViewMatrix(pickViewMatrix) { - if (!this._viewMatrix) { - return pickViewMatrix; - } - return this._viewMatrix; - } - - /** - * - * @param cfg - */ - createQuantizationRange(cfg) { - if (cfg.id === undefined || cfg.id === null) { - this.error("[createQuantizationRange] Config missing: id"); - return; - } - if (cfg.aabb) { - this.error("[createQuantizationRange] Config missing: aabb"); - return; - } - if (this._quantizationRanges[cfg.id]) { - this.error("[createQuantizationRange] QuantizationRange already created: " + cfg.id); - return; - } - this._quantizationRanges[cfg.id] = { - id: cfg.id, - aabb: cfg.aabb, - matrix: createPositionsDecodeMatrix(cfg.aabb, math.mat4()) - }; - } - - _createDefaultIndices(numIndices) { - const indices = []; - for (let i = 0; i < numIndices; i++) { - indices.push(i); - } - return indices; - } - - /** - * Creates a reusable geometry within this SceneModel. - * - * We can then supply the geometry ID to {@link SceneModel#createMesh} when we want to create meshes that - * instance the geometry. - * - * @param {*} cfg Geometry properties. - * @param {String|Number} cfg.id Mandatory ID for the geometry, to refer to with {@link SceneModel#createMesh}. - * @param {String} cfg.primitive The primitive type. Accepted values are 'points', 'lines', 'triangles', 'solid' and 'surface'. - * @param {Number[]} [cfg.positions] Flat array of uncompressed 3D vertex positions positions. Required for all primitive types. Overridden by ````positionsCompressed````. - * @param {Number[]} [cfg.positionsCompressed] Flat array of quantized 3D vertex positions. Overrides ````positions````, and must be accompanied by ````positionsDecodeMatrix````. - * @param {Number[]} [cfg.positionsDecodeMatrix] A 4x4 matrix for decompressing ````positionsCompressed````. Must be accompanied by ````positionsCompressed````. - * @param {Number[]} [cfg.normals] Flat array of normal vectors. Only used with "triangles", "solid" and "surface" primitives. When no normals are given, the geometry will be flat shaded using auto-generated face-aligned normals. - * @param {Number[]} [cfg.normalsCompressed] Flat array of oct-encoded normal vectors. Overrides ````normals````. Only used with "triangles", "solid" and "surface" primitives. When no normals are given, the geometry will be flat shaded using auto-generated face-aligned normals. - * @param {Number[]} [cfg.colors] Flat array of uncompressed RGBA vertex colors, as float values in range ````[0..1]````. Ignored when ````geometryId```` is given. Overridden by ````color```` and ````colorsCompressed````. - * @param {Number[]} [cfg.colorsCompressed] Flat array of compressed RGBA vertex colors, as unsigned short integers in range ````[0..255]````. Ignored when ````geometryId```` is given. Overrides ````colors```` and is overridden by ````color````. - * @param {Number[]} [cfg.uv] Flat array of uncompressed vertex UV coordinates. Only used with "triangles", "solid" and "surface" primitives. Required for textured rendering. - * @param {Number[]} [cfg.uvCompressed] Flat array of compressed vertex UV coordinates. Only used with "triangles", "solid" and "surface" primitives. Overrides ````uv````. Must be accompanied by ````uvDecodeMatrix````. Only used with "triangles", "solid" and "surface" primitives. Required for textured rendering. - * @param {Number[]} [cfg.uvDecodeMatrix] A 3x3 matrix for decompressing ````uvCompressed````. - * @param {Number[]} [cfg.indices] Array of primitive connectivity indices. Not required for `points` primitives. - * @param {Number[]} [cfg.edgeIndices] Array of edge line indices. Used only with 'triangles', 'solid' and 'surface' primitives. Automatically generated internally if not supplied, using the optional ````edgeThreshold```` given to the ````SceneModel```` constructor. - */ - createGeometry(cfg) { - if (cfg.id === undefined || cfg.id === null) { - this.error("[createGeometry] Config missing: id"); - return; - } - if (this._geometries[cfg.id]) { - this.error("[createGeometry] Geometry already created: " + cfg.id); - return; - } - if (cfg.primitive === undefined || cfg.primitive === null) { - cfg.primitive = "triangles"; - } - if (cfg.primitive !== "points" && cfg.primitive !== "lines" && cfg.primitive !== "triangles" && cfg.primitive !== "solid" && cfg.primitive !== "surface") { - this.error(`[createGeometry] Unsupported value for 'primitive': '${cfg.primitive}' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'.`); - return; - } - if (!cfg.positions && !cfg.positionsCompressed && !cfg.buckets) { - this.error("[createGeometry] Param expected: `positions`, `positionsCompressed' or 'buckets"); - return null; - } - if (cfg.positionsCompressed && !cfg.positionsDecodeMatrix && !cfg.positionsDecodeBoundary) { - this.error("[createGeometry] Param expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"); - return null; - } - if (cfg.positionsDecodeMatrix && cfg.positionsDecodeBoundary) { - this.error("[createGeometry] Only one of these params expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"); - return null; - } - if (cfg.uvCompressed && !cfg.uvDecodeMatrix) { - this.error("[createGeometry] Param expected: `uvDecodeMatrix` (required for `uvCompressed')"); - return null; - } - if (!cfg.buckets && !cfg.indices && (cfg.primitive === "triangles" || cfg.primitive === "solid" || cfg.primitive === "surface")) { - cfg.indices = this._createDefaultIndices((cfg.positions || cfg.positionsCompressed).length / 3); - } - if (!cfg.buckets && !cfg.indices && cfg.primitive !== "points") { - this.error(`[createGeometry] Param expected: indices (required for '${cfg.primitive}' primitive type)`); - return null; - } - if (cfg.positionsDecodeBoundary) { - cfg.positionsDecodeMatrix = createPositionsDecodeMatrix(cfg.positionsDecodeBoundary, math.mat4()); - } - if (cfg.positions) { - const aabb = math.collapseAABB3(); - cfg.positionsDecodeMatrix = math.mat4(); - math.expandAABB3Points3(aabb, cfg.positions); - cfg.positionsCompressed = quantizePositions(cfg.positions, aabb, cfg.positionsDecodeMatrix); - cfg.aabb = aabb; - } else if (cfg.positionsCompressed) { - const aabb = math.collapseAABB3(); - cfg.positionsDecodeMatrix = new Float64Array(cfg.positionsDecodeMatrix); - cfg.positionsCompressed = new Uint16Array(cfg.positionsCompressed); - math.expandAABB3Points3(aabb, cfg.positionsCompressed); - geometryCompressionUtils.decompressAABB(aabb, cfg.positionsDecodeMatrix); - cfg.aabb = aabb; - } else if (cfg.buckets) { - const aabb = math.collapseAABB3(); - this._dtxBuckets[cfg.id] = cfg.buckets; - for (let i = 0, len = cfg.buckets.length; i < len; i++) { - const bucket = cfg.buckets[i]; - if (bucket.positions) { - math.expandAABB3Points3(aabb, bucket.positions); - } else if (bucket.positionsCompressed) { - math.expandAABB3Points3(aabb, bucket.positionsCompressed); - } - } - if (cfg.positionsDecodeMatrix) { - geometryCompressionUtils.decompressAABB(aabb, cfg.positionsDecodeMatrix); - } - cfg.aabb = aabb; - } - if (cfg.colorsCompressed && cfg.colorsCompressed.length > 0) { - cfg.colorsCompressed = new Uint8Array(cfg.colorsCompressed); - } else if (cfg.colors && cfg.colors.length > 0) { - const colors = cfg.colors; - const colorsCompressed = new Uint8Array(colors.length); - for (let i = 0, len = colors.length; i < len; i++) { - colorsCompressed[i] = colors[i] * 255; - } - cfg.colorsCompressed = colorsCompressed; - } - if (!cfg.buckets && !cfg.edgeIndices && (cfg.primitive === "triangles" || cfg.primitive === "solid" || cfg.primitive === "surface")) { - if (cfg.positions) { - cfg.edgeIndices = buildEdgeIndices(cfg.positions, cfg.indices, null, 5.0); - } else { - cfg.edgeIndices = buildEdgeIndices(cfg.positionsCompressed, cfg.indices, cfg.positionsDecodeMatrix, 2.0); - } - } - if (cfg.uv) { - const bounds = geometryCompressionUtils.getUVBounds(cfg.uv); - const result = geometryCompressionUtils.compressUVs(cfg.uv, bounds.min, bounds.max); - cfg.uvCompressed = result.quantized; - cfg.uvDecodeMatrix = result.decodeMatrix; - } else if (cfg.uvCompressed) { - cfg.uvCompressed = new Uint16Array(cfg.uvCompressed); - cfg.uvDecodeMatrix = new Float64Array(cfg.uvDecodeMatrix); - } - if (cfg.normals) { // HACK - cfg.normals = null; - } - this._geometries [cfg.id] = cfg; - this._numTriangles += (cfg.indices ? Math.round(cfg.indices.length / 3) : 0); - this.numGeometries++; - } - - /** - * Creates a texture within this SceneModel. - * - * We can then supply the texture ID to {@link SceneModel#createTextureSet} when we want to create texture sets that use the texture. - * - * @param {*} cfg Texture properties. - * @param {String|Number} cfg.id Mandatory ID for the texture, to refer to with {@link SceneModel#createTextureSet}. - * @param {String} [cfg.src] Image file for the texture. Assumed to be transcoded if not having a recognized image file - * extension (jpg, jpeg, png etc.). If transcoded, then assumes ````SceneModel```` is configured with a {@link TextureTranscoder}. - * @param {ArrayBuffer[]} [cfg.buffers] Transcoded texture data. Assumes ````SceneModel```` is - * configured with a {@link TextureTranscoder}. This parameter is given as an array of buffers so we can potentially support multi-image textures, such as cube maps. - * @param {HTMLImageElement} [cfg.image] HTML Image object to load into this texture. Overrides ````src```` and ````buffers````. Never transcoded. - * @param {Number} [cfg.minFilter=LinearMipmapLinearFilter] How the texture is sampled when a texel covers less than one pixel. - * Supported values are {@link LinearMipmapLinearFilter}, {@link LinearMipMapNearestFilter}, {@link NearestMipMapNearestFilter}, {@link NearestMipMapLinearFilter} and {@link LinearMipMapLinearFilter}. - * @param {Number} [cfg.magFilter=LinearFilter] How the texture is sampled when a texel covers more than one pixel. Supported values are {@link LinearFilter} and {@link NearestFilter}. - * @param {Number} [cfg.wrapS=RepeatWrapping] Wrap parameter for texture coordinate *S*. Supported values are {@link ClampToEdgeWrapping}, {@link MirroredRepeatWrapping} and {@link RepeatWrapping}. - * @param {Number} [cfg.wrapT=RepeatWrapping] Wrap parameter for texture coordinate *T*. Supported values are {@link ClampToEdgeWrapping}, {@link MirroredRepeatWrapping} and {@link RepeatWrapping}.. - * @param {Number} [cfg.wrapR=RepeatWrapping] Wrap parameter for texture coordinate *R*. Supported values are {@link ClampToEdgeWrapping}, {@link MirroredRepeatWrapping} and {@link RepeatWrapping}. - * @param {Boolean} [cfg.flipY=false] Flips this Texture's source data along its vertical axis when ````true````. - * @param {Number} [cfg.encoding=LinearEncoding] Encoding format. Supported values are {@link LinearEncoding} and {@link sRGBEncoding}. - */ - createTexture(cfg) { - const textureId = cfg.id; - if (textureId === undefined || textureId === null) { - this.error("[createTexture] Config missing: id"); - return; - } - if (this._textures[textureId]) { - this.error("[createTexture] Texture already created: " + textureId); - return; - } - if (!cfg.src && !cfg.image && !cfg.buffers) { - this.error("[createTexture] Param expected: `src`, `image' or 'buffers'"); - return null; - } - let minFilter = cfg.minFilter || LinearMipmapLinearFilter; - if (minFilter !== LinearFilter && - minFilter !== LinearMipMapNearestFilter && - minFilter !== LinearMipmapLinearFilter && - minFilter !== NearestMipMapLinearFilter && - minFilter !== NearestMipMapNearestFilter) { - this.error(`[createTexture] Unsupported value for 'minFilter' - - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, - NearestMipMapLinearFilter and LinearMipmapLinearFilter. Defaulting to LinearMipmapLinearFilter.`); - minFilter = LinearMipmapLinearFilter; - } - let magFilter = cfg.magFilter || LinearFilter; - if (magFilter !== LinearFilter && magFilter !== NearestFilter) { - this.error(`[createTexture] Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter.`); - magFilter = LinearFilter; - } - let wrapS = cfg.wrapS || RepeatWrapping; - if (wrapS !== ClampToEdgeWrapping && wrapS !== MirroredRepeatWrapping && wrapS !== RepeatWrapping) { - this.error(`[createTexture] Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping.`); - wrapS = RepeatWrapping; - } - let wrapT = cfg.wrapT || RepeatWrapping; - if (wrapT !== ClampToEdgeWrapping && wrapT !== MirroredRepeatWrapping && wrapT !== RepeatWrapping) { - this.error(`[createTexture] Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping.`); - wrapT = RepeatWrapping; - } - let wrapR = cfg.wrapR || RepeatWrapping; - if (wrapR !== ClampToEdgeWrapping && wrapR !== MirroredRepeatWrapping && wrapR !== RepeatWrapping) { - this.error(`[createTexture] Unsupported value for 'wrapR' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping.`); - wrapR = RepeatWrapping; - } - let encoding = cfg.encoding || LinearEncoding; - if (encoding !== LinearEncoding && encoding !== sRGBEncoding) { - this.error("[createTexture] Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."); - encoding = LinearEncoding; - } - const texture = new Texture2D({ - gl: this.scene.canvas.gl, - minFilter, - magFilter, - wrapS, - wrapT, - wrapR, - // flipY: cfg.flipY, - encoding - }); - if (cfg.preloadColor) { - texture.setPreloadColor(cfg.preloadColor); - } - if (cfg.image) { // Ignore transcoder for Images - const image = cfg.image; - image.crossOrigin = "Anonymous"; - if (image.compressed) { - // see `parsedImage` in @loaders.gl/gltf/src/lib/parsers/parse-gltf.ts - // NOTE: @loaders.gl in its current version discards potential mipmaps, leaving only a single one - const data = image.data; - texture.setCompressedData({ - mipmaps: data, - props: { - format: data[0].format, - minFilter: minFilter, - magFilter: magFilter - } - }); - } else { - texture.setImage(image, {minFilter, magFilter, wrapS, wrapT, wrapR, flipY: cfg.flipY, encoding}); - } - } else if (cfg.src) { - const ext = cfg.src.split('.').pop(); - switch (ext) { // Don't transcode recognized image file types - case "jpeg": - case "jpg": - case "png": - case "gif": - const image = new Image(); - image.onload = () => { - texture.setImage(image, { - minFilter, - magFilter, - wrapS, - wrapT, - wrapR, - flipY: cfg.flipY, - encoding - }); - this.glRedraw(); - }; - image.src = cfg.src; // URL or Base64 string - break; - default: // Assume other file types need transcoding - if (!this._textureTranscoder) { - this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${ext}')`); - } else { - utils.loadArraybuffer(cfg.src, (arrayBuffer) => { - if (!arrayBuffer.byteLength) { - this.error(`[createTexture] Can't create texture from 'src': file data is zero length`); - return; - } - this._textureTranscoder.transcode([arrayBuffer], texture).then(() => { - this.glRedraw(); - }); - }, - function (errMsg) { - this.error(`[createTexture] Can't create texture from 'src': ${errMsg}`); - }); - } - break; - } - } else if (cfg.buffers) { // Buffers implicitly require transcoding - if (!this._textureTranscoder) { - this.error(`[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option`); - } else { - this._textureTranscoder.transcode(cfg.buffers, texture).then(() => { - this.glRedraw(); - }); - } - } - this._textures[textureId] = new SceneModelTexture({id: textureId, texture}); - } - - /** - * Creates a texture set within this SceneModel. - * - * * Stores the new {@link SceneModelTextureSet} in {@link SceneModel#textureSets}. - * - * A texture set is a collection of textures that can be shared among meshes. We can then supply the texture set - * ID to {@link SceneModel#createMesh} when we want to create meshes that use the texture set. - * - * The textures can work as a texture atlas, where each mesh can have geometry UVs that index - * a different part of the textures. This allows us to minimize the number of textures in our models, which - * means faster rendering. - * - * @param {*} cfg Texture set properties. - * @param {String|Number} cfg.id Mandatory ID for the texture set, to refer to with {@link SceneModel#createMesh}. - * @param {*} [cfg.colorTextureId] ID of *RGBA* base color texture, with color in *RGB* and alpha in *A*. - * @param {*} [cfg.metallicRoughnessTextureId] ID of *RGBA* metal-roughness texture, with the metallic factor in *R*, and roughness factor in *G*. - * @param {*} [cfg.normalsTextureId] ID of *RGBA* normal map texture, with normal map vectors in *RGB*. - * @param {*} [cfg.emissiveTextureId] ID of *RGBA* emissive map texture, with emissive color in *RGB*. - * @param {*} [cfg.occlusionTextureId] ID of *RGBA* occlusion map texture, with occlusion factor in *R*. - * @returns {SceneModelTransform} The new texture set. - */ - createTextureSet(cfg) { - const textureSetId = cfg.id; - if (textureSetId === undefined || textureSetId === null) { - this.error("[createTextureSet] Config missing: id"); - return false; - } - if (this._textureSets[textureSetId]) { - this.error(`[createTextureSet] Texture set already created: ${textureSetId}`); - return false; - } - - const getTexture = (cfgId, defaultKey) => { - const id = cfgId ?? defaultKey; - if (id in this._textures) { - return this._textures[id]; - } else { - throw cfgId; - } - }; - - try { - const textureSet = new SceneModelTextureSet({ - id: textureSetId, - model: this, - alphaCutoff: cfg.alphaCutoff, - colorTexture: getTexture(cfg.colorTextureId, DEFAULT_COLOR_TEXTURE_ID), - metallicRoughnessTexture: getTexture(cfg.metallicRoughnessTextureId, DEFAULT_METAL_ROUGH_TEXTURE_ID), - normalsTexture: getTexture(cfg.normalsTextureId, DEFAULT_NORMALS_TEXTURE_ID), - emissiveTexture: getTexture(cfg.emissiveTextureId, DEFAULT_EMISSIVE_TEXTURE_ID), - occlusionTexture: getTexture(cfg.occlusionTextureId, DEFAULT_OCCLUSION_TEXTURE_ID) - }); - this._textureSets[textureSetId] = textureSet; - return textureSet; - } catch (id) { - this.error(`[createTextureSet] Texture not found: ${id} - ensure that you create it first with createTexture()`); - return false; - } - } - - /** - * Creates a new {@link SceneModelTransform} within this SceneModel. - * - * * Stores the new {@link SceneModelTransform} in {@link SceneModel#transforms}. - * * Can be connected into hierarchies - * * Each {@link SceneModelTransform} can be used by unlimited {@link SceneModelMesh}es - * - * @param {*} cfg Transform creation parameters. - * @param {String} cfg.id Mandatory ID for the new transform. Must not clash with any existing components within the {@link Scene}. - * @param {String} [cfg.parentTransformId] ID of a parent transform, previously created with {@link SceneModel#createTextureSet}. - * @param {Number[]} [cfg.position=[0,0,0]] Local 3D position of the mesh. Overridden by ````transformId````. - * @param {Number[]} [cfg.scale=[1,1,1]] Scale of the transform. - * @param {Number[]} [cfg.rotation=[0,0,0]] Rotation of the transform as Euler angles given in degrees, for each of the X, Y and Z axis. - * @param {Number[]} [cfg.matrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]] Modelling transform matrix. Overrides the ````position````, ````scale```` and ````rotation```` parameters. - * @returns {SceneModelTransform} The new transform. - */ - createTransform(cfg) { - if (cfg.id === undefined || cfg.id === null) { - this.error("[createTransform] SceneModel.createTransform() config missing: id"); - return; - } - if (this._transforms[cfg.id]) { - this.error(`[createTransform] SceneModel already has a transform with this ID: ${cfg.id}`); - return; - } - let parentTransform; - if (cfg.parentTransformId) { - parentTransform = this._transforms[cfg.parentTransformId]; - if (!parentTransform) { - this.error("[createTransform] SceneModel.createTransform() config missing: id"); - return; - } - } - const transform = new SceneModelTransform({ - id: cfg.id, - model: this, - parent: parentTransform, - matrix: cfg.matrix, - position: cfg.position, - scale: cfg.scale, - rotation: cfg.rotation, - quaternion: cfg.quaternion - }); - this._transforms[transform.id] = transform; - return transform; - } - - /** - * Creates a new {@link SceneModelMesh} within this SceneModel. - * - * * It prepares and saves data for a SceneModelMesh {@link SceneModel#meshes} creation. SceneModelMesh will be created only once the SceneModelEntity (which references this particular SceneModelMesh) will be created. - * * The SceneModelMesh can either define its own geometry or share it with other SceneModelMeshes. To define own geometry, provide the - * various geometry arrays to this method. To share a geometry, provide the ID of a geometry created earlier - * with {@link SceneModel#createGeometry}. - * * If you accompany the arrays with an ````origin````, then ````createMesh()```` will assume - * that the geometry ````positions```` are in relative-to-center (RTC) coordinates, with ````origin```` being the - * origin of their RTC coordinate system. - * - * @param {object} cfg Object properties. - * @param {String} cfg.id Mandatory ID for the new mesh. Must not clash with any existing components within the {@link Scene}. - * @param {String|Number} [cfg.textureSetId] ID of a {@link SceneModelTextureSet} previously created with {@link SceneModel#createTextureSet}. - * @param {String|Number} [cfg.transformId] ID of a {@link SceneModelTransform} to instance, previously created with {@link SceneModel#createTransform}. Overrides all other transform parameters given to this method. - * @param {String|Number} [cfg.geometryId] ID of a geometry to instance, previously created with {@link SceneModel#createGeometry}. Overrides all other geometry parameters given to this method. - * @param {String} cfg.primitive The primitive type. Accepted values are 'points', 'lines', 'triangles', 'solid' and 'surface'. - * @param {Number[]} [cfg.positions] Flat array of uncompressed 3D vertex positions positions. Required for all primitive types. Overridden by ````positionsCompressed````. - * @param {Number[]} [cfg.positionsCompressed] Flat array of quantized 3D vertex positions. Overrides ````positions````, and must be accompanied by ````positionsDecodeMatrix````. - * @param {Number[]} [cfg.positionsDecodeMatrix] A 4x4 matrix for decompressing ````positionsCompressed````. Must be accompanied by ````positionsCompressed````. - * @param {Number[]} [cfg.normals] Flat array of normal vectors. Only used with "triangles", "solid" and "surface" primitives. When no normals are given, the geometry will be flat shaded using auto-generated face-aligned normals. - * @param {Number[]} [cfg.normalsCompressed] Flat array of oct-encoded normal vectors. Overrides ````normals````. Only used with "triangles", "solid" and "surface" primitives. When no normals are given, the geometry will be flat shaded using auto-generated face-aligned normals. - * @param {Number[]} [cfg.colors] Flat array of uncompressed RGBA vertex colors, as float values in range ````[0..1]````. Ignored when ````geometryId```` is given. Overridden by ````color```` and ````colorsCompressed````. - * @param {Number[]} [cfg.colorsCompressed] Flat array of compressed RGBA vertex colors, as unsigned short integers in range ````[0..255]````. Ignored when ````geometryId```` is given. Overrides ````colors```` and is overridden by ````color````. - * @param {Number[]} [cfg.uv] Flat array of uncompressed vertex UV coordinates. Only used with "triangles", "solid" and "surface" primitives. Required for textured rendering. - * @param {Number[]} [cfg.uvCompressed] Flat array of compressed vertex UV coordinates. Only used with "triangles", "solid" and "surface" primitives. Overrides ````uv````. Must be accompanied by ````uvDecodeMatrix````. Only used with "triangles", "solid" and "surface" primitives. Required for textured rendering. - * @param {Number[]} [cfg.uvDecodeMatrix] A 3x3 matrix for decompressing ````uvCompressed````. - * @param {Number[]} [cfg.indices] Array of primitive connectivity indices. Not required for `points` primitives. - * @param {Number[]} [cfg.edgeIndices] Array of edge line indices. Used only with 'triangles', 'solid' and 'surface' primitives. Automatically generated internally if not supplied, using the optional ````edgeThreshold```` given to the ````SceneModel```` constructor. - * @param {Number[]} [cfg.origin] Optional geometry origin, relative to {@link SceneModel#origin}. When this is given, then ````positions```` are assumed to be relative to this. - * @param {Number[]} [cfg.position=[0,0,0]] Local 3D position of the mesh. Overridden by ````transformId````. - * @param {Number[]} [cfg.scale=[1,1,1]] Scale of the mesh. Overridden by ````transformId````. - * @param {Number[]} [cfg.rotation=[0,0,0]] Rotation of the mesh as Euler angles given in degrees, for each of the X, Y and Z axis. Overridden by ````transformId````. - * @param {Number[]} [cfg.quaternion] Rotation of the mesh as a quaternion. Overridden by ````rotation````. - * @param {Number[]} [cfg.matrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]] Mesh modelling transform matrix. Overrides the ````position````, ````scale```` and ````rotation```` parameters. Also overridden by ````transformId````. - * @param {Number[]} [cfg.color=[1,1,1]] RGB color in range ````[0..1, 0..1, 0..1]````. Overridden by texture set ````colorTexture````. Overrides ````colors```` and ````colorsCompressed````. - * @param {Number} [cfg.opacity=1] Opacity in range ````[0..1]````. Overridden by texture set ````colorTexture````. - * @param {Number} [cfg.metallic=0] Metallic factor in range ````[0..1]````. Overridden by texture set ````metallicRoughnessTexture````. - * @param {Number} [cfg.roughness=1] Roughness factor in range ````[0..1]````. Overridden by texture set ````metallicRoughnessTexture````. - * @returns {SceneModelMesh} The new mesh. - */ - createMesh(cfg) { - - if (cfg.id === undefined || cfg.id === null) { - this.error("[createMesh] SceneModel.createMesh() config missing: id"); - return false; - } - - if (this._meshes[cfg.id]) { - this.error(`[createMesh] SceneModel already has a mesh with this ID: ${cfg.id}`); - return false; - } - - const geometryId = cfg.geometryId; - const instancing = geometryId !== undefined; - - if (instancing) { - if (cfg.positions || cfg.positionsCompressed || cfg.indices || cfg.edgeIndices || cfg.normals || cfg.normalsCompressed || cfg.uv || cfg.uvCompressed || cfg.positionsDecodeMatrix) { - this.error(`Mesh geometry parameters not expected when instancing a geometry (not expected: positions, positionsCompressed, indices, edgeIndices, normals, normalsCompressed, uv, uvCompressed, positionsDecodeMatrix)`); - return false; - } - - cfg.geometry = this._geometries[geometryId]; - if (!cfg.geometry) { - this.error(`[createMesh] Geometry not found: ${geometryId} - ensure that you create it first with createGeometry()`); - return false; - } - } else { - cfg.primitive ??= "triangles"; - } - - const primitive = instancing ? cfg.geometry.primitive : cfg.primitive; - const isTriangular = (primitive === "triangles") || (primitive === "solid") || (primitive === "surface"); - const textureSetId = cfg.textureSetId; - const useDTX = this._dtxEnabled && isTriangular && (! textureSetId); - - cfg.origin = cfg.origin ? math.addVec3(this._origin, cfg.origin, math.vec3()) : this._origin; - - if (! instancing) { - - // Batched geometry - - if (primitive !== "points" && primitive !== "lines" && primitive !== "triangles" && primitive !== "solid" && primitive !== "surface") { - this.error(`Unsupported value for 'primitive': '${primitive}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`); - return false; - } - if (!cfg.positions && !cfg.positionsCompressed && !cfg.buckets) { - this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"); - return false; - } - if (cfg.positions && (cfg.positionsDecodeMatrix || cfg.positionsDecodeBoundary)) { - this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"); - return false; - } - if (cfg.positionsCompressed && !cfg.positionsDecodeMatrix && !cfg.positionsDecodeBoundary) { - this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"); - return false; - } - if (cfg.uvCompressed && !cfg.uvDecodeMatrix) { - this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"); - return false; - } - if (!cfg.buckets && !cfg.indices) { - if (isTriangular) { - cfg.indices = this._createDefaultIndices((cfg.positions || cfg.positionsCompressed).length / 3); - } else if (primitive === "lines") { - this.error(`Param expected: indices (required for '${primitive}' primitive type)`); - return false; - } - } - if ((cfg.matrix || cfg.position || cfg.rotation || cfg.scale) && (cfg.positionsCompressed || cfg.positionsDecodeBoundary)) { - this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"); - return false; - } - - // MATRIX - optional for batching - - if (cfg.matrix) { - cfg.meshMatrix = cfg.matrix; - } else if (cfg.scale || cfg.rotation || cfg.position || cfg.quaternion) { - const scale = cfg.scale || DEFAULT_SCALE; - const position = cfg.position || DEFAULT_POSITION; - const quaternion = (cfg.rotation - ? math.eulerToQuaternion(cfg.rotation, "XYZ", tempQuaternion) - : cfg.quaternion || DEFAULT_QUATERNION); - cfg.meshMatrix = math.composeMat4(position, quaternion, scale, math.mat4()); - } - - if (cfg.positionsDecodeBoundary) { - cfg.positionsDecodeMatrix = createPositionsDecodeMatrix(cfg.positionsDecodeBoundary, math.mat4()); - } - - // RTC && COMPRESSION - - if (cfg.positions) { - const rtcPositions = []; - const rtcNeeded = worldToRTCPositions(cfg.positions, rtcPositions, tempVec3a$c); - if (rtcNeeded) { - cfg.positions = rtcPositions; - cfg.origin = math.addVec3(cfg.origin, tempVec3a$c, math.vec3()); - } - - const aabb = math.collapseAABB3(); - if (useDTX) { - cfg.positionsDecodeMatrix = math.mat4(); - math.expandAABB3Points3(aabb, cfg.positions); - cfg.positionsCompressed = quantizePositions(cfg.positions, aabb, cfg.positionsDecodeMatrix); - } else { - if (cfg.meshMatrix) { - math.transformPositions3(cfg.meshMatrix, cfg.positions, cfg.positions); - cfg.meshMatrix = null; // Positions now baked, don't need any more - } - math.expandAABB3Points3(aabb, cfg.positions); - } - cfg.aabb = aabb; - } else if (cfg.positionsCompressed) { - const aabb = math.collapseAABB3(); - math.expandAABB3Points3(aabb, cfg.positionsCompressed); - geometryCompressionUtils.decompressAABB(aabb, cfg.positionsDecodeMatrix); - cfg.aabb = aabb; - } - - if (useDTX && cfg.buckets) { - const aabb = math.collapseAABB3(); - cfg.buckets.forEach(bucket => { - const positions = bucket.positions || bucket.positionsCompressed; - if (positions) { - math.expandAABB3Points3(aabb, positions); - } - }); - if (cfg.positionsDecodeMatrix) { - geometryCompressionUtils.decompressAABB(aabb, cfg.positionsDecodeMatrix); - } - cfg.aabb = aabb; - } - - // EDGES - - if (isTriangular && (! cfg.buckets)) { - cfg.edgeIndices ||= buildEdgeIndices(cfg.positions || cfg.positionsCompressed, cfg.indices, cfg.positions ? null : cfg.positionsDecodeMatrix, 2.0); - } - - } else { - - // INSTANCING - - cfg.positionsDecodeMatrix = cfg.geometry.positionsDecodeMatrix; - - cfg.aabb = math.AABB3(cfg.geometry.aabb); - - const transformId = cfg.transformId; - if (transformId) { - - // TRANSFORM - - cfg.transform = this._transforms[transformId]; - - if (!cfg.transform) { - this.error(`[createMesh] Transform not found: ${transformId} - ensure that you create it first with createTransform()`); - return false; - } - - } else { - - // MATRIX - - if (cfg.matrix) { - cfg.meshMatrix = cfg.matrix; - } else if (cfg.scale || cfg.rotation || cfg.position || cfg.quaternion) { - const scale = cfg.scale || DEFAULT_SCALE; - const position = cfg.position || DEFAULT_POSITION; - const quaternion = (cfg.rotation - ? math.eulerToQuaternion(cfg.rotation, "XYZ", tempQuaternion) - : cfg.quaternion || DEFAULT_QUATERNION); - cfg.meshMatrix = math.composeMat4(position, quaternion, scale, math.mat4()); - } - } - } - - if (cfg.meshMatrix) { - math.AABB3ToOBB3(cfg.aabb, tempOBB3); - math.transformOBB3(cfg.meshMatrix, tempOBB3, tempOBB3); - math.OBB3ToAABB3(tempOBB3, cfg.aabb); - } - - cfg.color = cfg.color ? new Uint8Array(cfg.color.slice(0, 3).map(v => Math.floor(v * 255))) : defaultCompressedColor; - cfg.opacity = Math.floor((cfg.opacity ?? 1) * 255); - - if (useDTX) { - cfg.type = DTX; - - // BUCKETING - if (instancing) { - cfg.buckets = this._dtxBuckets[geometryId]; // lazy generated, reused - } - if (!cfg.buckets) { - cfg.buckets = createDTXBuckets(instancing ? cfg.geometry : cfg, this._enableVertexWelding, this._enableIndexBucketing); - if (instancing) { - this._dtxBuckets[geometryId] = cfg.buckets; - } - } - - } else { - cfg.type = instancing ? VBO_INSTANCED : VBO_BATCHED; - - // PBR - cfg.metallic = Math.floor((cfg.metallic ?? 0) * 255); - cfg.roughness = Math.floor((cfg.roughness ?? 1) * 255); - - // TEXTURE - // cfg.textureSetId = cfg.textureSetId || DEFAULT_TEXTURE_SET_ID; - if (textureSetId) { - cfg.textureSet = this._textureSets[textureSetId]; - if ((! instancing) && (!cfg.textureSet)) { - this.error(`[createMesh] Texture set not found: ${textureSetId} - ensure that you create it first with createTextureSet()`); - return false; - } - } - } - - cfg.numPrimitives = this._getNumPrimitives(cfg); - - const mesh = new SceneModelMesh(this, cfg.id, cfg.color, cfg.opacity, cfg.transform, cfg.textureSet); - const pickId = this.scene._renderer.getPickID(mesh); - mesh.pickId = pickId; - mesh.origin = math.vec3(cfg.origin); - mesh.layer = (cfg.type === DTX) ? this._getDTXLayer(cfg) : this._getVBOLayer(cfg.type === VBO_INSTANCED, cfg); - mesh.aabb = cfg.aabb; - cfg.pickColor = new Uint8Array([pickId & 0xFF, pickId >> 8 & 0xFF, pickId >> 16 & 0xFF, pickId >> 24 & 0xFF]); // Quantized pick color - cfg.solid = (cfg.primitive === "solid"); - cfg.meshMatrix = cfg.transform ? cfg.transform.worldMatrix : cfg.meshMatrix; - mesh.portionId = mesh.layer.createPortion(mesh, cfg); - mesh.numPrimitives = cfg.numPrimitives; - this._meshes[cfg.id] = mesh; - this._unusedMeshes[cfg.id] = mesh; - this._meshList.push(mesh); - return mesh; - } - - _getNumPrimitives(cfg) { - let countIndices = 0; - const primitive = cfg.geometry ? cfg.geometry.primitive : cfg.primitive; - switch (primitive) { - case "triangles": - case "solid": - case "surface": - switch (cfg.type) { - case DTX: - for (let i = 0, len = cfg.buckets.length; i < len; i++) { - countIndices += cfg.buckets[i].indices.length; - } - break; - case VBO_BATCHED: - countIndices += cfg.indices.length; - break; - case VBO_INSTANCED: - countIndices += cfg.geometry.indices.length; - break; - } - return Math.round(countIndices / 3); - case "points": - switch (cfg.type) { - case DTX: - for (let i = 0, len = cfg.buckets.length; i < len; i++) { - countIndices += cfg.buckets[i].positionsCompressed.length; - } - break; - case VBO_BATCHED: - countIndices += cfg.positions ? cfg.positions.length : cfg.positionsCompressed.length; - break; - case VBO_INSTANCED: - const geometry = cfg.geometry; - countIndices += geometry.positions ? geometry.positions.length : geometry.positionsCompressed.length; - break; - } - return Math.round(countIndices); - case "lines": - case "line-strip": - switch (cfg.type) { - case DTX: - for (let i = 0, len = cfg.buckets.length; i < len; i++) { - countIndices += cfg.buckets[i].indices.length; - } - break; - case VBO_BATCHED: - countIndices += cfg.indices.length; - break; - case VBO_INSTANCED: - countIndices += cfg.geometry.indices.length; - break; - } - return Math.round(countIndices / 2); - } - return 0; - } - - _getDTXLayer(cfg) { - const origin = cfg.origin; - const primitive = cfg.geometry ? cfg.geometry.primitive : cfg.primitive; - const layerId = `.${primitive}.${Math.round(origin[0])}.${Math.round(origin[1])}.${Math.round(origin[2])}`; - let dtxLayer = this._dtxLayers[layerId]; - if (dtxLayer) { - if (!dtxLayer.canCreatePortion(cfg)) { - // dtxLayer.finalize(); - delete this._dtxLayers[layerId]; - dtxLayer = null; - } else { - return dtxLayer; - } - } - switch (primitive) { - case "triangles": - case "solid": - case "surface": - dtxLayer = new DTXLayer(this, primitive, origin); - break; - default: - return; - } - this._dtxLayers[layerId] = dtxLayer; - this.layerList.push(dtxLayer); - this._layersToFinalize.push(dtxLayer); - return dtxLayer; - } - - _getVBOLayer(instancing, cfg) { - const geometry = instancing && cfg.geometry; - const primitive = instancing ? geometry.primitive : cfg.primitive; - const origin = cfg.origin; - const posDecode = (! instancing) && (cfg.positionsDecodeMatrix || cfg.positionsDecodeBoundary); - const positionsDecodeHash = posDecode ? this._createHashStringFromMatrix(posDecode) : "-"; - const textureSetId = cfg.textureSetId || "-"; - const geometryId = instancing ? cfg.geometryId : "-"; - const layerId = (instancing ? "instancing" : "batching") + `.${Math.round(origin[0])}.${Math.round(origin[1])}.${Math.round(origin[2])}.${primitive}.${positionsDecodeHash}.${textureSetId}.${geometryId}.${((cfg.normalsCompressed || cfg.normals || [ ]).length > 0) ? "n" : "-"}`; - - if ((! instancing) && (layerId in this._vboLayers)) { - const layer = this._vboLayers[layerId]; - const lenPositions = cfg.positionsCompressed ? cfg.positionsCompressed.length : cfg.positions.length; - if (! layer.canCreatePortion(lenPositions, (primitive === "points") ? 0 : cfg.indices.length)) { - layer.finalize(); - delete this._vboLayers[layerId]; - } - } - - if (! (layerId in this._vboLayers)) { - const layer = new VBOLayer(this, primitive, origin, { - textureSet: cfg.textureSet, - ...(instancing ? { - geometry: geometry, - } : { - maxGeometryBatchSize: this._maxGeometryBatchSize, - positionsDecodeMatrix: cfg.positionsDecodeMatrix, // Can be undefined - uvDecodeMatrix: cfg.uvDecodeMatrix, // Can be undefined - }) - }); - this.layerList.push(layer); - this._layersToFinalize.push(layer); - this._vboLayers[layerId] = layer; - } - return this._vboLayers[layerId]; - } - - _createHashStringFromMatrix(matrix) { - const matrixString = matrix.join(";"); - let hash = 0; - for (let i = 0; i < matrixString.length; i++) { - const char = matrixString.charCodeAt(i); - hash = (hash << 5) - hash + char; - hash |= 0; // Convert to 32-bit integer - } - const hashString = (hash >>> 0).toString(16); - return hashString; - } - - /** - * Creates a {@link SceneModelEntity} within this SceneModel. - * - * * Gives the SceneModelEntity one or more {@link SceneModelMesh}es previously created with - * {@link SceneModel#createMesh}. A SceneModelMesh can only belong to one SceneModelEntity, so you'll get an - * error if you try to reuse a mesh among multiple SceneModelEntitys. - * * The SceneModelEntity can have a {@link SceneModelTextureSet}, previously created with - * {@link SceneModel#createTextureSet}. A SceneModelTextureSet can belong to multiple SceneModelEntitys. - * * The SceneModelEntity can have a geometry, previously created with - * {@link SceneModel#createTextureSet}. A geometry is a "virtual component" and can belong to multiple SceneModelEntitys. - * - * @param {Object} cfg SceneModelEntity configuration. - * @param {String} cfg.id Optional ID for the new SceneModelEntity. Must not clash with any existing components within the {@link Scene}. - * @param {String[]} cfg.meshIds IDs of one or more meshes created previously with {@link SceneModel@createMesh}. - * @param {Boolean} [cfg.isObject] Set ````true```` if the {@link SceneModelEntity} represents an object, in which case it will be registered by {@link SceneModelEntity#id} in {@link Scene#objects} and can also have a corresponding {@link MetaObject} with matching {@link MetaObject#id}, registered by that ID in {@link MetaScene#metaObjects}. - * @param {Boolean} [cfg.visible=true] Indicates if the SceneModelEntity is initially visible. - * @param {Boolean} [cfg.culled=false] Indicates if the SceneModelEntity is initially culled from view. - * @param {Boolean} [cfg.pickable=true] Indicates if the SceneModelEntity is initially pickable. - * @param {Boolean} [cfg.clippable=true] Indicates if the SceneModelEntity is initially clippable. - * @param {Boolean} [cfg.collidable=true] Indicates if the SceneModelEntity is initially included in boundary calculations. - * @param {Boolean} [cfg.castsShadow=true] Indicates if the SceneModelEntity initially casts shadows. - * @param {Boolean} [cfg.receivesShadow=true] Indicates if the SceneModelEntity initially receives shadows. - * @param {Boolean} [cfg.xrayed=false] Indicates if the SceneModelEntity is initially xrayed. XRayed appearance is configured by {@link SceneModel#xrayMaterial}. - * @param {Boolean} [cfg.highlighted=false] Indicates if the SceneModelEntity is initially highlighted. Highlighted appearance is configured by {@link SceneModel#highlightMaterial}. - * @param {Boolean} [cfg.selected=false] Indicates if the SceneModelEntity is initially selected. Selected appearance is configured by {@link SceneModel#selectedMaterial}. - * @param {Boolean} [cfg.edges=false] Indicates if the SceneModelEntity's edges are initially emphasized. Edges appearance is configured by {@link SceneModel#edgeMaterial}. - * @returns {SceneModelEntity} The new SceneModelEntity. - */ - createEntity(cfg) { - if (cfg.id === undefined) { - cfg.id = math.createUUID(); - } else if (this.scene.components[cfg.id]) { - this.error(`Scene already has a Component with this ID: ${cfg.id} - will assign random ID`); - cfg.id = math.createUUID(); - } - if (cfg.meshIds === undefined) { - this.error("Config missing: meshIds"); - return null; - } - - const notFalse = v => v !== false; - let flags = 0; - flags |= (this._visible && notFalse(cfg.visible) && ENTITY_FLAGS.VISIBLE); - flags |= (this._pickable && notFalse(cfg.pickable) && ENTITY_FLAGS.PICKABLE); - flags |= (this._culled && notFalse(cfg.culled) && ENTITY_FLAGS.CULLED); - flags |= (this._clippable && notFalse(cfg.clippable) && ENTITY_FLAGS.CLIPPABLE); - flags |= (this._collidable && notFalse(cfg.collidable) && ENTITY_FLAGS.COLLIDABLE); - flags |= (this._xrayed && notFalse(cfg.xrayed) && ENTITY_FLAGS.XRAYED); - flags |= (this._highlighted && notFalse(cfg.highlighted) && ENTITY_FLAGS.HIGHLIGHTED); - flags |= (this._selected && notFalse(cfg.selected) && ENTITY_FLAGS.SELECTED); - flags |= (this._edges && notFalse(cfg.edges) && ENTITY_FLAGS.EDGES); - cfg.flags = flags; - - let meshes = []; - for (let i = 0, len = cfg.meshIds.length; i < len; i++) { - const meshId = cfg.meshIds[i]; - let mesh = this._meshes[meshId]; // Trying to get already created mesh - if (!mesh) { // Checks if there is already created mesh for this meshId - this.error(`Mesh with this ID not found: "${meshId}" - ignoring this mesh`); // There is no such cfg - continue; - } - if (mesh.parent) { - this.error(`Mesh with ID "${meshId}" already belongs to object with ID "${mesh.parent.id}" - ignoring this mesh`); - continue; - } - meshes.push(mesh); - delete this._unusedMeshes[meshId]; - } - const lodCullable = true; - const entity = new SceneModelEntity( - this, - cfg.isObject, - cfg.id, - meshes, - cfg.flags, - lodCullable); // Internally sets SceneModelEntity#parent to this SceneModel - this._entityList.push(entity); - this._entities[cfg.id] = entity; - this._entitiesToFinalize.push(entity); - this.numEntities++; - return entity; - } - - /** - * Pre-renders all meshes that have been added, even if the SceneModel has not bee finalized yet. - * This is use for progressively showing the SceneModel while it is being loaded or constructed. - * @returns {boolean} - */ - preFinalize() { - if (this.destroyed) { - return false; - } - if (this._layersToFinalize.length === 0) { - return false; - } - this._createDummyEntityForUnusedMeshes(); - for (let i = 0, len = this._layersToFinalize.length; i < len; i++) { - const layer = this._layersToFinalize[i]; - layer.finalize(); - } - this._vboLayers = {}; - this._dtxLayers = {}; - this._layersToFinalize = []; - for (let i = 0, len = this._entitiesToFinalize.length; i < len; i++) { - const entity = this._entitiesToFinalize[i]; - entity._finalize(); - } - for (let i = 0, len = this._entitiesToFinalize.length; i < len; i++) { - const entity = this._entitiesToFinalize[i]; - entity._finalize2(); - } - this._entitiesToFinalize = []; - this.scene._aabbDirty = true; - this._viewMatrixDirty = true; - this._matrixDirty = true; - this._aabbDirty = true; - this._setWorldMatrixDirty(); - this._sceneModelDirty(); - this.position = this._position; - // Sort layers to reduce WebGL shader switching when rendering them - this.layerList.sort((a, b) => { - if (a.sortId < b.sortId) { - return -1; - } - if (a.sortId > b.sortId) { - return 1; - } - return 0; - }); - for (let i = 0, len = this.layerList.length; i < len; i++) { - const layer = this.layerList[i]; - layer.layerIndex = i; - } - this.glRedraw(); - this._layersFinalized = true; - } - - /** - * Finalizes this SceneModel. - * - * Once finalized, you can't add anything more to this SceneModel. - */ - finalize() { - if (this.destroyed) { - return; - } - this.preFinalize(); - this._geometries = {}; - this._dtxBuckets = {}; - this._textures = {}; - this._textureSets = {}; - } - - /** @private */ - stateSortCompare(drawable1, drawable2) { - } - - /** @private */ - rebuildRenderFlags() { - this.renderFlags.reset(); - this._updateRenderFlagsVisibleLayers(); - if (this.renderFlags.numLayers > 0 && this.renderFlags.numVisibleLayers === 0) { - this.renderFlags.culled = true; - return; - } - this._updateRenderFlags(); - } - - /** - * @private - */ - _updateRenderFlagsVisibleLayers() { - const renderFlags = this.renderFlags; - renderFlags.numLayers = this.layerList.length; - renderFlags.numVisibleLayers = 0; - for (let layerIndex = 0, len = this.layerList.length; layerIndex < len; layerIndex++) { - const layer = this.layerList[layerIndex]; - const layerVisible = this._getActiveSectionPlanesForLayer(layer); - if (layerVisible) { - renderFlags.visibleLayers[renderFlags.numVisibleLayers++] = layerIndex; - } - } - } - - /** @private */ - _createDummyEntityForUnusedMeshes() { - const unusedMeshIds = Object.keys(this._unusedMeshes); - if (unusedMeshIds.length > 0) { - const entityId = `${this.id}-${math.createUUID()}`; - this.warn(`Creating dummy SceneModelEntity "${entityId}" for unused SceneMeshes: [${unusedMeshIds.join(",")}]`); - this.createEntity({ - id: entityId, - meshIds: unusedMeshIds, - isObject: true - }); - } - this._unusedMeshes = {}; - } - - _getActiveSectionPlanesForLayer(layer) { - const renderFlags = this.renderFlags; - const sectionPlanes = this.scene._sectionPlanesState.sectionPlanes; - const numSectionPlanes = sectionPlanes.length; - const baseIndex = layer.layerIndex * numSectionPlanes; - if (numSectionPlanes > 0) { - for (let i = 0; i < numSectionPlanes; i++) { - const sectionPlane = sectionPlanes[i]; - if (!sectionPlane.active) { - renderFlags.sectionPlanesActivePerLayer[baseIndex + i] = false; - } else { - renderFlags.sectionPlanesActivePerLayer[baseIndex + i] = true; - renderFlags.sectioned = true; - } - } - } - return true; - } - - _updateRenderFlags() { - if (this.numVisibleLayerPortions === 0) { - return; - } - if (this.numCulledLayerPortions === this.numPortions) { - return; - } - const renderFlags = this.renderFlags; - renderFlags.colorOpaque = (this.numTransparentLayerPortions < this.numPortions); - if (this.numTransparentLayerPortions > 0) { - renderFlags.colorTransparent = true; - } - if (this.numXRayedLayerPortions > 0) { - const xrayMaterial = this.scene.xrayMaterial._state; - if (xrayMaterial.fill) { - if (xrayMaterial.fillAlpha < 1.0) { - renderFlags.xrayedSilhouetteTransparent = true; - } else { - renderFlags.xrayedSilhouetteOpaque = true; - } - } - if (xrayMaterial.edges) { - if (xrayMaterial.edgeAlpha < 1.0) { - renderFlags.xrayedEdgesTransparent = true; - } else { - renderFlags.xrayedEdgesOpaque = true; - } - } - } - if (this.numEdgesLayerPortions > 0) { - const edgeMaterial = this.scene.edgeMaterial._state; - if (edgeMaterial.edges) { - renderFlags.edgesOpaque = (this.numTransparentLayerPortions < this.numPortions); - if (this.numTransparentLayerPortions > 0) { - renderFlags.edgesTransparent = true; - } - } - } - if (this.numSelectedLayerPortions > 0) { - const selectedMaterial = this.scene.selectedMaterial._state; - if (selectedMaterial.fill) { - if (selectedMaterial.fillAlpha < 1.0) { - renderFlags.selectedSilhouetteTransparent = true; - } else { - renderFlags.selectedSilhouetteOpaque = true; - } - } - if (selectedMaterial.edges) { - if (selectedMaterial.edgeAlpha < 1.0) { - renderFlags.selectedEdgesTransparent = true; - } else { - renderFlags.selectedEdgesOpaque = true; - } - } - } - if (this.numHighlightedLayerPortions > 0) { - const highlightMaterial = this.scene.highlightMaterial._state; - if (highlightMaterial.fill) { - if (highlightMaterial.fillAlpha < 1.0) { - renderFlags.highlightedSilhouetteTransparent = true; - } else { - renderFlags.highlightedSilhouetteOpaque = true; - } - } - if (highlightMaterial.edges) { - if (highlightMaterial.edgeAlpha < 1.0) { - renderFlags.highlightedEdgesTransparent = true; - } else { - renderFlags.highlightedEdgesOpaque = true; - } - } - } - } - - // -------------- RENDERING --------------------------------------------------------------------------------------- - - - /** - * @private - */ - _withEachVisibleLayer(frameCtx, testNumVisibleLayerPortions, cb) { - if (testNumVisibleLayerPortions && (this.numVisibleLayerPortions === 0)) { - return; - } - const activeSectionPlanes = this.scene._sectionPlanesState.sectionPlanes.filter(p => p.active); - const testLayerCull = frameCtx.testAABB; - const renderFlags = this.renderFlags; - for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) { - const layer = this.layerList[renderFlags.visibleLayers[i]]; - const aabb = layer.getAABB(); - if (((! testLayerCull) || testLayerCull(aabb)) && activeSectionPlanes.every(p => math.planeAABB3Intersect(p.dir, p.dist, aabb) >= 0)) { - cb(layer); - } - } - } - - drawColorOpaque (frameCtx) { this._withEachVisibleLayer(frameCtx, false, layer => layer.drawColorOpaque (this.renderFlags, frameCtx)); } - drawColorTransparent (frameCtx) { this._withEachVisibleLayer(frameCtx, false, layer => layer.drawColorTransparent (this.renderFlags, frameCtx)); } - drawDepth (frameCtx) { this._withEachVisibleLayer(frameCtx, false, layer => layer.drawDepth (this.renderFlags, frameCtx)); } // Dedicated to SAO because it skips transparent objects - drawSilhouetteXRayed (frameCtx) { this._withEachVisibleLayer(frameCtx, false, layer => layer.drawSilhouetteXRayed (this.renderFlags, frameCtx)); } - drawSilhouetteHighlighted(frameCtx) { this._withEachVisibleLayer(frameCtx, false, layer => layer.drawSilhouetteHighlighted(this.renderFlags, frameCtx)); } - drawSilhouetteSelected (frameCtx) { this._withEachVisibleLayer(frameCtx, false, layer => layer.drawSilhouetteSelected (this.renderFlags, frameCtx)); } - drawEdgesColorOpaque (frameCtx) { this._withEachVisibleLayer(frameCtx, false, layer => layer.drawEdgesColorOpaque (this.renderFlags, frameCtx)); } - drawEdgesColorTransparent(frameCtx) { this._withEachVisibleLayer(frameCtx, false, layer => layer.drawEdgesColorTransparent(this.renderFlags, frameCtx)); } - drawEdgesXRayed (frameCtx) { this._withEachVisibleLayer(frameCtx, false, layer => layer.drawEdgesXRayed (this.renderFlags, frameCtx)); } - drawEdgesHighlighted (frameCtx) { this._withEachVisibleLayer(frameCtx, false, layer => layer.drawEdgesHighlighted (this.renderFlags, frameCtx)); } - drawEdgesSelected (frameCtx) { this._withEachVisibleLayer(frameCtx, false, layer => layer.drawEdgesSelected (this.renderFlags, frameCtx)); } - drawOcclusion (frameCtx) { this._withEachVisibleLayer(frameCtx, true, layer => layer.drawOcclusion (this.renderFlags, frameCtx)); } - drawShadow (frameCtx) { this._withEachVisibleLayer(frameCtx, true, layer => layer.drawShadow (this.renderFlags, frameCtx)); } - drawPickMesh (frameCtx) { this._withEachVisibleLayer(frameCtx, true, layer => layer.drawPickMesh (this.renderFlags, frameCtx)); } - drawPickDepths (frameCtx) { this._withEachVisibleLayer(frameCtx, true, layer => layer.drawPickDepths (this.renderFlags, frameCtx)); } - drawPickNormals (frameCtx) { this._withEachVisibleLayer(frameCtx, true, layer => layer.drawPickNormals (this.renderFlags, frameCtx)); } - _drawSnap (frameCtx, isSnapInit) { this._withEachVisibleLayer(frameCtx, true, layer => layer.drawSnap (this.renderFlags, frameCtx, isSnapInit)); } - - drawSnapInit(frameCtx) { this._drawSnap(frameCtx, true ); } - drawSnap (frameCtx) { this._drawSnap(frameCtx, false); } - - /** - * Destroys this SceneModel. - */ - destroy() { - Object.values(this._vboLayers).forEach(l => l.destroy()); - this._vboLayers = {}; - this.scene.camera.off(this._onCameraViewMatrix); - this.scene.off(this._onTick); - for (let i = 0, len = this.layerList.length; i < len; i++) { - this.layerList[i].destroy(); - } - this.layerList = []; - for (let i = 0, len = this._entityList.length; i < len; i++) { - this._entityList[i]._destroy(); - } - this._layersToFinalize = []; - // Object.entries(this._geometries).forEach(([id, geometry]) => { - // geometry.destroy(); - // }); - this._geometries = {}; - this._dtxBuckets = {}; - this._textures = {}; - this._textureSets = {}; - this._meshes = {}; - this._entities = {}; - this.scene._aabbDirty = true; - if (this._isModel) { - this.scene._deregisterModel(this); - } - super.destroy(); - } -} - - -/** - * This function applies two steps to the provided mesh geometry data: - * - * - 1st, it reduces its `.positions` to unique positions, thus removing duplicate vertices. It will adjust the `.indices` and `.edgeIndices` array accordingly to the unique `.positions`. - * - * - 2nd, it tries to do an optimization called `index rebucketting` - * - * _Rebucketting minimizes the amount of RAM usage for a given mesh geometry by trying do demote its needed index bitness._ - * - * - _for 32 bit indices, will try to demote them to 16 bit indices_ - * - _for 16 bit indices, will try to demote them to 8 bits indices_ - * - _8 bits indices are kept as-is_ - * - * The fact that 32/16/8 bits are needed for indices, depends on the number of maximumm indexable vertices within the mesh geometry: this is, the number of vertices in the mesh geometry. - * - * The function returns the same provided input `geometry`, enrichened with the additional key `.preparedBukets`. - * - * @param {object} geometry The mesh information containing `.positions`, `.indices`, `.edgeIndices` arrays. - * - * @param enableVertexWelding - * @param enableIndexBucketing - * @returns {object} The mesh information enrichened with `.buckets` key. - */ -function createDTXBuckets(geometry, enableVertexWelding, enableIndexBucketing) { - let uniquePositionsCompressed, uniqueIndices, uniqueEdgeIndices; - if (enableVertexWelding || enableIndexBucketing) { // Expensive - careful! - [ - uniquePositionsCompressed, - uniqueIndices, - uniqueEdgeIndices, - ] = uniquifyPositions({ - positionsCompressed: geometry.positionsCompressed, - indices: geometry.indices, - edgeIndices: geometry.edgeIndices - }); - } else { - uniquePositionsCompressed = geometry.positionsCompressed; - uniqueIndices = geometry.indices; - uniqueEdgeIndices = geometry.edgeIndices; - } - let buckets; - if (enableIndexBucketing) { - let numUniquePositions = uniquePositionsCompressed.length / 3; - buckets = rebucketPositions({ - positionsCompressed: uniquePositionsCompressed, - indices: uniqueIndices, - edgeIndices: uniqueEdgeIndices, - }, - (numUniquePositions > (1 << 16)) ? 16 : 8, - // true - ); - } else { - buckets = [{ - positionsCompressed: uniquePositionsCompressed, - indices: uniqueIndices, - edgeIndices: uniqueEdgeIndices, - }]; - } - return buckets; -} - -/** - * A set of 3D line segments. - * - * * Creates a set of 3D line segments. - * * Registered by {@link LineSet#id} in {@link Scene#lineSets}. - * * Configure color using the {@link LinesMaterial} located at {@link Scene#linesMaterial}. - * * {@link BCFViewpointsPlugin} will save and load Linesets in BCF viewpoints. - * - * ## Usage - * - * In the example below, we'll load the Schependomlaan model, then use - * a ````LineSet```` to show a grid underneath the model. - * - * [](https://xeokit.github.io/xeokit-sdk/examples/scenegraph/#LineSet_grid) - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/scenegraph/#LineSet_grid)] - * - * ````javascript - * import {Viewer, XKTLoaderPlugin, LineSet, buildGridGeometry} from "https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/xeokit-sdk.es.min.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * const camera = viewer.camera; - * - * viewer.camera.eye = [-2.56, 8.38, 8.27]; - * viewer.camera.look = [13.44, 3.31, -14.83]; - * viewer.camera.up = [0.10, 0.98, -0.14]; - * - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * const model = xktLoader.load({ - * id: "myModel", - * src: "../assets/models/xkt/v8/ifc/Schependomlaan.ifc.xkt", - * position: [0,1,0], - * edges: true, - * saoEnabled: true - * }); - * - * const geometryArrays = buildGridGeometry({ - * size: 100, - * divisions: 30 - * }); - * - * new LineSet(viewer.scene, { - * positions: geometryArrays.positions, - * indices: geometryArrays.indices - * }); - * ```` - */ -class LineSet extends Component { - - /** - * Creates a new LineSet. - * - * Registers the LineSet in {@link Scene#lineSets}; causes Scene to fire a "lineSetCreated" event. - * - * @constructor - * @param {Component} [owner] Owner component. When destroyed, the owner will destroy this ````LineSet```` as well. - * @param {*} [cfg] ````LineSet```` configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} cfg.positions World-space 3D vertex positions. - * @param {Number[]} [cfg.indices] Indices to connect ````positions```` into line segments. Note that these are separate line segments, not a polyline. - * @param {Number[]} [cfg.color=[1,1,1]] The color of this ````LineSet````. This is both emissive and diffuse. - * @param {Boolean} [cfg.visible=true] Indicates whether or not this ````LineSet```` is visible. - * @param {Number} [cfg.opacity=1.0] ````LineSet````'s initial opacity factor. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._positions = cfg.positions || []; - - if (cfg.indices) { - this._indices = cfg.indices; - } else { - this._indices = []; - for (let i = 0, len = (this._positions.length / 3) - 1; i < len; i += 2) { - this._indices.push(i); - this._indices.push(i + 1); - } - } - - this._color = cfg.color || [1, 1, 1]; - this._opacity = cfg.opacity || 1.0; - - this._sceneModel = new SceneModel(this, { - isModel: false // Don't register in Scene.models - }); - - this._sceneModel.createMesh({ - id: "linesMesh", - primitive: "lines", - positions: this._positions, - indices: this._indices, - color: this._color, - opacity: this._opacity, - }); - - this._sceneModel.createEntity({ - meshIds: ["linesMesh"], - visible: cfg.visible, - clippable: cfg.clippable, - collidable: cfg.collidable - }); - - this._sceneModel.finalize(); - - this.scene._lineSetCreated(this); - } - - /** - * Sets if this ````LineSet```` is visible. - * - * Default value is ````true````. - * - * @param {Boolean} visible Set ````true```` to make this ````LineSet```` visible. - */ - set visible(visible) { - this._sceneModel.visible = visible; - } - - /** - * Gets if this ````LineSet```` is visible. - * - * Default value is ````true````. - * - * @returns {Boolean} Returns ````true```` if visible. - */ - get visible() { - return this._sceneModel.visible; - } - - /** - * Gets the 3D World-space vertex positions of the lines in this ````LineSet````. - * - * @returns {Number[]} - */ - get positions() { - return this._positions; - } - - /** - * Gets the vertex indices of the lines in this ````LineSet````. - * - * @returns {Number[]} - */ - get indices() { - return this._indices; - } - - /** - * Destroys this ````LineSet````. - * - * Removes the ```LineSet```` from {@link Scene#lineSets}; causes Scene to fire a "lineSetDestroyed" event. - */ - destroy() { - super.destroy(); // destroyes _sceneModel - this.scene._lineSetDestroyed(this); - } -} - -/** - * @desc A dynamic light source within a {@link Scene}. - * - * These are registered by {@link Light#id} in {@link Scene#lights}. - */ -class Light extends Component { - - /** - @private - */ - get type() { - return "Light"; - } - - /** - * @private - */ - get isLight() { - return true; - } - - constructor(owner, cfg = {}) { - super(owner, cfg); - } -} - -/** - * @desc An ambient light source of fixed color and intensity that illuminates all {@link Mesh}es equally. - * - * * {@link AmbientLight#color} multiplies by {@link PhongMaterial#ambient} at each position of each {@link ReadableGeometry} surface. - * * {@link AmbientLight#color} multiplies by {@link LambertMaterial#color} uniformly across each triangle of each {@link ReadableGeometry} (ie. flat shaded). - * * {@link AmbientLight}s, {@link DirLight}s and {@link PointLight}s are registered by their {@link Component#id} on {@link Scene#lights}. - * - * ## Usage - * - * In the example below we'll destroy the {@link Scene}'s default light sources then create an AmbientLight and a couple of {@link @DirLight}s: - * - * [[Run this example](/examples/index.html#lights_AmbientLight)] - * - * ````javascript - * import {Viewer, Mesh, buildTorusGeometry, - * ReadableGeometry, PhongMaterial, Texture, AmbientLight} from "xeokit-sdk.es.js"; - * - * // Create a Viewer and arrange the camera - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [0, 0, 5]; - * viewer.scene.camera.look = [0, 0, 0]; - * viewer.scene.camera.up = [0, 1, 0]; - * - * // Replace the Scene's default lights with a single custom AmbientLight - * - * viewer.scene.clearLights(); - * - * new AmbientLight(viewer.scene, { - * color: [0.0, 0.3, 0.7], - * intensity: 1.0 - * }); - * - * new DirLight(viewer.scene, { - * id: "keyLight", - * dir: [0.8, -0.6, -0.8], - * color: [1.0, 0.3, 0.3], - * intensity: 1.0, - * space: "view" - * }); - * - * new DirLight(viewer.scene, { - * id: "fillLight", - * dir: [-0.8, -0.4, -0.4], - * color: [0.3, 1.0, 0.3], - * intensity: 1.0, - * space: "view" - * }); - * - * new DirLight(viewer.scene, { - * id: "rimLight", - * dir: [0.2, -0.8, 0.8], - * color: [0.6, 0.6, 0.6], - * intensity: 1.0, - * space: "view" - * }); - * - * // Create a mesh with torus shape and PhongMaterial - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildSphereGeometry({ - * center: [0, 0, 0], - * radius: 1.5, - * tube: 0.5, - * radialSegments: 32, - * tubeSegments: 24, - * arc: Math.PI * 2.0 - * }), - * material: new PhongMaterial(viewer.scene, { - * ambient: [1.0, 1.0, 1.0], - * shininess: 30, - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }) - * }) - * }); - * - * // Adjust the color of our AmbientLight - * - * var ambientLight = viewer.scene.lights["myAmbientLight"]; - * ambientLight.color = [1.0, 0.8, 0.8]; - *```` - */ -class AmbientLight extends Light { - - /** - @private - */ - get type() { - return "AmbientLight"; - } - - /** - * @param {Component} owner Owner component. When destroyed, the owner will destroy this AmbientLight as well. - * @param {*} [cfg] AmbientLight configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.color=[0.7, 0.7, 0.8]] The color of this AmbientLight. - * @param {Number} [cfg.intensity=[1.0]] The intensity of this AmbientLight, as a factor in range ````[0..1]````. - */ - constructor(owner, cfg = {}) { - super(owner, cfg); - this._state = { - type: "ambient", - color: math.vec3([0.7, 0.7, 0.7]), - intensity: 1.0 - }; - this.color = cfg.color; - this.intensity = cfg.intensity; - this.scene._lightCreated(this); - } - - /** - * Sets the RGB color of this AmbientLight. - * - * Default value is ````[0.7, 0.7, 0.8]````. - * - * @param {Number[]} color The AmbientLight's RGB color. - */ - set color(color) { - this._state.color.set(color || [0.7, 0.7, 0.8]); - this.glRedraw(); - } - - /** - * Gets the RGB color of this AmbientLight. - * - * Default value is ````[0.7, 0.7, 0.8]````. - * - * @returns {Number[]} The AmbientLight's RGB color. - */ - get color() { - return this._state.color; - } - - /** - * Sets the intensity of this AmbientLight. - * - * Default value is ````1.0```` for maximum intensity. - * - * @param {Number} intensity The AmbientLight's intensity. - */ - set intensity(intensity) { - this._state.intensity = intensity !== undefined ? intensity : 1.0; - this.glRedraw(); - } - - /** - * Gets the intensity of this AmbientLight. - * - * Default value is ````1.0```` for maximum intensity. - * - * @returns {Number} The AmbientLight's intensity. - */ - get intensity() { - return this._state.intensity; - } - - /** - * Destroys this AmbientLight. - */ - destroy() { - - super.destroy(); - - this.scene._lightDestroyed(this); - } -} - -/** - * @desc Represents a WebGL render buffer. - * @private - */ -class RenderBuffer { - - constructor(gl, colorFormats, hasDepthTexture) { - /** @type {WebGL2RenderingContext} */ - this.gl = gl; - this.allocated = false; - this.buffer = null; - this.bound = false; - this._colorFormats = colorFormats; - this._hasDepthTexture = hasDepthTexture; - } - - setSize(size) { - this.size = size; - } - - bind() { - const width = this.size[0]; - const height = this.size[1]; - - if (this.buffer && ((this.buffer.width !== width) || (this.buffer.height !== height))) { - this.buffer.cleanup(); - this.buffer = null; - } - - if (! this.buffer) { - this._allocateBuffer(width, height); - this.bound = false; - } - - if (! this.bound) { - const gl = this.gl; - gl.bindFramebuffer(gl.FRAMEBUFFER, this.buffer.framebuf); - this.bound = true; - } - } - - _allocateBuffer(width, height) { - const internalformats = this._colorFormats || []; - - const gl = this.gl; - - const createTexture = () => { - const tex = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, tex); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - return tex; - }; - - const colorTextures = ((internalformats.length > 0) ? internalformats : [ null ]).map(internalformat => { - const tex = createTexture(); - if (internalformat) { - gl.texStorage2D(gl.TEXTURE_2D, 1, internalformat, width, height); - } else { - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - } - return tex; - }); - - const renderbuf = gl.createRenderbuffer(); - gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuf); - gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT32F, width, height); - - const framebuf = gl.createFramebuffer(); - gl.bindFramebuffer(gl.FRAMEBUFFER, framebuf); - for (let i = 0; i < colorTextures.length; i++) { - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.TEXTURE_2D, colorTextures[i], 0); - } - if (internalformats.length > 0) { - gl.drawBuffers(colorTextures.map((_, i) => gl.COLOR_ATTACHMENT0 + i)); - } - - const depthTexture = this._hasDepthTexture && createTexture(); - if (depthTexture) { - gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT32F, width, height, 0, gl.DEPTH_COMPONENT, gl.FLOAT, null); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, depthTexture, 0); - } else { - gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, renderbuf); - } - - gl.bindTexture(gl.TEXTURE_2D, null); - gl.bindRenderbuffer(gl.RENDERBUFFER, null); - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - - // Verify framebuffer is OK - - gl.bindFramebuffer(gl.FRAMEBUFFER, framebuf); - if (!gl.isFramebuffer(framebuf)) { - throw "Invalid framebuffer"; - } - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - - const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER); - - switch (status) { - - case gl.FRAMEBUFFER_COMPLETE: - break; - - case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT: - throw "Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT"; - - case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: - throw "Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"; - - case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS: - throw "Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS"; - - case gl.FRAMEBUFFER_UNSUPPORTED: - throw "Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED"; - - default: - throw "Incomplete framebuffer: " + status; - } - - this.buffer = { - cleanup: () => { - colorTextures.forEach(texture => gl.deleteTexture(texture)); - depthTexture && gl.deleteTexture(depthTexture); - gl.deleteFramebuffer(framebuf); - gl.deleteRenderbuffer(renderbuf); - }, - framebuf: framebuf, - width: width, - height: height - }; - - this.colorTextures = colorTextures.map(tex => ({ - bind: function(unit) { - gl.activeTexture(gl["TEXTURE" + unit]); - gl.bindTexture(gl.TEXTURE_2D, tex); - return true; - } - })); - - this.depthTexture = depthTexture && { - bind: function(unit) { - gl.activeTexture(gl["TEXTURE" + unit]); - gl.bindTexture(gl.TEXTURE_2D, depthTexture); - return true; - } - }; - } - - read(pickX, pickY, glFormat = null, glType = null, arrayType = Uint8Array, arrayMultiplier = 4, colorBufferIndex = 0) { - const pix = new arrayType(arrayMultiplier); - const gl = this.gl; - gl.readBuffer(gl.COLOR_ATTACHMENT0 + colorBufferIndex); - gl.readPixels(pickX, this.buffer.height - pickY - 1, 1, 1, glFormat || gl.RGBA, glType || gl.UNSIGNED_BYTE, pix, 0); - return pix; - } - - unbind() { - const gl = this.gl; - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - this.bound = false; - } - - destroy() { - if (this.allocated) { - this.buffer.cleanup(); - this.allocated = false; - this.buffer = null; - this.bound = false; - } - this.colorTextures = null; - this.depthTexture = null; - } -} - -/** - * @desc A directional light source that illuminates all {@link Mesh}es equally from a given direction. - * - * * Has an emission direction vector in {@link DirLight#dir}, but no position. - * * Defined in either *World* or *View* coordinate space. When in World-space, {@link DirLight#dir} is relative to the - * World coordinate system, and will appear to move as the {@link Camera} moves. When in View-space, {@link DirLight#dir} is - * relative to the View coordinate system, and will behave as if fixed to the viewer's head. - * * {@link AmbientLight}s, {@link DirLight}s and {@link PointLight}s are registered by their {@link Component#id} on {@link Scene#lights}. - * - * ## Usage - * - * In the example below we'll replace the {@link Scene}'s default light sources with three View-space DirLights. - * - * [[Run this example](/examples/index.html#lights_DirLight_view)] - * - * ````javascript - * import {Viewer, Mesh, buildSphereGeometry, - * buildPlaneGeometry, ReadableGeometry, - * PhongMaterial, Texture, DirLight} from "xeokit-sdk.es.js"; - * - * // Create a Viewer and arrange the camera - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [0, 0, 5]; - * viewer.scene.camera.look = [0, 0, 0]; - * viewer.scene.camera.up = [0, 1, 0]; - * - * // Replace the Scene's default lights with three custom view-space DirLights - * - * viewer.scene.clearLights(); - * - * new DirLight(viewer.scene, { - * id: "keyLight", - * dir: [0.8, -0.6, -0.8], - * color: [1.0, 0.3, 0.3], - * intensity: 1.0, - * space: "view" - * }); - * - * new DirLight(viewer.scene, { - * id: "fillLight", - * dir: [-0.8, -0.4, -0.4], - * color: [0.3, 1.0, 0.3], - * intensity: 1.0, - * space: "view" - * }); - * - * new DirLight(viewer.scene, { - * id: "rimLight", - * dir: [0.2, -0.8, 0.8], - * color: [0.6, 0.6, 0.6], - * intensity: 1.0, - * space: "view" - * }); - * - * - * // Create a sphere and ground plane - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildSphereGeometry({ - * radius: 2.0 - * }), - * material: new PhongMaterial(viewer.scene, { - * diffuse: [0.7, 0.7, 0.7], - * specular: [1.0, 1.0, 1.0], - * emissive: [0, 0, 0], - * alpha: 1.0, - * ambient: [1, 1, 0], - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }) - * }) - * }); - * - * new Mesh(viewer.scene, { - * geometry: buildPlaneGeometry(ReadableGeometry, viewer.scene, { - * xSize: 30, - * zSize: 30 - * }), - * material: new PhongMaterial(viewer.scene, { - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }), - * backfaces: true - * }), - * position: [0, -2.1, 0] - * }); - * ```` - */ -class DirLight extends Light { - - /** - @private - */ - get type() { - return "DirLight"; - } - - /** - * @param {Component} owner Owner component. When destroyed, the owner will destroy this DirLight as well. - * @param {*} [cfg] The DirLight configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.dir=[1.0, 1.0, 1.0]] A unit vector indicating the direction that the light is shining, given in either World or View space, depending on the value of the ````space```` parameter. - * @param {Number[]} [cfg.color=[0.7, 0.7, 0.8 ]] The color of this DirLight. - * @param {Number} [cfg.intensity=1.0] The intensity of this DirLight, as a factor in range ````[0..1]````. - * @param {String} [cfg.space="view"] The coordinate system the DirLight is defined in - ````"view"```` or ````"world"````. - * @param {Boolean} [cfg.castsShadow=false] Flag which indicates if this DirLight casts a castsShadow. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._shadowRenderBuf = null; - this._shadowViewMatrix = null; - this._shadowProjMatrix = null; - this._shadowViewMatrixDirty = true; - this._shadowProjMatrixDirty = true; - - const camera = this.scene.camera; - const canvas = this.scene.canvas; - - this._onCameraViewMatrix = camera.on("viewMatrix", () => { - this._shadowViewMatrixDirty = true; - }); - - this._onCameraProjMatrix = camera.on("projMatrix", () => { - this._shadowProjMatrixDirty = true; - }); - - this._onCanvasBoundary = canvas.on("boundary", () => { - this._shadowProjMatrixDirty = true; - }); - - this._state = new RenderState({ - - type: "dir", - dir: math.vec3([1.0, 1.0, 1.0]), - color: math.vec3([0.7, 0.7, 0.8]), - intensity: 1.0, - space: cfg.space || "view", - castsShadow: false, - - getShadowViewMatrix: () => { - if (this._shadowViewMatrixDirty) { - if (!this._shadowViewMatrix) { - this._shadowViewMatrix = math.identityMat4(); - } - const camera = this.scene.camera; - const dir = this._state.dir; - const look = camera.look; - const eye = [look[0] - dir[0], look[1] - dir[1], look[2] - dir[2]]; - const up = [0, 1, 0]; - math.lookAtMat4v(eye, look, up, this._shadowViewMatrix); - this._shadowViewMatrixDirty = false; - } - return this._shadowViewMatrix; - }, - - getShadowProjMatrix: () => { - if (this._shadowProjMatrixDirty) { // TODO: Set when canvas resizes - if (!this._shadowProjMatrix) { - this._shadowProjMatrix = math.identityMat4(); - } - math.orthoMat4c(-40, 40, -40, 40, -40.0, 80, this._shadowProjMatrix); // left, right, bottom, top, near, far, dest - this._shadowProjMatrixDirty = false; - } - return this._shadowProjMatrix; - }, - - getShadowRenderBuf: () => { - if (!this._shadowRenderBuf) { - this._shadowRenderBuf = new RenderBuffer(this.scene.canvas.gl); // Super old mobile devices have a limit of 1024x1024 textures - this._shadowRenderBuf.setSize([1024, 1024]); - } - return this._shadowRenderBuf; - } - }); - - this.dir = cfg.dir; - this.color = cfg.color; - this.intensity = cfg.intensity; - this.castsShadow = cfg.castsShadow; - - this.scene._lightCreated(this); - } - - /** - * Sets the direction in which the DirLight is shining. - * - * Default value is ````[1.0, 1.0, 1.0]````. - * - * @param {Number[]} value The direction vector. - */ - set dir(value) { - this._state.dir.set(value || [1.0, 1.0, 1.0]); - this._shadowViewMatrixDirty = true; - this.glRedraw(); - } - - /** - * Gets the direction in which the DirLight is shining. - * - * Default value is ````[1.0, 1.0, 1.0]````. - * - * @returns {Number[]} The direction vector. - */ - get dir() { - return this._state.dir; - } - - /** - * Sets the RGB color of this DirLight. - * - * Default value is ````[0.7, 0.7, 0.8]````. - * - * @param {Number[]} color The DirLight's RGB color. - */ - set color(color) { - this._state.color.set(color || [0.7, 0.7, 0.8]); - this.glRedraw(); - } - - /** - * Gets the RGB color of this DirLight. - * - * Default value is ````[0.7, 0.7, 0.8]````. - * - * @returns {Number[]} The DirLight's RGB color. - */ - get color() { - return this._state.color; - } - - /** - * Sets the intensity of this DirLight. - * - * Default intensity is ````1.0```` for maximum intensity. - * - * @param {Number} intensity The DirLight's intensity - */ - set intensity(intensity) { - intensity = intensity !== undefined ? intensity : 1.0; - this._state.intensity = intensity; - this.glRedraw(); - } - - /** - * Gets the intensity of this DirLight. - * - * Default value is ````1.0```` for maximum intensity. - * - * @returns {Number} The DirLight's intensity. - */ - get intensity() { - return this._state.intensity; - } - - /** - * Sets if this DirLight casts a shadow. - * - * Default value is ````false````. - * - * @param {Boolean} castsShadow Set ````true```` to cast shadows. - */ - set castsShadow(castsShadow) { - castsShadow = !!castsShadow; - if (this._state.castsShadow === castsShadow) { - return; - } - this._state.castsShadow = castsShadow; - this._shadowViewMatrixDirty = true; - this.glRedraw(); - } - - /** - * Gets if this DirLight casts a shadow. - * - * Default value is ````false````. - * - * @returns {Boolean} ````true```` if this DirLight casts shadows. - */ - get castsShadow() { - return this._state.castsShadow; - } - - /** - * Destroys this DirLight. - */ - destroy() { - - const camera = this.scene.camera; - const canvas = this.scene.canvas; - camera.off(this._onCameraViewMatrix); - camera.off(this._onCameraProjMatrix); - canvas.off(this._onCanvasBoundary); - - super.destroy(); - this._state.destroy(); - if (this._shadowRenderBuf) { - this._shadowRenderBuf.destroy(); - } - this.scene._lightDestroyed(this); - this.glRedraw(); - } -} - -/** - * A positional light source that originates from a single point and spreads outward in all directions, with optional attenuation over distance. - * - * * Has a position in {@link PointLight#pos}, but no direction. - * * Defined in either *World* or *View* coordinate space. When in World-space, {@link PointLight#pos} is relative to - * the World coordinate system, and will appear to move as the {@link Camera} moves. When in View-space, - * {@link PointLight#pos} is relative to the View coordinate system, and will behave as if fixed to the viewer's head. - * * Has {@link PointLight#constantAttenuation}, {@link PointLight#linearAttenuation} and {@link PointLight#quadraticAttenuation} - * factors, which indicate how intensity attenuates over distance. - * * {@link AmbientLight}s, {@link PointLight}s and {@link PointLight}s are registered by their {@link Component#id} on {@link Scene#lights}. - * - * ## Usage - * - * In the example below we'll replace the {@link Scene}'s default light sources with three World-space PointLights. - * - * [[Run this example](/examples/index.html#lights_PointLight_world)] - * - * ````javascript - * import {Viewer, Mesh, buildSphereGeometry, buildPlaneGeometry, - * ReadableGeometry, PhongMaterial, Texture, PointLight} from "xeokit-sdk.es.js"; - * - * // Create a Viewer and arrange the camera - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [0, 0, 5]; - * viewer.scene.camera.look = [0, 0, 0]; - * viewer.scene.camera.up = [0, 1, 0]; - * - * // Replace the Scene's default lights with three custom world-space PointLights - * - * viewer.scene.clearLights(); - * - * new PointLight(viewer.scene,{ - * id: "keyLight", - * pos: [-80, 60, 80], - * color: [1.0, 0.3, 0.3], - * intensity: 1.0, - * space: "world" - * }); - * - * new PointLight(viewer.scene,{ - * id: "fillLight", - * pos: [80, 40, 40], - * color: [0.3, 1.0, 0.3], - * intensity: 1.0, - * space: "world" - * }); - * - * new PointLight(viewer.scene,{ - * id: "rimLight", - * pos: [-20, 80, -80], - * color: [0.6, 0.6, 0.6], - * intensity: 1.0, - * space: "world" - * }); - * - * // Create a sphere and ground plane - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildSphereGeometry({ - * radius: 1.3 - * }), - * material: new PhongMaterial(viewer.scene, { - * diffuse: [0.7, 0.7, 0.7], - * specular: [1.0, 1.0, 1.0], - * emissive: [0, 0, 0], - * alpha: 1.0, - * ambient: [1, 1, 0], - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }) - * }) - * }); - * - * new Mesh(viewer.scene, { - * geometry: buildPlaneGeometry(ReadableGeometry, viewer.scene, { - * xSize: 30, - * zSize: 30 - * }), - * material: new PhongMaterial(viewer.scene, { - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }), - * backfaces: true - * }), - * position: [0, -2.1, 0] - * }); - * ```` - */ -class PointLight extends Light { - - /** - @private - */ - get type() { - return "PointLight"; - } - - /** - * @param {Component} owner Owner component. When destroyed, the owner will destroy this PointLight as well. - * @param {*} [cfg] The PointLight configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.pos=[ 1.0, 1.0, 1.0 ]] Position, in either World or View space, depending on the value of the **space** parameter. - * @param {Number[]} [cfg.color=[0.7, 0.7, 0.8 ]] Color of this PointLight. - * @param {Number} [cfg.intensity=1.0] Intensity of this PointLight, as a factor in range ````[0..1]````. - * @param {Number} [cfg.constantAttenuation=0] Constant attenuation factor. - * @param {Number} [cfg.linearAttenuation=0] Linear attenuation factor. - * @param {Number} [cfg.quadraticAttenuation=0]Quadratic attenuation factor. - * @param {String} [cfg.space="view"]The coordinate system this PointLight is defined in - "view" or "world". - * @param {Boolean} [cfg.castsShadow=false] Flag which indicates if this PointLight casts a castsShadow. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - const self = this; - - this._shadowRenderBuf = null; - this._shadowViewMatrix = null; - this._shadowProjMatrix = null; - this._shadowViewMatrixDirty = true; - this._shadowProjMatrixDirty = true; - - const camera = this.scene.camera; - const canvas = this.scene.canvas; - - this._onCameraViewMatrix = camera.on("viewMatrix", () => { - this._shadowViewMatrixDirty = true; - }); - - this._onCameraProjMatrix = camera.on("projMatrix", () => { - this._shadowProjMatrixDirty = true; - }); - - this._onCanvasBoundary = canvas.on("boundary", () => { - this._shadowProjMatrixDirty = true; - }); - - this._state = new RenderState({ - - type: "point", - pos: math.vec3([1.0, 1.0, 1.0]), - color: math.vec3([0.7, 0.7, 0.8]), - intensity: 1.0, attenuation: [0.0, 0.0, 0.0], - space: cfg.space || "view", - castsShadow: false, - - getShadowViewMatrix: () => { - if (self._shadowViewMatrixDirty) { - if (!self._shadowViewMatrix) { - self._shadowViewMatrix = math.identityMat4(); - } - const eye = self._state.pos; - const look = camera.look; - const up = camera.up; - math.lookAtMat4v(eye, look, up, self._shadowViewMatrix); - self._shadowViewMatrixDirty = false; - } - return self._shadowViewMatrix; - }, - - getShadowProjMatrix: () => { - if (self._shadowProjMatrixDirty) { // TODO: Set when canvas resizes - if (!self._shadowProjMatrix) { - self._shadowProjMatrix = math.identityMat4(); - } - const canvas = self.scene.canvas.canvas; - math.perspectiveMat4(70 * (Math.PI / 180.0), canvas.clientWidth / canvas.clientHeight, 0.1, 500.0, self._shadowProjMatrix); - self._shadowProjMatrixDirty = false; - } - return self._shadowProjMatrix; - }, - - getShadowRenderBuf: () => { - if (!self._shadowRenderBuf) { - self._shadowRenderBuf = new RenderBuffer(self.scene.canvas.gl); // Super old mobile devices have a limit of 1024x1024 textures - self._shadowRenderBuf.setSize([1024, 1024]); - } - return self._shadowRenderBuf; - } - }); - - this.pos = cfg.pos; - this.color = cfg.color; - this.intensity = cfg.intensity; - this.constantAttenuation = cfg.constantAttenuation; - this.linearAttenuation = cfg.linearAttenuation; - this.quadraticAttenuation = cfg.quadraticAttenuation; - this.castsShadow = cfg.castsShadow; - - this.scene._lightCreated(this); - } - - /** - * Sets the position of this PointLight. - * - * This will be either World- or View-space, depending on the value of {@link PointLight#space}. - * - * Default value is ````[1.0, 1.0, 1.0]````. - * - * @param {Number[]} pos The position. - */ - set pos(pos) { - this._state.pos.set(pos || [1.0, 1.0, 1.0]); - this._shadowViewMatrixDirty = true; - this.glRedraw(); - } - - /** - * Gets the position of this PointLight. - * - * This will be either World- or View-space, depending on the value of {@link PointLight#space}. - * - * Default value is ````[1.0, 1.0, 1.0]````. - * - * @returns {Number[]} The position. - */ - get pos() { - return this._state.pos; - } - - /** - * Sets the RGB color of this PointLight. - * - * Default value is ````[0.7, 0.7, 0.8]````. - * - * @param {Number[]} color The PointLight's RGB color. - */ - set color(color) { - this._state.color.set(color || [0.7, 0.7, 0.8]); - this.glRedraw(); - } - - /** - * Gets the RGB color of this PointLight. - * - * Default value is ````[0.7, 0.7, 0.8]````. - * - * @returns {Number[]} The PointLight's RGB color. - */ - get color() { - return this._state.color; - } - - /** - * Sets the intensity of this PointLight. - * - * Default intensity is ````1.0```` for maximum intensity. - * - * @param {Number} intensity The PointLight's intensity - */ - set intensity(intensity) { - intensity = intensity !== undefined ? intensity : 1.0; - this._state.intensity = intensity; - this.glRedraw(); - } - - /** - * Gets the intensity of this PointLight. - * - * Default value is ````1.0```` for maximum intensity. - * - * @returns {Number} The PointLight's intensity. - */ - get intensity() { - return this._state.intensity; - } - - /** - * Sets the constant attenuation factor for this PointLight. - * - * Default value is ````0````. - * - * @param {Number} value The constant attenuation factor. - */ - set constantAttenuation(value) { - this._state.attenuation[0] = value || 0.0; - this.glRedraw(); - } - - /** - * Gets the constant attenuation factor for this PointLight. - * - * Default value is ````0````. - * - * @returns {Number} The constant attenuation factor. - */ - get constantAttenuation() { - return this._state.attenuation[0]; - } - - /** - * Sets the linear attenuation factor for this PointLight. - * - * Default value is ````0````. - * - * @param {Number} value The linear attenuation factor. - */ - set linearAttenuation(value) { - this._state.attenuation[1] = value || 0.0; - this.glRedraw(); - } - - /** - * Gets the linear attenuation factor for this PointLight. - * - * Default value is ````0````. - * - * @returns {Number} The linear attenuation factor. - */ - get linearAttenuation() { - return this._state.attenuation[1]; - } - - /** - * Sets the quadratic attenuation factor for this PointLight. - * - * Default value is ````0````. - * - * @param {Number} value The quadratic attenuation factor. - */ - set quadraticAttenuation(value) { - this._state.attenuation[2] = value || 0.0; - this.glRedraw(); - } - - /** - * Gets the quadratic attenuation factor for this PointLight. - * - * Default value is ````0````. - * - * @returns {Number} The quadratic attenuation factor. - */ - get quadraticAttenuation() { - return this._state.attenuation[2]; - } - - /** - * Sets if this PointLight casts a shadow. - * - * Default value is ````false````. - * - * @param {Boolean} castsShadow Set ````true```` to cast shadows. - */ - set castsShadow(castsShadow) { - castsShadow = !!castsShadow; - if (this._state.castsShadow === castsShadow) { - return; - } - this._state.castsShadow = castsShadow; - this._shadowViewMatrixDirty = true; - this.glRedraw(); - } - - /** - * Gets if this PointLight casts a shadow. - * - * Default value is ````false````. - * - * @returns {Boolean} ````true```` if this PointLight casts shadows. - */ - get castsShadow() { - return this._state.castsShadow; - } - - /** - * Destroys this PointLight. - */ - destroy() { - - const camera = this.scene.camera; - const canvas = this.scene.canvas; - camera.off(this._onCameraViewMatrix); - camera.off(this._onCameraProjMatrix); - canvas.off(this._onCanvasBoundary); - - super.destroy(); - - this._state.destroy(); - if (this._shadowRenderBuf) { - this._shadowRenderBuf.destroy(); - } - this.scene._lightDestroyed(this); - this.glRedraw(); - } -} - -function ensureImageSizePowerOfTwo(image) { - if (!isPowerOfTwo(image.width) || !isPowerOfTwo(image.height)) { - const canvas = document.createElement("canvas"); - canvas.width = nextHighestPowerOfTwo(image.width); - canvas.height = nextHighestPowerOfTwo(image.height); - const ctx = canvas.getContext("2d"); - ctx.drawImage(image, - 0, 0, image.width, image.height, - 0, 0, canvas.width, canvas.height); - image = canvas; - } - return image; -} - -function isPowerOfTwo(x) { - return (x & (x - 1)) === 0; -} - -function nextHighestPowerOfTwo(x) { - --x; - for (let i = 1; i < 32; i <<= 1) { - x = x | x >> i; - } - return x + 1; -} - -/** - * @desc A cube texture map. - */ -class CubeTexture extends Component { - - /** - @private - */ - get type() { - return "CubeTexture"; - } - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID for this CubeTexture, unique among all components in the parent scene, generated automatically when omitted. - * @param {String[]} [cfg.src=null] Paths to six image files to load into this CubeTexture. - * @param {Boolean} [cfg.flipY=false] Flips this CubeTexture's source data along its vertical axis when true. - * @param {Number} [cfg.encoding=LinearEncoding] Encoding format. Supported values are {@link LinearEncoding} and {@link sRGBEncoding}. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - const gl = this.scene.canvas.gl; - - this._state = new RenderState({ - texture: new Texture2D({gl, target: gl.TEXTURE_CUBE_MAP}), - flipY: this._checkFlipY(cfg.minFilter), - encoding: this._checkEncoding(cfg.encoding), - minFilter: LinearMipmapLinearFilter, - magFilter: LinearFilter, - wrapS: ClampToEdgeWrapping, - wrapT: ClampToEdgeWrapping, - mipmaps: true - }); - - this._src = cfg.src; - this._images = []; - - this._loadSrc(cfg.src); - - stats.memory.textures++; - } - - _checkFlipY(value) { - return !!value; - } - - _checkEncoding(value) { - value = value || LinearEncoding; - if (value !== LinearEncoding && value !== sRGBEncoding) { - this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."); - value = LinearEncoding; - } - return value; - } - - _loadSrc(src) { - const self = this; - const gl = this.scene.canvas.gl; - this._images = []; - let loadFailed = false; - let numLoaded = 0; - for (let i = 0; i < src.length; i++) { - const image = new Image(); - image.onload = (function () { - let _image = image; - const index = i; - return function () { - if (loadFailed) { - return; - } - _image = ensureImageSizePowerOfTwo(_image); - self._images[index] = _image; - numLoaded++; - if (numLoaded === 6) { - let texture = self._state.texture; - if (!texture) { - texture = new Texture2D({gl, target: gl.TEXTURE_CUBE_MAP}); - self._state.texture = texture; - } - texture.setImage(self._images, self._state); - self.fire("loaded", self._src, false); - self.glRedraw(); - } - }; - })(); - image.onerror = function () { - loadFailed = true; - }; - image.src = src[i]; - } - } - - /** - * Destroys this CubeTexture - * - */ - destroy() { - super.destroy(); - if (this._state.texture) { - this._state.texture.destroy(); - } - stats.memory.textures--; - this._state.destroy(); - } -} - -/** - * @desc A reflection cube map. - * - * ## Usage - * - * ````javascript - * import {Viewer, Mesh, buildSphereGeometry, - * ReadableGeometry, MetallicMaterial, ReflectionMap} from "xeokit-sdk.es.js"; - * - * // Create a Viewer and arrange the camera - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [0, 0, 5]; - * viewer.scene.camera.look = [0, 0, 0]; - * viewer.scene.camera.up = [0, 1, 0]; - * - * new ReflectionMap(viewer.scene, { - * src: [ - * "textures/reflect/Uffizi_Gallery/Uffizi_Gallery_Radiance_PX.png", - * "textures/reflect/Uffizi_Gallery/Uffizi_Gallery_Radiance_NX.png", - * "textures/reflect/Uffizi_Gallery/Uffizi_Gallery_Radiance_PY.png", - * "textures/reflect/Uffizi_Gallery/Uffizi_Gallery_Radiance_NY.png", - * "textures/reflect/Uffizi_Gallery/Uffizi_Gallery_Radiance_PZ.png", - * "textures/reflect/Uffizi_Gallery/Uffizi_Gallery_Radiance_NZ.png" - * ] - * }); - * - * // Create a sphere and ground plane - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildSphereGeometry({ - * radius: 2.0 - * }), - * new MetallicMaterial(viewer.scene, { - * baseColor: [1, 1, 1], - * metallic: 1.0, - * roughness: 1.0 - * }) - * }); - * ```` - */ -class ReflectionMap extends CubeTexture { - - /** - @private - */ - get type() { - return "ReflectionMap"; - } - - /** - * @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID for this ReflectionMap, unique among all components in the parent scene, generated automatically when omitted. - * @param {String[]} [cfg.src=null] Paths to six image files to load into this ReflectionMap. - * @param {Boolean} [cfg.flipY=false] Flips this ReflectionMap's source data along its vertical axis when true. - * @param {Number} [cfg.encoding=LinearEncoding] Encoding format. Supported values are {@link LinearEncoding} and {@link sRGBEncoding}. - */ - constructor(owner, cfg = {}) { - super(owner, cfg); - this.scene._lightsState.addReflectionMap(this._state); - this.scene._reflectionMapCreated(this); - } - - /** - * Destroys this ReflectionMap. - */ - destroy() { - super.destroy(); - this.scene._reflectionMapDestroyed(this); - } -} - -/** - * @desc A **LightMap** specifies a cube texture light map. - * - * ## Usage - * - * ````javascript - * import {Viewer, Mesh, buildSphereGeometry, - * ReadableGeometry, MetallicMaterial, LightMap} from "xeokit-sdk.es.js"; - * - * // Create a Viewer and arrange the camera - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [0, 0, 5]; - * viewer.scene.camera.look = [0, 0, 0]; - * viewer.scene.camera.up = [0, 1, 0]; - * - * new LightMap(viewer.scene, { - * src: [ - * "textures/light/Uffizi_Gallery/Uffizi_Gallery_Irradiance_PX.png", - * "textures/light/Uffizi_Gallery/Uffizi_Gallery_Irradiance_NX.png", - * "textures/light/Uffizi_Gallery/Uffizi_Gallery_Irradiance_PY.png", - * "textures/light/Uffizi_Gallery/Uffizi_Gallery_Irradiance_NY.png", - * "textures/light/Uffizi_Gallery/Uffizi_Gallery_Irradiance_PZ.png", - * "textures/light/Uffizi_Gallery/Uffizi_Gallery_Irradiance_NZ.png" - * ] - * }); - * - * // Create a sphere and ground plane - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildSphereGeometry({ - * radius: 2.0 - * }), - * new MetallicMaterial(viewer.scene, { - * baseColor: [1, 1, 1], - * metallic: 1.0, - * roughness: 1.0 - * }) - * }); - * ```` - */ -class LightMap extends CubeTexture { - - /** - @private - */ - get type() { - return "LightMap"; - } - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID for this LightMap, unique among all components in the parent scene, generated automatically when omitted. - * @param {String:Object} [cfg.meta] Optional map of user-defined metadata to attach to this LightMap. - * @param {String[]} [cfg.src=null] Paths to six image files to load into this LightMap. - * @param {Boolean} [cfg.flipY=false] Flips this LightMap's source data along its vertical axis when true. - * @param {Number} [cfg.encoding=LinearEncoding] Encoding format. Supported values are {@link LinearEncoding} and {@link sRGBEncoding}. - */ - constructor(owner, cfg = {}) { - super(owner, cfg); - this.scene._lightMapCreated(this); - } - - destroy() { - super.destroy(); - this.scene._lightMapDestroyed(this); - } -} - -const tempVec4a$9 = math.vec4(); -const tempVec4b$8 = math.vec4(); - - -/** - * @desc Tracks the World, View and Canvas coordinates, and visibility, of a position within a {@link Scene}. - * - * ## Position - * - * A Marker holds its position in the World, View and Canvas coordinate systems in three properties: - * - * * {@link Marker#worldPos} holds the Marker's 3D World-space coordinates. This property can be dynamically updated. The Marker will fire a "worldPos" event whenever this property changes. - * * {@link Marker#viewPos} holds the Marker's 3D View-space coordinates. This property is read-only, and is automatically updated from {@link Marker#worldPos} and the current {@link Camera} position. The Marker will fire a "viewPos" event whenever this property changes. - * * {@link Marker#canvasPos} holds the Marker's 2D Canvas-space coordinates. This property is read-only, and is automatically updated from {@link Marker#canvasPos} and the current {@link Camera} position and projection. The Marker will fire a "canvasPos" event whenever this property changes. - * - * ## Visibility - * - * {@link Marker#visible} indicates if the Marker is currently visible. The Marker will fire a "visible" event whenever {@link Marker#visible} changes. - * - * This property will be ````false```` when: - * - * * {@link Marker#entity} is set to an {@link Entity}, and {@link Entity#visible} is ````false````, - * * {@link Marker#occludable} is ````true```` and the Marker is occluded by some {@link Entity} in the 3D view, or - * * {@link Marker#canvasPos} is outside the boundary of the {@link Canvas}. - * - * ## Usage - * - * In the example below, we'll create a Marker that's associated with a {@link Mesh} (which a type of {@link Entity}). - * - * We'll configure our Marker to - * become invisible whenever it's occluded by any Entities in the canvas. - * - * We'll also demonstrate how to query the Marker's visibility status and position (in the World, View and - * Canvas coordinate systems), and how to subscribe to change events on those properties. - * - * ````javascript - * import {Viewer, GLTFLoaderPlugin, Marker} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * // Create the torus Mesh - * // Recall that a Mesh is an Entity - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildTorusGeometry({ - * center: [0,0,0], - * radius: 1.0, - * tube: 0.5, - * radialSegments: 32, - * tubeSegments: 24, - * arc: Math.PI * 2.0 - * }), - * material: new PhongMaterial(viewer.scene, { - * diffuseMap: new Texture(viewer.scene, { - * src: "textures/diffuse/uvGrid2.jpg" - * }), - * backfaces: true - * }) - * }); - * - * // Create the Marker, associated with our Mesh Entity - * const myMarker = new Marker(viewer, { - * entity: entity, - * worldPos: [10,0,0], - * occludable: true - * }); - * - * // Get the Marker's current World, View and Canvas coordinates - * const worldPos = myMarker.worldPos; // 3D World-space position - * const viewPos = myMarker.viewPos; // 3D View-space position - * const canvasPos = myMarker.canvasPos; // 2D Canvas-space position - * - * const visible = myMarker.visible; - * - * // Listen for change of the Marker's 3D World-space position - * myMarker.on("worldPos", function(worldPos) { - * //... - * }); - * - * // Listen for change of the Marker's 3D View-space position, which happens - * // when either worldPos was updated or the Camera was moved - * myMarker.on("viewPos", function(viewPos) { - * //... - * }); - * - * // Listen for change of the Marker's 2D Canvas-space position, which happens - * // when worldPos or viewPos was updated, or Camera's projection was updated - * myMarker.on("canvasPos", function(canvasPos) { - * //... - * }); - * - * // Listen for change of Marker visibility. The Marker becomes invisible when it falls outside the canvas, - * // has an Entity that is also invisible, or when an Entity occludes the Marker's position in the 3D view. - * myMarker.on("visible", function(visible) { // Marker visibility has changed - * if (visible) { - * this.log("Marker is visible"); - * } else { - * this.log("Marker is invisible"); - * } - * }); - * - * // Listen for destruction of Marker - * myMarker.on("destroyed", () => { - * //... - * }); - * ```` - */ -class Marker extends Component { - - /** - * @constructor - * @param {Component} [owner] Owner component. When destroyed, the owner will destroy this Marker as well. - * @param {*} [cfg] Marker configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Entity} [cfg.entity] Entity to associate this Marker with. When the Marker has an Entity, then {@link Marker#visible} will always be ````false```` if {@link Entity#visible} is false. - * @param {Boolean} [cfg.occludable=false] Indicates whether or not this Marker is hidden (ie. {@link Marker#visible} is ````false```` whenever occluded by {@link Entity}s in the {@link Scene}. - * @param {Number[]} [cfg.worldPos=[0,0,0]] World-space 3D Marker position. - */ - constructor(owner, cfg) { - - super(owner, cfg); - - this._entity = null; - this._visible = null; - this._worldPos = math.vec3(); - this._origin = math.vec3(); - this._rtcPos = math.vec3(); - this._viewPos = math.vec3(); - this._canvasPos = math.vec2(); - this._occludable = false; - - this._onCameraViewMatrix = this.scene.camera.on("matrix", () => { - this._viewPosDirty = true; - this._needUpdate(); - }); - - this._onCameraProjMatrix = this.scene.camera.on("projMatrix", () => { - this._canvasPosDirty = true; - this._needUpdate(); - }); - - this._onEntityDestroyed = null; - this._onEntityModelDestroyed = null; - - this._renderer.addMarker(this); - - this.entity = cfg.entity; - this.worldPos = cfg.worldPos; - this.occludable = cfg.occludable; - } - - _update() { // this._needUpdate() schedules this for next tick - if (this._viewPosDirty) { - math.transformPoint3(this.scene.camera.viewMatrix, this._worldPos, this._viewPos); - this._viewPosDirty = false; - this._canvasPosDirty = true; - this.fire("viewPos", this._viewPos); - } - if (this._canvasPosDirty) { - tempVec4a$9.set(this._viewPos); - tempVec4a$9[3] = 1.0; - math.transformPoint4(this.scene.camera.projMatrix, tempVec4a$9, tempVec4b$8); - const aabb = this.scene.canvas.boundary; - this._canvasPos[0] = Math.floor((1 + tempVec4b$8[0] / tempVec4b$8[3]) * aabb[2] / 2); - this._canvasPos[1] = Math.floor((1 - tempVec4b$8[1] / tempVec4b$8[3]) * aabb[3] / 2); - this._canvasPosDirty = false; - this.fire("canvasPos", this._canvasPos); - } - } - - _setVisible(visible) { // Called by VisibilityTester and this._entity.on("destroyed"..) - if (this._visible === visible) ; - this._visible = visible; - this.fire("visible", this._visible); - } - - /** - * Sets the {@link Entity} this Marker is associated with. - * - * An Entity is optional. When the Marker has an Entity, then {@link Marker#visible} will always be ````false```` - * if {@link Entity#visible} is false. - * - * @type {Entity} - */ - set entity(entity) { - if (this._entity === entity) { - return; - } - this._cleanupDestroyedHandlers(); - this._entity = entity; - if (this._entity) { - if (this._entity.isSceneModelEntity) { - this._onEntityModelDestroyed = this._entity.model.on("destroyed", () => { // SceneModelEntity does not fire events, and cannot exist beyond its VBOSceneModel - this._entity = null; // Marker now may become visible, if it was synched to invisible Entity - this._onEntityModelDestroyed = null; - }); - } else { - this._onEntityDestroyed = this._entity.on("destroyed", () => { - this._entity = null; - this._onEntityDestroyed = null; - }); - } - } - this.fire("entity", this._entity, true /* forget */); - } - - /** - * Gets the {@link Entity} this Marker is associated with. - * - * @type {Entity} - */ - get entity() { - return this._entity; - } - - /** - * Sets whether occlusion testing is performed for this Marker. - * - * When this is ````true````, then {@link Marker#visible} will be ````false```` whenever the Marker is occluded by an {@link Entity} in the 3D view. - * - * The {@link Scene} periodically occlusion-tests all Markers on every 20th "tick" (which represents a rendered frame). We - * can adjust that frequency via property {@link Scene#ticksPerOcclusionTest}. - * - * @type {Boolean} - */ - set occludable(occludable) { - occludable = !!occludable; - if (occludable === this._occludable) { - return; - } - this._occludable = occludable; - if (this._occludable) { - this._renderer.markerWorldPosUpdated(this); - } - } - - /** - * Gets whether occlusion testing is performed for this Marker. - * - * When this is ````true````, then {@link Marker#visible} will be ````false```` whenever the Marker is occluded by an {@link Entity} in the 3D view. - * - * @type {Boolean} - */ - get occludable() { - return this._occludable; - } - - /** - * Sets the World-space 3D position of this Marker. - * - * Fires a "worldPos" event with new World position. - * - * @type {Number[]} - */ - set worldPos(worldPos) { - this._worldPos.set(worldPos || [0, 0, 0]); - worldToRTCPos(this._worldPos, this._origin, this._rtcPos); - if (this._occludable) { - this._renderer.markerWorldPosUpdated(this); - } - this._viewPosDirty = true; - this.fire("worldPos", this._worldPos); - this._needUpdate(); - } - - /** - * Gets the World-space 3D position of this Marker. - * - * @type {Number[]} - */ - get worldPos() { - return this._worldPos; - } - - /** - * Gets the RTC center of this Marker. - * - * This is automatically calculated from {@link Marker#worldPos}. - * - * @type {Number[]} - */ - get origin() { - return this._origin; - } - - /** - * Gets the RTC position of this Marker. - * - * This is automatically calculated from {@link Marker#worldPos}. - * - * @type {Number[]} - */ - get rtcPos() { - return this._rtcPos; - } - - /** - * View-space 3D coordinates of this Marker. - * - * This property is read-only and is automatically calculated from {@link Marker#worldPos} and the current {@link Camera} position. - * - * The Marker fires a "viewPos" event whenever this property changes. - * - * @type {Number[]} - * @final - */ - get viewPos() { - this._update(); - return this._viewPos; - } - - /** - * Canvas-space 2D coordinates of this Marker. - * - * This property is read-only and is automatically calculated from {@link Marker#worldPos} and the current {@link Camera} position and projection. - * - * The Marker fires a "canvasPos" event whenever this property changes. - * - * @type {Number[]} - * @final - */ - get canvasPos() { - this._update(); - return this._canvasPos; - } - - /** - * Indicates if this Marker is currently visible. - * - * This is read-only and is automatically calculated. - * - * The Marker is **invisible** whenever: - * - * * {@link Marker#canvasPos} is currently outside the canvas, - * * {@link Marker#entity} is set to an {@link Entity} that has {@link Entity#visible} ````false````, or - * * or {@link Marker#occludable} is ````true```` and the Marker is currently occluded by an Entity in the 3D view. - * - * The Marker fires a "visible" event whenever this property changes. - * - * @type {Boolean} - * @final - */ - get visible() { - return !!this._visible; - } - - /** - * Destroys this Marker. - */ - destroy() { - this.fire("destroyed", true); - this.scene.camera.off(this._onCameraViewMatrix); - this.scene.camera.off(this._onCameraProjMatrix); - this._cleanupDestroyedHandlers(); - this._renderer.removeMarker(this); - super.destroy(); - } - - _cleanupDestroyedHandlers() { - if (this._entity) { - if (this._onEntityDestroyed !== null) { - if (this._entity.model) { - this._entity.model.off(this._onEntityDestroyed); - } else { - this._entity.off(this._onEntityDestroyed); - } - this._onEntityDestroyed = null; - } - if (this._onEntityModelDestroyed !== null) { - if (this._entity.model) { - this._entity.model.off(this._onEntityModelDestroyed); - } - this._onEntityModelDestroyed = null; - } - } - } -} - -/** - * A {@link Marker} with a billboarded and textured quad attached to it. - * - * * Extends {@link Marker} - * * Keeps the quad oriented towards the viewpoint - * * Auto-fits the quad to the texture - * * Has a world-space position - * * Can be configured to hide the quad whenever the position is occluded by some other object - * - * ## Usage - * - * [[Run this example](/examples/index.html#markers_SpriteMarker)] - * - * ```` javascript - * import {Viewer, SpriteMarker } from "./https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/xeokit-sdk.es.min.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.scene.camera.eye = [0, 0, 25]; - * viewer.scene.camera.look = [0, 0, 0]; - * viewer.scene.camera.up = [0, 1, 0]; - * - * new SpriteMarker(viewer.scene, { - * worldPos: [-10, 0, 0], - * src: "../assets/textures/diffuse/uvGrid2_512x1024.jpg", - * size: 5, - * occludable: false - * }); - * - * new SpriteMarker(viewer.scene, { - * worldPos: [+10, 0, 0], - * src: "../assets/textures/diffuse/uvGrid2_1024x512.jpg", - * size: 4, - * occludable: false - * }); - *```` - */ -class SpriteMarker extends Marker { - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this SpriteMarker as well. - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID for this SpriteMarker, unique among all components in the parent scene, generated automatically when omitted. - * @param {Entity} [cfg.entity] Entity to associate this Marker with. When the SpriteMarker has an Entity, then {@link Marker#visible} will always be ````false```` if {@link Entity#visible} is false. - * @param {Boolean} [cfg.occludable=false] Indicates whether or not this Marker is hidden (ie. {@link Marker#visible} is ````false```` whenever occluded by {@link Entity}s in the {@link Scene}. - * @param {Number[]} [cfg.worldPos=[0,0,0]] World-space 3D Marker position. - * @param {String} [cfg.src=null] Path to image file to load into this SpriteMarker. See the {@link SpriteMarker#src} property for more info. - * @param {HTMLImageElement} [cfg.image=null] HTML Image object to load into this SpriteMarker. See the {@link SpriteMarker#image} property for more info. - * @param {Boolean} [cfg.flipY=false] Flips this SpriteMarker's texture image along its vertical axis when true. - * @param {String} [cfg.encoding="linear"] Texture encoding format. See the {@link Texture#encoding} property for more info. - */ - constructor(owner, cfg = {}) { - - super(owner, { - entity: cfg.entity, - occludable: cfg.occludable, - worldPos: cfg.worldPos - }); - - this._occluded = false; - this._visible = true; - this._src = null; - this._image = null; - this._pos = math.vec3(); - this._origin = math.vec3(); - this._rtcPos = math.vec3(); - this._dir = math.vec3(); - this._size = 1.0; - this._imageSize = math.vec2(); - - this._texture = new Texture(this, { - src: cfg.src - }); - - this._geometry = new ReadableGeometry(this, { - primitive: "triangles", - positions: [3, 3, 0, -3, 3, 0, -3, -3, 0, 3, -3, 0], - normals: [-1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0], - uv: [1, -1, 0, -1, 0, 0, 1, 0], - indices: [0, 1, 2, 0, 2, 3] // Ensure these will be front-faces - }); - - this._mesh = new Mesh(this, { - geometry: this._geometry, - material: new PhongMaterial(this, { - ambient: [0.9, 0.3, 0.9], - shininess: 30, - diffuseMap: this._texture, - backfaces: true - }), - scale: [1, 1, 1], // Note: by design, scale does not work with billboard - position: cfg.worldPos, - rotation: [90, 0, 0], - billboard: "spherical", - occluder: false // Don't occlude SpriteMarkers or Annotations - }); - - this.visible = true; - this.collidable = cfg.collidable; - this.clippable = cfg.clippable; - this.pickable = cfg.pickable; - this.opacity = cfg.opacity; - this.size = cfg.size; - - if (cfg.image) { - this.image = cfg.image; - } else { - this.src = cfg.src; - } - } - - _setVisible(visible) { // Called by VisibilityTester and this._entity.on("destroyed"..) - this._occluded = (!visible); - this._mesh.visible = this._visible && (!this._occluded); - super._setVisible(visible); - } - - /** - * Sets if this ````SpriteMarker```` is visible or not. - * - * Default value is ````true````. - * - * @param {Boolean} visible Set ````true```` to make this ````SpriteMarker```` visible. - */ - set visible(visible) { - this._visible = (visible === null || visible === undefined) ? true : visible; - this._mesh.visible = this._visible && (!this._occluded); - } - - /** - * Gets if this ````SpriteMarker```` is visible or not. - * - * Default value is ````true````. - * - * @returns {Boolean} Returns ````true```` if visible. - */ - get visible() { - return this._visible; - } - - /** - * Sets an ````HTMLImageElement```` to source the image from. - * - * Sets {@link Texture#src} null. - * - * @type {HTMLImageElement} - */ - set image(image) { - this._image = image; - if (this._image) { - this._imageSize[0] = this._image.width; - this._imageSize[1] = this._image.height; - this._updatePlaneSizeFromImage(); - this._src = null; - this._texture.image = this._image; - } - } - - /** - * Gets the ````HTMLImageElement```` the ````SpriteMarker````'s image is sourced from, if set. - * - * Returns null if not set. - * - * @type {HTMLImageElement} - */ - get image() { - return this._image; - } - - /** - * Sets an image file path that the ````SpriteMarker````'s image is sourced from. - * - * Accepted file types are PNG and JPEG. - * - * Sets {@link Texture#image} null. - * - * @type {String} - */ - set src(src) { - this._src = src; - if (this._src) { - this._image = null; - const image = new Image(); - image.onload = () => { - this._texture.image = image; - this._imageSize[0] = image.width; - this._imageSize[1] = image.height; - this._updatePlaneSizeFromImage(); - }; - image.src = this._src; - } - } - - /** - * Gets the image file path that the ````SpriteMarker````'s image is sourced from, if set. - * - * Returns null if not set. - * - * @type {String} - */ - get src() { - return this._src; - } - - /** - * Sets the World-space size of the longest edge of the ````SpriteMarker````. - * - * Note that ````SpriteMarker```` sets its aspect ratio to match its image. If we set a value of ````1000````, and - * the image has size ````400x300````, then the ````SpriteMarker```` will then have size ````1000 x 750````. - * - * Default value is ````1.0````. - * - * @param {Number} size New World-space size of the ````SpriteMarker````. - */ - set size(size) { - this._size = (size === undefined || size === null) ? 1.0 : size; - if (this._image) { - this._updatePlaneSizeFromImage(); - } - } - - /** - * Gets the World-space size of the longest edge of the ````SpriteMarker````. - * - * Returns {Number} World-space size of the ````SpriteMarker````. - */ - get size() { - return this._size; - } - - /** - * Sets if this ````SpriteMarker```` is included in boundary calculations. - * - * Default is ````true````. - * - * @type {Boolean} - */ - set collidable(value) { - this._mesh.collidable = (value !== false); - } - - /** - * Gets if this ````SpriteMarker```` is included in boundary calculations. - * - * Default is ````true````. - * - * @type {Boolean} - */ - get collidable() { - return this._mesh.collidable; - } - - /** - * Sets if this ````SpriteMarker```` is clippable. - * - * Clipping is done by the {@link SectionPlane}s in {@link Scene#sectionPlanes}. - * - * Default is ````true````. - * - * @type {Boolean} - */ - set clippable(value) { - this._mesh.clippable = (value !== false); - } - - /** - * Gets if this ````SpriteMarker```` is clippable. - * - * Clipping is done by the {@link SectionPlane}s in {@link Scene#sectionPlanes}. - * - * Default is ````true````. - * - * @type {Boolean} - */ - get clippable() { - return this._mesh.clippable; - } - - /** - * Sets if this ````SpriteMarker```` is pickable. - * - * Default is ````true````. - * - * @type {Boolean} - */ - set pickable(value) { - this._mesh.pickable = (value !== false); - } - - /** - * Gets if this ````SpriteMarker```` is pickable. - * - * Default is ````true````. - * - * @type {Boolean} - */ - get pickable() { - return this._mesh.pickable; - } - - /** - * Sets the opacity factor for this ````SpriteMarker````. - * - * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas. - * - * @type {Number} - */ - set opacity(opacity) { - this._mesh.opacity = opacity; - } - - /** - * Gets this ````SpriteMarker````'s opacity factor. - * - * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas. - * - * @type {Number} - */ - get opacity() { - return this._mesh.opacity; - } - - _updatePlaneSizeFromImage() { - const halfSize = this._size * 0.5; - const width = this._imageSize[0]; - const height = this._imageSize[1]; - const aspect = height / width; - if (width > height) { - this._geometry.positions = [ - halfSize, halfSize * aspect, 0, - -halfSize, halfSize * aspect, 0, - -halfSize, -halfSize * aspect, 0, - halfSize, -halfSize * aspect, 0 - ]; - } else { - this._geometry.positions = [ - halfSize / aspect, halfSize, 0, - -halfSize / aspect, halfSize, 0, - -halfSize / aspect, -halfSize, 0, - halfSize / aspect, -halfSize, 0 - ]; - } - } -} - -/** - * @desc Saves and restores the state of a {@link Scene}'s {@link Camera}. - * - * ## See Also - * - * * {@link ModelMemento} - Saves and restores a snapshot of the visual state of the {@link Entity}'s of a model within a {@link Scene}. - * * {@link ObjectsMemento} - Saves and restores a snapshot of the visual state of the {@link Entity}'s that represent objects within a {@link Scene}. - * - * ## Usage - * - * In the example below, we'll create a {@link Viewer} and use an {@link XKTLoaderPlugin} to load an ````.xkt```` model. When the model has loaded, we'll save a snapshot of the {@link Camera} state in an CameraMemento. Then we'll move the Camera, and then we'll restore its original state again from the CameraMemento. - * - * ````javascript - * import {Viewer, XKTLoaderPlugin, CameraMemento} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * // Load a model - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * const model = xktLoader.load({ - * id: "myModel", - * src: "./models/xkt/schependomlaan/schependomlaan.xkt" - * }); - * - * // Set camera - * viewer.camera.eye = [-2.56, 8.38, 8.27]; - * viewer.camera.look = [13.44, 3.31, -14.83]; - * viewer.camera.up = [0.10, 0.98, -0.14]; - * - * model.on("loaded", () => { - * - * // Model has loaded - * - * // Save memento of camera state - * const cameraMemento = new CameraMemento(); - * - * cameraMemento.saveCamera(viewer.scene); - * - * // Move the camera - * viewer.camera.eye = [45.3, 2.00, 5.13]; - * viewer.camera.look = [0.0, 5.5, 10.0]; - * viewer.camera.up = [0.10, 0.98, -0.14]; - * - * // Restore the camera state again - * objectsMemento.restoreCamera(viewer.scene); - * }); - * ```` - */ -class CameraMemento { - - /** - * Creates a CameraState. - * - * @param {Scene} [scene] When given, immediately saves the state of the given {@link Scene}'s {@link Camera}. - */ - constructor(scene) { - - /** @private */ - this._eye = math.vec3(); - - /** @private */ - this._look = math.vec3(); - - /** @private */ - this._up = math.vec3(); - - /** @private */ - this._projection = {}; - - if (scene) { - this.saveCamera(scene); - } - } - - /** - * Saves the state of the given {@link Scene}'s {@link Camera}. - * - * @param {Scene} scene The scene that contains the {@link Camera}. - */ - saveCamera(scene) { - - const camera = scene.camera; - const project = camera.project; - - this._eye.set(camera.eye); - this._look.set(camera.look); - this._up.set(camera.up); - - switch (camera.projection) { - - case "perspective": - this._projection = { - projection: "perspective", - fov: project.fov, - fovAxis: project.fovAxis, - near: project.near, - far: project.far - }; - break; - - case "ortho": - this._projection = { - projection: "ortho", - scale: project.scale, - near: project.near, - far: project.far - }; - break; - - case "frustum": - this._projection = { - projection: "frustum", - left: project.left, - right: project.right, - top: project.top, - bottom: project.bottom, - near: project.near, - far: project.far - }; - break; - - case "custom": - this._projection = { - projection: "custom", - matrix: project.matrix.slice() - }; - break; - } - } - - /** - * Restores a {@link Scene}'s {@link Camera} to the state previously captured with {@link CameraMemento#saveCamera}. - * - * @param {Scene} scene The scene. - * @param {Function} [done] When this callback is given, will fly the {@link Camera} to the saved state then fire the callback. Otherwise will just jump the Camera to the saved state. - */ - restoreCamera(scene, done) { - - const camera = scene.camera; - const savedProjection = this._projection; - - function restoreProjection() { - - switch (savedProjection.type) { - - case "perspective": - camera.perspective.fov = savedProjection.fov; - camera.perspective.fovAxis = savedProjection.fovAxis; - camera.perspective.near = savedProjection.near; - camera.perspective.far = savedProjection.far; - break; - - case "ortho": - camera.ortho.scale = savedProjection.scale; - camera.ortho.near = savedProjection.near; - camera.ortho.far = savedProjection.far; - break; - - case "frustum": - camera.frustum.left = savedProjection.left; - camera.frustum.right = savedProjection.right; - camera.frustum.top = savedProjection.top; - camera.frustum.bottom = savedProjection.bottom; - camera.frustum.near = savedProjection.near; - camera.frustum.far = savedProjection.far; - break; - - case "custom": - camera.customProjection.matrix = savedProjection.matrix; - break; - } - } - - if (done) { - scene.viewer.cameraFlight.flyTo({ - eye: this._eye, - look: this._look, - up: this._up, - orthoScale: savedProjection.scale, - projection: savedProjection.projection - }, () => { - restoreProjection(); - done(); - }); - } else { - camera.eye = this._eye; - camera.look = this._look; - camera.up = this._up; - restoreProjection(); - camera.projection = savedProjection.projection; - } - } -} - -const color$3 = math.vec3(); - -/** - * @desc Saves and restores a snapshot of the visual state of the {@link Entity}'s of a model within a {@link Scene}. - * - * ## Usage - * - * In the example below, we'll create a {@link Viewer} and use an {@link XKTLoaderPlugin} to load an ````.xkt```` model. When the model has loaded, we'll hide a couple of {@link Entity}s and save a snapshot of the visual states of all its Entitys in an ModelMemento. Then we'll show all the Entitys - * again, and then we'll restore the visual states of all the Entitys again from the ModelMemento, which will hide those two Entitys again. - * - * ## See Also - * - * * {@link CameraMemento} - Saves and restores the state of a {@link Scene}'s {@link Camera}. - * * {@link ObjectsMemento} - Saves and restores a snapshot of the visual state of the {@link Entity}'s that represent objects within a {@link Scene}. - * - * ````javascript - * import {Viewer, XKTLoaderPlugin, ModelMemento} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * // Load a model - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * const model = xktLoader.load({ - * id: "myModel", - * src: "./models/xkt/schependomlaan/schependomlaan.xkt" - * }); - * - * model.on("loaded", () => { - * - * // Model has loaded - * - * // Hide a couple of objects - * viewer.scene.objects["0u4wgLe6n0ABVaiXyikbkA"].visible = false; - * viewer.scene.objects["3u4wgLe3n0AXVaiXyikbYO"].visible = false; - * - * // Save memento of all object states, which includes those two hidden objects - * const ModelMemento = new ModelMemento(); - * - * const metaModel = viewer.metaScene.metaModels - * ModelMemento.saveObjects(viewer.scene); - * - * // Show all objects - * viewer.scene.setObjectsVisible(viewer.scene.objectIds, true); - * - * // Restore the objects states again, which involves hiding those two objects again - * ModelMemento.restoreObjects(viewer.scene); - * }); - * ````` - * - * ## Masking Saved State - * - * We can optionally supply a mask to focus what state we save and restore. - * - * For example, to save and restore only the {@link Entity#visible} and {@link Entity#clippable} states: - * - * ````javascript - * ModelMemento.saveObjects(viewer.scene, { - * visible: true, - * clippable: true - * }); - * - * //... - * - * // Restore the objects states again - * ModelMemento.restoreObjects(viewer.scene); - * ```` - */ -class ModelMemento { - - /** - * Creates a ModelMemento. - * - * @param {MetaModel} [metaModel] When given, immediately saves the model's {@link Entity} states to this ModelMemento. - */ - constructor(metaModel) { - - /** @private */ - this.objectsVisible = []; - - /** @private */ - this.objectsEdges = []; - - /** @private */ - this.objectsXrayed = []; - - /** @private */ - this.objectsHighlighted = []; - - /** @private */ - this.objectsSelected = []; - - /** @private */ - this.objectsClippable = []; - - /** @private */ - this.objectsPickable = []; - - /** @private */ - this.objectsColorize = []; - - /** @private */ - this.objectsOpacity = []; - - /** @private */ - this.numObjects = 0; - - if (metaModel) { - const metaScene = metaModel.metaScene; - const scene = metaScene.scene; - this.saveObjects(scene, metaModel); - } - } - - /** - * Saves a snapshot of the visual state of the {@link Entity}'s that represent objects within a model. - * - * @param {Scene} scene The scene. - * @param {MetaModel} metaModel Represents the model. Corresponds with an {@link Entity} that represents the model in the scene. - * @param {Object} [mask] Masks what state gets saved. Saves all state when not supplied. - * @param {boolean} [mask.visible] Saves {@link Entity#visible} values when ````true````. - * @param {boolean} [mask.visible] Saves {@link Entity#visible} values when ````true````. - * @param {boolean} [mask.edges] Saves {@link Entity#edges} values when ````true````. - * @param {boolean} [mask.xrayed] Saves {@link Entity#xrayed} values when ````true````. - * @param {boolean} [mask.highlighted] Saves {@link Entity#highlighted} values when ````true````. - * @param {boolean} [mask.selected] Saves {@link Entity#selected} values when ````true````. - * @param {boolean} [mask.clippable] Saves {@link Entity#clippable} values when ````true````. - * @param {boolean} [mask.pickable] Saves {@link Entity#pickable} values when ````true````. - * @param {boolean} [mask.colorize] Saves {@link Entity#colorize} values when ````true````. - * @param {boolean} [mask.opacity] Saves {@link Entity#opacity} values when ````true````. - */ - saveObjects(scene, metaModel, mask) { - - this.numObjects = 0; - - this._mask = mask ? utils.apply(mask, {}) : null; - - const visible = (!mask || mask.visible); - const edges = (!mask || mask.edges); - const xrayed = (!mask || mask.xrayed); - const highlighted = (!mask || mask.highlighted); - const selected = (!mask || mask.selected); - const clippable = (!mask || mask.clippable); - const pickable = (!mask || mask.pickable); - const colorize = (!mask || mask.colorize); - const opacity = (!mask || mask.opacity); - - const metaObjects = metaModel.metaObjects; - const objects = scene.objects; - - for (let i = 0, len = metaObjects.length; i < len; i++) { - const metaObject = metaObjects[i]; - const objectId = metaObject.id; - const object = objects[objectId]; - if (!object) { - continue; - } - if (visible) { - this.objectsVisible[i] = object.visible; - } - if (edges) { - this.objectsEdges[i] = object.edges; - } - if (xrayed) { - this.objectsXrayed[i] = object.xrayed; - } - if (highlighted) { - this.objectsHighlighted[i] = object.highlighted; - } - if (selected) { - this.objectsSelected[i] = object.selected; - } - if (clippable) { - this.objectsClippable[i] = object.clippable; - } - if (pickable) { - this.objectsPickable[i] = object.pickable; - } - if (colorize) { - const objectColor = object.colorize; - this.objectsColorize[i * 3 + 0] = objectColor[0]; - this.objectsColorize[i * 3 + 1] = objectColor[1]; - this.objectsColorize[i * 3 + 2] = objectColor[2]; - } - if (opacity) { - this.objectsOpacity[i] = object.opacity; - } - this.numObjects++; - } - } - - /** - * Restores a {@link Scene}'s {@link Entity}'s to their state previously captured with {@link ModelMemento#saveObjects}. - * - * Assumes that the model has not been destroyed or modified since saving. - * - * @param {Scene} scene The scene that was given to {@link ModelMemento#saveObjects}. - * @param {MetaModel} metaModel The metamodel that was given to {@link ModelMemento#saveObjects}. - */ - restoreObjects(scene, metaModel) { - - const mask = this._mask; - - const visible = (!mask || mask.visible); - const edges = (!mask || mask.edges); - const xrayed = (!mask || mask.xrayed); - const highlighted = (!mask || mask.highlighted); - const selected = (!mask || mask.selected); - const clippable = (!mask || mask.clippable); - const pickable = (!mask || mask.pickable); - const colorize = (!mask || mask.colorize); - const opacity = (!mask || mask.opacity); - - const metaObjects = metaModel.metaObjects; - const objects = scene.objects; - - for (let i = 0, len = metaObjects.length; i < len; i++) { - const metaObject = metaObjects[i]; - const objectId = metaObject.id; - const object = objects[objectId]; - if (!object) { - continue; - } - if (visible) { - object.visible = this.objectsVisible[i]; - } - if (edges) { - object.edges = this.objectsEdges[i]; - } - if (xrayed) { - object.xrayed = this.objectsXrayed[i]; - } - if (highlighted) { - object.highlighted = this.objectsHighlighted[i]; - } - if (selected) { - object.selected = this.objectsSelected[i]; - } - if (clippable) { - object.clippable = this.objectsClippable[i]; - } - if (pickable) { - object.pickable = this.objectsPickable[i]; - } - if (colorize) { - color$3[0] = this.objectsColorize[i * 3 + 0]; - color$3[1] = this.objectsColorize[i * 3 + 1]; - color$3[2] = this.objectsColorize[i * 3 + 2]; - object.colorize = color$3; - } - if (opacity) { - object.opacity = this.objectsOpacity[i]; - } - } - } -} - -const color$2 = math.vec3(); - -/** - * @desc Saves and restores a snapshot of the visual state of the {@link Entity}'s that represent objects within a {@link Scene}. - * - * * An Entity represents an object when {@link Entity#isObject} is ````true````. - * * Each object-Entity is registered by {@link Entity#id} in {@link Scene#objects}. - * - * ## See Also - * - * * {@link CameraMemento} - Saves and restores the state of a {@link Scene}'s {@link Camera}. - * * {@link ModelMemento} - Saves and restores a snapshot of the visual state of the {@link Entity}'s of a model within a {@link Scene}. - * - * ## Usage - * - * In the example below, we'll create a {@link Viewer} and use an {@link XKTLoaderPlugin} to load an ````.xkt```` model. When the model has loaded, we'll hide a couple of {@link Entity}s and save a snapshot of the visual states of all the Entitys in an ObjectsMemento. Then we'll show all the Entitys - * again, and then we'll restore the visual states of all the Entitys again from the ObjectsMemento, which will hide those two Entitys again. - * - * ````javascript - * import {Viewer, XKTLoaderPlugin, ObjectsMemento} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * // Load a model - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * const model = xktLoader.load({ - * id: "myModel", - * src: "./models/xkt/schependomlaan/schependomlaan.xkt" - * }); - * - * model.on("loaded", () => { - * - * // Model has loaded - * - * // Hide a couple of objects - * viewer.scene.objects["0u4wgLe6n0ABVaiXyikbkA"].visible = false; - * viewer.scene.objects["3u4wgLe3n0AXVaiXyikbYO"].visible = false; - * - * // Save memento of all object states, which includes those two hidden objects - * const objectsMemento = new ObjectsMemento(); - * - * objectsMemento.saveObjects(viewer.scene); - * - * // Show all objects - * viewer.scene.setObjectsVisible(viewer.scene.objectIds, true); - * - * // Restore the objects states again, which involves hiding those two objects again - * objectsMemento.restoreObjects(viewer.scene); - * }); - * ````` - * - * ## Masking Saved State - * - * We can optionally supply a mask to focus what state we save and restore. - * - * For example, to save and restore only the {@link Entity#visible} and {@link Entity#clippable} states: - * - * ````javascript - * objectsMemento.saveObjects(viewer.scene, { - * visible: true, - * clippable: true - * }); - * - * //... - * - * // Restore the objects states again - * objectsMemento.restoreObjects(viewer.scene); - * ```` - */ -class ObjectsMemento { - - /** - * Creates an ObjectsMemento. - */ - constructor() { - - /** @private */ - this.objectsVisible = []; - - /** @private */ - this.objectsEdges = []; - - /** @private */ - this.objectsXrayed = []; - - /** @private */ - this.objectsHighlighted = []; - - /** @private */ - this.objectsSelected = []; - - /** @private */ - this.objectsClippable = []; - - /** @private */ - this.objectsPickable = []; - - /** @private */ - this.objectsColorize = []; - - /** @private */ - this.objectsHasColorize = []; - - /** @private */ - this.objectsOpacity = []; - - /** @private */ - this.numObjects = 0; - } - - /** - * Saves a snapshot of the visual state of the {@link Entity}'s that represent objects within a {@link Scene}. - * - * @param {Scene} scene The scene. - * @param {Object} [mask] Masks what state gets saved. Saves all state when not supplied. - * @param {boolean} [mask.visible] Saves {@link Entity#visible} values when ````true````. - * @param {boolean} [mask.visible] Saves {@link Entity#visible} values when ````true````. - * @param {boolean} [mask.edges] Saves {@link Entity#edges} values when ````true````. - * @param {boolean} [mask.xrayed] Saves {@link Entity#xrayed} values when ````true````. - * @param {boolean} [mask.highlighted] Saves {@link Entity#highlighted} values when ````true````. - * @param {boolean} [mask.selected] Saves {@link Entity#selected} values when ````true````. - * @param {boolean} [mask.clippable] Saves {@link Entity#clippable} values when ````true````. - * @param {boolean} [mask.pickable] Saves {@link Entity#pickable} values when ````true````. - * @param {boolean} [mask.colorize] Saves {@link Entity#colorize} values when ````true````. - * @param {boolean} [mask.opacity] Saves {@link Entity#opacity} values when ````true````. - */ - saveObjects(scene, mask) { - - this.numObjects = 0; - - this._mask = mask ? utils.apply(mask, {}) : null; - - const objects = scene.objects; - const visible = (!mask || mask.visible); - const edges = (!mask || mask.edges); - const xrayed = (!mask || mask.xrayed); - const highlighted = (!mask || mask.highlighted); - const selected = (!mask || mask.selected); - const clippable = (!mask || mask.clippable); - const pickable = (!mask || mask.pickable); - const colorize = (!mask || mask.colorize); - const opacity = (!mask || mask.opacity); - - for (let objectId in objects) { - if (objects.hasOwnProperty(objectId)) { - const object = objects[objectId]; - const i = this.numObjects; - if (visible) { - this.objectsVisible[i] = object.visible; - } - if (edges) { - this.objectsEdges[i] = object.edges; - } - if (xrayed) { - this.objectsXrayed[i] = object.xrayed; - } - if (highlighted) { - this.objectsHighlighted[i] = object.highlighted; - } - if (selected) { - this.objectsSelected[i] = object.selected; - } - if (clippable) { - this.objectsClippable[i] = object.clippable; - } - if (pickable) { - this.objectsPickable[i] = object.pickable; - } - if (colorize) { - const objectColor = object.colorize; - if (objectColor) { - this.objectsColorize[i * 3 + 0] = objectColor[0]; - this.objectsColorize[i * 3 + 1] = objectColor[1]; - this.objectsColorize[i * 3 + 2] = objectColor[2]; - this.objectsHasColorize[i] = true; - } else { - this.objectsHasColorize[i] = false; - } - } - if (opacity) { - this.objectsOpacity[i] = object.opacity; - } - this.numObjects++; - } - } - } - - /** - * Restores a {@link Scene}'s {@link Entity}'s to their state previously captured with {@link ObjectsMemento#saveObjects}. - * @param {Scene} scene The scene. - */ - restoreObjects(scene) { - - const mask = this._mask; - - const visible = (!mask || mask.visible); - const edges = (!mask || mask.edges); - const xrayed = (!mask || mask.xrayed); - const highlighted = (!mask || mask.highlighted); - const selected = (!mask || mask.selected); - const clippable = (!mask || mask.clippable); - const pickable = (!mask || mask.pickable); - const colorize = (!mask || mask.colorize); - const opacity = (!mask || mask.opacity); - - var i = 0; - - const objects = scene.objects; - - for (let objectId in objects) { - if (objects.hasOwnProperty(objectId)) { - const object = objects[objectId]; - if (visible) { - object.visible = this.objectsVisible[i]; - } - if (edges) { - object.edges = this.objectsEdges[i]; - } - if (xrayed) { - object.xrayed = this.objectsXrayed[i]; - } - if (highlighted) { - object.highlighted = this.objectsHighlighted[i]; - } - if (selected) { - object.selected = this.objectsSelected[i]; - } - if (clippable) { - object.clippable = this.objectsClippable[i]; - } - if (pickable) { - object.pickable = this.objectsPickable[i]; - } - if (colorize ) { - if (this.objectsHasColorize[i]) { - color$2[0] = this.objectsColorize[i * 3 + 0]; - color$2[1] = this.objectsColorize[i * 3 + 1]; - color$2[2] = this.objectsColorize[i * 3 + 2]; - object.colorize = color$2; - } else { - object.colorize = null; - } - } - if (opacity) { - object.opacity = this.objectsOpacity[i]; - } - i++; - } - } - } -} - -/** - * @desc A {@link Curve} along which a 3D position can be animated. - * - * * As shown in the diagram below, a CubicBezierCurve is defined by four control points. - * * You can sample a {@link CubicBezierCurve#point} and a {@link CubicBezierCurve#tangent} vector on a CubicBezierCurve for any given value of {@link CubicBezierCurve#t} in the range [0..1]. - * * When you set {@link CubicBezierCurve#t} on a CubicBezierCurve, its {@link CubicBezierCurve#point} and {@link CubicBezierCurve#tangent} properties will update accordingly. - * * To build a complex path, you can combine an unlimited combination of CubicBezierCurves, {@link QuadraticBezierCurve}s and {@link SplineCurve}s into a {@link Path}. - * - *
- * - *
- * [Cubic Bezier Curve from WikiPedia](https://en.wikipedia.org/wiki/B%C3%A9zier_curve) - */ -class CubicBezierCurve extends Curve { - - /** - * @constructor - * @param {Component} [owner] Owner component. When destroyed, the owner will destroy this CubicBezierCurve as well. - * @param {*} [cfg] Configs - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number[]} [cfg.v0=[0,0,0]] The starting point. - * @param {Number[]} [cfg.v1=[0,0,0]] The first control point. - * @param {Number[]} [cfg.v2=[0,0,0]] The middle control point. - * @param {Number[]} [cfg.v3=[0,0,0]] The ending point. - * @param {Number} [cfg.t=0] Current position on this CubicBezierCurve, in range between 0..1. - */ - constructor(owner, cfg = {}) { - super(owner, cfg); - this.v0 = cfg.v0; - this.v1 = cfg.v1; - this.v2 = cfg.v2; - this.v3 = cfg.v3; - this.t = cfg.t; - } - - /** - * Sets the starting point on this CubicBezierCurve. - * - * Default value is ````[0.0, 0.0, 0.0]```` - * - * @param {Number[]} value The starting point. - */ - set v0(value) { - this._v0 = value || math.vec3([0, 0, 0]); - } - - /** - * Gets the starting point on this CubicBezierCurve. - * - * Default value is ````[0.0, 0.0, 0.0]```` - * - * @returns {Number[]} The starting point. - */ - get v0() { - return this._v0; - } - - /** - * Sets the first control point on this CubicBezierCurve. - * - * Default value is ````[0.0, 0.0, 0.0]```` - * - * @param {Number[]} value The first control point. - */ - set v1(value) { - this._v1 = value || math.vec3([0, 0, 0]); - } - - /** - * Gets the first control point on this CubicBezierCurve. - * - * Fires a {@link CubicBezierCurve#v1:event} event on change. - * - * Default value is ````[0.0, 0.0, 0.0]```` - * - * @returns {Number[]} The first control point. - */ - get v1() { - return this._v1; - } - - /** - * Sets the second control point on this CubicBezierCurve. - * - * Default value is ````[0.0, 0.0, 0.0]```` - * - * @param {Number[]} value The second control point. - */ - set v2(value) { - this._v2 = value || math.vec3([0, 0, 0]); - } - - /** - * Gets the second control point on this CubicBezierCurve. - * - * Default value is ````[0.0, 0.0, 0.0]```` - * - * @returns {Number[]} The second control point. - */ - get v2() { - return this._v2; - } - - /** - * Sets the end point on this CubicBezierCurve. - * - * Fires a {@link CubicBezierCurve#v3:event} event on change. - * - * Default value is ````[0.0, 0.0, 0.0]```` - * - * @param {Number[]} value The end point. - */ - set v3(value) { - this.fire("v3", this._v3 = value || math.vec3([0, 0, 0])); - } - - /** - * Gets the end point on this CubicBezierCurve. - * - * Fires a {@link CubicBezierCurve#v3:event} event on change. - * - * Default value is ````[0.0, 0.0, 0.0]```` - * - * @returns {Number[]} The end point. - */ - get v3() { - return this._v3; - } - - /** - * Sets the current position of progress along this CubicBezierCurve. - * - * Automatically clamps to range ````[0..1]````. - * - * @param {Number} value New progress time value. - */ - set t(value) { - value = value || 0; - this._t = value < 0.0 ? 0.0 : (value > 1.0 ? 1.0 : value); - } - - /** - * Gets the current position of progress along this CubicBezierCurve. - * - * @returns {Number} Current progress time value. - */ - get t() { - return this._t; - } - - /** - * Returns point on this CubicBezierCurve at the given position. - * - * @param {Number} t Position to get point at. - * - * @returns {Number[]} The point at the given position. - */ - get point() { - return this.getPoint(this._t); - } - - /** - * Returns point on this CubicBezierCurve at the given position. - * - * @param {Number} t Position to get point at. - * - * @returns {Number[]} The point at the given position. - */ - getPoint(t) { - - var vector = math.vec3(); - - vector[0] = math.b3(t, this._v0[0], this._v1[0], this._v2[0], this._v3[0]); - vector[1] = math.b3(t, this._v0[1], this._v1[1], this._v2[1], this._v3[1]); - vector[2] = math.b3(t, this._v0[2], this._v1[2], this._v2[2], this._v3[2]); - - return vector; - } - - getJSON() { - return { - v0: this._v0, - v1: this._v1, - v2: this._v2, - v3: this._v3, - t: this._t - }; - } -} - -/** - * @desc A complex curved path constructed from various {@link Curve} subtypes. - * - * * A Path can be constructed from these {@link Curve} subtypes: {@link SplineCurve}, {@link CubicBezierCurve} and {@link QuadraticBezierCurve}. - * * You can sample a {@link Path#point} and a {@link Curve#tangent} vector on a Path for any given value of {@link Path#t} in the range ````[0..1]````. - * * When you set {@link Path#t} on a Path, its {@link Path#point} and {@link Curve#tangent} properties will update accordingly. - */ -class Path extends Curve { - - /** - * @constructor - * @param {Component} [owner] Owner component. When destroyed, the owner will destroy this SectionPlane as well. - * @param {*} [cfg] Path configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {String []} [cfg.paths=[]] IDs or instances of {{#crossLink "path"}}{{/crossLink}} subtypes to add to this Path. - * @param {Number} [cfg.t=0] Current position on this Path, in range between 0..1. - */ - constructor(owner, cfg = {}) { - super(owner, cfg); - this._cachedLengths = []; - this._dirty = true; - this._curves = []; // Array of child Curve components - this._t = 0; - this._dirtySubs = []; // Subscriptions to "dirty" events from child Curve components - this._destroyedSubs = []; // Subscriptions to "destroyed" events from child Curve components - this.curves = cfg.curves || []; // Add initial curves - this.t = cfg.t; // Set initial progress - } - - /** - * Adds a {@link Curve} to this Path. - * - * @param {Curve} curve The {@link Curve} to add. - */ - addCurve(curve) { - this._curves.push(curve); - this._dirty = true; - } - - /** - * Sets the {@link Curve}s in this Path. - * - * Default value is ````[]````. - * - * @param {{Array of Spline, Path, QuadraticBezierCurve or CubicBezierCurve}} value. - */ - set curves(value) { - - value = value || []; - - var curve; - // Unsubscribe from events on old curves - var i; - var len; - for (i = 0, len = this._curves.length; i < len; i++) { - curve = this._curves[i]; - curve.off(this._dirtySubs[i]); - curve.off(this._destroyedSubs[i]); - } - - this._curves = []; - this._dirtySubs = []; - this._destroyedSubs = []; - - var self = this; - - function curveDirty() { - self._dirty = true; - } - - function curveDestroyed() { - var id = this.id; - for (i = 0, len = self._curves.length; i < len; i++) { - if (self._curves[i].id === id) { - self._curves = self._curves.slice(i, i + 1); - self._dirtySubs = self._dirtySubs.slice(i, i + 1); - self._destroyedSubs = self._destroyedSubs.slice(i, i + 1); - self._dirty = true; - return; - } - } - } - - for (i = 0, len = value.length; i < len; i++) { - curve = value[i]; - if (utils.isNumeric(curve) || utils.isString(curve)) { - // ID given for curve - find the curve component - var id = curve; - curve = this.scene.components[id]; - if (!curve) { - this.error("Component not found: " + _inQuotes(id)); - continue; - } - } - - var type = curve.type; - - if (type !== "xeokit.SplineCurve" && - type !== "xeokit.Path" && - type !== "xeokit.CubicBezierCurve" && - type !== "xeokit.QuadraticBezierCurve") { - - this.error("Component " + _inQuotes(curve.id) - + " is not a xeokit.SplineCurve, xeokit.Path or xeokit.QuadraticBezierCurve"); - - continue; - } - - this._curves.push(curve); - this._dirtySubs.push(curve.on("dirty", curveDirty)); - this._destroyedSubs.push(curve.once("destroyed", curveDestroyed)); - } - - this._dirty = true; - } - - /** - * Gets the {@link Curve}s in this Path. - * - * @returns {{Array of Spline, Path, QuadraticBezierCurve or CubicBezierCurve}} the {@link Curve}s in this path. - */ - get curves() { - return this._curves; - } - - /** - * Sets the current point of progress along this Path. - * - * Automatically clamps to range ````[0..1]````. - * - * Default value is ````0````. - * - * @param {Number} value The current point of progress. - */ - set t(value) { - value = value || 0; - this._t = value < 0.0 ? 0.0 : (value > 1.0 ? 1.0 : value); - } - - /** - * Gets the current point of progress along this Path. - * - * Default value is ````0````. - * - * @returns {Number} The current point of progress. - */ - get t() { - return this._t; - } - - /** - * Gets point on this Path corresponding to the current value of {@link Path#t}. - * - * @returns {Number[]} The point. - */ - get point() { - return this.getPoint(this._t); - } - - /** - * Length of this Path, which is the cumulative length of all {@link Curve}s currently in {@link Path#curves}. - * - * @return {Number} Length of this path. - */ - get length() { - var lens = this._getCurveLengths(); - return lens[lens.length - 1]; - } - - /** - * Gets a point on this Path corresponding to the given progress position. - * - * @param {Number} t Indicates point of progress along this curve, in the range [0..1]. - * @returns {Number[]} - */ - getPoint(t) { - var d = t * this.length; - var curveLengths = this._getCurveLengths(); - var i = 0, diff, curve; - while (i < curveLengths.length) { - if (curveLengths[i] >= d) { - diff = curveLengths[i] - d; - curve = this._curves[i]; - var u = 1 - diff / curve.length; - return curve.getPointAt(u); - } - i++; - } - return null; - } - - _getCurveLengths() { - if (!this._dirty) { - return this._cachedLengths; - } - var lengths = []; - var sums = 0; - var i, il = this._curves.length; - for (i = 0; i < il; i++) { - sums += this._curves[i].length; - lengths.push(sums); - - } - this._cachedLengths = lengths; - this._dirty = false; - return lengths; - } - - _getJSON() { - var curveIds = []; - for (var i = 0, len = this._curves.length; i < len; i++) { - curveIds.push(this._curves[i].id); - } - return { - curves: curveIds, - t: this._t - }; - } - - /** - * Destroys this Path. - */ - destroy() { - super.destroy(); - var i; - var len; - var curve; - for (i = 0, len = this._curves.length; i < len; i++) { - curve = this._curves[i]; - curve.off(this._dirtySubs[i]); - curve.off(this._destroyedSubs[i]); - } - } -} - -/** - * A **QuadraticBezierCurve** is a {@link Curve} along which a 3D position can be animated. - * - * * As shown in the diagram below, a QuadraticBezierCurve is defined by three control points - * * You can sample a {@link QuadraticBezierCurve#point} and a {@link Curve#tangent} vector on a QuadraticBezierCurve for any given value of {@link QuadraticBezierCurve#t} in the range ````[0..1]```` - * * When you set {@link QuadraticBezierCurve#t} on a QuadraticBezierCurve, its {@link QuadraticBezierCurve#point} and {@link Curve#tangent} will update accordingly. - * * To build a complex path, you can combine an unlimited combination of QuadraticBezierCurves, {@link CubicBezierCurve}s and {@link SplineCurve}s into a {@link Path}. - *
- * - *
- * *[Quadratic Bezier Curve from WikiPedia](https://en.wikipedia.org/wiki/B%C3%A9zier_curve)* - */ -class QuadraticBezierCurve extends Curve { - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this MetallicMaterial as well. - * @param {*} [cfg] Configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {{#crossLink "Scene"}}Scene{{/crossLink}}, generated automatically when omitted. - * @param {Number[]} [cfg.v0=[0,0,0]] The starting point. - * @param {Number[]} [cfg.v1=[0,0,0]] The middle control point. - * @param {Number[]} [cfg.v2=[0,0,0]] The end point. - * @param {Number[]} [cfg.t=0] Current position on this QuadraticBezierCurve, in range between ````0..1````. - */ - constructor(owner, cfg = {}) { - super(owner, cfg); - this.v0 = cfg.v0; - this.v1 = cfg.v1; - this.v2 = cfg.v2; - this.t = cfg.t; - } - - /** - * Sets the starting point on this QuadraticBezierCurve. - * - * Default value is ````[0.0, 0.0, 0.0]````. - * - * @param {Number[]} value New starting point. - */ - set v0(value) { - this._v0 = value || math.vec3([0, 0, 0]); - } - - /** - * Gets the starting point on this QuadraticBezierCurve. - * - * Default value is ````[0.0, 0.0, 0.0]````. - * - * @returns {Number[]} The starting point. - */ - get v0() { - return this._v0; - } - - /** - * Sets the middle control point on this QuadraticBezierCurve. - * - * Default value is ````[0.0, 0.0, 0.0]````. - * - * @param {Number[]} value New middle control point. - */ - set v1(value) { - this._v1 = value || math.vec3([0, 0, 0]); - } - - /** - * Gets the middle control point on this QuadraticBezierCurve. - * - * Default value is ````[0.0, 0.0, 0.0]````. - * - * @returns {Number[]} The middle control point. - */ - get v1() { - return this._v1; - } - - /** - * Sets the end point on this QuadraticBezierCurve. - * - * Default value is ````[0.0, 0.0, 0.0]````. - * - * @param {Number[]} value The new end point. - */ - set v2(value) { - this._v2 = value || math.vec3([0, 0, 0]); - } - - /** - * Gets the end point on this QuadraticBezierCurve. - * - * Default value is ````[0.0, 0.0, 0.0]````. - * - * @returns {Number[]} The end point. - */ - get v2() { - return this._v2; - } - - /** - * Sets the progress along this QuadraticBezierCurve. - * - * Automatically clamps to range [0..1]. - * - * Default value is ````0````. - * - * @param {Number} value The new progress location. - */ - set t(value) { - value = value || 0; - this._t = value < 0.0 ? 0.0 : (value > 1.0 ? 1.0 : value); - } - - /** - * Gets the progress along this QuadraticBezierCurve. - * - * Default value is ````0````. - * - * @returns {Number} The current progress location. - */ - get t() { - return this._t; - } - - /** - Point on this QuadraticBezierCurve at position {@link QuadraticBezierCurve/t}. - - @property point - @type {Number[]} - */ - get point() { - return this.getPoint(this._t); - } - - /** - * Returns the point on this QuadraticBezierCurve at the given position. - * - * @param {Number} t Position to get point at. - * @returns {Number[]} The point. - */ - getPoint(t) { - var vector = math.vec3(); - vector[0] = math.b2(t, this._v0[0], this._v1[0], this._v2[0]); - vector[1] = math.b2(t, this._v0[1], this._v1[1], this._v2[1]); - vector[2] = math.b2(t, this._v0[2], this._v1[2], this._v2[2]); - return vector; - } - - getJSON() { - return { - v0: this._v0, - v1: this._v1, - v2: this._v2, - t: this._t - }; - } -} - -/** - * @desc A high-performance model representation for efficient rendering and low memory usage. - * - * * PerformanceModel was replaced with {@link SceneModel} in ````xeokit-sdk v2.4````. - * * PerformanceModel currently extends {@link SceneModel}, in order to maintain backward-compatibility until we remove PerformanceModel. - * * See {@link SceneModel} for API details. - * - * @deprecated - * @implements {Drawable} - * @implements {Entity} - * @extends {SceneModel} - */ -class PerformanceModel extends SceneModel { - - /** - * See {@link VBOSceneModel} for details. - * - * @param owner - * @param cfg - */ - constructor(owner, cfg = {}) { - super(owner, cfg); - } -} - -const tempVec3a$b = math.vec3(); -const tempVec3b$8 = math.vec3(); -const tempVec4a$8 = math.vec4(); -const front = math.vec3([0, 0, -1]); -const back = math.vec3([0, 0, 1]); -const up = math.vec3([0, 1, 0]); - -/** - * @desc An arbitrarily-aligned World-space clipping plane. - * - * * Slices portions off objects to create cross-section views or reveal interiors. - * * Registered by {@link SectionPlane#id} in {@link Scene#sectionPlanes}. - * * Indicates World-space position in {@link SectionPlane#pos} and orientation in {@link SectionPlane#dir}. - * * Discards elements from the half-space in the direction of {@link SectionPlane#dir}. - * * Can be be enabled or disabled via {@link SectionPlane#active}. - * - * ## Usage - * - * In the example below, we'll create two SectionPlanes to slice a model loaded from glTF. Note that we could also create them - * using a {@link SectionPlanesPlugin}. - * - * ````javascript - * import {Viewer, GLTFLoaderPlugin, SectionPlane} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * const gltfLoaderPlugin = new GLTFModelsPlugin(viewer, { - * id: "GLTFModels" - * }); - * - * const model = gltfLoaderPlugin.load({ - * id: "myModel", - * src: "./models/gltf/mygltfmodel.gltf" - * }); - * - * // Create a SectionPlane on negative diagonal - * const sectionPlane1 = new SectionPlane(viewer.scene, { - * pos: [1.0, 1.0, 1.0], - * dir: [-1.0, -1.0, -1.0], - * active: true - * }), - * - * // Create a SectionPlane on positive diagonal - * const sectionPlane2 = new SectionPlane(viewer.scene, { - * pos: [-1.0, -1.0, -1.0], - * dir: [1.0, 1.0, 1.0], - * active: true - * }); - * ```` - */ -class SectionPlane extends Component { - - /** - @private - */ - get type() { - return "SectionPlane"; - } - - /** - * @constructor - * @param {Component} [owner] Owner component. When destroyed, the owner will destroy this SectionPlane as well. - * @param {*} [cfg] SectionPlane configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Boolean} [cfg.active=true] Indicates whether or not this SectionPlane is active. - * @param {Number[]} [cfg.pos=[0,0,0]] World-space position of the SectionPlane. - * @param {Number[]} [cfg.dir=[0,0,-1]] Vector perpendicular to the plane surface, indicating the SectionPlane plane orientation. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._state = new RenderState({ - active: true, - pos: math.vec3(), - quaternion: math.vec4(), - roll: 0, - dir: math.vec3(), - dist: 0 - }); - - this.active = cfg.active; - this.pos = cfg.pos; - this.dir = cfg.dir; - - this.scene._sectionPlaneCreated(this); - } - - /** - * Sets if this SectionPlane is active or not. - * - * Default value is ````true````. - * - * @param {Boolean} value Set ````true```` to activate else ````false```` to deactivate. - */ - set active(value) { - this._state.active = value !== false; - this.glRedraw(); - this.fire("active", this._state.active); - this.scene.fire("sectionPlaneUpdated", this); - } - - /** - * Gets if this SectionPlane is active or not. - * - * Default value is ````true````. - * - * @returns {Boolean} Returns ````true```` if active. - */ - get active() { - return this._state.active; - } - - /** - * Sets the World-space position of this SectionPlane's plane. - * - * Default value is ````[0, 0, 0]````. - * - * @param {Number[]} value New position. - */ - set pos(value) { - this._state.pos.set(value || [0, 0, 0]); - this._state.dist = (-math.dotVec3(this._state.pos, this._state.dir)); - this.fire("pos", this._state.pos); - this.scene.fire("sectionPlaneUpdated", this); - } - - /** - * Gets the World-space position of this SectionPlane's plane. - * - * Default value is ````[0, 0, 0]````. - * - * @returns {Number[]} Current position. - */ - get pos() { - return this._state.pos; - } - - /** - * Sets the quaternion of this SectionPlane's plane. - * - * Default value is ````[0, -1, 0, 0]````. - * - * @param {Number[]} value New quaternion. - */ - set quaternion(value) { - this._state.quaternion.set(value || [0, 0, 0, -1]); - math.vec3ApplyQuaternion(this._state.quaternion, back, this._state.dir); - const quatUp = math.vec3ApplyQuaternion(this._state.quaternion, up, tempVec3a$b); - const dirOnlyQ = math.vec3PairToQuaternion(back, this._state.dir, tempVec4a$8); - const dirOnlyUp = math.vec3ApplyQuaternion(dirOnlyQ, up, tempVec3b$8); - const angle = Math.acos(Math.min(1, math.dotVec3(quatUp, dirOnlyUp))); - const sign = Math.sign(math.dotVec3(this._state.dir, math.cross3Vec3(quatUp, dirOnlyUp, tempVec3b$8))); - this._state.roll = sign * angle; - this._onDirUpdated(); - } - - /** - * Gets the quaternion of this SectionPlane's plane. - * - * Default value is ````[0, -1, 0, 0]````. - * - * @returns {Number[]} value Current quaternion. - */ - get quaternion() { - return this._state.quaternion; - } - - /** - * Sets the roll of this SectionPlane's plane. - * - * Default value is ````0````. - * - * @param {Number[]} value New roll. - */ - set roll(value) { - this._state.roll = value || 0; - this._onDirRollUpdated(); - } - - /** - * Gets the roll of this SectionPlane's plane. - * - * Default value is ````0````. - * - * @returns {Number[]} value Current roll. - */ - get roll() { - return this._state.roll; - } - - /** - * Sets the direction of this SectionPlane's plane. - * - * Default value is ````[0, 0, -1]````. - * - * @param {Number[]} value New direction. - */ - set dir(value) { - this._state.dir.set(value || front); - this._onDirRollUpdated(); - } - - _onDirRollUpdated() { - math.vec3PairToQuaternion(back, this._state.dir, this._state.quaternion); - - tempVec4a$8[0] = 0; - tempVec4a$8[1] = 0; - tempVec4a$8[2] = -1; - tempVec4a$8[3] = this._state.roll; - math.angleAxisToQuaternion(tempVec4a$8, tempVec4a$8); - - math.mulQuaternions(this._state.quaternion, tempVec4a$8, this._state.quaternion); - - this._onDirUpdated(); - } - - _onDirUpdated() { - this._state.dist = (-math.dotVec3(this._state.pos, this._state.dir)); - this.glRedraw(); - this.fire("dir", this._state.dir); - this.scene.fire("sectionPlaneUpdated", this); - } - - /** - * Gets the direction of this SectionPlane's plane. - * - * Default value is ````[0, 0, -1]````. - * - * @returns {Number[]} value Current direction. - */ - get dir() { - return this._state.dir; - } - - /** - * Gets this SectionPlane's distance to the origin of the World-space coordinate system. - * - * This is the dot product of {@link SectionPlane#pos} and {@link SectionPlane#dir} and is automatically re-calculated - * each time either of two properties are updated. - * - * @returns {Number} - */ - get dist() { - return this._state.dist; - } - - /** - * Inverts the direction of {@link SectionPlane#dir}. - */ - flipDir() { - math.mulVec3Scalar(this._state.dir, -1.0, this._state.dir); - this.dir = this._state.dir; - } - - /** - * @destroy - */ - destroy() { - this._state.destroy(); - this.scene._sectionPlaneDestroyed(this); - super.destroy(); - } -} - -/** - * Transcodes texture data. - * - * A {@link SceneModel} configured with an appropriate TextureTranscoder will allow us to add textures from - * transcoded buffers or files. For a concrete example, see {@link VBOSceneModel}, which can be configured with - * a {@link KTX2TextureTranscoder}, which allows us to add textures from KTX2 buffers and files. - * - * @interface - */ -class TextureTranscoder { - - /** - * Transcodes texture data from transcoded buffers into a {@link Texture2D}. - * - * @param {ArrayBuffer[]} buffers Transcoded texture data. Given as an array of buffers so that we can support - * multi-image textures, such as cube maps. - * @param {*} config Transcoding options. - * @param {Texture2D} texture The texture to load. - * @returns {Promise} Resolves when the texture has loaded. - */ - transcode(buffers, texture, config = {}) { - } - - /** - * Destroys this transcoder. - */ - destroy() { - } -} - -/** - * @desc Pick result returned by {@link Scene#pick}. - * - */ -class PickResult { - - /** - * @private - */ - constructor() { - - /** - * Picked entity. - * Null when no entity was picked. - * @property entity - * @type {Entity|*} - */ - this.entity = null; - - /** - * Type of primitive that was picked - usually "triangle". - * Null when no primitive was picked. - * @property primitive - * @type {String} - */ - this.primitive = null; - - /** - * Index of primitive that was picked. - * -1 when no entity was picked. - * @property primIndex - * @type {number} - */ - this.primIndex = -1; - - /** - * True when the picked surface position is full precision. - * When false, the picked surface position should be regarded as approximate. - * Full-precision surface picking is performed with the {@link Scene#pick} method's ````pickSurfacePrecision```` option. - * @property pickSurfacePrecision - * @type {Boolean} - */ - this.pickSurfacePrecision = false; - - /** - * True when picked from touch input, else false when from mouse input. - * @type {boolean} - */ - this.touchInput = false; - - /** - * True when snapped to nearest edge. - * @type {boolean} - */ - this.snappedToEdge = false; - - /** - * True when snapped to nearest vertex. - * @type {boolean} - */ - this.snappedToVertex = false; - - this._origin = new Float64Array([0, 0, 0]); - this._direction = new Float64Array([0, 0, 0]); - this._indices = new Int32Array(3); - this._localPos = new Float64Array([0, 0, 0]); - this._worldPos = new Float64Array([0, 0, 0]); - this._viewPos = new Float64Array([0, 0, 0]); - this._canvasPos = new Int16Array([0, 0]); - this._snappedCanvasPos = new Int16Array([0, 0]); - this._bary = new Float64Array([0, 0, 0]); - this._worldNormal = new Float64Array([0, 0, 0]); - this._uv = new Float64Array([0, 0]); - - this.reset(); - } - - /** - * Canvas pick coordinates. - * @property canvasPos - * @type {Number[]} - */ - get canvasPos() { - return this._gotCanvasPos ? this._canvasPos : null; - } - - /** - * @private - * @param value - */ - set canvasPos(value) { - if (value) { - this._canvasPos[0] = value[0]; - this._canvasPos[1] = value[1]; - this._gotCanvasPos = true; - } else { - this._gotCanvasPos = false; - } - } - - /** - * World-space 3D ray origin when raypicked. - * @property origin - * @type {Number[]} - */ - get origin() { - return this._gotOrigin ? this._origin : null; - } - - /** - * @private - * @param value - */ - set origin(value) { - if (value) { - this._origin[0] = value[0]; - this._origin[1] = value[1]; - this._origin[2] = value[2]; - this._gotOrigin = true; - } else { - this._gotOrigin = false; - } - } - - /** - * World-space 3D ray direction when raypicked. - * @property direction - * @type {Number[]} - */ - get direction() { - return this._gotDirection ? this._direction : null; - } - - /** - * @private - * @param value - */ - set direction(value) { - if (value) { - this._direction[0] = value[0]; - this._direction[1] = value[1]; - this._direction[2] = value[2]; - this._gotDirection = true; - } else { - this._gotDirection = false; - } - } - - /** - * Picked triangle's vertex indices. - * @property indices - * @type {Int32Array} - */ - get indices() { - return this.entity && this._gotIndices ? this._indices : null; - } - - /** - * @private - * @param value - */ - set indices(value) { - if (value) { - this._indices[0] = value[0]; - this._indices[1] = value[1]; - this._indices[2] = value[2]; - this._gotIndices = true; - } else { - this._gotIndices = false; - } - } - - /** - * Picked Local-space point. - * @property localPos - * @type {Number[]} - */ - get localPos() { - return this.entity && this._gotLocalPos ? this._localPos : null; - } - - /** - * @private - * @param value - */ - set localPos(value) { - if (value) { - this._localPos[0] = value[0]; - this._localPos[1] = value[1]; - this._localPos[2] = value[2]; - this._gotLocalPos = true; - } else { - this._gotLocalPos = false; - } - } - - /** - * Canvas cursor coordinates, snapped when snap picking, otherwise same as {@link PickResult#pointerPos}. - * @property snappedCanvasPos - * @type {Number[]} - */ - get snappedCanvasPos() { - return this._gotSnappedCanvasPos ? this._snappedCanvasPos : null; - } - - /** - * @private - * @param value - */ - set snappedCanvasPos(value) { - if (value) { - this._snappedCanvasPos[0] = value[0]; - this._snappedCanvasPos[1] = value[1]; - this._gotSnappedCanvasPos = true; - } else { - this._gotSnappedCanvasPos = false; - } - } - - /** - * Picked World-space point. - * @property worldPos - * @type {Number[]} - */ - get worldPos() { - return this._gotWorldPos ? this._worldPos : null; - } - - /** - * @private - * @param value - */ - set worldPos(value) { - if (value) { - this._worldPos[0] = value[0]; - this._worldPos[1] = value[1]; - this._worldPos[2] = value[2]; - this._gotWorldPos = true; - } else { - this._gotWorldPos = false; - } - } - - /** - * Picked View-space point. - * @property viewPos - * @type {Number[]} - */ - get viewPos() { - return this.entity && this._gotViewPos ? this._viewPos : null; - } - - /** - * @private - * @param value - */ - set viewPos(value) { - if (value) { - this._viewPos[0] = value[0]; - this._viewPos[1] = value[1]; - this._viewPos[2] = value[2]; - this._gotViewPos = true; - } else { - this._gotViewPos = false; - } - } - - /** - * Barycentric coordinate within picked triangle. - * @property bary - * @type {Number[]} - */ - get bary() { - return this.entity && this._gotBary ? this._bary : null; - } - - /** - * @private - * @param value - */ - set bary(value) { - if (value) { - this._bary[0] = value[0]; - this._bary[1] = value[1]; - this._bary[2] = value[2]; - this._gotBary = true; - } else { - this._gotBary = false; - } - } - - /** - * Normal vector at picked position on surface. - * @property worldNormal - * @type {Number[]} - */ - get worldNormal() { - return this.entity && this._gotWorldNormal ? this._worldNormal : null; - } - - /** - * @private - * @param value - */ - set worldNormal(value) { - if (value) { - this._worldNormal[0] = value[0]; - this._worldNormal[1] = value[1]; - this._worldNormal[2] = value[2]; - this._gotWorldNormal = true; - } else { - this._gotWorldNormal = false; - } - } - - /** - * UV coordinates at picked position on surface. - * @property uv - * @type {Number[]} - */ - get uv() { - return this.entity && this._gotUV ? this._uv : null; - } - - /** - * @private - * @param value - */ - set uv(value) { - if (value) { - this._uv[0] = value[0]; - this._uv[1] = value[1]; - this._gotUV = true; - } else { - this._gotUV = false; - } - } - - /** - * True if snapped to edge or vertex. - * @returns {boolean} - */ - get snapped() { - return this.snappedToEdge || this.snappedToVertex; - } - - /** - * @private - */ - reset() { - this.entity = null; - this.primIndex = -1; - this.primitive = null; - this.pickSurfacePrecision = false; - this._gotCanvasPos = false; - this._gotSnappedCanvasPos = false; - this._gotOrigin = false; - this._gotDirection = false; - this._gotIndices = false; - this._gotLocalPos = false; - this._gotWorldPos = false; - this._gotViewPos = false; - this._gotBary = false; - this._gotWorldNormal = false; - this._gotUV = false; - this.touchInput = false; - this.snappedToEdge = false; - this.snappedToVertex = false; - } -} - -const os = { - isIphoneSafari() { - const userAgent = window.navigator.userAgent; - const isIphone = /iPhone/i.test(userAgent); - const isSafari = /Safari/i.test(userAgent) && !/Chrome/i.test(userAgent); - - return isIphone && isSafari; - }, - isIphoneOrIpadSafari() { - const userAgent = window.navigator.userAgent; - const isIphoneOrIpad = /iPhone|iPad/i.test(userAgent) || ( - // iPad detection: Check for touch support and macOS-like user agent - /Macintosh/i.test(userAgent) && navigator.maxTouchPoints && navigator.maxTouchPoints > 2 - ); - const isSafari = /Safari/i.test(userAgent) && !/Chrome/i.test(userAgent); - return isIphoneOrIpad && isSafari; - }, - isTouchDevice() { - return ( - 'ontouchstart' in window || //works for most devices - navigator.maxTouchPoints > 0 || //works for modern touch devices - navigator.mxMaxTouchPoints > 0 //works for older microsoft touch devices - ) - } -}; - -/** - @desc Base class for {@link Viewer} plugin classes. - */ -class Plugin { - - /** - * Creates this Plugin and installs it into the given {@link Viewer}. - * - * @param {string} id ID for this plugin, unique among all plugins in the viewer. - * @param {Viewer} viewer The viewer. - * @param {Object} [cfg] Options - */ - constructor(id, viewer, cfg) { - - /** - * ID for this Plugin, unique within its {@link Viewer}. - * - * @type {string} - */ - this.id = (cfg && cfg.id) ? cfg.id : id; - - /** - * The Viewer that contains this Plugin. - * - * @type {Viewer} - */ - this.viewer = viewer; - - this._subIdMap = null; // Subscription subId pool - this._subIdEvents = null; // Subscription subIds mapped to event names - this._eventSubs = null; // Event names mapped to subscribers - this._eventSubsNum = null; - this._events = null; // Maps names to events - this._eventCallDepth = 0; // Helps us catch stack overflows from recursive events - - viewer.addPlugin(this); - } - - /** - * Schedule a task to perform on the next browser interval - * @param task - */ - scheduleTask(task) { - core.scheduleTask(task, null); - } - - /** - * Fires an event on this Plugin. - * - * Notifies existing subscribers to the event, optionally retains the event to give to - * any subsequent notifications on the event as they are made. - * - * @param {String} event The event type name - * @param {Object} value The event parameters - * @param {Boolean} [forget=false] When true, does not retain for subsequent subscribers - */ - fire(event, value, forget) { - if (!this._events) { - this._events = {}; - } - if (!this._eventSubs) { - this._eventSubs = {}; - this._eventSubsNum = {}; - } - if (forget !== true) { - this._events[event] = value || true; // Save notification - } - const subs = this._eventSubs[event]; - let sub; - if (subs) { // Notify subscriptions - for (const subId in subs) { - if (subs.hasOwnProperty(subId)) { - sub = subs[subId]; - this._eventCallDepth++; - if (this._eventCallDepth < 300) { - sub.callback.call(sub.scope, value); - } else { - this.error("fire: potential stack overflow from recursive event '" + event + "' - dropping this event"); - } - this._eventCallDepth--; - } - } - } - } - - /** - * Subscribes to an event on this Plugin. - * - * The callback is be called with this Plugin as scope. - * - * @param {String} event The event - * @param {Function} callback Called fired on the event - * @param {Object} [scope=this] Scope for the callback - * @return {String} Handle to the subscription, which may be used to unsubscribe with {@link #off}. - */ - on(event, callback, scope) { - if (!this._events) { - this._events = {}; - } - if (!this._subIdMap) { - this._subIdMap = new Map$1(); // Subscription subId pool - } - if (!this._subIdEvents) { - this._subIdEvents = {}; - } - if (!this._eventSubs) { - this._eventSubs = {}; - } - if (!this._eventSubsNum) { - this._eventSubsNum = {}; - } - let subs = this._eventSubs[event]; - if (!subs) { - subs = {}; - this._eventSubs[event] = subs; - this._eventSubsNum[event] = 1; - } else { - this._eventSubsNum[event]++; - } - const subId = this._subIdMap.addItem(); // Create unique subId - subs[subId] = { - callback: callback, - scope: scope || this - }; - this._subIdEvents[subId] = event; - const value = this._events[event]; - if (value !== undefined) { // A publication exists, notify callback immediately - callback.call(scope || this, value); - } - return subId; - } - - /** - * Cancels an event subscription that was previously made with {@link Plugin#on} or {@link Plugin#once}. - * - * @param {String} subId Subscription ID - */ - off(subId) { - if (subId === undefined || subId === null) { - return; - } - if (!this._subIdEvents) { - return; - } - const event = this._subIdEvents[subId]; - if (event) { - delete this._subIdEvents[subId]; - const subs = this._eventSubs[event]; - if (subs) { - delete subs[subId]; - this._eventSubsNum[event]--; - } - this._subIdMap.removeItem(subId); // Release subId - } - } - - /** - * Subscribes to the next occurrence of the given event, then un-subscribes as soon as the event is subIdd. - * - * This is equivalent to calling {@link Plugin#on}, and then calling {@link Plugin#off} inside the callback function. - * - * @param {String} event Data event to listen to - * @param {Function} callback Called when fresh data is available at the event - * @param {Object} [scope=this] Scope for the callback - */ - once(event, callback, scope) { - const self = this; - const subId = this.on(event, - function (value) { - self.off(subId); - callback.call(scope || this, value); - }, - scope); - } - - /** - * Returns true if there are any subscribers to the given event on this Plugin. - * - * @param {String} event The event - * @return {Boolean} True if there are any subscribers to the given event on this Plugin. - */ - hasSubs(event) { - return (this._eventSubsNum && (this._eventSubsNum[event] > 0)); - } - - /** - * Logs a message to the JavaScript developer console, prefixed with the ID of this Plugin. - * - * @param {String} msg The error message - */ - log(msg) { - console.log(`[xeokit plugin ${this.id}]: ${msg}`); - } - - /** - * Logs a warning message to the JavaScript developer console, prefixed with the ID of this Plugin. - * - * @param {String} msg The error message - */ - warn(msg) { - console.warn(`[xeokit plugin ${this.id}]: ${msg}`); - } - - /** - * Logs an error message to the JavaScript developer console, prefixed with the ID of this Plugin. - * - * @param {String} msg The error message - */ - error(msg) { - console.error(`[xeokit plugin ${this.id}]: ${msg}`); - } - - /** - * Sends a message to this Plugin. - * - * @private - */ - send(name, value) { - //... - } - - /** - * Destroys this Plugin and removes it from its {@link Viewer}. - */ - destroy() { - this.viewer.removePlugin(this); - } -} - -const defaultCSS = ".sk-fading-circle {\ - background: transparent;\ - margin: 20px auto;\ - width: 50px;\ - height:50px;\ - position: relative;\ - }\ - .sk-fading-circle .sk-circle {\ - width: 120%;\ - height: 120%;\ - position: absolute;\ - left: 0;\ - top: 0;\ - }\ - .sk-fading-circle .sk-circle:before {\ - content: '';\ - display: block;\ - margin: 0 auto;\ - width: 15%;\ - height: 15%;\ - background-color: #ff8800;\ - border-radius: 100%;\ - -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both;\ - animation: sk-circleFadeDelay 1.2s infinite ease-in-out both;\ - }\ - .sk-fading-circle .sk-circle2 {\ - -webkit-transform: rotate(30deg);\ - -ms-transform: rotate(30deg);\ - transform: rotate(30deg);\ - }\ - .sk-fading-circle .sk-circle3 {\ - -webkit-transform: rotate(60deg);\ - -ms-transform: rotate(60deg);\ - transform: rotate(60deg);\ - }\ - .sk-fading-circle .sk-circle4 {\ - -webkit-transform: rotate(90deg);\ - -ms-transform: rotate(90deg);\ - transform: rotate(90deg);\ - }\ - .sk-fading-circle .sk-circle5 {\ - -webkit-transform: rotate(120deg);\ - -ms-transform: rotate(120deg);\ - transform: rotate(120deg);\ - }\ - .sk-fading-circle .sk-circle6 {\ - -webkit-transform: rotate(150deg);\ - -ms-transform: rotate(150deg);\ - transform: rotate(150deg);\ - }\ - .sk-fading-circle .sk-circle7 {\ - -webkit-transform: rotate(180deg);\ - -ms-transform: rotate(180deg);\ - transform: rotate(180deg);\ - }\ - .sk-fading-circle .sk-circle8 {\ - -webkit-transform: rotate(210deg);\ - -ms-transform: rotate(210deg);\ - transform: rotate(210deg);\ - }\ - .sk-fading-circle .sk-circle9 {\ - -webkit-transform: rotate(240deg);\ - -ms-transform: rotate(240deg);\ - transform: rotate(240deg);\ - }\ - .sk-fading-circle .sk-circle10 {\ - -webkit-transform: rotate(270deg);\ - -ms-transform: rotate(270deg);\ - transform: rotate(270deg);\ - }\ - .sk-fading-circle .sk-circle11 {\ - -webkit-transform: rotate(300deg);\ - -ms-transform: rotate(300deg);\ - transform: rotate(300deg);\ - }\ - .sk-fading-circle .sk-circle12 {\ - -webkit-transform: rotate(330deg);\ - -ms-transform: rotate(330deg);\ - transform: rotate(330deg);\ - }\ - .sk-fading-circle .sk-circle2:before {\ - -webkit-animation-delay: -1.1s;\ - animation-delay: -1.1s;\ - }\ - .sk-fading-circle .sk-circle3:before {\ - -webkit-animation-delay: -1s;\ - animation-delay: -1s;\ - }\ - .sk-fading-circle .sk-circle4:before {\ - -webkit-animation-delay: -0.9s;\ - animation-delay: -0.9s;\ - }\ - .sk-fading-circle .sk-circle5:before {\ - -webkit-animation-delay: -0.8s;\ - animation-delay: -0.8s;\ - }\ - .sk-fading-circle .sk-circle6:before {\ - -webkit-animation-delay: -0.7s;\ - animation-delay: -0.7s;\ - }\ - .sk-fading-circle .sk-circle7:before {\ - -webkit-animation-delay: -0.6s;\ - animation-delay: -0.6s;\ - }\ - .sk-fading-circle .sk-circle8:before {\ - -webkit-animation-delay: -0.5s;\ - animation-delay: -0.5s;\ - }\ - .sk-fading-circle .sk-circle9:before {\ - -webkit-animation-delay: -0.4s;\ - animation-delay: -0.4s;\ - }\ - .sk-fading-circle .sk-circle10:before {\ - -webkit-animation-delay: -0.3s;\ - animation-delay: -0.3s;\ - }\ - .sk-fading-circle .sk-circle11:before {\ - -webkit-animation-delay: -0.2s;\ - animation-delay: -0.2s;\ - }\ - .sk-fading-circle .sk-circle12:before {\ - -webkit-animation-delay: -0.1s;\ - animation-delay: -0.1s;\ - }\ - @-webkit-keyframes sk-circleFadeDelay {\ - 0%, 39%, 100% { opacity: 0; }\ - 40% { opacity: 1; }\ - }\ - @keyframes sk-circleFadeDelay {\ - 0%, 39%, 100% { opacity: 0; }\ - 40% { opacity: 1; }\ - }"; - -/** - * @desc Displays a progress animation at the center of its {@link Canvas} while things are loading or otherwise busy. - * - * - * * Located at {@link Canvas#spinner}. - * * Automatically shown while things are loading, however may also be shown by application code wanting to indicate busyness. - * * {@link Spinner#processes} holds the count of active processes. As a process starts, it increments {@link Spinner#processes}, then decrements it on completion or failure. - * * A Spinner is only visible while {@link Spinner#processes} is greater than zero. - * - * ````javascript - * var spinner = viewer.scene.canvas.spinner; - * - * // Increment count of busy processes represented by the spinner; - * // assuming the count was zero, this now shows the spinner - * spinner.processes++; - * - * // Increment the count again, by some other process; spinner already visible, now requires two decrements - * // before it becomes invisible again - * spinner.processes++; - * - * // Decrement the count; count still greater than zero, so spinner remains visible - * spinner.process--; - * - * // Decrement the count; count now zero, so spinner becomes invisible - * spinner.process--; - * ```` - */ -class Spinner extends Component { - - /** - @private - */ - get type() { - return "Spinner"; - } - - /** - @private - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._canvas = cfg.canvas; - this._element = null; - this._isCustom = false; // True when the element is custom HTML - - if (cfg.elementId) { // Custom spinner element supplied - this._element = document.getElementById(cfg.elementId); - if (!this._element) { - this.error("Can't find given Spinner HTML element: '" + cfg.elementId + "' - will automatically create default element"); - } else { - this._adjustPosition(); - } - } - - if (!this._element) { - this._createDefaultSpinner(); - } - - this.processes = 0; - } - - /** @private */ - _createDefaultSpinner() { - this._injectDefaultCSS(); - const element = document.createElement('div'); - const style = element.style; - style["z-index"] = "9000"; - style.position = "absolute"; - element.innerHTML = '
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
'; - this._canvas.parentElement.appendChild(element); - this._element = element; - this._isCustom = false; - this._adjustPosition(); - } - - /** - * @private - */ - _injectDefaultCSS() { - const elementId = "xeokit-spinner-css"; - if (document.getElementById(elementId)) { - return; - } - const defaultCSSNode = document.createElement('style'); - defaultCSSNode.innerHTML = defaultCSS; - defaultCSSNode.id = elementId; - document.body.appendChild(defaultCSSNode); - } - - /** - * @private - */ - _adjustPosition() { // (Re)positions spinner DIV over the center of the canvas - called by Canvas - if (this._isCustom) { - return; - } - const canvas = this._canvas; - const element = this._element; - const style = element.style; - style["left"] = (canvas.offsetLeft + (canvas.clientWidth * 0.5) - (element.clientWidth * 0.5)) + "px"; - style["top"] = (canvas.offsetTop + (canvas.clientHeight * 0.5) - (element.clientHeight * 0.5)) + "px"; - } - - /** - * Sets the number of processes this Spinner represents. - * - * The Spinner is visible while this property is greater than zero. - * - * Increment this property whenever you commence some process during which you want the Spinner to be visible, then decrement it again when the process is complete. - * - * Clamps to zero if you attempt to set to to a negative value. - * - * Fires a {@link Spinner#processes:event} event on change. - - * Default value is ````0````. - * - * @param {Number} value New processes count. - */ - set processes(value) { - value = value || 0; - if (this._processes === value) { - return; - } - if (value < 0) { - return; - } - const prevValue = this._processes; - this._processes = value; - const element = this._element; - if (element) { - element.style["visibility"] = (this._processes > 0) ? "visible" : "hidden"; - } - /** - Fired whenever this Spinner's {@link Spinner#visible} property changes. - - @event processes - @param value The property's new value - */ - this.fire("processes", this._processes); - if (this._processes === 0 && this._processes !== prevValue) { - /** - Fired whenever this Spinner's {@link Spinner#visible} property becomes zero. - - @event zeroProcesses - */ - this.fire("zeroProcesses", this._processes); - } - } - - /** - * Gets the number of processes this Spinner represents. - * - * The Spinner is visible while this property is greater than zero. - * - * @returns {Number} Current processes count. - */ - get processes() { - return this._processes; - } - - _destroy() { - if (this._element && (!this._isCustom)) { - this._element.parentNode.removeChild(this._element); - this._element = null; - } - const styleElement = document.getElementById("xeokit-spinner-css"); - if (styleElement) { - styleElement.parentNode.removeChild(styleElement); - } - } -} - -const WEBGL_CONTEXT_NAMES = [ - "webgl2", - "experimental-webgl", - "webkit-3d", - "moz-webgl", - "moz-glweb20" -]; - -/** - * @desc Manages its {@link Scene}'s HTML canvas. - * - * * Provides the HTML canvas element in {@link Canvas#canvas}. - * * Has a {@link Spinner}, provided at {@link Canvas#spinner}, which manages the loading progress indicator. - */ -class Canvas extends Component { - - /** - * @constructor - * @private - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._backgroundColor = math.vec3([ - cfg.backgroundColor ? cfg.backgroundColor[0] : 1, - cfg.backgroundColor ? cfg.backgroundColor[1] : 1, - cfg.backgroundColor ? cfg.backgroundColor[2] : 1]); - this._backgroundColorFromAmbientLight = !!cfg.backgroundColorFromAmbientLight; - - /** - * The HTML canvas. - * - * @property canvas - * @type {HTMLCanvasElement} - * @final - */ - this.canvas = cfg.canvas; - - /** - * The WebGL rendering context. - * - * @property gl - * @type {WebGLRenderingContext} - * @final - */ - this.gl = null; - - /** - * True when WebGL 2 support is enabled. - * - * @property webgl2 - * @type {Boolean} - * @final - */ - this.webgl2 = false; // Will set true in _initWebGL if WebGL is requested and we succeed in getting it. - - /** - * Indicates if this Canvas is transparent. - * - * @property transparent - * @type {Boolean} - * @default {false} - * @final - */ - this.transparent = !!cfg.transparent; - - /** - * Attributes for the WebGL context - * - * @type {{}|*} - */ - this.contextAttr = cfg.contextAttr || {}; - this.contextAttr.alpha = this.transparent; - - this.contextAttr.preserveDrawingBuffer = !!this.contextAttr.preserveDrawingBuffer; - this.contextAttr.stencil = false; - this.contextAttr.premultipliedAlpha = (!!this.contextAttr.premultipliedAlpha); // False by default: https://github.com/xeokit/xeokit-sdk/issues/251 - this.contextAttr.antialias = (this.contextAttr.antialias !== false); - - // If the canvas uses css styles to specify the sizes make sure the basic - // width and height attributes match or the WebGL context will use 300 x 150 - - this.resolutionScale = cfg.resolutionScale; - - this.canvas.width = Math.round(this.canvas.clientWidth * this._resolutionScale); - this.canvas.height = Math.round(this.canvas.clientHeight * this._resolutionScale); - - /** - * Boundary of the Canvas in absolute browser window coordinates. - * - * ### Usage: - * - * ````javascript - * var boundary = myScene.canvas.boundary; - * - * var xmin = boundary[0]; - * var ymin = boundary[1]; - * var width = boundary[2]; - * var height = boundary[3]; - * ```` - * - * @property boundary - * @type {Number[]} - * @final - */ - this.boundary = [ - this.canvas.offsetLeft, this.canvas.offsetTop, - this.canvas.clientWidth, this.canvas.clientHeight - ]; - - // Get WebGL context - - this._initWebGL(cfg); - - const self = this; - - // Attach to resize events on the canvas - let dirtyBoundary = true; // make sure we publish the 1st boundary event - - const resizeObserver = new ResizeObserver((entries) => { - for (const entry of entries) { - if (entry.contentBoxSize) { - dirtyBoundary = true; - } - } - }); - - resizeObserver.observe(this.canvas); - - // Publish canvas size and position changes on each scene tick - this._tick = this.scene.on("tick", () => { - // Only publish if the canvas bounds changed - if (!dirtyBoundary) { - return; - } - - dirtyBoundary = false; - - // Set the real size of the canvas (the drawable w*h) - self.canvas.width = Math.round(self.canvas.clientWidth * self._resolutionScale); - self.canvas.height = Math.round(self.canvas.clientHeight * self._resolutionScale); - - // Publish the boundary change - self.boundary[0] = self.canvas.offsetLeft; - self.boundary[1] = self.canvas.offsetTop; - self.boundary[2] = self.canvas.clientWidth; - self.boundary[3] = self.canvas.clientHeight; - - self.fire("boundary", self.boundary); - }); - - this._spinner = new Spinner(this.scene, { - canvas: this.canvas, - elementId: cfg.spinnerElementId - }); - } - - /** - @private - */ - get type() { - return "Canvas"; - } - - /** - * Gets whether the canvas clear color will be derived from {@link AmbientLight} or {@link Canvas#backgroundColor} - * when {@link Canvas#transparent} is ```true```. - * - * When {@link Canvas#transparent} is ```true``` and this is ````true````, then the canvas clear color will - * be taken from the {@link Scene}'s ambient light color. - * - * When {@link Canvas#transparent} is ```true``` and this is ````false````, then the canvas clear color will - * be taken from {@link Canvas#backgroundColor}. - * - * Default value is ````true````. - * - * @type {Boolean} - */ - get backgroundColorFromAmbientLight() { - return this._backgroundColorFromAmbientLight; - } - - /** - * Sets if the canvas background color is derived from an {@link AmbientLight}. - * - * This only has effect when the canvas is not transparent. When not enabled, the background color - * will be the canvas element's HTML/CSS background color. - * - * Default value is ````true````. - * - * @type {Boolean} - */ - set backgroundColorFromAmbientLight(backgroundColorFromAmbientLight) { - this._backgroundColorFromAmbientLight = (backgroundColorFromAmbientLight !== false); - this.glRedraw(); - } - - /** - * Gets the canvas clear color. - * - * Default value is ````[1, 1, 1]````. - * - * @type {Number[]} - */ - get backgroundColor() { - return this._backgroundColor; - } - - /** - * Sets the canvas clear color. - * - * Default value is ````[1, 1, 1]````. - * - * @type {Number[]} - */ - set backgroundColor(value) { - if (value) { - this._backgroundColor[0] = value[0]; - this._backgroundColor[1] = value[1]; - this._backgroundColor[2] = value[2]; - } else { - this._backgroundColor[0] = 1.0; - this._backgroundColor[1] = 1.0; - this._backgroundColor[2] = 1.0; - } - this.glRedraw(); - } - - /** - * Gets the scale of the canvas back buffer relative to the CSS-defined size of the canvas. - * - * This is a common way to trade off rendering quality for speed. If the canvas size is defined in CSS, then - * setting this to a value between ````[0..1]```` (eg ````0.5````) will render into a smaller back buffer, giving - * a performance boost. - * - * @returns {*|number} The resolution scale. - */ - get resolutionScale() { - return this._resolutionScale; - } - - /** - * Sets the scale of the canvas back buffer relative to the CSS-defined size of the canvas. - * - * This is a common way to trade off rendering quality for speed. If the canvas size is defined in CSS, then - * setting this to a value between ````[0..1]```` (eg ````0.5````) will render into a smaller back buffer, giving - * a performance boost. - * - * @param {*|number} resolutionScale The resolution scale. - */ - set resolutionScale(resolutionScale) { - resolutionScale = resolutionScale || 1.0; - if (resolutionScale === this._resolutionScale) { - return; - } - this._resolutionScale = resolutionScale; - const canvas = this.canvas; - canvas.width = Math.round(canvas.clientWidth * this._resolutionScale); - canvas.height = Math.round(canvas.clientHeight * this._resolutionScale); - this.glRedraw(); - } - - /** - * The busy {@link Spinner} for this Canvas. - * - * @property spinner - * @type Spinner - * @final - */ - get spinner() { - return this._spinner; - } - - /** - * Creates a default canvas in the DOM. - * @private - */ - _createCanvas() { - - const canvasId = "xeokit-canvas-" + math.createUUID(); - const body = document.getElementsByTagName("body")[0]; - const div = document.createElement('div'); - - const style = div.style; - style.height = "100%"; - style.width = "100%"; - style.padding = "0"; - style.margin = "0"; - style.background = "rgba(0,0,0,0);"; - style.float = "left"; - style.left = "0"; - style.top = "0"; - style.position = "absolute"; - style.opacity = "1.0"; - style["z-index"] = "-10000"; - - div.innerHTML += ''; - - body.appendChild(div); - - this.canvas = document.getElementById(canvasId); - } - - _getElementXY(e) { - let x = 0, y = 0; - while (e) { - x += (e.offsetLeft - e.scrollLeft); - y += (e.offsetTop - e.scrollTop); - e = e.offsetParent; - } - return {x: x, y: y}; - } - - /** - * Initialises the WebGL context - * @private - */ - _initWebGL() { - - // Default context attribute values - - if (!this.gl) { - for (let i = 0; !this.gl && i < WEBGL_CONTEXT_NAMES.length; i++) { - try { - this.gl = this.canvas.getContext(WEBGL_CONTEXT_NAMES[i], this.contextAttr); - } catch (e) { // Try with next context name - } - } - } - - if (!this.gl) { - - this.error('Failed to get a WebGL context'); - - /** - * Fired whenever the canvas failed to get a WebGL context, which probably means that WebGL - * is either unsupported or has been disabled. - * @event webglContextFailed - */ - this.fire("webglContextFailed", true, true); - } - - // data-textures: avoid to re-bind same texture - { - const gl = this.gl; - - let lastTextureUnit = "__"; - - let originalActiveTexture = gl.activeTexture; - - gl.activeTexture = function (arg1) { - if (lastTextureUnit === arg1) { - return; - } - - lastTextureUnit = arg1; - - originalActiveTexture.call (this, arg1); - }; - - let lastBindTexture = {}; - - let originalBindTexture = gl.bindTexture; - - gl.bindTexture = function (arg1, arg2) { - if (lastBindTexture[lastTextureUnit] === arg2) - { - return; - } - - lastBindTexture[lastTextureUnit] = arg2; - - originalBindTexture.call (this, arg1, arg2); - }; - - // setInterval ( - // () => { - // console.log (`${avoidedRebinds} avoided texture binds/sec`); - // avoidedRebinds = 0; - // }, - // 1000 - // ); - } - - if (this.gl) { - // Setup extension (if necessary) and hints for fragment shader derivative functions - if (this.webgl2) { - this.gl.hint(this.gl.FRAGMENT_SHADER_DERIVATIVE_HINT, this.gl.FASTEST); - - // data-textures: not using standard-derivatives - if (!(this.gl instanceof WebGL2RenderingContext)) ; - } - } - } - - /** - * @private - * @deprecated - */ - getSnapshot(params) { - throw "Canvas#getSnapshot() has been replaced by Viewer#getSnapshot() - use that method instead."; - } - - /** - * Reads colors of pixels from the last rendered frame. - * - * Call this method like this: - * - * ````JavaScript - * - * var colors = new Float32Array(8); - * - * viewer.scene.canvas.readPixels([ 100, 22, 12, 33 ], colors, 2); - * ```` - * - * Then the r,g,b components of the colors will be set to the colors at those pixels. - * - * @param {Number[]} pixels - * @param {Number[]} colors - * @param {Number} size - */ - readPixels(pixels, colors, size) { - return this.scene._renderer.snapshot.readPixels(pixels, colors, size); - } - - /** - * Simulates lost WebGL context. - */ - loseWebGLContext() { - if (this.canvas.loseContext) { - this.canvas.loseContext(); - } - } - - destroy() { - this.scene.off(this._tick); - this._spinner._destroy(); - this.gl = null; - super.destroy(); - } -} - -/** - * @desc Provides rendering context to {@link Drawable"}s as xeokit renders them for a frame. - * - * Also creates RTC viewing and picking matrices, caching and reusing matrices within each frame. - * - * @private - */ -class FrameContext { - - constructor(scene) { - this._matPool = []; - this.reset(); - } - - /** - * Called by the renderer before each frame. - * @private - */ - reset() { - - this._matPoolNextFreeIndex = 0; - this._rtcViewMats = {}; - - /** - * ID of the last {@link WebGLProgram} that was bound during the current frame. - * @property lastProgramId - * @type {Number} - */ - this.lastProgramId = null; - - /** - * Whether to render a physically-based representation for triangle surfaces. - * - * When ````false````, we'll render them with a fast vertex-shaded Gouraud-shaded representation, which - * is great for zillions of objects. - * - * When ````true````, we'll render them at a better visual quality, using smooth, per-fragment shading - * and a more realistic lighting model. - * - * @property quality - * @default false - * @type {Boolean} - */ - this.pbrEnabled = false; - - /** - * Whether to render color textures for triangle surfaces. - * - * @property quality - * @default false - * @type {Boolean} - */ - this.colorTextureEnabled = false; - - /** - * Whether SAO is currently enabled during the current frame. - * @property withSAO - * @default false - * @type {Boolean} - */ - this.withSAO = false; - - /** - * Whether backfaces are currently enabled during the current frame. - * @property backfaces - * @default false - * @type {Boolean} - */ - this.backfaces = false; - - /** - * The vertex winding order for what we currently consider to be a backface during current - * frame: true == "cw", false == "ccw". - * @property frontFace - * @default true - * @type {Boolean} - */ - this.frontface = true; - - /** - * The next available texture unit to bind a {@link Texture} to. - * @defauilt 0 - * @property textureUnit - * @type {number} - */ - this.textureUnit = 0; - - /** - * Performance statistic that counts how many times the renderer has called ````gl.drawElements()```` has been - * called so far within the current frame. - * @default 0 - * @property drawElements - * @type {number} - */ - this.drawElements = 0; - - /** - * Performance statistic that counts how many times ````gl.drawArrays()```` has been called so far within - * the current frame. - * @default 0 - * @property drawArrays - * @type {number} - */ - this.drawArrays = 0; - - /** - * Performance statistic that counts how many times ````gl.useProgram()```` has been called so far within - * the current frame. - * @default 0 - * @property useProgram - * @type {number} - */ - this.useProgram = 0; - - /** - * Statistic that counts how many times ````gl.bindTexture()```` has been called so far within the current frame. - * @default 0 - * @property bindTexture - * @type {number} - */ - this.bindTexture = 0; - - /** - * Counts how many times the renderer has called ````gl.bindArray()```` so far within the current frame. - * @defaulr 0 - * @property bindArray - * @type {number} - */ - this.bindArray = 0; - - /** - * Indicates which pass the renderer is currently rendering. - * - * See {@link Scene/passes:property"}}Scene#passes{{/crossLink}}, which configures how many passes we render - * per frame, which typically set to ````2```` when rendering a stereo view. - * - * @property pass - * @type {number} - */ - this.pass = 0; - - this.viewParams = { }; - - /** - * The 4x4 view matrix. - * - * @property viewMatrix - * @type {Number[]} - */ - this.viewParams.viewMatrix = null; - - /** - * The 4x4 projection matrix. - * - * @property projMatrix - * @type {Number[]} - */ - this.viewParams.projMatrix = null; - - /** - * Distance to the near clipping plane when rendering depth fragments for GPU-accelerated 3D picking. - * - * @property near - * @type {Number|*} - */ - this.viewParams.near = 0.01; - - /** - * Distance to the far clipping plane when rendering depth fragments for GPU-accelerated 3D picking. - * - * @property far - * @type {Number|*} - */ - this.viewParams.far = 5000; - - /** - * Whether or not the renderer is currently picking invisible objects. - * - * @property pickInvisible - * @type {Number} - */ - this.pickInvisible = false; - - /** The current line width. - * - * @property lineWidth - * @type Number - */ - this.lineWidth = 1; - - /** - * Collects info from SceneModel.drawSnapInit and SceneModel.drawSnap, - * which is then used in Renderer to determine snap-picking results. - * - * @type {[]} - */ - this.snapPickLayerParams = []; - - /** - * Collects info from SceneModel.drawSnapInit and SceneModel.drawSnap, - * which is then used in Renderer to determine snap-picking results. - * @type {Number[]} - */ - this.snapPickCoordinateScale = math.vec3(); - - /** - * Collects info from SceneModel.drawSnapInit and SceneModel.drawSnap, - * which is then used in Renderer to determine snap-picking results. - * @type {Number[]} - */ - this.snapPickOrigin = math.vec3(); - } - - /** - * Get View matrix for the given RTC center. - */ - getRTCViewMatrix(originHash, origin) { - let rtcViewMat = this._rtcViewMats[originHash]; - if (!rtcViewMat) { - rtcViewMat = this._getNewMat(); - createRTCViewMat(this.viewParams.viewMatrix, origin, rtcViewMat); - this._rtcViewMats[originHash] = rtcViewMat; - } - return rtcViewMat; - } - - _getNewMat() { - let mat = this._matPool[this._matPoolNextFreeIndex]; - if (!mat) { - mat = math.mat4(); - this._matPool[this._matPoolNextFreeIndex] = mat; - } - this._matPoolNextFreeIndex++; - return mat; - } -} - -/** - * @private - * @type {{WEBGL: boolean, SUPPORTED_EXTENSIONS: {}}} - */ -const WEBGL_INFO = { - WEBGL: false, - SUPPORTED_EXTENSIONS: {} -}; - -const canvas = document.createElement("canvas"); - -if (canvas) { - - const gl = canvas.getContext("webgl", {antialias: true}) || canvas.getContext("experimental-webgl", {antialias: true}); - - WEBGL_INFO.WEBGL = !!gl; - - if (WEBGL_INFO.WEBGL) { - WEBGL_INFO.ANTIALIAS = gl.getContextAttributes().antialias; - if (gl.getShaderPrecisionFormat) { - if (gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision > 0) { - WEBGL_INFO.FS_MAX_FLOAT_PRECISION = "highp"; - } else if (gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT).precision > 0) { - WEBGL_INFO.FS_MAX_FLOAT_PRECISION = "mediump"; - } else { - WEBGL_INFO.FS_MAX_FLOAT_PRECISION = "lowp"; - } - } else { - WEBGL_INFO.FS_MAX_FLOAT_PRECISION = "mediump"; - } - WEBGL_INFO.DEPTH_BUFFER_BITS = gl.getParameter(gl.DEPTH_BITS); - WEBGL_INFO.MAX_TEXTURE_SIZE = gl.getParameter(gl.MAX_TEXTURE_SIZE); - WEBGL_INFO.MAX_CUBE_MAP_SIZE = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE); - WEBGL_INFO.MAX_RENDERBUFFER_SIZE = gl.getParameter(gl.MAX_RENDERBUFFER_SIZE); - WEBGL_INFO.MAX_TEXTURE_UNITS = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS); - WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS); - WEBGL_INFO.MAX_VERTEX_ATTRIBS = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); - WEBGL_INFO.MAX_VERTEX_UNIFORM_VECTORS = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS); - WEBGL_INFO.MAX_FRAGMENT_UNIFORM_VECTORS = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS); - WEBGL_INFO.MAX_VARYING_VECTORS = gl.getParameter(gl.MAX_VARYING_VECTORS); - gl.getSupportedExtensions().forEach(function (ext) { - WEBGL_INFO.SUPPORTED_EXTENSIONS[ext] = true; - }); - } -} - -/** - * @private - */ -class OcclusionLayer { - - constructor(origin) { - this.aabb = math.AABB3(); - this.origin = math.vec3(origin); - this.originHash = this.origin.join(); - this.numMarkers = 0; - this.markers = {}; - this.markerList = []; // Ordered array of Markers - this.markerIndices = {}; // ID map of Marker indices in _markerList - this.positions = []; // Packed array of World-space marker positions - this.indices = []; // Indices corresponding to array above - this.positionsBuf = null; - this.lenPositionsBuf = 0; - this.indicesBuf = null; - this.sectionPlanesActive = []; - this.occlusionTestList = []; // List of - this.lenOcclusionTestList = 0; - this.pixels = []; - this.markerListDirty = false; - this.positionsDirty = true; - this.occlusionTestListDirty = false; - } - - addMarker(marker) { - this.markers[marker.id] = marker; - this.markerListDirty = true; - this.numMarkers++; - } - - markerWorldPosUpdated(marker) { - if (!this.markers[marker.id]) { // Not added - return; - } - const i = this.markerIndices[marker.id]; - this.positions[i * 3 + 0] = marker.worldPos[0]; - this.positions[i * 3 + 1] = marker.worldPos[1]; - this.positions[i * 3 + 2] = marker.worldPos[2]; - this.positionsDirty = true; // TODO: avoid reallocating VBO each time - } - - removeMarker(marker) { - delete this.markers[marker.id]; - this.markerListDirty = true; - this.numMarkers--; - } - - update(gl, markerInView) { - if (this.markerListDirty) { - this.numMarkers = 0; - for (var id in this.markers) { - if (this.markers.hasOwnProperty(id)) { - this.markerList[this.numMarkers] = this.markers[id]; - this.markerIndices[id] = this.numMarkers; - this.numMarkers++; - } - } - this.markerList.length = this.numMarkers; - this.markerListDirty = false; - this.positionsDirty = true; - this.occlusionTestListDirty = true; - } - - if (this.positionsDirty) { ////////////// TODO: Don't rebuild this when positions change, very wasteful - let j = 0; - for (let i = 0; i < this.numMarkers; i++) { - if (this.markerList[i]) { - const marker = this.markerList[i]; - const worldPos = marker.rtcPos; - this.positions[j++] = worldPos[0]; - this.positions[j++] = worldPos[1]; - this.positions[j++] = worldPos[2]; - this.indices[i] = i; - } - } - this.positions.length = this.numMarkers * 3; - this.indices.length = this.numMarkers; - this.positionsDirty = false; - - const aabb = this.aabb; - math.collapseAABB3(aabb); - math.expandAABB3Points3(aabb, this.positions); - const origin = this.origin; - aabb[0] += origin[0]; - aabb[1] += origin[1]; - aabb[2] += origin[2]; - aabb[3] += origin[0]; - aabb[4] += origin[1]; - aabb[5] += origin[2]; - - if (this.positionsBuf && (this.lenPositionsBuf !== this.positions.length)) { - this.positionsBuf.destroy(); - this.positionsBuf = null; - this.indicesBuf.destroy(); - this.indicesBuf = null; - } - - const positionsArr = new Float32Array(this.positions); - if (this.positionsBuf) { - this.positionsBuf.setData(positionsArr); // Just updating buffer elements, don't need to reallocate; Indices don't need updating - } else { - this.positionsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, positionsArr, positionsArr.length, 3, gl.STATIC_DRAW); - this.indicesBuf = new ArrayBuf(gl, gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(this.indices), this.indices.length, 1, gl.STATIC_DRAW); - this.lenPositionsBuf = this.positions.length; - } - } - - if (this.occlusionTestListDirty) { - let lenPixels = 0; - this.lenOcclusionTestList = 0; - for (let i = 0; i < this.numMarkers; i++) { - const marker = this.markerList[i]; - if ((marker.entity && !marker.entity.visible) || (! markerInView(marker))) { - marker._setVisible(false); - } else if (marker.occludable) { - this.occlusionTestList[this.lenOcclusionTestList++] = marker; - this.pixels[lenPixels++] = marker.canvasPos[0]; - this.pixels[lenPixels++] = marker.canvasPos[1]; - } else { - marker._setVisible(true); - } - } - } - } - - destroy() { - this.markers = {}; - this.markerList.length = 0; - if (this.positionsBuf) { - this.positionsBuf.destroy(); - } - if (this.indicesBuf) { - this.indicesBuf.destroy(); - } - } -} - -const MARKER_COLOR = math.vec3([ 255, 0, 0 ]); - -math.vec3(); - -/** - * Manages occlusion testing. Private member of a Renderer. - * @private - */ -class OcclusionTester { - - constructor(scene) { - - this._scene = scene; - - this._occlusionLayers = {}; - this._occlusionLayersList = []; - this._occlusionLayersListDirty = false; - - this._drawable = null; - - this._markersToOcclusionLayersMap = {}; - - const camera = scene.camera; - const markOcclusionTestListDirty = () => { this._occlusionTestListDirty = true; }; - this._onCameraViewMatrix = camera.on("viewMatrix", markOcclusionTestListDirty); - this._onCameraProjMatrix = camera.on("projMatrix", markOcclusionTestListDirty); - this._onCanvasBoundary = scene.canvas.on("boundary", markOcclusionTestListDirty); - } - - _addMarker(marker, originHash) { - if (! this._occlusionLayers[originHash]) { - this._occlusionLayers[originHash] = new OcclusionLayer(marker.origin); - this._occlusionLayersListDirty = true; - } - const occlusionLayer = this._occlusionLayers[originHash]; - occlusionLayer.addMarker(marker); - this._markersToOcclusionLayersMap[marker.id] = occlusionLayer; - } - - _removeMarker(occlusionLayer, marker) { - if (occlusionLayer.numMarkers === 1) { - occlusionLayer.destroy(); - delete this._occlusionLayers[occlusionLayer.originHash]; - this._occlusionLayersListDirty = true; - } else { - occlusionLayer.removeMarker(marker); - } - delete this._markersToOcclusionLayersMap[marker.id]; - } - - /** - * Adds a Marker for occlusion testing. - * @param marker - */ - addMarker(marker) { - const originHash = marker.origin.join(); - this._addMarker(marker, originHash); - this._occlusionTestListDirty = true; - } - - /** - * Notifies OcclusionTester that a Marker has updated its World-space position. - * @param marker - */ - markerWorldPosUpdated(marker) { - const occlusionLayer = this._markersToOcclusionLayersMap[marker.id]; - if (occlusionLayer) { - const originHash = marker.origin.join(); - if (originHash !== occlusionLayer.originHash) { - this._removeMarker(occlusionLayer, marker); - this._addMarker(marker, originHash); - } else { - occlusionLayer.markerWorldPosUpdated(marker); - } - } - } - - /** - * Removes a Marker from occlusion testing. - * @param marker - */ - removeMarker(marker) { - const originHash = marker.origin.join(); - const occlusionLayer = this._occlusionLayers[originHash]; - if (occlusionLayer) { - this._removeMarker(occlusionLayer, marker); - } - } - - /** - * Returns true if an occlusion test is needed. - * - * @returns {Boolean} - */ - get needOcclusionTest() { - return this._occlusionTestListDirty; - } - - /** - * Draws {@link Marker}s to the render buffer. - */ - drawMarkers() { - - const scene = this._scene; - const canvas = scene.canvas; - const gl = canvas.gl; - const sectionPlanesState = scene._sectionPlanesState; - const shaderSourceHash = [canvas.canvas.id, sectionPlanesState.getHash()].join(";"); - - if ((! this._drawable) || (shaderSourceHash !== this._drawable.shaderSourceHash)) { - if (this._drawable) { - this._drawable.destroy(); - } - - const programVariablesState = createProgramVariablesState(); - - const programVariables = programVariablesState.programVariables; - const viewMatrix = programVariables.createUniform("mat4", "viewMatrix"); - const projMatrix = programVariables.createUniform("mat4", "projMatrix"); - const position = programVariables.createAttribute("vec3", "position"); - const outColor = programVariables.createOutput("vec4", "outColor"); - const clipPos = "clipPos"; - - const [program, errors] = programVariablesState.buildProgram( - gl, - "OcclusionTester", - { - sectionPlanesState: sectionPlanesState, - clippableTest: () => "true", - getVertexData: () => { - const src = [ ]; - src.push(`vec4 worldPosition = vec4(${position}, 1.0);`); - src.push(`vec4 ${clipPos} = ${projMatrix} * ${viewMatrix} * worldPosition;`); - if (scene.markerZOffset < 0.000) { - src.push(`${clipPos}.z += ${scene.markerZOffset};`); - } - return src; - }, - worldPositionAttribute: "worldPosition", - getPointSize: () => "20.0", - clipPos: clipPos, - appendFragmentOutputs: (src) => src.push(`${outColor} = vec4(1.0, 0.0, 0.0, 1.0);`) - }); - - if (errors) { - console.error(errors.join("\n")); - throw errors.join("\n"); - } else { - this._occlusionTestListDirty = true; - this._drawable = { - shaderSourceHash: shaderSourceHash, - destroy: () => program.destroy(), - drawCall: () => { - const camera = scene.camera; - const project = camera.project; - - program.bind(); - - projMatrix.setInputValue(project.matrix); - - const boundary = canvas.boundary; - const canvasWidth = boundary[2]; - const canvasHeight = boundary[3]; - const near = camera.perspective.near; // Assume near enough to ortho near - const markerInView = marker => { - const viewPos = marker.viewPos; - const canvasPos = marker.canvasPos; - const canvasX = canvasPos[0]; - const canvasY = canvasPos[1]; - return (viewPos[2] <= -near) && (canvasX >= -10) && (canvasY >= -10) && (canvasX <= canvasWidth + 10) && (canvasY <= canvasHeight + 10); - }; - - this._occlusionLayersList.forEach(occlusionLayer => { - occlusionLayer.update(gl, markerInView); - - const culled = sectionPlanesState.sectionPlanes.some((sectionPlane, i) => { - const intersect = sectionPlane.active ? math.planeAABB3Intersect(sectionPlane.dir, sectionPlane.dist, occlusionLayer.aabb) : 1; - const outside = (intersect === -1); - occlusionLayer.sectionPlanesActive[i] = (intersect === 0); // if outside, then sectionPlanesActive won't be even tested - return outside; - }); - - if (! culled) { - const origin = occlusionLayer.origin; - - viewMatrix.setInputValue(createRTCViewMat(camera.viewMatrix, origin)); - - program.inputSetters.setUniforms( - null, - { - view: { far: project.far }, - mesh: { - origin: origin, - renderFlags: { sectionPlanesActivePerLayer: occlusionLayer.sectionPlanesActive } - } - }); - - position.setInputValue(occlusionLayer.positionsBuf); - - const indicesBuf = occlusionLayer.indicesBuf; - indicesBuf.bind(); - gl.drawElements(gl.POINTS, indicesBuf.numItems, indicesBuf.itemType, 0); - } - }); - } - }; - } - } - - if (this._occlusionLayersListDirty) { - let numOcclusionLayers = 0; - for (let originHash in this._occlusionLayers) { - if (this._occlusionLayers.hasOwnProperty(originHash)) { - this._occlusionLayersList[numOcclusionLayers++] = this._occlusionLayers[originHash]; - } - } - this._occlusionLayersList.length = numOcclusionLayers; - this._occlusionLayersListDirty = false; - } - - if (this._occlusionTestListDirty) { - for (let i = 0, len = this._occlusionLayersList.length; i < len; i++) { - const occlusionLayer = this._occlusionLayersList[i]; - occlusionLayer.occlusionTestListDirty = true; - } - this._occlusionTestListDirty = false; - } - - this._drawable.drawCall(); - } - - /** - * Sets visibilities of {@link Marker}s according to whether or not they are obscured by anything in the render buffer. - */ - doOcclusionTest(readColorPixel) { - this._occlusionLayersList.forEach(occlusionLayer => { - for (let i = 0; i < occlusionLayer.lenOcclusionTestList; i++) { - const j = i * 2; - const color = readColorPixel(occlusionLayer.pixels[j], occlusionLayer.pixels[j + 1]); - occlusionLayer.occlusionTestList[i]._setVisible(math.compareVec3(MARKER_COLOR, color)); - } - }); - } - - /** - * Destroys this OcclusionTester. - */ - destroy() { - if (! this.destroyed) { - this._occlusionLayersList.forEach(layer => layer.destroy()); - this._drawable && this._drawable.destroy(); - this._scene.camera.off(this._onCameraViewMatrix); - this._scene.camera.off(this._onCameraProjMatrix); - this._scene.canvas.off(this._onCanvasBoundary); - this.destroyed = true; - } - } -} - -const vec3_0 = math.vec3([0,0,0]); - -const iota$1 = (n) => { const ret = [ ]; for (let i = 0; i < n; ++i) ret.push(i); return ret; }; - -const tempPlanes = iota$1(6).map(() => math.vec4()); -const tempVec4 = math.vec4(); - -const bitShiftScreenZ = math.vec4([1.0 / (256.0 * 256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0]); - -const pixelToInt = pix => pix[0] + (pix[1] << 8) + (pix[2] << 16) + (pix[3] << 24); - -const toWorldNormal = (n) => math.normalizeVec3(math.divVec3Scalar(n, math.MAX_INT, math.vec3())); -const toWorldPos = (p, origin, scale) => math.vec3([ p[0] * scale[0] + origin[0], - p[1] * scale[1] + origin[1], - p[2] * scale[2] + origin[2] ]); - -const makeFrustumAABBIntersectionTest = function(camera) { - const m = math.mat4(); - math.mulMat4(camera.projMatrix, camera.viewMatrix, m); - - for (let i = 0; i < 3; ++i) { - tempPlanes[i * 2 + 0][0] = m[ 3] + m[i]; - tempPlanes[i * 2 + 0][1] = m[ 7] + m[i + 4]; - tempPlanes[i * 2 + 0][2] = m[11] + m[i + 8]; - tempPlanes[i * 2 + 0][3] = m[15] + m[i + 12]; - - tempPlanes[i * 2 + 1][0] = m[ 3] - m[i]; - tempPlanes[i * 2 + 1][1] = m[ 7] - m[i + 4]; - tempPlanes[i * 2 + 1][2] = m[11] - m[i + 8]; - tempPlanes[i * 2 + 1][3] = m[15] - m[i + 12]; - } - - // Normalize each plane - tempPlanes.forEach(p => math.divVec4Scalar(p, math.lenVec3(p), p)); - - return aabb => tempPlanes.every(p => { - // Compute the positive vertex (farthest in direction of normal) - tempVec4[0] = aabb[(p[0] >= 0) ? 3 : 0]; - tempVec4[1] = aabb[(p[1] >= 0) ? 4 : 1]; - tempVec4[2] = aabb[(p[2] >= 0) ? 5 : 2]; - tempVec4[3] = 1; - return math.dotVec4(p, tempVec4) >= 0; - }); -}; - -const makeRayAABBIntersectionTest = (O, D) => aabb => { - let tmin = -Infinity; - let tmax = Infinity; - - for (let i = 0; i < 3; i++) { - const origin = O[i]; - const direction = D[i]; - const minBound = aabb[i]; - const maxBound = aabb[i + 3]; - - if (Math.abs(direction) < 1e-8) { - // Ray is parallel to plane - if ((origin < minBound) || (origin > maxBound)) { - return false; // No intersection - } - } else { - const t1 = (minBound - origin) / direction; - const t2 = (maxBound - origin) / direction; - - tmin = Math.max(tmin, Math.min(t1, t2)); // near - tmax = Math.min(tmax, Math.max(t1, t2)); // far - - if (tmin > tmax) { - return false; // No intersection - } - } - } - - return tmax >= 0; // Check if intersection is in front of ray -}; - -/** - * @private - */ -const Renderer$1 = function (scene, options) { - - options = options || {}; - - const frameCtx = new FrameContext(); - const canvas = scene.canvas.canvas; - /** - * @type {WebGL2RenderingContext} - */ - const gl = scene.canvas.gl; - const canvasTransparent = (!!options.transparent); - const alphaDepthMask = options.alphaDepthMask; - - const pickIDs = new Map$1({}); - - let drawableTypeInfo = {}; - let drawables = {}; - - let postSortDrawableList = []; - let postCullDrawableList = []; - let uiDrawableList = []; - - let drawableListDirty = true; - let stateSortDirty = true; - let imageDirty = true; - - let transparentEnabled = true; - let edgesEnabled = true; - let saoEnabled = true; - let pbrEnabled = true; - let colorTextureEnabled = true; - - const renderBufferManager = (function() { - const renderBuffersBasic = {}; - const renderBuffersScaled = {}; - return { - getRenderBuffer: (id, colorFormats, hasDepthTexture) => { - const renderBuffers = (scene.canvas.resolutionScale === 1.0) ? renderBuffersBasic : renderBuffersScaled; - if (! renderBuffers[id]) { - renderBuffers[id] = new RenderBuffer(gl, colorFormats, hasDepthTexture); - } - return renderBuffers[id]; - }, - destroy: () => { - Object.values(renderBuffersBasic ).forEach(buf => buf.destroy()); - Object.values(renderBuffersScaled).forEach(buf => buf.destroy()); - } - }; - })(); - - const SAOProgram = (gl, name, programVariablesState, createOutColorDefinition) => { - const programVariables = programVariablesState.programVariables; - - const uViewportInv = programVariables.createUniform("vec2", "uViewportInv"); - const uCameraNear = programVariables.createUniform("float", "uCameraNear"); - const uCameraFar = programVariables.createUniform("float", "uCameraFar"); - const uDepthTexture = programVariables.createUniform("sampler2D", "uDepthTexture"); - - const uv = programVariables.createAttribute("vec2", "uv"); - const vUV = programVariables.createVarying("vec2", "vUV", () => uv); - const outColor = programVariables.createOutput("vec4", "outColor"); - - const getOutColor = programVariables.createFragmentDefinition( - "getOutColor", - (name, src) => { - const getDepth = "getDepth"; - src.push(` - float ${getDepth}(const in vec2 uv) { - return texture(${uDepthTexture}, uv).r; - } - `); - src.push(createOutColorDefinition(name, vUV, uViewportInv, uCameraNear, uCameraFar, getDepth)); - }); - - const [program, errors] = programVariablesState.buildProgram( - gl, - name, - { - clipPos: `vec4(2.0 * ${uv} - 1.0, 0.0, 1.0)`, - appendFragmentOutputs: (src) => src.push(`${outColor} = ${getOutColor}();`) - }); - - if (errors) { - console.error(errors.join("\n")); - throw errors; - } else { - const uvs = new Float32Array([1,1, 0,1, 0,0, 1,0]); - const uvBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, uvs, uvs.length, 2, gl.STATIC_DRAW); - - // Mitigation: if Uint8Array is used, the geometry is corrupted on OSX when using Chrome with data-textures - const indices = new Uint32Array([0, 1, 2, 0, 2, 3]); - const indicesBuf = new ArrayBuf(gl, gl.ELEMENT_ARRAY_BUFFER, indices, indices.length, 1, gl.STATIC_DRAW); - - return { - destroy: program.destroy, - bind: (viewportSize, project, depthTexture) => { - program.bind(); - uViewportInv.setInputValue([1 / viewportSize[0], 1 / viewportSize[1]]); - uCameraNear.setInputValue(project.near); - uCameraFar.setInputValue(project.far); - uDepthTexture.setInputValue(depthTexture); - uv.setInputValue(uvBuf); - }, - draw: () => { - indicesBuf.bind(); - gl.drawElements(gl.TRIANGLES, indicesBuf.numItems, indicesBuf.itemType, 0); - } - }; - } - }; - - // SAO implementation inspired from previous SAO work in THREE.js by ludobaka / ludobaka.github.io and bhouston - const saoOcclusionRenderer = (function() { - let currentRenrerer = null; - let curNumSamples = null; - return { - destroy: () => currentRenrerer && currentRenrerer.destroy(), - render: (viewportSize, project, sao, depthTexture) => { - const numSamples = Math.floor(sao.numSamples); - if (curNumSamples !== numSamples) { - currentRenrerer && currentRenrerer.destroy(); - - const programVariablesState = createProgramVariablesState(); - - const programVariables = programVariablesState.programVariables; - - const uProjectMatrix = programVariables.createUniform("mat4", "uProjectMatrix"); - const uInvProjMatrix = programVariables.createUniform("mat4", "uInvProjMatrix"); - const uPerspective = programVariables.createUniform("bool", "uPerspective"); - const uScale = programVariables.createUniform("float", "uScale"); - const uIntensity = programVariables.createUniform("float", "uIntensity"); - const uBias = programVariables.createUniform("float", "uBias"); - const uKernelRadius = programVariables.createUniform("float", "uKernelRadius"); - const uMinResolution = programVariables.createUniform("float", "uMinResolution"); - const uRandomSeed = programVariables.createUniform("float", "uRandomSeed"); - - const program = SAOProgram( - gl, - "SAOOcclusionRenderer", - programVariablesState, - (name, vUV, uViewportInv, uCameraNear, uCameraFar, getDepth) => { - return ` - #define EPSILON 1e-6 - #define PI 3.14159265359 - #define PI2 6.28318530718 - #define NUM_SAMPLES ${numSamples} - #define NUM_RINGS 4 - - const vec3 packFactors = vec3(256. * 256. * 256., 256. * 256., 256.); - - vec4 packFloatToRGBA(const in float v) { - vec4 r = vec4(fract(v * packFactors), v); - r.yzw -= r.xyz / 256.; - return r * 256. / 255.; - } - - highp float rand(const in vec2 uv) { - const highp float a = 12.9898, b = 78.233, c = 43758.5453; - return fract(sin(mod(dot(uv, vec2(a, b)), PI)) * c); - } - - vec3 getViewPos(const in vec2 screenPos, const in float depth) { - float near = ${uCameraNear}; - float far = ${uCameraFar}; - float viewZ = (${uPerspective} - ? ((near * far) / ((far - near) * depth - far)) - : (depth * (near - far) - near)); - float clipW = ${uProjectMatrix}[2][3] * viewZ + ${uProjectMatrix}[3][3]; - return (${uInvProjMatrix} * (clipW * vec4((vec3(screenPos, depth) - 0.5) * 2.0, 1.0))).xyz; - } - - vec4 ${name}() { - float centerDepth = ${getDepth}(${vUV}); - if (centerDepth >= (1.0 - EPSILON)) { - discard; - } - - vec3 centerViewPosition = getViewPos(${vUV}, centerDepth); - float scaleDividedByCameraFar = ${uScale} / ${uCameraFar}; - float minResolutionMultipliedByCameraFar = ${uMinResolution} * ${uCameraFar}; - vec3 centerViewNormal = normalize(cross(dFdx(centerViewPosition), dFdy(centerViewPosition))); - - vec2 radiusStep = ${uKernelRadius} * ${uViewportInv} / float(NUM_SAMPLES); - vec2 radius = radiusStep; - const float angleStep = PI2 * float(NUM_RINGS) / float(NUM_SAMPLES); - float angle = PI2 * rand(${vUV} + ${uRandomSeed}); - - float occlusionSum = 0.0; - float weightSum = 0.0; - - for (int i = 0; i < NUM_SAMPLES; i++) { - vec2 sampleUv = ${vUV} + vec2(cos(angle), sin(angle)) * radius; - radius += radiusStep; - angle += angleStep; - - float sampleDepth = ${getDepth}(sampleUv); - if (sampleDepth >= (1.0 - EPSILON)) { - continue; - } - - vec3 sampleViewPosition = getViewPos(sampleUv, sampleDepth); - vec3 viewDelta = sampleViewPosition - centerViewPosition; - float scaledScreenDistance = scaleDividedByCameraFar * length(viewDelta); - occlusionSum += max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - ${uBias}) / (1.0 + scaledScreenDistance * scaledScreenDistance ); - weightSum += 1.0; - } - - return packFloatToRGBA(1.0 - occlusionSum * ${uIntensity} / weightSum); - }`; - }); - - currentRenrerer = { - destroy: program.destroy, - render: (viewportSize, project, sao, depthTexture) => { - program.bind(viewportSize, project, depthTexture); - - uProjectMatrix.setInputValue(project.matrix); - uInvProjMatrix.setInputValue(project.inverseMatrix); - uPerspective.setInputValue(project.type === "Perspective"); - uScale.setInputValue(sao.scale * project.far / 5); - uIntensity.setInputValue(sao.intensity); - uBias.setInputValue(sao.bias); - uKernelRadius.setInputValue(sao.kernelRadius); - uMinResolution.setInputValue(sao.minResolution); - uRandomSeed.setInputValue(Math.random()); - - program.draw(); - } - }; - - curNumSamples = numSamples; - } - - currentRenrerer.render(viewportSize, project, sao, depthTexture); - } - }; - })(); - - const saoDepthLimitedBlurRenderer = (function() { - const blurStdDev = 4; - const blurDepthCutoff = 0.01; - const KERNEL_RADIUS = 16; - - const createSampleOffsets = (uvIncrement) => { - const offsets = []; - for (let i = 0; i <= KERNEL_RADIUS + 1; i++) { - offsets.push(uvIncrement[0] * i); - offsets.push(uvIncrement[1] * i); - } - return new Float32Array(offsets); - }; - - const sampleOffsetsVer = createSampleOffsets([0, 1]); - const sampleOffsetsHor = createSampleOffsets([1, 0]); - - const gaussian = (i, stdDev) => Math.exp(-(i * i) / (2.0 * (stdDev * stdDev))) / (Math.sqrt(2.0 * Math.PI) * stdDev); - const sampleWeights = new Float32Array(iota$1(KERNEL_RADIUS + 1).map(i => gaussian(i, blurStdDev))); // TODO: Optimize - - const programVariablesState = createProgramVariablesState(); - - const programVariables = programVariablesState.programVariables; - - const uDepthCutoff = programVariables.createUniform("float", "uDepthCutoff"); - const uSampleOffsets = programVariables.createUniformArray("vec2", "uSampleOffsets", KERNEL_RADIUS + 1); - const uSampleWeights = programVariables.createUniformArray("float", "uSampleWeights", KERNEL_RADIUS + 1); - - const uOcclusionTex = programVariables.createUniform("sampler2D", "uOcclusionTex"); - - const program = SAOProgram( - gl, - "SAODepthLimitedBlurRenderer", - programVariablesState, - (name, vUV, uViewportInv, uCameraNear, uCameraFar, getDepth) => { - return ` - #define EPSILON 1e-6 - - const vec3 packFactors = vec3(256. * 256. * 256., 256. * 256., 256.); - - vec4 packFloatToRGBA(const in float v) { - vec4 r = vec4(fract(v * packFactors), v); - r.yzw -= r.xyz / 256.; - return r * 256. / 255.; - } - - float getOcclusion(const in vec2 uv) { - vec4 v = texture(${uOcclusionTex}, uv); - return dot(floor(v * 255.0 + 0.5) / 255.0, 255. / 256. / vec4(packFactors, 1.)); // unpackRGBAToFloat - } - - float getViewZ(const in float depth) { - return (${uCameraNear} * ${uCameraFar}) / ((${uCameraFar} - ${uCameraNear}) * depth - ${uCameraFar}); - } - - vec4 ${name}() { - float centerDepth = ${getDepth}(${vUV}); - if (centerDepth >= (1.0 - EPSILON)) { - discard; - } - - float centerViewZ = getViewZ(centerDepth); - bool rBreak = false; - bool lBreak = false; - - float weightSum = ${uSampleWeights}[0]; - float occlusionSum = getOcclusion(${vUV}) * weightSum; - - for (int i = 1; i <= ${KERNEL_RADIUS}; i++) { - float sampleWeight = ${uSampleWeights}[i]; - vec2 sampleUVOffset = ${uSampleOffsets}[i] * ${uViewportInv}; - - if (! rBreak) { - vec2 rSampleUV = ${vUV} + sampleUVOffset; - if (abs(centerViewZ - getViewZ(${getDepth}(rSampleUV))) > ${uDepthCutoff}) { - rBreak = true; - } else { - occlusionSum += getOcclusion(rSampleUV) * sampleWeight; - weightSum += sampleWeight; - } - } - - if (! lBreak) { - vec2 lSampleUV = ${vUV} - sampleUVOffset; - if (abs(centerViewZ - getViewZ(${getDepth}(lSampleUV))) > ${uDepthCutoff}) { - lBreak = true; - } else { - occlusionSum += getOcclusion(lSampleUV) * sampleWeight; - weightSum += sampleWeight; - } - } - } - - return packFloatToRGBA(occlusionSum / weightSum); - }`; - }); - - return { - destroy: program.destroy, - render: (viewportSize, project, direction, depthTexture, occlusionTexture) => { - program.bind(viewportSize, project, depthTexture); - - uDepthCutoff.setInputValue(blurDepthCutoff); - uSampleOffsets.setInputValue((direction === 0) ? sampleOffsetsHor : sampleOffsetsVer); - uSampleWeights.setInputValue(sampleWeights); - uOcclusionTex.setInputValue(occlusionTexture); - - program.draw(); - } - }; - })(); - - const getSceneCameraViewParams = (function() { - let params = null; // scene.camera not defined yet - return function() { - if (! params) { - const camera = scene.camera; - params = { - get eye() { return camera.eye; }, - get far() { return camera.project.far; }, - get projMatrix() { return camera.projMatrix; }, - get viewMatrix() { return camera.viewMatrix; }, - get viewNormalMatrix() { return camera.viewNormalMatrix; } - }; - } - return params; - }; - })(); - - const getNearPlaneHeight = (camera, drawingBufferHeight) => ((camera.projection === "ortho") - ? 1.0 - : (drawingBufferHeight / (2 * Math.tan(0.5 * camera.perspective.fov * Math.PI / 180.0)))); - - this.scene = scene; - - this._occlusionTester = null; // Lazy-created in #addMarker() - - this.capabilities = { - astcSupported: !!getExtension(gl, 'WEBGL_compressed_texture_astc'), - etc1Supported: true, // WebGL2 - etc2Supported: !!getExtension(gl, 'WEBGL_compressed_texture_etc'), - dxtSupported: !!getExtension(gl, 'WEBGL_compressed_texture_s3tc'), - bptcSupported: !!getExtension(gl, 'EXT_texture_compression_bptc'), - pvrtcSupported: !!(getExtension(gl, 'WEBGL_compressed_texture_pvrtc') || getExtension(gl, 'WEBKIT_WEBGL_compressed_texture_pvrtc')) - }; - - this.setTransparentEnabled = function (enabled) { - transparentEnabled = enabled; - imageDirty = true; - }; - - this.setEdgesEnabled = function (enabled) { - edgesEnabled = enabled; - imageDirty = true; - }; - - this.setSAOEnabled = function (enabled) { - saoEnabled = enabled; - imageDirty = true; - }; - - this.setPBREnabled = function (enabled) { - pbrEnabled = enabled; - imageDirty = true; - }; - - this.setColorTextureEnabled = function (enabled) { - colorTextureEnabled = enabled; - imageDirty = true; - }; - - this.needStateSort = function () { - stateSortDirty = true; - }; - - this.shadowsDirty = function () { - }; - - this.imageDirty = function () { - imageDirty = true; - }; - - /** - * Inserts a drawable into this renderer. - * @private - */ - this.addDrawable = function (id, drawable) { - const type = drawable.type; - if (!type) { - console.error("Renderer#addDrawable() : drawable with ID " + id + " has no 'type' - ignoring"); - return; - } - let drawableInfo = drawableTypeInfo[type]; - if (!drawableInfo) { - drawableInfo = { - type: drawable.type, - count: 0, - isStateSortable: drawable.isStateSortable, - stateSortCompare: drawable.stateSortCompare, - drawableMap: {}, - drawableListPreCull: [], - drawableList: [] - }; - drawableTypeInfo[type] = drawableInfo; - } - drawableInfo.count++; - drawableInfo.drawableMap[id] = drawable; - drawables[id] = drawable; - drawableListDirty = true; - }; - - /** - * Removes a drawable from this renderer. - * @private - */ - this.removeDrawable = function (id) { - const drawable = drawables[id]; - if (!drawable) { - console.error("Renderer#removeDrawable() : drawable not found with ID " + id + " - ignoring"); - return; - } - const type = drawable.type; - const drawableInfo = drawableTypeInfo[type]; - if (--drawableInfo.count <= 0) { - delete drawableTypeInfo[type]; - } else { - delete drawableInfo.drawableMap[id]; - } - delete drawables[id]; - drawableListDirty = true; - }; - - /** - * Gets a unique pick ID for the given Pickable. A Pickable can be a {@link Mesh} or a {@link PerformanceMesh}. - * @returns {Number} New pick ID. - */ - this.getPickID = function (entity) { - return pickIDs.addItem(entity); - }; - - /** - * Released a pick ID for reuse. - * @param {Number} pickID Pick ID to release. - */ - this.putPickID = function (pickID) { - pickIDs.removeItem(pickID); - }; - - /** - * Clears the canvas. - * @private - */ - this.clear = function (params) { - gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); - if (canvasTransparent) { - gl.clearColor(1, 1, 1, 1); - } else { - const backgroundColor = scene.canvas.backgroundColorFromAmbientLight ? this.lights.getAmbientColorAndIntensity() : scene.canvas.backgroundColor; - gl.clearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], 1.0); - } - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - }; - - /** - * Returns true if the next call to render() will draw something - * @returns {Boolean} - */ - this.needsRender = function () { - const needsRender = (imageDirty || drawableListDirty || stateSortDirty); - return needsRender; - }; - - /** - * Renders inserted drawables. - * @private - */ - this.render = function(pass, clear) { - updateDrawlist(); - if (imageDirty) { - draw(pass, clear); - stats.frame.frameCount++; - imageDirty = false; - } - }; - - function updateDrawlist() { // Prepares state-sorted array of drawables from maps of inserted drawables - if (drawableListDirty) { - Object.values(drawableTypeInfo).forEach(drawableInfo => { - const drawableListPreCull = drawableInfo.drawableListPreCull; - let lenDrawableList = 0; - Object.values(drawableInfo.drawableMap).forEach(drawable => { drawableListPreCull[lenDrawableList++] = drawable; }); - drawableListPreCull.length = lenDrawableList; - }); - drawableListDirty = false; - stateSortDirty = true; - } - if (stateSortDirty) { - let lenDrawableList = 0; - Object.values(drawableTypeInfo).forEach(drawableInfo => { - drawableInfo.drawableListPreCull.forEach(drawable => { postSortDrawableList[lenDrawableList++] = drawable; }); - }); - postSortDrawableList.length = lenDrawableList; - postSortDrawableList.sort((a, b) => a.renderOrder - b.renderOrder); - stateSortDirty = false; - imageDirty = true; - } - if (imageDirty) { // Image is usually dirty because the camera moved - let lenDrawableList = 0; - let lenUiList = 0; - postSortDrawableList.forEach(drawable => { - drawable.rebuildRenderFlags(); - if (!drawable.renderFlags.culled) { - if (drawable.isUI) { - uiDrawableList[lenUiList++] = drawable; - } else { - postCullDrawableList[lenDrawableList++] = drawable; - } - } - }); - postCullDrawableList.length = lenDrawableList; - uiDrawableList.length = lenUiList; - } - } - - function draw(pass, clear) { - - const sao = scene.sao; - const occlusionTexture = saoEnabled && sao.possible && (sao.numSamples >= 1) && drawSAOBuffers(pass); - - scene._lightsState.lights.forEach(light => { - - if (light.castsShadow) { - const shadowRenderBuf = light.getShadowRenderBuf(); - shadowRenderBuf.bind(); - - frameCtx.reset(); - frameCtx.backfaces = true; - frameCtx.frontface = true; - frameCtx.viewParams.viewMatrix = light.getShadowViewMatrix(); - frameCtx.viewParams.projMatrix = light.getShadowProjMatrix(); - frameCtx.nearPlaneHeight = getNearPlaneHeight(scene.camera, gl.drawingBufferHeight); - - gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); - - gl.clearColor(0, 0, 0, 1); - gl.enable(gl.DEPTH_TEST); - gl.disable(gl.BLEND); - - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - - Object.values(drawableTypeInfo).forEach( - drawableInfo => { - drawableInfo.drawableList.forEach( - drawable => { - if ((drawable.visible !== false) && drawable.castsShadow && drawable.drawShadow) { - if (drawable.renderFlags.colorOpaque) { // Transparent objects don't cast shadows (yet) - drawable.drawShadow(frameCtx); - } - } - }); - }); - - shadowRenderBuf.unbind(); - } - }); - - drawColor(pass, clear, occlusionTexture); - } - - function drawSAOBuffers(pass) { - - const sao = scene.sao; - - const size = [gl.drawingBufferWidth, gl.drawingBufferHeight]; - - // Render depth buffer - const saoDepthRenderBuffer = renderBufferManager.getRenderBuffer("saoDepth", [], true); - saoDepthRenderBuffer.setSize(size); - saoDepthRenderBuffer.bind(); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - - frameCtx.reset(); - frameCtx.pass = pass; - frameCtx.viewParams = getSceneCameraViewParams(); - frameCtx.nearPlaneHeight = getNearPlaneHeight(scene.camera, gl.drawingBufferHeight); - - gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); - gl.clearColor(0, 0, 0, 0); - gl.enable(gl.DEPTH_TEST); - gl.frontFace(gl.CCW); - gl.enable(gl.CULL_FACE); - gl.depthMask(true); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - - postCullDrawableList.forEach(drawable => { - if (!drawable.culled && drawable.visible && drawable.drawDepth && drawable.saoEnabled && drawable.renderFlags.colorOpaque) { - drawable.drawDepth(frameCtx); - } - }); - - saoDepthRenderBuffer.unbind(); - - const depthTexture = saoDepthRenderBuffer.depthTexture; - - // Render occlusion buffer - - const occlusionRenderBuffer1 = renderBufferManager.getRenderBuffer("saoOcclusion"); - occlusionRenderBuffer1.setSize(size); - occlusionRenderBuffer1.bind(); - - gl.viewport(0, 0, size[0], size[1]); - gl.clearColor(0, 0, 0, 1); - gl.disable(gl.DEPTH_TEST); - gl.disable(gl.BLEND); - gl.frontFace(gl.CCW); - gl.clear(gl.COLOR_BUFFER_BIT); - - saoOcclusionRenderer.render(size, scene.camera.project, sao, depthTexture); - - occlusionRenderBuffer1.unbind(); - - if (sao.blur) { - const occlusionRenderBuffer2 = renderBufferManager.getRenderBuffer("saoOcclusion2"); - occlusionRenderBuffer2.setSize(size); - - const blurSAO = (src, dst, direction) => { - dst.bind(); - - gl.viewport(0, 0, size[0], size[1]); - gl.clearColor(0, 0, 0, 1); - gl.enable(gl.DEPTH_TEST); - gl.disable(gl.BLEND); - gl.frontFace(gl.CCW); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - - const project = scene.camera.project; - saoDepthLimitedBlurRenderer.render(size, project, direction, depthTexture, src.colorTextures[0]); - - dst.unbind(); - }; - - blurSAO(occlusionRenderBuffer1, occlusionRenderBuffer2, 0); // horizontally - blurSAO(occlusionRenderBuffer2, occlusionRenderBuffer1, 1); // vertically - } - - return occlusionRenderBuffer1.colorTextures[0]; - } - - function drawColor(pass, clear, occlusionTexture) { - - const normalDrawSAOBin = []; - const normalEdgesOpaqueBin = []; - const normalFillTransparentBin = []; - const normalEdgesTransparentBin = []; - - const xrayedFillOpaqueBin = []; - const xrayEdgesOpaqueBin = []; - const xrayedFillTransparentBin = []; - const xrayEdgesTransparentBin = []; - - const highlightedFillOpaqueBin = []; - const highlightedEdgesOpaqueBin = []; - const highlightedFillTransparentBin = []; - const highlightedEdgesTransparentBin = []; - - const selectedFillOpaqueBin = []; - const selectedEdgesOpaqueBin = []; - const selectedFillTransparentBin = []; - const selectedEdgesTransparentBin = []; - - - const ambientColorAndIntensity = scene._lightsState.getAmbientColorAndIntensity(); - - frameCtx.reset(); - frameCtx.pass = pass; - frameCtx.withSAO = false; - frameCtx.pbrEnabled = pbrEnabled && !!scene.pbrEnabled; - frameCtx.colorTextureEnabled = colorTextureEnabled && !!scene.colorTextureEnabled; - frameCtx.viewParams = getSceneCameraViewParams(); - frameCtx.nearPlaneHeight = getNearPlaneHeight(scene.camera, gl.drawingBufferHeight); - - gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); - - if (canvasTransparent) { - gl.clearColor(0, 0, 0, 0); - } else { - const backgroundColor = scene.canvas.backgroundColorFromAmbientLight ? ambientColorAndIntensity : scene.canvas.backgroundColor; - gl.clearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], 1.0); - } - - gl.enable(gl.DEPTH_TEST); - gl.frontFace(gl.CCW); - gl.enable(gl.CULL_FACE); - gl.depthMask(true); - gl.lineWidth(1); - - frameCtx.lineWidth = 1; - - scene.sao; - frameCtx.saoParams = [gl.drawingBufferWidth, gl.drawingBufferHeight, scene.sao.blendCutoff, scene.sao.blendFactor]; - frameCtx.occlusionTexture = occlusionTexture; - - let i; - let drawable; - - const startTime = Date.now(); - - if (clear) { - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - } - - frameCtx.testAABB = makeFrustumAABBIntersectionTest(scene.camera); - - const renderDrawables = function(drawables) { - - let normalDrawSAOBinLen = 0; - let normalEdgesOpaqueBinLen = 0; - let normalFillTransparentBinLen = 0; - let normalEdgesTransparentBinLen = 0; - - let xrayedFillOpaqueBinLen = 0; - let xrayEdgesOpaqueBinLen = 0; - let xrayedFillTransparentBinLen = 0; - let xrayEdgesTransparentBinLen = 0; - - let highlightedFillOpaqueBinLen = 0; - let highlightedEdgesOpaqueBinLen = 0; - let highlightedFillTransparentBinLen = 0; - let highlightedEdgesTransparentBinLen = 0; - - let selectedFillOpaqueBinLen = 0; - let selectedEdgesOpaqueBinLen = 0; - let selectedFillTransparentBinLen = 0; - let selectedEdgesTransparentBinLen = 0; - - //------------------------------------------------------------------------------------------------------ - // Render normal opaque solids, defer others to bins to render after - //------------------------------------------------------------------------------------------------------ - for (let i = 0, len = drawables.length; i < len; i++) { - - drawable = drawables[i]; - - if (drawable.culled === true || drawable.visible === false) { - continue; - } - - const renderFlags = drawable.renderFlags; - - if (renderFlags.colorOpaque) { - if (drawable.saoEnabled && occlusionTexture) { - normalDrawSAOBin[normalDrawSAOBinLen++] = drawable; - } else { - drawable.drawColorOpaque(frameCtx); - } - } - - if (transparentEnabled) { - if (renderFlags.colorTransparent) { - normalFillTransparentBin[normalFillTransparentBinLen++] = drawable; - } - } - - if (renderFlags.xrayedSilhouetteTransparent) { - xrayedFillTransparentBin[xrayedFillTransparentBinLen++] = drawable; - } - - if (renderFlags.xrayedSilhouetteOpaque) { - xrayedFillOpaqueBin[xrayedFillOpaqueBinLen++] = drawable; - } - - if (renderFlags.highlightedSilhouetteTransparent) { - highlightedFillTransparentBin[highlightedFillTransparentBinLen++] = drawable; - } - - if (renderFlags.highlightedSilhouetteOpaque) { - highlightedFillOpaqueBin[highlightedFillOpaqueBinLen++] = drawable; - } - - if (renderFlags.selectedSilhouetteTransparent) { - selectedFillTransparentBin[selectedFillTransparentBinLen++] = drawable; - } - - if (renderFlags.selectedSilhouetteOpaque) { - selectedFillOpaqueBin[selectedFillOpaqueBinLen++] = drawable; - } - - if (drawable.edges && edgesEnabled) { - if (renderFlags.edgesOpaque) { - normalEdgesOpaqueBin[normalEdgesOpaqueBinLen++] = drawable; - } - - if (renderFlags.edgesTransparent) { - normalEdgesTransparentBin[normalEdgesTransparentBinLen++] = drawable; - } - - if (renderFlags.selectedEdgesTransparent) { - selectedEdgesTransparentBin[selectedEdgesTransparentBinLen++] = drawable; - } - - if (renderFlags.selectedEdgesOpaque) { - selectedEdgesOpaqueBin[selectedEdgesOpaqueBinLen++] = drawable; - } - - if (renderFlags.xrayedEdgesTransparent) { - xrayEdgesTransparentBin[xrayEdgesTransparentBinLen++] = drawable; - } - - if (renderFlags.xrayedEdgesOpaque) { - xrayEdgesOpaqueBin[xrayEdgesOpaqueBinLen++] = drawable; - } - - if (renderFlags.highlightedEdgesTransparent) { - highlightedEdgesTransparentBin[highlightedEdgesTransparentBinLen++] = drawable; - } - - if (renderFlags.highlightedEdgesOpaque) { - highlightedEdgesOpaqueBin[highlightedEdgesOpaqueBinLen++] = drawable; - } - } - } - - //------------------------------------------------------------------------------------------------------ - // Render deferred bins - //------------------------------------------------------------------------------------------------------ - - // Opaque color with SAO - - if (normalDrawSAOBinLen > 0) { - frameCtx.withSAO = true; - for (i = 0; i < normalDrawSAOBinLen; i++) { - normalDrawSAOBin[i].drawColorOpaque(frameCtx); - } - } - - // Opaque edges - - if (normalEdgesOpaqueBinLen > 0) { - for (i = 0; i < normalEdgesOpaqueBinLen; i++) { - normalEdgesOpaqueBin[i].drawEdgesColorOpaque(frameCtx); - } - } - - // Opaque X-ray fill - - if (xrayedFillOpaqueBinLen > 0) { - for (i = 0; i < xrayedFillOpaqueBinLen; i++) { - xrayedFillOpaqueBin[i].drawSilhouetteXRayed(frameCtx); - } - } - - // Opaque X-ray edges - - if (xrayEdgesOpaqueBinLen > 0) { - for (i = 0; i < xrayEdgesOpaqueBinLen; i++) { - xrayEdgesOpaqueBin[i].drawEdgesXRayed(frameCtx); - } - } - - // Transparent - - if (xrayedFillTransparentBinLen > 0 || xrayEdgesTransparentBinLen > 0 || normalFillTransparentBinLen > 0 || normalEdgesTransparentBinLen > 0) { - gl.enable(gl.CULL_FACE); - gl.enable(gl.BLEND); - if (canvasTransparent) { - gl.blendEquation(gl.FUNC_ADD); - gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - } else { - gl.blendEquation(gl.FUNC_ADD); - gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); - } - frameCtx.backfaces = false; - if (!alphaDepthMask) { - gl.depthMask(false); - } - - // Transparent color edges - - if (normalFillTransparentBinLen > 0 || normalEdgesTransparentBinLen > 0) { - gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); - } - if (normalEdgesTransparentBinLen > 0) { - for (i = 0; i < normalEdgesTransparentBinLen; i++) { - drawable = normalEdgesTransparentBin[i]; - drawable.drawEdgesColorTransparent(frameCtx); - } - } - - // Transparent color fill - - if (normalFillTransparentBinLen > 0) { - const eye = frameCtx.viewParams.eye; - normalFillTransparentBin.length = normalFillTransparentBinLen; // normalFillTransparentBin reused by renderDrawables calls, so needs to be truncated if necessary - const byDist = normalFillTransparentBin.map(d => ({ drawable: d, distSq: math.distVec3(d.origin || vec3_0, eye) })); - byDist.sort((a, b) => b.distSq - a.distSq); - for (i = 0; i < normalFillTransparentBinLen; i++) { - byDist[i].drawable.drawColorTransparent(frameCtx); - } - } - - // Transparent X-ray edges - - if (xrayEdgesTransparentBinLen > 0) { - for (i = 0; i < xrayEdgesTransparentBinLen; i++) { - xrayEdgesTransparentBin[i].drawEdgesXRayed(frameCtx); - } - } - - // Transparent X-ray fill - - if (xrayedFillTransparentBinLen > 0) { - for (i = 0; i < xrayedFillTransparentBinLen; i++) { - xrayedFillTransparentBin[i].drawSilhouetteXRayed(frameCtx); - } - } - - gl.disable(gl.BLEND); - if (!alphaDepthMask) { - gl.depthMask(true); - } - } - - // Opaque highlight - - if (highlightedFillOpaqueBinLen > 0 || highlightedEdgesOpaqueBinLen > 0) { - frameCtx.lastProgramId = null; - if (scene.highlightMaterial.glowThrough) { - gl.clear(gl.DEPTH_BUFFER_BIT); - } - - // Opaque highlighted edges - - if (highlightedEdgesOpaqueBinLen > 0) { - for (i = 0; i < highlightedEdgesOpaqueBinLen; i++) { - highlightedEdgesOpaqueBin[i].drawEdgesHighlighted(frameCtx); - } - } - - // Opaque highlighted fill - - if (highlightedFillOpaqueBinLen > 0) { - for (i = 0; i < highlightedFillOpaqueBinLen; i++) { - highlightedFillOpaqueBin[i].drawSilhouetteHighlighted(frameCtx); - } - } - } - - // Highlighted transparent - - if (highlightedFillTransparentBinLen > 0 || highlightedEdgesTransparentBinLen > 0 || highlightedFillOpaqueBinLen > 0) { - frameCtx.lastProgramId = null; - if (scene.selectedMaterial.glowThrough) { - gl.clear(gl.DEPTH_BUFFER_BIT); - } - gl.enable(gl.BLEND); - if (canvasTransparent) { - gl.blendEquation(gl.FUNC_ADD); - gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - } else { - gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); - } - gl.enable(gl.CULL_FACE); - - // Highlighted transparent edges - - if (highlightedEdgesTransparentBinLen > 0) { - for (i = 0; i < highlightedEdgesTransparentBinLen; i++) { - highlightedEdgesTransparentBin[i].drawEdgesHighlighted(frameCtx); - } - } - - // Highlighted transparent fill - - if (highlightedFillTransparentBinLen > 0) { - for (i = 0; i < highlightedFillTransparentBinLen; i++) { - highlightedFillTransparentBin[i].drawSilhouetteHighlighted(frameCtx); - } - } - gl.disable(gl.BLEND); - } - - // Selected opaque - - if (selectedFillOpaqueBinLen > 0 || selectedEdgesOpaqueBinLen > 0) { - frameCtx.lastProgramId = null; - if (scene.selectedMaterial.glowThrough) { - gl.clear(gl.DEPTH_BUFFER_BIT); - } - - // Selected opaque fill - - if (selectedEdgesOpaqueBinLen > 0) { - for (i = 0; i < selectedEdgesOpaqueBinLen; i++) { - selectedEdgesOpaqueBin[i].drawEdgesSelected(frameCtx); - } - } - - // Selected opaque edges - - if (selectedFillOpaqueBinLen > 0) { - for (i = 0; i < selectedFillOpaqueBinLen; i++) { - selectedFillOpaqueBin[i].drawSilhouetteSelected(frameCtx); - } - } - } - - // Selected transparent - - if (selectedFillTransparentBinLen > 0 || selectedEdgesTransparentBinLen > 0) { - frameCtx.lastProgramId = null; - if (scene.selectedMaterial.glowThrough) { - gl.clear(gl.DEPTH_BUFFER_BIT); - } - gl.enable(gl.CULL_FACE); - gl.enable(gl.BLEND); - if (canvasTransparent) { - gl.blendEquation(gl.FUNC_ADD); - gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - } else { - gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); - } - - // Selected transparent edges - - if (selectedEdgesTransparentBinLen > 0) { - for (i = 0; i < selectedEdgesTransparentBinLen; i++) { - selectedEdgesTransparentBin[i].drawEdgesSelected(frameCtx); - } - } - - // Selected transparent fill - - if (selectedFillTransparentBinLen > 0) { - for (i = 0; i < selectedFillTransparentBinLen; i++) { - selectedFillTransparentBin[i].drawSilhouetteSelected(frameCtx); - } - } - gl.disable(gl.BLEND); - } - - }; - - renderDrawables(postCullDrawableList); - if (uiDrawableList.length > 0) { - gl.clear(gl.DEPTH_BUFFER_BIT); - renderDrawables(uiDrawableList); - } - - frameCtx.testAABB = null; - - const endTime = Date.now(); - const frameStats = stats.frame; - - frameStats.renderTime = (endTime - startTime) / 1000.0; - frameStats.drawElements = frameCtx.drawElements; - frameStats.drawArrays = frameCtx.drawArrays; - frameStats.useProgram = frameCtx.useProgram; - frameStats.bindTexture = frameCtx.bindTexture; - frameStats.bindArray = frameCtx.bindArray; - - const numTextureUnits = WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS; - for (let ii = 0; ii < numTextureUnits; ii++) { - gl.activeTexture(gl.TEXTURE0 + ii); - } - gl.bindTexture(gl.TEXTURE_CUBE_MAP, null); - gl.bindTexture(gl.TEXTURE_2D, null); - - const numVertexAttribs = WEBGL_INFO.MAX_VERTEX_ATTRIBS; // Fixes https://github.com/xeokit/xeokit-sdk/issues/174 - for (let ii = 0; ii < numVertexAttribs; ii++) { - gl.disableVertexAttribArray(ii); - } - } - - const resetPickFrameCtx = (canvasPos, clipTransformDiv, camera, eye, projMatrix, viewMatrix, frameCtx) => { - frameCtx.reset(); - frameCtx.backfaces = true; - frameCtx.frontface = true; // "ccw" - - frameCtx.viewParams.eye = eye; - frameCtx.viewParams.projMatrix = projMatrix; - frameCtx.viewParams.viewMatrix = viewMatrix; - frameCtx.nearPlaneHeight = getNearPlaneHeight(camera, gl.drawingBufferHeight); - - const resolutionScale = scene.canvas.resolutionScale; - frameCtx.pickClipPos = [ - canvasPos ? ( 2 * canvasPos[0] * resolutionScale / gl.drawingBufferWidth - 1) : 0, - canvasPos ? (1 - 2 * canvasPos[1] * resolutionScale / gl.drawingBufferHeight) : 0 - ]; - - frameCtx.pickClipPosInv = [ - gl.drawingBufferWidth / clipTransformDiv, - gl.drawingBufferHeight / clipTransformDiv - ]; - }; - - /** - * Picks an Entity. - * @private - */ - this.pick = (function () { - - const tempVec3a = math.vec3(); - const tempVec3b = math.vec3(); - const tempVec4a = math.vec4(); - const tempVec4b = math.vec4(); - const tempVec4c = math.vec4(); - const tempVec4d = math.vec4(); - const tempVec4e = math.vec4(); - const tempMat4a = math.mat4(); - const tempMat4b = math.mat4(); - const tempMat4c = math.mat4(); - const tempMat4d = math.mat4(); - - const upVec = math.vec3([0, 1, 0]); - const _pickResult = new PickResult(); - - const nearAndFar = math.vec2(); - - const canvasPos = math.vec3(); - - const worldRayOrigin = math.vec3(); - const worldRayDir = math.vec3(); - math.vec3(); - math.vec3(); - - const pickBuffer = new RenderBuffer(gl); - pickBuffer.setSize([1, 1]); - - const pickNormalBuffer = new RenderBuffer(gl, [gl.RGBA32I]); - pickNormalBuffer.setSize([3, 3]); - - return function (params, pickResult = _pickResult) { - - pickResult.reset(); - - updateDrawlist(); - - let pickViewMatrix = null; - let pickProjMatrix = null; - let projection = null; - const camera = scene.camera; - - pickResult.pickSurface = params.pickSurface; - - if (params.canvasPos) { - - canvasPos[0] = params.canvasPos[0]; - canvasPos[1] = params.canvasPos[1]; - - pickViewMatrix = camera.viewMatrix; - pickProjMatrix = camera.projMatrix; - projection = camera.projection; - - nearAndFar[0] = camera.project.near; - nearAndFar[1] = camera.project.far; - - pickResult.canvasPos = params.canvasPos; - - math.canvasPosToWorldRay(canvas, pickViewMatrix, pickProjMatrix, projection, canvasPos, tempVec3a, tempVec3b); - frameCtx.testAABB = makeRayAABBIntersectionTest(tempVec3a, tempVec3b); - } else { - - // Picking with arbitrary World-space ray - // Align camera along ray and fire ray through center of canvas - - canvasPos[0] = canvas.clientWidth * 0.5; - canvasPos[1] = canvas.clientHeight * 0.5; - - if (params.matrix) { - - pickViewMatrix = params.matrix; - pickProjMatrix = camera.projMatrix; - projection = camera.projection; - - nearAndFar[0] = camera.project.near; - nearAndFar[1] = camera.project.far; - - math.canvasPosToWorldRay(canvas, pickViewMatrix, pickProjMatrix, projection, canvasPos, tempVec3a, tempVec3b); - frameCtx.testAABB = makeRayAABBIntersectionTest(tempVec3a, tempVec3b); - } else { - - worldRayOrigin.set(params.origin || [0, 0, 0]); - worldRayDir.set(params.direction || [0, 0, 1]); - - const look = math.addVec3(worldRayOrigin, worldRayDir, tempVec3a); - const up = tempVec3b; - - if (Math.abs(math.dotVec3(worldRayDir, upVec)) > (1 - 1e-6)) { // worldRayDir aligned with Y axis - up[0] = 0; - up[1] = 0; - up[2] = Math.sign(worldRayDir[1]); - } else { - math.cross3Vec3(worldRayDir, upVec, up); - math.cross3Vec3(up, worldRayDir, up); - math.normalizeVec3(up, up); - } - - pickViewMatrix = math.lookAtMat4v(worldRayOrigin, look, up, tempMat4b); - // pickProjMatrix = camera.projMatrix; - pickProjMatrix = camera.ortho.matrix; - projection = "ortho"; - - nearAndFar[0] = camera.ortho.near; - nearAndFar[1] = camera.ortho.far; - - pickResult.origin = worldRayOrigin; - pickResult.direction = worldRayDir; - - frameCtx.testAABB = makeRayAABBIntersectionTest(pickResult.origin, pickResult.direction); - } - } - - pickBuffer.bind(); - - const resetFrameCtx = (clipTransformDiv) => resetPickFrameCtx(canvasPos, clipTransformDiv, camera, pickResult.origin || camera.eye, pickProjMatrix || camera.projMatrix, pickViewMatrix || camera.viewMatrix, frameCtx); - - // gpuPickPickable - resetFrameCtx(1); - frameCtx.pickInvisible = !!params.pickInvisible; - - gl.viewport(0, 0, 1, 1); - gl.depthMask(true); - gl.enable(gl.DEPTH_TEST); - gl.disable(gl.CULL_FACE); - gl.disable(gl.BLEND); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - - const includeEntityIds = params.includeEntityIds; - const excludeEntityIds = params.excludeEntityIds; - - const renderDrawables = function(drawables) { - drawables.forEach(drawable => { - if (!drawable.culled && drawable.visible && drawable.pickable && drawable.drawPickMesh // TODO: push this logic into drawable - && ((! includeEntityIds) || includeEntityIds[drawable.id]) - && ((! excludeEntityIds) || (! excludeEntityIds[drawable.id]))) { - drawable.drawPickMesh(frameCtx); - } - }); - }; - - renderDrawables(postCullDrawableList); - if (uiDrawableList.length > 0) { - gl.clear(gl.DEPTH_BUFFER_BIT); - renderDrawables(uiDrawableList); - } - - frameCtx.testAABB = null; - - const pickID = pixelToInt(pickBuffer.read(0, 0)); - const pickable = (pickID >= 0) && pickIDs.items[pickID]; - - if (!pickable) { - pickBuffer.unbind(); - return null; - } - - const pickedEntity = (pickable.delegatePickedEntity) ? pickable.delegatePickedEntity() : pickable; - - if (!pickedEntity) { - pickBuffer.unbind(); - return null; - } - - if (params.pickSurface) { - - // GPU-based ray-picking - - if (pickable.canPickTriangle && pickable.canPickTriangle()) { - - if (pickable.drawPickTriangles) { - resetFrameCtx(1); - // frameCtx.pickInvisible = !!params.pickInvisible; - - gl.viewport(0, 0, 1, 1); - gl.clearColor(0, 0, 0, 0); - gl.enable(gl.DEPTH_TEST); - gl.disable(gl.CULL_FACE); - gl.disable(gl.BLEND); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - - pickable.drawPickTriangles(frameCtx); - - pickResult.primIndex = 3 * pixelToInt(pickBuffer.read(0, 0)); // Convert from triangle number to first vertex in indices - } - - pickable.pickTriangleSurface(pickViewMatrix, pickProjMatrix, projection, pickResult); - - pickResult.pickSurfacePrecision = false; - - } else { - - if (pickable.canPickWorldPos && pickable.canPickWorldPos()) { - - // pickWorldPos - resetFrameCtx(1); - frameCtx.viewParams.near = nearAndFar[0]; - frameCtx.viewParams.far = nearAndFar[1]; - - gl.viewport(0, 0, 1, 1); - - gl.clearColor(0, 0, 0, 0); - gl.depthMask(true); - gl.enable(gl.DEPTH_TEST); - gl.disable(gl.CULL_FACE); - gl.disable(gl.BLEND); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - - pickable.drawPickDepths(frameCtx); // Draw color-encoded fragment screen-space depths - - const screenZ = math.dotVec4(pickBuffer.read(0, 0), bitShiftScreenZ); - - // Calculate clip space coordinates, which will be in range of x=[-1..1] and y=[-1..1], with y=(+1) at top - const x = (canvasPos[0] - canvas.clientWidth / 2) / (canvas.clientWidth / 2); - const y = -(canvasPos[1] - canvas.clientHeight / 2) / (canvas.clientHeight / 2); - - const origin = pickable.origin; - - const pvMatInverse = math.inverseMat4(math.mulMat4(pickProjMatrix, (origin ? createRTCViewMat(pickViewMatrix, origin, tempMat4a) : pickViewMatrix), tempMat4c), tempMat4d); - - const toWorld = (z, dst) => { - dst[0] = x; - dst[1] = y; - dst[2] = z; - dst[3] = 1; - math.transformVec4(pvMatInverse, dst, dst); - return math.mulVec4Scalar(dst, 1 / dst[3]); - }; - - const world1 = toWorld(-1, tempVec4a); - const world2 = toWorld( 1, tempVec4b); - - const dir = math.subVec3(world2, world1, tempVec4c); - const worldPos = math.addVec3(world1, math.mulVec4Scalar(dir, screenZ, tempVec4d), tempVec4e); - - if (origin) { - math.addVec3(worldPos, origin); - } - - pickResult.worldPos = worldPos; - - if (params.pickSurfaceNormal !== false) { - // gpuPickWorldNormal - resetFrameCtx(3); - - pickNormalBuffer.bind(); - - gl.viewport(0, 0, pickNormalBuffer.size[0], pickNormalBuffer.size[1]); - gl.enable(gl.DEPTH_TEST); - gl.disable(gl.CULL_FACE); - gl.disable(gl.BLEND); - gl.clear(gl.DEPTH_BUFFER_BIT); - gl.clearBufferiv(gl.COLOR, 0, new Int32Array([0, 0, 0, 0])); - - pickable.drawPickNormals(frameCtx); // Draw color-encoded fragment World-space normals - - const pix = pickNormalBuffer.read(1, 1, gl.RGBA_INTEGER, gl.INT, Int32Array, 4); - - pickNormalBuffer.unbind(); - - pickResult.worldNormal = toWorldNormal(pix); - } - - pickResult.pickSurfacePrecision = false; - } - } - } - pickBuffer.unbind(); - pickResult.entity = pickedEntity; - return pickResult; - }; - })(); - - /** - * @param {[number, number]} canvasPos - * @param {number} [snapRadiusInPixels=30] - * @param {boolean} [snapToVertex=true] - * @param {boolean} [snapToEdge=true] - * @param pickResult - * @returns {PickResult} - */ - this.snapPick = (function () { - - const _pickResult = new PickResult(); - - const getVertexPickBuffer = (function() { - const cache = { }; - return (snapRadiusInPixels) => { - if (! (snapRadiusInPixels in cache)) { - const buf = new RenderBuffer(gl, [gl.RGBA32I, gl.RGBA32I, gl.RGBA8UI], true); - buf.setSize([2 * snapRadiusInPixels + 1, 2 * snapRadiusInPixels + 1]); - cache[snapRadiusInPixels] = buf; - } - return cache[snapRadiusInPixels]; - }; - })(); - - return function (params, pickResult = _pickResult) { - - const {canvasPos, origin, direction, snapRadius, snapToVertex, snapToEdge} = params; - - if (!snapToVertex && !snapToEdge) { - return this.pick({canvasPos, pickSurface: true}); - } - - const camera = scene.camera; - const snapRadiusInPixels = snapRadius || 30; - const viewMatrix = (canvasPos - ? camera.viewMatrix - : math.lookAtMat4v( - origin, - math.addVec3(origin, direction, math.vec3()), - math.vec3([0, 1, 0]), - math.mat4())); - resetPickFrameCtx(canvasPos, 2 * snapRadiusInPixels, camera, camera.eye, camera.projMatrix, viewMatrix, frameCtx); - - // Bind and clear the snap render target - - const vertexPickBuffer = getVertexPickBuffer(snapRadiusInPixels); - vertexPickBuffer.bind(); - gl.viewport(0, 0, vertexPickBuffer.size[0], vertexPickBuffer.size[1]); - gl.enable(gl.DEPTH_TEST); - gl.frontFace(gl.CCW); - gl.disable(gl.CULL_FACE); - gl.depthMask(true); - gl.disable(gl.BLEND); - gl.depthFunc(gl.LEQUAL); - gl.clear(gl.DEPTH_BUFFER_BIT); - gl.clearBufferiv(gl.COLOR, 0, new Int32Array([0, 0, 0, 0])); - gl.clearBufferiv(gl.COLOR, 1, new Int32Array([0, 0, 0, 0])); - gl.clearBufferuiv(gl.COLOR, 2, new Uint32Array([0, 0, 0, 0])); - - // a) init z-buffer - gl.drawBuffers([gl.COLOR_ATTACHMENT0, gl.COLOR_ATTACHMENT1, gl.COLOR_ATTACHMENT2]); - - frameCtx.snapPickLayerParams = []; - frameCtx.snapPickLayerParams.push(null); // This recreates previous situation, which relied on snapPickLayerNumber - postCullDrawableList.forEach(drawable => { - if (!drawable.culled && drawable.visible && drawable.pickable && drawable.drawSnapInit) { - drawable.drawSnapInit(frameCtx); - } - }); - - const layerParamsSurface = frameCtx.snapPickLayerParams; - - // b) snap-pick - frameCtx.snapPickLayerParams = []; - - gl.depthMask(false); - gl.drawBuffers([gl.COLOR_ATTACHMENT0]); - - const drawSnap = (snapMode) => { - frameCtx.snapMode = snapMode; - frameCtx.snapPickLayerParams.push(null); // This recreates previous situation, which relied on snapPickLayerNumber - postCullDrawableList.forEach(drawable => { - if (!drawable.culled && drawable.visible && drawable.pickable && drawable.drawSnap) { - drawable.drawSnap(frameCtx); - } - }); - }; - - if (snapToEdge) { - drawSnap("edge"); - } - if (snapToVertex) { - drawSnap("vertex"); - } - - gl.depthMask(true); - - const layerParamsSnap = frameCtx.snapPickLayerParams; - - // Read and decode the snapped coordinates - const readSnapPickBuffer = (source, arrayType, glType) => { - const w = vertexPickBuffer.buffer.width; - const h = vertexPickBuffer.buffer.height; - const pix = new arrayType(4 * w * h); - gl.readBuffer(source); - gl.readPixels(0, 0, w, h, gl.RGBA_INTEGER, glType, pix, 0); - return pix; - }; - - const snapPickResultArray = readSnapPickBuffer(gl.COLOR_ATTACHMENT0, Int32Array, gl.INT); - const snapPickNormalResultArray = readSnapPickBuffer(gl.COLOR_ATTACHMENT1, Int32Array, gl.INT); - const snapPickIdResultArray = readSnapPickBuffer(gl.COLOR_ATTACHMENT2, Uint32Array, gl.UNSIGNED_INT); - - vertexPickBuffer.unbind(); - - // result 1) regular hi-precision world position - - let worldPos = null; - let worldNormal = null; - let pickable = null; - - const middleX = snapRadiusInPixels; - const middleY = snapRadiusInPixels; - const middleIndex = (middleX * 4) + (middleY * vertexPickBuffer.size[0] * 4); - const pickResultMiddleXY = snapPickResultArray.slice(middleIndex, middleIndex + 4); - const pickNormalResultMiddleXY = snapPickNormalResultArray.slice(middleIndex, middleIndex + 4); - const pickPickableResultMiddleXY = snapPickIdResultArray.slice(middleIndex, middleIndex + 4); - - if (pickResultMiddleXY[3] !== 0) { - const pickedLayerParmasSurface = layerParamsSurface[Math.abs(pickResultMiddleXY[3]) % layerParamsSurface.length]; - worldPos = toWorldPos(pickResultMiddleXY, pickedLayerParmasSurface.origin, pickedLayerParmasSurface.coordinateScale); - worldNormal = toWorldNormal(pickNormalResultMiddleXY); - - pickable = pickIDs.items[pixelToInt(pickPickableResultMiddleXY)]; - } - - // result 2) hi-precision snapped (to vertex/edge) world position - - const snapPickResult = [ ]; - for (let i = 0; i < snapPickResultArray.length; i += 4) { - const layerNumber = snapPickResultArray[i + 3]; - if (layerNumber > 0) { - const pixelNumber = Math.floor(i / 4); - const w = vertexPickBuffer.size[0]; - const x = pixelNumber % w - Math.floor(w / 2); - const y = Math.floor(pixelNumber / w) - Math.floor(w / 2); - snapPickResult.push({ - dist: math.lenVec2([ x, y ]), - isVertex: (snapToVertex && snapToEdge) ? (layerNumber > layerParamsSnap.length / 2) : snapToVertex, - result: snapPickResultArray.subarray(i, i+4), - normal: snapPickNormalResultArray.subarray(i, i+4), - id: snapPickIdResultArray.subarray(i, i+4) - }); - } - } - - const getPickedEntity = pickable => (pickable && pickable.delegatePickedEntity) ? pickable.delegatePickedEntity() : pickable; - - if (snapPickResult.length > 0) { - // closest vertex snap first, then closest edge snap - const res = snapPickResult.reduce((a,b) => ((((a.isVertex-b.isVertex) || (b.dist-a.dist)) > 0) ? a : b)); - const snapPick = res.result; - const pickedLayerParmas = layerParamsSnap[snapPick[3]]; - const snappedWorldPos = toWorldPos(snapPick, pickedLayerParmas.origin, pickedLayerParmas.coordinateScale); - const snappedCanvasPos = camera.projectWorldPos(snappedWorldPos); - - pickResult.reset(); - pickResult.snappedToEdge = !res.isVertex; - pickResult.snappedToVertex = res.isVertex; - pickResult.worldPos = snappedWorldPos; - pickResult.worldNormal = toWorldNormal(res.normal); - pickResult.entity = getPickedEntity(pickIDs.items[pixelToInt(res.id)]); - pickResult.canvasPos = canvasPos || (worldPos && camera.projectWorldPos(worldPos)) || snappedCanvasPos; - pickResult.snappedCanvasPos = snappedCanvasPos; - return pickResult; - - } else if (worldPos) { - - pickResult.reset(); - pickResult.snappedToEdge = false; - pickResult.snappedToVertex = false; - pickResult.worldPos = worldPos; - pickResult.worldNormal = worldNormal; - pickResult.entity = getPickedEntity(pickable); - pickResult.canvasPos = canvasPos || camera.projectWorldPos(worldPos); - pickResult.snappedCanvasPos = canvasPos; - return pickResult; - - } else { - return null; - } - }; - })(); - - /** - * Adds a {@link Marker} for occlusion testing. - * @param marker - */ - this.addMarker = function (marker) { - this._occlusionTester = this._occlusionTester || new OcclusionTester(scene); - this._occlusionTester.addMarker(marker); - scene.occlusionTestCountdown = 0; - }; - - /** - * Notifies that a {@link Marker#worldPos} has updated. - * @param marker - */ - this.markerWorldPosUpdated = function (marker) { - this._occlusionTester.markerWorldPosUpdated(marker); - }; - - /** - * Removes a {@link Marker} from occlusion testing. - * @param marker - */ - this.removeMarker = function (marker) { - this._occlusionTester.removeMarker(marker); - }; - - /** - * Performs an occlusion test for all added {@link Marker}s, updating - * their {@link Marker#visible} properties accordingly. - */ - this.doOcclusionTest = function () { - - if (this._occlusionTester && this._occlusionTester.needOcclusionTest) { - - updateDrawlist(); - - const readPixelBuf = renderBufferManager.getRenderBuffer("occlusionReadPix"); - if (readPixelBuf) { - readPixelBuf.setSize([gl.drawingBufferWidth, gl.drawingBufferHeight]); - readPixelBuf.bind(); - } - - frameCtx.reset(); - frameCtx.backfaces = true; - frameCtx.frontface = true; // "ccw" - frameCtx.viewParams = getSceneCameraViewParams(); - frameCtx.nearPlaneHeight = getNearPlaneHeight(scene.camera, gl.drawingBufferHeight); - - gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); - gl.clearColor(0, 0, 0, 0); - gl.enable(gl.DEPTH_TEST); - gl.disable(gl.CULL_FACE); - gl.disable(gl.BLEND); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - - postCullDrawableList.forEach(drawable => { - if (!drawable.culled && drawable.visible && drawable.pickable && drawable.drawOcclusion) { // TODO: Option to exclude transparent? - drawable.drawOcclusion(frameCtx); - } - }); - - this._occlusionTester.drawMarkers(); - - if (readPixelBuf) { - const resolutionScale = scene.canvas.resolutionScale; - this._occlusionTester.doOcclusionTest( // Updates Marker "visible" properties - (x, y) => readPixelBuf.read(Math.round(resolutionScale * x), Math.round(resolutionScale * y))); - readPixelBuf.unbind(); - } - } - }; - - this.snapshot = (() => { - let snapshotBound = false; - const snapshotBuffer = new RenderBuffer(gl); - let snapshotCanvas = null; - - return { - /** - * Read pixels from the renderer's current output. Performs a force-render first. - * @param pixels - * @param colors - * @param len - * @private - */ - readPixels: (pixels, colors, len) => { - snapshotBuffer.bind(); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - imageDirty = true; - this.render(); - for (let i = 0; i < len; i++) { - const j = i * 2; - const k = i * 4; - const color = snapshotBuffer.read(pixels[j], pixels[j + 1]); - colors[k] = color[0]; - colors[k + 1] = color[1]; - colors[k + 2] = color[2]; - colors[k + 3] = color[3]; - } - snapshotBuffer.unbind(); - imageDirty = true; - }, - - /** - * Enter snapshot mode. - * - * Switches rendering to a hidden snapshot canvas. - * - * Exit snapshot mode using endSnapshot(). - */ - beginSnapshot: () => { - snapshotBuffer.setSize([gl.drawingBufferWidth, gl.drawingBufferHeight]); - snapshotBuffer.bind(); - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - snapshotBound = true; - }, - - /** - * Returns an HTMLCanvas containing an image of the snapshot canvas. - * - * - The HTMLCanvas has a CanvasRenderingContext2D. - * - Expects the caller to draw more things on the HTMLCanvas (annotations etc). - * - * @returns {HTMLCanvasElement} - */ - renderSnapshotToCanvas: () => { - const width = snapshotBuffer.buffer.width; - const height = snapshotBuffer.buffer.height; - - if ((! snapshotCanvas) || (snapshotCanvas.width !== width) || (snapshotCanvas.height !== height)) { - snapshotCanvas = (function() { - const canvas = document.createElement('canvas'); - const context = canvas.getContext('2d'); - canvas.width = width; - canvas.height = height; - const pixelData = new Uint8Array(width * height * 4); - const imageData = context.createImageData(width, height); - - return { - width: width, - height: height, - getUpdatedCanvas: () => { - gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixelData); - - // flip verically - const halfHeight = Math.floor(height / 2); - const bytesPerRow = width * 4; - const temp = new Uint8Array(bytesPerRow); - for (let y = 0; y < halfHeight; ++y) { - const topOffset = y * bytesPerRow; - const bottomOffset = (height - y - 1) * bytesPerRow; - temp.set(pixelData.subarray(topOffset, topOffset + bytesPerRow)); - pixelData.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow); - pixelData.set(temp, bottomOffset); - } - - imageData.data.set(pixelData); - - context.resetTransform(); // Prevents strange scale-accumulation effect with html2canvas - context.putImageData(imageData, 0, 0); - - return canvas; - } - }; - })(); - } - - if (snapshotBound) { - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - imageDirty = true; - this.render(); - imageDirty = true; - } - - return snapshotCanvas.getUpdatedCanvas(); - }, - - /** - * Exists snapshot mode. - * - * Switches rendering back to the main canvas. - */ - endSnapshot: () => { - if (snapshotBound) { - snapshotBuffer.unbind(); - snapshotBound = false; - } - imageDirty = true; - this.render(); - } - }; - })(); - - /** - * Destroys this renderer. - * @private - */ - this.destroy = function () { - - drawableTypeInfo = {}; - drawables = {}; - - renderBufferManager.destroy(); - - saoOcclusionRenderer.destroy(); - saoDepthLimitedBlurRenderer.destroy(); - - if (this._occlusionTester) { - this._occlusionTester.destroy(); - } - }; -}; - -/** - * @desc Meditates mouse, touch and keyboard events for various interaction controls. - * - * Ordinarily, you would only use this component as a utility to help manage input events and state for your - * own custom input handlers. - * - * * Located at {@link Scene#input} - * * Used by (at least) {@link CameraControl} - * - * ## Usage - * - * Subscribing to mouse events on the canvas: - * - * ````javascript - * import {Viewer} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * const input = viewer.scene.input; - * - * const onMouseDown = input.on("mousedown", (canvasCoords) => { - * console.log("Mouse down at: x=" + canvasCoords[0] + ", y=" + coords[1]); - * }); - * - * const onMouseUp = input.on("mouseup", (canvasCoords) => { - * console.log("Mouse up at: x=" + canvasCoords[0] + ", y=" + canvasCoords[1]); - * }); - * - * const onMouseClicked = input.on("mouseclicked", (canvasCoords) => { - * console.log("Mouse clicked at: x=" + canvasCoords[0] + ", y=" + canvasCoords[1]); - * }); - * - * const onDblClick = input.on("dblclick", (canvasCoords) => { - * console.log("Double-click at: x=" + canvasCoords[0] + ", y=" + canvasCoords[1]); - * }); - * ```` - * - * Subscribing to keyboard events on the canvas: - * - * ````javascript - * const onKeyDown = input.on("keydown", (keyCode) => { - * switch (keyCode) { - * case this.KEY_A: - * console.log("The 'A' key is down"); - * break; - * - * case this.KEY_B: - * console.log("The 'B' key is down"); - * break; - * - * case this.KEY_C: - * console.log("The 'C' key is down"); - * break; - * - * default: - * console.log("Some other key is down"); - * } - * }); - * - * const onKeyUp = input.on("keyup", (keyCode) => { - * switch (keyCode) { - * case this.KEY_A: - * console.log("The 'A' key is up"); - * break; - * - * case this.KEY_B: - * console.log("The 'B' key is up"); - * break; - * - * case this.KEY_C: - * console.log("The 'C' key is up"); - * break; - * - * default: - * console.log("Some other key is up"); - * } - * }); - * ```` - * - * Checking if keys are down: - * - * ````javascript - * const isCtrlDown = input.ctrlDown; - * const isAltDown = input.altDown; - * const shiftDown = input.shiftDown; - * //... - * - * const isAKeyDown = input.keyDown[input.KEY_A]; - * const isBKeyDown = input.keyDown[input.KEY_B]; - * const isShiftKeyDown = input.keyDown[input.KEY_SHIFT]; - * //... - * - * ```` - * Unsubscribing from events: - * - * ````javascript - * input.off(onMouseDown); - * input.off(onMouseUp); - * //... - * ```` - * - * ## Disabling all events - * - * Event handling is enabled by default. - * - * To disable all events: - * - * ````javascript - * myViewer.scene.input.setEnabled(false); - * ```` - * To enable all events again: - * - * ````javascript - * myViewer.scene.input.setEnabled(true); - * ```` - * - * ## Disabling keyboard input - * - * When the mouse is over the canvas, the canvas will consume keyboard events. Therefore, sometimes we need - * to disable keyboard control, so that other UI elements can get those events. - * - * To disable keyboard events: - * - * ````javascript - * myViewer.scene.input.setKeyboardEnabled(false); - * ```` - * - * To enable keyboard events again: - * - * ````javascript - * myViewer.scene.input.setKeyboardEnabled(true) - * ```` - */ -class Input extends Component { - - /** - * @private - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - /** - * Code for the BACKSPACE key. - * @property KEY_BACKSPACE - * @final - * @type {Number} - */ - this.KEY_BACKSPACE = 8; - - /** - * Code for the TAB key. - * @property KEY_TAB - * @final - * @type {Number} - */ - this.KEY_TAB = 9; - - /** - * Code for the ENTER key. - * @property KEY_ENTER - * @final - * @type {Number} - */ - this.KEY_ENTER = 13; - - /** - * Code for the SHIFT key. - * @property KEY_SHIFT - * @final - * @type {Number} - */ - this.KEY_SHIFT = 16; - - /** - * Code for the CTRL key. - * @property KEY_CTRL - * @final - * @type {Number} - */ - this.KEY_CTRL = 17; - - /** - * Code for the ALT key. - * @property KEY_ALT - * @final - * @type {Number} - */ - this.KEY_ALT = 18; - - /** - * Code for the PAUSE_BREAK key. - * @property KEY_PAUSE_BREAK - * @final - * @type {Number} - */ - this.KEY_PAUSE_BREAK = 19; - - /** - * Code for the CAPS_LOCK key. - * @property KEY_CAPS_LOCK - * @final - * @type {Number} - */ - this.KEY_CAPS_LOCK = 20; - - /** - * Code for the ESCAPE key. - * @property KEY_ESCAPE - * @final - * @type {Number} - */ - this.KEY_ESCAPE = 27; - - /** - * Code for the PAGE_UP key. - * @property KEY_PAGE_UP - * @final - * @type {Number} - */ - this.KEY_PAGE_UP = 33; - - /** - * Code for the PAGE_DOWN key. - * @property KEY_PAGE_DOWN - * @final - * @type {Number} - */ - this.KEY_PAGE_DOWN = 34; - - /** - * Code for the END key. - * @property KEY_END - * @final - * @type {Number} - */ - this.KEY_END = 35; - - /** - * Code for the HOME key. - * @property KEY_HOME - * @final - * @type {Number} - */ - this.KEY_HOME = 36; - - /** - * Code for the LEFT_ARROW key. - * @property KEY_LEFT_ARROW - * @final - * @type {Number} - */ - this.KEY_LEFT_ARROW = 37; - - /** - * Code for the UP_ARROW key. - * @property KEY_UP_ARROW - * @final - * @type {Number} - */ - this.KEY_UP_ARROW = 38; - - /** - * Code for the RIGHT_ARROW key. - * @property KEY_RIGHT_ARROW - * @final - * @type {Number} - */ - this.KEY_RIGHT_ARROW = 39; - - /** - * Code for the DOWN_ARROW key. - * @property KEY_DOWN_ARROW - * @final - * @type {Number} - */ - this.KEY_DOWN_ARROW = 40; - - /** - * Code for the INSERT key. - * @property KEY_INSERT - * @final - * @type {Number} - */ - this.KEY_INSERT = 45; - - /** - * Code for the DELETE key. - * @property KEY_DELETE - * @final - * @type {Number} - */ - this.KEY_DELETE = 46; - - /** - * Code for the 0 key. - * @property KEY_NUM_0 - * @final - * @type {Number} - */ - this.KEY_NUM_0 = 48; - - /** - * Code for the 1 key. - * @property KEY_NUM_1 - * @final - * @type {Number} - */ - this.KEY_NUM_1 = 49; - - /** - * Code for the 2 key. - * @property KEY_NUM_2 - * @final - * @type {Number} - */ - this.KEY_NUM_2 = 50; - - /** - * Code for the 3 key. - * @property KEY_NUM_3 - * @final - * @type {Number} - */ - this.KEY_NUM_3 = 51; - - /** - * Code for the 4 key. - * @property KEY_NUM_4 - * @final - * @type {Number} - */ - this.KEY_NUM_4 = 52; - - /** - * Code for the 5 key. - * @property KEY_NUM_5 - * @final - * @type {Number} - */ - this.KEY_NUM_5 = 53; - - /** - * Code for the 6 key. - * @property KEY_NUM_6 - * @final - * @type {Number} - */ - this.KEY_NUM_6 = 54; - - /** - * Code for the 7 key. - * @property KEY_NUM_7 - * @final - * @type {Number} - */ - this.KEY_NUM_7 = 55; - - /** - * Code for the 8 key. - * @property KEY_NUM_8 - * @final - * @type {Number} - */ - this.KEY_NUM_8 = 56; - - /** - * Code for the 9 key. - * @property KEY_NUM_9 - * @final - * @type {Number} - */ - this.KEY_NUM_9 = 57; - - /** - * Code for the A key. - * @property KEY_A - * @final - * @type {Number} - */ - this.KEY_A = 65; - - /** - * Code for the B key. - * @property KEY_B - * @final - * @type {Number} - */ - this.KEY_B = 66; - - /** - * Code for the C key. - * @property KEY_C - * @final - * @type {Number} - */ - this.KEY_C = 67; - - /** - * Code for the D key. - * @property KEY_D - * @final - * @type {Number} - */ - this.KEY_D = 68; - - /** - * Code for the E key. - * @property KEY_E - * @final - * @type {Number} - */ - this.KEY_E = 69; - - /** - * Code for the F key. - * @property KEY_F - * @final - * @type {Number} - */ - this.KEY_F = 70; - - /** - * Code for the G key. - * @property KEY_G - * @final - * @type {Number} - */ - this.KEY_G = 71; - - /** - * Code for the H key. - * @property KEY_H - * @final - * @type {Number} - */ - this.KEY_H = 72; - - /** - * Code for the I key. - * @property KEY_I - * @final - * @type {Number} - */ - this.KEY_I = 73; - - /** - * Code for the J key. - * @property KEY_J - * @final - * @type {Number} - */ - this.KEY_J = 74; - - /** - * Code for the K key. - * @property KEY_K - * @final - * @type {Number} - */ - this.KEY_K = 75; - - /** - * Code for the L key. - * @property KEY_L - * @final - * @type {Number} - */ - this.KEY_L = 76; - - /** - * Code for the M key. - * @property KEY_M - * @final - * @type {Number} - */ - this.KEY_M = 77; - - /** - * Code for the N key. - * @property KEY_N - * @final - * @type {Number} - */ - this.KEY_N = 78; - - /** - * Code for the O key. - * @property KEY_O - * @final - * @type {Number} - */ - this.KEY_O = 79; - - /** - * Code for the P key. - * @property KEY_P - * @final - * @type {Number} - */ - this.KEY_P = 80; - - /** - * Code for the Q key. - * @property KEY_Q - * @final - * @type {Number} - */ - this.KEY_Q = 81; - - /** - * Code for the R key. - * @property KEY_R - * @final - * @type {Number} - */ - this.KEY_R = 82; - - /** - * Code for the S key. - * @property KEY_S - * @final - * @type {Number} - */ - this.KEY_S = 83; - - /** - * Code for the T key. - * @property KEY_T - * @final - * @type {Number} - */ - this.KEY_T = 84; - - /** - * Code for the U key. - * @property KEY_U - * @final - * @type {Number} - */ - this.KEY_U = 85; - - /** - * Code for the V key. - * @property KEY_V - * @final - * @type {Number} - */ - this.KEY_V = 86; - - /** - * Code for the W key. - * @property KEY_W - * @final - * @type {Number} - */ - this.KEY_W = 87; - - /** - * Code for the X key. - * @property KEY_X - * @final - * @type {Number} - */ - this.KEY_X = 88; - - /** - * Code for the Y key. - * @property KEY_Y - * @final - * @type {Number} - */ - this.KEY_Y = 89; - - /** - * Code for the Z key. - * @property KEY_Z - * @final - * @type {Number} - */ - this.KEY_Z = 90; - - /** - * Code for the LEFT_WINDOW key. - * @property KEY_LEFT_WINDOW - * @final - * @type {Number} - */ - this.KEY_LEFT_WINDOW = 91; - - /** - * Code for the RIGHT_WINDOW key. - * @property KEY_RIGHT_WINDOW - * @final - * @type {Number} - */ - this.KEY_RIGHT_WINDOW = 92; - - /** - * Code for the SELECT key. - * @property KEY_SELECT - * @final - * @type {Number} - */ - this.KEY_SELECT_KEY = 93; - - /** - * Code for the number pad 0 key. - * @property KEY_NUMPAD_0 - * @final - * @type {Number} - */ - this.KEY_NUMPAD_0 = 96; - - /** - * Code for the number pad 1 key. - * @property KEY_NUMPAD_1 - * @final - * @type {Number} - */ - this.KEY_NUMPAD_1 = 97; - - /** - * Code for the number pad 2 key. - * @property KEY_NUMPAD 2 - * @final - * @type {Number} - */ - this.KEY_NUMPAD_2 = 98; - - /** - * Code for the number pad 3 key. - * @property KEY_NUMPAD_3 - * @final - * @type {Number} - */ - this.KEY_NUMPAD_3 = 99; - - /** - * Code for the number pad 4 key. - * @property KEY_NUMPAD_4 - * @final - * @type {Number} - */ - this.KEY_NUMPAD_4 = 100; - - /** - * Code for the number pad 5 key. - * @property KEY_NUMPAD_5 - * @final - * @type {Number} - */ - this.KEY_NUMPAD_5 = 101; - - /** - * Code for the number pad 6 key. - * @property KEY_NUMPAD_6 - * @final - * @type {Number} - */ - this.KEY_NUMPAD_6 = 102; - - /** - * Code for the number pad 7 key. - * @property KEY_NUMPAD_7 - * @final - * @type {Number} - */ - this.KEY_NUMPAD_7 = 103; - - /** - * Code for the number pad 8 key. - * @property KEY_NUMPAD_8 - * @final - * @type {Number} - */ - this.KEY_NUMPAD_8 = 104; - - /** - * Code for the number pad 9 key. - * @property KEY_NUMPAD_9 - * @final - * @type {Number} - */ - this.KEY_NUMPAD_9 = 105; - - /** - * Code for the MULTIPLY key. - * @property KEY_MULTIPLY - * @final - * @type {Number} - */ - this.KEY_MULTIPLY = 106; - - /** - * Code for the ADD key. - * @property KEY_ADD - * @final - * @type {Number} - */ - this.KEY_ADD = 107; - - /** - * Code for the SUBTRACT key. - * @property KEY_SUBTRACT - * @final - * @type {Number} - */ - this.KEY_SUBTRACT = 109; - - /** - * Code for the DECIMAL POINT key. - * @property KEY_DECIMAL_POINT - * @final - * @type {Number} - */ - this.KEY_DECIMAL_POINT = 110; - - /** - * Code for the DIVIDE key. - * @property KEY_DIVIDE - * @final - * @type {Number} - */ - this.KEY_DIVIDE = 111; - - /** - * Code for the F1 key. - * @property KEY_F1 - * @final - * @type {Number} - */ - this.KEY_F1 = 112; - - /** - * Code for the F2 key. - * @property KEY_F2 - * @final - * @type {Number} - */ - this.KEY_F2 = 113; - - /** - * Code for the F3 key. - * @property KEY_F3 - * @final - * @type {Number} - */ - this.KEY_F3 = 114; - - /** - * Code for the F4 key. - * @property KEY_F4 - * @final - * @type {Number} - */ - this.KEY_F4 = 115; - - /** - * Code for the F5 key. - * @property KEY_F5 - * @final - * @type {Number} - */ - this.KEY_F5 = 116; - - /** - * Code for the F6 key. - * @property KEY_F6 - * @final - * @type {Number} - */ - this.KEY_F6 = 117; - - /** - * Code for the F7 key. - * @property KEY_F7 - * @final - * @type {Number} - */ - this.KEY_F7 = 118; - - /** - * Code for the F8 key. - * @property KEY_F8 - * @final - * @type {Number} - */ - this.KEY_F8 = 119; - - /** - * Code for the F9 key. - * @property KEY_F9 - * @final - * @type {Number} - */ - this.KEY_F9 = 120; - - /** - * Code for the F10 key. - * @property KEY_F10 - * @final - * @type {Number} - */ - this.KEY_F10 = 121; - - /** - * Code for the F11 key. - * @property KEY_F11 - * @final - * @type {Number} - */ - this.KEY_F11 = 122; - - /** - * Code for the F12 key. - * @property KEY_F12 - * @final - * @type {Number} - */ - this.KEY_F12 = 123; - - /** - * Code for the NUM_LOCK key. - * @property KEY_NUM_LOCK - * @final - * @type {Number} - */ - this.KEY_NUM_LOCK = 144; - - /** - * Code for the SCROLL_LOCK key. - * @property KEY_SCROLL_LOCK - * @final - * @type {Number} - */ - this.KEY_SCROLL_LOCK = 145; - - /** - * Code for the SEMI_COLON key. - * @property KEY_SEMI_COLON - * @final - * @type {Number} - */ - this.KEY_SEMI_COLON = 186; - - /** - * Code for the EQUAL_SIGN key. - * @property KEY_EQUAL_SIGN - * @final - * @type {Number} - */ - this.KEY_EQUAL_SIGN = 187; - - /** - * Code for the COMMA key. - * @property KEY_COMMA - * @final - * @type {Number} - */ - this.KEY_COMMA = 188; - - /** - * Code for the DASH key. - * @property KEY_DASH - * @final - * @type {Number} - */ - this.KEY_DASH = 189; - - /** - * Code for the PERIOD key. - * @property KEY_PERIOD - * @final - * @type {Number} - */ - this.KEY_PERIOD = 190; - - /** - * Code for the FORWARD_SLASH key. - * @property KEY_FORWARD_SLASH - * @final - * @type {Number} - */ - this.KEY_FORWARD_SLASH = 191; - - /** - * Code for the GRAVE_ACCENT key. - * @property KEY_GRAVE_ACCENT - * @final - * @type {Number} - */ - this.KEY_GRAVE_ACCENT = 192; - - /** - * Code for the OPEN_BRACKET key. - * @property KEY_OPEN_BRACKET - * @final - * @type {Number} - */ - this.KEY_OPEN_BRACKET = 219; - - /** - * Code for the BACK_SLASH key. - * @property KEY_BACK_SLASH - * @final - * @type {Number} - */ - this.KEY_BACK_SLASH = 220; - - /** - * Code for the CLOSE_BRACKET key. - * @property KEY_CLOSE_BRACKET - * @final - * @type {Number} - */ - this.KEY_CLOSE_BRACKET = 221; - - /** - * Code for the SINGLE_QUOTE key. - * @property KEY_SINGLE_QUOTE - * @final - * @type {Number} - */ - this.KEY_SINGLE_QUOTE = 222; - - /** - * Code for the SPACE key. - * @property KEY_SPACE - * @final - * @type {Number} - */ - this.KEY_SPACE = 32; - - /** - * Code for the left mouse button. - * @property MOUSE_LEFT_BUTTON - * @final - * @type {Number} - */ - this.MOUSE_LEFT_BUTTON = 260; - - /** - * Code for the middle mouse button. - * @property MOUSE_MIDDLE_BUTTON - * @final - * @type {Number} - */ - this.MOUSE_MIDDLE_BUTTON = 261; - - /** - * Code for the right mouse button. - * @property MOUSE_RIGHT_BUTTON - * @final - * @type {Number} - */ - this.MOUSE_RIGHT_BUTTON = 262; - - /** - * The canvas element that mouse and keyboards are bound to. - * - * @final - * @type {HTMLCanvasElement} - */ - this.element = cfg.element; - - /** True whenever ALT key is down. - * - * @type {boolean} - */ - this.altDown = false; - - /** True whenever CTRL key is down. - * - * @type {boolean} - */ - this.ctrlDown = false; - - /** True whenever left mouse button is down. - * - * @type {boolean} - */ - this.mouseDownLeft = false; - - /** - * True whenever middle mouse button is down. - * - * @type {boolean} - */ - this.mouseDownMiddle = false; - - /** - * True whenever the right mouse button is down. - * - * @type {boolean} - */ - this.mouseDownRight = false; - - /** - * Flag for each key that's down. - * - * @type {boolean[]} - */ - this.keyDown = []; - - /** True while input enabled - * - * @type {boolean} - */ - this.enabled = true; - - /** True while keyboard input is enabled. - * - * Default value is ````true````. - * - * {@link CameraControl} will not respond to keyboard events while this is ````false````. - * - * @type {boolean} - */ - this.keyboardEnabled = true; - - /** True while the mouse is over the canvas. - * - * @type {boolean} - */ - this.mouseover = false; - - /** - * Current mouse position within the canvas. - * @type {Number[]} - */ - this.mouseCanvasPos = math.vec2(); - - this._keyboardEventsElement = cfg.keyboardEventsElement || document; - - this._bindEvents(); - } - - _bindEvents() { - - if (this._eventsBound) { - return; - } - - this._keyboardEventsElement.addEventListener("keydown", this._keyDownListener = (e) => { - if (!this.enabled || (!this.keyboardEnabled)) { - return; - } - if (e.target.tagName !== "INPUT" && e.target.tagName !== "TEXTAREA") { - if (e.keyCode === this.KEY_CTRL) { - this.ctrlDown = true; - } else if (e.keyCode === this.KEY_ALT) { - this.altDown = true; - } else if (e.keyCode === this.KEY_SHIFT) { - this.shiftDown = true; - } - this.keyDown[e.keyCode] = true; - this.fire("keydown", e.keyCode, true); - } - }, false); - - this._keyboardEventsElement.addEventListener("keyup", this._keyUpListener = (e) => { - if (!this.enabled || (!this.keyboardEnabled)) { - return; - } - if (e.target.tagName !== "INPUT" && e.target.tagName !== "TEXTAREA") { - if (e.keyCode === this.KEY_CTRL) { - this.ctrlDown = false; - } else if (e.keyCode === this.KEY_ALT) { - this.altDown = false; - } else if (e.keyCode === this.KEY_SHIFT) { - this.shiftDown = false; - } - this.keyDown[e.keyCode] = false; - this.fire("keyup", e.keyCode, true); - } - }); - - this.element.addEventListener("mouseenter", this._mouseEnterListener = (e) => { - if (!this.enabled) { - return; - } - this.mouseover = true; - this._getMouseCanvasPos(e); - this.fire("mouseenter", this.mouseCanvasPos, true); - }); - - this.element.addEventListener("mouseleave", this._mouseLeaveListener = (e) => { - if (!this.enabled) { - return; - } - this.mouseover = false; - this._getMouseCanvasPos(e); - this.fire("mouseleave", this.mouseCanvasPos, true); - }); - - this.element.addEventListener("mousedown", this._mouseDownListener = (e) => { - if (!this.enabled) { - return; - } - switch (e.which) { - case 1:// Left button - this.mouseDownLeft = true; - break; - case 2:// Middle/both buttons - this.mouseDownMiddle = true; - break; - case 3:// Right button - this.mouseDownRight = true; - break; - } - this._getMouseCanvasPos(e); - this.element.focus(); - this.fire("mousedown", this.mouseCanvasPos, true); - if (this.mouseover) { - e.preventDefault(); - } - }); - - document.addEventListener("mouseup", this._mouseUpListener = (e) => { - if (!this.enabled) { - return; - } - switch (e.which) { - case 1:// Left button - this.mouseDownLeft = false; - break; - case 2:// Middle/both buttons - this.mouseDownMiddle = false; - break; - case 3:// Right button - this.mouseDownRight = false; - break; - } - this.fire("mouseup", this.mouseCanvasPos, true); - // if (this.mouseover) { - // e.preventDefault(); - // } - }, true); - - document.addEventListener("click", this._clickListener = (e) => { - if (!this.enabled) { - return; - } - switch (e.which) { - case 1:// Left button - this.mouseDownLeft = false; - this.mouseDownRight = false; - break; - case 2:// Middle/both buttons - this.mouseDownMiddle = false; - break; - case 3:// Right button - this.mouseDownLeft = false; - this.mouseDownRight = false; - break; - } - this._getMouseCanvasPos(e); - this.fire("click", this.mouseCanvasPos, true); - if (this.mouseover) { - e.preventDefault(); - } - }); - - document.addEventListener("dblclick", this._dblClickListener = (e) => { - if (!this.enabled) { - return; - } - switch (e.which) { - case 1:// Left button - this.mouseDownLeft = false; - this.mouseDownRight = false; - break; - case 2:// Middle/both buttons - this.mouseDownMiddle = false; - break; - case 3:// Right button - this.mouseDownLeft = false; - this.mouseDownRight = false; - break; - } - this._getMouseCanvasPos(e); - this.fire("dblclick", this.mouseCanvasPos, true); - if (this.mouseover) { - e.preventDefault(); - } - }); - - const tickifedMouseMoveFn = this.scene.tickify( - () => this.fire("mousemove", this.mouseCanvasPos, true) - ); - - this.element.addEventListener("mousemove", this._mouseMoveListener = (e) => { - if (!this.enabled) { - return; - } - this._getMouseCanvasPos(e); - tickifedMouseMoveFn(); - if (this.mouseover) { - e.preventDefault(); - } - }); - - this.element.addEventListener("contextmenu", this._contextmenuListener = (e) => { - if (!this.enabled) { - return; - } - this._getMouseCanvasPos(e); - this.fire("contextmenu", this.mouseCanvasPos, true); - }); - - const tickifiedMouseWheelFn = this.scene.tickify( - (delta) => { this.fire("mousewheel", delta, true); } - ); - - this.element.addEventListener("wheel", this._mouseWheelListener = (e, d) => { - if (!this.enabled) { - return; - } - const delta = Math.max(-1, Math.min(1, -e.deltaY * 40)); - tickifiedMouseWheelFn(delta); - }, {passive: true}); - - // mouseclicked - - { - let downX; - let downY; - // Tolerance between down and up positions for a mouse click - const tolerance = 2; - this.on("mousedown", (params) => { - downX = params[0]; - downY = params[1]; - }); - this.on("mouseup", (params) => { - if (downX >= (params[0] - tolerance) && - downX <= (params[0] + tolerance) && - downY >= (params[1] - tolerance) && - downY <= (params[1] + tolerance)) { - this.fire("mouseclicked", params, true); - } - }); - } - - this.element.addEventListener("touchstart", this._touchstartListener = (e) => { - if (!this.enabled) { - return; - } - [...e.changedTouches].forEach(e => { - this.fire("touchstart", [ e.identifier, this._getTouchCanvasPos(e) ], true); - }); - }); - - this.element.addEventListener("touchend", this._touchendListener = (e) => { - if (!this.enabled) { - return; - } - [...e.changedTouches].forEach(e => { - this.fire("touchend", [ e.identifier, this._getTouchCanvasPos(e) ], true); - }); - }); - - this._eventsBound = true; - } - - _unbindEvents() { - if (!this._eventsBound) { - return; - } - this._keyboardEventsElement.removeEventListener("keydown", this._keyDownListener); - this._keyboardEventsElement.removeEventListener("keyup", this._keyUpListener); - this.element.removeEventListener("mouseenter", this._mouseEnterListener); - this.element.removeEventListener("mouseleave", this._mouseLeaveListener); - this.element.removeEventListener("mousedown", this._mouseDownListener); - document.removeEventListener("mouseup", this._mouseDownListener); - document.removeEventListener("click", this._clickListener); - document.removeEventListener("dblclick", this._dblClickListener); - this.element.removeEventListener("mousemove", this._mouseMoveListener); - this.element.removeEventListener("contextmenu", this._contextmenuListener); - this.element.removeEventListener("wheel", this._mouseWheelListener); - this.element.removeEventListener("touchstart", this._touchstartListener); - this.element.removeEventListener("touchend", this._touchendListener); - if (window.OrientationChangeEvent) { - window.removeEventListener('orientationchange', this._orientationchangedListener); - } - if (window.DeviceMotionEvent) { - window.removeEventListener('devicemotion', this._deviceMotionListener); - } - if (window.DeviceOrientationEvent) { - window.removeEventListener("deviceorientation", this._deviceOrientListener); - } - this._eventsBound = false; - } - - _getTouchCanvasPos(event) { - let element = event.target; - let totalOffsetLeft = 0; - let totalOffsetTop = 0; - while (element.offsetParent) { - totalOffsetLeft += element.offsetLeft; - totalOffsetTop += element.offsetTop; - element = element.offsetParent; - } - return [ event.pageX - totalOffsetLeft, event.pageY - totalOffsetTop ]; - } - - _getMouseCanvasPos(event) { - if (!event) { - event = window.event; - this.mouseCanvasPos[0] = event.x; - this.mouseCanvasPos[1] = event.y; - } else { - let element = event.target; - - const rect = element.getBoundingClientRect(); - - this.mouseCanvasPos[0] = event.clientX - rect.left; - this.mouseCanvasPos[1] = event.clientY - rect.top; - } - } - - /** - * Sets whether input handlers are enabled. - * - * Default value is ````true````. - * - * @param {Boolean} enable Indicates if input handlers are enabled. - */ - setEnabled(enable) { - if (this.enabled !== enable) { - this.fire("enabled", this.enabled = enable); - } - } - - /** - * Gets whether input handlers are enabled. - * - * Default value is ````true````. - * - * @returns {Boolean} Indicates if input handlers are enabled. - */ - getEnabled() { - return this.enabled; - } - - /** - * Sets whether or not keyboard input is enabled. - * - * Default value is ````true````. - * - * {@link CameraControl} will not respond to keyboard events while this is set ````false````. - * - * @param {Boolean} value Indicates whether keyboard input is enabled. - */ - setKeyboardEnabled(value) { - this.keyboardEnabled = value; - } - - /** - * Gets whether keyboard input is enabled. - * - * Default value is ````true````. - * - * {@link CameraControl} will not respond to keyboard events while this is set ````false````. - * - * @returns {Boolean} Returns whether keyboard input is enabled. - */ - getKeyboardEnabled() { - return this.keyboardEnabled; - } - - /** - * @private - */ - destroy() { - super.destroy(); - this._unbindEvents(); - } -} - -/** - * @desc controls the canvas viewport for a {@link Scene}. - * - * * One Viewport per scene. - * * You can configure a Scene to render multiple times per frame, while setting the Viewport to different extents on each render. - * * Make a Viewport automatically size to its {@link Scene} {@link Canvas} by setting its {@link Viewport#autoBoundary} ````true````. - * - * - * Configuring the Scene to render twice on each frame, each time to a separate viewport: - * - * ````Javascript - * // Load glTF model - * var model = new xeokit.GLTFModel({ - src: "models/gltf/GearboxAssy/glTF-MaterialsCommon/GearboxAssy.gltf" - }); - - var scene = model.scene; - var viewport = scene.viewport; - - // Configure Scene to render twice for each frame - scene.passes = 2; // Default is 1 - scene.clearEachPass = false; // Default is false - - // Render to a separate viewport on each render - - var viewport = scene.viewport; - viewport.autoBoundary = false; - - scene.on("rendering", function (e) { - switch (e.pass) { - case 0: - viewport.boundary = [0, 0, 200, 200]; // xmin, ymin, width, height - break; - - case 1: - viewport.boundary = [200, 0, 200, 200]; - break; - } - }); - ```` - - @class Viewport - @module xeokit - @submodule rendering - @constructor - @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - @param {*} [cfg] Viewport configuration - @param {String} [cfg.id] Optional ID, unique among all components in the parent - {@link Scene}, generated automatically when omitted. - @param {String:Object} [cfg.meta] Optional map of user-defined metadata to attach to this Viewport. - @param [cfg.boundary] {Number[]} Canvas-space Viewport boundary, given as - (min, max, width, height). Defaults to the size of the parent - {@link Scene} {@link Canvas}. - @param [cfg.autoBoundary=false] {Boolean} Indicates if this Viewport's {@link Viewport#boundary} - automatically synchronizes with the size of the parent {@link Scene} {@link Canvas}. - - @extends Component - */ - -class Viewport extends Component { - - /** - @private - */ - get type() { - return "Viewport"; - } - - /** - @private - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._state = new RenderState({ - boundary: [0, 0, 100, 100] - }); - - this.boundary = cfg.boundary; - this.autoBoundary = cfg.autoBoundary; - } - - - /** - * Sets the canvas-space boundary of this Viewport, indicated as ````[min, max, width, height]````. - * - * When {@link Viewport#autoBoundary} is ````true````, ignores calls to this method and automatically synchronizes with {@link Canvas#boundary}. - * - * Fires a "boundary"" event on change. - * - * Defaults to the {@link Canvas} extents. - * - * @param {Number[]} value New Viewport extents. - */ - set boundary(value) { - - if (this._autoBoundary) { - return; - } - - if (!value) { - - const canvasBoundary = this.scene.canvas.boundary; - - const width = canvasBoundary[2]; - const height = canvasBoundary[3]; - - value = [0, 0, width, height]; - } - - this._state.boundary = value; - - this.glRedraw(); - - /** - Fired whenever this Viewport's {@link Viewport#boundary} property changes. - - @event boundary - @param value {Boolean} The property's new value - */ - this.fire("boundary", this._state.boundary); - } - - /** - * Gets the canvas-space boundary of this Viewport, indicated as ````[min, max, width, height]````. - * - * @returns {Number[]} The Viewport extents. - */ - get boundary() { - return this._state.boundary; - } - - /** - * Sets if {@link Viewport#boundary} automatically synchronizes with {@link Canvas#boundary}. - * - * Default is ````false````. - * - * @param {Boolean} value Set true to automatically sycnhronize. - */ - set autoBoundary(value) { - - value = !!value; - - if (value === this._autoBoundary) { - return; - } - - this._autoBoundary = value; - - if (this._autoBoundary) { - this._onCanvasSize = this.scene.canvas.on("boundary", - function (boundary) { - - const width = boundary[2]; - const height = boundary[3]; - - this._state.boundary = [0, 0, width, height]; - - this.glRedraw(); - - /** - Fired whenever this Viewport's {@link Viewport#boundary} property changes. - - @event boundary - @param value {Boolean} The property's new value - */ - this.fire("boundary", this._state.boundary); - - }, this); - - } else if (this._onCanvasSize) { - this.scene.canvas.off(this._onCanvasSize); - this._onCanvasSize = null; - } - - /** - Fired whenever this Viewport's {@link autoBoundary/autoBoundary} property changes. - - @event autoBoundary - @param value The property's new value - */ - this.fire("autoBoundary", this._autoBoundary); - } - - /** - * Gets if {@link Viewport#boundary} automatically synchronizes with {@link Canvas#boundary}. - * - * Default is ````false````. - * - * @returns {Boolean} Returns ````true```` when automatically sycnhronizing. - */ - get autoBoundary() { - return this._autoBoundary; - } - - _getState() { - return this._state; - } - - /** - * @private - */ - destroy() { - super.destroy(); - this._state.destroy(); - } -} - -/** - * @desc Defines its {@link Camera}'s perspective projection using a field-of-view angle. - * - * * Located at {@link Camera#perspective}. - * * Implicitly sets the left, right, top, bottom frustum planes using {@link Perspective#fov}. - * * {@link Perspective#near} and {@link Perspective#far} specify the distances to the WebGL clipping planes. - */ -class Perspective extends Component { - - /** - @private - */ - get type() { - return "Perspective"; - } - - /** - * @constructor - * @private - */ - constructor(camera, cfg = {}) { - - super(camera, cfg); - - /** - * The Camera this Perspective belongs to. - * - * @property camera - * @type {Camera} - * @final - */ - this.camera = camera; - - this._state = new RenderState({ - matrix: math.mat4(), - inverseMatrix: math.mat4(), - transposedMatrix: math.mat4(), - near: 0.1, - far: 10000.0 - }); - - this._inverseMatrixDirty = true; - this._transposedMatrixDirty = true; - - this._fov = 60.0; - - // Recompute aspect from change in canvas size - this._canvasResized = this.scene.canvas.on("boundary", this._needUpdate, this); - - this.fov = cfg.fov; - this.fovAxis = cfg.fovAxis; - this.near = cfg.near; - this.far = cfg.far; - } - - _update() { - - const WIDTH_INDEX = 2; - const HEIGHT_INDEX = 3; - const boundary = this.scene.canvas.boundary; - const aspect = boundary[WIDTH_INDEX] / boundary[HEIGHT_INDEX]; - const fovAxis = this._fovAxis; - - let fov = this._fov; - if (fovAxis === "x" || (fovAxis === "min" && aspect < 1) || (fovAxis === "max" && aspect > 1)) { - fov = fov / aspect; - } - fov = Math.min(fov, 120); - - math.perspectiveMat4(fov * (Math.PI / 180.0), aspect, this._state.near, this._state.far, this._state.matrix); - - this._inverseMatrixDirty = true; - this._transposedMatrixDirty = true; - - this.glRedraw(); - - this.camera._updateScheduled = true; - - this.fire("matrix", this._state.matrix); - } - - /** - * Sets the Perspective's field-of-view angle (FOV). - * - * Fires an "fov" event on change. - - * Default value is ````60.0````. - * - * @param {Number} value New field-of-view. - */ - set fov(value) { - value = (value !== undefined && value !== null) ? value : 60.0; - if (value === this._fov) { - return; - } - this._fov = value; - this._needUpdate(0); // Ensure matrix built on next "tick" - this.fire("fov", this._fov); - } - - /** - * Gets the Perspective's field-of-view angle (FOV). - * - * Default value is ````60.0````. - * - * @returns {Number} Current field-of-view. - */ - get fov() { - return this._fov; - } - - /** - * Sets the Perspective's FOV axis. - * - * Options are ````"x"````, ````"y"```` or ````"min"````, to use the minimum axis. - * - * Fires an "fovAxis" event on change. - - * Default value ````"min"````. - * - * @param {String} value New FOV axis value. - */ - set fovAxis(value) { - value = value || "min"; - if (this._fovAxis === value) { - return; - } - if (value !== "x" && value !== "y" && value !== "min") { - this.error("Unsupported value for 'fovAxis': " + value + " - defaulting to 'min'"); - value = "min"; - } - this._fovAxis = value; - this._needUpdate(0); // Ensure matrix built on next "tick" - this.fire("fovAxis", this._fovAxis); - } - - /** - * Gets the Perspective's FOV axis. - * - * Options are ````"x"````, ````"y"```` or ````"min"````, to use the minimum axis. - * - * Fires an "fovAxis" event on change. - - * Default value is ````"min"````. - * - * @returns {String} The current FOV axis value. - */ - get fovAxis() { - return this._fovAxis; - } - - /** - * Sets the position of the Perspective's near plane on the positive View-space Z-axis. - * - * Fires a "near" event on change. - * - * Default value is ````0.1````. - * - * @param {Number} value New Perspective near plane position. - */ - set near(value) { - const near = (value !== undefined && value !== null) ? value : 0.1; - if (this._state.near === near) { - return; - } - this._state.near = near; - this._needUpdate(0); // Ensure matrix built on next "tick" - this.fire("near", this._state.near); - } - - /** - * Gets the position of the Perspective's near plane on the positive View-space Z-axis. - * - * Fires an "emits" emits on change. - * - * Default value is ````0.1````. - * - * @returns The Perspective's near plane position. - */ - get near() { - return this._state.near; - } - - /** - * Sets the position of this Perspective's far plane on the positive View-space Z-axis. - * - * Fires a "far" event on change. - * - * Default value is ````10000.0````. - * - * @param {Number} value New Perspective far plane position. - */ - set far(value) { - const far = (value !== undefined && value !== null) ? value : 10000.0; - if (this._state.far === far) { - return; - } - this._state.far = far; - this._needUpdate(0); // Ensure matrix built on next "tick" - this.fire("far", this._state.far); - } - - /** - * Gets the position of this Perspective's far plane on the positive View-space Z-axis. - * - * Default value is ````10000.0````. - * - * @return {Number} The Perspective's far plane position. - */ - get far() { - return this._state.far; - } - - /** - * Gets the Perspective's projection transform matrix. - * - * Fires a "matrix" event on change. - * - * Default value is ````[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]````. - * - * @returns {Number[]} The Perspective's projection matrix. - */ - get matrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - return this._state.matrix; - } - - /** - * Gets the inverse of {@link Perspective#matrix}. - * - * @returns {Number[]} The inverse of {@link Perspective#matrix}. - */ - get inverseMatrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - if (this._inverseMatrixDirty) { - math.inverseMat4(this._state.matrix, this._state.inverseMatrix); - this._inverseMatrixDirty = false; - } - return this._state.inverseMatrix; - } - - /** - * Gets the transpose of {@link Perspective#matrix}. - * - * @returns {Number[]} The transpose of {@link Perspective#matrix}. - */ - get transposedMatrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - if (this._transposedMatrixDirty) { - math.transposeMat4(this._state.matrix, this._state.transposedMatrix); - this._transposedMatrixDirty = false; - } - return this._state.transposedMatrix; - } - - /** - * Un-projects the given Canvas-space coordinates and Screen-space depth, using this Perspective projection. - * - * @param {Number[]} canvasPos Inputs 2D Canvas-space coordinates. - * @param {Number} screenZ Inputs Screen-space Z coordinate. - * @param {Number[]} screenPos Outputs 3D Screen/Clip-space coordinates. - * @param {Number[]} viewPos Outputs un-projected 3D View-space coordinates. - * @param {Number[]} worldPos Outputs un-projected 3D World-space coordinates. - */ - unproject(canvasPos, screenZ, screenPos, viewPos, worldPos) { - - const canvas = this.scene.canvas.canvas; - - const halfCanvasWidth = canvas.offsetWidth / 2.0; - const halfCanvasHeight = canvas.offsetHeight / 2.0; - - screenPos[0] = (canvasPos[0] - halfCanvasWidth) / halfCanvasWidth; - screenPos[1] = (canvasPos[1] - halfCanvasHeight) / halfCanvasHeight; - screenPos[2] = screenZ; - screenPos[3] = 1.0; - - math.mulMat4v4(this.inverseMatrix, screenPos, viewPos); - math.mulVec3Scalar(viewPos, 1.0 / viewPos[3]); - - viewPos[3] = 1.0; - viewPos[1] *= -1; - - math.mulMat4v4(this.camera.inverseViewMatrix, viewPos, worldPos); - - return worldPos; - } - - /** @private - * - */ - destroy() { - super.destroy(); - this._state.destroy(); - this.scene.canvas.off(this._canvasResized); - } -} - -/** - * @desc Defines its {@link Camera}'s orthographic projection as a box-shaped view volume. - * - * * Located at {@link Camera#ortho}. - * * Works like Blender's orthographic projection, where the positions of the left, right, top and bottom planes are implicitly - * indicated with a single {@link Ortho#scale} property, which causes the frustum to be symmetrical on X and Y axis, large enough to - * contain the number of units given by {@link Ortho#scale}. - * * {@link Ortho#near} and {@link Ortho#far} indicated the distances to the WebGL clipping planes. - */ -class Ortho extends Component { - - /** - @private - */ - get type() { - return "Ortho"; - } - - /** - * @constructor - * @private - */ - constructor(camera, cfg = {}) { - - super(camera, cfg); - - /** - * The Camera this Ortho belongs to. - * - * @property camera - * @type {Camera} - * @final - */ - this.camera = camera; - - this._state = new RenderState({ - matrix: math.mat4(), - inverseMatrix: math.mat4(), - transposedMatrix: math.mat4(), - near: 0.1, - far: 10000.0 - }); - - this._inverseMatrixDirty = true; - this._transposedMatrixDirty = true; - - this.scale = cfg.scale; - this.near = cfg.near; - this.far = cfg.far; - - this._onCanvasBoundary = this.scene.canvas.on("boundary", this._needUpdate, this); - } - - _update() { - - const WIDTH_INDEX = 2; - const HEIGHT_INDEX = 3; - - const scene = this.scene; - const scale = this._scale; - const halfSize = 0.5 * scale; - - const boundary = scene.canvas.boundary; - const boundaryWidth = boundary[WIDTH_INDEX]; - const boundaryHeight = boundary[HEIGHT_INDEX]; - const aspect = boundaryWidth / boundaryHeight; - - let left; - let right; - let top; - let bottom; - - if (boundaryWidth > boundaryHeight) { - left = -halfSize; - right = halfSize; - top = halfSize / aspect; - bottom = -halfSize / aspect; - - } else { - left = -halfSize * aspect; - right = halfSize * aspect; - top = halfSize; - bottom = -halfSize; - } - - math.orthoMat4c(left, right, bottom, top, this._state.near, this._state.far, this._state.matrix); - - this._inverseMatrixDirty = true; - this._transposedMatrixDirty = true; - - this.glRedraw(); - - this.fire("matrix", this._state.matrix); - } - - - /** - * Sets scale factor for this Ortho's extents on X and Y axis. - * - * Clamps to minimum value of ````0.01```. - * - * Fires a "scale" event on change. - * - * Default value is ````1.0```` - * @param {Number} value New scale value. - */ - set scale(value) { - if (value === undefined || value === null) { - value = 1.0; - } - if (value <= 0) { - value = 0.01; - } - this._scale = value; - this._needUpdate(0); - this.fire("scale", this._scale); - } - - /** - * Gets scale factor for this Ortho's extents on X and Y axis. - * - * Clamps to minimum value of ````0.01```. - * - * Default value is ````1.0```` - * - * @returns {Number} New Ortho scale value. - */ - get scale() { - return this._scale; - } - - /** - * Sets the position of the Ortho's near plane on the positive View-space Z-axis. - * - * Fires a "near" emits on change. - * - * Default value is ````0.1````. - * - * @param {Number} value New Ortho near plane position. - */ - set near(value) { - const near = (value !== undefined && value !== null) ? value : 0.1; - if (this._state.near === near) { - return; - } - this._state.near = near; - this._needUpdate(0); - this.fire("near", this._state.near); - } - - /** - * Gets the position of the Ortho's near plane on the positive View-space Z-axis. - * - * Default value is ````0.1````. - * - * @returns {Number} New Ortho near plane position. - */ - get near() { - return this._state.near; - } - - /** - * Sets the position of the Ortho's far plane on the positive View-space Z-axis. - * - * Fires a "far" event on change. - * - * Default value is ````10000.0````. - * - * @param {Number} value New far ortho plane position. - */ - set far(value) { - const far = (value !== undefined && value !== null) ? value : 10000.0; - if (this._state.far === far) { - return; - } - this._state.far = far; - this._needUpdate(0); - this.fire("far", this._state.far); - } - - /** - * Gets the position of the Ortho's far plane on the positive View-space Z-axis. - * - * Default value is ````10000.0````. - * - * @returns {Number} New far ortho plane position. - */ - get far() { - return this._state.far; - } - - /** - * Gets the Ortho's projection transform matrix. - * - * Fires a "matrix" event on change. - * - * Default value is ````[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]````. - * - * @returns {Number[]} The Ortho's projection matrix. - */ - get matrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - return this._state.matrix; - } - - /** - * Gets the inverse of {@link Ortho#matrix}. - * - * @returns {Number[]} The inverse of {@link Ortho#matrix}. - */ - get inverseMatrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - if (this._inverseMatrixDirty) { - math.inverseMat4(this._state.matrix, this._state.inverseMatrix); - this._inverseMatrixDirty = false; - } - return this._state.inverseMatrix; - } - - /** - * Gets the transpose of {@link Ortho#matrix}. - * - * @returns {Number[]} The transpose of {@link Ortho#matrix}. - */ - get transposedMatrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - if (this._transposedMatrixDirty) { - math.transposeMat4(this._state.matrix, this._state.transposedMatrix); - this._transposedMatrixDirty = false; - } - return this._state.transposedMatrix; - } - - /** - * Un-projects the given Canvas-space coordinates, using this Ortho projection. - * - * @param {Number[]} canvasPos Inputs 2D Canvas-space coordinates. - * @param {Number} screenZ Inputs Screen-space Z coordinate. - * @param {Number[]} screenPos Outputs 3D Screen/Clip-space coordinates. - * @param {Number[]} viewPos Outputs un-projected 3D View-space coordinates. - * @param {Number[]} worldPos Outputs un-projected 3D World-space coordinates. - */ - unproject(canvasPos, screenZ, screenPos, viewPos, worldPos) { - - const canvas = this.scene.canvas.canvas; - - const halfCanvasWidth = canvas.offsetWidth / 2.0; - const halfCanvasHeight = canvas.offsetHeight / 2.0; - - screenPos[0] = (canvasPos[0] - halfCanvasWidth) / halfCanvasWidth; - screenPos[1] = (canvasPos[1] - halfCanvasHeight) / halfCanvasHeight; - screenPos[2] = screenZ; - screenPos[3] = 1.0; - - math.mulMat4v4(this.inverseMatrix, screenPos, viewPos); - math.mulVec3Scalar(viewPos, 1.0 / viewPos[3]); - - viewPos[3] = 1.0; - viewPos[1] *= -1; - - math.mulMat4v4(this.camera.inverseViewMatrix, viewPos, worldPos); - - return worldPos; - } - - /** @private - * - */ - destroy() { - super.destroy(); - this._state.destroy(); - this.scene.canvas.off(this._onCanvasBoundary); - } -} - -/** - * @desc Defines its {@link Camera}'s perspective projection as a frustum-shaped view volume. - * - * * Located at {@link Camera#frustum}. - * * Allows to explicitly set the positions of the left, right, top, bottom, near and far planes, which is useful for asymmetrical view volumes, such as for stereo viewing. - * * {@link Frustum#near} and {@link Frustum#far} specify the distances to the WebGL clipping planes. - */ -class Frustum extends Component { - - /** - @private - */ - get type() { - return "Frustum"; - } - - /** - * @constructor - * @private - */ - constructor(camera, cfg = {}) { - - super(camera, cfg); - - /** - * The Camera this Frustum belongs to. - * - * @property camera - * @type {Camera} - * @final - */ - this.camera = camera; - - this._state = new RenderState({ - matrix: math.mat4(), - inverseMatrix: math.mat4(), - transposedMatrix: math.mat4(), - near: 0.1, - far: 10000.0 - }); - - this._left = -1.0; - this._right = 1.0; - this._bottom = -1.0; - this._top = 1.0; - - this._inverseMatrixDirty = true; - this._transposedMatrixDirty = true; - - // Set component properties - - this.left = cfg.left; - this.right = cfg.right; - this.bottom = cfg.bottom; - this.top = cfg.top; - this.near = cfg.near; - this.far = cfg.far; - } - - _update() { - - math.frustumMat4(this._left, this._right, this._bottom, this._top, this._state.near, this._state.far, this._state.matrix); - - this._inverseMatrixDirty = true; - this._transposedMatrixDirty = true; - - this.glRedraw(); - - this.fire("matrix", this._state.matrix); - } - - /** - * Sets the position of the Frustum's left plane on the View-space X-axis. - * - * Fires a {@link Frustum#left:emits} emits on change. - * - * @param {Number} value New left frustum plane position. - */ - set left(value) { - this._left = (value !== undefined && value !== null) ? value : -1.0; - this._needUpdate(0); - this.fire("left", this._left); - } - - /** - * Gets the position of the Frustum's left plane on the View-space X-axis. - * - * @return {Number} Left frustum plane position. - */ - get left() { - return this._left; - } - - /** - * Sets the position of the Frustum's right plane on the View-space X-axis. - * - * Fires a {@link Frustum#right:emits} emits on change. - * - * @param {Number} value New right frustum plane position. - */ - set right(value) { - this._right = (value !== undefined && value !== null) ? value : 1.0; - this._needUpdate(0); - this.fire("right", this._right); - } - - /** - * Gets the position of the Frustum's right plane on the View-space X-axis. - * - * Fires a {@link Frustum#right:emits} emits on change. - * - * @return {Number} Right frustum plane position. - */ - get right() { - return this._right; - } - - /** - * Sets the position of the Frustum's top plane on the View-space Y-axis. - * - * Fires a {@link Frustum#top:emits} emits on change. - * - * @param {Number} value New top frustum plane position. - */ - set top(value) { - this._top = (value !== undefined && value !== null) ? value : 1.0; - this._needUpdate(0); - this.fire("top", this._top); - } - - /** - * Gets the position of the Frustum's top plane on the View-space Y-axis. - * - * Fires a {@link Frustum#top:emits} emits on change. - * - * @return {Number} Top frustum plane position. - */ - get top() { - return this._top; - } - - /** - * Sets the position of the Frustum's bottom plane on the View-space Y-axis. - * - * Fires a {@link Frustum#bottom:emits} emits on change. - * - * @emits {"bottom"} event with the value of this property whenever it changes. - * - * @param {Number} value New bottom frustum plane position. - */ - set bottom(value) { - this._bottom = (value !== undefined && value !== null) ? value : -1.0; - this._needUpdate(0); - this.fire("bottom", this._bottom); - } - - /** - * Gets the position of the Frustum's bottom plane on the View-space Y-axis. - * - * Fires a {@link Frustum#bottom:emits} emits on change. - * - * @return {Number} Bottom frustum plane position. - */ - get bottom() { - return this._bottom; - } - - /** - * Sets the position of the Frustum's near plane on the positive View-space Z-axis. - * - * Fires a {@link Frustum#near:emits} emits on change. - * - * Default value is ````0.1````. - * - * @param {Number} value New Frustum near plane position. - */ - set near(value) { - this._state.near = (value !== undefined && value !== null) ? value : 0.1; - this._needUpdate(0); - this.fire("near", this._state.near); - } - - /** - * Gets the position of the Frustum's near plane on the positive View-space Z-axis. - * - * Fires a {@link Frustum#near:emits} emits on change. - * - * Default value is ````0.1````. - * - * @return {Number} Near frustum plane position. - */ - get near() { - return this._state.near; - } - - /** - * Sets the position of the Frustum's far plane on the positive View-space Z-axis. - * - * Fires a {@link Frustum#far:emits} emits on change. - * - * Default value is ````10000.0````. - * - * @param {Number} value New far frustum plane position. - */ - set far(value) { - this._state.far = (value !== undefined && value !== null) ? value : 10000.0; - this._needUpdate(0); - this.fire("far", this._state.far); - } - - /** - * Gets the position of the Frustum's far plane on the positive View-space Z-axis. - * - * Default value is ````10000.0````. - * - * @return {Number} Far frustum plane position. - */ - get far() { - return this._state.far; - } - - /** - * Gets the Frustum's projection transform matrix. - * - * Fires a {@link Frustum#matrix:emits} emits on change. - * - * Default value is ````[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]````. - * - * @returns {Number[]} The Frustum's projection matrix matrix. - */ - get matrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - return this._state.matrix; - } - - /** - * Gets the inverse of {@link Frustum#matrix}. - * - * @returns {Number[]} The inverse orthographic projection matrix. - */ - get inverseMatrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - if (this._inverseMatrixDirty) { - math.inverseMat4(this._state.matrix, this._state.inverseMatrix); - this._inverseMatrixDirty = false; - } - return this._state.inverseMatrix; - } - - /** - * Gets the transpose of {@link Frustum#matrix}. - * - * @returns {Number[]} The transpose of {@link Frustum#matrix}. - */ - get transposedMatrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - if (this._transposedMatrixDirty) { - math.transposeMat4(this._state.matrix, this._state.transposedMatrix); - this._transposedMatrixDirty = false; - } - return this._state.transposedMatrix; - } - - /** - * Un-projects the given Canvas-space coordinates, using this Frustum projection. - * - * @param {Number[]} canvasPos Inputs 2D Canvas-space coordinates. - * @param {Number} screenZ Inputs Screen-space Z coordinate. - * @param {Number[]} screenPos Outputs 3D Screen/Clip-space coordinates. - * @param {Number[]} viewPos Outputs un-projected 3D View-space coordinates. - * @param {Number[]} worldPos Outputs un-projected 3D World-space coordinates. - */ - unproject(canvasPos, screenZ, screenPos, viewPos, worldPos) { - - const canvas = this.scene.canvas.canvas; - - const halfCanvasWidth = canvas.offsetWidth / 2.0; - const halfCanvasHeight = canvas.offsetHeight / 2.0; - - screenPos[0] = (canvasPos[0] - halfCanvasWidth) / halfCanvasWidth; - screenPos[1] = (canvasPos[1] - halfCanvasHeight) / halfCanvasHeight; - screenPos[2] = screenZ; - screenPos[3] = 1.0; - - math.mulMat4v4(this.inverseMatrix, screenPos, viewPos); - math.mulVec3Scalar(viewPos, 1.0 / viewPos[3]); - - viewPos[3] = 1.0; - viewPos[1] *= -1; - - math.mulMat4v4(this.camera.inverseViewMatrix, viewPos, worldPos); - - return worldPos; - } - - /** @private - * - */ - destroy() { - super.destroy(); - this._state.destroy(); - super.destroy(); - } -} - -/** - * @desc Defines a custom projection for a {@link Camera} as a custom 4x4 matrix.. - * - * Located at {@link Camera#customProjection}. - */ -class CustomProjection extends Component { - - /** - * @private - */ - get type() { - return "CustomProjection"; - } - - /** - * @constructor - * @private - */ - constructor(camera, cfg = {}) { - - super(camera, cfg); - - /** - * The Camera this CustomProjection belongs to. - * - * @property camera - * @type {Camera} - * @final - */ - this.camera = camera; - - this._state = new RenderState({ - matrix: math.mat4(), - inverseMatrix: math.mat4(), - transposedMatrix: math.mat4() - }); - - this._inverseMatrixDirty = true; - this._transposedMatrixDirty = false; - - this.matrix = cfg.matrix; - } - - /** - * Sets the CustomProjection's projection transform matrix. - * - * Fires a "matrix" event on change. - - * Default value is ````[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]````. - * - * @param {Number[]} matrix New value for the CustomProjection's matrix. - */ - set matrix(matrix) { - this._state.matrix.set(matrix || [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); - this._inverseMatrixDirty = true; - this._transposedMatrixDirty = true; - this.glRedraw(); - this.fire("matrix", this._state.matrix); - } - - /** - * Gets the CustomProjection's projection transform matrix. - * - * Default value is ````[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]````. - * - * @return {Number[]} New value for the CustomProjection's matrix. - */ - get matrix() { - return this._state.matrix; - } - - /** - * Gets the inverse of {@link CustomProjection#matrix}. - * - * @returns {Number[]} The inverse of {@link CustomProjection#matrix}. - */ - get inverseMatrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - if (this._inverseMatrixDirty) { - math.inverseMat4(this._state.matrix, this._state.inverseMatrix); - this._inverseMatrixDirty = false; - } - return this._state.inverseMatrix; - } - - /** - * Gets the transpose of {@link CustomProjection#matrix}. - * - * @returns {Number[]} The transpose of {@link CustomProjection#matrix}. - */ - get transposedMatrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - if (this._transposedMatrixDirty) { - math.transposeMat4(this._state.matrix, this._state.transposedMatrix); - this._transposedMatrixDirty = false; - } - return this._state.transposedMatrix; - } - - /** - * Un-projects the given Canvas-space coordinates, using this CustomProjection. - * - * @param {Number[]} canvasPos Inputs 2D Canvas-space coordinates. - * @param {Number} screenZ Inputs Screen-space Z coordinate. - * @param {Number[]} screenPos Outputs 3D Screen/Clip-space coordinates. - * @param {Number[]} viewPos Outputs un-projected 3D View-space coordinates. - * @param {Number[]} worldPos Outputs un-projected 3D World-space coordinates. - */ - unproject(canvasPos, screenZ, screenPos, viewPos, worldPos) { - - const canvas = this.scene.canvas.canvas; - - const halfCanvasWidth = canvas.offsetWidth / 2.0; - const halfCanvasHeight = canvas.offsetHeight / 2.0; - - screenPos[0] = (canvasPos[0] - halfCanvasWidth) / halfCanvasWidth; - screenPos[1] = (canvasPos[1] - halfCanvasHeight) / halfCanvasHeight; - screenPos[2] = screenZ; - screenPos[3] = 1.0; - - math.mulMat4v4(this.inverseMatrix, screenPos, viewPos); - math.mulVec3Scalar(viewPos, 1.0 / viewPos[3]); - - viewPos[3] = 1.0; - viewPos[1] *= -1; - - math.mulMat4v4(this.camera.inverseViewMatrix, viewPos, worldPos); - - return worldPos; - } - - /** @private - * - */ - destroy() { - super.destroy(); - this._state.destroy(); - } -} - -const tempVec3$4 = math.vec3(); -const tempVec3b$7 = math.vec3(); -const tempVec3c$6 = math.vec3(); -const tempVec3d$1 = math.vec3(); -const tempVec3e = math.vec3(); -const tempVec3f = math.vec3(); -const tempVec4a$7 = math.vec4(); -const tempVec4b$7 = math.vec4(); -const tempVec4c$2 = math.vec4(); -const tempMat = math.mat4(); -const tempMatb = math.mat4(); -const eyeLookVec = math.vec3(); -const eyeLookVecNorm = math.vec3(); -const eyeLookOffset = math.vec3(); -const offsetEye = math.vec3(); - -/** - * @desc Manages viewing and projection transforms for its {@link Scene}. - * - * * One Camera per {@link Scene} - * * Scene is located at {@link Viewer#scene} and Camera is located at {@link Scene#camera} - * * Controls viewing and projection transforms - * * Has methods to pan, zoom and orbit (or first-person rotation) - * * Dynamically configurable World-space axis - * * Has {@link Perspective}, {@link Ortho} and {@link Frustum} and {@link CustomProjection}, which you can dynamically switch it between - * * Switchable gimbal lock - * * Can be "flown" to look at targets using a {@link CameraFlightAnimation} - * * Can be animated along a path using a {@link CameraPathAnimation} - * - * ## Getting the Camera - * - * There is exactly one Camera per {@link Scene}: - * - * ````javascript - * import {Viewer} from "xeokit-sdk.es.js"; - * - * var camera = viewer.scene.camera; - * - * ```` - * - * ## Setting the Camera Position - * - * Get and set the Camera's absolute position via {@link Camera#eye}, {@link Camera#look} and {@link Camera#up}: - * - * ````javascript - * camera.eye = [-10,0,0]; - * camera.look = [-10,0,0]; - * camera.up = [0,1,0]; - * ```` - * - * ## Camera View and Projection Matrices - * - * The Camera's view matrix transforms coordinates from World-space to View-space. - * - * Getting the view matrix: - * - * ````javascript - * var viewMatrix = camera.viewMatrix; - * var viewNormalMatrix = camera.normalMatrix; - * ```` - * - * The Camera's view normal matrix transforms normal vectors from World-space to View-space. - * - * Getting the view normal matrix: - * - * ````javascript - * var viewNormalMatrix = camera.normalMatrix; - * ```` - * - * The Camera fires a ````"viewMatrix"```` event whenever the {@link Camera#viewMatrix} and {@link Camera#viewNormalMatrix} updates. - * - * Listen for view matrix updates: - * - * ````javascript - * camera.on("viewMatrix", function(matrix) { ... }); - * ```` - * - * ## Rotating the Camera - * - * Orbiting the {@link Camera#look} position: - * - * ````javascript - * camera.orbitYaw(20.0); - * camera.orbitPitch(10.0); - * ```` - * - * First-person rotation, rotates {@link Camera#look} and {@link Camera#up} about {@link Camera#eye}: - * - * ````javascript - * camera.yaw(5.0); - * camera.pitch(-10.0); - * ```` - * - * ## Panning the Camera - * - * Panning along the Camera's local axis (ie. left/right, up/down, forward/backward): - * - * ````javascript - * camera.pan([-20, 0, 10]); - * ```` - * - * ## Zooming the Camera - * - * Zoom to vary distance between {@link Camera#eye} and {@link Camera#look}: - * - * ````javascript - * camera.zoom(-5); // Move five units closer - * ```` - * - * Get the current distance between {@link Camera#eye} and {@link Camera#look}: - * - * ````javascript - * var distance = camera.eyeLookDist; - * ```` - * - * ## Projection - * - * The Camera has a Component to manage each projection type, which are: {@link Perspective}, {@link Ortho} - * and {@link Frustum} and {@link CustomProjection}. - * - * You can configure those components at any time, regardless of which is currently active: - * - * The Camera has a {@link Perspective} to manage perspective - * ````javascript - * - * // Set some properties on Perspective - * camera.perspective.near = 0.4; - * camera.perspective.fov = 45; - * - * // Set some properties on Ortho - * camera.ortho.near = 0.8; - * camera.ortho.far = 1000; - * - * // Set some properties on Frustum - * camera.frustum.left = -1.0; - * camera.frustum.right = 1.0; - * camera.frustum.far = 1000.0; - * - * // Set the matrix property on CustomProjection - * camera.customProjection.matrix = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; - * - * // Switch between the projection types - * camera.projection = "perspective"; // Switch to perspective - * camera.projection = "frustum"; // Switch to frustum - * camera.projection = "ortho"; // Switch to ortho - * camera.projection = "customProjection"; // Switch to custom - * ```` - * - * Camera provides the projection matrix for the currently active projection in {@link Camera#projMatrix}. - * - * Get the projection matrix: - * - * ````javascript - * var projMatrix = camera.projMatrix; - * ```` - * - * Listen for projection matrix updates: - * - * ````javascript - * camera.on("projMatrix", function(matrix) { ... }); - * ```` - * - * ## Configuring World up direction - * - * We can dynamically configure the directions of the World-space coordinate system. - * - * Setting the +Y axis as World "up", +X as right and -Z as forwards (convention in some modeling software): - * - * ````javascript - * camera.worldAxis = [ - * 1, 0, 0, // Right - * 0, 1, 0, // Up - * 0, 0,-1 // Forward - * ]; - * ```` - * - * Setting the +Z axis as World "up", +X as right and -Y as "up" (convention in most CAD and BIM viewers): - * - * ````javascript - * camera.worldAxis = [ - * 1, 0, 0, // Right - * 0, 0, 1, // Up - * 0,-1, 0 // Forward - * ]; - * ```` - * - * The Camera has read-only convenience properties that provide each axis individually: - * - * ````javascript - * var worldRight = camera.worldRight; - * var worldForward = camera.worldForward; - * var worldUp = camera.worldUp; - * ```` - * - * ### Gimbal locking - * - * By default, the Camera locks yaw rotation to pivot about the World-space "up" axis. We can dynamically lock and unlock that at any time: - * - * ````javascript - * camera.gimbalLock = false; // Yaw rotation now happens about Camera's local Y-axis - * camera.gimbalLock = true; // Yaw rotation now happens about World's "up" axis - * ```` - * - * See: https://en.wikipedia.org/wiki/Gimbal_lock - */ -class Camera extends Component { - - /** - @private - */ - get type() { - return "Camera"; - } - - /** - * @constructor - * @private - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._state = new RenderState({ - offsetEyeFromLook: true, // TODO: treat as legacy and get rid of at some later point - deviceMatrix: math.mat4(), - hasDeviceMatrix: false, // True when deviceMatrix set to other than identity - matrix: math.mat4(), - normalMatrix: math.mat4(), - inverseMatrix: math.mat4() - }); - - this._perspective = new Perspective(this); - this._ortho = new Ortho(this); - this._frustum = new Frustum(this); - this._customProjection = new CustomProjection(this); - this._project = this._perspective; - - this._eye = math.vec3([0, 0, 10.0]); - this._look = math.vec3([0, 0, 0]); - this._up = math.vec3([0, 1, 0]); - - this._worldUp = math.vec3([0, 1, 0]); - this._worldRight = math.vec3([1, 0, 0]); - this._worldForward = math.vec3([0, 0, -1]); - - this.deviceMatrix = cfg.deviceMatrix; - this.eye = cfg.eye; - this.look = cfg.look; - this.up = cfg.up; - this.worldAxis = cfg.worldAxis; - this.gimbalLock = cfg.gimbalLock; - this.constrainPitch = cfg.constrainPitch; - - this.projection = cfg.projection; - - this._perspective.on("matrix", () => { - if (this._projectionType === "perspective") { - this.fire("projMatrix", this._perspective.matrix); - } - }); - this._ortho.on("matrix", () => { - if (this._projectionType === "ortho") { - this.fire("projMatrix", this._ortho.matrix); - } - }); - this._frustum.on("matrix", () => { - if (this._projectionType === "frustum") { - this.fire("projMatrix", this._frustum.matrix); - } - }); - this._customProjection.on("matrix", () => { - if (this._projectionType === "customProjection") { - this.fire("projMatrix", this._customProjection.matrix); - } - }); - } - - _update() { - const state = this._state; - // In ortho mode, build the view matrix with an eye position that's translated - // well back from look, so that the front sectionPlane plane doesn't unexpectedly cut - // the front off the view (not a problem with perspective, since objects close enough - // to be clipped by the front plane are usually too big to see anything of their cross-sections). - let eye; - if (this.projection === "ortho" && this._state.offsetEyeFromLook) { - math.subVec3(this._eye, this._look, eyeLookVec); - math.normalizeVec3(eyeLookVec, eyeLookVecNorm); - math.mulVec3Scalar(eyeLookVecNorm, 1000.0, eyeLookOffset); - math.addVec3(this._look, eyeLookOffset, offsetEye); - eye = offsetEye; - } else { - eye = this._eye; - } - if (state.hasDeviceMatrix) { - math.lookAtMat4v(eye, this._look, this._up, tempMatb); - math.mulMat4(state.deviceMatrix, tempMatb, state.matrix); - //state.matrix.set(state.deviceMatrix); - } else { - math.lookAtMat4v(eye, this._look, this._up, state.matrix); - } - math.inverseMat4(this._state.matrix, this._state.inverseMatrix); - math.transposeMat4(this._state.inverseMatrix, this._state.normalMatrix); - this.glRedraw(); - this.fire("matrix", this._state.matrix); - this.fire("viewMatrix", this._state.matrix); - } - - /** - * Rotates {@link Camera#eye} about {@link Camera#look}, around the {@link Camera#up} vector - * - * @param {Number} angleInc Angle of rotation in degrees - */ - orbitYaw(angleInc) { - let lookEyeVec = math.subVec3(this._eye, this._look, tempVec3$4); - math.rotationMat4v(angleInc * 0.0174532925, this._gimbalLock ? this._worldUp : this._up, tempMat); - lookEyeVec = math.transformPoint3(tempMat, lookEyeVec, tempVec3b$7); - this.eye = math.addVec3(this._look, lookEyeVec, tempVec3c$6); // Set eye position as 'look' plus 'eye' vector - this.up = math.transformPoint3(tempMat, this._up, tempVec3d$1); // Rotate 'up' vector - } - - /** - * Rotates {@link Camera#eye} about {@link Camera#look} around the right axis (orthogonal to {@link Camera#up} and "look"). - * - * @param {Number} angleInc Angle of rotation in degrees - */ - orbitPitch(angleInc) { - if (this._constrainPitch) { - angleInc = math.dotVec3(this._up, this._worldUp) / math.DEGTORAD; - if (angleInc < 1) { - return; - } - } - let eye2 = math.subVec3(this._eye, this._look, tempVec3$4); - const left = math.cross3Vec3(math.normalizeVec3(eye2, tempVec3b$7), math.normalizeVec3(this._up, tempVec3c$6)); - math.rotationMat4v(angleInc * 0.0174532925, left, tempMat); - eye2 = math.transformPoint3(tempMat, eye2, tempVec3d$1); - this.up = math.transformPoint3(tempMat, this._up, tempVec3e); - this.eye = math.addVec3(eye2, this._look, tempVec3f); - } - - /** - * Rotates {@link Camera#look} about {@link Camera#eye}, around the {@link Camera#up} vector. - * - * @param {Number} angleInc Angle of rotation in degrees - */ - yaw(angleInc) { - let look2 = math.subVec3(this._look, this._eye, tempVec3$4); - math.rotationMat4v(angleInc * 0.0174532925, this._gimbalLock ? this._worldUp : this._up, tempMat); - look2 = math.transformPoint3(tempMat, look2, tempVec3b$7); - this.look = math.addVec3(look2, this._eye, tempVec3c$6); - if (this._gimbalLock) { - this.up = math.transformPoint3(tempMat, this._up, tempVec3d$1); - } - } - - /** - * Rotates {@link Camera#look} about {@link Camera#eye}, around the right axis (orthogonal to {@link Camera#up} and "look"). - - * @param {Number} angleInc Angle of rotation in degrees - */ - pitch(angleInc) { - if (this._constrainPitch) { - angleInc = math.dotVec3(this._up, this._worldUp) / math.DEGTORAD; - if (angleInc < 1) { - return; - } - } - let look2 = math.subVec3(this._look, this._eye, tempVec3$4); - const left = math.cross3Vec3(math.normalizeVec3(look2, tempVec3b$7), math.normalizeVec3(this._up, tempVec3c$6)); - math.rotationMat4v(angleInc * 0.0174532925, left, tempMat); - this.up = math.transformPoint3(tempMat, this._up, tempVec3f); - look2 = math.transformPoint3(tempMat, look2, tempVec3d$1); - this.look = math.addVec3(look2, this._eye, tempVec3e); - } - - /** - * Pans the Camera along its local X, Y and Z axis. - * - * @param pan The pan vector - */ - pan(pan) { - const eye2 = math.subVec3(this._eye, this._look, tempVec3$4); - const vec = [0, 0, 0]; - let v; - if (pan[0] !== 0) { - const left = math.cross3Vec3(math.normalizeVec3(eye2, []), math.normalizeVec3(this._up, tempVec3b$7)); - v = math.mulVec3Scalar(left, pan[0]); - vec[0] += v[0]; - vec[1] += v[1]; - vec[2] += v[2]; - } - if (pan[1] !== 0) { - v = math.mulVec3Scalar(math.normalizeVec3(this._up, tempVec3c$6), pan[1]); - vec[0] += v[0]; - vec[1] += v[1]; - vec[2] += v[2]; - } - if (pan[2] !== 0) { - v = math.mulVec3Scalar(math.normalizeVec3(eye2, tempVec3d$1), pan[2]); - vec[0] += v[0]; - vec[1] += v[1]; - vec[2] += v[2]; - } - this.eye = math.addVec3(this._eye, vec, tempVec3e); - this.look = math.addVec3(this._look, vec, tempVec3f); - } - - /** - * Increments/decrements the Camera's zoom factor, which is the distance between {@link Camera#eye} and {@link Camera#look}. - * - * @param {Number} delta Zoom factor increment. - */ - zoom(delta) { - const vec = math.subVec3(this._eye, this._look, tempVec3$4); - const lenLook = Math.abs(math.lenVec3(vec, tempVec3b$7)); - const newLenLook = Math.abs(lenLook + delta); - if (newLenLook < 0.5) { - return; - } - const dir = math.normalizeVec3(vec, tempVec3c$6); - this.eye = math.addVec3(this._look, math.mulVec3Scalar(dir, newLenLook), tempVec3d$1); - } - - /** - * Sets the position of the Camera's eye. - * - * Default value is ````[0,0,10]````. - * - * @emits "eye" event on change, with the value of this property. - * @type {Number[]} New eye position. - */ - set eye(eye) { - this._eye.set(eye || [0, 0, 10]); - this._needUpdate(0); // Ensure matrix built on next "tick" - this.fire("eye", this._eye); - } - - /** - * Gets the position of the Camera's eye. - * - * Default vale is ````[0,0,10]````. - * - * @type {Number[]} New eye position. - */ - get eye() { - return this._eye; - } - - /** - * Sets the position of this Camera's point-of-interest. - * - * Default value is ````[0,0,0]````. - * - * @emits "look" event on change, with the value of this property. - * - * @param {Number[]} look Camera look position. - */ - set look(look) { - this._look.set(look || [0, 0, 0]); - this._needUpdate(0); // Ensure matrix built on next "tick" - this.fire("look", this._look); - } - - /** - * Gets the position of this Camera's point-of-interest. - * - * Default value is ````[0,0,0]````. - * - * @returns {Number[]} Camera look position. - */ - get look() { - return this._look; - } - - /** - * Sets the direction of this Camera's {@link Camera#up} vector. - * - * @emits "up" event on change, with the value of this property. - * - * @param {Number[]} up Direction of "up". - */ - set up(up) { - this._up.set(up || [0, 1, 0]); - this._needUpdate(0); - this.fire("up", this._up); - } - - /** - * Gets the direction of this Camera's {@link Camera#up} vector. - * - * @returns {Number[]} Direction of "up". - */ - get up() { - return this._up; - } - - /** - * Sets an optional matrix to premultiply into {@link Camera#matrix} matrix. - * - * This is intended to be used for stereo rendering with WebVR etc. - * - * @param {Number[]} matrix The matrix. - */ - set deviceMatrix(matrix) { - this._state.deviceMatrix.set(matrix || [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); - this._state.hasDeviceMatrix = !!matrix; - this._needUpdate(0); - this.fire("deviceMatrix", this._state.deviceMatrix); - } - - /** - * Gets an optional matrix to premultiply into {@link Camera#matrix} matrix. - * - * @returns {Number[]} The matrix. - */ - get deviceMatrix() { - return this._state.deviceMatrix; - } - - /** - * Sets the up, right and forward axis of the World coordinate system. - * - * Has format: ````[rightX, rightY, rightZ, upX, upY, upZ, forwardX, forwardY, forwardZ]```` - * - * Default axis is ````[1, 0, 0, 0, 1, 0, 0, 0, 1]```` - * - * @param {Number[]} axis The new Wworld coordinate axis. - */ - set worldAxis(axis) { - axis = axis || [1, 0, 0, 0, 1, 0, 0, 0, 1]; - if (!this._worldAxis) { - this._worldAxis = math.vec3(axis); - } else { - this._worldAxis.set(axis); - } - this._worldRight[0] = this._worldAxis[0]; - this._worldRight[1] = this._worldAxis[1]; - this._worldRight[2] = this._worldAxis[2]; - this._worldUp[0] = this._worldAxis[3]; - this._worldUp[1] = this._worldAxis[4]; - this._worldUp[2] = this._worldAxis[5]; - this._worldForward[0] = this._worldAxis[6]; - this._worldForward[1] = this._worldAxis[7]; - this._worldForward[2] = this._worldAxis[8]; - this.fire("worldAxis", this._worldAxis); - } - - /** - * Gets the up, right and forward axis of the World coordinate system. - * - * Has format: ````[rightX, rightY, rightZ, upX, upY, upZ, forwardX, forwardY, forwardZ]```` - * - * Default axis is ````[1, 0, 0, 0, 1, 0, 0, 0, 1]```` - * - * @returns {Number[]} The current World coordinate axis. - */ - get worldAxis() { - return this._worldAxis; - } - - /** - * Gets the direction of World-space "up". - * - * This is set by {@link Camera#worldAxis}. - * - * Default value is ````[0,1,0]````. - * - * @returns {Number[]} The "up" vector. - */ - get worldUp() { - return this._worldUp; - } - - /** - * Gets if the World-space X-axis is "up". - * @returns {Boolean} - */ - get xUp() { - return this._worldUp[0] > this._worldUp[1] && this._worldUp[0] > this._worldUp[2]; - } - - /** - * Gets if the World-space Y-axis is "up". - * @returns {Boolean} - */ - get yUp() { - return this._worldUp[1] > this._worldUp[0] && this._worldUp[1] > this._worldUp[2]; - } - - /** - * Gets if the World-space Z-axis is "up". - * @returns {Boolean} - */ - get zUp() { - return this._worldUp[2] > this._worldUp[0] && this._worldUp[2] > this._worldUp[1]; - } - - /** - * Gets the direction of World-space "right". - * - * This is set by {@link Camera#worldAxis}. - * - * Default value is ````[1,0,0]````. - * - * @returns {Number[]} The "up" vector. - */ - get worldRight() { - return this._worldRight; - } - - /** - * Gets the direction of World-space "forwards". - * - * This is set by {@link Camera#worldAxis}. - * - * Default value is ````[0,0,1]````. - * - * @returns {Number[]} The "up" vector. - */ - get worldForward() { - return this._worldForward; - } - - /** - * Sets whether to lock yaw rotation to pivot about the World-space "up" axis. - * - * Fires a {@link Camera#gimbalLock:event} event on change. - * - * @params {Boolean} gimbalLock Set true to lock gimbal. - */ - set gimbalLock(value) { - this._gimbalLock = value !== false; - this.fire("gimbalLock", this._gimbalLock); - } - - /** - * Gets whether to lock yaw rotation to pivot about the World-space "up" axis. - * - * @returns {Boolean} Returns ````true```` if gimbal is locked. - */ - get gimbalLock() { - return this._gimbalLock; - } - - /** - * Sets whether to prevent camera from being pitched upside down. - * - * The camera is upside down when the angle between {@link Camera#up} and {@link Camera#worldUp} is less than one degree. - * - * Fires a {@link Camera#constrainPitch:event} event on change. - * - * Default value is ````false````. - * - * @param {Boolean} value Set ````true```` to contrain pitch rotation. - */ - set constrainPitch(value) { - this._constrainPitch = !!value; - this.fire("constrainPitch", this._constrainPitch); - } - - /** - * Gets whether to prevent camera from being pitched upside down. - * - * The camera is upside down when the angle between {@link Camera#up} and {@link Camera#worldUp} is less than one degree. - * - * Default value is ````false````. - * - * @returns {Boolean} ````true```` if pitch rotation is currently constrained. - get constrainPitch() { - return this._constrainPitch; - } - - /** - * Gets distance from {@link Camera#look} to {@link Camera#eye}. - * - * @returns {Number} The distance. - */ - get eyeLookDist() { - return math.lenVec3(math.subVec3(this._look, this._eye, tempVec3$4)); - } - - /** - * Gets the Camera's viewing transformation matrix. - * - * Fires a {@link Camera#matrix:event} event on change. - * - * @returns {Number[]} The viewing transform matrix. - */ - get matrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - return this._state.matrix; - } - - /** - * Gets the Camera's viewing transformation matrix. - * - * Fires a {@link Camera#matrix:event} event on change. - * - * @returns {Number[]} The viewing transform matrix. - */ - get viewMatrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - return this._state.matrix; - } - - /** - * The Camera's viewing normal transformation matrix. - * - * Fires a {@link Camera#matrix:event} event on change. - * - * @returns {Number[]} The viewing normal transform matrix. - */ - get normalMatrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - return this._state.normalMatrix; - } - - /** - * The Camera's viewing normal transformation matrix. - * - * Fires a {@link Camera#matrix:event} event on change. - * - * @returns {Number[]} The viewing normal transform matrix. - */ - get viewNormalMatrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - return this._state.normalMatrix; - } - - /** - * Gets the inverse of the Camera's viewing transform matrix. - * - * This has the same value as {@link Camera#normalMatrix}. - * - * @returns {Number[]} The inverse viewing transform matrix. - */ - get inverseViewMatrix() { - if (this._updateScheduled) { - this._doUpdate(); - } - return this._state.inverseMatrix; - } - - /** - * Gets the Camera's projection transformation projMatrix. - * - * Fires a {@link Camera#projMatrix:event} event on change. - * - * @returns {Number[]} The projection matrix. - */ - get projMatrix() { - return this[this.projection].matrix; - } - - /** - * Gets the Camera's perspective projection. - * - * The Camera uses this while {@link Camera#projection} equals ````perspective````. - * - * @returns {Perspective} The Perspective component. - */ - get perspective() { - return this._perspective; - } - - /** - * Gets the Camera's orthographic projection. - * - * The Camera uses this while {@link Camera#projection} equals ````ortho````. - * - * @returns {Ortho} The Ortho component. - */ - get ortho() { - return this._ortho; - } - - /** - * Gets the Camera's frustum projection. - * - * The Camera uses this while {@link Camera#projection} equals ````frustum````. - * - * @returns {Frustum} The Ortho component. - */ - get frustum() { - return this._frustum; - } - - /** - * Gets the Camera's custom projection. - * - * This is used while {@link Camera#projection} equals "customProjection". - * - * @returns {CustomProjection} The custom projection. - */ - get customProjection() { - return this._customProjection; - } - - /** - * Sets the active projection type. - * - * Accepted values are ````"perspective"````, ````"ortho"````, ````"frustum"```` and ````"customProjection"````. - * - * Default value is ````"perspective"````. - * - * @param {String} value Identifies the active projection type. - */ - set projection(value) { - value = value || "perspective"; - if (this._projectionType === value) { - return; - } - if (value === "perspective") { - this._project = this._perspective; - } else if (value === "ortho") { - this._project = this._ortho; - } else if (value === "frustum") { - this._project = this._frustum; - } else if (value === "customProjection") { - this._project = this._customProjection; - } else { - this.error("Unsupported value for 'projection': " + value + " defaulting to 'perspective'"); - this._project = this._perspective; - value = "perspective"; - } - this._project._update(); - this._projectionType = value; - this.glRedraw(); - this._update(); // Need to rebuild lookat matrix with full eye, look & up - this.fire("dirty"); - this.fire("projection", this._projectionType); - this.fire("projMatrix", this._project.matrix); - } - - /** - * Gets the active projection type. - * - * Possible values are ````"perspective"````, ````"ortho"````, ````"frustum"```` and ````"customProjection"````. - * - * Default value is ````"perspective"````. - * - * @returns {String} Identifies the active projection type. - */ - get projection() { - return this._projectionType; - } - - /** - * Gets the currently active projection for this Camera. - * - * The currently active project is selected with {@link Camera#projection}. - * - * @returns {Perspective|Ortho|Frustum|CustomProjection} The currently active projection is active. - */ - get project() { - return this._project; - } - - /** - * Gets whether to offset the ortho camera's effective eye from its look - * - * Default value for legacy reasons is ````true````. - */ - get offsetEyeFromLook() { - return this._state.offsetEyeFromLook; - } - - /** - * Offsets the ortho camera's effective eye from its look - * - * Default value for legacy reasons is ````true````. - */ - set offsetEyeFromLook(v) { - this._state.offsetEyeFromLook = v; - this._needUpdate(0); // Ensure matrix built on next "tick" - } - - /** - * Get the 2D canvas position of a 3D world position. - * - * @param {[number, number, number]} worldPos - * @returns {[number, number]} the canvas position - */ - projectWorldPos(worldPos) { - const _worldPos = tempVec4a$7; - const viewPos = tempVec4b$7; - const screenPos = tempVec4c$2; - _worldPos[0] = worldPos[0]; - _worldPos[1] = worldPos[1]; - _worldPos[2] = worldPos[2]; - _worldPos[3] = 1; - math.mulMat4v4(this.viewMatrix, _worldPos, viewPos); - math.mulMat4v4(this.projMatrix, viewPos, screenPos); - math.mulVec3Scalar(screenPos, 1.0 / screenPos[3]); - screenPos[3] = 1.0; - screenPos[1] *= -1; - const canvas = this.scene.canvas.canvas; - const halfCanvasWidth = canvas.offsetWidth / 2.0; - const halfCanvasHeight = canvas.offsetHeight / 2.0; - const canvasPos = [ - screenPos[0] * halfCanvasWidth + halfCanvasWidth, - screenPos[1] * halfCanvasHeight + halfCanvasHeight, - ]; - return canvasPos; - } - - /** - * Destroys this Camera. - */ - destroy() { - super.destroy(); - this._state.destroy(); - } -} - -//---------------------------------------------------------------------------------------------------------------------- - -const unitsInfo = { - meters: { - abbrev: "m" - }, - metres: { - abbrev: "m" - }, - centimeters: { - abbrev: "cm" - }, - centimetres: { - abbrev: "cm" - }, - millimeters: { - abbrev: "mm" - }, - millimetres: { - abbrev: "mm" - }, - yards: { - abbrev: "yd" - }, - feet: { - abbrev: "ft" - }, - inches: { - abbrev: "in" - } -}; - -/** - * @desc Configures its {@link Scene}'s measurement unit and mapping between the Real-space and World-space 3D Cartesian coordinate systems. - * - * - * ## Overview - * - * * Located at {@link Scene#metrics}. - * * {@link Metrics#units} configures the Real-space unit type, which is ````"meters"```` by default. - * * {@link Metrics#scale} configures the number of Real-space units represented by each unit within the World-space 3D coordinate system. This is ````1.0```` by default. - * * {@link Metrics#origin} configures the 3D Real-space origin, in current Real-space units, at which this {@link Scene}'s World-space coordinate origin sits, This is ````[0,0,0]```` by default. - * - * ## Usage - * - * Let's load a model using an {@link XKTLoaderPlugin}, then configure the Real-space unit type and the coordinate - * mapping between the Real-space and World-space 3D coordinate systems. - * - * ````JavaScript - * import {Viewer, XKTLoaderPlugin} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas" - * }); - * - * viewer.scene.camera.eye = [-2.37, 18.97, -26.12]; - * viewer.scene.camera.look = [10.97, 5.82, -11.22]; - * viewer.scene.camera.up = [0.36, 0.83, 0.40]; - * - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * const model = xktLoader.load({ - * src: "./models/xkt/duplex/duplex.xkt" - * }); - * - * const metrics = viewer.scene.metrics; - * - * metrics.units = "meters"; - * metrics.scale = 10.0; - * metrics.origin = [100.0, 0.0, 200.0]; - * ```` - */ -class Metrics extends Component { - - /** - * @constructor - * @private - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._units = "meters"; - this._scale = 1.0; - this._origin = math.vec3([0, 0, 0]); - - this.units = cfg.units; - this.scale = cfg.scale; - this.origin = cfg.origin; - } - - /** - * Gets info about the supported Real-space unit types. - * - * This will be: - * - * ````javascript - * { - * { - * meters: { - * abbrev: "m" - * }, - * metres: { - * abbrev: "m" - * }, - * centimeters: { - * abbrev: "cm" - * }, - * centimetres: { - * abbrev: "cm" - * }, - * millimeters: { - * abbrev: "mm" - * }, - * millimetres: { - * abbrev: "mm" - * }, - * yards: { - * abbrev: "yd" - * }, - * feet: { - * abbrev: "ft" - * }, - * inches: { - * abbrev: "in" - * } - * } - * } - * ```` - * - * @type {*} - */ - get unitsInfo() { - return unitsInfo; - } - - /** - * Sets the {@link Scene}'s Real-space unit type. - * - * Accepted values are ````"meters"````, ````"centimeters"````, ````"millimeters"````, ````"metres"````, ````"centimetres"````, ````"millimetres"````, ````"yards"````, ````"feet"```` and ````"inches"````. - * - * @emits ````"units"```` event on change, with the value of this property. - * @type {String} - */ - set units(value) { - if (!value) { - value = "meters"; - } - const info = unitsInfo[value]; - if (!info) { - this.error("Unsupported value for 'units': " + value + " defaulting to 'meters'"); - value = "meters"; - } - this._units = value; - this.fire("units", this._units); - } - - /** - * Gets the {@link Scene}'s Real-space unit type. - * - * @type {String} - */ - get units() { - return this._units; - } - - /** - * Sets the number of Real-space units represented by each unit of the {@link Scene}'s World-space coordinate system. - * - * For example, if {@link Metrics#units} is ````"meters"````, and there are ten meters per World-space coordinate system unit, then ````scale```` would have a value of ````10.0````. - * - * @emits ````"scale"```` event on change, with the value of this property. - * @type {Number} - */ - set scale(value) { - value = value || 1; - if (value <= 0) { - this.error("scale value should be larger than zero"); - return; - } - this._scale = value; - this.fire("scale", this._scale); - } - - /** - * Gets the number of Real-space units represented by each unit of the {@link Scene}'s World-space coordinate system. - * - * @type {Number} - */ - get scale() { - return this._scale; - } - - /** - * Sets the Real-space 3D origin, in Real-space units, at which this {@link Scene}'s World-space coordinate origin ````[0,0,0]```` sits. - * - * @emits "origin" event on change, with the value of this property. - * @type {Number[]} - */ - set origin(value) { - if (!value) { - this._origin[0] = 0; - this._origin[1] = 0; - this._origin[2] = 0; - return; - } - this._origin[0] = value[0]; - this._origin[1] = value[1]; - this._origin[2] = value[2]; - this.fire("origin", this._origin); - } - - /** - * Gets the 3D Real-space origin, in Real-space units, at which this {@link Scene}'s World-space coordinate origin ````[0,0,0]```` sits. - * - * @type {Number[]} - */ - get origin() { - return this._origin; - } - - /** - * Converts a 3D position from World-space to Real-space. - * - * This is equivalent to ````realPos = #origin + (worldPos * #scale)````. - * - * @param {Number[]} worldPos World-space 3D position, in World coordinate system units. - * @param {Number[]} [realPos] Destination for Real-space 3D position. - * @returns {Number[]} Real-space 3D position, in units indicated by {@link Metrics#units}. - */ - worldToRealPos(worldPos, realPos = math.vec3(3)) { - realPos[0] = this._origin[0] + (this._scale * worldPos[0]); - realPos[1] = this._origin[1] + (this._scale * worldPos[1]); - realPos[2] = this._origin[2] + (this._scale * worldPos[2]); - } - - /** - * Converts a 3D position from Real-space to World-space. - * - * This is equivalent to ````worldPos = (worldPos - #origin) / #scale````. - * - * @param {Number[]} realPos Real-space 3D position. - * @param {Number[]} [worldPos] Destination for World-space 3D position. - * @returns {Number[]} World-space 3D position. - */ - realToWorldPos(realPos, worldPos = math.vec3(3)) { - worldPos[0] = (realPos[0] - this._origin[0]) / this._scale; - worldPos[1] = (realPos[1] - this._origin[1]) / this._scale; - worldPos[2] = (realPos[2] - this._origin[2]) / this._scale; - return worldPos; - } -} - -/** - * @desc Configures Scalable Ambient Obscurance (SAO) for a {@link Scene}. - * - * - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/viewer/#sao_ConferenceCenter)] - * - * ## Overview - * - * SAO approximates [Ambient Occlusion](https://en.wikipedia.org/wiki/Ambient_occlusion) in realtime. It darkens creases, cavities and surfaces - * that are close to each other, which tend to be occluded from ambient light and appear darker. - * - * The animated GIF above shows the effect as we repeatedly enable and disable SAO. When SAO is enabled, we can see darkening - * in regions such as the corners, and the crevices between stairs. This increases the amount of detail we can see when ambient - * light is high, or when objects have uniform colors across their surfaces. Run the example to experiment with the various - * SAO configurations. - * - * xeokit's implementation of SAO is based on the paper [Scalable Ambient Obscurance](https://research.nvidia.com/sites/default/files/pubs/2012-06_Scalable-Ambient-Obscurance/McGuire12SAO.pdf). - * - * ## Caveats - * - * Currently, SAO only works with perspective and orthographic projections. Therefore, to use SAO, make sure {@link Camera#projection} is - * either "perspective" or "ortho". - * - * {@link SAO#scale} and {@link SAO#intensity} must be tuned to the distance - * between {@link Perspective#near} and {@link Perspective#far}, or the distance - * between {@link Ortho#near} and {@link Ortho#far}, depending on which of those two projections the {@link Camera} is currently - * using. Use the [live example](https://xeokit.github.io/xeokit-sdk/examples/viewer/#sao_ConferenceCenter) to get a - * feel for that. - * - * ## Usage - * - * In the example below, we'll start by logging a warning message to the console if SAO is not supported by the - * system. - * - *Then we'll enable and configure SAO, position the camera, and configure the near and far perspective and orthographic - * clipping planes. Finally, we'll use {@link XKTLoaderPlugin} to load the OTC Conference Center model. - * - * ````javascript - * import {Viewer, XKTLoaderPlugin} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * const sao = viewer.scene.sao; - * - * if (!sao.supported) { - * sao.warn("SAO is not supported on this system - ignoring SAO configs") - * } - * - * sao.enabled = true; // Enable SAO - only works if supported (see above) - * sao.intensity = 0.15; - * sao.bias = 0.5; - * sao.scale = 1.0; - * sao.minResolution = 0.0; - * sao.numSamples = 10; - * sao.kernelRadius = 100; - * sao.blendCutoff = 0.1; - * - * const camera = viewer.scene.camera; - * - * camera.eye = [3.69, 5.83, -23.98]; - * camera.look = [84.31, -29.88, -116.21]; - * camera.up = [0.18, 0.96, -0.21]; - * - * camera.perspective.near = 0.1; - * camera.perspective.far = 2000.0; - * - * camera.ortho.near = 0.1; - * camera.ortho.far = 2000.0; - * camera.projection = "perspective"; - * - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * const model = xktLoader.load({ - * id: "myModel", - * src: "./models/xkt/OTCConferenceCenter.xkt" - * edges: true - * }); - * ```` - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/viewer/#sao_ConferenceCenter)] - * - * ## Efficiency - * - * SAO can incur some rendering overhead, especially on objects that are viewed close to the camera. For this reason, - * it's recommended to use a low value for {@link SAO#kernelRadius}. A low radius will sample pixels that are close - * to the source pixel, which will allow the GPU to efficiently cache those pixels. When {@link Camera#projection} is "perspective", - * objects near to the viewpoint will use larger radii than farther pixels. Therefore, computing SAO for close objects - * is more expensive than for objects far away, that occupy fewer pixels on the canvas. - * - * ## Selectively enabling SAO for models - * - * When loading multiple models into a Scene, we sometimes only want SAO on the models that are actually going to - * show it, such as the architecture or structure, and not show SAO on models that won't show it well, such as the - * electrical wiring, or plumbing. - * - * To illustrate, lets load some of the models for the West Riverside Hospital. We'll enable SAO on the structure model, - * but disable it on the electrical and plumbing. - * - * This will only apply SAO to those models if {@link SAO#supported} and {@link SAO#enabled} are both true. - * - * Note, by the way, how we load the models in sequence. Since XKTLoaderPlugin uses scratch memory as part of its loading - * process, this allows the plugin to reuse that same memory across multiple loads, instead of having to create multiple - * pools of scratch memory. - * - * ````javascript - * const structure = xktLoader.load({ - * id: "structure", - * src: "./models/xkt/WestRiverSideHospital/structure.xkt" - * edges: true, - * saoEnabled: true - * }); - * - * structure.on("loaded", () => { - * - * const electrical = xktLoader.load({ - * id: "electrical", - * src: "./models/xkt/WestRiverSideHospital/electrical.xkt", - * edges: true - * }); - * - * electrical.on("loaded", () => { - * - * const plumbing = xktLoader.load({ - * id: "plumbing", - * src: "./models/xkt/WestRiverSideHospital/plumbing.xkt", - * edges: true - * }); - * }); - * }); - * ```` - * - * ## Disabling SAO while camera is moving - * - * For smoother interaction with large models on low-power hardware, we can disable SAO while the {@link Camera} is moving: - * - * ````javascript - * const timeoutDuration = 150; // Milliseconds - * var timer = timeoutDuration; - * var saoDisabled = false; - * - * const onCameraMatrix = scene.camera.on("matrix", () => { - * timer = timeoutDuration; - * if (!saoDisabled) { - * scene.sao.enabled = false; - * saoDisabled = true; - * } - * }); - * - * const onSceneTick = scene.on("tick", (tickEvent) => { - * if (!saoDisabled) { - * return; - * } - * timer -= tickEvent.deltaTime; // Milliseconds - * if (timer <= 0) { - * if (saoDisabled) { - * scene.sao.enabled = true; - * saoDisabled = false; - * } - * } - * }); - * ```` - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/index.html#techniques_nonInteractiveQuality)] - */ -class SAO extends Component { - - /** @private */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._supported = WEBGL_INFO.SUPPORTED_EXTENSIONS["OES_standard_derivatives"]; // For computing normals in SAO fragment shader - - this.enabled = cfg.enabled; - this.kernelRadius = cfg.kernelRadius; - this.intensity = cfg.intensity; - this.bias = cfg.bias; - this.scale = cfg.scale; - this.minResolution = cfg.minResolution; - this.numSamples = cfg.numSamples; - this.blur = cfg.blur; - this.blendCutoff = cfg.blendCutoff; - this.blendFactor = cfg.blendFactor; - } - - /** - * Gets whether or not SAO is supported by this browser and GPU. - * - * Even when enabled, SAO will only work if supported. - * - * @type {Boolean} - */ - get supported() { - return this._supported; - } - - /** - * Sets whether SAO is enabled for the {@link Scene}. - * - * Even when enabled, SAO will only work if supported. - * - * Default value is ````false````. - * - * @type {Boolean} - */ - set enabled(value) { - value = !!value; - if (this._enabled === value) { - return; - } - this._enabled = value; - this.glRedraw(); - } - - /** - * Gets whether SAO is enabled for the {@link Scene}. - * - * Even when enabled, SAO will only apply if supported. - * - * Default value is ````false````. - * - * @type {Boolean} - */ - get enabled() { - return this._enabled; - } - - /** - * Returns true if SAO is currently possible, where it is supported, enabled, and the current scene state is compatible. - * Called internally by renderer logic. - * @private - * @returns {Boolean} - */ - get possible() { - if (!this._supported) { - return false; - } - if (!this._enabled) { - return false; - } - const projection = this.scene.camera.projection; - if (projection === "customProjection") { - return false; - } - if (projection === "frustum") { - return false; - } - return true; - } - - /** - * @private - * @returns {boolean|*} - */ - get active() { - return this._active; - } - - /** - * Sets the maximum area that SAO takes into account when checking for possible occlusion for each fragment. - * - * Default value is ````100.0````. - * - * @type {Number} - */ - set kernelRadius(value) { - if (value === undefined || value === null) { - value = 100.0; - } - if (this._kernelRadius === value) { - return; - } - this._kernelRadius = value; - this.glRedraw(); - } - - /** - * Gets the maximum area that SAO takes into account when checking for possible occlusion for each fragment. - * - * Default value is ````100.0````. - * - * @type {Number} - */ - get kernelRadius() { - return this._kernelRadius; - } - - /** - * Sets the degree of darkening (ambient obscurance) produced by the SAO effect. - * - * Default value is ````0.15````. - * - * @type {Number} - */ - set intensity(value) { - if (value === undefined || value === null) { - value = 0.15; - } - if (this._intensity === value) { - return; - } - this._intensity = value; - this.glRedraw(); - } - - /** - * Gets the degree of darkening (ambient obscurance) produced by the SAO effect. - * - * Default value is ````0.15````. - * - * @type {Number} - */ - get intensity() { - return this._intensity; - } - - /** - * Sets the SAO bias. - * - * Default value is ````0.5````. - * - * @type {Number} - */ - set bias(value) { - if (value === undefined || value === null) { - value = 0.5; - } - if (this._bias === value) { - return; - } - this._bias = value; - this.glRedraw(); - } - - /** - * Gets the SAO bias. - * - * Default value is ````0.5````. - * - * @type {Number} - */ - get bias() { - return this._bias; - } - - /** - * Sets the SAO occlusion scale. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - set scale(value) { - if (value === undefined || value === null) { - value = 1.0; - } - if (this._scale === value) { - return; - } - this._scale = value; - this.glRedraw(); - } - - /** - * Gets the SAO occlusion scale. - * - * Default value is ````1.0````. - * - * @type {Number} - */ - get scale() { - return this._scale; - } - - /** - * Sets the SAO minimum resolution. - * - * Default value is ````0.0````. - * - * @type {Number} - */ - set minResolution(value) { - if (value === undefined || value === null) { - value = 0.0; - } - if (this._minResolution === value) { - return; - } - this._minResolution = value; - this.glRedraw(); - } - - /** - * Gets the SAO minimum resolution. - * - * Default value is ````0.0````. - * - * @type {Number} - */ - get minResolution() { - return this._minResolution; - } - - /** - * Sets the number of SAO samples. - * - * Default value is ````10````. - * - * Update this sparingly, since it causes a shader recompile. - * - * @type {Number} - */ - set numSamples(value) { - if (value === undefined || value === null) { - value = 10; - } - if (this._numSamples === value) { - return; - } - this._numSamples = value; - this.glRedraw(); - } - - /** - * Gets the number of SAO samples. - * - * Default value is ````10````. - * - * @type {Number} - */ - get numSamples() { - return this._numSamples; - } - - /** - * Sets whether Guassian blur is enabled. - * - * Default value is ````true````. - * - * @type {Boolean} - */ - set blur(value) { - value = (value !== false); - if (this._blur === value) { - return; - } - this._blur = value; - this.glRedraw(); - } - - /** - * Gets whether Guassian blur is enabled. - * - * Default value is ````true````. - * - * @type {Boolean} - */ - get blur() { - return this._blur; - } - - /** - * Sets the SAO blend cutoff. - * - * Default value is ````0.3````. - * - * Normally you don't need to alter this. - * - * @type {Number} - */ - set blendCutoff(value) { - if (value === undefined || value === null) { - value = 0.3; - } - if (this._blendCutoff === value) { - return; - } - this._blendCutoff = value; - this.glRedraw(); - } - - /** - * Gets the SAO blend cutoff. - * - * Default value is ````0.3````. - * - * Normally you don't need to alter this. - * - * @type {Number} - */ - get blendCutoff() { - return this._blendCutoff; - } - - /** - * Sets the SAO blend factor. - * - * Default value is ````1.0````. - * - * Normally you don't need to alter this. - * - * @type {Number} - */ - set blendFactor(value) { - if (value === undefined || value === null) { - value = 1.0; - } - if (this._blendFactor === value) { - return; - } - this._blendFactor = value; - this.glRedraw(); - } - - /** - * Gets the SAO blend scale. - * - * Default value is ````1.0````. - * - * Normally you don't need to alter this. - * - * @type {Number} - */ - get blendFactor() { - return this._blendFactor; - } - - /** - * Destroys this component. - */ - destroy() { - super.destroy(); - } -} - -/** - * @desc Configures cross-section slices for a {@link Scene}. - * - * ## Overview - * - * Cross-sections allow to create an additional colored slice for used clipping planes. It is only a visual effect - * calculated by shaders. It makes it easier to see the intersection between the model and the clipping plane this way. - * - * ## Usage - * - * In the example below, we'll configure CrossSections to manipulate the slice representation. - * - * ````javascript - * //------------------------------------------------------------------------------------------------------------------ - * // Import the modules we need for this example - * //------------------------------------------------------------------------------------------------------------------ - * - * import {PhongMaterial, Viewer, math, SectionPlanesPlugin, XKTLoaderPlugin, Mesh, ReadableGeometry, buildPolylineGeometryFromCurve, SplineCurve} from "../../dist/xeokit-sdk.es.js"; - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a Viewer and arrange the camera - * //------------------------------------------------------------------------------------------------------------------ - * - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.camera.eye = [-2.341298674548419, 22.43987089731119, 7.236688436028655]; - * viewer.camera.look = [4.399999999999963, 3.7240000000000606, 8.899000000000006]; - * viewer.camera.up = [0.9102954845584759, 0.34781746407929504, 0.22446635042673466]; - * - * const cameraControl = viewer.cameraControl; - * cameraControl.navMode = "orbit"; - * cameraControl.followPointer = true; - * - * //---------------------------------------------------------------------------------------------------------------------- - * // Create a xeokit loader plugin, load a model, fit to view - * //---------------------------------------------------------------------------------------------------------------------- - * - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * var t0 = performance.now(); - * - * document.getElementById("time").innerHTML = "Loading model..."; - * - * const sceneModel = xktLoader.load({ - * id: "myModel", - * src: "../../assets/models/xkt/v10/glTF-Embedded/Duplex_A_20110505.glTFEmbedded.xkt", - * edges: true - * }); - * - * sceneModel.on("loaded", () => { - * var t1 = performance.now(); - * document.getElementById("time").innerHTML = "Model loaded in " + Math.floor(t1 - t0) / 1000.0 + " seconds
Objects: " + sceneModel.numEntities; - * - * let path = new SplineCurve(viewer.scene, { - * points: [ - * [0, 0, -10], - * [0, 0, -3], - * [10, 0, 10], - * [10, 0, 30], - * ], - * }); - * - * new Mesh(viewer.scene, { - * geometry: new ReadableGeometry(viewer.scene, buildPolylineGeometryFromCurve({ - * id: "SplineCurve", - * curve: path, - * divisions: 50, - * })), - * material: new PhongMaterial(viewer.scene, { - * emissive: [1, 0, 0] - * }) - * }); - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a moving SectionPlane, that moves through the table models - * //------------------------------------------------------------------------------------------------------------------ - * - * const sectionPlanes = new SectionPlanesPlugin(viewer, { - * overviewCanvasId: "mySectionPlanesOverviewCanvas", - * overviewVisible: true - * }); - * - * let currentPoint = path.getPoint(0); - * let currentDirection = path.getTangent(0); - * - * const sectionPlane = sectionPlanes.createSectionPlane({ - * id: "mySectionPlane", - * pos: currentPoint, - * dir: currentDirection - * }); - * - * sectionPlanes.showControl(sectionPlane.id); - * - * //------------------------------------------------------------------------------------------------------------------ - * // Controlling SectionPlane position and direction - * //------------------------------------------------------------------------------------------------------------------ - * - * let currentT = 0.0; - * document.getElementById("section_path").oninput = function() { - * currentT = Number(document.getElementById("section_path").value); - * currentPoint = path.getPoint(currentT); - * currentDirection = path.getTangent(currentT); - * sectionPlane.pos = currentPoint; - * sectionPlane.dir = currentDirection; - * }; - * - * window.viewer = viewer; - * - * //------------------------------------------------------------------------------------------------------------------ - * // Controlling CrossSections settings - * //------------------------------------------------------------------------------------------------------------------ - * - * viewer.scene.crossSections.sliceThickness = 0.05; - * viewer.scene.crossSections.sliceColor = [0.0, 0.0, 0.0, 1.0]; - * }); - * ```` - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/slicing/#SectionPlanesPlugin_Duplex_SectionPath_CrossSections)] - * - */ -class CrossSections extends Component { - - /** @private */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this.sliceColor = cfg.sliceColor; - this.sliceThickness = cfg.sliceThickness; - } - - /** - * Sets the thickness of a slice created by a section. - * - * Default value is ````0.0````. - * - * @type {Number} - */ - set sliceThickness(value) { - if (value === undefined || value === null) { - value = 0.0; - } - if (this._sliceThickness === value) { - return; - } - this._sliceThickness = value; - this.glRedraw(); - } - - /** - * Gets the thickness of a slice created by a section. - * - * Default value is ````0.0````. - * - * @type {Number} - */ - get sliceThickness() { - return this._sliceThickness; - } - - /** - * Sets the color of a slice created by a section. - * - * Default value is ````[0.0, 0.0, 0.0, 1.0]````. - * - * @type {Number} - */ - set sliceColor(value) { - if (value === undefined || value === null) { - value = [0.0, 0.0, 0.0, 1.0]; - } - if (this._sliceColor === value) { - return; - } - this._sliceColor = value; - this.glRedraw(); - } - - /** - * Gets the color of a slice created by a section. - * - * Default value is ````[0.0, 0.0, 0.0, 1.0]````. - * - * @type {Number} - */ - get sliceColor() { - return this._sliceColor; - } - - /** - * Destroys this component. - */ - destroy() { - super.destroy(); - } -} - -const PRESETS$1 = { - "default": { - pointSize: 4, - roundPoints: true, - perspectivePoints: true - }, - "square": { - pointSize: 4, - roundPoints: false, - perspectivePoints: true - }, - "round": { - pointSize: 4, - roundPoints: true, - perspectivePoints: true - } -}; - -/** - * @desc Configures the size and shape of "points" geometry primitives. - * - * * Located at {@link Scene#pointsMaterial}. - * * Supports round and square points. - * * Optional perspective point scaling. - * * Globally configures "points" primitives for all {@link VBOSceneModel}s. - * - * ## Usage - * - * In the example below, we'll customize the {@link Scene}'s global ````PointsMaterial````, then use - * an {@link XKTLoaderPlugin} to load a model containing a point cloud. - * - * [[Run this example](/examples/index.html#materials_PointsMaterial)] - * - * ````javascript - * import {Viewer, XKTLoaderPlugin} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.scene.camera.eye = [0, 0, 5]; - * viewer.scene.camera.look = [0, 0, 0]; - * viewer.scene.camera.up = [0, 1, 0]; - * - * viewer.scene.pointsMaterial.pointSize = 2; - * viewer.scene.pointsMaterial.roundPoints = true; - * viewer.scene.pointsMaterial.perspectivePoints = true; - * viewer.scene.pointsMaterial.minPerspectivePointSize = 1; - * viewer.scene.pointsMaterial.maxPerspectivePointSize = 6; - * viewer.scene.pointsMaterial.filterIntensity = true; - * viewer.scene.pointsMaterial.minIntensity = 0.0; - * viewer.scene.pointsMaterial.maxIntensity = 1.0; - * - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * const model = xktLoader.load({ - * id: "myModel", - * src: "../assets/models/xkt/MAP-PointCloud.xkt" - * }); - * ```` - */ -class PointsMaterial extends Material { - - /** - @private - */ - get type() { - return "PointsMaterial"; - } - - /** - * Gets available PointsMaterial presets. - * - * @type {Object} - */ - get presets() { - return PRESETS$1; - }; - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - * @param {*} [cfg] The PointsMaterial configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number} [cfg.pointSize=2] Point size in pixels. - * @param {Boolean} [cfg.roundPoints=true] Whether points are round (````true````) or square (````false````). - * @param {Boolean} [cfg.perspectivePoints=true] Whether apparent point size reduces with distance when {@link Camera#projection} is set to "perspective". - * @param {Number} [cfg.minPerspectivePointSize=1] When ````perspectivePoints```` is ````true````, this is the minimum rendered size of each point in pixels. - * @param {Number} [cfg.maxPerspectivePointSize=6] When ````perspectivePoints```` is ````true````, this is the maximum rendered size of each point in pixels. - * @param {Boolean} [cfg.filterIntensity=false] When this is true, points are only rendered when their intensity value falls within the range given in {@link } - * @param {Number} [cfg.minIntensity=0] When ````filterIntensity```` is ````true````, points with intensity below this value will not be rendered. - * @param {Number} [cfg.maxIntensity=1] When ````filterIntensity```` is ````true````, points with intensity above this value will not be rendered. - * @param {String} [cfg.preset] Selects a preset PointsMaterial configuration - see {@link PointsMaterial#presets}. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._state = new RenderState({ - type: "PointsMaterial", - pointSize: null, - roundPoints: null, - perspectivePoints: null, - minPerspectivePointSize: null, - maxPerspectivePointSize: null, - filterIntensity: null, - minIntensity: null, - maxIntensity: null - }); - - if (cfg.preset) { // Apply preset then override with configs where provided - this.preset = cfg.preset; - if (cfg.pointSize !== undefined) { - this.pointSize = cfg.pointSize; - } - if (cfg.roundPoints !== undefined) { - this.roundPoints = cfg.roundPoints; - } - if (cfg.perspectivePoints !== undefined) { - this.perspectivePoints = cfg.perspectivePoints; - } - if (cfg.minPerspectivePointSize !== undefined) { - this.minPerspectivePointSize = cfg.minPerspectivePointSize; - } - if (cfg.maxPerspectivePointSize !== undefined) { - this.maxPerspectivePointSize = cfg.minPerspectivePointSize; - } - } else { - this._preset = "default"; - this.pointSize = cfg.pointSize; - this.roundPoints = cfg.roundPoints; - - this.perspectivePoints = cfg.perspectivePoints; - this.minPerspectivePointSize = cfg.minPerspectivePointSize; - this.maxPerspectivePointSize = cfg.maxPerspectivePointSize; - } - - this.filterIntensity = cfg.filterIntensity; - this.minIntensity = cfg.minIntensity; - this.maxIntensity = cfg.maxIntensity; - } - - /** - * Sets point size. - * - * Default value is ````2.0```` pixels. - * - * @type {Number} - */ - set pointSize(value) { - this._state.pointSize = value || 2.0; - this.glRedraw(); - } - - /** - * Gets point size. - * - * Default value is ````2.0```` pixels. - * - * @type {Number} - */ - get pointSize() { - return this._state.pointSize; - } - - - /** - * Sets if points are round or square. - * - * Default is ````true```` to set points round. - * - * @type {Boolean} - */ - set roundPoints(value) { - value = (value !== false); - if (this._state.roundPoints === value) { - return; - } - this._state.roundPoints = value; - this.scene._needRecompile = true; - this.glRedraw(); - } - - /** - * Gets if points are round or square. - * - * Default is ````true```` to set points round. - * - * @type {Boolean} - */ - get roundPoints() { - return this._state.roundPoints; - } - - /** - * Sets if rendered point size reduces with distance when {@link Camera#projection} is set to ````"perspective"````. - * - * Default is ````true````. - * - * @type {Boolean} - */ - set perspectivePoints(value) { - value = (value !== false); - if (this._state.perspectivePoints === value) { - return; - } - this._state.perspectivePoints = value; - this.scene._needRecompile = true; - this.glRedraw(); - } - - /** - * Gets if rendered point size reduces with distance when {@link Camera#projection} is set to "perspective". - * - * Default is ````false````. - * - * @type {Boolean} - */ - get perspectivePoints() { - return this._state.perspectivePoints; - } - - /** - * Sets the minimum rendered size of points when {@link PointsMaterial#perspectivePoints} is ````true````. - * - * Default value is ````1.0```` pixels. - * - * @type {Number} - */ - set minPerspectivePointSize(value) { - this._state.minPerspectivePointSize = value || 1.0; - this.scene._needRecompile = true; - this.glRedraw(); - } - - /** - * Gets the minimum rendered size of points when {@link PointsMaterial#perspectivePoints} is ````true````. - * - * Default value is ````1.0```` pixels. - * - * @type {Number} - */ - get minPerspectivePointSize() { - return this._state.minPerspectivePointSize; - } - - /** - * Sets the maximum rendered size of points when {@link PointsMaterial#perspectivePoints} is ````true````. - * - * Default value is ````6```` pixels. - * - * @type {Number} - */ - set maxPerspectivePointSize(value) { - this._state.maxPerspectivePointSize = value || 6; - this.scene._needRecompile = true; - this.glRedraw(); - } - - /** - * Gets the maximum rendered size of points when {@link PointsMaterial#perspectivePoints} is ````true````. - * - * Default value is ````6```` pixels. - * - * @type {Number} - */ - get maxPerspectivePointSize() { - return this._state.maxPerspectivePointSize; - } - - /** - * Sets if rendered point size reduces with distance when {@link Camera#projection} is set to ````"perspective"````. - * - * Default is ````false````. - * - * @type {Boolean} - */ - set filterIntensity(value) { - value = (value !== false); - if (this._state.filterIntensity === value) { - return; - } - this._state.filterIntensity = value; - this.scene._needRecompile = true; - this.glRedraw(); - } - - /** - * Gets if rendered point size reduces with distance when {@link Camera#projection} is set to "perspective". - * - * Default is ````false````. - * - * @type {Boolean} - */ - get filterIntensity() { - return this._state.filterIntensity; - } - - /** - * Sets the minimum rendered size of points when {@link PointsMaterial#perspectivePoints} is ````true````. - * - * Default value is ````0````. - * - * @type {Number} - */ - set minIntensity(value) { - this._state.minIntensity = (value !== undefined && value !== null) ? value: 0.0; - this.glRedraw(); - } - - /** - * Gets the minimum rendered size of points when {@link PointsMaterial#filterIntensity} is ````true````. - * - * Default value is ````0````. - * - * @type {Number} - */ - get minIntensity() { - return this._state.minIntensity; - } - - /** - * Sets the maximum rendered size of points when {@link PointsMaterial#filterIntensity} is ````true````. - * - * Default value is ````1````. - * - * @type {Number} - */ - set maxIntensity(value) { - this._state.maxIntensity = (value !== undefined && value !== null) ? value: 1.0; - this.glRedraw(); - } - - /** - * Gets the maximum rendered size of points when {@link PointsMaterial#filterIntensity} is ````true````. - * - * Default value is ````1````. - * - * @type {Number} - */ - get maxIntensity() { - return this._state.maxIntensity; - } - - /** - * Selects a preset ````PointsMaterial```` configuration. - * - * Default value is ````"default"````. - * - * @type {String} - */ - set preset(value) { - value = value || "default"; - if (this._preset === value) { - return; - } - const preset = PRESETS$1[value]; - if (!preset) { - this.error("unsupported preset: '" + value + "' - supported values are " + Object.keys(PRESETS$1).join(", ")); - return; - } - this.pointSize = preset.pointSize; - this.roundPoints = preset.roundPoints; - this.perspectivePoints = preset.perspectivePoints; - this.minPerspectivePointSize = preset.minPerspectivePointSize; - this.maxPerspectivePointSize = preset.maxPerspectivePointSize; - this._preset = value; - } - - /** - * The current preset ````PointsMaterial```` configuration. - * - * Default value is ````"default"````. - * - * @type {String} - */ - get preset() { - return this._preset; - } - - /** - * @private - * @return {string} - */ - get hash() { - return [ - this.pointSize, - this.roundPoints, - this.perspectivePoints, - this.minPerspectivePointSize, - this.maxPerspectivePointSize, - this.filterIntensity - ].join((";")); - } - - /** - * Destroys this ````PointsMaterial````. - */ - destroy() { - super.destroy(); - this._state.destroy(); - } -} - -const PRESETS = { - "default": { - lineWidth: 1 - }, - "thick": { - lineWidth: 2 - }, - "thicker": { - lineWidth: 4 - } -}; - -/** - * @desc Configures the shape of "lines" geometry primitives. - * - * * Located at {@link Scene#linesMaterial}. - * * Globally configures "lines" primitives for all {@link VBOSceneModel}s. - * - * ## Usage - * - * In the example below, we'll customize the {@link Scene}'s global ````LinesMaterial````, then use - * an {@link XKTLoaderPlugin} to load a model containing line segments. - * - * [[Run this example](/examples/index.html#materials_LinesMaterial)] - * - * ````javascript - * import {Viewer, XKTLoaderPlugin} from "xeokit-sdk.es.js"; - * - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true - * }); - * - * viewer.scene.camera.eye = [0, 0, 5]; - * viewer.scene.camera.look = [0, 0, 0]; - * viewer.scene.camera.up = [0, 1, 0]; - * - * viewer.scene.linesMaterial.lineWidth = 3; - * - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * const model = xktLoader.load({ - * id: "myModel", - * src: "./models/xkt/Duplex.ifc.xkt" - * }); - * ```` - */ -class LinesMaterial extends Material { - - /** - @private - */ - get type() { - return "LinesMaterial"; - } - - /** - * Gets available LinesMaterial presets. - * - * @type {Object} - */ - get presets() { - return PRESETS; - }; - - /** - * @constructor - * @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well. - * @param {*} [cfg] The LinesMaterial configuration - * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted. - * @param {Number} [cfg.lineWidth=1] Line width in pixels. - * @param {String} [cfg.preset] Selects a preset LinesMaterial configuration - see {@link LinesMaterial#presets}. - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - this._state = new RenderState({ - type: "LinesMaterial", - lineWidth: null - }); - - if (cfg.preset) { // Apply preset then override with configs where provided - this.preset = cfg.preset; - if (cfg.lineWidth !== undefined) { - this.lineWidth = cfg.lineWidth; - } - } else { - this._preset = "default"; - this.lineWidth = cfg.lineWidth; - } - } - - /** - * Sets line width. - * - * Default value is ````1```` pixels. - * - * @type {Number} - */ - set lineWidth(value) { - this._state.lineWidth = value || 1; - this.glRedraw(); - } - - /** - * Gets the line width. - * - * Default value is ````1```` pixels. - * - * @type {Number} - */ - get lineWidth() { - return this._state.lineWidth; - } - - /** - * Selects a preset LinesMaterial configuration. - * - * Default value is ````"default"````. - * - * @type {String} - */ - set preset(value) { - value = value || "default"; - if (this._preset === value) { - return; - } - const preset = PRESETS[value]; - if (!preset) { - this.error("unsupported preset: '" + value + "' - supported values are " + Object.keys(PRESETS).join(", ")); - return; - } - this.lineWidth = preset.lineWidth; - this._preset = value; - } - - /** - * The current preset LinesMaterial configuration. - * - * Default value is ````"default"````. - * - * @type {String} - */ - get preset() { - return this._preset; - } - - /** - * @private - * @return {string} - */ - get hash() { - return ["" + this.lineWidth].join((";")); - } - - /** - * Destroys this LinesMaterial. - */ - destroy() { - super.destroy(); - this._state.destroy(); - } -} - -const tempVec3a$a = math.vec3(); - -/** - * @desc Implements hatching for Solid objects on a {@link Scene}. - * - * [[Run this example](https://xeokit.github.io/xeokit-sdk/examples/slicing/SectionPlanesPlugin_Duplex_SectionCaps.html)] - * - * ##Overview - * - * The WebGL implementation for capping sliced 3D objects works by first calculating intersection segments where a cutting - * plane meets the object's edges. These segments form a contour that is triangulated using the Earcut algorithm, which - * handles any internal holes efficiently. The resulting triangulated cap is then integrated into the original mesh with - * appropriate normals and UVs. - * - * ##Usage - * - * In the example, we'll start by enabling readable geometry on the viewer. - * - * Then we'll position the camera, and configure the near and far perspective and orthographic - * clipping planes. Finally, we'll use {@link XKTLoaderPlugin} to load the Duplex model. - * - * ````javascript - * const viewer = new Viewer({ - * canvasId: "myCanvas", - * transparent: true, - * readableGeometryEnabled: true - * }); - * - * viewer.camera.eye = [-2.341298674548419, 22.43987089731119, 7.236688436028655]; - * viewer.camera.look = [4.399999999999963, 3.7240000000000606, 8.899000000000006]; - * viewer.camera.up = [0.9102954845584759, 0.34781746407929504, 0.22446635042673466]; - * - * const cameraControl = viewer.cameraControl; - * cameraControl.navMode = "orbit"; - * cameraControl.followPointer = true; - * - * const xktLoader = new XKTLoaderPlugin(viewer); - * - * var t0 = performance.now(); - * - * document.getElementById("time").innerHTML = "Loading model..."; - * - * const sceneModel = xktLoader.load({ - * id: "myModel", - * src: "../../assets/models/xkt/v10/glTF-Embedded/Duplex_A_20110505.glTFEmbedded.xkt", - * edges: true - * }); - * - * sceneModel.on("loaded", () => { - * - * var t1 = performance.now(); - * document.getElementById("time").innerHTML = "Model loaded in " + Math.floor(t1 - t0) / 1000.0 + " seconds
Objects: " + sceneModel.numEntities; - * - * //------------------------------------------------------------------------------------------------------------------ - * // Add caps materials to all objects inside the loaded model that have an opacity equal to or above 0.7 - * //------------------------------------------------------------------------------------------------------------------ - * const opacityThreshold = 0.7; - * const material = new PhongMaterial(viewer.scene,{ - * diffuse: [1.0, 0.0, 0.0], - * backfaces: true - * }); - * addCapsMaterialsToAllObjects(sceneModel, opacityThreshold, material); - * - * //------------------------------------------------------------------------------------------------------------------ - * // Create a moving SectionPlane, that moves through the table models - * //------------------------------------------------------------------------------------------------------------------ - * - * const sectionPlanes = new SectionPlanesPlugin(viewer, { - * overviewCanvasId: "mySectionPlanesOverviewCanvas", - * overviewVisible: true, - * }); - * - * const sectionPlane = sectionPlanes.createSectionPlane({ - * id: "mySectionPlane", - * pos: [0.5, 2.5, 5.0], - * dir: math.normalizeVec3([1.0, 0.01, 1]) - * }); - * - * sectionPlanes.showControl(sectionPlane.id); - * - * window.viewer = viewer; - * - * }); - * - * function addCapsMaterialsToAllObjects(sceneModel, opacityThreshold, material) { - * const allObjects = sceneModel.objects; - * for(const key in allObjects){ - * const object = allObjects[key]; - * if(object.opacity >= opacityThreshold) - * object.capMaterial = material; - * } - * } - * ```` - */ - -class SectionCaps { - /** - * @constructor - */ - constructor(scene) { - let destroy = null; - const modelCaches = { }; - const sectionPlanes = [ ]; - - this.destroy = () => destroy && destroy(); - - let updateTimeout = null; - - const update = () => { - clearTimeout(updateTimeout); - updateTimeout = setTimeout(() => { - const visibleSceneModels = Object.values(scene.models).filter(sceneModel => (sceneModel.id in modelCaches) && sceneModel.visible); - sectionPlanes.forEach((plane) => { - if (plane.active) { - const sliceMesh = math.makeSectionPlaneSlicer(plane); - visibleSceneModels.forEach(sceneModel => { - const modelAABB = sceneModel.aabb; - if (math.planeIntersectsAABB3(plane, modelAABB)) { - // modelCenter is critical to use when handling models with large coordinates. - // See XCD-306 and examples/slicing/SectionCaps_at_distance.html for more details. - const modelCenter = math.getAABB3Center(modelAABB, math.vec3()); - - modelCaches[sceneModel.id].entityCaches.forEach((entityCache, entityId) => { - const entity = sceneModel.objects[entityId]; - if (entityCache.generateCaps && entity.capMaterial && math.planeIntersectsAABB3(plane, entity.aabb)) { - entityCache.meshCaches ||= entity.meshes.filter(mesh => mesh.isSolid()).map(mesh => { - const meshIndices = [ ]; - const meshVertices = [ ]; - mesh.getEachIndex(i => meshIndices.push(i)); - mesh.getEachVertex(v => meshVertices.push(...math.subVec3(v, modelCenter, tempVec3a$a))); - return { mesh: mesh, meshIndices: meshIndices, meshVertices: meshVertices }; - }); - - entityCache.meshCaches.filter(meshCache => math.planeIntersectsAABB3(plane, meshCache.mesh.aabb)).forEach((meshCache, meshIdx) => { - const geo = sliceMesh({ origin: modelCenter, indices: meshCache.meshIndices, positions: meshCache.meshVertices }, { onlyPosSliceWithUV: true }).pos; - if (geo) { - entityCache.capMeshes.push(new Mesh(scene, { - isObject: true, - id: `${plane.id}-${entityId}-${meshIdx}`, - material: entity.capMaterial, - origin: math.addVec3(modelCenter, math.mulVec3Scalar(plane.dir, 0.001, tempVec3a$a), tempVec3a$a), - geometry: new ReadableGeometry(scene, { - primitive: "triangles", - indices: geo.indices, - positions: geo.positions, - normals: geo.normals, - uv: geo.uv - }) - })); - } - }); - } - }); - } - }); - } - }); - visibleSceneModels.forEach(sceneModel => modelCaches[sceneModel.id].entityCaches.forEach(entityCache => entityCache.generateCaps = false)); - }, 100); - }; - - this._onCapMaterialUpdated = (entity) => { - if (! destroy) { - updateTimeout = null; - - const handleSectionPlane = (sectionPlane) => { - const onSectionPlaneUpdated = () => { - Object.values(modelCaches).forEach(modelCache => modelCache.entityCaches.forEach(entityCache => { - entityCache.destroyCaps(); - entityCache.generateCaps = true; - })); - update(); - }; - sectionPlanes.push(sectionPlane); - sectionPlane.on('pos', onSectionPlaneUpdated); - sectionPlane.on('dir', onSectionPlaneUpdated); - sectionPlane.on('active', onSectionPlaneUpdated); - sectionPlane.once('destroyed', () => { - const idx = sectionPlanes.indexOf(sectionPlane); - if (idx >= 0) { - sectionPlanes.splice(idx, 1); - onSectionPlaneUpdated(); - } - }); - }; - - for (const key in scene.sectionPlanes){ - handleSectionPlane(scene.sectionPlanes[key]); - } - - const onSectionPlaneCreated = scene.on('sectionPlaneCreated', handleSectionPlane); - - const onTick = scene.on("tick", () => { - //on ticks we only check if there is a model that we have saved vertices for, - //but it's no more available on the scene, or if its visibility changed - let doUpdate = false; - for (const sceneModelId in modelCaches) { - const sceneModel = scene.models[sceneModelId]; - if (! sceneModel) { - modelCaches[sceneModelId].entityCaches.forEach(entityCache => entityCache.destroyCaps()); - delete modelCaches[sceneModelId]; - doUpdate = true; - } else if (modelCaches[sceneModelId].modelVisible != sceneModel.visible) { - const modelCache = modelCaches[sceneModelId]; - modelCache.modelVisible = !!sceneModel.visible; - modelCache.entityCaches.forEach(entityCache => { - entityCache.destroyCaps(); - entityCache.generateCaps = true; - }); - doUpdate = true; - } - } - if (doUpdate) { - update(); - } - }); - destroy = () => { - for (const sceneModelId in modelCaches) { - modelCaches[sceneModelId].entityCaches.forEach(entityCache => entityCache.destroyCaps()); - } - scene.off(onSectionPlaneCreated); - scene.off(onTick); - }; - } - - const model = entity.model; - const modelId = model.id; - modelCaches[modelId] ||= { modelVisible: model.visible, entityCaches: new Map() }; - const entityCaches = modelCaches[modelId].entityCaches; - const entityId = entity.id; - if (! entityCaches.has(entityId)) { - const entityCache = { - capMeshes: [ ], - meshCaches: null, - generateCaps: false, - destroyCaps: () => { - entityCache.capMeshes.forEach(capMesh => capMesh.destroy()); - entityCache.capMeshes.length = 0; - } - }; - entityCaches.set(entityId, entityCache); - } - const entityCache = entityCaches.get(entityId); - entityCache.destroyCaps(); - entityCache.generateCaps = true; - update(); - }; - } -} - -// Cached vars to avoid garbage collection - -function getEntityIDMap(scene, entityIds) { - const map = {}; - let entityId; - let entity; - for (let i = 0, len = entityIds.length; i < len; i++) { - entityId = entityIds[i]; - entity = scene.components[entityId]; - if (!entity) { - scene.warn("pick(): Component not found: " + entityId); - continue; - } - if (!entity.isEntity) { - scene.warn("pick(): Component is not an Entity: " + entityId); - continue; - } - map[entityId] = true; - } - return map; -} - -/** - * Fired whenever a debug message is logged on a component within this Scene. - * @event log - * @param {String} value The debug message - */ - -/** - * Fired whenever an error is logged on a component within this Scene. - * @event error - * @param {String} value The error message - */ - -/** - * Fired whenever a warning is logged on a component within this Scene. - * @event warn - * @param {String} value The warning message - */ - -/** - * @desc Contains the components that comprise a 3D scene. - * - * * A {@link Viewer} has a single Scene, which it provides in {@link Viewer#scene}. - * * Plugins like {@link AxisGizmoPlugin} also have their own private Scenes. - * * Each Scene has a corresponding {@link MetaScene}, which the Viewer provides in {@link Viewer#metaScene}. - * - * ## Getting a Viewer's Scene - * - * ````javascript - * var scene = viewer.scene; - * ```` - * - * ## Creating and accessing Scene components - * - * As a brief introduction to creating Scene components, we'll create a {@link Mesh} that has a - * {@link buildTorusGeometry} and a {@link PhongMaterial}: - * - * ````javascript - * var teapotMesh = new Mesh(scene, { - * id: "myMesh", // <<---------- ID automatically generated if not provided - * geometry: new TorusGeometry(scene), - * material: new PhongMaterial(scene, { - * id: "myMaterial", - * diffuse: [0.2, 0.2, 1.0] - * }) - * }); - * - * teapotMesh.scene.camera.eye = [45, 45, 45]; - * ```` - * - * Find components by ID in their Scene's {@link Scene#components} map: - * - * ````javascript - * var teapotMesh = scene.components["myMesh"]; - * teapotMesh.visible = false; - * - * var teapotMaterial = scene.components["myMaterial"]; - * teapotMaterial.diffuse = [1,0,0]; // Change to red - * ```` - * - * A Scene also has a map of component instances for each {@link Component} subtype: - * - * ````javascript - * var meshes = scene.types["Mesh"]; - * var teapotMesh = meshes["myMesh"]; - * teapotMesh.xrayed = true; - * - * var phongMaterials = scene.types["PhongMaterial"]; - * var teapotMaterial = phongMaterials["myMaterial"]; - * teapotMaterial.diffuse = [0,1,0]; // Change to green - * ```` - * - * See {@link Node}, {@link Node} and {@link Model} for how to create and access more sophisticated content. - * - * ## Controlling the camera - * - * Use the Scene's {@link Camera} to control the current viewpoint and projection: - * - * ````javascript - * var camera = myScene.camera; - * - * camera.eye = [-10,0,0]; - * camera.look = [-10,0,0]; - * camera.up = [0,1,0]; - * - * camera.projection = "perspective"; - * camera.perspective.fov = 45; - * //... - * ```` - * - * ## Managing the canvas - * - * The Scene's {@link Canvas} component provides various conveniences relevant to the WebGL canvas, such - * as firing resize events etc: - * - * ````javascript - * var canvas = scene.canvas; - * - * canvas.on("boundary", function(boundary) { - * //... - * }); - * ```` - * - * ## Picking - * - * Use {@link Scene#pick} to pick and raycast entites. - * - * For example, to pick a point on the surface of the closest entity at the given canvas coordinates: - * - * ````javascript - * var pickResult = scene.pick({ - * pickSurface: true, - * canvasPos: [23, 131] - * }); - * - * if (pickResult) { // Picked an entity - * - * var entity = pickResult.entity; - * - * var primitive = pickResult.primitive; // Type of primitive that was picked, usually "triangles" - * var primIndex = pickResult.primIndex; // Position of triangle's first index in the picked Mesh's Geometry's indices array - * var indices = pickResult.indices; // UInt32Array containing the triangle's vertex indices - * var localPos = pickResult.localPos; // Float64Array containing the picked Local-space position on the triangle - * var worldPos = pickResult.worldPos; // Float64Array containing the picked World-space position on the triangle - * var viewPos = pickResult.viewPos; // Float64Array containing the picked View-space position on the triangle - * var bary = pickResult.bary; // Float64Array containing the picked barycentric position within the triangle - * var normal = pickResult.normal; // Float64Array containing the interpolated normal vector at the picked position on the triangle - * var uv = pickResult.uv; // Float64Array containing the interpolated UV coordinates at the picked position on the triangle - * } - * ```` - * - * ## Pick masking - * - * We can use {@link Scene#pick}'s ````includeEntities```` and ````excludeEntities```` options to mask which {@link Mesh}es we attempt to pick. - * - * This is useful for picking through things, to pick only the Entities of interest. - * - * To pick only Entities ````"gearbox#77.0"```` and ````"gearbox#79.0"````, picking through any other Entities that are - * in the way, as if they weren't there: - * - * ````javascript - * var pickResult = scene.pick({ - * canvasPos: [23, 131], - * includeEntities: ["gearbox#77.0", "gearbox#79.0"] - * }); - * - * if (pickResult) { - * // Entity will always be either "gearbox#77.0" or "gearbox#79.0" - * var entity = pickResult.entity; - * } - * ```` - * - * To pick any pickable Entity, except for ````"gearbox#77.0"```` and ````"gearbox#79.0"````, picking through those - * Entities if they happen to be in the way: - * - * ````javascript - * var pickResult = scene.pick({ - * canvasPos: [23, 131], - * excludeEntities: ["gearbox#77.0", "gearbox#79.0"] - * }); - * - * if (pickResult) { - * // Entity will never be "gearbox#77.0" or "gearbox#79.0" - * var entity = pickResult.entity; - * } - * ```` - * - * See {@link Scene#pick} for more info on picking. - * - * ## Querying and tracking boundaries - * - * Getting a Scene's World-space axis-aligned boundary (AABB): - * - * ````javascript - * var aabb = scene.aabb; // [xmin, ymin, zmin, xmax, ymax, zmax] - * ```` - * - * Subscribing to updates to the AABB, which occur whenever {@link Entity}s are transformed, their - * {@link ReadableGeometry}s have been updated, or the {@link Camera} has moved: - * - * ````javascript - * scene.on("boundary", function() { - * var aabb = scene.aabb; - * }); - * ```` - * - * Getting the AABB of the {@link Entity}s with the given IDs: - * - * ````JavaScript - * scene.getAABB(); // Gets collective boundary of all Entities in the scene - * scene.getAABB("saw"); // Gets boundary of an Object - * scene.getAABB(["saw", "gearbox"]); // Gets collective boundary of two Objects - * ```` - * - * See {@link Scene#getAABB} and {@link Entity} for more info on querying and tracking boundaries. - * - * ## Managing the viewport - * - * The Scene's {@link Viewport} component manages the WebGL viewport: - * - * ````javascript - * var viewport = scene.viewport - * viewport.boundary = [0, 0, 500, 400];; - * ```` - * - * ## Controlling rendering - * - * You can configure a Scene to perform multiple "passes" (renders) per frame. This is useful when we want to render the - * scene to multiple viewports, such as for stereo effects. - * - * In the example, below, we'll configure the Scene to render twice on each frame, each time to different viewport. We'll do this - * with a callback that intercepts the Scene before each render and sets its {@link Viewport} to a - * different portion of the canvas. By default, the Scene will clear the canvas only before the first render, allowing the - * two views to be shown on the canvas at the same time. - * - * ````Javascript - * var viewport = scene.viewport; - * - * // Configure Scene to render twice for each frame - * scene.passes = 2; // Default is 1 - * scene.clearEachPass = false; // Default is false - * - * // Render to a separate viewport on each render - * - * var viewport = scene.viewport; - * viewport.autoBoundary = false; - * - * scene.on("rendering", function (e) { - * switch (e.pass) { - * case 0: - * viewport.boundary = [0, 0, 200, 200]; // xmin, ymin, width, height - * break; - * - * case 1: - * viewport.boundary = [200, 0, 200, 200]; - * break; - * } - * }); - * - * // We can also intercept the Scene after each render, - * // (though we're not using this for anything here) - * scene.on("rendered", function (e) { - * switch (e.pass) { - * case 0: - * break; - * - * case 1: - * break; - * } - * }); - * ```` - * - * ## Gamma correction - * - * Within its shaders, xeokit performs shading calculations in linear space. - * - * By default, the Scene expects color textures (eg. {@link PhongMaterial#diffuseMap}, - * {@link MetallicMaterial#baseColorMap} and {@link SpecularMaterial#diffuseMap}) to - * be in pre-multipled gamma space, so will convert those to linear space before they are used in shaders. Other textures are - * always expected to be in linear space. - * - * By default, the Scene will also gamma-correct its rendered output. - * - * You can configure the Scene to expect all those color textures to be linear space, so that it does not gamma-correct them: - * - * ````javascript - * scene.gammaInput = false; - * ```` - * - * You would still need to gamma-correct the output, though, if it's going straight to the canvas, so normally we would - * leave that enabled: - * - * ````javascript - * scene.gammaOutput = true; - * ```` - * - * See {@link Texture} for more information on texture encoding and gamma. - * - * @class Scene - */ -class Scene extends Component { - - /** - @private - */ - get type() { - return "Scene"; - } - - /** - * @private - * @constructor - * @param {Viewer} viewer The Viewer this Scene belongs to. - * @param {Object} cfg Scene configuration. - * @param {String} [cfg.canvasId] ID of an existing HTML canvas for the {@link Scene#canvas} - either this or canvasElement is mandatory. When both values are given, the element reference is always preferred to the ID. - * @param {HTMLCanvasElement} [cfg.canvasElement] Reference of an existing HTML canvas for the {@link Scene#canvas} - either this or canvasId is mandatory. When both values are given, the element reference is always preferred to the ID. - * @param {HTMLElement} [cfg.keyboardEventsElement] Optional reference to HTML element on which key events should be handled. Defaults to the HTML Document. - * @param {number} [cfg.numCachedSectionPlanes=0] Enhances the efficiency of SectionPlane creation by proactively allocating Viewer resources for a specified quantity - * of SectionPlanes. Introducing this parameter streamlines the initial creation speed of SectionPlanes, particularly up to the designated quantity. This parameter internally - * configures renderer logic for the specified number of SectionPlanes, eliminating the need for setting up logic with each SectionPlane creation and thereby enhancing - * responsiveness. It is important to consider that each SectionPlane imposes rendering performance, so it is recommended to set this value to a quantity that aligns with - * your expected usage. - * @throws {String} Throws an exception when canvasId or canvasElement are missing or they aren't pointing to a valid HTMLCanvasElement. - */ - constructor(viewer, cfg = {}) { - - super(null, cfg); - const canvas = cfg.canvasElement || document.querySelector(`#${cfg.canvasId}`); - - if (!(canvas instanceof HTMLCanvasElement)) { - throw "Mandatory config expected: valid canvasId or canvasElement"; - } - - /** - * @type {{[key: string]: {wrapperFunc: Function, tickSubId: string}}} - */ - this._tickifiedFunctions = {}; - - const transparent = (!!cfg.transparent); - const alphaDepthMask = (!!cfg.alphaDepthMask); - - this._aabbDirty = true; - - this._readableGeometry = !!cfg.readableGeometryEnabled; - - /** - * The {@link Viewer} this Scene belongs to. - * @type {Viewer} - */ - this.viewer = viewer; - - /** Decremented each frame, triggers occlusion test for occludable {@link Marker}s when zero. - * @private - * @type {number} - */ - this.occlusionTestCountdown = 0; - - /** - The number of models currently loading. - - @property loading - @final - @type {Number} - */ - this.loading = 0; - - /** - The epoch time (in milliseconds since 1970) when this Scene was instantiated. - - @property timeCreated - @final - @type {Number} - */ - this.startTime = (new Date()).getTime(); - - /** - * Map of {@link Entity}s that represent models. - * - * Each {@link Entity} is mapped here by {@link Entity#id} when {@link Entity#isModel} is ````true````. - * - * @property models - * @final - * @type {{String:Entity}} - */ - this.models = {}; - - /** - * Map of {@link Entity}s that represents objects. - * - * Each {@link Entity} is mapped here by {@link Entity#id} when {@link Entity#isObject} is ````true````. - * - * @property objects - * @final - * @type {{String:Entity}} - */ - this.objects = {}; - this._numObjects = 0; - - /** - * Map of currently visible {@link Entity}s that represent objects. - * - * An Entity represents an object if {@link Entity#isObject} is ````true````, and is visible when {@link Entity#visible} is true. - * - * @property visibleObjects - * @final - * @type {{String:Object}} - */ - this.visibleObjects = {}; - this._numVisibleObjects = 0; - - /** - * Map of currently xrayed {@link Entity}s that represent objects. - * - * An Entity represents an object if {@link Entity#isObject} is ````true````, and is xrayed when {@link Entity#xrayed} is true. - * - * Each {@link Entity} is mapped here by {@link Entity#id}. - * - * @property xrayedObjects - * @final - * @type {{String:Object}} - */ - this.xrayedObjects = {}; - this._numXRayedObjects = 0; - - /** - * Map of currently highlighted {@link Entity}s that represent objects. - * - * An Entity represents an object if {@link Entity#isObject} is ````true```` is true, and is highlighted when {@link Entity#highlighted} is true. - * - * Each {@link Entity} is mapped here by {@link Entity#id}. - * - * @property highlightedObjects - * @final - * @type {{String:Object}} - */ - this.highlightedObjects = {}; - this._numHighlightedObjects = 0; - - /** - * Map of currently selected {@link Entity}s that represent objects. - * - * An Entity represents an object if {@link Entity#isObject} is true, and is selected while {@link Entity#selected} is true. - * - * Each {@link Entity} is mapped here by {@link Entity#id}. - * - * @property selectedObjects - * @final - * @type {{String:Object}} - */ - this.selectedObjects = {}; - this._numSelectedObjects = 0; - - /** - * Map of currently colorized {@link Entity}s that represent objects. - * - * An Entity represents an object if {@link Entity#isObject} is ````true````. - * - * Each {@link Entity} is mapped here by {@link Entity#id}. - * - * @property colorizedObjects - * @final - * @type {{String:Object}} - */ - this.colorizedObjects = {}; - this._numColorizedObjects = 0; - - /** - * Map of {@link Entity}s that represent objects whose opacity was updated. - * - * An Entity represents an object if {@link Entity#isObject} is ````true````. - * - * Each {@link Entity} is mapped here by {@link Entity#id}. - * - * @property opacityObjects - * @final - * @type {{String:Object}} - */ - this.opacityObjects = {}; - this._numOpacityObjects = 0; - - /** - * Map of {@link Entity}s that represent objects whose {@link Entity#offset}s were updated. - * - * An Entity represents an object if {@link Entity#isObject} is ````true````. - * - * Each {@link Entity} is mapped here by {@link Entity#id}. - * - * @property offsetObjects - * @final - * @type {{String:Object}} - */ - this.offsetObjects = {}; - this._numOffsetObjects = 0; - - // Cached ID arrays, lazy-rebuilt as needed when stale after map updates - - /** - Lazy-regenerated ID lists. - */ - this._modelIds = null; - this._objectIds = null; - this._visibleObjectIds = null; - this._xrayedObjectIds = null; - this._highlightedObjectIds = null; - this._selectedObjectIds = null; - this._colorizedObjectIds = null; - this._opacityObjectIds = null; - this._offsetObjectIds = null; - - this._collidables = {}; // Components that contribute to the Scene AABB - this._compilables = {}; // Components that require shader compilation - - this._needRecompile = false; - - /** - * For each {@link Component} type, a map of IDs to {@link Component} instances of that type. - * - * @type {{String:{String:Component}}} - */ - this.types = {}; - - /** - * The {@link Component}s within this Scene, each mapped to its {@link Component#id}. - * - * *@type {{String:Component}} - */ - this.components = {}; - - /** - * The {@link SectionPlane}s in this Scene, each mapped to its {@link SectionPlane#id}. - * - * @type {{String:SectionPlane}} - */ - this.sectionPlanes = {}; - - /** - * The {@link Light}s in this Scene, each mapped to its {@link Light#id}. - * - * @type {{String:Light}} - */ - this.lights = {}; - - /** - * The {@link LightMap}s in this Scene, each mapped to its {@link LightMap#id}. - * - * @type {{String:LightMap}} - */ - this.lightMaps = {}; - - /** - * The {@link ReflectionMap}s in this Scene, each mapped to its {@link ReflectionMap#id}. - * - * @type {{String:ReflectionMap}} - */ - this.reflectionMaps = {}; - - /** - * The {@link Bitmap}s in this Scene, each mapped to its {@link Bitmap#id}. - * - * @type {{String:Bitmap}} - */ - this.bitmaps = {}; - - /** - * The {@link LineSet}s in this Scene, each mapped to its {@link LineSet#id}. - * - * @type {{String:LineSet}} - */ - this.lineSets = {}; - - /** - * The real world offset for this Scene - * - * @type {Number[]} - */ - this.realWorldOffset = cfg.realWorldOffset || new Float64Array([0, 0, 0]); - - /** - * Manages the HTML5 canvas for this Scene. - * - * @type {Canvas} - */ - this.canvas = new Canvas(this, { - dontClear: true, // Never destroy this component with Scene#clear(); - canvas: canvas, - spinnerElementId: cfg.spinnerElementId, - transparent: transparent, - webgl2: cfg.webgl2 !== false, - contextAttr: cfg.contextAttr || {}, - backgroundColor: cfg.backgroundColor, - backgroundColorFromAmbientLight: cfg.backgroundColorFromAmbientLight, - premultipliedAlpha: cfg.premultipliedAlpha - }); - - const onContextLost = (event) => this.viewer.destroy(); - canvas.addEventListener("webglcontextlost", onContextLost, false); - this._removeWebglcontextlostListener = () => canvas.removeEventListener("webglcontextlost", onContextLost, false); - - this.canvas.on("boundary", () => { - this.glRedraw(); - }); - - this.canvas.on("webglContextFailed", () => { - alert("xeokit failed to find WebGL!"); - }); - - this._renderer = new Renderer$1(this, { - transparent: transparent, - alphaDepthMask: alphaDepthMask - }); - - this.canvas._renderer = this._renderer; - - this._sectionPlanesState = new (function () { - - this.sectionPlanes = []; - - this.clippingCaps = false; - - this._numCachedSectionPlanes = 0; - - let hash = null; - - this.getHash = function () { - if (hash) { - return hash; - } - const numAllocatedSectionPlanes = this.getNumAllocatedSectionPlanes(); - this.sectionPlanes; - if (numAllocatedSectionPlanes === 0) { - return this.hash = ";"; - } - - const hashParts = []; - for (let i = 0, len = numAllocatedSectionPlanes; i < len; i++) { - hashParts.push("cp"); - } - hashParts.push(";"); - hash = hashParts.join(""); - return hash; - }; - - this.addSectionPlane = function (sectionPlane) { - this.sectionPlanes.push(sectionPlane); - hash = null; - }; - - this.removeSectionPlane = function (sectionPlane) { - for (let i = 0, len = this.sectionPlanes.length; i < len; i++) { - if (this.sectionPlanes[i].id === sectionPlane.id) { - this.sectionPlanes.splice(i, 1); - hash = null; - return; - } - } - }; - - this.setNumCachedSectionPlanes = function (numCachedSectionPlanes) { - this._numCachedSectionPlanes = numCachedSectionPlanes; - hash = null; - }; - - this.getNumCachedSectionPlanes = function () { - return this._numCachedSectionPlanes; - }; - - this.getNumAllocatedSectionPlanes = function () { - const num = this.sectionPlanes.length; - return (num > this._numCachedSectionPlanes) ? num : this._numCachedSectionPlanes; - }; - })(); - - this._sectionPlanesState.setNumCachedSectionPlanes(cfg.numCachedSectionPlanes || 0); - - this._lightsState = new (function () { - - const DEFAULT_AMBIENT = math.vec4([0, 0, 0, 0]); - const ambientColorIntensity = math.vec4(); - - this.lights = []; - this.reflectionMaps = []; - this.lightMaps = []; - - let hash = null; - let ambientLight = null; - - this.getHash = function () { - if (hash) { - return hash; - } - const hashParts = []; - const lights = this.lights; - let light; - for (let i = 0, len = lights.length; i < len; i++) { - light = lights[i]; - hashParts.push("/"); - hashParts.push(light.type); - hashParts.push((light.space === "world") ? "w" : "v"); - if (light.castsShadow) { - hashParts.push("sh"); - } - } - if (this.lightMaps.length > 0) { - hashParts.push("/lm"); - } - if (this.reflectionMaps.length > 0) { - hashParts.push("/rm"); - } - hashParts.push(";"); - hash = hashParts.join(""); - return hash; - }; - - this.addLight = function (state) { - this.lights.push(state); - ambientLight = null; - hash = null; - }; - - this.removeLight = function (state) { - for (let i = 0, len = this.lights.length; i < len; i++) { - const light = this.lights[i]; - if (light.id === state.id) { - this.lights.splice(i, 1); - if (ambientLight && ambientLight.id === state.id) { - ambientLight = null; - } - hash = null; - return; - } - } - }; - - this.addReflectionMap = function (state) { - this.reflectionMaps.push(state); - hash = null; - }; - - this.removeReflectionMap = function (state) { - for (let i = 0, len = this.reflectionMaps.length; i < len; i++) { - if (this.reflectionMaps[i].id === state.id) { - this.reflectionMaps.splice(i, 1); - hash = null; - return; - } - } - }; - - this.addLightMap = function (state) { - this.lightMaps.push(state); - hash = null; - }; - - this.removeLightMap = function (state) { - for (let i = 0, len = this.lightMaps.length; i < len; i++) { - if (this.lightMaps[i].id === state.id) { - this.lightMaps.splice(i, 1); - hash = null; - return; - } - } - }; - - this.getAmbientColorAndIntensity = function () { - if (!ambientLight) { - for (let i = 0, len = this.lights.length; i < len; i++) { - const light = this.lights[i]; - if (light.type === "ambient") { - ambientLight = light; - break; - } - } - } - if (ambientLight) { - const color = ambientLight.color; - const intensity = ambientLight.intensity; - ambientColorIntensity[0] = color[0]; - ambientColorIntensity[1] = color[1]; - ambientColorIntensity[2] = color[2]; - ambientColorIntensity[3] = intensity; - return ambientColorIntensity; - } else { - return DEFAULT_AMBIENT; - } - }; - - })(); - - /** - * Publishes input events that occur on this Scene's canvas. - * - * @property input - * @type {Input} - * @final - */ - this.input = new Input(this, { - dontClear: true, // Never destroy this component with Scene#clear(); - element: this.canvas.canvas, - keyboardEventsElement: cfg.keyboardEventsElement - }); - - /** - * Configures this Scene's units of measurement and coordinate mapping between Real-space and World-space 3D coordinate systems. - * - * @property metrics - * @type {Metrics} - * @final - */ - this.metrics = new Metrics(this, { - units: cfg.units, - scale: cfg.scale, - origin: cfg.origin - }); - - /** Configures Scalable Ambient Obscurance (SAO) for this Scene. - * @type {SAO} - * @final - */ - this.sao = new SAO(this, { - enabled: cfg.saoEnabled - }); - - /** Configures Cross Sections for this Scene. - * @type {CrossSections} - * @final - */ - this.crossSections = new CrossSections(this, { - - }); - - this.ticksPerRender = cfg.ticksPerRender; - this.ticksPerOcclusionTest = cfg.ticksPerOcclusionTest; - this.passes = cfg.passes; - this.clearEachPass = cfg.clearEachPass; - this.gammaInput = cfg.gammaInput; - this.gammaOutput = cfg.gammaOutput; - this.gammaFactor = cfg.gammaFactor; - - this._entityOffsetsEnabled = !!cfg.entityOffsetsEnabled; - this._logarithmicDepthBufferEnabled = !!cfg.logarithmicDepthBufferEnabled; - - this._dtxEnabled = (cfg.dtxEnabled !== false); - this._pbrEnabled = !!cfg.pbrEnabled; - this._colorTextureEnabled = (cfg.colorTextureEnabled !== false); - this._dtxEnabled = !!cfg.dtxEnabled; - this._markerZOffset = cfg.markerZOffset; - - // Register Scene on xeokit - // Do this BEFORE we add components below - core._addScene(this); - - this._initDefaults(); - - // Global components - - this._viewport = new Viewport(this, { - id: "default.viewport", - autoBoundary: true, - dontClear: true // Never destroy this component with Scene#clear(); - }); - - this._camera = new Camera(this, { - id: "default.camera", - dontClear: true // Never destroy this component with Scene#clear(); - }); - - this._sectionCaps = new SectionCaps(this); - - // Default lights - - new AmbientLight(this, { - color: [1.0, 1.0, 1.0], - intensity: 0.7 - }); - - new DirLight(this, { - dir: [0.8, -.5, -0.5], - color: [0.67, 0.67, 1.0], - intensity: 0.7, - space: "world" - }); - - new DirLight(this, { - dir: [-0.8, -1.0, 0.5], - color: [1, 1, .9], - intensity: 0.9, - space: "world" - }); - - this._camera.on("dirty", () => { - this._renderer.imageDirty(); - }); - } - - _initDefaults() { - } - - _addComponent(component) { - if (component.id) { // Manual ID - if (this.components[component.id]) { - this.error("Component " + utils.inQuotes(component.id) + " already exists in Scene - ignoring ID, will randomly-generate instead"); - component.id = null; - } - } - if (!component.id) { // Auto ID - if (window.nextID === undefined) { - window.nextID = 0; - } - //component.id = math.createUUID(); - component.id = "__" + window.nextID++; - while (this.components[component.id]) { - component.id = math.createUUID(); - } - } - this.components[component.id] = component; - - // Register for class type - const type = component.type; - let types = this.types[component.type]; - if (!types) { - types = this.types[type] = {}; - } - types[component.id] = component; - - if (component.compile) { - this._compilables[component.id] = component; - } - if (component.isDrawable) { - this._renderer.addDrawable(component.id, component); - this._collidables[component.id] = component; - } - } - - _removeComponent(component) { - var id = component.id; - var type = component.type; - delete this.components[id]; - // Unregister for types - const types = this.types[type]; - if (types) { - delete types[id]; - if (utils.isEmptyObject(types)) { - delete this.types[type]; - } - } - if (component.compile) { - delete this._compilables[component.id]; - } - if (component.isDrawable) { - this._renderer.removeDrawable(component.id); - delete this._collidables[component.id]; - } - } - - // Methods below are called by various component types to register themselves on their - // Scene. Violates Hollywood Principle, where we could just filter on type in _addComponent, - // but this is faster than checking the type of each component in such a filter. - - _sectionPlaneCreated(sectionPlane) { - this.sectionPlanes[sectionPlane.id] = sectionPlane; - this.scene._sectionPlanesState.addSectionPlane(sectionPlane._state); - this.scene.fire("sectionPlaneCreated", sectionPlane, true /* Don't retain event */); - this._needRecompile = true; - } - - _bitmapCreated(bitmap) { - this.bitmaps[bitmap.id] = bitmap; - this.scene.fire("bitmapCreated", bitmap, true /* Don't retain event */); - } - - _lineSetCreated(lineSet) { - this.lineSets[lineSet.id] = lineSet; - this.scene.fire("lineSetCreated", lineSet, true /* Don't retain event */); - } - - _lightCreated(light) { - this.lights[light.id] = light; - this.scene._lightsState.addLight(light._state); - this._needRecompile = true; - } - - _lightMapCreated(lightMap) { - this.lightMaps[lightMap.id] = lightMap; - this.scene._lightsState.addLightMap(lightMap._state); - this._needRecompile = true; - } - - _reflectionMapCreated(reflectionMap) { - this.reflectionMaps[reflectionMap.id] = reflectionMap; - this.scene._lightsState.addReflectionMap(reflectionMap._state); - this._needRecompile = true; - } - - _sectionPlaneDestroyed(sectionPlane) { - delete this.sectionPlanes[sectionPlane.id]; - this.scene._sectionPlanesState.removeSectionPlane(sectionPlane._state); - this.scene.fire("sectionPlaneDestroyed", sectionPlane, true /* Don't retain event */); - this._needRecompile = true; - } - - _bitmapDestroyed(bitmap) { - delete this.bitmaps[bitmap.id]; - this.scene.fire("bitmapDestroyed", bitmap, true /* Don't retain event */); - } - - _lineSetDestroyed(lineSet) { - delete this.lineSets[lineSet.id]; - this.scene.fire("lineSetDestroyed", lineSet, true /* Don't retain event */); - } - - _lightDestroyed(light) { - delete this.lights[light.id]; - this.scene._lightsState.removeLight(light._state); - this._needRecompile = true; - } - - _lightMapDestroyed(lightMap) { - delete this.lightMaps[lightMap.id]; - this.scene._lightsState.removeLightMap(lightMap._state); - this._needRecompile = true; - } - - _reflectionMapDestroyed(reflectionMap) { - delete this.reflectionMaps[reflectionMap.id]; - this.scene._lightsState.removeReflectionMap(reflectionMap._state); - this._needRecompile = true; - } - - _registerModel(entity) { - this.models[entity.id] = entity; - this._modelIds = null; // Lazy regenerate - } - - _deregisterModel(entity) { - const modelId = entity.id; - delete this.models[modelId]; - this._modelIds = null; // Lazy regenerate - this.fire("modelUnloaded", modelId); - } - - _registerObject(entity) { - this.objects[entity.id] = entity; - this._numObjects++; - this._objectIds = null; // Lazy regenerate - } - - _deregisterObject(entity) { - delete this.objects[entity.id]; - this._numObjects--; - this._objectIds = null; // Lazy regenerate - } - - _objectVisibilityUpdated(entity, notify = true) { - if (entity.visible) { - this.visibleObjects[entity.id] = entity; - this._numVisibleObjects++; - } else { - delete this.visibleObjects[entity.id]; - this._numVisibleObjects--; - } - this._visibleObjectIds = null; // Lazy regenerate - if (notify) { - this.fire("objectVisibility", entity, true); - } - } - - _deRegisterVisibleObject(entity) { - delete this.visibleObjects[entity.id]; - this._numVisibleObjects--; - this._visibleObjectIds = null; // Lazy regenerate - } - - _objectXRayedUpdated(entity, notify = true) { - if (entity.xrayed) { - this.xrayedObjects[entity.id] = entity; - this._numXRayedObjects++; - } else { - delete this.xrayedObjects[entity.id]; - this._numXRayedObjects--; - } - this._xrayedObjectIds = null; // Lazy regenerate - if (notify) { - this.fire("objectXRayed", entity, true); - } - } - - _deRegisterXRayedObject(entity) { - delete this.xrayedObjects[entity.id]; - this._numXRayedObjects--; - this._xrayedObjectIds = null; // Lazy regenerate - } - - _objectHighlightedUpdated(entity) { - if (entity.highlighted) { - this.highlightedObjects[entity.id] = entity; - this._numHighlightedObjects++; - } else { - delete this.highlightedObjects[entity.id]; - this._numHighlightedObjects--; - } - this._highlightedObjectIds = null; // Lazy regenerate - } - - _deRegisterHighlightedObject(entity) { - delete this.highlightedObjects[entity.id]; - this._numHighlightedObjects--; - this._highlightedObjectIds = null; // Lazy regenerate - } - - _objectSelectedUpdated(entity, notify = true) { - if (entity.selected) { - this.selectedObjects[entity.id] = entity; - this._numSelectedObjects++; - } else { - delete this.selectedObjects[entity.id]; - this._numSelectedObjects--; - } - this._selectedObjectIds = null; // Lazy regenerate - if (notify) { - this.fire("objectSelected", entity, true); - } - } - - _deRegisterSelectedObject(entity) { - delete this.selectedObjects[entity.id]; - this._numSelectedObjects--; - this._selectedObjectIds = null; // Lazy regenerate - } - - - _objectColorizeUpdated(entity, colorized) { - if (colorized) { - this.colorizedObjects[entity.id] = entity; - this._numColorizedObjects++; - } else { - delete this.colorizedObjects[entity.id]; - this._numColorizedObjects--; - } - this._colorizedObjectIds = null; // Lazy regenerate - } - - _deRegisterColorizedObject(entity) { - delete this.colorizedObjects[entity.id]; - this._numColorizedObjects--; - this._colorizedObjectIds = null; // Lazy regenerate - } - - _objectOpacityUpdated(entity, opacityUpdated) { - if (opacityUpdated) { - this.opacityObjects[entity.id] = entity; - this._numOpacityObjects++; - } else { - delete this.opacityObjects[entity.id]; - this._numOpacityObjects--; - } - this._opacityObjectIds = null; // Lazy regenerate - } - - _deRegisterOpacityObject(entity) { - delete this.opacityObjects[entity.id]; - this._numOpacityObjects--; - this._opacityObjectIds = null; // Lazy regenerate - } - - _objectOffsetUpdated(entity, offset) { - if (!offset || offset[0] === 0 && offset[1] === 0 && offset[2] === 0) { - this.offsetObjects[entity.id] = entity; - this._numOffsetObjects++; - } else { - delete this.offsetObjects[entity.id]; - this._numOffsetObjects--; - } - this._offsetObjectIds = null; // Lazy regenerate - } - - _deRegisterOffsetObject(entity) { - delete this.offsetObjects[entity.id]; - this._numOffsetObjects--; - this._offsetObjectIds = null; // Lazy regenerate - } - - /** - * Returns the capabilities of this Scene. - * - * @private - * @returns {{astcSupported: boolean, etc1Supported: boolean, pvrtcSupported: boolean, etc2Supported: boolean, dxtSupported: boolean, bptcSupported: boolean}} - */ - get capabilities() { - return this._renderer.capabilities; - } - - /** - * Whether {@link Entity#offset} is enabled. - * - * This is set via the {@link Viewer} constructor and is ````false```` by default. - * - * @returns {Boolean} True if {@link Entity#offset} is enabled. - */ - get entityOffsetsEnabled() { - return this._entityOffsetsEnabled; - } - - /** - * Whether geometry is readable. - * - * This is set via the {@link Viewer} constructor and is ````false```` by default. - * - * The ````readableGeometryEnabled```` option for ````Scene#pick```` only works if this is set ````true````. - * - * Note that when ````true````, this configuration will increase the amount of browser memory used by the Viewer. - * - * @returns {Boolean} True if geometry is readable. - */ - get readableGeometryEnabled() { - return this._readableGeometry; - } - - /** - * Whether precision surface picking is enabled. - * @deprecated - * @returns {*|boolean} - */ - get pickSurfacePrecisionEnabled() { - return this._readableGeometry; - } - - /** - * Whether logarithmic depth buffer is enabled. - * - * This is set via the {@link Viewer} constructor and is ````false```` by default. - * - * @returns {Boolean} True if logarithmic depth buffer is enabled. - */ - get logarithmicDepthBufferEnabled() { - return this._logarithmicDepthBufferEnabled; - } - - /** - * Sets the number of {@link SectionPlane}s for which this Scene pre-caches resources. - * - * This property enhances the efficiency of SectionPlane creation by proactively allocating and caching Viewer resources for a specified quantity - * of SectionPlanes. Introducing this parameter streamlines the initial creation speed of SectionPlanes, particularly up to the designated quantity. This parameter internally - * configures renderer logic for the specified number of SectionPlanes, eliminating the need for setting up logic with each SectionPlane creation and thereby enhancing - * responsiveness. It is important to consider that each SectionPlane impacts rendering performance, so it is recommended to set this value to a quantity that aligns with - * your expected usage. - * - * Default is ````0````. - */ - set numCachedSectionPlanes(numCachedSectionPlanes) { - numCachedSectionPlanes = numCachedSectionPlanes || 0; - if (this._sectionPlanesState.getNumCachedSectionPlanes() !== numCachedSectionPlanes) { - this._sectionPlanesState.setNumCachedSectionPlanes(numCachedSectionPlanes); - this._needRecompile = true; - this.glRedraw(); - } - } - - /** - * Gets the number of {@link SectionPlane}s for which this Scene pre-caches resources. - * - * This property enhances the efficiency of SectionPlane creation by proactively allocating and caching Viewer resources for a specified quantity - * of SectionPlanes. Introducing this parameter streamlines the initial creation speed of SectionPlanes, particularly up to the designated quantity. This parameter internally - * configures renderer logic for the specified number of SectionPlanes, eliminating the need for setting up logic with each SectionPlane creation and thereby enhancing - * responsiveness. It is important to consider that each SectionPlane impacts rendering performance, so it is recommended to set this value to a quantity that aligns with - * your expected usage. - * - * Default is ````0````. - * - * @returns {number} The number of {@link SectionPlane}s for which this Scene pre-caches resources. - */ - get numCachedSectionPlanes() { - return this._sectionPlanesState.getNumCachedSectionPlanes(); - } - - /** - * Sets whether physically-based rendering is enabled. - * - * Default is ````false````. - */ - set pbrEnabled(pbrEnabled) { - this._pbrEnabled = !!pbrEnabled; - this.glRedraw(); - } - - /** - * Gets whether physically-based rendering is enabled. - * - * Default is ````false````. - * - * @returns {Boolean} True if quality rendering is enabled. - */ - get pbrEnabled() { - return this._pbrEnabled; - } - - /** - * Sets whether data texture scene representation (DTX) is enabled for the {@link Scene}. - * - * Even when enabled, DTX will only work if supported. - * - * Default value is ````false````. - * - * @type {Boolean} - */ - set dtxEnabled(value) { - value = !!value; - if (this._dtxEnabled === value) { - return; - } - this._dtxEnabled = value; - } - - /** - * Gets whether data texture-based scene representation (DTX) is enabled for the {@link Scene}. - * - * Even when enabled, DTX will only apply if supported. - * - * Default value is ````false````. - * - * @type {Boolean} - */ - get dtxEnabled() { - return this._dtxEnabled; - } - - /** - * Sets whether basic color texture rendering is enabled. - * - * Default is ````true````. - * - * @returns {Boolean} True if basic color texture rendering is enabled. - */ - set colorTextureEnabled(colorTextureEnabled) { - this._colorTextureEnabled = !!colorTextureEnabled; - this.glRedraw(); - } - - /** - * Gets whether basic color texture rendering is enabled. - * - * Default is ````true````. - * - * @returns {Boolean} True if basic color texture rendering is enabled. - */ - get colorTextureEnabled() { - return this._colorTextureEnabled; - } - - /** - * Gets the Z value of offset for Marker's OcclusionTester. - * The closest the value is to 0.000 the more precise OcclusionTester will be, but at the same time the less - * precise it will behave for Markers that are located exactly on the Surface. - * - * Default is ````-0.001````. - * - * @returns {Number} Z offset for Marker - */ - get markerZOffset() { - if (this._markerZOffset == null) { - return -0.001; - } - return this._markerZOffset; - } - - /** - * Performs an occlusion test on all {@link Marker}s in this {@link Scene}. - * - * Sets each {@link Marker#visible} ````true```` if the Marker is currently not occluded by any opaque {@link Entity}s - * in the Scene, or ````false```` if an Entity is occluding it. - */ - doOcclusionTest() { - if (this._needRecompile) { - this._recompile(); - this._needRecompile = false; - } - this._renderer.doOcclusionTest(); - } - - /** - * Renders a single frame of this Scene. - * - * The Scene will periodically render itself after any updates, but you can call this method to force a render - * if required. - * - * @param {Boolean} [forceRender=false] Forces a render when true, otherwise only renders if something has changed in this Scene - * since the last render. - */ - render(forceRender) { - - if (forceRender) { - core.runTasks(); - } - - const renderEvent = { - sceneId: null, - pass: 0 - }; - - if (this._needRecompile) { - this._recompile(); - this._renderer.imageDirty(); - this._needRecompile = false; - } - - if (!forceRender && !this._renderer.needsRender()) { - return; - } - - renderEvent.sceneId = this.id; - - for (let pass = 0; pass < this._passes; pass++) { - - renderEvent.pass = pass; - - /** - * Fired when about to render a frame for a Scene. - * - * @event rendering - * @param {String} sceneID The ID of this Scene. - * @param {Number} pass Index of the pass we are about to render (see {@link Scene#passes}). - */ - this.fire("rendering", renderEvent, true); - - if (forceRender) { - this._renderer.imageDirty(); - } - this._renderer.render(pass, this._clearEachPass || (pass === 0)); - - /** - * Fired when we have just rendered a frame for a Scene. - * - * @event rendering - * @param {String} sceneID The ID of this Scene. - * @param {Number} pass Index of the pass we rendered (see {@link Scene#passes}). - */ - this.fire("rendered", renderEvent, true); - } - - this._saveAmbientColor(); - } - - - /** - * @private - */ - compile() { - if (this._needRecompile) { - this._recompile(); - this._renderer.imageDirty(); - this._needRecompile = false; - } - } - - _recompile() { - for (const id in this._compilables) { - if (this._compilables.hasOwnProperty(id)) { - this._compilables[id].compile(); - } - } - this._renderer.shadowsDirty(); - this.fire("compile", this, true); - } - - _saveAmbientColor() { - const canvas = this.canvas; - if (!canvas.transparent && !canvas.backgroundImage && !canvas.backgroundColor) { - const ambientColorIntensity = this._lightsState.getAmbientColorAndIntensity(); - if (!this._lastAmbientColor || - this._lastAmbientColor[0] !== ambientColorIntensity[0] || - this._lastAmbientColor[1] !== ambientColorIntensity[1] || - this._lastAmbientColor[2] !== ambientColorIntensity[2] || - this._lastAmbientColor[3] !== ambientColorIntensity[3]) { - canvas.backgroundColor = ambientColorIntensity; - if (!this._lastAmbientColor) { - this._lastAmbientColor = math.vec4([0, 0, 0, 1]); - } - this._lastAmbientColor.set(ambientColorIntensity); - } - } else { - this._lastAmbientColor = null; - } - } - - /** - * Gets the IDs of the {@link Entity}s in {@link Scene#models}. - * - * @type {String[]} - */ - get modelIds() { - if (!this._modelIds) { - this._modelIds = Object.keys(this.models); - } - return this._modelIds; - } - - /** - * Gets the number of {@link Entity}s in {@link Scene#objects}. - * - * @type {Number} - */ - get numObjects() { - return this._numObjects; - } - - /** - * Gets the IDs of the {@link Entity}s in {@link Scene#objects}. - * - * @type {String[]} - */ - get objectIds() { - if (!this._objectIds) { - this._objectIds = Object.keys(this.objects); - } - return this._objectIds; - } - - /** - * Gets the number of {@link Entity}s in {@link Scene#visibleObjects}. - * - * @type {Number} - */ - get numVisibleObjects() { - return this._numVisibleObjects; - } - - /** - * Gets the IDs of the {@link Entity}s in {@link Scene#visibleObjects}. - * - * @type {String[]} - */ - get visibleObjectIds() { - if (!this._visibleObjectIds) { - this._visibleObjectIds = Object.keys(this.visibleObjects); - } - return this._visibleObjectIds; - } - - /** - * Gets the number of {@link Entity}s in {@link Scene#xrayedObjects}. - * - * @type {Number} - */ - get numXRayedObjects() { - return this._numXRayedObjects; - } - - /** - * Gets the IDs of the {@link Entity}s in {@link Scene#xrayedObjects}. - * - * @type {String[]} - */ - get xrayedObjectIds() { - if (!this._xrayedObjectIds) { - this._xrayedObjectIds = Object.keys(this.xrayedObjects); - } - return this._xrayedObjectIds; - } - - /** - * Gets the number of {@link Entity}s in {@link Scene#highlightedObjects}. - * - * @type {Number} - */ - get numHighlightedObjects() { - return this._numHighlightedObjects; - } - - /** - * Gets the IDs of the {@link Entity}s in {@link Scene#highlightedObjects}. - * - * @type {String[]} - */ - get highlightedObjectIds() { - if (!this._highlightedObjectIds) { - this._highlightedObjectIds = Object.keys(this.highlightedObjects); - } - return this._highlightedObjectIds; - } - - /** - * Gets the number of {@link Entity}s in {@link Scene#selectedObjects}. - * - * @type {Number} - */ - get numSelectedObjects() { - return this._numSelectedObjects; - } - - /** - * Gets the IDs of the {@link Entity}s in {@link Scene#selectedObjects}. - * - * @type {String[]} - */ - get selectedObjectIds() { - if (!this._selectedObjectIds) { - this._selectedObjectIds = Object.keys(this.selectedObjects); - } - return this._selectedObjectIds; - } - - /** - * Gets the number of {@link Entity}s in {@link Scene#colorizedObjects}. - * - * @type {Number} - */ - get numColorizedObjects() { - return this._numColorizedObjects; - } - - /** - * Gets the IDs of the {@link Entity}s in {@link Scene#colorizedObjects}. - * - * @type {String[]} - */ - get colorizedObjectIds() { - if (!this._colorizedObjectIds) { - this._colorizedObjectIds = Object.keys(this.colorizedObjects); - } - return this._colorizedObjectIds; - } - - /** - * Gets the IDs of the {@link Entity}s in {@link Scene#opacityObjects}. - * - * @type {String[]} - */ - get opacityObjectIds() { - if (!this._opacityObjectIds) { - this._opacityObjectIds = Object.keys(this.opacityObjects); - } - return this._opacityObjectIds; - } - - /** - * Gets the IDs of the {@link Entity}s in {@link Scene#offsetObjects}. - * - * @type {String[]} - */ - get offsetObjectIds() { - if (!this._offsetObjectIds) { - this._offsetObjectIds = Object.keys(this.offsetObjects); - } - return this._offsetObjectIds; - } - - /** - * Sets the number of "ticks" that happen between each render or this Scene. - * - * Default value is ````1````. - * - * @type {Number} - */ - set ticksPerRender(value) { - if (value === undefined || value === null) { - value = 1; - } else if (!utils.isNumeric(value) || value <= 0) { - this.error("Unsupported value for 'ticksPerRender': '" + value + - "' - should be an integer greater than zero."); - value = 1; - } - if (value === this._ticksPerRender) { - return; - } - this._ticksPerRender = value; - } - - /** - * Gets the number of "ticks" that happen between each render or this Scene. - * - * Default value is ````1````. - * - * @type {Number} - */ - get ticksPerRender() { - return this._ticksPerRender; - } - - /** - * Sets the number of "ticks" that happen between occlusion testing for {@link Marker}s. - * - * Default value is ````20````. - * - * @type {Number} - */ - set ticksPerOcclusionTest(value) { - if (value === undefined || value === null) { - value = 20; - } else if (!utils.isNumeric(value) || value <= 0) { - this.error("Unsupported value for 'ticksPerOcclusionTest': '" + value + - "' - should be an integer greater than zero."); - value = 20; - } - if (value === this._ticksPerOcclusionTest) { - return; - } - this._ticksPerOcclusionTest = value; - } - - /** - * Gets the number of "ticks" that happen between each render of this Scene. - * - * Default value is ````1````. - * - * @type {Number} - */ - get ticksPerOcclusionTest() { - return this._ticksPerOcclusionTest; - } - - /** - * Sets the number of times this Scene renders per frame. - * - * Default value is ````1````. - * - * @type {Number} - */ - set passes(value) { - if (value === undefined || value === null) { - value = 1; - } else if (!utils.isNumeric(value) || value <= 0) { - this.error("Unsupported value for 'passes': '" + value + - "' - should be an integer greater than zero."); - value = 1; - } - if (value === this._passes) { - return; - } - this._passes = value; - this.glRedraw(); - } - - /** - * Gets the number of times this Scene renders per frame. - * - * Default value is ````1````. - * - * @type {Number} - */ - get passes() { - return this._passes; - } - - /** - * When {@link Scene#passes} is greater than ````1````, indicates whether or not to clear the canvas before each pass (````true````) or just before the first pass (````false````). - * - * Default value is ````false````. - * - * @type {Boolean} - */ - set clearEachPass(value) { - value = !!value; - if (value === this._clearEachPass) { - return; - } - this._clearEachPass = value; - this.glRedraw(); - } - - /** - * When {@link Scene#passes} is greater than ````1````, indicates whether or not to clear the canvas before each pass (````true````) or just before the first pass (````false````). - * - * Default value is ````false````. - * - * @type {Boolean} - */ - get clearEachPass() { - return this._clearEachPass; - } - - /** - * Sets whether or not {@link Scene} should expect all {@link Texture}s and colors to have pre-multiplied gamma. - * - * Default value is ````false````. - * - * @type {Boolean} - */ - set gammaInput(value) { - value = value !== false; - if (value === this._renderer.gammaInput) { - return; - } - this._renderer.gammaInput = value; - this._needRecompile = true; - this.glRedraw(); - } - - /** - * Gets whether or not {@link Scene} should expect all {@link Texture}s and colors to have pre-multiplied gamma. - * - * Default value is ````false````. - * - * @type {Boolean} - */ - get gammaInput() { - return this._renderer.gammaInput; - } - - /** - * Sets whether or not to render pixels with pre-multiplied gama. - * - * Default value is ````false````. - * - * @type {Boolean} - */ - set gammaOutput(value) { - value = !!value; - if (value === this._renderer.gammaOutput) { - return; - } - this._renderer.gammaOutput = value; - this._needRecompile = true; - this.glRedraw(); - } - - /** - * Gets whether or not to render pixels with pre-multiplied gama. - * - * Default value is ````true````. - * - * @type {Boolean} - */ - get gammaOutput() { - return this._renderer.gammaOutput; - } - - /** - * Sets the gamma factor to use when {@link Scene#gammaOutput} is set true. - * - * Default value is ````2.2````. - * - * @type {Number} - */ - set gammaFactor(value) { - value = (value === undefined || value === null) ? 2.2 : value; - if (value === this._renderer.gammaFactor) { - return; - } - this._renderer.gammaFactor = value; - this.glRedraw(); - } - - /** - * Gets the gamma factor to use when {@link Scene#gammaOutput} is set true. - * - * Default value is ````2.2````. - * - * @type {Number} - */ - get gammaFactor() { - return this._renderer.gammaFactor; - } - - /** - * Gets the default {@link Geometry} for this Scene, which is a {@link ReadableGeometry} with a unit-sized box shape. - * - * Has {@link ReadableGeometry#id} set to "default.geometry". - * - * {@link Mesh}s in this Scene have {@link Mesh#geometry} set to this {@link ReadableGeometry} by default. - * - * @type {ReadableGeometry} - */ - get geometry() { - return this.components["default.geometry"] || buildBoxGeometry(ReadableGeometry); - } - - /** - * Gets the default {@link Material} for this Scene, which is a {@link PhongMaterial}. - * - * Has {@link PhongMaterial#id} set to "default.material". - * - * {@link Mesh}s in this Scene have {@link Mesh#material} set to this {@link PhongMaterial} by default. - * - * @type {PhongMaterial} - */ - get material() { - return this.components["default.material"] || new PhongMaterial(this, { - id: "default.material", - emissive: [0.4, 0.4, 0.4], // Visible by default on geometry without normals - dontClear: true - }); - } - - /** - * Gets the default xraying {@link EmphasisMaterial} for this Scene. - * - * Has {@link EmphasisMaterial#id} set to "default.xrayMaterial". - * - * {@link Mesh}s in this Scene have {@link Mesh#xrayMaterial} set to this {@link EmphasisMaterial} by default. - * - * {@link Mesh}s are xrayed while {@link Mesh#xrayed} is ````true````. - * - * @type {EmphasisMaterial} - */ - get xrayMaterial() { - return this.components["default.xrayMaterial"] || new EmphasisMaterial(this, { - id: "default.xrayMaterial", - fill: true, - fillColor: [0.970588207244873, 0.7965892553329468, 0.6660899519920349], - fillAlpha: 0.4, - edges: true, - edgeColor: [0.529411792755127, 0.4577854573726654, 0.4100345969200134], - edgeAlpha: 1.0, - edgeWidth: 1, - dontClear: true - }); - } - - /** - * Gets the default highlight {@link EmphasisMaterial} for this Scene. - * - * Has {@link EmphasisMaterial#id} set to "default.highlightMaterial". - * - * {@link Mesh}s in this Scene have {@link Mesh#highlightMaterial} set to this {@link EmphasisMaterial} by default. - * - * {@link Mesh}s are highlighted while {@link Mesh#highlighted} is ````true````. - * - * @type {EmphasisMaterial} - */ - get highlightMaterial() { - return this.components["default.highlightMaterial"] || new EmphasisMaterial(this, { - id: "default.highlightMaterial", - fill: true, - fillColor: [1.0, 1.0, 0.0], - fillAlpha: 0.5, - edges: true, - edgeColor: [1.0, 1.0, 1.0], - edgeAlpha: 1.0, - edgeWidth: 1, - dontClear: true - }); - } - - /** - * Gets the default selection {@link EmphasisMaterial} for this Scene. - * - * Has {@link EmphasisMaterial#id} set to "default.selectedMaterial". - * - * {@link Mesh}s in this Scene have {@link Mesh#highlightMaterial} set to this {@link EmphasisMaterial} by default. - * - * {@link Mesh}s are highlighted while {@link Mesh#highlighted} is ````true````. - * - * @type {EmphasisMaterial} - */ - get selectedMaterial() { - return this.components["default.selectedMaterial"] || new EmphasisMaterial(this, { - id: "default.selectedMaterial", - fill: true, - fillColor: [0.0, 1.0, 0.0], - fillAlpha: 0.5, - edges: true, - edgeColor: [1.0, 1.0, 1.0], - edgeAlpha: 1.0, - edgeWidth: 1, - dontClear: true - }); - } - - /** - * Gets the default {@link EdgeMaterial} for this Scene. - * - * Has {@link EdgeMaterial#id} set to "default.edgeMaterial". - * - * {@link Mesh}s in this Scene have {@link Mesh#edgeMaterial} set to this {@link EdgeMaterial} by default. - * - * {@link Mesh}s have their edges emphasized while {@link Mesh#edges} is ````true````. - * - * @type {EdgeMaterial} - */ - get edgeMaterial() { - return this.components["default.edgeMaterial"] || new EdgeMaterial(this, { - id: "default.edgeMaterial", - fill: true, - fillColor: [0.4, 0.4, 0.4], - fillAlpha: 0.2, - edges: true, - edgeColor: [0.0, 0.0, 0.0], - edgeAlpha: 1.0, - edgeWidth: 1, - dontClear: true - }); - } - - /** - * Gets the {@link PointsMaterial} for this Scene. - * - * @type {PointsMaterial} - */ - get pointsMaterial() { - return this.components["default.pointsMaterial"] || new PointsMaterial(this, { - id: "default.pointsMaterial", - fill: true, - fillColor: [0.4, 0.4, 0.4], - fillAlpha: 0.2, - edges: true, - edgeColor: [0.2, 0.2, 0.2], - edgeAlpha: 0.5, - edgeWidth: 1, - dontClear: true - }); - } - - /** - * Gets the {@link LinesMaterial} for this Scene. - * - * @type {LinesMaterial} - */ - get linesMaterial() { - return this.components["default.linesMaterial"] || new LinesMaterial(this, { - id: "default.linesMaterial", - fill: true, - fillColor: [0.4, 0.4, 0.4], - fillAlpha: 0.2, - edges: true, - edgeColor: [0.2, 0.2, 0.2], - edgeAlpha: 0.5, - edgeWidth: 1, - dontClear: true - }); - } - - /** - * Gets the {@link Viewport} for this Scene. - * - * @type Viewport - */ - get viewport() { - return this._viewport; - } - - /** - * Gets the {@link Camera} for this Scene. - * - * @type {Camera} - */ - get camera() { - return this._camera; - } - - /** - * Gets the World-space 3D center of this Scene. - * - *@type {Number[]} - */ - get center() { - if (this._aabbDirty || !this._center) { - const aabb = this.aabb; - if (!this._center) { - this._center = math.vec3(); - } - this._center[0] = (aabb[0] + aabb[3]) / 2; - this._center[1] = (aabb[1] + aabb[4]) / 2; - this._center[2] = (aabb[2] + aabb[5]) / 2; - } - return this._center; - } - - /** - * Gets the World-space axis-aligned 3D boundary (AABB) of this Scene. - * - * The AABB is represented by a six-element Float64Array containing the min/max extents of the axis-aligned volume, ie. ````[xmin, ymin,zmin,xmax,ymax, zmax]````. - * - * When the Scene has no content, will be ````[-100,-100,-100,100,100,100]````. - * - * @type {Number[]} - */ - get aabb() { - if (this._aabbDirty) { - if (!this._aabb) { - this._aabb = math.AABB3(); - } - let xmin = math.MAX_DOUBLE; - let ymin = math.MAX_DOUBLE; - let zmin = math.MAX_DOUBLE; - let xmax = math.MIN_DOUBLE; - let ymax = math.MIN_DOUBLE; - let zmax = math.MIN_DOUBLE; - let aabb; - const collidables = this._collidables; - let collidable; - let valid = false; - for (const collidableId in collidables) { - if (collidables.hasOwnProperty(collidableId)) { - collidable = collidables[collidableId]; - if (collidable.collidable === false) { - continue; - } - aabb = collidable.aabb; - if (aabb[0] < xmin) { - xmin = aabb[0]; - } - if (aabb[1] < ymin) { - ymin = aabb[1]; - } - if (aabb[2] < zmin) { - zmin = aabb[2]; - } - if (aabb[3] > xmax) { - xmax = aabb[3]; - } - if (aabb[4] > ymax) { - ymax = aabb[4]; - } - if (aabb[5] > zmax) { - zmax = aabb[5]; - } - valid = true; - } - } - if (!valid) { - xmin = -100; - ymin = -100; - zmin = -100; - xmax = 100; - ymax = 100; - zmax = 100; - } - this._aabb[0] = xmin; - this._aabb[1] = ymin; - this._aabb[2] = zmin; - this._aabb[3] = xmax; - this._aabb[4] = ymax; - this._aabb[5] = zmax; - this._aabbDirty = false; - this._center = null; - } - return this._aabb; - } - - _setAABBDirty() { - //if (!this._aabbDirty) { - this._aabbDirty = true; - this.fire("boundary"); - // } - } - - /** - * Attempts to pick an {@link Entity} in this Scene. - * - * Ignores {@link Entity}s with {@link Entity#pickable} set ````false````. - * - * When an {@link Entity} is picked, fires a "pick" event on the {@link Entity} with the pick result as parameters. - * - * Picking the {@link Entity} at the given canvas coordinates: - - * ````javascript - * var pickResult = scene.pick({ - * canvasPos: [23, 131] - * }); - * - * if (pickResult) { // Picked an Entity - * var entity = pickResult.entity; - * } - * ```` - * - * Picking, with a ray cast through the canvas, hits an {@link Entity}: - * - * ````javascript - * var pickResult = scene.pick({ - * pickSurface: true, - * canvasPos: [23, 131] - * }); - * - * if (pickResult) { // Picked an Entity - * - * var entity = pickResult.entity; - * - * if (pickResult.primitive === "triangle") { - * - * // Picked a triangle on the entity surface - * - * var primIndex = pickResult.primIndex; // Position of triangle's first index in the picked Entity's Geometry's indices array - * var indices = pickResult.indices; // UInt32Array containing the triangle's vertex indices - * var localPos = pickResult.localPos; // Float64Array containing the picked Local-space position on the triangle - * var worldPos = pickResult.worldPos; // Float64Array containing the picked World-space position on the triangle - * var viewPos = pickResult.viewPos; // Float64Array containing the picked View-space position on the triangle - * var bary = pickResult.bary; // Float64Array containing the picked barycentric position within the triangle - * var worldNormal = pickResult.worldNormal; // Float64Array containing the interpolated World-space normal vector at the picked position on the triangle - * var uv = pickResult.uv; // Float64Array containing the interpolated UV coordinates at the picked position on the triangle - * - * } else if (pickResult.worldPos && pickResult.worldNormal) { - * - * // Picked a point and normal on the entity surface - * - * var worldPos = pickResult.worldPos; // Float64Array containing the picked World-space position on the Entity surface - * var worldNormal = pickResult.worldNormal; // Float64Array containing the picked World-space normal vector on the Entity Surface - * } - * } - * ```` - * - * Picking the {@link Entity} that intersects an arbitrarily-aligned World-space ray: - * - * ````javascript - * var pickResult = scene.pick({ - * pickSurface: true, // Picking with arbitrarily-positioned ray - * origin: [0,0,-5], // Ray origin - * direction: [0,0,1] // Ray direction - * }); - * - * if (pickResult) { // Picked an Entity with the ray - * - * var entity = pickResult.entity; - * - * if (pickResult.primitive == "triangle") { - * - * // Picked a triangle on the entity surface - * - * var primitive = pickResult.primitive; // Type of primitive that was picked, usually "triangles" - * var primIndex = pickResult.primIndex; // Position of triangle's first index in the picked Entity's Geometry's indices array - * var indices = pickResult.indices; // UInt32Array containing the triangle's vertex indices - * var localPos = pickResult.localPos; // Float64Array containing the picked Local-space position on the triangle - * var worldPos = pickResult.worldPos; // Float64Array containing the picked World-space position on the triangle - * var viewPos = pickResult.viewPos; // Float64Array containing the picked View-space position on the triangle - * var bary = pickResult.bary; // Float64Array containing the picked barycentric position within the triangle - * var worldNormal = pickResult.worldNormal; // Float64Array containing the interpolated World-space normal vector at the picked position on the triangle - * var uv = pickResult.uv; // Float64Array containing the interpolated UV coordinates at the picked position on the triangle - * var origin = pickResult.origin; // Float64Array containing the World-space ray origin - * var direction = pickResult.direction; // Float64Array containing the World-space ray direction - * - * } else if (pickResult.worldPos && pickResult.worldNormal) { - * - * // Picked a point and normal on the entity surface - * - * var worldPos = pickResult.worldPos; // Float64Array containing the picked World-space position on the Entity surface - * var worldNormal = pickResult.worldNormal; // Float64Array containing the picked World-space normal vector on the Entity Surface - * } - * } - * ```` - * - * @param {*} params Picking parameters. - * @param {Boolean} [params.pickSurface=false] Whether to find the picked position on the surface of the Entity. - * @param {Boolean} [params.pickSurfacePrecision=false] When picking an Entity surface position, indicates whether or not we want full-precision {@link PickResult#worldPos}. Only works when {@link Scene#readableGeometryEnabled} is ````true````. If pick succeeds, the returned {@link PickResult} will have {@link PickResult#precision} set ````true````, to indicate that it contains full-precision surface pick results. - * @param {Boolean} [params.pickSurfaceNormal=false] Whether to find the picked normal on the surface of the Entity. Only works if ````pickSurface```` is given. - * @param {Number[]} [params.canvasPos] Canvas-space coordinates. When ray-picking, this will override the **origin** and ** direction** parameters and will cause the ray to be fired through the canvas at this position, directly along the negative View-space Z-axis. - * @param {Number[]} [params.origin] World-space ray origin when ray-picking. Ignored when canvasPos given. - * @param {Number[]} [params.direction] World-space ray direction when ray-picking. Also indicates the length of the ray. Ignored when canvasPos given. - * @param {Number[]} [params.matrix] 4x4 transformation matrix to define the World-space ray origin and direction, as an alternative to ````origin```` and ````direction````. - * @param {Number} [params.snapRadius=30] The snap radius, in canvas pixels. - * @param {boolean} [params.snapToVertex=true] Whether to snap to vertex. Only works when `canvasPos` given. - * @param {boolean} [params.snapToEdge=true] Whether to snap to edge. Only works when `canvasPos` given. - * @param {PickResult} [pickResult] Holds the results of the pick attempt. Will use the Scene's singleton PickResult if you don't supply your own. - * @returns {PickResult} Holds results of the pick attempt, returned when an {@link Entity} is picked, else null. See method comments for description. - */ - pick(params, pickResult) { - - if (! this.canvas) { - this.error("Picking not allowed on a destroyed Scene"); - return null; - } - - if (this.canvas.boundary[2] === 0 || this.canvas.boundary[3] === 0) { - this.error("Picking not allowed while canvas has zero width or height"); - return null; - } - - params = params || {}; - - params.pickSurface = params.pickSurface || params.rayPick; // Backwards compatibility - - if (!params.canvasPos && !params.matrix && (!params.origin || !params.direction)) { - this.warn("picking without canvasPos, matrix, or ray origin and direction"); - } - - const includeEntities = params.includeEntities || params.include; // Backwards compat - if (includeEntities) { - params.includeEntityIds = getEntityIDMap(this, includeEntities); - } - - const excludeEntities = params.excludeEntities || params.exclude; // Backwards compat - if (excludeEntities) { - params.excludeEntityIds = getEntityIDMap(this, excludeEntities); - } - - if (this._needRecompile) { - this._recompile(); - this._renderer.imageDirty(); - this._needRecompile = false; - } - - if (params.snapToEdge || params.snapToVertex) { - pickResult = this._renderer.snapPick(params, pickResult); - } else { - pickResult = this._renderer.pick(params, pickResult); - } - - if (pickResult) { - if (pickResult.entity && pickResult.entity.fire) { - pickResult.entity.fire("picked", pickResult); // TODO: SceneModelEntity doesn't fire events - } - } - - return pickResult; - } - - /** - * @param {Object} params Picking parameters. - * @param {Number[]} params.canvasPos Canvas-space coordinates. - * @param {Number} [params.snapRadius=30] The snap radius, in canvas pixels - * @param {boolean} [params.snapToVertex=true] Whether to snap to vertex. - * @param {boolean} [params.snapToEdge=true] Whether to snap to edge. - * @deprecated - */ - snapPick(params) { - if (! this.canvas) { - this.error("Picking not allowed on a destroyed Scene"); - return null; - } - if (undefined === this._warnSnapPickDeprecated) { - this._warnSnapPickDeprecated = true; - this.warn("Scene.snapPick() is deprecated since v2.4.2 - use Scene.pick() instead"); - } - if (!params.canvasPos) { - this.error("Scene.snapPick() canvasPos parameter expected"); - return; - } - return this._renderer.snapPick(params); - } - - /** - * Destroys all non-default {@link Component}s in this Scene. - */ - clear() { - var component; - for (const id in this.components) { - if (this.components.hasOwnProperty(id)) { - component = this.components[id]; - if (!component._dontClear) { // Don't destroy components like Camera, Input, Viewport etc. - component.destroy(); - } - } - } - } - - /** - * Destroys all {@link Light}s in this Scene.. - */ - clearLights() { - const ids = Object.keys(this.lights); - for (let i = 0, len = ids.length; i < len; i++) { - this.lights[ids[i]].destroy(); - } - } - - /** - * Destroys all {@link SectionPlane}s in this Scene. - */ - clearSectionPlanes() { - const ids = Object.keys(this.sectionPlanes); - for (let i = 0, len = ids.length; i < len; i++) { - this.sectionPlanes[ids[i]].destroy(); - } - } - - /** - * Destroys all {@link Line}s in this Scene. - */ - clearBitmaps() { - const ids = Object.keys(this.bitmaps); - for (let i = 0, len = ids.length; i < len; i++) { - this.bitmaps[ids[i]].destroy(); - } - } - - - /** - * Destroys all {@link Line}s in this Scene. - */ - clearLines() { - const ids = Object.keys(this.lineSets); - for (let i = 0, len = ids.length; i < len; i++) { - this.lineSets[ids[i]].destroy(); - } - } - - /** - * Gets the collective axis-aligned boundary (AABB) of a batch of {@link Entity}s that represent objects. - * - * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````. - * - * Each {@link Entity} on which {@link Entity#isObject} is registered by {@link Entity#id} in {@link Scene#visibleObjects}. - * - * Each {@link Entity} is only included in the AABB when {@link Entity#collidable} is ````true````. - * - * @param {String[]} ids Array of {@link Entity#id} values. - * @returns {[Number, Number, Number, Number, Number, Number]} An axis-aligned World-space bounding box, given as elements ````[xmin, ymin, zmin, xmax, ymax, zmax]````. - */ - getAABB(ids) { - if (ids === undefined) { - return this.aabb; - } - if (utils.isString(ids)) { - const entity = this.objects[ids]; - if (entity && entity.aabb) { // A Component subclass with an AABB - return entity.aabb; - } - ids = [ids]; // Must be an entity type - } - if (ids.length === 0) { - return this.aabb; - } - let xmin = math.MAX_DOUBLE; - let ymin = math.MAX_DOUBLE; - let zmin = math.MAX_DOUBLE; - let xmax = math.MIN_DOUBLE; - let ymax = math.MIN_DOUBLE; - let zmax = math.MIN_DOUBLE; - let valid; - this.withObjects(ids, entity => { - if (entity.collidable) { - const aabb = entity.aabb; - if (aabb[0] < xmin) { - xmin = aabb[0]; - } - if (aabb[1] < ymin) { - ymin = aabb[1]; - } - if (aabb[2] < zmin) { - zmin = aabb[2]; - } - if (aabb[3] > xmax) { - xmax = aabb[3]; - } - if (aabb[4] > ymax) { - ymax = aabb[4]; - } - if (aabb[5] > zmax) { - zmax = aabb[5]; - } - valid = true; - } - } - ); - if (valid) { - const aabb2 = math.AABB3(); - aabb2[0] = xmin; - aabb2[1] = ymin; - aabb2[2] = zmin; - aabb2[3] = xmax; - aabb2[4] = ymax; - aabb2[5] = zmax; - return aabb2; - } else { - return this.aabb; // Scene AABB - } - } - - /** - * Batch-updates {@link Entity#visible} on {@link Entity}s that represent objects. - * - * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````. - * - * Each {@link Entity} on which both {@link Entity#isObject} and {@link Entity#visible} are ````true```` is - * registered by {@link Entity#id} in {@link Scene#visibleObjects}. - * - * @param {String[]} ids Array of {@link Entity#id} values. - * @param {Boolean} visible Whether or not to set visible. - * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied. - */ - setObjectsVisible(ids, visible) { - return this.withObjects(ids, entity => { - const changed = (entity.visible !== visible); - entity.visible = visible; - return changed; - }); - } - - /** - * Batch-updates {@link Entity#collidable} on {@link Entity}s that represent objects. - * - * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````. - * - * @param {String[]} ids Array of {@link Entity#id} values. - * @param {Boolean} collidable Whether or not to set collidable. - * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied. - */ - setObjectsCollidable(ids, collidable) { - return this.withObjects(ids, entity => { - const changed = (entity.collidable !== collidable); - entity.collidable = collidable; - return changed; - }); - } - - /** - * Batch-updates {@link Entity#culled} on {@link Entity}s that represent objects. - * - * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````. - * - * @param {String[]} ids Array of {@link Entity#id} values. - * @param {Boolean} culled Whether or not to cull. - * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied. - */ - setObjectsCulled(ids, culled) { - return this.withObjects(ids, entity => { - const changed = (entity.culled !== culled); - entity.culled = culled; - return changed; - }); - } - - /** - * Batch-updates {@link Entity#selected} on {@link Entity}s that represent objects. - * - * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````. - * - * Each {@link Entity} on which both {@link Entity#isObject} and {@link Entity#selected} are ````true```` is - * registered by {@link Entity#id} in {@link Scene#selectedObjects}. - * - * @param {String[]} ids Array of {@link Entity#id} values. - * @param {Boolean} selected Whether or not to select. - * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied. - */ - setObjectsSelected(ids, selected) { - return this.withObjects(ids, entity => { - const changed = (entity.selected !== selected); - entity.selected = selected; - return changed; - }); - } - - /** - * Batch-updates {@link Entity#highlighted} on {@link Entity}s that represent objects. - * - * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````. - * - * Each {@link Entity} on which both {@link Entity#isObject} and {@link Entity#highlighted} are ````true```` is - * registered by {@link Entity#id} in {@link Scene#highlightedObjects}. - * - * @param {String[]} ids Array of {@link Entity#id} values. - * @param {Boolean} highlighted Whether or not to highlight. - * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied. - */ - setObjectsHighlighted(ids, highlighted) { - return this.withObjects(ids, entity => { - const changed = (entity.highlighted !== highlighted); - entity.highlighted = highlighted; - return changed; - }); - } - - /** - * Batch-updates {@link Entity#xrayed} on {@link Entity}s that represent objects. - * - * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````. - * - * @param {String[]} ids Array of {@link Entity#id} values. - * @param {Boolean} xrayed Whether or not to xray. - * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied. - */ - setObjectsXRayed(ids, xrayed) { - return this.withObjects(ids, entity => { - const changed = (entity.xrayed !== xrayed); - entity.xrayed = xrayed; - return changed; - }); - } - - /** - * Batch-updates {@link Entity#edges} on {@link Entity}s that represent objects. - * - * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````. - * - * @param {String[]} ids Array of {@link Entity#id} values. - * @param {Boolean} edges Whether or not to show edges. - * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied. - */ - setObjectsEdges(ids, edges) { - return this.withObjects(ids, entity => { - const changed = (entity.edges !== edges); - entity.edges = edges; - return changed; - }); - } - - /** - * Batch-updates {@link Entity#colorize} on {@link Entity}s that represent objects. - * - * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````. - * - * @param {String[]} ids Array of {@link Entity#id} values. - * @param {Number[]} [colorize=(1,1,1)] RGB colorize factors, multiplied by the rendered pixel colors. - * @returns {Boolean} True if any {@link Entity}s were colorized, else false if all updates were redundant and not applied. - */ - setObjectsColorized(ids, colorize) { - return this.withObjects(ids, entity => { - entity.colorize = colorize; - }); - } - - /** - * Batch-updates {@link Entity#opacity} on {@link Entity}s that represent objects. - * - * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````. - * - * @param {String[]} ids Array of {@link Entity#id} values. - * @param {Number} [opacity=1.0] Opacity factor, multiplied by the rendered pixel alphas. - * @returns {Boolean} True if any {@link Entity}s changed opacity, else false if all updates were redundant and not applied. - */ - setObjectsOpacity(ids, opacity) { - return this.withObjects(ids, entity => { - const changed = (entity.opacity !== opacity); - entity.opacity = opacity; - return changed; - }); - } - - /** - * Batch-updates {@link Entity#pickable} on {@link Entity}s that represent objects. - * - * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````. - * - * @param {String[]} ids Array of {@link Entity#id} values. - * @param {Boolean} pickable Whether or not to set pickable. - * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied. - */ - setObjectsPickable(ids, pickable) { - return this.withObjects(ids, entity => { - const changed = (entity.pickable !== pickable); - entity.pickable = pickable; - return changed; - }); - } - - /** - * Batch-updates {@link Entity#offset} on {@link Entity}s that represent objects. - * - * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````. - * - * @param {String[]} ids Array of {@link Entity#id} values. - * @param {Number[]} [offset] 3D offset vector. - */ - setObjectsOffset(ids, offset) { - this.withObjects(ids, entity => { - entity.offset = offset; - }); - } - - /** - * Iterates with a callback over {@link Entity}s that represent objects. - * - * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````. - * - * @param {String[]} ids Array of {@link Entity#id} values. - * @param {Function} callback Callback to execute on eacn {@link Entity}. - * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied. - */ - withObjects(ids, callback) { - if (utils.isString(ids)) { - ids = [ids]; - } - let changed = false; - for (let i = 0, len = ids.length; i < len; i++) { - const id = ids[i]; - let entity = this.objects[id]; - if (entity) { - changed = callback(entity) || changed; - } else { - const modelIds = this.modelIds; - for (let i = 0, len = modelIds.length; i < len; i++) { - const modelId = modelIds[i]; - const globalObjectId = math.globalizeObjectId(modelId, id); - entity = this.objects[globalObjectId]; - if (entity) { - changed = callback(entity) || changed; - } - } - } - } - return changed; - } - - /** - * This method will "tickify" the provided `cb` function. - * - * This means, the function will be wrapped so: - * - * - it runs time-aligned to scene ticks - * - it runs maximum once per scene-tick - * - * @param {Function} cb The function to tickify - * @returns {Function} - */ - tickify(cb) { - const cbString = cb.toString(); - - /** - * Check if the function is already tickified, and if so return the cached one. - */ - if (cbString in this._tickifiedFunctions) { - return this._tickifiedFunctions[cbString].wrapperFunc; - } - - let alreadyRun = 0; - let needToRun = 0; - - let lastArgs; - - /** - * The provided `cb` function is replaced with a "set-dirty" function - * - * @type {Function} - */ - const wrapperFunc = function (...args) { - lastArgs = args; - needToRun++; - }; - - /** - * An each scene tick, if the "dirty-flag" is set, run the `cb` function. - * - * This will make it run time-aligned to the scene tick. - */ - const tickSubId = this.on("tick", () => { - const tmp = needToRun; - if (tmp > alreadyRun) { - alreadyRun = tmp; - cb(...lastArgs); - } - }); - - /** - * And, store the list of subscribers. - */ - this._tickifiedFunctions[cbString] = {tickSubId, wrapperFunc}; - - return wrapperFunc; - } - - /** - * Destroys this Scene. - */ - destroy() { - - super.destroy(); - - this._removeWebglcontextlostListener(); - // this.canvas.gl.getExtension("WEBGL_lose_context").loseContext(); // disabled because of XCD-306 and XEOK-295 - - for (const id in this.components) { - if (this.components.hasOwnProperty(id)) { - this.components[id].destroy(); - } - } - - //destroy section caps separately because it's not a component - this._sectionCaps.destroy(); - - this.canvas.gl = null; - - // Memory leak prevention - this.components = null; - this.models = null; - this.objects = null; - this.visibleObjects = null; - this.xrayedObjects = null; - this.highlightedObjects = null; - this.selectedObjects = null; - this.colorizedObjects = null; - this.opacityObjects = null; - this.sectionPlanes = null; - this.lights = null; - this.lightMaps = null; - this.reflectionMaps = null; - this._objectIds = null; - this._visibleObjectIds = null; - this._xrayedObjectIds = null; - this._highlightedObjectIds = null; - this._selectedObjectIds = null; - this._colorizedObjectIds = null; - this._sectionCaps = null; - this.types = null; - this.components = null; - this.canvas = null; - this._renderer = null; - this.input = null; - this._viewport = null; - this._camera = null; - } -} - -const screenPos = math.vec4(); -const viewPos = math.vec4(); - -const tempVec3a$9 = math.vec3(); -const tempVec3b$6 = math.vec3(); -const tempVec3c$5 = math.vec3(); - -const tempVec4a$6 = math.vec4(); -const tempVec4b$6 = math.vec4(); -const tempVec4c$1 = math.vec4(); - -/** - * @private - */ -class PanController { - - constructor(scene) { - this._scene = scene; - } - - /** - * Dollys the Camera towards the given target 2D canvas position. - * - * When the target's corresponding World-space position is also provided, then this function will also test if we've - * dollied past the target, and will return ````true```` if that's the case. - * - * @param [optionalTargetWorldPos] Optional world position of the target - * @param targetCanvasPos Canvas position of the target - * @param dollyDelta Amount to dolly - * @return True if optionalTargetWorldPos was given, and we've dollied past that position. - */ - dollyToCanvasPos(optionalTargetWorldPos, targetCanvasPos, dollyDelta) { - - let dolliedThroughSurface = false; - - const camera = this._scene.camera; - - if (optionalTargetWorldPos) { - const eyeToWorldPosVec = math.subVec3(optionalTargetWorldPos, camera.eye, tempVec3a$9); - const eyeWorldPosDist = math.lenVec3(eyeToWorldPosVec); - dolliedThroughSurface = (eyeWorldPosDist < dollyDelta); - } - - if (camera.projection === "perspective") { - - camera.ortho.scale = camera.ortho.scale - dollyDelta; - - const unprojectedWorldPos = this._unproject(targetCanvasPos, tempVec4a$6); - const offset = math.subVec3(unprojectedWorldPos, camera.eye, tempVec4c$1); - const moveVec = math.mulVec3Scalar(math.normalizeVec3(offset), -dollyDelta, []); - - camera.eye = [camera.eye[0] - moveVec[0], camera.eye[1] - moveVec[1], camera.eye[2] - moveVec[2]]; - camera.look = [camera.look[0] - moveVec[0], camera.look[1] - moveVec[1], camera.look[2] - moveVec[2]]; - - if (optionalTargetWorldPos) { - - // Subtle UX tweak - if we have a target World position, then set camera eye->look distance to - // the same distance as from eye->target. This just gives us a better position for look, - // if we subsequently orbit eye about look, so that we don't orbit a position that's - // suddenly a lot closer than the point we pivoted about on the surface of the last object - // that we click-drag-pivoted on. - - const eyeTargetVec = math.subVec3(optionalTargetWorldPos, camera.eye, tempVec3a$9); - const lenEyeTargetVec = math.lenVec3(eyeTargetVec); - const eyeLookVec = math.mulVec3Scalar(math.normalizeVec3(math.subVec3(camera.look, camera.eye, tempVec3b$6)), lenEyeTargetVec); - camera.look = [camera.eye[0] + eyeLookVec[0], camera.eye[1] + eyeLookVec[1], camera.eye[2] + eyeLookVec[2]]; - } - - } else if (camera.projection === "ortho") { - - // - set ortho scale, getting the unprojected targetCanvasPos before and after, get that difference in a vector; - // - get the vector in which we're dollying; - // - add both vectors to camera eye and look. - - const worldPos1 = this._unproject(targetCanvasPos, tempVec4a$6); - - camera.ortho.scale = camera.ortho.scale - dollyDelta; - camera.ortho._update(); // HACK - - const worldPos2 = this._unproject(targetCanvasPos, tempVec4b$6); - const offset = math.subVec3(worldPos2, worldPos1, tempVec4c$1); - const eyeLookMoveVec = math.mulVec3Scalar(math.normalizeVec3(math.subVec3(camera.look, camera.eye, tempVec3a$9)), -dollyDelta, tempVec3b$6); - const moveVec = math.addVec3(offset, eyeLookMoveVec, tempVec3c$5); - - camera.eye = [camera.eye[0] - moveVec[0], camera.eye[1] - moveVec[1], camera.eye[2] - moveVec[2]]; - camera.look = [camera.look[0] - moveVec[0], camera.look[1] - moveVec[1], camera.look[2] - moveVec[2]]; - } - - return dolliedThroughSurface; - } - - _unproject(canvasPos, worldPos) { - - const camera = this._scene.camera; - const transposedProjectMat = camera.project.transposedMatrix; - const Pt3 = transposedProjectMat.subarray(8, 12); - const Pt4 = transposedProjectMat.subarray(12); - const D = [0, 0, -1.0, 1]; - const screenZ = math.dotVec4(D, Pt3) / math.dotVec4(D, Pt4); - - camera.project.unproject(canvasPos, screenZ, screenPos, viewPos, worldPos); - - return worldPos; - } - - destroy() { - } -} - -const tempVec3a$8 = math.vec3(); -const tempVec3b$5 = math.vec3(); -const tempVec3c$4 = math.vec3(); - -const tempVec4a$5 = math.vec4(); -const tempVec4b$5 = math.vec4(); -const tempVec4c = math.vec4(); - -const TOP_LIMIT = 0.001; -const BOTTOM_LIMIT = Math.PI - 0.001; - - -/** @private */ -class PivotController { - - /** - * @private - */ - constructor(scene, configs) { - - // Pivot math by: http://www.derschmale.com/ - - this._scene = scene; - this._configs = configs; - this._pivotWorldPos = math.vec3(); - this._cameraOffset = math.vec3(); - this._azimuth = 0; - this._polar = 0; - this._radius = 0; - this._pivotPosSet = false; // Initially false, true as soon as _pivotWorldPos has been set to some value - this._pivoting = false; // True while pivoting - this._shown = false; - - this._pivotSphereEnabled = false; - this._pivotSphere = null; - this._pivotSphereSize = 1; - this._pivotSphereGeometry = null; - this._pivotSphereMaterial = null; - this._rtcCenter = math.vec3(); - this._rtcPos = math.vec3(); - - this._pivotViewPos = math.vec4(); - this._pivotProjPos = math.vec4(); - this._pivotCanvasPos = math.vec2(); - this._cameraDirty = true; - - this._onViewMatrix = this._scene.camera.on("viewMatrix", () => { - this._cameraDirty = true; - }); - - this._onProjMatrix = this._scene.camera.on("projMatrix", () => { - this._cameraDirty = true; - }); - - this._onTick = this._scene.on("tick", () => { - this.updatePivotElement(); - this.updatePivotSphere(); - }); - } - - createPivotSphere() { - const currentPos = this.getPivotPos(); - const cameraPos = math.vec3(); - math.decomposeMat4(math.inverseMat4(this._scene.viewer.camera.viewMatrix, math.mat4()), cameraPos, math.vec4(), math.vec3()); - const length = math.distVec3(cameraPos, currentPos); - let radius = (Math.tan(Math.PI / 500) * length) * this._pivotSphereSize; - - if (this._scene.camera.projection == "ortho") { - radius /= (this._scene.camera.ortho.scale / 2); - } - - worldToRTCPos(currentPos, this._rtcCenter, this._rtcPos); - this._pivotSphereGeometry = new VBOGeometry( - this._scene, - buildSphereGeometry({ radius }) - ); - this._pivotSphere = new Mesh(this._scene, { - geometry: this._pivotSphereGeometry, - material: this._pivotSphereMaterial, - pickable: false, - position: this._rtcPos, - rtcCenter: this._rtcCenter - }); - }; - - destroyPivotSphere() { - if (this._pivotSphere) { - this._pivotSphere.destroy(); - this._pivotSphere = null; - } - if (this._pivotSphereGeometry) { - this._pivotSphereGeometry.destroy(); - this._pivotSphereGeometry = null; - } - } - - updatePivotElement() { - - const camera = this._scene.camera; - const canvas = this._scene.canvas; - - if (this._pivoting && this._cameraDirty) { - - math.transformPoint3(camera.viewMatrix, this.getPivotPos(), this._pivotViewPos); - this._pivotViewPos[3] = 1; - math.transformPoint4(camera.projMatrix, this._pivotViewPos, this._pivotProjPos); - - const canvasAABB = canvas.boundary; - const canvasWidth = canvasAABB[2]; - const canvasHeight = canvasAABB[3]; - - this._pivotCanvasPos[0] = Math.floor((1 + this._pivotProjPos[0] / this._pivotProjPos[3]) * canvasWidth / 2); - this._pivotCanvasPos[1] = Math.floor((1 - this._pivotProjPos[1] / this._pivotProjPos[3]) * canvasHeight / 2); - - // data-textures: avoid to do continuous DOM layout calculations - let canvasBoundingRect = canvas._lastBoundingClientRect; - - if (!canvasBoundingRect || canvas._canvasSizeChanged) - { - const canvasElem = canvas.canvas; - - canvasBoundingRect = canvas._lastBoundingClientRect = canvasElem.getBoundingClientRect (); - } - - if (this._pivotElement) { - this._pivotElement.style.left = (Math.floor(canvasBoundingRect.left + this._pivotCanvasPos[0]) - (this._pivotElement.clientWidth / 2) + window.scrollX) + "px"; - this._pivotElement.style.top = (Math.floor(canvasBoundingRect.top + this._pivotCanvasPos[1]) - (this._pivotElement.clientHeight / 2) + window.scrollY) + "px"; - } - this._cameraDirty = false; - } - } - - updatePivotSphere() { - if (this._pivoting && this._pivotSphere) { - worldToRTCPos(this.getPivotPos(), this._rtcCenter, this._rtcPos); - if(!math.compareVec3(this._rtcPos, this._pivotSphere.position)) { - this.destroyPivotSphere(); - this.createPivotSphere(); - } - } - } - /** - * Sets the HTML DOM element that will represent the pivot position. - * - * @param pivotElement - */ - setPivotElement(pivotElement) { - this._pivotElement = pivotElement; - } - - /** - * Sets a sphere as the representation of the pivot position. - * - * @param {Object} [cfg] Sphere configuration. - * @param {String} [cfg.size=1] Optional size factor of the sphere. Defaults to 1. - * @param {String} [cfg.color=Array] Optional maretial color. Defaults to a red. - */ - enablePivotSphere(cfg = {}) { - this.destroyPivotSphere(); - this._pivotSphereEnabled = true; - if (cfg.size) { - this._pivotSphereSize = cfg.size; - } - const color = cfg.color || [1, 0, 0]; - this._pivotSphereMaterial = new PhongMaterial(this._scene, { - emissive: color, - ambient: color, - specular: [0,0,0], - diffuse: [0,0,0], - }); - } - - /** - * Remove the sphere as the representation of the pivot position. - * - */ - disablePivotSphere() { - this.destroyPivotSphere(); - this._pivotSphereEnabled = false; - } - - /** - * Begins pivoting. - */ - startPivot() { - - const camera = this._scene.camera; - - let lookat = math.lookAtMat4v(camera.eye, camera.look, camera.up); - math.transformPoint3(lookat, this.getPivotPos(), this._cameraOffset); - - const pivotPos = this.getPivotPos(); - this._cameraOffset[2] += math.distVec3(camera.eye, pivotPos); - - lookat = math.inverseMat4(lookat); - - const offset = math.transformVec3(lookat, this._cameraOffset); - const diff = math.vec3(); - - math.subVec3(camera.eye, pivotPos, diff); - math.addVec3(diff, offset); - - if (camera.zUp) { - const t = diff[1]; - diff[1] = diff[2]; - diff[2] = t; - } - - this._radius = math.lenVec3(diff); - this._polar = Math.acos(diff[1] / this._radius); - this._azimuth = Math.atan2(diff[0], diff[2]); - this._pivoting = true; - } - - _cameraLookingDownwards() { // Returns true if angle between camera viewing direction and World-space "up" axis is too small - const camera = this._scene.camera; - const forwardAxis = math.normalizeVec3(math.subVec3(camera.look, camera.eye, tempVec3a$8)); - const rightAxis = math.cross3Vec3(forwardAxis, camera.worldUp, tempVec3b$5); - let rightAxisLen = math.sqLenVec3(rightAxis); - return (rightAxisLen <= 0.0001); - } - - /** - * Returns true if we are currently pivoting. - * - * @returns {Boolean} - */ - getPivoting() { - return this._pivoting; - } - - /** - * Sets a 3D World-space position to pivot about. - * - * @param {Number[]} worldPos The new World-space pivot position. - */ - setPivotPos(worldPos) { - this._pivotWorldPos.set(worldPos); - this._pivotPosSet = true; - } - - /** - * Sets the pivot position to the 3D projection of the given 2D canvas coordinates on a sphere centered - * at the viewpoint. The radius of the sphere is configured via {@link CameraControl#smartPivot}. - * - * - * @param canvasPos - */ - setCanvasPivotPos(canvasPos) { - const camera = this._scene.camera; - const pivotShereRadius = Math.abs(math.distVec3(this._scene.center, camera.eye)); - const transposedProjectMat = camera.project.transposedMatrix; - const Pt3 = transposedProjectMat.subarray(8, 12); - const Pt4 = transposedProjectMat.subarray(12); - const D = [0, 0, -1.0, 1]; - const screenZ = math.dotVec4(D, Pt3) / math.dotVec4(D, Pt4); - const worldPos = tempVec4a$5; - camera.project.unproject(canvasPos, screenZ, tempVec4b$5, tempVec4c, worldPos); - const eyeWorldPosVec = math.normalizeVec3(math.subVec3(worldPos, camera.eye, tempVec3a$8)); - const posOnSphere = math.addVec3(camera.eye, math.mulVec3Scalar(eyeWorldPosVec, pivotShereRadius, tempVec3b$5), tempVec3c$4); - this.setPivotPos(posOnSphere); - } - - /** - * Gets the current position we're pivoting about. - * @returns {Number[]} The current World-space pivot position. - */ - getPivotPos() { - return (this._pivotPosSet) ? this._pivotWorldPos : this._scene.camera.look; // Avoid pivoting about [0,0,0] by default - } - - /** - * Continues to pivot. - * - * @param {Number} yawInc Yaw rotation increment. - * @param {Number} pitchInc Pitch rotation increment. - */ - continuePivot(yawInc, pitchInc) { - if (!this._pivoting) { - return; - } - if (yawInc === 0 && pitchInc === 0) { - return; - } - const camera = this._scene.camera; - var dx = -yawInc; - const dy = -pitchInc; - if (camera.worldUp[2] === 1) { - dx = -dx; - } - this._azimuth += -dx * .01; - - const isMovingUp = dy < 0; - const isMovingDown = dy > 0; - - // Track if we're at limits - only check if we're very close to the limit - const atTopLimit = Math.abs(this._polar - TOP_LIMIT) < 0.005; - const atBottomLimit = Math.abs(this._polar - BOTTOM_LIMIT) < 0.005; - - let newPolar = this._polar + dy * .01; - - // Case 1: At top limit and trying to go beyond - if (atTopLimit && isMovingUp) { - newPolar = TOP_LIMIT; - } - // Case 2: At bottom limit and trying to go beyond - else if (atBottomLimit && isMovingDown) { - newPolar = BOTTOM_LIMIT; - } - // Case 3: Normal rotation or moving away from a limit - else { - newPolar = math.clamp(newPolar, TOP_LIMIT, BOTTOM_LIMIT); - } - - this._polar = newPolar; - - const pos = [ - this._radius * Math.sin(this._polar) * Math.sin(this._azimuth), - this._radius * Math.cos(this._polar), - this._radius * Math.sin(this._polar) * Math.cos(this._azimuth) - ]; - if (camera.worldUp[2] === 1) { - const t = pos[1]; - pos[1] = pos[2]; - pos[2] = t; - } - // Preserve the eye->look distance, since in xeokit "look" is the point-of-interest, not the direction vector. - const eyeLookLen = math.lenVec3(math.subVec3(camera.look, camera.eye, math.vec3())); - const pivotPos = this.getPivotPos(); - math.addVec3(pos, pivotPos); - let lookat = math.lookAtMat4v(pos, pivotPos, camera.worldUp); - lookat = math.inverseMat4(lookat); - const offset = math.transformVec3(lookat, this._cameraOffset); - lookat[12] -= offset[0]; - lookat[13] -= offset[1]; - lookat[14] -= offset[2]; - const zAxis = [lookat[8], lookat[9], lookat[10]]; - camera.eye = [lookat[12], lookat[13], lookat[14]]; - math.subVec3(camera.eye, math.mulVec3Scalar(zAxis, eyeLookLen), camera.look); - camera.up = [lookat[4], lookat[5], lookat[6]]; - this.showPivot(); - } - - /** - * Shows the pivot position. - * - * Only works if we set an HTML DOM element to represent the pivot position. - */ - showPivot() { - if (this._shown) { - return; - } - if (this._pivotElement) { - this.updatePivotElement(); - this._pivotElement.style.visibility = "visible"; - } - if (this._pivotSphereEnabled) { - this.destroyPivotSphere(); - this.createPivotSphere(); - } - this._shown = true; - } - - /** - * Hides the pivot position. - * - * Only works if we set an HTML DOM element to represent the pivot position. - */ - hidePivot() { - if (!this._shown) { - return; - } - if (this._pivotElement) { - this._pivotElement.style.visibility = "hidden"; - } - if (this._pivotSphereEnabled) { - this.destroyPivotSphere(); - } - this._shown = false; - } - - /** - * Finishes pivoting. - */ - endPivot() { - this._pivoting = false; - } - - destroy() { - this.destroyPivotSphere(); - this._scene.camera.off(this._onViewMatrix); - this._scene.camera.off(this._onProjMatrix); - this._scene.off(this._onTick); - } -} - -/** - * - * @private - */ -class PickController { - - constructor(cameraControl, configs) { - /** - * @type {Scene} - */ - this._scene = cameraControl.scene; - - this._cameraControl = cameraControl; - - this._scene.canvas.canvas.oncontextmenu = function (e) { - e.preventDefault(); - }; - - this._configs = configs; - - /** - * Set true to schedule picking of an Entity. - * @type {boolean} - */ - this.schedulePickEntity = false; - - /** - * Set true to schedule picking of a position on teh surface of an Entity. - * @type {boolean} - */ - this.schedulePickSurface = false; - - /** - * Set true to schedule snap-picking with surface picking as a fallback - used for measurement. - * @type {boolean} - */ - this.scheduleSnapOrPick = false; - - /** - * The canvas position at which to do the next scheduled pick. - * @type {Number[]} - */ - this.pickCursorPos = math.vec2(); - - /** - * Will be true after picking to indicate that something was picked. - * @type {boolean} - */ - this.picked = false; - - /** - * Will be true after picking to indicate that a position on the surface of an Entity was picked. - * @type {boolean} - */ - this.pickedSurface = false; - - /** - * Will hold the PickResult after after picking. - * @type {PickResult} - */ - this.pickResult = null; - - this._lastPickedEntityId = null; - - this._lastHash = null; - - this._needFireEvents = 0; - } - - /** - * Immediately attempts a pick, if scheduled. - */ - update() { - - if (!this._configs.pointerEnabled) { - return; - } - - if (!this.schedulePickEntity && !this.schedulePickSurface) { - return; - } - - const hash = `${~~this.pickCursorPos[0]}-${~~this.pickCursorPos[1]}-${this.scheduleSnapOrPick}-${this.schedulePickSurface}-${this.schedulePickEntity}`; - if (this._lastHash === hash) { - return; - } - - this.picked = false; - this.pickedSurface = false; - this.snappedOrPicked = false; - this.hoveredSnappedOrSurfaceOff = false; - - const hasHoverSurfaceSubs = this._cameraControl.hasSubs("hoverSurface"); - - if (this.scheduleSnapOrPick) { - const snapPickResult = this._scene.pick({ - canvasPos: this.pickCursorPos, - snapRadius: this._configs.snapRadius, - snapToVertex: this._configs.snapToVertex, - snapToEdge: this._configs.snapToEdge, - }); - if (snapPickResult && (snapPickResult.snappedToEdge || snapPickResult.snappedToVertex)) { - this.snapPickResult = snapPickResult; - this.snappedOrPicked = true; - this._needFireEvents++; - } else { - this.schedulePickSurface = true; // Fallback - this.snapPickResult = null; - } - } - - if (this.schedulePickSurface) { - if (this.pickResult && this.pickResult.worldPos) { - const pickResultCanvasPos = this.pickResult.canvasPos; - if (pickResultCanvasPos[0] === this.pickCursorPos[0] && pickResultCanvasPos[1] === this.pickCursorPos[1]) { - this.picked = true; - this.pickedSurface = true; - this._needFireEvents += hasHoverSurfaceSubs ? 1 : 0; - this.schedulePickEntity = false; - this.schedulePickSurface = false; - if (this.scheduleSnapOrPick) { - this.snappedOrPicked = true; - } else { - this.hoveredSnappedOrSurfaceOff = true; - } - this.scheduleSnapOrPick = false; - return; - } - } - } - - if (this.schedulePickEntity) { - if (this.pickResult && (this.pickResult.canvasPos || this.pickResult.snappedCanvasPos)) { - const pickResultCanvasPos = this.pickResult.canvasPos || this.pickResult.snappedCanvasPos; - if (pickResultCanvasPos[0] === this.pickCursorPos[0] && pickResultCanvasPos[1] === this.pickCursorPos[1]) { - this.picked = true; - this.pickedSurface = false; - this.schedulePickEntity = false; - this.schedulePickSurface = false; - return; - } - } - } - - if (this.schedulePickSurface || (this.scheduleSnapOrPick && !this.snapPickResult)) { - this.pickResult = this._scene.pick({ - pickSurface: true, - pickSurfaceNormal: false, - canvasPos: this.pickCursorPos - }); - if (this.pickResult) { - this.picked = true; - if (this.scheduleSnapOrPick) { - this.snappedOrPicked = true; - } else { - this.pickedSurface = true; - } - this._needFireEvents++; - } else if (this.scheduleSnapOrPick) { - this.hoveredSnappedOrSurfaceOff = true; - this._needFireEvents++; - } - - } else { // schedulePickEntity == true - - this.pickResult = this._scene.pick({ - canvasPos: this.pickCursorPos - }); - - if (this.pickResult) { - this.picked = true; - this.pickedSurface = false; - this._needFireEvents++; - } - } - - this.scheduleSnapOrPick = false; - this.schedulePickEntity = false; - this.schedulePickSurface = false; - } - - fireEvents() { - - if (this._needFireEvents === 0) { - return; - } - - if (this.hoveredSnappedOrSurfaceOff) { - this._cameraControl.fire("hoverSnapOrSurfaceOff", { - canvasPos: this.pickCursorPos, - pointerPos : this.pickCursorPos - }, true); - } - - if (this.snappedOrPicked) { - if (this.snapPickResult) { - const pickResult = new PickResult(); - pickResult.entity = this.snapPickResult.entity; - pickResult.snappedToVertex = this.snapPickResult.snappedToVertex; - pickResult.snappedToEdge = this.snapPickResult.snappedToEdge; - pickResult.worldPos = this.snapPickResult.worldPos; - pickResult.canvasPos = this.pickCursorPos; - pickResult.snappedCanvasPos = this.snapPickResult.snappedCanvasPos; - this._cameraControl.fire("hoverSnapOrSurface", pickResult, true); - this.snapPickResult = null; - } else { - this._cameraControl.fire("hoverSnapOrSurface", this.pickResult, true); - } - } - - if (this.picked && this.pickResult && (this.pickResult.entity || this.pickResult.worldPos)) { - - if (this.pickResult.entity) { - - const pickedEntityId = this.pickResult.entity.id; - - if (this._lastPickedEntityId !== pickedEntityId) { - - if (this._lastPickedEntityId !== undefined) { - this._cameraControl.fire("hoverOut", { - entity: this._scene.objects[this._lastPickedEntityId] - }, true); - } - - this._cameraControl.fire("hoverEnter", this.pickResult, true); - this._lastPickedEntityId = pickedEntityId; - } - } - - this._cameraControl.fire("hover", this.pickResult, true); - - if (this.pickResult.worldPos) { - this.pickedSurface = true; - this._cameraControl.fire("hoverSurface", this.pickResult, true); - } - - } else { - - if (this._lastPickedEntityId !== undefined) { - this._cameraControl.fire("hoverOut", { - entity: this._scene.objects[this._lastPickedEntityId] - }, true); - this._lastPickedEntityId = undefined; - } - - this._cameraControl.fire("hoverOff", { - canvasPos: this.pickCursorPos - }, true); - } - - this.pickResult = null; - - this._needFireEvents = 0; - } -} - -/** - * @private - */ - -const canvasPos = math.vec2(); - -const getCanvasPosFromEvent$3 = function(event, canvas, canvasPos) { - if (!event) { - event = window.event; - canvasPos[0] = event.x; - canvasPos[1] = event.y; - } else { - const canvasRect = canvas.getBoundingClientRect(); - canvasPos[0] = event.clientX - canvasRect.left; - canvasPos[1] = event.clientY - canvasRect.top; - } - return canvasPos; -}; - -/** - * @private - */ -class MousePanRotateDollyHandler { - - constructor(scene, controllers, configs, states, updates) { - - this._scene = scene; - - const pickController = controllers.pickController; - const cameraControl = controllers.cameraControl; - - let lastX = 0; - let lastY = 0; - let lastXDown = 0; - let lastYDown = 0; - - let mouseDownLeft; - let mouseDownMiddle; - let mouseDownRight; - - let mouseDownPicked = false; - const pickedWorldPos = math.vec3(); - - let mouseMovedOnCanvasSinceLastWheel = true; - - const canvas = this._scene.canvas.canvas; - - const keyDown = []; - - document.addEventListener("keydown", this._documentKeyDownHandler = (e) => { - if (!(configs.active && configs.pointerEnabled) || (!scene.input.keyboardEnabled)) { - return; - } - const keyCode = e.keyCode; - keyDown[keyCode] = true; - }); - - document.addEventListener("keyup", this._documentKeyUpHandler = (e) => { - if (!(configs.active && configs.pointerEnabled) || (!scene.input.keyboardEnabled)) { - return; - } - const keyCode = e.keyCode; - keyDown[keyCode] = false; - }); - - document.addEventListener("visibilitychange", this._onVisibilityChange = () => { - keyDown.splice(0); - }); - - window.addEventListener("blur", this._onBlur = () => { - keyDown.splice(0); - }); - - function setMousedownState(pick = true) { - setMousedownPositions(); - if (pick) { - setMousedownPick(); - } - } - - function setMousedownPositions() { - - lastX = states.pointerCanvasPos[0]; - lastY = states.pointerCanvasPos[1]; - lastXDown = states.pointerCanvasPos[0]; - lastYDown = states.pointerCanvasPos[1]; - } - - function setMousedownPick() { - pickController.pickCursorPos = states.pointerCanvasPos; - pickController.schedulePickSurface = true; - pickController.update(); - - if (pickController.picked && pickController.pickedSurface && pickController.pickResult && pickController.pickResult.worldPos) { - mouseDownPicked = true; - pickedWorldPos.set(pickController.pickResult.worldPos); - } else { - mouseDownPicked = false; - } - } - - function isPanning() { - return configs.planView || cameraControl._isKeyDownForAction(cameraControl.MOUSE_PAN, keyDown); - } - - function isRotating() { - return cameraControl._isKeyDownForAction(cameraControl.MOUSE_ROTATE, keyDown); - } - - - canvas.addEventListener("mousedown", this._mouseDownHandler = (e) => { - - if (!(configs.active && configs.pointerEnabled)) { - return; - } - - switch (e.which) { - - case 1: // Left button - - if (keyDown[scene.input.KEY_SHIFT] || configs.planView) { - - mouseDownLeft = true; - keyDown[scene.input.MOUSE_LEFT_BUTTON] = true; - - setMousedownState(); - - } else { - - mouseDownLeft = true; - keyDown[scene.input.MOUSE_LEFT_BUTTON] = true; - - setMousedownState(false); - } - - break; - - case 2: // Middle/both buttons - - mouseDownMiddle = true; - keyDown[scene.input.MOUSE_MIDDLE_BUTTON] = true; - - setMousedownState(); - - break; - - case 3: // Right button - - mouseDownRight = true; - keyDown[scene.input.MOUSE_RIGHT_BUTTON] = true; - - if (configs.panRightClick) { - - setMousedownState(); - } - - break; - } - }); - - document.addEventListener("mousemove", this._documentMouseMoveHandler = (e) => { - - if (!(configs.active && configs.pointerEnabled)) { - return; - } - - if (!mouseDownLeft && !mouseDownMiddle && !mouseDownRight) { - return; - } - - // Scaling drag-rotate to canvas boundary - - const canvasBoundary = scene.canvas.boundary; - - const canvasWidth = canvasBoundary[2]; - const canvasHeight = canvasBoundary[3]; - const x = states.pointerCanvasPos[0]; - const y = states.pointerCanvasPos[1]; - - const panning = isPanning(); - const rotating = isRotating(); - - const xDelta = document.pointerLockElement ? e.movementX : (x - lastX); - const yDelta = document.pointerLockElement ? e.movementY : (y - lastY); - - if (panning) { - - const camera = scene.camera; - - // We use only canvasHeight here so that aspect ratio does not distort speed - - if (camera.projection === "perspective") { - - const depth = Math.abs(mouseDownPicked ? math.lenVec3(math.subVec3(pickedWorldPos, scene.camera.eye, [])) : scene.camera.eyeLookDist); - const targetDistance = depth * Math.tan((camera.perspective.fov / 2) * Math.PI / 180.0); - - updates.panDeltaX += (1.5 * xDelta * targetDistance / canvasHeight); - updates.panDeltaY += (1.5 * yDelta * targetDistance / canvasHeight); - - } else { - - updates.panDeltaX += 0.5 * camera.ortho.scale * (xDelta / canvasHeight); - updates.panDeltaY += 0.5 * camera.ortho.scale * (yDelta / canvasHeight); - } - - } else if (rotating) { - - if (!configs.planView) { // No rotating in plan-view mode - - if (configs.firstPerson) { - updates.rotateDeltaY -= (xDelta / canvasWidth) * configs.dragRotationRate / 2; - updates.rotateDeltaX += (yDelta / canvasHeight) * (configs.dragRotationRate / 4); - - } else { - updates.rotateDeltaY -= (xDelta / canvasWidth) * (configs.dragRotationRate * 1.5); - updates.rotateDeltaX += (yDelta / canvasHeight) * (configs.dragRotationRate * 1.5); - } - } - } - - lastX = x; - lastY = y; - }); - - canvas.addEventListener("mousemove", this._canvasMouseMoveHandler = (e) => { - - if (!(configs.active && configs.pointerEnabled)) { - return; - } - - if (!states.mouseover) { - return; - } - - mouseMovedOnCanvasSinceLastWheel = true; - }); - - document.addEventListener("mouseup", this._documentMouseUpHandler = (e) => { - if (!(configs.active && configs.pointerEnabled)) { - return; - } - switch (e.which) { - case 1: // Left button - mouseDownLeft = false; - mouseDownMiddle = false; - mouseDownRight = false; - keyDown[scene.input.MOUSE_LEFT_BUTTON] = false; - keyDown[scene.input.MOUSE_MIDDLE_BUTTON] = false; - keyDown[scene.input.MOUSE_RIGHT_BUTTON] = false; - break; - case 2: // Middle/both buttons - mouseDownLeft = false; - mouseDownMiddle = false; - mouseDownRight = false; - keyDown[scene.input.MOUSE_LEFT_BUTTON] = false; - keyDown[scene.input.MOUSE_MIDDLE_BUTTON] = false; - keyDown[scene.input.MOUSE_RIGHT_BUTTON] = false; - break; - case 3: // Right button - mouseDownLeft = false; - mouseDownMiddle = false; - mouseDownRight = false; - keyDown[scene.input.MOUSE_LEFT_BUTTON] = false; - keyDown[scene.input.MOUSE_MIDDLE_BUTTON] = false; - keyDown[scene.input.MOUSE_RIGHT_BUTTON] = false; - break; - } - }); - - canvas.addEventListener("mouseup", this._mouseUpHandler = (e) => { - if (!(configs.active && configs.pointerEnabled)) { - return; - } - switch (e.which) { - case 3: // Right button - getCanvasPosFromEvent$3(e, canvas, canvasPos); - const x = canvasPos[0]; - const y = canvasPos[1]; - if (Math.abs(x - lastXDown) < 3 && Math.abs(y - lastYDown) < 3) { - controllers.cameraControl.fire("rightClick", { // For context menus - pagePos: [Math.round(e.pageX), Math.round(e.pageY)], - canvasPos: canvasPos, - event: e - }, true); - } - break; - } - canvas.style.removeProperty("cursor"); - }); - - canvas.addEventListener("mouseenter", this._mouseEnterHandler = () => { - if (!(configs.active && configs.pointerEnabled)) { - return; - } - }); - - const maxElapsed = 1 / 20; - const minElapsed = 1 / 60; - - let secsNowLast = null; - - canvas.addEventListener("wheel", this._mouseWheelHandler = (e) => { - if (!(configs.active && configs.pointerEnabled && configs.zoomOnMouseWheel && cameraControl._isKeyDownForAction(cameraControl.MOUSE_DOLLY, keyDown))) { - return; - } - const secsNow = performance.now() / 1000.0; - var secsElapsed = (secsNowLast !== null) ? (secsNow - secsNowLast) : 0; - secsNowLast = secsNow; - if (secsElapsed > maxElapsed) { - secsElapsed = maxElapsed; - } - if (secsElapsed < minElapsed) { - secsElapsed = minElapsed; - } - const delta = Math.max(-1, Math.min(1, -e.deltaY * 40)); - if (delta === 0) { - return; - } - const normalizedDelta = delta / Math.abs(delta); - updates.dollyDelta += -normalizedDelta * secsElapsed * configs.mouseWheelDollyRate; - - if (mouseMovedOnCanvasSinceLastWheel) { - if ((states.pointerCanvasPos[0] === 0) && (states.pointerCanvasPos[1] === 0)) { - // Dirty fix to initiate states.pointerCanvasPos if a wheel over an empty space is the first action in a scene - getCanvasPosFromEvent$3(e, canvas, states.pointerCanvasPos); // Added to fix XCD-386: The zoom speed slows down when zooming into an empty space for the first time on a relatively large model, and it cannot be reset without reloading - } - states.followPointerDirty = true; - mouseMovedOnCanvasSinceLastWheel = false; - } - - }, {passive: true}); - } - - reset() { - } - - destroy() { - - const canvas = this._scene.canvas.canvas; - - document.removeEventListener("keydown", this._documentKeyDownHandler); - document.removeEventListener("keyup", this._documentKeyUpHandler); - document.removeEventListener("visibilitychange", this._onVisibilityChange); - window.removeEventListener("blur", this._onBlur); - canvas.removeEventListener("mousedown", this._mouseDownHandler); - document.removeEventListener("mousemove", this._documentMouseMoveHandler); - canvas.removeEventListener("mousemove", this._canvasMouseMoveHandler); - document.removeEventListener("mouseup", this._documentMouseUpHandler); - canvas.removeEventListener("mouseup", this._mouseUpHandler); - canvas.removeEventListener("mouseenter", this._mouseEnterHandler); - canvas.removeEventListener("wheel", this._mouseWheelHandler); - } -} - -const center = math.vec3(); -const tempVec3a$7 = math.vec3(); -const tempVec3b$4 = math.vec3(); -const tempVec3c$3 = math.vec3(); -const tempVec3d = math.vec3(); - -const tempCameraTarget = { - eye: math.vec3(), - look: math.vec3(), - up: math.vec3() -}; - -/** - * @private - */ -class KeyboardAxisViewHandler { - - constructor(scene, controllers, configs, states) { - - this._scene = scene; - const cameraControl = controllers.cameraControl; - const camera = scene.camera; - - this._onSceneKeyDown = scene.input.on("keydown", () => { - - if (!(configs.active && configs.pointerEnabled) || (!scene.input.keyboardEnabled)) { - return; - } - - if (configs.keyboardEnabledOnlyIfMouseover && !states.mouseover) { - return; - } - - const axisViewRight = cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_RIGHT); - const axisViewBack = cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_BACK); - const axisViewLeft = cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_LEFT); - const axisViewFront = cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_FRONT); - const axisViewTop = cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_TOP); - const axisViewBottom = cameraControl._isKeyDownForAction(cameraControl.AXIS_VIEW_BOTTOM); - - if ((!axisViewRight) && (!axisViewBack) && (!axisViewLeft) && (!axisViewFront) && (!axisViewTop) && (!axisViewBottom)) { - return; - } - - const aabb = scene.aabb; - const diag = math.getAABB3Diag(aabb); - - math.getAABB3Center(aabb, center); - - const perspectiveDist = Math.abs(diag / Math.tan(controllers.cameraFlight.fitFOV * math.DEGTORAD)); - const orthoScale = diag * 1.1; - - tempCameraTarget.orthoScale = orthoScale; - - if (axisViewRight) { - - tempCameraTarget.eye.set(math.addVec3(center, math.mulVec3Scalar(camera.worldRight, perspectiveDist, tempVec3a$7), tempVec3d)); - tempCameraTarget.look.set(center); - tempCameraTarget.up.set(camera.worldUp); - - } else if (axisViewBack) { - - tempCameraTarget.eye.set(math.addVec3(center, math.mulVec3Scalar(camera.worldForward, perspectiveDist, tempVec3a$7), tempVec3d)); - tempCameraTarget.look.set(center); - tempCameraTarget.up.set(camera.worldUp); - - } else if (axisViewLeft) { - - tempCameraTarget.eye.set(math.addVec3(center, math.mulVec3Scalar(camera.worldRight, -perspectiveDist, tempVec3a$7), tempVec3d)); - tempCameraTarget.look.set(center); - tempCameraTarget.up.set(camera.worldUp); - - } else if (axisViewFront) { - - tempCameraTarget.eye.set(math.addVec3(center, math.mulVec3Scalar(camera.worldForward, -perspectiveDist, tempVec3a$7), tempVec3d)); - tempCameraTarget.look.set(center); - tempCameraTarget.up.set(camera.worldUp); - - } else if (axisViewTop) { - - tempCameraTarget.eye.set(math.addVec3(center, math.mulVec3Scalar(camera.worldUp, perspectiveDist, tempVec3a$7), tempVec3d)); - tempCameraTarget.look.set(center); - tempCameraTarget.up.set(math.normalizeVec3(math.mulVec3Scalar(camera.worldForward, 1, tempVec3b$4), tempVec3c$3)); - - } else if (axisViewBottom) { - - tempCameraTarget.eye.set(math.addVec3(center, math.mulVec3Scalar(camera.worldUp, -perspectiveDist, tempVec3a$7), tempVec3d)); - tempCameraTarget.look.set(center); - tempCameraTarget.up.set(math.normalizeVec3(math.mulVec3Scalar(camera.worldForward, -1, tempVec3b$4))); - } - - if ((!configs.firstPerson) && configs.followPointer) { - controllers.pivotController.setPivotPos(center); - } - - if (controllers.cameraFlight.duration > 0) { - controllers.cameraFlight.flyTo(tempCameraTarget, () => { - if (controllers.pivotController.getPivoting() && configs.followPointer) { - controllers.pivotController.showPivot(); - } - }); - - } else { - controllers.cameraFlight.jumpTo(tempCameraTarget); - if (controllers.pivotController.getPivoting() && configs.followPointer) { - controllers.pivotController.showPivot(); - } - } - }); - } - - reset() { - } - - destroy() { - this._scene.input.off(this._onSceneKeyDown); - } -} - -/** - * @private - */ -class MousePickHandler { - - constructor(scene, controllers, configs, states, updates) { - - this._scene = scene; - - const pickController = controllers.pickController; - const pivotController = controllers.pivotController; - const cameraControl = controllers.cameraControl; - - this._clicks = 0; - this._timeout = null; - this._lastPickedEntityId = null; - this._lastClickedWorldPos = null; - - let leftDown = false; - let rightDown = false; - - const canvas = this._scene.canvas.canvas; - - const flyCameraTo = (pickResult) => { - let pos; - if (pickResult && pickResult.worldPos) { - pos = pickResult.worldPos; - } - const aabb = pickResult && pickResult.entity ? pickResult.entity.aabb : scene.aabb; - if (pos) { // Fly to look at point, don't change eye->look dist - const camera = scene.camera; - math.subVec3(camera.eye, camera.look, []); - controllers.cameraFlight.flyTo({ - // look: pos, - // eye: xeokit.math.addVec3(pos, diff, []), - // up: camera.up, - aabb: aabb - }); - // TODO: Option to back off to fit AABB in view - } else {// Fly to fit target boundary in view - controllers.cameraFlight.flyTo({ - aabb: aabb - }); - } - }; - - const tickifiedMouseMoveFn = scene.tickify ( - this._canvasMouseMoveHandler = (e) => { - if (!(configs.active && configs.pointerEnabled)) { - return; - } - - if (leftDown || rightDown) { - return; - } - - if (cameraControl.hasSubs("rayMove")) - { - const origin = math.vec3(); - const direction = math.vec3(); - math.canvasPosToWorldRay(scene.canvas.canvas, scene.camera.viewMatrix, scene.camera.projMatrix, scene.camera.projection, states.pointerCanvasPos, origin, direction); - cameraControl.fire("rayMove", { canvasPos: states.pointerCanvasPos, ray: { origin: origin, direction: direction, canvasPos: states.pointerCanvasPos } }, true); - } - - const hoverSubs = cameraControl.hasSubs("hover"); - const hoverEnterSubs = cameraControl.hasSubs("hoverEnter"); - const hoverOutSubs = cameraControl.hasSubs("hoverOut"); - const hoverOffSubs = cameraControl.hasSubs("hoverOff"); - const hoverSurfaceSubs = cameraControl.hasSubs("hoverSurface"); - const hoverSnapOrSurfaceSubs = cameraControl.hasSubs("hoverSnapOrSurface"); - - if (hoverSubs || hoverEnterSubs || hoverOutSubs || hoverOffSubs || hoverSurfaceSubs || hoverSnapOrSurfaceSubs) { - - pickController.pickCursorPos = states.pointerCanvasPos; - pickController.schedulePickEntity = true; - pickController.schedulePickSurface = hoverSurfaceSubs; - pickController.scheduleSnapOrPick = hoverSnapOrSurfaceSubs; - - pickController.update(); - - if (pickController.pickResult) { - - if (pickController.pickResult.entity) { - const pickedEntityId = pickController.pickResult.entity.id; - - if (this._lastPickedEntityId !== pickedEntityId) { - - if (this._lastPickedEntityId !== undefined) { - - cameraControl.fire("hoverOut", { // Hovered off an entity - entity: scene.objects[this._lastPickedEntityId] - }, true); - } - - cameraControl.fire("hoverEnter", pickController.pickResult, true); // Hovering over a new entity - - this._lastPickedEntityId = pickedEntityId; - } - } - - cameraControl.fire("hover", pickController.pickResult, true); - - if (pickController.pickResult.worldPos || pickController.pickResult.snappedWorldPos) { // Hovering the surface of an entity - cameraControl.fire("hoverSurface", pickController.pickResult, true); - } - - } else { - - if (this._lastPickedEntityId !== undefined) { - - cameraControl.fire("hoverOut", { // Hovered off an entity - entity: scene.objects[this._lastPickedEntityId] - }, true); - - this._lastPickedEntityId = undefined; - } - - cameraControl.fire("hoverOff", { // Not hovering on any entity - canvasPos: pickController.pickCursorPos - }, true); - } - } - } - ); - - canvas.addEventListener("mousemove", tickifiedMouseMoveFn); - - canvas.addEventListener('mousedown', this._canvasMouseDownHandler = (e) => { - - if (e.which === 1) { - leftDown = true; - } - - if (e.which === 3) { - rightDown = true; - } - - const leftButtonDown = (e.which === 1); - - if (!leftButtonDown) { - return; - } - - if (!(configs.active && configs.pointerEnabled)) { - return; - } - - // Left mouse button down to start pivoting - - states.mouseDownClientX = e.clientX; - states.mouseDownClientY = e.clientY; - states.mouseDownCursorX = states.pointerCanvasPos[0]; - states.mouseDownCursorY = states.pointerCanvasPos[1]; - - if ((!configs.firstPerson) && configs.followPointer) { - - pickController.pickCursorPos = states.pointerCanvasPos; - pickController.schedulePickSurface = true; - - pickController.update(); - - if (e.which === 1) {// Left button - const pickResult = pickController.pickResult; - if (pickResult && pickResult.worldPos) { - pivotController.setPivotPos(pickResult.worldPos); - pivotController.startPivot(); - this._lastClickedWorldPos = pickResult.worldPos.slice(); - } else { - if (configs.smartPivot) { - pivotController.setCanvasPivotPos(states.pointerCanvasPos); - } else { - if (this._lastClickedWorldPos) { - pivotController.setPivotPos(this._lastClickedWorldPos); - } else { - pivotController.setPivotPos(scene.camera.look); - } - } - pivotController.startPivot(); - } - } - } - }); - - document.addEventListener('mouseup', this._documentMouseUpHandler = (e) => { - - if (e.which === 1) { - leftDown = false; - } - - if (e.which === 3) { - rightDown = false; - } - - if (pivotController.getPivoting()) { - pivotController.endPivot(); - } - }); - - canvas.addEventListener('mouseup', this._canvasMouseUpHandler = (e) => { - - if (!(configs.active && configs.pointerEnabled)) { - return; - } - - const leftButtonUp = (e.which === 1); - - if (!leftButtonUp) { - return; - } - - // Left mouse button up to possibly pick or double-pick - - pivotController.hidePivot(); - - if (Math.abs(e.clientX - states.mouseDownClientX) > 3 || Math.abs(e.clientY - states.mouseDownClientY) > 3) { - return; - } - - const pickedSubs = cameraControl.hasSubs("picked"); - const pickedNothingSubs = cameraControl.hasSubs("pickedNothing"); - const pickedSurfaceSubs = cameraControl.hasSubs("pickedSurface"); - const doublePickedSubs = cameraControl.hasSubs("doublePicked"); - const doublePickedSurfaceSubs = cameraControl.hasSubs("doublePickedSurface"); - const doublePickedNothingSubs = cameraControl.hasSubs("doublePickedNothing"); - - if ((!configs.doublePickFlyTo) && - (!doublePickedSubs) && - (!doublePickedSurfaceSubs) && - (!doublePickedNothingSubs)) { - - // Avoid the single/double click differentiation timeout - - if (pickedSubs || pickedNothingSubs || pickedSurfaceSubs) { - - pickController.pickCursorPos = states.pointerCanvasPos; - pickController.schedulePickEntity = true; - pickController.schedulePickSurface = pickedSurfaceSubs; - pickController.update(); - - if (pickController.pickResult) { - - cameraControl.fire("picked", pickController.pickResult, true); - - if (pickController.pickedSurface) { - cameraControl.fire("pickedSurface", pickController.pickResult, true); - } - } else { - cameraControl.fire("pickedNothing", { - canvasPos: states.pointerCanvasPos - }, true); - } - } - - this._clicks = 0; - - return; - } - - this._clicks++; - - if (this._clicks === 1) { // First click - - pickController.pickCursorPos = states.pointerCanvasPos; - pickController.schedulePickEntity = configs.doublePickFlyTo; - pickController.schedulePickSurface = pickedSurfaceSubs; - pickController.update(); - - const firstClickPickResult = pickController.pickResult; - const firstClickPickSurface = pickController.pickedSurface; - - this._timeout = setTimeout(() => { - - if (firstClickPickResult) { - - cameraControl.fire("picked", firstClickPickResult, true); - - if (firstClickPickSurface) { - - cameraControl.fire("pickedSurface", firstClickPickResult, true); - - if ((!configs.firstPerson) && configs.followPointer) { - controllers.pivotController.setPivotPos(firstClickPickResult.worldPos); - if (controllers.pivotController.startPivot()) { - controllers.pivotController.showPivot(); - } - } - } - } else { - cameraControl.fire("pickedNothing", { - canvasPos: states.pointerCanvasPos - }, true); - } - - this._clicks = 0; - - }, configs.doubleClickTimeFrame); - - } else { // Second click - - if (this._timeout !== null) { - window.clearTimeout(this._timeout); - this._timeout = null; - } - - pickController.pickCursorPos = states.pointerCanvasPos; - pickController.schedulePickEntity = configs.doublePickFlyTo || doublePickedSubs || doublePickedSurfaceSubs; - pickController.schedulePickSurface = pickController.schedulePickEntity && doublePickedSurfaceSubs; - pickController.update(); - - if (pickController.pickResult) { - - cameraControl.fire("doublePicked", pickController.pickResult, true); - - if (pickController.pickedSurface) { - cameraControl.fire("doublePickedSurface", pickController.pickResult, true); - } - - if (configs.doublePickFlyTo) { - - flyCameraTo(pickController.pickResult); - - if ((!configs.firstPerson) && configs.followPointer) { - - const pickedEntityAABB = pickController.pickResult.entity.aabb; - const pickedEntityCenterPos = math.getAABB3Center(pickedEntityAABB); - - controllers.pivotController.setPivotPos(pickedEntityCenterPos); - - if (controllers.pivotController.startPivot()) { - controllers.pivotController.showPivot(); - } - } - } - - } else { - - cameraControl.fire("doublePickedNothing", { - canvasPos: states.pointerCanvasPos - }, true); - - if (configs.doublePickFlyTo) { - - flyCameraTo(); - - if ((!configs.firstPerson) && configs.followPointer) { - - const sceneAABB = scene.aabb; - const sceneCenterPos = math.getAABB3Center(sceneAABB); - - controllers.pivotController.setPivotPos(sceneCenterPos); - - if (controllers.pivotController.startPivot()) { - controllers.pivotController.showPivot(); - } - } - } - } - - this._clicks = 0; - } - }, false); - } - - reset() { - this._clicks = 0; - this._lastPickedEntityId = null; - if (this._timeout) { - window.clearTimeout(this._timeout); - this._timeout = null; - } - } - - destroy() { - const canvas = this._scene.canvas.canvas; - canvas.removeEventListener("mousemove", this._canvasMouseMoveHandler); - canvas.removeEventListener("mousedown", this._canvasMouseDownHandler); - document.removeEventListener("mouseup", this._documentMouseUpHandler); - canvas.removeEventListener("mouseup", this._canvasMouseUpHandler); - if (this._timeout) { - window.clearTimeout(this._timeout); - this._timeout = null; - } - } -} - -/** - * @private - */ -class KeyboardPanRotateDollyHandler { - - constructor(scene, controllers, configs, states, updates) { - - this._scene = scene; - const input = scene.input; - - const keyDownMap = []; - - scene.canvas.canvas; - - let mouseMovedSinceLastKeyboardDolly = true; - - this._onSceneMouseMove = input.on("mousemove", () => { - mouseMovedSinceLastKeyboardDolly = true; - }); - - this._onSceneKeyDown = input.on("keydown", (keyCode) => { - if (!(configs.active && configs.pointerEnabled) || (!scene.input.keyboardEnabled)) { - return; - } - if (configs.keyboardEnabledOnlyIfMouseover && !states.mouseover) { - return; - } - keyDownMap[keyCode] = true; - }); - - this._onSceneKeyUp = input.on("keyup", (keyCode) => { - if (!(configs.active && configs.pointerEnabled) || (!scene.input.keyboardEnabled)) { - return; - } - keyDownMap[keyCode] = false; - - if (controllers.pivotController.getPivoting()) { - controllers.pivotController.endPivot(); - } - }); - - document.addEventListener("visibilitychange", this._onVisibilityChange = () => { - keyDownMap.splice(0); - }); - - window.addEventListener("blur", this._onBlur = () => { - keyDownMap.splice(0); - }); - - this._onTick = scene.on("tick", (e) => { - - if (!(configs.active && configs.pointerEnabled) || (!scene.input.keyboardEnabled)) { - return; - } - - if (configs.keyboardEnabledOnlyIfMouseover && !states.mouseover) { - return; - } - - const cameraControl = controllers.cameraControl; - const elapsedSecs = (e.deltaTime / 1000.0); - - //------------------------------------------------------------------------------------------------- - // Keyboard rotation - //------------------------------------------------------------------------------------------------- - - if (!configs.planView) { - - const rotateYPos = cameraControl._isKeyDownForAction(cameraControl.ROTATE_Y_POS, keyDownMap); - const rotateYNeg = cameraControl._isKeyDownForAction(cameraControl.ROTATE_Y_NEG, keyDownMap); - const rotateXPos = cameraControl._isKeyDownForAction(cameraControl.ROTATE_X_POS, keyDownMap); - const rotateXNeg = cameraControl._isKeyDownForAction(cameraControl.ROTATE_X_NEG, keyDownMap); - - const orbitDelta = elapsedSecs * configs.keyboardRotationRate; - - if (rotateYPos || rotateYNeg || rotateXPos || rotateXNeg) { - - if ((!configs.firstPerson) && configs.followPointer) { - controllers.pivotController.startPivot(); - } - - if (rotateYPos) { - updates.rotateDeltaY += orbitDelta; - - } else if (rotateYNeg) { - updates.rotateDeltaY -= orbitDelta; - } - - if (rotateXPos) { - updates.rotateDeltaX += orbitDelta; - - } else if (rotateXNeg) { - updates.rotateDeltaX -= orbitDelta; - } - - if ((!configs.firstPerson) && configs.followPointer) { - controllers.pivotController.startPivot(); - } - } - } - - //------------------------------------------------------------------------------------------------- - // Keyboard panning - //------------------------------------------------------------------------------------------------- - - if (!keyDownMap[input.KEY_CTRL] && !keyDownMap[input.KEY_ALT]) { - - const dollyBackwards = cameraControl._isKeyDownForAction(cameraControl.DOLLY_BACKWARDS, keyDownMap); - const dollyForwards = cameraControl._isKeyDownForAction(cameraControl.DOLLY_FORWARDS, keyDownMap); - - if (dollyBackwards || dollyForwards) { - - const dollyDelta = elapsedSecs * configs.keyboardDollyRate; - - if ((!configs.firstPerson) && configs.followPointer) { - controllers.pivotController.startPivot(); - } - if (dollyForwards) { - updates.dollyDelta -= dollyDelta; - } else if (dollyBackwards) { - updates.dollyDelta += dollyDelta; - } - - if (mouseMovedSinceLastKeyboardDolly) { - states.followPointerDirty = true; - mouseMovedSinceLastKeyboardDolly = false; - } - } - } - - const panForwards = cameraControl._isKeyDownForAction(cameraControl.PAN_FORWARDS, keyDownMap); - const panBackwards = cameraControl._isKeyDownForAction(cameraControl.PAN_BACKWARDS, keyDownMap); - const panLeft = cameraControl._isKeyDownForAction(cameraControl.PAN_LEFT, keyDownMap); - const panRight = cameraControl._isKeyDownForAction(cameraControl.PAN_RIGHT, keyDownMap); - const panUp = cameraControl._isKeyDownForAction(cameraControl.PAN_UP, keyDownMap); - const panDown = cameraControl._isKeyDownForAction(cameraControl.PAN_DOWN, keyDownMap); - - const panDelta = (keyDownMap[input.KEY_ALT] ? 0.3 : 1.0) * elapsedSecs * configs.keyboardPanRate; // ALT for slower pan rate - - if (panForwards || panBackwards || panLeft || panRight || panUp || panDown) { - - if ((!configs.firstPerson) && configs.followPointer) { - controllers.pivotController.startPivot(); - } - - if (panDown) { - updates.panDeltaY += panDelta; - - } else if (panUp) { - updates.panDeltaY += -panDelta; - } - - if (panRight) { - updates.panDeltaX += -panDelta; - - } else if (panLeft) { - updates.panDeltaX += panDelta; - } - - if (panBackwards) { - updates.panDeltaZ += panDelta; - - } else if (panForwards) { - updates.panDeltaZ += -panDelta; - } - } - }); - } - - reset() { - } - - destroy() { - - this._scene.off(this._onTick); - - this._scene.input.off(this._onSceneMouseMove); - this._scene.input.off(this._onSceneKeyDown); - document.removeEventListener("visibilitychange", this._onVisibilityChange); - window.removeEventListener("blur", this._onBlur); - this._scene.input.off(this._onSceneKeyUp); - } -} - -const SCALE_DOLLY_EACH_FRAME = 1; // Recalculate dolly speed for eye->target distance on each Nth frame -const EPSILON = 0.001; -const tempVec3$3 = math.vec3(); - -/** - * Handles camera updates on each "tick" that were scheduled by the various controllers. - * - * @private - */ -class CameraUpdater { - - constructor(scene, controllers, configs, states, updates) { - - this._scene = scene; - const camera = scene.camera; - const pickController = controllers.pickController; - const pivotController = controllers.pivotController; - const panController = controllers.panController; - const cameraControl = controllers.cameraControl; - - let countDown = SCALE_DOLLY_EACH_FRAME; // Decrements on each tick - let dollyDistFactor = 1.0; // Calculated when countDown is zero - let followPointerWorldPos = null; // Holds the pointer's World position when configs.followPointer is true - - this._onTick = scene.on("tick", () => { - - if (!(configs.active && configs.pointerEnabled)) { - return; - } - - let cursorType = "default"; - - //---------------------------------------------------------------------------------------------------------- - // Dolly decay - //------------------------------------------------------------------------------------ ---------------------- - - if (Math.abs(updates.dollyDelta) < EPSILON) { - updates.dollyDelta = 0; - } - - //---------------------------------------------------------------------------------------------------------- - // Rotation decay - //---------------------------------------------------------------------------------------------------------- - - if (Math.abs(updates.rotateDeltaX) < EPSILON) { - updates.rotateDeltaX = 0; - } - - if (Math.abs(updates.rotateDeltaY) < EPSILON) { - updates.rotateDeltaY = 0; - } - - if (updates.rotateDeltaX !== 0 || updates.rotateDeltaY !== 0) { - updates.dollyDelta = 0; - } - - //---------------------------------------------------------------------------------------------------------- - // Dolly speed eye->look scaling - // - // If pointer is over an object, then dolly speed is proportional to the distance to that object. - // - // If pointer is not over an object, then dolly speed is proportional to the distance to the last - // object the pointer was over. This is so that we can dolly to structures that may have gaps through - // which empty background shows, that the pointer may inadvertently be over. In these cases, we don't - // want dolly speed wildly varying depending on how accurately the user avoids the gaps with the pointer. - //---------------------------------------------------------------------------------------------------------- - - if (configs.followPointer) { - - if (--countDown <= 0) { - - countDown = SCALE_DOLLY_EACH_FRAME; - - if (updates.dollyDelta !== 0) { - if (updates.rotateDeltaY === 0 && updates.rotateDeltaX === 0) { - - if (configs.followPointer && states.followPointerDirty) { - - pickController.pickCursorPos = states.pointerCanvasPos; - pickController.schedulePickSurface = true; - pickController.update(); - - if (pickController.pickResult && pickController.pickResult.worldPos) { - followPointerWorldPos = pickController.pickResult.worldPos; - - } else { - dollyDistFactor = 1.0; - followPointerWorldPos = null; - } - - states.followPointerDirty = false; - } - } - - if (followPointerWorldPos) { - const dist = Math.abs(math.lenVec3(math.subVec3(followPointerWorldPos, scene.camera.eye, tempVec3$3))); - dollyDistFactor = dist / configs.dollyProximityThreshold; - } - - if (dollyDistFactor < configs.dollyMinSpeed) { - dollyDistFactor = configs.dollyMinSpeed; - } - } - } - } else { - dollyDistFactor = 1; - followPointerWorldPos = null; - } - - const dollyDeltaForDist = (updates.dollyDelta * dollyDistFactor); - - //---------------------------------------------------------------------------------------------------------- - // Rotation - //---------------------------------------------------------------------------------------------------------- - - if (updates.rotateDeltaY !== 0 || updates.rotateDeltaX !== 0) { - - if (configs.firstPerson) { - if (updates.rotateDeltaX !== 0) { - camera.pitch(-updates.rotateDeltaX); - } - if (updates.rotateDeltaY !== 0) { - camera.yaw(updates.rotateDeltaY); - } - } - else { - if (configs.followPointer && pivotController.getPivoting()){ - pivotController.continuePivot(updates.rotateDeltaY, updates.rotateDeltaX); - pivotController.showPivot(); - } - } - - updates.rotateDeltaX *= configs.rotationInertia; - updates.rotateDeltaY *= configs.rotationInertia; - - cursorType = cameraControl._cursors.rotate; - } - - //---------------------------------------------------------------------------------------------------------- - // Panning - //---------------------------------------------------------------------------------------------------------- - - if (Math.abs(updates.panDeltaX) < EPSILON) { - updates.panDeltaX = 0; - } - - if (Math.abs(updates.panDeltaY) < EPSILON) { - updates.panDeltaY = 0; - } - - if (Math.abs(updates.panDeltaZ) < EPSILON) { - updates.panDeltaZ = 0; - } - - if (updates.panDeltaX !== 0 || updates.panDeltaY !== 0 || updates.panDeltaZ !== 0) { - - const vec = math.vec3(); - - vec[0] = updates.panDeltaX; - vec[1] = updates.panDeltaY; - vec[2] = updates.panDeltaZ; - - let verticalEye; - let verticalLook; - - if (configs.constrainVertical) { - - if (camera.xUp) { - verticalEye = camera.eye[0]; - verticalLook = camera.look[0]; - } else if (camera.yUp) { - verticalEye = camera.eye[1]; - verticalLook = camera.look[1]; - } else if (camera.zUp) { - verticalEye = camera.eye[2]; - verticalLook = camera.look[2]; - } - - camera.pan(vec); - - const eye = camera.eye; - const look = camera.look; - - if (camera.xUp) { - eye[0] = verticalEye; - look[0] = verticalLook; - } else if (camera.yUp) { - eye[1] = verticalEye; - look[1] = verticalLook; - } else if (camera.zUp) { - eye[2] = verticalEye; - look[2] = verticalLook; - } - - camera.eye = eye; - camera.look = look; - - } else { - camera.pan(vec); - } - - cursorType = cameraControl._cursors.pan; - } - - updates.panDeltaX *= configs.panInertia; - updates.panDeltaY *= configs.panInertia; - updates.panDeltaZ *= configs.panInertia; - - //---------------------------------------------------------------------------------------------------------- - // Dollying - //---------------------------------------------------------------------------------------------------------- - - if (dollyDeltaForDist !== 0) { - - if (dollyDeltaForDist < 0) { - cursorType = cameraControl._cursors.dollyForward; - } else { - cursorType = cameraControl._cursors.dollyBackward; - } - - if (configs.firstPerson) { - - let verticalEye; - let verticalLook; - - if (configs.constrainVertical) { - if (camera.xUp) { - verticalEye = camera.eye[0]; - verticalLook = camera.look[0]; - } else if (camera.yUp) { - verticalEye = camera.eye[1]; - verticalLook = camera.look[1]; - } else if (camera.zUp) { - verticalEye = camera.eye[2]; - verticalLook = camera.look[2]; - } - } - - if (configs.followPointer) { - const dolliedThroughSurface = panController.dollyToCanvasPos(followPointerWorldPos, states.pointerCanvasPos, -dollyDeltaForDist); - if (dolliedThroughSurface) { - states.followPointerDirty = true; - } - } else { - camera.pan([0, 0, dollyDeltaForDist]); - camera.ortho.scale = camera.ortho.scale - dollyDeltaForDist; - } - - if (configs.constrainVertical) { - const eye = camera.eye; - const look = camera.look; - if (camera.xUp) { - eye[0] = verticalEye; - look[0] = verticalLook; - } else if (camera.yUp) { - eye[1] = verticalEye; - look[1] = verticalLook; - } else if (camera.zUp) { - eye[2] = verticalEye; - look[2] = verticalLook; - } - camera.eye = eye; - camera.look = look; - } - - } else if (configs.planView) { - - if (configs.followPointer) { - const dolliedThroughSurface = panController.dollyToCanvasPos(followPointerWorldPos, states.pointerCanvasPos, -dollyDeltaForDist); - if (dolliedThroughSurface) { - states.followPointerDirty = true; - } - } else { - camera.ortho.scale = camera.ortho.scale + dollyDeltaForDist; - camera.zoom(dollyDeltaForDist); - } - - } else { // Orbiting - - if (configs.followPointer) { - const dolliedThroughSurface = panController.dollyToCanvasPos(followPointerWorldPos, states.pointerCanvasPos, -dollyDeltaForDist); - if (dolliedThroughSurface) { - states.followPointerDirty = true; - } - } else { - camera.ortho.scale = camera.ortho.scale + dollyDeltaForDist; - camera.zoom(dollyDeltaForDist); - } - } - - updates.dollyDelta *= configs.dollyInertia; - } - - pickController.fireEvents(); - - document.body.style.cursor = cursorType; - }); - } - - - destroy() { - this._scene.off(this._onTick); - } -} - -/** - * @private - */ -class MouseMiscHandler { - - constructor(scene, controllers, configs, states, updates) { - - this._scene = scene; - - const canvas = this._scene.canvas.canvas; - - canvas.addEventListener("mouseenter", this._mouseEnterHandler = () => { - states.mouseover = true; - }); - - canvas.addEventListener("mouseleave", this._mouseLeaveHandler = () => { - states.mouseover = false; - canvas.style.cursor = null; - }); - - document.addEventListener("mousemove", this._mouseMoveHandler = (e) => { - getCanvasPosFromEvent$2(e, canvas, states.pointerCanvasPos); - states.mouseover = true; // Added to fix XCD-386: The zoom speed slows down when zooming into an empty space for the first time on a relatively large model, and it cannot be reset without reloading - }); - - canvas.addEventListener("mousedown", this._mouseDownHandler = (e) => { - if (!(configs.active && configs.pointerEnabled)) { - return; - } - getCanvasPosFromEvent$2(e, canvas, states.pointerCanvasPos); - states.mouseover = true; - }); - - canvas.addEventListener("mouseup", this._mouseUpHandler = (e) => { - if (!(configs.active && configs.pointerEnabled)) { - return; - } - }); - } - - reset() { - } - - destroy() { - - const canvas = this._scene.canvas.canvas; - - document.removeEventListener("mousemove", this._mouseMoveHandler); - canvas.removeEventListener("mouseenter", this._mouseEnterHandler); - canvas.removeEventListener("mouseleave", this._mouseLeaveHandler); - canvas.removeEventListener("mousedown", this._mouseDownHandler); - canvas.removeEventListener("mouseup", this._mouseUpHandler); - } -} - -function getCanvasPosFromEvent$2(event, canvas, canvasPos) { - if (!event) { - event = window.event; - canvasPos[0] = event.x; - canvasPos[1] = event.y; - } else { - const { left, top } = canvas.getBoundingClientRect(); - canvasPos[0] = event.clientX - left; - canvasPos[1] = event.clientY - top; - } - return canvasPos; -} - -const getCanvasPosFromEvent$1 = function(event, canvas, canvasPos) { - if (!event) { - event = window.event; - canvasPos[0] = event.x; - canvasPos[1] = event.y; - } else { - const canvasRect = canvas.getBoundingClientRect(); - canvasPos[0] = event.clientX - canvasRect.left; - canvasPos[1] = event.clientY - canvasRect.top; - } - return canvasPos; -}; - -/** - * @private - */ -class TouchPanRotateAndDollyHandler { - - constructor(scene, controllers, configs, states, updates) { - - this._scene = scene; - - const pickController = controllers.pickController; - const pivotController = controllers.pivotController; - - const tapStartCanvasPos = math.vec2(); - const tapCanvasPos0 = math.vec2(); - const tapCanvasPos1 = math.vec2(); - const touch0Vec = math.vec2(); - - const lastCanvasTouchPosList = []; - const canvas = this._scene.canvas.canvas; - - let numTouches = 0; - let waitForTick = false; - - this._onTick = scene.on("tick", () => { - waitForTick = false; - }); - - canvas.addEventListener("touchstart", this._canvasTouchStartHandler = (event) => { - - if (!(configs.active && configs.pointerEnabled)) { - return; - } - - event.preventDefault(); - - const touches = event.touches; - const changedTouches = event.changedTouches; - - states.touchStartTime = Date.now(); - - if (touches.length === 1 && changedTouches.length === 1) { - - getCanvasPosFromEvent$1(touches[0], canvas, tapStartCanvasPos); - - if (configs.followPointer) { - - pickController.pickCursorPos = tapStartCanvasPos; - pickController.schedulePickSurface = true; - pickController.update(); - - if (!configs.planView) { - - if (pickController.picked && pickController.pickedSurface && pickController.pickResult && pickController.pickResult.worldPos) { - - pivotController.setPivotPos(pickController.pickResult.worldPos); - - if (!configs.firstPerson && pivotController.startPivot()) { - pivotController.showPivot(); - } - - } else { - - if (configs.smartPivot) { - pivotController.setCanvasPivotPos(states.pointerCanvasPos); - } else { - pivotController.setPivotPos(scene.camera.look); - } - - if (!configs.firstPerson && pivotController.startPivot()) { - pivotController.showPivot(); - } - } - } - } - - } - - while (lastCanvasTouchPosList.length < touches.length) { - lastCanvasTouchPosList.push(math.vec2()); - } - - for (let i = 0, len = touches.length; i < len; ++i) { - getCanvasPosFromEvent$1(touches[i], canvas, lastCanvasTouchPosList[i]); - } - - numTouches = touches.length; - }); - - canvas.addEventListener("touchend", this._canvasTouchEndHandler = () => { - if (pivotController.getPivoting()) { - pivotController.endPivot(); - pivotController.hidePivot(); - } - }); - - canvas.addEventListener("touchmove", this._canvasTouchMoveHandler = (event) => { - - if (!(configs.active && configs.pointerEnabled)) { - return; - } - - event.stopPropagation(); - event.preventDefault(); - - if (waitForTick) { - // Limit changes detection to one per frame - return; - } - - waitForTick = true; - - // Scaling drag-rotate to canvas boundary - - const canvasBoundary = scene.canvas.boundary; - const canvasWidth = canvasBoundary[2]; - const canvasHeight = canvasBoundary[3]; - - const touches = event.touches; - - if (event.touches.length !== numTouches) { - // Two fingers were pressed, then one of them is removed - // We don't want to rotate in this case (weird behavior) - return; - } - - if (numTouches === 1) { - - getCanvasPosFromEvent$1(touches[0], canvas, tapCanvasPos0); - - //----------------------------------------------------------------------------------------------- - // Drag rotation - //----------------------------------------------------------------------------------------------- - - math.subVec2(tapCanvasPos0, lastCanvasTouchPosList[0], touch0Vec); - - const xPanDelta = touch0Vec[0]; - const yPanDelta = touch0Vec[1]; - - if (states.longTouchTimeout !== null && (Math.abs(xPanDelta) > configs.longTapRadius || Math.abs(yPanDelta) > configs.longTapRadius)) { - clearTimeout(states.longTouchTimeout); - states.longTouchTimeout = null; - } - - if (configs.planView) { // No rotating in plan-view mode - - const camera = scene.camera; - - // We use only canvasHeight here so that aspect ratio does not distort speed - - if (camera.projection === "perspective") { - - const depth = Math.abs(scene.camera.eyeLookDist); - const targetDistance = depth * Math.tan((camera.perspective.fov / 2) * Math.PI / 180.0); - - updates.panDeltaX += (xPanDelta * targetDistance / canvasHeight) * configs.touchPanRate; - updates.panDeltaY += (yPanDelta * targetDistance / canvasHeight) * configs.touchPanRate; - - } else { - - updates.panDeltaX += 0.5 * camera.ortho.scale * (xPanDelta / canvasHeight) * configs.touchPanRate; - updates.panDeltaY += 0.5 * camera.ortho.scale * (yPanDelta / canvasHeight) * configs.touchPanRate; - } - - } else { - // if (!absorbTinyFirstDrag) { - updates.rotateDeltaY -= (xPanDelta / canvasWidth) * (configs.dragRotationRate * 1.0); // Full horizontal rotation - updates.rotateDeltaX += (yPanDelta / canvasHeight) * (configs.dragRotationRate * 1.5); // Half vertical rotation - // } else { - // firstDragDeltaY -= (xPanDelta / canvasWidth) * (configs.dragRotationRate * 1.0); // Full horizontal rotation - // firstDragDeltaX += (yPanDelta / canvasHeight) * (configs.dragRotationRate * 1.5); // Half vertical rotation - // if (Math.abs(firstDragDeltaX) > 5 || Math.abs(firstDragDeltaY) > 5) { - // updates.rotateDeltaX += firstDragDeltaX; - // updates.rotateDeltaY += firstDragDeltaY; - // firstDragDeltaX = 0; - // firstDragDeltaY = 0; - // absorbTinyFirstDrag = false; - // } - // } - } - - } else if (numTouches === 2) { - - const touch0 = touches[0]; - const touch1 = touches[1]; - - getCanvasPosFromEvent$1(touch0, canvas, tapCanvasPos0); - getCanvasPosFromEvent$1(touch1, canvas, tapCanvasPos1); - - const lastMiddleTouch = math.geometricMeanVec2(lastCanvasTouchPosList[0], lastCanvasTouchPosList[1]); - const currentMiddleTouch = math.geometricMeanVec2(tapCanvasPos0, tapCanvasPos1); - - const touchDelta = math.vec2(); - - math.subVec2(lastMiddleTouch, currentMiddleTouch, touchDelta); - - const xPanDelta = touchDelta[0]; - const yPanDelta = touchDelta[1]; - - const camera = scene.camera; - - // Dollying - - const d1 = math.distVec2([touch0.pageX, touch0.pageY], [touch1.pageX, touch1.pageY]); - const d2 = math.distVec2(lastCanvasTouchPosList[0], lastCanvasTouchPosList[1]); - - const dollyDelta = (d2 - d1) * configs.touchDollyRate; - - updates.dollyDelta = dollyDelta; - states.followPointerDirty = true; // Added to fix XCD-386: The zoom speed slows down when zooming into an empty space for the first time on a relatively large model, and it cannot be reset without reloading - - if (Math.abs(dollyDelta) < 1.0) { - - // We use only canvasHeight here so that aspect ratio does not distort speed - - if (camera.projection === "perspective") { - const pickedWorldPos = pickController.pickResult ? pickController.pickResult.worldPos : scene.center; - - const depth = Math.abs(math.lenVec3(math.subVec3(pickedWorldPos, scene.camera.eye, []))); - const targetDistance = depth * Math.tan((camera.perspective.fov / 2) * Math.PI / 180.0); - - updates.panDeltaX -= (xPanDelta * targetDistance / canvasHeight) * configs.touchPanRate; - updates.panDeltaY -= (yPanDelta * targetDistance / canvasHeight) * configs.touchPanRate; - - } else { - - updates.panDeltaX -= 0.5 * camera.ortho.scale * (xPanDelta / canvasHeight) * configs.touchPanRate; - updates.panDeltaY -= 0.5 * camera.ortho.scale * (yPanDelta / canvasHeight) * configs.touchPanRate; - } - } - - - states.pointerCanvasPos = currentMiddleTouch; - } - - for (let i = 0; i < numTouches; ++i) { - getCanvasPosFromEvent$1(touches[i], canvas, lastCanvasTouchPosList[i]); - } - }); - } - - reset() { - } - - destroy() { - const canvas = this._scene.canvas.canvas; - canvas.removeEventListener("touchstart", this._canvasTouchStartHandler); - canvas.removeEventListener("touchend", this._canvasTouchEndHandler); - canvas.removeEventListener("touchmove", this._canvasTouchMoveHandler); - this._scene.off(this._onTick); - } -} - -const TAP_INTERVAL = 150; -const DBL_TAP_INTERVAL = 325; -const TAP_DISTANCE_THRESHOLD = 4; - -const getCanvasPosFromEvent = function (event, canvasPos) { - if (!event) { - event = window.event; - canvasPos[0] = event.x; - canvasPos[1] = event.y; - } else { - let element = event.target; - let totalOffsetLeft = 0; - let totalOffsetTop = 0; - while (element.offsetParent) { - totalOffsetLeft += element.offsetLeft; - totalOffsetTop += element.offsetTop; - element = element.offsetParent; - } - canvasPos[0] = event.pageX - totalOffsetLeft; - canvasPos[1] = event.pageY - totalOffsetTop; - } - return canvasPos; -}; - -/** - * @private - */ -class TouchPickHandler { - - constructor(scene, controllers, configs, states, updates) { - - this._scene = scene; - - const pickController = controllers.pickController; - const cameraControl = controllers.cameraControl; - - let touchStartTime; - const activeTouches = []; - const tapStartPos = new Float32Array(2); - let tapStartTime = -1; - let lastTapTime = -1; - - const canvas = this._scene.canvas.canvas; - - const flyCameraTo = (pickResult) => { - let pos; - if (pickResult && pickResult.worldPos) { - pos = pickResult.worldPos; - } - const aabb = pickResult ? pickResult.entity.aabb : scene.aabb; - if (pos) { // Fly to look at point, don't change eye->look dist - const camera = scene.camera; - math.subVec3(camera.eye, camera.look, []); - controllers.cameraFlight.flyTo({ - aabb: aabb - }); - // TODO: Option to back off to fit AABB in view - } else {// Fly to fit target boundary in view - controllers.cameraFlight.flyTo({ - aabb: aabb - }); - } - }; - - canvas.addEventListener("touchstart", this._canvasTouchStartHandler = (e) => { - - if (!(configs.active && configs.pointerEnabled)) { - return; - } - - if (states.longTouchTimeout !== null) { - clearTimeout(states.longTouchTimeout); - states.longTouchTimeout = null; - } - - const touches = e.touches; - const changedTouches = e.changedTouches; - - touchStartTime = Date.now(); - - if (touches.length === 1 && changedTouches.length === 1) { - tapStartTime = touchStartTime; - - getCanvasPosFromEvent(touches[0], tapStartPos); - - const rightClickClientX = tapStartPos[0]; - const rightClickClientY = tapStartPos[1]; - - const rightClickPageX = touches[0].pageX; - const rightClickPageY = touches[0].pageY; - - states.longTouchTimeout = setTimeout(() => { - if (configs.active && configs.pointerEnabled) { - controllers.cameraControl.fire("rightClick", { // For context menus - pagePos: [Math.round(rightClickPageX), Math.round(rightClickPageY)], - canvasPos: [Math.round(rightClickClientX), Math.round(rightClickClientY)], - event: e - }, true); - } - states.longTouchTimeout = null; - }, configs.longTapTimeout); - - } else { - tapStartTime = -1; - } - - while (activeTouches.length < touches.length) { - activeTouches.push(new Float32Array(2)); - } - - for (let i = 0, len = touches.length; i < len; ++i) { - getCanvasPosFromEvent(touches[i], activeTouches[i]); - } - - activeTouches.length = touches.length; - - }, {passive: true}); - - - canvas.addEventListener("touchend", this._canvasTouchEndHandler = (e) => { - - if (!(configs.active && configs.pointerEnabled)) { - return; - } - - const currentTime = Date.now(); - const touches = e.touches; - const changedTouches = e.changedTouches; - - const pickedSurfaceSubs = cameraControl.hasSubs("pickedSurface"); - - if (states.longTouchTimeout !== null) { - clearTimeout(states.longTouchTimeout); - states.longTouchTimeout = null; - } - - // process tap - - if (touches.length === 0 && changedTouches.length === 1) { - - if (tapStartTime > -1 && currentTime - tapStartTime < TAP_INTERVAL) { - - if (lastTapTime > -1 && tapStartTime - lastTapTime < DBL_TAP_INTERVAL) { - - // Double-tap - - getCanvasPosFromEvent(changedTouches[0], pickController.pickCursorPos); - pickController.schedulePickEntity = true; - pickController.schedulePickSurface = pickedSurfaceSubs; - - pickController.update(); - - if (pickController.pickResult) { - - pickController.pickResult.touchInput = true; - - cameraControl.fire("doublePicked", pickController.pickResult); - - if (pickController.pickedSurface) { - cameraControl.fire("doublePickedSurface", pickController.pickResult); - } - - if (configs.doublePickFlyTo) { - flyCameraTo(pickController.pickResult); - } - } else { - cameraControl.fire("doublePickedNothing"); - if (configs.doublePickFlyTo) { - flyCameraTo(); - } - } - - lastTapTime = -1; - - } else if (math.distVec2(activeTouches[0], tapStartPos) < TAP_DISTANCE_THRESHOLD) { - - // Single-tap - - getCanvasPosFromEvent(changedTouches[0], pickController.pickCursorPos); - pickController.schedulePickEntity = true; - pickController.schedulePickSurface = pickedSurfaceSubs; - - pickController.update(); - - if (pickController.pickResult) { - - pickController.pickResult.touchInput = true; - - cameraControl.fire("picked", pickController.pickResult); - - if (pickController.pickedSurface) { - cameraControl.fire("pickedSurface", pickController.pickResult); - } - - } else { - cameraControl.fire("pickedNothing"); - } - - lastTapTime = currentTime; - } - - tapStartTime = -1; - } - } - - activeTouches.length = touches.length; - - for (let i = 0, len = touches.length; i < len; ++i) { - activeTouches[i][0] = touches[i].pageX; - activeTouches[i][1] = touches[i].pageY; - } - - // e.stopPropagation(); - - }, {passive: true}); - - } - - reset() { - // TODO - // tapStartTime = -1; - // lastTapTime = -1; - - } - - destroy() { - const canvas = this._scene.canvas.canvas; - canvas.removeEventListener("touchstart", this._canvasTouchStartHandler); - canvas.removeEventListener("touchend", this._canvasTouchEndHandler); - } -} - -const DEFAULT_SNAP_PICK_RADIUS = 30; -const DEFAULT_SNAP_VERTEX = true; -const DEFAULT_SNAP_EDGE = true; - -/** - * @desc Controls the {@link Camera} with user input, and fires events when the user interacts with pickable {@link Entity}s. - * - * # Contents - * - * * [Overview](#overview) - * * [Examples](#examples) - * * [Orbit Mode](#orbit-mode) - * + [Following the Pointer in Orbit Mode](#--following-the-pointer-in-orbit-mode--) - * + [Showing the Pivot Position](#--showing-the-pivot-position--) - * + [Axis-Aligned Views in Orbit Mode](#--axis-aligned-views-in-orbit-mode--) - * + [View-Fitting Entitys in Orbit Mode](#--view-fitting-entitys-in-orbit-mode--) - * * [First-Person Mode](#first-person-mode) - * + [Following the Pointer in First-Person Mode](#--following-the-pointer-in-first-person-mode--) - * + [Constraining Vertical Position in First-Person Mode](#--constraining-vertical-position-in-first-person-mode--) - * + [Axis-Aligned Views in First-Person Mode](#--axis-aligned-views-in-first-person-mode--) - * + [View-Fitting Entitys in First-Person Mode](#--view-fitting-entitys-in-first-person-mode--) - * * [Plan-View Mode](#plan-view-mode) - * + [Following the Pointer in Plan-View Mode](#--following-the-pointer-in-plan-view-mode--) - * + [Axis-Aligned Views in Plan-View Mode](#--axis-aligned-views-in-plan-view-mode--) - * * [CameraControl Events](#cameracontrol-events) - * + ["hover"](#---hover---) - * + ["hoverOff"](#---hoveroff---) - * + ["hoverEnter"](#---hoverenter---) - * + ["hoverOut"](#---hoverout---) - * + ["picked"](#---picked---) - * + ["pickedSurface"](#---pickedsurface---) - * + ["pickedNothing"](#---pickednothing---) - * + ["doublePicked"](#---doublepicked---) - * + ["doublePickedSurface"](#---doublepickedsurface---) - * + ["doublePickedNothing"](#---doublepickednothing---) - * + ["rightClick"](#---rightclick---) - * * [Custom Keyboard Mappings](#custom-keyboard-mappings) - * - *

- * - * # Overview - * - * * Each {@link Viewer} has a ````CameraControl````, located at {@link Viewer#cameraControl}. - * * {@link CameraControl#navMode} selects the navigation mode: - * * ````"orbit"```` rotates the {@link Camera} position about the target. - * * ````"firstPerson"```` rotates the World about the Camera position. - * * ````"planView"```` never rotates, but still allows to pan and dolly, typically for an axis-aligned view. - * * {@link CameraControl#followPointer} makes the Camera follow the mouse or touch pointer. - * * {@link CameraControl#constrainVertical} locks the Camera to its current height when in first-person mode. - * * ````CameraControl```` fires pick events when we hover, click or tap on an {@link Entity}. - *

- * - * # Examples - * - * * [Orbit Navigation - Duplex Model](https://xeokit.github.io/xeokit-sdk/examples/index.html#CameraControl_orbit_Duplex) - * * [Orbit Navigation - Holter Tower Model](https://xeokit.github.io/xeokit-sdk/examples/index.html#CameraControl_orbit_HolterTower) - * * [First-Person Navigation - Duplex Model](https://xeokit.github.io/xeokit-sdk/examples/index.html#CameraControl_firstPerson_Duplex) - * * [First-Person Navigation - Holter Tower Model](https://xeokit.github.io/xeokit-sdk/examples/index.html#CameraControl_firstPerson_HolterTower) - * * [Plan-view Navigation - Schependomlaan Model](https://xeokit.github.io/xeokit-sdk/examples/index.html#CameraControl_planView_Schependomlaan) - * * [Custom Keyboard Mapping](https://xeokit.github.io/xeokit-sdk/examples/index.html#CameraControl_keyMap) - *

- * - * # Orbit Mode - * - * In orbit mode, ````CameraControl```` orbits the {@link Camera} about the target. - * - * To enable orbit mode: - * - * ````javascript - * const cameraControl = myViewer.cameraControl; - * cameraControl.navMode = "orbit"; - * ```` - * - * Then orbit by: - * - * * left-dragging the mouse, - * * tap-dragging the touch pad, and - * * pressing arrow keys, or ````Q```` and ````E```` on a QWERTY keyboard, or ````A```` and ````E```` on an AZERTY keyboard. - *

- * - * Dolly forwards and backwards by: - * - * * spinning the mouse wheel, - * * pinching on the touch pad, and - * * pressing the ````+```` and ````-```` keys, or ````W```` and ````S```` on a QWERTY keyboard, or ````Z```` and ````S```` for AZERTY. - *

- * - * Pan horizontally and vertically by: - * - * * right-dragging the mouse, - * * left-dragging the mouse with the SHIFT key down, - * * tap-dragging the touch pad with SHIFT down, - * * pressing the ````A````, ````D````, ````Z```` and ````X```` keys on a QWERTY keyboard, and - * * pressing the ````Q````, ````D````, ````W```` and ````X```` keys on an AZERTY keyboard, - *

- * - * ## Following the Pointer in Orbit Mode - * - * When {@link CameraControl#followPointer} is ````true````in orbiting mode, the mouse or touch pointer will dynamically - * indicate the target that the {@link Camera} will orbit, as well as dolly to and from. - * - * Lets ensure that we're in orbit mode, then enable the {@link Camera} to follow the pointer: - * - * ````javascript - * cameraControl.navMode = "orbit"; - * cameraControl.followPointer = true; - * ```` - * - * ## Smart Pivoting - * - * TODO - * - * ## Showing the Pivot Position - * - * We can configure {@link CameraControl#pivotElement} with an HTML element to indicate the current - * pivot position. The indicator will appear momentarily each time we move the {@link Camera} while in orbit mode with - * {@link CameraControl#followPointer} set ````true````. - * - * First we'll define some CSS to style our pivot indicator as a black dot with a white border: - * - * ````css - * .camera-pivot-marker { - * color: #ffffff; - * position: absolute; - * width: 25px; - * height: 25px; - * border-radius: 15px; - * border: 2px solid #ebebeb; - * background: black; - * visibility: hidden; - * box-shadow: 5px 5px 15px 1px #000000; - * z-index: 10000; - * pointer-events: none; - * } - * ```` - * - * Then we'll attach our pivot indicator's HTML element to the ````CameraControl````: - * - * ````javascript - * const pivotElement = document.createRange().createContextualFragment("
").firstChild; - * - * document.body.appendChild(pivotElement); - * - * cameraControl.pivotElement = pivotElement; - * ```` - * - * ## Axis-Aligned Views in Orbit Mode - * - * In orbit mode, we can use keys 1-6 to position the {@link Camera} to look at the center of the {@link Scene} from along each of the - * six World-space axis. Pressing one of these keys will fly the {@link Camera} to the corresponding axis-aligned view. - * - * ## View-Fitting Entitys in Orbit Mode - * - * When {@link CameraControl#doublePickFlyTo} is ````true````, we can left-double-click or - * double-tap (ie. "double-pick") an {@link Entity} to fit it to view. This will cause the {@link Camera} - * to fly to that Entity. Our target then becomes the center of that Entity. If we are currently pivoting, - * then our pivot position is then also set to the Entity center. - * - * Disable that behaviour by setting {@link CameraControl#doublePickFlyTo} ````false````. - * - * # First-Person Mode - * - * In first-person mode, ````CameraControl```` rotates the World about the {@link Camera} position. - * - * To enable first-person mode: - * - * ````javascript - * cameraControl.navMode = "firstPerson"; - * ```` - * - * Then rotate by: - * - * * left-dragging the mouse, - * * tap-dragging the touch pad, - * * pressing arrow keys, or ````Q```` and ````E```` on a QWERTY keyboard, or ````A```` and ````E```` on an AZERTY keyboard. - *

- * - * Dolly forwards and backwards by: - * - * * spinning the mouse wheel, - * * pinching on the touch pad, and - * * pressing the ````+```` and ````-```` keys, or ````W```` and ````S```` on a QWERTY keyboard, or ````Z```` and ````S```` for AZERTY. - *

- * - * Pan left, right, up and down by: - * - * * left-dragging or right-dragging the mouse, and - * * tap-dragging the touch pad with SHIFT down. - * - * Pan forwards, backwards, left, right, up and down by pressing the ````WSADZX```` keys on a QWERTY keyboard, - * or ````WSQDWX```` keys on an AZERTY keyboard. - *

- * - * ## Following the Pointer in First-Person Mode - * - * When {@link CameraControl#followPointer} is ````true```` in first-person mode, the mouse or touch pointer will dynamically - * indicate the target to which the {@link Camera} will dolly to and from. In first-person mode, however, the World will always rotate - * about the {@link Camera} position. - * - * Lets ensure that we're in first-person mode, then enable the {@link Camera} to follow the pointer: - * - * ````javascript - * cameraControl.navMode = "firstPerson"; - * cameraControl.followPointer = true; - * ```` - * - * When the pointer is over empty space, the target will remain the last object that the pointer was over. - * - * ## Constraining Vertical Position in First-Person Mode - * - * In first-person mode, we can lock the {@link Camera} to its current position on the vertical World axis, which is useful for walk-through navigation: - * - * ````javascript - * cameraControl.constrainVertical = true; - * ```` - * - * ## Axis-Aligned Views in First-Person Mode - * - * In first-person mode we can use keys 1-6 to position the {@link Camera} to look at the center of - * the {@link Scene} from along each of the six World-space axis. Pressing one of these keys will fly the {@link Camera} to the - * corresponding axis-aligned view. - * - * ## View-Fitting Entitys in First-Person Mode - * - * As in orbit mode, when in first-person mode and {@link CameraControl#doublePickFlyTo} is ````true````, we can double-click - * or double-tap an {@link Entity} (ie. "double-picking") to fit it in view. This will cause the {@link Camera} to fly to - * that Entity. Our target then becomes the center of that Entity. - * - * Disable that behaviour by setting {@link CameraControl#doublePickFlyTo} ````false````. - * - * # Plan-View Mode - * - * In plan-view mode, ````CameraControl```` pans and rotates the {@link Camera}, without rotating it. - * - * To enable plan-view mode: - * - * ````javascript - * cameraControl.navMode = "planView"; - * ```` - * - * Dolly forwards and backwards by: - * - * * spinning the mouse wheel, - * * pinching on the touch pad, and - * * pressing the ````+```` and ````-```` keys. - * - *
- * Pan left, right, up and down by: - * - * * left-dragging or right-dragging the mouse, and - * * tap-dragging the touch pad with SHIFT down. - * - * Pan forwards, backwards, left, right, up and down by pressing the ````WSADZX```` keys on a QWERTY keyboard, - * or ````WSQDWX```` keys on an AZERTY keyboard. - *

- * - * ## Following the Pointer in Plan-View Mode - * - * When {@link CameraControl#followPointer} is ````true```` in plan-view mode, the mouse or touch pointer will dynamically - * indicate the target to which the {@link Camera} will dolly to and from. In plan-view mode, however, the {@link Camera} cannot rotate. - * - * Lets ensure that we're in plan-view mode, then enable the {@link Camera} to follow the pointer: - * - * ````javascript - * cameraControl.navMode = "planView"; - * cameraControl.followPointer = true; // Default - * ```` - * - * When the pointer is over empty space, the target will remain the last object that the pointer was over. - * - * ## Axis-Aligned Views in Plan-View Mode - * - * As in orbit and first-person modes, in plan-view mode we can use keys 1-6 to position the {@link Camera} to look at the center of - * the {@link Scene} from along each of the six World-space axis. Pressing one of these keys will fly the {@link Camera} to the - * corresponding axis-aligned view. - * - * # CameraControl Events - * - * ````CameraControl```` fires events as we interact with {@link Entity}s using mouse or touch input. - * - * The following examples demonstrate how to subscribe to those events. - * - * The first example shows how to save a handle to a subscription, which we can later use to unsubscribe. - * - * ## "hover" - * - * Event fired when the pointer moves while hovering over an Entity. - * - * ````javascript - * const onHover = cameraControl.on("hover", (e) => { - * const entity = e.entity; // Entity - * const canvasPos = e.canvasPos; // 2D canvas position - * }); - * ```` - * - * To unsubscribe from the event: - * - * ````javascript - * cameraControl.off(onHover); - * ```` - * - * ## "hoverOff" - * - * Event fired when the pointer moves while hovering over empty space. - * - * ````javascript - * cameraControl.on("hoverOff", (e) => { - * const canvasPos = e.canvasPos; - * }); - * ```` - * - * ## "hoverEnter" - * - * Event fired when the pointer moves onto an Entity. - * - * ````javascript - * cameraControl.on("hoverEnter", (e) => { - * const entity = e.entity; - * const canvasPos = e.canvasPos; - * }); - * ```` - * - * ## "hoverOut" - * - * Event fired when the pointer moves off an Entity. - * - * ````javascript - * cameraControl.on("hoverOut", (e) => { - * const entity = e.entity; - * const canvasPos = e.canvasPos; - * }); - * ```` - * - * ## "picked" - * - * Event fired when we left-click or tap on an Entity. - * - * ````javascript - * cameraControl.on("picked", (e) => { - * const entity = e.entity; - * const canvasPos = e.canvasPos; - * }); - * ```` - * - * ## "pickedSurface" - * - * Event fired when we left-click or tap on the surface of an Entity. - * - * ````javascript - * cameraControl.on("picked", (e) => { - * const entity = e.entity; - * const canvasPos = e.canvasPos; - * const worldPos = e.worldPos; // 3D World-space position - * const viewPos = e.viewPos; // 3D View-space position - * const worldNormal = e.worldNormal; // 3D World-space normal vector - * }); - * ```` - * - * ## "pickedNothing" - * - * Event fired when we left-click or tap on empty space. - * - * ````javascript - * cameraControl.on("pickedNothing", (e) => { - * const canvasPos = e.canvasPos; - * }); - * ```` - * - * ## "doublePicked" - * - * Event fired wwhen we left-double-click or double-tap on an Entity. - * - * ````javascript - * cameraControl.on("doublePicked", (e) => { - * const entity = e.entity; - * const canvasPos = e.canvasPos; - * }); - * ```` - * - * ## "doublePickedSurface" - * - * Event fired when we left-double-click or double-tap on the surface of an Entity. - * - * ````javascript - * cameraControl.on("doublePickedSurface", (e) => { - * const entity = e.entity; - * const canvasPos = e.canvasPos; - * const worldPos = e.worldPos; - * const viewPos = e.viewPos; - * const worldNormal = e.worldNormal; - * }); - * ```` - * - * ## "doublePickedNothing" - * - * Event fired when we left-double-click or double-tap on empty space. - * - * ````javascript - * cameraControl.on("doublePickedNothing", (e) => { - * const canvasPos = e.canvasPos; - * }); - * ```` - * - * ## "rightClick" - * - * Event fired when we right-click on the canvas. - * - * ````javascript - * cameraControl.on("rightClick", (e) => { - * const event = e.event; // Mouse event - * const canvasPos = e.canvasPos; - * }); - * ```` - * - * ## Custom Keyboard Mappings - * - * We can customize````CameraControl```` key bindings as shown below. - * - * In this example, we'll just set the default bindings for a QWERTY keyboard. - * - * ````javascript - * const input = myViewer.scene.input; - * - * cameraControl.navMode = "orbit"; - * cameraControl.followPointer = true; - * - * const keyMap = {}; - * - * keyMap[cameraControl.PAN_LEFT] = [input.KEY_A]; - * keyMap[cameraControl.PAN_RIGHT] = [input.KEY_D]; - * keyMap[cameraControl.PAN_UP] = [input.KEY_Z]; - * keyMap[cameraControl.PAN_DOWN] = [input.KEY_X]; - * keyMap[cameraControl.DOLLY_FORWARDS] = [input.KEY_W, input.KEY_ADD]; - * keyMap[cameraControl.DOLLY_BACKWARDS] = [input.KEY_S, input.KEY_SUBTRACT]; - * keyMap[cameraControl.ROTATE_X_POS] = [input.KEY_DOWN_ARROW]; - * keyMap[cameraControl.ROTATE_X_NEG] = [input.KEY_UP_ARROW]; - * keyMap[cameraControl.ROTATE_Y_POS] = [input.KEY_LEFT_ARROW]; - * keyMap[cameraControl.ROTATE_Y_NEG] = [input.KEY_RIGHT_ARROW]; - * keyMap[cameraControl.AXIS_VIEW_RIGHT] = [input.KEY_NUM_1]; - * keyMap[cameraControl.AXIS_VIEW_BACK] = [input.KEY_NUM_2]; - * keyMap[cameraControl.AXIS_VIEW_LEFT] = [input.KEY_NUM_3]; - * keyMap[cameraControl.AXIS_VIEW_FRONT] = [input.KEY_NUM_4]; - * keyMap[cameraControl.AXIS_VIEW_TOP] = [input.KEY_NUM_5]; - * keyMap[cameraControl.AXIS_VIEW_BOTTOM] = [input.KEY_NUM_6]; - * keyMap[cameraControl.MOUSE_PAN] = [[input.KEY_SHIFT, input.MOUSE_LEFT_BUTTON]]; - * keyMap[cameraControl.MOUSE_ROTATE] = [ - * [input.KEY_SHIFT, input.MOUSE_MIDDLE_BUTTON], - * [input.KEY_SHIFT, input.MOUSE_RIGHT_BUTTON] - * ] - * keyMap[cameraControl.MOUSE_DOLLY] = [[input.KEY_CTRL, input.MOUSE_RIGHT_BUTTON]]; - * - * cameraControl.keyMap = keyMap; - * ```` - * - * We can also just configure default bindings for a specified keyboard layout, like this: - * - * ````javascript - * cameraControl.keyMap = "qwerty"; - * ```` - * - * Then, ````CameraControl```` will internally set {@link CameraControl#keyMap} to the default key map for the QWERTY - * layout (which is the same set of mappings we set in the previous example). In other words, if we subsequently - * read {@link CameraControl#keyMap}, it will now be a key map, instead of the "qwerty" string value we set it to. - * - * Supported layouts are, so far: - * - * * ````"qwerty"```` - * * ````"azerty"```` - * - * ## Basic Keyboard Mapping - * * ````"OR" Relation```` - * Set multiple keys to trigger an action if any one is pressed: - * - * ````javascript - * keyMap[cameraControl.DOLLY_BACKWARDS] = [input.KEY_S, input.KEY_SUBTRACT]; - * ```` - * - * If either ````KEY_S```` or ````KEY_SUBTRACT```` is pressed, the camera will dolly backward. - * - * * ````"AND" Relation```` - * To require all keys in a combination to be pressed: - * - * ````javascript - * keyMap[cameraControl.DOLLY_BACKWARDS] = [[input.KEY_S, input.KEY_SUBTRACT]]; - * ```` - * - * The camera will dolly backward if ````both KEY_S```` and ````KEY_SUBTRACT```` are pressed. - * - * * ````Mix "AND" and "OR" Relation```` - * Use a combination of keys and groups for flexibility: - * - * ````javascript - * keyMap[cameraControl.DOLLY_BACKWARDS] = [ - * [input.KEY_S, input.KEY_SUBTRACT], // 'And' group - * input.KEY_SHIFT // 'Or' with previous - * ]; - * ```` - * - * The camera will dolly backward if ````KEY_S```` + ````KEY_SUBTRACT```` are pressed together, or if ````KEY_SHIFT```` is pressed. - * - * ## Special Mouse Actions - * Certain actions support combinations with specific mouse buttons or events: - * - * * ````MOUSE_PAN```` - * For panning with a key and mouse movement: - * - * ````javascript - * keyMap[cameraControl.MOUSE_PAN] = [[input.KEY_SHIFT, input.MOUSE_LEFT_BUTTON]]; - * ```` - * - * Panning is triggered by pressing ````KEY_SHIFT```` + ````MOUSE_LEFT_BUTTON```` while moving the mouse. - * - * * ````MOUSE_ROTATE```` - * Similar to panning, rotation can be configured with key and mouse button combinations: - * - * ````javascript - * keyMap[cameraControl.MOUSE_ROTATE] = [[input.KEY_CTRL, input.MOUSE_LEFT_BUTTON]]; - * ```` - * - * Rotation is triggered by pressing ````KEY_CTRL```` + ````MOUSE_LEFT_BUTTON```` during mouse movement. - * - * * ````MOUSE_DOLLY```` - * Dolly with mouse wheel scrolling and optional key combinations: - * - * ````javascript - * keyMap[cameraControl.MOUSE_DOLLY] = [[input.KEY_ALT]]; - * ```` - * - * Dolly action occurs when scrolling the mouse wheel with ````KEY_ALT```` held (no need to specify MOUSE_WHEEL). - * - * ## Special Mouse Actions - * Use ````input.MOUSE_LEFT_BUTTON````, ````input.MOUSE_MIDDLE_BUTTON````, and ````input.MOUSE_RIGHT_BUTTON```` in combinations only for camera movements involving the mouse. - */ -class CameraControl extends Component { - - /** - * @private - * @constructor - */ - constructor(owner, cfg = {}) { - - super(owner, cfg); - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.PAN_LEFT = 0; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.PAN_RIGHT = 1; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.PAN_UP = 2; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.PAN_DOWN = 3; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.PAN_FORWARDS = 4; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.PAN_BACKWARDS = 5; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.ROTATE_X_POS = 6; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.ROTATE_X_NEG = 7; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.ROTATE_Y_POS = 8; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.ROTATE_Y_NEG = 9; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.DOLLY_FORWARDS = 10; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.DOLLY_BACKWARDS = 11; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.AXIS_VIEW_RIGHT = 12; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.AXIS_VIEW_BACK = 13; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.AXIS_VIEW_LEFT = 14; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.AXIS_VIEW_FRONT = 15; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.AXIS_VIEW_TOP = 16; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.AXIS_VIEW_BOTTOM = 17; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.MOUSE_PAN = 18; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.MOUSE_ROTATE = 19; - - /** - * Identifies the XX action. - * @final - * @type {Number} - */ - this.MOUSE_DOLLY = 20; - - this._keyMap = {}; // Maps key codes to the above actions - - this.scene.canvas.canvas.oncontextmenu = (e) => { - e.preventDefault(); - }; - - // User-settable CameraControl configurations - - this._configs = { - - // Private - - longTapTimeout: 600, // Millisecs - longTapRadius: 5, // Pixels - - // General - - active: true, - keyboardLayout: "qwerty", - navMode: "orbit", - planView: false, - firstPerson: false, - followPointer: true, - doublePickFlyTo: true, - panRightClick: true, - showPivot: false, - pointerEnabled: true, - constrainVertical: false, - smartPivot: false, - doubleClickTimeFrame: 250, - zoomOnMouseWheel: true, - - snapToVertex: DEFAULT_SNAP_VERTEX, - snapToEdge: DEFAULT_SNAP_EDGE, - snapRadius: DEFAULT_SNAP_PICK_RADIUS, - - keyboardEnabledOnlyIfMouseover: true, - - // Rotation - - dragRotationRate: 360.0, - keyboardRotationRate: 90.0, - rotationInertia: 0.0, - - // Panning - - keyboardPanRate: 1.0, - touchPanRate: 1.0, - panInertia: 0.5, - - // Dollying - - keyboardDollyRate: 10, - mouseWheelDollyRate: 100, - touchDollyRate: 0.2, - dollyInertia: 0, - dollyProximityThreshold: 30.0, - dollyMinSpeed: 0.04 - }; - - // Current runtime state of the CameraControl - - this._states = { - pointerCanvasPos: math.vec2(), - mouseover: false, - followPointerDirty: true, - mouseDownClientX: 0, - mouseDownClientY: 0, - mouseDownCursorX: 0, - mouseDownCursorY: 0, - touchStartTime: null, - activeTouches: [], - tapStartPos: math.vec2(), - tapStartTime: -1, - lastTapTime: -1, - longTouchTimeout: null - }; - - // Updates for CameraUpdater to process on next Scene "tick" event - - this._updates = { - rotateDeltaX: 0, - rotateDeltaY: 0, - panDeltaX: 0, - panDeltaY: 0, - panDeltaZ: 0, - dollyDelta: 0 - }; - - // Controllers to assist input event handlers with controlling the Camera - - const scene = this.scene; - - this._controllers = { - cameraControl: this, - pickController: new PickController(this, this._configs), - pivotController: new PivotController(scene, this._configs), - panController: new PanController(scene), - cameraFlight: new CameraFlightAnimation(this, { - duration: 0.5 - }) - }; - - // Input event handlers - - this._handlers = [ - new MouseMiscHandler(this.scene, this._controllers, this._configs, this._states, this._updates), - new TouchPanRotateAndDollyHandler(this.scene, this._controllers, this._configs, this._states, this._updates), - new MousePanRotateDollyHandler(this.scene, this._controllers, this._configs, this._states, this._updates), - new KeyboardAxisViewHandler(this.scene, this._controllers, this._configs, this._states, this._updates), - new MousePickHandler(this.scene, this._controllers, this._configs, this._states, this._updates), - new TouchPickHandler(this.scene, this._controllers, this._configs, this._states, this._updates), - new KeyboardPanRotateDollyHandler(this.scene, this._controllers, this._configs, this._states, this._updates) - ]; - - this._cursors = { - dollyForward: "zoom-in", - dollyBackward: "zoom-out", - rotate: 'grabbing', - pan: 'move', - }; - - // Applies scheduled updates to the Camera on each Scene "tick" event - - this._cameraUpdater = new CameraUpdater(this.scene, this._controllers, this._configs, this._states, this._updates); - - // Set initial user configurations - - this.navMode = cfg.navMode; - if (cfg.planView) { - this.planView = cfg.planView; - } - this.constrainVertical = cfg.constrainVertical; - if (cfg.keyboardLayout) { - this.keyboardLayout = cfg.keyboardLayout; // Deprecated - } else { - this.keyMap = cfg.keyMap; - } - this.doublePickFlyTo = cfg.doublePickFlyTo; - this.panRightClick = cfg.panRightClick; - this.active = cfg.active; - this.followPointer = cfg.followPointer; - this.rotationInertia = cfg.rotationInertia; - this.keyboardPanRate = cfg.keyboardPanRate; - this.touchPanRate = cfg.touchPanRate; - this.keyboardRotationRate = cfg.keyboardRotationRate; - this.dragRotationRate = cfg.dragRotationRate; - this.touchDollyRate = cfg.touchDollyRate; - this.dollyInertia = cfg.dollyInertia; - this.dollyProximityThreshold = cfg.dollyProximityThreshold; - this.dollyMinSpeed = cfg.dollyMinSpeed; - this.panInertia = cfg.panInertia; - this.pointerEnabled = true; - this.keyboardDollyRate = cfg.keyboardDollyRate; - this.mouseWheelDollyRate = cfg.mouseWheelDollyRate; - } - - /** - * Sets custom mappings of keys to ````CameraControl```` actions. - * - * See class docs for usage. - * - * @param {{Number:(Number | Number[])[]} | String} value Either a set of new key mappings, or a string to select a keyboard layout, - * which causes ````CameraControl```` to use the default key mappings for that layout. - */ - set keyMap(value) { - value = value || "qwerty"; - if (utils.isString(value)) { - const input = this.scene.input; - const keyMap = {}; - - switch (value) { - - default: - this.error("Unsupported value for 'keyMap': " + value + " defaulting to 'qwerty'"); - // Intentional fall-through to "qwerty" - case "qwerty": - keyMap[this.PAN_LEFT] = [input.KEY_A]; - keyMap[this.PAN_RIGHT] = [input.KEY_D]; - keyMap[this.PAN_UP] = [input.KEY_Z]; - keyMap[this.PAN_DOWN] = [input.KEY_X]; - keyMap[this.PAN_BACKWARDS] = []; - keyMap[this.PAN_FORWARDS] = []; - keyMap[this.DOLLY_FORWARDS] = [input.KEY_W, input.KEY_ADD]; - keyMap[this.DOLLY_BACKWARDS] = [input.KEY_S, input.KEY_SUBTRACT]; - keyMap[this.ROTATE_X_POS] = [input.KEY_DOWN_ARROW]; - keyMap[this.ROTATE_X_NEG] = [input.KEY_UP_ARROW]; - keyMap[this.ROTATE_Y_POS] = [input.KEY_Q, input.KEY_LEFT_ARROW]; - keyMap[this.ROTATE_Y_NEG] = [input.KEY_E, input.KEY_RIGHT_ARROW]; - keyMap[this.AXIS_VIEW_RIGHT] = [input.KEY_NUM_1]; - keyMap[this.AXIS_VIEW_BACK] = [input.KEY_NUM_2]; - keyMap[this.AXIS_VIEW_LEFT] = [input.KEY_NUM_3]; - keyMap[this.AXIS_VIEW_FRONT] = [input.KEY_NUM_4]; - keyMap[this.AXIS_VIEW_TOP] = [input.KEY_NUM_5]; - keyMap[this.AXIS_VIEW_BOTTOM] = [input.KEY_NUM_6]; - keyMap[this.MOUSE_PAN] = [ - [input.MOUSE_LEFT_BUTTON, input.KEY_SHIFT], - this._configs.panRightClick ? input.MOUSE_RIGHT_BUTTON : input.MOUSE_MIDDLE_BUTTON - ]; - keyMap[this.MOUSE_ROTATE] = [input.MOUSE_LEFT_BUTTON]; - keyMap[this.MOUSE_DOLLY] = []; - break; - - case "azerty": - keyMap[this.PAN_LEFT] = [input.KEY_Q]; - keyMap[this.PAN_RIGHT] = [input.KEY_D]; - keyMap[this.PAN_UP] = [input.KEY_W]; - keyMap[this.PAN_DOWN] = [input.KEY_X]; - keyMap[this.PAN_BACKWARDS] = []; - keyMap[this.PAN_FORWARDS] = []; - keyMap[this.DOLLY_FORWARDS] = [input.KEY_Z, input.KEY_ADD]; - keyMap[this.DOLLY_BACKWARDS] = [input.KEY_S, input.KEY_SUBTRACT]; - keyMap[this.ROTATE_X_POS] = [input.KEY_DOWN_ARROW]; - keyMap[this.ROTATE_X_NEG] = [input.KEY_UP_ARROW]; - keyMap[this.ROTATE_Y_POS] = [input.KEY_A, input.KEY_LEFT_ARROW]; - keyMap[this.ROTATE_Y_NEG] = [input.KEY_E, input.KEY_RIGHT_ARROW]; - keyMap[this.AXIS_VIEW_RIGHT] = [input.KEY_NUM_1]; - keyMap[this.AXIS_VIEW_BACK] = [input.KEY_NUM_2]; - keyMap[this.AXIS_VIEW_LEFT] = [input.KEY_NUM_3]; - keyMap[this.AXIS_VIEW_FRONT] = [input.KEY_NUM_4]; - keyMap[this.AXIS_VIEW_TOP] = [input.KEY_NUM_5]; - keyMap[this.AXIS_VIEW_BOTTOM] = [input.KEY_NUM_6]; - keyMap[this.MOUSE_PAN] = [ - [input.MOUSE_LEFT_BUTTON, input.KEY_SHIFT], - this._configs.panRightClick ? input.MOUSE_RIGHT_BUTTON : input.MOUSE_MIDDLE_BUTTON - ]; - keyMap[this.MOUSE_ROTATE] = [input.MOUSE_LEFT_BUTTON]; - keyMap[this.MOUSE_DOLLY] = []; - break; - } - - this._keyMap = keyMap; - } else { - const keyMap = value; - this._keyMap = keyMap; - } - } - - /** - * Gets custom mappings of keys to {@link CameraControl} actions. - * - * @returns {{Number:(Number | Number[])[]}} Current key mappings. - */ - get keyMap() { - return this._keyMap; - } - - _areAllKeysDown(keyDownMap, keys) { - if (!keys || keys.length <= 0) { - return true; - } - if (!keyDownMap) { - return false; - } - for (let i = 0, len = keys.length; i < len; i++) { - const key = keys[i]; - if (!keyDownMap[key]) - return false; - } - return true; - } - - _isAnyOtherKeyDown(keyDownMap, keyMap) { - for (let i = 0, len = keyDownMap.length; i < len; i++) { - if (keyDownMap[i]) { - if (Array.isArray(keyMap)) { - if (keyMap.indexOf(i) < 0) return true; - } - else if (i !== keyMap) return true; - } - } - return false; - } - - _isMouseAction(action) { - switch (action) { - case this.MOUSE_ROTATE: - case this.MOUSE_DOLLY: - case this.MOUSE_PAN: - return true; - default: - return false; - } - } - - /** - * Returns true if any keys configured for the given action are down. - * @param action - * @param keyDownMap - * @private - */ - _isKeyDownForAction(action, keyDownMap) { - const keys = this._keyMap[action]; - if (!keys) { - return false; - } - if (keys.length === 0 && this._isMouseAction(action)) return true; - if (!keyDownMap) { - keyDownMap = this.scene.input.keyDown; - } - for (let i = 0, len = keys.length; i < len; i++) { - const key = keys[i]; - if (!Array.isArray(key)) { - if (keyDownMap[key] && !this._isAnyOtherKeyDown(keyDownMap, key)) - return true; - } - else { - if (this._areAllKeysDown(keyDownMap, key) && !this._isAnyOtherKeyDown(keyDownMap, key)) - return true; - } - - } - return false; - } - - /** - * Sets the HTMl element to represent the pivot point when {@link CameraControl#followPointer} is true. - * - * See class comments for an example. - * - * @param {HTMLElement} element HTML element representing the pivot point. - */ - set pivotElement(element) { - this._controllers.pivotController.setPivotElement(element); - } - - /** - * Sets if this ````CameraControl```` is active or not. - * - * When inactive, the ````CameraControl```` will not react to input. - * - * Default is ````true````. - * - * @param {Boolean} value Set ````true```` to activate this ````CameraControl````. - */ - set active(value) { - value = value !== false; - this._configs.active = value; - this._handlers[1]._active = value; - this._handlers[5]._active = value; - } - - /** - * Gets if this ````CameraControl```` is active or not. - * - * When inactive, the ````CameraControl```` will not react to input. - * - * Default is ````true````. - * - * @returns {Boolean} Returns ````true```` if this ````CameraControl```` is active. - */ - get active() { - return this._configs.active; - } - - /** - * Sets whether the pointer snap to vertex. - * - * @param {boolean} snapToVertex - */ - set snapToVertex(snapToVertex) { - this._configs.snapToVertex = !!snapToVertex; - } - - /** - * Gets whether the pointer snap to vertex. - * - * @returns {boolean} - */ - get snapToVertex() { - return this._configs.snapToVertex; - } - - /** - * Sets whether the pointer snap to edge. - * - * @param {boolean} snapToEdge - */ - set snapToEdge(snapToEdge) { - this._configs.snapToEdge = !!snapToEdge; - } - - /** - * Gets whether the pointer snap to edge. - * - * @returns {boolean} - */ - get snapToEdge() { - return this._configs.snapToEdge; - } - - /** - * Sets the current snap radius for "hoverSnapOrSurface" events, to specify whether the radius - * within which the pointer snaps to the nearest vertex or the nearest edge. - * - * Default value is 30 pixels. - * - * @param {Number} snapRadius The snap radius. - */ - set snapRadius(snapRadius) { - snapRadius = snapRadius || DEFAULT_SNAP_PICK_RADIUS; - this._configs.snapRadius = snapRadius; - } - - /** - * Gets the current snap radius. - * - * @returns {Number} The snap radius. - */ - get snapRadius() { - return this._configs.snapRadius; - } - - /** - * If `true`, the keyboard shortcuts are enabled ONLY if the mouse is over the canvas. - * - * @param {boolean} value - */ - set keyboardEnabledOnlyIfMouseover(value) { - this._configs.keyboardEnabledOnlyIfMouseover = !!value; - } - - /** - * Gets whether the keyboard shortcuts are enabled ONLY if the mouse is over the canvas or ALWAYS. - * - * @returns {boolean} - */ - get keyboardEnabledOnlyIfMouseover() { - return this._configs.keyboardEnabledOnlyIfMouseover; - } - - /** - * Sets the current navigation mode. - * - * Accepted values are: - * - * * "orbit" - rotation orbits about the current target or pivot point, - * * "firstPerson" - rotation is about the current eye position, - * * "planView" - rotation is disabled. - * - * See class comments for more info. - * - * @param {String} navMode The navigation mode: "orbit", "firstPerson" or "planView". - */ - set navMode(navMode) { - navMode = navMode || "orbit"; - if (navMode !== "firstPerson" && navMode !== "orbit" && navMode !== "planView") { - this.error("Unsupported value for navMode: " + navMode + " - supported values are 'orbit', 'firstPerson' and 'planView' - defaulting to 'orbit'"); - navMode = "orbit"; - } - this._configs.firstPerson = (navMode === "firstPerson"); - this._configs.planView = (navMode === "planView"); - if (this._configs.firstPerson || this._configs.planView) { - this._controllers.pivotController.hidePivot(); - this._controllers.pivotController.endPivot(); - } - this._configs.navMode = navMode; - } - - /** - * Gets the current navigation mode. - * - * @returns {String} The navigation mode: "orbit", "firstPerson" or "planView". - */ - get navMode() { - return this._configs.navMode; - } - - /** - * Sets whether mouse and touch input is enabled. - * - * Default is ````true````. - * - * Disabling mouse and touch input on ````CameraControl```` is useful when we want to temporarily use mouse or - * touch input to interact with some other 3D control, without disturbing the {@link Camera}. - * - * @param {Boolean} value Set ````true```` to enable mouse and touch input. - */ - set pointerEnabled(value) { - this._reset(); - this._configs.pointerEnabled = !!value; - } - - /** - * Sets the cursor to be used when a particular action is being performed. - * - * Accepted actions are: - * - * * "dollyForward" - when the camera is dollying in the forward direction - * * "dollyBackward" - when the camera is dollying in the backward direction - * * "pan" - when the camera is being panned - * * "rotate" - when the camera is being rotated - * - * @param {String} action - * @param {String} style - */ - setCursorStyle(action, style) { - if (Object.prototype.hasOwnProperty.call(this._cursors, action)) { - this._cursors = { ...this._cursors, [action]: style }; - } - else - console.warn(`Action '${action}' is not valid for cursor styles.`); - } - - /** - * Gets the current style for a particular action. - * - * @param {String} action To get the style for - * @returns {String} style set on the cursor for action - */ - getCursorStyle(action) { - return this._cursors[action] || null; - } - - _reset() { - for (let i = 0, len = this._handlers.length; i < len; i++) { - const handler = this._handlers[i]; - if (handler.reset) { - handler.reset(); - } - } - - this._updates.panDeltaX = 0; - this._updates.panDeltaY = 0; - this._updates.rotateDeltaX = 0; - this._updates.rotateDeltaY = 0; - this._updates.dolyDelta = 0; - } - - /** - * Gets whether mouse and touch input is enabled. - * - * Default is ````true````. - * - * Disabling mouse and touch input on ````CameraControl```` is desirable when we want to temporarily use mouse or - * touch input to interact with some other 3D control, without interfering with the {@link Camera}. - * - * @returns {Boolean} Returns ````true```` if mouse and touch input is enabled. - */ - get pointerEnabled() { - return this._configs.pointerEnabled; - } - - /** - * Sets whether the {@link Camera} follows the mouse/touch pointer. - * - * In orbiting mode, the Camera will orbit about the pointer, and will dolly to and from the pointer. - * - * In fly-to mode, the Camera will dolly to and from the pointer, however the World will always rotate about the Camera position. - * - * In plan-view mode, the Camera will dolly to and from the pointer, however the Camera will not rotate. - * - * Default is ````true````. - * - * See class comments for more info. - * - * @param {Boolean} value Set ````true```` to enable the Camera to follow the pointer. - */ - set followPointer(value) { - this._configs.followPointer = (value !== false); - } - - /** - * Sets whether the {@link Camera} follows the mouse/touch pointer. - * - * In orbiting mode, the Camera will orbit about the pointer, and will dolly to and from the pointer. - * - * In fly-to mode, the Camera will dolly to and from the pointer, however the World will always rotate about the Camera position. - * - * In plan-view mode, the Camera will dolly to and from the pointer, however the Camera will not rotate. - * - * Default is ````true````. - * - * See class comments for more info. - * - * @returns {Boolean} Returns ````true```` if the Camera follows the pointer. - */ - get followPointer() { - return this._configs.followPointer; - } - - /** - * Sets the current World-space 3D target position. - * - * Only applies when {@link CameraControl#followPointer} is ````true````. - * - * @param {Number[]} worldPos The new World-space 3D target position. - */ - set pivotPos(worldPos) { - this._controllers.pivotController.setPivotPos(worldPos); - } - - /** - * Gets the current World-space 3D pivot position. - * - * Only applies when {@link CameraControl#followPointer} is ````true````. - * - * @return {Number[]} worldPos The current World-space 3D pivot position. - */ - get pivotPos() { - return this._controllers.pivotController.getPivotPos(); - } - - /** - * @deprecated - * @param {Boolean} value Set ````true```` to enable dolly-to-pointer behaviour. - */ - set dollyToPointer(value) { - this.warn("dollyToPointer property is deprecated - replaced with followPointer"); - this.followPointer = value; - } - - /** - * @deprecated - * @returns {Boolean} Returns ````true```` if dolly-to-pointer behaviour is enabled. - */ - get dollyToPointer() { - this.warn("dollyToPointer property is deprecated - replaced with followPointer"); - return this.followPointer; - } - - /** - * @deprecated - * @param {Boolean} value Set ````true```` to enable dolly-to-pointer behaviour. - */ - set panToPointer(value) { - this.warn("panToPointer property is deprecated - replaced with followPointer"); - } - - /** - * @deprecated - * @returns {Boolean} Returns ````true```` if dolly-to-pointer behaviour is enabled. - */ - get panToPointer() { - this.warn("panToPointer property is deprecated - replaced with followPointer"); - return false; - } - - /** - * Sets whether this ````CameraControl```` is in plan-view mode. - * - * When in plan-view mode, rotation is disabled. - * - * Default is ````false````. - * - * Deprecated - use {@link CameraControl#navMode} instead. - * - * @param {Boolean} value Set ````true```` to enable plan-view mode. - * @deprecated - */ - set planView(value) { - this._configs.planView = !!value; - this._configs.firstPerson = false; - if (this._configs.planView) { - this._controllers.pivotController.hidePivot(); - this._controllers.pivotController.endPivot(); - } - this.warn("planView property is deprecated - replaced with navMode"); - } - - /** - * Gets whether this ````CameraControl```` is in plan-view mode. - * - * When in plan-view mode, rotation is disabled. - * - * Default is ````false````. - * - * Deprecated - use {@link CameraControl#navMode} instead. - * - * @returns {Boolean} Returns ````true```` if plan-view mode is enabled. - * @deprecated - */ - get planView() { - this.warn("planView property is deprecated - replaced with navMode"); - return this._configs.planView; - } - - /** - * Sets whether this ````CameraControl```` is in first-person mode. - * - * In "first person" mode (disabled by default) the look position rotates about the eye position. Otherwise, {@link Camera#eye} rotates about {@link Camera#look}. - * - * Default is ````false````. - * - * Deprecated - use {@link CameraControl#navMode} instead. - * - * @param {Boolean} value Set ````true```` to enable first-person mode. - * @deprecated - */ - set firstPerson(value) { - this.warn("firstPerson property is deprecated - replaced with navMode"); - this._configs.firstPerson = !!value; - this._configs.planView = false; - if (this._configs.firstPerson) { - this._controllers.pivotController.hidePivot(); - this._controllers.pivotController.endPivot(); - } - } - - /** - * Gets whether this ````CameraControl```` is in first-person mode. - * - * In "first person" mode (disabled by default) the look position rotates about the eye position. Otherwise, {@link Camera#eye} rotates about {@link Camera#look}. - * - * Default is ````false````. - * - * Deprecated - use {@link CameraControl#navMode} instead. - * - * @returns {Boolean} Returns ````true```` if first-person mode is enabled. - * @deprecated - */ - get firstPerson() { - this.warn("firstPerson property is deprecated - replaced with navMode"); - return this._configs.firstPerson; - } - - /** - * Sets whether to vertically constrain the {@link Camera} position for first-person navigation. - * - * When set ````true````, this constrains {@link Camera#eye} to its current vertical position. - * - * Only applies when {@link CameraControl#navMode} is ````"firstPerson"````. - * - * Default is ````false````. - * - * @param {Boolean} value Set ````true```` to vertically constrain the Camera. - */ - set constrainVertical(value) { - this._configs.constrainVertical = !!value; - } - - /** - * Gets whether to vertically constrain the {@link Camera} position for first-person navigation. - * - * When set ````true````, this constrains {@link Camera#eye} to its current vertical position. - * - * Only applies when {@link CameraControl#navMode} is ````"firstPerson"````. - * - * Default is ````false````. - * - * @returns {Boolean} ````true```` when Camera is vertically constrained. - */ - get constrainVertical() { - return this._configs.constrainVertical; - } - - /** - * Sets whether double-picking an {@link Entity} causes the {@link Camera} to fly to its boundary. - * - * Default is ````false````. - * - * @param {Boolean} value Set ````true```` to enable double-pick-fly-to mode. - */ - set doublePickFlyTo(value) { - this._configs.doublePickFlyTo = value !== false; - } - - /** - * Gets whether double-picking an {@link Entity} causes the {@link Camera} to fly to its boundary. - * - * Default is ````false````. - * - * @returns {Boolean} Returns ````true```` when double-pick-fly-to mode is enabled. - */ - get doublePickFlyTo() { - return this._configs.doublePickFlyTo; - } - - /** - * Sets whether either right-clicking (true) or middle-clicking (false) pans the {@link Camera}. - * - * Default is ````true````. - * - * @param {Boolean} value Set ````false```` to disable pan on right-click. - */ - set panRightClick(value) { - this._configs.panRightClick = value !== false; - const panKeyMap = this._keyMap[this.MOUSE_PAN]; - if (panKeyMap && panKeyMap.length > 0) { - const input = this.scene.input; - for (let i = 0, len = panKeyMap.length; i < len; i++) { - if (this._configs.panRightClick && panKeyMap[i] === input.MOUSE_MIDDLE_BUTTON) - this._keyMap[this.MOUSE_PAN][i] = input.MOUSE_RIGHT_BUTTON; - else if (!this._configs.panRightClick && panKeyMap[i] === input.MOUSE_RIGHT_BUTTON) - this._keyMap[this.MOUSE_PAN][i] = input.MOUSE_MIDDLE_BUTTON; - } - } - } - - /** - * Gets whether right-clicking pans the {@link Camera}. - * - * Default is ````true````. - * - * @returns {Boolean} Returns ````false```` when pan on right-click is disabled. - */ - get panRightClick() { - return this._configs.panRightClick; - } - - /** - * Sets a factor in range ````[0..1]```` indicating how much the {@link Camera} keeps moving after you finish rotating it. - * - * A value of ````0.0```` causes it to immediately stop, ````0.5```` causes its movement to decay 50% on each tick, - * while ````1.0```` causes no decay, allowing it continue moving, by the current rate of rotation. - * - * You may choose an inertia of zero when you want be able to precisely rotate the Camera, - * without interference from inertia. Zero inertia can also mean that less frames are rendered while - * you are rotating the Camera. - * - * Default is ````0.0````. - * - * Does not apply when {@link CameraControl#navMode} is ````"planView"````, which disallows rotation. - * - * @param {Number} rotationInertia New inertial factor. - */ - set rotationInertia(rotationInertia) { - this._configs.rotationInertia = (rotationInertia !== undefined && rotationInertia !== null) ? rotationInertia : 0.0; - } - - /** - * Gets the rotation inertia factor. - * - * Default is ````0.0````. - * - * Does not apply when {@link CameraControl#navMode} is ````"planView"````, which disallows rotation. - * - * @returns {Number} The inertia factor. - */ - get rotationInertia() { - return this._configs.rotationInertia; - } - - /** - * Sets how much the {@link Camera} pans each second with keyboard input. - * - * Default is ````5.0````, to pan the Camera ````5.0```` World-space units every second that - * a panning key is depressed. See the ````CameraControl```` class documentation for which keys control - * panning. - * - * Panning direction is aligned to our Camera's orientation. When we pan horizontally, we pan - * to our left and right, when we pan vertically, we pan upwards and downwards, and when we pan forwards - * and backwards, we pan along the direction the Camera is pointing. - * - * Unlike dollying when {@link followPointer} is ````true````, panning does not follow the pointer. - * - * @param {Number} keyboardPanRate The new keyboard pan rate. - */ - set keyboardPanRate(keyboardPanRate) { - this._configs.keyboardPanRate = (keyboardPanRate !== null && keyboardPanRate !== undefined) ? keyboardPanRate : 5.0; - } - - - /** - * Sets how fast the camera pans on touch panning - * - * @param {Number} touchPanRate The new touch pan rate. - */ - set touchPanRate(touchPanRate) { - this._configs.touchPanRate = (touchPanRate !== null && touchPanRate !== undefined) ? touchPanRate : 1.0; - } - - /** - * Gets how fast the {@link Camera} pans on touch panning - * - * Default is ````1.0````. - * - * @returns {Number} The current touch pan rate. - */ - get touchPanRate() { - return this._configs.touchPanRate; - } - - /** - * Gets how much the {@link Camera} pans each second with keyboard input. - * - * Default is ````5.0````. - * - * @returns {Number} The current keyboard pan rate. - */ - get keyboardPanRate() { - return this._configs.keyboardPanRate; - } - - /** - * Sets how many degrees per second the {@link Camera} rotates/orbits with keyboard input. - * - * Default is ````90.0````, to rotate/orbit the Camera ````90.0```` degrees every second that - * a rotation key is depressed. See the ````CameraControl```` class documentation for which keys control - * rotation/orbit. - * - * @param {Number} keyboardRotationRate The new keyboard rotation rate. - */ - set keyboardRotationRate(keyboardRotationRate) { - this._configs.keyboardRotationRate = (keyboardRotationRate !== null && keyboardRotationRate !== undefined) ? keyboardRotationRate : 90.0; - } - - /** - * Sets how many degrees per second the {@link Camera} rotates/orbits with keyboard input. - * - * Default is ````90.0````. - * - * @returns {Number} The current keyboard rotation rate. - */ - get keyboardRotationRate() { - return this._configs.keyboardRotationRate; - } - - /** - * Sets the current drag rotation rate. - * - * This configures how many degrees the {@link Camera} rotates/orbits for a full sweep of the canvas by mouse or touch dragging. - * - * For example, a value of ````360.0```` indicates that the ````Camera```` rotates/orbits ````360.0```` degrees horizontally - * when we sweep the entire width of the canvas. - * - * ````CameraControl```` makes vertical rotation half as sensitive as horizontal rotation, so that we don't tend to - * flip upside-down. Therefore, a value of ````360.0```` rotates/orbits the ````Camera```` through ````180.0```` degrees - * vertically when we sweep the entire height of the canvas. - * - * Default is ````360.0````. - * - * @param {Number} dragRotationRate The new drag rotation rate. - */ - set dragRotationRate(dragRotationRate) { - this._configs.dragRotationRate = (dragRotationRate !== null && dragRotationRate !== undefined) ? dragRotationRate : 360.0; - } - - /** - * Gets the current drag rotation rate. - * - * Default is ````360.0````. - * - * @returns {Number} The current drag rotation rate. - */ - get dragRotationRate() { - return this._configs.dragRotationRate; - } - - /** - * Sets how much the {@link Camera} dollys each second with keyboard input. - * - * Default is ````15.0````, to dolly the {@link Camera} ````15.0```` World-space units per second while we hold down - * the ````+```` and ````-```` keys. - * - * @param {Number} keyboardDollyRate The new keyboard dolly rate. - */ - set keyboardDollyRate(keyboardDollyRate) { - this._configs.keyboardDollyRate = (keyboardDollyRate !== null && keyboardDollyRate !== undefined) ? keyboardDollyRate : 15.0; - } - - /** - * Gets how much the {@link Camera} dollys each second with keyboard input. - * - * Default is ````15.0````. - * - * @returns {Number} The current keyboard dolly rate. - */ - get keyboardDollyRate() { - return this._configs.keyboardDollyRate; - } - - /** - * Sets how much the {@link Camera} dollys with touch input. - * - * Default is ````0.2```` - * - * @param {Number} touchDollyRate The new touch dolly rate. - */ - set touchDollyRate(touchDollyRate) { - this._configs.touchDollyRate = (touchDollyRate !== null && touchDollyRate !== undefined) ? touchDollyRate : 0.2; - } - - /** - * Gets how much the {@link Camera} dollys each second with touch input. - * - * Default is ````0.2````. - * - * @returns {Number} The current touch dolly rate. - */ - get touchDollyRate() { - return this._configs.touchDollyRate; - } - - /** - * Sets how much the {@link Camera} dollys each second while the mouse wheel is spinning. - * - * Default is ````100.0````, to dolly the {@link Camera} ````10.0```` World-space units per second as we spin - * the mouse wheel. - * - * @param {Number} mouseWheelDollyRate The new mouse wheel dolly rate. - */ - set mouseWheelDollyRate(mouseWheelDollyRate) { - this._configs.mouseWheelDollyRate = (mouseWheelDollyRate !== null && mouseWheelDollyRate !== undefined) ? mouseWheelDollyRate : 100.0; - } - - /** - * Gets how much the {@link Camera} dollys each second while the mouse wheel is spinning. - * - * Default is ````100.0````. - * - * @returns {Number} The current mouseWheel dolly rate. - */ - get mouseWheelDollyRate() { - return this._configs.mouseWheelDollyRate; - } - - /** - * Sets the dolly inertia factor. - * - * This factor configures how much the {@link Camera} keeps moving after you finish dollying it. - * - * This factor is a value in range ````[0..1]````. A value of ````0.0```` causes dollying to immediately stop, - * ````0.5```` causes dollying to decay 50% on each animation frame, while ````1.0```` causes no decay, which allows dollying - * to continue until further input stops it. - * - * You might set ````dollyInertia```` to zero when you want be able to precisely position or rotate the Camera, - * without interference from inertia. This also means that xeokit renders less frames while dollying the Camera, - * which can improve rendering performance. - * - * Default is ````0````. - * - * @param {Number} dollyInertia New dolly inertia factor. - */ - set dollyInertia(dollyInertia) { - this._configs.dollyInertia = (dollyInertia !== undefined && dollyInertia !== null) ? dollyInertia : 0; - } - - /** - * Gets the dolly inertia factor. - * - * Default is ````0````. - * - * @returns {Number} The current dolly inertia factor. - */ - get dollyInertia() { - return this._configs.dollyInertia; - } - - /** - * Sets the proximity to the closest object below which dolly speed decreases, and above which dolly speed increases. - * - * Default is ````35.0````. - * - * @param {Number} dollyProximityThreshold New dolly proximity threshold. - */ - set dollyProximityThreshold(dollyProximityThreshold) { - this._configs.dollyProximityThreshold = (dollyProximityThreshold !== undefined && dollyProximityThreshold !== null) ? dollyProximityThreshold : 35.0; - } - - /** - * Gets the proximity to the closest object below which dolly speed decreases, and above which dolly speed increases. - * - * Default is ````35.0````. - * - * @returns {Number} The current dolly proximity threshold. - */ - get dollyProximityThreshold() { - return this._configs.dollyProximityThreshold; - } - - /** - * Sets the minimum dolly speed. - * - * Default is ````0.04````. - * - * @param {Number} dollyMinSpeed New dolly minimum speed. - */ - set dollyMinSpeed(dollyMinSpeed) { - this._configs.dollyMinSpeed = (dollyMinSpeed !== undefined && dollyMinSpeed !== null) ? dollyMinSpeed : 0.04; - } - - /** - * Gets the minimum dolly speed. - * - * Default is ````0.04````. - * - * @returns {Number} The current minimum dolly speed. - */ - get dollyMinSpeed() { - return this._configs.dollyMinSpeed; - } - - /** - * Sets the pan inertia factor. - * - * This factor configures how much the {@link Camera} keeps moving after you finish panning it. - * - * This factor is a value in range ````[0..1]````. A value of ````0.0```` causes panning to immediately stop, - * ````0.5```` causes panning to decay 50% on each animation frame, while ````1.0```` causes no decay, which allows panning - * to continue until further input stops it. - * - * You might set ````panInertia```` to zero when you want be able to precisely position or rotate the Camera, - * without interference from inertia. This also means that xeokit renders less frames while panning the Camera, - * wich can improve rendering performance. - * - * Default is ````0.5````. - * - * @param {Number} panInertia New pan inertia factor. - */ - set panInertia(panInertia) { - this._configs.panInertia = (panInertia !== undefined && panInertia !== null) ? panInertia : 0.5; - } - - /** - * Gets the pan inertia factor. - * - * Default is ````0.5````. - * - * @returns {Number} The current pan inertia factor. - */ - get panInertia() { - return this._configs.panInertia; - } - - /** - * Sets the keyboard layout. - * - * Supported layouts are: - * - * * ````"qwerty"```` (default) - * * ````"azerty"```` - * - * @deprecated - * @param {String} value Selects the keyboard layout. - */ - set keyboardLayout(value) { - // this.warn("keyboardLayout property is deprecated - use keyMap property instead"); - value = value || "qwerty"; - if (value !== "qwerty" && value !== "azerty") { - this.error("Unsupported value for keyboardLayout - defaulting to 'qwerty'"); - value = "qwerty"; - } - this._configs.keyboardLayout = value; - this.keyMap = this._configs.keyboardLayout; - } - - /** - * Gets the keyboard layout. - * - * Supported layouts are: - * - * * ````"qwerty"```` (default) - * * ````"azerty"```` - * - * @deprecated - * @returns {String} The current keyboard layout. - */ - get keyboardLayout() { - return this._configs.keyboardLayout; - } - - /** - * Sets a sphere as the representation of the pivot position. - * - * @param {Object} [cfg] Sphere configuration. - * @param {String} [cfg.size=1] Optional size factor of the sphere. Defaults to 1. - * @param {String} [cfg.material=PhongMaterial] Optional size factor of the sphere. Defaults to a red opaque material. - */ - enablePivotSphere(cfg = {}) { - this._controllers.pivotController.enablePivotSphere(cfg); - } - - /** - * Remove the sphere as the representation of the pivot position. - * - */ - disablePivotSphere() { - this._controllers.pivotController.disablePivotSphere(); - } - - /** - * Sets whether smart default pivoting is enabled. - * - * When ````true````, we'll pivot by default about the 3D position of the mouse/touch pointer on an - * imaginary sphere that's centered at {@link Camera#eye} and sized to the {@link Scene} boundary. - * - * When ````false````, we'll pivot by default about {@link Camera#look}. - * - * Default is ````false````. - * - * @param {Boolean} enabled Set ````true```` to pivot by default about the selected point on the virtual sphere, or ````false```` to pivot by default about {@link Camera#look}. - */ - set smartPivot(enabled) { - this._configs.smartPivot = (enabled !== false); - } - - /** - * Gets whether smart default pivoting is enabled. - * - * When ````true````, we'll pivot by default about the 3D position of the mouse/touch pointer on an - * imaginary sphere that's centered at {@link Camera#eye} and sized to the {@link Scene} boundary. - * - * When ````false````, we'll pivot by default about {@link Camera#look}. - * - * Default is ````false````. - * - * @returns {Boolean} Returns ````true```` when pivoting by default about the selected point on the virtual sphere, or ````false```` when pivoting by default about {@link Camera#look}. - */ - get smartPivot() { - return this._configs.smartPivot; - } - - /** - * Sets the double click time frame length in milliseconds. - * - * If two mouse click events occur within this time frame, it is considered a double click. - * - * Default is ````250```` - * - * @param {Number} value New double click time frame. - */ - set doubleClickTimeFrame(value) { - this._configs.doubleClickTimeFrame = (value !== undefined && value !== null) ? value : 250; - } - - /** - * Gets the double click time frame length in milliseconds. - * - * Default is ````250```` - * - * @param {Number} value Current double click time frame. - */ - get doubleClickTimeFrame() { - return this._configs.doubleClickTimeFrame; - } - - /** - * Sets whether to zoom the camera on mouse wheel - * - * Default is ````true```` - * - * @param {Boolean} enabled - */ - set zoomOnMouseWheel(enabled) { - this._configs.zoomOnMouseWheel = !!enabled; - } - - /** - * Gets whether to zoom the camera on mouse wheel - * - * @returns {Boolean} - */ - get zoomOnMouseWheel() { - return this._configs.zoomOnMouseWheel; - } - - /** - * Destroys this ````CameraControl````. - * @private - */ - destroy() { - this._destroyHandlers(); - this._destroyControllers(); - this._cameraUpdater.destroy(); - super.destroy(); - } - - _destroyHandlers() { - for (let i = 0, len = this._handlers.length; i < len; i++) { - const handler = this._handlers[i]; - if (handler.destroy) { - handler.destroy(); - } - } - } - - _destroyControllers() { - for (let i = 0, len = this._controllers.length; i < len; i++) { - const controller = this._controllers[i]; - if (controller.destroy) { - controller.destroy(); - } - } - } -} - -/** - * @desc A property within a {@link PropertySet}. - * - * @class Property - */ -class Property { - - /** - * @private - */ - constructor(name, value, type, valueType, description) { - - /** - * The name of this property. - * - * @property name - * @type {String} - */ - this.name = name; - - /** - * The type of this property. - * - * @property type - * @type {Number|String} - */ - this.type = type; - - /** - * The value of this property. - * - * @property value - * @type {*} - */ - this.value = value; - - /** - * The type of this property's value. - * - * @property valueType - * @type {Number|String} - */ - this.valueType = valueType; - - /** - * Informative text to explain the property. - * - * @property name - * @type {String} - */ - this.description = description; - } -} - -/** - * @desc A set of properties associated with one or more {@link MetaObject}s. - * - * A PropertySet is created within {@link MetaScene#createMetaModel} and belongs to a {@link MetaModel}. - * - * Each PropertySet is registered by {@link PropertySet#id} in {@link MetaScene#propertySets} and {@link MetaModel#propertySets}. - * - * @class PropertySet - */ -class PropertySet { - - /** - * @private - */ - constructor(params) { - - /** - * Globally-unique ID for this PropertySet. - * - * PropertySet instances are registered by this ID in {@link MetaScene#propertySets} and {@link MetaModel#propertySets}. - * - * @property id - * @type {String} - */ - this.id = params.id; - - /** - * ID of the corresponding object within the originating system, if any. - * - * @type {String} - * @abstract - */ - this.originalSystemId = params.originalSystemId; - - /** - * The MetaModels that share this PropertySet. - * @type {MetaModel[]} - */ - this.metaModels = []; - - /** - * Human-readable name of this PropertySet. - * - * @property name - * @type {String} - */ - this.name = params.name; - - /** - * Type of this PropertySet. - * - * @property type - * @type {String} - */ - this.type = params.type; - - /** - * Properties within this PropertySet. - * - * @property properties - * @type {Property[]} - */ - this.properties = []; - - if (params.properties) { - const properties = params.properties; - for (let i = 0, len = properties.length; i < len; i++) { - const property = properties[i]; - if (Number.isInteger(property)) { // Will decompress in MetaModel.finalize(); - this.properties.push(property); - } else { - this.properties.push(new Property(property.name, property.value, property.type, property.valueType, property.description)); - } - } - } - } -} - -/** - * @desc Metadata corresponding to an {@link Entity} that represents an object. - * - * An {@link Entity} represents an object when {@link Entity#isObject} is ````true```` - * - * A MetaObject corresponds to an {@link Entity} by having the same {@link MetaObject#id} as the {@link Entity#id}. - * - * A MetaObject is created within {@link MetaScene#createMetaModel} and belongs to a {@link MetaModel}. - * - * Each MetaObject is registered by {@link MetaObject#id} in {@link MetaScene#metaObjects}. - * - * A {@link MetaModel} represents its object structure with a tree of MetaObjects, with {@link MetaModel#rootMetaObject} referencing - * the root MetaObject. - * - * @class MetaObject - */ -class MetaObject { - - /** - * @private - */ - constructor(params) { - - /** - * The MetaModels that share this MetaObject. - * @type {MetaModel[]} - */ - this.metaModels = []; - - /** - * Globally-unique ID. - * - * MetaObject instances are registered by this ID in {@link MetaScene#metaObjects}. - * - * @property id - * @type {String|Number} - */ - this.id = params.id; - - /** - * ID of the parent MetaObject. - * @type {String|Number} - */ - this.parentId = params.parentId; - - /** - * The parent MetaObject. - * @type {MetaObject | null} - */ - this.parent = null; - - /** - * ID of the corresponding object within the originating system, if any. - * - * @type {String} - * @abstract - */ - this.originalSystemId = params.originalSystemId; - - /** - * Human-readable name. - * - * @property name - * @type {String} - */ - this.name = params.name; - - /** - * Type - often an IFC product type. - * - * @property type - * @type {String} - */ - this.type = params.type; - - /** - * IDs of PropertySets associated with this MetaObject. - * @type {[]|*} - */ - this.propertySetIds = params.propertySetIds; - - /** - * The {@link PropertySet}s associated with this MetaObject. - * - * @property propertySets - * @type {PropertySet[]} - */ - this.propertySets = []; - - /** - * The attributes of this MetaObject. - * @type {{}} - */ - this.attributes = params.attributes || {}; - - if (params.external !== undefined && params.external !== null) { - - /** - * External application-specific metadata - * - * Undefined when there are is no external application-specific metadata. - * - * @property external - * @type {*} - */ - this.external = params.external; - } - } - - /** - * Backwards compatibility with the object belonging to a single MetaModel. - * - * @property metaModel - * @type {MetaModel|null} - **/ - get metaModel() { - if (this.metaModels.length == 1) { - return this.metaModels[0]; - } - - return null; - } - - /** - * Gets the {@link MetaObject#id}s of the {@link MetaObject}s within the subtree. - * - * @returns {String[]} Array of {@link MetaObject#id}s. - */ - getObjectIDsInSubtree() { - const objectIds = []; - - function visit(metaObject) { - if (!metaObject) { - return; - } - objectIds.push(metaObject.id); - const children = metaObject.children; - if (children) { - for (var i = 0, len = children.length; i < len; i++) { - visit(children[i]); - } - } - } - - visit(this); - return objectIds; - } - - - /** - * Iterates over the {@link MetaObject}s within the subtree. - * - * @param {Function} callback Callback fired at each {@link MetaObject}. - */ - withMetaObjectsInSubtree(callback) { - - function visit(metaObject) { - if (!metaObject) { - return; - } - callback(metaObject); - const children = metaObject.children; - if (children) { - for (var i = 0, len = children.length; i < len; i++) { - visit(children[i]); - } - } - } - - visit(this); - } - - /** - * Gets the {@link MetaObject#id}s of the {@link MetaObject}s within the subtree that have the given {@link MetaObject#type}s. - * - * @param {String[]} types {@link MetaObject#type} values. - * @returns {String[]} Array of {@link MetaObject#id}s. - */ - getObjectIDsInSubtreeByType(types) { - const mask = {}; - for (var i = 0, len = types.length; i < len; i++) { - mask[types[i]] = types[i]; - } - const objectIds = []; - - function visit(metaObject) { - if (!metaObject) { - return; - } - if (mask[metaObject.type]) { - objectIds.push(metaObject.id); - } - const children = metaObject.children; - if (children) { - for (var i = 0, len = children.length; i < len; i++) { - visit(children[i]); - } - } - } - - visit(this); - return objectIds; - } - - /** - * Returns properties of this MeteObject as JSON. - * - * @returns {{id: (String|Number), type: String, name: String, parent: (String|Number|Undefined)}} - */ - getJSON() { - var json = { - id: this.id, - type: this.type, - name: this.name - }; - if (this.parent) { - json.parent = this.parent.id; - } - return json; - } -} - -/** - * @desc Metadata corresponding to an {@link Entity} that represents a model. - * - * An {@link Entity} represents a model when {@link Entity#isModel} is ````true```` - * - * A MetaModel corresponds to an {@link Entity} by having the same {@link MetaModel#id} as the {@link Entity#id}. - * - * A MetaModel is created by {@link MetaScene#createMetaModel} and belongs to a {@link MetaScene}. - * - * Each MetaModel is registered by {@link MetaModel#id} in {@link MetaScene#metaModels}. - * - * A {@link MetaModel} represents its object structure with a tree of {@link MetaObject}s, with {@link MetaModel#rootMetaObject} referencing the root {@link MetaObject}. - * - * @class MetaModel - */ -class MetaModel { - - /** - * Creates a new, unfinalized MetaModel. - * - * * The MetaModel is immediately registered by {@link MetaModel#id} in {@link MetaScene#metaModels}, even though it's not yet populated. - * * The MetaModel then needs to be populated with one or more calls to {@link metaModel#loadData}. - * * As we populate it, the MetaModel will create {@link MetaObject}s and {@link PropertySet}s in itself, and in the MetaScene. - * * When populated, call {@link MetaModel#finalize} to finish it off, which causes MetaScene to fire a "metaModelCreated" event. - */ - constructor(params) { - - /** - * Globally-unique ID. - * - * MetaModels are registered by ID in {@link MetaScene#metaModels}. - * - * When this MetaModel corresponds to an {@link Entity} then this ID will match the {@link Entity#id}. - * - * @property id - * @type {String|Number} - */ - this.id = params.id; - - /** - * The project ID - * @property projectId - * @type {String|Number} - */ - this.projectId = params.projectId; - - /** - * The revision ID, if available. - * - * Will be undefined if not available. - * - * @property revisionId - * @type {String|Number} - */ - this.revisionId = params.revisionId; - - /** - * The model author, if available. - * - * Will be undefined if not available. - * - * @property author - * @type {String} - */ - this.author = params.author; - - /** - * The date the model was created, if available. - * - * Will be undefined if not available. - * - * @property createdAt - * @type {String} - */ - this.createdAt = params.createdAt; - - /** - * The application that created the model, if available. - * - * Will be undefined if not available. - * - * @property creatingApplication - * @type {String} - */ - this.creatingApplication = params.creatingApplication; - - /** - * The model schema version, if available. - * - * Will be undefined if not available. - * - * @property schema - * @type {String} - */ - this.schema = params.schema; - - /** - * Metadata on the {@link Scene}. - * - * @property metaScene - * @type {MetaScene} - */ - this.metaScene = params.metaScene; - - /** - * The {@link PropertySet}s in this MetaModel. - * - * @property propertySets - * @type {PropertySet[]} - */ - this.propertySets = []; - - /** - * The root {@link MetaObject}s in this MetaModel's composition structure hierarchy. - * - * @property rootMetaObject - * @type {MetaObject[]} - */ - this.rootMetaObjects = []; - - /** - * The {@link MetaObject}s in this MetaModel, each mapped to its ID. - * - * @property metaObjects - * @type {{String:MetaObject}} - */ - this.metaObjects = {}; - - /** - * Connectivity graph. - * @type {{}} - */ - this.graph = params.graph || {}; - - this.metaScene.metaModels[this.id] = this; - - this._propertyLookup = []; - - /** - * True when this MetaModel has been finalized. - * @type {boolean} - */ - this.finalized = false; - } - - /** - * Backwards compatibility with the model having a single root MetaObject. - * - * @property rootMetaObject - * @type {MetaObject|null} - */ - get rootMetaObject() { - if (this.rootMetaObjects.length === 1) { - return this.rootMetaObjects[0]; - } - return null; - } - - /** - * Load metamodel data into this MetaModel. - * @param metaModelData - */ - loadData(metaModelData, options = {}) { - - if (this.finalized) { - throw "MetaScene already finalized - can't add more data"; - } - - this._globalizeIDs(metaModelData, options); - - const metaScene = this.metaScene; - const propertyLookup = metaModelData.properties; - - if (propertyLookup) { - for (let i = 0, len = propertyLookup.length; i < len; i++) { - this._propertyLookup.push(propertyLookup[i]); - } - } - - // Create global Property Sets - - if (metaModelData.propertySets) { - for (let i = 0, len = metaModelData.propertySets.length; i < len; i++) { - const propertySetData = metaModelData.propertySets[i]; - if (!propertySetData.properties) { // HACK: https://github.com/Creoox/creoox-ifc2gltfcxconverter/issues/8 - propertySetData.properties = []; - } - let propertySet = metaScene.propertySets[propertySetData.id]; - if (!propertySet) { - propertySet = new PropertySet({ - id: propertySetData.id, - originalSystemId: propertySetData.originalSystemId || propertySetData.id, - type: propertySetData.type, - name: propertySetData.name, - properties: propertySetData.properties - }); - metaScene.propertySets[propertySet.id] = propertySet; - } - propertySet.metaModels.push(this); - this.propertySets.push(propertySet); - } - } - - if (metaModelData.metaObjects) { - for (let i = 0, len = metaModelData.metaObjects.length; i < len; i++) { - const metaObjectData = metaModelData.metaObjects[i]; - const id = metaObjectData.id; - let metaObject = metaScene.metaObjects[id]; - if (!metaObject) { - const type = metaObjectData.type; - const originalSystemId = metaObjectData.originalSystemId; - const propertySetIds = metaObjectData.propertySets || metaObjectData.propertySetIds; - metaObject = new MetaObject({ - id, - originalSystemId, - parentId: metaObjectData.parent, - type, - name: metaObjectData.name, - attributes: metaObjectData.attributes, - propertySetIds, - external: metaObjectData.external, - }); - this.metaScene.metaObjects[id] = metaObject; - metaObject.metaModels = []; - } - this.metaObjects[id] = metaObject; - if (!metaObjectData.parent) { - this.rootMetaObjects.push(metaObject); - metaScene.rootMetaObjects[id] = metaObject; - } - metaObject.metaModels.push(this); - } - } - } - - _decompressProperties(propertyLookup, properties) { - const propsNotFound = []; - for (let i = 0, len = properties.length; i < len; i++) { - const property = properties[i]; - if (Number.isInteger(property)) { - const lookupProperty = propertyLookup[property]; - if (lookupProperty) { - properties[i] = lookupProperty; - } else { - propsNotFound.push(property); - } - } - } - if (propsNotFound.length > 0) { - console.error(`[MetaModel._decompressProperties] Properties not found: ${propsNotFound}`); - } - } - - finalize() { - - if (this.finalized) { - throw "MetaScene already finalized - can't re-finalize"; - } - - // Re-link MetaScene's entire MetaObject parent/child hierarchy - - const metaScene = this.metaScene; - - for (let objectId in metaScene.metaObjects) { - const metaObject = metaScene.metaObjects[objectId]; - if (metaObject.children) { - metaObject.children = []; - } - - // Re-link each MetaObject's property sets - - if (metaObject.propertySets) { - metaObject.propertySets = []; - } - if (metaObject.propertySetIds) { - for (let i = 0, len = metaObject.propertySetIds.length; i < len; i++) { - const propertySetId = metaObject.propertySetIds[i]; - const propertySet = metaScene.propertySets[propertySetId]; - metaObject.propertySets.push(propertySet); - } - } - } - - for (let objectId in metaScene.metaObjects) { - const metaObject = metaScene.metaObjects[objectId]; - if (metaObject.parentId) { - const parentMetaObject = metaScene.metaObjects[metaObject.parentId]; - if (parentMetaObject) { - metaObject.parent = parentMetaObject; - (parentMetaObject.children || (parentMetaObject.children = [])).push(metaObject); - } - } - } - - // Relink MetaObjects to their MetaModels - - for (let objectId in metaScene.metaObjects) { - const metaObject = metaScene.metaObjects[objectId]; - metaObject.metaModels = []; - } - - for (let modelId in metaScene.metaModels) { - const metaModel = metaScene.metaModels[modelId]; - for (let objectId in metaModel.metaObjects) { - const metaObject = metaModel.metaObjects[objectId]; - metaObject.metaModels.push(metaModel); - } - } - - // Rebuild MetaScene's MetaObjects-by-type lookup - - metaScene.metaObjectsByType = {}; - for (let objectId in metaScene.metaObjects) { - const metaObject = metaScene.metaObjects[objectId]; - const type = metaObject.type; - (metaScene.metaObjectsByType[type] || (metaScene.metaObjectsByType[type] = {}))[objectId] = metaObject; - } - - // Decompress properties - - if (this.propertySets) { - for (let i = 0, len = this.propertySets.length; i < len; i++) { - const propertySet = this.propertySets[i]; - this._decompressProperties(this._propertyLookup, propertySet.properties); - } - } - - - this._propertyLookup = []; - - this.finalized = true; - - this.metaScene.fire("metaModelCreated", this.id); - } - - /** - * Gets this MetaModel as JSON. - * @returns {{schema: (String|string|*), createdAt: (String|string|*), metaObjects: *[], author: (String|string|*), id: (String|Number|string|number|*), creatingApplication: (String|string|*), projectId: (String|Number|string|number|*), propertySets: *[]}} - */ - getJSON() { - const json = { - id: this.id, - projectId: this.projectId, - author: this.author, - createdAt: this.createdAt, - schema: this.schema, - creatingApplication: this.creatingApplication, - metaObjects: [], - propertySets: [] - }; - const metaObjectsList = Object.values(this.metaObjects); - for (let i = 0, len = metaObjectsList.length; i < len; i++) { - const metaObject = metaObjectsList[i]; - const metaObjectCfg = { - id: metaObject.id, - originalSystemId: metaObject.originalSystemId, - extId: metaObject.extId, - type: metaObject.type, - name: metaObject.name - }; - if (metaObject.parent) { - metaObjectCfg.parent = metaObject.parent.id; - } - if (metaObject.attributes) { - metaObjectCfg.attributes = metaObject.attributes; - } - if (metaObject.propertySetIds) { - metaObjectCfg.propertySetIds = metaObject.propertySetIds; - } - json.metaObjects.push(metaObjectCfg); - } - for (let i = 0, len = this.propertySets.length; i < len; i++) { - const propertySet = this.propertySets[i]; - const propertySetCfg = { - id: propertySet.id, - originalSystemId: propertySet.originalSystemId, - extId: propertySet.extId, - type: propertySet.type, - name: propertySet.name, - propertyies: [] - }; - for (let j = 0, lenj = propertySet.properties.length; j < lenj; j++) { - const property = propertySet.properties[j]; - const propertyCfg = { - id: property.id, - description: property.description, - type: property.type, - name: property.name, - value: property.value, - valueType: property.valueType - }; - propertySetCfg.properties.push(propertyCfg); - } - json.propertySets.push(propertySetCfg); - } - return json; - } - - _globalizeIDs(metaModelData, options) { - - const globalize = !!options.globalizeObjectIds; - - if (metaModelData.metaObjects) { - for (let i = 0, len = metaModelData.metaObjects.length; i < len; i++) { - const metaObjectData = metaModelData.metaObjects[i]; - - // Globalize MetaObject IDs and parent IDs - - metaObjectData.originalSystemId = metaObjectData.id; - if (metaObjectData.parent) { - metaObjectData.originalParentSystemId = metaObjectData.parent; - } - if (globalize) { - metaObjectData.id = math.globalizeObjectId(this.id, metaObjectData.id); - if (metaObjectData.parent) { - metaObjectData.parent = math.globalizeObjectId(this.id, metaObjectData.parent); - } - } - - // Globalize MetaObject property set IDs - - if (globalize) { - const propertySetIds = metaObjectData.propertySetIds; - if (propertySetIds) { - const propertySetGlobalIds = []; - for (let j = 0, lenj = propertySetIds.length; j < lenj; j++) { - propertySetGlobalIds.push(math.globalizeObjectId(this.id, propertySetIds[j])); - } - metaObjectData.propertySetIds = propertySetGlobalIds; - metaObjectData.originalSystemPropertySetIds = propertySetIds; - } - } else { - metaObjectData.originalSystemPropertySetIds = metaObjectData.propertySetIds; - } - } - } - - // Globalize global PropertySet IDs - - if (metaModelData.propertySets) { - for (let i = 0, len = metaModelData.propertySets.length; i < len; i++) { - const propertySet = metaModelData.propertySets[i]; - propertySet.originalSystemId = propertySet.id; - if (globalize) { - propertySet.id = math.globalizeObjectId(this.id, propertySet.id); - } - } - } - } -} - -/** - * @desc Metadata corresponding to a {@link Scene}. - * - * * Located in {@link Viewer#metaScene}. - * * Contains {@link MetaModel}s and {@link MetaObject}s. - * * [Scene graph example with metadata](http://xeokit.github.io/xeokit-sdk/examples/index.html#sceneRepresentation_SceneGraph_metadata) - */ -class MetaScene { - - /** - * @private - */ - constructor(viewer, scene) { - - /** - * The {@link Viewer}. - * @property viewer - * @type {Viewer} - */ - this.viewer = viewer; - - /** - * The {@link Scene}. - * @property scene - * @type {Scene} - */ - this.scene = scene; - - /** - * The {@link MetaModel}s belonging to this MetaScene, each mapped to its {@link MetaModel#modelId}. - * - * @type {{String:MetaModel}} - */ - this.metaModels = {}; - - /** - * The {@link PropertySet}s belonging to this MetaScene, each mapped to its {@link PropertySet#id}. - * - * @type {{String:PropertySet}} - */ - this.propertySets = {}; - - /** - * The {@link MetaObject}s belonging to this MetaScene, each mapped to its {@link MetaObject#id}. - * - * @type {{String:MetaObject}} - */ - this.metaObjects = {}; - - /** - * The {@link MetaObject}s belonging to this MetaScene, each mapped to its {@link MetaObject#type}. - * - * @type {{String:MetaObject}} - */ - this.metaObjectsByType = {}; - - /** - * The root {@link MetaObject}s belonging to this MetaScene, each mapped to its {@link MetaObject#id}. - * - * @type {{String:MetaObject}} - */ - this.rootMetaObjects = {}; - - /** - * Subscriptions to events sent with {@link fire}. - * @private - */ - this._eventSubs = {}; - } - - /** - * Subscribes to an event fired at this Viewer. - * - * @param {String} event The event - * @param {Function} callback Callback fired on the event - */ - on(event, callback) { - let subs = this._eventSubs[event]; - if (!subs) { - subs = []; - this._eventSubs[event] = subs; - } - subs.push(callback); - } - - /** - * Fires an event at this Viewer. - * - * @param {String} event Event name - * @param {Object} value Event parameters - */ - fire(event, value) { - const subs = this._eventSubs[event]; - if (subs) { - for (let i = 0, len = subs.length; i < len; i++) { - subs[i](value); - } - } - } - - /** - * Unsubscribes from an event fired at this Viewer. - * @param event - */ - off(event) { // TODO - - } - - /** - * Creates a {@link MetaModel} in this MetaScene. - * - * The MetaModel will contain a hierarchy of {@link MetaObject}s, created from the - * meta objects in ````metaModelData````. - * - * The meta object hierarchy in ````metaModelData```` is expected to be non-cyclic, with a single root. If the meta - * objects are cyclic, then this method will log an error and attempt to recover by creating a dummy root MetaObject - * of type "Model" and connecting all other MetaObjects as its direct children. If the meta objects contain multiple - * roots, then this method similarly attempts to recover by creating a dummy root MetaObject of type "Model" and - * connecting all the root MetaObjects as its children. - * - * @param {String} modelId ID for the new {@link MetaModel}, which will have {@link MetaModel#id} set to this value. - * @param {Object} metaModelData Data for the {@link MetaModel}. - * @param {Object} [options] Options for creating the {@link MetaModel}. - * @param {Boolean} [options.globalizeObjectIds=false] Whether to globalize each {@link MetaObject#id}. Set this ````true```` when you need to load multiple instances of the same meta model, to avoid ID clashes between the meta objects in the different instances. - * @returns {MetaModel} The new MetaModel. - */ - createMetaModel(modelId, metaModelData, options = {}) { - - const metaModel = new MetaModel({ // Registers MetaModel in #metaModels - metaScene: this, - id: modelId, - projectId: metaModelData.projectId || "none", - revisionId: metaModelData.revisionId || "none", - author: metaModelData.author || "none", - createdAt: metaModelData.createdAt || "none", - creatingApplication: metaModelData.creatingApplication || "none", - schema: metaModelData.schema || "none", - propertySets: [] - }); - - metaModel.loadData(metaModelData); - - metaModel.finalize(); - - return metaModel; - } - - /** - * Destroys this MetaScene. - */ - _destroy() { - this.viewer = null; - this.scene = null; - this.metaModels = {}; - this.propertySets = {}; - this.metaObjects = {}; - this.metaObjectsByType = {}; - this.rootMetaObjects = {}; - this._eventSubs = {}; - } - - /** - * Removes a {@link MetaModel} from this MetaScene. - * - * Fires a "metaModelDestroyed" event with the value of the {@link MetaModel#id}. - * - * @param {String} metaModelId ID of the target {@link MetaModel}. - */ - destroyMetaModel(metaModelId) { - - const metaModel = this.metaModels[metaModelId]; - if (!metaModel) { - return; - } - - // Remove global PropertySets - - if (metaModel.propertySets) { - for (let i = 0, len = metaModel.propertySets.length; i < len; i++) { - const propertySet = metaModel.propertySets[i]; - if (propertySet.metaModels.length === 1 && propertySet.metaModels[0].id === metaModelId) { // Property set owned only by this model, delete - delete this.propertySets[propertySet.id]; - } else { - const newMetaModels = []; - for (let j = 0, lenj = propertySet.metaModels.length; j < lenj; j++) { - if (propertySet.metaModels[j].id !== metaModelId) { - newMetaModels.push(propertySet.metaModels[j]); - } - } - propertySet.metaModels = newMetaModels; - } - } - } - - // Remove MetaObjects - - if (metaModel.metaObjects) { - for (let objectId in metaModel.metaObjects) { - const metaObject = metaModel.metaObjects[objectId]; - if (metaObject.metaModels.length === 1 && metaObject.metaModels[0].id === metaModelId) { // MetaObject owned only by this model, delete - delete this.metaObjects[objectId]; - if (!metaObject.parent) { - delete this.rootMetaObjects[objectId]; - } - } else { - metaObject.metaModels = metaObject.metaModels.filter(metaModel => metaModel.id !== metaModelId); - } - } - } - - // Re-link entire MetaObject parent/child hierarchy - - for (let objectId in this.metaObjects) { - const metaObject = this.metaObjects[objectId]; - if (metaObject.children) { - metaObject.children = []; - } - - // Re-link each MetaObject's property sets - - if (metaObject.propertySets) { - metaObject.propertySets = []; - } - if (metaObject.propertySetIds) { - for (let i = 0, len = metaObject.propertySetIds.length; i < len; i++) { - const propertySetId = metaObject.propertySetIds[i]; - const propertySet = this.propertySets[propertySetId]; - metaObject.propertySets.push(propertySet); - } - } - } - - this.metaObjectsByType = {}; - - for (let objectId in this.metaObjects) { - const metaObject = this.metaObjects[objectId]; - const type = metaObject.type; - if (metaObject.children) { - metaObject.children = null; - } - (this.metaObjectsByType[type] || (this.metaObjectsByType[type] = {}))[objectId] = metaObject; - } - - for (let objectId in this.metaObjects) { - const metaObject = this.metaObjects[objectId]; - if (metaObject.parentId) { - const parentMetaObject = this.metaObjects[metaObject.parentId]; - if (parentMetaObject) { - metaObject.parent = parentMetaObject; - (parentMetaObject.children || (parentMetaObject.children = [])).push(metaObject); - } - } - } - - delete this.metaModels[metaModelId]; - - // Relink MetaObjects to their MetaModels - - for (let objectId in this.metaObjects) { - const metaObject = this.metaObjects[objectId]; - metaObject.metaModels = []; - } - - for (let modelId in this.metaModels) { - const metaModel = this.metaModels[modelId]; - for (let objectId in metaModel.metaObjects) { - const metaObject = metaModel.metaObjects[objectId]; - metaObject.metaModels.push(metaModel); - } - } - - this.fire("metaModelDestroyed", metaModelId); - } - - /** - * Gets the {@link MetaObject#id}s of the {@link MetaObject}s that have the given {@link MetaObject#type}. - * - * @param {String} type The type. - * @returns {String[]} Array of {@link MetaObject#id}s. - */ - getObjectIDsByType(type) { - const metaObjects = this.metaObjectsByType[type]; - return metaObjects ? Object.keys(metaObjects) : []; - } - - /** - * Gets the {@link MetaObject#id}s of the {@link MetaObject}s within the given subtree. - * - * @param {String} id ID of the root {@link MetaObject} of the given subtree. - * @param {String[]} [includeTypes] Optional list of types to include. - * @param {String[]} [excludeTypes] Optional list of types to exclude. - * @returns {String[]} Array of {@link MetaObject#id}s. - */ - getObjectIDsInSubtree(id, includeTypes, excludeTypes) { - - const list = []; - const metaObject = this.metaObjects[id]; - const includeMask = (includeTypes && includeTypes.length > 0) ? arrayToMap(includeTypes) : null; - const excludeMask = (excludeTypes && excludeTypes.length > 0) ? arrayToMap(excludeTypes) : null; - - const visit = (metaObject) => { - if (!metaObject) { - return; - } - var include = true; - if (excludeMask && excludeMask[metaObject.type]) { - include = false; - } else if (includeMask && (!includeMask[metaObject.type])) { - include = false; - } - if (include) { - list.push(metaObject.id); - } - const children = metaObject.children; - if (children) { - for (var i = 0, len = children.length; i < len; i++) { - visit(children[i]); - } - } - }; - - visit(metaObject); - return list; - } - - /** - * Iterates over the {@link MetaObject}s within the subtree. - * - * @param {String} id ID of root {@link MetaObject}. - * @param {Function} callback Callback fired at each {@link MetaObject}. - */ - withMetaObjectsInSubtree(id, callback) { - const metaObject = this.metaObjects[id]; - if (!metaObject) { - return; - } - metaObject.withMetaObjectsInSubtree(callback); - } -} - -function arrayToMap(array) { - const map = {}; - for (var i = 0, len = array.length; i < len; i++) { - map[array[i]] = true; - } - return map; -} - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -/** - * Parses `data` using a specified loader - * @param data - * @param loaders - * @param options - * @param context - */ -// implementation signature -async function parseFromContext(data, loaders, options, context) { - return context._parse(data, loaders, options, context); -} - -/** - * Throws an `Error` with the optional `message` if `condition` is falsy - * @note Replacement for the external assert method to reduce bundle size - */ -function assert$4(condition, message) { - if (!condition) { - throw new Error(message || 'loader assertion failed.'); - } -} - -// Purpose: include this in your module to avoid -/** true if running in a browser */ -const isBrowser$2 = -// @ts-ignore process does not exist on browser -Boolean(typeof process !== 'object' || String(process) !== '[object process]' || process.browser); -// Extract node major version -const matches$1 = typeof process !== 'undefined' && process.version && /v([0-9]*)/.exec(process.version); -/** Major Node version (as a number) */ -(matches$1 && parseFloat(matches$1[1])) || 0; - -// Do not name these variables the same as the global objects - will break bundling -const window_ = globalThis; -const process_ = globalThis.process || {}; - -// based on https://github.com/cheton/is-electron -// https://github.com/electron/electron/issues/2288 -/* eslint-disable complexity */ -function isElectron(mockUserAgent) { - // Renderer process - // @ts-expect-error - if (typeof window !== 'undefined' && window.process?.type === 'renderer') { - return true; - } - // Main process - // eslint-disable-next-line - if (typeof process !== 'undefined' && Boolean(process.versions?.['electron'])) { - return true; - } - // Detect the user agent when the `nodeIntegration` option is set to true - const realUserAgent = typeof navigator !== 'undefined' && navigator.userAgent; - const userAgent = mockUserAgent || realUserAgent; - return Boolean(userAgent && userAgent.indexOf('Electron') >= 0); -} - -// This function is needed in initialization stages, -/** Check if in browser by duck-typing Node context */ -function isBrowser$1() { - const isNode = - // @ts-expect-error - typeof process === 'object' && String(process) === '[object process]' && !process?.browser; - return !isNode || isElectron(); -} - -// Extract injected version from package.json (injected by babel plugin) -// @ts-expect-error -const VERSION$7 = "4.1.0" ; -// TODO - wish we could just export a constant -// export const isBrowser = checkIfBrowser(); - -// probe.gl, MIT license -function getStorage(type) { - try { - const storage = window[type]; - const x = '__storage_test__'; - storage.setItem(x, x); - storage.removeItem(x); - return storage; - } - catch (e) { - return null; - } -} -// Store keys in local storage via simple interface -class LocalStorage { - constructor(id, defaultConfig, type = 'sessionStorage') { - this.storage = getStorage(type); - this.id = id; - this.config = defaultConfig; - this._loadConfiguration(); - } - getConfiguration() { - return this.config; - } - setConfiguration(configuration) { - Object.assign(this.config, configuration); - if (this.storage) { - const serialized = JSON.stringify(this.config); - this.storage.setItem(this.id, serialized); - } - } - // Get config from persistent store, if available - _loadConfiguration() { - let configuration = {}; - if (this.storage) { - const serializedConfiguration = this.storage.getItem(this.id); - configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {}; - } - Object.assign(this.config, configuration); - return this; - } -} - -// probe.gl, MIT license -/** - * Format time - */ -function formatTime(ms) { - let formatted; - if (ms < 10) { - formatted = `${ms.toFixed(2)}ms`; - } - else if (ms < 100) { - formatted = `${ms.toFixed(1)}ms`; - } - else if (ms < 1000) { - formatted = `${ms.toFixed(0)}ms`; - } - else { - formatted = `${(ms / 1000).toFixed(2)}s`; - } - return formatted; -} -function leftPad(string, length = 8) { - const padLength = Math.max(length - string.length, 0); - return `${' '.repeat(padLength)}${string}`; -} - -var COLOR; -(function (COLOR) { - COLOR[COLOR["BLACK"] = 30] = "BLACK"; - COLOR[COLOR["RED"] = 31] = "RED"; - COLOR[COLOR["GREEN"] = 32] = "GREEN"; - COLOR[COLOR["YELLOW"] = 33] = "YELLOW"; - COLOR[COLOR["BLUE"] = 34] = "BLUE"; - COLOR[COLOR["MAGENTA"] = 35] = "MAGENTA"; - COLOR[COLOR["CYAN"] = 36] = "CYAN"; - COLOR[COLOR["WHITE"] = 37] = "WHITE"; - COLOR[COLOR["BRIGHT_BLACK"] = 90] = "BRIGHT_BLACK"; - COLOR[COLOR["BRIGHT_RED"] = 91] = "BRIGHT_RED"; - COLOR[COLOR["BRIGHT_GREEN"] = 92] = "BRIGHT_GREEN"; - COLOR[COLOR["BRIGHT_YELLOW"] = 93] = "BRIGHT_YELLOW"; - COLOR[COLOR["BRIGHT_BLUE"] = 94] = "BRIGHT_BLUE"; - COLOR[COLOR["BRIGHT_MAGENTA"] = 95] = "BRIGHT_MAGENTA"; - COLOR[COLOR["BRIGHT_CYAN"] = 96] = "BRIGHT_CYAN"; - COLOR[COLOR["BRIGHT_WHITE"] = 97] = "BRIGHT_WHITE"; -})(COLOR || (COLOR = {})); -const BACKGROUND_INCREMENT = 10; -function getColor(color) { - if (typeof color !== 'string') { - return color; - } - color = color.toUpperCase(); - return COLOR[color] || COLOR.WHITE; -} -function addColor(string, color, background) { - if (!isBrowser$1 && typeof string === 'string') { - if (color) { - const colorCode = getColor(color); - string = `\u001b[${colorCode}m${string}\u001b[39m`; - } - if (background) { - // background colors values are +10 - const colorCode = getColor(background); - string = `\u001b[${colorCode + BACKGROUND_INCREMENT}m${string}\u001b[49m`; - } - } - return string; -} - -// Copyright (c) 2015 - 2017 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -/** - * Binds the "this" argument of all functions on a class instance to the instance - * @param obj - class instance (typically a react component) - */ -function autobind(obj, predefined = ['constructor']) { - const proto = Object.getPrototypeOf(obj); - const propNames = Object.getOwnPropertyNames(proto); - const object = obj; - for (const key of propNames) { - const value = object[key]; - if (typeof value === 'function') { - if (!predefined.find((name) => key === name)) { - object[key] = value.bind(obj); - } - } - } -} - -function assert$3(condition, message) { - if (!condition) { - throw new Error(message || 'Assertion failed'); - } -} - -// probe.gl, MIT license -/** Get best timer available. */ -function getHiResTimestamp() { - let timestamp; - if (isBrowser$1() && window_.performance) { - timestamp = window_?.performance?.now?.(); - } - else if ('hrtime' in process_) { - // @ts-ignore - const timeParts = process_?.hrtime?.(); - timestamp = timeParts[0] * 1000 + timeParts[1] / 1e6; - } - else { - timestamp = Date.now(); - } - return timestamp; -} - -// probe.gl, MIT license -// Instrumentation in other packages may override console methods, so preserve them here -const originalConsole = { - debug: isBrowser$1() ? console.debug || console.log : console.log, - log: console.log, - info: console.info, - warn: console.warn, - error: console.error -}; -const DEFAULT_LOG_CONFIGURATION = { - enabled: true, - level: 0 -}; -function noop() { } // eslint-disable-line @typescript-eslint/no-empty-function -const cache = {}; -const ONCE = { once: true }; -/** A console wrapper */ -class Log { - constructor({ id } = { id: '' }) { - this.VERSION = VERSION$7; - this._startTs = getHiResTimestamp(); - this._deltaTs = getHiResTimestamp(); - this.userData = {}; - // TODO - fix support from throttling groups - this.LOG_THROTTLE_TIMEOUT = 0; // Time before throttled messages are logged again - this.id = id; - this.userData = {}; - this._storage = new LocalStorage(`__probe-${this.id}__`, DEFAULT_LOG_CONFIGURATION); - this.timeStamp(`${this.id} started`); - autobind(this); - Object.seal(this); - } - set level(newLevel) { - this.setLevel(newLevel); - } - get level() { - return this.getLevel(); - } - isEnabled() { - return this._storage.config.enabled; - } - getLevel() { - return this._storage.config.level; - } - /** @return milliseconds, with fractions */ - getTotal() { - return Number((getHiResTimestamp() - this._startTs).toPrecision(10)); - } - /** @return milliseconds, with fractions */ - getDelta() { - return Number((getHiResTimestamp() - this._deltaTs).toPrecision(10)); - } - /** @deprecated use logLevel */ - set priority(newPriority) { - this.level = newPriority; - } - /** @deprecated use logLevel */ - get priority() { - return this.level; - } - /** @deprecated use logLevel */ - getPriority() { - return this.level; - } - // Configure - enable(enabled = true) { - this._storage.setConfiguration({ enabled }); - return this; - } - setLevel(level) { - this._storage.setConfiguration({ level }); - return this; - } - /** return the current status of the setting */ - get(setting) { - return this._storage.config[setting]; - } - // update the status of the setting - set(setting, value) { - this._storage.setConfiguration({ [setting]: value }); - } - /** Logs the current settings as a table */ - settings() { - if (console.table) { - console.table(this._storage.config); - } - else { - console.log(this._storage.config); - } - } - // Unconditional logging - assert(condition, message) { - if (!condition) { - throw new Error(message || 'Assertion failed'); - } - } - warn(message) { - return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE); - } - error(message) { - return this._getLogFunction(0, message, originalConsole.error, arguments); - } - /** Print a deprecation warning */ - deprecated(oldUsage, newUsage) { - return this.warn(`\`${oldUsage}\` is deprecated and will be removed \ -in a later version. Use \`${newUsage}\` instead`); - } - /** Print a removal warning */ - removed(oldUsage, newUsage) { - return this.error(`\`${oldUsage}\` has been removed. Use \`${newUsage}\` instead`); - } - probe(logLevel, message) { - return this._getLogFunction(logLevel, message, originalConsole.log, arguments, { - time: true, - once: true - }); - } - log(logLevel, message) { - return this._getLogFunction(logLevel, message, originalConsole.debug, arguments); - } - info(logLevel, message) { - return this._getLogFunction(logLevel, message, console.info, arguments); - } - once(logLevel, message) { - return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE); - } - /** Logs an object as a table */ - table(logLevel, table, columns) { - if (table) { - return this._getLogFunction(logLevel, table, console.table || noop, (columns && [columns]), { - tag: getTableHeader(table) - }); - } - return noop; - } - time(logLevel, message) { - return this._getLogFunction(logLevel, message, console.time ? console.time : console.info); - } - timeEnd(logLevel, message) { - return this._getLogFunction(logLevel, message, console.timeEnd ? console.timeEnd : console.info); - } - timeStamp(logLevel, message) { - return this._getLogFunction(logLevel, message, console.timeStamp || noop); - } - group(logLevel, message, opts = { collapsed: false }) { - const options = normalizeArguments({ logLevel, message, opts }); - const { collapsed } = opts; - // @ts-expect-error - options.method = (collapsed ? console.groupCollapsed : console.group) || console.info; - return this._getLogFunction(options); - } - groupCollapsed(logLevel, message, opts = {}) { - return this.group(logLevel, message, Object.assign({}, opts, { collapsed: true })); - } - groupEnd(logLevel) { - return this._getLogFunction(logLevel, '', console.groupEnd || noop); - } - // EXPERIMENTAL - withGroup(logLevel, message, func) { - this.group(logLevel, message)(); - try { - func(); - } - finally { - this.groupEnd(logLevel)(); - } - } - trace() { - if (console.trace) { - console.trace(); - } - } - // PRIVATE METHODS - /** Deduces log level from a variety of arguments */ - _shouldLog(logLevel) { - return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel); - } - _getLogFunction(logLevel, message, method, args, opts) { - if (this._shouldLog(logLevel)) { - // normalized opts + timings - opts = normalizeArguments({ logLevel, message, args, opts }); - method = method || opts.method; - assert$3(method); - opts.total = this.getTotal(); - opts.delta = this.getDelta(); - // reset delta timer - this._deltaTs = getHiResTimestamp(); - const tag = opts.tag || opts.message; - if (opts.once && tag) { - if (!cache[tag]) { - cache[tag] = getHiResTimestamp(); - } - else { - return noop; - } - } - // TODO - Make throttling work with groups - // if (opts.nothrottle || !throttle(tag, this.LOG_THROTTLE_TIMEOUT)) { - // return noop; - // } - message = decorateMessage(this.id, opts.message, opts); - // Bind console function so that it can be called after being returned - return method.bind(console, message, ...opts.args); - } - return noop; - } -} -Log.VERSION = VERSION$7; -/** - * Get logLevel from first argument: - * - log(logLevel, message, args) => logLevel - * - log(message, args) => 0 - * - log({logLevel, ...}, message, args) => logLevel - * - log({logLevel, message, args}) => logLevel - */ -function normalizeLogLevel(logLevel) { - if (!logLevel) { - return 0; - } - let resolvedLevel; - switch (typeof logLevel) { - case 'number': - resolvedLevel = logLevel; - break; - case 'object': - // Backward compatibility - // TODO - deprecate `priority` - // @ts-expect-error - resolvedLevel = logLevel.logLevel || logLevel.priority || 0; - break; - default: - return 0; - } - // 'log level must be a number' - assert$3(Number.isFinite(resolvedLevel) && resolvedLevel >= 0); - return resolvedLevel; -} -/** - * "Normalizes" the various argument patterns into an object with known types - * - log(logLevel, message, args) => {logLevel, message, args} - * - log(message, args) => {logLevel: 0, message, args} - * - log({logLevel, ...}, message, args) => {logLevel, message, args} - * - log({logLevel, message, args}) => {logLevel, message, args} - */ -function normalizeArguments(opts) { - const { logLevel, message } = opts; - opts.logLevel = normalizeLogLevel(logLevel); - // We use `arguments` instead of rest parameters (...args) because IE - // does not support the syntax. Rest parameters is transpiled to code with - // perf impact. Doing it here instead avoids constructing args when logging is - // disabled. - // TODO - remove when/if IE support is dropped - const args = opts.args ? Array.from(opts.args) : []; - // args should only contain arguments that appear after `message` - // eslint-disable-next-line no-empty - while (args.length && args.shift() !== message) { } - switch (typeof logLevel) { - case 'string': - case 'function': - if (message !== undefined) { - args.unshift(message); - } - opts.message = logLevel; - break; - case 'object': - Object.assign(opts, logLevel); - break; - } - // Resolve functions into strings by calling them - if (typeof opts.message === 'function') { - opts.message = opts.message(); - } - const messageType = typeof opts.message; - // 'log message must be a string' or object - assert$3(messageType === 'string' || messageType === 'object'); - // original opts + normalized opts + opts arg + fixed up message - return Object.assign(opts, { args }, opts.opts); -} -function decorateMessage(id, message, opts) { - if (typeof message === 'string') { - const time = opts.time ? leftPad(formatTime(opts.total)) : ''; - message = opts.time ? `${id}: ${time} ${message}` : `${id}: ${message}`; - message = addColor(message, opts.color, opts.background); - } - return message; -} -function getTableHeader(table) { - for (const key in table) { - for (const title in table[key]) { - return title || 'untitled'; - } - } - return 'empty'; -} - -// loaders.gl -// Version constant cannot be imported, it needs to correspond to the build version of **this** module. -// __VERSION__ is injected by babel-plugin-version-inline -// @ts-ignore TS2304: Cannot find name '__VERSION__'. -const VERSION$6 = "4.3.3" ; -const version = VERSION$6[0] >= '0' && VERSION$6[0] <= '9' ? `v${VERSION$6}` : ''; -// Make sure we set the global variable -function createLog() { - const log = new Log({ id: 'loaders.gl' }); - globalThis.loaders = globalThis.loaders || {}; - globalThis.loaders.log = log; - globalThis.loaders.version = version; - globalThis.probe = globalThis.probe || {}; - globalThis.probe.loaders = log; - return log; -} -const log = createLog(); - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -/** - * - * @param baseOptions Can be undefined, in which case a fresh options object will be minted - * @param newOptions - * @returns - */ -function mergeLoaderOptions(baseOptions, newOptions) { - return mergeOptionsRecursively(baseOptions || {}, newOptions); -} -function mergeOptionsRecursively(baseOptions, newOptions, level = 0) { - // Sanity check (jest test runner overwrites the console object which can lead to infinite recursion) - if (level > 3) { - return newOptions; - } - const options = { ...baseOptions }; - for (const [key, newValue] of Object.entries(newOptions)) { - if (newValue && typeof newValue === 'object' && !Array.isArray(newValue)) { - options[key] = mergeOptionsRecursively(options[key] || {}, newOptions[key], level + 1); - // Object.assign(options[key] as object, newOptions[key]); - } - else { - options[key] = newOptions[key]; - } - } - return options; -} - -// loaders.gl -/** - * Register application-imported modules - * These modules are typically to big to bundle, or may have issues on some bundlers/environments - */ -function registerJSModules(modules) { - globalThis.loaders ||= {}; - globalThis.loaders.modules ||= {}; - Object.assign(globalThis.loaders.modules, modules); -} -/** - * Get a pre-registered application-imported module, return null if not present - */ -function getJSModuleOrNull(name) { - const module = globalThis.loaders?.modules?.[name]; - return module || null; -} - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -// Version constant cannot be imported, it needs to correspond to the build version of **this** module. -/** - * TODO - unpkg.com doesn't seem to have a `latest` specifier for alpha releases... - * 'beta' on beta branch, 'latest' on prod branch - */ -const NPM_TAG = 'latest'; -function getVersion() { - if (!globalThis._loadersgl_?.version) { - globalThis._loadersgl_ = globalThis._loadersgl_ || {}; - // __VERSION__ is injected by babel-plugin-version-inline - { - globalThis._loadersgl_.version = "4.3.3"; - } - } - return globalThis._loadersgl_.version; -} -const VERSION$5 = getVersion(); - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -// Replacement for the external assert method to reduce bundle size -// Note: We don't use the second "message" argument in calling code, -// so no need to support it here -/** Throws an `Error` with the optional `message` if `condition` is falsy */ -function assert$2(condition, message) { - if (!condition) { - throw new Error(message || 'loaders.gl assertion failed.'); - } -} - -// loaders.gl -/** true if running in the browser, false if running in Node.js */ -const isBrowser = -// @ts-ignore process.browser -typeof process !== 'object' || String(process) !== '[object process]' || process.browser; -/** true if running on a worker thread */ -const isWorker = typeof importScripts === 'function'; -/** true if running on a mobile device */ -const isMobile = typeof window !== 'undefined' && typeof window.orientation !== 'undefined'; -// Extract node major version -const matches = typeof process !== 'undefined' && process.version && /v([0-9]*)/.exec(process.version); -/** Version of Node.js if running under Node, otherwise 0 */ -(matches && parseFloat(matches[1])) || 0; - -// loaders.gl -/** - * Represents one Job handled by a WorkerPool or WorkerFarm - */ -class WorkerJob { - name; - workerThread; - isRunning = true; - /** Promise that resolves when Job is done */ - result; - _resolve = () => { }; - _reject = () => { }; - constructor(jobName, workerThread) { - this.name = jobName; - this.workerThread = workerThread; - this.result = new Promise((resolve, reject) => { - this._resolve = resolve; - this._reject = reject; - }); - } - /** - * Send a message to the job's worker thread - * @param data any data structure, ideally consisting mostly of transferrable objects - */ - postMessage(type, payload) { - this.workerThread.postMessage({ - source: 'loaders.gl', // Lets worker ignore unrelated messages - type, - payload - }); - } - /** - * Call to resolve the `result` Promise with the supplied value - */ - done(value) { - assert$2(this.isRunning); - this.isRunning = false; - this._resolve(value); - } - /** - * Call to reject the `result` Promise with the supplied error - */ - error(error) { - assert$2(this.isRunning); - this.isRunning = false; - this._reject(error); - } -} - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -/** Browser polyfill for Node.js built-in `worker_threads` module. - * These fills are non-functional, and just intended to ensure that - * `import 'worker_threads` doesn't break browser builds. - * The replacement is done in package.json browser field - */ -class NodeWorker { - terminate() { } -} - -// loaders.gl -const workerURLCache = new Map(); -/** - * Creates a loadable URL from worker source or URL - * that can be used to create `Worker` instances. - * Due to CORS issues it may be necessary to wrap a URL in a small importScripts - * @param props - * @param props.source Worker source - * @param props.url Worker URL - * @returns loadable url - */ -function getLoadableWorkerURL(props) { - assert$2((props.source && !props.url) || (!props.source && props.url)); // Either source or url must be defined - let workerURL = workerURLCache.get(props.source || props.url); - if (!workerURL) { - // Differentiate worker urls from worker source code - if (props.url) { - workerURL = getLoadableWorkerURLFromURL(props.url); - workerURLCache.set(props.url, workerURL); - } - if (props.source) { - workerURL = getLoadableWorkerURLFromSource(props.source); - workerURLCache.set(props.source, workerURL); - } - } - assert$2(workerURL); - return workerURL; -} -/** - * Build a loadable worker URL from worker URL - * @param url - * @returns loadable URL - */ -function getLoadableWorkerURLFromURL(url) { - // A local script url, we can use it to initialize a Worker directly - if (!url.startsWith('http')) { - return url; - } - // A remote script, we need to use `importScripts` to load from different origin - const workerSource = buildScriptSource(url); - return getLoadableWorkerURLFromSource(workerSource); -} -/** - * Build a loadable worker URL from worker source - * @param workerSource - * @returns loadable url - */ -function getLoadableWorkerURLFromSource(workerSource) { - const blob = new Blob([workerSource], { type: 'application/javascript' }); - return URL.createObjectURL(blob); -} -/** - * Per spec, worker cannot be initialized with a script from a different origin - * However a local worker script can still import scripts from other origins, - * so we simply build a wrapper script. - * - * @param workerUrl - * @returns source - */ -function buildScriptSource(workerUrl) { - return `\ -try { - importScripts('${workerUrl}'); -} catch (error) { - console.error(error); - throw error; -}`; -} - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -// NOTE - there is a copy of this function is both in core and loader-utils -// core does not need all the utils in loader-utils, just this one. -/** - * Returns an array of Transferrable objects that can be used with postMessage - * https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage - * @param object data to be sent via postMessage - * @param recursive - not for application use - * @param transfers - not for application use - * @returns a transfer list that can be passed to postMessage - */ -function getTransferList(object, recursive = true, transfers) { - // Make sure that items in the transfer list is unique - const transfersSet = transfers || new Set(); - if (!object) ; - else if (isTransferable(object)) { - transfersSet.add(object); - } - else if (isTransferable(object.buffer)) { - // Typed array - transfersSet.add(object.buffer); - } - else if (ArrayBuffer.isView(object)) ; - else if (recursive && typeof object === 'object') { - for (const key in object) { - // Avoid perf hit - only go one level deep - getTransferList(object[key], recursive, transfersSet); - } - } - // If transfers is defined, is internal recursive call - // Otherwise it's called by the user - return transfers === undefined ? Array.from(transfersSet) : []; -} -// https://developer.mozilla.org/en-US/docs/Web/API/Transferable -function isTransferable(object) { - if (!object) { - return false; - } - if (object instanceof ArrayBuffer) { - return true; - } - if (typeof MessagePort !== 'undefined' && object instanceof MessagePort) { - return true; - } - if (typeof ImageBitmap !== 'undefined' && object instanceof ImageBitmap) { - return true; - } - // @ts-ignore - if (typeof OffscreenCanvas !== 'undefined' && object instanceof OffscreenCanvas) { - return true; - } - return false; -} - -// loaders.gl -const NOOP = () => { }; -/** - * Represents one worker thread - */ -class WorkerThread { - name; - source; - url; - terminated = false; - worker; - onMessage; - onError; - _loadableURL = ''; - /** Checks if workers are supported on this platform */ - static isSupported() { - return ((typeof Worker !== 'undefined' && isBrowser) || - (typeof NodeWorker !== 'undefined' && !isBrowser)); - } - constructor(props) { - const { name, source, url } = props; - assert$2(source || url); // Either source or url must be defined - this.name = name; - this.source = source; - this.url = url; - this.onMessage = NOOP; - this.onError = (error) => console.log(error); // eslint-disable-line - this.worker = isBrowser ? this._createBrowserWorker() : this._createNodeWorker(); - } - /** - * Terminate this worker thread - * @note Can free up significant memory - */ - destroy() { - this.onMessage = NOOP; - this.onError = NOOP; - this.worker.terminate(); // eslint-disable-line @typescript-eslint/no-floating-promises - this.terminated = true; - } - get isRunning() { - return Boolean(this.onMessage); - } - /** - * Send a message to this worker thread - * @param data any data structure, ideally consisting mostly of transferrable objects - * @param transferList If not supplied, calculated automatically by traversing data - */ - postMessage(data, transferList) { - transferList = transferList || getTransferList(data); - // @ts-ignore - this.worker.postMessage(data, transferList); - } - // PRIVATE - /** - * Generate a standard Error from an ErrorEvent - * @param event - */ - _getErrorFromErrorEvent(event) { - // Note Error object does not have the expected fields if loading failed completely - // https://developer.mozilla.org/en-US/docs/Web/API/Worker#Event_handlers - // https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent - let message = 'Failed to load '; - message += `worker ${this.name} from ${this.url}. `; - if (event.message) { - message += `${event.message} in `; - } - // const hasFilename = event.filename && !event.filename.startsWith('blob:'); - // message += hasFilename ? event.filename : this.source.slice(0, 100); - if (event.lineno) { - message += `:${event.lineno}:${event.colno}`; - } - return new Error(message); - } - /** - * Creates a worker thread on the browser - */ - _createBrowserWorker() { - this._loadableURL = getLoadableWorkerURL({ source: this.source, url: this.url }); - const worker = new Worker(this._loadableURL, { name: this.name }); - worker.onmessage = (event) => { - if (!event.data) { - this.onError(new Error('No data received')); - } - else { - this.onMessage(event.data); - } - }; - // This callback represents an uncaught exception in the worker thread - worker.onerror = (error) => { - this.onError(this._getErrorFromErrorEvent(error)); - this.terminated = true; - }; - // TODO - not clear when this would be called, for now just log in case it happens - worker.onmessageerror = (event) => console.error(event); // eslint-disable-line - return worker; - } - /** - * Creates a worker thread in node.js - * @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool - */ - _createNodeWorker() { - let worker; - if (this.url) { - // Make sure relative URLs start with './' - const absolute = this.url.includes(':/') || this.url.startsWith('/'); - const url = absolute ? this.url : `./${this.url}`; - // console.log('Starting work from', url); - worker = new NodeWorker(url, { eval: false }); - } - else if (this.source) { - worker = new NodeWorker(this.source, { eval: true }); - } - else { - throw new Error('no worker'); - } - worker.on('message', (data) => { - // console.error('message', data); - this.onMessage(data); - }); - worker.on('error', (error) => { - // console.error('error', error); - this.onError(error); - }); - worker.on('exit', (code) => { - // console.error('exit', code); - }); - return worker; - } -} - -// loaders.gl -/** - * Process multiple data messages with small pool of identical workers - */ -class WorkerPool { - name = 'unnamed'; - source; // | Function; - url; - maxConcurrency = 1; - maxMobileConcurrency = 1; - onDebug = () => { }; - reuseWorkers = true; - props = {}; - jobQueue = []; - idleQueue = []; - count = 0; - isDestroyed = false; - /** Checks if workers are supported on this platform */ - static isSupported() { - return WorkerThread.isSupported(); - } - /** - * @param processor - worker function - * @param maxConcurrency - max count of workers - */ - constructor(props) { - this.source = props.source; - this.url = props.url; - this.setProps(props); - } - /** - * Terminates all workers in the pool - * @note Can free up significant memory - */ - destroy() { - // Destroy idle workers, active Workers will be destroyed on completion - this.idleQueue.forEach((worker) => worker.destroy()); - this.isDestroyed = true; - } - setProps(props) { - this.props = { ...this.props, ...props }; - if (props.name !== undefined) { - this.name = props.name; - } - if (props.maxConcurrency !== undefined) { - this.maxConcurrency = props.maxConcurrency; - } - if (props.maxMobileConcurrency !== undefined) { - this.maxMobileConcurrency = props.maxMobileConcurrency; - } - if (props.reuseWorkers !== undefined) { - this.reuseWorkers = props.reuseWorkers; - } - if (props.onDebug !== undefined) { - this.onDebug = props.onDebug; - } - } - async startJob(name, onMessage = (job, type, data) => job.done(data), onError = (job, error) => job.error(error)) { - // Promise resolves when thread starts working on this job - const startPromise = new Promise((onStart) => { - // Promise resolves when thread completes or fails working on this job - this.jobQueue.push({ name, onMessage, onError, onStart }); - return this; - }); - this._startQueuedJob(); // eslint-disable-line @typescript-eslint/no-floating-promises - return await startPromise; - } - // PRIVATE - /** - * Starts first queued job if worker is available or can be created - * Called when job is started and whenever a worker returns to the idleQueue - */ - async _startQueuedJob() { - if (!this.jobQueue.length) { - return; - } - const workerThread = this._getAvailableWorker(); - if (!workerThread) { - return; - } - // We have a worker, dequeue and start the job - const queuedJob = this.jobQueue.shift(); - if (queuedJob) { - // Emit a debug event - // @ts-ignore - this.onDebug({ - message: 'Starting job', - name: queuedJob.name, - workerThread, - backlog: this.jobQueue.length - }); - // Create a worker job to let the app access thread and manage job completion - const job = new WorkerJob(queuedJob.name, workerThread); - // Set the worker thread's message handlers - workerThread.onMessage = (data) => queuedJob.onMessage(job, data.type, data.payload); - workerThread.onError = (error) => queuedJob.onError(job, error); - // Resolve the start promise so that the app can start sending messages to worker - queuedJob.onStart(job); - // Wait for the app to signal that the job is complete, then return worker to queue - try { - await job.result; - } - catch (error) { - // eslint-disable-next-line no-console - console.error(`Worker exception: ${error}`); - } - finally { - this.returnWorkerToQueue(workerThread); - } - } - } - /** - * Returns a worker to the idle queue - * Destroys the worker if - * - pool is destroyed - * - if this pool doesn't reuse workers - * - if maxConcurrency has been lowered - * @param worker - */ - returnWorkerToQueue(worker) { - const shouldDestroyWorker = - // Workers on Node.js prevent the process from exiting. - // Until we figure out how to close them before exit, we always destroy them - !isBrowser || - // If the pool is destroyed, there is no reason to keep the worker around - this.isDestroyed || - // If the app has disabled worker reuse, any completed workers should be destroyed - !this.reuseWorkers || - // If concurrency has been lowered, this worker might be surplus to requirements - this.count > this._getMaxConcurrency(); - if (shouldDestroyWorker) { - worker.destroy(); - this.count--; - } - else { - this.idleQueue.push(worker); - } - if (!this.isDestroyed) { - this._startQueuedJob(); // eslint-disable-line @typescript-eslint/no-floating-promises - } - } - /** - * Returns idle worker or creates new worker if maxConcurrency has not been reached - */ - _getAvailableWorker() { - // If a worker has completed and returned to the queue, it can be used - if (this.idleQueue.length > 0) { - return this.idleQueue.shift() || null; - } - // Create fresh worker if we haven't yet created the max amount of worker threads for this worker source - if (this.count < this._getMaxConcurrency()) { - this.count++; - const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`; - return new WorkerThread({ name, source: this.source, url: this.url }); - } - // No worker available, have to wait - return null; - } - _getMaxConcurrency() { - return isMobile ? this.maxMobileConcurrency : this.maxConcurrency; - } -} - -// loaders.gl -const DEFAULT_PROPS = { - maxConcurrency: 3, - maxMobileConcurrency: 1, - reuseWorkers: true, - onDebug: () => { } -}; -/** - * Process multiple jobs with a "farm" of different workers in worker pools. - */ -class WorkerFarm { - props; - workerPools = new Map(); - // singleton - static _workerFarm; - /** Checks if workers are supported on this platform */ - static isSupported() { - return WorkerThread.isSupported(); - } - /** Get the singleton instance of the global worker farm */ - static getWorkerFarm(props = {}) { - WorkerFarm._workerFarm = WorkerFarm._workerFarm || new WorkerFarm({}); - WorkerFarm._workerFarm.setProps(props); - return WorkerFarm._workerFarm; - } - /** get global instance with WorkerFarm.getWorkerFarm() */ - constructor(props) { - this.props = { ...DEFAULT_PROPS }; - this.setProps(props); - /** @type Map} */ - this.workerPools = new Map(); - } - /** - * Terminate all workers in the farm - * @note Can free up significant memory - */ - destroy() { - for (const workerPool of this.workerPools.values()) { - workerPool.destroy(); - } - this.workerPools = new Map(); - } - /** - * Set props used when initializing worker pools - * @param props - */ - setProps(props) { - this.props = { ...this.props, ...props }; - // Update worker pool props - for (const workerPool of this.workerPools.values()) { - workerPool.setProps(this._getWorkerPoolProps()); - } - } - /** - * Returns a worker pool for the specified worker - * @param options - only used first time for a specific worker name - * @param options.name - the name of the worker - used to identify worker pool - * @param options.url - - * @param options.source - - * @example - * const job = WorkerFarm.getWorkerFarm().getWorkerPool({name, url}).startJob(...); - */ - getWorkerPool(options) { - const { name, source, url } = options; - let workerPool = this.workerPools.get(name); - if (!workerPool) { - workerPool = new WorkerPool({ - name, - source, - url - }); - workerPool.setProps(this._getWorkerPoolProps()); - this.workerPools.set(name, workerPool); - } - return workerPool; - } - _getWorkerPoolProps() { - return { - maxConcurrency: this.props.maxConcurrency, - maxMobileConcurrency: this.props.maxMobileConcurrency, - reuseWorkers: this.props.reuseWorkers, - onDebug: this.props.onDebug - }; - } -} - -// loaders.gl -/** - * Generate a worker URL based on worker object and options - * @returns A URL to one of the following: - * - a published worker on unpkg CDN - * - a local test worker - * - a URL provided by the user in options - */ -function getWorkerURL(worker, options = {}) { - const workerOptions = options[worker.id] || {}; - const workerFile = isBrowser ? `${worker.id}-worker.js` : `${worker.id}-worker-node.js`; - let url = workerOptions.workerUrl; - // HACK: Allow for non-nested workerUrl for the CompressionWorker. - // For the compression worker, workerOptions is currently not nested correctly. For most loaders, - // you'd have options within an object, i.e. `{mvt: {coordinates: ...}}` but the CompressionWorker - // puts options at the top level, not within a `compression` key (its `id`). For this reason, the - // above `workerOptions` will always be a string (i.e. `'gzip'`) for the CompressionWorker. To not - // break backwards compatibility, we allow the CompressionWorker to have options at the top level. - if (!url && worker.id === 'compression') { - url = options.workerUrl; - } - // If URL is test, generate local loaders.gl url - // @ts-ignore _workerType - if (options._workerType === 'test') { - if (isBrowser) { - url = `modules/${worker.module}/dist/${workerFile}`; - } - else { - // In the test environment the ts-node loader requires TypeScript code - url = `modules/${worker.module}/src/workers/${worker.id}-worker-node.ts`; - } - } - // If url override is not provided, generate a URL to published version on npm CDN unpkg.com - if (!url) { - // GENERATE - let version = worker.version; - // On master we need to load npm alpha releases published with the `beta` tag - if (version === 'latest') { - // throw new Error('latest worker version specified'); - version = NPM_TAG; - } - const versionTag = version ? `@${version}` : ''; - url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`; - } - assert$2(url); - // Allow user to override location - return url; -} - -// loaders.gl -/** - * Check if worker is compatible with this library version - * @param worker - * @param libVersion - * @returns `true` if the two versions are compatible - */ -function validateWorkerVersion(worker, coreVersion = VERSION$5) { - assert$2(worker, 'no worker provided'); - const workerVersion = worker.version; - if (!coreVersion || !workerVersion) { - return false; - } - // TODO enable when fix the __version__ injection - // const coreVersions = parseVersion(coreVersion); - // const workerVersions = parseVersion(workerVersion); - // assert( - // coreVersion.major === workerVersion.major && coreVersion.minor <= workerVersion.minor, - // `worker: ${worker.name} is not compatible. ${coreVersion.major}.${ - // coreVersion.minor - // }+ is required.` - // ); - return true; -} - -// loaders.gl -const loadLibraryPromises = {}; // promises -/** - * Dynamically loads a library ("module") - * - * - wasm library: Array buffer is returned - * - js library: Parse JS is returned - * - * Method depends on environment - * - browser - script element is created and installed on document - * - worker - eval is called on global context - * - node - file is required - * - * @param libraryUrl - * @param moduleName - * @param options - */ -async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null) { - if (moduleName) { - libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName); - } - // Ensure libraries are only loaded once - loadLibraryPromises[libraryUrl] = - // eslint-disable-next-line @typescript-eslint/no-misused-promises - loadLibraryPromises[libraryUrl] || loadLibraryFromFile(libraryUrl); - return await loadLibraryPromises[libraryUrl]; -} -// TODO - sort out how to resolve paths for main/worker and dev/prod -function getLibraryUrl(library, moduleName, options = {}, libraryName = null) { - // Check if already a URL - if (!options.useLocalLibraries && library.startsWith('http')) { - return library; - } - libraryName = libraryName || library; - // Allow application to import and supply libraries through `options.modules` - // TODO - See js-module-utils in loader-utils - const modules = options.modules || {}; - if (modules[libraryName]) { - return modules[libraryName]; - } - // Load from local files, not from CDN scripts in Node.js - // TODO - needs to locate the modules directory when installed! - if (!isBrowser) { - return `modules/${moduleName}/dist/libs/${libraryName}`; - } - // In browser, load from external scripts - if (options.CDN) { - assert$2(options.CDN.startsWith('http')); - return `${options.CDN}/${moduleName}@${VERSION$5}/dist/libs/${libraryName}`; - } - // TODO - loading inside workers requires paths relative to worker script location... - if (isWorker) { - return `../src/libs/${libraryName}`; - } - return `modules/${moduleName}/src/libs/${libraryName}`; -} -async function loadLibraryFromFile(libraryUrl) { - if (libraryUrl.endsWith('wasm')) { - return await loadAsArrayBuffer(libraryUrl); - } - if (!isBrowser) { - // TODO - Node doesn't yet support dynamic import from https URLs - // try { - // return await import(libraryUrl); - // } catch (error) { - // console.error(error); - // } - try { - const { requireFromFile } = globalThis.loaders || {}; - return await requireFromFile?.(libraryUrl); - } - catch (error) { - console.error(error); // eslint-disable-line no-console - return null; - } - } - if (isWorker) { - return importScripts(libraryUrl); - } - // TODO - fix - should be more secure than string parsing since observes CORS - // if (isBrowser) { - // return await loadScriptFromFile(libraryUrl); - // } - const scriptSource = await loadAsText(libraryUrl); - return loadLibraryFromString(scriptSource, libraryUrl); -} -/* -async function loadScriptFromFile(libraryUrl) { - const script = document.createElement('script'); - script.src = libraryUrl; - return await new Promise((resolve, reject) => { - script.onload = data => { - resolve(data); - }; - script.onerror = reject; - }); -} -*/ -// TODO - Needs security audit... -// - Raw eval call -// - Potentially bypasses CORS -// Upside is that this separates fetching and parsing -// we could create a`LibraryLoader` or`ModuleLoader` -function loadLibraryFromString(scriptSource, id) { - if (!isBrowser) { - const { requireFromString } = globalThis.loaders || {}; - return requireFromString?.(scriptSource, id); - } - if (isWorker) { - // Use lvalue trick to make eval run in global scope - eval.call(globalThis, scriptSource); // eslint-disable-line no-eval - // https://stackoverflow.com/questions/9107240/1-evalthis-vs-evalthis-in-javascript - // http://perfectionkills.com/global-eval-what-are-the-options/ - return null; - } - const script = document.createElement('script'); - script.id = id; - // most browsers like a separate text node but some throw an error. The second method covers those. - try { - script.appendChild(document.createTextNode(scriptSource)); - } - catch (e) { - script.text = scriptSource; - } - document.body.appendChild(script); - return null; -} -// TODO - technique for module injection into worker, from THREE.DracoLoader... -/* -function combineWorkerWithLibrary(worker, jsContent) { - var fn = wWorker.toString(); - var body = [ - '// injected', - jsContent, - '', - '// worker', - fn.substring(fn.indexOf('{') + 1, fn.lastIndexOf('}')) - ].join('\n'); - this.workerSourceURL = URL.createObjectURL(new Blob([body])); -} -*/ -async function loadAsArrayBuffer(url) { - const { readFileAsArrayBuffer } = globalThis.loaders || {}; - if (isBrowser || !readFileAsArrayBuffer || url.startsWith('http')) { - const response = await fetch(url); - return await response.arrayBuffer(); - } - return await readFileAsArrayBuffer(url); -} -/** - * Load a file from local file system - * @param filename - * @returns - */ -async function loadAsText(url) { - const { readFileAsText } = globalThis.loaders || {}; - if (isBrowser || !readFileAsText || url.startsWith('http')) { - const response = await fetch(url); - return await response.text(); - } - return await readFileAsText(url); -} - -/** - * Determines if a loader can parse with worker - * @param loader - * @param options - */ -function canParseWithWorker(loader, options) { - if (!WorkerFarm.isSupported()) { - return false; - } - // Node workers are still experimental - if (!isBrowser && !options?._nodeWorkers) { - return false; - } - return loader.worker && options?.worker; -} -/** - * this function expects that the worker function sends certain messages, - * this can be automated if the worker is wrapper by a call to createLoaderWorker in @loaders.gl/loader-utils. - */ -async function parseWithWorker(loader, data, options, context, parseOnMainThread) { - const name = loader.id; // TODO - const url = getWorkerURL(loader, options); - const workerFarm = WorkerFarm.getWorkerFarm(options); - const workerPool = workerFarm.getWorkerPool({ name, url }); - // options.log object contains functions which cannot be transferred - // context.fetch & context.parse functions cannot be transferred - // TODO - decide how to handle logging on workers - options = JSON.parse(JSON.stringify(options)); - context = JSON.parse(JSON.stringify(context || {})); - const job = await workerPool.startJob('process-on-worker', - // @ts-expect-error - onMessage.bind(null, parseOnMainThread) // eslint-disable-line @typescript-eslint/no-misused-promises - ); - job.postMessage('process', { - // @ts-ignore - input: data, - options, - context - }); - const result = await job.result; - // TODO - what is going on here? - return await result.result; -} -/** - * Handle worker's responses to the main thread - * @param job - * @param type - * @param payload - */ -async function onMessage(parseOnMainThread, job, type, payload) { - switch (type) { - case 'done': - job.done(payload); - break; - case 'error': - job.error(new Error(payload.error)); - break; - case 'process': - // Worker is asking for main thread to parseO - const { id, input, options } = payload; - try { - const result = await parseOnMainThread(input, options); - job.postMessage('done', { id, result }); - } - catch (error) { - const message = error instanceof Error ? error.message : 'unknown error'; - job.postMessage('error', { id, error: message }); - } - break; - default: - // eslint-disable-next-line - console.warn(`parse-with-worker unknown message ${type}`); - } -} - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -/** - * Get the first characters from a binary file (interpret the first bytes as an ASCII string) - * @param data - * @param length - * @returns - */ -function getFirstCharacters$1(data, length = 5) { - if (typeof data === 'string') { - return data.slice(0, length); - } - else if (ArrayBuffer.isView(data)) { - // Typed Arrays can have offsets into underlying buffer - return getMagicString$2(data.buffer, data.byteOffset, length); - } - else if (data instanceof ArrayBuffer) { - const byteOffset = 0; - return getMagicString$2(data, byteOffset, length); - } - return ''; -} -/** - * Gets a magic string from a "file" - * Typically used to check or detect file format - * @param arrayBuffer - * @param byteOffset - * @param length - * @returns - */ -function getMagicString$2(arrayBuffer, byteOffset, length) { - if (arrayBuffer.byteLength <= byteOffset + length) { - return ''; - } - const dataView = new DataView(arrayBuffer); - let magic = ''; - for (let i = 0; i < length; i++) { - magic += String.fromCharCode(dataView.getUint8(byteOffset + i)); - } - return magic; -} - -/** - * Minimal JSON parser that throws more meaningful error messages - */ -function parseJSON(string) { - try { - return JSON.parse(string); - } - catch (_) { - throw new Error(`Failed to parse JSON from data starting with "${getFirstCharacters$1(string)}"`); - } -} - -/** - * compare two binary arrays for equality - * @param a - * @param b - * @param byteLength - */ -function compareArrayBuffers(arrayBuffer1, arrayBuffer2, byteLength) { - byteLength = byteLength || arrayBuffer1.byteLength; - if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) { - return false; - } - const array1 = new Uint8Array(arrayBuffer1); - const array2 = new Uint8Array(arrayBuffer2); - for (let i = 0; i < array1.length; ++i) { - if (array1[i] !== array2[i]) { - return false; - } - } - return true; -} -/** - * Concatenate a sequence of ArrayBuffers from arguments - * @return A concatenated ArrayBuffer - */ -function concatenateArrayBuffers(...sources) { - return concatenateArrayBuffersFromArray(sources); -} -/** - * Concatenate a sequence of ArrayBuffers from array - * @return A concatenated ArrayBuffer - */ -function concatenateArrayBuffersFromArray(sources) { - // Make sure all inputs are wrapped in typed arrays - const sourceArrays = sources.map((source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2); - // Get length of all inputs - const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0); - // Allocate array with space for all inputs - const result = new Uint8Array(byteLength); - // Copy the subarrays - let offset = 0; - for (const sourceArray of sourceArrays) { - result.set(sourceArray, offset); - offset += sourceArray.byteLength; - } - // We work with ArrayBuffers, discard the typed array wrapper - return result.buffer; -} -/** - * Copy a view of an ArrayBuffer into new ArrayBuffer with byteOffset = 0 - * @param arrayBuffer - * @param byteOffset - * @param byteLength - */ -function sliceArrayBuffer(arrayBuffer, byteOffset, byteLength) { - const subArray = byteLength !== undefined - ? new Uint8Array(arrayBuffer).subarray(byteOffset, byteOffset + byteLength) - : new Uint8Array(arrayBuffer).subarray(byteOffset); - const arrayCopy = new Uint8Array(subArray); - return arrayCopy.buffer; -} - -/** - * Calculate new size of an arrayBuffer to be aligned to an n-byte boundary - * This function increases `byteLength` by the minimum delta, - * allowing the total length to be divided by `padding` - * @param byteLength - * @param padding - */ -function padToNBytes(byteLength, padding) { - assert$4(byteLength >= 0); // `Incorrect 'byteLength' value: ${byteLength}` - assert$4(padding > 0); // `Incorrect 'padding' value: ${padding}` - return (byteLength + (padding - 1)) & ~(padding - 1); -} -/** - * Copy from source to target at the targetOffset - * - * @param source - The data to copy - * @param target - The destination to copy data into - * @param targetOffset - The start offset into target to place the copied data - * @returns the new offset taking into account proper padding - */ -function copyToArray(source, target, targetOffset) { - let sourceArray; - if (source instanceof ArrayBuffer) { - sourceArray = new Uint8Array(source); - } - else { - // Pack buffer onto the big target array - // - // 'source.data.buffer' could be a view onto a larger buffer. - // We MUST use this constructor to ensure the byteOffset and byteLength is - // set to correct values from 'source.data' and not the underlying - // buffer for target.set() to work properly. - const srcByteOffset = source.byteOffset; - const srcByteLength = source.byteLength; - // In gltf parser it is set as "arrayBuffer" instead of "buffer" - // https://github.com/visgl/loaders.gl/blob/1e3a82a0a65d7b6a67b1e60633453e5edda2960a/modules/gltf/src/lib/parse-gltf.js#L85 - sourceArray = new Uint8Array(source.buffer || source.arrayBuffer, srcByteOffset, srcByteLength); - } - // Pack buffer onto the big target array - target.set(sourceArray, targetOffset); - return targetOffset + padToNBytes(sourceArray.byteLength, 4); -} - -// Breaking big data into iterable chunks, concatenating iterable chunks into big data objects -/** - * Concatenates all data chunks yielded by an (async) iterator - * This function can e.g. be used to enable atomic parsers to work on (async) iterator inputs - */ -async function concatenateArrayBuffersAsync(asyncIterator) { - const arrayBuffers = []; - for await (const chunk of asyncIterator) { - arrayBuffers.push(chunk); - } - return concatenateArrayBuffers(...arrayBuffers); -} - -// Simple file alias mechanisms for tests. -let pathPrefix = ''; -const fileAliases = {}; -/** - * Resolves aliases and adds path-prefix to paths - */ -function resolvePath(filename) { - for (const alias in fileAliases) { - if (filename.startsWith(alias)) { - const replacement = fileAliases[alias]; - filename = filename.replace(alias, replacement); - } - } - if (!filename.startsWith('http://') && !filename.startsWith('https://')) { - filename = `${pathPrefix}${filename}`; - } - return filename; -} - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -// Isolates Buffer references to ensure they are only bundled under Node.js (avoids big webpack polyfill) -// this file is selected by the package.json "browser" field). -/** - * Convert Buffer to ArrayBuffer - * Converts Node.js `Buffer` to `ArrayBuffer` (without triggering bundler to include Buffer polyfill on browser) - * @todo better data type - */ -function toArrayBuffer$1(buffer) { - return buffer; -} - -// loaders.gl -/** - * Check for Node.js `Buffer` (without triggering bundler to include Buffer polyfill on browser) - */ -function isBuffer$1(value) { - return value && typeof value === 'object' && value.isBuffer; -} -/** - * Convert an object to an array buffer - */ -function toArrayBuffer(data) { - // Note: Should be called first, Buffers can trigger other detections below - if (isBuffer$1(data)) { - return toArrayBuffer$1(data); - } - if (data instanceof ArrayBuffer) { - return data; - } - // Careful - Node Buffers look like Uint8Arrays (keep after isBuffer) - if (ArrayBuffer.isView(data)) { - if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) { - return data.buffer; - } - return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength); - } - if (typeof data === 'string') { - const text = data; - const uint8Array = new TextEncoder().encode(text); - return uint8Array.buffer; - } - // HACK to support Blob polyfill - if (data && typeof data === 'object' && data._toArrayBuffer) { - return data._toArrayBuffer(); - } - throw new Error('toArrayBuffer'); -} - -// Beginning of a minimal implementation of the Node.js path API, that doesn't pull in big polyfills. -/** - * Replacement for Node.js path.filename - * @param url - */ -function filename(url) { - const slashIndex = url ? url.lastIndexOf('/') : -1; - return slashIndex >= 0 ? url.substr(slashIndex + 1) : ''; -} -/** - * Replacement for Node.js path.dirname - * @param url - */ -function dirname(url) { - const slashIndex = url ? url.lastIndexOf('/') : -1; - return slashIndex >= 0 ? url.substr(0, slashIndex) : ''; -} - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -const isBoolean = (x) => typeof x === 'boolean'; -const isFunction = (x) => typeof x === 'function'; -const isObject = (x) => x !== null && typeof x === 'object'; -const isPureObject = (x) => isObject(x) && x.constructor === {}.constructor; -const isIterable = (x) => Boolean(x) && typeof x[Symbol.iterator] === 'function'; -const isAsyncIterable = (x) => x && typeof x[Symbol.asyncIterator] === 'function'; -const isResponse = (x) => (typeof Response !== 'undefined' && x instanceof Response) || - (x && x.arrayBuffer && x.text && x.json); -const isBlob = (x) => typeof Blob !== 'undefined' && x instanceof Blob; -/** Check for Node.js `Buffer` without triggering bundler to include buffer polyfill */ -const isBuffer = (x) => x && typeof x === 'object' && x.isBuffer; -const isReadableDOMStream = (x) => (typeof ReadableStream !== 'undefined' && x instanceof ReadableStream) || - (isObject(x) && isFunction(x.tee) && isFunction(x.cancel) && isFunction(x.getReader)); -const isReadableNodeStream = (x) => isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable); -const isReadableStream = (x) => isReadableDOMStream(x) || isReadableNodeStream(x); - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -class FetchError extends Error { - constructor(message, info) { - super(message); - this.reason = info.reason; - this.url = info.url; - this.response = info.response; - } - /** A best effort reason for why the fetch failed */ - reason; - /** The URL that failed to load. Empty string if not available. */ - url; - /** The Response object, if any. */ - response; -} - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -// TODO - build/integrate proper MIME type parsing -// https://mimesniff.spec.whatwg.org/ -const DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/; -const MIME_TYPE_PATTERN = /^([-\w.]+\/[-\w.+]+)/; -/** - * Compare two MIME types, case insensitively etc. - * @param mimeType1 - * @param mimeType2 - * @returns true if the MIME types are equivalent - * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#structure_of_a_mime_type - */ -function compareMIMETypes(mimeType1, mimeType2) { - if (mimeType1.toLowerCase() === mimeType2.toLowerCase()) { - return true; - } - return false; -} -/** - * Remove extra data like `charset` from MIME types - * @param mimeString - * @returns A clean MIME type, or an empty string - * - * @todo - handle more advanced MIMETYpes, multiple types - * @todo - extract charset etc - */ -function parseMIMEType(mimeString) { - // If resource is a data url, extract any embedded mime type - const matches = MIME_TYPE_PATTERN.exec(mimeString); - if (matches) { - return matches[1]; - } - return mimeString; -} -/** - * Extract MIME type from data URL - * - * @param mimeString - * @returns A clean MIME type, or an empty string - * - * @todo - handle more advanced MIMETYpes, multiple types - * @todo - extract charset etc - */ -function parseMIMETypeFromURL(url) { - // If resource is a data URL, extract any embedded mime type - const matches = DATA_URL_PATTERN.exec(url); - if (matches) { - return matches[1]; - } - return ''; -} - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -const QUERY_STRING_PATTERN = /\?.*/; -function extractQueryString(url) { - const matches = url.match(QUERY_STRING_PATTERN); - return matches && matches[0]; -} -function stripQueryString(url) { - return url.replace(QUERY_STRING_PATTERN, ''); -} -function shortenUrlForDisplay(url) { - if (url.length < 50) { - return url; - } - const urlEnd = url.slice(url.length - 15); - const urlStart = url.substr(0, 32); - return `${urlStart}...${urlEnd}`; -} - -// loaders.gl -/** - * Returns the URL associated with this resource. - * The returned value may include a query string and need further processing. - * If it cannot determine url, the corresponding value will be an empty string - * - * @todo string parameters are assumed to be URLs - */ -function getResourceUrl(resource) { - // If resource is a `Response`, it contains the information directly as a field - if (isResponse(resource)) { - const response = resource; - return response.url; - } - // If the resource is a Blob or a File (subclass of Blob) - if (isBlob(resource)) { - const blob = resource; - // File objects have a "name" property. Blob objects don't have any - // url (name) information - return blob.name || ''; - } - if (typeof resource === 'string') { - return resource; - } - // Unknown - return ''; -} -/** - * Returns the URL associated with this resource. - * The returned value may include a query string and need further processing. - * If it cannot determine url, the corresponding value will be an empty string - * - * @todo string parameters are assumed to be URLs - */ -function getResourceMIMEType(resource) { - // If resource is a response, it contains the information directly - if (isResponse(resource)) { - const response = resource; - const contentTypeHeader = response.headers.get('content-type') || ''; - const noQueryUrl = stripQueryString(response.url); - return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl); - } - // If the resource is a Blob or a File (subclass of Blob) - if (isBlob(resource)) { - const blob = resource; - return blob.type || ''; - } - if (typeof resource === 'string') { - return parseMIMETypeFromURL(resource); - } - // Unknown - return ''; -} -/** - * Returns (approximate) content length for a resource if it can be determined. - * Returns -1 if content length cannot be determined. - * @param resource - - * @note string parameters are NOT assumed to be URLs - */ -function getResourceContentLength(resource) { - if (isResponse(resource)) { - const response = resource; - return response.headers['content-length'] || -1; - } - if (isBlob(resource)) { - const blob = resource; - return blob.size; - } - if (typeof resource === 'string') { - // TODO - handle data URL? - return resource.length; - } - if (resource instanceof ArrayBuffer) { - return resource.byteLength; - } - if (ArrayBuffer.isView(resource)) { - return resource.byteLength; - } - return -1; -} - -// loaders.gl -/** - * Returns a Response object - * Adds content-length header when possible - * - * @param resource - */ -async function makeResponse(resource) { - if (isResponse(resource)) { - return resource; - } - // Add content-length header if possible - const headers = {}; - const contentLength = getResourceContentLength(resource); - if (contentLength >= 0) { - headers['content-length'] = String(contentLength); - } - // `new Response(File)` does not preserve content-type and URL - // so we add them here - const url = getResourceUrl(resource); - const type = getResourceMIMEType(resource); - if (type) { - headers['content-type'] = type; - } - // Add a custom header with initial bytes if available - const initialDataUrl = await getInitialDataUrl(resource); - if (initialDataUrl) { - headers['x-first-bytes'] = initialDataUrl; - } - // TODO - is this the best way of handling strings? - // Maybe package as data URL instead? - if (typeof resource === 'string') { - // Convert to ArrayBuffer to avoid Response treating it as a URL - resource = new TextEncoder().encode(resource); - } - // Attempt to create a Response from the resource, adding headers and setting url - const response = new Response(resource, { headers }); - // We can't control `Response.url` via constructor, use a property override to record URL. - Object.defineProperty(response, 'url', { value: url }); - return response; -} -/** - * Checks response status (async) and throws a helpful error message if status is not OK. - * @param response - */ -async function checkResponse(response) { - if (!response.ok) { - const error = await getResponseError(response); - throw error; - } -} -// HELPERS -async function getResponseError(response) { - const shortUrl = shortenUrlForDisplay(response.url); - let message = `Failed to fetch resource (${response.status}) ${response.statusText}: ${shortUrl}`; - message = message.length > 100 ? `${message.slice(0, 100)}...` : message; - const info = { - reason: response.statusText, - url: response.url, - response - }; - // See if we got an error message in the body - try { - const contentType = response.headers.get('Content-Type'); - info.reason = - !response.bodyUsed && contentType?.includes('application/json') - ? await response.json() - : await response.text(); - } - catch (error) { - // eslint forbids return in a finally statement, so we just catch here - } - return new FetchError(message, info); -} -async function getInitialDataUrl(resource) { - const INITIAL_DATA_LENGTH = 5; - if (typeof resource === 'string') { - return `data:,${resource.slice(0, INITIAL_DATA_LENGTH)}`; - } - if (resource instanceof Blob) { - const blobSlice = resource.slice(0, 5); - return await new Promise((resolve) => { - const reader = new FileReader(); - reader.onload = (event) => resolve(event?.target?.result); - reader.readAsDataURL(blobSlice); - }); - } - if (resource instanceof ArrayBuffer) { - const slice = resource.slice(0, INITIAL_DATA_LENGTH); - const base64 = arrayBufferToBase64(slice); - return `data:base64,${base64}`; - } - return null; -} -// https://stackoverflow.com/questions/9267899/arraybuffer-to-base64-encoded-string -function arrayBufferToBase64(buffer) { - let binary = ''; - const bytes = new Uint8Array(buffer); - for (let i = 0; i < bytes.byteLength; i++) { - binary += String.fromCharCode(bytes[i]); - } - return btoa(binary); -} - -// loaders.gl -// import {FetchError} from './fetch-error'; -function isNodePath(url) { - return !isRequestURL(url) && !isDataURL(url); -} -function isRequestURL(url) { - return url.startsWith('http:') || url.startsWith('https:'); -} -function isDataURL(url) { - return url.startsWith('data:'); -} -/** - * fetch API compatible function - * - Supports fetching from Node.js local file system paths - * - Respects pathPrefix and file aliases - */ -async function fetchFile$1(urlOrData, fetchOptions) { - if (typeof urlOrData === 'string') { - const url = resolvePath(urlOrData); - // Support fetching from local file system - if (isNodePath(url)) { - if (globalThis.loaders?.fetchNode) { - return globalThis.loaders?.fetchNode(url, fetchOptions); - } - // throw new Error( - // 'fetchFile: globalThis.loaders.fetchNode not defined. Install @loaders.gl/polyfills' - // ); - } - // Call global fetch - return await fetch(url, fetchOptions); - } - // TODO - should we still call fetch on non-URL inputs? - return await makeResponse(urlOrData); -} - -// loaders.gl -const probeLog = new Log({ id: 'loaders.gl' }); -// Logs nothing -class NullLog { - log() { - return () => { }; - } - info() { - return () => { }; - } - warn() { - return () => { }; - } - error() { - return () => { }; - } -} -// Logs to console -class ConsoleLog { - console; - constructor() { - this.console = console; // eslint-disable-line - } - log(...args) { - return this.console.log.bind(this.console, ...args); - } - info(...args) { - return this.console.info.bind(this.console, ...args); - } - warn(...args) { - return this.console.warn.bind(this.console, ...args); - } - error(...args) { - return this.console.error.bind(this.console, ...args); - } -} - -// loaders.gl -const DEFAULT_LOADER_OPTIONS = { - // baseUri - fetch: null, - mimeType: undefined, - nothrow: false, - log: new ConsoleLog(), // A probe.gl compatible (`log.log()()` syntax) that just logs to console - useLocalLibraries: false, - CDN: 'https://unpkg.com/@loaders.gl', - worker: true, // By default, use worker if provided by loader. - maxConcurrency: 3, // How many worker instances should be created for each loader. - maxMobileConcurrency: 1, // How many worker instances should be created for each loader on mobile devices. - reuseWorkers: isBrowser$2, // By default reuse workers in browser (Node.js refuses to terminate if browsers are running) - _nodeWorkers: false, // By default do not support node workers - _workerType: '', // 'test' to use locally generated workers - limit: 0, - _limitMB: 0, - batchSize: 'auto', - batchDebounceMs: 0, - metadata: false, // TODO - currently only implemented for parseInBatches, adds initial metadata batch, - transforms: [] -}; -const REMOVED_LOADER_OPTIONS = { - throws: 'nothrow', - dataType: '(no longer used)', - uri: 'baseUri', - // Warn if fetch options are used on top-level - method: 'fetch.method', - headers: 'fetch.headers', - body: 'fetch.body', - mode: 'fetch.mode', - credentials: 'fetch.credentials', - cache: 'fetch.cache', - redirect: 'fetch.redirect', - referrer: 'fetch.referrer', - referrerPolicy: 'fetch.referrerPolicy', - integrity: 'fetch.integrity', - keepalive: 'fetch.keepalive', - signal: 'fetch.signal' -}; - -// loaders.gl -/** - * Helper for safely accessing global loaders.gl variables - * Wraps initialization of global variable in function to defeat overly aggressive tree-shakers - */ -function getGlobalLoaderState() { - // @ts-ignore - globalThis.loaders = globalThis.loaders || {}; - // @ts-ignore - const { loaders } = globalThis; - // Add _state object to keep separate from modules added to globalThis.loaders - if (!loaders._state) { - loaders._state = {}; - } - return loaders._state; -} -/** - * Store global loader options on the global object to increase chances of cross loaders-version interoperability - * NOTE: This use case is not reliable but can help when testing new versions of loaders.gl with existing frameworks - * @returns global loader options merged with default loader options - */ -function getGlobalLoaderOptions() { - const state = getGlobalLoaderState(); - // Ensure all default loader options from this library are mentioned - state.globalOptions = state.globalOptions || { ...DEFAULT_LOADER_OPTIONS }; - return state.globalOptions; -} -/** - * Merges options with global opts and loader defaults, also injects baseUri - * @param options - * @param loader - * @param loaders - * @param url - */ -function normalizeOptions(options, loader, loaders, url) { - loaders = loaders || []; - loaders = Array.isArray(loaders) ? loaders : [loaders]; - validateOptions(options, loaders); - return normalizeOptionsInternal(loader, options, url); -} -// VALIDATE OPTIONS -/** - * Warn for unsupported options - * @param options - * @param loaders - */ -function validateOptions(options, loaders) { - // Check top level options - validateOptionsObject(options, null, DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS, loaders); - for (const loader of loaders) { - // Get the scoped, loader specific options from the user supplied options - const idOptions = ((options && options[loader.id]) || {}); - // Get scoped, loader specific default and deprecated options from the selected loader - const loaderOptions = (loader.options && loader.options[loader.id]) || {}; - const deprecatedOptions = (loader.deprecatedOptions && loader.deprecatedOptions[loader.id]) || {}; - // Validate loader specific options - // @ts-ignore - validateOptionsObject(idOptions, loader.id, loaderOptions, deprecatedOptions, loaders); - } -} -// eslint-disable-next-line max-params, complexity -function validateOptionsObject(options, id, defaultOptions, deprecatedOptions, loaders) { - const loaderName = id || 'Top level'; - const prefix = id ? `${id}.` : ''; - for (const key in options) { - // If top level option value is an object it could options for a loader, so ignore - const isSubOptions = !id && isObject(options[key]); - const isBaseUriOption = key === 'baseUri' && !id; - const isWorkerUrlOption = key === 'workerUrl' && id; - // .workerUrl requires special handling as it is now auto-generated and no longer specified as a default option. - if (!(key in defaultOptions) && !isBaseUriOption && !isWorkerUrlOption) { - // Issue deprecation warnings - if (key in deprecatedOptions) { - probeLog.warn(`${loaderName} loader option \'${prefix}${key}\' no longer supported, use \'${deprecatedOptions[key]}\'`)(); - } - else if (!isSubOptions) { - const suggestion = findSimilarOption(key, loaders); - probeLog.warn(`${loaderName} loader option \'${prefix}${key}\' not recognized. ${suggestion}`)(); - } - } - } -} -function findSimilarOption(optionKey, loaders) { - const lowerCaseOptionKey = optionKey.toLowerCase(); - let bestSuggestion = ''; - for (const loader of loaders) { - for (const key in loader.options) { - if (optionKey === key) { - return `Did you mean \'${loader.id}.${key}\'?`; - } - const lowerCaseKey = key.toLowerCase(); - const isPartialMatch = lowerCaseOptionKey.startsWith(lowerCaseKey) || lowerCaseKey.startsWith(lowerCaseOptionKey); - if (isPartialMatch) { - bestSuggestion = bestSuggestion || `Did you mean \'${loader.id}.${key}\'?`; - } - } - } - return bestSuggestion; -} -function normalizeOptionsInternal(loader, options, url) { - const loaderDefaultOptions = loader.options || {}; - const mergedOptions = { ...loaderDefaultOptions }; - addUrlOptions(mergedOptions, url); - // LOGGING: options.log can be set to `null` to defeat logging - if (mergedOptions.log === null) { - mergedOptions.log = new NullLog(); - } - mergeNestedFields(mergedOptions, getGlobalLoaderOptions()); - mergeNestedFields(mergedOptions, options); - return mergedOptions; -} -// Merge nested options objects -function mergeNestedFields(mergedOptions, options) { - for (const key in options) { - // Check for nested options - // object in options => either no key in defaultOptions or object in defaultOptions - if (key in options) { - const value = options[key]; - if (isPureObject(value) && isPureObject(mergedOptions[key])) { - mergedOptions[key] = { - ...mergedOptions[key], - ...options[key] - }; - } - else { - mergedOptions[key] = options[key]; - } - } - // else: No need to merge nested opts, and the initial merge already copied over the nested options - } -} -/** - * Harvest information from the url - * @deprecated This is mainly there to support a hack in the GLTFLoader - * TODO - baseUri should be a directory, i.e. remove file component from baseUri - * TODO - extract extension? - * TODO - extract query parameters? - * TODO - should these be injected on context instead of options? - */ -function addUrlOptions(options, url) { - if (url && !('baseUri' in options)) { - options.baseUri = url; - } -} - -// loaders.gl -function isLoaderObject(loader) { - if (!loader) { - return false; - } - if (Array.isArray(loader)) { - loader = loader[0]; - } - const hasExtensions = Array.isArray(loader?.extensions); - /* Now handled by types and worker loaders do not have these - let hasParser = - loader.parseTextSync || - loader.parseSync || - loader.parse || - loader.parseStream || // TODO Remove, Replace with parseInBatches - loader.parseInBatches; - */ - return hasExtensions; -} -function normalizeLoader(loader) { - // This error is fairly easy to trigger by mixing up import statements etc - // So we make an exception and add a developer error message for this case - // To help new users from getting stuck here - assert$4(loader, 'null loader'); - assert$4(isLoaderObject(loader), 'invalid loader'); - // NORMALIZE [LOADER, OPTIONS] => LOADER - // If [loader, options], create a new loaders object with options merged in - let options; - if (Array.isArray(loader)) { - options = loader[1]; - loader = loader[0]; - loader = { - ...loader, - options: { ...loader.options, ...options } - }; - } - // NORMALIZE text and binary flags - // Ensure at least one of text/binary flags are properly set - // @ts-expect-error - if (loader?.parseTextSync || loader?.parseText) { - loader.text = true; - } - if (!loader.text) { - loader.binary = true; - } - return loader; -} - -// loaders.gl -/** - * Store global registered loaders on the global object to increase chances of cross loaders-version interoperability - * This use case is not reliable but can help when testing new versions of loaders.gl with existing frameworks - */ -const getGlobalLoaderRegistry = () => { - const state = getGlobalLoaderState(); - state.loaderRegistry = state.loaderRegistry || []; - return state.loaderRegistry; -}; -/** - * @deprecated It is recommended that applications manage loader registration. This function will likely be remove in loaders.gl v5 - */ -function getRegisteredLoaders() { - return getGlobalLoaderRegistry(); -} - -// loaders.gl -const EXT_PATTERN = /\.([^.]+)$/; -// TODO - Need a variant that peeks at streams for parseInBatches -// TODO - Detect multiple matching loaders? Use heuristics to grade matches? -// TODO - Allow apps to pass context to disambiguate between multiple matches (e.g. multiple .json formats)? -/** - * Find a loader that matches file extension and/or initial file content - * Search the loaders array argument for a loader that matches url extension or initial data - * Returns: a normalized loader - * @param data data to assist - * @param loaders - * @param options - * @param context used internally, applications should not provide this parameter - */ -async function selectLoader(data, loaders = [], options, context) { - if (!validHTTPResponse(data)) { - return null; - } - // First make a sync attempt, disabling exceptions - let loader = selectLoaderSync(data, loaders, { ...options, nothrow: true }, context); - if (loader) { - return loader; - } - // For Blobs and Files, try to asynchronously read a small initial slice and test again with that - // to see if we can detect by initial content - if (isBlob(data)) { - data = await data.slice(0, 10).arrayBuffer(); - loader = selectLoaderSync(data, loaders, options, context); - } - // no loader available - if (!loader && !options?.nothrow) { - throw new Error(getNoValidLoaderMessage(data)); - } - return loader; -} -/** - * Find a loader that matches file extension and/or initial file content - * Search the loaders array argument for a loader that matches url extension or initial data - * Returns: a normalized loader - * @param data data to assist - * @param loaders - * @param options - * @param context used internally, applications should not provide this parameter - */ -function selectLoaderSync(data, loaders = [], options, context) { - if (!validHTTPResponse(data)) { - return null; - } - // eslint-disable-next-line complexity - // if only a single loader was provided (not as array), force its use - // TODO - Should this behavior be kept and documented? - if (loaders && !Array.isArray(loaders)) { - // TODO - remove support for legacy loaders - return normalizeLoader(loaders); - } - // Build list of candidate loaders that will be searched in order for a match - let candidateLoaders = []; - // First search supplied loaders - if (loaders) { - candidateLoaders = candidateLoaders.concat(loaders); - } - // Then fall back to registered loaders - if (!options?.ignoreRegisteredLoaders) { - candidateLoaders.push(...getRegisteredLoaders()); - } - // TODO - remove support for legacy loaders - normalizeLoaders(candidateLoaders); - const loader = selectLoaderInternal(data, candidateLoaders, options, context); - // no loader available - if (!loader && !options?.nothrow) { - throw new Error(getNoValidLoaderMessage(data)); - } - return loader; -} -/** Implements loaders selection logic */ -// eslint-disable-next-line complexity -function selectLoaderInternal(data, loaders, options, context) { - const url = getResourceUrl(data); - const type = getResourceMIMEType(data); - const testUrl = stripQueryString(url) || context?.url; - let loader = null; - let reason = ''; - // if options.mimeType is supplied, it takes precedence - if (options?.mimeType) { - loader = findLoaderByMIMEType(loaders, options?.mimeType); - reason = `match forced by supplied MIME type ${options?.mimeType}`; - } - // Look up loader by url - loader = loader || findLoaderByUrl(loaders, testUrl); - reason = reason || (loader ? `matched url ${testUrl}` : ''); - // Look up loader by mime type - loader = loader || findLoaderByMIMEType(loaders, type); - reason = reason || (loader ? `matched MIME type ${type}` : ''); - // Look for loader via initial bytes (Note: not always accessible (e.g. Response, stream, async iterator) - // @ts-ignore Blob | Response - loader = loader || findLoaderByInitialBytes(loaders, data); - // @ts-ignore Blob | Response - reason = reason || (loader ? `matched initial data ${getFirstCharacters(data)}` : ''); - // Look up loader by fallback mime type - if (options?.fallbackMimeType) { - loader = loader || findLoaderByMIMEType(loaders, options?.fallbackMimeType); - reason = reason || (loader ? `matched fallback MIME type ${type}` : ''); - } - if (reason) { - log.log(1, `selectLoader selected ${loader?.name}: ${reason}.`); - } - return loader; -} -/** Check HTTP Response */ -function validHTTPResponse(data) { - // HANDLE HTTP status - if (data instanceof Response) { - // 204 - NO CONTENT. This handles cases where e.g. a tile server responds with 204 for a missing tile - if (data.status === 204) { - return false; - } - } - return true; -} -/** Generate a helpful message to help explain why loader selection failed. */ -function getNoValidLoaderMessage(data) { - const url = getResourceUrl(data); - const type = getResourceMIMEType(data); - let message = 'No valid loader found ('; - message += url ? `${filename(url)}, ` : 'no url provided, '; - message += `MIME type: ${type ? `"${type}"` : 'not provided'}, `; - // First characters are only accessible when called on data (string or arrayBuffer). - // @ts-ignore Blob | Response - const firstCharacters = data ? getFirstCharacters(data) : ''; - message += firstCharacters ? ` first bytes: "${firstCharacters}"` : 'first bytes: not available'; - message += ')'; - return message; -} -function normalizeLoaders(loaders) { - for (const loader of loaders) { - normalizeLoader(loader); - } -} -// TODO - Would be nice to support http://example.com/file.glb?parameter=1 -// E.g: x = new URL('http://example.com/file.glb?load=1'; x.pathname -function findLoaderByUrl(loaders, url) { - // Get extension - const match = url && EXT_PATTERN.exec(url); - const extension = match && match[1]; - return extension ? findLoaderByExtension(loaders, extension) : null; -} -function findLoaderByExtension(loaders, extension) { - extension = extension.toLowerCase(); - for (const loader of loaders) { - for (const loaderExtension of loader.extensions) { - if (loaderExtension.toLowerCase() === extension) { - return loader; - } - } - } - return null; -} -function findLoaderByMIMEType(loaders, mimeType) { - for (const loader of loaders) { - if (loader.mimeTypes?.some((mimeType1) => compareMIMETypes(mimeType, mimeType1))) { - return loader; - } - // Support referring to loaders using the "unregistered tree" - // https://en.wikipedia.org/wiki/Media_type#Unregistered_tree - if (compareMIMETypes(mimeType, `application/x.${loader.id}`)) { - return loader; - } - } - return null; -} -function findLoaderByInitialBytes(loaders, data) { - if (!data) { - return null; - } - for (const loader of loaders) { - if (typeof data === 'string') { - if (testDataAgainstText(data, loader)) { - return loader; - } - } - else if (ArrayBuffer.isView(data)) { - // Typed Arrays can have offsets into underlying buffer - if (testDataAgainstBinary(data.buffer, data.byteOffset, loader)) { - return loader; - } - } - else if (data instanceof ArrayBuffer) { - const byteOffset = 0; - if (testDataAgainstBinary(data, byteOffset, loader)) { - return loader; - } - } - // TODO Handle streaming case (requires creating a new AsyncIterator) - } - return null; -} -function testDataAgainstText(data, loader) { - if (loader.testText) { - return loader.testText(data); - } - const tests = Array.isArray(loader.tests) ? loader.tests : [loader.tests]; - return tests.some((test) => data.startsWith(test)); -} -function testDataAgainstBinary(data, byteOffset, loader) { - const tests = Array.isArray(loader.tests) ? loader.tests : [loader.tests]; - return tests.some((test) => testBinary(data, byteOffset, loader, test)); -} -function testBinary(data, byteOffset, loader, test) { - if (test instanceof ArrayBuffer) { - return compareArrayBuffers(test, data, test.byteLength); - } - switch (typeof test) { - case 'function': - return test(data); - case 'string': - // Magic bytes check: If `test` is a string, check if binary data starts with that strings - const magic = getMagicString$1(data, byteOffset, test.length); - return test === magic; - default: - return false; - } -} -function getFirstCharacters(data, length = 5) { - if (typeof data === 'string') { - return data.slice(0, length); - } - else if (ArrayBuffer.isView(data)) { - // Typed Arrays can have offsets into underlying buffer - return getMagicString$1(data.buffer, data.byteOffset, length); - } - else if (data instanceof ArrayBuffer) { - const byteOffset = 0; - return getMagicString$1(data, byteOffset, length); - } - return ''; -} -function getMagicString$1(arrayBuffer, byteOffset, length) { - if (arrayBuffer.byteLength < byteOffset + length) { - return ''; - } - const dataView = new DataView(arrayBuffer); - let magic = ''; - for (let i = 0; i < length; i++) { - magic += String.fromCharCode(dataView.getUint8(byteOffset + i)); - } - return magic; -} - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -const DEFAULT_CHUNK_SIZE$2 = 256 * 1024; -/** - * Returns an iterator that breaks a big string into chunks and yields them one-by-one as ArrayBuffers - * @param blob string to iterate over - * @param options - * @param options.chunkSize - */ -function* makeStringIterator(string, options) { - const chunkSize = options?.chunkSize || DEFAULT_CHUNK_SIZE$2; - let offset = 0; - const textEncoder = new TextEncoder(); - while (offset < string.length) { - // Create a chunk of the right size - const chunkLength = Math.min(string.length - offset, chunkSize); - const chunk = string.slice(offset, offset + chunkLength); - offset += chunkLength; - // yield an ArrayBuffer chunk - yield textEncoder.encode(chunk); - } -} - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -const DEFAULT_CHUNK_SIZE$1 = 256 * 1024; -/** - * Returns an iterator that breaks a big ArrayBuffer into chunks and yields them one-by-one - * @param blob ArrayBuffer to iterate over - * @param options - * @param options.chunkSize - */ -function* makeArrayBufferIterator(arrayBuffer, options = {}) { - const { chunkSize = DEFAULT_CHUNK_SIZE$1 } = options; - let byteOffset = 0; - while (byteOffset < arrayBuffer.byteLength) { - // Create a chunk of the right size - const chunkByteLength = Math.min(arrayBuffer.byteLength - byteOffset, chunkSize); - const chunk = new ArrayBuffer(chunkByteLength); - // Copy data from the big chunk - const sourceArray = new Uint8Array(arrayBuffer, byteOffset, chunkByteLength); - const chunkArray = new Uint8Array(chunk); - chunkArray.set(sourceArray); - // yield the chunk - byteOffset += chunkByteLength; - yield chunk; - } -} - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -const DEFAULT_CHUNK_SIZE = 1024 * 1024; // 1MB — biggest value that keeps UI responsive -/** - * Returns an iterator that breaks a big Blob into chunks and yields them one-by-one - * @param blob Blob or File object - * @param options - * @param options.chunkSize - */ -async function* makeBlobIterator(blob, options) { - const chunkSize = options?.chunkSize || DEFAULT_CHUNK_SIZE; - let offset = 0; - while (offset < blob.size) { - const end = offset + chunkSize; - const chunk = await blob.slice(offset, end).arrayBuffer(); - offset = end; - yield chunk; - } -} - -// loaders.gl -/** - * Returns an async iterable that reads from a stream (works in both Node.js and browsers) - * @param stream stream to iterator over - */ -function makeStreamIterator(stream, options) { - return isBrowser$2 - ? makeBrowserStreamIterator(stream, options) - : makeNodeStreamIterator(stream); -} -/** - * Returns an async iterable that reads from a DOM (browser) stream - * @param stream stream to iterate from - * @see https://jakearchibald.com/2017/async-iterators-and-generators/#making-streams-iterate - */ -async function* makeBrowserStreamIterator(stream, options) { - // WhatWG: stream is supposed to have a `getIterator` method - // if (typeof stream.getIterator === 'function') { - // return stream.getIterator(); - // } - // if (typeof stream[Symbol.asyncIterator] === 'function') { - // return makeToArrayBufferIterator(stream); - // } - // In the browser, we first need to get a lock on the stream - const reader = stream.getReader(); - let nextBatchPromise; - try { - // eslint-disable-next-line no-constant-condition - while (true) { - const currentBatchPromise = nextBatchPromise || reader.read(); - // Issue a read for an additional batch, while we await the next batch - // Idea is to make fetching happen in parallel with processing / parsing - if (options?._streamReadAhead) { - nextBatchPromise = reader.read(); - } - // Read from the stream - // value is a Uint8Array - const { done, value } = await currentBatchPromise; - // Exit if we're done - if (done) { - return; - } - // Else yield the chunk - yield toArrayBuffer(value); - } - } - catch (error) { - // TODO - examples makes it look like this should always be called, - // but that generates exceptions so only call it if we do not reach the end - reader.releaseLock(); - } -} -/** - * Returns an async iterable that reads from a DOM (browser) stream - * @param stream stream to iterate from - * @note Requires Node.js >= 10 - */ -async function* makeNodeStreamIterator(stream, options) { - // Hacky test for node version to ensure we don't call bad polyfills - // NODE 10+: stream is an asyncIterator - for await (const chunk of stream) { - yield toArrayBuffer(chunk); // Coerce each chunk to ArrayBuffer - } -} -/* TODO - remove NODE < 10 - * @see https://github.com/bustle/streaming-iterables, MIT license - * - if (typeof stream[Symbol.asyncIterator] === 'function') { - return; - } - - // TODO - check if is this ever used in Node 10+? - // eslint-disable-next-line no-constant-condition - while (true) { - const data = stream.read(); - if (data !== null) { - yield toArrayBuffer(data); - // eslint-disable-next-line no-continue - continue; - } - if (stream._readableState?.ended) { - return; - } - await onceReadable(stream); - } - -async function onceReadable(stream: Readable): Promise { - return new Promise((resolve) => { - stream.once('readable', resolve); - }); -} - */ - -// loaders.gl -/** - * Returns an iterator that breaks its input into chunks and yields them one-by-one. - * @param data - * @param options - * @returns - * This function can e.g. be used to enable data sources that can only be read atomically - * (such as `Blob` and `File` via `FileReader`) to still be parsed in batches. - */ -function makeIterator(data, options) { - if (typeof data === 'string') { - // Note: Converts string chunks to binary - return makeStringIterator(data, options); - } - if (data instanceof ArrayBuffer) { - return makeArrayBufferIterator(data, options); - } - if (isBlob(data)) { - return makeBlobIterator(data, options); - } - if (isReadableStream(data)) { - return makeStreamIterator(data, options); - } - if (isResponse(data)) { - const response = data; - return makeStreamIterator(response.body, options); - } - throw new Error('makeIterator'); -} - -// loaders.gl -const ERR_DATA = 'Cannot convert supplied data type'; -// eslint-disable-next-line complexity -function getArrayBufferOrStringFromDataSync(data, loader, options) { - if (loader.text && typeof data === 'string') { - return data; - } - if (isBuffer(data)) { - // @ts-ignore - data = data.buffer; - } - if (data instanceof ArrayBuffer) { - const arrayBuffer = data; - if (loader.text && !loader.binary) { - const textDecoder = new TextDecoder('utf8'); - return textDecoder.decode(arrayBuffer); - } - return arrayBuffer; - } - // We may need to handle offsets - if (ArrayBuffer.isView(data)) { - // TextDecoder is invoked on typed arrays and will handle offsets - if (loader.text && !loader.binary) { - const textDecoder = new TextDecoder('utf8'); - return textDecoder.decode(data); - } - let arrayBuffer = data.buffer; - // Since we are returning the underlying arrayBuffer, we must create a new copy - // if this typed array / Buffer is a partial view into the ArryayBuffer - // TODO - this is a potentially unnecessary copy - const byteLength = data.byteLength || data.length; - if (data.byteOffset !== 0 || byteLength !== arrayBuffer.byteLength) { - // console.warn(`loaders.gl copying arraybuffer of length ${byteLength}`); - arrayBuffer = arrayBuffer.slice(data.byteOffset, data.byteOffset + byteLength); - } - return arrayBuffer; - } - throw new Error(ERR_DATA); -} -// Convert async iterator to a promise -async function getArrayBufferOrStringFromData(data, loader, options) { - const isArrayBuffer = data instanceof ArrayBuffer || ArrayBuffer.isView(data); - if (typeof data === 'string' || isArrayBuffer) { - return getArrayBufferOrStringFromDataSync(data, loader); - } - // Blobs and files are FileReader compatible - if (isBlob(data)) { - data = await makeResponse(data); - } - if (isResponse(data)) { - const response = data; - await checkResponse(response); - return loader.binary ? await response.arrayBuffer() : await response.text(); - } - if (isReadableStream(data)) { - // @ts-expect-error TS2559 options type - data = makeIterator(data, options); - } - if (isIterable(data) || isAsyncIterable(data)) { - // Assume arrayBuffer iterator - attempt to concatenate - return concatenateArrayBuffersAsync(data); - } - throw new Error(ERR_DATA); -} - -// loaders.gl -/** - * Gets the current fetch function from options and context - * @param options - * @param context - */ -function getFetchFunction(options, context) { - const globalOptions = getGlobalLoaderOptions(); - const loaderOptions = options || globalOptions; - // options.fetch can be a function - if (typeof loaderOptions.fetch === 'function') { - return loaderOptions.fetch; - } - // options.fetch can be an options object - if (isObject(loaderOptions.fetch)) { - return (url) => fetchFile$1(url, loaderOptions.fetch); - } - // else refer to context (from parent loader) if available - if (context?.fetch) { - return context?.fetch; - } - // else return the default fetch function - return fetchFile$1; -} - -// loaders.gl -/** - * "sub" loaders invoked by other loaders get a "context" injected on `this` - * The context will inject core methods like `parse` and contain information - * about loaders and options passed in to the top-level `parse` call. - * - * @param context - * @param options - * @param previousContext - */ -function getLoaderContext(context, options, parentContext) { - // For recursive calls, we already have a context - // TODO - add any additional loaders to context? - if (parentContext) { - return parentContext; - } - const newContext = { - fetch: getFetchFunction(options, context), - ...context - }; - // Parse URLs so that subloaders can easily generate correct strings - if (newContext.url) { - const baseUrl = stripQueryString(newContext.url); - newContext.baseUrl = baseUrl; - newContext.queryString = extractQueryString(newContext.url); - newContext.filename = filename(baseUrl); - newContext.baseUrl = dirname(baseUrl); - } - // Recursive loading does not use single loader - if (!Array.isArray(newContext.loaders)) { - newContext.loaders = null; - } - return newContext; -} -// eslint-disable-next-line complexity -function getLoadersFromContext(loaders, context) { - // A single loader (non-array) indicates no selection desired. Force select. - if (loaders && !Array.isArray(loaders)) { - return loaders; - } - // Create a merged list - let candidateLoaders; - if (loaders) { - candidateLoaders = Array.isArray(loaders) ? loaders : [loaders]; - } - if (context && context.loaders) { - const contextLoaders = Array.isArray(context.loaders) ? context.loaders : [context.loaders]; - candidateLoaders = candidateLoaders ? [...candidateLoaders, ...contextLoaders] : contextLoaders; - } - // If no loaders, return null to look in globally registered loaders - return candidateLoaders && candidateLoaders.length ? candidateLoaders : undefined; -} - -// loaders.gl -/** - * Parses `data` using a specified loader - * @param data - * @param loaders - * @param options - * @param context - */ -// implementation signature -async function parse$4(data, loaders, options, context) { - // Signature: parse(data, options, context | url) - // Uses registered loaders - if (loaders && !Array.isArray(loaders) && !isLoaderObject(loaders)) { - context = undefined; // context not supported in short signature - options = loaders; - loaders = undefined; - } - data = await data; // Resolve any promise - options = options || {}; // Could be invalid... - // Extract a url for auto detection - const url = getResourceUrl(data); - // Chooses a loader (and normalizes it) - // Also use any loaders in the context, new loaders take priority - const typedLoaders = loaders; - const candidateLoaders = getLoadersFromContext(typedLoaders, context); - // todo hacky type cast - const loader = await selectLoader(data, candidateLoaders, options); - // Note: if no loader was found, if so just return null - if (!loader) { - return null; - } - // Normalize options - // @ts-expect-error - options = normalizeOptions(options, loader, candidateLoaders, url); // Could be invalid... - // Get a context (if already present, will be unchanged) - context = getLoaderContext( - // @ts-expect-error - { url, _parse: parse$4, loaders: candidateLoaders }, options, context || null); - return await parseWithLoader(loader, data, options, context); -} -// TODO: support progress and abort -// TODO - should accept loader.parseAsyncIterator and concatenate. -async function parseWithLoader(loader, data, options, context) { - validateWorkerVersion(loader); - options = mergeLoaderOptions(loader.options, options); - if (isResponse(data)) { - // Serialize to support passing the response to web worker - const response = data; - const { ok, redirected, status, statusText, type, url } = response; - const headers = Object.fromEntries(response.headers.entries()); - // @ts-expect-error TODO - fix this - context.response = { headers, ok, redirected, status, statusText, type, url }; - } - data = await getArrayBufferOrStringFromData(data, loader, options); - const loaderWithParser = loader; - // First check for synchronous text parser, wrap results in promises - if (loaderWithParser.parseTextSync && typeof data === 'string') { - return loaderWithParser.parseTextSync(data, options, context); - } - // If we have a workerUrl and the loader can parse the given options efficiently in a worker - if (canParseWithWorker(loader, options)) { - return await parseWithWorker(loader, data, options, context, parse$4); - } - // Check for asynchronous parser - if (loaderWithParser.parseText && typeof data === 'string') { - return await loaderWithParser.parseText(data, options, context); - } - if (loaderWithParser.parse) { - return await loaderWithParser.parse(data, options, context); - } - // This should not happen, all sync loaders should also offer `parse` function - assert$2(!loaderWithParser.parseSync); - // TBD - If asynchronous parser not available, return null - throw new Error(`${loader.id} loader - no parser found and worker is disabled`); -} - -// loaders.gl -/** - * Deduces a simple data type "descriptor from a typed array instance - */ -function getDataTypeFromTypedArray(array) { - switch (array.constructor) { - case Int8Array: - return 'int8'; - case Uint8Array: - case Uint8ClampedArray: - return 'uint8'; - case Int16Array: - return 'int16'; - case Uint16Array: - return 'uint16'; - case Int32Array: - return 'int32'; - case Uint32Array: - return 'uint32'; - case Float32Array: - return 'float32'; - case Float64Array: - return 'float64'; - default: - return 'null'; - } -} - -/** - * Get number of vertices in mesh - * @param attributes - */ -/** - * Get the (axis aligned) bounding box of a mesh - * @param attributes - * @returns array of two vectors representing the axis aligned bounding box - */ -// eslint-disable-next-line complexity -function getMeshBoundingBox(attributes) { - let minX = Infinity; - let minY = Infinity; - let minZ = Infinity; - let maxX = -Infinity; - let maxY = -Infinity; - let maxZ = -Infinity; - const positions = attributes.POSITION ? attributes.POSITION.value : []; - const len = positions && positions.length; - for (let i = 0; i < len; i += 3) { - const x = positions[i]; - const y = positions[i + 1]; - const z = positions[i + 2]; - minX = x < minX ? x : minX; - minY = y < minY ? y : minY; - minZ = z < minZ ? z : minZ; - maxX = x > maxX ? x : maxX; - maxY = y > maxY ? y : maxY; - maxZ = z > maxZ ? z : maxZ; - } - return [ - [minX, minY, minZ], - [maxX, maxY, maxZ] - ]; -} - -// loaders.gl -/** - * Create a schema for mesh attributes data - * @param attributes - * @param metadata - * @returns - */ -function deduceMeshSchema(attributes, metadata = {}) { - const fields = deduceMeshFields(attributes); - return { fields, metadata }; -} -/** - * Create arrow-like schema field for mesh attribute - * @param attributeName - * @param attribute - * @param optionalMetadata - * @returns - */ -function deduceMeshField(name, attribute, optionalMetadata) { - const type = getDataTypeFromTypedArray(attribute.value); - const metadata = optionalMetadata ? optionalMetadata : makeMeshAttributeMetadata(attribute); - return { - name, - type: { type: 'fixed-size-list', listSize: attribute.size, children: [{ name: 'value', type }] }, - nullable: false, - metadata - }; -} -/** - * Create fields array for mesh attributes - * @param attributes - * @returns - */ -function deduceMeshFields(attributes) { - const fields = []; - for (const attributeName in attributes) { - const attribute = attributes[attributeName]; - fields.push(deduceMeshField(attributeName, attribute)); - } - return fields; -} -/** - * Make metadata by mesh attribute properties - * @param attribute - * @returns - */ -function makeMeshAttributeMetadata(attribute) { - const result = {}; - if ('byteOffset' in attribute) { - result.byteOffset = attribute.byteOffset.toString(10); - } - if ('byteStride' in attribute) { - result.byteStride = attribute.byteStride.toString(10); - } - if ('normalized' in attribute) { - result.normalized = attribute.normalized.toString(); - } - return result; -} - -// Version constant cannot be imported, it needs to correspond to the build version of **this** module. -// __VERSION__ is injected by babel-plugin-version-inline -// @ts-ignore TS2304: Cannot find name '__VERSION__'. -const VERSION$4 = "4.3.3" ; - -// @ts-ignore TS2339: Property does not exist on type -const parseImageNode = globalThis.loaders?.parseImageNode; -const IMAGE_SUPPORTED = typeof Image !== 'undefined'; // NOTE: "false" positives if jsdom is installed -const IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== 'undefined'; -const NODE_IMAGE_SUPPORTED = Boolean(parseImageNode); -const DATA_SUPPORTED = isBrowser$2 ? true : NODE_IMAGE_SUPPORTED; -/** - * Checks if a loaders.gl image type is supported - * @param type image type string - */ -function isImageTypeSupported(type) { - switch (type) { - case 'auto': - // Should only ever be false in Node.js, if polyfills have not been installed... - return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED; - case 'imagebitmap': - return IMAGE_BITMAP_SUPPORTED; - case 'image': - return IMAGE_SUPPORTED; - case 'data': - return DATA_SUPPORTED; - default: - throw new Error(`@loaders.gl/images: image ${type} not supported in this environment`); - } -} -/** - * Returns the "most performant" supported image type on this platform - * @returns image type string - */ -function getDefaultImageType() { - if (IMAGE_BITMAP_SUPPORTED) { - return 'imagebitmap'; - } - if (IMAGE_SUPPORTED) { - return 'image'; - } - if (DATA_SUPPORTED) { - return 'data'; - } - // This should only happen in Node.js - throw new Error('Install \'@loaders.gl/polyfills\' to parse images under Node.js'); -} - -function getImageType(image) { - const format = getImageTypeOrNull(image); - if (!format) { - throw new Error('Not an image'); - } - return format; -} -function getImageData(image) { - switch (getImageType(image)) { - case 'data': - return image; - case 'image': - case 'imagebitmap': - // Extract the image data from the image via a canvas - const canvas = document.createElement('canvas'); - // TODO - reuse the canvas? - const context = canvas.getContext('2d'); - if (!context) { - throw new Error('getImageData'); - } - // @ts-ignore - canvas.width = image.width; - // @ts-ignore - canvas.height = image.height; - // @ts-ignore - context.drawImage(image, 0, 0); - // @ts-ignore - return context.getImageData(0, 0, image.width, image.height); - default: - throw new Error('getImageData'); - } -} -// PRIVATE -// eslint-disable-next-line complexity -function getImageTypeOrNull(image) { - if (typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) { - return 'imagebitmap'; - } - if (typeof Image !== 'undefined' && image instanceof Image) { - return 'image'; - } - if (image && typeof image === 'object' && image.data && image.width && image.height) { - return 'data'; - } - return null; -} - -// SVG parsing has limitations, e.g: -// https://bugs.chromium.org/p/chromium/issues/detail?id=606319 -const SVG_DATA_URL_PATTERN = /^data:image\/svg\+xml/; -const SVG_URL_PATTERN = /\.svg((\?|#).*)?$/; -function isSVG$1(url) { - return url && (SVG_DATA_URL_PATTERN.test(url) || SVG_URL_PATTERN.test(url)); -} -function getBlobOrSVGDataUrl(arrayBuffer, url) { - if (isSVG$1(url)) { - // Prepare a properly tagged data URL, and load using normal mechanism - const textDecoder = new TextDecoder(); - let xmlText = textDecoder.decode(arrayBuffer); - // TODO Escape in browser to support e.g. Chinese characters - try { - if (typeof unescape === 'function' && typeof encodeURIComponent === 'function') { - xmlText = unescape(encodeURIComponent(xmlText)); - } - } - catch (error) { - throw new Error(error.message); - } - // base64 encoding is safer. utf-8 fails in some browsers - const src = `data:image/svg+xml;base64,${btoa(xmlText)}`; - return src; - } - return getBlob(arrayBuffer, url); -} -function getBlob(arrayBuffer, url) { - if (isSVG$1(url)) { - // https://bugs.chromium.org/p/chromium/issues/detail?id=606319 - // return new Blob([new Uint8Array(arrayBuffer)], {type: 'image/svg+xml'}); - throw new Error('SVG cannot be parsed directly to imagebitmap'); - } - // TODO - how to determine mime type? Param? Sniff here? - return new Blob([new Uint8Array(arrayBuffer)]); // MIME type not needed? -} - -// Parses html image from array buffer -async function parseToImage(arrayBuffer, options, url) { - // Note: image parsing requires conversion to Blob (for createObjectURL). - // Potentially inefficient for not using `response.blob()` (and for File / Blob inputs)... - // But presumably not worth adding 'blob' flag to loader objects? - const blobOrDataUrl = getBlobOrSVGDataUrl(arrayBuffer, url); - const URL = self.URL || self.webkitURL; - const objectUrl = typeof blobOrDataUrl !== 'string' && URL.createObjectURL(blobOrDataUrl); - try { - return await loadToImage(objectUrl || blobOrDataUrl, options); - } - finally { - if (objectUrl) { - URL.revokeObjectURL(objectUrl); - } - } -} -async function loadToImage(url, options) { - const image = new Image(); - image.src = url; - // The `image.onload()` callback does not guarantee that the image has been decoded - // so a main thread "freeze" can be incurred when using the image for the first time. - // `Image.decode()` returns a promise that completes when image is decoded. - // https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decode - // Note: When calling `img.decode()`, we do not need to wait for `img.onload()` - // Note: `HTMLImageElement.decode()` is not available in Edge and IE11 - if (options.image && options.image.decode && image.decode) { - await image.decode(); - return image; - } - // Create a promise that tracks onload/onerror callbacks - return await new Promise((resolve, reject) => { - try { - image.onload = () => resolve(image); - image.onerror = (error) => { - const message = error instanceof Error ? error.message : 'error'; - reject(new Error(message)); - }; - } - catch (error) { - reject(error); - } - }); -} - -const EMPTY_OBJECT = {}; -let imagebitmapOptionsSupported = true; -/** - * Asynchronously parses an array buffer into an ImageBitmap - this contains the decoded data - * ImageBitmaps are supported on worker threads, but not supported on Edge, IE11 and Safari - * https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap#Browser_compatibility - * - * TODO - createImageBitmap supports source rect (5 param overload), pass through? - */ -async function parseToImageBitmap(arrayBuffer, options, url) { - let blob; - // Cannot parse SVG directly to ImageBitmap, parse to Image first - if (isSVG$1(url)) { - // Note: this only works on main thread - const image = await parseToImage(arrayBuffer, options, url); - blob = image; - } - else { - // Create blob from the array buffer - blob = getBlob(arrayBuffer, url); - } - const imagebitmapOptions = options && options.imagebitmap; - return await safeCreateImageBitmap(blob, imagebitmapOptions); -} -/** - * Safely creates an imageBitmap with options - * * - * Firefox crashes if imagebitmapOptions is supplied - * Avoid supplying if not provided or supported, remember if not supported - */ -async function safeCreateImageBitmap(blob, imagebitmapOptions = null) { - if (isEmptyObject(imagebitmapOptions) || !imagebitmapOptionsSupported) { - imagebitmapOptions = null; - } - if (imagebitmapOptions) { - try { - // @ts-ignore Options - return await createImageBitmap(blob, imagebitmapOptions); - } - catch (error) { - console.warn(error); // eslint-disable-line - imagebitmapOptionsSupported = false; - } - } - return await createImageBitmap(blob); -} -function isEmptyObject(object) { - // @ts-ignore - for (const key in object || EMPTY_OBJECT) { - return false; - } - return true; -} - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -// code adapted from https://github.com/sindresorhus/file-type under MIT license -/** - * Tests if a buffer is in ISO base media file format (ISOBMFF) @see https://en.wikipedia.org/wiki/ISO_base_media_file_format - * (ISOBMFF is a media container standard based on the Apple QuickTime container format) - */ -function getISOBMFFMediaType(buffer) { - // Almost all ISO base media files start with `ftyp` box. (It's not required to be first, but it's recommended to be.) - if (!checkString(buffer, 'ftyp', 4)) { - return null; - } - // Extra check: test for 8859-1 printable characters (for simplicity, it's a mask which also catches one non-printable character). - if ((buffer[8] & 0x60) === 0x00) { - return null; - } - // `ftyp` box must contain a brand major identifier, which must consist of ISO 8859-1 printable characters. - return decodeMajorBrand(buffer); -} -/** - * brands explained @see https://github.com/strukturag/libheif/issues/83 - * code adapted from @see https://github.com/sindresorhus/file-type/blob/main/core.js#L489-L492 - */ -function decodeMajorBrand(buffer) { - const brandMajor = getUTF8String(buffer, 8, 12).replace('\0', ' ').trim(); - switch (brandMajor) { - case 'avif': - case 'avis': - return { extension: 'avif', mimeType: 'image/avif' }; - default: - return null; - } - // We don't need these now, but they are easy to add - // case 'mif1': - // return {extension: 'heic', mimeType: 'image/heif'}; - // case 'msf1': - // return {extension: 'heic', mimeType: 'image/heif-sequence'}; - // case 'heic': - // case 'heix': - // return {extension: 'heic', mimeType: 'image/heic'}; - // case 'hevc': - // case 'hevx': - // return {extension: 'heic', mimeType: 'image/heic-sequence'}; - // case 'qt': - // return {ext: 'mov', mime: 'video/quicktime'}; - // case 'M4V': - // case 'M4VH': - // case 'M4VP': - // return {ext: 'm4v', mime: 'video/x-m4v'}; - // case 'M4P': - // return {ext: 'm4p', mime: 'video/mp4'}; - // case 'M4B': - // return {ext: 'm4b', mime: 'audio/mp4'}; - // case 'M4A': - // return {ext: 'm4a', mime: 'audio/x-m4a'}; - // case 'F4V': - // return {ext: 'f4v', mime: 'video/mp4'}; - // case 'F4P': - // return {ext: 'f4p', mime: 'video/mp4'}; - // case 'F4A': - // return {ext: 'f4a', mime: 'audio/mp4'}; - // case 'F4B': - // return {ext: 'f4b', mime: 'audio/mp4'}; - // case 'crx': - // return {ext: 'cr3', mime: 'image/x-canon-cr3'}; - // default: - // if (brandMajor.startsWith('3g')) { - // if (brandMajor.startsWith('3g2')) { - // return {ext: '3g2', mime: 'video/3gpp2'}; - // } - // return {ext: '3gp', mime: 'video/3gpp'}; - // } - // return {ext: 'mp4', mime: 'video/mp4'}; -} -/** Interpret a chunk of bytes as a UTF8 string */ -function getUTF8String(array, start, end) { - return String.fromCharCode(...array.slice(start, end)); -} -function stringToBytes(string) { - return [...string].map((character) => character.charCodeAt(0)); -} -function checkString(buffer, header, offset = 0) { - const headerBytes = stringToBytes(header); - for (let i = 0; i < headerBytes.length; ++i) { - if (headerBytes[i] !== buffer[i + offset]) { - return false; - } - } - return true; -} - -// Attributions -const BIG_ENDIAN = false; -const LITTLE_ENDIAN$1 = true; -/** - * Extracts `{mimeType, width and height}` from a memory buffer containing a known image format - * Currently supports `image/png`, `image/jpeg`, `image/bmp` and `image/gif`. - * @param binaryData: DataView | ArrayBuffer image file memory to parse - * @returns metadata or null if memory is not a valid image file format layout. - */ -function getBinaryImageMetadata(binaryData) { - const dataView = toDataView(binaryData); - return (getPngMetadata(dataView) || - getJpegMetadata(dataView) || - getGifMetadata(dataView) || - getBmpMetadata(dataView) || - getISOBMFFMetadata(dataView)); -} -// ISOBMFF -function getISOBMFFMetadata(binaryData) { - const buffer = new Uint8Array(binaryData instanceof DataView ? binaryData.buffer : binaryData); - const mediaType = getISOBMFFMediaType(buffer); - if (!mediaType) { - return null; - } - return { - mimeType: mediaType.mimeType, - // TODO - decode width and height - width: 0, - height: 0 - }; -} -// PNG -function getPngMetadata(binaryData) { - const dataView = toDataView(binaryData); - // Check file contains the first 4 bytes of the PNG signature. - const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 0x89504e47; - if (!isPng) { - return null; - } - // Extract size from a binary PNG file - return { - mimeType: 'image/png', - width: dataView.getUint32(16, BIG_ENDIAN), - height: dataView.getUint32(20, BIG_ENDIAN) - }; -} -// GIF -// Extract size from a binary GIF file -// TODO: GIF is not this simple -function getGifMetadata(binaryData) { - const dataView = toDataView(binaryData); - // Check first 4 bytes of the GIF signature ("GIF8"). - const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 0x47494638; - if (!isGif) { - return null; - } - // GIF is little endian. - return { - mimeType: 'image/gif', - width: dataView.getUint16(6, LITTLE_ENDIAN$1), - height: dataView.getUint16(8, LITTLE_ENDIAN$1) - }; -} -// BMP -// TODO: BMP is not this simple -function getBmpMetadata(binaryData) { - const dataView = toDataView(binaryData); - // Check magic number is valid (first 2 characters should be "BM"). - // The mandatory bitmap file header is 14 bytes long. - const isBmp = dataView.byteLength >= 14 && - dataView.getUint16(0, BIG_ENDIAN) === 0x424d && - dataView.getUint32(2, LITTLE_ENDIAN$1) === dataView.byteLength; - if (!isBmp) { - return null; - } - // BMP is little endian. - return { - mimeType: 'image/bmp', - width: dataView.getUint32(18, LITTLE_ENDIAN$1), - height: dataView.getUint32(22, LITTLE_ENDIAN$1) - }; -} -// JPEG -// Extract width and height from a binary JPEG file -function getJpegMetadata(binaryData) { - const dataView = toDataView(binaryData); - // Check file contains the JPEG "start of image" (SOI) marker - // followed by another marker. - const isJpeg = dataView.byteLength >= 3 && - dataView.getUint16(0, BIG_ENDIAN) === 0xffd8 && - dataView.getUint8(2) === 0xff; - if (!isJpeg) { - return null; - } - const { tableMarkers, sofMarkers } = getJpegMarkers(); - // Exclude the two byte SOI marker. - let i = 2; - while (i + 9 < dataView.byteLength) { - const marker = dataView.getUint16(i, BIG_ENDIAN); - // The frame that contains the width and height of the JPEG image. - if (sofMarkers.has(marker)) { - return { - mimeType: 'image/jpeg', - height: dataView.getUint16(i + 5, BIG_ENDIAN), // Number of lines - width: dataView.getUint16(i + 7, BIG_ENDIAN) // Number of pixels per line - }; - } - // Miscellaneous tables/data preceding the frame header. - if (!tableMarkers.has(marker)) { - return null; - } - // Length includes size of length parameter but not the two byte header. - i += 2; - i += dataView.getUint16(i, BIG_ENDIAN); - } - return null; -} -function getJpegMarkers() { - // Tables/misc header markers. - // DQT, DHT, DAC, DRI, COM, APP_n - const tableMarkers = new Set([0xffdb, 0xffc4, 0xffcc, 0xffdd, 0xfffe]); - for (let i = 0xffe0; i < 0xfff0; ++i) { - tableMarkers.add(i); - } - // SOF markers and DHP marker. - // These markers are after tables/misc data. - const sofMarkers = new Set([ - 0xffc0, 0xffc1, 0xffc2, 0xffc3, 0xffc5, 0xffc6, 0xffc7, 0xffc9, 0xffca, 0xffcb, 0xffcd, 0xffce, - 0xffcf, 0xffde - ]); - return { tableMarkers, sofMarkers }; -} -// TODO - move into image module? -function toDataView(data) { - if (data instanceof DataView) { - return data; - } - if (ArrayBuffer.isView(data)) { - return new DataView(data.buffer); - } - // TODO: make these functions work for Node.js buffers? - // if (bufferToArrayBuffer) { - // data = bufferToArrayBuffer(data); - // } - // Careful - Node Buffers will look like ArrayBuffers (keep after isBuffer) - if (data instanceof ArrayBuffer) { - return new DataView(data); - } - throw new Error('toDataView'); -} - -// Use polyfills if installed to parsed image using get-pixels -async function parseToNodeImage(arrayBuffer, options) { - const { mimeType } = getBinaryImageMetadata(arrayBuffer) || {}; - // @ts-ignore - const parseImageNode = globalThis.loaders?.parseImageNode; - assert$4(parseImageNode); // '@loaders.gl/polyfills not installed' - // @ts-expect-error TODO should we throw error in this case? - return await parseImageNode(arrayBuffer, mimeType); -} - -// Parse to platform defined image type (data on node, ImageBitmap or HTMLImage on browser) -// eslint-disable-next-line complexity -async function parseImage(arrayBuffer, options, context) { - options = options || {}; - const imageOptions = options.image || {}; - // The user can request a specific output format via `options.image.type` - const imageType = imageOptions.type || 'auto'; - const { url } = context || {}; - // Note: For options.image.type === `data`, we may still need to load as `image` or `imagebitmap` - const loadType = getLoadableImageType(imageType); - let image; - switch (loadType) { - case 'imagebitmap': - image = await parseToImageBitmap(arrayBuffer, options, url); - break; - case 'image': - image = await parseToImage(arrayBuffer, options, url); - break; - case 'data': - // Node.js loads imagedata directly - image = await parseToNodeImage(arrayBuffer); - break; - default: - assert$4(false); - } - // Browser: if options.image.type === 'data', we can now extract data from the loaded image - if (imageType === 'data') { - image = getImageData(image); - } - return image; -} -// Get a loadable image type from image type -function getLoadableImageType(type) { - switch (type) { - case 'auto': - case 'data': - // Browser: For image data we need still need to load using an image format - // Node: the default image type is `data`. - return getDefaultImageType(); - default: - // Throw an error if not supported - isImageTypeSupported(type); - return type; - } -} - -// import type { ImageType } from '@loaders.gl/schema'; -const EXTENSIONS$1 = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'svg', 'avif']; -const MIME_TYPES = [ - 'image/png', - 'image/jpeg', - 'image/gif', - 'image/webp', - 'image/avif', - 'image/bmp', - 'image/vnd.microsoft.icon', - 'image/svg+xml' -]; -const DEFAULT_IMAGE_LOADER_OPTIONS = { - image: { - type: 'auto', - decode: true // if format is HTML - } - // imagebitmap: {} - passes (platform dependent) parameters to ImageBitmap constructor -}; -/** - * Loads a platform-specific image type - * Note: This type can be used as input data to WebGL texture creation - */ -const ImageLoader = { - dataType: null, - batchType: null, - id: 'image', - module: 'images', - name: 'Images', - version: VERSION$4, - mimeTypes: MIME_TYPES, - extensions: EXTENSIONS$1, - parse: parseImage, - // TODO: byteOffset, byteLength; - tests: [(arrayBuffer) => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))], - options: DEFAULT_IMAGE_LOADER_OPTIONS -}; - -// loaders.gl -/** Cache sync values for speed */ -const mimeTypeSupportedSync = {}; -/** - * Check if image MIME type is supported. Result is cached to avoid repeated tests. - */ -function isImageFormatSupported(mimeType) { - if (mimeTypeSupportedSync[mimeType] === undefined) { - const supported = isBrowser$2 - ? checkBrowserImageFormatSupport(mimeType) - : checkNodeImageFormatSupport(mimeType); - mimeTypeSupportedSync[mimeType] = supported; - } - return mimeTypeSupportedSync[mimeType]; -} -/** - * Checks that polyfills are installed and that mimeType is supported by polyfills - * @todo Ideally polyfills should declare what formats they support, instead of storing that data here. - */ -function checkNodeImageFormatSupport(mimeType) { - const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif']; - const imageFormatsNode = globalThis.loaders?.imageFormatsNode || NODE_FORMAT_SUPPORT; - const parseImageNode = globalThis.loaders?.parseImageNode; - return Boolean(parseImageNode) && imageFormatsNode.includes(mimeType); -} -/** Checks image format support synchronously. - * @note Unreliable, fails on AVIF - */ -function checkBrowserImageFormatSupport(mimeType) { - switch (mimeType) { - case 'image/avif': // Will fail - case 'image/webp': - return testBrowserImageFormatSupport(mimeType); - default: - return true; - } -} -/** - * Checks browser synchronously - * Checks if toDataURL supports the mimeType. - * @note Imperfect testOn Chrome this is true for WebP but not for AVIF - */ -function testBrowserImageFormatSupport(mimeType) { - try { - const element = document.createElement('canvas'); - const dataURL = element.toDataURL(mimeType); - return dataURL.indexOf(`data:${mimeType}`) === 0; - } - catch { - // Probably Safari... - return false; - } -} - -// Replacement for the external assert method to reduce bundle size -// Note: We don't use the second "message" argument in calling code, -// so no need to support it here -function assert$1(condition, message) { - if (!condition) { - throw new Error(message || 'assert failed: gltf'); - } -} - -const COMPONENTS$1 = { - SCALAR: 1, - VEC2: 2, - VEC3: 3, - VEC4: 4, - MAT2: 4, - MAT3: 9, - MAT4: 16 -}; -const BYTES$1 = { - 5120: 1, // BYTE - 5121: 1, // UNSIGNED_BYTE - 5122: 2, // SHORT - 5123: 2, // UNSIGNED_SHORT - 5125: 4, // UNSIGNED_INT - 5126: 4 // FLOAT -}; - -const TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4']; -const ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT = [ - [Int8Array, 5120], - [Uint8Array, 5121], - [Int16Array, 5122], - [Uint16Array, 5123], - [Uint32Array, 5125], - [Float32Array, 5126], - [Float64Array, 5130] -]; -const ARRAY_TO_COMPONENT_TYPE = new Map(ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT); -const ATTRIBUTE_TYPE_TO_COMPONENTS$1 = { - SCALAR: 1, - VEC2: 2, - VEC3: 3, - VEC4: 4, - MAT2: 4, - MAT3: 9, - MAT4: 16 -}; -const ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE$1 = { - 5120: 1, - 5121: 1, - 5122: 2, - 5123: 2, - 5125: 4, - 5126: 4 -}; -const ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY$1 = { - 5120: Int8Array, - 5121: Uint8Array, - 5122: Int16Array, - 5123: Uint16Array, - 5125: Uint32Array, - 5126: Float32Array -}; -function getAccessorTypeFromSize(size) { - const type = TYPES[size - 1]; - return type || TYPES[0]; -} -function getComponentTypeFromArray(typedArray) { - const componentType = ARRAY_TO_COMPONENT_TYPE.get(typedArray.constructor); - if (!componentType) { - throw new Error('Illegal typed array'); - } - return componentType; -} -function getAccessorArrayTypeAndLength(accessor, bufferView) { - const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY$1[accessor.componentType]; - const components = ATTRIBUTE_TYPE_TO_COMPONENTS$1[accessor.type]; - const bytesPerComponent = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE$1[accessor.componentType]; - const length = accessor.count * components; - const byteLength = accessor.count * components * bytesPerComponent; - assert$1(byteLength >= 0 && byteLength <= bufferView.byteLength); - const componentByteSize = BYTES$1[accessor.componentType]; - const numberOfComponentsInElement = COMPONENTS$1[accessor.type]; - return { ArrayType, length, byteLength, componentByteSize, numberOfComponentsInElement }; -} - -// TODO - GLTFScenegraph should use these -// accepts buffer view index or buffer view object -// returns a `Uint8Array` -function getTypedArrayForBufferView(json, buffers, bufferViewIndex) { - const bufferView = json.bufferViews[bufferViewIndex]; - assert$1(bufferView); - // Get hold of the arrayBuffer - const bufferIndex = bufferView.buffer; - const binChunk = buffers[bufferIndex]; - assert$1(binChunk); - const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset; - return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength); -} -/** - * Gets data pointed by the accessor. - * @param json - json part of gltf content of a GLTF tile. - * @param buffers - Array containing buffers of data. - * @param accessor - accepts accessor index or accessor object. - * @returns {TypedArray} Typed array with type matching the type of data poited by the accessor. - */ -// eslint-disable-next-line complexity -function getTypedArrayForAccessor(json, buffers, accessor) { - const gltfAccessor = typeof accessor === 'number' ? json.accessors?.[accessor] : accessor; - if (!gltfAccessor) { - throw new Error(`No gltf accessor ${JSON.stringify(accessor)}`); - } - const bufferView = json.bufferViews?.[gltfAccessor.bufferView || 0]; - if (!bufferView) { - throw new Error(`No gltf buffer view for accessor ${bufferView}`); - } - // Get `arrayBuffer` the `bufferView` looks at - const { arrayBuffer, byteOffset: bufferByteOffset } = buffers[bufferView.buffer]; - // Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets - const byteOffset = (bufferByteOffset || 0) + (gltfAccessor.byteOffset || 0) + (bufferView.byteOffset || 0); - // Deduce TypedArray type and its length from `accessor` and `bufferView` data - const { ArrayType, length, componentByteSize, numberOfComponentsInElement } = getAccessorArrayTypeAndLength(gltfAccessor, bufferView); - // 'length' is a whole number of components of all elements in the buffer pointed by the accessor - // Multiplier to calculate the address of the element in the arrayBuffer - const elementByteSize = componentByteSize * numberOfComponentsInElement; - const elementAddressScale = bufferView.byteStride || elementByteSize; - // Creare an array of component's type where all components (not just elements) will reside - if (typeof bufferView.byteStride === 'undefined' || bufferView.byteStride === elementByteSize) { - // No iterleaving - const result = new ArrayType(arrayBuffer, byteOffset, length); - return result; - } - // Iterleaving - const result = new ArrayType(length); - for (let i = 0; i < gltfAccessor.count; i++) { - const values = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, numberOfComponentsInElement); - result.set(values, i * numberOfComponentsInElement); - } - return result; -} - -// loaders.gl -function makeDefaultGLTFJson() { - return { - asset: { - version: '2.0', - generator: 'loaders.gl' - }, - buffers: [], - extensions: {}, - extensionsRequired: [], - extensionsUsed: [] - }; -} -/** - * Class for structured access to GLTF data - */ -class GLTFScenegraph { - // internal - gltf; - sourceBuffers; - byteLength; - // TODO - why is this not GLTFWithBuffers - what happens to images? - constructor(gltf) { - // Declare locally so - this.gltf = { - json: gltf?.json || makeDefaultGLTFJson(), - buffers: gltf?.buffers || [], - images: gltf?.images || [] - }; - this.sourceBuffers = []; - this.byteLength = 0; - // Initialize buffers - if (this.gltf.buffers && this.gltf.buffers[0]) { - this.byteLength = this.gltf.buffers[0].byteLength; - this.sourceBuffers = [this.gltf.buffers[0]]; - } - } - // Accessors - get json() { - return this.gltf.json; - } - getApplicationData(key) { - // TODO - Data is already unpacked by GLBParser - const data = this.json[key]; - return data; - } - getExtraData(key) { - // TODO - Data is already unpacked by GLBParser - const extras = (this.json.extras || {}); - return extras[key]; - } - hasExtension(extensionName) { - const isUsedExtension = this.getUsedExtensions().find((name) => name === extensionName); - const isRequiredExtension = this.getRequiredExtensions().find((name) => name === extensionName); - return typeof isUsedExtension === 'string' || typeof isRequiredExtension === 'string'; - } - getExtension(extensionName) { - const isExtension = this.getUsedExtensions().find((name) => name === extensionName); - const extensions = this.json.extensions || {}; - return isExtension ? extensions[extensionName] : null; - } - getRequiredExtension(extensionName) { - const isRequired = this.getRequiredExtensions().find((name) => name === extensionName); - return isRequired ? this.getExtension(extensionName) : null; - } - getRequiredExtensions() { - return this.json.extensionsRequired || []; - } - getUsedExtensions() { - return this.json.extensionsUsed || []; - } - getRemovedExtensions() { - return (this.json.extensionsRemoved || []); - } - getObjectExtension(object, extensionName) { - const extensions = object.extensions || {}; - return extensions[extensionName]; - } - getScene(index) { - return this.getObject('scenes', index); - } - getNode(index) { - return this.getObject('nodes', index); - } - getSkin(index) { - return this.getObject('skins', index); - } - getMesh(index) { - return this.getObject('meshes', index); - } - getMaterial(index) { - return this.getObject('materials', index); - } - getAccessor(index) { - return this.getObject('accessors', index); - } - // getCamera(index: number): object | null { - // return null; // TODO: fix thi: object as null; - // } - getTexture(index) { - return this.getObject('textures', index); - } - getSampler(index) { - return this.getObject('samplers', index); - } - getImage(index) { - return this.getObject('images', index); - } - getBufferView(index) { - return this.getObject('bufferViews', index); - } - getBuffer(index) { - return this.getObject('buffers', index); - } - getObject(array, index) { - // check if already resolved - if (typeof index === 'object') { - return index; - } - const object = this.json[array] && this.json[array][index]; - if (!object) { - throw new Error(`glTF file error: Could not find ${array}[${index}]`); // eslint-disable-line - } - return object; - } - /** - * Accepts buffer view index or buffer view object - * @returns a `Uint8Array` - */ - getTypedArrayForBufferView(bufferView) { - bufferView = this.getBufferView(bufferView); - // @ts-ignore - const bufferIndex = bufferView.buffer; - // Get hold of the arrayBuffer - // const buffer = this.getBuffer(bufferIndex); - const binChunk = this.gltf.buffers[bufferIndex]; - assert$1(binChunk); - // @ts-ignore - const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset; - // @ts-ignore - return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength); - } - /** Accepts accessor index or accessor object - * @returns a typed array with type that matches the types - */ - getTypedArrayForAccessor(accessor) { - // @ts-ignore - const gltfAccessor = this.getAccessor(accessor); - return getTypedArrayForAccessor(this.gltf.json, this.gltf.buffers, gltfAccessor); - } - /** accepts accessor index or accessor object - * returns a `Uint8Array` - */ - getTypedArrayForImageData(image) { - // @ts-ignore - image = this.getAccessor(image); - // @ts-ignore - const bufferView = this.getBufferView(image.bufferView); - const buffer = this.getBuffer(bufferView.buffer); - // @ts-ignore - const arrayBuffer = buffer.data; - const byteOffset = bufferView.byteOffset || 0; - return new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength); - } - // MODIFERS - /** - * Add an extra application-defined key to the top-level data structure - */ - addApplicationData(key, data) { - this.json[key] = data; - return this; - } - /** - * `extras` - Standard GLTF field for storing application specific data - */ - addExtraData(key, data) { - this.json.extras = this.json.extras || {}; - this.json.extras[key] = data; - return this; - } - addObjectExtension(object, extensionName, data) { - // @ts-ignore - object.extensions = object.extensions || {}; - // TODO - clobber or merge? - // @ts-ignore - object.extensions[extensionName] = data; - this.registerUsedExtension(extensionName); - return this; - } - setObjectExtension(object, extensionName, data) { - const extensions = object.extensions || {}; - extensions[extensionName] = data; - // TODO - add to usedExtensions... - } - removeObjectExtension(object, extensionName) { - const extensions = object?.extensions || {}; - if (extensions[extensionName]) { - this.json.extensionsRemoved = this.json.extensionsRemoved || []; - const extensionsRemoved = this.json.extensionsRemoved; - if (!extensionsRemoved.includes(extensionName)) { - extensionsRemoved.push(extensionName); - } - } - delete extensions[extensionName]; - } - /** - * Add to standard GLTF top level extension object, mark as used - */ - addExtension(extensionName, extensionData = {}) { - assert$1(extensionData); - this.json.extensions = this.json.extensions || {}; - this.json.extensions[extensionName] = extensionData; - this.registerUsedExtension(extensionName); - return extensionData; - } - /** - * Standard GLTF top level extension object, mark as used and required - */ - addRequiredExtension(extensionName, extensionData = {}) { - assert$1(extensionData); - this.addExtension(extensionName, extensionData); - this.registerRequiredExtension(extensionName); - return extensionData; - } - /** - * Add extensionName to list of used extensions - */ - registerUsedExtension(extensionName) { - this.json.extensionsUsed = this.json.extensionsUsed || []; - if (!this.json.extensionsUsed.find((ext) => ext === extensionName)) { - this.json.extensionsUsed.push(extensionName); - } - } - /** - * Add extensionName to list of required extensions - */ - registerRequiredExtension(extensionName) { - this.registerUsedExtension(extensionName); - this.json.extensionsRequired = this.json.extensionsRequired || []; - if (!this.json.extensionsRequired.find((ext) => ext === extensionName)) { - this.json.extensionsRequired.push(extensionName); - } - } - /** - * Removes an extension from the top-level list - */ - removeExtension(extensionName) { - if (this.json.extensions?.[extensionName]) { - this.json.extensionsRemoved = this.json.extensionsRemoved || []; - const extensionsRemoved = this.json.extensionsRemoved; - if (!extensionsRemoved.includes(extensionName)) { - extensionsRemoved.push(extensionName); - } - } - if (this.json.extensions) { - delete this.json.extensions[extensionName]; - } - if (this.json.extensionsRequired) { - this._removeStringFromArray(this.json.extensionsRequired, extensionName); - } - if (this.json.extensionsUsed) { - this._removeStringFromArray(this.json.extensionsUsed, extensionName); - } - } - /** - * Set default scene which is to be displayed at load time - */ - setDefaultScene(sceneIndex) { - this.json.scene = sceneIndex; - } - /** - * @todo: add more properties for scene initialization: - * name`, `extensions`, `extras` - * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-scene - */ - addScene(scene) { - const { nodeIndices } = scene; - this.json.scenes = this.json.scenes || []; - this.json.scenes.push({ nodes: nodeIndices }); - return this.json.scenes.length - 1; - } - /** - * @todo: add more properties for node initialization: - * `name`, `extensions`, `extras`, `camera`, `children`, `skin`, `rotation`, `scale`, `translation`, `weights` - * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#node - */ - addNode(node) { - const { meshIndex, matrix } = node; - this.json.nodes = this.json.nodes || []; - const nodeData = { mesh: meshIndex }; - if (matrix) { - // @ts-ignore - nodeData.matrix = matrix; - } - this.json.nodes.push(nodeData); - return this.json.nodes.length - 1; - } - /** Adds a mesh to the json part */ - addMesh(mesh) { - const { attributes, indices, material, mode = 4 } = mesh; - const accessors = this._addAttributes(attributes); - const glTFMesh = { - primitives: [ - { - attributes: accessors, - mode - } - ] - }; - if (indices) { - const indicesAccessor = this._addIndices(indices); - // @ts-ignore - glTFMesh.primitives[0].indices = indicesAccessor; - } - if (Number.isFinite(material)) { - // @ts-ignore - glTFMesh.primitives[0].material = material; - } - this.json.meshes = this.json.meshes || []; - this.json.meshes.push(glTFMesh); - return this.json.meshes.length - 1; - } - addPointCloud(attributes) { - // @ts-ignore - const accessorIndices = this._addAttributes(attributes); - const glTFMesh = { - primitives: [ - { - attributes: accessorIndices, - mode: 0 // GL.POINTS - } - ] - }; - this.json.meshes = this.json.meshes || []; - this.json.meshes.push(glTFMesh); - return this.json.meshes.length - 1; - } - /** - * Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference - * Buffer will be copied into BIN chunk during "pack" - * Currently encodes as glTF image - * @param imageData - * @param mimeType - */ - addImage(imageData, mimeTypeOpt) { - // If image is referencing a bufferView instead of URI, mimeType must be defined: - // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#images - // "a reference to a bufferView; in that case mimeType must be defined." - const metadata = getBinaryImageMetadata(imageData); - const mimeType = mimeTypeOpt || metadata?.mimeType; - const bufferViewIndex = this.addBufferView(imageData); - const glTFImage = { - bufferView: bufferViewIndex, - mimeType - }; - this.json.images = this.json.images || []; - this.json.images.push(glTFImage); - return this.json.images.length - 1; - } - /** - * Add one untyped source buffer, create a matching glTF `bufferView`, and return its index - * @param buffer - */ - addBufferView(buffer, bufferIndex = 0, byteOffset = this.byteLength) { - const byteLength = buffer.byteLength; - assert$1(Number.isFinite(byteLength)); - // Add this buffer to the list of buffers to be written to the body. - this.sourceBuffers = this.sourceBuffers || []; - this.sourceBuffers.push(buffer); - const glTFBufferView = { - buffer: bufferIndex, - // Write offset from the start of the binary body - byteOffset, - byteLength - }; - // We've now added the contents to the body, so update the total length - // Every sub-chunk needs to be 4-byte align ed - this.byteLength += padToNBytes(byteLength, 4); - // Add a bufferView indicating start and length of this binary sub-chunk - this.json.bufferViews = this.json.bufferViews || []; - this.json.bufferViews.push(glTFBufferView); - return this.json.bufferViews.length - 1; - } - /** - * Adds an accessor to a bufferView - * @param bufferViewIndex - * @param accessor - */ - addAccessor(bufferViewIndex, accessor) { - const glTFAccessor = { - bufferView: bufferViewIndex, - // @ts-ignore - type: getAccessorTypeFromSize(accessor.size), - // @ts-ignore - componentType: accessor.componentType, - // @ts-ignore - count: accessor.count, - // @ts-ignore - max: accessor.max, - // @ts-ignore - min: accessor.min - }; - this.json.accessors = this.json.accessors || []; - this.json.accessors.push(glTFAccessor); - return this.json.accessors.length - 1; - } - /** - * Add a binary buffer. Builds glTF "JSON metadata" and saves buffer reference - * Buffer will be copied into BIN chunk during "pack" - * Currently encodes buffers as glTF accessors, but this could be optimized - * @param sourceBuffer - * @param accessor - */ - addBinaryBuffer(sourceBuffer, accessor = { size: 3 }) { - const bufferViewIndex = this.addBufferView(sourceBuffer); - // @ts-ignore - let minMax = { min: accessor.min, max: accessor.max }; - if (!minMax.min || !minMax.max) { - // @ts-ignore - minMax = this._getAccessorMinMax(sourceBuffer, accessor.size); - } - const accessorDefaults = { - // @ts-ignore - size: accessor.size, - componentType: getComponentTypeFromArray(sourceBuffer), - // @ts-ignore - count: Math.round(sourceBuffer.length / accessor.size), - min: minMax.min, - max: minMax.max - }; - return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor)); - } - /** - * Adds a texture to the json part - * @todo: add more properties for texture initialization - * `sampler`, `name`, `extensions`, `extras` - * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#texture - */ - addTexture(texture) { - const { imageIndex } = texture; - const glTFTexture = { - source: imageIndex - }; - this.json.textures = this.json.textures || []; - this.json.textures.push(glTFTexture); - return this.json.textures.length - 1; - } - /** Adds a material to the json part */ - addMaterial(pbrMaterialInfo) { - this.json.materials = this.json.materials || []; - this.json.materials.push(pbrMaterialInfo); - return this.json.materials.length - 1; - } - /** Pack the binary chunk */ - createBinaryChunk() { - // Allocate total array - const totalByteLength = this.byteLength; - const arrayBuffer = new ArrayBuffer(totalByteLength); - const targetArray = new Uint8Array(arrayBuffer); - // Copy each array into - let dstByteOffset = 0; - for (const sourceBuffer of this.sourceBuffers || []) { - dstByteOffset = copyToArray(sourceBuffer, targetArray, dstByteOffset); - } - // Update the glTF BIN CHUNK byte length - if (this.json?.buffers?.[0]) { - this.json.buffers[0].byteLength = totalByteLength; - } - else { - this.json.buffers = [{ byteLength: totalByteLength }]; - } - // Save generated arrayBuffer - this.gltf.binary = arrayBuffer; - // Put arrayBuffer to sourceBuffers for possible additional writing data in the chunk - this.sourceBuffers = [arrayBuffer]; - this.gltf.buffers = [{ arrayBuffer, byteOffset: 0, byteLength: arrayBuffer.byteLength }]; - } - // PRIVATE - _removeStringFromArray(array, string) { - let found = true; - while (found) { - const index = array.indexOf(string); - if (index > -1) { - array.splice(index, 1); - } - else { - found = false; - } - } - } - /** - * Add attributes to buffers and create `attributes` object which is part of `mesh` - */ - _addAttributes(attributes = {}) { - const result = {}; - for (const attributeKey in attributes) { - const attributeData = attributes[attributeKey]; - const attrName = this._getGltfAttributeName(attributeKey); - const accessor = this.addBinaryBuffer(attributeData.value, attributeData); - result[attrName] = accessor; - } - return result; - } - /** - * Add indices to buffers - */ - _addIndices(indices) { - return this.addBinaryBuffer(indices, { size: 1 }); - } - /** - * Deduce gltf specific attribue name from input attribute name - */ - _getGltfAttributeName(attributeName) { - switch (attributeName.toLowerCase()) { - case 'position': - case 'positions': - case 'vertices': - return 'POSITION'; - case 'normal': - case 'normals': - return 'NORMAL'; - case 'color': - case 'colors': - return 'COLOR_0'; - case 'texcoord': - case 'texcoords': - return 'TEXCOORD_0'; - default: - return attributeName; - } - } - /** - * Calculate `min` and `max` arrays of accessor according to spec: - * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-accessor - */ - _getAccessorMinMax(buffer, size) { - const result = { min: null, max: null }; - if (buffer.length < size) { - return result; - } - // @ts-ignore - result.min = []; - // @ts-ignore - result.max = []; - const initValues = buffer.subarray(0, size); - for (const value of initValues) { - // @ts-ignore - result.min.push(value); - // @ts-ignore - result.max.push(value); - } - for (let index = size; index < buffer.length; index += size) { - for (let componentIndex = 0; componentIndex < size; componentIndex++) { - // @ts-ignore - result.min[0 + componentIndex] = Math.min( - // @ts-ignore - result.min[0 + componentIndex], buffer[index + componentIndex]); - // @ts-ignore - result.max[0 + componentIndex] = Math.max( - // @ts-ignore - result.max[0 + componentIndex], buffer[index + componentIndex]); - } - } - return result; - } -} - -/** - * loaders.gl, MIT license - * - * Shared code for 3DTiles extensions: - * * EXT_feature_metadata - * * EXT_mesh_features - * * EXT_structural_metadata - */ -function emod(n) { - return ((n % 1) + 1) % 1; -} -const ATTRIBUTE_TYPE_TO_COMPONENTS = { - SCALAR: 1, - VEC2: 2, - VEC3: 3, - VEC4: 4, - MAT2: 4, - MAT3: 9, - MAT4: 16, - BOOLEAN: 1, - STRING: 1, - ENUM: 1 -}; -const ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = { - INT8: Int8Array, - UINT8: Uint8Array, - INT16: Int16Array, - UINT16: Uint16Array, - INT32: Int32Array, - UINT32: Uint32Array, - INT64: BigInt64Array, - UINT64: BigUint64Array, - FLOAT32: Float32Array, - FLOAT64: Float64Array -}; -const ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = { - INT8: 1, - UINT8: 1, - INT16: 2, - UINT16: 2, - INT32: 4, - UINT32: 4, - INT64: 8, - UINT64: 8, - FLOAT32: 4, - FLOAT64: 8 -}; -function getArrayElementByteSize(attributeType, componentType) { - return (ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType] * - ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType]); -} -/** - * Gets offset array from `arrayOffsets` or `stringOffsets`. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param bufferViewIndex - Buffer view index - * @param offsetType - The type of values in `arrayOffsets` or `stringOffsets`. - * @param numberOfElements - The number of elements in each property array. - * @returns Array of values offsets. The number of offsets in the array is equal to `numberOfElements` plus one. - */ -function getOffsetsForProperty(scenegraph, bufferViewIndex, offsetType, numberOfElements) { - if (offsetType !== 'UINT8' && - offsetType !== 'UINT16' && - offsetType !== 'UINT32' && - offsetType !== 'UINT64') { - return null; - } - const arrayOffsetsBytes = scenegraph.getTypedArrayForBufferView(bufferViewIndex); - const arrayOffsets = convertRawBufferToMetadataArray(arrayOffsetsBytes, 'SCALAR', // offsets consist of ONE component - offsetType, numberOfElements + 1 // The number of offsets is equal to the property table `count` plus one. - ); - // We don't support BigInt offsets at the moment. It requires additional logic and potential issues in Safari - if (arrayOffsets instanceof BigInt64Array || arrayOffsets instanceof BigUint64Array) { - return null; - } - return arrayOffsets; -} -/** - * Converts raw bytes that are in the buffer to an array of the type defined by the schema. - * @param data - Raw bytes in the buffer. - * @param attributeType - SCALAR, VECN, MATN. - * @param componentType - Type of the component in elements, e.g. 'UINT8' or 'FLOAT32'. - * @param elementCount - Number of elements in the array. Default value is 1. - * @returns Data array - */ -function convertRawBufferToMetadataArray(data, attributeType, componentType, elementCount = 1) { - const numberOfComponents = ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType]; - const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[componentType]; - const size = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType]; - const length = elementCount * numberOfComponents; - const byteLength = length * size; - let buffer = data.buffer; - let offset = data.byteOffset; - if (offset % size !== 0) { - const bufferArray = new Uint8Array(buffer); - buffer = bufferArray.slice(offset, offset + byteLength).buffer; - offset = 0; - } - return new ArrayType(buffer, offset, length); -} -/** - * Processes data encoded in the texture associated with the primitive. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param textureInfo - Reference to the texture where extension data are stored. - * @param primitive - Primitive object in the mesh. - * @returns Array of data taken. Null if data can't be taken from the texture. - */ -function getPrimitiveTextureData(scenegraph, textureInfo, primitive) { - /* - texture.index is an index for the "textures" array. - The texture object referenced by this index looks like this: - { - "sampler": 0, - "source": 0 - } - "sampler" is an index for the "samplers" array - "source" is an index for the "images" array that contains data stored in rgba channels of the image. - - texture.texCoord is a number-suffix (like 1) for an attribute like "TEXCOORD_1" in meshes.primitives - The value of "TEXCOORD_1" is an accessor that is used to get coordinates. - These coordinates are being used to get data from the image. - - Default for texture.texCoord is 0 - @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/specification/2.0/schema/textureInfo.schema.json - */ - const texCoordAccessorKey = `TEXCOORD_${textureInfo.texCoord || 0}`; - const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey]; - const textureCoordinates = scenegraph.getTypedArrayForAccessor(texCoordAccessorIndex); - const json = scenegraph.gltf.json; - const textureIndex = textureInfo.index; - const imageIndex = json.textures?.[textureIndex]?.source; - if (typeof imageIndex !== 'undefined') { - const mimeType = json.images?.[imageIndex]?.mimeType; - const parsedImage = scenegraph.gltf.images?.[imageIndex]; - // Checking for width is to prevent handling Un-processed images (e.g. [analyze] stage, where loadImages option is set to false) - if (parsedImage && typeof parsedImage.width !== 'undefined') { - const textureData = []; - for (let index = 0; index < textureCoordinates.length; index += 2) { - const value = getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, textureInfo.channels); - textureData.push(value); - } - return textureData; - } - } - return []; -} -/** - * Puts property data to attributes. - * It creates corresponding buffer, bufferView and accessor - * so the data can be accessed like regular data stored in buffers. - * @param scenegraph - Scenegraph object. - * @param attributeName - Name of the attribute. - * @param propertyData - Property data to store. - * @param featureTable - Array where unique data from the property data are being stored. - * @param primitive - Primitive object. - */ -function primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTable, primitive) { - // No reason to create an empty buffer if there is no property data to store. - if (!propertyData?.length) { - return; - } - /* - featureTable will contain unique values, e.g. - propertyData = [24, 35, 28, 24] - featureTable = [24, 35, 28] - featureIndices will contain indices that refer featureTextureTable, e.g. - featureIndices = [0, 1, 2, 0] - */ - const featureIndices = []; - for (const texelData of propertyData) { - let index = featureTable.findIndex((item) => item === texelData); - if (index === -1) { - index = featureTable.push(texelData) - 1; - } - featureIndices.push(index); - } - const typedArray = new Uint32Array(featureIndices); - const bufferIndex = scenegraph.gltf.buffers.push({ - arrayBuffer: typedArray.buffer, - byteOffset: typedArray.byteOffset, - byteLength: typedArray.byteLength - }) - 1; - const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0); - const accessorIndex = scenegraph.addAccessor(bufferViewIndex, { - size: 1, - componentType: getComponentTypeFromArray(typedArray), - count: typedArray.length - }); - primitive.attributes[attributeName] = accessorIndex; -} -/** - * Gets the value from the texture by coordinates provided. - * @param parsedImage - Image where the data are stored. - * @param mimeType - MIME type. - * @param textureCoordinates - uv coordinates to access data in the image. - * @param index - Index of uv coordinates in the array textureCoordinates. - * @param channels - Image channels where data are stored. - * Channels of an RGBA texture are numbered 0..3 respectively. - * For Ext_mesh_features and EXT_strucural_metadata the channels default is [0] - * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_mesh_features/schema/featureIdTexture.schema.json - * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTexture.property.schema.json - * @returns Value taken from the image. - */ -function getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, channels = [0]) { - const CHANNELS_MAP = { - r: { offset: 0, shift: 0 }, - g: { offset: 1, shift: 8 }, - b: { offset: 2, shift: 16 }, - a: { offset: 3, shift: 24 } - }; - const u = textureCoordinates[index]; - const v = textureCoordinates[index + 1]; - let components = 1; - if (mimeType && (mimeType.indexOf('image/jpeg') !== -1 || mimeType.indexOf('image/png') !== -1)) - components = 4; - const offset = coordinatesToOffset(u, v, parsedImage, components); - let value = 0; - for (const c of channels) { - /* - According to the EXT_feature_metadata extension specification: - Channels are labeled by rgba and are swizzled with a string of 1-4 characters. - According to the EXT_mesh_features extension specification: - The channels array contains non-negative integer values corresponding to channels of the source texture that the feature ID consists of. - Channels of an RGBA texture are numbered 0–3 respectively. - Function getImageValueByCoordinates is used to process both extensions. - So, there should be possible to get the element of CHANNELS_MAP by either index (0, 1, 2, 3) or key (r, g, b, a). - */ - const map = typeof c === 'number' ? Object.values(CHANNELS_MAP)[c] : CHANNELS_MAP[c]; - const imageOffset = offset + map.offset; - const imageData = getImageData(parsedImage); - if (imageData.data.length <= imageOffset) { - throw new Error(`${imageData.data.length} <= ${imageOffset}`); - } - const imageValue = imageData.data[imageOffset]; - value |= imageValue << map.shift; - } - return value; -} -/** - * Retrieves the offset in the image where the data are stored. - * @param u - u-coordinate. - * @param v - v-coordinate. - * @param parsedImage - Image where the data are stored. - * @param componentsCount - Number of components the data consists of. - * @returns Offset in the image where the data are stored. - */ -function coordinatesToOffset(u, v, parsedImage, componentsCount = 1) { - const w = parsedImage.width; - const iX = emod(u) * (w - 1); - const indX = Math.round(iX); - const h = parsedImage.height; - const iY = emod(v) * (h - 1); - const indY = Math.round(iY); - const components = parsedImage.components ? parsedImage.components : componentsCount; - // components is a number of channels in the image - const offset = (indY * w + indX) * components; - return offset; -} -/** - * Parses variable-length array data. - * In this case every value of the property in the table will be an array - * of arbitrary length. - * @param valuesData - Values in a flat typed array. - * @param numberOfElements - Number of rows in the property table. - * @param arrayOffsets - Offsets of nested arrays in the flat values array. - * @param valuesDataBytesLength - Data byte length. - * @param valueSize - Value size in bytes. - * @returns Array of typed arrays. - */ -function parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength, valueSize) { - const attributeValueArray = []; - for (let index = 0; index < numberOfElements; index++) { - const arrayOffset = arrayOffsets[index]; - const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index]; - if (arrayByteSize + arrayOffset > valuesDataBytesLength) { - break; - } - const typedArrayOffset = arrayOffset / valueSize; - const elementCount = arrayByteSize / valueSize; - attributeValueArray.push(valuesData.slice(typedArrayOffset, typedArrayOffset + elementCount)); - } - return attributeValueArray; -} -/** - * Parses fixed-length array data. - * In this case every value of the property in the table will be an array - * of constant length equal to `arrayCount`. - * @param valuesData - Values in a flat typed array. - * @param numberOfElements - Number of rows in the property table. - * @param arrayCount - Nested arrays length. - * @returns Array of typed arrays. - */ -function parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount) { - const attributeValueArray = []; - for (let index = 0; index < numberOfElements; index++) { - const elementOffset = index * arrayCount; - attributeValueArray.push(valuesData.slice(elementOffset, elementOffset + arrayCount)); - } - return attributeValueArray; -} -/** - * Decodes properties of string type from binary source. - * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table. - * @param valuesDataBytes - Data taken from values property of the property table property. - * @param arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types. - * @param stringOffsets - Index of the buffer view containing offsets for strings. It should be available for string type. - * @returns String property values - */ -function getPropertyDataString(numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets) { - if (arrayOffsets) { - // TODO: implement it as soon as we have the corresponding tileset - throw new Error('Not implemented - arrayOffsets for strings is specified'); - } - if (stringOffsets) { - const stringsArray = []; - const textDecoder = new TextDecoder('utf8'); - let stringOffset = 0; - for (let index = 0; index < numberOfElements; index++) { - const stringByteSize = stringOffsets[index + 1] - stringOffsets[index]; - if (stringByteSize + stringOffset <= valuesDataBytes.length) { - const stringData = valuesDataBytes.subarray(stringOffset, stringByteSize + stringOffset); - const stringAttribute = textDecoder.decode(stringData); - stringsArray.push(stringAttribute); - stringOffset += stringByteSize; - } - } - return stringsArray; - } - return []; -} - -const EXT_MESH_FEATURES_NAME = 'EXT_mesh_features'; -const name$a = EXT_MESH_FEATURES_NAME; -async function decode$b(gltfData, options) { - const scenegraph = new GLTFScenegraph(gltfData); - decodeExtMeshFeatures(scenegraph, options); -} -function encode$5(gltfData, options) { - const scenegraph = new GLTFScenegraph(gltfData); - encodeExtMeshFeatures(scenegraph); - scenegraph.createBinaryChunk(); - return scenegraph.gltf; -} -/** - * Decodes feature metadata from extension. - * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data. - * @param {GLTFLoaderOptions} options - GLTFLoader options. - */ -function decodeExtMeshFeatures(scenegraph, options) { - const json = scenegraph.gltf.json; - if (!json.meshes) { - return; - } - // Iterate through all meshes/primitives. - for (const mesh of json.meshes) { - for (const primitive of mesh.primitives) { - processMeshPrimitiveFeatures(scenegraph, primitive, options); - } - } -} -/** - * Takes data from EXT_mesh_features and store it in 'data' property of featureIds. - * If combined with EXT_structural_metadata, corresponding data are taken from the property tables of that extension. - * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data. - * @param {GLTFMeshPrimitive} primitive - Primitive that contains extensions. - * @param {GLTFLoaderOptions} options - GLTFLoader options. - */ -function processMeshPrimitiveFeatures(scenegraph, primitive, options) { - // Processing of mesh primitive features requires buffers to be loaded. - if (!options?.gltf?.loadBuffers) { - return; - } - const extension = primitive.extensions?.[EXT_MESH_FEATURES_NAME]; - const featureIds = extension?.featureIds; - if (!featureIds) { - return; - } - for (const featureId of featureIds) { - let featureIdData; - // Process "Feature ID by Vertex" - if (typeof featureId.attribute !== 'undefined') { - const accessorKey = `_FEATURE_ID_${featureId.attribute}`; - const accessorIndex = primitive.attributes[accessorKey]; - featureIdData = scenegraph.getTypedArrayForAccessor(accessorIndex); - } - // Process "Feature ID by Texture Coordinates" - else if (typeof featureId.texture !== 'undefined' && options?.gltf?.loadImages) { - featureIdData = getPrimitiveTextureData(scenegraph, featureId.texture, primitive); - } - // Process "Feature ID by Index" - else { - /* - When both featureId.attribute and featureId.texture are undefined, - then the feature ID value for each vertex is given implicitly, via the index of the vertex. - In this case, the featureCount must match the number of vertices of the mesh primitive. - */ - // TODO: At the moment of writing we don't have a tileset with the data of that kind. Implement it later. - featureIdData = []; - } - featureId.data = featureIdData; - } -} -/* - Encoding data -*/ -function encodeExtMeshFeatures(scenegraph, options) { - const meshes = scenegraph.gltf.json.meshes; - if (!meshes) { - return; - } - // Iterate through all meshes/primitives. - for (const mesh of meshes) { - for (const primitive of mesh.primitives) { - encodeExtMeshFeaturesForPrimitive(scenegraph, primitive); - } - } -} -/** - * Creates ExtMeshFeatures, creates a featureId containing feature ids provided. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param primitive - target primitive instance that will contain the extension - * @param featureIdArray - Array of feature id - * @param propertyTableIndex - index of the property table created by the ExtStructuralMetadata (optional). - */ -function createExtMeshFeatures(scenegraph, primitive, featureIdArray, propertyTableIndex) { - if (!primitive.extensions) { - primitive.extensions = {}; - } - let extension = primitive.extensions[EXT_MESH_FEATURES_NAME]; - if (!extension) { - extension = { featureIds: [] }; - primitive.extensions[EXT_MESH_FEATURES_NAME] = extension; - } - const { featureIds } = extension; - const featureId = { - featureCount: featureIdArray.length, - propertyTable: propertyTableIndex, - data: featureIdArray - }; - featureIds.push(featureId); - scenegraph.addObjectExtension(primitive, EXT_MESH_FEATURES_NAME, extension); -} -/** - * Encodes a feature ID set to extension. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param primitive - Primitive that the data encoded belongs to. - * @see https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_mesh_features - */ -function encodeExtMeshFeaturesForPrimitive(scenegraph, primitive) { - const extension = primitive.extensions?.[EXT_MESH_FEATURES_NAME]; - if (!extension) { - return; - } - const featureIds = extension.featureIds; - featureIds.forEach((featureId, elementIndex) => { - if (featureId.data) { - const { accessorKey, index } = createAccessorKey(primitive.attributes); - const typedArray = new Uint32Array(featureId.data); - // Clean up featureId object. - // Everything that could come from the original extension in case of round-trip decode/encode operations should be deleted. - // We need make sure the featureId object is clean. - featureIds[elementIndex] = { - featureCount: typedArray.length, - propertyTable: featureId.propertyTable, - attribute: index - }; - scenegraph.gltf.buffers.push({ - arrayBuffer: typedArray.buffer, - byteOffset: typedArray.byteOffset, - byteLength: typedArray.byteLength - }); - const bufferViewIndex = scenegraph.addBufferView(typedArray); - const accessorIndex = scenegraph.addAccessor(bufferViewIndex, { - size: 1, - componentType: getComponentTypeFromArray(typedArray), - count: typedArray.length - }); - primitive.attributes[accessorKey] = accessorIndex; - } - }); -} -/** - * Creates an accessor key for the attribute array provided. - * The generated key has a suffix (number) that is the next consequtive in the list of existing accessors. - * @param attributes - attribute array - * @returns accessor key and the key suffix (number) used in the key. - */ -function createAccessorKey(attributes) { - const prefix = '_FEATURE_ID_'; - // Search for all "_FEATURE_ID_n" attribures in the primitive provided if any. - // If there are some, e.g. "_FEATURE_ID_0", "_FEATURE_ID_1", - // we will add a new one with the name "_FEATURE_ID_2" - const attrs = Object.keys(attributes).filter((item) => item.indexOf(prefix) === 0); - let max = -1; - for (const a of attrs) { - const n = Number(a.substring(prefix.length)); - if (n > max) { - max = n; - } - } - max++; - const accessorKey = `${prefix}${max}`; - return { accessorKey, index: max }; -} - -var EXT_mesh_features = /*#__PURE__*/Object.freeze({ - __proto__: null, - name: name$a, - decode: decode$b, - encode: encode$5, - createExtMeshFeatures: createExtMeshFeatures -}); - -const EXT_STRUCTURAL_METADATA_NAME = 'EXT_structural_metadata'; -const name$9 = EXT_STRUCTURAL_METADATA_NAME; -async function decode$a(gltfData, options) { - const scenegraph = new GLTFScenegraph(gltfData); - decodeExtStructuralMetadata(scenegraph, options); -} -function encode$4(gltfData, options) { - const scenegraph = new GLTFScenegraph(gltfData); - encodeExtStructuralMetadata(scenegraph); - scenegraph.createBinaryChunk(); - return scenegraph.gltf; -} -/* -// Example of the extension. -// See more info at https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata -const extensions = { - "extensions": { - "EXT_structural_metadata": { - "schema": { - "classes": { - "tree": { - "name": "Tree", - "description": "Woody, perennial plant.", - "properties": { - "species": { - "description": "Type of tree.", - "type": "ENUM", - "enumType": "speciesEnum", - "required": true - }, - "age": { - "description": "The age of the tree, in years", - "type": "SCALAR", - "componentType": "UINT8", - "required": true - } - } - } - }, - "enums": { - "speciesEnum": { - "name": "Species", - "description": "An example enum for tree species.", - // valueType is not defined here. Default is "UINT16" - "values": [ - { "name": "Unspecified", "value": 0 }, - { "name": "Oak", "value": 1 } - ] - } - } - }, - "propertyTables": [{ - "name": "tree_survey_2021-09-29", - "class": "tree", - "count": 10, // The number of elements in each property array (in `species`, in `age`). - "properties": { - "species": { - "values": 0, // It's an index of the buffer view containing property values. - }, - "age": { - "values": 1 - } - } - }] - } - } -} -*/ -/** - * Decodes feature metadata from extension. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param options - GLTFLoader options. - */ -function decodeExtStructuralMetadata(scenegraph, options) { - // Decoding metadata involves buffers processing. - // So, if buffers have not been loaded, there is no reason to process metadata. - if (!options.gltf?.loadBuffers) { - return; - } - const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME); - if (!extension) { - return; - } - if (options.gltf?.loadImages) { - decodePropertyTextures$1(scenegraph, extension); - } - decodePropertyTables$1(scenegraph, extension); -} -/** - * Processes the data stored in the textures - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param extension - Top-level extension. - */ -function decodePropertyTextures$1(scenegraph, extension) { - const propertyTextures = extension.propertyTextures; - const json = scenegraph.gltf.json; - if (propertyTextures && json.meshes) { - // Iterate through all meshes/primitives. - for (const mesh of json.meshes) { - for (const primitive of mesh.primitives) { - processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension); - } - } - } -} -/** - * Processes the data stored in the property tables. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param extension - Top-level extension. - */ -function decodePropertyTables$1(scenegraph, extension) { - const schema = extension.schema; - if (!schema) { - return; - } - const schemaClasses = schema.classes; - const propertyTables = extension.propertyTables; - if (schemaClasses && propertyTables) { - for (const schemaName in schemaClasses) { - const propertyTable = findPropertyTableByClass$1(propertyTables, schemaName); - if (propertyTable) { - processPropertyTable$1(scenegraph, schema, propertyTable); - } - } - } -} -/** - * Finds the property table by class name. - * @param propertyTables - propertyTable definition taken from the top-level extension. - * @param schemaClassName - class name in the extension schema. - */ -function findPropertyTableByClass$1(propertyTables, schemaClassName) { - for (const propertyTable of propertyTables) { - if (propertyTable.class === schemaClassName) { - return propertyTable; - } - } - return null; -} -/** - * Takes data from property textures reffered by the primitive. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param propertyTextures - propertyTexture definition taken from the top-level extention. - * @param primitive - Primitive object. - * @param extension - Top-level extension. - */ -function processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension) { - if (!propertyTextures) { - return; - } - const primitiveExtension = primitive.extensions?.[EXT_STRUCTURAL_METADATA_NAME]; - const primitivePropertyTextureIndices = primitiveExtension?.propertyTextures; - if (!primitivePropertyTextureIndices) { - return; - } - for (const primitivePropertyTextureIndex of primitivePropertyTextureIndices) { - const propertyTexture = propertyTextures[primitivePropertyTextureIndex]; - processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension); - } -} -/** - * Takes property data from the texture pointed by the primitive and appends them to `exension.data`. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param propertyTexture - propertyTexture definition taken from the top-level extension. - * @param primitive - Primitive object. - * @param extension - Top-level extension. - */ -function processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension) { - if (!propertyTexture.properties) { - return; - } - if (!extension.dataAttributeNames) { - extension.dataAttributeNames = []; - } - /* Iterate through all properties defined in propertyTexture, e.g. "speed" and "direction": - { - "class": "wind", - "properties": { - "speed": { - "index": 0, - "texCoord": 0, - "channels": [0] - }, - "direction": { - "index": 0, - "texCoord": 0, - "channels": [1, 2] - } - } - } - */ - const className = propertyTexture.class; - for (const propertyName in propertyTexture.properties) { - // propertyName has values like "speed", "direction" - // Make attributeName as a combination of the class name and the propertyName like "wind_speed" or "wind_direction" - const attributeName = `${className}_${propertyName}`; - const textureInfoTopLevel = propertyTexture.properties?.[propertyName]; - if (!textureInfoTopLevel) { - // eslint-disable-next-line no-continue - continue; - } - // The data taken from all meshes/primitives (the same property, e.g. "speed" or "direction") will be combined into one array and saved in textureInfoTopLevel.data - // Initially textureInfoTopLevel.data will be initialized with an empty array. - if (!textureInfoTopLevel.data) { - textureInfoTopLevel.data = []; - } - const featureTextureTable = textureInfoTopLevel.data; - const propertyData = getPrimitiveTextureData(scenegraph, textureInfoTopLevel, primitive); - if (propertyData === null) { - // eslint-disable-next-line no-continue - continue; - } - primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTextureTable, primitive); - textureInfoTopLevel.data = featureTextureTable; - extension.dataAttributeNames.push(attributeName); - } -} -/** - * Navigates through all properies in the property table, gets properties data, - * and put the data to `propertyTable.data` as an array. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param schema - schema object. - * @param propertyTable - propertyTable definition taken from the top-level extension. - */ -function processPropertyTable$1(scenegraph, schema, propertyTable) { - const schemaClass = schema.classes?.[propertyTable.class]; - if (!schemaClass) { - throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`); - } - const numberOfElements = propertyTable.count; // `propertyTable.count` is a number of elements in each property array. - for (const propertyName in schemaClass.properties) { - const classProperty = schemaClass.properties[propertyName]; - const propertyTableProperty = propertyTable.properties?.[propertyName]; - if (propertyTableProperty) { - // Getting all elements (`numberOfElements`) of the array in the `propertyTableProperty` - const data = getPropertyDataFromBinarySource$1(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty); - propertyTableProperty.data = data; - } - } -} -/** - * Decodes a propertyTable column from binary source based on property type. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param schema - Schema object. - * @param classProperty - class property object. - * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table. - * @param propertyTableProperty - propertyTable's property metadata. - * @returns {string[] | number[] | string[][] | number[][]} - */ -function getPropertyDataFromBinarySource$1(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty) { - let data = []; - const valuesBufferView = propertyTableProperty.values; - const valuesDataBytes = scenegraph.getTypedArrayForBufferView(valuesBufferView); - const arrayOffsets = getArrayOffsetsForProperty$1(scenegraph, classProperty, propertyTableProperty, numberOfElements); - const stringOffsets = getStringOffsetsForProperty$1(scenegraph, propertyTableProperty, numberOfElements); - switch (classProperty.type) { - case 'SCALAR': - case 'VEC2': - case 'VEC3': - case 'VEC4': - case 'MAT2': - case 'MAT3': - case 'MAT4': { - data = getPropertyDataNumeric$1(classProperty, numberOfElements, valuesDataBytes, arrayOffsets); - break; - } - case 'BOOLEAN': { - // TODO: implement it as soon as we have the corresponding tileset - throw new Error(`Not implemented - classProperty.type=${classProperty.type}`); - } - case 'STRING': { - data = getPropertyDataString(numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets); - break; - } - case 'ENUM': { - data = getPropertyDataENUM(schema, classProperty, numberOfElements, valuesDataBytes, arrayOffsets); - break; - } - default: - throw new Error(`Unknown classProperty type ${classProperty.type}`); - } - return data; -} -/** - * Parses propertyTable.property.arrayOffsets that are offsets of sub-arrays in a flatten array of values. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param classProperty - class property object. - * @param propertyTableProperty - propertyTable's property metadata. - * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table. - * @returns Typed array with offset values. - * @see https://github.com/CesiumGS/glTF/blob/2976f1183343a47a29e4059a70961371cd2fcee8/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTable.property.schema.json#L21 - */ -function getArrayOffsetsForProperty$1(scenegraph, classProperty, propertyTableProperty, numberOfElements) { - if (classProperty.array && - // `count` is a number of array elements. May only be defined when `array` is true. - // If `count` is NOT defined, it's a VARIABLE-length array - typeof classProperty.count === 'undefined' && - // `arrayOffsets` is an index of the buffer view containing offsets for variable-length arrays. - typeof propertyTableProperty.arrayOffsets !== 'undefined') { - // Data are in a VARIABLE-length array - return getOffsetsForProperty(scenegraph, propertyTableProperty.arrayOffsets, propertyTableProperty.arrayOffsetType || 'UINT32', numberOfElements); - } - return null; -} -/** - * Parses propertyTable.property.stringOffsets. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param propertyTableProperty - propertyTable's property metadata. - * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table. - * @returns Typed array with offset values. - * @see https://github.com/CesiumGS/glTF/blob/2976f1183343a47a29e4059a70961371cd2fcee8/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTable.property.schema.json#L29C10-L29C23 - */ -function getStringOffsetsForProperty$1(scenegraph, propertyTableProperty, numberOfElements) { - if (typeof propertyTableProperty.stringOffsets !== 'undefined' // `stringOffsets` is an index of the buffer view containing offsets for strings. - ) { - // Data are in a FIXED-length array - return getOffsetsForProperty(scenegraph, propertyTableProperty.stringOffsets, propertyTableProperty.stringOffsetType || 'UINT32', numberOfElements); - } - return null; -} -/** - * Decodes properties of SCALAR, VEC-N, MAT-N types from binary sourse. - * @param classProperty - class property object. - * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table. - * @param valuesDataBytes - Data taken from values property of the property table property. - * @param arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types. - * @returns Property values in a typed array or in an array of typed arrays. - */ -function getPropertyDataNumeric$1(classProperty, numberOfElements, valuesDataBytes, arrayOffsets) { - const isArray = classProperty.array; - const arrayCount = classProperty.count; - const elementSize = getArrayElementByteSize(classProperty.type, classProperty.componentType); - const elementCount = valuesDataBytes.byteLength / elementSize; - let valuesData; - if (classProperty.componentType) { - valuesData = convertRawBufferToMetadataArray(valuesDataBytes, classProperty.type, - // The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types. - classProperty.componentType, elementCount); - } - else { - // The spec doesn't provide any info what to do if componentType is not set. - valuesData = valuesDataBytes; - } - if (isArray) { - if (arrayOffsets) { - // VARIABLE-length array - return parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize); - } - if (arrayCount) { - // FIXED-length array - return parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount); - } - return []; - } - return valuesData; -} -/** - * Decodes properties of enum type from binary source. - * @param schema - Schema object. - * @param classProperty - Class property object. - * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table. - * @param valuesDataBytes - Data taken from values property of the property table property. - * @param arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types. - * @returns Strings array of nested strings array. - */ -function getPropertyDataENUM(schema, classProperty, numberOfElements, valuesDataBytes, arrayOffsets) { - const enumType = classProperty.enumType; - // Enum ID as declared in the `enums` dictionary. Required when `type` is `ENUM`. - if (!enumType) { - throw new Error('Incorrect data in the EXT_structural_metadata extension: classProperty.enumType is not set for type ENUM'); - } - const enumEntry = schema.enums?.[enumType]; - if (!enumEntry) { - throw new Error(`Incorrect data in the EXT_structural_metadata extension: schema.enums does't contain ${enumType}`); - } - const enumValueType = enumEntry.valueType || 'UINT16'; - const elementSize = getArrayElementByteSize(classProperty.type, enumValueType); - const elementCount = valuesDataBytes.byteLength / elementSize; - let valuesData = convertRawBufferToMetadataArray(valuesDataBytes, classProperty.type, enumValueType, elementCount); - if (!valuesData) { - valuesData = valuesDataBytes; - } - if (classProperty.array) { - if (arrayOffsets) { - // VARIABLE-length array - return parseVariableLengthArrayENUM({ - valuesData, - numberOfElements, - arrayOffsets, - valuesDataBytesLength: valuesDataBytes.length, - elementSize, - enumEntry - }); - } - const arrayCount = classProperty.count; - if (arrayCount) { - // FIXED-length array - return parseFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry); - } - return []; - } - // Single value (not an array) - return getEnumsArray(valuesData, 0, numberOfElements, enumEntry); -} -/** - * Parses variable length nested ENUM arrays. - * @param params.valuesData - Values in a flat typed array. - * @param params.numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table. - * @param params.arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types. - * @param params.valuesDataBytesLength - Byte length of values array. - * @param params.elementSize - Single element byte size. - * @param params.enumEntry - Enums dictionary. - * @returns Nested strings array. - */ -function parseVariableLengthArrayENUM(params) { - const { valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength, elementSize, enumEntry } = params; - const attributeValueArray = []; - for (let index = 0; index < numberOfElements; index++) { - const arrayOffset = arrayOffsets[index]; - const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index]; - if (arrayByteSize + arrayOffset > valuesDataBytesLength) { - break; - } - const typedArrayOffset = arrayOffset / elementSize; - const elementCount = arrayByteSize / elementSize; - const array = getEnumsArray(valuesData, typedArrayOffset, elementCount, enumEntry); - attributeValueArray.push(array); - } - return attributeValueArray; -} -/** - * Parses fixed length ENUM arrays. - * @param valuesData - Values in a flat typed array. - * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table. - * @param arrayCount - Nested arrays length. - * @param enumEntry - Enums dictionary. - * @returns Nested strings array. - */ -function parseFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry) { - const attributeValueArray = []; - for (let index = 0; index < numberOfElements; index++) { - const elementOffset = arrayCount * index; - const array = getEnumsArray(valuesData, elementOffset, arrayCount, enumEntry); - attributeValueArray.push(array); - } - return attributeValueArray; -} -/** - * Parses ENUM values into a string array. - * @param valuesData - Values in a flat typed array. - * @param offset - Offset to start parse from. - * @param count - Values length to parse. - * @param enumEntry - Enums dictionary. - * @returns Array of strings with parsed ENUM names. - */ -function getEnumsArray(valuesData, offset, count, enumEntry) { - const array = []; - for (let i = 0; i < count; i++) { - // At the moment we don't support BigInt. It requires additional calculations logic - // and might be an issue in Safari - if (valuesData instanceof BigInt64Array || valuesData instanceof BigUint64Array) { - array.push(''); - } - else { - const value = valuesData[offset + i]; - const enumObject = getEnumByValue(enumEntry, value); - if (enumObject) { - array.push(enumObject.name); - } - else { - array.push(''); - } - } - } - return array; -} -/** - * Looks up ENUM whose `value` property matches the specified number in the parameter `value`. - * @param {GLTF_EXT_structural_metadata_Enum} enumEntry - ENUM entry containing the array of possible enums. - * @param {number} value - The value of the ENUM to locate. - * @returns {GLTF_EXT_structural_metadata_EnumValue | null} ENUM matcihng the specified value or null of no ENUM object was found. - */ -function getEnumByValue(enumEntry, value) { - for (const enumValue of enumEntry.values) { - if (enumValue.value === value) { - return enumValue; - } - } - return null; -} -const SCHEMA_CLASS_ID_DEFAULT = 'schemaClassId'; -function encodeExtStructuralMetadata(scenegraph, options) { - const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME); - if (!extension) { - return; - } - if (extension.propertyTables) { - for (const table of extension.propertyTables) { - const classId = table.class; - const schemaClass = extension.schema?.classes?.[classId]; - if (table.properties && schemaClass) { - encodeProperties(table, schemaClass, scenegraph); - } - } - } -} -function encodeProperties(table, schemaClass, scenegraph) { - for (const propertyName in table.properties) { - const data = table.properties[propertyName].data; - if (data) { - const classProperty = schemaClass.properties[propertyName]; - if (classProperty) { - const tableProperty = createPropertyTableProperty(data, classProperty, scenegraph); - // Override table property that came with "data" - table.properties[propertyName] = tableProperty; - } - } - } -} -/** - * Creates ExtStructuralMetadata, creates the schema and creates a property table containing feature data provided. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param propertyAttributes - property attributes - * @param classId - classId to use for encoding metadata. - * @returns Index of the table created. - */ -function createExtStructuralMetadata(scenegraph, propertyAttributes, classId = SCHEMA_CLASS_ID_DEFAULT) { - let extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME); - if (!extension) { - extension = scenegraph.addExtension(EXT_STRUCTURAL_METADATA_NAME); - } - extension.schema = createSchema(propertyAttributes, classId, extension.schema); - const table = createPropertyTable(propertyAttributes, classId, extension.schema); - if (!extension.propertyTables) { - extension.propertyTables = []; - } - return extension.propertyTables.push(table) - 1; // index of the table -} -function createSchema(propertyAttributes, classId, schemaToUpdate) { - const schema = schemaToUpdate ?? { - id: 'schema_id' - }; - const schemaClass = { - properties: {} - }; - for (const attribute of propertyAttributes) { - const classProperty = { - type: attribute.elementType, - componentType: attribute.componentType - }; - schemaClass.properties[attribute.name] = classProperty; - } - schema.classes = {}; - schema.classes[classId] = schemaClass; - return schema; -} -function createPropertyTable(propertyAttributes, classId, schema) { - const table = { - class: classId, - count: 0 - }; - // count is a number of rows in the table - let count = 0; - const schemaClass = schema.classes?.[classId]; - for (const attribute of propertyAttributes) { - if (count === 0) { - count = attribute.values.length; - } - // The number of elements in all propertyAttributes must be the same - if (count !== attribute.values.length && attribute.values.length) { - throw new Error('Illegal values in attributes'); - } - const classProperty = schemaClass?.properties[attribute.name]; - if (classProperty) { - // const tableProperty = createPropertyTableProperty(attribute, classProperty, scenegraph); - if (!table.properties) { - table.properties = {}; - } - // values is a required field. Its real value will be set while encoding data - table.properties[attribute.name] = { values: 0, data: attribute.values }; - } - } - table.count = count; - return table; -} -function createPropertyTableProperty( -// attribute: PropertyAttribute, -values, classProperty, scenegraph) { - const prop = { values: 0 }; - if (classProperty.type === 'STRING') { - const { stringData, stringOffsets } = createPropertyDataString(values); - prop.stringOffsets = createBufferView(stringOffsets, scenegraph); - prop.values = createBufferView(stringData, scenegraph); - } - else if (classProperty.type === 'SCALAR' && classProperty.componentType) { - const data = createPropertyDataScalar(values, classProperty.componentType); - prop.values = createBufferView(data, scenegraph); - } - return prop; -} -const COMPONENT_TYPE_TO_ARRAY_CONSTRUCTOR = { - INT8: Int8Array, - UINT8: Uint8Array, - INT16: Int16Array, - UINT16: Uint16Array, - INT32: Int32Array, - UINT32: Uint32Array, - INT64: Int32Array, - UINT64: Uint32Array, - FLOAT32: Float32Array, - FLOAT64: Float64Array -}; -function createPropertyDataScalar(array, componentType) { - const numberArray = []; - for (const value of array) { - numberArray.push(Number(value)); - } - const Construct = COMPONENT_TYPE_TO_ARRAY_CONSTRUCTOR[componentType]; - if (!Construct) { - throw new Error('Illegal component type'); - } - return new Construct(numberArray); -} -function createPropertyDataString(strings) { - const utf8Encode = new TextEncoder(); - const arr = []; - let len = 0; - for (const str of strings) { - const uint8Array = utf8Encode.encode(str); - len += uint8Array.length; - arr.push(uint8Array); - } - const strArray = new Uint8Array(len); - const strOffsets = []; - let offset = 0; - for (const str of arr) { - strArray.set(str, offset); - strOffsets.push(offset); - offset += str.length; - } - strOffsets.push(offset); // The last offset represents the byte offset after the last string. - const stringOffsetsTypedArray = new Uint32Array(strOffsets); // Its length = len+1 - return { stringData: strArray, stringOffsets: stringOffsetsTypedArray }; -} -function createBufferView(typedArray, scenegraph) { - scenegraph.gltf.buffers.push({ - arrayBuffer: typedArray.buffer, - byteOffset: typedArray.byteOffset, - byteLength: typedArray.byteLength - }); - return scenegraph.addBufferView(typedArray); -} - -var EXT_structural_metadata = /*#__PURE__*/Object.freeze({ - __proto__: null, - name: name$9, - decode: decode$a, - encode: encode$4, - createExtStructuralMetadata: createExtStructuralMetadata -}); - -/** Extension name */ -const EXT_FEATURE_METADATA_NAME = 'EXT_feature_metadata'; -const name$8 = EXT_FEATURE_METADATA_NAME; -async function decode$9(gltfData, options) { - const scenegraph = new GLTFScenegraph(gltfData); - decodeExtFeatureMetadata(scenegraph, options); -} -/** - * Decodes feature metadata from extension. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param options - GLTFLoader options. - */ -function decodeExtFeatureMetadata(scenegraph, options) { - // Decoding metadata involves buffers processing. - // So, if buffers have not been loaded, there is no reason to process metadata. - if (!options.gltf?.loadBuffers) { - return; - } - const extension = scenegraph.getExtension(EXT_FEATURE_METADATA_NAME); - if (!extension) { - return; - } - if (options.gltf?.loadImages) { - decodePropertyTextures(scenegraph, extension); - } - decodePropertyTables(scenegraph, extension); -} -/** - * Processes the data stored in the textures - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param extension - Top-level extension. - */ -function decodePropertyTextures(scenegraph, extension) { - const schema = extension.schema; - if (!schema) { - return; - } - const schemaClasses = schema.classes; - const { featureTextures } = extension; - if (schemaClasses && featureTextures) { - for (const schemaName in schemaClasses) { - const schemaClass = schemaClasses[schemaName]; - const featureTexture = findFeatureTextureByClass(featureTextures, schemaName); - if (featureTexture) { - handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass); - } - } - } -} -/** - * Processes the data stored in the property tables. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param extension - Top-level extension. - */ -function decodePropertyTables(scenegraph, extension) { - const schema = extension.schema; - if (!schema) { - return; - } - const schemaClasses = schema.classes; - const propertyTables = extension.featureTables; - if (schemaClasses && propertyTables) { - for (const schemaName in schemaClasses) { - const propertyTable = findPropertyTableByClass(propertyTables, schemaName); - if (propertyTable) { - processPropertyTable(scenegraph, schema, propertyTable); - } - } - } -} -/** - * Finds the property table by class name. - * @param propertyTables - propertyTable definition taken from the top-level extension. - * @param schemaClassName - class name in the extension schema. - */ -function findPropertyTableByClass(propertyTables, schemaClassName) { - for (const propertyTableName in propertyTables) { - const propertyTable = propertyTables[propertyTableName]; - if (propertyTable.class === schemaClassName) { - return propertyTable; - } - } - return null; -} -function findFeatureTextureByClass(featureTextures, schemaClassName) { - for (const featureTexturesName in featureTextures) { - const featureTable = featureTextures[featureTexturesName]; - if (featureTable.class === schemaClassName) { - return featureTable; - } - } - return null; -} -/** - * Navigates through all properies in the property table, gets properties data, - * and put the data to `propertyTable.data` as an array. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param schema - schema object. - * @param propertyTable - propertyTable definition taken from the top-level extension. - */ -function processPropertyTable(scenegraph, schema, propertyTable) { - // Though 'class' is not required by spec, it doesn't make any scence when it's not provided. - // So, bale out here. - if (!propertyTable.class) { - return; - } - const schemaClass = schema.classes?.[propertyTable.class]; - if (!schemaClass) { - throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`); - } - const numberOfElements = propertyTable.count; // `propertyTable.count` is a number of elements in each property array. - for (const propertyName in schemaClass.properties) { - const classProperty = schemaClass.properties[propertyName]; - const propertyTableProperty = propertyTable.properties?.[propertyName]; - if (propertyTableProperty) { - // Getting all elements (`numberOfElements`) of the array in the `propertyTableProperty` - const data = getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty); - propertyTableProperty.data = data; - } - } -} -/** - * Navigates through all properies in feature texture and gets properties data. - * Data will be stored in featureTexture.properties[propertyName].data. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param featureTexture - * @param schemaClass - */ -function handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass) { - const attributeName = featureTexture.class; - for (const propertyName in schemaClass.properties) { - const featureTextureProperty = featureTexture?.properties?.[propertyName]; - if (featureTextureProperty) { - const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName); - featureTextureProperty.data = data; - } - } -} -/** - * Decodes properties from binary sourse based on property type. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param schemaProperty - * @param numberOfFeatures - * @param featureTableProperty - */ -function getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfFeatures, featureTableProperty) { - let data = []; - const bufferView = featureTableProperty.bufferView; - const dataArray = scenegraph.getTypedArrayForBufferView(bufferView); - const arrayOffsets = getArrayOffsetsForProperty(scenegraph, classProperty, featureTableProperty, numberOfFeatures); - const stringOffsets = getStringOffsetsForProperty(scenegraph, classProperty, featureTableProperty, numberOfFeatures); - if (classProperty.type === 'STRING' || classProperty.componentType === 'STRING') { - data = getPropertyDataString(numberOfFeatures, dataArray, arrayOffsets, stringOffsets); - } - else if (isNumericProperty(classProperty)) { - data = getPropertyDataNumeric(classProperty, numberOfFeatures, dataArray, arrayOffsets); - } - return data; -} -/** - * Parses propertyTable.property.arrayOffsets that are offsets of sub-arrays in a flatten array of values. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param classProperty - class property object. - * @param propertyTableProperty - propertyTable's property metadata. - * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table. - * @returns Typed array with offset values. - * @see https://github.com/CesiumGS/glTF/blob/2976f1183343a47a29e4059a70961371cd2fcee8/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTable.property.schema.json#L21 - */ -function getArrayOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements) { - /* - If ARRAY is used, then componentType must also be specified. - ARRAY is a fixed-length array when componentCount is defined, and variable-length otherwise. - */ - if (classProperty.type === 'ARRAY' && - // `componentCount` is a number of fixed-length array elements. - // If `componentCount` is NOT defined, it's a VARIABLE-length array - typeof classProperty.componentCount === 'undefined' && - // `arrayOffsetBufferView` is an index of the buffer view containing offsets for variable-length arrays. - typeof propertyTableProperty.arrayOffsetBufferView !== 'undefined') { - // Data are in a VARIABLE-length array - return getOffsetsForProperty(scenegraph, propertyTableProperty.arrayOffsetBufferView, propertyTableProperty.offsetType || 'UINT32', // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView - numberOfElements); - } - return null; -} -/** - * Parses featureTable.property.stringOffsetBufferView. - * String offsets is an array of offsets of strings in the united array of characters. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param propertyTableProperty - propertyTable's property metadata. - * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table. - * @returns Typed array of offset values. The number of offsets in the array is equal to `numberOfElements` plus one. - * @see https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/featureTable.property.schema.json#L50C10-L50C32 - */ -function getStringOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements) { - if (typeof propertyTableProperty.stringOffsetBufferView !== 'undefined' // `stringOffsetBufferView` is an index of the buffer view containing offsets for strings. - ) { - // Data are in a FIXED-length array - return getOffsetsForProperty(scenegraph, propertyTableProperty.stringOffsetBufferView, propertyTableProperty.offsetType || 'UINT32', // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView - numberOfElements); - } - return null; -} -/** - * Checks if the feature table property is of numeric type. - * @param schemaPropertyType - feature table property - * @returns true if property is numeric, else - false - */ -function isNumericProperty(schemaProperty) { - const types = [ - 'UINT8', - 'INT16', - 'UINT16', - 'INT32', - 'UINT32', - 'INT64', - 'UINT64', - 'FLOAT32', - 'FLOAT64' - ]; - return (types.includes(schemaProperty.type) || - (typeof schemaProperty.componentType !== 'undefined' && - types.includes(schemaProperty.componentType))); -} -/** - * Decodes properties of numeric types from binary sourse. - * @param classProperty - class property object. - * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table. - * @param valuesDataBytes - Data taken from values property of the property table property. - * @param arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types. - * @returns Property values in a typed array or in an array of typed arrays. - */ -function getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets) { - const isArray = classProperty.type === 'ARRAY'; - const arrayCount = classProperty.componentCount; - /* - We are getting Numeric data. So, - the component type can be one of NumericComponentType, - the attribute type should be 'SCALAR' - */ - const attributeType = 'SCALAR'; - const componentType = classProperty.componentType || classProperty.type; - const elementSize = getArrayElementByteSize(attributeType, componentType); - const elementCount = valuesDataBytes.byteLength / elementSize; - const valuesData = convertRawBufferToMetadataArray(valuesDataBytes, attributeType, componentType, elementCount); - if (isArray) { - if (arrayOffsets) { - // VARIABLE-length array - return parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize); - } - if (arrayCount) { - // FIXED-length array - return parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount); - } - return []; - } - return valuesData; -} -/** - * Gets properties from texture associated with all mesh primitives. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param featureTextureProperty - * @param attributeName - * @returns Feature texture data - */ -function getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName) { - const json = scenegraph.gltf.json; - if (!json.meshes) { - return []; - } - const featureTextureTable = []; - for (const mesh of json.meshes) { - for (const primitive of mesh.primitives) { - processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive); - } - } - return featureTextureTable; -} -/** - * Processes data encoded in the texture associated with the primitive. This data will be accessible through the attributes. - * @param scenegraph - Instance of the class for structured access to GLTF data. - * @param attributeName - * @param featureTextureProperty - * @param featureTextureTable - * @param primitive - */ -function processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive) { - const textureInfoTopLevel = { - channels: featureTextureProperty.channels, - ...featureTextureProperty.texture - }; - const propertyData = getPrimitiveTextureData(scenegraph, textureInfoTopLevel, primitive); - if (!propertyData) { - return; - } - primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTextureTable, primitive); -} - -var EXT_feature_metadata = /*#__PURE__*/Object.freeze({ - __proto__: null, - name: name$8, - decode: decode$9 -}); - -// Version constant cannot be imported, it needs to correspond to the build version of **this** module. -// __VERSION__ is injected by babel-plugin-version-inline -// @ts-ignore TS2304: Cannot find name '__VERSION__'. -const VERSION$3 = "4.3.3" ; - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -// Version constant cannot be imported, it needs to correspond to the build version of **this** module. -// __VERSION__ is injected by babel-plugin-version-inline -// @ts-ignore TS2304: Cannot find name '__VERSION__'. -const VERSION$2 = "4.3.3" ; - -// loaders.gl -const BASIS_EXTERNAL_LIBRARIES = { - /** Basis transcoder, javascript wrapper part */ - TRANSCODER: 'basis_transcoder.js', - /** Basis transcoder, compiled web assembly part */ - TRANSCODER_WASM: 'basis_transcoder.wasm', - /** Basis encoder, javascript wrapper part */ - ENCODER: 'basis_encoder.js', - /** Basis encoder, compiled web assembly part */ - ENCODER_WASM: 'basis_encoder.wasm' -}; -let loadBasisTranscoderPromise; -/** - * Loads wasm transcoder module - * @param options - * @returns {BasisFile} promise - */ -async function loadBasisTranscoderModule(options) { - registerJSModules(options.modules); - const basis = getJSModuleOrNull('basis'); - if (basis) { - return basis; - } - loadBasisTranscoderPromise ||= loadBasisTranscoder(options); - return await loadBasisTranscoderPromise; -} -/** - * Loads wasm transcoder module - * @param options - * @returns {BasisFile} promise - */ -async function loadBasisTranscoder(options) { - let BASIS = null; - let wasmBinary = null; - [BASIS, wasmBinary] = await Promise.all([ - await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER, 'textures', options), - await loadLibrary(BASIS_EXTERNAL_LIBRARIES.TRANSCODER_WASM, 'textures', options) - ]); - // Depends on how import happened... - // @ts-ignore TS2339: Property does not exist on type - BASIS = BASIS || globalThis.BASIS; - return await initializeBasisTranscoderModule(BASIS, wasmBinary); -} -/** - * Initialize wasm transcoder module - * @param BasisModule - js part of the module - * @param wasmBinary - wasm part of the module - * @returns {BasisFile} promise - */ -function initializeBasisTranscoderModule(BasisModule, wasmBinary) { - const options = {}; - if (wasmBinary) { - options.wasmBinary = wasmBinary; - } - return new Promise((resolve) => { - // if you try to return BasisModule the browser crashes! - BasisModule(options).then((module) => { - const { BasisFile, initializeBasis } = module; - initializeBasis(); - resolve({ BasisFile }); - }); - }); -} -let loadBasisEncoderPromise; -/** - * Loads wasm encoder module - * @param options - * @returns {BasisFile, KTX2File} promise - */ -async function loadBasisEncoderModule(options) { - const modules = options.modules || {}; - if (modules.basisEncoder) { - return modules.basisEncoder; - } - loadBasisEncoderPromise = loadBasisEncoderPromise || loadBasisEncoder(options); - return await loadBasisEncoderPromise; -} -/** - * Loads wasm encoder module - * @param options - * @returns {BasisFile, KTX2File} promise - */ -async function loadBasisEncoder(options) { - let BASIS_ENCODER = null; - let wasmBinary = null; - [BASIS_ENCODER, wasmBinary] = await Promise.all([ - await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER, 'textures', options), - await loadLibrary(BASIS_EXTERNAL_LIBRARIES.ENCODER_WASM, 'textures', options) - ]); - // Depends on how import happened... - // @ts-ignore TS2339: Property does not exist on type - BASIS_ENCODER = BASIS_ENCODER || globalThis.BASIS; - return await initializeBasisEncoderModule(BASIS_ENCODER, wasmBinary); -} -/** - * Initialize wasm transcoder module - * @param BasisEncoderModule - js part of the module - * @param wasmBinary - wasm part of the module - * @returns {BasisFile, KTX2File} promise - */ -function initializeBasisEncoderModule(BasisEncoderModule, wasmBinary) { - const options = {}; - if (wasmBinary) { - options.wasmBinary = wasmBinary; - } - return new Promise((resolve) => { - // if you try to return BasisModule the browser crashes! - BasisEncoderModule(options).then((module) => { - const { BasisFile, KTX2File, initializeBasis, BasisEncoder } = module; - initializeBasis(); - resolve({ BasisFile, KTX2File, BasisEncoder }); - }); - }); -} - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -/* eslint-disable camelcase */ -const GL_EXTENSIONS_CONSTANTS = { - // WEBGL_compressed_texture_s3tc - COMPRESSED_RGB_S3TC_DXT1_EXT: 0x83f0, - COMPRESSED_RGBA_S3TC_DXT1_EXT: 0x83f1, - COMPRESSED_RGBA_S3TC_DXT3_EXT: 0x83f2, - COMPRESSED_RGBA_S3TC_DXT5_EXT: 0x83f3, - // WEBGL_compressed_texture_es3 - COMPRESSED_R11_EAC: 0x9270, - COMPRESSED_SIGNED_R11_EAC: 0x9271, - COMPRESSED_RG11_EAC: 0x9272, - COMPRESSED_SIGNED_RG11_EAC: 0x9273, - COMPRESSED_RGB8_ETC2: 0x9274, - COMPRESSED_RGBA8_ETC2_EAC: 0x9275, - COMPRESSED_SRGB8_ETC2: 0x9276, - COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 0x9277, - COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 0x9278, - COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 0x9279, - // WEBGL_compressed_texture_pvrtc - COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 0x8c00, - COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 0x8c02, - COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 0x8c01, - COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 0x8c03, - // WEBGL_compressed_texture_etc1 - COMPRESSED_RGB_ETC1_WEBGL: 0x8d64, - // WEBGL_compressed_texture_atc - COMPRESSED_RGB_ATC_WEBGL: 0x8c92, - COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: 0x8c93, - COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: 0x87ee, - // WEBGL_compressed_texture_astc - COMPRESSED_RGBA_ASTC_4X4_KHR: 0x93b0, - COMPRESSED_RGBA_ASTC_5X4_KHR: 0x93b1, - COMPRESSED_RGBA_ASTC_5X5_KHR: 0x93b2, - COMPRESSED_RGBA_ASTC_6X5_KHR: 0x93b3, - COMPRESSED_RGBA_ASTC_6X6_KHR: 0x93b4, - COMPRESSED_RGBA_ASTC_8X5_KHR: 0x93b5, - COMPRESSED_RGBA_ASTC_8X6_KHR: 0x93b6, - COMPRESSED_RGBA_ASTC_8X8_KHR: 0x93b7, - COMPRESSED_RGBA_ASTC_10X5_KHR: 0x93b8, - COMPRESSED_RGBA_ASTC_10X6_KHR: 0x93b9, - COMPRESSED_RGBA_ASTC_10X8_KHR: 0x93ba, - COMPRESSED_RGBA_ASTC_10X10_KHR: 0x93bb, - COMPRESSED_RGBA_ASTC_12X10_KHR: 0x93bc, - COMPRESSED_RGBA_ASTC_12X12_KHR: 0x93bd, - COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR: 0x93d0, - COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR: 0x93d1, - COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR: 0x93d2, - COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR: 0x93d3, - COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR: 0x93d4, - COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR: 0x93d5, - COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR: 0x93d6, - COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR: 0x93d7, - COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR: 0x93d8, - COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR: 0x93d9, - COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR: 0x93da, - COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR: 0x93db, - COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR: 0x93dc, - COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR: 0x93dd, - // EXT_texture_compression_rgtc - COMPRESSED_RED_RGTC1_EXT: 0x8dbb, - COMPRESSED_SIGNED_RED_RGTC1_EXT: 0x8dbc, - COMPRESSED_RED_GREEN_RGTC2_EXT: 0x8dbd, - COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: 0x8dbe, - // WEBGL_compressed_texture_s3tc_srgb - COMPRESSED_SRGB_S3TC_DXT1_EXT: 0x8c4c, - COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 0x8c4d, - COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 0x8c4e, - COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 0x8c4f -}; - -// loaders.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -const BROWSER_PREFIXES = ['', 'WEBKIT_', 'MOZ_']; -const WEBGL_EXTENSIONS = { - /* eslint-disable camelcase */ - WEBGL_compressed_texture_s3tc: 'dxt', - WEBGL_compressed_texture_s3tc_srgb: 'dxt-srgb', - WEBGL_compressed_texture_etc1: 'etc1', - WEBGL_compressed_texture_etc: 'etc2', - WEBGL_compressed_texture_pvrtc: 'pvrtc', - WEBGL_compressed_texture_atc: 'atc', - WEBGL_compressed_texture_astc: 'astc', - EXT_texture_compression_rgtc: 'rgtc' - /* eslint-enable camelcase */ -}; -let formats = null; -/** - * Returns a list of formats. - * Creates a temporary WebGLRenderingContext if none is provided. - * - * @param gl - Optional context. - */ -function getSupportedGPUTextureFormats(gl) { - if (!formats) { - gl = gl || getWebGLContext() || undefined; - formats = new Set(); - for (const prefix of BROWSER_PREFIXES) { - for (const extension in WEBGL_EXTENSIONS) { - if (gl && gl.getExtension(`${prefix}${extension}`)) { - const gpuTextureFormat = WEBGL_EXTENSIONS[extension]; - formats.add(gpuTextureFormat); - } - } - } - } - return formats; -} -/** - * @returns {WebGLRenderingContext?} - */ -function getWebGLContext() { - try { - const canvas = document.createElement('canvas'); - return canvas.getContext('webgl'); - } - catch (error) { - return null; - } -} - -// loaders.gl -const KTX2_ID = [ - // '´', 'K', 'T', 'X', '2', '0', 'ª', '\r', '\n', '\x1A', '\n' - 0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a -]; -// eslint-disable-next-line complexity -function isKTX(data) { - // const id = new Uint8Array(data.buffer, data.byteOffset, data.byteLength); - const id = new Uint8Array(data); - const notKTX = id.byteLength < KTX2_ID.length || - id[0] !== KTX2_ID[0] || // '´' - id[1] !== KTX2_ID[1] || // 'K' - id[2] !== KTX2_ID[2] || // 'T' - id[3] !== KTX2_ID[3] || // 'X' - id[4] !== KTX2_ID[4] || // ' ' - id[5] !== KTX2_ID[5] || // '2' - id[6] !== KTX2_ID[6] || // '0' - id[7] !== KTX2_ID[7] || // 'ª' - id[8] !== KTX2_ID[8] || // '\r' - id[9] !== KTX2_ID[9] || // '\n' - id[10] !== KTX2_ID[10] || // '\x1A' - id[11] !== KTX2_ID[11]; // '\n' - return !notKTX; -} - -// loaders.gl -const OutputFormat = { - etc1: { - basisFormat: 0, - compressed: true, - format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL - }, - etc2: { basisFormat: 1, compressed: true }, - bc1: { - basisFormat: 2, - compressed: true, - format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT - }, - bc3: { - basisFormat: 3, - compressed: true, - format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT - }, - bc4: { basisFormat: 4, compressed: true }, - bc5: { basisFormat: 5, compressed: true }, - 'bc7-m6-opaque-only': { basisFormat: 6, compressed: true }, - 'bc7-m5': { basisFormat: 7, compressed: true }, - 'pvrtc1-4-rgb': { - basisFormat: 8, - compressed: true, - format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG - }, - 'pvrtc1-4-rgba': { - basisFormat: 9, - compressed: true, - format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG - }, - 'astc-4x4': { - basisFormat: 10, - compressed: true, - format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR - }, - 'atc-rgb': { basisFormat: 11, compressed: true }, - 'atc-rgba-interpolated-alpha': { basisFormat: 12, compressed: true }, - rgba32: { basisFormat: 13, compressed: false }, - rgb565: { basisFormat: 14, compressed: false }, - bgr565: { basisFormat: 15, compressed: false }, - rgba4444: { basisFormat: 16, compressed: false } -}; -/** - * parse data with a Binomial Basis_Universal module - * @param data - * @param options - * @returns compressed texture data - */ -async function parseBasis(data, options) { - if (options.basis.containerFormat === 'auto') { - if (isKTX(data)) { - const fileConstructors = await loadBasisEncoderModule(options); - return parseKTX2File(fileConstructors.KTX2File, data, options); - } - const { BasisFile } = await loadBasisTranscoderModule(options); - return parseBasisFile(BasisFile, data, options); - } - switch (options.basis.module) { - case 'encoder': - const fileConstructors = await loadBasisEncoderModule(options); - switch (options.basis.containerFormat) { - case 'ktx2': - return parseKTX2File(fileConstructors.KTX2File, data, options); - case 'basis': - default: - return parseBasisFile(fileConstructors.BasisFile, data, options); - } - case 'transcoder': - default: - const { BasisFile } = await loadBasisTranscoderModule(options); - return parseBasisFile(BasisFile, data, options); - } -} -/** - * Parse *.basis file data - * @param BasisFile - initialized transcoder module - * @param data - * @param options - * @returns compressed texture data - */ -function parseBasisFile(BasisFile, data, options) { - const basisFile = new BasisFile(new Uint8Array(data)); - try { - if (!basisFile.startTranscoding()) { - throw new Error('Failed to start basis transcoding'); - } - const imageCount = basisFile.getNumImages(); - const images = []; - for (let imageIndex = 0; imageIndex < imageCount; imageIndex++) { - const levelsCount = basisFile.getNumLevels(imageIndex); - const levels = []; - for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) { - levels.push(transcodeImage(basisFile, imageIndex, levelIndex, options)); - } - images.push(levels); - } - return images; - } - finally { - basisFile.close(); - basisFile.delete(); - } -} -/** - * Parse the particular level image of a basis file - * @param basisFile - * @param imageIndex - * @param levelIndex - * @param options - * @returns compressed texture data - */ -function transcodeImage(basisFile, imageIndex, levelIndex, options) { - const width = basisFile.getImageWidth(imageIndex, levelIndex); - const height = basisFile.getImageHeight(imageIndex, levelIndex); - // See https://github.com/BinomialLLC/basis_universal/pull/83 - const hasAlpha = basisFile.getHasAlpha( /* imageIndex, levelIndex */); - // Check options for output format etc - const { compressed, format, basisFormat } = getBasisOptions(options, hasAlpha); - const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat); - const decodedData = new Uint8Array(decodedSize); - if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) { - throw new Error('failed to start Basis transcoding'); - } - return { - // standard loaders.gl image category payload - width, - height, - data: decodedData, - compressed, - format, - // Additional fields - // Add levelSize field. - hasAlpha - }; -} -/** - * Parse *.ktx2 file data - * @param KTX2File - * @param data - * @param options - * @returns compressed texture data - */ -function parseKTX2File(KTX2File, data, options) { - const ktx2File = new KTX2File(new Uint8Array(data)); - try { - if (!ktx2File.startTranscoding()) { - throw new Error('failed to start KTX2 transcoding'); - } - const levelsCount = ktx2File.getLevels(); - const levels = []; - for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) { - levels.push(transcodeKTX2Image(ktx2File, levelIndex, options)); - } - return [levels]; - } - finally { - ktx2File.close(); - ktx2File.delete(); - } -} -/** - * Parse the particular level image of a ktx2 file - * @param ktx2File - * @param levelIndex - * @param options - * @returns - */ -function transcodeKTX2Image(ktx2File, levelIndex, options) { - const { alphaFlag, height, width } = ktx2File.getImageLevelInfo(levelIndex, 0, 0); - // Check options for output format etc - const { compressed, format, basisFormat } = getBasisOptions(options, alphaFlag); - const decodedSize = ktx2File.getImageTranscodedSizeInBytes(levelIndex, 0 /* layerIndex */, 0 /* faceIndex */, basisFormat); - const decodedData = new Uint8Array(decodedSize); - if (!ktx2File.transcodeImage(decodedData, levelIndex, 0 /* layerIndex */, 0 /* faceIndex */, basisFormat, 0, -1 /* channel0 */, -1 /* channel1 */)) { - throw new Error('Failed to transcode KTX2 image'); - } - return { - // standard loaders.gl image category payload - width, - height, - data: decodedData, - compressed, - // Additional fields - levelSize: decodedSize, - hasAlpha: alphaFlag, - format - }; -} -/** - * Get BasisFormat by loader format option - * @param options - * @param hasAlpha - * @returns BasisFormat data - */ -function getBasisOptions(options, hasAlpha) { - let format = options && options.basis && options.basis.format; - if (format === 'auto') { - format = selectSupportedBasisFormat(); - } - if (typeof format === 'object') { - format = hasAlpha ? format.alpha : format.noAlpha; - } - format = format.toLowerCase(); - return OutputFormat[format]; -} -/** - * Select transcode format from the list of supported formats - * @returns key for OutputFormat map - */ -function selectSupportedBasisFormat() { - const supportedFormats = getSupportedGPUTextureFormats(); - if (supportedFormats.has('astc')) { - return 'astc-4x4'; - } - else if (supportedFormats.has('dxt')) { - return { - alpha: 'bc3', - noAlpha: 'bc1' - }; - } - else if (supportedFormats.has('pvrtc')) { - return { - alpha: 'pvrtc1-4-rgba', - noAlpha: 'pvrtc1-4-rgb' - }; - } - else if (supportedFormats.has('etc1')) { - return 'etc1'; - } - else if (supportedFormats.has('etc2')) { - return 'etc2'; - } - return 'rgb565'; -} - -// loaders.gl -/** - * Worker loader for Basis super compressed textures - */ -const BasisWorkerLoader = { - dataType: null, - batchType: null, - name: 'Basis', - id: 'basis', - module: 'textures', - version: VERSION$2, - worker: true, - extensions: ['basis', 'ktx2'], - mimeTypes: ['application/octet-stream', 'image/ktx2'], - tests: ['sB'], - binary: true, - options: { - basis: { - format: 'auto', - libraryPath: 'libs/', - containerFormat: 'auto', - module: 'transcoder' - } - } -}; -/** - * Loader for Basis super compressed textures - */ -const BasisLoader = { - ...BasisWorkerLoader, - parse: parseBasis -}; - -/** Binary GLTF is little endian. */ -const LITTLE_ENDIAN = true; -/** 'glTF' in Big-Endian ASCII */ -const MAGIC_glTF = 0x676c5446; -const GLB_FILE_HEADER_SIZE = 12; -const GLB_CHUNK_HEADER_SIZE = 8; -const GLB_CHUNK_TYPE_JSON = 0x4e4f534a; -const GLB_CHUNK_TYPE_BIN = 0x004e4942; -const GLB_V1_CONTENT_FORMAT_JSON = 0x0; -/** @deprecated - Backward compatibility for old xviz files */ -const GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0; -/** @deprecated - Backward compatibility for old xviz files */ -const GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1; -function getMagicString(dataView, byteOffset = 0) { - return `\ -${String.fromCharCode(dataView.getUint8(byteOffset + 0))}\ -${String.fromCharCode(dataView.getUint8(byteOffset + 1))}\ -${String.fromCharCode(dataView.getUint8(byteOffset + 2))}\ -${String.fromCharCode(dataView.getUint8(byteOffset + 3))}`; -} -/** Check if the contents of an array buffer contains GLB byte markers */ -function isGLB(arrayBuffer, byteOffset = 0, options = {}) { - const dataView = new DataView(arrayBuffer); - // Check that GLB Header starts with the magic number - const { magic = MAGIC_glTF } = options; - const magic1 = dataView.getUint32(byteOffset, false); - return magic1 === magic || magic1 === MAGIC_glTF; -} -/** - * Synchronously parse a GLB - * @param glb - Target, Output is stored there - * @param arrayBuffer - Input data - * @param byteOffset - Offset into arrayBuffer to start parsing from (for "embedded" GLBs, e.g. in 3D tiles) - * @param options - * @returns - */ -function parseGLBSync(glb, arrayBuffer, byteOffset = 0, options = {}) { - // Check that GLB Header starts with the magic number - const dataView = new DataView(arrayBuffer); - // Compare format with GLBLoader documentation - const type = getMagicString(dataView, byteOffset + 0); - const version = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); // Version 2 of binary glTF container format - const byteLength = dataView.getUint32(byteOffset + 8, LITTLE_ENDIAN); // Total byte length of binary file - Object.assign(glb, { - // Put less important stuff in a header, to avoid clutter - header: { - byteOffset, // Byte offset into the initial arrayBuffer - byteLength, - hasBinChunk: false - }, - type, - version, - json: {}, - binChunks: [] - }); - byteOffset += GLB_FILE_HEADER_SIZE; - switch (glb.version) { - case 1: - return parseGLBV1(glb, dataView, byteOffset); - case 2: - return parseGLBV2(glb, dataView, byteOffset, (options = {})); - default: - throw new Error(`Invalid GLB version ${glb.version}. Only supports version 1 and 2.`); - } -} -/** - * Parse a V1 GLB - * @param glb - target, output is stored in this object - * @param dataView - Input, memory to be parsed - * @param byteOffset - Offset of first byte of GLB data in the data view - * @returns Number of bytes parsed (there could be additional non-GLB data after the GLB) - */ -function parseGLBV1(glb, dataView, byteOffset) { - // Sanity: ensure file is big enough to hold at least the headers - assert$4(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE); - // Explanation of GLB structure: - // https://cloud.githubusercontent.com/assets/3479527/22600725/36b87122-ea55-11e6-9d40-6fd42819fcab.png - const contentLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN); // Byte length of chunk - const contentFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); // Chunk format as uint32 - byteOffset += GLB_CHUNK_HEADER_SIZE; - // GLB v1 only supports a single chunk type - assert$4(contentFormat === GLB_V1_CONTENT_FORMAT_JSON); - parseJSONChunk(glb, dataView, byteOffset, contentLength); - // No need to call the function padToBytes() from parseJSONChunk() - byteOffset += contentLength; - byteOffset += parseBINChunk(glb, dataView, byteOffset, glb.header.byteLength); - return byteOffset; -} -/** - * Parse a V2 GLB - * @param glb - target, output is stored in this object - * @param dataView - Input, memory to be parsed - * @param byteOffset - Offset of first byte of GLB data in the data view - * @returns Number of bytes parsed (there could be additional non-GLB data after the GLB) - */ -function parseGLBV2(glb, dataView, byteOffset, options) { - // Sanity: ensure file is big enough to hold at least the first chunk header - assert$4(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE); - parseGLBChunksSync(glb, dataView, byteOffset, options); - return byteOffset + glb.header.byteLength; -} -/** Iterate over GLB chunks and parse them */ -function parseGLBChunksSync(glb, dataView, byteOffset, options) { - // Per spec we must iterate over chunks, ignoring all except JSON and BIN - // Iterate as long as there is space left for another chunk header - while (byteOffset + 8 <= glb.header.byteLength) { - const chunkLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN); // Byte length of chunk - const chunkFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN); // Chunk format as uint32 - byteOffset += GLB_CHUNK_HEADER_SIZE; - // Per spec we must iterate over chunks, ignoring all except JSON and BIN - switch (chunkFormat) { - case GLB_CHUNK_TYPE_JSON: - parseJSONChunk(glb, dataView, byteOffset, chunkLength); - break; - case GLB_CHUNK_TYPE_BIN: - parseBINChunk(glb, dataView, byteOffset, chunkLength); - break; - // Backward compatibility for very old xviz files - case GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED: - if (!options.strict) { - parseJSONChunk(glb, dataView, byteOffset, chunkLength); - } - break; - case GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED: - if (!options.strict) { - parseBINChunk(glb, dataView, byteOffset, chunkLength); - } - break; - } - byteOffset += padToNBytes(chunkLength, 4); - } - return byteOffset; -} -/* Parse a GLB JSON chunk */ -function parseJSONChunk(glb, dataView, byteOffset, chunkLength) { - // 1. Create a "view" of the binary encoded JSON data inside the GLB - const jsonChunk = new Uint8Array(dataView.buffer, byteOffset, chunkLength); - // 2. Decode the JSON binary array into clear text - const textDecoder = new TextDecoder('utf8'); - const jsonText = textDecoder.decode(jsonChunk); - // 3. Parse the JSON text into a JavaScript data structure - glb.json = JSON.parse(jsonText); - return padToNBytes(chunkLength, 4); -} -/** Parse a GLB BIN chunk */ -function parseBINChunk(glb, dataView, byteOffset, chunkLength) { - // Note: BIN chunk can be optional - glb.header.hasBinChunk = true; - glb.binChunks.push({ - byteOffset, - byteLength: chunkLength, - arrayBuffer: dataView.buffer - // TODO - copy, or create typed array view? - }); - return padToNBytes(chunkLength, 4); -} - -// Resolves a relative url against a baseUrl -// If url is absolute, return it unchanged -function resolveUrl(url, options) { - // TODO: Use better logic to handle all protocols plus not delay on data - const absolute = url.startsWith('data:') || url.startsWith('http:') || url.startsWith('https:'); - if (absolute) { - return url; - } - const baseUrl = options.baseUri || options.uri; - if (!baseUrl) { - throw new Error(`'baseUri' must be provided to resolve relative url ${url}`); - } - return baseUrl.substr(0, baseUrl.lastIndexOf('/') + 1) + url; -} - -// This file is part of meshoptimizer library and is distributed under the terms of MIT License. -// Built with clang version 11.0.0 (https://github.com/llvm/llvm-project.git 0160ad802e899c2922bc9b29564080c22eb0908c) -// Built from meshoptimizer 0.16 -const wasm_base = 'B9h9z9tFBBBF8fL9gBB9gLaaaaaFa9gEaaaB9gFaFa9gEaaaFaEMcBFFFGGGEIIILF9wFFFLEFBFKNFaFCx/IFMO/LFVK9tv9t9vq95GBt9f9f939h9z9t9f9j9h9s9s9f9jW9vq9zBBp9tv9z9o9v9wW9f9kv9j9v9kv9WvqWv94h919m9mvqBF8Z9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv94h919m9mvqBGy9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv949TvZ91v9u9jvBEn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9P9jWBIi9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9R919hWBLn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9F949wBKI9z9iqlBOc+x8ycGBM/qQFTa8jUUUUBCU/EBlHL8kUUUUBC9+RKGXAGCFJAI9LQBCaRKAE2BBC+gF9HQBALAEAIJHOAGlAGTkUUUBRNCUoBAG9uC/wgBZHKCUGAKCUG9JyRVAECFJRICBRcGXEXAcAF9PQFAVAFAclAcAVJAF9JyRMGXGXAG9FQBAMCbJHKC9wZRSAKCIrCEJCGrRQANCUGJRfCBRbAIRTEXGXAOATlAQ9PQBCBRISEMATAQJRIGXAS9FQBCBRtCBREEXGXAOAIlCi9PQBCBRISLMANCU/CBJAEJRKGXGXGXGXGXATAECKrJ2BBAtCKZrCEZfIBFGEBMAKhB83EBAKCNJhB83EBSEMAKAI2BIAI2BBHmCKrHYAYCE6HYy86BBAKCFJAICIJAYJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCGJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCEJAYAPJHY2BBAmCEZHmAmCE6Hmy86BBAKCIJAYAmJHY2BBAI2BFHmCKrHPAPCE6HPy86BBAKCLJAYAPJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCKJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCOJAYAPJHY2BBAmCEZHmAmCE6Hmy86BBAKCNJAYAmJHY2BBAI2BGHmCKrHPAPCE6HPy86BBAKCVJAYAPJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCcJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCMJAYAPJHY2BBAmCEZHmAmCE6Hmy86BBAKCSJAYAmJHm2BBAI2BEHICKrHYAYCE6HYy86BBAKCQJAmAYJHm2BBAICIrCEZHYAYCE6HYy86BBAKCfJAmAYJHm2BBAICGrCEZHYAYCE6HYy86BBAKCbJAmAYJHK2BBAICEZHIAICE6HIy86BBAKAIJRISGMAKAI2BNAI2BBHmCIrHYAYCb6HYy86BBAKCFJAICNJAYJHY2BBAmCbZHmAmCb6Hmy86BBAKCGJAYAmJHm2BBAI2BFHYCIrHPAPCb6HPy86BBAKCEJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCIJAmAYJHm2BBAI2BGHYCIrHPAPCb6HPy86BBAKCLJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCKJAmAYJHm2BBAI2BEHYCIrHPAPCb6HPy86BBAKCOJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCNJAmAYJHm2BBAI2BIHYCIrHPAPCb6HPy86BBAKCVJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCcJAmAYJHm2BBAI2BLHYCIrHPAPCb6HPy86BBAKCMJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCSJAmAYJHm2BBAI2BKHYCIrHPAPCb6HPy86BBAKCQJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCfJAmAYJHm2BBAI2BOHICIrHYAYCb6HYy86BBAKCbJAmAYJHK2BBAICbZHIAICb6HIy86BBAKAIJRISFMAKAI8pBB83BBAKCNJAICNJ8pBB83BBAICTJRIMAtCGJRtAECTJHEAS9JQBMMGXAIQBCBRISEMGXAM9FQBANAbJ2BBRtCBRKAfREEXAEANCU/CBJAKJ2BBHTCFrCBATCFZl9zAtJHt86BBAEAGJREAKCFJHKAM9HQBMMAfCFJRfAIRTAbCFJHbAG9HQBMMABAcAG9sJANCUGJAMAG9sTkUUUBpANANCUGJAMCaJAG9sJAGTkUUUBpMAMCBAIyAcJRcAIQBMC9+RKSFMCBC99AOAIlAGCAAGCA9Ly6yRKMALCU/EBJ8kUUUUBAKM+OmFTa8jUUUUBCoFlHL8kUUUUBC9+RKGXAFCE9uHOCtJAI9LQBCaRKAE2BBHNC/wFZC/gF9HQBANCbZHVCF9LQBALCoBJCgFCUFT+JUUUBpALC84Jha83EBALC8wJha83EBALC8oJha83EBALCAJha83EBALCiJha83EBALCTJha83EBALha83ENALha83EBAEAIJC9wJRcAECFJHNAOJRMGXAF9FQBCQCbAVCF6yRSABRECBRVCBRQCBRfCBRICBRKEXGXAMAcuQBC9+RKSEMGXGXAN2BBHOC/vF9LQBALCoBJAOCIrCa9zAKJCbZCEWJHb8oGIRTAb8oGBRtGXAOCbZHbAS9PQBALAOCa9zAIJCbZCGWJ8oGBAVAbyROAb9FRbGXGXAGCG9HQBABAt87FBABCIJAO87FBABCGJAT87FBSFMAEAtjGBAECNJAOjGBAECIJATjGBMAVAbJRVALCoBJAKCEWJHmAOjGBAmATjGIALAICGWJAOjGBALCoBJAKCFJCbZHKCEWJHTAtjGBATAOjGIAIAbJRIAKCFJRKSGMGXGXAbCb6QBAQAbJAbC989zJCFJRQSFMAM1BBHbCgFZROGXGXAbCa9MQBAMCFJRMSFMAM1BFHbCgBZCOWAOCgBZqROGXAbCa9MQBAMCGJRMSFMAM1BGHbCgBZCfWAOqROGXAbCa9MQBAMCEJRMSFMAM1BEHbCgBZCdWAOqROGXAbCa9MQBAMCIJRMSFMAM2BIC8cWAOqROAMCLJRMMAOCFrCBAOCFZl9zAQJRQMGXGXAGCG9HQBABAt87FBABCIJAQ87FBABCGJAT87FBSFMAEAtjGBAECNJAQjGBAECIJATjGBMALCoBJAKCEWJHOAQjGBAOATjGIALAICGWJAQjGBALCoBJAKCFJCbZHKCEWJHOAtjGBAOAQjGIAICFJRIAKCFJRKSFMGXAOCDF9LQBALAIAcAOCbZJ2BBHbCIrHTlCbZCGWJ8oGBAVCFJHtATyROALAIAblCbZCGWJ8oGBAtAT9FHmJHtAbCbZHTyRbAT9FRTGXGXAGCG9HQBABAV87FBABCIJAb87FBABCGJAO87FBSFMAEAVjGBAECNJAbjGBAECIJAOjGBMALAICGWJAVjGBALCoBJAKCEWJHYAOjGBAYAVjGIALAICFJHICbZCGWJAOjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAIAmJCbZHICGWJAbjGBALCoBJAKCGJCbZHKCEWJHOAVjGBAOAbjGIAKCFJRKAIATJRIAtATJRVSFMAVCBAM2BBHYyHTAOC/+F6HPJROAYCbZRtGXGXAYCIrHmQBAOCFJRbSFMAORbALAIAmlCbZCGWJ8oGBROMGXGXAtQBAbCFJRVSFMAbRVALAIAYlCbZCGWJ8oGBRbMGXGXAP9FQBAMCFJRYSFMAM1BFHYCgFZRTGXGXAYCa9MQBAMCGJRYSFMAM1BGHYCgBZCOWATCgBZqRTGXAYCa9MQBAMCEJRYSFMAM1BEHYCgBZCfWATqRTGXAYCa9MQBAMCIJRYSFMAM1BIHYCgBZCdWATqRTGXAYCa9MQBAMCLJRYSFMAMCKJRYAM2BLC8cWATqRTMATCFrCBATCFZl9zAQJHQRTMGXGXAmCb6QBAYRPSFMAY1BBHMCgFZROGXGXAMCa9MQBAYCFJRPSFMAY1BFHMCgBZCOWAOCgBZqROGXAMCa9MQBAYCGJRPSFMAY1BGHMCgBZCfWAOqROGXAMCa9MQBAYCEJRPSFMAY1BEHMCgBZCdWAOqROGXAMCa9MQBAYCIJRPSFMAYCLJRPAY2BIC8cWAOqROMAOCFrCBAOCFZl9zAQJHQROMGXGXAtCb6QBAPRMSFMAP1BBHMCgFZRbGXGXAMCa9MQBAPCFJRMSFMAP1BFHMCgBZCOWAbCgBZqRbGXAMCa9MQBAPCGJRMSFMAP1BGHMCgBZCfWAbqRbGXAMCa9MQBAPCEJRMSFMAP1BEHMCgBZCdWAbqRbGXAMCa9MQBAPCIJRMSFMAPCLJRMAP2BIC8cWAbqRbMAbCFrCBAbCFZl9zAQJHQRbMGXGXAGCG9HQBABAT87FBABCIJAb87FBABCGJAO87FBSFMAEATjGBAECNJAbjGBAECIJAOjGBMALCoBJAKCEWJHYAOjGBAYATjGIALAICGWJATjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAICFJHICbZCGWJAOjGBALCoBJAKCGJCbZCEWJHOATjGBAOAbjGIALAIAm9FAmCb6qJHICbZCGWJAbjGBAIAt9FAtCb6qJRIAKCEJRKMANCFJRNABCKJRBAECSJREAKCbZRKAICbZRIAfCEJHfAF9JQBMMCBC99AMAc6yRKMALCoFJ8kUUUUBAKM/tIFGa8jUUUUBCTlRLC9+RKGXAFCLJAI9LQBCaRKAE2BBC/+FZC/QF9HQBALhB83ENAECFJRKAEAIJC98JREGXAF9FQBGXAGCG6QBEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMALCNJAICFZCGWqHGAICGrCBAICFrCFZl9zAG8oGBJHIjGBABAIjGBABCIJRBAFCaJHFQBSGMMEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMABAICGrCBAICFrCFZl9zALCNJAICFZCGWqHI8oGBJHG87FBAIAGjGBABCGJRBAFCaJHFQBMMCBC99AKAE6yRKMAKM+lLKFaF99GaG99FaG99GXGXAGCI9HQBAF9FQFEXGXGX9DBBB8/9DBBB+/ABCGJHG1BB+yAB1BBHE+yHI+L+TABCFJHL1BBHK+yHO+L+THN9DBBBB9gHVyAN9DBB/+hANAN+U9DBBBBANAVyHcAc+MHMAECa3yAI+SHIAI+UAcAMAKCa3yAO+SHcAc+U+S+S+R+VHO+U+SHN+L9DBBB9P9d9FQBAN+oRESFMCUUUU94REMAGAE86BBGXGX9DBBB8/9DBBB+/Ac9DBBBB9gyAcAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMALAG86BBGXGX9DBBB8/9DBBB+/AI9DBBBB9gyAIAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMABAG86BBABCIJRBAFCaJHFQBSGMMAF9FQBEXGXGX9DBBB8/9DBBB+/ABCIJHG8uFB+yAB8uFBHE+yHI+L+TABCGJHL8uFBHK+yHO+L+THN9DBBBB9gHVyAN9DB/+g6ANAN+U9DBBBBANAVyHcAc+MHMAECa3yAI+SHIAI+UAcAMAKCa3yAO+SHcAc+U+S+S+R+VHO+U+SHN+L9DBBB9P9d9FQBAN+oRESFMCUUUU94REMAGAE87FBGXGX9DBBB8/9DBBB+/Ac9DBBBB9gyAcAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMALAG87FBGXGX9DBBB8/9DBBB+/AI9DBBBB9gyAIAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMABAG87FBABCNJRBAFCaJHFQBMMM/SEIEaE99EaF99GXAF9FQBCBREABRIEXGXGX9D/zI818/AICKJ8uFBHLCEq+y+VHKAI8uFB+y+UHO9DB/+g6+U9DBBB8/9DBBB+/AO9DBBBB9gy+SHN+L9DBBB9P9d9FQBAN+oRVSFMCUUUU94RVMAICIJ8uFBRcAICGJ8uFBRMABALCFJCEZAEqCFWJAV87FBGXGXAKAM+y+UHN9DB/+g6+U9DBBB8/9DBBB+/AN9DBBBB9gy+SHS+L9DBBB9P9d9FQBAS+oRMSFMCUUUU94RMMABALCGJCEZAEqCFWJAM87FBGXGXAKAc+y+UHK9DB/+g6+U9DBBB8/9DBBB+/AK9DBBBB9gy+SHS+L9DBBB9P9d9FQBAS+oRcSFMCUUUU94RcMABALCaJCEZAEqCFWJAc87FBGXGX9DBBU8/AOAO+U+TANAN+U+TAKAK+U+THO9DBBBBAO9DBBBB9gy+R9DB/+g6+U9DBBB8/+SHO+L9DBBB9P9d9FQBAO+oRcSFMCUUUU94RcMABALCEZAEqCFWJAc87FBAICNJRIAECIJREAFCaJHFQBMMM9JBGXAGCGrAF9sHF9FQBEXABAB8oGBHGCNWCN91+yAGCi91CnWCUUU/8EJ+++U84GBABCIJRBAFCaJHFQBMMM9TFEaCBCB8oGUkUUBHFABCEJC98ZJHBjGUkUUBGXGXAB8/BCTWHGuQBCaREABAGlCggEJCTrXBCa6QFMAFREMAEM/lFFFaGXGXAFABqCEZ9FQBABRESFMGXGXAGCT9PQBABRESFMABREEXAEAF8oGBjGBAECIJAFCIJ8oGBjGBAECNJAFCNJ8oGBjGBAECSJAFCSJ8oGBjGBAECTJREAFCTJRFAGC9wJHGCb9LQBMMAGCI9JQBEXAEAF8oGBjGBAFCIJRFAECIJREAGC98JHGCE9LQBMMGXAG9FQBEXAEAF2BB86BBAECFJREAFCFJRFAGCaJHGQBMMABMoFFGaGXGXABCEZ9FQBABRESFMAFCgFZC+BwsN9sRIGXGXAGCT9PQBABRESFMABREEXAEAIjGBAECSJAIjGBAECNJAIjGBAECIJAIjGBAECTJREAGC9wJHGCb9LQBMMAGCI9JQBEXAEAIjGBAECIJREAGC98JHGCE9LQBMMGXAG9FQBEXAEAF86BBAECFJREAGCaJHGQBMMABMMMFBCUNMIT9kBB'; -const wasm_simd = 'B9h9z9tFBBBF8dL9gBB9gLaaaaaFa9gEaaaB9gGaaB9gFaFaEQSBBFBFFGEGEGIILF9wFFFLEFBFKNFaFCx/aFMO/LFVK9tv9t9vq95GBt9f9f939h9z9t9f9j9h9s9s9f9jW9vq9zBBp9tv9z9o9v9wW9f9kv9j9v9kv9WvqWv94h919m9mvqBG8Z9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv94h919m9mvqBIy9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv949TvZ91v9u9jvBLn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9P9jWBKi9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9R919hWBNn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9F949wBcI9z9iqlBMc/j9JSIBTEM9+FLa8jUUUUBCTlRBCBRFEXCBRGCBREEXABCNJAGJAECUaAFAGrCFZHIy86BBAEAIJREAGCFJHGCN9HQBMAFCx+YUUBJAE86BBAFCEWCxkUUBJAB8pEN83EBAFCFJHFCUG9HQBMMkRIbaG97FaK978jUUUUBCU/KBlHL8kUUUUBC9+RKGXAGCFJAI9LQBCaRKAE2BBC+gF9HQBALAEAIJHOAGlAG/8cBBCUoBAG9uC/wgBZHKCUGAKCUG9JyRNAECFJRKCBRVGXEXAVAF9PQFANAFAVlAVANJAF9JyRcGXGXAG9FQBAcCbJHIC9wZHMCE9sRSAMCFWRQAICIrCEJCGrRfCBRbEXAKRTCBRtGXEXGXAOATlAf9PQBCBRKSLMALCU/CBJAtAM9sJRmATAfJRKCBREGXAMCoB9JQBAOAKlC/gB9JQBCBRIEXAmAIJREGXGXGXGXGXATAICKrJ2BBHYCEZfIBFGEBMAECBDtDMIBSEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAEAKDBBBDMIBAKCTJRKMGXGXGXGXGXAYCGrCEZfIBFGEBMAECBDtDMITSEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMITAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMITAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAEAKDBBBDMITAKCTJRKMGXGXGXGXGXAYCIrCEZfIBFGEBMAECBDtDMIASEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIAAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIAAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAEAKDBBBDMIAAKCTJRKMGXGXGXGXGXAYCKrfIBFGEBMAECBDtDMI8wSEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBAYCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMI8wAKCIJAnDeBJAYCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBAYCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMI8wAKCNJAnDeBJAYCx+YUUBJ2BBJRKSFMAEAKDBBBDMI8wAKCTJRKMAICoBJREAICUFJAM9LQFAERIAOAKlC/fB9LQBMMGXAEAM9PQBAECErRIEXGXAOAKlCi9PQBCBRKSOMAmAEJRYGXGXGXGXGXATAECKrJ2BBAICKZrCEZfIBFGEBMAYCBDtDMIBSEMAYAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAYAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAYAKDBBBDMIBAKCTJRKMAICGJRIAECTJHEAM9JQBMMGXAK9FQBAKRTAtCFJHtCI6QGSFMMCBRKSEMGXAM9FQBALCUGJAbJREALAbJDBGBRnCBRYEXAEALCU/CBJAYJHIDBIBHdCFD9tAdCFDbHPD9OD9hD9RHdAIAMJDBIBHiCFD9tAiAPD9OD9hD9RHiDQBTFtGmEYIPLdKeOnH8ZAIAQJDBIBHpCFD9tApAPD9OD9hD9RHpAIASJDBIBHyCFD9tAyAPD9OD9hD9RHyDQBTFtGmEYIPLdKeOnH8cDQBFTtGEmYILPdKOenHPAPDQBFGEBFGEBFGEBFGEAnD9uHnDyBjGBAEAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJHIAnA8ZA8cDQNVi8ZcMpySQ8c8dfb8e8fHPAPDQBFGEBFGEBFGEBFGED9uHnDyBjGBAIAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJHIAnAdAiDQNiV8ZcpMyS8cQ8df8eb8fHdApAyDQNiV8ZcpMyS8cQ8df8eb8fHiDQBFTtGEmYILPdKOenHPAPDQBFGEBFGEBFGEBFGED9uHnDyBjGBAIAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJHIAnAdAiDQNVi8ZcMpySQ8c8dfb8e8fHPAPDQBFGEBFGEBFGEBFGED9uHnDyBjGBAIAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJREAYCTJHYAM9JQBMMAbCIJHbAG9JQBMMABAVAG9sJALCUGJAcAG9s/8cBBALALCUGJAcCaJAG9sJAG/8cBBMAcCBAKyAVJRVAKQBMC9+RKSFMCBC99AOAKlAGCAAGCA9Ly6yRKMALCU/KBJ8kUUUUBAKMNBT+BUUUBM+KmFTa8jUUUUBCoFlHL8kUUUUBC9+RKGXAFCE9uHOCtJAI9LQBCaRKAE2BBHNC/wFZC/gF9HQBANCbZHVCF9LQBALCoBJCgFCUF/8MBALC84Jha83EBALC8wJha83EBALC8oJha83EBALCAJha83EBALCiJha83EBALCTJha83EBALha83ENALha83EBAEAIJC9wJRcAECFJHNAOJRMGXAF9FQBCQCbAVCF6yRSABRECBRVCBRQCBRfCBRICBRKEXGXAMAcuQBC9+RKSEMGXGXAN2BBHOC/vF9LQBALCoBJAOCIrCa9zAKJCbZCEWJHb8oGIRTAb8oGBRtGXAOCbZHbAS9PQBALAOCa9zAIJCbZCGWJ8oGBAVAbyROAb9FRbGXGXAGCG9HQBABAt87FBABCIJAO87FBABCGJAT87FBSFMAEAtjGBAECNJAOjGBAECIJATjGBMAVAbJRVALCoBJAKCEWJHmAOjGBAmATjGIALAICGWJAOjGBALCoBJAKCFJCbZHKCEWJHTAtjGBATAOjGIAIAbJRIAKCFJRKSGMGXGXAbCb6QBAQAbJAbC989zJCFJRQSFMAM1BBHbCgFZROGXGXAbCa9MQBAMCFJRMSFMAM1BFHbCgBZCOWAOCgBZqROGXAbCa9MQBAMCGJRMSFMAM1BGHbCgBZCfWAOqROGXAbCa9MQBAMCEJRMSFMAM1BEHbCgBZCdWAOqROGXAbCa9MQBAMCIJRMSFMAM2BIC8cWAOqROAMCLJRMMAOCFrCBAOCFZl9zAQJRQMGXGXAGCG9HQBABAt87FBABCIJAQ87FBABCGJAT87FBSFMAEAtjGBAECNJAQjGBAECIJATjGBMALCoBJAKCEWJHOAQjGBAOATjGIALAICGWJAQjGBALCoBJAKCFJCbZHKCEWJHOAtjGBAOAQjGIAICFJRIAKCFJRKSFMGXAOCDF9LQBALAIAcAOCbZJ2BBHbCIrHTlCbZCGWJ8oGBAVCFJHtATyROALAIAblCbZCGWJ8oGBAtAT9FHmJHtAbCbZHTyRbAT9FRTGXGXAGCG9HQBABAV87FBABCIJAb87FBABCGJAO87FBSFMAEAVjGBAECNJAbjGBAECIJAOjGBMALAICGWJAVjGBALCoBJAKCEWJHYAOjGBAYAVjGIALAICFJHICbZCGWJAOjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAIAmJCbZHICGWJAbjGBALCoBJAKCGJCbZHKCEWJHOAVjGBAOAbjGIAKCFJRKAIATJRIAtATJRVSFMAVCBAM2BBHYyHTAOC/+F6HPJROAYCbZRtGXGXAYCIrHmQBAOCFJRbSFMAORbALAIAmlCbZCGWJ8oGBROMGXGXAtQBAbCFJRVSFMAbRVALAIAYlCbZCGWJ8oGBRbMGXGXAP9FQBAMCFJRYSFMAM1BFHYCgFZRTGXGXAYCa9MQBAMCGJRYSFMAM1BGHYCgBZCOWATCgBZqRTGXAYCa9MQBAMCEJRYSFMAM1BEHYCgBZCfWATqRTGXAYCa9MQBAMCIJRYSFMAM1BIHYCgBZCdWATqRTGXAYCa9MQBAMCLJRYSFMAMCKJRYAM2BLC8cWATqRTMATCFrCBATCFZl9zAQJHQRTMGXGXAmCb6QBAYRPSFMAY1BBHMCgFZROGXGXAMCa9MQBAYCFJRPSFMAY1BFHMCgBZCOWAOCgBZqROGXAMCa9MQBAYCGJRPSFMAY1BGHMCgBZCfWAOqROGXAMCa9MQBAYCEJRPSFMAY1BEHMCgBZCdWAOqROGXAMCa9MQBAYCIJRPSFMAYCLJRPAY2BIC8cWAOqROMAOCFrCBAOCFZl9zAQJHQROMGXGXAtCb6QBAPRMSFMAP1BBHMCgFZRbGXGXAMCa9MQBAPCFJRMSFMAP1BFHMCgBZCOWAbCgBZqRbGXAMCa9MQBAPCGJRMSFMAP1BGHMCgBZCfWAbqRbGXAMCa9MQBAPCEJRMSFMAP1BEHMCgBZCdWAbqRbGXAMCa9MQBAPCIJRMSFMAPCLJRMAP2BIC8cWAbqRbMAbCFrCBAbCFZl9zAQJHQRbMGXGXAGCG9HQBABAT87FBABCIJAb87FBABCGJAO87FBSFMAEATjGBAECNJAbjGBAECIJAOjGBMALCoBJAKCEWJHYAOjGBAYATjGIALAICGWJATjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAICFJHICbZCGWJAOjGBALCoBJAKCGJCbZCEWJHOATjGBAOAbjGIALAIAm9FAmCb6qJHICbZCGWJAbjGBAIAt9FAtCb6qJRIAKCEJRKMANCFJRNABCKJRBAECSJREAKCbZRKAICbZRIAfCEJHfAF9JQBMMCBC99AMAc6yRKMALCoFJ8kUUUUBAKM/tIFGa8jUUUUBCTlRLC9+RKGXAFCLJAI9LQBCaRKAE2BBC/+FZC/QF9HQBALhB83ENAECFJRKAEAIJC98JREGXAF9FQBGXAGCG6QBEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMALCNJAICFZCGWqHGAICGrCBAICFrCFZl9zAG8oGBJHIjGBABAIjGBABCIJRBAFCaJHFQBSGMMEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMABAICGrCBAICFrCFZl9zALCNJAICFZCGWqHI8oGBJHG87FBAIAGjGBABCGJRBAFCaJHFQBMMCBC99AKAE6yRKMAKM/xLGEaK978jUUUUBCAlHE8kUUUUBGXGXAGCI9HQBGXAFC98ZHI9FQBABRGCBRLEXAGAGDBBBHKCiD+rFCiD+sFD/6FHOAKCND+rFCiD+sFD/6FAOD/gFAKCTD+rFCiD+sFD/6FHND/gFD/kFD/lFHVCBDtD+2FHcAOCUUUU94DtHMD9OD9RD/kFHO9DBB/+hDYAOAOD/mFAVAVD/mFANAcANAMD9OD9RD/kFHOAOD/mFD/kFD/kFD/jFD/nFHND/mF9DBBX9LDYHcD/kFCgFDtD9OAKCUUU94DtD9OD9QAOAND/mFAcD/kFCND+rFCU/+EDtD9OD9QAVAND/mFAcD/kFCTD+rFCUU/8ODtD9OD9QDMBBAGCTJRGALCIJHLAI9JQBMMAIAF9PQFAEAFCEZHLCGWHGqCBCTAGl/8MBAEABAICGWJHIAG/8cBBGXAL9FQBAEAEDBIBHKCiD+rFCiD+sFD/6FHOAKCND+rFCiD+sFD/6FAOD/gFAKCTD+rFCiD+sFD/6FHND/gFD/kFD/lFHVCBDtD+2FHcAOCUUUU94DtHMD9OD9RD/kFHO9DBB/+hDYAOAOD/mFAVAVD/mFANAcANAMD9OD9RD/kFHOAOD/mFD/kFD/kFD/jFD/nFHND/mF9DBBX9LDYHcD/kFCgFDtD9OAKCUUU94DtD9OD9QAOAND/mFAcD/kFCND+rFCU/+EDtD9OD9QAVAND/mFAcD/kFCTD+rFCUU/8ODtD9OD9QDMIBMAIAEAG/8cBBSFMABAFC98ZHGT+HUUUBAGAF9PQBAEAFCEZHICEWHLJCBCAALl/8MBAEABAGCEWJHGAL/8cBBAEAIT+HUUUBAGAEAL/8cBBMAECAJ8kUUUUBM+yEGGaO97GXAF9FQBCBRGEXABCTJHEAEDBBBHICBDtHLCUU98D8cFCUU98D8cEHKD9OABDBBBHOAIDQILKOSQfbPden8c8d8e8fCggFDtD9OD/6FAOAIDQBFGENVcMTtmYi8ZpyHICTD+sFD/6FHND/gFAICTD+rFCTD+sFD/6FHVD/gFD/kFD/lFHI9DB/+g6DYAVAIALD+2FHLAVCUUUU94DtHcD9OD9RD/kFHVAVD/mFAIAID/mFANALANAcD9OD9RD/kFHIAID/mFD/kFD/kFD/jFD/nFHND/mF9DBBX9LDYHLD/kFCTD+rFAVAND/mFALD/kFCggEDtD9OD9QHVAIAND/mFALD/kFCaDbCBDnGCBDnECBDnKCBDnOCBDncCBDnMCBDnfCBDnbD9OHIDQNVi8ZcMpySQ8c8dfb8e8fD9QDMBBABAOAKD9OAVAIDQBFTtGEmYILPdKOenD9QDMBBABCAJRBAGCIJHGAF9JQBMMM94FEa8jUUUUBCAlHE8kUUUUBABAFC98ZHIT+JUUUBGXAIAF9PQBAEAFCEZHLCEWHFJCBCAAFl/8MBAEABAICEWJHBAF/8cBBAEALT+JUUUBABAEAF/8cBBMAECAJ8kUUUUBM/hEIGaF97FaL978jUUUUBCTlRGGXAF9FQBCBREEXAGABDBBBHIABCTJHLDBBBHKDQILKOSQfbPden8c8d8e8fHOCTD+sFHNCID+rFDMIBAB9DBBU8/DY9D/zI818/DYANCEDtD9QD/6FD/nFHNAIAKDQBFGENVcMTtmYi8ZpyHICTD+rFCTD+sFD/6FD/mFHKAKD/mFANAICTD+sFD/6FD/mFHVAVD/mFANAOCTD+rFCTD+sFD/6FD/mFHOAOD/mFD/kFD/kFD/lFCBDtD+4FD/jF9DB/+g6DYHND/mF9DBBX9LDYHID/kFCggEDtHcD9OAVAND/mFAID/kFCTD+rFD9QHVAOAND/mFAID/kFCTD+rFAKAND/mFAID/kFAcD9OD9QHNDQBFTtGEmYILPdKOenHID8dBAGDBIBDyB+t+J83EBABCNJAID8dFAGDBIBDyF+t+J83EBALAVANDQNVi8ZcMpySQ8c8dfb8e8fHND8dBAGDBIBDyG+t+J83EBABCiJAND8dFAGDBIBDyE+t+J83EBABCAJRBAECIJHEAF9JQBMMM/3FGEaF978jUUUUBCoBlREGXAGCGrAF9sHIC98ZHL9FQBCBRGABRFEXAFAFDBBBHKCND+rFCND+sFD/6FAKCiD+sFCnD+rFCUUU/8EDtD+uFD/mFDMBBAFCTJRFAGCIJHGAL9JQBMMGXALAI9PQBAEAICEZHGCGWHFqCBCoBAFl/8MBAEABALCGWJHLAF/8cBBGXAG9FQBAEAEDBIBHKCND+rFCND+sFD/6FAKCiD+sFCnD+rFCUUU/8EDtD+uFD/mFDMIBMALAEAF/8cBBMM9TFEaCBCB8oGUkUUBHFABCEJC98ZJHBjGUkUUBGXGXAB8/BCTWHGuQBCaREABAGlCggEJCTrXBCa6QFMAFREMAEMMMFBCUNMIT9tBB'; -// Uses bulk-memory and simd extensions -const detector = new Uint8Array([ - 0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 3, 2, 0, 0, 5, 3, 1, 0, 1, 12, 1, 0, 10, 22, 2, - 12, 0, 65, 0, 65, 0, 65, 0, 252, 10, 0, 0, 11, 7, 0, 65, 0, 253, 15, 26, 11 -]); -// Used to unpack wasm -const wasmpack = new Uint8Array([ - 32, 0, 65, 253, 3, 1, 2, 34, 4, 106, 6, 5, 11, 8, 7, 20, 13, 33, 12, 16, 128, 9, 116, 64, 19, 113, - 127, 15, 10, 21, 22, 14, 255, 66, 24, 54, 136, 107, 18, 23, 192, 26, 114, 118, 132, 17, 77, 101, - 130, 144, 27, 87, 131, 44, 45, 74, 156, 154, 70, 167 -]); -const FILTERS = { - // legacy index-based enums for glTF - 0: '', - 1: 'meshopt_decodeFilterOct', - 2: 'meshopt_decodeFilterQuat', - 3: 'meshopt_decodeFilterExp', - // string-based enums for glTF - NONE: '', - OCTAHEDRAL: 'meshopt_decodeFilterOct', - QUATERNION: 'meshopt_decodeFilterQuat', - EXPONENTIAL: 'meshopt_decodeFilterExp' -}; -const DECODERS = { - // legacy index-based enums for glTF - 0: 'meshopt_decodeVertexBuffer', - 1: 'meshopt_decodeIndexBuffer', - 2: 'meshopt_decodeIndexSequence', - // string-based enums for glTF - ATTRIBUTES: 'meshopt_decodeVertexBuffer', - TRIANGLES: 'meshopt_decodeIndexBuffer', - INDICES: 'meshopt_decodeIndexSequence' -}; -// eslint-disable-next-line max-params -async function meshoptDecodeGltfBuffer(target, count, size, source, mode, filter = 'NONE') { - const instance = await loadWasmInstance(); - decode$8(instance, instance.exports[DECODERS[mode]], target, count, size, source, instance.exports[FILTERS[filter || 'NONE']]); -} -let wasmPromise; -async function loadWasmInstance() { - // eslint-disable-next-line - if (!wasmPromise) { - wasmPromise = loadWasmModule(); - } - return wasmPromise; -} -async function loadWasmModule() { - let wasm = wasm_base; - if (WebAssembly.validate(detector)) { - wasm = wasm_simd; - // eslint-disable-next-line no-console - console.log('Warning: meshopt_decoder is using experimental SIMD support'); - } - const result = await WebAssembly.instantiate(unpack(wasm), {}); - await result.instance.exports.__wasm_call_ctors(); - return result.instance; -} -function unpack(data) { - const result = new Uint8Array(data.length); - for (let i = 0; i < data.length; ++i) { - const ch = data.charCodeAt(i); - result[i] = ch > 96 ? ch - 71 : ch > 64 ? ch - 65 : ch > 47 ? ch + 4 : ch > 46 ? 63 : 62; - } - let write = 0; - for (let i = 0; i < data.length; ++i) { - result[write++] = result[i] < 60 ? wasmpack[result[i]] : (result[i] - 60) * 64 + result[++i]; - } - return result.buffer.slice(0, write); -} -// eslint-disable-next-line max-params -function decode$8(instance, fun, target, count, size, source, filter) { - const sbrk = instance.exports.sbrk; - const count4 = (count + 3) & ~3; // pad for SIMD filter - const tp = sbrk(count4 * size); - const sp = sbrk(source.length); - const heap = new Uint8Array(instance.exports.memory.buffer); - heap.set(source, sp); - const res = fun(tp, count, size, sp, source.length); - if (res === 0 && filter) { - filter(tp, count4, size); - } - target.set(heap.subarray(tp, tp + count * size)); - sbrk(tp - sbrk(0)); - if (res !== 0) { - throw new Error(`Malformed buffer data: ${res}`); - } -} - -/** Extension name */ -const EXT_MESHOPT_COMPRESSION = 'EXT_meshopt_compression'; -const name$7 = EXT_MESHOPT_COMPRESSION; -async function decode$7(gltfData, options) { - const scenegraph = new GLTFScenegraph(gltfData); - if (!options?.gltf?.decompressMeshes || !options.gltf?.loadBuffers) { - return; - } - const promises = []; - for (const bufferViewIndex of gltfData.json.bufferViews || []) { - promises.push(decodeMeshoptBufferView(scenegraph, bufferViewIndex)); - } - // Decompress meshes in parallel - await Promise.all(promises); - // We have now decompressed all primitives, so remove the top-level extension - scenegraph.removeExtension(EXT_MESHOPT_COMPRESSION); -} -/** Decode one meshopt buffer view */ -async function decodeMeshoptBufferView(scenegraph, bufferView) { - const meshoptExtension = scenegraph.getObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION); - if (meshoptExtension) { - const { byteOffset = 0, byteLength = 0, byteStride, count, mode, filter = 'NONE', buffer: bufferIndex } = meshoptExtension; - const buffer = scenegraph.gltf.buffers[bufferIndex]; - const source = new Uint8Array(buffer.arrayBuffer, buffer.byteOffset + byteOffset, byteLength); - const result = new Uint8Array(scenegraph.gltf.buffers[bufferView.buffer].arrayBuffer, bufferView.byteOffset, bufferView.byteLength); - await meshoptDecodeGltfBuffer(result, count, byteStride, source, mode, filter); - scenegraph.removeObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION); - } -} - -var EXT_meshopt_compression = /*#__PURE__*/Object.freeze({ - __proto__: null, - name: name$7, - decode: decode$7 -}); - -// GLTF EXTENSION: EXT_TEXTURE_WEBP -const EXT_TEXTURE_WEBP = 'EXT_texture_webp'; -/** Extension name */ -const name$6 = EXT_TEXTURE_WEBP; -/** - * Replaces a texture source reference with the extension texture - * Done in preprocess() to prevent load of default image - */ -function preprocess$3(gltfData, options) { - const scenegraph = new GLTFScenegraph(gltfData); - if (!isImageFormatSupported('image/webp')) { - if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) { - throw new Error(`gltf: Required extension ${EXT_TEXTURE_WEBP} not supported by browser`); - } - return; - } - const { json } = scenegraph; - for (const texture of json.textures || []) { - const extension = scenegraph.getObjectExtension(texture, EXT_TEXTURE_WEBP); - if (extension) { - // TODO - if multiple texture extensions are present which one wins? - texture.source = extension.source; - } - scenegraph.removeObjectExtension(texture, EXT_TEXTURE_WEBP); - } - // Remove the top-level extension - scenegraph.removeExtension(EXT_TEXTURE_WEBP); -} - -var EXT_texture_webp = /*#__PURE__*/Object.freeze({ - __proto__: null, - name: name$6, - preprocess: preprocess$3 -}); - -// GLTF EXTENSION: KHR_texture_basisu -const KHR_TEXTURE_BASISU = 'KHR_texture_basisu'; -/** Extension name */ -const name$5 = KHR_TEXTURE_BASISU; -/** - * Replaces a texture source reference with the extension texture - * Done in preprocess() to prevent load of default image - */ -function preprocess$2(gltfData, options) { - const scene = new GLTFScenegraph(gltfData); - const { json } = scene; - for (const texture of json.textures || []) { - const extension = scene.getObjectExtension(texture, KHR_TEXTURE_BASISU); - if (extension) { - // TODO - if multiple texture extensions are present which one wins? - texture.source = extension.source; - scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU); - } - } - // Remove the top-level extension - scene.removeExtension(KHR_TEXTURE_BASISU); -} - -var KHR_texture_basisu = /*#__PURE__*/Object.freeze({ - __proto__: null, - name: name$5, - preprocess: preprocess$2 -}); - -// Version constant cannot be imported, it needs to correspond to the build version of **this** module. -// __VERSION__ is injected by babel-plugin-version-inline -// @ts-ignore TS2304: Cannot find name '__VERSION__'. -const VERSION$1 = "4.3.3" ; - -// loaders.gl -/** - * Worker loader for Draco3D compressed geometries - */ -const DracoLoader$1 = { - dataType: null, - batchType: null, - name: 'Draco', - id: 'draco', - module: 'draco', - // shapes: ['mesh'], - version: VERSION$1, - worker: true, - extensions: ['drc'], - mimeTypes: ['application/octet-stream'], - binary: true, - tests: ['DRACO'], - options: { - draco: { - decoderType: typeof WebAssembly === 'object' ? 'wasm' : 'js', // 'js' for IE11 - libraryPath: 'libs/', - extraAttributes: {}, - attributeNameEntry: undefined - } - } -}; - -/** Extract an arrow-like schema from a Draco mesh */ -function getDracoSchema(attributes, loaderData, indices) { - const metadata = makeMetadata(loaderData.metadata); - const fields = []; - const namedLoaderDataAttributes = transformAttributesLoaderData(loaderData.attributes); - for (const attributeName in attributes) { - const attribute = attributes[attributeName]; - const field = getArrowFieldFromAttribute(attributeName, attribute, namedLoaderDataAttributes[attributeName]); - fields.push(field); - } - if (indices) { - const indicesField = getArrowFieldFromAttribute('indices', indices); - fields.push(indicesField); - } - return { fields, metadata }; -} -function transformAttributesLoaderData(loaderData) { - const result = {}; - for (const key in loaderData) { - const dracoAttribute = loaderData[key]; - result[dracoAttribute.name || 'undefined'] = dracoAttribute; - } - return result; -} -function getArrowFieldFromAttribute(attributeName, attribute, loaderData) { - const metadataMap = loaderData ? makeMetadata(loaderData.metadata) : undefined; - const field = deduceMeshField(attributeName, attribute, metadataMap); - return field; -} -function makeMetadata(metadata) { - const serializedMetadata = {}; - for (const key in metadata) { - serializedMetadata[`${key}.string`] = JSON.stringify(metadata[key]); - } - return serializedMetadata; -} - -/* eslint-disable camelcase */ -// Native Draco attribute names to GLTF attribute names. -const DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP = { - POSITION: 'POSITION', - NORMAL: 'NORMAL', - COLOR: 'COLOR_0', - TEX_COORD: 'TEXCOORD_0' -}; -const DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP = { - 1: Int8Array, - 2: Uint8Array, - 3: Int16Array, - 4: Uint16Array, - 5: Int32Array, - 6: Uint32Array, - // 7: BigInt64Array, - // 8: BigUint64Array, - 9: Float32Array - // 10: Float64Array - // 11: BOOL - What array type do we use for this? -}; -const INDEX_ITEM_SIZE = 4; -class DracoParser { - draco; - decoder; - metadataQuerier; - // draco - the draco decoder, either import `draco3d` or load dynamically - constructor(draco) { - this.draco = draco; - this.decoder = new this.draco.Decoder(); - this.metadataQuerier = new this.draco.MetadataQuerier(); - } - /** - * Destroy draco resources - */ - destroy() { - this.draco.destroy(this.decoder); - this.draco.destroy(this.metadataQuerier); - } - /** - * NOTE: caller must call `destroyGeometry` on the return value after using it - * @param arrayBuffer - * @param options - */ - parseSync(arrayBuffer, options = {}) { - const buffer = new this.draco.DecoderBuffer(); - buffer.Init(new Int8Array(arrayBuffer), arrayBuffer.byteLength); - this._disableAttributeTransforms(options); - const geometry_type = this.decoder.GetEncodedGeometryType(buffer); - const dracoGeometry = geometry_type === this.draco.TRIANGULAR_MESH - ? new this.draco.Mesh() - : new this.draco.PointCloud(); - try { - let dracoStatus; - switch (geometry_type) { - case this.draco.TRIANGULAR_MESH: - dracoStatus = this.decoder.DecodeBufferToMesh(buffer, dracoGeometry); - break; - case this.draco.POINT_CLOUD: - dracoStatus = this.decoder.DecodeBufferToPointCloud(buffer, dracoGeometry); - break; - default: - throw new Error('DRACO: Unknown geometry type.'); - } - if (!dracoStatus.ok() || !dracoGeometry.ptr) { - const message = `DRACO decompression failed: ${dracoStatus.error_msg()}`; - // console.error(message); - throw new Error(message); - } - const loaderData = this._getDracoLoaderData(dracoGeometry, geometry_type, options); - const geometry = this._getMeshData(dracoGeometry, loaderData, options); - const boundingBox = getMeshBoundingBox(geometry.attributes); - const schema = getDracoSchema(geometry.attributes, loaderData, geometry.indices); - const data = { - loader: 'draco', - loaderData, - header: { - vertexCount: dracoGeometry.num_points(), - boundingBox - }, - ...geometry, - schema - }; - return data; - } - finally { - this.draco.destroy(buffer); - if (dracoGeometry) { - this.draco.destroy(dracoGeometry); - } - } - } - // Draco specific "loader data" - /** - * Extract - * @param dracoGeometry - * @param geometry_type - * @param options - * @returns - */ - _getDracoLoaderData(dracoGeometry, geometry_type, options) { - const metadata = this._getTopLevelMetadata(dracoGeometry); - const attributes = this._getDracoAttributes(dracoGeometry, options); - return { - geometry_type, - num_attributes: dracoGeometry.num_attributes(), - num_points: dracoGeometry.num_points(), - num_faces: dracoGeometry instanceof this.draco.Mesh ? dracoGeometry.num_faces() : 0, - metadata, - attributes - }; - } - /** - * Extract all draco provided information and metadata for each attribute - * @param dracoGeometry - * @param options - * @returns - */ - _getDracoAttributes(dracoGeometry, options) { - const dracoAttributes = {}; - for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) { - // Note: Draco docs do not seem clear on `GetAttribute` ids just being a zero-based index, - // but it does seems to work this way - const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId); - const metadata = this._getAttributeMetadata(dracoGeometry, attributeId); - dracoAttributes[dracoAttribute.unique_id()] = { - unique_id: dracoAttribute.unique_id(), - attribute_type: dracoAttribute.attribute_type(), - data_type: dracoAttribute.data_type(), - num_components: dracoAttribute.num_components(), - byte_offset: dracoAttribute.byte_offset(), - byte_stride: dracoAttribute.byte_stride(), - normalized: dracoAttribute.normalized(), - attribute_index: attributeId, - metadata - }; - // Add transformation parameters for any attributes app wants untransformed - const quantization = this._getQuantizationTransform(dracoAttribute, options); - if (quantization) { - dracoAttributes[dracoAttribute.unique_id()].quantization_transform = quantization; - } - const octahedron = this._getOctahedronTransform(dracoAttribute, options); - if (octahedron) { - dracoAttributes[dracoAttribute.unique_id()].octahedron_transform = octahedron; - } - } - return dracoAttributes; - } - /** - * Get standard loaders.gl mesh category data - * Extracts the geometry from draco - * @param dracoGeometry - * @param options - */ - _getMeshData(dracoGeometry, loaderData, options) { - const attributes = this._getMeshAttributes(loaderData, dracoGeometry, options); - const positionAttribute = attributes.POSITION; - if (!positionAttribute) { - throw new Error('DRACO: No position attribute found.'); - } - // For meshes, we need indices to define the faces. - if (dracoGeometry instanceof this.draco.Mesh) { - switch (options.topology) { - case 'triangle-strip': - return { - topology: 'triangle-strip', - mode: 4, // GL.TRIANGLES - attributes, - indices: { - value: this._getTriangleStripIndices(dracoGeometry), - size: 1 - } - }; - case 'triangle-list': - default: - return { - topology: 'triangle-list', - mode: 5, // GL.TRIANGLE_STRIP - attributes, - indices: { - value: this._getTriangleListIndices(dracoGeometry), - size: 1 - } - }; - } - } - // PointCloud - must come last as Mesh inherits from PointCloud - return { - topology: 'point-list', - mode: 0, // GL.POINTS - attributes - }; - } - _getMeshAttributes(loaderData, dracoGeometry, options) { - const attributes = {}; - for (const loaderAttribute of Object.values(loaderData.attributes)) { - const attributeName = this._deduceAttributeName(loaderAttribute, options); - loaderAttribute.name = attributeName; - const values = this._getAttributeValues(dracoGeometry, loaderAttribute); - if (values) { - const { value, size } = values; - attributes[attributeName] = { - value, - size, - byteOffset: loaderAttribute.byte_offset, - byteStride: loaderAttribute.byte_stride, - normalized: loaderAttribute.normalized - }; - } - } - return attributes; - } - // MESH INDICES EXTRACTION - /** - * For meshes, we need indices to define the faces. - * @param dracoGeometry - */ - _getTriangleListIndices(dracoGeometry) { - // Example on how to retrieve mesh and attributes. - const numFaces = dracoGeometry.num_faces(); - const numIndices = numFaces * 3; - const byteLength = numIndices * INDEX_ITEM_SIZE; - const ptr = this.draco._malloc(byteLength); - try { - this.decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr); - return new Uint32Array(this.draco.HEAPF32.buffer, ptr, numIndices).slice(); - } - finally { - this.draco._free(ptr); - } - } - /** - * For meshes, we need indices to define the faces. - * @param dracoGeometry - */ - _getTriangleStripIndices(dracoGeometry) { - const dracoArray = new this.draco.DracoInt32Array(); - try { - /* const numStrips = */ this.decoder.GetTriangleStripsFromMesh(dracoGeometry, dracoArray); - return getUint32Array(dracoArray); - } - finally { - this.draco.destroy(dracoArray); - } - } - /** - * - * @param dracoGeometry - * @param dracoAttribute - * @param attributeName - */ - _getAttributeValues(dracoGeometry, attribute) { - const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type]; - if (!TypedArrayCtor) { - // eslint-disable-next-line no-console - console.warn(`DRACO: Unsupported attribute type ${attribute.data_type}`); - return null; - } - const numComponents = attribute.num_components; - const numPoints = dracoGeometry.num_points(); - const numValues = numPoints * numComponents; - const byteLength = numValues * TypedArrayCtor.BYTES_PER_ELEMENT; - const dataType = getDracoDataType(this.draco, TypedArrayCtor); - let value; - const ptr = this.draco._malloc(byteLength); - try { - const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attribute.attribute_index); - this.decoder.GetAttributeDataArrayForAllPoints(dracoGeometry, dracoAttribute, dataType, byteLength, ptr); - value = new TypedArrayCtor(this.draco.HEAPF32.buffer, ptr, numValues).slice(); - } - finally { - this.draco._free(ptr); - } - return { value, size: numComponents }; - } - // Attribute names - /** - * DRACO does not store attribute names - We need to deduce an attribute name - * for each attribute - _getAttributeNames( - dracoGeometry: Mesh | PointCloud, - options: DracoParseOptions - ): {[unique_id: number]: string} { - const attributeNames: {[unique_id: number]: string} = {}; - for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) { - const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId); - const attributeName = this._deduceAttributeName(dracoAttribute, options); - attributeNames[attributeName] = attributeName; - } - return attributeNames; - } - */ - /** - * Deduce an attribute name. - * @note DRACO does not save attribute names, just general type (POSITION, COLOR) - * to help optimize compression. We generate GLTF compatible names for the Draco-recognized - * types - * @param attributeData - */ - _deduceAttributeName(attribute, options) { - // Deduce name based on application provided map - const uniqueId = attribute.unique_id; - for (const [attributeName, attributeUniqueId] of Object.entries(options.extraAttributes || {})) { - if (attributeUniqueId === uniqueId) { - return attributeName; - } - } - // Deduce name based on attribute type - const thisAttributeType = attribute.attribute_type; - for (const dracoAttributeConstant in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP) { - const attributeType = this.draco[dracoAttributeConstant]; - if (attributeType === thisAttributeType) { - // TODO - Return unique names if there multiple attributes per type - // (e.g. multiple TEX_COORDS or COLORS) - return DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP[dracoAttributeConstant]; - } - } - // Look up in metadata - // TODO - shouldn't this have priority? - const entryName = options.attributeNameEntry || 'name'; - if (attribute.metadata[entryName]) { - return attribute.metadata[entryName].string; - } - // Attribute of "GENERIC" type, we need to assign some name - return `CUSTOM_ATTRIBUTE_${uniqueId}`; - } - // METADATA EXTRACTION - /** Get top level metadata */ - _getTopLevelMetadata(dracoGeometry) { - const dracoMetadata = this.decoder.GetMetadata(dracoGeometry); - return this._getDracoMetadata(dracoMetadata); - } - /** Get per attribute metadata */ - _getAttributeMetadata(dracoGeometry, attributeId) { - const dracoMetadata = this.decoder.GetAttributeMetadata(dracoGeometry, attributeId); - return this._getDracoMetadata(dracoMetadata); - } - /** - * Extract metadata field values - * @param dracoMetadata - * @returns - */ - _getDracoMetadata(dracoMetadata) { - // The not so wonderful world of undocumented Draco APIs :( - if (!dracoMetadata || !dracoMetadata.ptr) { - return {}; - } - const result = {}; - const numEntries = this.metadataQuerier.NumEntries(dracoMetadata); - for (let entryIndex = 0; entryIndex < numEntries; entryIndex++) { - const entryName = this.metadataQuerier.GetEntryName(dracoMetadata, entryIndex); - result[entryName] = this._getDracoMetadataField(dracoMetadata, entryName); - } - return result; - } - /** - * Extracts possible values for one metadata entry by name - * @param dracoMetadata - * @param entryName - */ - _getDracoMetadataField(dracoMetadata, entryName) { - const dracoArray = new this.draco.DracoInt32Array(); - try { - // Draco metadata fields can hold int32 arrays - this.metadataQuerier.GetIntEntryArray(dracoMetadata, entryName, dracoArray); - const intArray = getInt32Array(dracoArray); - return { - int: this.metadataQuerier.GetIntEntry(dracoMetadata, entryName), - string: this.metadataQuerier.GetStringEntry(dracoMetadata, entryName), - double: this.metadataQuerier.GetDoubleEntry(dracoMetadata, entryName), - intArray - }; - } - finally { - this.draco.destroy(dracoArray); - } - } - // QUANTIZED ATTRIBUTE SUPPORT (NO DECOMPRESSION) - /** Skip transforms for specific attribute types */ - _disableAttributeTransforms(options) { - const { quantizedAttributes = [], octahedronAttributes = [] } = options; - const skipAttributes = [...quantizedAttributes, ...octahedronAttributes]; - for (const dracoAttributeName of skipAttributes) { - this.decoder.SkipAttributeTransform(this.draco[dracoAttributeName]); - } - } - /** - * Extract (and apply?) Position Transform - * @todo not used - */ - _getQuantizationTransform(dracoAttribute, options) { - const { quantizedAttributes = [] } = options; - const attribute_type = dracoAttribute.attribute_type(); - const skip = quantizedAttributes.map((type) => this.decoder[type]).includes(attribute_type); - if (skip) { - const transform = new this.draco.AttributeQuantizationTransform(); - try { - if (transform.InitFromAttribute(dracoAttribute)) { - return { - quantization_bits: transform.quantization_bits(), - range: transform.range(), - min_values: new Float32Array([1, 2, 3]).map((i) => transform.min_value(i)) - }; - } - } - finally { - this.draco.destroy(transform); - } - } - return null; - } - _getOctahedronTransform(dracoAttribute, options) { - const { octahedronAttributes = [] } = options; - const attribute_type = dracoAttribute.attribute_type(); - const octahedron = octahedronAttributes - .map((type) => this.decoder[type]) - .includes(attribute_type); - if (octahedron) { - const transform = new this.draco.AttributeQuantizationTransform(); - try { - if (transform.InitFromAttribute(dracoAttribute)) { - return { - quantization_bits: transform.quantization_bits() - }; - } - } - finally { - this.draco.destroy(transform); - } - } - return null; - } -} -/** - * Get draco specific data type by TypedArray constructor type - * @param attributeType - * @returns draco specific data type - */ -function getDracoDataType(draco, attributeType) { - switch (attributeType) { - case Float32Array: - return draco.DT_FLOAT32; - case Int8Array: - return draco.DT_INT8; - case Int16Array: - return draco.DT_INT16; - case Int32Array: - return draco.DT_INT32; - case Uint8Array: - return draco.DT_UINT8; - case Uint16Array: - return draco.DT_UINT16; - case Uint32Array: - return draco.DT_UINT32; - default: - return draco.DT_INVALID; - } -} -/** - * Copy a Draco int32 array into a JS typed array - */ -function getInt32Array(dracoArray) { - const numValues = dracoArray.size(); - const intArray = new Int32Array(numValues); - for (let i = 0; i < numValues; i++) { - intArray[i] = dracoArray.GetValue(i); - } - return intArray; -} -/** - * Copy a Draco int32 array into a JS typed array - */ -function getUint32Array(dracoArray) { - const numValues = dracoArray.size(); - const intArray = new Int32Array(numValues); - for (let i = 0; i < numValues; i++) { - intArray[i] = dracoArray.GetValue(i); - } - return intArray; -} - -// Dynamic DRACO module loading inspired by THREE.DRACOLoader -const DRACO_DECODER_VERSION = '1.5.6'; -const DRACO_ENCODER_VERSION = '1.4.1'; -const STATIC_DECODER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_DECODER_VERSION}`; -const DRACO_EXTERNAL_LIBRARIES = { - /** The primary Draco3D encoder, javascript wrapper part */ - DECODER: 'draco_wasm_wrapper.js', - /** The primary draco decoder, compiled web assembly part */ - DECODER_WASM: 'draco_decoder.wasm', - /** Fallback decoder for non-webassebly environments. Very big bundle, lower performance */ - FALLBACK_DECODER: 'draco_decoder.js', - /** Draco encoder */ - ENCODER: 'draco_encoder.js' -}; -const DRACO_EXTERNAL_LIBRARY_URLS = { - [DRACO_EXTERNAL_LIBRARIES.DECODER]: `${STATIC_DECODER_URL}/${DRACO_EXTERNAL_LIBRARIES.DECODER}`, - [DRACO_EXTERNAL_LIBRARIES.DECODER_WASM]: `${STATIC_DECODER_URL}/${DRACO_EXTERNAL_LIBRARIES.DECODER_WASM}`, - [DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER]: `${STATIC_DECODER_URL}/${DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER}`, - [DRACO_EXTERNAL_LIBRARIES.ENCODER]: `https://raw.githubusercontent.com/google/draco/${DRACO_ENCODER_VERSION}/javascript/${DRACO_EXTERNAL_LIBRARIES.ENCODER}` -}; -let loadDecoderPromise; -async function loadDracoDecoderModule(options) { - const modules = options.modules || {}; - // Check if a bundled draco3d library has been supplied by application - if (modules.draco3d) { - loadDecoderPromise ||= modules.draco3d.createDecoderModule({}).then((draco) => { - return { draco }; - }); - } - else { - // If not, dynamically load the WASM script from our CDN - loadDecoderPromise ||= loadDracoDecoder(options); - } - return await loadDecoderPromise; -} -// DRACO DECODER LOADING -async function loadDracoDecoder(options) { - let DracoDecoderModule; - let wasmBinary; - switch (options.draco && options.draco.decoderType) { - case 'js': - DracoDecoderModule = await loadLibrary(DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER], 'draco', options, DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER); - break; - case 'wasm': - default: - [DracoDecoderModule, wasmBinary] = await Promise.all([ - await loadLibrary(DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER], 'draco', options, DRACO_EXTERNAL_LIBRARIES.DECODER), - await loadLibrary(DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER_WASM], 'draco', options, DRACO_EXTERNAL_LIBRARIES.DECODER_WASM) - ]); - } - // Depends on how import happened... - // @ts-ignore - DracoDecoderModule = DracoDecoderModule || globalThis.DracoDecoderModule; - return await initializeDracoDecoder(DracoDecoderModule, wasmBinary); -} -function initializeDracoDecoder(DracoDecoderModule, wasmBinary) { - const options = {}; - if (wasmBinary) { - options.wasmBinary = wasmBinary; - } - return new Promise((resolve) => { - DracoDecoderModule({ - ...options, - onModuleLoaded: (draco) => resolve({ draco }) // Module is Promise-like. Wrap in object to avoid loop. - }); - }); -} - -/** - * Browser worker doesn't work because of issue during "draco_encoder.js" loading. - * Refused to execute script from 'https://raw.githubusercontent.com/google/draco/1.4.1/javascript/draco_encoder.js' because its MIME type ('') is not executable. - */ -({ - id: 'draco-writer', - name: 'Draco compressed geometry writer', - module: 'draco', - version: VERSION$1, - worker: true, - options: { - draco: {}, - source: null - } -}); -/** - * Loader for Draco3D compressed geometries - */ -const DracoLoader = { - ...DracoLoader$1, - parse: parse$3 -}; -async function parse$3(arrayBuffer, options) { - const { draco } = await loadDracoDecoderModule(options); - const dracoParser = new DracoParser(draco); - try { - return dracoParser.parseSync(arrayBuffer, options?.draco); - } - finally { - dracoParser.destroy(); - } -} - -// TODO - remove -// Returns a fresh attributes object with glTF-standardized attributes names -// Attributes that cannot be identified will not be included -// Removes `indices` if present, as it should be stored separately from the attributes -function getGLTFAccessors(attributes) { - const accessors = {}; - for (const name in attributes) { - const attribute = attributes[name]; - if (name !== 'indices') { - const glTFAccessor = getGLTFAccessor(attribute); - accessors[name] = glTFAccessor; - } - } - return accessors; -} -// Fix up a single accessor. -// Input: typed array or a partial accessor object -// Return: accessor object -function getGLTFAccessor(attribute) { - const { buffer, size, count } = getAccessorData(attribute); - const glTFAccessor = { - // glTF Accessor values - // TODO: Instead of a bufferView index we could have an actual buffer (typed array) - // bufferView: null, - // TODO: Deprecate `value` in favor of bufferView? - // @ts-ignore - value: buffer, - size, // Decoded `type` (e.g. SCALAR) - byteOffset: 0, - count, - type: getAccessorTypeFromSize(size), - componentType: getComponentTypeFromArray(buffer) - }; - return glTFAccessor; -} -// export function getGLTFAttribute(data, gltfAttributeName): GLTFAccessor { -// return data.attributes[data.glTFAttributeMap[gltfAttributeName]]; -// } -function getAccessorData(attribute) { - let buffer = attribute; - let size = 1; - let count = 0; - if (attribute && attribute.value) { - buffer = attribute.value; - size = attribute.size || 1; - } - if (buffer) { - if (!ArrayBuffer.isView(buffer)) { - buffer = toTypedArray(buffer, Float32Array); - } - count = buffer.length / size; - } - return { buffer, size, count }; -} -// Convert non-typed arrays to arrays of specified format -function toTypedArray(array, ArrayType, convertTypedArrays = false) { - if (!array) { - return null; - } - if (Array.isArray(array)) { - return new ArrayType(array); - } - if (convertTypedArrays && !(array instanceof ArrayType)) { - return new ArrayType(array); - } - return array; -} - -// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression -const KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression'; -/** Extension name */ -const name$4 = KHR_DRACO_MESH_COMPRESSION; -function preprocess$1(gltfData, options, context) { - const scenegraph = new GLTFScenegraph(gltfData); - for (const primitive of makeMeshPrimitiveIterator(scenegraph)) { - if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) ; - } -} -async function decode$6(gltfData, options, context) { - if (!options?.gltf?.decompressMeshes) { - return; - } - const scenegraph = new GLTFScenegraph(gltfData); - const promises = []; - for (const primitive of makeMeshPrimitiveIterator(scenegraph)) { - if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) { - promises.push(decompressPrimitive(scenegraph, primitive, options, context)); - } - } - // Decompress meshes in parallel - await Promise.all(promises); - // We have now decompressed all primitives, so remove the top-level extension - scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION); -} -function encode$3(gltfData, options = {}) { - const scenegraph = new GLTFScenegraph(gltfData); - for (const mesh of scenegraph.json.meshes || []) { - // eslint-disable-next-line camelcase - // @ts-ignore - compressMesh(mesh); - // NOTE: Only add the extension if something was actually compressed - scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION); - } -} -// DECODE -// Unpacks one mesh primitive and removes the extension from the primitive -// DracoDecoder needs to be imported and registered by app -// Returns: Promise that resolves when all pending draco decoder jobs for this mesh complete -// TODO - Implement fallback behavior per KHR_DRACO_MESH_COMPRESSION spec -async function decompressPrimitive(scenegraph, primitive, options, context) { - const dracoExtension = scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION); - if (!dracoExtension) { - return; - } - const buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView); - // TODO - parse does not yet deal well with byte offsets embedded in typed arrays. Copy buffer - // TODO - remove when `parse` is fixed to handle `byteOffset`s - const bufferCopy = sliceArrayBuffer(buffer.buffer, buffer.byteOffset); // , buffer.byteLength); - const dracoOptions = { ...options }; - // TODO - remove hack: The entire tileset might be included, too expensive to serialize - delete dracoOptions['3d-tiles']; - const decodedData = await parseFromContext(bufferCopy, DracoLoader, dracoOptions, context); - const decodedAttributes = getGLTFAccessors(decodedData.attributes); - // Restore min/max values - for (const [attributeName, decodedAttribute] of Object.entries(decodedAttributes)) { - if (attributeName in primitive.attributes) { - const accessorIndex = primitive.attributes[attributeName]; - const accessor = scenegraph.getAccessor(accessorIndex); - if (accessor?.min && accessor?.max) { - decodedAttribute.min = accessor.min; - decodedAttribute.max = accessor.max; - } - } - } - // @ts-ignore - primitive.attributes = decodedAttributes; - if (decodedData.indices) { - // @ts-ignore - primitive.indices = getGLTFAccessor(decodedData.indices); - } - // Extension has been processed, delete it - scenegraph.removeObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION); - checkPrimitive(primitive); -} -// ENCODE -// eslint-disable-next-line max-len -// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported -function compressMesh(attributes, indices, mode = 4, options, context) { - if (!options.DracoWriter) { - throw new Error('options.gltf.DracoWriter not provided'); - } - // TODO - use DracoWriter using encode w/ registered DracoWriter... - const compressedData = options.DracoWriter.encodeSync({ attributes }); - // Draco compression may change the order and number of vertices in a mesh. - // To satisfy the requirement that accessors properties be correct for both - // compressed and uncompressed data, generators should create uncompressed - // attributes and indices using data that has been decompressed from the Draco buffer, - // rather than the original source data. - // @ts-ignore TODO this needs to be fixed - const decodedData = context?.parseSync?.({ attributes }); - const fauxAccessors = options._addFauxAttributes(decodedData.attributes); - const bufferViewIndex = options.addBufferView(compressedData); - const glTFMesh = { - primitives: [ - { - attributes: fauxAccessors, // TODO - verify with spec - mode, // GL.POINTS - extensions: { - [KHR_DRACO_MESH_COMPRESSION]: { - bufferView: bufferViewIndex, - attributes: fauxAccessors // TODO - verify with spec - } - } - } - ] - }; - return glTFMesh; -} -// UTILS -function checkPrimitive(primitive) { - if (!primitive.attributes && Object.keys(primitive.attributes).length > 0) { - throw new Error('glTF: Empty primitive detected: Draco decompression failure?'); - } -} -function* makeMeshPrimitiveIterator(scenegraph) { - for (const mesh of scenegraph.json.meshes || []) { - for (const primitive of mesh.primitives) { - yield primitive; - } - } -} - -var KHR_draco_mesh_compression = /*#__PURE__*/Object.freeze({ - __proto__: null, - name: name$4, - preprocess: preprocess$1, - decode: decode$6, - encode: encode$3 -}); - -// math.gl -const DEFAULT_CONFIG = { - EPSILON: 1e-12, - debug: false, - precision: 4, - printTypes: false, - printDegrees: false, - printRowMajor: true, - _cartographicRadians: false -}; -// Configuration is truly global as of v3.6 to ensure single config even if multiple copies of math.gl -// Multiple copies of config can be quite tricky to debug... -globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } }; -const config = globalThis.mathgl.config; -/** - * Formats a value into a string - * @param value - * @param param1 - * @returns - */ -function formatValue(value, { precision = config.precision } = {}) { - value = round(value); - // get rid of trailing zeros - return `${parseFloat(value.toPrecision(precision))}`; -} -/** - * Check if value is an "array" - * Returns `true` if value is either an array or a typed array - * Note: returns `false` for `ArrayBuffer` and `DataView` instances - * @note isTypedArray and isNumericArray are often more useful in TypeScript - */ -function isArray(value) { - return Array.isArray(value) || (ArrayBuffer.isView(value) && !(value instanceof DataView)); -} -/* eslint-disable */ -/** - * Compares any two math objects, using `equals` method if available. - * @param a - * @param b - * @param epsilon - * @returns - */ -function equals(a, b, epsilon) { - const oldEpsilon = config.EPSILON; - if (epsilon) { - config.EPSILON = epsilon; - } - try { - if (a === b) { - return true; - } - if (isArray(a) && isArray(b)) { - if (a.length !== b.length) { - return false; - } - for (let i = 0; i < a.length; ++i) { - // eslint-disable-next-line max-depth - if (!equals(a[i], b[i])) { - return false; - } - } - return true; - } - if (a && a.equals) { - return a.equals(b); - } - if (b && b.equals) { - return b.equals(a); - } - if (typeof a === 'number' && typeof b === 'number') { - return Math.abs(a - b) <= config.EPSILON * Math.max(1, Math.abs(a), Math.abs(b)); - } - return false; - } - finally { - config.EPSILON = oldEpsilon; - } -} -// HELPERS -function round(value) { - return Math.round(value / config.EPSILON) * config.EPSILON; -} - -// math.gl -/** Base class for vectors and matrices */ -class MathArray extends Array { - // Common methods - /** - * Clone the current object - * @returns a new copy of this object - */ - clone() { - // @ts-expect-error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. - return new this.constructor().copy(this); // eslint-disable-line - } - fromArray(array, offset = 0) { - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] = array[i + offset]; - } - return this.check(); - } - toArray(targetArray = [], offset = 0) { - for (let i = 0; i < this.ELEMENTS; ++i) { - targetArray[offset + i] = this[i]; - } - return targetArray; - } - toObject(targetObject) { - return targetObject; - } - from(arrayOrObject) { - return Array.isArray(arrayOrObject) - ? this.copy(arrayOrObject) - : // @ts-ignore - this.fromObject(arrayOrObject); - } - to(arrayOrObject) { - // @ts-ignore - if (arrayOrObject === this) { - return this; - } - // @ts-expect-error TS2339: Property 'toObject' does not exist on type 'MathArray'. - return isArray(arrayOrObject) ? this.toArray(arrayOrObject) : this.toObject(arrayOrObject); - } - toTarget(target) { - return target ? this.to(target) : this; - } - /** @deprecated */ - toFloat32Array() { - return new Float32Array(this); - } - toString() { - return this.formatString(config); - } - /** Formats string according to options */ - formatString(opts) { - let string = ''; - for (let i = 0; i < this.ELEMENTS; ++i) { - string += (i > 0 ? ', ' : '') + formatValue(this[i], opts); - } - return `${opts.printTypes ? this.constructor.name : ''}[${string}]`; - } - equals(array) { - if (!array || this.length !== array.length) { - return false; - } - for (let i = 0; i < this.ELEMENTS; ++i) { - if (!equals(this[i], array[i])) { - return false; - } - } - return true; - } - exactEquals(array) { - if (!array || this.length !== array.length) { - return false; - } - for (let i = 0; i < this.ELEMENTS; ++i) { - if (this[i] !== array[i]) { - return false; - } - } - return true; - } - // Modifiers - /** Negates all values in this object */ - negate() { - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] = -this[i]; - } - return this.check(); - } - lerp(a, b, t) { - if (t === undefined) { - return this.lerp(this, a, b); - } - for (let i = 0; i < this.ELEMENTS; ++i) { - const ai = a[i]; - const endValue = typeof b === 'number' ? b : b[i]; - this[i] = ai + t * (endValue - ai); - } - return this.check(); - } - /** Minimal */ - min(vector) { - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] = Math.min(vector[i], this[i]); - } - return this.check(); - } - /** Maximal */ - max(vector) { - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] = Math.max(vector[i], this[i]); - } - return this.check(); - } - clamp(minVector, maxVector) { - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] = Math.min(Math.max(this[i], minVector[i]), maxVector[i]); - } - return this.check(); - } - add(...vectors) { - for (const vector of vectors) { - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] += vector[i]; - } - } - return this.check(); - } - subtract(...vectors) { - for (const vector of vectors) { - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] -= vector[i]; - } - } - return this.check(); - } - scale(scale) { - if (typeof scale === 'number') { - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] *= scale; - } - } - else { - for (let i = 0; i < this.ELEMENTS && i < scale.length; ++i) { - this[i] *= scale[i]; - } - } - return this.check(); - } - /** - * Multiplies all elements by `scale` - * Note: `Matrix4.multiplyByScalar` only scales its 3x3 "minor" - */ - multiplyByScalar(scalar) { - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] *= scalar; - } - return this.check(); - } - // Debug checks - /** Throws an error if array length is incorrect or contains illegal values */ - check() { - if (config.debug && !this.validate()) { - throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`); - } - return this; - } - /** Returns false if the array length is incorrect or contains illegal values */ - validate() { - let valid = this.length === this.ELEMENTS; - for (let i = 0; i < this.ELEMENTS; ++i) { - valid = valid && Number.isFinite(this[i]); - } - return valid; - } - // three.js compatibility - /** @deprecated */ - sub(a) { - return this.subtract(a); - } - /** @deprecated */ - setScalar(a) { - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] = a; - } - return this.check(); - } - /** @deprecated */ - addScalar(a) { - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] += a; - } - return this.check(); - } - /** @deprecated */ - subScalar(a) { - return this.addScalar(-a); - } - /** @deprecated */ - multiplyScalar(scalar) { - // Multiplies all elements - // `Matrix4.scale` only scales its 3x3 "minor" - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] *= scalar; - } - return this.check(); - } - /** @deprecated */ - divideScalar(a) { - return this.multiplyByScalar(1 / a); - } - /** @deprecated */ - clampScalar(min, max) { - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] = Math.min(Math.max(this[i], min), max); - } - return this.check(); - } - /** @deprecated */ - get elements() { - return this; - } -} - -// math.gl -function validateVector(v, length) { - if (v.length !== length) { - return false; - } - // Could be arguments "array" (v.every not availasble) - for (let i = 0; i < v.length; ++i) { - if (!Number.isFinite(v[i])) { - return false; - } - } - return true; -} -function checkNumber(value) { - if (!Number.isFinite(value)) { - throw new Error(`Invalid number ${JSON.stringify(value)}`); - } - return value; -} -function checkVector(v, length, callerName = '') { - if (config.debug && !validateVector(v, length)) { - throw new Error(`math.gl: ${callerName} some fields set to invalid numbers'`); - } - return v; -} - -// math.gl -// SPDX-License-Identifier: MIT -// Copyright (c) vis.gl contributors -function assert(condition, message) { - if (!condition) { - throw new Error(`math.gl assertion ${message}`); - } -} - -// math.gl -/** Base class for vectors with at least 2 elements */ -class Vector$1 extends MathArray { - // ACCESSORS - get x() { - return this[0]; - } - set x(value) { - this[0] = checkNumber(value); - } - get y() { - return this[1]; - } - set y(value) { - this[1] = checkNumber(value); - } - /** - * Returns the length of the vector from the origin to the point described by this vector - * - * @note `length` is a reserved word for Arrays, so `v.length()` will return number of elements - * Instead we provide `len` and `magnitude` - */ - len() { - return Math.sqrt(this.lengthSquared()); - } - /** - * Returns the length of the vector from the origin to the point described by this vector - */ - magnitude() { - return this.len(); - } - /** - * Returns the squared length of the vector from the origin to the point described by this vector - */ - lengthSquared() { - let length = 0; - for (let i = 0; i < this.ELEMENTS; ++i) { - length += this[i] * this[i]; - } - return length; - } - /** - * Returns the squared length of the vector from the origin to the point described by this vector - */ - magnitudeSquared() { - return this.lengthSquared(); - } - distance(mathArray) { - return Math.sqrt(this.distanceSquared(mathArray)); - } - distanceSquared(mathArray) { - let length = 0; - for (let i = 0; i < this.ELEMENTS; ++i) { - const dist = this[i] - mathArray[i]; - length += dist * dist; - } - return checkNumber(length); - } - dot(mathArray) { - let product = 0; - for (let i = 0; i < this.ELEMENTS; ++i) { - product += this[i] * mathArray[i]; - } - return checkNumber(product); - } - // MODIFIERS - normalize() { - const length = this.magnitude(); - if (length !== 0) { - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] /= length; - } - } - return this.check(); - } - multiply(...vectors) { - for (const vector of vectors) { - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] *= vector[i]; - } - } - return this.check(); - } - divide(...vectors) { - for (const vector of vectors) { - for (let i = 0; i < this.ELEMENTS; ++i) { - this[i] /= vector[i]; - } - } - return this.check(); - } - // THREE.js compatibility - lengthSq() { - return this.lengthSquared(); - } - distanceTo(vector) { - return this.distance(vector); - } - distanceToSquared(vector) { - return this.distanceSquared(vector); - } - getComponent(i) { - assert(i >= 0 && i < this.ELEMENTS, 'index is out of range'); - return checkNumber(this[i]); - } - setComponent(i, value) { - assert(i >= 0 && i < this.ELEMENTS, 'index is out of range'); - this[i] = value; - return this.check(); - } - addVectors(a, b) { - return this.copy(a).add(b); - } - subVectors(a, b) { - return this.copy(a).subtract(b); - } - multiplyVectors(a, b) { - return this.copy(a).multiply(b); - } - addScaledVector(a, b) { - // @ts-expect-error error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. - return this.add(new this.constructor(a).multiplyScalar(b)); - } -} - -// @eslint-disable -let ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array; - -// @eslint-disable -/** - * 2 Dimensional Vector - * @module vec2 - */ -/** - * Creates a new, empty vec2 - * - * @returns a new 2D vector - */ -function create$1() { - const out = new ARRAY_TYPE(2); - if (ARRAY_TYPE != Float32Array) { - out[0] = 0; - out[1] = 0; - } - return out; -} -/** - * Transforms the vec2 with a mat3 - * 3rd vector component is implicitly '1' - * - * @param {NumericArray} out the receiving vector - * @param {Readonly} a the vector to transform - * @param {ReadonlyMat3} m matrix to transform with - * @returns {NumericArray} out - */ -function transformMat3$1(out, a, m) { - const x = a[0]; - const y = a[1]; - out[0] = m[0] * x + m[3] * y + m[6]; - out[1] = m[1] * x + m[4] * y + m[7]; - return out; -} -/** - * Perform some operation over an array of vec2s. - * - * @param {Array} a the array of vectors to iterate over - * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed - * @param {Number} offset Number of elements to skip at the beginning of the array - * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array - * @param {Function} fn Function to call for each vector in the array - * @param {Object} [arg] additional argument to pass to fn - * @returns {Array} a - * @function - */ -((function () { - const vec = create$1(); - return function (a, stride, offset, count, fn, arg) { - let i; - let l; - if (!stride) { - stride = 2; - } - if (!offset) { - offset = 0; - } - if (count) { - l = Math.min(count * stride + offset, a.length); - } - else { - l = a.length; - } - for (i = offset; i < l; i += stride) { - vec[0] = a[i]; - vec[1] = a[i + 1]; - fn(vec, vec, arg); - a[i] = vec[0]; - a[i + 1] = vec[1]; - } - return a; - }; -}))(); - -// math.gl -// vec3 additions -// Transform as vector, only uses 3x3 minor matrix -function vec3_transformMat4AsVector(out, a, m) { - const x = a[0]; - const y = a[1]; - const z = a[2]; - const w = m[3] * x + m[7] * y + m[11] * z || 1.0; - out[0] = (m[0] * x + m[4] * y + m[8] * z) / w; - out[1] = (m[1] * x + m[5] * y + m[9] * z) / w; - out[2] = (m[2] * x + m[6] * y + m[10] * z) / w; - return out; -} -function vec3_transformMat2(out, a, m) { - const x = a[0]; - const y = a[1]; - out[0] = m[0] * x + m[2] * y; - out[1] = m[1] * x + m[3] * y; - out[2] = a[2]; - return out; -} -function vec4_transformMat3(out, a, m) { - const x = a[0]; - const y = a[1]; - const z = a[2]; - out[0] = m[0] * x + m[3] * y + m[6] * z; - out[1] = m[1] * x + m[4] * y + m[7] * z; - out[2] = m[2] * x + m[5] * y + m[8] * z; - out[3] = a[3]; - return out; -} - -// @eslint-disable -/** - * 3 Dimensional Vector - * @module vec3 - */ -/** - * Creates a new, empty vec3 - * - * @returns {vec3} a new 3D vector - */ -function create() { - const out = new ARRAY_TYPE(3); - if (ARRAY_TYPE != Float32Array) { - out[0] = 0; - out[1] = 0; - out[2] = 0; - } - return out; -} -/** - * Calculates the dot product of two vec3's - * - * @param {ReadonlyVec3} a the first operand - * @param {ReadonlyVec3} b the second operand - * @returns {Number} dot product of a and b - */ -function dot(a, b) { - return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; -} -/** - * Computes the cross product of two vec3's - * - * @param {vec3} out the receiving vector - * @param {ReadonlyVec3} a the first operand - * @param {ReadonlyVec3} b the second operand - * @returns {vec3} out - */ -function cross(out, a, b) { - const ax = a[0]; - const ay = a[1]; - const az = a[2]; - const bx = b[0]; - const by = b[1]; - const bz = b[2]; - out[0] = ay * bz - az * by; - out[1] = az * bx - ax * bz; - out[2] = ax * by - ay * bx; - return out; -} -/** - * Transforms the vec3 with a mat4. - * 4th vector component is implicitly '1' - * - * @param {vec3} out the receiving vector - * @param {ReadonlyVec3} a the vector to transform - * @param {ReadonlyMat4} m matrix to transform with - * @returns {vec3} out - */ -function transformMat4(out, a, m) { - const x = a[0]; - const y = a[1]; - const z = a[2]; - let w = m[3] * x + m[7] * y + m[11] * z + m[15]; - w = w || 1.0; - out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w; - out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w; - out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w; - return out; -} -/** - * Transforms the vec3 with a mat3. - * - * @param {vec3} out the receiving vector - * @param {ReadonlyVec3} a the vector to transform - * @param {ReadonlyMat3} m the 3x3 matrix to transform with - * @returns {vec3} out - */ -function transformMat3(out, a, m) { - const x = a[0]; - const y = a[1]; - const z = a[2]; - out[0] = x * m[0] + y * m[3] + z * m[6]; - out[1] = x * m[1] + y * m[4] + z * m[7]; - out[2] = x * m[2] + y * m[5] + z * m[8]; - return out; -} -/** - * Transforms the vec3 with a quat - * Can also be used for dual quaternions. (Multiply it with the real part) - * - * @param {vec3} out the receiving vector - * @param {ReadonlyVec3} a the vector to transform - * @param {ReadonlyQuat} q quaternion to transform with - * @returns {vec3} out - */ -function transformQuat(out, a, q) { - // benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed - const qx = q[0]; - const qy = q[1]; - const qz = q[2]; - const qw = q[3]; - const x = a[0]; - const y = a[1]; - const z = a[2]; - // var qvec = [qx, qy, qz]; - // var uv = vec3.cross([], qvec, a); - let uvx = qy * z - qz * y; - let uvy = qz * x - qx * z; - let uvz = qx * y - qy * x; - // var uuv = vec3.cross([], qvec, uv); - let uuvx = qy * uvz - qz * uvy; - let uuvy = qz * uvx - qx * uvz; - let uuvz = qx * uvy - qy * uvx; - // vec3.scale(uv, uv, 2 * w); - const w2 = qw * 2; - uvx *= w2; - uvy *= w2; - uvz *= w2; - // vec3.scale(uuv, uuv, 2); - uuvx *= 2; - uuvy *= 2; - uuvz *= 2; - // return vec3.add(out, a, vec3.add(out, uv, uuv)); - out[0] = x + uvx + uuvx; - out[1] = y + uvy + uuvy; - out[2] = z + uvz + uuvz; - return out; -} -/** - * Rotate a 3D vector around the x-axis - * @param {vec3} out The receiving vec3 - * @param {ReadonlyVec3} a The vec3 point to rotate - * @param {ReadonlyVec3} b The origin of the rotation - * @param {Number} rad The angle of rotation in radians - * @returns {vec3} out - */ -function rotateX(out, a, b, rad) { - const p = []; - const r = []; - // Translate point to the origin - p[0] = a[0] - b[0]; - p[1] = a[1] - b[1]; - p[2] = a[2] - b[2]; - // perform rotation - r[0] = p[0]; - r[1] = p[1] * Math.cos(rad) - p[2] * Math.sin(rad); - r[2] = p[1] * Math.sin(rad) + p[2] * Math.cos(rad); - // translate to correct position - out[0] = r[0] + b[0]; - out[1] = r[1] + b[1]; - out[2] = r[2] + b[2]; - return out; -} -/** - * Rotate a 3D vector around the y-axis - * @param {vec3} out The receiving vec3 - * @param {ReadonlyVec3} a The vec3 point to rotate - * @param {ReadonlyVec3} b The origin of the rotation - * @param {Number} rad The angle of rotation in radians - * @returns {vec3} out - */ -function rotateY(out, a, b, rad) { - const p = []; - const r = []; - // Translate point to the origin - p[0] = a[0] - b[0]; - p[1] = a[1] - b[1]; - p[2] = a[2] - b[2]; - // perform rotation - r[0] = p[2] * Math.sin(rad) + p[0] * Math.cos(rad); - r[1] = p[1]; - r[2] = p[2] * Math.cos(rad) - p[0] * Math.sin(rad); - // translate to correct position - out[0] = r[0] + b[0]; - out[1] = r[1] + b[1]; - out[2] = r[2] + b[2]; - return out; -} -/** - * Rotate a 3D vector around the z-axis - * @param {vec3} out The receiving vec3 - * @param {ReadonlyVec3} a The vec3 point to rotate - * @param {ReadonlyVec3} b The origin of the rotation - * @param {Number} rad The angle of rotation in radians - * @returns {vec3} out - */ -function rotateZ(out, a, b, rad) { - const p = []; - const r = []; - // Translate point to the origin - p[0] = a[0] - b[0]; - p[1] = a[1] - b[1]; - p[2] = a[2] - b[2]; - // perform rotation - r[0] = p[0] * Math.cos(rad) - p[1] * Math.sin(rad); - r[1] = p[0] * Math.sin(rad) + p[1] * Math.cos(rad); - r[2] = p[2]; - // translate to correct position - out[0] = r[0] + b[0]; - out[1] = r[1] + b[1]; - out[2] = r[2] + b[2]; - return out; -} -/** - * Get the angle between two 3D vectors - * @param {ReadonlyVec3} a The first operand - * @param {ReadonlyVec3} b The second operand - * @returns {Number} The angle in radians - */ -function angle$1(a, b) { - const ax = a[0]; - const ay = a[1]; - const az = a[2]; - const bx = b[0]; - const by = b[1]; - const bz = b[2]; - const mag = Math.sqrt((ax * ax + ay * ay + az * az) * (bx * bx + by * by + bz * bz)); - const cosine = mag && dot(a, b) / mag; - return Math.acos(Math.min(Math.max(cosine, -1), 1)); -} -/** - * Perform some operation over an array of vec3s. - * - * @param {Array} a the array of vectors to iterate over - * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed - * @param {Number} offset Number of elements to skip at the beginning of the array - * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array - * @param {Function} fn Function to call for each vector in the array - * @param {Object} [arg] additional argument to pass to fn - * @returns {Array} a - * @function - */ -((function () { - const vec = create(); - return function (a, stride, offset, count, fn, arg) { - let i; - let l; - if (!stride) { - stride = 3; - } - if (!offset) { - offset = 0; - } - if (count) { - l = Math.min(count * stride + offset, a.length); - } - else { - l = a.length; - } - for (i = offset; i < l; i += stride) { - vec[0] = a[i]; - vec[1] = a[i + 1]; - vec[2] = a[i + 2]; - fn(vec, vec, arg); - a[i] = vec[0]; - a[i + 1] = vec[1]; - a[i + 2] = vec[2]; - } - return a; - }; -}))(); - -// math.gl -const ORIGIN = [0, 0, 0]; -let ZERO$1; -/** - * Three-element vector class with common linear algebra operations. - * Subclass of Array meaning that it is highly compatible with other libraries - */ -class Vector3 extends Vector$1 { - static get ZERO() { - if (!ZERO$1) { - ZERO$1 = new Vector3(0, 0, 0); - Object.freeze(ZERO$1); - } - return ZERO$1; - } - /** - * @class - * @param x - * @param y - * @param z - */ - constructor(x = 0, y = 0, z = 0) { - // PERF NOTE: initialize elements as double precision numbers - super(-0, -0, -0); - if (arguments.length === 1 && isArray(x)) { - this.copy(x); - } - else { - // this.set(x, y, z); - if (config.debug) { - checkNumber(x); - checkNumber(y); - checkNumber(z); - } - // @ts-expect-error TS2412: Property '0' of type 'number | [number, number, number]' is not assignable to numeric index type 'number' - this[0] = x; - this[1] = y; - this[2] = z; - } - } - set(x, y, z) { - this[0] = x; - this[1] = y; - this[2] = z; - return this.check(); - } - copy(array) { - this[0] = array[0]; - this[1] = array[1]; - this[2] = array[2]; - return this.check(); - } - fromObject(object) { - if (config.debug) { - checkNumber(object.x); - checkNumber(object.y); - checkNumber(object.z); - } - this[0] = object.x; - this[1] = object.y; - this[2] = object.z; - return this.check(); - } - toObject(object) { - object.x = this[0]; - object.y = this[1]; - object.z = this[2]; - return object; - } - // Getters/setters - get ELEMENTS() { - return 3; - } - get z() { - return this[2]; - } - set z(value) { - this[2] = checkNumber(value); - } - // ACCESSORS - angle(vector) { - return angle$1(this, vector); - } - // MODIFIERS - cross(vector) { - cross(this, this, vector); - return this.check(); - } - rotateX({ radians, origin = ORIGIN }) { - rotateX(this, this, origin, radians); - return this.check(); - } - rotateY({ radians, origin = ORIGIN }) { - rotateY(this, this, origin, radians); - return this.check(); - } - rotateZ({ radians, origin = ORIGIN }) { - rotateZ(this, this, origin, radians); - return this.check(); - } - // Transforms - // transforms as point (4th component is implicitly 1) - transform(matrix4) { - return this.transformAsPoint(matrix4); - } - // transforms as point (4th component is implicitly 1) - transformAsPoint(matrix4) { - transformMat4(this, this, matrix4); - return this.check(); - } - // transforms as vector (4th component is implicitly 0, ignores translation. slightly faster) - transformAsVector(matrix4) { - vec3_transformMat4AsVector(this, this, matrix4); - return this.check(); - } - transformByMatrix3(matrix3) { - transformMat3(this, this, matrix3); - return this.check(); - } - transformByMatrix2(matrix2) { - vec3_transformMat2(this, this, matrix2); - return this.check(); - } - transformByQuaternion(quaternion) { - transformQuat(this, this, quaternion); - return this.check(); - } -} - -// math.gl -/** Base class for matrices */ -class Matrix extends MathArray { - // fromObject(object) { - // const array = object.elements; - // return this.fromRowMajor(array); - // } - // toObject(object) { - // const array = object.elements; - // this.toRowMajor(array); - // return object; - // } - // TODO better override formatString? - toString() { - let string = '['; - if (config.printRowMajor) { - string += 'row-major:'; - for (let row = 0; row < this.RANK; ++row) { - for (let col = 0; col < this.RANK; ++col) { - string += ` ${this[col * this.RANK + row]}`; - } - } - } - else { - string += 'column-major:'; - for (let i = 0; i < this.ELEMENTS; ++i) { - string += ` ${this[i]}`; - } - } - string += ']'; - return string; - } - getElementIndex(row, col) { - return col * this.RANK + row; - } - // By default assumes row major indices - getElement(row, col) { - return this[col * this.RANK + row]; - } - // By default assumes row major indices - setElement(row, col, value) { - this[col * this.RANK + row] = checkNumber(value); - return this; - } - getColumn(columnIndex, result = new Array(this.RANK).fill(-0)) { - const firstIndex = columnIndex * this.RANK; - for (let i = 0; i < this.RANK; ++i) { - result[i] = this[firstIndex + i]; - } - return result; - } - setColumn(columnIndex, columnVector) { - const firstIndex = columnIndex * this.RANK; - for (let i = 0; i < this.RANK; ++i) { - this[firstIndex + i] = columnVector[i]; - } - return this; - } -} - -/** - * Transpose the values of a mat3 - * - * @param {mat3} out the receiving matrix - * @param {ReadonlyMat3} a the source matrix - * @returns {mat3} out - */ -function transpose(out, a) { - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (out === a) { - const a01 = a[1]; - const a02 = a[2]; - const a12 = a[5]; - out[1] = a[3]; - out[2] = a[6]; - out[3] = a01; - out[5] = a[7]; - out[6] = a02; - out[7] = a12; - } - else { - out[0] = a[0]; - out[1] = a[3]; - out[2] = a[6]; - out[3] = a[1]; - out[4] = a[4]; - out[5] = a[7]; - out[6] = a[2]; - out[7] = a[5]; - out[8] = a[8]; - } - return out; -} -/** - * Inverts a mat3 - * - * @param {mat3} out the receiving matrix - * @param {ReadonlyMat3} a the source matrix - * @returns {mat3} out - */ -function invert(out, a) { - const a00 = a[0]; - const a01 = a[1]; - const a02 = a[2]; - const a10 = a[3]; - const a11 = a[4]; - const a12 = a[5]; - const a20 = a[6]; - const a21 = a[7]; - const a22 = a[8]; - const b01 = a22 * a11 - a12 * a21; - const b11 = -a22 * a10 + a12 * a20; - const b21 = a21 * a10 - a11 * a20; - // Calculate the determinant - let det = a00 * b01 + a01 * b11 + a02 * b21; - if (!det) { - return null; - } - det = 1.0 / det; - out[0] = b01 * det; - out[1] = (-a22 * a01 + a02 * a21) * det; - out[2] = (a12 * a01 - a02 * a11) * det; - out[3] = b11 * det; - out[4] = (a22 * a00 - a02 * a20) * det; - out[5] = (-a12 * a00 + a02 * a10) * det; - out[6] = b21 * det; - out[7] = (-a21 * a00 + a01 * a20) * det; - out[8] = (a11 * a00 - a01 * a10) * det; - return out; -} -/** - * Calculates the determinant of a mat3 - * - * @param {ReadonlyMat3} a the source matrix - * @returns {Number} determinant of a - */ -function determinant(a) { - const a00 = a[0]; - const a01 = a[1]; - const a02 = a[2]; - const a10 = a[3]; - const a11 = a[4]; - const a12 = a[5]; - const a20 = a[6]; - const a21 = a[7]; - const a22 = a[8]; - return (a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20)); -} -/** - * Multiplies two mat3's - * - * @param {mat3} out the receiving matrix - * @param {ReadonlyMat3} a the first operand - * @param {ReadonlyMat3} b the second operand - * @returns {mat3} out - */ -function multiply(out, a, b) { - const a00 = a[0]; - const a01 = a[1]; - const a02 = a[2]; - const a10 = a[3]; - const a11 = a[4]; - const a12 = a[5]; - const a20 = a[6]; - const a21 = a[7]; - const a22 = a[8]; - const b00 = b[0]; - const b01 = b[1]; - const b02 = b[2]; - const b10 = b[3]; - const b11 = b[4]; - const b12 = b[5]; - const b20 = b[6]; - const b21 = b[7]; - const b22 = b[8]; - out[0] = b00 * a00 + b01 * a10 + b02 * a20; - out[1] = b00 * a01 + b01 * a11 + b02 * a21; - out[2] = b00 * a02 + b01 * a12 + b02 * a22; - out[3] = b10 * a00 + b11 * a10 + b12 * a20; - out[4] = b10 * a01 + b11 * a11 + b12 * a21; - out[5] = b10 * a02 + b11 * a12 + b12 * a22; - out[6] = b20 * a00 + b21 * a10 + b22 * a20; - out[7] = b20 * a01 + b21 * a11 + b22 * a21; - out[8] = b20 * a02 + b21 * a12 + b22 * a22; - return out; -} -/** - * Translate a mat3 by the given vector - * - * @param {mat3} out the receiving matrix - * @param {ReadonlyMat3} a the matrix to translate - * @param {ReadonlyVec2} v vector to translate by - * @returns {mat3} out - */ -function translate(out, a, v) { - const a00 = a[0]; - const a01 = a[1]; - const a02 = a[2]; - const a10 = a[3]; - const a11 = a[4]; - const a12 = a[5]; - const a20 = a[6]; - const a21 = a[7]; - const a22 = a[8]; - const x = v[0]; - const y = v[1]; - out[0] = a00; - out[1] = a01; - out[2] = a02; - out[3] = a10; - out[4] = a11; - out[5] = a12; - out[6] = x * a00 + y * a10 + a20; - out[7] = x * a01 + y * a11 + a21; - out[8] = x * a02 + y * a12 + a22; - return out; -} -/** - * Rotates a mat3 by the given angle - * - * @param {mat3} out the receiving matrix - * @param {ReadonlyMat3} a the matrix to rotate - * @param {Number} rad the angle to rotate the matrix by - * @returns {mat3} out - */ -function rotate(out, a, rad) { - const a00 = a[0]; - const a01 = a[1]; - const a02 = a[2]; - const a10 = a[3]; - const a11 = a[4]; - const a12 = a[5]; - const a20 = a[6]; - const a21 = a[7]; - const a22 = a[8]; - const s = Math.sin(rad); - const c = Math.cos(rad); - out[0] = c * a00 + s * a10; - out[1] = c * a01 + s * a11; - out[2] = c * a02 + s * a12; - out[3] = c * a10 - s * a00; - out[4] = c * a11 - s * a01; - out[5] = c * a12 - s * a02; - out[6] = a20; - out[7] = a21; - out[8] = a22; - return out; -} -/** - * Scales the mat3 by the dimensions in the given vec2 - * - * @param {mat3} out the receiving matrix - * @param {ReadonlyMat3} a the matrix to scale - * @param {ReadonlyVec2} v the vec2 to scale the matrix by - * @returns {mat3} out - **/ -function scale(out, a, v) { - const x = v[0]; - const y = v[1]; - out[0] = x * a[0]; - out[1] = x * a[1]; - out[2] = x * a[2]; - out[3] = y * a[3]; - out[4] = y * a[4]; - out[5] = y * a[5]; - out[6] = a[6]; - out[7] = a[7]; - out[8] = a[8]; - return out; -} -/** - * Calculates a 3x3 matrix from the given quaternion - * - * @param {mat3} out mat3 receiving operation result - * @param {ReadonlyQuat} q Quaternion to create matrix from - * - * @returns {mat3} out - */ -function fromQuat(out, q) { - const x = q[0]; - const y = q[1]; - const z = q[2]; - const w = q[3]; - const x2 = x + x; - const y2 = y + y; - const z2 = z + z; - const xx = x * x2; - const yx = y * x2; - const yy = y * y2; - const zx = z * x2; - const zy = z * y2; - const zz = z * z2; - const wx = w * x2; - const wy = w * y2; - const wz = w * z2; - out[0] = 1 - yy - zz; - out[3] = yx - wz; - out[6] = zx + wy; - out[1] = yx + wz; - out[4] = 1 - xx - zz; - out[7] = zy - wx; - out[2] = zx - wy; - out[5] = zy + wx; - out[8] = 1 - xx - yy; - return out; -} - -// math.gl -// eslint-disable-next-line no-shadow -var INDICES; -(function (INDICES) { - INDICES[INDICES["COL0ROW0"] = 0] = "COL0ROW0"; - INDICES[INDICES["COL0ROW1"] = 1] = "COL0ROW1"; - INDICES[INDICES["COL0ROW2"] = 2] = "COL0ROW2"; - INDICES[INDICES["COL1ROW0"] = 3] = "COL1ROW0"; - INDICES[INDICES["COL1ROW1"] = 4] = "COL1ROW1"; - INDICES[INDICES["COL1ROW2"] = 5] = "COL1ROW2"; - INDICES[INDICES["COL2ROW0"] = 6] = "COL2ROW0"; - INDICES[INDICES["COL2ROW1"] = 7] = "COL2ROW1"; - INDICES[INDICES["COL2ROW2"] = 8] = "COL2ROW2"; -})(INDICES || (INDICES = {})); -const IDENTITY_MATRIX = Object.freeze([1, 0, 0, 0, 1, 0, 0, 0, 1]); -/** - * A 3x3 matrix with common linear algebra operations - * Subclass of Array meaning that it is highly compatible with other libraries - */ -class Matrix3 extends Matrix { - static get IDENTITY() { - return getIdentityMatrix(); - } - static get ZERO() { - return getZeroMatrix(); - } - get ELEMENTS() { - return 9; - } - get RANK() { - return 3; - } - get INDICES() { - return INDICES; - } - constructor(array, ...args) { - // PERF NOTE: initialize elements as double precision numbers - super(-0, -0, -0, -0, -0, -0, -0, -0, -0); - if (arguments.length === 1 && Array.isArray(array)) { - this.copy(array); - } - else if (args.length > 0) { - this.copy([array, ...args]); - } - else { - this.identity(); - } - } - copy(array) { - // Element wise copy for performance - this[0] = array[0]; - this[1] = array[1]; - this[2] = array[2]; - this[3] = array[3]; - this[4] = array[4]; - this[5] = array[5]; - this[6] = array[6]; - this[7] = array[7]; - this[8] = array[8]; - return this.check(); - } - // Constructors - identity() { - return this.copy(IDENTITY_MATRIX); - } - /** - * - * @param object - * @returns self - */ - // eslint-disable-next-line @typescript-eslint/no-unused-vars - fromObject(object) { - return this.check(); - } - /** Calculates a 3x3 matrix from the given quaternion - * q quat Quaternion to create matrix from - */ - fromQuaternion(q) { - fromQuat(this, q); - return this.check(); - } - /** - * accepts column major order, stores in column major order - */ - // eslint-disable-next-line max-params - set(m00, m10, m20, m01, m11, m21, m02, m12, m22) { - this[0] = m00; - this[1] = m10; - this[2] = m20; - this[3] = m01; - this[4] = m11; - this[5] = m21; - this[6] = m02; - this[7] = m12; - this[8] = m22; - return this.check(); - } - /** - * accepts row major order, stores as column major - */ - // eslint-disable-next-line max-params - setRowMajor(m00, m01, m02, m10, m11, m12, m20, m21, m22) { - this[0] = m00; - this[1] = m10; - this[2] = m20; - this[3] = m01; - this[4] = m11; - this[5] = m21; - this[6] = m02; - this[7] = m12; - this[8] = m22; - return this.check(); - } - // Accessors - determinant() { - return determinant(this); - } - // Modifiers - transpose() { - transpose(this, this); - return this.check(); - } - /** Invert a matrix. Note that this can fail if the matrix is not invertible */ - invert() { - invert(this, this); - return this.check(); - } - // Operations - multiplyLeft(a) { - multiply(this, a, this); - return this.check(); - } - multiplyRight(a) { - multiply(this, this, a); - return this.check(); - } - rotate(radians) { - rotate(this, this, radians); - return this.check(); - } - scale(factor) { - if (Array.isArray(factor)) { - scale(this, this, factor); - } - else { - scale(this, this, [factor, factor]); - } - return this.check(); - } - translate(vec) { - translate(this, this, vec); - return this.check(); - } - // Transforms - transform(vector, result) { - let out; - switch (vector.length) { - case 2: - out = transformMat3$1(result || [-0, -0], vector, this); - break; - case 3: - out = transformMat3(result || [-0, -0, -0], vector, this); - break; - case 4: - out = vec4_transformMat3(result || [-0, -0, -0, -0], vector, this); - break; - default: - throw new Error('Illegal vector'); - } - checkVector(out, vector.length); - return out; - } - /** @deprecated */ - transformVector(vector, result) { - return this.transform(vector, result); - } - /** @deprecated */ - transformVector2(vector, result) { - return this.transform(vector, result); - } - /** @deprecated */ - transformVector3(vector, result) { - return this.transform(vector, result); - } -} -let ZERO_MATRIX3; -let IDENTITY_MATRIX3 = null; -function getZeroMatrix() { - if (!ZERO_MATRIX3) { - ZERO_MATRIX3 = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]); - Object.freeze(ZERO_MATRIX3); - } - return ZERO_MATRIX3; -} -function getIdentityMatrix() { - if (!IDENTITY_MATRIX3) { - IDENTITY_MATRIX3 = new Matrix3(); - Object.freeze(IDENTITY_MATRIX3); - } - return IDENTITY_MATRIX3; -} - -/** - * https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/README.md - */ -/** Extension name */ -const KHR_TEXTURE_TRANSFORM = 'KHR_texture_transform'; -const name$3 = KHR_TEXTURE_TRANSFORM; -const scratchVector = new Vector3(); -const scratchRotationMatrix = new Matrix3(); -const scratchScaleMatrix = new Matrix3(); -/** - * The extension entry to process the transformation - * @param gltfData gltf buffers and json - * @param options GLTFLoader options - */ -async function decode$5(gltfData, options) { - const gltfScenegraph = new GLTFScenegraph(gltfData); - const hasExtension = gltfScenegraph.hasExtension(KHR_TEXTURE_TRANSFORM); - if (!hasExtension || !options.gltf?.loadBuffers) { - return; - } - const materials = gltfData.json.materials || []; - for (let i = 0; i < materials.length; i++) { - transformTexCoords(i, gltfData); - } -} -/** - * Transform TEXCOORD by material - * @param materialIndex processing material index - * @param gltfData gltf buffers and json - */ -function transformTexCoords(materialIndex, gltfData) { - const material = gltfData.json.materials?.[materialIndex]; - const materialTextures = [ - material?.pbrMetallicRoughness?.baseColorTexture, - material?.emissiveTexture, - material?.normalTexture, - material?.occlusionTexture, - material?.pbrMetallicRoughness?.metallicRoughnessTexture - ]; - // Save processed texCoords in order no to process the same twice - const processedTexCoords = []; - for (const textureInfo of materialTextures) { - if (textureInfo && textureInfo?.extensions?.[KHR_TEXTURE_TRANSFORM]) { - transformPrimitives(gltfData, materialIndex, textureInfo, processedTexCoords); - } - } -} -/** - * Transform primitives of the particular material - * @param gltfData gltf data - * @param materialIndex primitives with this material will be transformed - * @param texture texture object - * @param processedTexCoords storage to save already processed texCoords - */ -function transformPrimitives(gltfData, materialIndex, texture, processedTexCoords) { - const transformParameters = getTransformParameters(texture, processedTexCoords); - if (!transformParameters) { - return; - } - const meshes = gltfData.json.meshes || []; - for (const mesh of meshes) { - for (const primitive of mesh.primitives) { - const material = primitive.material; - if (Number.isFinite(material) && materialIndex === material) { - transformPrimitive(gltfData, primitive, transformParameters); - } - } - } -} -/** - * Get parameters for TEXCOORD transformation - * @param texture texture object - * @param processedTexCoords storage to save already processed texCoords - * @returns texCoord couple and transformation matrix - */ -function getTransformParameters(texture, processedTexCoords) { - const textureInfo = texture.extensions?.[KHR_TEXTURE_TRANSFORM]; - const { texCoord: originalTexCoord = 0 } = texture; - // If texCoord is not set in the extension, original attribute data will be replaced - const { texCoord = originalTexCoord } = textureInfo; - // Make sure that couple [originalTexCoord, extensionTexCoord] is not processed twice - const isProcessed = processedTexCoords.findIndex(([original, newTexCoord]) => original === originalTexCoord && newTexCoord === texCoord) !== -1; - if (!isProcessed) { - const matrix = makeTransformationMatrix(textureInfo); - if (originalTexCoord !== texCoord) { - texture.texCoord = texCoord; - } - processedTexCoords.push([originalTexCoord, texCoord]); - return { originalTexCoord, texCoord, matrix }; - } - return null; -} -/** - * Transform `TEXCOORD_0` attribute in the primitive - * @param gltfData gltf data - * @param primitive primitive object - * @param transformParameters texCoord couple and transformation matrix - */ -function transformPrimitive(gltfData, primitive, transformParameters) { - const { originalTexCoord, texCoord, matrix } = transformParameters; - const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`]; - if (Number.isFinite(texCoordAccessor)) { - // Get accessor of the `TEXCOORD_0` attribute - const accessor = gltfData.json.accessors?.[texCoordAccessor]; - if (accessor && accessor.bufferView) { - // Get `bufferView` of the `accessor` - const bufferView = gltfData.json.bufferViews?.[accessor.bufferView]; - if (bufferView) { - // Get `arrayBuffer` the `bufferView` look at - const { arrayBuffer, byteOffset: bufferByteOffset } = gltfData.buffers[bufferView.buffer]; - // Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets - const byteOffset = (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0); - // Deduce TypedArray type and its length from `accessor` and `bufferView` data - const { ArrayType, length } = getAccessorArrayTypeAndLength(accessor, bufferView); - // Number of bytes each component occupies - const bytes = BYTES$1[accessor.componentType]; - // Number of components. For the `TEXCOORD_0` with `VEC2` type, it must return 2 - const components = COMPONENTS$1[accessor.type]; - // Multiplier to calculate the address of the `TEXCOORD_0` element in the arrayBuffer - const elementAddressScale = bufferView.byteStride || bytes * components; - // Data transform to Float32Array - const result = new Float32Array(length); - for (let i = 0; i < accessor.count; i++) { - // Take [u, v] couple from the arrayBuffer - const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2); - // Set and transform Vector3 per https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#overview - scratchVector.set(uv[0], uv[1], 1); - scratchVector.transformByMatrix3(matrix); - // Save result in Float32Array - result.set([scratchVector[0], scratchVector[1]], i * components); - } - // If texCoord the same, replace gltf structural data - if (originalTexCoord === texCoord) { - updateGltf(accessor, bufferView, gltfData.buffers, result); - } - else { - // If texCoord change, create new attribute - createAttribute(texCoord, accessor, primitive, gltfData, result); - } - } - } - } -} -/** - * Update GLTF structural objects with new data as we create new `Float32Array` for `TEXCOORD_0`. - * @param accessor accessor to change - * @param bufferView bufferView to change - * @param buffers binary buffers - * @param newTexcoordArray typed array with data after transformation - */ -function updateGltf(accessor, bufferView, buffers, newTexCoordArray) { - accessor.componentType = 5126; - buffers.push({ - arrayBuffer: newTexCoordArray.buffer, - byteOffset: 0, - byteLength: newTexCoordArray.buffer.byteLength - }); - bufferView.buffer = buffers.length - 1; - bufferView.byteLength = newTexCoordArray.buffer.byteLength; - bufferView.byteOffset = 0; - delete bufferView.byteStride; -} -/** - * - * @param newTexCoord new `texCoord` value - * @param originalAccessor original accessor object, that store data before transformation - * @param primitive primitive object - * @param gltfData gltf data - * @param newTexCoordArray typed array with data after transformation - * @returns - */ -function createAttribute(newTexCoord, originalAccessor, primitive, gltfData, newTexCoordArray) { - gltfData.buffers.push({ - arrayBuffer: newTexCoordArray.buffer, - byteOffset: 0, - byteLength: newTexCoordArray.buffer.byteLength - }); - const bufferViews = gltfData.json.bufferViews; - if (!bufferViews) { - return; - } - bufferViews.push({ - buffer: gltfData.buffers.length - 1, - byteLength: newTexCoordArray.buffer.byteLength, - byteOffset: 0 - }); - const accessors = gltfData.json.accessors; - if (!accessors) { - return; - } - accessors.push({ - bufferView: bufferViews?.length - 1, - byteOffset: 0, - componentType: 5126, - count: originalAccessor.count, - type: 'VEC2' - }); - primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1; -} -/** - * Construct transformation matrix from the extension data (transition, rotation, scale) - * @param extensionData extension data - * @returns transformation matrix - */ -function makeTransformationMatrix(extensionData) { - const { offset = [0, 0], rotation = 0, scale = [1, 1] } = extensionData; - const translationMatrix = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1); - const rotationMatrix = scratchRotationMatrix.set(Math.cos(rotation), Math.sin(rotation), 0, -Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1); - const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1); - return translationMatrix.multiplyRight(rotationMatrix).multiplyRight(scaleMatrix); -} - -var KHR_texture_transform = /*#__PURE__*/Object.freeze({ - __proto__: null, - name: name$3, - decode: decode$5 -}); - -// GLTF EXTENSION: KHR_lights_punctual -const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual'; -const name$2 = KHR_LIGHTS_PUNCTUAL; -async function decode$4(gltfData) { - const gltfScenegraph = new GLTFScenegraph(gltfData); - const { json } = gltfScenegraph; - // Move the light array out of the extension and remove the extension - const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL); - if (extension) { - // @ts-ignore - gltfScenegraph.json.lights = extension.lights; - gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL); - } - // Any nodes that have the extension, add lights field pointing to light object - // and remove the extension - for (const node of json.nodes || []) { - const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL); - if (nodeExtension) { - // @ts-ignore - node.light = nodeExtension.light; - } - gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL); - } -} -// Move the light ar ray out of the extension and remove the extension -async function encode$2(gltfData) { - const gltfScenegraph = new GLTFScenegraph(gltfData); - const { json } = gltfScenegraph; - // @ts-ignore - if (json.lights) { - const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL); - // @ts-ignore - assert$1(!extension.lights); - // @ts-ignore - extension.lights = json.lights; - // @ts-ignore - delete json.lights; - } - // Any nodes that have lights field pointing to light object - // add the extension - // @ts-ignore - if (gltfScenegraph.json.lights) { - // @ts-ignore - for (const light of gltfScenegraph.json.lights) { - const node = light.node; - gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light); - } - // @ts-ignore - delete gltfScenegraph.json.lights; - } -} - -var KHR_lights_punctual = /*#__PURE__*/Object.freeze({ - __proto__: null, - name: name$2, - decode: decode$4, - encode: encode$2 -}); - -// GLTF EXTENSION: KHR_materials_unlit -const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit'; -const name$1 = KHR_MATERIALS_UNLIT; -async function decode$3(gltfData) { - const gltfScenegraph = new GLTFScenegraph(gltfData); - const { json } = gltfScenegraph; - // Any nodes that have the extension, add lights field pointing to light object - // and remove the extension - for (const material of json.materials || []) { - const extension = material.extensions && material.extensions.KHR_materials_unlit; - if (extension) { - // @ts-ignore TODO - material.unlit = true; - } - gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT); - } - // Remove the top-level extension - gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT); -} -function encode$1(gltfData) { - const gltfScenegraph = new GLTFScenegraph(gltfData); - const { json } = gltfScenegraph; - // Any nodes that have lights field pointing to light object - // add the extension - // @ts-ignore - if (gltfScenegraph.materials) { - for (const material of json.materials || []) { - // @ts-ignore - if (material.unlit) { - // @ts-ignore - delete material.unlit; - gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {}); - gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT); - } - } - } -} - -var KHR_materials_unlit = /*#__PURE__*/Object.freeze({ - __proto__: null, - name: name$1, - decode: decode$3, - encode: encode$1 -}); - -// GLTF EXTENSION: KHR_techniques_webgl -const KHR_TECHNIQUES_WEBGL = 'KHR_techniques_webgl'; -const name = KHR_TECHNIQUES_WEBGL; -async function decode$2(gltfData) { - const gltfScenegraph = new GLTFScenegraph(gltfData); - const { json } = gltfScenegraph; - const extension = gltfScenegraph.getExtension(KHR_TECHNIQUES_WEBGL); - if (extension) { - const techniques = resolveTechniques(extension, gltfScenegraph); - for (const material of json.materials || []) { - const materialExtension = gltfScenegraph.getObjectExtension(material, KHR_TECHNIQUES_WEBGL); - if (materialExtension) { - // @ts-ignore TODO - material.technique = Object.assign({}, materialExtension, - // @ts-ignore - techniques[materialExtension.technique]); - // @ts-ignore TODO - material.technique.values = resolveValues(material.technique, gltfScenegraph); - } - gltfScenegraph.removeObjectExtension(material, KHR_TECHNIQUES_WEBGL); - } - // Remove the top-level extension - gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL); - } -} -// eslint-disable-next-line -async function encode(gltfData, options) { - // TODO -} -function resolveTechniques(techniquesExtension, -// programs: {[key: string]: any}[], -// shaders: {[key: string]: any}[], -// techniques: {[key: string]: any}[] -gltfScenegraph) { - const { programs = [], shaders = [], techniques = [] } = techniquesExtension; - const textDecoder = new TextDecoder(); - shaders.forEach((shader) => { - if (Number.isFinite(shader.bufferView)) { - shader.code = textDecoder.decode(gltfScenegraph.getTypedArrayForBufferView(shader.bufferView)); - } - else { - // TODO: handle URI shader - throw new Error('KHR_techniques_webgl: no shader code'); - } - }); - programs.forEach((program) => { - program.fragmentShader = shaders[program.fragmentShader]; - program.vertexShader = shaders[program.vertexShader]; - }); - techniques.forEach((technique) => { - technique.program = programs[technique.program]; - }); - return techniques; -} -function resolveValues(technique, gltfScenegraph) { - const values = Object.assign({}, technique.values); - // merge values from uniforms - Object.keys(technique.uniforms || {}).forEach((uniform) => { - if (technique.uniforms[uniform].value && !(uniform in values)) { - values[uniform] = technique.uniforms[uniform].value; - } - }); - // resolve textures - Object.keys(values).forEach((uniform) => { - if (typeof values[uniform] === 'object' && values[uniform].index !== undefined) { - // Assume this is a texture - // TODO: find if there are any other types that can be referenced - values[uniform].texture = gltfScenegraph.getTexture(values[uniform].index); - } - }); - return values; -} - -var KHR_techniques_webgl = /*#__PURE__*/Object.freeze({ - __proto__: null, - name: name, - decode: decode$2, - encode: encode -}); - -// GLTF 1.0 extensions (decode only) -/** - * List of extensions processed by the GLTFLoader - * Note that may extensions can only be handled on the rendering stage and are left out here - * These are just extensions that can be handled fully or partially during loading. - */ -const EXTENSIONS = [ - // 1.0 - // KHR_binary_gltf is handled separately - must be processed before other parsing starts - // KHR_binary_gltf, - // 2.0 - EXT_structural_metadata, - EXT_mesh_features, - EXT_meshopt_compression, - EXT_texture_webp, - // Basisu should come after webp, we want basisu to be preferred if both are provided - KHR_texture_basisu, - KHR_draco_mesh_compression, - KHR_lights_punctual, - KHR_materials_unlit, - KHR_techniques_webgl, - KHR_texture_transform, - EXT_feature_metadata -]; -/** Call before any resource loading starts */ -function preprocessExtensions(gltf, options = {}, context) { - const extensions = EXTENSIONS.filter((extension) => useExtension(extension.name, options)); - for (const extension of extensions) { - extension.preprocess?.(gltf, options, context); - } -} -/** Call after resource loading */ -async function decodeExtensions(gltf, options = {}, context) { - const extensions = EXTENSIONS.filter((extension) => useExtension(extension.name, options)); - for (const extension of extensions) { - // Note: We decode async extensions sequentially, this might not be necessary - // Currently we only have Draco, but when we add Basis we may revisit - await extension.decode?.(gltf, options, context); - } -} -function useExtension(extensionName, options) { - const excludes = options?.gltf?.excludeExtensions || {}; - const exclude = extensionName in excludes && !excludes[extensionName]; - return !exclude; -} - -// GLTF 1.0 EXTENSION: KHR_binary_glTF -const KHR_BINARY_GLTF = 'KHR_binary_glTF'; -function preprocess(gltfData) { - const gltfScenegraph = new GLTFScenegraph(gltfData); - const { json } = gltfScenegraph; - // Note: json.buffers.binary_glTF also needs to be replaced - // This is currently done during gltf normalization - // Image and shader nodes can have the extension - // https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/image.KHR_binary_glTF.schema.json - for (const image of json.images || []) { - const extension = gltfScenegraph.getObjectExtension(image, KHR_BINARY_GLTF); - // The data in the extension is valid as glTF 2.0 data inside the object, so just copy it in - if (extension) { - Object.assign(image, extension); - } - gltfScenegraph.removeObjectExtension(image, KHR_BINARY_GLTF); - } - // TODO shaders - At least traverse and throw error if used? - // https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/shader.KHR_binary_glTF.schema.json - // glTF v1 one files have a partially formed URI field that is not expected in (and causes problems in) 2.0 - if (json.buffers && json.buffers[0]) { - delete json.buffers[0].uri; - } - // Remove the top-level extension as it has now been processed - gltfScenegraph.removeExtension(KHR_BINARY_GLTF); -} -// KHR_binary_gltf is a 1.0 extension that is supported natively by 2.0 -// export function encode() { -// throw new Error(KHR_BINARY_GLTF); -// } - -/* eslint-disable camelcase */ -// Binary format changes (mainly implemented by GLBLoader) -// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF -// JSON format changes: -// https://github.com/khronosgroup/gltf/issues/605 -// - [x] Top-level JSON objects are arrays now -// - [ ] Removed indirection from animation: sampler now refers directly to accessors, #712 -// - [ ] material.parameter.value and technique.parameter.value must be an array, #690 -// - [ ] Node can have only one mesh #821 -// - [ ] Added reqs on JSON encoding -// - [ ] Added reqs on binary data alignment #802 (comment) -// Additions: -// - [ ] Added accessor.normalized, #691, #706 -// - [ ] Added glExtensionsUsed property and 5125 (UNSIGNED_INT) accessor.componentType value, #619 -// - [ ] Added extensionsRequired property, #720, #721 -// - [ ] Added "STEP" as valid animation.sampler.interpolation value, #712 -// Removals: -// - [x] Removed buffer.type, #786, #629 -// - [ ] Removed revision number from profile.version, #709 -// - [ ] Removed technique.functions.scissor and removed 3089 (SCISSOR_TEST) as a valid value for technique.states.enable, #681 -// - [ ] Techniques, programs, and shaders were moved out to KHR_technique_webgl extension. -// Other edits: -// - [x] asset is now required, #642 -// - [ ] buffer.byteLength and bufferView.byteLength are now required, #560. -// - [ ] accessor.min and accessor.max are now required, #593, and clarified that the JSON value and binary data must be the same, #628. -// - [ ] Clarified animation.sampler and animation.channel restrictions, #712 -// - [ ] skin.inverseBindMatrices is now optional, #461. -// - [ ] Attribute parameters can't have a value defined in the technique or parameter, #563 (comment). -// - [ ] Only TEXCOORD and COLOR attribute semantics can be written in the form [semantic]_[set_index], #563 (comment). -// - [ ] TEXCOORD and COLOR attribute semantics must be written in the form [semantic]_[set_index], e.g., just TEXCOORD should be TEXCOORD_0, and just COLOR should be COLOR_0, #649 -// - [ ] camera.perspective.aspectRatio and camera.perspective.yfov must now be > 0, not >= 0, #563 (comment). -// - [ ] Application-specific parameter semantics must start with an underscore, e.g., _TEMPERATURE and _SIMULATION_TIME, #563 (comment). -// - [ ] Properties in technique.parameters must be defined in technique.uniforms or technique.attributes, -// #563 (comment). -// - [ ] technique.parameter.count can only be defined when the semantic is JOINTMATRIX or an application-specific semantic is used. It can never be defined for attribute parameters; only uniforms, d2f6945 -// - [ ] technique.parameter.semantic is required when the parameter is an attribute, 28e113d -// - [ ] Mesh-only models are allowed, e.g., without materials, #642 -// - [ ] Skeleton hierarchies (nodes containing jointName) must be separated from non-skeleton hierarchies., #647 -// - [ ] technique.states.functions.blendColor and technique.states.functions.depthRange parameters now must match WebGL function min/max, #707 -const GLTF_ARRAYS = { - accessors: 'accessor', - animations: 'animation', - buffers: 'buffer', - bufferViews: 'bufferView', - images: 'image', - materials: 'material', - meshes: 'mesh', - nodes: 'node', - samplers: 'sampler', - scenes: 'scene', - skins: 'skin', - textures: 'texture' -}; -const GLTF_KEYS = { - accessor: 'accessors', - animations: 'animation', - buffer: 'buffers', - bufferView: 'bufferViews', - image: 'images', - material: 'materials', - mesh: 'meshes', - node: 'nodes', - sampler: 'samplers', - scene: 'scenes', - skin: 'skins', - texture: 'textures' -}; -/** - * Converts (normalizes) glTF v1 to v2 - */ -class GLTFV1Normalizer { - idToIndexMap = { - animations: {}, - accessors: {}, - buffers: {}, - bufferViews: {}, - images: {}, - materials: {}, - meshes: {}, - nodes: {}, - samplers: {}, - scenes: {}, - skins: {}, - textures: {} - }; - json; - // constructor() {} - /** - * Convert (normalize) glTF < 2.0 to glTF 2.0 - * @param gltf - object with json and binChunks - * @param options - * @param options normalize Whether to actually normalize - */ - normalize(gltf, options) { - this.json = gltf.json; - const json = gltf.json; - // Check version - switch (json.asset && json.asset.version) { - // We are converting to v2 format. Return if there is nothing to do - case '2.0': - return; - // This class is written to convert 1.0 - case undefined: - case '1.0': - break; - default: - // eslint-disable-next-line no-undef, no-console - console.warn(`glTF: Unknown version ${json.asset.version}`); - return; - } - if (!options.normalize) { - // We are still missing a few conversion tricks, remove once addressed - throw new Error('glTF v1 is not supported.'); - } - // eslint-disable-next-line no-undef, no-console - console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.'); - this._addAsset(json); - // In glTF2 top-level fields are Arrays not Object maps - this._convertTopLevelObjectsToArrays(json); - // Extract bufferView indices for images - // (this extension needs to be invoked early in the normalization process) - // TODO can this be handled by standard extension processing instead of called explicitly? - preprocess(gltf); - // Convert object references from ids to indices - this._convertObjectIdsToArrayIndices(json); - this._updateObjects(json); - this._updateMaterial(json); - } - // asset is now required, #642 https://github.com/KhronosGroup/glTF/issues/639 - _addAsset(json) { - json.asset = json.asset || {}; - // We are normalizing to glTF v2, so change version to "2.0" - json.asset.version = '2.0'; - json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl'; - } - _convertTopLevelObjectsToArrays(json) { - // TODO check that all arrays are covered - for (const arrayName in GLTF_ARRAYS) { - this._convertTopLevelObjectToArray(json, arrayName); - } - } - /** Convert one top level object to array */ - _convertTopLevelObjectToArray(json, mapName) { - const objectMap = json[mapName]; - if (!objectMap || Array.isArray(objectMap)) { - return; - } - // Rewrite the top-level field as an array - json[mapName] = []; - // Copy the map key into object.id - for (const id in objectMap) { - const object = objectMap[id]; - object.id = object.id || id; // Mutates the loaded object - const index = json[mapName].length; - json[mapName].push(object); - this.idToIndexMap[mapName][id] = index; - } - } - /** Go through all objects in all top-level arrays and replace ids with indices */ - _convertObjectIdsToArrayIndices(json) { - for (const arrayName in GLTF_ARRAYS) { - this._convertIdsToIndices(json, arrayName); - } - if ('scene' in json) { - json.scene = this._convertIdToIndex(json.scene, 'scene'); - } - // Convert any index references that are not using array names - // texture.source (image) - for (const texture of json.textures) { - this._convertTextureIds(texture); - } - for (const mesh of json.meshes) { - this._convertMeshIds(mesh); - } - for (const node of json.nodes) { - this._convertNodeIds(node); - } - for (const node of json.scenes) { - this._convertSceneIds(node); - } - } - _convertTextureIds(texture) { - if (texture.source) { - texture.source = this._convertIdToIndex(texture.source, 'image'); - } - } - _convertMeshIds(mesh) { - for (const primitive of mesh.primitives) { - const { attributes, indices, material } = primitive; - for (const attributeName in attributes) { - attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor'); - } - if (indices) { - primitive.indices = this._convertIdToIndex(indices, 'accessor'); - } - if (material) { - primitive.material = this._convertIdToIndex(material, 'material'); - } - } - } - _convertNodeIds(node) { - if (node.children) { - node.children = node.children.map((child) => this._convertIdToIndex(child, 'node')); - } - if (node.meshes) { - node.meshes = node.meshes.map((mesh) => this._convertIdToIndex(mesh, 'mesh')); - } - } - _convertSceneIds(scene) { - if (scene.nodes) { - scene.nodes = scene.nodes.map((node) => this._convertIdToIndex(node, 'node')); - } - } - /** Go through all objects in a top-level array and replace ids with indices */ - _convertIdsToIndices(json, topLevelArrayName) { - if (!json[topLevelArrayName]) { - console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`); // eslint-disable-line no-console, no-undef - json[topLevelArrayName] = []; - } - for (const object of json[topLevelArrayName]) { - for (const key in object) { - const id = object[key]; - const index = this._convertIdToIndex(id, key); - object[key] = index; - } - } - } - _convertIdToIndex(id, key) { - const arrayName = GLTF_KEYS[key]; - if (arrayName in this.idToIndexMap) { - const index = this.idToIndexMap[arrayName][id]; - if (!Number.isFinite(index)) { - throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`); - } - return index; - } - return id; - } - /** - * - * @param {*} json - */ - _updateObjects(json) { - for (const buffer of this.json.buffers) { - // - [x] Removed buffer.type, #786, #629 - delete buffer.type; - } - } - /** - * Update material (set pbrMetallicRoughness) - * @param {*} json - */ - _updateMaterial(json) { - for (const material of json.materials) { - material.pbrMetallicRoughness = { - baseColorFactor: [1, 1, 1, 1], - metallicFactor: 1, - roughnessFactor: 1 - }; - const textureId = material.values?.tex || material.values?.texture2d_0 || material.values?.diffuseTex; - const textureIndex = json.textures.findIndex((texture) => texture.id === textureId); - if (textureIndex !== -1) { - material.pbrMetallicRoughness.baseColorTexture = { index: textureIndex }; - } - } - } -} -function normalizeGLTFV1(gltf, options = {}) { - return new GLTFV1Normalizer().normalize(gltf, options); -} - -async function parseGLTF$1(gltf, arrayBufferOrString, byteOffset = 0, options, context) { - parseGLTFContainerSync(gltf, arrayBufferOrString, byteOffset, options); - normalizeGLTFV1(gltf, { normalize: options?.gltf?.normalize }); - preprocessExtensions(gltf, options, context); - // Load linked buffers asynchronously and decodes base64 buffers in parallel - if (options?.gltf?.loadBuffers && gltf.json.buffers) { - await loadBuffers(gltf, options, context); - } - // loadImages and decodeExtensions should not be running in parallel, because - // decodeExtensions uses data from images taken during the loadImages call. - if (options?.gltf?.loadImages) { - await loadImages(gltf, options, context); - } - await decodeExtensions(gltf, options, context); - return gltf; -} -/** - * - * @param gltf - * @param data - can be ArrayBuffer (GLB), ArrayBuffer (Binary JSON), String (JSON), or Object (parsed JSON) - * @param byteOffset - * @param options - */ -function parseGLTFContainerSync(gltf, data, byteOffset, options) { - // Initialize gltf container - if (options.uri) { - gltf.baseUri = options.uri; - } - // If data is binary and starting with magic bytes, assume binary JSON text, convert to string - if (data instanceof ArrayBuffer && !isGLB(data, byteOffset, options)) { - const textDecoder = new TextDecoder(); - data = textDecoder.decode(data); - } - if (typeof data === 'string') { - // If string, try to parse as JSON - gltf.json = parseJSON(data); - } - else if (data instanceof ArrayBuffer) { - // If still ArrayBuffer, parse as GLB container - const glb = {}; - byteOffset = parseGLBSync(glb, data, byteOffset, options.glb); - assert$1(glb.type === 'glTF', `Invalid GLB magic string ${glb.type}`); - gltf._glb = glb; - gltf.json = glb.json; - } - else { - assert$1(false, 'GLTF: must be ArrayBuffer or string'); - } - // Populate buffers - // Create an external buffers array to hold binary data - const buffers = gltf.json.buffers || []; - gltf.buffers = new Array(buffers.length).fill(null); - // Populates JSON and some bin chunk info - if (gltf._glb && gltf._glb.header.hasBinChunk) { - const { binChunks } = gltf._glb; - gltf.buffers[0] = { - arrayBuffer: binChunks[0].arrayBuffer, - byteOffset: binChunks[0].byteOffset, - byteLength: binChunks[0].byteLength - }; - // TODO - this modifies JSON and is a post processing thing - // gltf.json.buffers[0].data = gltf.buffers[0].arrayBuffer; - // gltf.json.buffers[0].byteOffset = gltf.buffers[0].byteOffset; - } - // Populate images - const images = gltf.json.images || []; - gltf.images = new Array(images.length).fill({}); -} -/** Asynchronously fetch and parse buffers, store in buffers array outside of json - * TODO - traverse gltf and determine which buffers are actually needed - */ -async function loadBuffers(gltf, options, context) { - // TODO - const buffers = gltf.json.buffers || []; - for (let i = 0; i < buffers.length; ++i) { - const buffer = buffers[i]; - if (buffer.uri) { - const { fetch } = context; - assert$1(fetch); - const uri = resolveUrl(buffer.uri, options); - const response = await context?.fetch?.(uri); - const arrayBuffer = await response?.arrayBuffer?.(); - gltf.buffers[i] = { - arrayBuffer, - byteOffset: 0, - byteLength: arrayBuffer.byteLength - }; - delete buffer.uri; - } - else if (gltf.buffers[i] === null) { - gltf.buffers[i] = { - arrayBuffer: new ArrayBuffer(buffer.byteLength), - byteOffset: 0, - byteLength: buffer.byteLength - }; - } - } -} -/** - * Loads all images - * TODO - traverse gltf and determine which images are actually needed - * @param gltf - * @param options - * @param context - * @returns - */ -async function loadImages(gltf, options, context) { - const imageIndices = getReferencesImageIndices(gltf); - const images = gltf.json.images || []; - const promises = []; - for (const imageIndex of imageIndices) { - promises.push(loadImage(gltf, images[imageIndex], imageIndex, options, context)); - } - return await Promise.all(promises); -} -/** Make sure we only load images that are actually referenced by textures */ -function getReferencesImageIndices(gltf) { - const imageIndices = new Set(); - const textures = gltf.json.textures || []; - for (const texture of textures) { - if (texture.source !== undefined) { - imageIndices.add(texture.source); - } - } - return Array.from(imageIndices).sort(); -} -/** Asynchronously fetches and parses one image, store in images array outside of json */ -async function loadImage(gltf, image, index, options, context) { - let arrayBuffer; - if (image.uri && !image.hasOwnProperty('bufferView')) { - const uri = resolveUrl(image.uri, options); - const { fetch } = context; - const response = await fetch(uri); - arrayBuffer = await response.arrayBuffer(); - image.bufferView = { - data: arrayBuffer - }; - } - if (Number.isFinite(image.bufferView)) { - const array = getTypedArrayForBufferView(gltf.json, gltf.buffers, image.bufferView); - arrayBuffer = sliceArrayBuffer(array.buffer, array.byteOffset, array.byteLength); - } - assert$1(arrayBuffer, 'glTF image has no data'); - // Call `parse` - let parsedImage = (await parseFromContext(arrayBuffer, [ImageLoader, BasisLoader], { - ...options, - mimeType: image.mimeType, - basis: options.basis || { format: selectSupportedBasisFormat() } - }, context)); - if (parsedImage && parsedImage[0]) { - parsedImage = { - compressed: true, - // @ts-expect-error - mipmaps: false, - width: parsedImage[0].width, - height: parsedImage[0].height, - data: parsedImage[0] - }; - } - // TODO making sure ImageLoader is overridable by using array of loaders - // const parsedImage = await parse(arrayBuffer, [ImageLoader]); - // Store the loaded image - gltf.images = gltf.images || []; - // @ts-expect-error TODO - sort out image typing asap - gltf.images[index] = parsedImage; -} - -/** - * GLTF loader - */ -const GLTFLoader = { - dataType: null, - batchType: null, - name: 'glTF', - id: 'gltf', - module: 'gltf', - version: VERSION$3, - extensions: ['gltf', 'glb'], - mimeTypes: ['model/gltf+json', 'model/gltf-binary'], - text: true, - binary: true, - tests: ['glTF'], - parse: parse$2, - options: { - gltf: { - normalize: true, // Normalize glTF v1 to glTF v2 format (not yet stable) - loadBuffers: true, // Fetch any linked .BIN buffers, decode base64 - loadImages: true, // Create image objects - decompressMeshes: true // Decompress Draco encoded meshes - }, - // common? - log: console // eslint-disable-line - } -}; -async function parse$2(arrayBuffer, options = {}, context) { - // Apps can call the parse method directly, we so apply default options here - options = { ...GLTFLoader.options, ...options }; - // @ts-ignore - options.gltf = { ...GLTFLoader.options.gltf, ...options.gltf }; - const { byteOffset = 0 } = options; - const gltf = {}; - return await parseGLTF$1(gltf, arrayBuffer, byteOffset, options, context); -} - -// loaders.gl -// This is a post processor for loaded glTF files -// The goal is to make the loaded data easier to use in WebGL applications -// -// Functions: -// * Resolve indexed arrays structure of glTF into a linked tree. -// * Translate stringified enum keys and values into WebGL constants. -// * Load images (optional) -// ENUM LOOKUP -const COMPONENTS = { - SCALAR: 1, - VEC2: 2, - VEC3: 3, - VEC4: 4, - MAT2: 4, - MAT3: 9, - MAT4: 16 -}; -const BYTES = { - 5120: 1, // BYTE - 5121: 1, // UNSIGNED_BYTE - 5122: 2, // SHORT - 5123: 2, // UNSIGNED_SHORT - 5125: 4, // UNSIGNED_INT - 5126: 4 // FLOAT -}; -const GL_SAMPLER = { - // Sampler parameters - TEXTURE_MAG_FILTER: 0x2800, - TEXTURE_MIN_FILTER: 0x2801, - TEXTURE_WRAP_S: 0x2802, - TEXTURE_WRAP_T: 0x2803, - // Sampler default values - REPEAT: 0x2901, - LINEAR: 0x2601, - NEAREST_MIPMAP_LINEAR: 0x2702 -}; -const SAMPLER_PARAMETER_GLTF_TO_GL = { - magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER, - minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER, - wrapS: GL_SAMPLER.TEXTURE_WRAP_S, - wrapT: GL_SAMPLER.TEXTURE_WRAP_T -}; -// When undefined, a sampler with repeat wrapping and auto filtering should be used. -// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#texture -const DEFAULT_SAMPLER_PARAMETERS = { - [GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR, - [GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR, - [GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT, - [GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT -}; -function makeDefaultSampler() { - return { - id: 'default-sampler', - parameters: DEFAULT_SAMPLER_PARAMETERS - }; -} -function getBytesFromComponentType(componentType) { - return BYTES[componentType]; -} -function getSizeFromAccessorType(type) { - return COMPONENTS[type]; -} -class GLTFPostProcessor { - baseUri = ''; - // @ts-expect-error - jsonUnprocessed; - // @ts-expect-error - json; - buffers = []; - images = []; - postProcess(gltf, options = {}) { - const { json, buffers = [], images = [] } = gltf; - // @ts-expect-error - const { baseUri = '' } = gltf; - assert$1(json); - this.baseUri = baseUri; - this.buffers = buffers; - this.images = images; - this.jsonUnprocessed = json; - this.json = this._resolveTree(gltf.json, options); - return this.json; - } - // Convert indexed glTF structure into tree structure - // cross-link index resolution, enum lookup, convenience calculations - // eslint-disable-next-line complexity, max-statements - _resolveTree(gltf, options = {}) { - // @ts-expect-error - const json = { ...gltf }; - this.json = json; - if (gltf.bufferViews) { - json.bufferViews = gltf.bufferViews.map((bufView, i) => this._resolveBufferView(bufView, i)); - } - if (gltf.images) { - json.images = gltf.images.map((image, i) => this._resolveImage(image, i)); - } - if (gltf.samplers) { - json.samplers = gltf.samplers.map((sampler, i) => this._resolveSampler(sampler, i)); - } - if (gltf.textures) { - json.textures = gltf.textures.map((texture, i) => this._resolveTexture(texture, i)); - } - if (gltf.accessors) { - json.accessors = gltf.accessors.map((accessor, i) => this._resolveAccessor(accessor, i)); - } - if (gltf.materials) { - json.materials = gltf.materials.map((material, i) => this._resolveMaterial(material, i)); - } - if (gltf.meshes) { - json.meshes = gltf.meshes.map((mesh, i) => this._resolveMesh(mesh, i)); - } - if (gltf.nodes) { - json.nodes = gltf.nodes.map((node, i) => this._resolveNode(node, i)); - json.nodes = json.nodes.map((node, i) => this._resolveNodeChildren(node)); - } - if (gltf.skins) { - json.skins = gltf.skins.map((skin, i) => this._resolveSkin(skin, i)); - } - if (gltf.scenes) { - json.scenes = gltf.scenes.map((scene, i) => this._resolveScene(scene, i)); - } - if (typeof this.json.scene === 'number' && json.scenes) { - json.scene = json.scenes[this.json.scene]; - } - return json; - } - getScene(index) { - return this._get(this.json.scenes, index); - } - getNode(index) { - return this._get(this.json.nodes, index); - } - getSkin(index) { - return this._get(this.json.skins, index); - } - getMesh(index) { - return this._get(this.json.meshes, index); - } - getMaterial(index) { - return this._get(this.json.materials, index); - } - getAccessor(index) { - return this._get(this.json.accessors, index); - } - getCamera(index) { - return this._get(this.json.cameras, index); - } - getTexture(index) { - return this._get(this.json.textures, index); - } - getSampler(index) { - return this._get(this.json.samplers, index); - } - getImage(index) { - return this._get(this.json.images, index); - } - getBufferView(index) { - return this._get(this.json.bufferViews, index); - } - getBuffer(index) { - return this._get(this.json.buffers, index); - } - _get(array, index) { - // check if already resolved - if (typeof index === 'object') { - return index; - } - const object = array && array[index]; - if (!object) { - console.warn(`glTF file error: Could not find ${array}[${index}]`); // eslint-disable-line - } - return object; - } - // PARSING HELPERS - _resolveScene(scene, index) { - return { - ...scene, - // @ts-ignore - id: scene.id || `scene-${index}`, - nodes: (scene.nodes || []).map((node) => this.getNode(node)) - }; - } - _resolveNode(gltfNode, index) { - // @ts-expect-error - const node = { - ...gltfNode, - // @ts-expect-error id could already be present, glTF standard does not prevent it - id: gltfNode?.id || `node-${index}` - }; - if (gltfNode.mesh !== undefined) { - node.mesh = this.getMesh(gltfNode.mesh); - } - if (gltfNode.camera !== undefined) { - node.camera = this.getCamera(gltfNode.camera); - } - if (gltfNode.skin !== undefined) { - node.skin = this.getSkin(gltfNode.skin); - } - // TODO deprecated - Delete in v4.0? - // @ts-expect-error node.meshes does not seem to be part of the GLTF standard - if (gltfNode.meshes !== undefined && gltfNode.meshes.length) { - // @ts-expect-error - node.mesh = gltfNode.meshes.reduce((accum, meshIndex) => { - const mesh = this.getMesh(meshIndex); - accum.id = mesh.id; - accum.primitives = accum.primitives.concat(mesh.primitives); - return accum; - }, { primitives: [] }); - } - return node; - } - _resolveNodeChildren(node) { - if (node.children) { - // @ts-expect-error node.children are numbers at this stage - node.children = node.children.map((child) => this.getNode(child)); - } - return node; - } - _resolveSkin(gltfSkin, index) { - const inverseBindMatrices = typeof gltfSkin.inverseBindMatrices === 'number' - ? this.getAccessor(gltfSkin.inverseBindMatrices) - : undefined; - return { - ...gltfSkin, - id: gltfSkin.id || `skin-${index}`, - inverseBindMatrices - }; - } - _resolveMesh(gltfMesh, index) { - const mesh = { - ...gltfMesh, - id: gltfMesh.id || `mesh-${index}`, - primitives: [] - }; - if (gltfMesh.primitives) { - mesh.primitives = gltfMesh.primitives.map((gltfPrimitive) => { - const primitive = { - ...gltfPrimitive, - attributes: {}, - indices: undefined, - material: undefined - }; - const attributes = gltfPrimitive.attributes; - for (const attribute in attributes) { - primitive.attributes[attribute] = this.getAccessor(attributes[attribute]); - } - if (gltfPrimitive.indices !== undefined) { - primitive.indices = this.getAccessor(gltfPrimitive.indices); - } - if (gltfPrimitive.material !== undefined) { - primitive.material = this.getMaterial(gltfPrimitive.material); - } - return primitive; - }); - } - return mesh; - } - _resolveMaterial(gltfMaterial, index) { - // @ts-expect-error - const material = { - ...gltfMaterial, - // @ts-expect-error - id: gltfMaterial.id || `material-${index}` - }; - if (material.normalTexture) { - material.normalTexture = { ...material.normalTexture }; - material.normalTexture.texture = this.getTexture(material.normalTexture.index); - } - if (material.occlusionTexture) { - material.occlusionTexture = { ...material.occlusionTexture }; - material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index); - } - if (material.emissiveTexture) { - material.emissiveTexture = { ...material.emissiveTexture }; - material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index); - } - if (!material.emissiveFactor) { - material.emissiveFactor = material.emissiveTexture ? [1, 1, 1] : [0, 0, 0]; - } - if (material.pbrMetallicRoughness) { - material.pbrMetallicRoughness = { ...material.pbrMetallicRoughness }; - const mr = material.pbrMetallicRoughness; - if (mr.baseColorTexture) { - mr.baseColorTexture = { ...mr.baseColorTexture }; - mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index); - } - if (mr.metallicRoughnessTexture) { - mr.metallicRoughnessTexture = { ...mr.metallicRoughnessTexture }; - mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index); - } - } - return material; - } - _resolveAccessor(gltfAccessor, index) { - // Look up enums - const bytesPerComponent = getBytesFromComponentType(gltfAccessor.componentType); - const components = getSizeFromAccessorType(gltfAccessor.type); - const bytesPerElement = bytesPerComponent * components; - const accessor = { - ...gltfAccessor, - // @ts-expect-error - id: gltfAccessor.id || `accessor-${index}`, - bytesPerComponent, - components, - bytesPerElement, - value: undefined, - bufferView: undefined, - sparse: undefined - }; - if (gltfAccessor.bufferView !== undefined) { - // Draco encoded meshes don't have bufferView - accessor.bufferView = this.getBufferView(gltfAccessor.bufferView); - } - // Create TypedArray for the accessor - // Note: The canonical way to instantiate is to ignore this array and create - // WebGLBuffer's using the bufferViews. - if (accessor.bufferView) { - const buffer = accessor.bufferView.buffer; - const { ArrayType, byteLength } = getAccessorArrayTypeAndLength(accessor, accessor.bufferView); - const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset; - let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength); - if (accessor.bufferView.byteStride) { - cutBuffer = this._getValueFromInterleavedBuffer(buffer, byteOffset, accessor.bufferView.byteStride, accessor.bytesPerElement, accessor.count); - } - accessor.value = new ArrayType(cutBuffer); - } - return accessor; - } - /** - * Take values of particular accessor from interleaved buffer - * various parts of the buffer - * @param buffer - * @param byteOffset - * @param byteStride - * @param bytesPerElement - * @param count - * @returns - */ - _getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) { - const result = new Uint8Array(count * bytesPerElement); - for (let i = 0; i < count; i++) { - const elementOffset = byteOffset + i * byteStride; - result.set(new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)), i * bytesPerElement); - } - return result.buffer; - } - _resolveTexture(gltfTexture, index) { - return { - ...gltfTexture, - // @ts-expect-error id could already be present, glTF standard does not prevent it - id: gltfTexture.id || `texture-${index}`, - sampler: typeof gltfTexture.sampler === 'number' - ? this.getSampler(gltfTexture.sampler) - : makeDefaultSampler(), - source: typeof gltfTexture.source === 'number' ? this.getImage(gltfTexture.source) : undefined - }; - } - _resolveSampler(gltfSampler, index) { - const sampler = { - // @ts-expect-error id could already be present, glTF standard does not prevent it - id: gltfSampler.id || `sampler-${index}`, - ...gltfSampler, - parameters: {} - }; - // Map textual parameters to GL parameter values - for (const key in sampler) { - const glEnum = this._enumSamplerParameter(key); - if (glEnum !== undefined) { - sampler.parameters[glEnum] = sampler[key]; - } - } - return sampler; - } - _enumSamplerParameter(key) { - return SAMPLER_PARAMETER_GLTF_TO_GL[key]; - } - _resolveImage(gltfImage, index) { - const image = { - ...gltfImage, - // @ts-expect-error id could already be present, glTF standard does not prevent it - id: gltfImage.id || `image-${index}`, - image: null, - bufferView: gltfImage.bufferView !== undefined ? this.getBufferView(gltfImage.bufferView) : undefined - }; - // Check if image has been preloaded by the GLTFLoader - // If so, link it into the JSON and drop the URI - const preloadedImage = this.images[index]; - if (preloadedImage) { - image.image = preloadedImage; - } - return image; - } - _resolveBufferView(gltfBufferView, index) { - const bufferIndex = gltfBufferView.buffer; - const arrayBuffer = this.buffers[bufferIndex].arrayBuffer; - // Add offset of buffer, then offset of buffer view - let byteOffset = this.buffers[bufferIndex].byteOffset || 0; - if (gltfBufferView.byteOffset) { - byteOffset += gltfBufferView.byteOffset; - } - const bufferView = { - // // @ts-expect-error id could already be present, glTF standard does not prevent it - id: `bufferView-${index}`, - ...gltfBufferView, - // ...this.buffers[bufferIndex], - buffer: this.buffers[bufferIndex], - data: new Uint8Array(arrayBuffer, byteOffset, gltfBufferView.byteLength) - }; - return bufferView; - } - _resolveCamera(gltfCamera, index) { - const camera = { - ...gltfCamera, - // @ts-expect-error id could already be present, glTF standard does not prevent it - id: gltfCamera.id || `camera-${index}` - }; - return camera; - } -} -function postProcessGLTF(gltf, options) { - return new GLTFPostProcessor().postProcess(gltf, options); -} - -// __VERSION__ is injected by babel-plugin-version-inline -// @ts-ignore TS2304: Cannot find name '__VERSION__'. -const VERSION = "4.3.3" ; -/** - * Loader for the LAS (LASer) point cloud format - * @note Does not support LAS v1.4 - */ -const LASLoader$2 = { - dataType: null, - batchType: null, - name: 'LAS', - id: 'las', - module: 'las', - version: VERSION, - worker: true, - extensions: ['las', 'laz'], // LAZ is the "compressed" flavor of LAS, - mimeTypes: ['application/octet-stream'], // TODO - text version? - text: true, - binary: true, - tests: ['LAS'], - options: { - las: { - shape: 'mesh', - fp64: false, - skip: 1, - colorDepth: 8 - } - } -}; - -// @ts-nocheck -/* eslint-disable */ -/* - * Last update 2020-07-23 - * - * Compiled from Howard Butler's laz-perf - * https://github.com/hobu/laz-perf - * Under LGPL License - * - * To update this file: - * - git clone https://github.com/hobu/laz-perf - * - cd laz-perf - * - echo 'set(CMAKE_CXX_FLAGS "-s SINGLE_FILE=1 ${CMAKE_CXX_FLAGS}"' >> emscripten/CMakeLists.txt - * - mkdir build && cd build - * - cmake .. -DEMSCRIPTEN=1 -DCMAKE_TOOLCHAIN_FILE=/emscripten//cmake/Modules/Platform/Emscripten.cmake - * - VERBOSE=1 make - * - * See the laz-perf repository for required dependencies - * - * The result should be build/emscripten/laz-perf.asm.js - * Copy the content of this file in the getModule function below - */ -// laz-perf.js -function getModule() { - var Module = typeof Module !== 'undefined' ? Module : {}; - var moduleOverrides = {}; - var key; - for (key in Module) { - if (Module.hasOwnProperty(key)) { - moduleOverrides[key] = Module[key]; - } - } - var ENVIRONMENT_IS_WEB = false; - var ENVIRONMENT_IS_WORKER = false; - var ENVIRONMENT_IS_NODE = false; - var ENVIRONMENT_IS_SHELL = false; - ENVIRONMENT_IS_WEB = typeof window === 'object'; - ENVIRONMENT_IS_WORKER = typeof importScripts === 'function'; - ENVIRONMENT_IS_NODE = - typeof process === 'object' && - typeof process.versions === 'object' && - typeof process.versions.node === 'string'; - ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER; - var scriptDirectory = ''; - function locateFile(path) { - if (Module['locateFile']) { - return Module['locateFile'](path, scriptDirectory); - } - return scriptDirectory + path; - } - var read_, readAsync, readBinary; - var nodeFS; - var nodePath; - if (ENVIRONMENT_IS_NODE) { - if (ENVIRONMENT_IS_WORKER) { - scriptDirectory = require('path').dirname(scriptDirectory) + '/'; - } - else { - const dirname = typeof __dirname !== 'undefined' ? __dirname : ''; - scriptDirectory = dirname + '/'; - } - read_ = function shell_read(filename, binary) { - var ret = tryParseAsDataURI(filename); - if (ret) { - return binary ? ret : ret.toString(); - } - if (!nodeFS) - nodeFS = require('fs'); - if (!nodePath) - nodePath = require('path'); - filename = nodePath['normalize'](filename); - return nodeFS['readFileSync'](filename, binary ? null : 'utf8'); - }; - readBinary = function readBinary(filename) { - var ret = read_(filename, true); - if (!ret.buffer) { - ret = new Uint8Array(ret); - } - assert(ret.buffer); - return ret; - }; - if (process['argv'].length > 1) { - process['argv'][1].replace(/\\/g, '/'); - } - process['argv'].slice(2); - if (typeof module !== 'undefined') { - module['exports'] = Module; - } - process['on']('uncaughtException', function (ex) { - if (!(ex instanceof ExitStatus)) { - throw ex; - } - }); - process['on']('unhandledRejection', abort); - Module['inspect'] = function () { - return '[Emscripten Module object]'; - }; - } - else if (ENVIRONMENT_IS_SHELL) { - if (typeof read != 'undefined') { - read_ = function shell_read(f) { - var data = tryParseAsDataURI(f); - if (data) { - return intArrayToString(data); - } - return read(f); - }; - } - readBinary = function readBinary(f) { - var data; - data = tryParseAsDataURI(f); - if (data) { - return data; - } - if (typeof readbuffer === 'function') { - return new Uint8Array(readbuffer(f)); - } - data = read(f, 'binary'); - assert(typeof data === 'object'); - return data; - }; - if (typeof scriptArgs != 'undefined') { - scriptArgs; - } - if (typeof print !== 'undefined') { - if (typeof console === 'undefined') - console = {}; - console.log = print; - console.warn = console.error = typeof printErr !== 'undefined' ? printErr : print; - } - } - else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) { - if (ENVIRONMENT_IS_WORKER) { - scriptDirectory = self.location.href; - } - else if (document.currentScript) { - scriptDirectory = document.currentScript.src; - } - if (scriptDirectory.indexOf('blob:') !== 0) { - scriptDirectory = scriptDirectory.substr(0, scriptDirectory.lastIndexOf('/') + 1); - } - else { - scriptDirectory = ''; - } - { - read_ = function shell_read(url) { - try { - var xhr = new XMLHttpRequest(); - xhr.open('GET', url, false); - xhr.send(null); - return xhr.responseText; - } - catch (err) { - var data = tryParseAsDataURI(url); - if (data) { - return intArrayToString(data); - } - throw err; - } - }; - if (ENVIRONMENT_IS_WORKER) { - readBinary = function readBinary(url) { - try { - var xhr = new XMLHttpRequest(); - xhr.open('GET', url, false); - xhr.responseType = 'arraybuffer'; - xhr.send(null); - return new Uint8Array(xhr.response); - } - catch (err) { - var data = tryParseAsDataURI(url); - if (data) { - return data; - } - throw err; - } - }; - } - readAsync = function readAsync(url, onload, onerror) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', url, true); - xhr.responseType = 'arraybuffer'; - xhr.onload = function xhr_onload() { - if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { - onload(xhr.response); - return; - } - var data = tryParseAsDataURI(url); - if (data) { - onload(data.buffer); - return; - } - onerror(); - }; - xhr.onerror = onerror; - xhr.send(null); - }; - } - } - else ; - var out = Module['print'] || console.log.bind(console); - var err = Module['printErr'] || console.warn.bind(console); - for (key in moduleOverrides) { - if (moduleOverrides.hasOwnProperty(key)) { - Module[key] = moduleOverrides[key]; - } - } - moduleOverrides = null; - if (Module['arguments']) - ; - if (Module['thisProgram']) - ; - if (Module['quit']) - ; - new Array(0); - var tempRet0 = 0; - var setTempRet0 = function (value) { - tempRet0 = value; - }; - var getTempRet0 = function () { - return tempRet0; - }; - var GLOBAL_BASE = 8; - if (Module['wasmBinary']) - ; - if (Module['noExitRuntime']) - ; - var ABORT = false; - function assert(condition, text) { - if (!condition) { - abort('Assertion failed: ' + text); - } - } - var UTF8Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf8') : undefined; - function UTF8ArrayToString(heap, idx, maxBytesToRead) { - var endIdx = idx + maxBytesToRead; - var endPtr = idx; - while (heap[endPtr] && !(endPtr >= endIdx)) - ++endPtr; - if (endPtr - idx > 16 && heap.subarray && UTF8Decoder) { - return UTF8Decoder.decode(heap.subarray(idx, endPtr)); - } - else { - var str = ''; - while (idx < endPtr) { - var u0 = heap[idx++]; - if (!(u0 & 128)) { - str += String.fromCharCode(u0); - continue; - } - var u1 = heap[idx++] & 63; - if ((u0 & 224) == 192) { - str += String.fromCharCode(((u0 & 31) << 6) | u1); - continue; - } - var u2 = heap[idx++] & 63; - if ((u0 & 240) == 224) { - u0 = ((u0 & 15) << 12) | (u1 << 6) | u2; - } - else { - u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heap[idx++] & 63); - } - if (u0 < 65536) { - str += String.fromCharCode(u0); - } - else { - var ch = u0 - 65536; - str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023)); - } - } - } - return str; - } - function UTF8ToString(ptr, maxBytesToRead) { - return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : ''; - } - function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) { - if (!(maxBytesToWrite > 0)) - return 0; - var startIdx = outIdx; - var endIdx = outIdx + maxBytesToWrite - 1; - for (var i = 0; i < str.length; ++i) { - var u = str.charCodeAt(i); - if (u >= 55296 && u <= 57343) { - var u1 = str.charCodeAt(++i); - u = (65536 + ((u & 1023) << 10)) | (u1 & 1023); - } - if (u <= 127) { - if (outIdx >= endIdx) - break; - heap[outIdx++] = u; - } - else if (u <= 2047) { - if (outIdx + 1 >= endIdx) - break; - heap[outIdx++] = 192 | (u >> 6); - heap[outIdx++] = 128 | (u & 63); - } - else if (u <= 65535) { - if (outIdx + 2 >= endIdx) - break; - heap[outIdx++] = 224 | (u >> 12); - heap[outIdx++] = 128 | ((u >> 6) & 63); - heap[outIdx++] = 128 | (u & 63); - } - else { - if (outIdx + 3 >= endIdx) - break; - heap[outIdx++] = 240 | (u >> 18); - heap[outIdx++] = 128 | ((u >> 12) & 63); - heap[outIdx++] = 128 | ((u >> 6) & 63); - heap[outIdx++] = 128 | (u & 63); - } - } - heap[outIdx] = 0; - return outIdx - startIdx; - } - function stringToUTF8(str, outPtr, maxBytesToWrite) { - return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite); - } - function lengthBytesUTF8(str) { - var len = 0; - for (var i = 0; i < str.length; ++i) { - var u = str.charCodeAt(i); - if (u >= 55296 && u <= 57343) - u = (65536 + ((u & 1023) << 10)) | (str.charCodeAt(++i) & 1023); - if (u <= 127) - ++len; - else if (u <= 2047) - len += 2; - else if (u <= 65535) - len += 3; - else - len += 4; - } - return len; - } - var UTF16Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-16le') : undefined; - function UTF16ToString(ptr, maxBytesToRead) { - var endPtr = ptr; - var idx = endPtr >> 1; - var maxIdx = idx + maxBytesToRead / 2; - while (!(idx >= maxIdx) && HEAPU16[idx]) - ++idx; - endPtr = idx << 1; - if (endPtr - ptr > 32 && UTF16Decoder) { - return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr)); - } - else { - var i = 0; - var str = ''; - while (1) { - var codeUnit = HEAP16[(ptr + i * 2) >> 1]; - if (codeUnit == 0 || i == maxBytesToRead / 2) - return str; - ++i; - str += String.fromCharCode(codeUnit); - } - } - } - function stringToUTF16(str, outPtr, maxBytesToWrite) { - if (maxBytesToWrite === undefined) { - maxBytesToWrite = 2147483647; - } - if (maxBytesToWrite < 2) - return 0; - maxBytesToWrite -= 2; - var startPtr = outPtr; - var numCharsToWrite = maxBytesToWrite < str.length * 2 ? maxBytesToWrite / 2 : str.length; - for (var i = 0; i < numCharsToWrite; ++i) { - var codeUnit = str.charCodeAt(i); - HEAP16[outPtr >> 1] = codeUnit; - outPtr += 2; - } - HEAP16[outPtr >> 1] = 0; - return outPtr - startPtr; - } - function lengthBytesUTF16(str) { - return str.length * 2; - } - function UTF32ToString(ptr, maxBytesToRead) { - var i = 0; - var str = ''; - while (!(i >= maxBytesToRead / 4)) { - var utf32 = HEAP32[(ptr + i * 4) >> 2]; - if (utf32 == 0) - break; - ++i; - if (utf32 >= 65536) { - var ch = utf32 - 65536; - str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023)); - } - else { - str += String.fromCharCode(utf32); - } - } - return str; - } - function stringToUTF32(str, outPtr, maxBytesToWrite) { - if (maxBytesToWrite === undefined) { - maxBytesToWrite = 2147483647; - } - if (maxBytesToWrite < 4) - return 0; - var startPtr = outPtr; - var endPtr = startPtr + maxBytesToWrite - 4; - for (var i = 0; i < str.length; ++i) { - var codeUnit = str.charCodeAt(i); - if (codeUnit >= 55296 && codeUnit <= 57343) { - var trailSurrogate = str.charCodeAt(++i); - codeUnit = (65536 + ((codeUnit & 1023) << 10)) | (trailSurrogate & 1023); - } - HEAP32[outPtr >> 2] = codeUnit; - outPtr += 4; - if (outPtr + 4 > endPtr) - break; - } - HEAP32[outPtr >> 2] = 0; - return outPtr - startPtr; - } - function lengthBytesUTF32(str) { - var len = 0; - for (var i = 0; i < str.length; ++i) { - var codeUnit = str.charCodeAt(i); - if (codeUnit >= 55296 && codeUnit <= 57343) - ++i; - len += 4; - } - return len; - } - var buffer, HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64; - function updateGlobalBufferAndViews(buf) { - buffer = buf; - Module['HEAP8'] = HEAP8 = new Int8Array(buf); - Module['HEAP16'] = HEAP16 = new Int16Array(buf); - Module['HEAP32'] = HEAP32 = new Int32Array(buf); - Module['HEAPU8'] = HEAPU8 = new Uint8Array(buf); - Module['HEAPU16'] = HEAPU16 = new Uint16Array(buf); - Module['HEAPU32'] = HEAPU32 = new Uint32Array(buf); - Module['HEAPF32'] = HEAPF32 = new Float32Array(buf); - Module['HEAPF64'] = HEAPF64 = new Float64Array(buf); - } - var DYNAMIC_BASE = 5265264, DYNAMICTOP_PTR = 22176; - var INITIAL_INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 167772160; - if (Module['buffer']) { - buffer = Module['buffer']; - } - else { - buffer = new ArrayBuffer(INITIAL_INITIAL_MEMORY); - } - INITIAL_INITIAL_MEMORY = buffer.byteLength; - updateGlobalBufferAndViews(buffer); - HEAP32[DYNAMICTOP_PTR >> 2] = DYNAMIC_BASE; - function callRuntimeCallbacks(callbacks) { - while (callbacks.length > 0) { - var callback = callbacks.shift(); - if (typeof callback == 'function') { - callback(Module); - continue; - } - var func = callback.func; - if (typeof func === 'number') { - if (callback.arg === undefined) { - Module['dynCall_v'](func); - } - else { - Module['dynCall_vi'](func, callback.arg); - } - } - else { - func(callback.arg === undefined ? null : callback.arg); - } - } - } - var __ATPRERUN__ = []; - var __ATINIT__ = []; - var __ATMAIN__ = []; - var __ATPOSTRUN__ = []; - function preRun() { - if (Module['preRun']) { - if (typeof Module['preRun'] == 'function') - Module['preRun'] = [Module['preRun']]; - while (Module['preRun'].length) { - addOnPreRun(Module['preRun'].shift()); - } - } - callRuntimeCallbacks(__ATPRERUN__); - } - function initRuntime() { - callRuntimeCallbacks(__ATINIT__); - } - function preMain() { - callRuntimeCallbacks(__ATMAIN__); - } - function postRun() { - if (Module['postRun']) { - if (typeof Module['postRun'] == 'function') - Module['postRun'] = [Module['postRun']]; - while (Module['postRun'].length) { - addOnPostRun(Module['postRun'].shift()); - } - } - callRuntimeCallbacks(__ATPOSTRUN__); - } - function addOnPreRun(cb) { - __ATPRERUN__.unshift(cb); - } - function addOnPostRun(cb) { - __ATPOSTRUN__.unshift(cb); - } - var runDependencies = 0; - var dependenciesFulfilled = null; - function addRunDependency(id) { - runDependencies++; - if (Module['monitorRunDependencies']) { - Module['monitorRunDependencies'](runDependencies); - } - } - function removeRunDependency(id) { - runDependencies--; - if (Module['monitorRunDependencies']) { - Module['monitorRunDependencies'](runDependencies); - } - if (runDependencies == 0) { - if (dependenciesFulfilled) { - var callback = dependenciesFulfilled; - dependenciesFulfilled = null; - callback(); - } - } - } - Module['preloadedImages'] = {}; - Module['preloadedAudios'] = {}; - function abort(what) { - if (Module['onAbort']) { - Module['onAbort'](what); - } - what += ''; - out(what); - err(what); - ABORT = true; - what = 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.'; - throw what; - } - var memoryInitializer = null; - function hasPrefix(str, prefix) { - return String.prototype.startsWith ? str.startsWith(prefix) : str.indexOf(prefix) === 0; - } - var dataURIPrefix = 'data:application/octet-stream;base64,'; - function isDataURI(filename) { - return hasPrefix(filename, dataURIPrefix); - } - __ATINIT__.push({ - func: function () { - globalCtors(); - } - }); - memoryInitializer = - 'data:application/octet-stream;base64,AAAAAAAAAAAPDg0MCwoJCA4AAQMGCgoJDQECBAcLCwoMAwQFCAwMCwsGBwgJDQ0MCgoLDA0ODg0JCgsMDQ4PDggJCgsMDQ4PAAECAwQFBgcBAAECAwQFBgIBAAECAwQFAwIBAAECAwQEAwIBAAECAwUEAwIBAAECBgUEAwIBAAEHBgUEAwIBAMgPAAAoDQAAEBAAACAQAADIDwAAUA0AABAQAAAgEAAAEQAKABEREQAAAAAFAAAAAAAACQAAAAALAAAAAAAAAAARAA8KERERAwoHAAEACQsLAAAJBgsAAAsABhEAAAAREREAAAAAAAAAAAAAAAAAAAAACwAAAAAAAAAAEQAKChEREQAKAAACAAkLAAAACQALAAALAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAADAAAAAAJDAAAAAAADAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAANAAAABA0AAAAACQ4AAAAAAA4AAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAADwAAAAAPAAAAAAkQAAAAAAAQAAAQAAASAAAAEhISAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABIAAAASEhIAAAAAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALAAAAAAAAAAAAAAAKAAAAAAoAAAAACQsAAAAAAAsAAAsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAMAAAAAAkMAAAAAAAMAAAMAAAwMTIzNDU2Nzg5QUJDREVGGRJEOwI/LEcUPTMwChsGRktFNw9JDo4XA0AdPGkrNh9KLRwBICUpIQgMFRYiLhA4Pgs0MRhkdHV2L0EJfzkRI0MyQomKiwUEJignDSoeNYwHGkiTE5SVAAAAAAAAAAAASWxsZWdhbCBieXRlIHNlcXVlbmNlAERvbWFpbiBlcnJvcgBSZXN1bHQgbm90IHJlcHJlc2VudGFibGUATm90IGEgdHR5AFBlcm1pc3Npb24gZGVuaWVkAE9wZXJhdGlvbiBub3QgcGVybWl0dGVkAE5vIHN1Y2ggZmlsZSBvciBkaXJlY3RvcnkATm8gc3VjaCBwcm9jZXNzAEZpbGUgZXhpc3RzAFZhbHVlIHRvbyBsYXJnZSBmb3IgZGF0YSB0eXBlAE5vIHNwYWNlIGxlZnQgb24gZGV2aWNlAE91dCBvZiBtZW1vcnkAUmVzb3VyY2UgYnVzeQBJbnRlcnJ1cHRlZCBzeXN0ZW0gY2FsbABSZXNvdXJjZSB0ZW1wb3JhcmlseSB1bmF2YWlsYWJsZQBJbnZhbGlkIHNlZWsAQ3Jvc3MtZGV2aWNlIGxpbmsAUmVhZC1vbmx5IGZpbGUgc3lzdGVtAERpcmVjdG9yeSBub3QgZW1wdHkAQ29ubmVjdGlvbiByZXNldCBieSBwZWVyAE9wZXJhdGlvbiB0aW1lZCBvdXQAQ29ubmVjdGlvbiByZWZ1c2VkAEhvc3QgaXMgZG93bgBIb3N0IGlzIHVucmVhY2hhYmxlAEFkZHJlc3MgaW4gdXNlAEJyb2tlbiBwaXBlAEkvTyBlcnJvcgBObyBzdWNoIGRldmljZSBvciBhZGRyZXNzAEJsb2NrIGRldmljZSByZXF1aXJlZABObyBzdWNoIGRldmljZQBOb3QgYSBkaXJlY3RvcnkASXMgYSBkaXJlY3RvcnkAVGV4dCBmaWxlIGJ1c3kARXhlYyBmb3JtYXQgZXJyb3IASW52YWxpZCBhcmd1bWVudABBcmd1bWVudCBsaXN0IHRvbyBsb25nAFN5bWJvbGljIGxpbmsgbG9vcABGaWxlbmFtZSB0b28gbG9uZwBUb28gbWFueSBvcGVuIGZpbGVzIGluIHN5c3RlbQBObyBmaWxlIGRlc2NyaXB0b3JzIGF2YWlsYWJsZQBCYWQgZmlsZSBkZXNjcmlwdG9yAE5vIGNoaWxkIHByb2Nlc3MAQmFkIGFkZHJlc3MARmlsZSB0b28gbGFyZ2UAVG9vIG1hbnkgbGlua3MATm8gbG9ja3MgYXZhaWxhYmxlAFJlc291cmNlIGRlYWRsb2NrIHdvdWxkIG9jY3VyAFN0YXRlIG5vdCByZWNvdmVyYWJsZQBQcmV2aW91cyBvd25lciBkaWVkAE9wZXJhdGlvbiBjYW5jZWxlZABGdW5jdGlvbiBub3QgaW1wbGVtZW50ZWQATm8gbWVzc2FnZSBvZiBkZXNpcmVkIHR5cGUASWRlbnRpZmllciByZW1vdmVkAERldmljZSBub3QgYSBzdHJlYW0ATm8gZGF0YSBhdmFpbGFibGUARGV2aWNlIHRpbWVvdXQAT3V0IG9mIHN0cmVhbXMgcmVzb3VyY2VzAExpbmsgaGFzIGJlZW4gc2V2ZXJlZABQcm90b2NvbCBlcnJvcgBCYWQgbWVzc2FnZQBGaWxlIGRlc2NyaXB0b3IgaW4gYmFkIHN0YXRlAE5vdCBhIHNvY2tldABEZXN0aW5hdGlvbiBhZGRyZXNzIHJlcXVpcmVkAE1lc3NhZ2UgdG9vIGxhcmdlAFByb3RvY29sIHdyb25nIHR5cGUgZm9yIHNvY2tldABQcm90b2NvbCBub3QgYXZhaWxhYmxlAFByb3RvY29sIG5vdCBzdXBwb3J0ZWQAU29ja2V0IHR5cGUgbm90IHN1cHBvcnRlZABOb3Qgc3VwcG9ydGVkAFByb3RvY29sIGZhbWlseSBub3Qgc3VwcG9ydGVkAEFkZHJlc3MgZmFtaWx5IG5vdCBzdXBwb3J0ZWQgYnkgcHJvdG9jb2wAQWRkcmVzcyBub3QgYXZhaWxhYmxlAE5ldHdvcmsgaXMgZG93bgBOZXR3b3JrIHVucmVhY2hhYmxlAENvbm5lY3Rpb24gcmVzZXQgYnkgbmV0d29yawBDb25uZWN0aW9uIGFib3J0ZWQATm8gYnVmZmVyIHNwYWNlIGF2YWlsYWJsZQBTb2NrZXQgaXMgY29ubmVjdGVkAFNvY2tldCBub3QgY29ubmVjdGVkAENhbm5vdCBzZW5kIGFmdGVyIHNvY2tldCBzaHV0ZG93bgBPcGVyYXRpb24gYWxyZWFkeSBpbiBwcm9ncmVzcwBPcGVyYXRpb24gaW4gcHJvZ3Jlc3MAU3RhbGUgZmlsZSBoYW5kbGUAUmVtb3RlIEkvTyBlcnJvcgBRdW90YSBleGNlZWRlZABObyBtZWRpdW0gZm91bmQAV3JvbmcgbWVkaXVtIHR5cGUATm8gZXJyb3IgaW5mb3JtYXRpb24AAAAAAADgFgAAmRgAAGAQAAAAAAAA4BYAAEIZAABgEAAAAAAAAOAWAAAqGgAASA8AAAAAAAC4FgAANBsAAOAWAACfGgAAMAoAAAAAAADgFgAAaRsAAEgPAAAAAAAA4BYAAIobAABIDwAAAAAAALgWAAAPHAAA4BYAAHwcAABIDwAAAAAAAOAWAACVHAAASA8AAAAAAADgFgAAHh0AAEgPAAAAAAAA4BYAAHcdAABIDwAAAAAAAOAWAACQHQAASA8AAAAAAADgFgAAQh4AAEgPAAAAAAAA4BYAAIceAABgEAAAAAAAAOAWAACkHwAASA8AAAAAAAC4FgAAZyAAAOAWAADkHwAA8AoAAAAAAADgFgAAjyAAAGAQAAAAAAAAuBYAAMMiAADgFgAAAiIAABgLAAAAAAAA4BYAAOEiAABgEAAAAAAAAOAWAADQJAAAGAsAAAAAAADgFgAAkSUAAGAQAAAAAAAA4BYAAIAnAAAYCwAAAAAAAOAWAAA9KAAAYBAAAAAAAADgFgAAJCoAABgLAAAAAAAA4BYAAOkqAABgEAAAAAAAAOAWAADgLAAA8AoAAAAAAADgFgAAui0AAGAQAAAAAAAA4BYAANsvAADwCgAAAAAAAOAWAADTMAAAYBAAAAAAAADgFgAAMDMAAPAKAAAAAAAA4BYAACQ0AABgEAAAAAAAAOAWAAB5NgAA8AoAAAAAAADgFgAAizcAAGAQAAAAAAAA4BYAABw6AABgEAAAAAAAAOAWAACdOgAAYBAAAAAAAADgFgAAXjsAAPAKAAAAAAAA4BYAALU7AABgEAAAAAAAAOAWAADMPAAAGAsAAAAAAADgFgAATz0AAGAQAAAAAAAA4BYAAL4+AAAYCwAAAAAAAOAWAABBPwAAYBAAAAAAAADgFgAAsEAAABgLAAAAAAAA4BYAADNBAABgEAAAAAAAAOAWAACiQgAAGAsAAAAAAADgFgAAJUMAAGAQAAAAAAAA4BYAAJREAAAYCwAAAAAAAOAWAAAXRQAAYBAAAAAAAADgFgAAhkYAABgLAAAAAAAA4BYAAAlHAABgEAAAAAAAALgWAAB4SAAAiBcAAIBIAAAAAAAAIA0AAIgXAACJSAAAAQAAACANAAC4FgAAqkgAAIgXAAC6SAAAAAAAAEgNAACIFwAAy0gAAAEAAABIDQAAuBYAABhMAAC4FgAAN0wAALgWAABWTAAAuBYAAHVMAAC4FgAAlEwAALgWAACzTAAAuBYAANJMAAC4FgAA8UwAALgWAAAQTQAAuBYAAC9NAAC4FgAATk0AALgWAABtTQAAuBYAAIxNAACkFwAAn00AAAAAAAABAAAA8A0AAAAAAAC4FgAA4U0AAKQXAAAHTgAAAAAAAAEAAADwDQAAAAAAAKQXAABJTgAAAAAAAAEAAADwDQAAAAAAAKQXAACITgAAAAAAAAEAAADwDQAAAAAAAKQXAADHTgAAAAAAAAEAAADwDQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALgWAADNTwAA4BYAAC1QAAAADwAAAAAAAOAWAADaTwAAEA8AAAAAAAC4FgAA+08AAOAWAAAIUAAA8A4AAAAAAADgFgAAhlAAAOgOAAAAAAAA4BYAAJNQAADoDgAAAAAAAOAWAACjUAAA6A4AAAAAAADgFgAAtVAAADgPAAAAAAAA4BYAAMZQAAA4DwAAAAAAAOAWAADXUAAAAA8AAAAAAADgFgAA+VAAAHgPAAAAAAAA4BYAAB1RAAAADwAAAAAAAOAWAABCUQAAeA8AAAAAAADgFgAAjlEAAAAPAAAAAAAAbBcAALZRAABsFwAAuFEAAGwXAAC7UQAAbBcAAL1RAABsFwAAv1EAAGwXAADBUQAAbBcAAMNRAABsFwAAxVEAAGwXAADHUQAAbBcAAMlRAABsFwAAy1EAAGwXAADNUQAAbBcAAM9RAABsFwAA0VEAAOAWAADTUQAA8A4AAAAAAADgFgAARlIAAOgOAAAAAAAAuBYAAGJSAACkFwAAe1IAAAAAAAABAAAAWBAAAAAAAADgFgAA9FIAAIgQAAAAAAAA4BYAABdTAACYEAAAAAAAALgWAAAuUwAA4BYAAHBTAACIEAAAAAAAAOAWAACSUwAASA8AAAAAAAAAAAAAAAoAAAEAAAACAAAAAwAAAAEAAAAEAAAAAAAAABAKAAABAAAABQAAAAYAAAACAAAABwAAAAAAAAAgCgAACAAAAAkAAAABAAAAAAAAADgKAAAKAAAACwAAAAIAAAABAAAADAAAAA0AAAACAAAAAwAAAAMAAAAAAAAASAoAAAgAAAAOAAAAAQAAAAAAAABYCgAACAAAAA8AAAABAAAAAAAAAIAKAAAIAAAAEAAAAAEAAAAAAAAAcAoAAAgAAAARAAAAAQAAAAAAAACQCgAACAAAABIAAAABAAAAAAAAAKAKAAAIAAAAEwAAAAEAAAAAAAAAsAoAAAgAAAAUAAAAAQAAAAAAAADACgAACAAAABUAAAABAAAAAAAAANAKAAABAAAAFgAAABcAAAAEAAAAGAAAAAAAAADgCgAACAAAABkAAAABAAAAAAAAAPgKAAAFAAAAGgAAABsAAAAAAAAA8AoAAAEAAAAcAAAAHQAAAAAAAAAICwAAAQAAAB4AAAAfAAAABgAAACAAAAAAAAAAIAsAACEAAAAiAAAABwAAAAgAAAAAAAAAGAsAACMAAAAkAAAABwAAAAkAAAAAAAAAMAsAAAEAAAAlAAAAJgAAAAoAAAAnAAAAAAAAAEALAAAoAAAAKQAAAAcAAAALAAAAAAAAAFALAAABAAAAKgAAACsAAAAMAAAALAAAAAAAAABgCwAALQAAAC4AAAAHAAAADQAAAAAAAABwCwAAAQAAAC8AAAAwAAAADgAAADEAAAAAAAAAgAsAADIAAAAzAAAABwAAAA8AAAAAAAAAkAsAAAEAAAA0AAAANQAAABAAAAA2AAAAAAAAAKALAAARAAAANwAAADgAAAAAAAAAsAsAAAEAAAA5AAAAOgAAABIAAAA7AAAAAAAAAMALAAATAAAAPAAAAD0AAAAAAAAA0AsAAAEAAAA+AAAAPwAAABQAAABAAAAAAAAAAOALAAAVAAAAQQAAAEIAAAAAAAAA8AsAAAEAAABDAAAARAAAABYAAABFAAAAAAAAAAAMAAAXAAAARgAAAEcAAAAAAAAAEAwAAAEAAABIAAAASQAAABgAAABKAAAAAAAAACAMAAABAAAASwAAAEwAAAAZAAAATQAAAAAAAAAwDAAAAQAAAE4AAABPAAAAGgAAAFAAAAAAAAAAQAwAABsAAABRAAAAUgAAAAAAAABQDAAAAQAAAFMAAABUAAAAHAAAAFUAAAAAAAAAYAwAAFYAAABXAAAABwAAAB0AAAAAAAAAcAwAAAEAAABYAAAAWQAAAB4AAABaAAAAAAAAAIAMAABbAAAAXAAAAAcAAAAfAAAAAAAAAJAMAAABAAAAXQAAAF4AAAAgAAAAXwAAAAAAAACgDAAAYAAAAGEAAAAHAAAAIQAAAAAAAACwDAAAAQAAAGIAAABjAAAAIgAAAGQAAAAAAAAAwAwAAGUAAABmAAAABwAAACMAAAAAAAAA0AwAAAEAAABnAAAAaAAAACQAAABpAAAAAAAAAOAMAABqAAAAawAAAAcAAAAlAAAAAAAAAPAMAAABAAAAbAAAAG0AAAAmAAAAbgAAAAAAAAAADQAAbwAAAHAAAAAHAAAAJwAAAAAAAAAQDQAAAQAAAHEAAAByAAAAKAAAAHMAAAAoDQAAyA8AACgNAAAIEAAAEBAAACgNAABQDQAAyA8AAFANAAAgEAAAyA8AAFANAAAIEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABsVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADwDgAAdAAAAHUAAAB2AAAAdwAAAAIAAAABAAAAAQAAAAEAAAAAAAAAGA8AAHQAAAB4AAAAdgAAAHcAAAACAAAAAgAAAAIAAAACAAAAAAAAACgPAAB5AAAAegAAAAQAAAAAAAAAOA8AAHsAAAB8AAAABQAAAAAAAABIDwAACAAAAH0AAAABAAAAAAAAAFgPAAB7AAAAfgAAAAUAAAAAAAAAaA8AAHsAAAB/AAAABQAAAAAAAAC4DwAAdAAAAIAAAAB2AAAAdwAAAAMAAAAAAAAAiA8AAHQAAACBAAAAdgAAAHcAAAAEAAAAAAAAADgQAAB0AAAAggAAAHYAAAB3AAAAAgAAAAMAAAADAAAAAwAAAAAAAABIEAAAgwAAAIQAAAAGAAAAAAAAAHgQAACFAAAAhgAAAAcAAAABAAAABQAAAAYAAAACAAAAAAAAAKAQAACFAAAAhwAAAAgAAAADAAAABQAAAAYAAAAEAAAA4BcAAAQYAAAAAAAAsBAAAIgAAACJAAAAAQAAAExBU1ppcABvcGVuAGdldFBvaW50AGdldENvdW50AER5bmFtaWNMQVNaaXAAYWRkRmllbGRGbG9hdGluZwBhZGRGaWVsZFNpZ25lZABhZGRGaWVsZFVuc2lnbmVkAE5TdDNfXzIyMF9fc2hhcmVkX3B0cl9wb2ludGVySVBONmxhc3ppcDdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRU5TXzE0ZGVmYXVsdF9kZWxldGVJUzNfRUVOU185YWxsb2NhdG9ySVMzX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXA3c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRQBOU3QzX18yMjBfX3NoYXJlZF9wdHJfcG9pbnRlcklQTjZsYXN6aXAyaW82cmVhZGVyMTBiYXNpY19maWxlSU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRU5TXzE0ZGVmYXVsdF9kZWxldGVJUzdfRUVOU185YWxsb2NhdG9ySVM3X0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXAyaW82cmVhZGVyMTBiYXNpY19maWxlSU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFAExBU0YATjZsYXN6aXAxM2ludmFsaWRfbWFnaWNFAGFsbG9jYXRvcjxUPjo6YWxsb2NhdGUoc2l6ZV90IG4pICduJyBleGNlZWRzIG1heGltdW0gc3VwcG9ydGVkIHNpemUARmlsZSBtYWdpYyBpcyBub3QgdmFsaWQATlN0M19fMjEwX19mdW5jdGlvbjZfX2Z1bmNJWk42bGFzemlwMmlvNnJlYWRlcjEwYmFzaWNfZmlsZUlOUzJfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRTExX3ZhbGlkYXRvcnNFdkVVbFJOUzNfNmhlYWRlckVFX05TXzlhbGxvY2F0b3JJU0JfRUVGdlNBX0VFRQBOU3QzX18yMTBfX2Z1bmN0aW9uNl9fYmFzZUlGdlJONmxhc3ppcDJpbzZoZWFkZXJFRUVFAE42bGFzemlwMjFvbGRfc3R5bGVfY29tcHJlc3Npb25FAE42bGFzemlwMTRub3RfY29tcHJlc3NlZEUAVGhlIGZpbGUgc2VlbXMgdG8gaGF2ZSBvbGQgc3R5bGUgY29tcHJlc3Npb24gd2hpY2ggaXMgbm90IHN1cHBvcnRlZABUaGUgZmlsZSBkb2Vzbid0IHNlZW0gdG8gYmUgY29tcHJlc3NlZABaTjZsYXN6aXAyaW82cmVhZGVyMTBiYXNpY19maWxlSU5TXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUUxMV92YWxpZGF0b3JzRXZFVWxSTlMwXzZoZWFkZXJFRV8AbGFzemlwIGVuY29kZWQATjZsYXN6aXAxM25vX2xhc3ppcF92bHJFAE42bGFzemlwMjVsYXN6aXBfZm9ybWF0X3Vuc3VwcG9ydGVkRQBPbmx5IExBU3ppcCBQT0lOVFdJU0UgQ0hVTktFRCBkZWNvbXByZXNzb3IgaXMgc3VwcG9ydGVkAE5vIExBU3ppcCBWTFIgd2FzIGZvdW5kIGluIHRoZSBWTFJzIHNlY3Rpb24ATjZsYXN6aXAyMmNodW5rX3RhYmxlX3JlYWRfZXJyb3JFAENodW5rIHRhYmxlIG9mZnNldCA9PSAtMSBpcyBub3Qgc3VwcG9ydGVkIGF0IHRoaXMgdGltZQBONmxhc3ppcDEzbm90X3N1cHBvcnRlZEUATjZsYXN6aXAyNnVua25vd25fY2h1bmtfdGFibGVfZm9ybWF0RQBjaHVua19zaXplID09IHVpbnQubWF4IGlzIG5vdCBzdXBwb3J0ZWQgYXQgdGhpcyB0aW1lLgBUaGVyZSB3YXMgYSBwcm9ibGVtIHJlYWRpbmcgdGhlIGNodW5rIHRhYmxlAFRoZSBjaHVuayB0YWJsZSB2ZXJzaW9uIG51bWJlciBpcyB1bmtub3duAE42bGFzemlwMTFlbmRfb2ZfZmlsZUUAUmVhY2hlZCBFbmQgb2YgZmlsZQBJbnZhbGlkIG51bWJlciBvZiBzeW1ib2xzAE5TdDNfXzIyMF9fc2hhcmVkX3B0cl9wb2ludGVySVBONmxhc3ppcDhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOU18xNGRlZmF1bHRfZGVsZXRlSVM5X0VFTlNfOWFsbG9jYXRvcklTOV9FRUVFAE5TdDNfXzIxNGRlZmF1bHRfZGVsZXRlSU42bGFzemlwOGRlY29kZXJzMTBhcml0aG1ldGljSU5TMV8yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOUzFfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRUVFAE42bGFzemlwMTl1bmtub3duX3NjaGVtYV90eXBlRQBUaGUgTEFaIHNjaGVtYSBpcyBub3QgcmVjb2duaXplZABONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2ZpZWxkX2RlY29tcHJlc3NvcklOU184ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlNfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlNfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyMGR5bmFtaWNfZGVjb21wcmVzc29yRQBOU3QzX18yMjBfX3NoYXJlZF9wdHJfcG9pbnRlcklQTjZsYXN6aXA3Zm9ybWF0czI2ZHluYW1pY19maWVsZF9kZWNvbXByZXNzb3JJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVFRU5TXzE0ZGVmYXVsdF9kZWxldGVJU0NfRUVOU185YWxsb2NhdG9ySVNDX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXA3Zm9ybWF0czI2ZHluYW1pY19maWVsZF9kZWNvbXByZXNzb3JJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOU18yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOU183c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMwXzVmaWVsZElOUzBfM2xhczdwb2ludDEwRU5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNDX0VFRUVFRQBONmxhc3ppcDdmb3JtYXRzMTBiYXNlX2ZpZWxkRQBOU3QzX18yMjBfX3NoYXJlZF9wdHJfcG9pbnRlcklQTjZsYXN6aXA3Zm9ybWF0czI2ZHluYW1pY19kZWNvbXByZXNzb3JfZmllbGRJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzJfNWZpZWxkSU5TMl8zbGFzN3BvaW50MTBFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0VfRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTSV9FRU5TXzlhbGxvY2F0b3JJU0lfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TMV8yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOUzFfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRU5TMl81ZmllbGRJTlMyXzNsYXM3cG9pbnQxMEVOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTRV9FRUVFRUVFRQBONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOU184ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlNfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlNfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRU5TMF81ZmllbGRJTlMwXzNsYXM3Z3BzdGltZUVOUzBfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTQ19FRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzVmaWVsZElOUzJfM2xhczdncHN0aW1lRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNFX0VFRUVFRU5TXzE0ZGVmYXVsdF9kZWxldGVJU0lfRUVOU185YWxsb2NhdG9ySVNJX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXA3Zm9ybWF0czI2ZHluYW1pY19kZWNvbXByZXNzb3JfZmllbGRJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzJfNWZpZWxkSU5TMl8zbGFzN2dwc3RpbWVFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0VfRUVFRUVFRUUATjZsYXN6aXA3Zm9ybWF0czI2ZHluYW1pY19kZWNvbXByZXNzb3JfZmllbGRJTlNfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzBfNWZpZWxkSU5TMF8zbGFzM3JnYkVOUzBfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTQ19FRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzVmaWVsZElOUzJfM2xhczNyZ2JFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0VfRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTSV9FRU5TXzlhbGxvY2F0b3JJU0lfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TMV8yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOUzFfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRU5TMl81ZmllbGRJTlMyXzNsYXMzcmdiRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNFX0VFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOU18yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOU183c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMwXzVmaWVsZElOUzBfM2xhczEwZXh0cmFieXRlc0VOUzBfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTQ19FRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzVmaWVsZElOUzJfM2xhczEwZXh0cmFieXRlc0VOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTRV9FRUVFRUVOU18xNGRlZmF1bHRfZGVsZXRlSVNJX0VFTlNfOWFsbG9jYXRvcklTSV9FRUVFAE5TdDNfXzIxNGRlZmF1bHRfZGVsZXRlSU42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzVmaWVsZElOUzJfM2xhczEwZXh0cmFieXRlc0VOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTRV9FRUVFRUVFRQBONmxhc3ppcDdmb3JtYXRzMjFkeW5hbWljX2RlY29tcHJlc3NvcjFJTlNfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzBfMTlyZWNvcmRfZGVjb21wcmVzc29ySUpOUzBfNWZpZWxkSU5TMF8zbGFzN3BvaW50MTBFTlMwXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0RfRUVFRUVFRUVFAE5TdDNfXzIyMF9fc2hhcmVkX3B0cl9wb2ludGVySVBONmxhc3ppcDdmb3JtYXRzMjFkeW5hbWljX2RlY29tcHJlc3NvcjFJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzJfMTlyZWNvcmRfZGVjb21wcmVzc29ySUpOUzJfNWZpZWxkSU5TMl8zbGFzN3BvaW50MTBFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0ZfRUVFRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTS19FRU5TXzlhbGxvY2F0b3JJU0tfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjFkeW5hbWljX2RlY29tcHJlc3NvcjFJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzJfMTlyZWNvcmRfZGVjb21wcmVzc29ySUpOUzJfNWZpZWxkSU5TMl8zbGFzN3BvaW50MTBFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0ZfRUVFRUVFRUVFRUUATjZsYXN6aXA3Zm9ybWF0czIxZHluYW1pY19kZWNvbXByZXNzb3IxSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOU18yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOU183c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMwXzE5cmVjb3JkX2RlY29tcHJlc3NvcklKTlMwXzVmaWVsZElOUzBfM2xhczdwb2ludDEwRU5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNEX0VFRUVOU0JfSU5TQ183Z3BzdGltZUVOU0VfSVNIX0VFRUVFRUVFRQBOU3QzX18yMjBfX3NoYXJlZF9wdHJfcG9pbnRlcklQTjZsYXN6aXA3Zm9ybWF0czIxZHluYW1pY19kZWNvbXByZXNzb3IxSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzE5cmVjb3JkX2RlY29tcHJlc3NvcklKTlMyXzVmaWVsZElOUzJfM2xhczdwb2ludDEwRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNGX0VFRUVOU0RfSU5TRV83Z3BzdGltZUVOU0dfSVNKX0VFRUVFRUVFRU5TXzE0ZGVmYXVsdF9kZWxldGVJU05fRUVOU185YWxsb2NhdG9ySVNOX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXA3Zm9ybWF0czIxZHluYW1pY19kZWNvbXByZXNzb3IxSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzE5cmVjb3JkX2RlY29tcHJlc3NvcklKTlMyXzVmaWVsZElOUzJfM2xhczdwb2ludDEwRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNGX0VFRUVOU0RfSU5TRV83Z3BzdGltZUVOU0dfSVNKX0VFRUVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyMWR5bmFtaWNfZGVjb21wcmVzc29yMUlOU184ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlNfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlNfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRU5TMF8xOXJlY29yZF9kZWNvbXByZXNzb3JJSk5TMF81ZmllbGRJTlMwXzNsYXM3cG9pbnQxMEVOUzBfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTRF9FRUVFTlNCX0lOU0NfM3JnYkVOU0VfSVNIX0VFRUVFRUVFRQBOU3QzX18yMjBfX3NoYXJlZF9wdHJfcG9pbnRlcklQTjZsYXN6aXA3Zm9ybWF0czIxZHluYW1pY19kZWNvbXByZXNzb3IxSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzE5cmVjb3JkX2RlY29tcHJlc3NvcklKTlMyXzVmaWVsZElOUzJfM2xhczdwb2ludDEwRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNGX0VFRUVOU0RfSU5TRV8zcmdiRU5TR19JU0pfRUVFRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTTl9FRU5TXzlhbGxvY2F0b3JJU05fRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjFkeW5hbWljX2RlY29tcHJlc3NvcjFJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzJfMTlyZWNvcmRfZGVjb21wcmVzc29ySUpOUzJfNWZpZWxkSU5TMl8zbGFzN3BvaW50MTBFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0ZfRUVFRU5TRF9JTlNFXzNyZ2JFTlNHX0lTSl9FRUVFRUVFRUVFRQBONmxhc3ppcDdmb3JtYXRzMjFkeW5hbWljX2RlY29tcHJlc3NvcjFJTlNfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzBfMTlyZWNvcmRfZGVjb21wcmVzc29ySUpOUzBfNWZpZWxkSU5TMF8zbGFzN3BvaW50MTBFTlMwXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0RfRUVFRU5TQl9JTlNDXzdncHN0aW1lRU5TRV9JU0hfRUVFRU5TQl9JTlNDXzNyZ2JFTlNFX0lTS19FRUVFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyMWR5bmFtaWNfZGVjb21wcmVzc29yMUlOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TMV8yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOUzFfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRU5TMl8xOXJlY29yZF9kZWNvbXByZXNzb3JJSk5TMl81ZmllbGRJTlMyXzNsYXM3cG9pbnQxMEVOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTRl9FRUVFTlNEX0lOU0VfN2dwc3RpbWVFTlNHX0lTSl9FRUVFTlNEX0lOU0VfM3JnYkVOU0dfSVNNX0VFRUVFRUVFRU5TXzE0ZGVmYXVsdF9kZWxldGVJU1FfRUVOU185YWxsb2NhdG9ySVNRX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXA3Zm9ybWF0czIxZHluYW1pY19kZWNvbXByZXNzb3IxSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzE5cmVjb3JkX2RlY29tcHJlc3NvcklKTlMyXzVmaWVsZElOUzJfM2xhczdwb2ludDEwRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNGX0VFRUVOU0RfSU5TRV83Z3BzdGltZUVOU0dfSVNKX0VFRUVOU0RfSU5TRV8zcmdiRU5TR19JU01fRUVFRUVFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUDEwYnVmX3N0cmVhbU5TXzE0ZGVmYXVsdF9kZWxldGVJUzFfRUVOU185YWxsb2NhdG9ySVMxX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJMTBidWZfc3RyZWFtRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTNV9FRU5TXzlhbGxvY2F0b3JJUzVfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZmllbGRfZGVjb21wcmVzc29ySU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRUVFAE5TdDNfXzIyMF9fc2hhcmVkX3B0cl9wb2ludGVySVBONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2ZpZWxkX2RlY29tcHJlc3NvcklOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFRUVOU18xNGRlZmF1bHRfZGVsZXRlSVM4X0VFTlNfOWFsbG9jYXRvcklTOF9FRUVFAE5TdDNfXzIxNGRlZmF1bHRfZGVsZXRlSU42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZmllbGRfZGVjb21wcmVzc29ySU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJaU5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSWlFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSWlOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElpRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZElpTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJaUVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJak5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSWpFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSWpOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElqRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZElqTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJakVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJYU5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSWFFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSWFOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElhRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZElhTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJYUVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJc05TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSXNFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSXNOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElzRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZElzTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJc0VFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJaE5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSWhFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSWhOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZEloRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZEloTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJaEVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJdE5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSXRFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSXROUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZEl0RUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZEl0TlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJdEVFRUVFRUVFADZMQVNaaXAAUDZMQVNaaXAAUEs2TEFTWmlwAGlpAHYAdmkAdmlpaWkAdmlpaQBpaWkAMTNEeW5hbWljTEFTWmlwAFAxM0R5bmFtaWNMQVNaaXAAUEsxM0R5bmFtaWNMQVNaaXAAdm9pZABib29sAGNoYXIAc2lnbmVkIGNoYXIAdW5zaWduZWQgY2hhcgBzaG9ydAB1bnNpZ25lZCBzaG9ydABpbnQAdW5zaWduZWQgaW50AGxvbmcAdW5zaWduZWQgbG9uZwBmbG9hdABkb3VibGUAc3RkOjpzdHJpbmcAc3RkOjpiYXNpY19zdHJpbmc8dW5zaWduZWQgY2hhcj4Ac3RkOjp3c3RyaW5nAHN0ZDo6dTE2c3RyaW5nAHN0ZDo6dTMyc3RyaW5nAGVtc2NyaXB0ZW46OnZhbABlbXNjcmlwdGVuOjptZW1vcnlfdmlldzxjaGFyPgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzxzaWduZWQgY2hhcj4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8dW5zaWduZWQgY2hhcj4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8c2hvcnQ+AGVtc2NyaXB0ZW46Om1lbW9yeV92aWV3PHVuc2lnbmVkIHNob3J0PgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzxpbnQ+AGVtc2NyaXB0ZW46Om1lbW9yeV92aWV3PHVuc2lnbmVkIGludD4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8bG9uZz4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8dW5zaWduZWQgbG9uZz4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8aW50OF90PgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzx1aW50OF90PgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzxpbnQxNl90PgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzx1aW50MTZfdD4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8aW50MzJfdD4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8dWludDMyX3Q+AGVtc2NyaXB0ZW46Om1lbW9yeV92aWV3PGZsb2F0PgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzxkb3VibGU+AGVtc2NyaXB0ZW46Om1lbW9yeV92aWV3PGxvbmcgZG91YmxlPgBOMTBlbXNjcmlwdGVuMTFtZW1vcnlfdmlld0llRUUATjEwZW1zY3JpcHRlbjExbWVtb3J5X3ZpZXdJZEVFAE4xMGVtc2NyaXB0ZW4xMW1lbW9yeV92aWV3SWZFRQBOMTBlbXNjcmlwdGVuMTFtZW1vcnlfdmlld0ltRUUATjEwZW1zY3JpcHRlbjExbWVtb3J5X3ZpZXdJbEVFAE4xMGVtc2NyaXB0ZW4xMW1lbW9yeV92aWV3SWpFRQBOMTBlbXNjcmlwdGVuMTFtZW1vcnlfdmlld0lpRUUATjEwZW1zY3JpcHRlbjExbWVtb3J5X3ZpZXdJdEVFAE4xMGVtc2NyaXB0ZW4xMW1lbW9yeV92aWV3SXNFRQBOMTBlbXNjcmlwdGVuMTFtZW1vcnlfdmlld0loRUUATjEwZW1zY3JpcHRlbjExbWVtb3J5X3ZpZXdJYUVFAE4xMGVtc2NyaXB0ZW4xMW1lbW9yeV92aWV3SWNFRQBOMTBlbXNjcmlwdGVuM3ZhbEUATlN0M19fMjEyYmFzaWNfc3RyaW5nSURpTlNfMTFjaGFyX3RyYWl0c0lEaUVFTlNfOWFsbG9jYXRvcklEaUVFRUUATlN0M19fMjIxX19iYXNpY19zdHJpbmdfY29tbW9uSUxiMUVFRQBOU3QzX18yMTJiYXNpY19zdHJpbmdJRHNOU18xMWNoYXJfdHJhaXRzSURzRUVOU185YWxsb2NhdG9ySURzRUVFRQBOU3QzX18yMTJiYXNpY19zdHJpbmdJd05TXzExY2hhcl90cmFpdHNJd0VFTlNfOWFsbG9jYXRvckl3RUVFRQBOU3QzX18yMTJiYXNpY19zdHJpbmdJaE5TXzExY2hhcl90cmFpdHNJaEVFTlNfOWFsbG9jYXRvckloRUVFRQBOU3QzX18yMTJiYXNpY19zdHJpbmdJY05TXzExY2hhcl90cmFpdHNJY0VFTlNfOWFsbG9jYXRvckljRUVFRQAtKyAgIDBYMHgAKG51bGwpAC0wWCswWCAwWC0weCsweCAweABpbmYASU5GAG5hbgBOQU4ALgB0ZXJtaW5hdGluZyB3aXRoICVzIGV4Y2VwdGlvbiBvZiB0eXBlICVzOiAlcwB0ZXJtaW5hdGluZyB3aXRoICVzIGV4Y2VwdGlvbiBvZiB0eXBlICVzAHRlcm1pbmF0aW5nIHdpdGggJXMgZm9yZWlnbiBleGNlcHRpb24AdGVybWluYXRpbmcAdW5jYXVnaHQAU3Q5ZXhjZXB0aW9uAE4xMF9fY3h4YWJpdjExNl9fc2hpbV90eXBlX2luZm9FAFN0OXR5cGVfaW5mbwBOMTBfX2N4eGFiaXYxMjBfX3NpX2NsYXNzX3R5cGVfaW5mb0UATjEwX19jeHhhYml2MTE3X19jbGFzc190eXBlX2luZm9FAHRlcm1pbmF0ZV9oYW5kbGVyIHVuZXhwZWN0ZWRseSByZXR1cm5lZABzdGQ6OmJhZF9hbGxvYwBTdDliYWRfYWxsb2MAU3QxMWxvZ2ljX2Vycm9yAFN0MTNydW50aW1lX2Vycm9yAFN0MTJsZW5ndGhfZXJyb3IAU3QxMm91dF9vZl9yYW5nZQBOMTBfX2N4eGFiaXYxMTdfX3BiYXNlX3R5cGVfaW5mb0UATjEwX19jeHhhYml2MTE5X19wb2ludGVyX3R5cGVfaW5mb0UATjEwX19jeHhhYml2MTIwX19mdW5jdGlvbl90eXBlX2luZm9FAE4xMF9fY3h4YWJpdjEyOV9fcG9pbnRlcl90b19tZW1iZXJfdHlwZV9pbmZvRQBQdXJlIHZpcnR1YWwgZnVuY3Rpb24gY2FsbGVkIQBOMTBfX2N4eGFiaXYxMjNfX2Z1bmRhbWVudGFsX3R5cGVfaW5mb0UAdgBEbgBiAGMAaABhAHMAdABpAGoAbABtAGYAZABOMTBfX2N4eGFiaXYxMjFfX3ZtaV9jbGFzc190eXBlX2luZm9FAF9fY3hhX2d1YXJkX2FjcXVpcmUgZGV0ZWN0ZWQgcmVjdXJzaXZlIGluaXRpYWxpemF0aW9uAHN0ZDo6YmFkX2Z1bmN0aW9uX2NhbGwATlN0M19fMjE3YmFkX2Z1bmN0aW9uX2NhbGxFAE5TdDNfXzIxNF9fc2hhcmVkX2NvdW50RQBOU3QzX18yMTlfX3NoYXJlZF93ZWFrX2NvdW50RQBtdXRleCBsb2NrIGZhaWxlZABiYXNpY19zdHJpbmcAdW5zcGVjaWZpZWQgZ2VuZXJpY19jYXRlZ29yeSBlcnJvcgBVbmtub3duIGVycm9yICVkAGdlbmVyaWMATlN0M19fMjI0X19nZW5lcmljX2Vycm9yX2NhdGVnb3J5RQBOU3QzX18yMTJfX2RvX21lc3NhZ2VFAE5TdDNfXzIxNGVycm9yX2NhdGVnb3J5RQB1bnNwZWNpZmllZCBzeXN0ZW1fY2F0ZWdvcnkgZXJyb3IAc3lzdGVtAE5TdDNfXzIyM19fc3lzdGVtX2Vycm9yX2NhdGVnb3J5RQBOU3QzX18yMTJzeXN0ZW1fZXJyb3JFADogAHZlY3Rvcg=='; - var tempDoublePtr = 22368; - function ___cxa_allocate_exception(size) { - return _malloc(size); - } - var ___exception_infos = {}; - function ___exception_addRef(ptr) { - if (!ptr) - return; - var info = ___exception_infos[ptr]; - info.refcount++; - } - function ___exception_deAdjust(adjusted) { - if (!adjusted || ___exception_infos[adjusted]) - return adjusted; - for (var key in ___exception_infos) { - var ptr = +key; - var adj = ___exception_infos[ptr].adjusted; - var len = adj.length; - for (var i = 0; i < len; i++) { - if (adj[i] === adjusted) { - return ptr; - } - } - } - return adjusted; - } - function ___cxa_begin_catch(ptr) { - var info = ___exception_infos[ptr]; - if (info && !info.caught) { - info.caught = true; - __ZSt18uncaught_exceptionv.uncaught_exceptions--; - } - if (info) - info.rethrown = false; - ___exception_addRef(___exception_deAdjust(ptr)); - return ptr; - } - function ___cxa_throw(ptr, type, destructor) { - ___exception_infos[ptr] = { - ptr: ptr, - adjusted: [ptr], - type: type, - destructor: destructor, - refcount: 0, - caught: false, - rethrown: false - }; - if (!('uncaught_exception' in __ZSt18uncaught_exceptionv)) { - __ZSt18uncaught_exceptionv.uncaught_exceptions = 1; - } - else { - __ZSt18uncaught_exceptionv.uncaught_exceptions++; - } - throw ptr; - } - function ___cxa_uncaught_exceptions() { - return __ZSt18uncaught_exceptionv.uncaught_exceptions; - } - function ___gxx_personality_v0() { } - function getShiftFromSize(size) { - switch (size) { - case 1: - return 0; - case 2: - return 1; - case 4: - return 2; - case 8: - return 3; - default: - throw new TypeError('Unknown type size: ' + size); - } - } - function embind_init_charCodes() { - var codes = new Array(256); - for (var i = 0; i < 256; ++i) { - codes[i] = String.fromCharCode(i); - } - embind_charCodes = codes; - } - var embind_charCodes = undefined; - function readLatin1String(ptr) { - var ret = ''; - var c = ptr; - while (HEAPU8[c]) { - ret += embind_charCodes[HEAPU8[c++]]; - } - return ret; - } - var awaitingDependencies = {}; - var registeredTypes = {}; - var typeDependencies = {}; - var char_0 = 48; - var char_9 = 57; - function makeLegalFunctionName(name) { - if (undefined === name) { - return '_unknown'; - } - name = name.replace(/[^a-zA-Z0-9_]/g, '$'); - var f = name.charCodeAt(0); - if (f >= char_0 && f <= char_9) { - return '_' + name; - } - else { - return name; - } - } - function createNamedFunction(name, body) { - name = makeLegalFunctionName(name); - return new Function('body', 'return function ' + - name + - '() {\n' + - ' "use strict";' + - ' return body.apply(this, arguments);\n' + - '};\n')(body); - } - function extendError(baseErrorType, errorName) { - var errorClass = createNamedFunction(errorName, function (message) { - this.name = errorName; - this.message = message; - var stack = new Error(message).stack; - if (stack !== undefined) { - this.stack = this.toString() + '\n' + stack.replace(/^Error(:[^\n]*)?\n/, ''); - } - }); - errorClass.prototype = Object.create(baseErrorType.prototype); - errorClass.prototype.constructor = errorClass; - errorClass.prototype.toString = function () { - if (this.message === undefined) { - return this.name; - } - else { - return this.name + ': ' + this.message; - } - }; - return errorClass; - } - var BindingError = undefined; - function throwBindingError(message) { - throw new BindingError(message); - } - var InternalError = undefined; - function throwInternalError(message) { - throw new InternalError(message); - } - function whenDependentTypesAreResolved(myTypes, dependentTypes, getTypeConverters) { - myTypes.forEach(function (type) { - typeDependencies[type] = dependentTypes; - }); - function onComplete(typeConverters) { - var myTypeConverters = getTypeConverters(typeConverters); - if (myTypeConverters.length !== myTypes.length) { - throwInternalError('Mismatched type converter count'); - } - for (var i = 0; i < myTypes.length; ++i) { - registerType(myTypes[i], myTypeConverters[i]); - } - } - var typeConverters = new Array(dependentTypes.length); - var unregisteredTypes = []; - var registered = 0; - dependentTypes.forEach(function (dt, i) { - if (registeredTypes.hasOwnProperty(dt)) { - typeConverters[i] = registeredTypes[dt]; - } - else { - unregisteredTypes.push(dt); - if (!awaitingDependencies.hasOwnProperty(dt)) { - awaitingDependencies[dt] = []; - } - awaitingDependencies[dt].push(function () { - typeConverters[i] = registeredTypes[dt]; - ++registered; - if (registered === unregisteredTypes.length) { - onComplete(typeConverters); - } - }); - } - }); - if (0 === unregisteredTypes.length) { - onComplete(typeConverters); - } - } - function registerType(rawType, registeredInstance, options) { - options = options || {}; - if (!('argPackAdvance' in registeredInstance)) { - throw new TypeError('registerType registeredInstance requires argPackAdvance'); - } - var name = registeredInstance.name; - if (!rawType) { - throwBindingError('type "' + name + '" must have a positive integer typeid pointer'); - } - if (registeredTypes.hasOwnProperty(rawType)) { - if (options.ignoreDuplicateRegistrations) { - return; - } - else { - throwBindingError("Cannot register type '" + name + "' twice"); - } - } - registeredTypes[rawType] = registeredInstance; - delete typeDependencies[rawType]; - if (awaitingDependencies.hasOwnProperty(rawType)) { - var callbacks = awaitingDependencies[rawType]; - delete awaitingDependencies[rawType]; - callbacks.forEach(function (cb) { - cb(); - }); - } - } - function __embind_register_bool(rawType, name, size, trueValue, falseValue) { - var shift = getShiftFromSize(size); - name = readLatin1String(name); - registerType(rawType, { - name: name, - fromWireType: function (wt) { - return !!wt; - }, - toWireType: function (destructors, o) { - return o ? trueValue : falseValue; - }, - argPackAdvance: 8, - readValueFromPointer: function (pointer) { - var heap; - if (size === 1) { - heap = HEAP8; - } - else if (size === 2) { - heap = HEAP16; - } - else if (size === 4) { - heap = HEAP32; - } - else { - throw new TypeError('Unknown boolean type size: ' + name); - } - return this['fromWireType'](heap[pointer >> shift]); - }, - destructorFunction: null - }); - } - function ClassHandle_isAliasOf(other) { - if (!(this instanceof ClassHandle)) { - return false; - } - if (!(other instanceof ClassHandle)) { - return false; - } - var leftClass = this.$$.ptrType.registeredClass; - var left = this.$$.ptr; - var rightClass = other.$$.ptrType.registeredClass; - var right = other.$$.ptr; - while (leftClass.baseClass) { - left = leftClass.upcast(left); - leftClass = leftClass.baseClass; - } - while (rightClass.baseClass) { - right = rightClass.upcast(right); - rightClass = rightClass.baseClass; - } - return leftClass === rightClass && left === right; - } - function shallowCopyInternalPointer(o) { - return { - count: o.count, - deleteScheduled: o.deleteScheduled, - preservePointerOnDelete: o.preservePointerOnDelete, - ptr: o.ptr, - ptrType: o.ptrType, - smartPtr: o.smartPtr, - smartPtrType: o.smartPtrType - }; - } - function throwInstanceAlreadyDeleted(obj) { - function getInstanceTypeName(handle) { - return handle.$$.ptrType.registeredClass.name; - } - throwBindingError(getInstanceTypeName(obj) + ' instance already deleted'); - } - var finalizationGroup = false; - function detachFinalizer(handle) { } - function runDestructor($$) { - if ($$.smartPtr) { - $$.smartPtrType.rawDestructor($$.smartPtr); - } - else { - $$.ptrType.registeredClass.rawDestructor($$.ptr); - } - } - function releaseClassHandle($$) { - $$.count.value -= 1; - var toDelete = 0 === $$.count.value; - if (toDelete) { - runDestructor($$); - } - } - function attachFinalizer(handle) { - if ('undefined' === typeof FinalizationGroup) { - attachFinalizer = function (handle) { - return handle; - }; - return handle; - } - finalizationGroup = new FinalizationGroup(function (iter) { - for (var result = iter.next(); !result.done; result = iter.next()) { - var $$ = result.value; - if (!$$.ptr) { - console.warn('object already deleted: ' + $$.ptr); - } - else { - releaseClassHandle($$); - } - } - }); - attachFinalizer = function (handle) { - finalizationGroup.register(handle, handle.$$, handle.$$); - return handle; - }; - detachFinalizer = function (handle) { - finalizationGroup.unregister(handle.$$); - }; - return attachFinalizer(handle); - } - function ClassHandle_clone() { - if (!this.$$.ptr) { - throwInstanceAlreadyDeleted(this); - } - if (this.$$.preservePointerOnDelete) { - this.$$.count.value += 1; - return this; - } - else { - var clone = attachFinalizer(Object.create(Object.getPrototypeOf(this), { - $$: { - value: shallowCopyInternalPointer(this.$$) - } - })); - clone.$$.count.value += 1; - clone.$$.deleteScheduled = false; - return clone; - } - } - function ClassHandle_delete() { - if (!this.$$.ptr) { - throwInstanceAlreadyDeleted(this); - } - if (this.$$.deleteScheduled && !this.$$.preservePointerOnDelete) { - throwBindingError('Object already scheduled for deletion'); - } - detachFinalizer(this); - releaseClassHandle(this.$$); - if (!this.$$.preservePointerOnDelete) { - this.$$.smartPtr = undefined; - this.$$.ptr = undefined; - } - } - function ClassHandle_isDeleted() { - return !this.$$.ptr; - } - var delayFunction = undefined; - var deletionQueue = []; - function flushPendingDeletes() { - while (deletionQueue.length) { - var obj = deletionQueue.pop(); - obj.$$.deleteScheduled = false; - obj['delete'](); - } - } - function ClassHandle_deleteLater() { - if (!this.$$.ptr) { - throwInstanceAlreadyDeleted(this); - } - if (this.$$.deleteScheduled && !this.$$.preservePointerOnDelete) { - throwBindingError('Object already scheduled for deletion'); - } - deletionQueue.push(this); - if (deletionQueue.length === 1 && delayFunction) { - delayFunction(flushPendingDeletes); - } - this.$$.deleteScheduled = true; - return this; - } - function init_ClassHandle() { - ClassHandle.prototype['isAliasOf'] = ClassHandle_isAliasOf; - ClassHandle.prototype['clone'] = ClassHandle_clone; - ClassHandle.prototype['delete'] = ClassHandle_delete; - ClassHandle.prototype['isDeleted'] = ClassHandle_isDeleted; - ClassHandle.prototype['deleteLater'] = ClassHandle_deleteLater; - } - function ClassHandle() { } - var registeredPointers = {}; - function ensureOverloadTable(proto, methodName, humanName) { - if (undefined === proto[methodName].overloadTable) { - var prevFunc = proto[methodName]; - proto[methodName] = function () { - if (!proto[methodName].overloadTable.hasOwnProperty(arguments.length)) { - throwBindingError("Function '" + - humanName + - "' called with an invalid number of arguments (" + - arguments.length + - ') - expects one of (' + - proto[methodName].overloadTable + - ')!'); - } - return proto[methodName].overloadTable[arguments.length].apply(this, arguments); - }; - proto[methodName].overloadTable = []; - proto[methodName].overloadTable[prevFunc.argCount] = prevFunc; - } - } - function exposePublicSymbol(name, value, numArguments) { - if (Module.hasOwnProperty(name)) { - if (undefined === numArguments || - (undefined !== Module[name].overloadTable && - undefined !== Module[name].overloadTable[numArguments])) { - throwBindingError("Cannot register public name '" + name + "' twice"); - } - ensureOverloadTable(Module, name, name); - if (Module.hasOwnProperty(numArguments)) { - throwBindingError('Cannot register multiple overloads of a function with the same number of arguments (' + - numArguments + - ')!'); - } - Module[name].overloadTable[numArguments] = value; - } - else { - Module[name] = value; - if (undefined !== numArguments) { - Module[name].numArguments = numArguments; - } - } - } - function RegisteredClass(name, constructor, instancePrototype, rawDestructor, baseClass, getActualType, upcast, downcast) { - this.name = name; - this.constructor = constructor; - this.instancePrototype = instancePrototype; - this.rawDestructor = rawDestructor; - this.baseClass = baseClass; - this.getActualType = getActualType; - this.upcast = upcast; - this.downcast = downcast; - this.pureVirtualFunctions = []; - } - function upcastPointer(ptr, ptrClass, desiredClass) { - while (ptrClass !== desiredClass) { - if (!ptrClass.upcast) { - throwBindingError('Expected null or instance of ' + - desiredClass.name + - ', got an instance of ' + - ptrClass.name); - } - ptr = ptrClass.upcast(ptr); - ptrClass = ptrClass.baseClass; - } - return ptr; - } - function constNoSmartPtrRawPointerToWireType(destructors, handle) { - if (handle === null) { - if (this.isReference) { - throwBindingError('null is not a valid ' + this.name); - } - return 0; - } - if (!handle.$$) { - throwBindingError('Cannot pass "' + _embind_repr(handle) + '" as a ' + this.name); - } - if (!handle.$$.ptr) { - throwBindingError('Cannot pass deleted object as a pointer of type ' + this.name); - } - var handleClass = handle.$$.ptrType.registeredClass; - var ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass); - return ptr; - } - function genericPointerToWireType(destructors, handle) { - var ptr; - if (handle === null) { - if (this.isReference) { - throwBindingError('null is not a valid ' + this.name); - } - if (this.isSmartPointer) { - ptr = this.rawConstructor(); - if (destructors !== null) { - destructors.push(this.rawDestructor, ptr); - } - return ptr; - } - else { - return 0; - } - } - if (!handle.$$) { - throwBindingError('Cannot pass "' + _embind_repr(handle) + '" as a ' + this.name); - } - if (!handle.$$.ptr) { - throwBindingError('Cannot pass deleted object as a pointer of type ' + this.name); - } - if (!this.isConst && handle.$$.ptrType.isConst) { - throwBindingError('Cannot convert argument of type ' + - (handle.$$.smartPtrType ? handle.$$.smartPtrType.name : handle.$$.ptrType.name) + - ' to parameter type ' + - this.name); - } - var handleClass = handle.$$.ptrType.registeredClass; - ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass); - if (this.isSmartPointer) { - if (undefined === handle.$$.smartPtr) { - throwBindingError('Passing raw pointer to smart pointer is illegal'); - } - switch (this.sharingPolicy) { - case 0: - if (handle.$$.smartPtrType === this) { - ptr = handle.$$.smartPtr; - } - else { - throwBindingError('Cannot convert argument of type ' + - (handle.$$.smartPtrType ? handle.$$.smartPtrType.name : handle.$$.ptrType.name) + - ' to parameter type ' + - this.name); - } - break; - case 1: - ptr = handle.$$.smartPtr; - break; - case 2: - if (handle.$$.smartPtrType === this) { - ptr = handle.$$.smartPtr; - } - else { - var clonedHandle = handle['clone'](); - ptr = this.rawShare(ptr, __emval_register(function () { - clonedHandle['delete'](); - })); - if (destructors !== null) { - destructors.push(this.rawDestructor, ptr); - } - } - break; - default: - throwBindingError('Unsupporting sharing policy'); - } - } - return ptr; - } - function nonConstNoSmartPtrRawPointerToWireType(destructors, handle) { - if (handle === null) { - if (this.isReference) { - throwBindingError('null is not a valid ' + this.name); - } - return 0; - } - if (!handle.$$) { - throwBindingError('Cannot pass "' + _embind_repr(handle) + '" as a ' + this.name); - } - if (!handle.$$.ptr) { - throwBindingError('Cannot pass deleted object as a pointer of type ' + this.name); - } - if (handle.$$.ptrType.isConst) { - throwBindingError('Cannot convert argument of type ' + - handle.$$.ptrType.name + - ' to parameter type ' + - this.name); - } - var handleClass = handle.$$.ptrType.registeredClass; - var ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass); - return ptr; - } - function simpleReadValueFromPointer(pointer) { - return this['fromWireType'](HEAPU32[pointer >> 2]); - } - function RegisteredPointer_getPointee(ptr) { - if (this.rawGetPointee) { - ptr = this.rawGetPointee(ptr); - } - return ptr; - } - function RegisteredPointer_destructor(ptr) { - if (this.rawDestructor) { - this.rawDestructor(ptr); - } - } - function RegisteredPointer_deleteObject(handle) { - if (handle !== null) { - handle['delete'](); - } - } - function downcastPointer(ptr, ptrClass, desiredClass) { - if (ptrClass === desiredClass) { - return ptr; - } - if (undefined === desiredClass.baseClass) { - return null; - } - var rv = downcastPointer(ptr, ptrClass, desiredClass.baseClass); - if (rv === null) { - return null; - } - return desiredClass.downcast(rv); - } - function getInheritedInstanceCount() { - return Object.keys(registeredInstances).length; - } - function getLiveInheritedInstances() { - var rv = []; - for (var k in registeredInstances) { - if (registeredInstances.hasOwnProperty(k)) { - rv.push(registeredInstances[k]); - } - } - return rv; - } - function setDelayFunction(fn) { - delayFunction = fn; - if (deletionQueue.length && delayFunction) { - delayFunction(flushPendingDeletes); - } - } - function init_embind() { - Module['getInheritedInstanceCount'] = getInheritedInstanceCount; - Module['getLiveInheritedInstances'] = getLiveInheritedInstances; - Module['flushPendingDeletes'] = flushPendingDeletes; - Module['setDelayFunction'] = setDelayFunction; - } - var registeredInstances = {}; - function getBasestPointer(class_, ptr) { - if (ptr === undefined) { - throwBindingError('ptr should not be undefined'); - } - while (class_.baseClass) { - ptr = class_.upcast(ptr); - class_ = class_.baseClass; - } - return ptr; - } - function getInheritedInstance(class_, ptr) { - ptr = getBasestPointer(class_, ptr); - return registeredInstances[ptr]; - } - function makeClassHandle(prototype, record) { - if (!record.ptrType || !record.ptr) { - throwInternalError('makeClassHandle requires ptr and ptrType'); - } - var hasSmartPtrType = !!record.smartPtrType; - var hasSmartPtr = !!record.smartPtr; - if (hasSmartPtrType !== hasSmartPtr) { - throwInternalError('Both smartPtrType and smartPtr must be specified'); - } - record.count = { - value: 1 - }; - return attachFinalizer(Object.create(prototype, { - $$: { - value: record - } - })); - } - function RegisteredPointer_fromWireType(ptr) { - var rawPointer = this.getPointee(ptr); - if (!rawPointer) { - this.destructor(ptr); - return null; - } - var registeredInstance = getInheritedInstance(this.registeredClass, rawPointer); - if (undefined !== registeredInstance) { - if (0 === registeredInstance.$$.count.value) { - registeredInstance.$$.ptr = rawPointer; - registeredInstance.$$.smartPtr = ptr; - return registeredInstance['clone'](); - } - else { - var rv = registeredInstance['clone'](); - this.destructor(ptr); - return rv; - } - } - function makeDefaultHandle() { - if (this.isSmartPointer) { - return makeClassHandle(this.registeredClass.instancePrototype, { - ptrType: this.pointeeType, - ptr: rawPointer, - smartPtrType: this, - smartPtr: ptr - }); - } - else { - return makeClassHandle(this.registeredClass.instancePrototype, { - ptrType: this, - ptr: ptr - }); - } - } - var actualType = this.registeredClass.getActualType(rawPointer); - var registeredPointerRecord = registeredPointers[actualType]; - if (!registeredPointerRecord) { - return makeDefaultHandle.call(this); - } - var toType; - if (this.isConst) { - toType = registeredPointerRecord.constPointerType; - } - else { - toType = registeredPointerRecord.pointerType; - } - var dp = downcastPointer(rawPointer, this.registeredClass, toType.registeredClass); - if (dp === null) { - return makeDefaultHandle.call(this); - } - if (this.isSmartPointer) { - return makeClassHandle(toType.registeredClass.instancePrototype, { - ptrType: toType, - ptr: dp, - smartPtrType: this, - smartPtr: ptr - }); - } - else { - return makeClassHandle(toType.registeredClass.instancePrototype, { - ptrType: toType, - ptr: dp - }); - } - } - function init_RegisteredPointer() { - RegisteredPointer.prototype.getPointee = RegisteredPointer_getPointee; - RegisteredPointer.prototype.destructor = RegisteredPointer_destructor; - RegisteredPointer.prototype['argPackAdvance'] = 8; - RegisteredPointer.prototype['readValueFromPointer'] = simpleReadValueFromPointer; - RegisteredPointer.prototype['deleteObject'] = RegisteredPointer_deleteObject; - RegisteredPointer.prototype['fromWireType'] = RegisteredPointer_fromWireType; - } - function RegisteredPointer(name, registeredClass, isReference, isConst, isSmartPointer, pointeeType, sharingPolicy, rawGetPointee, rawConstructor, rawShare, rawDestructor) { - this.name = name; - this.registeredClass = registeredClass; - this.isReference = isReference; - this.isConst = isConst; - this.isSmartPointer = isSmartPointer; - this.pointeeType = pointeeType; - this.sharingPolicy = sharingPolicy; - this.rawGetPointee = rawGetPointee; - this.rawConstructor = rawConstructor; - this.rawShare = rawShare; - this.rawDestructor = rawDestructor; - if (!isSmartPointer && registeredClass.baseClass === undefined) { - if (isConst) { - this['toWireType'] = constNoSmartPtrRawPointerToWireType; - this.destructorFunction = null; - } - else { - this['toWireType'] = nonConstNoSmartPtrRawPointerToWireType; - this.destructorFunction = null; - } - } - else { - this['toWireType'] = genericPointerToWireType; - } - } - function replacePublicSymbol(name, value, numArguments) { - if (!Module.hasOwnProperty(name)) { - throwInternalError('Replacing nonexistant public symbol'); - } - if (undefined !== Module[name].overloadTable && undefined !== numArguments) { - Module[name].overloadTable[numArguments] = value; - } - else { - Module[name] = value; - Module[name].argCount = numArguments; - } - } - function embind__requireFunction(signature, rawFunction) { - signature = readLatin1String(signature); - function makeDynCaller(dynCall) { - var args = []; - for (var i = 1; i < signature.length; ++i) { - args.push('a' + i); - } - var name = 'dynCall_' + signature + '_' + rawFunction; - var body = 'return function ' + name + '(' + args.join(', ') + ') {\n'; - body += - ' return dynCall(rawFunction' + (args.length ? ', ' : '') + args.join(', ') + ');\n'; - body += '};\n'; - return new Function('dynCall', 'rawFunction', body)(dynCall, rawFunction); - } - var dc = Module['dynCall_' + signature]; - var fp = makeDynCaller(dc); - if (typeof fp !== 'function') { - throwBindingError('unknown function pointer with signature ' + signature + ': ' + rawFunction); - } - return fp; - } - var UnboundTypeError = undefined; - function getTypeName(type) { - var ptr = ___getTypeName(type); - var rv = readLatin1String(ptr); - _free(ptr); - return rv; - } - function throwUnboundTypeError(message, types) { - var unboundTypes = []; - var seen = {}; - function visit(type) { - if (seen[type]) { - return; - } - if (registeredTypes[type]) { - return; - } - if (typeDependencies[type]) { - typeDependencies[type].forEach(visit); - return; - } - unboundTypes.push(type); - seen[type] = true; - } - types.forEach(visit); - throw new UnboundTypeError(message + ': ' + unboundTypes.map(getTypeName).join([', '])); - } - function __embind_register_class(rawType, rawPointerType, rawConstPointerType, baseClassRawType, getActualTypeSignature, getActualType, upcastSignature, upcast, downcastSignature, downcast, name, destructorSignature, rawDestructor) { - name = readLatin1String(name); - getActualType = embind__requireFunction(getActualTypeSignature, getActualType); - if (upcast) { - upcast = embind__requireFunction(upcastSignature, upcast); - } - if (downcast) { - downcast = embind__requireFunction(downcastSignature, downcast); - } - rawDestructor = embind__requireFunction(destructorSignature, rawDestructor); - var legalFunctionName = makeLegalFunctionName(name); - exposePublicSymbol(legalFunctionName, function () { - throwUnboundTypeError('Cannot construct ' + name + ' due to unbound types', [ - baseClassRawType - ]); - }); - whenDependentTypesAreResolved([rawType, rawPointerType, rawConstPointerType], baseClassRawType ? [baseClassRawType] : [], function (base) { - base = base[0]; - var baseClass; - var basePrototype; - if (baseClassRawType) { - baseClass = base.registeredClass; - basePrototype = baseClass.instancePrototype; - } - else { - basePrototype = ClassHandle.prototype; - } - var constructor = createNamedFunction(legalFunctionName, function () { - if (Object.getPrototypeOf(this) !== instancePrototype) { - throw new BindingError("Use 'new' to construct " + name); - } - if (undefined === registeredClass.constructor_body) { - throw new BindingError(name + ' has no accessible constructor'); - } - var body = registeredClass.constructor_body[arguments.length]; - if (undefined === body) { - throw new BindingError('Tried to invoke ctor of ' + - name + - ' with invalid number of parameters (' + - arguments.length + - ') - expected (' + - Object.keys(registeredClass.constructor_body).toString() + - ') parameters instead!'); - } - return body.apply(this, arguments); - }); - var instancePrototype = Object.create(basePrototype, { - constructor: { - value: constructor - } - }); - constructor.prototype = instancePrototype; - var registeredClass = new RegisteredClass(name, constructor, instancePrototype, rawDestructor, baseClass, getActualType, upcast, downcast); - var referenceConverter = new RegisteredPointer(name, registeredClass, true, false, false); - var pointerConverter = new RegisteredPointer(name + '*', registeredClass, false, false, false); - var constPointerConverter = new RegisteredPointer(name + ' const*', registeredClass, false, true, false); - registeredPointers[rawType] = { - pointerType: pointerConverter, - constPointerType: constPointerConverter - }; - replacePublicSymbol(legalFunctionName, constructor); - return [referenceConverter, pointerConverter, constPointerConverter]; - }); - } - function heap32VectorToArray(count, firstElement) { - var array = []; - for (var i = 0; i < count; i++) { - array.push(HEAP32[(firstElement >> 2) + i]); - } - return array; - } - function runDestructors(destructors) { - while (destructors.length) { - var ptr = destructors.pop(); - var del = destructors.pop(); - del(ptr); - } - } - function __embind_register_class_constructor(rawClassType, argCount, rawArgTypesAddr, invokerSignature, invoker, rawConstructor) { - assert(argCount > 0); - var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr); - invoker = embind__requireFunction(invokerSignature, invoker); - var args = [rawConstructor]; - var destructors = []; - whenDependentTypesAreResolved([], [rawClassType], function (classType) { - classType = classType[0]; - var humanName = 'constructor ' + classType.name; - if (undefined === classType.registeredClass.constructor_body) { - classType.registeredClass.constructor_body = []; - } - if (undefined !== classType.registeredClass.constructor_body[argCount - 1]) { - throw new BindingError('Cannot register multiple constructors with identical number of parameters (' + - (argCount - 1) + - ") for class '" + - classType.name + - "'! Overload resolution is currently only performed using the parameter count, not actual type info!"); - } - classType.registeredClass.constructor_body[argCount - 1] = function unboundTypeHandler() { - throwUnboundTypeError('Cannot construct ' + classType.name + ' due to unbound types', rawArgTypes); - }; - whenDependentTypesAreResolved([], rawArgTypes, function (argTypes) { - classType.registeredClass.constructor_body[argCount - 1] = function constructor_body() { - if (arguments.length !== argCount - 1) { - throwBindingError(humanName + - ' called with ' + - arguments.length + - ' arguments, expected ' + - (argCount - 1)); - } - destructors.length = 0; - args.length = argCount; - for (var i = 1; i < argCount; ++i) { - args[i] = argTypes[i]['toWireType'](destructors, arguments[i - 1]); - } - var ptr = invoker.apply(null, args); - runDestructors(destructors); - return argTypes[0]['fromWireType'](ptr); - }; - return []; - }); - return []; - }); - } - function new_(constructor, argumentList) { - if (!(constructor instanceof Function)) { - throw new TypeError('new_ called with constructor type ' + typeof constructor + ' which is not a function'); - } - var dummy = createNamedFunction(constructor.name || 'unknownFunctionName', function () { }); - dummy.prototype = constructor.prototype; - var obj = new dummy(); - var r = constructor.apply(obj, argumentList); - return r instanceof Object ? r : obj; - } - function craftInvokerFunction(humanName, argTypes, classType, cppInvokerFunc, cppTargetFunc) { - var argCount = argTypes.length; - if (argCount < 2) { - throwBindingError("argTypes array size mismatch! Must at least get return value and 'this' types!"); - } - var isClassMethodFunc = argTypes[1] !== null && classType !== null; - var needsDestructorStack = false; - for (var i = 1; i < argTypes.length; ++i) { - if (argTypes[i] !== null && argTypes[i].destructorFunction === undefined) { - needsDestructorStack = true; - break; - } - } - var returns = argTypes[0].name !== 'void'; - var argsList = ''; - var argsListWired = ''; - for (var i = 0; i < argCount - 2; ++i) { - argsList += (i !== 0 ? ', ' : '') + 'arg' + i; - argsListWired += (i !== 0 ? ', ' : '') + 'arg' + i + 'Wired'; - } - var invokerFnBody = 'return function ' + - makeLegalFunctionName(humanName) + - '(' + - argsList + - ') {\n' + - 'if (arguments.length !== ' + - (argCount - 2) + - ') {\n' + - "throwBindingError('function " + - humanName + - " called with ' + arguments.length + ' arguments, expected " + - (argCount - 2) + - " args!');\n" + - '}\n'; - if (needsDestructorStack) { - invokerFnBody += 'var destructors = [];\n'; - } - var dtorStack = needsDestructorStack ? 'destructors' : 'null'; - var args1 = ['throwBindingError', 'invoker', 'fn', 'runDestructors', 'retType', 'classParam']; - var args2 = [ - throwBindingError, - cppInvokerFunc, - cppTargetFunc, - runDestructors, - argTypes[0], - argTypes[1] - ]; - if (isClassMethodFunc) { - invokerFnBody += 'var thisWired = classParam.toWireType(' + dtorStack + ', this);\n'; - } - for (var i = 0; i < argCount - 2; ++i) { - invokerFnBody += - 'var arg' + - i + - 'Wired = argType' + - i + - '.toWireType(' + - dtorStack + - ', arg' + - i + - '); // ' + - argTypes[i + 2].name + - '\n'; - args1.push('argType' + i); - args2.push(argTypes[i + 2]); - } - if (isClassMethodFunc) { - argsListWired = 'thisWired' + (argsListWired.length > 0 ? ', ' : '') + argsListWired; - } - invokerFnBody += - (returns ? 'var rv = ' : '') + - 'invoker(fn' + - (argsListWired.length > 0 ? ', ' : '') + - argsListWired + - ');\n'; - if (needsDestructorStack) { - invokerFnBody += 'runDestructors(destructors);\n'; - } - else { - for (var i = isClassMethodFunc ? 1 : 2; i < argTypes.length; ++i) { - var paramName = i === 1 ? 'thisWired' : 'arg' + (i - 2) + 'Wired'; - if (argTypes[i].destructorFunction !== null) { - invokerFnBody += paramName + '_dtor(' + paramName + '); // ' + argTypes[i].name + '\n'; - args1.push(paramName + '_dtor'); - args2.push(argTypes[i].destructorFunction); - } - } - } - if (returns) { - invokerFnBody += 'var ret = retType.fromWireType(rv);\n' + 'return ret;\n'; - } - invokerFnBody += '}\n'; - args1.push(invokerFnBody); - var invokerFunction = new_(Function, args1).apply(null, args2); - return invokerFunction; - } - function __embind_register_class_function(rawClassType, methodName, argCount, rawArgTypesAddr, invokerSignature, rawInvoker, context, isPureVirtual) { - var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr); - methodName = readLatin1String(methodName); - rawInvoker = embind__requireFunction(invokerSignature, rawInvoker); - whenDependentTypesAreResolved([], [rawClassType], function (classType) { - classType = classType[0]; - var humanName = classType.name + '.' + methodName; - if (isPureVirtual) { - classType.registeredClass.pureVirtualFunctions.push(methodName); - } - function unboundTypesHandler() { - throwUnboundTypeError('Cannot call ' + humanName + ' due to unbound types', rawArgTypes); - } - var proto = classType.registeredClass.instancePrototype; - var method = proto[methodName]; - if (undefined === method || - (undefined === method.overloadTable && - method.className !== classType.name && - method.argCount === argCount - 2)) { - unboundTypesHandler.argCount = argCount - 2; - unboundTypesHandler.className = classType.name; - proto[methodName] = unboundTypesHandler; - } - else { - ensureOverloadTable(proto, methodName, humanName); - proto[methodName].overloadTable[argCount - 2] = unboundTypesHandler; - } - whenDependentTypesAreResolved([], rawArgTypes, function (argTypes) { - var memberFunction = craftInvokerFunction(humanName, argTypes, classType, rawInvoker, context); - if (undefined === proto[methodName].overloadTable) { - memberFunction.argCount = argCount - 2; - proto[methodName] = memberFunction; - } - else { - proto[methodName].overloadTable[argCount - 2] = memberFunction; - } - return []; - }); - return []; - }); - } - var emval_free_list = []; - var emval_handle_array = [ - {}, - { - value: undefined - }, - { - value: null - }, - { - value: true - }, - { - value: false - } - ]; - function __emval_decref(handle) { - if (handle > 4 && 0 === --emval_handle_array[handle].refcount) { - emval_handle_array[handle] = undefined; - emval_free_list.push(handle); - } - } - function count_emval_handles() { - var count = 0; - for (var i = 5; i < emval_handle_array.length; ++i) { - if (emval_handle_array[i] !== undefined) { - ++count; - } - } - return count; - } - function get_first_emval() { - for (var i = 5; i < emval_handle_array.length; ++i) { - if (emval_handle_array[i] !== undefined) { - return emval_handle_array[i]; - } - } - return null; - } - function init_emval() { - Module['count_emval_handles'] = count_emval_handles; - Module['get_first_emval'] = get_first_emval; - } - function __emval_register(value) { - switch (value) { - case undefined: { - return 1; - } - case null: { - return 2; - } - case true: { - return 3; - } - case false: { - return 4; - } - default: { - var handle = emval_free_list.length ? emval_free_list.pop() : emval_handle_array.length; - emval_handle_array[handle] = { - refcount: 1, - value: value - }; - return handle; - } - } - } - function __embind_register_emval(rawType, name) { - name = readLatin1String(name); - registerType(rawType, { - name: name, - fromWireType: function (handle) { - var rv = emval_handle_array[handle].value; - __emval_decref(handle); - return rv; - }, - toWireType: function (destructors, value) { - return __emval_register(value); - }, - argPackAdvance: 8, - readValueFromPointer: simpleReadValueFromPointer, - destructorFunction: null - }); - } - function _embind_repr(v) { - if (v === null) { - return 'null'; - } - var t = typeof v; - if (t === 'object' || t === 'array' || t === 'function') { - return v.toString(); - } - else { - return '' + v; - } - } - function floatReadValueFromPointer(name, shift) { - switch (shift) { - case 2: - return function (pointer) { - return this['fromWireType'](HEAPF32[pointer >> 2]); - }; - case 3: - return function (pointer) { - return this['fromWireType'](HEAPF64[pointer >> 3]); - }; - default: - throw new TypeError('Unknown float type: ' + name); - } - } - function __embind_register_float(rawType, name, size) { - var shift = getShiftFromSize(size); - name = readLatin1String(name); - registerType(rawType, { - name: name, - fromWireType: function (value) { - return value; - }, - toWireType: function (destructors, value) { - if (typeof value !== 'number' && typeof value !== 'boolean') { - throw new TypeError('Cannot convert "' + _embind_repr(value) + '" to ' + this.name); - } - return value; - }, - argPackAdvance: 8, - readValueFromPointer: floatReadValueFromPointer(name, shift), - destructorFunction: null - }); - } - function integerReadValueFromPointer(name, shift, signed) { - switch (shift) { - case 0: - return signed - ? function readS8FromPointer(pointer) { - return HEAP8[pointer]; - } - : function readU8FromPointer(pointer) { - return HEAPU8[pointer]; - }; - case 1: - return signed - ? function readS16FromPointer(pointer) { - return HEAP16[pointer >> 1]; - } - : function readU16FromPointer(pointer) { - return HEAPU16[pointer >> 1]; - }; - case 2: - return signed - ? function readS32FromPointer(pointer) { - return HEAP32[pointer >> 2]; - } - : function readU32FromPointer(pointer) { - return HEAPU32[pointer >> 2]; - }; - default: - throw new TypeError('Unknown integer type: ' + name); - } - } - function __embind_register_integer(primitiveType, name, size, minRange, maxRange) { - name = readLatin1String(name); - if (maxRange === -1) { - maxRange = 4294967295; - } - var shift = getShiftFromSize(size); - var fromWireType = function (value) { - return value; - }; - if (minRange === 0) { - var bitshift = 32 - 8 * size; - fromWireType = function (value) { - return (value << bitshift) >>> bitshift; - }; - } - var isUnsignedType = name.indexOf('unsigned') != -1; - registerType(primitiveType, { - name: name, - fromWireType: fromWireType, - toWireType: function (destructors, value) { - if (typeof value !== 'number' && typeof value !== 'boolean') { - throw new TypeError('Cannot convert "' + _embind_repr(value) + '" to ' + this.name); - } - if (value < minRange || value > maxRange) { - throw new TypeError('Passing a number "' + - _embind_repr(value) + - '" from JS side to C/C++ side to an argument of type "' + - name + - '", which is outside the valid range [' + - minRange + - ', ' + - maxRange + - ']!'); - } - return isUnsignedType ? value >>> 0 : value | 0; - }, - argPackAdvance: 8, - readValueFromPointer: integerReadValueFromPointer(name, shift, minRange !== 0), - destructorFunction: null - }); - } - function __embind_register_memory_view(rawType, dataTypeIndex, name) { - var typeMapping = [ - Int8Array, - Uint8Array, - Int16Array, - Uint16Array, - Int32Array, - Uint32Array, - Float32Array, - Float64Array - ]; - var TA = typeMapping[dataTypeIndex]; - function decodeMemoryView(handle) { - handle = handle >> 2; - var heap = HEAPU32; - var size = heap[handle]; - var data = heap[handle + 1]; - return new TA(buffer, data, size); - } - name = readLatin1String(name); - registerType(rawType, { - name: name, - fromWireType: decodeMemoryView, - argPackAdvance: 8, - readValueFromPointer: decodeMemoryView - }, { - ignoreDuplicateRegistrations: true - }); - } - function __embind_register_std_string(rawType, name) { - name = readLatin1String(name); - var stdStringIsUTF8 = name === 'std::string'; - registerType(rawType, { - name: name, - fromWireType: function (value) { - var length = HEAPU32[value >> 2]; - var str; - if (stdStringIsUTF8) { - var decodeStartPtr = value + 4; - for (var i = 0; i <= length; ++i) { - var currentBytePtr = value + 4 + i; - if (HEAPU8[currentBytePtr] == 0 || i == length) { - var maxRead = currentBytePtr - decodeStartPtr; - var stringSegment = UTF8ToString(decodeStartPtr, maxRead); - if (str === undefined) { - str = stringSegment; - } - else { - str += String.fromCharCode(0); - str += stringSegment; - } - decodeStartPtr = currentBytePtr + 1; - } - } - } - else { - var a = new Array(length); - for (var i = 0; i < length; ++i) { - a[i] = String.fromCharCode(HEAPU8[value + 4 + i]); - } - str = a.join(''); - } - _free(value); - return str; - }, - toWireType: function (destructors, value) { - if (value instanceof ArrayBuffer) { - value = new Uint8Array(value); - } - var getLength; - var valueIsOfTypeString = typeof value === 'string'; - if (!(valueIsOfTypeString || - value instanceof Uint8Array || - value instanceof Uint8ClampedArray || - value instanceof Int8Array)) { - throwBindingError('Cannot pass non-string to std::string'); - } - if (stdStringIsUTF8 && valueIsOfTypeString) { - getLength = function () { - return lengthBytesUTF8(value); - }; - } - else { - getLength = function () { - return value.length; - }; - } - var length = getLength(); - var ptr = _malloc(4 + length + 1); - HEAPU32[ptr >> 2] = length; - if (stdStringIsUTF8 && valueIsOfTypeString) { - stringToUTF8(value, ptr + 4, length + 1); - } - else { - if (valueIsOfTypeString) { - for (var i = 0; i < length; ++i) { - var charCode = value.charCodeAt(i); - if (charCode > 255) { - _free(ptr); - throwBindingError('String has UTF-16 code units that do not fit in 8 bits'); - } - HEAPU8[ptr + 4 + i] = charCode; - } - } - else { - for (var i = 0; i < length; ++i) { - HEAPU8[ptr + 4 + i] = value[i]; - } - } - } - if (destructors !== null) { - destructors.push(_free, ptr); - } - return ptr; - }, - argPackAdvance: 8, - readValueFromPointer: simpleReadValueFromPointer, - destructorFunction: function (ptr) { - _free(ptr); - } - }); - } - function __embind_register_std_wstring(rawType, charSize, name) { - name = readLatin1String(name); - var decodeString, encodeString, getHeap, lengthBytesUTF, shift; - if (charSize === 2) { - decodeString = UTF16ToString; - encodeString = stringToUTF16; - lengthBytesUTF = lengthBytesUTF16; - getHeap = function () { - return HEAPU16; - }; - shift = 1; - } - else if (charSize === 4) { - decodeString = UTF32ToString; - encodeString = stringToUTF32; - lengthBytesUTF = lengthBytesUTF32; - getHeap = function () { - return HEAPU32; - }; - shift = 2; - } - registerType(rawType, { - name: name, - fromWireType: function (value) { - var length = HEAPU32[value >> 2]; - var HEAP = getHeap(); - var str; - var decodeStartPtr = value + 4; - for (var i = 0; i <= length; ++i) { - var currentBytePtr = value + 4 + i * charSize; - if (HEAP[currentBytePtr >> shift] == 0 || i == length) { - var maxReadBytes = currentBytePtr - decodeStartPtr; - var stringSegment = decodeString(decodeStartPtr, maxReadBytes); - if (str === undefined) { - str = stringSegment; - } - else { - str += String.fromCharCode(0); - str += stringSegment; - } - decodeStartPtr = currentBytePtr + charSize; - } - } - _free(value); - return str; - }, - toWireType: function (destructors, value) { - if (!(typeof value === 'string')) { - throwBindingError('Cannot pass non-string to C++ string type ' + name); - } - var length = lengthBytesUTF(value); - var ptr = _malloc(4 + length + charSize); - HEAPU32[ptr >> 2] = length >> shift; - encodeString(value, ptr + 4, length + charSize); - if (destructors !== null) { - destructors.push(_free, ptr); - } - return ptr; - }, - argPackAdvance: 8, - readValueFromPointer: simpleReadValueFromPointer, - destructorFunction: function (ptr) { - _free(ptr); - } - }); - } - function __embind_register_void(rawType, name) { - name = readLatin1String(name); - registerType(rawType, { - isVoid: true, - name: name, - argPackAdvance: 0, - fromWireType: function () { - return undefined; - }, - toWireType: function (destructors, o) { - return undefined; - } - }); - } - function _abort() { - abort(); - } - function _emscripten_get_heap_size() { - return HEAPU8.length; - } - function abortOnCannotGrowMemory(requestedSize) { - abort('OOM'); - } - function _emscripten_resize_heap(requestedSize) { - abortOnCannotGrowMemory(); - } - function _llvm_trap() { - abort('trap!'); - } - function _emscripten_memcpy_big(dest, src, num) { - HEAPU8.copyWithin(dest, src, src + num); - } - embind_init_charCodes(); - BindingError = Module['BindingError'] = extendError(Error, 'BindingError'); - InternalError = Module['InternalError'] = extendError(Error, 'InternalError'); - init_ClassHandle(); - init_RegisteredPointer(); - init_embind(); - UnboundTypeError = Module['UnboundTypeError'] = extendError(Error, 'UnboundTypeError'); - init_emval(); - function intArrayToString(array) { - var ret = []; - for (var i = 0; i < array.length; i++) { - var chr = array[i]; - if (chr > 255) { - chr &= 255; - } - ret.push(String.fromCharCode(chr)); - } - return ret.join(''); - } - var decodeBase64 = typeof atob === 'function' - ? atob - : function (input) { - var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; - var output = ''; - var chr1, chr2, chr3; - var enc1, enc2, enc3, enc4; - var i = 0; - input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ''); - do { - enc1 = keyStr.indexOf(input.charAt(i++)); - enc2 = keyStr.indexOf(input.charAt(i++)); - enc3 = keyStr.indexOf(input.charAt(i++)); - enc4 = keyStr.indexOf(input.charAt(i++)); - chr1 = (enc1 << 2) | (enc2 >> 4); - chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); - chr3 = ((enc3 & 3) << 6) | enc4; - output = output + String.fromCharCode(chr1); - if (enc3 !== 64) { - output = output + String.fromCharCode(chr2); - } - if (enc4 !== 64) { - output = output + String.fromCharCode(chr3); - } - } while (i < input.length); - return output; - }; - function intArrayFromBase64(s) { - if (typeof ENVIRONMENT_IS_NODE === 'boolean' && ENVIRONMENT_IS_NODE) { - var buf; - try { - buf = Buffer.from(s, 'base64'); - } - catch (_) { - buf = new Buffer(s, 'base64'); - } - return new Uint8Array(buf['buffer'], buf['byteOffset'], buf['byteLength']); - } - try { - var decoded = decodeBase64(s); - var bytes = new Uint8Array(decoded.length); - for (var i = 0; i < decoded.length; ++i) { - bytes[i] = decoded.charCodeAt(i); - } - return bytes; - } - catch (_) { - throw new Error('Converting base64 string to bytes failed.'); - } - } - function tryParseAsDataURI(filename) { - if (!isDataURI(filename)) { - return; - } - return intArrayFromBase64(filename.slice(dataURIPrefix.length)); - } - var asmGlobalArg = { - Math: Math, - Int8Array: Int8Array, - Int16Array: Int16Array, - Int32Array: Int32Array, - Uint8Array: Uint8Array, - Uint16Array: Uint16Array, - Float32Array: Float32Array, - Float64Array: Float64Array - }; - var asmLibraryArg = { - A: _emscripten_memcpy_big, - B: _emscripten_resize_heap, - C: _llvm_trap, - D: tempDoublePtr, - a: abort, - b: setTempRet0, - c: getTempRet0, - d: ___cxa_allocate_exception, - e: ___cxa_begin_catch, - f: ___cxa_throw, - g: ___cxa_uncaught_exceptions, - h: ___exception_addRef, - i: ___exception_deAdjust, - j: ___gxx_personality_v0, - k: __embind_register_bool, - l: __embind_register_class, - m: __embind_register_class_constructor, - n: __embind_register_class_function, - o: __embind_register_emval, - p: __embind_register_float, - q: __embind_register_integer, - r: __embind_register_memory_view, - s: __embind_register_std_string, - t: __embind_register_std_wstring, - u: __embind_register_void, - v: __emval_decref, - w: __emval_register, - x: _abort, - y: _embind_repr, - z: _emscripten_get_heap_size - }; // EMSCRIPTEN_START_ASM - var asm = /** @suppress {uselessCode} */ (function (global, env, buffer) { - 'use asm'; - var a = new global.Int8Array(buffer), b = new global.Int16Array(buffer), c = new global.Int32Array(buffer), d = new global.Uint8Array(buffer), e = new global.Uint16Array(buffer), f = new global.Float32Array(buffer), g = new global.Float64Array(buffer), h = env.D | 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0.0, q = global.Math.imul, r = global.Math.clz32, s = env.a, t = env.b, u = env.c, v = env.d, w = env.e, x = env.f, y = env.g, z = env.h, A = env.i, B = env.j, C = env.k, D = env.l, E = env.m, F = env.n, G = env.o, H = env.p, I = env.q, J = env.r, K = env.s, L = env.t, M = env.u, N = env.v, O = env.w, P = env.x, Q = env.y, R = env.z, S = env.A, T = env.B, U = env.C, V = 22384, W = 5265264, X = 0.0; - // EMSCRIPTEN_START_FUNCS - function ia() { - em(); - fm(); - } - function ja() { - ka(0); - return; - } - function ka(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0; - a = V; - V = (V + 16) | 0; - b = (a + 8) | 0; - d = a; - vk(); - m = xk() | 0; - g = yk() | 0; - f = Ak() | 0; - h = Bk() | 0; - i = Ck() | 0; - j = Dk() | 0; - k = Jk() | 0; - l = Kk() | 0; - e = Kk() | 0; - D(f | 0, h | 0, i | 0, j | 0, k | 0, 9, l | 0, m | 0, e | 0, g | 0, 6204, Lk() | 0, 138); - Nk(1); - c[d >> 2] = 5; - c[(d + 4) >> 2] = 0; - c[b >> 2] = c[d >> 2]; - c[(b + 4) >> 2] = c[(d + 4) >> 2]; - Uk(6211, b); - c[d >> 2] = 3; - c[(d + 4) >> 2] = 0; - c[b >> 2] = c[d >> 2]; - c[(b + 4) >> 2] = c[(d + 4) >> 2]; - cl(6216, b); - c[d >> 2] = 10; - c[(d + 4) >> 2] = 0; - c[b >> 2] = c[d >> 2]; - c[(b + 4) >> 2] = c[(d + 4) >> 2]; - kl(6225, b); - sl(); - g = ul() | 0; - e = vl() | 0; - m = xl() | 0; - l = yl() | 0; - k = zl() | 0; - j = Dk() | 0; - i = Jk() | 0; - h = Kk() | 0; - f = Kk() | 0; - D(m | 0, l | 0, k | 0, j | 0, i | 0, 11, h | 0, g | 0, f | 0, e | 0, 6234, Lk() | 0, 139); - Gl(2); - c[d >> 2] = 6; - c[(d + 4) >> 2] = 0; - c[b >> 2] = c[d >> 2]; - c[(b + 4) >> 2] = c[(d + 4) >> 2]; - Nl(6211, b); - c[d >> 2] = 4; - c[(d + 4) >> 2] = 0; - c[b >> 2] = c[d >> 2]; - c[(b + 4) >> 2] = c[(d + 4) >> 2]; - Ul(6248, b); - c[d >> 2] = 5; - c[(d + 4) >> 2] = 0; - c[b >> 2] = c[d >> 2]; - c[(b + 4) >> 2] = c[(d + 4) >> 2]; - Ul(6265, b); - c[d >> 2] = 6; - c[(d + 4) >> 2] = 0; - c[b >> 2] = c[d >> 2]; - c[(b + 4) >> 2] = c[(d + 4) >> 2]; - Ul(6280, b); - c[d >> 2] = 7; - c[(d + 4) >> 2] = 0; - c[b >> 2] = c[d >> 2]; - c[(b + 4) >> 2] = c[(d + 4) >> 2]; - _l(6216, b); - V = a; - return; - } - function la(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0, h = 0, i = 0; - e = V; - V = (V + 32) | 0; - h = (e + 16) | 0; - f = (e + 8) | 0; - i = e; - g = eq(20) | 0; - ta(g, b, d); - c[i >> 2] = 0; - c[h >> 2] = c[i >> 2]; - va(f, g, h); - b = c[f >> 2] | 0; - c[f >> 2] = c[a >> 2]; - c[a >> 2] = b; - b = (f + 4) | 0; - d = (a + 4) | 0; - g = c[b >> 2] | 0; - c[b >> 2] = c[d >> 2]; - c[d >> 2] = g; - wa(f); - d = eq(352) | 0; - ua(d, c[a >> 2] | 0); - g = (a + 8) | 0; - c[i >> 2] = 0; - c[h >> 2] = c[i >> 2]; - Fa(f, d, h); - d = c[f >> 2] | 0; - c[f >> 2] = c[g >> 2]; - c[g >> 2] = d; - g = (f + 4) | 0; - d = (a + 12) | 0; - b = c[g >> 2] | 0; - c[g >> 2] = c[d >> 2]; - c[d >> 2] = b; - Ga(f); - V = e; - return; - } - function ma(a, b) { - a = a | 0; - b = b | 0; - dd(c[(a + 8) >> 2] | 0, b); - return; - } - function na(a) { - a = a | 0; - a = ((Qh(c[(a + 8) >> 2] | 0) | 0) + 107) | 0; - return (d[a >> 0] | (d[(a + 1) >> 0] << 8) | (d[(a + 2) >> 0] << 16) | (d[(a + 3) >> 0] << 24) | 0); - } - function oa(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0, h = 0, i = 0; - e = V; - V = (V + 32) | 0; - g = (e + 16) | 0; - f = (e + 8) | 0; - h = e; - i = eq(12) | 0; - Rh(i, b, d); - c[h >> 2] = 0; - c[g >> 2] = c[h >> 2]; - Vh(f, i, g); - i = c[f >> 2] | 0; - c[f >> 2] = c[a >> 2]; - c[a >> 2] = i; - i = (f + 4) | 0; - d = (a + 4) | 0; - b = c[i >> 2] | 0; - c[i >> 2] = c[d >> 2]; - c[d >> 2] = b; - Wh(f); - d = (a + 8) | 0; - b = eq(12) | 0; - Sh(b, c[a >> 2] | 0); - c[h >> 2] = 0; - c[g >> 2] = c[h >> 2]; - ai(f, b, g); - b = c[f >> 2] | 0; - c[f >> 2] = c[d >> 2]; - c[d >> 2] = b; - b = (f + 4) | 0; - h = (a + 12) | 0; - i = c[b >> 2] | 0; - c[b >> 2] = c[h >> 2]; - c[h >> 2] = i; - bi(f); - Th(f, c[d >> 2] | 0); - d = (a + 16) | 0; - h = c[f >> 2] | 0; - i = (f + 4) | 0; - b = c[i >> 2] | 0; - c[f >> 2] = 0; - c[i >> 2] = 0; - c[g >> 2] = c[d >> 2]; - c[d >> 2] = h; - d = (a + 20) | 0; - c[(g + 4) >> 2] = c[d >> 2]; - c[d >> 2] = b; - Uh(g); - Uh(f); - V = e; - return; - } - function pa(a, b) { - a = a | 0; - b = b | 0; - var d = 0; - a = (a + 16) | 0; - d = c[a >> 2] | 0; - a: do - if (d | 0) - switch (b | 0) { - case 4: { - ui(d); - break a; - } - case 8: { - vi(d); - vi(c[a >> 2] | 0); - break a; - } - default: - break a; - } - while (0); - return; - } - function qa(a, b) { - a = a | 0; - b = b | 0; - var d = 0; - d = (a + 16) | 0; - a = c[d >> 2] | 0; - a: do - if (a | 0) { - switch (b | 0) { - case 1: { - hj(a); - break a; - } - case 2: { - ij(a); - break a; - } - case 8: { - ui(a); - a = c[d >> 2] | 0; - break; - } - case 4: - break; - default: - break a; - } - ui(a); - } - while (0); - return; - } - function ra(a, b) { - a = a | 0; - b = b | 0; - var d = 0; - d = (a + 16) | 0; - a = c[d >> 2] | 0; - a: do - if (a | 0) { - switch (b | 0) { - case 1: { - Rj(a); - break a; - } - case 2: { - Sj(a); - break a; - } - case 8: { - vi(a); - a = c[d >> 2] | 0; - break; - } - case 4: - break; - default: - break a; - } - vi(a); - } - while (0); - return; - } - function sa(a, b) { - a = a | 0; - b = b | 0; - a = c[(a + 16) >> 2] | 0; - if (a | 0) - $[c[c[a >> 2] >> 2] & 63](a, b) | 0; - return; - } - function ta(b, d, e) { - b = b | 0; - d = d | 0; - e = e | 0; - c[b >> 2] = d; - c[(b + 4) >> 2] = e; - c[(b + 8) >> 2] = 0; - a[(b + 12) >> 0] = 0; - a[(b + 13) >> 0] = 0; - c[(b + 16) >> 2] = 0; - return; - } - function ua(a, b) { - a = a | 0; - b = b | 0; - c[a >> 2] = b; - Va((a + 4) | 0, b); - Wa((a + 247) | 0); - c[(a + 288) >> 2] = 0; - c[(a + 292) >> 2] = 0; - c[(a + 296) >> 2] = 0; - Xa((a + 300) | 0); - b = (a + 312) | 0; - c[b >> 2] = 0; - c[(b + 4) >> 2] = 0; - c[(b + 8) >> 2] = 0; - c[(b + 12) >> 2] = 0; - Ya((a + 328) | 0); - Za(a); - return; - } - function va(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 4296; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - xa(a, e); - V = d; - return; - } - function wa(a) { - a = a | 0; - var b = 0, d = 0; - a = c[(a + 4) >> 2] | 0; - if (a | 0 ? ((d = (a + 4) | 0), (b = c[d >> 2] | 0), (c[d >> 2] = b + -1), (b | 0) == 0) : 0) { - ca[c[((c[a >> 2] | 0) + 8) >> 2] & 255](a); - qq(a); - } - return; - } - function xa(a, b) { - a = a | 0; - b = b | 0; - return; - } - function ya(a) { - a = a | 0; - w(a | 0) | 0; - lp(); - } - function za(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function Aa(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - jp(a); - return; - } - function Ba(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 6407 ? (a + 12) | 0 : 0) | 0; - } - function Ca(a) { - a = a | 0; - Da(a, 16); - return; - } - function Da(a, b) { - a = a | 0; - b = b | 0; - Ea(a); - return; - } - function Ea(a) { - a = a | 0; - jp(a); - return; - } - function Fa(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 4324; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Ha(a, e); - V = d; - return; - } - function Ga(a) { - a = a | 0; - var b = 0, d = 0; - a = c[(a + 4) >> 2] | 0; - if (a | 0 ? ((d = (a + 4) | 0), (b = c[d >> 2] | 0), (c[d >> 2] = b + -1), (b | 0) == 0) : 0) { - ca[c[((c[a >> 2] | 0) + 8) >> 2] & 255](a); - qq(a); - } - return; - } - function Ha(a, b) { - a = a | 0; - b = b | 0; - return; - } - function Ia(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function Ja(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) { - Ma(a); - jp(a); - } - return; - } - function Ka(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 6605 ? (a + 12) | 0 : 0) | 0; - } - function La(a) { - a = a | 0; - Da(a, 16); - return; - } - function Ma(a) { - a = a | 0; - Na((a + 320) | 0); - Oa((a + 312) | 0); - Pa((a + 300) | 0); - Ta((a + 288) | 0); - Qa((a + 247) | 0); - Ra((a + 4) | 0); - return; - } - function Na(a) { - a = a | 0; - var b = 0, d = 0; - a = c[(a + 4) >> 2] | 0; - if (a | 0 ? ((d = (a + 4) | 0), (b = c[d >> 2] | 0), (c[d >> 2] = b + -1), (b | 0) == 0) : 0) { - ca[c[((c[a >> 2] | 0) + 8) >> 2] & 255](a); - qq(a); - } - return; - } - function Oa(a) { - a = a | 0; - var b = 0, d = 0; - a = c[(a + 4) >> 2] | 0; - if (a | 0 ? ((d = (a + 4) | 0), (b = c[d >> 2] | 0), (c[d >> 2] = b + -1), (b | 0) == 0) : 0) { - ca[c[((c[a >> 2] | 0) + 8) >> 2] & 255](a); - qq(a); - } - return; - } - function Pa(a) { - a = a | 0; - Sa(a); - return; - } - function Qa(a) { - a = a | 0; - a = (a + 34) | 0; - a = d[a >> 0] | (d[(a + 1) >> 0] << 8) | (d[(a + 2) >> 0] << 16) | (d[(a + 3) >> 0] << 24); - if (a | 0) - gq(a); - return; - } - function Ra(a) { - a = a | 0; - Ua(c[(a + 12) >> 2] | 0); - return; - } - function Sa(a) { - a = a | 0; - var b = 0, d = 0; - b = c[a >> 2] | 0; - d = b; - if (b | 0) { - c[(a + 4) >> 2] = d; - Da(b, ((c[(a + 8) >> 2] | 0) - d) | 0); - } - return; - } - function Ta(a) { - a = a | 0; - var b = 0, d = 0; - b = c[a >> 2] | 0; - d = b; - if (b | 0) { - c[(a + 4) >> 2] = d; - Da(b, ((c[(a + 8) >> 2] | 0) - d) | 0); - } - return; - } - function Ua(a) { - a = a | 0; - er(c[(a + -4) >> 2] | 0); - return; - } - function Va(a, b) { - a = a | 0; - b = b | 0; - c[a >> 2] = b; - c[(a + 4) >> 2] = 0; - c[(a + 8) >> 2] = 0; - c[(a + 12) >> 2] = _a(1048576) | 0; - return; - } - function Wa(b) { - b = b | 0; - var c = 0; - c = (b + 32) | 0; - a[c >> 0] = 0; - a[(c + 1) >> 0] = 0; - b = (b + 34) | 0; - a[b >> 0] = 0; - a[(b + 1) >> 0] = 0; - a[(b + 2) >> 0] = 0; - a[(b + 3) >> 0] = 0; - return; - } - function Xa(a) { - a = a | 0; - c[a >> 2] = 0; - c[(a + 4) >> 2] = 0; - c[(a + 8) >> 2] = 0; - return; - } - function Ya(a) { - a = a | 0; - c[a >> 2] = 0; - c[(a + 4) >> 2] = 0; - c[(a + 8) >> 2] = 0; - c[(a + 12) >> 2] = 0; - a = (a + 16) | 0; - c[a >> 2] = -1; - c[(a + 4) >> 2] = -1; - return; - } - function Za(b) { - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0; - i = V; - V = (V + 64) | 0; - g = (i + 32) | 0; - e = (i + 56) | 0; - d = (i + 16) | 0; - h = i; - $a(c[b >> 2] | 0, e, 4); - mb(g, e, (e + 4) | 0); - e = lb(6693) | 0; - f = a[(g + 11) >> 0] | 0; - if ((e | 0) == (((f << 24) >> 24 < 0 ? c[(g + 4) >> 2] | 0 : f & 255) | 0)) { - f = (Hq(g, 0, -1, 6693, e) | 0) == 0; - Cq(g); - if (f) { - e = c[b >> 2] | 0; - c[d >> 2] = 0; - c[(d + 4) >> 2] = 0; - c[(d + 8) >> 2] = 0; - c[(d + 12) >> 2] = 0; - c[g >> 2] = c[d >> 2]; - c[(g + 4) >> 2] = c[(d + 4) >> 2]; - c[(g + 8) >> 2] = c[(d + 8) >> 2]; - c[(g + 12) >> 2] = c[(d + 12) >> 2]; - bb(e, g); - e = (b + 20) | 0; - $a(c[b >> 2] | 0, e, 227); - cb(b, e); - f = db() | 0; - d = c[f >> 2] | 0; - f = c[(f + 4) >> 2] | 0; - if ((d | 0) != (f | 0)) - do { - eb(g, d); - fb(g, e); - gb(g); - d = (d + 24) | 0; - } while ((d | 0) != (f | 0)); - hb(b); - ib(b); - jb(c[b >> 2] | 0); - f = c[b >> 2] | 0; - d = ((c[(b + 116) >> 2] | 0) + 8) | 0; - e = h; - c[e >> 2] = 0; - c[(e + 4) >> 2] = 0; - e = (h + 8) | 0; - c[e >> 2] = d; - c[(e + 4) >> 2] = 0; - c[g >> 2] = c[h >> 2]; - c[(g + 4) >> 2] = c[(h + 4) >> 2]; - c[(g + 8) >> 2] = c[(h + 8) >> 2]; - c[(g + 12) >> 2] = c[(h + 12) >> 2]; - bb(f, g); - kb((b + 4) | 0); - V = i; - return; - } - } - else - Cq(g); - i = v(8) | 0; - ab(i); - x(i | 0, 2592, 8); - } - function _a(a) { - a = a | 0; - var b = 0; - b = dr((a + 68) | 0) | 0; - a = (b + 68) & -64; - c[(a + -4) >> 2] = b; - return a | 0; - } - function $a(b, d, e) { - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0, h = 0, i = 0, j = 0, k = 0; - i = (b + 13) | 0; - if (!(a[i >> 0] | 0)) { - h = (b + 4) | 0; - f = c[h >> 2] | 0; - j = (b + 8) | 0; - g = c[j >> 2] | 0; - k = (f - g) | 0; - e = (k | 0) < (e | 0) ? k : e; - if (e) { - vr(d | 0, ((c[b >> 2] | 0) + g) | 0, e | 0) | 0; - g = c[j >> 2] | 0; - f = c[h >> 2] | 0; - } - k = (g + e) | 0; - c[j >> 2] = k; - c[(b + 16) >> 2] = e; - if ((k | 0) >= (f | 0)) - a[i >> 0] = 1; - } - else - a[(b + 12) >> 0] = 1; - return; - } - function ab(a) { - a = a | 0; - xq(a, 6791); - c[a >> 2] = 4352; - return; - } - function bb(b, d) { - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0; - g = (d + 8) | 0; - d = c[g >> 2] | 0; - g = c[(g + 4) >> 2] | 0; - e = c[(b + 4) >> 2] | 0; - f = (((e | 0) < 0) << 31) >> 31; - if (((g | 0) < (f | 0)) | (((g | 0) == (f | 0)) & (d >>> 0 < e >>> 0))) - c[(b + 8) >> 2] = d; - else - a[(b + 12) >> 0] = 1; - return; - } - function cb(b, c) { - b = b | 0; - c = c | 0; - var d = 0.0, e = 0.0, f = 0, i = 0.0, j = 0, k = 0.0, l = 0, m = 0.0, n = 0, o = 0.0; - n = (c + 179) | 0; - a[h >> 0] = a[n >> 0]; - a[(h + 1) >> 0] = a[(n + 1) >> 0]; - a[(h + 2) >> 0] = a[(n + 2) >> 0]; - a[(h + 3) >> 0] = a[(n + 3) >> 0]; - a[(h + 4) >> 0] = a[(n + 4) >> 0]; - a[(h + 5) >> 0] = a[(n + 5) >> 0]; - a[(h + 6) >> 0] = a[(n + 6) >> 0]; - a[(h + 7) >> 0] = a[(n + 7) >> 0]; - m = +g[h >> 3]; - j = (c + 187) | 0; - a[h >> 0] = a[j >> 0]; - a[(h + 1) >> 0] = a[(j + 1) >> 0]; - a[(h + 2) >> 0] = a[(j + 2) >> 0]; - a[(h + 3) >> 0] = a[(j + 3) >> 0]; - a[(h + 4) >> 0] = a[(j + 4) >> 0]; - a[(h + 5) >> 0] = a[(j + 5) >> 0]; - a[(h + 6) >> 0] = a[(j + 6) >> 0]; - a[(h + 7) >> 0] = a[(j + 7) >> 0]; - o = +g[h >> 3]; - b = (c + 195) | 0; - a[h >> 0] = a[b >> 0]; - a[(h + 1) >> 0] = a[(b + 1) >> 0]; - a[(h + 2) >> 0] = a[(b + 2) >> 0]; - a[(h + 3) >> 0] = a[(b + 3) >> 0]; - a[(h + 4) >> 0] = a[(b + 4) >> 0]; - a[(h + 5) >> 0] = a[(b + 5) >> 0]; - a[(h + 6) >> 0] = a[(b + 6) >> 0]; - a[(h + 7) >> 0] = a[(b + 7) >> 0]; - i = +g[h >> 3]; - l = (c + 203) | 0; - a[h >> 0] = a[l >> 0]; - a[(h + 1) >> 0] = a[(l + 1) >> 0]; - a[(h + 2) >> 0] = a[(l + 2) >> 0]; - a[(h + 3) >> 0] = a[(l + 3) >> 0]; - a[(h + 4) >> 0] = a[(l + 4) >> 0]; - a[(h + 5) >> 0] = a[(l + 5) >> 0]; - a[(h + 6) >> 0] = a[(l + 6) >> 0]; - a[(h + 7) >> 0] = a[(l + 7) >> 0]; - k = +g[h >> 3]; - f = (c + 211) | 0; - a[h >> 0] = a[f >> 0]; - a[(h + 1) >> 0] = a[(f + 1) >> 0]; - a[(h + 2) >> 0] = a[(f + 2) >> 0]; - a[(h + 3) >> 0] = a[(f + 3) >> 0]; - a[(h + 4) >> 0] = a[(f + 4) >> 0]; - a[(h + 5) >> 0] = a[(f + 5) >> 0]; - a[(h + 6) >> 0] = a[(f + 6) >> 0]; - a[(h + 7) >> 0] = a[(f + 7) >> 0]; - d = +g[h >> 3]; - c = (c + 219) | 0; - a[h >> 0] = a[c >> 0]; - a[(h + 1) >> 0] = a[(c + 1) >> 0]; - a[(h + 2) >> 0] = a[(c + 2) >> 0]; - a[(h + 3) >> 0] = a[(c + 3) >> 0]; - a[(h + 4) >> 0] = a[(c + 4) >> 0]; - a[(h + 5) >> 0] = a[(c + 5) >> 0]; - a[(h + 6) >> 0] = a[(c + 6) >> 0]; - a[(h + 7) >> 0] = a[(c + 7) >> 0]; - e = +g[h >> 3]; - g[h >> 3] = o; - a[n >> 0] = a[h >> 0]; - a[(n + 1) >> 0] = a[(h + 1) >> 0]; - a[(n + 2) >> 0] = a[(h + 2) >> 0]; - a[(n + 3) >> 0] = a[(h + 3) >> 0]; - a[(n + 4) >> 0] = a[(h + 4) >> 0]; - a[(n + 5) >> 0] = a[(h + 5) >> 0]; - a[(n + 6) >> 0] = a[(h + 6) >> 0]; - a[(n + 7) >> 0] = a[(h + 7) >> 0]; - g[h >> 3] = m; - a[l >> 0] = a[h >> 0]; - a[(l + 1) >> 0] = a[(h + 1) >> 0]; - a[(l + 2) >> 0] = a[(h + 2) >> 0]; - a[(l + 3) >> 0] = a[(h + 3) >> 0]; - a[(l + 4) >> 0] = a[(h + 4) >> 0]; - a[(l + 5) >> 0] = a[(h + 5) >> 0]; - a[(l + 6) >> 0] = a[(h + 6) >> 0]; - a[(l + 7) >> 0] = a[(h + 7) >> 0]; - g[h >> 3] = k; - a[j >> 0] = a[h >> 0]; - a[(j + 1) >> 0] = a[(h + 1) >> 0]; - a[(j + 2) >> 0] = a[(h + 2) >> 0]; - a[(j + 3) >> 0] = a[(h + 3) >> 0]; - a[(j + 4) >> 0] = a[(h + 4) >> 0]; - a[(j + 5) >> 0] = a[(h + 5) >> 0]; - a[(j + 6) >> 0] = a[(h + 6) >> 0]; - a[(j + 7) >> 0] = a[(h + 7) >> 0]; - g[h >> 3] = i; - a[f >> 0] = a[h >> 0]; - a[(f + 1) >> 0] = a[(h + 1) >> 0]; - a[(f + 2) >> 0] = a[(h + 2) >> 0]; - a[(f + 3) >> 0] = a[(h + 3) >> 0]; - a[(f + 4) >> 0] = a[(h + 4) >> 0]; - a[(f + 5) >> 0] = a[(h + 5) >> 0]; - a[(f + 6) >> 0] = a[(h + 6) >> 0]; - a[(f + 7) >> 0] = a[(h + 7) >> 0]; - g[h >> 3] = e; - a[b >> 0] = a[h >> 0]; - a[(b + 1) >> 0] = a[(h + 1) >> 0]; - a[(b + 2) >> 0] = a[(h + 2) >> 0]; - a[(b + 3) >> 0] = a[(h + 3) >> 0]; - a[(b + 4) >> 0] = a[(h + 4) >> 0]; - a[(b + 5) >> 0] = a[(h + 5) >> 0]; - a[(b + 6) >> 0] = a[(h + 6) >> 0]; - a[(b + 7) >> 0] = a[(h + 7) >> 0]; - g[h >> 3] = d; - a[c >> 0] = a[h >> 0]; - a[(c + 1) >> 0] = a[(h + 1) >> 0]; - a[(c + 2) >> 0] = a[(h + 2) >> 0]; - a[(c + 3) >> 0] = a[(h + 3) >> 0]; - a[(c + 4) >> 0] = a[(h + 4) >> 0]; - a[(c + 5) >> 0] = a[(h + 5) >> 0]; - a[(c + 6) >> 0] = a[(h + 6) >> 0]; - a[(c + 7) >> 0] = a[(h + 7) >> 0]; - return; - } - function db() { - var b = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0; - g = V; - V = (V + 48) | 0; - e = (g + 24) | 0; - f = g; - b = (g + 44) | 0; - if ((a[21440] | 0) == 0 ? Tp(21440) | 0 : 0) { - c[5374] = 0; - c[5375] = 0; - c[5376] = 0; - $p(21440); - } - if ((a[21448] | 0) == 0 ? Tp(21448) | 0 : 0) - $p(21448); - if ((c[5374] | 0) == (c[5375] | 0)) { - rq(21508); - if ((c[5374] | 0) == (c[5375] | 0)) { - a[e >> 0] = a[b >> 0] | 0; - pb(f, e); - b = c[5375] | 0; - do - if (b >>> 0 >= (c[5376] | 0) >>> 0) { - b = (((((b - (c[5374] | 0)) | 0) / 24) | 0) + 1) | 0; - d = xb(21496) | 0; - if (d >>> 0 < b >>> 0) - cr(21496); - else { - h = c[5374] | 0; - j = ((((c[5376] | 0) - h) | 0) / 24) | 0; - i = j << 1; - ub(e, j >>> 0 < (d >>> 1) >>> 0 ? (i >>> 0 < b >>> 0 ? b : i) : d, ((((c[5375] | 0) - h) | 0) / 24) | 0, 21504); - d = (e + 8) | 0; - sb(c[d >> 2] | 0, f); - c[d >> 2] = (c[d >> 2] | 0) + 24; - vb(21496, e); - wb(e); - break; - } - } - else { - qb(e, 21496, 1); - j = (e + 4) | 0; - sb(c[j >> 2] | 0, f); - c[j >> 2] = (c[j >> 2] | 0) + 24; - rb(e); - } - while (0); - gb(f); - } - sq(21508); - } - V = g; - return 21496; - } - function eb(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0; - d = (b + 16) | 0; - e = c[d >> 2] | 0; - do - if (e) - if ((b | 0) == (e | 0)) { - e = tb(a) | 0; - c[(a + 16) >> 2] = e; - d = c[d >> 2] | 0; - da[c[((c[d >> 2] | 0) + 12) >> 2] & 15](d, e); - break; - } - else { - c[(a + 16) >> 2] = Z[c[((c[e >> 2] | 0) + 8) >> 2] & 15](e) | 0; - break; - } - else - c[(a + 16) >> 2] = 0; - while (0); - return; - } - function fb(a, b) { - a = a | 0; - b = b | 0; - a = c[(a + 16) >> 2] | 0; - if (!a) { - b = v(4) | 0; - c[b >> 2] = 0; - Nb(b); - x(b | 0, 4168, 131); - } - else { - da[c[((c[a >> 2] | 0) + 24) >> 2] & 15](a, b); - return; - } - } - function gb(a) { - a = a | 0; - var b = 0; - b = c[(a + 16) >> 2] | 0; - if ((a | 0) != (b | 0)) { - if (b | 0) - ca[c[((c[b >> 2] | 0) + 20) >> 2] & 255](b); - } - else - ca[c[((c[b >> 2] | 0) + 16) >> 2] & 255](b); - return; - } - function hb(b) { - b = b | 0; - var f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, q = 0; - q = V; - V = (V + 96) | 0; - i = (q + 16) | 0; - o = q; - l = (q + 72) | 0; - j = c[b >> 2] | 0; - m = e[(b + 114) >> 1] | 0; - n = o; - c[n >> 2] = 0; - c[(n + 4) >> 2] = 0; - n = (o + 8) | 0; - c[n >> 2] = m; - c[(n + 4) >> 2] = 0; - c[i >> 2] = c[o >> 2]; - c[(i + 4) >> 2] = c[(o + 4) >> 2]; - c[(i + 8) >> 2] = c[(o + 8) >> 2]; - c[(i + 12) >> 2] = c[(o + 12) >> 2]; - bb(j, i); - j = (b + 120) | 0; - a: do - if (c[j >> 2] | 0) { - k = (i + 2) | 0; - m = (i + 16) | 0; - n = (i + 20) | 0; - o = (i + 18) | 0; - g = 0; - while (1) { - if (!(Ob(c[b >> 2] | 0) | 0)) - break a; - if (Pb(c[b >> 2] | 0) | 0) - break a; - $a(c[b >> 2] | 0, i, 54); - f = 7277; - h = k; - while (1) { - if ((a[h >> 0] | 0) != (a[f >> 0] | 0)) - break; - h = (h + 1) | 0; - if ((h | 0) == (m | 0)) { - p = 8; - break; - } - else - f = (f + 1) | 0; - } - if ((p | 0) == 8 - ? ((p = 0), ((d[o >> 0] | (d[(o + 1) >> 0] << 8)) << 16) >> 16 == 22204) - : 0) - break; - Rb(c[b >> 2] | 0, (d[n >> 0] | (d[(n + 1) >> 0] << 8)) & 65535, 0, 1); - g = (g + 1) | 0; - if (g >>> 0 >= (c[j >> 2] | 0) >>> 0) - break a; - } - o = (d[n >> 0] | (d[(n + 1) >> 0] << 8)) & 65535; - p = fq(o) | 0; - $a(c[b >> 2] | 0, p, o); - Qb(b, p); - jp(p); - p = (b + 125) | 0; - Tb(l, (b + 247) | 0, (d[p >> 0] | (d[(p + 1) >> 0] << 8)) & 65535); - Ub((b + 300) | 0, l) | 0; - Pa(l); - V = q; - return; - } - while (0); - q = v(8) | 0; - Sb(q); - x(q | 0, 2672, 8); - } - function ib(a) { - a = a | 0; - var b = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0; - n = V; - V = (V + 176) | 0; - g = (n + 40) | 0; - h = (n + 24) | 0; - b = (n + 16) | 0; - f = n; - k = (n + 152) | 0; - l = (n + 136) | 0; - m = (n + 56) | 0; - j = c[a >> 2] | 0; - i = (a + 116) | 0; - o = c[i >> 2] | 0; - e = h; - c[e >> 2] = 0; - c[(e + 4) >> 2] = 0; - e = (h + 8) | 0; - c[e >> 2] = o; - c[(e + 4) >> 2] = 0; - c[g >> 2] = c[h >> 2]; - c[(g + 4) >> 2] = c[(h + 4) >> 2]; - c[(g + 8) >> 2] = c[(h + 8) >> 2]; - c[(g + 12) >> 2] = c[(h + 12) >> 2]; - bb(j, g); - j = b; - c[j >> 2] = 0; - c[(j + 4) >> 2] = 0; - $a(c[a >> 2] | 0, b, 8); - if (!(Ob(c[a >> 2] | 0) | 0)) { - o = v(8) | 0; - hc(o); - x(o | 0, 2704, 8); - } - e = b; - b = c[e >> 2] | 0; - e = c[(e + 4) >> 2] | 0; - if (((b | 0) == -1) & ((e | 0) == -1)) { - o = v(8) | 0; - ic(o, 7488); - x(o | 0, 2720, 8); - } - o = c[a >> 2] | 0; - j = f; - c[j >> 2] = 0; - c[(j + 4) >> 2] = 0; - j = (f + 8) | 0; - c[j >> 2] = b; - c[(j + 4) >> 2] = e; - c[g >> 2] = c[f >> 2]; - c[(g + 4) >> 2] = c[(f + 4) >> 2]; - c[(g + 8) >> 2] = c[(f + 8) >> 2]; - c[(g + 12) >> 2] = c[(f + 12) >> 2]; - bb(o, g); - if (!(Ob(c[a >> 2] | 0) | 0)) { - o = v(8) | 0; - hc(o); - x(o | 0, 2704, 8); - } - $a(c[a >> 2] | 0, g, 8); - if (!(Ob(c[a >> 2] | 0) | 0)) { - o = v(8) | 0; - hc(o); - x(o | 0, 2704, 8); - } - if (c[g >> 2] | 0) { - o = v(8) | 0; - jc(o); - x(o | 0, 2736, 8); - } - h = (a + 288) | 0; - j = (a + 292) | 0; - c[j >> 2] = c[h >> 2]; - o = (a + 259) | 0; - if ((d[o >> 0] | - (d[(o + 1) >> 0] << 8) | - (d[(o + 2) >> 0] << 16) | - (d[(o + 3) >> 0] << 24) | - 0) == - -1) { - o = v(8) | 0; - ic(o, 7606); - x(o | 0, 2720, 8); - } - f = (g + 4) | 0; - kc(h, ((c[f >> 2] | 0) + 1) | 0); - o = c[h >> 2] | 0; - c[o >> 2] = (c[i >> 2] | 0) + 8; - c[(o + 4) >> 2] = 0; - if ((c[f >> 2] | 0) >>> 0 > 1) { - Va(k, c[a >> 2] | 0); - lc(l, k); - mc(m, 32, 2, 8, 0); - nc(l); - oc(m); - if (!(c[f >> 2] | 0)) { - h = c[h >> 2] | 0; - e = h; - } - else { - e = 1; - do { - if (e >>> 0 > 1) - b = c[((c[h >> 2] | 0) + ((e + -1) << 3)) >> 2] | 0; - else - b = 0; - i = pc(m, l, b, 1) | 0; - b = c[h >> 2] | 0; - o = (b + (e << 3)) | 0; - c[o >> 2] = i; - c[(o + 4) >> 2] = (((i | 0) < 0) << 31) >> 31; - e = (e + 1) | 0; - } while (e >>> 0 <= (c[f >> 2] | 0) >>> 0); - e = b; - h = b; - } - b = c[j >> 2] | 0; - if (((b - e) >> 3) >>> 0 > 1) { - g = (b - h) >> 3; - f = h; - b = 1; - e = c[f >> 2] | 0; - f = c[(f + 4) >> 2] | 0; - do { - o = (h + (b << 3)) | 0; - j = o; - e = lr(c[j >> 2] | 0, c[(j + 4) >> 2] | 0, e | 0, f | 0) | 0; - f = u() | 0; - c[o >> 2] = e; - c[(o + 4) >> 2] = f; - b = (b + 1) | 0; - } while (b >>> 0 < g >>> 0); - } - qc(m); - rc(l); - Ra(k); - } - V = n; - return; - } - function jb(b) { - b = b | 0; - a[(b + 12) >> 0] = 0; - a[(b + 13) >> 0] = 0; - return; - } - function kb(a) { - a = a | 0; - c[(a + 8) >> 2] = 0; - c[(a + 4) >> 2] = 0; - return; - } - function lb(a) { - a = a | 0; - return fo(a) | 0; - } - function mb(b, d, e) { - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0, h = 0, i = 0, j = 0, k = 0; - i = V; - V = (V + 16) | 0; - g = d; - h = i; - f = (e - g) | 0; - if (f >>> 0 > 4294967279) - yq(b); - if (f >>> 0 < 11) - a[(b + 11) >> 0] = f; - else { - k = (f + 16) & -16; - j = eq(k) | 0; - c[b >> 2] = j; - c[(b + 8) >> 2] = k | -2147483648; - c[(b + 4) >> 2] = f; - b = j; - } - if ((d | 0) != (e | 0)) { - g = (e - g) | 0; - f = b; - while (1) { - nb(f, d); - d = (d + 1) | 0; - if ((d | 0) == (e | 0)) - break; - else - f = (f + 1) | 0; - } - b = (b + g) | 0; - } - a[h >> 0] = 0; - nb(b, h); - V = i; - return; - } - function nb(b, c) { - b = b | 0; - c = c | 0; - a[b >> 0] = a[c >> 0] | 0; - return; - } - function ob(a) { - a = a | 0; - yp(a); - jp(a); - return; - } - function pb(a, b) { - a = a | 0; - b = b | 0; - c[a >> 2] = 4372; - c[(a + 16) >> 2] = a; - return; - } - function qb(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - c[a >> 2] = b; - b = c[(b + 4) >> 2] | 0; - c[(a + 4) >> 2] = b; - c[(a + 8) >> 2] = b + ((d * 24) | 0); - return; - } - function rb(a) { - a = a | 0; - c[((c[a >> 2] | 0) + 4) >> 2] = c[(a + 4) >> 2]; - return; - } - function sb(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0; - d = (b + 16) | 0; - e = c[d >> 2] | 0; - do - if (e) - if ((b | 0) == (e | 0)) { - e = tb(a) | 0; - c[(a + 16) >> 2] = e; - d = c[d >> 2] | 0; - da[c[((c[d >> 2] | 0) + 12) >> 2] & 15](d, e); - break; - } - else { - c[(a + 16) >> 2] = e; - c[d >> 2] = 0; - break; - } - else - c[(a + 16) >> 2] = 0; - while (0); - return; - } - function tb(a) { - a = a | 0; - return a | 0; - } - function ub(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0; - f = (a + 12) | 0; - c[f >> 2] = 0; - c[(a + 16) >> 2] = e; - do - if (b) - if (b >>> 0 > 178956970) { - f = v(8) | 0; - vq(f, 6723); - c[f >> 2] = 5956; - x(f | 0, 3928, 123); - } - else { - e = eq((b * 24) | 0) | 0; - break; - } - else - e = 0; - while (0); - c[a >> 2] = e; - d = (e + ((d * 24) | 0)) | 0; - c[(a + 8) >> 2] = d; - c[(a + 4) >> 2] = d; - c[f >> 2] = e + ((b * 24) | 0); - return; - } - function vb(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0; - i = c[a >> 2] | 0; - j = (a + 4) | 0; - d = c[j >> 2] | 0; - h = (b + 4) | 0; - if ((d | 0) == (i | 0)) { - f = h; - g = a; - e = c[h >> 2] | 0; - d = i; - } - else { - e = c[h >> 2] | 0; - do { - d = (d + -24) | 0; - sb((e + -24) | 0, d); - e = ((c[h >> 2] | 0) + -24) | 0; - c[h >> 2] = e; - } while ((d | 0) != (i | 0)); - f = h; - g = a; - d = c[a >> 2] | 0; - } - c[g >> 2] = e; - c[f >> 2] = d; - i = (b + 8) | 0; - h = c[j >> 2] | 0; - c[j >> 2] = c[i >> 2]; - c[i >> 2] = h; - i = (a + 8) | 0; - j = (b + 12) | 0; - a = c[i >> 2] | 0; - c[i >> 2] = c[j >> 2]; - c[j >> 2] = a; - c[b >> 2] = c[f >> 2]; - return; - } - function wb(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0; - d = c[(a + 4) >> 2] | 0; - e = (a + 8) | 0; - b = c[e >> 2] | 0; - if ((b | 0) != (d | 0)) - do { - f = (b + -24) | 0; - c[e >> 2] = f; - gb(f); - b = c[e >> 2] | 0; - } while ((b | 0) != (d | 0)); - b = c[a >> 2] | 0; - if (b | 0) - Da(b, ((c[(a + 12) >> 2] | 0) - b) | 0); - return; - } - function xb(a) { - a = a | 0; - return 178956970; - } - function yb(a) { - a = a | 0; - jp(a); - return; - } - function zb(a) { - a = a | 0; - a = eq(8) | 0; - c[a >> 2] = 4372; - return a | 0; - } - function Ab(a, b) { - a = a | 0; - b = b | 0; - c[b >> 2] = 4372; - return; - } - function Bb(a) { - a = a | 0; - return; - } - function Cb(a) { - a = a | 0; - Da(a, 8); - return; - } - function Db(a, b) { - a = a | 0; - b = b | 0; - Hb((a + 4) | 0, b); - return; - } - function Eb(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 7183 ? (a + 4) | 0 : 0) | 0; - } - function Fb(a) { - a = a | 0; - return 2664; - } - function Gb(a) { - a = a | 0; - return; - } - function Hb(a, b) { - a = a | 0; - b = b | 0; - Ib(a, b); - return; - } - function Ib(b, c) { - b = b | 0; - c = c | 0; - var e = 0, f = 0; - b = (c + 104) | 0; - c = d[b >> 0] | 0; - e = c >>> 7; - f = (c >>> 6) & 1; - if (((e | 0) == 1) & ((f | 0) != 0)) { - f = v(8) | 0; - Jb(f); - x(f | 0, 2632, 8); - } - if ((e | 0) == (f | 0)) { - f = v(8) | 0; - Kb(f); - x(f | 0, 2648, 8); - } - else { - a[b >> 0] = c & 63; - return; - } - } - function Jb(a) { - a = a | 0; - xq(a, 7076); - c[a >> 2] = 4416; - return; - } - function Kb(a) { - a = a | 0; - xq(a, 7144); - c[a >> 2] = 4436; - return; - } - function Lb(a) { - a = a | 0; - yp(a); - jp(a); - return; - } - function Mb(a) { - a = a | 0; - yp(a); - jp(a); - return; - } - function Nb(a) { - a = a | 0; - c[a >> 2] = 6092; - return; - } - function Ob(b) { - b = b | 0; - var c = 0; - c = (b + 12) | 0; - b = (a[c >> 0] | 0) == 0; - a[c >> 0] = 0; - return b | 0; - } - function Pb(b) { - b = b | 0; - return ((a[(b + 13) >> 0] | 0) != 0) | 0; - } - function Qb(a, b) { - a = a | 0; - b = b | 0; - a = (a + 247) | 0; - Vb(a, b); - if (((d[a >> 0] | (d[(a + 1) >> 0] << 8)) << 16) >> 16 == 2) - return; - else { - b = v(8) | 0; - Wb(b); - x(b | 0, 2688, 8); - } - } - function Rb(b, d, e, f) { - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - var g = 0, h = 0; - switch (f | 0) { - case 0: - break; - case 2: { - f = c[(b + 4) >> 2] | 0; - d = - lr(lr(d | 0, e | 0, -1, -1) | 0, u() | 0, f | 0, ((((f | 0) < 0) << 31) >> 31) | 0) | 0; - e = u() | 0; - break; - } - case 1: { - f = c[(b + 8) >> 2] | 0; - d = lr(f | 0, ((((f | 0) < 0) << 31) >> 31) | 0, d | 0, e | 0) | 0; - e = u() | 0; - break; - } - default: { - e = 0; - d = 0; - } - } - g = c[(b + 4) >> 2] | 0; - h = (((g | 0) < 0) << 31) >> 31; - f = (b + 12) | 0; - if (((e | 0) < 0) | (((e | 0) > (h | 0)) | (((e | 0) == (h | 0)) & (d >>> 0 >= g >>> 0)))) - a[f >> 0] = 1; - else { - a[f >> 0] = 0; - c[(b + 8) >> 2] = d; - } - return; - } - function Sb(a) { - a = a | 0; - xq(a, 7410); - c[a >> 2] = 4476; - return; - } - function Tb(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - var e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0; - h = V; - V = (V + 16) | 0; - g = h; - Xa(a); - f = (b + 32) | 0; - if (((d[f >> 0] | (d[(f + 1) >> 0] << 8)) << 16) >> 16) { - e = (b + 34) | 0; - b = 0; - do { - j = - d[e >> 0] | (d[(e + 1) >> 0] << 8) | (d[(e + 2) >> 0] << 16) | (d[(e + 3) >> 0] << 24); - k = (j + ((b * 6) | 0)) | 0; - i = (j + ((b * 6) | 0) + 2) | 0; - j = (j + ((b * 6) | 0) + 4) | 0; - _b(g, (d[k >> 0] | (d[(k + 1) >> 0] << 8)) & 65535, (d[i >> 0] | (d[(i + 1) >> 0] << 8)) & 65535, (d[j >> 0] | (d[(j + 1) >> 0] << 8)) & 65535); - Zb(a, g); - c = (c - ((d[i >> 0] | (d[(i + 1) >> 0] << 8)) & 65535)) | 0; - b = (b + 1) | 0; - } while (b >>> 0 < ((d[f >> 0] | (d[(f + 1) >> 0] << 8)) & 65535) >>> 0); - } - if ((c | 0) < 0) { - k = v(8) | 0; - Wb(k); - x(k | 0, 2688, 8); - } - if (c | 0) { - _b(g, 0, c, 2); - Zb(a, g); - } - V = h; - return; - } - function Ub(b, c) { - b = b | 0; - c = c | 0; - var d = 0, e = 0; - d = V; - V = (V + 16) | 0; - e = (d + 1) | 0; - a[e >> 0] = a[d >> 0] | 0; - fc(b, c, e); - V = d; - return b | 0; - } - function Vb(b, c) { - b = b | 0; - c = c | 0; - var e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0; - f = (c + 2) | 0; - h = d[c >> 0] | (d[(c + 1) >> 0] << 8); - a[b >> 0] = h; - a[(b + 1) >> 0] = h >> 8; - h = (b + 2) | 0; - f = d[f >> 0] | (d[(f + 1) >> 0] << 8); - a[h >> 0] = f; - a[(h + 1) >> 0] = f >> 8; - a[(b + 4) >> 0] = a[(c + 4) >> 0] | 0; - h = (c + 6) | 0; - a[(b + 5) >> 0] = a[(c + 5) >> 0] | 0; - f = (c + 8) | 0; - e = (b + 6) | 0; - h = d[h >> 0] | (d[(h + 1) >> 0] << 8); - a[e >> 0] = h; - a[(e + 1) >> 0] = h >> 8; - e = (c + 12) | 0; - h = (b + 8) | 0; - f = d[f >> 0] | (d[(f + 1) >> 0] << 8) | (d[(f + 2) >> 0] << 16) | (d[(f + 3) >> 0] << 24); - a[h >> 0] = f; - a[(h + 1) >> 0] = f >> 8; - a[(h + 2) >> 0] = f >> 16; - a[(h + 3) >> 0] = f >> 24; - h = (b + 12) | 0; - e = d[e >> 0] | (d[(e + 1) >> 0] << 8) | (d[(e + 2) >> 0] << 16) | (d[(e + 3) >> 0] << 24); - a[h >> 0] = e; - a[(h + 1) >> 0] = e >> 8; - a[(h + 2) >> 0] = e >> 16; - a[(h + 3) >> 0] = e >> 24; - h = (c + 16) | 0; - e = h; - e = d[e >> 0] | (d[(e + 1) >> 0] << 8) | (d[(e + 2) >> 0] << 16) | (d[(e + 3) >> 0] << 24); - h = (h + 4) | 0; - h = d[h >> 0] | (d[(h + 1) >> 0] << 8) | (d[(h + 2) >> 0] << 16) | (d[(h + 3) >> 0] << 24); - f = (b + 16) | 0; - i = f; - a[i >> 0] = e; - a[(i + 1) >> 0] = e >> 8; - a[(i + 2) >> 0] = e >> 16; - a[(i + 3) >> 0] = e >> 24; - f = (f + 4) | 0; - a[f >> 0] = h; - a[(f + 1) >> 0] = h >> 8; - a[(f + 2) >> 0] = h >> 16; - a[(f + 3) >> 0] = h >> 24; - f = (c + 32) | 0; - h = (c + 24) | 0; - i = h; - i = d[i >> 0] | (d[(i + 1) >> 0] << 8) | (d[(i + 2) >> 0] << 16) | (d[(i + 3) >> 0] << 24); - h = (h + 4) | 0; - h = d[h >> 0] | (d[(h + 1) >> 0] << 8) | (d[(h + 2) >> 0] << 16) | (d[(h + 3) >> 0] << 24); - e = (b + 24) | 0; - g = e; - a[g >> 0] = i; - a[(g + 1) >> 0] = i >> 8; - a[(g + 2) >> 0] = i >> 16; - a[(g + 3) >> 0] = i >> 24; - e = (e + 4) | 0; - a[e >> 0] = h; - a[(e + 1) >> 0] = h >> 8; - a[(e + 2) >> 0] = h >> 16; - a[(e + 3) >> 0] = h >> 24; - e = (c + 34) | 0; - h = (b + 32) | 0; - f = d[f >> 0] | (d[(f + 1) >> 0] << 8); - a[h >> 0] = f; - a[(h + 1) >> 0] = f >> 8; - g = (b + 34) | 0; - b = d[g >> 0] | (d[(g + 1) >> 0] << 8) | (d[(g + 2) >> 0] << 16) | (d[(g + 3) >> 0] << 24); - if (!b) - b = f; - else { - gq(b); - b = d[h >> 0] | (d[(h + 1) >> 0] << 8); - } - f = fq(((b & 65535) * 6) | 0) | 0; - a[g >> 0] = f; - a[(g + 1) >> 0] = f >> 8; - a[(g + 2) >> 0] = f >> 16; - a[(g + 3) >> 0] = f >> 24; - if ((b << 16) >> 16 - ? ((b = (c + 36) | 0), - (i = d[e >> 0] | (d[(e + 1) >> 0] << 8)), - (a[f >> 0] = i), - (a[(f + 1) >> 0] = i >> 8), - (c = (c + 38) | 0), - (i = (f + 2) | 0), - (b = d[b >> 0] | (d[(b + 1) >> 0] << 8)), - (a[i >> 0] = b), - (a[(i + 1) >> 0] = b >> 8), - (i = (f + 4) | 0), - (c = d[c >> 0] | (d[(c + 1) >> 0] << 8)), - (a[i >> 0] = c), - (a[(i + 1) >> 0] = c >> 8), - ((d[h >> 0] | (d[(h + 1) >> 0] << 8)) & 65535) > 1) - : 0) { - b = 1; - do { - c = e; - e = (e + 6) | 0; - i = - d[g >> 0] | (d[(g + 1) >> 0] << 8) | (d[(g + 2) >> 0] << 16) | (d[(g + 3) >> 0] << 24); - j = (c + 8) | 0; - f = (i + ((b * 6) | 0)) | 0; - k = d[e >> 0] | (d[(e + 1) >> 0] << 8); - a[f >> 0] = k; - a[(f + 1) >> 0] = k >> 8; - c = (c + 10) | 0; - f = (i + ((b * 6) | 0) + 2) | 0; - j = d[j >> 0] | (d[(j + 1) >> 0] << 8); - a[f >> 0] = j; - a[(f + 1) >> 0] = j >> 8; - i = (i + ((b * 6) | 0) + 4) | 0; - c = d[c >> 0] | (d[(c + 1) >> 0] << 8); - a[i >> 0] = c; - a[(i + 1) >> 0] = c >> 8; - b = (b + 1) | 0; - } while (b >>> 0 < ((d[h >> 0] | (d[(h + 1) >> 0] << 8)) & 65535) >>> 0); - } - return; - } - function Wb(a) { - a = a | 0; - xq(a, 7354); - c[a >> 2] = 4456; - return; - } - function Xb(a) { - a = a | 0; - yp(a); - jp(a); - return; - } - function Yb(a) { - a = a | 0; - yp(a); - jp(a); - return; - } - function Zb(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0; - i = V; - V = (V + 32) | 0; - f = i; - g = (a + 4) | 0; - d = c[g >> 2] | 0; - h = (a + 8) | 0; - do - if ((d | 0) == (c[h >> 2] | 0)) { - d = (((((d - (c[a >> 2] | 0)) | 0) / 12) | 0) + 1) | 0; - e = ec(a) | 0; - if (e >>> 0 < d >>> 0) - cr(a); - else { - j = c[a >> 2] | 0; - k = ((((c[h >> 2] | 0) - j) | 0) / 12) | 0; - h = k << 1; - bc(f, k >>> 0 < (e >>> 1) >>> 0 ? (h >>> 0 < d >>> 0 ? d : h) : e, ((((c[g >> 2] | 0) - j) | 0) / 12) | 0, (a + 8) | 0); - h = (f + 8) | 0; - g = c[h >> 2] | 0; - c[g >> 2] = c[b >> 2]; - c[(g + 4) >> 2] = c[(b + 4) >> 2]; - c[(g + 8) >> 2] = c[(b + 8) >> 2]; - c[h >> 2] = (c[h >> 2] | 0) + 12; - cc(a, f); - dc(f); - break; - } - } - else { - $b(f, a, 1); - k = (f + 4) | 0; - j = c[k >> 2] | 0; - c[j >> 2] = c[b >> 2]; - c[(j + 4) >> 2] = c[(b + 4) >> 2]; - c[(j + 8) >> 2] = c[(b + 8) >> 2]; - c[k >> 2] = (c[k >> 2] | 0) + 12; - ac(f); - } - while (0); - V = i; - return; - } - function _b(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - c[a >> 2] = b; - c[(a + 4) >> 2] = d; - c[(a + 8) >> 2] = e; - return; - } - function $b(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - c[a >> 2] = b; - b = c[(b + 4) >> 2] | 0; - c[(a + 4) >> 2] = b; - c[(a + 8) >> 2] = b + ((d * 12) | 0); - return; - } - function ac(a) { - a = a | 0; - c[((c[a >> 2] | 0) + 4) >> 2] = c[(a + 4) >> 2]; - return; - } - function bc(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0; - f = (a + 12) | 0; - c[f >> 2] = 0; - c[(a + 16) >> 2] = e; - do - if (b) - if (b >>> 0 > 357913941) { - f = v(8) | 0; - vq(f, 6723); - c[f >> 2] = 5956; - x(f | 0, 3928, 123); - } - else { - e = eq((b * 12) | 0) | 0; - break; - } - else - e = 0; - while (0); - c[a >> 2] = e; - d = (e + ((d * 12) | 0)) | 0; - c[(a + 8) >> 2] = d; - c[(a + 4) >> 2] = d; - c[f >> 2] = e + ((b * 12) | 0); - return; - } - function cc(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0; - e = c[a >> 2] | 0; - h = (a + 4) | 0; - g = (b + 4) | 0; - f = ((c[h >> 2] | 0) - e) | 0; - d = ((c[g >> 2] | 0) + (((((f | 0) / -12) | 0) * 12) | 0)) | 0; - c[g >> 2] = d; - if ((f | 0) > 0) { - ur(d | 0, e | 0, f | 0) | 0; - e = g; - d = c[g >> 2] | 0; - } - else - e = g; - g = c[a >> 2] | 0; - c[a >> 2] = d; - c[e >> 2] = g; - g = (b + 8) | 0; - f = c[h >> 2] | 0; - c[h >> 2] = c[g >> 2]; - c[g >> 2] = f; - g = (a + 8) | 0; - h = (b + 12) | 0; - a = c[g >> 2] | 0; - c[g >> 2] = c[h >> 2]; - c[h >> 2] = a; - c[b >> 2] = c[e >> 2]; - return; - } - function dc(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = c[(a + 4) >> 2] | 0; - d = (a + 8) | 0; - e = c[d >> 2] | 0; - if ((e | 0) != (b | 0)) - c[d >> 2] = e + ((~(((((e + -12 - b) | 0) >>> 0) / 12) | 0) * 12) | 0); - b = c[a >> 2] | 0; - if (b | 0) - Da(b, ((c[(a + 12) >> 2] | 0) - b) | 0); - return; - } - function ec(a) { - a = a | 0; - return 357913941; - } - function fc(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0; - gc(a); - c[a >> 2] = c[b >> 2]; - d = (b + 4) | 0; - c[(a + 4) >> 2] = c[d >> 2]; - e = (b + 8) | 0; - c[(a + 8) >> 2] = c[e >> 2]; - c[e >> 2] = 0; - c[d >> 2] = 0; - c[b >> 2] = 0; - return; - } - function gc(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0; - b = c[a >> 2] | 0; - d = b; - if (b | 0) { - e = (a + 4) | 0; - c[e >> 2] = d; - f = (a + 8) | 0; - Da(b, ((c[f >> 2] | 0) - d) | 0); - c[f >> 2] = 0; - c[e >> 2] = 0; - c[a >> 2] = 0; - } - return; - } - function hc(a) { - a = a | 0; - xq(a, 7660); - c[a >> 2] = 4496; - return; - } - function ic(a, b) { - a = a | 0; - b = b | 0; - xq(a, b); - c[a >> 2] = 4516; - return; - } - function jc(a) { - a = a | 0; - xq(a, 7704); - c[a >> 2] = 4536; - return; - } - function kc(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0; - d = (a + 4) | 0; - f = c[a >> 2] | 0; - e = ((c[d >> 2] | 0) - f) >> 3; - if (e >>> 0 >= b >>> 0) { - if (e >>> 0 > b >>> 0) - c[d >> 2] = f + (b << 3); - } - else - vc(a, (b - e) | 0); - return; - } - function lc(a, b) { - a = a | 0; - b = b | 0; - c[a >> 2] = b; - c[(a + 4) >> 2] = 0; - c[(a + 8) >> 2] = -1; - return; - } - function mc(a, b, d, e, f) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - var g = 0; - c[(a + 4) >> 2] = b; - c[(a + 8) >> 2] = d; - c[(a + 12) >> 2] = e; - c[(a + 16) >> 2] = f; - c[(a + 36) >> 2] = 0; - c[(a + 40) >> 2] = 0; - c[(a + 44) >> 2] = 0; - Gc((a + 48) | 0); - c[(a + 68) >> 2] = 0; - c[(a + 72) >> 2] = 0; - c[(a + 76) >> 2] = 0; - do - if (!f) { - d = (a + 20) | 0; - if (((b + -1) | 0) >>> 0 < 31) { - c[d >> 2] = b; - f = 1 << b; - c[(a + 24) >> 2] = f; - d = f >>> 1; - c[(a + 28) >> 2] = 0 - d; - d = (f + -1 - d) | 0; - break; - } - else { - c[d >> 2] = 32; - c[(a + 24) >> 2] = 0; - c[(a + 28) >> 2] = -2147483648; - d = 2147483647; - break; - } - } - else { - e = (a + 20) | 0; - c[e >> 2] = 0; - c[(a + 24) >> 2] = f; - d = f; - g = 0; - while (1) { - d = d >>> 1; - b = (g + 1) | 0; - if (!d) - break; - else - g = b; - } - c[e >> 2] = ((1 << g) | 0) == (f | 0) ? g : b; - d = f >>> 1; - c[(a + 28) >> 2] = 0 - d; - d = (f + -1 - d) | 0; - } - while (0); - c[(a + 32) >> 2] = d; - c[a >> 2] = 0; - return; - } - function nc(a) { - a = a | 0; - var b = 0; - b = ((Jc(c[a >> 2] | 0) | 0) & 255) << 24; - b = (((Jc(c[a >> 2] | 0) | 0) & 255) << 16) | b; - b = b | (((Jc(c[a >> 2] | 0) | 0) & 255) << 8); - c[(a + 4) >> 2] = b | ((Jc(c[a >> 2] | 0) | 0) & 255); - return; - } - function oc(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, q = 0, r = 0, s = 0, t = 0; - q = V; - V = (V + 64) | 0; - o = (q + 44) | 0; - p = q; - k = (a + 36) | 0; - l = (a + 40) | 0; - a: do - if ((c[k >> 2] | 0) == (c[l >> 2] | 0)) { - m = (a + 8) | 0; - b: do - if (!(c[m >> 2] | 0)) - n = (a + 20) | 0; - else { - f = (a + 20) | 0; - g = (a + 44) | 0; - h = (o + 4) | 0; - i = (a + 44) | 0; - j = (o + 8) | 0; - e = 0; - while (1) { - Oc(p, ((c[f >> 2] | 0) + 1) | 0, 0, 0); - b = c[l >> 2] | 0; - if (b >>> 0 < (c[g >> 2] | 0) >>> 0) { - Pc(o, k, 1); - Rc(c[h >> 2] | 0, p); - c[h >> 2] = (c[h >> 2] | 0) + 44; - Qc(o); - } - else { - b = (((((b - (c[k >> 2] | 0)) | 0) / 44) | 0) + 1) | 0; - d = Vc(k) | 0; - if (d >>> 0 < b >>> 0) - break; - r = c[k >> 2] | 0; - t = ((((c[g >> 2] | 0) - r) | 0) / 44) | 0; - s = t << 1; - Sc(o, t >>> 0 < (d >>> 1) >>> 0 ? (s >>> 0 < b >>> 0 ? b : s) : d, ((((c[l >> 2] | 0) - r) | 0) / 44) | 0, i); - Rc(c[j >> 2] | 0, p); - c[j >> 2] = (c[j >> 2] | 0) + 44; - Tc(k, o); - Uc(o); - } - Ic(p); - e = (e + 1) | 0; - if (e >>> 0 >= (c[m >> 2] | 0) >>> 0) { - n = f; - break b; - } - } - cr(k); - } - while (0); - if (c[n >> 2] | 0) { - h = (a + 12) | 0; - i = (a + 68) | 0; - j = (a + 72) | 0; - k = (a + 76) | 0; - l = (o + 4) | 0; - f = (a + 76) | 0; - g = (o + 8) | 0; - e = 1; - while (1) { - b = c[h >> 2] | 0; - Oc(p, 1 << (e >>> 0 > b >>> 0 ? b : e), 0, 0); - b = c[j >> 2] | 0; - if (b >>> 0 < (c[k >> 2] | 0) >>> 0) { - Pc(o, i, 1); - Rc(c[l >> 2] | 0, p); - c[l >> 2] = (c[l >> 2] | 0) + 44; - Qc(o); - } - else { - b = (((((b - (c[i >> 2] | 0)) | 0) / 44) | 0) + 1) | 0; - d = Vc(i) | 0; - if (d >>> 0 < b >>> 0) - break; - t = c[i >> 2] | 0; - r = ((((c[k >> 2] | 0) - t) | 0) / 44) | 0; - s = r << 1; - Sc(o, r >>> 0 < (d >>> 1) >>> 0 ? (s >>> 0 < b >>> 0 ? b : s) : d, ((((c[j >> 2] | 0) - t) | 0) / 44) | 0, f); - Rc(c[g >> 2] | 0, p); - c[g >> 2] = (c[g >> 2] | 0) + 44; - Tc(i, o); - Uc(o); - } - Ic(p); - e = (e + 1) | 0; - if (e >>> 0 > (c[n >> 2] | 0) >>> 0) - break a; - } - cr(i); - } - } - while (0); - V = q; - return; - } - function pc(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - d = ((Yc(a, b, ((c[(a + 36) >> 2] | 0) + ((e * 44) | 0)) | 0) | 0) + d) | 0; - b = c[(a + 24) >> 2] | 0; - if ((d | 0) < 0) - return (d + b) | 0; - else - return (d - (d >>> 0 < b >>> 0 ? 0 : b)) | 0; - return 0; - } - function qc(a) { - a = a | 0; - Hc((a + 68) | 0); - Hc((a + 36) | 0); - return; - } - function rc(a) { - a = a | 0; - return; - } - function sc(a) { - a = a | 0; - yp(a); - jp(a); - return; - } - function tc(a) { - a = a | 0; - yp(a); - jp(a); - return; - } - function uc(a) { - a = a | 0; - yp(a); - jp(a); - return; - } - function vc(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0; - i = V; - V = (V + 32) | 0; - f = i; - g = (a + 8) | 0; - h = (a + 4) | 0; - d = c[h >> 2] | 0; - do - if ((((c[g >> 2] | 0) - d) >> 3) >>> 0 < b >>> 0) { - d = (((d - (c[a >> 2] | 0)) >> 3) + b) | 0; - e = Dc(a) | 0; - if (e >>> 0 < d >>> 0) - cr(a); - else { - j = c[a >> 2] | 0; - k = ((c[g >> 2] | 0) - j) | 0; - g = k >> 2; - xc(f, (k >> 3) >>> 0 < (e >>> 1) >>> 0 ? (g >>> 0 < d >>> 0 ? d : g) : e, ((c[h >> 2] | 0) - j) >> 3, (a + 8) | 0); - yc(f, b); - zc(a, f); - Ac(f); - break; - } - } - else - wc(a, b); - while (0); - V = i; - return; - } - function wc(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0; - f = V; - V = (V + 16) | 0; - e = f; - Bc(e, a, b); - a = (e + 4) | 0; - b = c[a >> 2] | 0; - d = c[(e + 8) >> 2] | 0; - if ((b | 0) != (d | 0)) { - d = (d + -8 - b) | 0; - wr(b | 0, 0, ((d + 8) & -8) | 0) | 0; - c[a >> 2] = b + (((d >>> 3) + 1) << 3); - } - Cc(e); - V = f; - return; - } - function xc(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0; - f = (a + 12) | 0; - c[f >> 2] = 0; - c[(a + 16) >> 2] = e; - do - if (b) - if (b >>> 0 > 536870911) { - f = v(8) | 0; - vq(f, 6723); - c[f >> 2] = 5956; - x(f | 0, 3928, 123); - } - else { - e = eq(b << 3) | 0; - break; - } - else - e = 0; - while (0); - c[a >> 2] = e; - d = (e + (d << 3)) | 0; - c[(a + 8) >> 2] = d; - c[(a + 4) >> 2] = d; - c[f >> 2] = e + (b << 3); - return; - } - function yc(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0; - e = V; - V = (V + 16) | 0; - d = e; - Ec(d, (a + 8) | 0, b); - a = c[d >> 2] | 0; - b = c[(d + 4) >> 2] | 0; - if ((a | 0) != (b | 0)) { - b = (b + -8 - a) | 0; - wr(a | 0, 0, ((b + 8) & -8) | 0) | 0; - c[d >> 2] = a + (((b >>> 3) + 1) << 3); - } - Fc(d); - V = e; - return; - } - function zc(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0; - e = c[a >> 2] | 0; - h = (a + 4) | 0; - g = (b + 4) | 0; - f = ((c[h >> 2] | 0) - e) | 0; - d = ((c[g >> 2] | 0) + ((0 - (f >> 3)) << 3)) | 0; - c[g >> 2] = d; - if ((f | 0) > 0) { - ur(d | 0, e | 0, f | 0) | 0; - e = g; - d = c[g >> 2] | 0; - } - else - e = g; - g = c[a >> 2] | 0; - c[a >> 2] = d; - c[e >> 2] = g; - g = (b + 8) | 0; - f = c[h >> 2] | 0; - c[h >> 2] = c[g >> 2]; - c[g >> 2] = f; - g = (a + 8) | 0; - h = (b + 12) | 0; - a = c[g >> 2] | 0; - c[g >> 2] = c[h >> 2]; - c[h >> 2] = a; - c[b >> 2] = c[e >> 2]; - return; - } - function Ac(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = c[(a + 4) >> 2] | 0; - d = (a + 8) | 0; - e = c[d >> 2] | 0; - if ((e | 0) != (b | 0)) - c[d >> 2] = e + (~(((e + -8 - b) | 0) >>> 3) << 3); - b = c[a >> 2] | 0; - if (b | 0) - Da(b, ((c[(a + 12) >> 2] | 0) - b) | 0); - return; - } - function Bc(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - c[a >> 2] = b; - b = c[(b + 4) >> 2] | 0; - c[(a + 4) >> 2] = b; - c[(a + 8) >> 2] = b + (d << 3); - return; - } - function Cc(a) { - a = a | 0; - c[((c[a >> 2] | 0) + 4) >> 2] = c[(a + 4) >> 2]; - return; - } - function Dc(a) { - a = a | 0; - return 536870911; - } - function Ec(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - c[a >> 2] = c[b >> 2]; - c[(a + 4) >> 2] = (c[b >> 2] | 0) + (d << 3); - c[(a + 8) >> 2] = b; - return; - } - function Fc(a) { - a = a | 0; - c[c[(a + 8) >> 2] >> 2] = c[a >> 2]; - return; - } - function Gc(a) { - a = a | 0; - c[(a + 12) >> 2] = 1; - c[(a + 16) >> 2] = 2; - c[(a + 8) >> 2] = 4096; - c[(a + 4) >> 2] = 4; - c[a >> 2] = 4; - return; - } - function Hc(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - d = c[a >> 2] | 0; - if (d | 0) { - e = (a + 4) | 0; - b = c[e >> 2] | 0; - if ((b | 0) == (d | 0)) - b = d; - else { - do { - b = (b + -44) | 0; - Ic(b); - } while ((b | 0) != (d | 0)); - b = c[a >> 2] | 0; - } - c[e >> 2] = d; - Da(b, ((c[(a + 8) >> 2] | 0) - b) | 0); - } - return; - } - function Ic(a) { - a = a | 0; - var b = 0; - b = c[(a + 8) >> 2] | 0; - if (b | 0) - Ua(b); - b = c[(a + 12) >> 2] | 0; - if (b | 0) - Ua(b); - b = c[(a + 16) >> 2] | 0; - if (b | 0) - Ua(b); - return; - } - function Jc(b) { - b = b | 0; - var d = 0, e = 0; - e = (b + 4) | 0; - d = c[e >> 2] | 0; - if ((d | 0) >= (c[(b + 8) >> 2] | 0)) { - Kc(b); - d = c[e >> 2] | 0; - } - b = c[(b + 12) >> 2] | 0; - c[e >> 2] = d + 1; - return a[(b + d) >> 0] | 0; - } - function Kc(a) { - a = a | 0; - var b = 0; - c[(a + 4) >> 2] = 0; - $a(c[a >> 2] | 0, c[(a + 12) >> 2] | 0, 1048576); - b = Lc(c[a >> 2] | 0) | 0; - c[(a + 8) >> 2] = b; - if (!b) { - b = v(8) | 0; - Mc(b); - x(b | 0, 2752, 8); - } - else - return; - } - function Lc(a) { - a = a | 0; - return c[(a + 16) >> 2] | 0; - } - function Mc(a) { - a = a | 0; - xq(a, 7769); - c[a >> 2] = 4556; - return; - } - function Nc(a) { - a = a | 0; - yp(a); - jp(a); - return; - } - function Oc(b, d, e, f) { - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - var g = 0, h = 0, i = 0; - c[b >> 2] = d; - a[(b + 4) >> 0] = e & 1; - h = (b + 8) | 0; - c[h >> 2] = 0; - i = (b + 12) | 0; - c[i >> 2] = 0; - g = (b + 16) | 0; - c[g >> 2] = 0; - if (((d + -2) | 0) >>> 0 > 2046) { - b = v(8) | 0; - xq(b, 7789); - x(b | 0, 3912, 8); - } - c[(b + 32) >> 2] = d + -1; - if ((d >>> 0 > 16) & (e ^ 1)) { - e = 3; - while (1) - if ((1 << (e + 2)) >>> 0 < d >>> 0) - e = (e + 1) | 0; - else - break; - d = 1 << e; - c[(b + 36) >> 2] = d; - c[(b + 40) >> 2] = 15 - e; - c[g >> 2] = _a(((d << 2) + 8) | 0) | 0; - d = c[b >> 2] | 0; - } - else { - c[g >> 2] = 0; - c[(b + 40) >> 2] = 0; - c[(b + 36) >> 2] = 0; - } - c[h >> 2] = _a(d << 2) | 0; - g = _a(c[b >> 2] << 2) | 0; - c[i >> 2] = g; - c[(b + 20) >> 2] = 0; - d = c[b >> 2] | 0; - e = (b + 24) | 0; - c[e >> 2] = d; - d = (d | 0) != 0; - if (!f) { - if (d) { - d = 0; - do { - c[(g + (d << 2)) >> 2] = 1; - d = (d + 1) | 0; - } while (d >>> 0 < (c[b >> 2] | 0) >>> 0); - } - } - else if (d) { - d = 0; - do { - c[(g + (d << 2)) >> 2] = c[(f + (d << 2)) >> 2]; - d = (d + 1) | 0; - } while (d >>> 0 < (c[b >> 2] | 0) >>> 0); - } - Xc(b); - f = (((c[b >> 2] | 0) + 6) | 0) >>> 1; - c[e >> 2] = f; - c[(b + 28) >> 2] = f; - return; - } - function Pc(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - c[a >> 2] = b; - b = c[(b + 4) >> 2] | 0; - c[(a + 4) >> 2] = b; - c[(a + 8) >> 2] = b + ((d * 44) | 0); - return; - } - function Qc(a) { - a = a | 0; - c[((c[a >> 2] | 0) + 4) >> 2] = c[(a + 4) >> 2]; - return; - } - function Rc(b, d) { - b = b | 0; - d = d | 0; - var e = 0; - c[b >> 2] = c[d >> 2]; - a[(b + 4) >> 0] = a[(d + 4) >> 0] | 0; - e = (d + 8) | 0; - c[(b + 8) >> 2] = c[e >> 2]; - c[(b + 12) >> 2] = c[(d + 12) >> 2]; - c[(b + 16) >> 2] = c[(d + 16) >> 2]; - c[(b + 20) >> 2] = c[(d + 20) >> 2]; - c[(b + 24) >> 2] = c[(d + 24) >> 2]; - c[(b + 28) >> 2] = c[(d + 28) >> 2]; - c[(b + 32) >> 2] = c[(d + 32) >> 2]; - c[(b + 36) >> 2] = c[(d + 36) >> 2]; - c[(b + 40) >> 2] = c[(d + 40) >> 2]; - c[e >> 2] = 0; - c[(e + 4) >> 2] = 0; - c[(e + 8) >> 2] = 0; - return; - } - function Sc(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0; - f = (a + 12) | 0; - c[f >> 2] = 0; - c[(a + 16) >> 2] = e; - do - if (b) - if (b >>> 0 > 97612893) { - f = v(8) | 0; - vq(f, 6723); - c[f >> 2] = 5956; - x(f | 0, 3928, 123); - } - else { - e = eq((b * 44) | 0) | 0; - break; - } - else - e = 0; - while (0); - c[a >> 2] = e; - d = (e + ((d * 44) | 0)) | 0; - c[(a + 8) >> 2] = d; - c[(a + 4) >> 2] = d; - c[f >> 2] = e + ((b * 44) | 0); - return; - } - function Tc(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0; - i = c[a >> 2] | 0; - j = (a + 4) | 0; - d = c[j >> 2] | 0; - h = (b + 4) | 0; - if ((d | 0) == (i | 0)) { - f = h; - g = a; - e = c[h >> 2] | 0; - d = i; - } - else { - e = c[h >> 2] | 0; - do { - d = (d + -44) | 0; - Wc((e + -44) | 0, d); - e = ((c[h >> 2] | 0) + -44) | 0; - c[h >> 2] = e; - } while ((d | 0) != (i | 0)); - f = h; - g = a; - d = c[a >> 2] | 0; - } - c[g >> 2] = e; - c[f >> 2] = d; - i = (b + 8) | 0; - h = c[j >> 2] | 0; - c[j >> 2] = c[i >> 2]; - c[i >> 2] = h; - i = (a + 8) | 0; - j = (b + 12) | 0; - a = c[i >> 2] | 0; - c[i >> 2] = c[j >> 2]; - c[j >> 2] = a; - c[b >> 2] = c[f >> 2]; - return; - } - function Uc(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0; - d = c[(a + 4) >> 2] | 0; - e = (a + 8) | 0; - b = c[e >> 2] | 0; - if ((b | 0) != (d | 0)) - do { - f = (b + -44) | 0; - c[e >> 2] = f; - Ic(f); - b = c[e >> 2] | 0; - } while ((b | 0) != (d | 0)); - b = c[a >> 2] | 0; - if (b | 0) - Da(b, ((c[(a + 12) >> 2] | 0) - b) | 0); - return; - } - function Vc(a) { - a = a | 0; - return 97612893; - } - function Wc(b, d) { - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0, h = 0; - e = c[d >> 2] | 0; - c[b >> 2] = e; - a[(b + 4) >> 0] = a[(d + 4) >> 0] | 0; - c[(b + 20) >> 2] = c[(d + 20) >> 2]; - c[(b + 24) >> 2] = c[(d + 24) >> 2]; - c[(b + 28) >> 2] = c[(d + 28) >> 2]; - c[(b + 32) >> 2] = c[(d + 32) >> 2]; - h = (b + 36) | 0; - c[h >> 2] = c[(d + 36) >> 2]; - c[(b + 40) >> 2] = c[(d + 40) >> 2]; - e = e << 2; - f = _a(e) | 0; - c[(b + 8) >> 2] = f; - g = c[b >> 2] | 0; - if (g | 0) - vr(f | 0, c[(d + 8) >> 2] | 0, (g << 2) | 0) | 0; - e = _a(e) | 0; - c[(b + 12) >> 2] = e; - f = c[b >> 2] | 0; - if (f | 0) - vr(e | 0, c[(d + 12) >> 2] | 0, (f << 2) | 0) | 0; - e = c[h >> 2] | 0; - if (e) { - f = _a(((e << 2) + 8) | 0) | 0; - c[(b + 16) >> 2] = f; - e = ((c[h >> 2] << 2) + 8) | 0; - if (e | 0) - vr(f | 0, c[(d + 16) >> 2] | 0, e | 0) | 0; - } - else - c[(b + 16) >> 2] = 0; - return; - } - function Xc(b) { - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, r = 0; - r = (b + 24) | 0; - g = (b + 20) | 0; - d = ((c[g >> 2] | 0) + (c[r >> 2] | 0)) | 0; - c[g >> 2] = d; - if (d >>> 0 > 32768) { - c[g >> 2] = 0; - if (!(c[b >> 2] | 0)) - d = 0; - else { - f = c[(b + 12) >> 2] | 0; - e = 0; - do { - n = (f + (e << 2)) | 0; - d = (((c[n >> 2] | 0) + 1) | 0) >>> 1; - c[n >> 2] = d; - d = ((c[g >> 2] | 0) + d) | 0; - c[g >> 2] = d; - e = (e + 1) | 0; - } while (e >>> 0 < (c[b >> 2] | 0) >>> 0); - } - } - n = (2147483648 / (d >>> 0)) | 0; - do - if ((a[(b + 4) >> 0] | 0) == 0 ? ((o = (b + 36) | 0), (c[o >> 2] | 0) != 0) : 0) { - if (c[b >> 2] | 0) { - j = c[(b + 8) >> 2] | 0; - k = c[(b + 12) >> 2] | 0; - l = (b + 40) | 0; - m = (b + 16) | 0; - d = 0; - h = 0; - i = 0; - do { - e = (q(h, n) | 0) >>> 16; - c[(j + (i << 2)) >> 2] = e; - h = ((c[(k + (i << 2)) >> 2] | 0) + h) | 0; - e = e >>> (c[l >> 2] | 0); - if (d >>> 0 < e >>> 0) { - f = (i + -1) | 0; - g = c[m >> 2] | 0; - do { - d = (d + 1) | 0; - c[(g + (d << 2)) >> 2] = f; - } while ((d | 0) != (e | 0)); - d = e; - } - i = (i + 1) | 0; - } while (i >>> 0 < (c[b >> 2] | 0) >>> 0); - e = c[m >> 2] | 0; - c[e >> 2] = 0; - if (d >>> 0 > (c[o >> 2] | 0) >>> 0) { - d = b; - break; - } - } - else { - e = c[(b + 16) >> 2] | 0; - c[e >> 2] = 0; - d = 0; - } - do { - d = (d + 1) | 0; - c[(e + (d << 2)) >> 2] = (c[b >> 2] | 0) + -1; - } while (d >>> 0 <= (c[o >> 2] | 0) >>> 0); - d = b; - } - else - p = 7; - while (0); - if ((p | 0) == 7) - if (!(c[b >> 2] | 0)) - d = b; - else { - f = c[(b + 8) >> 2] | 0; - g = c[(b + 12) >> 2] | 0; - d = 0; - e = 0; - do { - c[(f + (d << 2)) >> 2] = (q(e, n) | 0) >>> 16; - e = ((c[(g + (d << 2)) >> 2] | 0) + e) | 0; - d = (d + 1) | 0; - } while (d >>> 0 < (c[b >> 2] | 0) >>> 0); - d = b; - } - p = (((c[r >> 2] | 0) * 5) | 0) >>> 2; - o = ((c[d >> 2] << 3) + 48) | 0; - p = p >>> 0 > o >>> 0 ? o : p; - c[r >> 2] = p; - c[(b + 28) >> 2] = p; - return; - } - function Yc(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0; - d = Zc(b, d) | 0; - c[a >> 2] = d; - do - if (d) { - if (d >>> 0 >= 32) { - d = c[(a + 28) >> 2] | 0; - break; - } - e = c[(a + 12) >> 2] | 0; - if (d >>> 0 > e >>> 0) { - e = (d - e) | 0; - d = Zc(b, ((c[(a + 68) >> 2] | 0) + ((((d + -1) | 0) * 44) | 0)) | 0) | 0; - e = (d << e) | (_c(b, e) | 0); - } - else - e = Zc(b, ((c[(a + 68) >> 2] | 0) + ((((d + -1) | 0) * 44) | 0)) | 0) | 0; - d = c[a >> 2] | 0; - if ((e | 0) < ((1 << (d + -1)) | 0)) { - d = (e + 1 + (-1 << d)) | 0; - break; - } - else { - d = (e + 1) | 0; - break; - } - } - else - d = $c(b, (a + 48) | 0) | 0; - while (0); - return d | 0; - } - function Zc(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0; - n = (a + 8) | 0; - m = c[n >> 2] | 0; - f = c[(b + 16) >> 2] | 0; - if (f) { - e = (a + 4) | 0; - d = c[e >> 2] | 0; - l = m >>> 15; - c[n >> 2] = l; - j = ((d >>> 0) / (l >>> 0)) | 0; - i = j >>> (c[(b + 40) >> 2] | 0); - g = c[(f + (i << 2)) >> 2] | 0; - i = ((c[(f + ((i + 1) << 2)) >> 2] | 0) + 1) | 0; - h = (g + 1) | 0; - k = c[(b + 8) >> 2] | 0; - if (i >>> 0 > h >>> 0) { - f = g; - g = i; - do { - h = ((g + f) | 0) >>> 1; - i = (c[(k + (h << 2)) >> 2] | 0) >>> 0 > j >>> 0; - f = i ? f : h; - g = i ? h : g; - h = (f + 1) | 0; - } while (g >>> 0 > h >>> 0); - g = f; - } - f = q(c[(k + (g << 2)) >> 2] | 0, l) | 0; - if ((g | 0) == (c[(b + 32) >> 2] | 0)) - h = m; - else - h = q(c[(k + (h << 2)) >> 2] | 0, l) | 0; - } - else { - k = m >>> 15; - c[n >> 2] = k; - i = c[b >> 2] | 0; - l = c[(b + 8) >> 2] | 0; - e = (a + 4) | 0; - d = c[e >> 2] | 0; - j = i >>> 1; - f = 0; - h = m; - g = 0; - do { - o = q(c[(l + (j << 2)) >> 2] | 0, k) | 0; - m = o >>> 0 > d >>> 0; - h = m ? o : h; - f = m ? f : o; - g = m ? g : j; - i = m ? j : i; - j = ((g + i) | 0) >>> 1; - } while ((j | 0) != (g | 0)); - } - c[e >> 2] = d - f; - o = (h - f) | 0; - c[n >> 2] = o; - if (o >>> 0 < 16777216) - ad(a); - n = ((c[(b + 12) >> 2] | 0) + (g << 2)) | 0; - c[n >> 2] = (c[n >> 2] | 0) + 1; - n = (b + 28) | 0; - o = ((c[n >> 2] | 0) + -1) | 0; - c[n >> 2] = o; - if (!o) - Xc(b); - return g | 0; - } - function _c(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0; - if (b >>> 0 > 19) { - d = (bd(a) | 0) & 65535; - return ((_c(a, (b + -16) | 0) | 0) << 16) | d | 0; - } - e = (a + 4) | 0; - f = c[e >> 2] | 0; - g = (a + 8) | 0; - d = (c[g >> 2] | 0) >>> b; - c[g >> 2] = d; - b = ((f >>> 0) / (d >>> 0)) | 0; - c[e >> 2] = f - (q(b, d) | 0); - if (d >>> 0 < 16777216) - ad(a); - return b | 0; - } - function $c(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0; - e = (a + 8) | 0; - f = c[e >> 2] | 0; - d = q(f >>> 13, c[(b + 8) >> 2] | 0) | 0; - g = (a + 4) | 0; - h = c[g >> 2] | 0; - i = h >>> 0 >= d >>> 0; - if (i) { - c[g >> 2] = h - d; - d = (f - d) | 0; - c[e >> 2] = d; - } - else { - c[e >> 2] = d; - h = (b + 12) | 0; - c[h >> 2] = (c[h >> 2] | 0) + 1; - } - if (d >>> 0 < 16777216) - ad(a); - h = (b + 4) | 0; - a = ((c[h >> 2] | 0) + -1) | 0; - c[h >> 2] = a; - if (!a) - cd(b); - return (i & 1) | 0; - } - function ad(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0; - b = (a + 4) | 0; - d = (a + 8) | 0; - e = c[b >> 2] | 0; - do { - e = (e << 8) | ((Jc(c[a >> 2] | 0) | 0) & 255); - c[b >> 2] = e; - f = c[d >> 2] << 8; - c[d >> 2] = f; - } while (f >>> 0 < 16777216); - return; - } - function bd(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0; - d = (a + 4) | 0; - f = c[d >> 2] | 0; - b = (a + 8) | 0; - e = (c[b >> 2] | 0) >>> 16; - c[b >> 2] = e; - b = ((f >>> 0) / (e >>> 0)) | 0; - c[d >> 2] = f - (q(b, e) | 0); - ad(a); - return (b & 65535) | 0; - } - function cd(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0; - f = c[a >> 2] | 0; - d = (a + 16) | 0; - b = ((c[d >> 2] | 0) + f) | 0; - c[d >> 2] = b; - if (b >>> 0 > 8192) { - e = ((b + 1) | 0) >>> 1; - c[d >> 2] = e; - g = (a + 12) | 0; - b = (((c[g >> 2] | 0) + 1) | 0) >>> 1; - c[g >> 2] = b; - if ((b | 0) == (e | 0)) { - b = (e + 1) | 0; - c[d >> 2] = b; - d = b; - b = e; - } - else - d = e; - } - else { - d = b; - b = c[(a + 12) >> 2] | 0; - } - c[(a + 8) >> 2] = (q(b, (2147483648 / (d >>> 0)) | 0) | 0) >>> 18; - g = (f * 5) | 0; - g = g >>> 0 > 259 ? 64 : g >>> 2; - c[a >> 2] = g; - c[(a + 4) >> 2] = g; - return; - } - function dd(a, b) { - a = a | 0; - b = b | 0; - var e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0; - m = V; - V = (V + 32) | 0; - h = (m + 16) | 0; - i = (m + 8) | 0; - j = m; - k = (a + 336) | 0; - f = k; - g = (a + 259) | 0; - if (!((c[(f + 4) >> 2] | 0) == 0 - ? (c[f >> 2] | 0) == - (d[g >> 0] | - (d[(g + 1) >> 0] << 8) | - (d[(g + 2) >> 0] << 16) | - (d[(g + 3) >> 0] << 24) | - 0) - : 0)) { - f = (a + 320) | 0; - e = c[f >> 2] | 0; - g = e; - if (!((e | 0) != 0 ? (c[(a + 312) >> 2] | 0) != 0 : 0)) { - e = g; - l = 5; - } - } - else { - f = (a + 320) | 0; - e = c[(a + 320) >> 2] | 0; - l = 5; - } - if ((l | 0) == 5) { - l = (a + 320) | 0; - c[h >> 2] = e; - c[l >> 2] = 0; - e = (a + 324) | 0; - c[(h + 4) >> 2] = c[e >> 2]; - c[e >> 2] = 0; - Na(h); - g = (a + 312) | 0; - c[h >> 2] = c[g >> 2]; - c[g >> 2] = 0; - n = (a + 316) | 0; - c[(h + 4) >> 2] = c[n >> 2]; - c[n >> 2] = 0; - Oa(h); - o = eq(12) | 0; - lc(o, (a + 4) | 0); - c[j >> 2] = 0; - c[h >> 2] = c[j >> 2]; - fd(i, o, h); - o = c[i >> 2] | 0; - c[i >> 2] = c[g >> 2]; - c[g >> 2] = o; - o = (i + 4) | 0; - j = c[o >> 2] | 0; - c[o >> 2] = c[n >> 2]; - c[n >> 2] = j; - Oa(i); - ed(i, c[g >> 2] | 0, (a + 300) | 0); - g = c[i >> 2] | 0; - n = (i + 4) | 0; - j = c[n >> 2] | 0; - c[i >> 2] = 0; - c[n >> 2] = 0; - c[h >> 2] = c[l >> 2]; - c[l >> 2] = g; - c[(h + 4) >> 2] = c[e >> 2]; - c[e >> 2] = j; - Na(h); - Na(i); - e = (a + 328) | 0; - j = e; - j = lr(c[j >> 2] | 0, c[(j + 4) >> 2] | 0, 1, 0) | 0; - l = u() | 0; - c[e >> 2] = j; - c[(e + 4) >> 2] = l; - e = k; - c[e >> 2] = 0; - c[(e + 4) >> 2] = 0; - e = c[f >> 2] | 0; - } - $[c[c[e >> 2] >> 2] & 63](e, b) | 0; - l = k; - l = lr(c[l >> 2] | 0, c[(l + 4) >> 2] | 0, 1, 0) | 0; - n = u() | 0; - o = k; - c[o >> 2] = l; - c[(o + 4) >> 2] = n; - V = m; - return; - } - function ed(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0, h = 0; - h = V; - V = (V + 64) | 0; - e = (h + 56) | 0; - f = h; - g = ld(d) | 0; - if ((g | 0) == -1) { - h = v(8) | 0; - md(h); - x(h | 0, 2784, 8); - } - d = nd(d) | 0; - a: do - if (!d) - switch (g | 0) { - case 0: { - g = eq(4788) | 0; - xd(g); - wd(a, b, g); - break a; - } - case 1: { - g = eq(5116) | 0; - zd(g); - yd(a, b, g); - break a; - } - case 2: { - g = eq(5104) | 0; - Bd(g); - Ad(a, b, g); - break a; - } - case 3: { - g = eq(5432) | 0; - Dd(g); - Cd(a, b, g); - break a; - } - default: { - c[a >> 2] = 0; - c[(a + 4) >> 2] = 0; - break a; - } - } - else { - od(e, b); - pd(c[e >> 2] | 0); - if ((g | 2 | 0) == 3) - qd(c[e >> 2] | 0); - if ((g | 1 | 0) == 3) - rd(c[e >> 2] | 0); - g = c[e >> 2] | 0; - td(f, d); - sd(g, f); - ud(f); - c[a >> 2] = c[e >> 2]; - g = (e + 4) | 0; - c[(a + 4) >> 2] = c[g >> 2]; - c[e >> 2] = 0; - c[g >> 2] = 0; - vd(e); - } - while (0); - V = h; - return; - } - function fd(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 4576; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - gd(a, e); - V = d; - return; - } - function gd(a, b) { - a = a | 0; - b = b | 0; - return; - } - function hd(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function id(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) { - rc(a); - jp(a); - } - return; - } - function jd(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 7983 ? (a + 12) | 0 : 0) | 0; - } - function kd(a) { - a = a | 0; - Da(a, 16); - return; - } - function ld(a) { - a = a | 0; - var b = 0, d = 0; - b = ((c[(a + 4) >> 2] | 0) - (c[a >> 2] | 0)) | 0; - a: do - if (((b | 0) != 0 - ? ((d = ((((b | 0) / 12) | 0) + ((((nd(a) | 0) != 0) << 31) >> 31)) | 0), - (d | 0) != 0) - : 0) - ? ((b = c[a >> 2] | 0), !(Ed(b, Fd() | 0) | 0)) - : 0) { - switch (d | 0) { - case 1: { - a = 0; - break a; - } - case 2: { - if (Gd(((c[a >> 2] | 0) + 12) | 0, Hd() | 0) | 0) { - a = 1; - break a; - } - if (Gd(((c[a >> 2] | 0) + 12) | 0, Id() | 0) | 0) { - a = 2; - break a; - } - break; - } - case 3: { - if (Gd(((c[a >> 2] | 0) + 12) | 0, Hd() | 0) | 0 - ? ((d = ((c[a >> 2] | 0) + 24) | 0), Gd(d, Id() | 0) | 0) - : 0) { - a = 3; - break a; - } - break; - } - default: { - } - } - a = -1; - } - else - a = -1; - while (0); - return a | 0; - } - function md(a) { - a = a | 0; - xq(a, 8131); - c[a >> 2] = 4604; - return; - } - function nd(a) { - a = a | 0; - var b = 0, d = 0; - b = c[(a + 4) >> 2] | 0; - if (((b | 0) != (c[a >> 2] | 0) ? ((d = b), (c[(d + -12) >> 2] | 0) == 0) : 0) - ? (c[(d + -4) >> 2] | 0) == 2 - : 0) - a = c[(d + -8) >> 2] | 0; - else - a = 0; - return a | 0; - } - function od(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0; - d = V; - V = (V + 16) | 0; - e = (d + 4) | 0; - g = d; - f = eq(24) | 0; - Kd(f, b); - c[g >> 2] = 0; - c[e >> 2] = c[g >> 2]; - Ld(a, f, e); - V = d; - return; - } - function pd(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0; - j = V; - V = (V + 32) | 0; - e = (j + 12) | 0; - f = j; - b = (j + 8) | 0; - h = eq(4792) | 0; - Zd(h, c[(a + 4) >> 2] | 0); - g = (a + 8) | 0; - c[b >> 2] = 0; - c[e >> 2] = c[b >> 2]; - _d(f, h, e); - h = (a + 12) | 0; - b = c[h >> 2] | 0; - i = (a + 16) | 0; - do - if (b >>> 0 >= (c[i >> 2] | 0) >>> 0) { - b = (((b - (c[g >> 2] | 0)) >> 3) + 1) | 0; - d = ee(g) | 0; - if (d >>> 0 < b >>> 0) - cr(g); - else { - k = c[g >> 2] | 0; - l = ((c[i >> 2] | 0) - k) | 0; - i = l >> 2; - be(e, (l >> 3) >>> 0 < (d >>> 1) >>> 0 ? (i >>> 0 < b >>> 0 ? b : i) : d, ((c[h >> 2] | 0) - k) >> 3, (a + 16) | 0); - i = (e + 8) | 0; - h = c[i >> 2] | 0; - c[h >> 2] = c[f >> 2]; - a = (f + 4) | 0; - c[(h + 4) >> 2] = c[a >> 2]; - c[f >> 2] = 0; - c[a >> 2] = 0; - c[i >> 2] = h + 8; - ce(g, e); - de(e); - break; - } - } - else { - $d(e, g, 1); - l = (e + 4) | 0; - k = c[l >> 2] | 0; - c[k >> 2] = c[f >> 2]; - i = (f + 4) | 0; - c[(k + 4) >> 2] = c[i >> 2]; - c[f >> 2] = 0; - c[i >> 2] = 0; - c[l >> 2] = k + 8; - ae(e); - } - while (0); - Sd(f); - V = j; - return; - } - function qd(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0; - j = V; - V = (V + 32) | 0; - e = (j + 12) | 0; - f = j; - b = (j + 8) | 0; - h = eq(336) | 0; - af(h, c[(a + 4) >> 2] | 0); - g = (a + 8) | 0; - c[b >> 2] = 0; - c[e >> 2] = c[b >> 2]; - bf(f, h, e); - h = (a + 12) | 0; - b = c[h >> 2] | 0; - i = (a + 16) | 0; - do - if (b >>> 0 >= (c[i >> 2] | 0) >>> 0) { - b = (((b - (c[g >> 2] | 0)) >> 3) + 1) | 0; - d = ee(g) | 0; - if (d >>> 0 < b >>> 0) - cr(g); - else { - k = c[g >> 2] | 0; - l = ((c[i >> 2] | 0) - k) | 0; - i = l >> 2; - be(e, (l >> 3) >>> 0 < (d >>> 1) >>> 0 ? (i >>> 0 < b >>> 0 ? b : i) : d, ((c[h >> 2] | 0) - k) >> 3, (a + 16) | 0); - i = (e + 8) | 0; - h = c[i >> 2] | 0; - c[h >> 2] = c[f >> 2]; - a = (f + 4) | 0; - c[(h + 4) >> 2] = c[a >> 2]; - c[f >> 2] = 0; - c[a >> 2] = 0; - c[i >> 2] = h + 8; - ce(g, e); - de(e); - break; - } - } - else { - $d(e, g, 1); - l = (e + 4) | 0; - k = c[l >> 2] | 0; - c[k >> 2] = c[f >> 2]; - i = (f + 4) | 0; - c[(k + 4) >> 2] = c[i >> 2]; - c[f >> 2] = 0; - c[i >> 2] = 0; - c[l >> 2] = k + 8; - ae(e); - } - while (0); - Sd(f); - V = j; - return; - } - function rd(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0; - j = V; - V = (V + 32) | 0; - e = (j + 12) | 0; - f = j; - b = (j + 8) | 0; - h = eq(324) | 0; - Af(h, c[(a + 4) >> 2] | 0); - g = (a + 8) | 0; - c[b >> 2] = 0; - c[e >> 2] = c[b >> 2]; - Bf(f, h, e); - h = (a + 12) | 0; - b = c[h >> 2] | 0; - i = (a + 16) | 0; - do - if (b >>> 0 >= (c[i >> 2] | 0) >>> 0) { - b = (((b - (c[g >> 2] | 0)) >> 3) + 1) | 0; - d = ee(g) | 0; - if (d >>> 0 < b >>> 0) - cr(g); - else { - k = c[g >> 2] | 0; - l = ((c[i >> 2] | 0) - k) | 0; - i = l >> 2; - be(e, (l >> 3) >>> 0 < (d >>> 1) >>> 0 ? (i >>> 0 < b >>> 0 ? b : i) : d, ((c[h >> 2] | 0) - k) >> 3, (a + 16) | 0); - i = (e + 8) | 0; - h = c[i >> 2] | 0; - c[h >> 2] = c[f >> 2]; - a = (f + 4) | 0; - c[(h + 4) >> 2] = c[a >> 2]; - c[f >> 2] = 0; - c[a >> 2] = 0; - c[i >> 2] = h + 8; - ce(g, e); - de(e); - break; - } - } - else { - $d(e, g, 1); - l = (e + 4) | 0; - k = c[l >> 2] | 0; - c[k >> 2] = c[f >> 2]; - i = (f + 4) | 0; - c[(k + 4) >> 2] = c[i >> 2]; - c[f >> 2] = 0; - c[i >> 2] = 0; - c[l >> 2] = k + 8; - ae(e); - } - while (0); - Sd(f); - V = j; - return; - } - function sd(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0; - j = V; - V = (V + 32) | 0; - h = (j + 12) | 0; - i = j; - e = (j + 8) | 0; - g = eq(64) | 0; - Qf(g, c[(a + 4) >> 2] | 0, b); - f = (a + 8) | 0; - c[e >> 2] = 0; - c[h >> 2] = c[e >> 2]; - Rf(i, g, h); - g = (a + 12) | 0; - b = c[g >> 2] | 0; - e = (a + 16) | 0; - do - if (b >>> 0 >= (c[e >> 2] | 0) >>> 0) { - b = (((b - (c[f >> 2] | 0)) >> 3) + 1) | 0; - d = ee(f) | 0; - if (d >>> 0 < b >>> 0) - cr(f); - else { - k = c[f >> 2] | 0; - l = ((c[e >> 2] | 0) - k) | 0; - e = l >> 2; - be(h, (l >> 3) >>> 0 < (d >>> 1) >>> 0 ? (e >>> 0 < b >>> 0 ? b : e) : d, ((c[g >> 2] | 0) - k) >> 3, (a + 16) | 0); - a = (h + 8) | 0; - g = c[a >> 2] | 0; - c[g >> 2] = c[i >> 2]; - e = (i + 4) | 0; - c[(g + 4) >> 2] = c[e >> 2]; - c[i >> 2] = 0; - c[e >> 2] = 0; - c[a >> 2] = g + 8; - ce(f, h); - de(h); - break; - } - } - else { - $d(h, f, 1); - l = (h + 4) | 0; - k = c[l >> 2] | 0; - c[k >> 2] = c[i >> 2]; - a = (i + 4) | 0; - c[(k + 4) >> 2] = c[a >> 2]; - c[i >> 2] = 0; - c[a >> 2] = 0; - c[l >> 2] = k + 8; - ae(h); - } - while (0); - Sd(i); - V = j; - return; - } - function td(b, d) { - b = b | 0; - d = d | 0; - var e = 0, f = 0; - e = V; - V = (V + 48) | 0; - f = e; - c[b >> 2] = d; - a[(b + 4) >> 0] = 0; - Jg((b + 8) | 0, d); - Jg((b + 20) | 0, d); - Oc(f, 256, 0, 0); - Kg((b + 32) | 0, d, f); - Ic(f); - V = e; - return; - } - function ud(a) { - a = a | 0; - Ng((a + 32) | 0); - _f((a + 20) | 0); - _f((a + 8) | 0); - return; - } - function vd(a) { - a = a | 0; - var b = 0, d = 0; - a = c[(a + 4) >> 2] | 0; - if (a | 0 ? ((d = (a + 4) | 0), (b = c[d >> 2] | 0), (c[d >> 2] = b + -1), (b | 0) == 0) : 0) { - ca[c[((c[a >> 2] | 0) + 8) >> 2] & 255](a); - qq(a); - } - return; - } - function wd(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0, h = 0; - e = V; - V = (V + 16) | 0; - f = (e + 4) | 0; - h = e; - g = eq(12) | 0; - Og(g, b, d); - c[h >> 2] = 0; - c[f >> 2] = c[h >> 2]; - Pg(a, g, f); - V = e; - return; - } - function xd(a) { - a = a | 0; - ge(a); - $g((a + 4784) | 0); - return; - } - function yd(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0, h = 0; - e = V; - V = (V + 16) | 0; - f = (e + 4) | 0; - h = e; - g = eq(12) | 0; - ah(g, b, d); - c[h >> 2] = 0; - c[f >> 2] = c[h >> 2]; - bh(a, g, f); - V = e; - return; - } - function zd(a) { - a = a | 0; - ge(a); - nh((a + 4784) | 0); - return; - } - function Ad(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0, h = 0; - e = V; - V = (V + 16) | 0; - f = (e + 4) | 0; - h = e; - g = eq(12) | 0; - oh(g, b, d); - c[h >> 2] = 0; - c[f >> 2] = c[h >> 2]; - ph(a, g, f); - V = e; - return; - } - function Bd(a) { - a = a | 0; - ge(a); - Bh((a + 4784) | 0); - return; - } - function Cd(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0, h = 0; - e = V; - V = (V + 16) | 0; - f = (e + 4) | 0; - h = e; - g = eq(12) | 0; - Ch(g, b, d); - c[h >> 2] = 0; - c[f >> 2] = c[h >> 2]; - Dh(a, g, f); - V = e; - return; - } - function Dd(a) { - a = a | 0; - ge(a); - Ph((a + 4784) | 0); - return; - } - function Ed(a, b) { - a = a | 0; - b = b | 0; - return ((Gd(a, b) | 0) ^ 1) | 0; - } - function Fd() { - if ((a[21456] | 0) == 0 ? Tp(21456) | 0 : 0) { - _b(21536, 6, 20, 2); - $p(21456); - } - return 21536; - } - function Gd(a, b) { - a = a | 0; - b = b | 0; - if ((c[a >> 2] | 0) == (c[b >> 2] | 0) ? (c[(a + 8) >> 2] | 0) == (c[(b + 8) >> 2] | 0) : 0) - a = (c[(a + 4) >> 2] | 0) == (c[(b + 4) >> 2] | 0); - else - a = 0; - return a | 0; - } - function Hd() { - if ((a[21464] | 0) == 0 ? Tp(21464) | 0 : 0) { - _b(21548, 7, 8, 2); - $p(21464); - } - return 21548; - } - function Id() { - if ((a[21472] | 0) == 0 ? Tp(21472) | 0 : 0) { - _b(21560, 8, 6, 2); - $p(21472); - } - return 21560; - } - function Jd(a) { - a = a | 0; - yp(a); - jp(a); - return; - } - function Kd(b, d) { - b = b | 0; - d = d | 0; - Md(b); - c[b >> 2] = 4624; - c[(b + 4) >> 2] = d; - c[(b + 8) >> 2] = 0; - c[(b + 12) >> 2] = 0; - c[(b + 16) >> 2] = 0; - a[(b + 20) >> 0] = 1; - return; - } - function Ld(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 4664; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Ud(a, e); - V = d; - return; - } - function Md(a) { - a = a | 0; - c[a >> 2] = 4644; - return; - } - function Nd(b, d) { - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0; - k = V; - V = (V + 16) | 0; - h = k; - e = c[(b + 8) >> 2] | 0; - i = c[(b + 12) >> 2] | 0; - if ((e | 0) != (i | 0)) { - j = (h + 4) | 0; - do { - f = c[e >> 2] | 0; - c[h >> 2] = f; - g = c[(e + 4) >> 2] | 0; - c[j >> 2] = g; - if (g | 0) { - g = (g + 4) | 0; - c[g >> 2] = (c[g >> 2] | 0) + 1; - } - d = $[c[((c[f >> 2] | 0) + 12) >> 2] & 63](f, d) | 0; - Sd(h); - e = (e + 8) | 0; - } while ((e | 0) != (i | 0)); - } - e = (b + 20) | 0; - if (a[e >> 0] | 0) { - a[e >> 0] = 0; - nc(c[(b + 4) >> 2] | 0); - } - V = k; - return d | 0; - } - function Od(a) { - a = a | 0; - c[a >> 2] = 4624; - Td((a + 8) | 0); - Qd(a); - return; - } - function Pd(a) { - a = a | 0; - Od(a); - jp(a); - return; - } - function Qd(a) { - a = a | 0; - return; - } - function Rd(a) { - a = a | 0; - U(); - } - function Sd(a) { - a = a | 0; - var b = 0, d = 0; - a = c[(a + 4) >> 2] | 0; - if (a | 0 ? ((d = (a + 4) | 0), (b = c[d >> 2] | 0), (c[d >> 2] = b + -1), (b | 0) == 0) : 0) { - ca[c[((c[a >> 2] | 0) + 8) >> 2] & 255](a); - qq(a); - } - return; - } - function Td(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - d = c[a >> 2] | 0; - if (d | 0) { - e = (a + 4) | 0; - b = c[e >> 2] | 0; - if ((b | 0) == (d | 0)) - b = d; - else { - do { - b = (b + -8) | 0; - Sd(b); - } while ((b | 0) != (d | 0)); - b = c[a >> 2] | 0; - } - c[e >> 2] = d; - Da(b, ((c[(a + 8) >> 2] | 0) - b) | 0); - } - return; - } - function Ud(a, b) { - a = a | 0; - b = b | 0; - return; - } - function Vd(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function Wd(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 8) >> 2] & 255](a); - return; - } - function Xd(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 8546 ? (a + 12) | 0 : 0) | 0; - } - function Yd(a) { - a = a | 0; - Da(a, 16); - return; - } - function Zd(a, b) { - a = a | 0; - b = b | 0; - fe(a); - c[a >> 2] = 4692; - c[(a + 4) >> 2] = b; - ge((a + 8) | 0); - return; - } - function _d(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 4740; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Xe(a, e); - V = d; - return; - } - function $d(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - c[a >> 2] = b; - b = c[(b + 4) >> 2] | 0; - c[(a + 4) >> 2] = b; - c[(a + 8) >> 2] = b + (d << 3); - return; - } - function ae(a) { - a = a | 0; - c[((c[a >> 2] | 0) + 4) >> 2] = c[(a + 4) >> 2]; - return; - } - function be(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0; - f = (a + 12) | 0; - c[f >> 2] = 0; - c[(a + 16) >> 2] = e; - do - if (b) - if (b >>> 0 > 536870911) { - f = v(8) | 0; - vq(f, 6723); - c[f >> 2] = 5956; - x(f | 0, 3928, 123); - } - else { - e = eq(b << 3) | 0; - break; - } - else - e = 0; - while (0); - c[a >> 2] = e; - d = (e + (d << 3)) | 0; - c[(a + 8) >> 2] = d; - c[(a + 4) >> 2] = d; - c[f >> 2] = e + (b << 3); - return; - } - function ce(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0; - i = c[a >> 2] | 0; - j = (a + 4) | 0; - d = c[j >> 2] | 0; - h = (b + 4) | 0; - if ((d | 0) == (i | 0)) { - f = h; - g = a; - e = c[h >> 2] | 0; - d = i; - } - else { - e = c[h >> 2] | 0; - do { - g = d; - d = (d + -8) | 0; - c[(e + -8) >> 2] = c[d >> 2]; - g = (g + -4) | 0; - c[(e + -4) >> 2] = c[g >> 2]; - c[d >> 2] = 0; - c[g >> 2] = 0; - e = ((c[h >> 2] | 0) + -8) | 0; - c[h >> 2] = e; - } while ((d | 0) != (i | 0)); - f = h; - g = a; - d = c[a >> 2] | 0; - } - c[g >> 2] = e; - c[f >> 2] = d; - i = (b + 8) | 0; - h = c[j >> 2] | 0; - c[j >> 2] = c[i >> 2]; - c[i >> 2] = h; - i = (a + 8) | 0; - j = (b + 12) | 0; - a = c[i >> 2] | 0; - c[i >> 2] = c[j >> 2]; - c[j >> 2] = a; - c[b >> 2] = c[f >> 2]; - return; - } - function de(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0; - d = c[(a + 4) >> 2] | 0; - e = (a + 8) | 0; - b = c[e >> 2] | 0; - if ((b | 0) != (d | 0)) - do { - f = (b + -8) | 0; - c[e >> 2] = f; - Sd(f); - b = c[e >> 2] | 0; - } while ((b | 0) != (d | 0)); - b = c[a >> 2] | 0; - if (b | 0) - Da(b, ((c[(a + 12) >> 2] | 0) - b) | 0); - return; - } - function ee(a) { - a = a | 0; - return 536870911; - } - function fe(a) { - a = a | 0; - c[a >> 2] = 4716; - return; - } - function ge(b) { - b = b | 0; - oe(b); - pe((b + 3980) | 0); - qe((b + 4380) | 0); - a[(b + 4780) >> 0] = 0; - a[(b + 4781) >> 0] = 0; - return; - } - function he(a) { - a = a | 0; - c[a >> 2] = 4692; - ze((a + 8) | 0); - le(a); - return; - } - function ie(a) { - a = a | 0; - he(a); - jp(a); - return; - } - function je(a, b) { - a = a | 0; - b = b | 0; - return b | 0; - } - function ke(a, b) { - a = a | 0; - b = b | 0; - return Be((a + 8) | 0, c[(a + 4) >> 2] | 0, b) | 0; - } - function le(a) { - a = a | 0; - return; - } - function me(a) { - a = a | 0; - le(a); - jp(a); - return; - } - function ne(a, b) { - a = a | 0; - b = b | 0; - return b | 0; - } - function oe(d) { - d = d | 0; - var e = 0, f = 0; - te(d); - ue((d + 52) | 0); - ue((d + 436) | 0); - Oc((d + 852) | 0, 64, 0, 0); - a[(d + 3976) >> 0] = 0; - e = (d + 20) | 0; - f = (e + 32) | 0; - do { - b[e >> 1] = 0; - e = (e + 2) | 0; - } while ((e | 0) < (f | 0)); - e = eq(44) | 0; - Oc(e, 256, 0, 0); - c[(d + 896) >> 2] = e; - e = eq(44) | 0; - Oc(e, 256, 0, 0); - c[(d + 900) >> 2] = e; - e = (d + 820) | 0; - c[e >> 2] = 0; - c[(e + 4) >> 2] = 0; - c[(e + 8) >> 2] = 0; - c[(e + 12) >> 2] = 0; - c[(e + 16) >> 2] = 0; - c[(e + 20) >> 2] = 0; - c[(e + 24) >> 2] = 0; - c[(e + 28) >> 2] = 0; - e = 0; - do { - f = eq(44) | 0; - Oc(f, 256, 0, 0); - c[(d + 904 + (e << 2)) >> 2] = f; - f = eq(44) | 0; - Oc(f, 256, 0, 0); - c[(d + 1928 + (e << 2)) >> 2] = f; - f = eq(44) | 0; - Oc(f, 256, 0, 0); - c[(d + 2952 + (e << 2)) >> 2] = f; - e = (e + 1) | 0; - } while (e >>> 0 < 256); - return; - } - function pe(a) { - a = a | 0; - xe(a, 16, 4, 8, 0); - xe((a + 80) | 0, 16, 1, 8, 0); - xe((a + 160) | 0, 32, 2, 8, 0); - xe((a + 240) | 0, 32, 22, 8, 0); - xe((a + 320) | 0, 32, 20, 8, 0); - return; - } - function qe(a) { - a = a | 0; - mc(a, 16, 4, 8, 0); - mc((a + 80) | 0, 16, 1, 8, 0); - mc((a + 160) | 0, 32, 2, 8, 0); - mc((a + 240) | 0, 32, 22, 8, 0); - mc((a + 320) | 0, 32, 20, 8, 0); - return; - } - function re(a) { - a = a | 0; - ye((a + 320) | 0); - ye((a + 240) | 0); - ye((a + 160) | 0); - ye((a + 80) | 0); - ye(a); - return; - } - function se(a) { - a = a | 0; - var b = 0, d = 0; - b = c[(a + 896) >> 2] | 0; - if (b | 0) { - Ic(b); - jp(b); - } - b = c[(a + 900) >> 2] | 0; - if (b | 0) { - Ic(b); - jp(b); - } - d = 0; - do { - b = c[(a + 904 + (d << 2)) >> 2] | 0; - if (b | 0) { - Ic(b); - jp(b); - } - b = c[(a + 1928 + (d << 2)) >> 2] | 0; - if (b | 0) { - Ic(b); - jp(b); - } - b = c[(a + 2952 + (d << 2)) >> 2] | 0; - if (b | 0) { - Ic(b); - jp(b); - } - d = (d + 1) | 0; - } while ((d | 0) != 256); - Ic((a + 852) | 0); - return; - } - function te(b) { - b = b | 0; - var c = 0; - a[b >> 0] = 0; - a[(b + 1) >> 0] = 0; - a[(b + 2) >> 0] = 0; - a[(b + 3) >> 0] = 0; - c = (b + 4) | 0; - a[c >> 0] = 0; - a[(c + 1) >> 0] = 0; - a[(c + 2) >> 0] = 0; - a[(c + 3) >> 0] = 0; - b = (b + 12) | 0; - c = b; - a[c >> 0] = 0; - a[(c + 1) >> 0] = 0; - a[(c + 2) >> 0] = 0; - a[(c + 3) >> 0] = 0; - b = (b + 4) | 0; - a[b >> 0] = 0; - a[(b + 1) >> 0] = 0; - a[(b + 2) >> 0] = 0; - a[(b + 3) >> 0] = 0; - return; - } - function ue(a) { - a = a | 0; - var b = 0; - b = (a + 384) | 0; - do { - ve(a); - a = (a + 24) | 0; - } while ((a | 0) != (b | 0)); - return; - } - function ve(a) { - a = a | 0; - we(a); - return; - } - function we(b) { - b = b | 0; - c[b >> 2] = 0; - c[(b + 4) >> 2] = 0; - c[(b + 8) >> 2] = 0; - c[(b + 12) >> 2] = 0; - c[(b + 16) >> 2] = 0; - a[(b + 20) >> 0] = 1; - return; - } - function xe(a, b, d, e, f) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - var g = 0; - c[(a + 4) >> 2] = b; - c[(a + 8) >> 2] = d; - c[(a + 12) >> 2] = e; - c[(a + 16) >> 2] = f; - c[(a + 36) >> 2] = 0; - c[(a + 40) >> 2] = 0; - c[(a + 44) >> 2] = 0; - Gc((a + 48) | 0); - c[(a + 68) >> 2] = 0; - c[(a + 72) >> 2] = 0; - c[(a + 76) >> 2] = 0; - do - if (!f) { - d = (a + 20) | 0; - if (((b + -1) | 0) >>> 0 < 31) { - c[d >> 2] = b; - f = 1 << b; - c[(a + 24) >> 2] = f; - d = f >>> 1; - c[(a + 28) >> 2] = 0 - d; - d = (f + -1 - d) | 0; - break; - } - else { - c[d >> 2] = 32; - c[(a + 24) >> 2] = 0; - c[(a + 28) >> 2] = -2147483648; - d = 2147483647; - break; - } - } - else { - e = (a + 20) | 0; - c[e >> 2] = 0; - c[(a + 24) >> 2] = f; - d = f; - g = 0; - while (1) { - d = d >>> 1; - b = (g + 1) | 0; - if (!d) - break; - else - g = b; - } - c[e >> 2] = ((1 << g) | 0) == (f | 0) ? g : b; - d = f >>> 1; - c[(a + 28) >> 2] = 0 - d; - d = (f + -1 - d) | 0; - } - while (0); - c[(a + 32) >> 2] = d; - c[a >> 2] = 0; - return; - } - function ye(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0; - g = (a + 36) | 0; - d = c[g >> 2] | 0; - e = (a + 40) | 0; - b = c[e >> 2] | 0; - if ((b | 0) != (d | 0)) - do { - b = (b + -44) | 0; - Ic(b); - } while ((b | 0) != (d | 0)); - c[e >> 2] = d; - e = (a + 68) | 0; - f = c[e >> 2] | 0; - d = (a + 72) | 0; - b = c[d >> 2] | 0; - if ((b | 0) != (f | 0)) - do { - b = (b + -44) | 0; - Ic(b); - } while ((b | 0) != (f | 0)); - c[d >> 2] = f; - Hc(e); - Hc(g); - return; - } - function ze(a) { - a = a | 0; - Ae((a + 4380) | 0); - re((a + 3980) | 0); - se(a); - return; - } - function Ae(a) { - a = a | 0; - qc((a + 320) | 0); - qc((a + 240) | 0); - qc((a + 160) | 0); - qc((a + 80) | 0); - qc(a); - return; - } - function Be(f, g, h) { - f = f | 0; - g = g | 0; - h = h | 0; - var i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, q = 0; - p = V; - V = (V + 32) | 0; - o = p; - i = (f + 4781) | 0; - if (!(a[i >> 0] | 0)) { - Ce((f + 4380) | 0); - a[i >> 0] = 1; - } - i = (f + 3976) | 0; - if (!(a[i >> 0] | 0)) { - a[i >> 0] = 1; - Ee(De(g) | 0, h, 20); - Fe(o, h); - k = f; - i = o; - j = (k + 20) | 0; - do { - a[k >> 0] = a[i >> 0] | 0; - k = (k + 1) | 0; - i = (i + 1) | 0; - } while ((k | 0) < (j | 0)); - b[(f + 12) >> 1] = 0; - } - else { - m = Zc(g, (f + 852) | 0) | 0; - if (m) { - if ((m & 32) | 0) - He((Zc(g, c[(f + 904 + (((Ge(f) | 0) & 255) << 2)) >> 2] | 0) | 0) & 255, f); - n = (f + 14) | 0; - k = a[n >> 0] | 0; - i = k & 7; - k = ((k & 255) >>> 3) & 7; - j = d[(16 + (k << 3) + i) >> 0] | 0; - i = d[(80 + (k << 3) + i) >> 0] | 0; - if (!(m & 16)) - l = b[(f + 20 + (j << 1)) >> 1] | 0; - else { - q = (f + 20 + (j << 1)) | 0; - l = (pc((f + 4380) | 0, g, e[q >> 1] | 0, j >>> 0 < 3 ? j : 3) | 0) & 65535; - b[q >> 1] = l; - } - b[(f + 12) >> 1] = l; - if ((m & 8) | 0) { - q = (f + 15) | 0; - a[q >> 0] = Zc(g, c[(f + 1928 + (d[q >> 0] << 2)) >> 2] | 0) | 0; - } - if ((m & 4) | 0) { - n = Zc(g, c[(f + 896 + ((((d[n >> 0] | 0) >>> 6) & 1) << 2)) >> 2] | 0) | 0; - q = (f + 16) | 0; - a[q >> 0] = Ie((n + (a[q >> 0] | 0)) | 0) | 0; - } - if ((m & 2) | 0) { - q = (f + 17) | 0; - a[q >> 0] = Zc(g, c[(f + 2952 + (d[q >> 0] << 2)) >> 2] | 0) | 0; - } - if (m & 1) { - q = (f + 18) | 0; - b[q >> 1] = pc((f + 4460) | 0, g, e[q >> 1] | 0, 0) | 0; - } - } - else { - q = a[(f + 14) >> 0] | 0; - i = q & 7; - q = ((q & 255) >>> 3) & 7; - k = q; - j = d[(16 + (q << 3) + i) >> 0] | 0; - i = d[(80 + (q << 3) + i) >> 0] | 0; - } - l = (f + 52 + ((j * 24) | 0)) | 0; - m = (f + 4540) | 0; - n = ((k | 0) == 1) & 1; - k = pc(m, g, Je(l) | 0, n) | 0; - c[o >> 2] = k; - c[f >> 2] = (c[f >> 2] | 0) + k; - Ke(l, o); - l = (f + 436 + ((j * 24) | 0)) | 0; - k = Je(l) | 0; - j = Le(m) | 0; - q = (f + 4620) | 0; - j = pc(q, g, k, (j >>> 0 < 20 ? j & -2 : 20) | n) | 0; - c[o >> 2] = j; - k = (f + 4) | 0; - c[k >> 2] = (c[k >> 2] | 0) + j; - Ke(l, o); - o = Le(m) | 0; - o = ((Le(q) | 0) + o) | 0; - q = (f + 820 + (i << 2)) | 0; - o = - pc((f + 4700) | 0, g, c[q >> 2] | 0, (o >>> 0 < 36 ? (o >>> 1) & 2147483646 : 18) | n) | - 0; - c[(f + 8) >> 2] = o; - c[q >> 2] = o; - Me(f, h); - } - V = p; - return (h + 20) | 0; - } - function Ce(a) { - a = a | 0; - oc(a); - oc((a + 80) | 0); - oc((a + 160) | 0); - oc((a + 240) | 0); - oc((a + 320) | 0); - return; - } - function De(a) { - a = a | 0; - return c[a >> 2] | 0; - } - function Ee(b, d, e) { - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0, h = 0, i = 0, j = 0, k = 0; - k = (b + 4) | 0; - f = c[k >> 2] | 0; - j = ((c[(b + 8) >> 2] | 0) - f) | 0; - j = j >>> 0 > e >>> 0 ? e : j; - i = (b + 12) | 0; - g = ((c[i >> 2] | 0) + f) | 0; - h = (g + j) | 0; - if (j) { - f = g; - g = d; - while (1) { - a[g >> 0] = a[f >> 0] | 0; - f = (f + 1) | 0; - if ((f | 0) == (h | 0)) - break; - else - g = (g + 1) | 0; - } - f = c[k >> 2] | 0; - } - c[k >> 2] = f + j; - e = (e - j) | 0; - if (e | 0) { - Kc(b); - g = ((c[i >> 2] | 0) + (c[k >> 2] | 0)) | 0; - h = (g + e) | 0; - f = (d + j) | 0; - while (1) { - a[f >> 0] = a[g >> 0] | 0; - g = (g + 1) | 0; - if ((g | 0) == (h | 0)) - break; - else - f = (f + 1) | 0; - } - c[k >> 2] = (c[k >> 2] | 0) + e; - } - return; - } - function Fe(d, e) { - d = d | 0; - e = e | 0; - te(d); - c[d >> 2] = Ne(e) | 0; - c[(d + 4) >> 2] = Ne((e + 4) | 0) | 0; - c[(d + 8) >> 2] = Ne((e + 8) | 0) | 0; - b[(d + 12) >> 1] = Oe((e + 12) | 0) | 0; - He(Pe((e + 14) | 0) | 0, d); - a[(d + 15) >> 0] = Pe((e + 15) | 0) | 0; - a[(d + 16) >> 0] = Qe((e + 16) | 0) | 0; - a[(d + 17) >> 0] = Qe((e + 17) | 0) | 0; - b[(d + 18) >> 1] = Oe((e + 18) | 0) | 0; - return; - } - function Ge(b) { - b = b | 0; - return a[(b + 14) >> 0] | 0; - } - function He(b, c) { - b = b | 0; - c = c | 0; - a[(c + 14) >> 0] = b; - return; - } - function Ie(a) { - a = a | 0; - return (a & 255) | 0; - } - function Je(a) { - a = a | 0; - return c[(a + 8) >> 2] | 0; - } - function Ke(b, d) { - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0; - k = (b + 20) | 0; - do - if (!(a[k >> 0] | 0)) { - j = (b + 8) | 0; - e = c[j >> 2] | 0; - f = c[d >> 2] | 0; - g = (b + 4) | 0; - h = c[g >> 2] | 0; - if ((e | 0) >= (f | 0)) { - if ((h | 0) < (f | 0)) { - c[b >> 2] = h; - c[g >> 2] = c[d >> 2]; - } - else - c[b >> 2] = f; - a[k >> 0] = 1; - break; - } - c[b >> 2] = h; - c[g >> 2] = e; - g = (b + 16) | 0; - h = c[g >> 2] | 0; - i = c[d >> 2] | 0; - e = (b + 12) | 0; - f = c[e >> 2] | 0; - if ((h | 0) < (i | 0)) { - c[j >> 2] = f; - c[e >> 2] = h; - c[g >> 2] = c[d >> 2]; - break; - } - if ((f | 0) < (i | 0)) { - c[j >> 2] = f; - c[e >> 2] = c[d >> 2]; - break; - } - else { - c[j >> 2] = i; - break; - } - } - else { - g = c[d >> 2] | 0; - i = (b + 8) | 0; - e = c[i >> 2] | 0; - h = (b + 12) | 0; - f = c[h >> 2] | 0; - if ((g | 0) >= (e | 0)) { - e = (b + 16) | 0; - if ((g | 0) < (f | 0)) { - c[e >> 2] = f; - c[h >> 2] = c[d >> 2]; - } - else - c[e >> 2] = g; - a[k >> 0] = 0; - break; - } - c[(b + 16) >> 2] = f; - c[h >> 2] = e; - e = c[d >> 2] | 0; - f = c[b >> 2] | 0; - g = (b + 4) | 0; - h = c[g >> 2] | 0; - if ((e | 0) < (f | 0)) { - c[i >> 2] = h; - c[g >> 2] = f; - c[b >> 2] = c[d >> 2]; - break; - } - if ((e | 0) < (h | 0)) { - c[i >> 2] = h; - c[g >> 2] = c[d >> 2]; - break; - } - else { - c[i >> 2] = e; - break; - } - } - while (0); - return; - } - function Le(a) { - a = a | 0; - return c[a >> 2] | 0; - } - function Me(b, c) { - b = b | 0; - c = c | 0; - var e = 0; - Se(d[b >> 0] | (d[(b + 1) >> 0] << 8) | (d[(b + 2) >> 0] << 16) | (d[(b + 3) >> 0] << 24), c); - e = (b + 4) | 0; - Se(d[e >> 0] | (d[(e + 1) >> 0] << 8) | (d[(e + 2) >> 0] << 16) | (d[(e + 3) >> 0] << 24), (c + 4) | 0); - e = (b + 8) | 0; - Se(d[e >> 0] | (d[(e + 1) >> 0] << 8) | (d[(e + 2) >> 0] << 16) | (d[(e + 3) >> 0] << 24), (c + 8) | 0); - e = (b + 12) | 0; - Te(d[e >> 0] | (d[(e + 1) >> 0] << 8), (c + 12) | 0); - Ue(Ge(b) | 0, (c + 14) | 0); - Ue(a[(b + 15) >> 0] | 0, (c + 15) | 0); - Ve(a[(b + 16) >> 0] | 0, (c + 16) | 0); - Ve(a[(b + 17) >> 0] | 0, (c + 17) | 0); - b = (b + 18) | 0; - Te(d[b >> 0] | (d[(b + 1) >> 0] << 8), (c + 18) | 0); - return; - } - function Ne(a) { - a = a | 0; - return Re(a) | 0; - } - function Oe(b) { - b = b | 0; - return (((a[(b + 1) >> 0] << 8) | d[b >> 0]) & 65535) | 0; - } - function Pe(b) { - b = b | 0; - return a[b >> 0] | 0; - } - function Qe(b) { - b = b | 0; - return a[b >> 0] | 0; - } - function Re(a) { - a = a | 0; - return (((d[(a + 1) >> 0] | 0) << 8) | - (d[a >> 0] | 0) | - ((d[(a + 2) >> 0] | 0) << 16) | - ((d[(a + 3) >> 0] | 0) << 24) | - 0); - } - function Se(a, b) { - a = a | 0; - b = b | 0; - We(a, b); - return; - } - function Te(b, c) { - b = b | 0; - c = c | 0; - a[(c + 1) >> 0] = (b & 65535) >>> 8; - a[c >> 0] = b; - return; - } - function Ue(b, c) { - b = b | 0; - c = c | 0; - a[c >> 0] = b; - return; - } - function Ve(b, c) { - b = b | 0; - c = c | 0; - a[c >> 0] = b; - return; - } - function We(b, c) { - b = b | 0; - c = c | 0; - a[(c + 3) >> 0] = b >>> 24; - a[(c + 2) >> 0] = b >>> 16; - a[(c + 1) >> 0] = b >>> 8; - a[c >> 0] = b; - return; - } - function Xe(a, b) { - a = a | 0; - b = b | 0; - return; - } - function Ye(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function Ze(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 4) >> 2] & 255](a); - return; - } - function _e(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 9202 ? (a + 12) | 0 : 0) | 0; - } - function $e(a) { - a = a | 0; - Da(a, 16); - return; - } - function af(a, b) { - a = a | 0; - b = b | 0; - fe(a); - c[a >> 2] = 4768; - c[(a + 4) >> 2] = b; - cf((a + 8) | 0); - return; - } - function bf(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 4792; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Xe(a, e); - V = d; - return; - } - function cf(b) { - b = b | 0; - gf(b); - hf((b + 164) | 0); - jf((b + 244) | 0); - a[(b + 324) >> 0] = 0; - a[(b + 325) >> 0] = 0; - return; - } - function df(a) { - a = a | 0; - c[a >> 2] = 4768; - of((a + 8) | 0); - le(a); - return; - } - function ef(a) { - a = a | 0; - df(a); - jp(a); - return; - } - function ff(a, b) { - a = a | 0; - b = b | 0; - return qf((a + 8) | 0, c[(a + 4) >> 2] | 0, b) | 0; - } - function gf(b) { - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0; - h = V; - V = (V + 16) | 0; - f = h; - a[b >> 0] = 0; - Oc((b + 4) | 0, 516, 0, 0); - Oc((b + 48) | 0, 6, 0, 0); - c[(b + 92) >> 2] = 0; - c[(b + 96) >> 2] = 0; - e = (b + 100) | 0; - mf(e); - nf(f); - g = c[f >> 2] | 0; - f = c[(f + 4) >> 2] | 0; - d = 4; - while (1) { - i = e; - j = i; - a[j >> 0] = g; - a[(j + 1) >> 0] = g >> 8; - a[(j + 2) >> 0] = g >> 16; - a[(j + 3) >> 0] = g >> 24; - i = (i + 4) | 0; - a[i >> 0] = f; - a[(i + 1) >> 0] = f >> 8; - a[(i + 2) >> 0] = f >> 16; - a[(i + 3) >> 0] = f >> 24; - d = (d + -1) | 0; - if (!d) - break; - else - e = (e + 8) | 0; - } - j = (b + 132) | 0; - c[j >> 2] = 0; - c[(j + 4) >> 2] = 0; - c[(j + 8) >> 2] = 0; - c[(j + 12) >> 2] = 0; - c[(j + 16) >> 2] = 0; - c[(j + 20) >> 2] = 0; - c[(j + 24) >> 2] = 0; - c[(j + 28) >> 2] = 0; - V = h; - return; - } - function hf(a) { - a = a | 0; - xe(a, 32, 9, 8, 0); - return; - } - function jf(a) { - a = a | 0; - mc(a, 32, 9, 8, 0); - return; - } - function kf(a) { - a = a | 0; - ye(a); - return; - } - function lf(a) { - a = a | 0; - Ic((a + 48) | 0); - Ic((a + 4) | 0); - return; - } - function mf(a) { - a = a | 0; - var b = 0; - b = (a + 32) | 0; - do { - nf(a); - a = (a + 8) | 0; - } while ((a | 0) != (b | 0)); - return; - } - function nf(b) { - b = b | 0; - var c = 0; - c = b; - a[c >> 0] = 0; - a[(c + 1) >> 0] = 0; - a[(c + 2) >> 0] = 0; - a[(c + 3) >> 0] = 0; - b = (b + 4) | 0; - a[b >> 0] = 0; - a[(b + 1) >> 0] = 0; - a[(b + 2) >> 0] = 0; - a[(b + 3) >> 0] = 0; - return; - } - function of(a) { - a = a | 0; - pf((a + 244) | 0); - kf((a + 164) | 0); - lf(a); - return; - } - function pf(a) { - a = a | 0; - qc(a); - return; - } - function qf(b, e, f) { - b = b | 0; - e = e | 0; - f = f | 0; - var g = 0, h = 0, i = 0, j = 0, k = 0; - g = (b + 325) | 0; - if (!(a[g >> 0] | 0)) { - rf((b + 244) | 0); - a[g >> 0] = 1; - } - if (!(a[b >> 0] | 0)) { - a[b >> 0] = 1; - Ee(De(e) | 0, f, 8); - i = sf(f) | 0; - j = u() | 0; - b = (b + 100) | 0; - e = b; - a[e >> 0] = i; - a[(e + 1) >> 0] = i >> 8; - a[(e + 2) >> 0] = i >> 16; - a[(e + 3) >> 0] = i >> 24; - b = (b + 4) | 0; - a[b >> 0] = j; - a[(b + 1) >> 0] = j >> 8; - a[(b + 2) >> 0] = j >> 16; - a[(b + 3) >> 0] = j >> 24; - } - else { - j = (b + 92) | 0; - a: do - if (!(c[(b + 132 + (c[j >> 2] << 2)) >> 2] | 0)) { - g = Zc(e, (b + 48) | 0) | 0; - switch (g | 0) { - case 1: { - e = pc((b + 244) | 0, e, 0, 0) | 0; - c[(b + 132 + (c[j >> 2] << 2)) >> 2] = e; - e = c[j >> 2] | 0; - k = c[(b + 132 + (e << 2)) >> 2] | 0; - i = (b + 100 + (e << 3)) | 0; - h = i; - g = h; - h = (h + 4) | 0; - k = - lr(d[g >> 0] | - (d[(g + 1) >> 0] << 8) | - (d[(g + 2) >> 0] << 16) | - (d[(g + 3) >> 0] << 24) | - 0, d[h >> 0] | - (d[(h + 1) >> 0] << 8) | - (d[(h + 2) >> 0] << 16) | - (d[(h + 3) >> 0] << 24) | - 0, k | 0, ((((k | 0) < 0) << 31) >> 31) | 0) | 0; - h = u() | 0; - g = i; - a[g >> 0] = k; - a[(g + 1) >> 0] = k >> 8; - a[(g + 2) >> 0] = k >> 16; - a[(g + 3) >> 0] = k >> 24; - i = (i + 4) | 0; - a[i >> 0] = h; - a[(i + 1) >> 0] = h >> 8; - a[(i + 2) >> 0] = h >> 16; - a[(i + 3) >> 0] = h >> 24; - c[(b + 148 + (e << 2)) >> 2] = 0; - break a; - } - case 2: { - k = (b + 96) | 0; - c[k >> 2] = ((c[k >> 2] | 0) + 1) & 3; - i = (b + 100 + (c[j >> 2] << 3) + 4) | 0; - i = - pc((b + 244) | 0, e, d[i >> 0] | - (d[(i + 1) >> 0] << 8) | - (d[(i + 2) >> 0] << 16) | - (d[(i + 3) >> 0] << 24), 8) | 0; - g = (b + 100 + (c[k >> 2] << 3)) | 0; - h = g; - a[h >> 0] = 0; - a[(h + 1) >> 0] = 0; - a[(h + 2) >> 0] = 0; - a[(h + 3) >> 0] = 0; - g = (g + 4) | 0; - a[g >> 0] = i; - a[(g + 1) >> 0] = i >> 8; - a[(g + 2) >> 0] = i >> 16; - a[(g + 3) >> 0] = i >> 24; - g = tf(e) | 0; - k = c[k >> 2] | 0; - e = (b + 100 + (k << 3)) | 0; - i = e; - h = i; - i = (i + 4) | 0; - i = - d[i >> 0] | - (d[(i + 1) >> 0] << 8) | - (d[(i + 2) >> 0] << 16) | - (d[(i + 3) >> 0] << 24); - g = - d[h >> 0] | - (d[(h + 1) >> 0] << 8) | - (d[(h + 2) >> 0] << 16) | - (d[(h + 3) >> 0] << 24) | - g; - h = e; - a[h >> 0] = g; - a[(h + 1) >> 0] = g >> 8; - a[(h + 2) >> 0] = g >> 16; - a[(h + 3) >> 0] = g >> 24; - e = (e + 4) | 0; - a[e >> 0] = i; - a[(e + 1) >> 0] = i >> 8; - a[(e + 2) >> 0] = i >> 16; - a[(e + 3) >> 0] = i >> 24; - c[j >> 2] = k; - c[(b + 132 + (k << 2)) >> 2] = 0; - c[(b + 148 + (c[j >> 2] << 2)) >> 2] = 0; - break a; - } - default: { - if ((g | 0) <= 2) - break a; - c[j >> 2] = (g + 2 + (c[j >> 2] | 0)) & 3; - qf(b, e, f) | 0; - break a; - } - } - } - else { - i = Zc(e, (b + 4) | 0) | 0; - if ((i | 0) == 1) { - g = pc((b + 244) | 0, e, c[(b + 132 + (c[j >> 2] << 2)) >> 2] | 0, 1) | 0; - k = c[j >> 2] | 0; - e = (b + 100 + (k << 3)) | 0; - i = e; - h = i; - i = (i + 4) | 0; - g = - lr(d[h >> 0] | - (d[(h + 1) >> 0] << 8) | - (d[(h + 2) >> 0] << 16) | - (d[(h + 3) >> 0] << 24) | - 0, d[i >> 0] | - (d[(i + 1) >> 0] << 8) | - (d[(i + 2) >> 0] << 16) | - (d[(i + 3) >> 0] << 24) | - 0, g | 0, ((((g | 0) < 0) << 31) >> 31) | 0) | 0; - i = u() | 0; - h = e; - a[h >> 0] = g; - a[(h + 1) >> 0] = g >> 8; - a[(h + 2) >> 0] = g >> 16; - a[(h + 3) >> 0] = g >> 24; - e = (e + 4) | 0; - a[e >> 0] = i; - a[(e + 1) >> 0] = i >> 8; - a[(e + 2) >> 0] = i >> 16; - a[(e + 3) >> 0] = i >> 24; - c[(b + 148 + (k << 2)) >> 2] = 0; - break; - } - if ((i | 0) >= 511) { - if ((i | 0) == 512) { - k = (b + 96) | 0; - c[k >> 2] = ((c[k >> 2] | 0) + 1) & 3; - i = (b + 100 + (c[j >> 2] << 3) + 4) | 0; - i = - pc((b + 244) | 0, e, d[i >> 0] | - (d[(i + 1) >> 0] << 8) | - (d[(i + 2) >> 0] << 16) | - (d[(i + 3) >> 0] << 24), 8) | 0; - g = (b + 100 + (c[k >> 2] << 3)) | 0; - h = g; - a[h >> 0] = 0; - a[(h + 1) >> 0] = 0; - a[(h + 2) >> 0] = 0; - a[(h + 3) >> 0] = 0; - g = (g + 4) | 0; - a[g >> 0] = i; - a[(g + 1) >> 0] = i >> 8; - a[(g + 2) >> 0] = i >> 16; - a[(g + 3) >> 0] = i >> 24; - g = tf(e) | 0; - k = c[k >> 2] | 0; - e = (b + 100 + (k << 3)) | 0; - i = e; - h = i; - i = (i + 4) | 0; - i = - d[i >> 0] | - (d[(i + 1) >> 0] << 8) | - (d[(i + 2) >> 0] << 16) | - (d[(i + 3) >> 0] << 24); - g = - d[h >> 0] | - (d[(h + 1) >> 0] << 8) | - (d[(h + 2) >> 0] << 16) | - (d[(h + 3) >> 0] << 24) | - g; - h = e; - a[h >> 0] = g; - a[(h + 1) >> 0] = g >> 8; - a[(h + 2) >> 0] = g >> 16; - a[(h + 3) >> 0] = g >> 24; - e = (e + 4) | 0; - a[e >> 0] = i; - a[(e + 1) >> 0] = i >> 8; - a[(e + 2) >> 0] = i >> 16; - a[(e + 3) >> 0] = i >> 24; - c[j >> 2] = k; - c[(b + 132 + (k << 2)) >> 2] = 0; - c[(b + 148 + (c[j >> 2] << 2)) >> 2] = 0; - break; - } - if ((i | 0) <= 511) - break; - c[j >> 2] = ((c[j >> 2] | 0) + i) & 3; - qf(b, e, f) | 0; - break; - } - do - if (!i) { - g = pc((b + 244) | 0, e, 0, 7) | 0; - h = (b + 148 + (c[j >> 2] << 2)) | 0; - c[h >> 2] = (c[h >> 2] | 0) + 1; - h = c[j >> 2] | 0; - if ((c[(b + 148 + (h << 2)) >> 2] | 0) > 3) { - c[(b + 132 + (h << 2)) >> 2] = g; - c[(b + 148 + (c[j >> 2] << 2)) >> 2] = 0; - } - } - else { - if ((i | 0) < 500) { - g = (b + 244) | 0; - h = q(c[(b + 132 + (c[j >> 2] << 2)) >> 2] | 0, i) | 0; - if ((i | 0) < 10) { - g = pc(g, e, h, 2) | 0; - break; - } - else { - g = pc(g, e, h, 3) | 0; - break; - } - } - if ((i | 0) == 500) { - g = - pc((b + 244) | 0, e, ((c[(b + 132 + (c[j >> 2] << 2)) >> 2] | 0) * 500) | 0, 4) | 0; - h = (b + 148 + (c[j >> 2] << 2)) | 0; - c[h >> 2] = (c[h >> 2] | 0) + 1; - h = c[j >> 2] | 0; - if ((c[(b + 148 + (h << 2)) >> 2] | 0) <= 3) - break; - c[(b + 132 + (h << 2)) >> 2] = g; - c[(b + 148 + (c[j >> 2] << 2)) >> 2] = 0; - break; - } - g = (500 - i) | 0; - h = (b + 244) | 0; - i = c[(b + 132 + (c[j >> 2] << 2)) >> 2] | 0; - if ((g | 0) > -10) { - g = pc(h, e, q(i, g) | 0, 5) | 0; - break; - } - g = pc(h, e, q(i, -10) | 0, 6) | 0; - h = (b + 148 + (c[j >> 2] << 2)) | 0; - c[h >> 2] = (c[h >> 2] | 0) + 1; - h = c[j >> 2] | 0; - if ((c[(b + 148 + (h << 2)) >> 2] | 0) > 3) { - c[(b + 132 + (h << 2)) >> 2] = g; - c[(b + 148 + (c[j >> 2] << 2)) >> 2] = 0; - } - } - while (0); - k = (b + 100 + (c[j >> 2] << 3)) | 0; - h = k; - e = h; - h = (h + 4) | 0; - h = - lr(d[e >> 0] | - (d[(e + 1) >> 0] << 8) | - (d[(e + 2) >> 0] << 16) | - (d[(e + 3) >> 0] << 24) | - 0, d[h >> 0] | - (d[(h + 1) >> 0] << 8) | - (d[(h + 2) >> 0] << 16) | - (d[(h + 3) >> 0] << 24) | - 0, g | 0, ((((g | 0) < 0) << 31) >> 31) | 0) | 0; - e = u() | 0; - i = k; - a[i >> 0] = h; - a[(i + 1) >> 0] = h >> 8; - a[(i + 2) >> 0] = h >> 16; - a[(i + 3) >> 0] = h >> 24; - k = (k + 4) | 0; - a[k >> 0] = e; - a[(k + 1) >> 0] = e >> 8; - a[(k + 2) >> 0] = e >> 16; - a[(k + 3) >> 0] = e >> 24; - } - while (0); - uf((b + 100 + (c[j >> 2] << 3)) | 0, f); - } - return (f + 8) | 0; - } - function rf(a) { - a = a | 0; - oc(a); - return; - } - function sf(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = V; - V = (V + 16) | 0; - d = b; - e = Re(a) | 0; - vf(d, e, Re((a + 4) | 0) | 0); - a = c[d >> 2] | 0; - t(c[(d + 4) >> 2] | 0); - V = b; - return a | 0; - } - function tf(a) { - a = a | 0; - var b = 0; - b = (bd(a) | 0) & 65535; - return (((bd(a) | 0) & 65535) << 16) | b | 0; - } - function uf(a, b) { - a = a | 0; - b = b | 0; - var c = 0; - c = a; - We(d[c >> 0] | (d[(c + 1) >> 0] << 8) | (d[(c + 2) >> 0] << 16) | (d[(c + 3) >> 0] << 24), b); - a = (a + 4) | 0; - We(d[a >> 0] | (d[(a + 1) >> 0] << 8) | (d[(a + 2) >> 0] << 16) | (d[(a + 3) >> 0] << 24), (b + 4) | 0); - return; - } - function vf(b, c, d) { - b = b | 0; - c = c | 0; - d = d | 0; - var e = 0; - e = b; - a[e >> 0] = c; - a[(e + 1) >> 0] = c >> 8; - a[(e + 2) >> 0] = c >> 16; - a[(e + 3) >> 0] = c >> 24; - c = (b + 4) | 0; - a[c >> 0] = d; - a[(c + 1) >> 0] = d >> 8; - a[(c + 2) >> 0] = d >> 16; - a[(c + 3) >> 0] = d >> 24; - return; - } - function wf(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function xf(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 4) >> 2] & 255](a); - return; - } - function yf(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 9890 ? (a + 12) | 0 : 0) | 0; - } - function zf(a) { - a = a | 0; - Da(a, 16); - return; - } - function Af(a, b) { - a = a | 0; - b = b | 0; - fe(a); - c[a >> 2] = 4820; - c[(a + 4) >> 2] = b; - Cf((a + 8) | 0); - return; - } - function Bf(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 4844; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Xe(a, e); - V = d; - return; - } - function Cf(b) { - b = b | 0; - a[b >> 0] = 0; - Gf((b + 1) | 0); - Oc((b + 8) | 0, 128, 0, 0); - Oc((b + 52) | 0, 256, 0, 0); - Oc((b + 96) | 0, 256, 0, 0); - Oc((b + 140) | 0, 256, 0, 0); - Oc((b + 184) | 0, 256, 0, 0); - Oc((b + 228) | 0, 256, 0, 0); - Oc((b + 272) | 0, 256, 0, 0); - return; - } - function Df(a) { - a = a | 0; - c[a >> 2] = 4820; - Hf((a + 8) | 0); - le(a); - return; - } - function Ef(a) { - a = a | 0; - Df(a); - jp(a); - return; - } - function Ff(a, b) { - a = a | 0; - b = b | 0; - return If((a + 8) | 0, c[(a + 4) >> 2] | 0, b) | 0; - } - function Gf(b) { - b = b | 0; - var c = 0; - a[b >> 0] = 0; - a[(b + 1) >> 0] = 0; - c = (b + 2) | 0; - a[c >> 0] = 0; - a[(c + 1) >> 0] = 0; - b = (b + 4) | 0; - a[b >> 0] = 0; - a[(b + 1) >> 0] = 0; - return; - } - function Hf(a) { - a = a | 0; - Ic((a + 272) | 0); - Ic((a + 228) | 0); - Ic((a + 184) | 0); - Ic((a + 140) | 0); - Ic((a + 96) | 0); - Ic((a + 52) | 0); - Ic((a + 8) | 0); - return; - } - function If(c, f, g) { - c = c | 0; - f = f | 0; - g = g | 0; - var h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0; - o = V; - V = (V + 16) | 0; - m = o; - if (!(a[c >> 0] | 0)) { - a[c >> 0] = 1; - Ee(De(f) | 0, g, 6); - Jf(m, g); - n = (c + 1) | 0; - a[n >> 0] = a[m >> 0] | 0; - a[(n + 1) >> 0] = a[(m + 1) >> 0] | 0; - a[(n + 2) >> 0] = a[(m + 2) >> 0] | 0; - a[(n + 3) >> 0] = a[(m + 3) >> 0] | 0; - a[(n + 4) >> 0] = a[(m + 4) >> 0] | 0; - a[(n + 5) >> 0] = a[(m + 5) >> 0] | 0; - } - else { - n = Zc(f, (c + 8) | 0) | 0; - Gf(m); - if (!(n & 1)) { - h = (c + 1) | 0; - h = (d[h >> 0] | (d[(h + 1) >> 0] << 8)) & 255; - } - else { - l = (Zc(f, (c + 52) | 0) | 0) & 255; - h = (c + 1) | 0; - h = (Ie((l + ((d[h >> 0] | (d[(h + 1) >> 0] << 8)) & 255)) | 0) | 0) & 255; - } - b[m >> 1] = h; - if (!(n & 2)) { - l = (c + 1) | 0; - h = h | ((d[l >> 0] | (d[(l + 1) >> 0] << 8)) & -256); - } - else { - h = (Zc(f, (c + 96) | 0) | 0) & 255; - l = (c + 1) | 0; - h = - ((Ie(((((d[l >> 0] | (d[(l + 1) >> 0] << 8)) & 65535) >>> 8) + h) | 0) | 0) & 255) << 8; - h = (h | e[m >> 1]) & 65535; - } - b[m >> 1] = h; - do - if (n & 64) { - k = (c + 1) | 0; - i = ((h & 255) - ((d[k >> 0] | (d[(k + 1) >> 0] << 8)) & 255)) | 0; - if (!(n & 4)) { - h = (c + 3) | 0; - h = (d[h >> 0] | (d[(h + 1) >> 0] << 8)) & 255; - } - else { - h = (Zc(f, (c + 140) | 0) | 0) & 255; - l = (c + 3) | 0; - l = (i + ((d[l >> 0] | (d[(l + 1) >> 0] << 8)) & 255)) | 0; - h = (Ie((((l | 0) < 1 ? 0 : (l | 0) > 254 ? 255 : l & 255) + h) | 0) | 0) & 255; - } - l = (m + 2) | 0; - b[l >> 1] = h; - if (!(n & 16)) { - h = (c + 5) | 0; - h = (d[h >> 0] | (d[(h + 1) >> 0] << 8)) & 255; - } - else { - h = Zc(f, (c + 228) | 0) | 0; - p = (c + 3) | 0; - j = (c + 5) | 0; - j = - (((((i + (b[l >> 1] & 255) - ((d[p >> 0] | (d[(p + 1) >> 0] << 8)) & 255)) | 0) / - 2) | - 0) + - ((d[j >> 0] | (d[(j + 1) >> 0] << 8)) & 255)) | - 0; - h = - (Ie((((j | 0) < 1 ? 0 : (j | 0) > 254 ? 255 : j & 255) + (h & 255)) | 0) | 0) & 255; - } - j = (m + 4) | 0; - b[j >> 1] = h; - h = - (((e[m >> 1] | 0) >>> 8) - (((d[k >> 0] | (d[(k + 1) >> 0] << 8)) & 65535) >>> 8)) | - 0; - if (!(n & 8)) { - i = (c + 3) | 0; - i = b[l >> 1] | ((d[i >> 0] | (d[(i + 1) >> 0] << 8)) & -256); - } - else { - i = (Zc(f, (c + 184) | 0) | 0) & 255; - p = (c + 3) | 0; - p = ((((d[p >> 0] | (d[(p + 1) >> 0] << 8)) & 65535) >>> 8) + h) | 0; - i = - ((Ie((((p | 0) < 1 ? 0 : (p | 0) > 254 ? 255 : p & 255) + i) | 0) | 0) & 255) << 8; - i = (i | e[l >> 1]) & 65535; - } - b[l >> 1] = i; - if (!(n & 32)) { - p = (c + 5) | 0; - b[j >> 1] = b[j >> 1] | ((d[p >> 0] | (d[(p + 1) >> 0] << 8)) & -256); - break; - } - else { - p = Zc(f, (c + 272) | 0) | 0; - f = (c + 3) | 0; - n = (c + 5) | 0; - n = - (((((((e[l >> 1] | 0) >>> 8) + - h - - (((d[f >> 0] | (d[(f + 1) >> 0] << 8)) & 65535) >>> 8)) | - 0) / - 2) | - 0) + - (((d[n >> 0] | (d[(n + 1) >> 0] << 8)) & 65535) >>> 8)) | - 0; - p = - ((Ie((((n | 0) < 1 ? 0 : (n | 0) > 254 ? 255 : n & 255) + (p & 255)) | 0) | 0) & - 255) << - 8; - b[j >> 1] = p | e[j >> 1]; - break; - } - } - else { - b[(m + 2) >> 1] = h; - b[(m + 4) >> 1] = h; - } - while (0); - p = (c + 1) | 0; - a[p >> 0] = a[m >> 0] | 0; - a[(p + 1) >> 0] = a[(m + 1) >> 0] | 0; - a[(p + 2) >> 0] = a[(m + 2) >> 0] | 0; - a[(p + 3) >> 0] = a[(m + 3) >> 0] | 0; - a[(p + 4) >> 0] = a[(m + 4) >> 0] | 0; - a[(p + 5) >> 0] = a[(m + 5) >> 0] | 0; - Kf(p, g); - } - V = o; - return (g + 6) | 0; - } - function Jf(a, b) { - a = a | 0; - b = b | 0; - var c = 0, d = 0; - d = Oe(b) | 0; - c = Oe((b + 2) | 0) | 0; - Lf(a, d, c, Oe((b + 4) | 0) | 0); - return; - } - function Kf(a, b) { - a = a | 0; - b = b | 0; - var c = 0; - Te(d[a >> 0] | (d[(a + 1) >> 0] << 8), b); - c = (a + 2) | 0; - Te(d[c >> 0] | (d[(c + 1) >> 0] << 8), (b + 2) | 0); - a = (a + 4) | 0; - Te(d[a >> 0] | (d[(a + 1) >> 0] << 8), (b + 4) | 0); - return; - } - function Lf(b, c, d, e) { - b = b | 0; - c = c | 0; - d = d | 0; - e = e | 0; - a[b >> 0] = c; - a[(b + 1) >> 0] = c >> 8; - c = (b + 2) | 0; - a[c >> 0] = d; - a[(c + 1) >> 0] = d >> 8; - d = (b + 4) | 0; - a[d >> 0] = e; - a[(d + 1) >> 0] = e >> 8; - return; - } - function Mf(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function Nf(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 4) >> 2] & 255](a); - return; - } - function Of(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 10570 ? (a + 12) | 0 : 0) | 0; - } - function Pf(a) { - a = a | 0; - Da(a, 16); - return; - } - function Qf(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - fe(a); - c[a >> 2] = 4872; - c[(a + 4) >> 2] = b; - Sf((a + 8) | 0, d); - return; - } - function Rf(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 4896; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Xe(a, e); - V = d; - return; - } - function Sf(b, d) { - b = b | 0; - d = d | 0; - c[b >> 2] = c[d >> 2]; - a[(b + 4) >> 0] = a[(d + 4) >> 0] | 0; - Wf((b + 8) | 0, (d + 8) | 0); - Wf((b + 20) | 0, (d + 20) | 0); - Xf((b + 32) | 0, (d + 32) | 0); - return; - } - function Tf(a) { - a = a | 0; - c[a >> 2] = 4872; - ud((a + 8) | 0); - le(a); - return; - } - function Uf(a) { - a = a | 0; - Tf(a); - jp(a); - return; - } - function Vf(a, b) { - a = a | 0; - b = b | 0; - return Dg((a + 8) | 0, c[(a + 4) >> 2] | 0, b) | 0; - } - function Wf(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0; - c[a >> 2] = 0; - c[(a + 4) >> 2] = 0; - c[(a + 8) >> 2] = 0; - d = (b + 4) | 0; - e = ((c[d >> 2] | 0) - (c[b >> 2] | 0)) | 0; - if (e | 0) { - Yf(a, e); - Zf(a, c[b >> 2] | 0, c[d >> 2] | 0, e); - } - return; - } - function Xf(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0; - d = V; - V = (V + 32) | 0; - e = (d + 24) | 0; - f = (d + 16) | 0; - h = (d + 8) | 0; - g = d; - c[a >> 2] = 0; - c[(a + 4) >> 2] = 0; - c[(a + 8) >> 2] = 0; - c[(a + 12) >> 2] = 0; - c[(a + 16) >> 2] = 0; - c[(a + 20) >> 2] = 0; - zg(h, b); - Ag(g, b); - c[f >> 2] = c[h >> 2]; - c[(f + 4) >> 2] = c[(h + 4) >> 2]; - c[e >> 2] = c[g >> 2]; - c[(e + 4) >> 2] = c[(g + 4) >> 2]; - cg(a, f, e, 0); - V = d; - return; - } - function Yf(a, b) { - a = a | 0; - b = b | 0; - var d = 0; - if (($f(a) | 0) >>> 0 < b >>> 0) - cr(a); - else { - d = eq(b) | 0; - c[(a + 4) >> 2] = d; - c[a >> 2] = d; - c[(a + 8) >> 2] = d + b; - return; - } - } - function Zf(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0; - g = V; - V = (V + 16) | 0; - f = g; - ag(f, a, e); - e = (f + 4) | 0; - a = (d - b) | 0; - if ((a | 0) > 0) { - ur(c[e >> 2] | 0, b | 0, a | 0) | 0; - c[e >> 2] = (c[e >> 2] | 0) + a; - } - bg(f); - V = g; - return; - } - function _f(a) { - a = a | 0; - var b = 0, d = 0; - b = c[a >> 2] | 0; - d = b; - if (b | 0) { - c[(a + 4) >> 2] = d; - Da(b, ((c[(a + 8) >> 2] | 0) - d) | 0); - } - return; - } - function $f(a) { - a = a | 0; - return 2147483647; - } - function ag(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - c[a >> 2] = b; - b = c[(b + 4) >> 2] | 0; - c[(a + 4) >> 2] = b; - c[(a + 8) >> 2] = b + d; - return; - } - function bg(a) { - a = a | 0; - c[((c[a >> 2] | 0) + 4) >> 2] = c[(a + 4) >> 2]; - return; - } - function cg(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, q = 0; - q = V; - V = (V + 96) | 0; - p = (q + 80) | 0; - m = (q + 64) | 0; - j = (q + 48) | 0; - k = (q + 40) | 0; - l = (q + 8) | 0; - i = q; - n = (q + 32) | 0; - o = (q + 16) | 0; - h = b; - g = c[h >> 2] | 0; - h = c[(h + 4) >> 2] | 0; - f = d; - d = c[f >> 2] | 0; - f = c[(f + 4) >> 2] | 0; - e = g; - if ((f | 0) == (h | 0)) - h = 0; - else - h = - (((((f - (c[d >> 2] | 0)) | 0) / 44) | 0) + - ((((d - g) >> 2) * 93) | 0) + - ((((h - (c[g >> 2] | 0)) | 0) / -44) | 0)) | - 0; - d = ((c[(a + 8) >> 2] | 0) - (c[(a + 4) >> 2] | 0)) | 0; - d = - (((d | 0) == 0 ? 0 : ((((d >> 2) * 93) | 0) + -1) | 0) - - ((c[(a + 20) >> 2] | 0) + (c[(a + 16) >> 2] | 0))) | - 0; - if (h >>> 0 > d >>> 0) - eg(a, (h - d) | 0); - fg(k, a); - fg(i, a); - f = i; - d = c[f >> 2] | 0; - f = c[(f + 4) >> 2] | 0; - g = l; - c[g >> 2] = d; - c[(g + 4) >> 2] = f; - g = d; - if (h | 0) { - d = (((((f - (c[d >> 2] | 0)) | 0) / 44) | 0) + h) | 0; - if ((d | 0) > 0) { - i = ((d >>> 0) / 93) | 0; - h = (g + (i << 2)) | 0; - c[l >> 2] = h; - d = ((c[h >> 2] | 0) + ((((d - ((i * 93) | 0)) | 0) * 44) | 0)) | 0; - } - else { - d = (92 - d) | 0; - i = (g + ((((d | 0) / -93) | 0) << 2)) | 0; - c[l >> 2] = i; - d = ((c[i >> 2] | 0) + ((((92 - ((d | 0) % 93 | 0)) | 0) * 44) | 0)) | 0; - } - c[(l + 4) >> 2] = d; - } - c[m >> 2] = c[k >> 2]; - c[(m + 4) >> 2] = c[(k + 4) >> 2]; - c[p >> 2] = c[l >> 2]; - c[(p + 4) >> 2] = c[(l + 4) >> 2]; - gg(j, m, p); - hg(p, j); - ig(m, j); - if (jg(p, m) | 0) { - g = (o + 4) | 0; - h = (b + 4) | 0; - do { - kg(n, p); - lg(o, a, n); - d = c[o >> 2] | 0; - if ((d | 0) != (c[g >> 2] | 0)) { - f = c[h >> 2] | 0; - do { - Wc(d, f); - d = ((c[o >> 2] | 0) + 44) | 0; - c[o >> 2] = d; - f = (f + 44) | 0; - c[h >> 2] = f; - if (((f - (c[e >> 2] | 0)) | 0) == 4092) { - e = (e + 4) | 0; - c[b >> 2] = e; - f = c[e >> 2] | 0; - c[h >> 2] = f; - } - } while ((d | 0) != (c[g >> 2] | 0)); - } - mg(o); - ng(p) | 0; - } while (jg(p, m) | 0); - } - V = q; - return; - } - function dg(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = c[(a + 4) >> 2] | 0; - d = (a + 8) | 0; - e = c[d >> 2] | 0; - if ((e | 0) != (b | 0)) - c[d >> 2] = e + (~(((e + -4 - b) | 0) >>> 2) << 2); - b = c[a >> 2] | 0; - if (b | 0) - Da(b, ((c[(a + 12) >> 2] | 0) - b) | 0); - return; - } - function eg(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, r = 0, s = 0, t = 0, u = 0, v = 0, w = 0, x = 0, y = 0, z = 0, A = 0, B = 0, C = 0; - B = V; - V = (V + 64) | 0; - v = (B + 52) | 0; - u = (B + 48) | 0; - w = (B + 28) | 0; - x = (B + 24) | 0; - y = (B + 20) | 0; - p = B; - z = (a + 8) | 0; - d = c[z >> 2] | 0; - A = (a + 4) | 0; - j = c[A >> 2] | 0; - s = ((((d | 0) == (j | 0)) & 1) + b) | 0; - h = ((s >>> 0) / 93) | 0; - h = (h + ((((s - ((h * 93) | 0)) | 0) != 0) & 1)) | 0; - s = (a + 16) | 0; - e = c[s >> 2] | 0; - i = ((e >>> 0) / 93) | 0; - r = h >>> 0 < i >>> 0 ? h : i; - b = (h - r) | 0; - g = d; - a: do - if (!b) { - c[s >> 2] = (q(r, -93) | 0) + e; - if (r | 0) { - i = (a + 12) | 0; - k = (a + 12) | 0; - l = (w + 4) | 0; - m = (w + 8) | 0; - n = (w + 12) | 0; - b = r; - e = j; - while (1) { - h = c[e >> 2] | 0; - g = (e + 4) | 0; - c[A >> 2] = g; - t = c[i >> 2] | 0; - e = t; - do - if ((d | 0) == (t | 0)) { - t = c[a >> 2] | 0; - d = t; - if (g >>> 0 <= t >>> 0) { - d = (e - d) | 0; - d = (d | 0) == 0 ? 1 : d >> 1; - qg(w, d, d >>> 2, k); - c[x >> 2] = c[A >> 2]; - c[y >> 2] = c[z >> 2]; - c[u >> 2] = c[x >> 2]; - c[v >> 2] = c[y >> 2]; - ug(w, u, v); - d = c[a >> 2] | 0; - c[a >> 2] = c[w >> 2]; - c[w >> 2] = d; - d = c[A >> 2] | 0; - c[A >> 2] = c[l >> 2]; - c[l >> 2] = d; - d = c[z >> 2] | 0; - c[z >> 2] = c[m >> 2]; - c[m >> 2] = d; - d = c[i >> 2] | 0; - c[i >> 2] = c[n >> 2]; - c[n >> 2] = d; - tg(w); - d = c[z >> 2] | 0; - break; - } - t = g; - d = (((((t - d) >> 2) + 1) | 0) / -2) | 0; - f = (g + (d << 2)) | 0; - e = (e - t) | 0; - if (!e) - d = f; - else { - vr(f | 0, g | 0, e | 0) | 0; - d = ((c[A >> 2] | 0) + (d << 2)) | 0; - } - t = (f + ((e >> 2) << 2)) | 0; - c[z >> 2] = t; - c[A >> 2] = d; - d = t; - } - while (0); - c[d >> 2] = h; - d = ((c[z >> 2] | 0) + 4) | 0; - c[z >> 2] = d; - b = (b + -1) | 0; - if (!b) - break a; - e = c[A >> 2] | 0; - } - } - } - else { - t = (a + 12) | 0; - e = c[t >> 2] | 0; - f = (e - (c[a >> 2] | 0)) | 0; - d = (g - j) >> 2; - if (b >>> 0 > (((f >> 2) - d) | 0) >>> 0) { - o = f >> 1; - n = (d + b) | 0; - qg(p, o >>> 0 < n >>> 0 ? n : o, (d - r) | 0, (a + 12) | 0); - do { - c[v >> 2] = eq(4092) | 0; - rg(p, v); - b = (b + -1) | 0; - } while ((b | 0) != 0); - if (!r) - d = c[A >> 2] | 0; - else { - i = (p + 8) | 0; - j = (p + 12) | 0; - k = (p + 4) | 0; - l = (p + 16) | 0; - m = (w + 4) | 0; - n = (w + 8) | 0; - o = (w + 12) | 0; - h = r; - b = c[i >> 2] | 0; - d = c[A >> 2] | 0; - do { - g = c[j >> 2] | 0; - e = g; - do - if ((b | 0) == (g | 0)) { - f = c[k >> 2] | 0; - g = c[p >> 2] | 0; - b = g; - if (f >>> 0 <= g >>> 0) { - b = (e - b) | 0; - b = (b | 0) == 0 ? 1 : b >> 1; - qg(w, b, b >>> 2, c[l >> 2] | 0); - c[x >> 2] = c[k >> 2]; - c[y >> 2] = c[i >> 2]; - c[u >> 2] = c[x >> 2]; - c[v >> 2] = c[y >> 2]; - ug(w, u, v); - b = c[p >> 2] | 0; - c[p >> 2] = c[w >> 2]; - c[w >> 2] = b; - b = c[k >> 2] | 0; - c[k >> 2] = c[m >> 2]; - c[m >> 2] = b; - b = c[i >> 2] | 0; - c[i >> 2] = c[n >> 2]; - c[n >> 2] = b; - b = c[j >> 2] | 0; - c[j >> 2] = c[o >> 2]; - c[o >> 2] = b; - tg(w); - b = c[i >> 2] | 0; - break; - } - C = f; - b = (((((C - b) >> 2) + 1) | 0) / -2) | 0; - g = (f + (b << 2)) | 0; - e = (e - C) | 0; - if (!e) - b = g; - else { - vr(g | 0, f | 0, e | 0) | 0; - b = ((c[k >> 2] | 0) + (b << 2)) | 0; - } - C = (g + ((e >> 2) << 2)) | 0; - c[i >> 2] = C; - c[k >> 2] = b; - b = C; - } - while (0); - c[b >> 2] = c[d >> 2]; - b = ((c[i >> 2] | 0) + 4) | 0; - c[i >> 2] = b; - d = ((c[A >> 2] | 0) + 4) | 0; - c[A >> 2] = d; - h = (h + -1) | 0; - } while ((h | 0) != 0); - } - b = c[z >> 2] | 0; - if ((b | 0) != (d | 0)) { - do { - b = (b + -4) | 0; - sg(p, b); - d = c[A >> 2] | 0; - } while ((b | 0) != (d | 0)); - b = c[z >> 2] | 0; - } - C = c[a >> 2] | 0; - c[a >> 2] = c[p >> 2]; - c[p >> 2] = C; - C = (p + 4) | 0; - c[A >> 2] = c[C >> 2]; - c[C >> 2] = d; - C = (p + 8) | 0; - c[z >> 2] = c[C >> 2]; - c[C >> 2] = b; - C = (p + 12) | 0; - A = c[t >> 2] | 0; - c[t >> 2] = c[C >> 2]; - c[C >> 2] = A; - c[s >> 2] = (c[s >> 2] | 0) + (q(r, -93) | 0); - tg(p); - break; - } - else { - b: do - if ((e | 0) == (g | 0)) - k = 18; - else { - while (1) { - c[v >> 2] = eq(4092) | 0; - og(a, v); - b = (b + -1) | 0; - if (!b) - break; - if ((c[t >> 2] | 0) == (c[z >> 2] | 0)) { - k = 18; - break b; - } - } - d = r; - b = c[s >> 2] | 0; - } - while (0); - if ((k | 0) == 18) { - e = ~(h >>> 0 > i >>> 0 ? i : h); - d = b; - do { - c[v >> 2] = eq(4092) | 0; - pg(a, v); - d = (d + -1) | 0; - f = - (((((c[z >> 2] | 0) - (c[A >> 2] | 0)) | 0) == 4 ? 92 : 93) + (c[s >> 2] | 0)) | - 0; - c[s >> 2] = f; - } while ((d | 0) != 0); - d = (b + -1 - e) | 0; - b = f; - } - c[s >> 2] = b + (q(d, -93) | 0); - if (!d) - break; - i = (a + 12) | 0; - j = (w + 4) | 0; - k = (w + 8) | 0; - l = (w + 12) | 0; - b = c[z >> 2] | 0; - do { - g = c[A >> 2] | 0; - h = c[g >> 2] | 0; - g = (g + 4) | 0; - c[A >> 2] = g; - C = c[t >> 2] | 0; - e = C; - do - if ((b | 0) == (C | 0)) { - C = c[a >> 2] | 0; - b = C; - if (g >>> 0 <= C >>> 0) { - b = (e - b) | 0; - b = (b | 0) == 0 ? 1 : b >> 1; - qg(w, b, b >>> 2, i); - c[x >> 2] = c[A >> 2]; - c[y >> 2] = c[z >> 2]; - c[u >> 2] = c[x >> 2]; - c[v >> 2] = c[y >> 2]; - ug(w, u, v); - b = c[a >> 2] | 0; - c[a >> 2] = c[w >> 2]; - c[w >> 2] = b; - b = c[A >> 2] | 0; - c[A >> 2] = c[j >> 2]; - c[j >> 2] = b; - b = c[z >> 2] | 0; - c[z >> 2] = c[k >> 2]; - c[k >> 2] = b; - b = c[t >> 2] | 0; - c[t >> 2] = c[l >> 2]; - c[l >> 2] = b; - tg(w); - b = c[z >> 2] | 0; - break; - } - C = g; - b = (((((C - b) >> 2) + 1) | 0) / -2) | 0; - f = (g + (b << 2)) | 0; - e = (e - C) | 0; - if (!e) - b = f; - else { - vr(f | 0, g | 0, e | 0) | 0; - b = ((c[A >> 2] | 0) + (b << 2)) | 0; - } - C = (f + ((e >> 2) << 2)) | 0; - c[z >> 2] = C; - c[A >> 2] = b; - b = C; - } - while (0); - c[b >> 2] = h; - b = ((c[z >> 2] | 0) + 4) | 0; - c[z >> 2] = b; - d = (d + -1) | 0; - } while ((d | 0) != 0); - } - } - while (0); - V = B; - return; - } - function fg(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0; - d = ((c[(b + 16) >> 2] | 0) + (c[(b + 20) >> 2] | 0)) | 0; - g = c[(b + 4) >> 2] | 0; - e = ((d >>> 0) / 93) | 0; - f = (g + (e << 2)) | 0; - if ((c[(b + 8) >> 2] | 0) == (g | 0)) - b = 0; - else - b = ((c[f >> 2] | 0) + ((((d - ((e * 93) | 0)) | 0) * 44) | 0)) | 0; - c[a >> 2] = f; - c[(a + 4) >> 2] = b; - return; - } - function gg(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - f = b; - b = c[(f + 4) >> 2] | 0; - e = a; - c[e >> 2] = c[f >> 2]; - c[(e + 4) >> 2] = b; - e = d; - b = c[(e + 4) >> 2] | 0; - d = (a + 8) | 0; - c[d >> 2] = c[e >> 2]; - c[(d + 4) >> 2] = b; - return; - } - function hg(a, b) { - a = a | 0; - b = b | 0; - c[a >> 2] = c[b >> 2]; - c[(a + 4) >> 2] = c[(b + 4) >> 2]; - c[(a + 8) >> 2] = c[(b + 8) >> 2]; - c[(a + 12) >> 2] = c[(b + 12) >> 2]; - return; - } - function ig(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0; - d = V; - V = (V + 32) | 0; - e = (d + 24) | 0; - f = (d + 16) | 0; - h = (d + 8) | 0; - g = d; - i = (b + 8) | 0; - j = c[i >> 2] | 0; - i = c[(i + 4) >> 2] | 0; - b = h; - c[b >> 2] = j; - c[(b + 4) >> 2] = i; - b = g; - c[b >> 2] = j; - c[(b + 4) >> 2] = i; - c[f >> 2] = c[h >> 2]; - c[(f + 4) >> 2] = c[(h + 4) >> 2]; - c[e >> 2] = c[g >> 2]; - c[(e + 4) >> 2] = c[(g + 4) >> 2]; - gg(a, f, e); - V = d; - return; - } - function jg(a, b) { - a = a | 0; - b = b | 0; - return ((xg(a, b) | 0) ^ 1) | 0; - } - function kg(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0; - d = c[b >> 2] | 0; - e = c[(b + 4) >> 2] | 0; - if ((d | 0) == (c[(b + 8) >> 2] | 0)) - yg(a, e, c[(b + 12) >> 2] | 0); - else - yg(a, e, ((c[d >> 2] | 0) + 4092) | 0); - return; - } - function lg(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0; - e = c[d >> 2] | 0; - c[a >> 2] = e; - c[(a + 4) >> 2] = c[(d + 4) >> 2]; - c[(a + 8) >> 2] = e; - c[(a + 12) >> 2] = b; - return; - } - function mg(a) { - a = a | 0; - var b = 0; - b = ((c[(a + 12) >> 2] | 0) + 20) | 0; - c[b >> 2] = (c[b >> 2] | 0) + (((((c[a >> 2] | 0) - (c[(a + 8) >> 2] | 0)) | 0) / 44) | 0); - return; - } - function ng(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = c[a >> 2] | 0; - d = (a + 8) | 0; - if ((b | 0) == (c[d >> 2] | 0)) { - e = d; - b = c[(e + 4) >> 2] | 0; - d = a; - c[d >> 2] = c[e >> 2]; - c[(d + 4) >> 2] = b; - } - else { - e = (b + 4) | 0; - c[a >> 2] = e; - c[(a + 4) >> 2] = c[e >> 2]; - } - return a | 0; - } - function og(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, q = 0; - p = V; - V = (V + 48) | 0; - f = (p + 32) | 0; - e = (p + 28) | 0; - i = (p + 8) | 0; - j = (p + 4) | 0; - k = p; - o = (a + 8) | 0; - d = c[o >> 2] | 0; - l = (a + 12) | 0; - n = c[l >> 2] | 0; - g = n; - do - if ((d | 0) == (n | 0)) { - n = (a + 4) | 0; - m = c[n >> 2] | 0; - q = c[a >> 2] | 0; - h = q; - if (m >>> 0 <= q >>> 0) { - d = (g - h) | 0; - d = (d | 0) == 0 ? 1 : d >> 1; - qg(i, d, d >>> 2, (a + 12) | 0); - c[j >> 2] = c[n >> 2]; - c[k >> 2] = c[o >> 2]; - c[e >> 2] = c[j >> 2]; - c[f >> 2] = c[k >> 2]; - ug(i, e, f); - d = c[a >> 2] | 0; - c[a >> 2] = c[i >> 2]; - c[i >> 2] = d; - d = (i + 4) | 0; - q = c[n >> 2] | 0; - c[n >> 2] = c[d >> 2]; - c[d >> 2] = q; - d = (i + 8) | 0; - q = c[o >> 2] | 0; - c[o >> 2] = c[d >> 2]; - c[d >> 2] = q; - d = (i + 12) | 0; - q = c[l >> 2] | 0; - c[l >> 2] = c[d >> 2]; - c[d >> 2] = q; - tg(i); - d = c[o >> 2] | 0; - break; - } - f = m; - e = (((((f - h) >> 2) + 1) | 0) / -2) | 0; - a = (m + (e << 2)) | 0; - f = (d - f) | 0; - if (!f) - d = a; - else { - vr(a | 0, m | 0, f | 0) | 0; - d = ((c[n >> 2] | 0) + (e << 2)) | 0; - } - q = (a + ((f >> 2) << 2)) | 0; - c[o >> 2] = q; - c[n >> 2] = d; - d = q; - } - while (0); - c[d >> 2] = c[b >> 2]; - c[o >> 2] = (c[o >> 2] | 0) + 4; - V = p; - return; - } - function pg(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, q = 0; - p = V; - V = (V + 48) | 0; - e = (p + 32) | 0; - d = (p + 28) | 0; - h = (p + 8) | 0; - i = (p + 4) | 0; - j = p; - o = (a + 4) | 0; - m = c[o >> 2] | 0; - n = c[a >> 2] | 0; - k = n; - do - if ((m | 0) == (n | 0)) { - n = (a + 8) | 0; - l = c[n >> 2] | 0; - g = (a + 12) | 0; - q = c[g >> 2] | 0; - f = q; - if (l >>> 0 >= q >>> 0) { - q = (f - k) | 0; - q = (q | 0) == 0 ? 1 : q >> 1; - qg(h, q, ((q + 3) | 0) >>> 2, (a + 12) | 0); - c[i >> 2] = c[o >> 2]; - c[j >> 2] = c[n >> 2]; - c[d >> 2] = c[i >> 2]; - c[e >> 2] = c[j >> 2]; - ug(h, d, e); - d = c[a >> 2] | 0; - c[a >> 2] = c[h >> 2]; - c[h >> 2] = d; - d = (h + 4) | 0; - q = c[o >> 2] | 0; - c[o >> 2] = c[d >> 2]; - c[d >> 2] = q; - d = (h + 8) | 0; - q = c[n >> 2] | 0; - c[n >> 2] = c[d >> 2]; - c[d >> 2] = q; - d = (h + 12) | 0; - q = c[g >> 2] | 0; - c[g >> 2] = c[d >> 2]; - c[d >> 2] = q; - tg(h); - d = c[o >> 2] | 0; - break; - } - e = l; - a = (((((f - e) >> 2) + 1) | 0) / 2) | 0; - f = (l + (a << 2)) | 0; - e = (e - m) | 0; - d = (f + ((0 - (e >> 2)) << 2)) | 0; - if (!e) { - d = f; - e = f; - } - else { - vr(d | 0, m | 0, e | 0) | 0; - e = ((c[n >> 2] | 0) + (a << 2)) | 0; - } - c[o >> 2] = d; - c[n >> 2] = e; - } - else - d = m; - while (0); - c[(d + -4) >> 2] = c[b >> 2]; - c[o >> 2] = (c[o >> 2] | 0) + -4; - V = p; - return; - } - function qg(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0; - f = (a + 12) | 0; - c[f >> 2] = 0; - c[(a + 16) >> 2] = e; - do - if (b) - if (b >>> 0 > 1073741823) { - f = v(8) | 0; - vq(f, 6723); - c[f >> 2] = 5956; - x(f | 0, 3928, 123); - } - else { - e = eq(b << 2) | 0; - break; - } - else - e = 0; - while (0); - c[a >> 2] = e; - d = (e + (d << 2)) | 0; - c[(a + 8) >> 2] = d; - c[(a + 4) >> 2] = d; - c[f >> 2] = e + (b << 2); - return; - } - function rg(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, q = 0; - p = V; - V = (V + 48) | 0; - f = (p + 32) | 0; - e = (p + 28) | 0; - i = (p + 8) | 0; - j = (p + 4) | 0; - k = p; - o = (a + 8) | 0; - d = c[o >> 2] | 0; - l = (a + 12) | 0; - n = c[l >> 2] | 0; - g = n; - do - if ((d | 0) == (n | 0)) { - n = (a + 4) | 0; - m = c[n >> 2] | 0; - q = c[a >> 2] | 0; - h = q; - if (m >>> 0 <= q >>> 0) { - d = (g - h) | 0; - d = (d | 0) == 0 ? 1 : d >> 1; - qg(i, d, d >>> 2, c[(a + 16) >> 2] | 0); - c[j >> 2] = c[n >> 2]; - c[k >> 2] = c[o >> 2]; - c[e >> 2] = c[j >> 2]; - c[f >> 2] = c[k >> 2]; - ug(i, e, f); - d = c[a >> 2] | 0; - c[a >> 2] = c[i >> 2]; - c[i >> 2] = d; - d = (i + 4) | 0; - q = c[n >> 2] | 0; - c[n >> 2] = c[d >> 2]; - c[d >> 2] = q; - d = (i + 8) | 0; - q = c[o >> 2] | 0; - c[o >> 2] = c[d >> 2]; - c[d >> 2] = q; - d = (i + 12) | 0; - q = c[l >> 2] | 0; - c[l >> 2] = c[d >> 2]; - c[d >> 2] = q; - tg(i); - d = c[o >> 2] | 0; - break; - } - f = m; - e = (((((f - h) >> 2) + 1) | 0) / -2) | 0; - a = (m + (e << 2)) | 0; - f = (d - f) | 0; - if (!f) - d = a; - else { - vr(a | 0, m | 0, f | 0) | 0; - d = ((c[n >> 2] | 0) + (e << 2)) | 0; - } - q = (a + ((f >> 2) << 2)) | 0; - c[o >> 2] = q; - c[n >> 2] = d; - d = q; - } - while (0); - c[d >> 2] = c[b >> 2]; - c[o >> 2] = (c[o >> 2] | 0) + 4; - V = p; - return; - } - function sg(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, q = 0; - p = V; - V = (V + 48) | 0; - e = (p + 32) | 0; - d = (p + 28) | 0; - h = (p + 8) | 0; - i = (p + 4) | 0; - j = p; - o = (a + 4) | 0; - m = c[o >> 2] | 0; - n = c[a >> 2] | 0; - k = n; - do - if ((m | 0) == (n | 0)) { - n = (a + 8) | 0; - l = c[n >> 2] | 0; - g = (a + 12) | 0; - q = c[g >> 2] | 0; - f = q; - if (l >>> 0 >= q >>> 0) { - q = (f - k) | 0; - q = (q | 0) == 0 ? 1 : q >> 1; - qg(h, q, ((q + 3) | 0) >>> 2, c[(a + 16) >> 2] | 0); - c[i >> 2] = c[o >> 2]; - c[j >> 2] = c[n >> 2]; - c[d >> 2] = c[i >> 2]; - c[e >> 2] = c[j >> 2]; - ug(h, d, e); - d = c[a >> 2] | 0; - c[a >> 2] = c[h >> 2]; - c[h >> 2] = d; - d = (h + 4) | 0; - q = c[o >> 2] | 0; - c[o >> 2] = c[d >> 2]; - c[d >> 2] = q; - d = (h + 8) | 0; - q = c[n >> 2] | 0; - c[n >> 2] = c[d >> 2]; - c[d >> 2] = q; - d = (h + 12) | 0; - q = c[g >> 2] | 0; - c[g >> 2] = c[d >> 2]; - c[d >> 2] = q; - tg(h); - d = c[o >> 2] | 0; - break; - } - e = l; - a = (((((f - e) >> 2) + 1) | 0) / 2) | 0; - f = (l + (a << 2)) | 0; - e = (e - m) | 0; - d = (f + ((0 - (e >> 2)) << 2)) | 0; - if (!e) { - d = f; - e = f; - } - else { - vr(d | 0, m | 0, e | 0) | 0; - e = ((c[n >> 2] | 0) + (a << 2)) | 0; - } - c[o >> 2] = d; - c[n >> 2] = e; - } - else - d = m; - while (0); - c[(d + -4) >> 2] = c[b >> 2]; - c[o >> 2] = (c[o >> 2] | 0) + -4; - V = p; - return; - } - function tg(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = c[(a + 4) >> 2] | 0; - d = (a + 8) | 0; - e = c[d >> 2] | 0; - if ((e | 0) != (b | 0)) - c[d >> 2] = e + (~(((e + -4 - b) | 0) >>> 2) << 2); - b = c[a >> 2] | 0; - if (b | 0) - Da(b, ((c[(a + 12) >> 2] | 0) - b) | 0); - return; - } - function ug(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0, h = 0; - h = V; - V = (V + 16) | 0; - g = h; - f = c[b >> 2] | 0; - vg(g, (a + 8) | 0, ((c[d >> 2] | 0) - f) >> 2); - a = c[g >> 2] | 0; - e = (g + 4) | 0; - if ((a | 0) != (c[e >> 2] | 0)) { - d = f; - do { - c[a >> 2] = c[d >> 2]; - a = ((c[g >> 2] | 0) + 4) | 0; - c[g >> 2] = a; - d = (d + 4) | 0; - } while ((a | 0) != (c[e >> 2] | 0)); - c[b >> 2] = d; - } - wg(g); - V = h; - return; - } - function vg(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - c[a >> 2] = c[b >> 2]; - c[(a + 4) >> 2] = (c[b >> 2] | 0) + (d << 2); - c[(a + 8) >> 2] = b; - return; - } - function wg(a) { - a = a | 0; - c[c[(a + 8) >> 2] >> 2] = c[a >> 2]; - return; - } - function xg(a, b) { - a = a | 0; - b = b | 0; - return ((c[(a + 4) >> 2] | 0) == (c[(b + 4) >> 2] | 0)) | 0; - } - function yg(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - c[a >> 2] = b; - c[(a + 4) >> 2] = d; - return; - } - function zg(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0; - g = c[(b + 4) >> 2] | 0; - d = c[(b + 16) >> 2] | 0; - e = ((d >>> 0) / 93) | 0; - f = (g + (e << 2)) | 0; - if ((c[(b + 8) >> 2] | 0) == (g | 0)) - b = 0; - else - b = ((c[f >> 2] | 0) + ((((d - ((e * 93) | 0)) | 0) * 44) | 0)) | 0; - c[a >> 2] = f; - c[(a + 4) >> 2] = b; - return; - } - function Ag(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0; - d = ((c[(b + 16) >> 2] | 0) + (c[(b + 20) >> 2] | 0)) | 0; - g = c[(b + 4) >> 2] | 0; - e = ((d >>> 0) / 93) | 0; - f = (g + (e << 2)) | 0; - if ((c[(b + 8) >> 2] | 0) == (g | 0)) - b = 0; - else - b = ((c[f >> 2] | 0) + ((((d - ((e * 93) | 0)) | 0) * 44) | 0)) | 0; - c[a >> 2] = f; - c[(a + 4) >> 2] = b; - return; - } - function Bg(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0; - i = V; - V = (V + 16) | 0; - e = (i + 8) | 0; - g = i; - Cg(e, a); - fg(g, a); - f = (e + 4) | 0; - b = c[f >> 2] | 0; - g = (g + 4) | 0; - if ((b | 0) != (c[g >> 2] | 0)) - do { - Ic(b); - b = ((c[f >> 2] | 0) + 44) | 0; - c[f >> 2] = b; - d = c[e >> 2] | 0; - if (((b - (c[d >> 2] | 0)) | 0) == 4092) { - b = (d + 4) | 0; - c[e >> 2] = b; - b = c[b >> 2] | 0; - c[f >> 2] = b; - } - } while ((b | 0) != (c[g >> 2] | 0)); - c[(a + 20) >> 2] = 0; - f = (a + 8) | 0; - e = (a + 4) | 0; - d = c[e >> 2] | 0; - b = ((c[f >> 2] | 0) - d) >> 2; - if (b >>> 0 > 2) - do { - Da(c[d >> 2] | 0, 4092); - d = ((c[e >> 2] | 0) + 4) | 0; - c[e >> 2] = d; - b = ((c[f >> 2] | 0) - d) >> 2; - } while (b >>> 0 > 2); - switch (b | 0) { - case 1: { - b = 46; - h = 11; - break; - } - case 2: { - b = 93; - h = 11; - break; - } - default: { - } - } - if ((h | 0) == 11) - c[(a + 16) >> 2] = b; - V = i; - return; - } - function Cg(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0; - g = c[(b + 4) >> 2] | 0; - d = c[(b + 16) >> 2] | 0; - e = ((d >>> 0) / 93) | 0; - f = (g + (e << 2)) | 0; - if ((c[(b + 8) >> 2] | 0) == (g | 0)) - b = 0; - else - b = ((c[f >> 2] | 0) + ((((d - ((e * 93) | 0)) | 0) * 44) | 0)) | 0; - c[a >> 2] = f; - c[(a + 4) >> 2] = b; - return; - } - function Dg(b, e, f) { - b = b | 0; - e = e | 0; - f = f | 0; - var g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0; - m = V; - V = (V + 16) | 0; - l = m; - j = (b + 4) | 0; - if (!(a[j >> 0] | 0)) { - l = De(e) | 0; - Ee(l, f, c[b >> 2] | 0); - l = c[b >> 2] | 0; - i = (f + l) | 0; - if (!l) - g = 0; - else { - g = f; - h = c[(b + 8) >> 2] | 0; - while (1) { - a[h >> 0] = a[g >> 0] | 0; - g = (g + 1) | 0; - if ((g | 0) == (i | 0)) - break; - else - h = (h + 1) | 0; - } - g = c[b >> 2] | 0; - } - a[j >> 0] = 1; - f = (f + g) | 0; - } - else { - h = c[(b + 20) >> 2] | 0; - g = c[(b + 8) >> 2] | 0; - Cg(l, (b + 32) | 0); - b = (b + 12) | 0; - if ((g | 0) != (c[b >> 2] | 0)) { - k = (l + 4) | 0; - j = g; - i = h; - g = c[k >> 2] | 0; - while (1) { - h = d[j >> 0] | 0; - h = Eg(((Zc(e, g) | 0) + h) | 0) | 0; - a[i >> 0] = h; - a[f >> 0] = h; - a[j >> 0] = h; - j = (j + 1) | 0; - f = (f + 1) | 0; - h = c[l >> 2] | 0; - g = ((c[k >> 2] | 0) + 44) | 0; - c[k >> 2] = g; - if (((g - (c[h >> 2] | 0)) | 0) == 4092) { - g = (h + 4) | 0; - c[l >> 2] = g; - g = c[g >> 2] | 0; - c[k >> 2] = g; - } - if ((j | 0) == (c[b >> 2] | 0)) - break; - else - i = (i + 1) | 0; - } - } - } - V = m; - return f | 0; - } - function Eg(a) { - a = a | 0; - return (a & 255) | 0; - } - function Fg(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function Gg(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 4) >> 2] & 255](a); - return; - } - function Hg(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 11262 ? (a + 12) | 0 : 0) | 0; - } - function Ig(a) { - a = a | 0; - Da(a, 16); - return; - } - function Jg(a, b) { - a = a | 0; - b = b | 0; - c[a >> 2] = 0; - c[(a + 4) >> 2] = 0; - c[(a + 8) >> 2] = 0; - if (b | 0) { - Yf(a, b); - Lg(a, b); - } - return; - } - function Kg(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - c[a >> 2] = 0; - c[(a + 4) >> 2] = 0; - c[(a + 8) >> 2] = 0; - c[(a + 12) >> 2] = 0; - c[(a + 16) >> 2] = 0; - c[(a + 20) >> 2] = 0; - if (b | 0) - Mg(a, b, d); - return; - } - function Lg(b, d) { - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0; - g = V; - V = (V + 16) | 0; - f = g; - ag(f, b, d); - d = (f + 4) | 0; - b = c[d >> 2] | 0; - e = (f + 8) | 0; - if ((b | 0) != (c[e >> 2] | 0)) - do { - a[b >> 0] = 0; - b = ((c[d >> 2] | 0) + 1) | 0; - c[d >> 2] = b; - } while ((b | 0) != (c[e >> 2] | 0)); - bg(f); - V = g; - return; - } - function Mg(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0; - o = V; - V = (V + 96) | 0; - n = (o + 80) | 0; - k = (o + 64) | 0; - h = (o + 48) | 0; - i = (o + 40) | 0; - j = (o + 8) | 0; - f = o; - l = (o + 32) | 0; - m = (o + 16) | 0; - e = ((c[(a + 8) >> 2] | 0) - (c[(a + 4) >> 2] | 0)) | 0; - e = - (((e | 0) == 0 ? 0 : ((((e >> 2) * 93) | 0) + -1) | 0) - - ((c[(a + 20) >> 2] | 0) + (c[(a + 16) >> 2] | 0))) | - 0; - if (e >>> 0 < b >>> 0) - eg(a, (b - e) | 0); - fg(i, a); - fg(f, a); - e = c[f >> 2] | 0; - f = c[(f + 4) >> 2] | 0; - g = j; - c[g >> 2] = e; - c[(g + 4) >> 2] = f; - g = e; - if (b | 0) { - e = (((((f - (c[e >> 2] | 0)) | 0) / 44) | 0) + b) | 0; - if ((e | 0) > 0) { - b = ((e >>> 0) / 93) | 0; - g = (g + (b << 2)) | 0; - c[j >> 2] = g; - e = ((c[g >> 2] | 0) + ((((e - ((b * 93) | 0)) | 0) * 44) | 0)) | 0; - } - else { - e = (92 - e) | 0; - b = (g + ((((e | 0) / -93) | 0) << 2)) | 0; - c[j >> 2] = b; - e = ((c[b >> 2] | 0) + ((((92 - ((e | 0) % 93 | 0)) | 0) * 44) | 0)) | 0; - } - c[(j + 4) >> 2] = e; - } - c[k >> 2] = c[i >> 2]; - c[(k + 4) >> 2] = c[(i + 4) >> 2]; - c[n >> 2] = c[j >> 2]; - c[(n + 4) >> 2] = c[(j + 4) >> 2]; - gg(h, k, n); - hg(n, h); - ig(k, h); - if (jg(n, k) | 0) { - f = (m + 4) | 0; - do { - kg(l, n); - lg(m, a, l); - e = c[m >> 2] | 0; - if ((e | 0) != (c[f >> 2] | 0)) - do { - Wc(e, d); - e = ((c[m >> 2] | 0) + 44) | 0; - c[m >> 2] = e; - } while ((e | 0) != (c[f >> 2] | 0)); - mg(m); - ng(n) | 0; - } while (jg(n, k) | 0); - } - V = o; - return; - } - function Ng(a) { - a = a | 0; - var b = 0, d = 0; - Bg(a); - b = c[(a + 4) >> 2] | 0; - d = c[(a + 8) >> 2] | 0; - if ((b | 0) != (d | 0)) - do { - Da(c[b >> 2] | 0, 4092); - b = (b + 4) | 0; - } while ((b | 0) != (d | 0)); - dg(a); - return; - } - function Og(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - Md(a); - c[a >> 2] = 4924; - c[(a + 4) >> 2] = b; - c[(a + 8) >> 2] = d; - return; - } - function Pg(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 4944; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Wg(a, e); - V = d; - return; - } - function Qg(a, b) { - a = a | 0; - b = b | 0; - return Tg(c[(a + 8) >> 2] | 0, c[(a + 4) >> 2] | 0, b) | 0; - } - function Rg(a) { - a = a | 0; - var b = 0, d = 0; - c[a >> 2] = 4924; - d = (a + 8) | 0; - b = c[d >> 2] | 0; - c[d >> 2] = 0; - if (b | 0) { - Vg(b); - jp(b); - } - Qd(a); - return; - } - function Sg(a) { - a = a | 0; - Rg(a); - jp(a); - return; - } - function Tg(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - return Ug((a + 4784) | 0, b, Be(a, b, c) | 0) | 0; - } - function Ug(b, c, d) { - b = b | 0; - c = c | 0; - d = d | 0; - if (a[b >> 0] | 0) { - nc(c); - a[b >> 0] = 0; - } - return d | 0; - } - function Vg(a) { - a = a | 0; - ze(a); - return; - } - function Wg(a, b) { - a = a | 0; - b = b | 0; - return; - } - function Xg(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function Yg(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 8) >> 2] & 255](a); - return; - } - function Zg(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 12004 ? (a + 12) | 0 : 0) | 0; - } - function _g(a) { - a = a | 0; - Da(a, 16); - return; - } - function $g(b) { - b = b | 0; - a[b >> 0] = 1; - return; - } - function ah(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - Md(a); - c[a >> 2] = 4972; - c[(a + 4) >> 2] = b; - c[(a + 8) >> 2] = d; - return; - } - function bh(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 4992; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Wg(a, e); - V = d; - return; - } - function ch(a, b) { - a = a | 0; - b = b | 0; - return fh(c[(a + 8) >> 2] | 0, c[(a + 4) >> 2] | 0, b) | 0; - } - function dh(a) { - a = a | 0; - var b = 0, d = 0; - c[a >> 2] = 4972; - d = (a + 8) | 0; - b = c[d >> 2] | 0; - c[d >> 2] = 0; - if (b | 0) { - hh(b); - jp(b); - } - Qd(a); - return; - } - function eh(a) { - a = a | 0; - dh(a); - jp(a); - return; - } - function fh(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - return gh((a + 4784) | 0, b, Be(a, b, c) | 0) | 0; - } - function gh(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - return Ug((a + 328) | 0, b, qf(a, b, c) | 0) | 0; - } - function hh(a) { - a = a | 0; - ih((a + 4784) | 0); - ze(a); - return; - } - function ih(a) { - a = a | 0; - of(a); - return; - } - function jh(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function kh(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 8) >> 2] & 255](a); - return; - } - function lh(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 12827 ? (a + 12) | 0 : 0) | 0; - } - function mh(a) { - a = a | 0; - Da(a, 16); - return; - } - function nh(a) { - a = a | 0; - cf(a); - $g((a + 328) | 0); - return; - } - function oh(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - Md(a); - c[a >> 2] = 5020; - c[(a + 4) >> 2] = b; - c[(a + 8) >> 2] = d; - return; - } - function ph(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 5040; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Wg(a, e); - V = d; - return; - } - function qh(a, b) { - a = a | 0; - b = b | 0; - return th(c[(a + 8) >> 2] | 0, c[(a + 4) >> 2] | 0, b) | 0; - } - function rh(a) { - a = a | 0; - var b = 0, d = 0; - c[a >> 2] = 5020; - d = (a + 8) | 0; - b = c[d >> 2] | 0; - c[d >> 2] = 0; - if (b | 0) { - vh(b); - jp(b); - } - Qd(a); - return; - } - function sh(a) { - a = a | 0; - rh(a); - jp(a); - return; - } - function th(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - return uh((a + 4784) | 0, b, Be(a, b, c) | 0) | 0; - } - function uh(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - return Ug((a + 316) | 0, b, If(a, b, c) | 0) | 0; - } - function vh(a) { - a = a | 0; - wh((a + 4784) | 0); - ze(a); - return; - } - function wh(a) { - a = a | 0; - Hf(a); - return; - } - function xh(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function yh(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 8) >> 2] & 255](a); - return; - } - function zh(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 13672 ? (a + 12) | 0 : 0) | 0; - } - function Ah(a) { - a = a | 0; - Da(a, 16); - return; - } - function Bh(a) { - a = a | 0; - Cf(a); - $g((a + 316) | 0); - return; - } - function Ch(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - Md(a); - c[a >> 2] = 5068; - c[(a + 4) >> 2] = b; - c[(a + 8) >> 2] = d; - return; - } - function Dh(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 5088; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Wg(a, e); - V = d; - return; - } - function Eh(a, b) { - a = a | 0; - b = b | 0; - return Hh(c[(a + 8) >> 2] | 0, c[(a + 4) >> 2] | 0, b) | 0; - } - function Fh(a) { - a = a | 0; - var b = 0, d = 0; - c[a >> 2] = 5068; - d = (a + 8) | 0; - b = c[d >> 2] | 0; - c[d >> 2] = 0; - if (b | 0) { - Jh(b); - jp(b); - } - Qd(a); - return; - } - function Gh(a) { - a = a | 0; - Fh(a); - jp(a); - return; - } - function Hh(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - return Ih((a + 4784) | 0, b, Be(a, b, c) | 0) | 0; - } - function Ih(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - return uh((a + 328) | 0, b, qf(a, b, c) | 0) | 0; - } - function Jh(a) { - a = a | 0; - Kh((a + 4784) | 0); - ze(a); - return; - } - function Kh(a) { - a = a | 0; - wh((a + 328) | 0); - of(a); - return; - } - function Lh(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function Mh(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 8) >> 2] & 255](a); - return; - } - function Nh(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 14573 ? (a + 12) | 0 : 0) | 0; - } - function Oh(a) { - a = a | 0; - Da(a, 16); - return; - } - function Ph(a) { - a = a | 0; - cf(a); - Bh((a + 328) | 0); - return; - } - function Qh(a) { - a = a | 0; - return (a + 20) | 0; - } - function Rh(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - c[a >> 2] = b; - c[(a + 4) >> 2] = d; - c[(a + 8) >> 2] = 0; - return; - } - function Sh(a, b) { - a = a | 0; - b = b | 0; - c[a >> 2] = b; - c[(a + 4) >> 2] = 0; - c[(a + 8) >> 2] = -1; - return; - } - function Th(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0; - d = V; - V = (V + 16) | 0; - e = (d + 4) | 0; - g = d; - f = eq(24) | 0; - ii(f, b); - c[g >> 2] = 0; - c[e >> 2] = c[g >> 2]; - ji(a, f, e); - V = d; - return; - } - function Uh(a) { - a = a | 0; - var b = 0, d = 0; - a = c[(a + 4) >> 2] | 0; - if (a | 0 ? ((d = (a + 4) | 0), (b = c[d >> 2] | 0), (c[d >> 2] = b + -1), (b | 0) == 0) : 0) { - ca[c[((c[a >> 2] | 0) + 8) >> 2] & 255](a); - qq(a); - } - return; - } - function Vh(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 5116; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Xh(a, e); - V = d; - return; - } - function Wh(a) { - a = a | 0; - var b = 0, d = 0; - a = c[(a + 4) >> 2] | 0; - if (a | 0 ? ((d = (a + 4) | 0), (b = c[d >> 2] | 0), (c[d >> 2] = b + -1), (b | 0) == 0) : 0) { - ca[c[((c[a >> 2] | 0) + 8) >> 2] & 255](a); - qq(a); - } - return; - } - function Xh(a, b) { - a = a | 0; - b = b | 0; - return; - } - function Yh(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function Zh(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - jp(a); - return; - } - function _h(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 14966 ? (a + 12) | 0 : 0) | 0; - } - function $h(a) { - a = a | 0; - Da(a, 16); - return; - } - function ai(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 5144; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - ci(a, e); - V = d; - return; - } - function bi(a) { - a = a | 0; - var b = 0, d = 0; - a = c[(a + 4) >> 2] | 0; - if (a | 0 ? ((d = (a + 4) | 0), (b = c[d >> 2] | 0), (c[d >> 2] = b + -1), (b | 0) == 0) : 0) { - ca[c[((c[a >> 2] | 0) + 8) >> 2] & 255](a); - qq(a); - } - return; - } - function ci(a, b) { - a = a | 0; - b = b | 0; - return; - } - function di(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function ei(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) { - hi(a); - jp(a); - } - return; - } - function fi(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 15127 ? (a + 12) | 0 : 0) | 0; - } - function gi(a) { - a = a | 0; - Da(a, 16); - return; - } - function hi(a) { - a = a | 0; - return; - } - function ii(b, d) { - b = b | 0; - d = d | 0; - Md(b); - c[b >> 2] = 5172; - c[(b + 4) >> 2] = d; - c[(b + 8) >> 2] = 0; - c[(b + 12) >> 2] = 0; - c[(b + 16) >> 2] = 0; - a[(b + 20) >> 0] = 1; - return; - } - function ji(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 5192; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - pi(a, e); - V = d; - return; - } - function ki(b, d) { - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0; - k = V; - V = (V + 16) | 0; - h = k; - e = c[(b + 8) >> 2] | 0; - i = c[(b + 12) >> 2] | 0; - if ((e | 0) != (i | 0)) { - j = (h + 4) | 0; - do { - f = c[e >> 2] | 0; - c[h >> 2] = f; - g = c[(e + 4) >> 2] | 0; - c[j >> 2] = g; - if (g | 0) { - g = (g + 4) | 0; - c[g >> 2] = (c[g >> 2] | 0) + 1; - } - d = $[c[((c[f >> 2] | 0) + 12) >> 2] & 63](f, d) | 0; - Sd(h); - e = (e + 8) | 0; - } while ((e | 0) != (i | 0)); - } - e = (b + 20) | 0; - if (a[e >> 0] | 0) { - a[e >> 0] = 0; - ni(c[(b + 4) >> 2] | 0); - } - V = k; - return d | 0; - } - function li(a) { - a = a | 0; - c[a >> 2] = 5172; - Td((a + 8) | 0); - Qd(a); - return; - } - function mi(a) { - a = a | 0; - li(a); - jp(a); - return; - } - function ni(a) { - a = a | 0; - var b = 0; - b = ((oi(c[a >> 2] | 0) | 0) & 255) << 24; - b = (((oi(c[a >> 2] | 0) | 0) & 255) << 16) | b; - b = b | (((oi(c[a >> 2] | 0) | 0) & 255) << 8); - c[(a + 4) >> 2] = b | ((oi(c[a >> 2] | 0) | 0) & 255); - return; - } - function oi(b) { - b = b | 0; - var d = 0, e = 0; - d = c[b >> 2] | 0; - e = (b + 8) | 0; - b = c[e >> 2] | 0; - c[e >> 2] = b + 1; - return a[(d + b) >> 0] | 0; - } - function pi(a, b) { - a = a | 0; - b = b | 0; - return; - } - function qi(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function ri(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 8) >> 2] & 255](a); - return; - } - function si(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 15450 ? (a + 12) | 0 : 0) | 0; - } - function ti(a) { - a = a | 0; - Da(a, 16); - return; - } - function ui(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0; - j = V; - V = (V + 32) | 0; - e = (j + 12) | 0; - f = j; - b = (j + 8) | 0; - h = eq(180) | 0; - wi(h, c[(a + 4) >> 2] | 0); - g = (a + 8) | 0; - c[b >> 2] = 0; - c[e >> 2] = c[b >> 2]; - xi(f, h, e); - h = (a + 12) | 0; - b = c[h >> 2] | 0; - i = (a + 16) | 0; - do - if (b >>> 0 >= (c[i >> 2] | 0) >>> 0) { - b = (((b - (c[g >> 2] | 0)) >> 3) + 1) | 0; - d = ee(g) | 0; - if (d >>> 0 < b >>> 0) - cr(g); - else { - k = c[g >> 2] | 0; - l = ((c[i >> 2] | 0) - k) | 0; - i = l >> 2; - be(e, (l >> 3) >>> 0 < (d >>> 1) >>> 0 ? (i >>> 0 < b >>> 0 ? b : i) : d, ((c[h >> 2] | 0) - k) >> 3, (a + 16) | 0); - i = (e + 8) | 0; - h = c[i >> 2] | 0; - c[h >> 2] = c[f >> 2]; - a = (f + 4) | 0; - c[(h + 4) >> 2] = c[a >> 2]; - c[f >> 2] = 0; - c[a >> 2] = 0; - c[i >> 2] = h + 8; - ce(g, e); - de(e); - break; - } - } - else { - $d(e, g, 1); - l = (e + 4) | 0; - k = c[l >> 2] | 0; - c[k >> 2] = c[f >> 2]; - i = (f + 4) | 0; - c[(k + 4) >> 2] = c[i >> 2]; - c[f >> 2] = 0; - c[i >> 2] = 0; - c[l >> 2] = k + 8; - ae(e); - } - while (0); - Sd(f); - V = j; - return; - } - function vi(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0; - j = V; - V = (V + 32) | 0; - e = (j + 12) | 0; - f = j; - b = (j + 8) | 0; - h = eq(180) | 0; - Ui(h, c[(a + 4) >> 2] | 0); - g = (a + 8) | 0; - c[b >> 2] = 0; - c[e >> 2] = c[b >> 2]; - Vi(f, h, e); - h = (a + 12) | 0; - b = c[h >> 2] | 0; - i = (a + 16) | 0; - do - if (b >>> 0 >= (c[i >> 2] | 0) >>> 0) { - b = (((b - (c[g >> 2] | 0)) >> 3) + 1) | 0; - d = ee(g) | 0; - if (d >>> 0 < b >>> 0) - cr(g); - else { - k = c[g >> 2] | 0; - l = ((c[i >> 2] | 0) - k) | 0; - i = l >> 2; - be(e, (l >> 3) >>> 0 < (d >>> 1) >>> 0 ? (i >>> 0 < b >>> 0 ? b : i) : d, ((c[h >> 2] | 0) - k) >> 3, (a + 16) | 0); - i = (e + 8) | 0; - h = c[i >> 2] | 0; - c[h >> 2] = c[f >> 2]; - a = (f + 4) | 0; - c[(h + 4) >> 2] = c[a >> 2]; - c[f >> 2] = 0; - c[a >> 2] = 0; - c[i >> 2] = h + 8; - ce(g, e); - de(e); - break; - } - } - else { - $d(e, g, 1); - l = (e + 4) | 0; - k = c[l >> 2] | 0; - c[k >> 2] = c[f >> 2]; - i = (f + 4) | 0; - c[(k + 4) >> 2] = c[i >> 2]; - c[f >> 2] = 0; - c[i >> 2] = 0; - c[l >> 2] = k + 8; - ae(e); - } - while (0); - Sd(f); - V = j; - return; - } - function wi(a, b) { - a = a | 0; - b = b | 0; - fe(a); - c[a >> 2] = 5220; - c[(a + 4) >> 2] = b; - yi((a + 8) | 0); - return; - } - function xi(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 5244; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Xe(a, e); - V = d; - return; - } - function yi(b) { - b = b | 0; - xe(b, 32, 1, 8, 0); - mc((b + 80) | 0, 32, 1, 8, 0); - a[(b + 160) >> 0] = 0; - a[(b + 161) >> 0] = 0; - Ci((b + 164) | 0); - return; - } - function zi(a) { - a = a | 0; - c[a >> 2] = 5220; - Di((a + 8) | 0); - le(a); - return; - } - function Ai(a) { - a = a | 0; - zi(a); - jp(a); - return; - } - function Bi(a, b) { - a = a | 0; - b = b | 0; - return Ei((a + 8) | 0, c[(a + 4) >> 2] | 0, b) | 0; - } - function Ci(b) { - b = b | 0; - a[(b + 4) >> 0] = 0; - return; - } - function Di(a) { - a = a | 0; - qc((a + 80) | 0); - ye(a); - return; - } - function Ei(b, d, e) { - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0, h = 0; - h = V; - V = (V + 16) | 0; - f = h; - if (!(a[(b + 161) >> 0] | 0)) - oc((b + 80) | 0); - g = (b + 164) | 0; - if (Fi(g) | 0) { - d = Gi((b + 80) | 0, d, c[g >> 2] | 0, 0) | 0; - c[f >> 2] = d; - Se(d, e); - } - else { - Ii(Hi(d) | 0, e, 4); - c[f >> 2] = Ne(e) | 0; - } - Ji(g, f); - V = h; - return (e + 4) | 0; - } - function Fi(b) { - b = b | 0; - return ((a[(b + 4) >> 0] | 0) != 0) | 0; - } - function Gi(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - d = ((Ki(a, b, ((c[(a + 36) >> 2] | 0) + ((e * 44) | 0)) | 0) | 0) + d) | 0; - b = c[(a + 24) >> 2] | 0; - if ((d | 0) < 0) - return (d + b) | 0; - else - return (d - (d >>> 0 < b >>> 0 ? 0 : b)) | 0; - return 0; - } - function Hi(a) { - a = a | 0; - return c[a >> 2] | 0; - } - function Ii(b, c, d) { - b = b | 0; - c = c | 0; - d = d | 0; - var e = 0; - if ((d | 0) > 0) { - e = 0; - do { - a[(c + e) >> 0] = oi(b) | 0; - e = (e + 1) | 0; - } while ((e | 0) != (d | 0)); - } - return; - } - function Ji(b, d) { - b = b | 0; - d = d | 0; - var e = 0; - e = (b + 4) | 0; - if (!(a[e >> 0] | 0)) - a[e >> 0] = 1; - c[b >> 2] = c[d >> 2]; - return; - } - function Ki(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0; - d = Li(b, d) | 0; - c[a >> 2] = d; - do - if (d) { - if (d >>> 0 >= 32) { - d = c[(a + 28) >> 2] | 0; - break; - } - e = c[(a + 12) >> 2] | 0; - if (d >>> 0 > e >>> 0) { - e = (d - e) | 0; - d = Li(b, ((c[(a + 68) >> 2] | 0) + ((((d + -1) | 0) * 44) | 0)) | 0) | 0; - e = (d << e) | (Mi(b, e) | 0); - } - else - e = Li(b, ((c[(a + 68) >> 2] | 0) + ((((d + -1) | 0) * 44) | 0)) | 0) | 0; - d = c[a >> 2] | 0; - if ((e | 0) < ((1 << (d + -1)) | 0)) { - d = (e + 1 + (-1 << d)) | 0; - break; - } - else { - d = (e + 1) | 0; - break; - } - } - else - d = Ni(b, (a + 48) | 0) | 0; - while (0); - return d | 0; - } - function Li(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0; - n = (a + 8) | 0; - m = c[n >> 2] | 0; - f = c[(b + 16) >> 2] | 0; - if (f) { - e = (a + 4) | 0; - d = c[e >> 2] | 0; - l = m >>> 15; - c[n >> 2] = l; - j = ((d >>> 0) / (l >>> 0)) | 0; - i = j >>> (c[(b + 40) >> 2] | 0); - g = c[(f + (i << 2)) >> 2] | 0; - i = ((c[(f + ((i + 1) << 2)) >> 2] | 0) + 1) | 0; - h = (g + 1) | 0; - k = c[(b + 8) >> 2] | 0; - if (i >>> 0 > h >>> 0) { - f = g; - g = i; - do { - h = ((g + f) | 0) >>> 1; - i = (c[(k + (h << 2)) >> 2] | 0) >>> 0 > j >>> 0; - f = i ? f : h; - g = i ? h : g; - h = (f + 1) | 0; - } while (g >>> 0 > h >>> 0); - g = f; - } - f = q(c[(k + (g << 2)) >> 2] | 0, l) | 0; - if ((g | 0) == (c[(b + 32) >> 2] | 0)) - h = m; - else - h = q(c[(k + (h << 2)) >> 2] | 0, l) | 0; - } - else { - k = m >>> 15; - c[n >> 2] = k; - i = c[b >> 2] | 0; - l = c[(b + 8) >> 2] | 0; - e = (a + 4) | 0; - d = c[e >> 2] | 0; - j = i >>> 1; - f = 0; - h = m; - g = 0; - do { - o = q(c[(l + (j << 2)) >> 2] | 0, k) | 0; - m = o >>> 0 > d >>> 0; - h = m ? o : h; - f = m ? f : o; - g = m ? g : j; - i = m ? j : i; - j = ((g + i) | 0) >>> 1; - } while ((j | 0) != (g | 0)); - } - c[e >> 2] = d - f; - o = (h - f) | 0; - c[n >> 2] = o; - if (o >>> 0 < 16777216) - Oi(a); - n = ((c[(b + 12) >> 2] | 0) + (g << 2)) | 0; - c[n >> 2] = (c[n >> 2] | 0) + 1; - n = (b + 28) | 0; - o = ((c[n >> 2] | 0) + -1) | 0; - c[n >> 2] = o; - if (!o) - Xc(b); - return g | 0; - } - function Mi(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0; - if (b >>> 0 > 19) { - d = (Pi(a) | 0) & 65535; - return ((Mi(a, (b + -16) | 0) | 0) << 16) | d | 0; - } - e = (a + 4) | 0; - f = c[e >> 2] | 0; - g = (a + 8) | 0; - d = (c[g >> 2] | 0) >>> b; - c[g >> 2] = d; - b = ((f >>> 0) / (d >>> 0)) | 0; - c[e >> 2] = f - (q(b, d) | 0); - if (d >>> 0 < 16777216) - Oi(a); - return b | 0; - } - function Ni(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0, i = 0; - e = (a + 8) | 0; - f = c[e >> 2] | 0; - d = q(f >>> 13, c[(b + 8) >> 2] | 0) | 0; - g = (a + 4) | 0; - h = c[g >> 2] | 0; - i = h >>> 0 >= d >>> 0; - if (i) { - c[g >> 2] = h - d; - d = (f - d) | 0; - c[e >> 2] = d; - } - else { - c[e >> 2] = d; - h = (b + 12) | 0; - c[h >> 2] = (c[h >> 2] | 0) + 1; - } - if (d >>> 0 < 16777216) - Oi(a); - h = (b + 4) | 0; - a = ((c[h >> 2] | 0) + -1) | 0; - c[h >> 2] = a; - if (!a) - cd(b); - return (i & 1) | 0; - } - function Oi(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0; - b = (a + 4) | 0; - d = (a + 8) | 0; - e = c[b >> 2] | 0; - do { - e = (e << 8) | ((oi(c[a >> 2] | 0) | 0) & 255); - c[b >> 2] = e; - f = c[d >> 2] << 8; - c[d >> 2] = f; - } while (f >>> 0 < 16777216); - return; - } - function Pi(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0; - d = (a + 4) | 0; - f = c[d >> 2] | 0; - b = (a + 8) | 0; - e = (c[b >> 2] | 0) >>> 16; - c[b >> 2] = e; - b = ((f >>> 0) / (e >>> 0)) | 0; - c[d >> 2] = f - (q(b, e) | 0); - Oi(a); - return (b & 65535) | 0; - } - function Qi(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function Ri(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 4) >> 2] & 255](a); - return; - } - function Si(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 15904 ? (a + 12) | 0 : 0) | 0; - } - function Ti(a) { - a = a | 0; - Da(a, 16); - return; - } - function Ui(a, b) { - a = a | 0; - b = b | 0; - fe(a); - c[a >> 2] = 5272; - c[(a + 4) >> 2] = b; - Wi((a + 8) | 0); - return; - } - function Vi(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 5296; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Xe(a, e); - V = d; - return; - } - function Wi(b) { - b = b | 0; - xe(b, 32, 1, 8, 0); - mc((b + 80) | 0, 32, 1, 8, 0); - a[(b + 160) >> 0] = 0; - a[(b + 161) >> 0] = 0; - _i((b + 164) | 0); - return; - } - function Xi(a) { - a = a | 0; - c[a >> 2] = 5272; - $i((a + 8) | 0); - le(a); - return; - } - function Yi(a) { - a = a | 0; - Xi(a); - jp(a); - return; - } - function Zi(a, b) { - a = a | 0; - b = b | 0; - return aj((a + 8) | 0, c[(a + 4) >> 2] | 0, b) | 0; - } - function _i(b) { - b = b | 0; - a[(b + 4) >> 0] = 0; - return; - } - function $i(a) { - a = a | 0; - qc((a + 80) | 0); - ye(a); - return; - } - function aj(b, d, e) { - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0, h = 0; - h = V; - V = (V + 16) | 0; - f = h; - if (!(a[(b + 161) >> 0] | 0)) - oc((b + 80) | 0); - g = (b + 164) | 0; - if (bj(g) | 0) { - d = Gi((b + 80) | 0, d, c[g >> 2] | 0, 0) | 0; - c[f >> 2] = d; - We(d, e); - } - else { - Ii(Hi(d) | 0, e, 4); - c[f >> 2] = Re(e) | 0; - } - cj(g, f); - V = h; - return (e + 4) | 0; - } - function bj(b) { - b = b | 0; - return ((a[(b + 4) >> 0] | 0) != 0) | 0; - } - function cj(b, d) { - b = b | 0; - d = d | 0; - var e = 0; - e = (b + 4) | 0; - if (!(a[e >> 0] | 0)) - a[e >> 0] = 1; - c[b >> 2] = c[d >> 2]; - return; - } - function dj(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function ej(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 4) >> 2] & 255](a); - return; - } - function fj(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 16402 ? (a + 12) | 0 : 0) | 0; - } - function gj(a) { - a = a | 0; - Da(a, 16); - return; - } - function hj(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0; - j = V; - V = (V + 32) | 0; - e = (j + 12) | 0; - f = j; - b = (j + 8) | 0; - h = eq(172) | 0; - jj(h, c[(a + 4) >> 2] | 0); - g = (a + 8) | 0; - c[b >> 2] = 0; - c[e >> 2] = c[b >> 2]; - kj(f, h, e); - h = (a + 12) | 0; - b = c[h >> 2] | 0; - i = (a + 16) | 0; - do - if (b >>> 0 >= (c[i >> 2] | 0) >>> 0) { - b = (((b - (c[g >> 2] | 0)) >> 3) + 1) | 0; - d = ee(g) | 0; - if (d >>> 0 < b >>> 0) - cr(g); - else { - k = c[g >> 2] | 0; - l = ((c[i >> 2] | 0) - k) | 0; - i = l >> 2; - be(e, (l >> 3) >>> 0 < (d >>> 1) >>> 0 ? (i >>> 0 < b >>> 0 ? b : i) : d, ((c[h >> 2] | 0) - k) >> 3, (a + 16) | 0); - i = (e + 8) | 0; - h = c[i >> 2] | 0; - c[h >> 2] = c[f >> 2]; - a = (f + 4) | 0; - c[(h + 4) >> 2] = c[a >> 2]; - c[f >> 2] = 0; - c[a >> 2] = 0; - c[i >> 2] = h + 8; - ce(g, e); - de(e); - break; - } - } - else { - $d(e, g, 1); - l = (e + 4) | 0; - k = c[l >> 2] | 0; - c[k >> 2] = c[f >> 2]; - i = (f + 4) | 0; - c[(k + 4) >> 2] = c[i >> 2]; - c[f >> 2] = 0; - c[i >> 2] = 0; - c[l >> 2] = k + 8; - ae(e); - } - while (0); - Sd(f); - V = j; - return; - } - function ij(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0; - j = V; - V = (V + 32) | 0; - e = (j + 12) | 0; - f = j; - b = (j + 8) | 0; - h = eq(176) | 0; - Aj(h, c[(a + 4) >> 2] | 0); - g = (a + 8) | 0; - c[b >> 2] = 0; - c[e >> 2] = c[b >> 2]; - Bj(f, h, e); - h = (a + 12) | 0; - b = c[h >> 2] | 0; - i = (a + 16) | 0; - do - if (b >>> 0 >= (c[i >> 2] | 0) >>> 0) { - b = (((b - (c[g >> 2] | 0)) >> 3) + 1) | 0; - d = ee(g) | 0; - if (d >>> 0 < b >>> 0) - cr(g); - else { - k = c[g >> 2] | 0; - l = ((c[i >> 2] | 0) - k) | 0; - i = l >> 2; - be(e, (l >> 3) >>> 0 < (d >>> 1) >>> 0 ? (i >>> 0 < b >>> 0 ? b : i) : d, ((c[h >> 2] | 0) - k) >> 3, (a + 16) | 0); - i = (e + 8) | 0; - h = c[i >> 2] | 0; - c[h >> 2] = c[f >> 2]; - a = (f + 4) | 0; - c[(h + 4) >> 2] = c[a >> 2]; - c[f >> 2] = 0; - c[a >> 2] = 0; - c[i >> 2] = h + 8; - ce(g, e); - de(e); - break; - } - } - else { - $d(e, g, 1); - l = (e + 4) | 0; - k = c[l >> 2] | 0; - c[k >> 2] = c[f >> 2]; - i = (f + 4) | 0; - c[(k + 4) >> 2] = c[i >> 2]; - c[f >> 2] = 0; - c[i >> 2] = 0; - c[l >> 2] = k + 8; - ae(e); - } - while (0); - Sd(f); - V = j; - return; - } - function jj(a, b) { - a = a | 0; - b = b | 0; - fe(a); - c[a >> 2] = 5324; - c[(a + 4) >> 2] = b; - lj((a + 8) | 0); - return; - } - function kj(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 5348; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Xe(a, e); - V = d; - return; - } - function lj(b) { - b = b | 0; - xe(b, 8, 1, 8, 0); - mc((b + 80) | 0, 8, 1, 8, 0); - a[(b + 160) >> 0] = 0; - a[(b + 161) >> 0] = 0; - pj((b + 162) | 0); - return; - } - function mj(a) { - a = a | 0; - c[a >> 2] = 5324; - qj((a + 8) | 0); - le(a); - return; - } - function nj(a) { - a = a | 0; - mj(a); - jp(a); - return; - } - function oj(a, b) { - a = a | 0; - b = b | 0; - return rj((a + 8) | 0, c[(a + 4) >> 2] | 0, b) | 0; - } - function pj(b) { - b = b | 0; - a[(b + 1) >> 0] = 0; - return; - } - function qj(a) { - a = a | 0; - qc((a + 80) | 0); - ye(a); - return; - } - function rj(b, c, d) { - b = b | 0; - c = c | 0; - d = d | 0; - var e = 0, f = 0, g = 0; - g = V; - V = (V + 16) | 0; - e = g; - if (!(a[(b + 161) >> 0] | 0)) - oc((b + 80) | 0); - f = (b + 162) | 0; - if (sj(f) | 0) { - c = (Gi((b + 80) | 0, c, a[f >> 0] | 0, 0) | 0) & 255; - a[e >> 0] = c; - tj(c, d); - } - else { - Ii(Hi(c) | 0, d, 1); - a[e >> 0] = uj(d) | 0; - } - vj(f, e); - V = g; - return (d + 1) | 0; - } - function sj(b) { - b = b | 0; - return ((a[(b + 1) >> 0] | 0) != 0) | 0; - } - function tj(b, c) { - b = b | 0; - c = c | 0; - a[c >> 0] = b; - return; - } - function uj(b) { - b = b | 0; - return a[b >> 0] | 0; - } - function vj(b, c) { - b = b | 0; - c = c | 0; - var d = 0; - d = (b + 1) | 0; - if (!(a[d >> 0] | 0)) - a[d >> 0] = 1; - a[b >> 0] = a[c >> 0] | 0; - return; - } - function wj(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function xj(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 4) >> 2] & 255](a); - return; - } - function yj(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 16900 ? (a + 12) | 0 : 0) | 0; - } - function zj(a) { - a = a | 0; - Da(a, 16); - return; - } - function Aj(a, b) { - a = a | 0; - b = b | 0; - fe(a); - c[a >> 2] = 5376; - c[(a + 4) >> 2] = b; - Cj((a + 8) | 0); - return; - } - function Bj(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 5400; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Xe(a, e); - V = d; - return; - } - function Cj(b) { - b = b | 0; - xe(b, 16, 1, 8, 0); - mc((b + 80) | 0, 16, 1, 8, 0); - a[(b + 160) >> 0] = 0; - a[(b + 161) >> 0] = 0; - Gj((b + 162) | 0); - return; - } - function Dj(a) { - a = a | 0; - c[a >> 2] = 5376; - Hj((a + 8) | 0); - le(a); - return; - } - function Ej(a) { - a = a | 0; - Dj(a); - jp(a); - return; - } - function Fj(a, b) { - a = a | 0; - b = b | 0; - return Ij((a + 8) | 0, c[(a + 4) >> 2] | 0, b) | 0; - } - function Gj(b) { - b = b | 0; - a[(b + 2) >> 0] = 0; - return; - } - function Hj(a) { - a = a | 0; - qc((a + 80) | 0); - ye(a); - return; - } - function Ij(c, d, e) { - c = c | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0, h = 0; - h = V; - V = (V + 16) | 0; - f = h; - if (!(a[(c + 161) >> 0] | 0)) - oc((c + 80) | 0); - g = (c + 162) | 0; - if (Jj(g) | 0) { - d = (Gi((c + 80) | 0, d, b[g >> 1] | 0, 0) | 0) & 65535; - b[f >> 1] = d; - Kj(d, e); - } - else { - Ii(Hi(d) | 0, e, 2); - b[f >> 1] = Lj(e) | 0; - } - Mj(g, f); - V = h; - return (e + 2) | 0; - } - function Jj(b) { - b = b | 0; - return ((a[(b + 2) >> 0] | 0) != 0) | 0; - } - function Kj(a, b) { - a = a | 0; - b = b | 0; - Te(a, b); - return; - } - function Lj(a) { - a = a | 0; - return Oe(a) | 0; - } - function Mj(c, d) { - c = c | 0; - d = d | 0; - var e = 0; - e = (c + 2) | 0; - if (!(a[e >> 0] | 0)) - a[e >> 0] = 1; - b[c >> 1] = b[d >> 1] | 0; - return; - } - function Nj(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function Oj(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 4) >> 2] & 255](a); - return; - } - function Pj(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 17398 ? (a + 12) | 0 : 0) | 0; - } - function Qj(a) { - a = a | 0; - Da(a, 16); - return; - } - function Rj(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0; - j = V; - V = (V + 32) | 0; - e = (j + 12) | 0; - f = j; - b = (j + 8) | 0; - h = eq(172) | 0; - Tj(h, c[(a + 4) >> 2] | 0); - g = (a + 8) | 0; - c[b >> 2] = 0; - c[e >> 2] = c[b >> 2]; - Uj(f, h, e); - h = (a + 12) | 0; - b = c[h >> 2] | 0; - i = (a + 16) | 0; - do - if (b >>> 0 >= (c[i >> 2] | 0) >>> 0) { - b = (((b - (c[g >> 2] | 0)) >> 3) + 1) | 0; - d = ee(g) | 0; - if (d >>> 0 < b >>> 0) - cr(g); - else { - k = c[g >> 2] | 0; - l = ((c[i >> 2] | 0) - k) | 0; - i = l >> 2; - be(e, (l >> 3) >>> 0 < (d >>> 1) >>> 0 ? (i >>> 0 < b >>> 0 ? b : i) : d, ((c[h >> 2] | 0) - k) >> 3, (a + 16) | 0); - i = (e + 8) | 0; - h = c[i >> 2] | 0; - c[h >> 2] = c[f >> 2]; - a = (f + 4) | 0; - c[(h + 4) >> 2] = c[a >> 2]; - c[f >> 2] = 0; - c[a >> 2] = 0; - c[i >> 2] = h + 8; - ce(g, e); - de(e); - break; - } - } - else { - $d(e, g, 1); - l = (e + 4) | 0; - k = c[l >> 2] | 0; - c[k >> 2] = c[f >> 2]; - i = (f + 4) | 0; - c[(k + 4) >> 2] = c[i >> 2]; - c[f >> 2] = 0; - c[i >> 2] = 0; - c[l >> 2] = k + 8; - ae(e); - } - while (0); - Sd(f); - V = j; - return; - } - function Sj(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0; - j = V; - V = (V + 32) | 0; - e = (j + 12) | 0; - f = j; - b = (j + 8) | 0; - h = eq(176) | 0; - gk(h, c[(a + 4) >> 2] | 0); - g = (a + 8) | 0; - c[b >> 2] = 0; - c[e >> 2] = c[b >> 2]; - hk(f, h, e); - h = (a + 12) | 0; - b = c[h >> 2] | 0; - i = (a + 16) | 0; - do - if (b >>> 0 >= (c[i >> 2] | 0) >>> 0) { - b = (((b - (c[g >> 2] | 0)) >> 3) + 1) | 0; - d = ee(g) | 0; - if (d >>> 0 < b >>> 0) - cr(g); - else { - k = c[g >> 2] | 0; - l = ((c[i >> 2] | 0) - k) | 0; - i = l >> 2; - be(e, (l >> 3) >>> 0 < (d >>> 1) >>> 0 ? (i >>> 0 < b >>> 0 ? b : i) : d, ((c[h >> 2] | 0) - k) >> 3, (a + 16) | 0); - i = (e + 8) | 0; - h = c[i >> 2] | 0; - c[h >> 2] = c[f >> 2]; - a = (f + 4) | 0; - c[(h + 4) >> 2] = c[a >> 2]; - c[f >> 2] = 0; - c[a >> 2] = 0; - c[i >> 2] = h + 8; - ce(g, e); - de(e); - break; - } - } - else { - $d(e, g, 1); - l = (e + 4) | 0; - k = c[l >> 2] | 0; - c[k >> 2] = c[f >> 2]; - i = (f + 4) | 0; - c[(k + 4) >> 2] = c[i >> 2]; - c[f >> 2] = 0; - c[i >> 2] = 0; - c[l >> 2] = k + 8; - ae(e); - } - while (0); - Sd(f); - V = j; - return; - } - function Tj(a, b) { - a = a | 0; - b = b | 0; - fe(a); - c[a >> 2] = 5428; - c[(a + 4) >> 2] = b; - Vj((a + 8) | 0); - return; - } - function Uj(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 5452; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Xe(a, e); - V = d; - return; - } - function Vj(b) { - b = b | 0; - xe(b, 8, 1, 8, 0); - mc((b + 80) | 0, 8, 1, 8, 0); - a[(b + 160) >> 0] = 0; - a[(b + 161) >> 0] = 0; - Zj((b + 162) | 0); - return; - } - function Wj(a) { - a = a | 0; - c[a >> 2] = 5428; - _j((a + 8) | 0); - le(a); - return; - } - function Xj(a) { - a = a | 0; - Wj(a); - jp(a); - return; - } - function Yj(a, b) { - a = a | 0; - b = b | 0; - return $j((a + 8) | 0, c[(a + 4) >> 2] | 0, b) | 0; - } - function Zj(b) { - b = b | 0; - a[(b + 1) >> 0] = 0; - return; - } - function _j(a) { - a = a | 0; - qc((a + 80) | 0); - ye(a); - return; - } - function $j(b, c, e) { - b = b | 0; - c = c | 0; - e = e | 0; - var f = 0, g = 0, h = 0; - h = V; - V = (V + 16) | 0; - f = h; - if (!(a[(b + 161) >> 0] | 0)) - oc((b + 80) | 0); - g = (b + 162) | 0; - if (ak(g) | 0) { - c = (Gi((b + 80) | 0, c, d[g >> 0] | 0, 0) | 0) & 255; - a[f >> 0] = c; - Ue(c, e); - } - else { - Ii(Hi(c) | 0, e, 1); - a[f >> 0] = Pe(e) | 0; - } - bk(g, f); - V = h; - return (e + 1) | 0; - } - function ak(b) { - b = b | 0; - return ((a[(b + 1) >> 0] | 0) != 0) | 0; - } - function bk(b, c) { - b = b | 0; - c = c | 0; - var d = 0; - d = (b + 1) | 0; - if (!(a[d >> 0] | 0)) - a[d >> 0] = 1; - a[b >> 0] = a[c >> 0] | 0; - return; - } - function ck(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function dk(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 4) >> 2] & 255](a); - return; - } - function ek(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 17896 ? (a + 12) | 0 : 0) | 0; - } - function fk(a) { - a = a | 0; - Da(a, 16); - return; - } - function gk(a, b) { - a = a | 0; - b = b | 0; - fe(a); - c[a >> 2] = 5480; - c[(a + 4) >> 2] = b; - ik((a + 8) | 0); - return; - } - function hk(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - d = V; - V = (V + 16) | 0; - e = d; - c[a >> 2] = b; - f = eq(16) | 0; - c[(f + 4) >> 2] = 0; - c[(f + 8) >> 2] = 0; - c[f >> 2] = 5504; - c[(f + 12) >> 2] = b; - c[(a + 4) >> 2] = f; - c[e >> 2] = b; - c[(e + 4) >> 2] = b; - Xe(a, e); - V = d; - return; - } - function ik(b) { - b = b | 0; - xe(b, 16, 1, 8, 0); - mc((b + 80) | 0, 16, 1, 8, 0); - a[(b + 160) >> 0] = 0; - a[(b + 161) >> 0] = 0; - mk((b + 162) | 0); - return; - } - function jk(a) { - a = a | 0; - c[a >> 2] = 5480; - nk((a + 8) | 0); - le(a); - return; - } - function kk(a) { - a = a | 0; - jk(a); - jp(a); - return; - } - function lk(a, b) { - a = a | 0; - b = b | 0; - return ok((a + 8) | 0, c[(a + 4) >> 2] | 0, b) | 0; - } - function mk(b) { - b = b | 0; - a[(b + 2) >> 0] = 0; - return; - } - function nk(a) { - a = a | 0; - qc((a + 80) | 0); - ye(a); - return; - } - function ok(c, d, f) { - c = c | 0; - d = d | 0; - f = f | 0; - var g = 0, h = 0, i = 0; - i = V; - V = (V + 16) | 0; - g = i; - if (!(a[(c + 161) >> 0] | 0)) - oc((c + 80) | 0); - h = (c + 162) | 0; - if (pk(h) | 0) { - d = (Gi((c + 80) | 0, d, e[h >> 1] | 0, 0) | 0) & 65535; - b[g >> 1] = d; - Te(d, f); - } - else { - Ii(Hi(d) | 0, f, 2); - b[g >> 1] = Oe(f) | 0; - } - qk(h, g); - V = i; - return (f + 2) | 0; - } - function pk(b) { - b = b | 0; - return ((a[(b + 2) >> 0] | 0) != 0) | 0; - } - function qk(c, d) { - c = c | 0; - d = d | 0; - var e = 0; - e = (c + 2) | 0; - if (!(a[e >> 0] | 0)) - a[e >> 0] = 1; - b[c >> 1] = b[d >> 1] | 0; - return; - } - function rk(a) { - a = a | 0; - pq(a); - jp(a); - return; - } - function sk(a) { - a = a | 0; - a = c[(a + 12) >> 2] | 0; - if (a | 0) - ca[c[((c[a >> 2] | 0) + 4) >> 2] & 255](a); - return; - } - function tk(a, b) { - a = a | 0; - b = b | 0; - return ((c[(b + 4) >> 2] | 0) == 18394 ? (a + 12) | 0 : 0) | 0; - } - function uk(a) { - a = a | 0; - Da(a, 16); - return; - } - function vk() { - return; - } - function wk(a) { - a = a | 0; - return Ek(a) | 0; - } - function xk() { - return 0; - } - function yk() { - return 0; - } - function zk(a) { - a = a | 0; - if (a | 0) { - Fk(a); - jp(a); - } - return; - } - function Ak() { - return Gk() | 0; - } - function Bk() { - return Hk() | 0; - } - function Ck() { - return Ik() | 0; - } - function Dk() { - return 0; - } - function Ek(a) { - a = a | 0; - return 3360; - } - function Fk(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0; - b = V; - V = (V + 16) | 0; - e = b; - c[e >> 2] = c[a >> 2]; - c[a >> 2] = 0; - d = (a + 4) | 0; - c[(e + 4) >> 2] = c[d >> 2]; - c[d >> 2] = 0; - wa(e); - d = (a + 8) | 0; - c[e >> 2] = c[d >> 2]; - c[d >> 2] = 0; - f = (a + 12) | 0; - c[(e + 4) >> 2] = c[f >> 2]; - c[f >> 2] = 0; - Ga(e); - Ga(d); - wa(a); - V = b; - return; - } - function Gk() { - return 3360; - } - function Hk() { - return 3368; - } - function Ik() { - return 3384; - } - function Jk() { - return 18579; - } - function Kk() { - return 18582; - } - function Lk() { - return 18584; - } - function Mk() { - var a = 0; - a = eq(16) | 0; - Tk(a); - return a | 0; - } - function Nk(a) { - a = a | 0; - var b = 0, c = 0, d = 0, e = 0; - b = V; - V = (V + 16) | 0; - c = b; - e = Ak() | 0; - d = Pk(c) | 0; - c = Qk(c) | 0; - E(e | 0, d | 0, c | 0, Jk() | 0, 12, a | 0); - V = b; - return; - } - function Ok(a) { - a = a | 0; - return Rk(Y[a & 3]() | 0) | 0; - } - function Pk(a) { - a = a | 0; - return 1; - } - function Qk(a) { - a = a | 0; - return Sk() | 0; - } - function Rk(a) { - a = a | 0; - return a | 0; - } - function Sk() { - return 5524; - } - function Tk(a) { - a = a | 0; - c[a >> 2] = 0; - c[(a + 4) >> 2] = 0; - c[(a + 8) >> 2] = 0; - c[(a + 12) >> 2] = 0; - return; - } - function Uk(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0; - d = V; - V = (V + 16) | 0; - e = d; - f = (d + 8) | 0; - h = c[(b + 4) >> 2] | 0; - c[e >> 2] = c[b >> 2]; - c[(e + 4) >> 2] = h; - h = Ak() | 0; - g = Wk(f) | 0; - f = Xk(f) | 0; - b = bl() | 0; - F(h | 0, a | 0, g | 0, f | 0, b | 0, 4, Yk(e) | 0, 0); - V = d; - return; - } - function Vk(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0; - g = Zk(b) | 0; - b = c[a >> 2] | 0; - f = c[(a + 4) >> 2] | 0; - a = (g + (f >> 1)) | 0; - if (f & 1) - b = c[((c[a >> 2] | 0) + b) >> 2] | 0; - f = _k(d) | 0; - g = $k(e) | 0; - ea[b & 15](a, f, g); - return; - } - function Wk(a) { - a = a | 0; - return 4; - } - function Xk(a) { - a = a | 0; - return al() | 0; - } - function Yk(a) { - a = a | 0; - var b = 0, d = 0; - b = eq(8) | 0; - d = c[(a + 4) >> 2] | 0; - c[b >> 2] = c[a >> 2]; - c[(b + 4) >> 2] = d; - return b | 0; - } - function Zk(a) { - a = a | 0; - return a | 0; - } - function _k(a) { - a = a | 0; - return a | 0; - } - function $k(a) { - a = a | 0; - return a | 0; - } - function al() { - return 144; - } - function bl() { - return 18587; - } - function cl(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0; - d = V; - V = (V + 16) | 0; - e = d; - f = (d + 8) | 0; - h = c[(b + 4) >> 2] | 0; - c[e >> 2] = c[b >> 2]; - c[(e + 4) >> 2] = h; - h = Ak() | 0; - g = el(f) | 0; - f = fl(f) | 0; - b = jl() | 0; - F(h | 0, a | 0, g | 0, f | 0, b | 0, 7, gl(e) | 0, 0); - V = d; - return; - } - function dl(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - f = Zk(b) | 0; - b = c[a >> 2] | 0; - e = c[(a + 4) >> 2] | 0; - a = (f + (e >> 1)) | 0; - if (e & 1) - b = c[((c[a >> 2] | 0) + b) >> 2] | 0; - f = hl(d) | 0; - da[b & 15](a, f); - return; - } - function el(a) { - a = a | 0; - return 3; - } - function fl(a) { - a = a | 0; - return il() | 0; - } - function gl(a) { - a = a | 0; - var b = 0, d = 0; - b = eq(8) | 0; - d = c[(a + 4) >> 2] | 0; - c[b >> 2] = c[a >> 2]; - c[(b + 4) >> 2] = d; - return b | 0; - } - function hl(a) { - a = a | 0; - return a | 0; - } - function il() { - return 5528; - } - function jl() { - return 18593; - } - function kl(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0; - d = V; - V = (V + 16) | 0; - e = d; - f = (d + 8) | 0; - h = c[(b + 4) >> 2] | 0; - c[e >> 2] = c[b >> 2]; - c[(e + 4) >> 2] = h; - h = Ak() | 0; - g = ml(f) | 0; - f = nl(f) | 0; - b = rl() | 0; - F(h | 0, a | 0, g | 0, f | 0, b | 0, 41, ol(e) | 0, 0); - V = d; - return; - } - function ll(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0; - e = V; - V = (V + 16) | 0; - d = e; - g = Zk(b) | 0; - b = c[a >> 2] | 0; - f = c[(a + 4) >> 2] | 0; - a = (g + (f >> 1)) | 0; - if (f & 1) - b = c[((c[a >> 2] | 0) + b) >> 2] | 0; - c[d >> 2] = Z[b & 15](a) | 0; - g = pl(d) | 0; - V = e; - return g | 0; - } - function ml(a) { - a = a | 0; - return 2; - } - function nl(a) { - a = a | 0; - return ql() | 0; - } - function ol(a) { - a = a | 0; - var b = 0, d = 0; - b = eq(8) | 0; - d = c[(a + 4) >> 2] | 0; - c[b >> 2] = c[a >> 2]; - c[(b + 4) >> 2] = d; - return b | 0; - } - function pl(a) { - a = a | 0; - return c[a >> 2] | 0; - } - function ql() { - return 5540; - } - function rl() { - return 18598; - } - function sl() { - return; - } - function tl(a) { - a = a | 0; - return Al(a) | 0; - } - function ul() { - return 0; - } - function vl() { - return 0; - } - function wl(a) { - a = a | 0; - if (a | 0) { - Bl(a); - jp(a); - } - return; - } - function xl() { - return Cl() | 0; - } - function yl() { - return Dl() | 0; - } - function zl() { - return El() | 0; - } - function Al(a) { - a = a | 0; - return 3400; - } - function Bl(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0; - b = V; - V = (V + 16) | 0; - e = b; - c[e >> 2] = c[a >> 2]; - c[a >> 2] = 0; - d = (a + 4) | 0; - c[(e + 4) >> 2] = c[d >> 2]; - c[d >> 2] = 0; - Wh(e); - d = (a + 16) | 0; - c[e >> 2] = c[d >> 2]; - c[d >> 2] = 0; - f = (a + 20) | 0; - c[(e + 4) >> 2] = c[f >> 2]; - c[f >> 2] = 0; - Uh(e); - c[e >> 2] = c[d >> 2]; - c[d >> 2] = 0; - c[(e + 4) >> 2] = c[f >> 2]; - c[f >> 2] = 0; - Uh(e); - Uh(d); - bi((a + 8) | 0); - Wh(a); - V = b; - return; - } - function Cl() { - return 3400; - } - function Dl() { - return 3408; - } - function El() { - return 3424; - } - function Fl() { - var a = 0; - a = eq(24) | 0; - Ml(a); - return a | 0; - } - function Gl(a) { - a = a | 0; - var b = 0, c = 0, d = 0, e = 0; - b = V; - V = (V + 16) | 0; - c = b; - e = xl() | 0; - d = Il(c) | 0; - c = Jl(c) | 0; - E(e | 0, d | 0, c | 0, Jk() | 0, 13, a | 0); - V = b; - return; - } - function Hl(a) { - a = a | 0; - return Kl(Y[a & 3]() | 0) | 0; - } - function Il(a) { - a = a | 0; - return 1; - } - function Jl(a) { - a = a | 0; - return Ll() | 0; - } - function Kl(a) { - a = a | 0; - return a | 0; - } - function Ll() { - return 5548; - } - function Ml(a) { - a = a | 0; - c[a >> 2] = 0; - c[(a + 4) >> 2] = 0; - c[(a + 8) >> 2] = 0; - c[(a + 12) >> 2] = 0; - c[(a + 16) >> 2] = 0; - c[(a + 20) >> 2] = 0; - return; - } - function Nl(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0; - d = V; - V = (V + 16) | 0; - e = d; - f = (d + 8) | 0; - h = c[(b + 4) >> 2] | 0; - c[e >> 2] = c[b >> 2]; - c[(e + 4) >> 2] = h; - h = xl() | 0; - g = Pl(f) | 0; - f = Ql(f) | 0; - b = bl() | 0; - F(h | 0, a | 0, g | 0, f | 0, b | 0, 5, Rl(e) | 0, 0); - V = d; - return; - } - function Ol(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0; - g = Sl(b) | 0; - b = c[a >> 2] | 0; - f = c[(a + 4) >> 2] | 0; - a = (g + (f >> 1)) | 0; - if (f & 1) - b = c[((c[a >> 2] | 0) + b) >> 2] | 0; - f = _k(d) | 0; - g = $k(e) | 0; - ea[b & 15](a, f, g); - return; - } - function Pl(a) { - a = a | 0; - return 4; - } - function Ql(a) { - a = a | 0; - return Tl() | 0; - } - function Rl(a) { - a = a | 0; - var b = 0, d = 0; - b = eq(8) | 0; - d = c[(a + 4) >> 2] | 0; - c[b >> 2] = c[a >> 2]; - c[(b + 4) >> 2] = d; - return b | 0; - } - function Sl(a) { - a = a | 0; - return a | 0; - } - function Tl() { - return 160; - } - function Ul(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0; - d = V; - V = (V + 16) | 0; - e = d; - f = (d + 8) | 0; - h = c[(b + 4) >> 2] | 0; - c[e >> 2] = c[b >> 2]; - c[(e + 4) >> 2] = h; - h = xl() | 0; - g = Wl(f) | 0; - f = Xl(f) | 0; - b = jl() | 0; - F(h | 0, a | 0, g | 0, f | 0, b | 0, 8, Yl(e) | 0, 0); - V = d; - return; - } - function Vl(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - f = Sl(b) | 0; - b = c[a >> 2] | 0; - e = c[(a + 4) >> 2] | 0; - a = (f + (e >> 1)) | 0; - if (e & 1) - b = c[((c[a >> 2] | 0) + b) >> 2] | 0; - f = $k(d) | 0; - da[b & 15](a, f); - return; - } - function Wl(a) { - a = a | 0; - return 3; - } - function Xl(a) { - a = a | 0; - return Zl() | 0; - } - function Yl(a) { - a = a | 0; - var b = 0, d = 0; - b = eq(8) | 0; - d = c[(a + 4) >> 2] | 0; - c[b >> 2] = c[a >> 2]; - c[(b + 4) >> 2] = d; - return b | 0; - } - function Zl() { - return 5552; - } - function _l(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0; - d = V; - V = (V + 16) | 0; - e = d; - f = (d + 8) | 0; - h = c[(b + 4) >> 2] | 0; - c[e >> 2] = c[b >> 2]; - c[(e + 4) >> 2] = h; - h = xl() | 0; - g = am(f) | 0; - f = bm(f) | 0; - b = jl() | 0; - F(h | 0, a | 0, g | 0, f | 0, b | 0, 9, cm(e) | 0, 0); - V = d; - return; - } - function $l(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - f = Sl(b) | 0; - b = c[a >> 2] | 0; - e = c[(a + 4) >> 2] | 0; - a = (f + (e >> 1)) | 0; - if (e & 1) - b = c[((c[a >> 2] | 0) + b) >> 2] | 0; - f = hl(d) | 0; - da[b & 15](a, f); - return; - } - function am(a) { - a = a | 0; - return 3; - } - function bm(a) { - a = a | 0; - return dm() | 0; - } - function cm(a) { - a = a | 0; - var b = 0, d = 0; - b = eq(8) | 0; - d = c[(a + 4) >> 2] | 0; - c[b >> 2] = c[a >> 2]; - c[(b + 4) >> 2] = d; - return b | 0; - } - function dm() { - return 5564; - } - function em() { - ja(); - return; - } - function fm() { - gm(); - return; - } - function gm() { - hm(22144); - return; - } - function hm(a) { - a = a | 0; - var b = 0; - b = V; - V = (V + 16) | 0; - c[b >> 2] = a; - im(); - V = b; - return; - } - function im() { - M(jm() | 0, 18653); - C(km() | 0, 18658, 1, 1, 0); - lm(18663); - mm(18668); - nm(18680); - om(18694); - pm(18700); - qm(18715); - rm(18719); - sm(18732); - tm(18737); - um(18751); - vm(18757); - K(wm() | 0, 18764); - K(xm() | 0, 18776); - L(ym() | 0, 4, 18809); - L(zm() | 0, 2, 18822); - L(Am() | 0, 4, 18837); - G(Bm() | 0, 18852); - Cm(18868); - Dm(18898); - Em(18935); - Fm(18974); - Gm(19005); - Hm(19045); - Im(19074); - Jm(19112); - Km(19142); - Dm(19181); - Em(19213); - Fm(19246); - Gm(19279); - Hm(19313); - Im(19346); - Lm(19380); - Mm(19411); - Nm(19443); - return; - } - function jm() { - return _n() | 0; - } - function km() { - return Zn() | 0; - } - function lm(a) { - a = a | 0; - var b = 0, d = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - a = Xn() | 0; - I(a | 0, c[d >> 2] | 0, 1, ((-128 << 24) >> 24) | 0, ((127 << 24) >> 24) | 0); - V = b; - return; - } - function mm(a) { - a = a | 0; - var b = 0, d = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - a = Vn() | 0; - I(a | 0, c[d >> 2] | 0, 1, ((-128 << 24) >> 24) | 0, ((127 << 24) >> 24) | 0); - V = b; - return; - } - function nm(a) { - a = a | 0; - var b = 0, d = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - a = Tn() | 0; - I(a | 0, c[d >> 2] | 0, 1, 0, 255); - V = b; - return; - } - function om(a) { - a = a | 0; - var b = 0, d = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - a = Rn() | 0; - I(a | 0, c[d >> 2] | 0, 2, ((-32768 << 16) >> 16) | 0, ((32767 << 16) >> 16) | 0); - V = b; - return; - } - function pm(a) { - a = a | 0; - var b = 0, d = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - a = Pn() | 0; - I(a | 0, c[d >> 2] | 0, 2, 0, 65535); - V = b; - return; - } - function qm(a) { - a = a | 0; - var b = 0, d = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - a = Nn() | 0; - I(a | 0, c[d >> 2] | 0, 4, -2147483648, 2147483647); - V = b; - return; - } - function rm(a) { - a = a | 0; - var b = 0, d = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - a = Ln() | 0; - I(a | 0, c[d >> 2] | 0, 4, 0, -1); - V = b; - return; - } - function sm(a) { - a = a | 0; - var b = 0, d = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - a = Jn() | 0; - I(a | 0, c[d >> 2] | 0, 4, -2147483648, 2147483647); - V = b; - return; - } - function tm(a) { - a = a | 0; - var b = 0, d = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - a = Hn() | 0; - I(a | 0, c[d >> 2] | 0, 4, 0, -1); - V = b; - return; - } - function um(a) { - a = a | 0; - var b = 0, d = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - a = Fn() | 0; - H(a | 0, c[d >> 2] | 0, 4); - V = b; - return; - } - function vm(a) { - a = a | 0; - var b = 0, d = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - a = Dn() | 0; - H(a | 0, c[d >> 2] | 0, 8); - V = b; - return; - } - function wm() { - return Cn() | 0; - } - function xm() { - return Bn() | 0; - } - function ym() { - return An() | 0; - } - function zm() { - return zn() | 0; - } - function Am() { - return yn() | 0; - } - function Bm() { - return xn() | 0; - } - function Cm(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - e = un() | 0; - a = vn() | 0; - J(e | 0, a | 0, c[d >> 2] | 0); - V = b; - return; - } - function Dm(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - e = rn() | 0; - a = sn() | 0; - J(e | 0, a | 0, c[d >> 2] | 0); - V = b; - return; - } - function Em(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - e = on() | 0; - a = pn() | 0; - J(e | 0, a | 0, c[d >> 2] | 0); - V = b; - return; - } - function Fm(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - e = ln() | 0; - a = mn() | 0; - J(e | 0, a | 0, c[d >> 2] | 0); - V = b; - return; - } - function Gm(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - e = hn() | 0; - a = jn() | 0; - J(e | 0, a | 0, c[d >> 2] | 0); - V = b; - return; - } - function Hm(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - e = en() | 0; - a = fn() | 0; - J(e | 0, a | 0, c[d >> 2] | 0); - V = b; - return; - } - function Im(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - e = bn() | 0; - a = cn() | 0; - J(e | 0, a | 0, c[d >> 2] | 0); - V = b; - return; - } - function Jm(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - e = _m() | 0; - a = $m() | 0; - J(e | 0, a | 0, c[d >> 2] | 0); - V = b; - return; - } - function Km(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - e = Xm() | 0; - a = Ym() | 0; - J(e | 0, a | 0, c[d >> 2] | 0); - V = b; - return; - } - function Lm(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - e = Um() | 0; - a = Vm() | 0; - J(e | 0, a | 0, c[d >> 2] | 0); - V = b; - return; - } - function Mm(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - e = Rm() | 0; - a = Sm() | 0; - J(e | 0, a | 0, c[d >> 2] | 0); - V = b; - return; - } - function Nm(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - b = V; - V = (V + 16) | 0; - d = b; - c[d >> 2] = a; - e = Om() | 0; - a = Pm() | 0; - J(e | 0, a | 0, c[d >> 2] | 0); - V = b; - return; - } - function Om() { - return Qm() | 0; - } - function Pm() { - return 7; - } - function Qm() { - return 3440; - } - function Rm() { - return Tm() | 0; - } - function Sm() { - return 7; - } - function Tm() { - return 3448; - } - function Um() { - return Wm() | 0; - } - function Vm() { - return 6; - } - function Wm() { - return 3456; - } - function Xm() { - return Zm() | 0; - } - function Ym() { - return 5; - } - function Zm() { - return 3464; - } - function _m() { - return an() | 0; - } - function $m() { - return 4; - } - function an() { - return 3472; - } - function bn() { - return dn() | 0; - } - function cn() { - return 5; - } - function dn() { - return 3480; - } - function en() { - return gn() | 0; - } - function fn() { - return 4; - } - function gn() { - return 3488; - } - function hn() { - return kn() | 0; - } - function jn() { - return 3; - } - function kn() { - return 3496; - } - function ln() { - return nn() | 0; - } - function mn() { - return 2; - } - function nn() { - return 3504; - } - function on() { - return qn() | 0; - } - function pn() { - return 1; - } - function qn() { - return 3512; - } - function rn() { - return tn() | 0; - } - function sn() { - return 0; - } - function tn() { - return 3520; - } - function un() { - return wn() | 0; - } - function vn() { - return 0; - } - function wn() { - return 3528; - } - function xn() { - return 3536; - } - function yn() { - return 3544; - } - function zn() { - return 3576; - } - function An() { - return 3600; - } - function Bn() { - return 3624; - } - function Cn() { - return 3648; - } - function Dn() { - return En() | 0; - } - function En() { - return 4144; - } - function Fn() { - return Gn() | 0; - } - function Gn() { - return 4136; - } - function Hn() { - return In() | 0; - } - function In() { - return 4128; - } - function Jn() { - return Kn() | 0; - } - function Kn() { - return 4120; - } - function Ln() { - return Mn() | 0; - } - function Mn() { - return 4112; - } - function Nn() { - return On() | 0; - } - function On() { - return 4104; - } - function Pn() { - return Qn() | 0; - } - function Qn() { - return 4096; - } - function Rn() { - return Sn() | 0; - } - function Sn() { - return 4088; - } - function Tn() { - return Un() | 0; - } - function Un() { - return 4072; - } - function Vn() { - return Wn() | 0; - } - function Wn() { - return 4080; - } - function Xn() { - return Yn() | 0; - } - function Yn() { - return 4064; - } - function Zn() { - return 4056; - } - function _n() { - return 4040; - } - function $n(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0; - b = V; - V = (V + 16) | 0; - d = (b + 8) | 0; - e = (b + 4) | 0; - f = b; - c[f >> 2] = a; - c[e >> 2] = c[f >> 2]; - c[d >> 2] = c[((c[e >> 2] | 0) + 4) >> 2]; - a = Jo(c[d >> 2] | 0) | 0; - V = b; - return a | 0; - } - function ao() { - return 21636; - } - function bo(a) { - a = a | 0; - return (((a + -48) | 0) >>> 0 < 10) | 0; - } - function co() { - return 5576; - } - function eo(b, c) { - b = b | 0; - c = c | 0; - var d = 0, e = 0; - d = a[b >> 0] | 0; - e = a[c >> 0] | 0; - if ((d << 24) >> 24 == 0 ? 1 : (d << 24) >> 24 != (e << 24) >> 24) - b = e; - else { - do { - b = (b + 1) | 0; - c = (c + 1) | 0; - d = a[b >> 0] | 0; - e = a[c >> 0] | 0; - } while (!((d << 24) >> 24 == 0 ? 1 : (d << 24) >> 24 != (e << 24) >> 24)); - b = e; - } - return ((d & 255) - (b & 255)) | 0; - } - function fo(b) { - b = b | 0; - var d = 0, e = 0, f = 0; - f = b; - a: do - if (!(f & 3)) - e = 5; - else { - d = f; - while (1) { - if (!(a[b >> 0] | 0)) { - b = d; - break a; - } - b = (b + 1) | 0; - d = b; - if (!(d & 3)) { - e = 5; - break; - } - } - } - while (0); - if ((e | 0) == 5) { - while (1) { - d = c[b >> 2] | 0; - if (!(((d & -2139062144) ^ -2139062144) & (d + -16843009))) - b = (b + 4) | 0; - else - break; - } - if (((d & 255) << 24) >> 24) - do - b = (b + 1) | 0; - while ((a[b >> 0] | 0) != 0); - } - return (b - f) | 0; - } - function go(a) { - a = a | 0; - return; - } - function ho(a) { - a = a | 0; - return 1; - } - function io(b) { - b = b | 0; - var d = 0, e = 0; - d = (b + 74) | 0; - e = a[d >> 0] | 0; - a[d >> 0] = (e + 255) | e; - d = c[b >> 2] | 0; - if (!(d & 8)) { - c[(b + 8) >> 2] = 0; - c[(b + 4) >> 2] = 0; - e = c[(b + 44) >> 2] | 0; - c[(b + 28) >> 2] = e; - c[(b + 20) >> 2] = e; - c[(b + 16) >> 2] = e + (c[(b + 48) >> 2] | 0); - b = 0; - } - else { - c[b >> 2] = d | 32; - b = -1; - } - return b | 0; - } - function jo(b, d, e) { - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0, h = 0, i = 0, j = 0; - f = (e + 16) | 0; - g = c[f >> 2] | 0; - if (!g) - if (!(io(e) | 0)) { - g = c[f >> 2] | 0; - h = 5; - } - else - f = 0; - else - h = 5; - a: do - if ((h | 0) == 5) { - j = (e + 20) | 0; - i = c[j >> 2] | 0; - f = i; - if (((g - i) | 0) >>> 0 < d >>> 0) { - f = aa[c[(e + 36) >> 2] & 7](e, b, d) | 0; - break; - } - b: do - if (((a[(e + 75) >> 0] | 0) < 0) | ((d | 0) == 0)) { - h = 0; - g = b; - } - else { - i = d; - while (1) { - g = (i + -1) | 0; - if ((a[(b + g) >> 0] | 0) == 10) - break; - if (!g) { - h = 0; - g = b; - break b; - } - else - i = g; - } - f = aa[c[(e + 36) >> 2] & 7](e, b, i) | 0; - if (f >>> 0 < i >>> 0) - break a; - h = i; - g = (b + i) | 0; - d = (d - i) | 0; - f = c[j >> 2] | 0; - } - while (0); - ur(f | 0, g | 0, d | 0) | 0; - c[j >> 2] = (c[j >> 2] | 0) + d; - f = (h + d) | 0; - } - while (0); - return f | 0; - } - function ko(a, b) { - a = a | 0; - b = b | 0; - if (!b) - b = 0; - else - b = lo(c[b >> 2] | 0, c[(b + 4) >> 2] | 0, a) | 0; - return ((b | 0) == 0 ? a : b) | 0; - } - function lo(b, d, e) { - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0; - o = ((c[b >> 2] | 0) + 1794895138) | 0; - h = mo(c[(b + 8) >> 2] | 0, o) | 0; - f = mo(c[(b + 12) >> 2] | 0, o) | 0; - g = mo(c[(b + 16) >> 2] | 0, o) | 0; - a: do - if ((h >>> 0 < (d >>> 2) >>> 0 - ? ((n = (d - (h << 2)) | 0), (f >>> 0 < n >>> 0) & (g >>> 0 < n >>> 0)) - : 0) - ? (((g | f) & 3) | 0) == 0 - : 0) { - n = f >>> 2; - m = g >>> 2; - l = 0; - while (1) { - j = h >>> 1; - k = (l + j) | 0; - i = k << 1; - g = (i + n) | 0; - f = mo(c[(b + (g << 2)) >> 2] | 0, o) | 0; - g = mo(c[(b + ((g + 1) << 2)) >> 2] | 0, o) | 0; - if (!((g >>> 0 < d >>> 0) & (f >>> 0 < ((d - g) | 0) >>> 0))) { - f = 0; - break a; - } - if (a[(b + (g + f)) >> 0] | 0) { - f = 0; - break a; - } - f = eo(e, (b + g) | 0) | 0; - if (!f) - break; - f = (f | 0) < 0; - if ((h | 0) == 1) { - f = 0; - break a; - } - l = f ? l : k; - h = f ? j : (h - j) | 0; - } - f = (i + m) | 0; - g = mo(c[(b + (f << 2)) >> 2] | 0, o) | 0; - f = mo(c[(b + ((f + 1) << 2)) >> 2] | 0, o) | 0; - if ((f >>> 0 < d >>> 0) & (g >>> 0 < ((d - f) | 0) >>> 0)) - f = (a[(b + (f + g)) >> 0] | 0) == 0 ? (b + f) | 0 : 0; - else - f = 0; - } - else - f = 0; - while (0); - return f | 0; - } - function mo(a, b) { - a = a | 0; - b = b | 0; - var c = 0; - c = tr(a | 0) | 0; - return ((b | 0) == 0 ? a : c) | 0; - } - function no(b, d, e) { - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0, h = 0; - h = d & 255; - f = (e | 0) != 0; - a: do - if (f & (((b & 3) | 0) != 0)) { - g = d & 255; - while (1) { - if ((a[b >> 0] | 0) == (g << 24) >> 24) { - g = 6; - break a; - } - b = (b + 1) | 0; - e = (e + -1) | 0; - f = (e | 0) != 0; - if (!(f & (((b & 3) | 0) != 0))) { - g = 5; - break; - } - } - } - else - g = 5; - while (0); - if ((g | 0) == 5) - if (f) - g = 6; - else - b = 0; - b: do - if ((g | 0) == 6) { - if ((a[b >> 0] | 0) != ((d & 255) << 24) >> 24) { - f = q(h, 16843009) | 0; - c: do - if (e >>> 0 > 3) - do { - h = c[b >> 2] ^ f; - if ((((h & -2139062144) ^ -2139062144) & (h + -16843009)) | 0) - break c; - b = (b + 4) | 0; - e = (e + -4) | 0; - } while (e >>> 0 > 3); - while (0); - } - if (!e) - b = 0; - else { - f = d & 255; - while (1) { - if ((a[b >> 0] | 0) == (f << 24) >> 24) - break b; - e = (e + -1) | 0; - if (!e) { - b = 0; - break; - } - else - b = (b + 1) | 0; - } - } - } - while (0); - return b | 0; - } - function oo(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - return ro(a, b, c, 1, 8) | 0; - } - function po(b, e, f, g, h, i) { - b = b | 0; - e = +e; - f = f | 0; - g = g | 0; - h = h | 0; - i = i | 0; - var j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, r = 0.0, s = 0, t = 0, v = 0, w = 0, x = 0, y = 0, z = 0, A = 0, B = 0, C = 0, D = 0, E = 0, F = 0, G = 0, H = 0; - H = V; - V = (V + 560) | 0; - l = (H + 32) | 0; - w = (H + 536) | 0; - G = H; - F = G; - m = (H + 540) | 0; - c[w >> 2] = 0; - E = (m + 12) | 0; - Do(e) | 0; - j = u() | 0; - if ((j | 0) < 0) { - e = -e; - Do(e) | 0; - D = 1; - C = 20247; - j = u() | 0; - } - else { - D = (((h & 2049) | 0) != 0) & 1; - C = ((h & 2048) | 0) == 0 ? (((h & 1) | 0) == 0 ? 20248 : 20253) : 20250; - } - do - if ((0 == 0) & (((j & 2146435072) | 0) == 2146435072)) { - G = ((i & 32) | 0) != 0; - j = (D + 3) | 0; - zo(b, 32, f, j, h & -65537); - to(b, C, D); - to(b, (e != e) | (0.0 != 0.0) ? (G ? 20274 : 20278) : G ? 20266 : 20270, 3); - zo(b, 32, f, j, h ^ 8192); - } - else { - r = +Eo(e, w) * 2.0; - j = r != 0.0; - if (j) - c[w >> 2] = (c[w >> 2] | 0) + -1; - v = i | 32; - if ((v | 0) == 97) { - o = i & 32; - s = (o | 0) == 0 ? C : (C + 9) | 0; - p = D | 2; - j = (12 - g) | 0; - do - if (!((g >>> 0 > 11) | ((j | 0) == 0))) { - e = 8.0; - do { - j = (j + -1) | 0; - e = e * 16.0; - } while ((j | 0) != 0); - if ((a[s >> 0] | 0) == 45) { - e = -(e + (-r - e)); - break; - } - else { - e = r + e - e; - break; - } - } - else - e = r; - while (0); - k = c[w >> 2] | 0; - j = (k | 0) < 0 ? (0 - k) | 0 : k; - j = yo(j, (((j | 0) < 0) << 31) >> 31, E) | 0; - if ((j | 0) == (E | 0)) { - j = (m + 11) | 0; - a[j >> 0] = 48; - } - a[(j + -1) >> 0] = ((k >> 31) & 2) + 43; - n = (j + -2) | 0; - a[n >> 0] = i + 15; - k = (g | 0) < 1; - l = ((h & 8) | 0) == 0; - m = G; - do { - D = ~~e; - j = (m + 1) | 0; - a[m >> 0] = o | d[(640 + D) >> 0]; - e = (e - +(D | 0)) * 16.0; - if (((j - F) | 0) == 1 ? !(l & (k & (e == 0.0))) : 0) { - a[j >> 0] = 46; - m = (m + 2) | 0; - } - else - m = j; - } while (e != 0.0); - if ((g | 0) != 0 ? ((-2 - F + m) | 0) < (g | 0) : 0) { - k = E; - l = n; - j = (g + 2 + k - l) | 0; - } - else { - k = E; - l = n; - j = (k - F - l + m) | 0; - } - E = (j + p) | 0; - zo(b, 32, f, E, h); - to(b, s, p); - zo(b, 48, f, E, h ^ 65536); - F = (m - F) | 0; - to(b, G, F); - G = (k - l) | 0; - zo(b, 48, (j - (F + G)) | 0, 0, 0); - to(b, n, G); - zo(b, 32, f, E, h ^ 8192); - j = E; - break; - } - k = (g | 0) < 0 ? 6 : g; - if (j) { - j = ((c[w >> 2] | 0) + -28) | 0; - c[w >> 2] = j; - e = r * 268435456.0; - } - else { - e = r; - j = c[w >> 2] | 0; - } - B = (j | 0) < 0 ? l : (l + 288) | 0; - l = B; - do { - z = ~~e >>> 0; - c[l >> 2] = z; - l = (l + 4) | 0; - e = (e - +(z >>> 0)) * 1.0e9; - } while (e != 0.0); - z = B; - if ((j | 0) > 0) { - o = B; - while (1) { - n = (j | 0) < 29 ? j : 29; - j = (l + -4) | 0; - if (j >>> 0 >= o >>> 0) { - m = 0; - do { - t = rr(c[j >> 2] | 0, 0, n | 0) | 0; - t = lr(t | 0, u() | 0, m | 0, 0) | 0; - x = u() | 0; - m = pr(t | 0, x | 0, 1e9, 0) | 0; - y = kr(m | 0, u() | 0, 1e9, 0) | 0; - y = mr(t | 0, x | 0, y | 0, u() | 0) | 0; - u() | 0; - c[j >> 2] = y; - j = (j + -4) | 0; - } while (j >>> 0 >= o >>> 0); - if (m) { - y = (o + -4) | 0; - c[y >> 2] = m; - m = y; - } - else - m = o; - } - else - m = o; - a: do - if (l >>> 0 > m >>> 0) { - j = l; - while (1) { - l = (j + -4) | 0; - if (c[l >> 2] | 0) { - l = j; - break a; - } - if (l >>> 0 > m >>> 0) - j = l; - else - break; - } - } - while (0); - j = ((c[w >> 2] | 0) - n) | 0; - c[w >> 2] = j; - if ((j | 0) > 0) - o = m; - else - break; - } - } - else - m = B; - if ((j | 0) < 0) { - g = (((((k + 25) | 0) / 9) | 0) + 1) | 0; - t = (v | 0) == 102; - do { - s = (0 - j) | 0; - s = (s | 0) < 9 ? s : 9; - if (m >>> 0 < l >>> 0) { - n = ((1 << s) + -1) | 0; - o = 1e9 >>> s; - p = 0; - j = m; - do { - y = c[j >> 2] | 0; - c[j >> 2] = (y >>> s) + p; - p = q(y & n, o) | 0; - j = (j + 4) | 0; - } while (j >>> 0 < l >>> 0); - m = (c[m >> 2] | 0) == 0 ? (m + 4) | 0 : m; - if (p) { - c[l >> 2] = p; - l = (l + 4) | 0; - } - } - else - m = (c[m >> 2] | 0) == 0 ? (m + 4) | 0 : m; - j = t ? B : m; - l = (((l - j) >> 2) | 0) > (g | 0) ? (j + (g << 2)) | 0 : l; - j = ((c[w >> 2] | 0) + s) | 0; - c[w >> 2] = j; - } while ((j | 0) < 0); - t = m; - } - else - t = m; - if (t >>> 0 < l >>> 0) { - j = (((z - t) >> 2) * 9) | 0; - n = c[t >> 2] | 0; - if (n >>> 0 >= 10) { - m = 10; - do { - m = (m * 10) | 0; - j = (j + 1) | 0; - } while (n >>> 0 >= m >>> 0); - } - } - else - j = 0; - x = (v | 0) == 103; - y = (k | 0) != 0; - m = (k - ((v | 0) == 102 ? 0 : j) + (((y & x) << 31) >> 31)) | 0; - if ((m | 0) < ((((((l - z) >> 2) * 9) | 0) + -9) | 0)) { - w = (m + 9216) | 0; - m = ((w | 0) / 9) | 0; - g = (B + 4 + ((m + -1024) << 2)) | 0; - m = (w - ((m * 9) | 0)) | 0; - if ((m | 0) < 8) { - n = 10; - while (1) { - n = (n * 10) | 0; - if ((m | 0) < 7) - m = (m + 1) | 0; - else - break; - } - } - else - n = 10; - p = c[g >> 2] | 0; - m = ((p >>> 0) / (n >>> 0)) | 0; - s = (p - (q(m, n) | 0)) | 0; - o = ((g + 4) | 0) == (l | 0); - if (!(o & ((s | 0) == 0))) { - r = ((m & 1) | 0) == 0 ? 9007199254740992.0 : 9007199254740994.0; - w = n >>> 1; - e = s >>> 0 < w >>> 0 ? 0.5 : o & ((s | 0) == (w | 0)) ? 1.0 : 1.5; - if (D) { - w = (a[C >> 0] | 0) == 45; - e = w ? -e : e; - r = w ? -r : r; - } - m = (p - s) | 0; - c[g >> 2] = m; - if (r + e != r) { - w = (m + n) | 0; - c[g >> 2] = w; - if (w >>> 0 > 999999999) { - n = g; - j = t; - while (1) { - m = (n + -4) | 0; - c[n >> 2] = 0; - if (m >>> 0 < j >>> 0) { - j = (j + -4) | 0; - c[j >> 2] = 0; - } - w = ((c[m >> 2] | 0) + 1) | 0; - c[m >> 2] = w; - if (w >>> 0 > 999999999) - n = m; - else { - n = j; - break; - } - } - } - else { - m = g; - n = t; - } - j = (((z - n) >> 2) * 9) | 0; - p = c[n >> 2] | 0; - if (p >>> 0 >= 10) { - o = 10; - do { - o = (o * 10) | 0; - j = (j + 1) | 0; - } while (p >>> 0 >= o >>> 0); - } - } - else { - m = g; - n = t; - } - } - else { - m = g; - n = t; - } - w = (m + 4) | 0; - l = l >>> 0 > w >>> 0 ? w : l; - } - else - n = t; - g = (0 - j) | 0; - b: do - if (l >>> 0 > n >>> 0) - while (1) { - m = (l + -4) | 0; - if (c[m >> 2] | 0) { - w = l; - v = 1; - break b; - } - if (m >>> 0 > n >>> 0) - l = m; - else { - w = m; - v = 0; - break; - } - } - else { - w = l; - v = 0; - } - while (0); - do - if (x) { - k = (k + ((y ^ 1) & 1)) | 0; - if (((k | 0) > (j | 0)) & ((j | 0) > -5)) { - o = (i + -1) | 0; - k = (k + -1 - j) | 0; - } - else { - o = (i + -2) | 0; - k = (k + -1) | 0; - } - if (!(h & 8)) { - if (v ? ((A = c[(w + -4) >> 2] | 0), (A | 0) != 0) : 0) - if (!((A >>> 0) % 10 | 0)) { - m = 0; - l = 10; - do { - l = (l * 10) | 0; - m = (m + 1) | 0; - } while (!((A >>> 0) % (l >>> 0) | 0 | 0)); - } - else - m = 0; - else - m = 9; - l = (((((w - z) >> 2) * 9) | 0) + -9) | 0; - if ((o | 32 | 0) == 102) { - i = (l - m) | 0; - i = (i | 0) > 0 ? i : 0; - k = (k | 0) < (i | 0) ? k : i; - break; - } - else { - i = (l + j - m) | 0; - i = (i | 0) > 0 ? i : 0; - k = (k | 0) < (i | 0) ? k : i; - break; - } - } - } - else - o = i; - while (0); - t = (k | 0) != 0; - p = t ? 1 : (h >>> 3) & 1; - s = (o | 32 | 0) == 102; - if (s) { - x = 0; - j = (j | 0) > 0 ? j : 0; - } - else { - l = (j | 0) < 0 ? g : j; - l = yo(l, (((l | 0) < 0) << 31) >> 31, E) | 0; - m = E; - if (((m - l) | 0) < 2) - do { - l = (l + -1) | 0; - a[l >> 0] = 48; - } while (((m - l) | 0) < 2); - a[(l + -1) >> 0] = ((j >> 31) & 2) + 43; - j = (l + -2) | 0; - a[j >> 0] = o; - x = j; - j = (m - j) | 0; - } - j = (D + 1 + k + p + j) | 0; - zo(b, 32, f, j, h); - to(b, C, D); - zo(b, 48, f, j, h ^ 65536); - if (s) { - p = n >>> 0 > B >>> 0 ? B : n; - s = (G + 9) | 0; - n = s; - o = (G + 8) | 0; - m = p; - do { - l = yo(c[m >> 2] | 0, 0, s) | 0; - if ((m | 0) == (p | 0)) { - if ((l | 0) == (s | 0)) { - a[o >> 0] = 48; - l = o; - } - } - else if (l >>> 0 > G >>> 0) { - wr(G | 0, 48, (l - F) | 0) | 0; - do - l = (l + -1) | 0; - while (l >>> 0 > G >>> 0); - } - to(b, l, (n - l) | 0); - m = (m + 4) | 0; - } while (m >>> 0 <= B >>> 0); - if (!((((h & 8) | 0) == 0) & (t ^ 1))) - to(b, 20282, 1); - if ((m >>> 0 < w >>> 0) & ((k | 0) > 0)) - while (1) { - l = yo(c[m >> 2] | 0, 0, s) | 0; - if (l >>> 0 > G >>> 0) { - wr(G | 0, 48, (l - F) | 0) | 0; - do - l = (l + -1) | 0; - while (l >>> 0 > G >>> 0); - } - to(b, l, (k | 0) < 9 ? k : 9); - m = (m + 4) | 0; - l = (k + -9) | 0; - if (!((m >>> 0 < w >>> 0) & ((k | 0) > 9))) { - k = l; - break; - } - else - k = l; - } - zo(b, 48, (k + 9) | 0, 9, 0); - } - else { - w = v ? w : (n + 4) | 0; - if ((n >>> 0 < w >>> 0) & ((k | 0) > -1)) { - g = (G + 9) | 0; - t = ((h & 8) | 0) == 0; - v = g; - p = (0 - F) | 0; - s = (G + 8) | 0; - o = n; - do { - l = yo(c[o >> 2] | 0, 0, g) | 0; - if ((l | 0) == (g | 0)) { - a[s >> 0] = 48; - l = s; - } - do - if ((o | 0) == (n | 0)) { - m = (l + 1) | 0; - to(b, l, 1); - if (t & ((k | 0) < 1)) { - l = m; - break; - } - to(b, 20282, 1); - l = m; - } - else { - if (l >>> 0 <= G >>> 0) - break; - wr(G | 0, 48, (l + p) | 0) | 0; - do - l = (l + -1) | 0; - while (l >>> 0 > G >>> 0); - } - while (0); - F = (v - l) | 0; - to(b, l, (k | 0) > (F | 0) ? F : k); - k = (k - F) | 0; - o = (o + 4) | 0; - } while ((o >>> 0 < w >>> 0) & ((k | 0) > -1)); - } - zo(b, 48, (k + 18) | 0, 18, 0); - to(b, x, (E - x) | 0); - } - zo(b, 32, f, j, h ^ 8192); - } - while (0); - V = H; - return ((j | 0) < (f | 0) ? f : j) | 0; - } - function qo(a, b) { - a = a | 0; - b = b | 0; - var d = 0.0, e = 0; - e = ((c[b >> 2] | 0) + (8 - 1)) & ~(8 - 1); - d = +g[e >> 3]; - c[b >> 2] = e + 8; - g[a >> 3] = d; - return; - } - function ro(b, d, e, f, g) { - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - g = g | 0; - var h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, q = 0, r = 0, s = 0, t = 0; - t = V; - V = (V + 224) | 0; - p = (t + 208) | 0; - q = (t + 160) | 0; - r = (t + 80) | 0; - s = t; - h = q; - i = (h + 40) | 0; - do { - c[h >> 2] = 0; - h = (h + 4) | 0; - } while ((h | 0) < (i | 0)); - c[p >> 2] = c[e >> 2]; - if ((so(0, d, p, r, q, f, g) | 0) < 0) - e = -1; - else { - if ((c[(b + 76) >> 2] | 0) > -1) - o = ho(b) | 0; - else - o = 0; - e = c[b >> 2] | 0; - n = e & 32; - if ((a[(b + 74) >> 0] | 0) < 1) - c[b >> 2] = e & -33; - h = (b + 48) | 0; - if (!(c[h >> 2] | 0)) { - i = (b + 44) | 0; - j = c[i >> 2] | 0; - c[i >> 2] = s; - k = (b + 28) | 0; - c[k >> 2] = s; - l = (b + 20) | 0; - c[l >> 2] = s; - c[h >> 2] = 80; - m = (b + 16) | 0; - c[m >> 2] = s + 80; - e = so(b, d, p, r, q, f, g) | 0; - if (j) { - aa[c[(b + 36) >> 2] & 7](b, 0, 0) | 0; - e = (c[l >> 2] | 0) == 0 ? -1 : e; - c[i >> 2] = j; - c[h >> 2] = 0; - c[m >> 2] = 0; - c[k >> 2] = 0; - c[l >> 2] = 0; - } - } - else - e = so(b, d, p, r, q, f, g) | 0; - h = c[b >> 2] | 0; - c[b >> 2] = h | n; - if (o | 0) - go(b); - e = ((h & 32) | 0) == 0 ? e : -1; - } - V = t; - return e | 0; - } - function so(d, e, f, h, i, j, k) { - d = d | 0; - e = e | 0; - f = f | 0; - h = h | 0; - i = i | 0; - j = j | 0; - k = k | 0; - var l = 0, m = 0, n = 0, o = 0, p = 0, q = 0, r = 0, s = 0, t = 0, v = 0, w = 0, x = 0, y = 0, z = 0, A = 0, B = 0, C = 0, D = 0, E = 0, F = 0, G = 0, H = 0, I = 0, J = 0, K = 0; - J = V; - V = (V + 64) | 0; - G = (J + 56) | 0; - I = (J + 40) | 0; - B = J; - D = (J + 48) | 0; - E = (J + 60) | 0; - c[G >> 2] = e; - y = (d | 0) != 0; - z = (B + 40) | 0; - A = z; - B = (B + 39) | 0; - C = (D + 4) | 0; - l = 0; - e = 0; - n = 0; - a: while (1) { - do { - do - if ((e | 0) > -1) - if ((l | 0) > ((2147483647 - e) | 0)) { - c[(ao() | 0) >> 2] = 61; - e = -1; - break; - } - else { - e = (l + e) | 0; - break; - } - while (0); - r = c[G >> 2] | 0; - l = a[r >> 0] | 0; - if (!((l << 24) >> 24)) { - x = 92; - break a; - } - m = r; - b: while (1) { - switch ((l << 24) >> 24) { - case 37: { - x = 10; - break b; - } - case 0: { - l = m; - break b; - } - default: { - } - } - w = (m + 1) | 0; - c[G >> 2] = w; - l = a[w >> 0] | 0; - m = w; - } - c: do - if ((x | 0) == 10) { - x = 0; - l = m; - do { - if ((a[(m + 1) >> 0] | 0) != 37) - break c; - l = (l + 1) | 0; - m = (m + 2) | 0; - c[G >> 2] = m; - } while ((a[m >> 0] | 0) == 37); - } - while (0); - l = (l - r) | 0; - if (y) - to(d, r, l); - } while ((l | 0) != 0); - w = (bo(a[((c[G >> 2] | 0) + 1) >> 0] | 0) | 0) == 0; - m = c[G >> 2] | 0; - if (!w ? (a[(m + 2) >> 0] | 0) == 36 : 0) { - t = ((a[(m + 1) >> 0] | 0) + -48) | 0; - p = 1; - l = 3; - } - else { - t = -1; - p = n; - l = 1; - } - l = (m + l) | 0; - c[G >> 2] = l; - m = a[l >> 0] | 0; - n = (((m << 24) >> 24) + -32) | 0; - if ((n >>> 0 > 31) | ((((1 << n) & 75913) | 0) == 0)) - o = 0; - else { - o = 0; - do { - o = (1 << n) | o; - l = (l + 1) | 0; - c[G >> 2] = l; - m = a[l >> 0] | 0; - n = (((m << 24) >> 24) + -32) | 0; - } while (!((n >>> 0 > 31) | ((((1 << n) & 75913) | 0) == 0))); - } - if ((m << 24) >> 24 == 42) { - if ((bo(a[(l + 1) >> 0] | 0) | 0) != 0 - ? ((H = c[G >> 2] | 0), (a[(H + 2) >> 0] | 0) == 36) - : 0) { - l = (H + 1) | 0; - c[(i + (((a[l >> 0] | 0) + -48) << 2)) >> 2] = 10; - l = c[(h + (((a[l >> 0] | 0) + -48) << 3)) >> 2] | 0; - n = 1; - m = (H + 3) | 0; - } - else { - if (p | 0) { - e = -1; - break; - } - if (y) { - w = ((c[f >> 2] | 0) + (4 - 1)) & ~(4 - 1); - l = c[w >> 2] | 0; - c[f >> 2] = w + 4; - } - else - l = 0; - n = 0; - m = ((c[G >> 2] | 0) + 1) | 0; - } - c[G >> 2] = m; - w = (l | 0) < 0; - v = w ? (0 - l) | 0 : l; - o = w ? o | 8192 : o; - w = n; - } - else { - l = uo(G) | 0; - if ((l | 0) < 0) { - e = -1; - break; - } - v = l; - w = p; - m = c[G >> 2] | 0; - } - do - if ((a[m >> 0] | 0) == 46) { - l = (m + 1) | 0; - if ((a[l >> 0] | 0) != 42) { - c[G >> 2] = l; - l = uo(G) | 0; - m = c[G >> 2] | 0; - break; - } - if (bo(a[(m + 2) >> 0] | 0) | 0 ? ((F = c[G >> 2] | 0), (a[(F + 3) >> 0] | 0) == 36) : 0) { - l = (F + 2) | 0; - c[(i + (((a[l >> 0] | 0) + -48) << 2)) >> 2] = 10; - l = c[(h + (((a[l >> 0] | 0) + -48) << 3)) >> 2] | 0; - m = (F + 4) | 0; - c[G >> 2] = m; - break; - } - if (w | 0) { - e = -1; - break a; - } - if (y) { - s = ((c[f >> 2] | 0) + (4 - 1)) & ~(4 - 1); - l = c[s >> 2] | 0; - c[f >> 2] = s + 4; - } - else - l = 0; - m = ((c[G >> 2] | 0) + 2) | 0; - c[G >> 2] = m; - } - else - l = -1; - while (0); - s = 0; - while (1) { - if ((((a[m >> 0] | 0) + -65) | 0) >>> 0 > 57) { - e = -1; - break a; - } - n = m; - m = (m + 1) | 0; - c[G >> 2] = m; - n = a[((a[n >> 0] | 0) + -65 + (176 + ((s * 58) | 0))) >> 0] | 0; - p = n & 255; - if (((p + -1) | 0) >>> 0 >= 8) - break; - else - s = p; - } - if (!((n << 24) >> 24)) { - e = -1; - break; - } - q = (t | 0) > -1; - do - if ((n << 24) >> 24 == 19) - if (q) { - e = -1; - break a; - } - else - x = 54; - else { - if (q) { - c[(i + (t << 2)) >> 2] = p; - q = (h + (t << 3)) | 0; - t = c[(q + 4) >> 2] | 0; - x = I; - c[x >> 2] = c[q >> 2]; - c[(x + 4) >> 2] = t; - x = 54; - break; - } - if (!y) { - e = 0; - break a; - } - vo(I, p, f, k); - m = c[G >> 2] | 0; - x = 55; - } - while (0); - if ((x | 0) == 54) { - x = 0; - if (y) - x = 55; - else - l = 0; - } - d: do - if ((x | 0) == 55) { - x = 0; - m = a[(m + -1) >> 0] | 0; - m = ((s | 0) != 0) & (((m & 15) | 0) == 3) ? m & -33 : m; - n = o & -65537; - t = ((o & 8192) | 0) == 0 ? o : n; - e: do - switch (m | 0) { - case 110: - switch (((s & 255) << 24) >> 24) { - case 0: { - c[c[I >> 2] >> 2] = e; - l = 0; - break d; - } - case 1: { - c[c[I >> 2] >> 2] = e; - l = 0; - break d; - } - case 2: { - l = c[I >> 2] | 0; - c[l >> 2] = e; - c[(l + 4) >> 2] = (((e | 0) < 0) << 31) >> 31; - l = 0; - break d; - } - case 3: { - b[c[I >> 2] >> 1] = e; - l = 0; - break d; - } - case 4: { - a[c[I >> 2] >> 0] = e; - l = 0; - break d; - } - case 6: { - c[c[I >> 2] >> 2] = e; - l = 0; - break d; - } - case 7: { - l = c[I >> 2] | 0; - c[l >> 2] = e; - c[(l + 4) >> 2] = (((e | 0) < 0) << 31) >> 31; - l = 0; - break d; - } - default: { - l = 0; - break d; - } - } - case 112: { - m = 120; - l = l >>> 0 > 8 ? l : 8; - n = t | 8; - x = 67; - break; - } - case 88: - case 120: { - n = t; - x = 67; - break; - } - case 111: { - q = I; - q = xo(c[q >> 2] | 0, c[(q + 4) >> 2] | 0, z) | 0; - n = (A - q) | 0; - o = 0; - p = 20230; - l = (((t & 8) | 0) == 0) | ((l | 0) > (n | 0)) ? l : (n + 1) | 0; - n = t; - x = 73; - break; - } - case 105: - case 100: { - n = I; - m = c[n >> 2] | 0; - n = c[(n + 4) >> 2] | 0; - if ((n | 0) < 0) { - m = mr(0, 0, m | 0, n | 0) | 0; - n = u() | 0; - o = I; - c[o >> 2] = m; - c[(o + 4) >> 2] = n; - o = 1; - p = 20230; - x = 72; - break e; - } - else { - o = (((t & 2049) | 0) != 0) & 1; - p = ((t & 2048) | 0) == 0 ? (((t & 1) | 0) == 0 ? 20230 : 20232) : 20231; - x = 72; - break e; - } - } - case 117: { - n = I; - o = 0; - p = 20230; - m = c[n >> 2] | 0; - n = c[(n + 4) >> 2] | 0; - x = 72; - break; - } - case 99: { - a[B >> 0] = c[I >> 2]; - r = B; - o = 0; - p = 20230; - q = 1; - m = n; - l = A; - break; - } - case 115: { - s = c[I >> 2] | 0; - s = (s | 0) == 0 ? 20240 : s; - t = no(s, 0, l) | 0; - K = (t | 0) == 0; - r = s; - o = 0; - p = 20230; - q = K ? l : (t - s) | 0; - m = n; - l = K ? (s + l) | 0 : t; - break; - } - case 67: { - c[D >> 2] = c[I >> 2]; - c[C >> 2] = 0; - c[I >> 2] = D; - p = -1; - x = 79; - break; - } - case 83: { - if (!l) { - zo(d, 32, v, 0, t); - l = 0; - x = 89; - } - else { - p = l; - x = 79; - } - break; - } - case 65: - case 71: - case 70: - case 69: - case 97: - case 103: - case 102: - case 101: { - l = _[j & 1](d, +g[I >> 3], v, l, t, m) | 0; - break d; - } - default: { - o = 0; - p = 20230; - q = l; - m = t; - l = A; - } - } - while (0); - f: do - if ((x | 0) == 67) { - q = I; - q = wo(c[q >> 2] | 0, c[(q + 4) >> 2] | 0, z, m & 32) | 0; - p = I; - p = (((n & 8) | 0) == 0) | (((c[p >> 2] | 0) == 0) & ((c[(p + 4) >> 2] | 0) == 0)); - o = p ? 0 : 2; - p = p ? 20230 : (20230 + (m >>> 4)) | 0; - x = 73; - } - else if ((x | 0) == 72) { - q = yo(m, n, z) | 0; - n = t; - x = 73; - } - else if ((x | 0) == 79) { - x = 0; - o = c[I >> 2] | 0; - l = 0; - while (1) { - m = c[o >> 2] | 0; - if (!m) - break; - m = Ao(E, m) | 0; - n = (m | 0) < 0; - if (n | (m >>> 0 > ((p - l) | 0) >>> 0)) { - x = 83; - break; - } - l = (m + l) | 0; - if (p >>> 0 > l >>> 0) - o = (o + 4) | 0; - else - break; - } - if ((x | 0) == 83) { - x = 0; - if (n) { - e = -1; - break a; - } - } - zo(d, 32, v, l, t); - if (!l) { - l = 0; - x = 89; - } - else { - n = c[I >> 2] | 0; - o = 0; - while (1) { - m = c[n >> 2] | 0; - if (!m) { - x = 89; - break f; - } - m = Ao(E, m) | 0; - o = (m + o) | 0; - if ((o | 0) > (l | 0)) { - x = 89; - break f; - } - to(d, E, m); - if (o >>> 0 >= l >>> 0) { - x = 89; - break; - } - else - n = (n + 4) | 0; - } - } - } - while (0); - if ((x | 0) == 73) { - x = 0; - m = I; - m = ((c[m >> 2] | 0) != 0) | ((c[(m + 4) >> 2] | 0) != 0); - K = ((l | 0) != 0) | m; - m = (A - q + ((m ^ 1) & 1)) | 0; - r = K ? q : z; - q = K ? ((l | 0) > (m | 0) ? l : m) : 0; - m = (l | 0) > -1 ? n & -65537 : n; - l = A; - } - else if ((x | 0) == 89) { - x = 0; - zo(d, 32, v, l, t ^ 8192); - l = (v | 0) > (l | 0) ? v : l; - break; - } - t = (l - r) | 0; - s = (q | 0) < (t | 0) ? t : q; - K = (s + o) | 0; - l = (v | 0) < (K | 0) ? K : v; - zo(d, 32, l, K, m); - to(d, p, o); - zo(d, 48, l, K, m ^ 65536); - zo(d, 48, s, t, 0); - to(d, r, t); - zo(d, 32, l, K, m ^ 8192); - } - while (0); - n = w; - } - g: do - if ((x | 0) == 92) - if (!d) - if (!n) - e = 0; - else { - e = 1; - while (1) { - l = c[(i + (e << 2)) >> 2] | 0; - if (!l) - break; - vo((h + (e << 3)) | 0, l, f, k); - e = (e + 1) | 0; - if (e >>> 0 >= 10) { - e = 1; - break g; - } - } - while (1) { - if (c[(i + (e << 2)) >> 2] | 0) { - e = -1; - break g; - } - e = (e + 1) | 0; - if (e >>> 0 >= 10) { - e = 1; - break; - } - } - } - while (0); - V = J; - return e | 0; - } - function to(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - if (!(c[a >> 2] & 32)) - jo(b, d, a) | 0; - return; - } - function uo(b) { - b = b | 0; - var d = 0, e = 0; - if (!(bo(a[c[b >> 2] >> 0] | 0) | 0)) - d = 0; - else { - d = 0; - do { - e = c[b >> 2] | 0; - d = (((d * 10) | 0) + -48 + (a[e >> 0] | 0)) | 0; - e = (e + 1) | 0; - c[b >> 2] = e; - } while ((bo(a[e >> 0] | 0) | 0) != 0); - } - return d | 0; - } - function vo(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, h = 0.0; - a: do - if (b >>> 0 <= 20) - do - switch (b | 0) { - case 9: { - b = ((c[d >> 2] | 0) + (4 - 1)) & ~(4 - 1); - e = c[b >> 2] | 0; - c[d >> 2] = b + 4; - c[a >> 2] = e; - break a; - } - case 10: { - e = ((c[d >> 2] | 0) + (4 - 1)) & ~(4 - 1); - b = c[e >> 2] | 0; - c[d >> 2] = e + 4; - e = a; - c[e >> 2] = b; - c[(e + 4) >> 2] = (((b | 0) < 0) << 31) >> 31; - break a; - } - case 11: { - e = ((c[d >> 2] | 0) + (4 - 1)) & ~(4 - 1); - b = c[e >> 2] | 0; - c[d >> 2] = e + 4; - e = a; - c[e >> 2] = b; - c[(e + 4) >> 2] = 0; - break a; - } - case 12: { - e = ((c[d >> 2] | 0) + (8 - 1)) & ~(8 - 1); - b = e; - f = c[b >> 2] | 0; - b = c[(b + 4) >> 2] | 0; - c[d >> 2] = e + 8; - e = a; - c[e >> 2] = f; - c[(e + 4) >> 2] = b; - break a; - } - case 13: { - f = ((c[d >> 2] | 0) + (4 - 1)) & ~(4 - 1); - e = c[f >> 2] | 0; - c[d >> 2] = f + 4; - e = ((e & 65535) << 16) >> 16; - f = a; - c[f >> 2] = e; - c[(f + 4) >> 2] = (((e | 0) < 0) << 31) >> 31; - break a; - } - case 14: { - f = ((c[d >> 2] | 0) + (4 - 1)) & ~(4 - 1); - e = c[f >> 2] | 0; - c[d >> 2] = f + 4; - f = a; - c[f >> 2] = e & 65535; - c[(f + 4) >> 2] = 0; - break a; - } - case 15: { - f = ((c[d >> 2] | 0) + (4 - 1)) & ~(4 - 1); - e = c[f >> 2] | 0; - c[d >> 2] = f + 4; - e = ((e & 255) << 24) >> 24; - f = a; - c[f >> 2] = e; - c[(f + 4) >> 2] = (((e | 0) < 0) << 31) >> 31; - break a; - } - case 16: { - f = ((c[d >> 2] | 0) + (4 - 1)) & ~(4 - 1); - e = c[f >> 2] | 0; - c[d >> 2] = f + 4; - f = a; - c[f >> 2] = e & 255; - c[(f + 4) >> 2] = 0; - break a; - } - case 17: { - f = ((c[d >> 2] | 0) + (8 - 1)) & ~(8 - 1); - h = +g[f >> 3]; - c[d >> 2] = f + 8; - g[a >> 3] = h; - break a; - } - case 18: { - da[e & 15](a, d); - break a; - } - default: - break a; - } - while (0); - while (0); - return; - } - function wo(b, c, e, f) { - b = b | 0; - c = c | 0; - e = e | 0; - f = f | 0; - if (!(((b | 0) == 0) & ((c | 0) == 0))) - do { - e = (e + -1) | 0; - a[e >> 0] = d[(640 + (b & 15)) >> 0] | 0 | f; - b = qr(b | 0, c | 0, 4) | 0; - c = u() | 0; - } while (!(((b | 0) == 0) & ((c | 0) == 0))); - return e | 0; - } - function xo(b, c, d) { - b = b | 0; - c = c | 0; - d = d | 0; - if (!(((b | 0) == 0) & ((c | 0) == 0))) - do { - d = (d + -1) | 0; - a[d >> 0] = (b & 7) | 48; - b = qr(b | 0, c | 0, 3) | 0; - c = u() | 0; - } while (!(((b | 0) == 0) & ((c | 0) == 0))); - return d | 0; - } - function yo(b, c, d) { - b = b | 0; - c = c | 0; - d = d | 0; - var e = 0, f = 0, g = 0; - if ((c >>> 0 > 0) | (((c | 0) == 0) & (b >>> 0 > 4294967295))) { - do { - e = b; - b = pr(b | 0, c | 0, 10, 0) | 0; - f = c; - c = u() | 0; - g = kr(b | 0, c | 0, 10, 0) | 0; - g = mr(e | 0, f | 0, g | 0, u() | 0) | 0; - u() | 0; - d = (d + -1) | 0; - a[d >> 0] = (g & 255) | 48; - } while ((f >>> 0 > 9) | (((f | 0) == 9) & (e >>> 0 > 4294967295))); - c = b; - } - else - c = b; - if (c) - do { - g = c; - c = ((c >>> 0) / 10) | 0; - d = (d + -1) | 0; - a[d >> 0] = (g - ((c * 10) | 0)) | 48; - } while (g >>> 0 >= 10); - return d | 0; - } - function zo(a, b, c, d, e) { - a = a | 0; - b = b | 0; - c = c | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0; - g = V; - V = (V + 256) | 0; - f = g; - if (((c | 0) > (d | 0)) & (((e & 73728) | 0) == 0)) { - e = (c - d) | 0; - wr(f | 0, ((b << 24) >> 24) | 0, (e >>> 0 < 256 ? e : 256) | 0) | 0; - if (e >>> 0 > 255) { - b = (c - d) | 0; - do { - to(a, f, 256); - e = (e + -256) | 0; - } while (e >>> 0 > 255); - e = b & 255; - } - to(a, f, e); - } - V = g; - return; - } - function Ao(a, b) { - a = a | 0; - b = b | 0; - if (!a) - a = 0; - else - a = Bo(a, b, 0) | 0; - return a | 0; - } - function Bo(b, d, e) { - b = b | 0; - d = d | 0; - e = e | 0; - do - if (b) { - if (d >>> 0 < 128) { - a[b >> 0] = d; - b = 1; - break; - } - if (!(c[c[((Co() | 0) + 176) >> 2] >> 2] | 0)) - if (((d & -128) | 0) == 57216) { - a[b >> 0] = d; - b = 1; - break; - } - else { - c[(ao() | 0) >> 2] = 25; - b = -1; - break; - } - if (d >>> 0 < 2048) { - a[b >> 0] = (d >>> 6) | 192; - a[(b + 1) >> 0] = (d & 63) | 128; - b = 2; - break; - } - if ((d >>> 0 < 55296) | (((d & -8192) | 0) == 57344)) { - a[b >> 0] = (d >>> 12) | 224; - a[(b + 1) >> 0] = ((d >>> 6) & 63) | 128; - a[(b + 2) >> 0] = (d & 63) | 128; - b = 3; - break; - } - if (((d + -65536) | 0) >>> 0 < 1048576) { - a[b >> 0] = (d >>> 18) | 240; - a[(b + 1) >> 0] = ((d >>> 12) & 63) | 128; - a[(b + 2) >> 0] = ((d >>> 6) & 63) | 128; - a[(b + 3) >> 0] = (d & 63) | 128; - b = 4; - break; - } - else { - c[(ao() | 0) >> 2] = 25; - b = -1; - break; - } - } - else - b = 1; - while (0); - return b | 0; - } - function Co() { - return co() | 0; - } - function Do(a) { - a = +a; - var b = 0; - g[h >> 3] = a; - b = c[h >> 2] | 0; - t(c[(h + 4) >> 2] | 0); - return b | 0; - } - function Eo(a, b) { - a = +a; - b = b | 0; - var d = 0, e = 0, f = 0; - g[h >> 3] = a; - d = c[h >> 2] | 0; - e = c[(h + 4) >> 2] | 0; - f = qr(d | 0, e | 0, 52) | 0; - u() | 0; - switch (f & 2047) { - case 0: { - if (a != 0.0) { - a = +Eo(a * 18446744073709551616.0, b); - d = ((c[b >> 2] | 0) + -64) | 0; - } - else - d = 0; - c[b >> 2] = d; - break; - } - case 2047: - break; - default: { - c[b >> 2] = (f & 2047) + -1022; - c[h >> 2] = d; - c[(h + 4) >> 2] = (e & -2146435073) | 1071644672; - a = +g[h >> 3]; - } - } - return +a; - } - function Fo(b, c, d) { - b = b | 0; - c = c | 0; - d = d | 0; - var e = 0, f = 0; - a: do - if (!d) - b = 0; - else { - while (1) { - e = a[b >> 0] | 0; - f = a[c >> 0] | 0; - if ((e << 24) >> 24 != (f << 24) >> 24) - break; - d = (d + -1) | 0; - if (!d) { - b = 0; - break a; - } - else { - b = (b + 1) | 0; - c = (c + 1) | 0; - } - } - b = ((e & 255) - (f & 255)) | 0; - } - while (0); - return b | 0; - } - function Go(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0; - f = V; - V = (V + 16) | 0; - g = f; - c[g >> 2] = e; - e = Ho(a, b, d, g) | 0; - V = f; - return e | 0; - } - function Ho(b, d, e, f) { - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - var g = 0, h = 0, i = 0, j = 0; - j = V; - V = (V + 160) | 0; - g = (j + 144) | 0; - i = j; - ur(i | 0, 3672, 144) | 0; - if (((d + -1) | 0) >>> 0 > 2147483646) - if (!d) { - b = g; - d = 1; - h = 4; - } - else { - c[(ao() | 0) >> 2] = 61; - d = -1; - } - else - h = 4; - if ((h | 0) == 4) { - h = (-2 - b) | 0; - h = d >>> 0 > h >>> 0 ? h : d; - c[(i + 48) >> 2] = h; - g = (i + 20) | 0; - c[g >> 2] = b; - c[(i + 44) >> 2] = b; - d = (b + h) | 0; - b = (i + 16) | 0; - c[b >> 2] = d; - c[(i + 28) >> 2] = d; - d = oo(i, e, f) | 0; - if (h) { - i = c[g >> 2] | 0; - a[(i + ((((i | 0) == (c[b >> 2] | 0)) << 31) >> 31)) >> 0] = 0; - } - } - V = j; - return d | 0; - } - function Io(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - e = (a + 20) | 0; - f = c[e >> 2] | 0; - a = ((c[(a + 16) >> 2] | 0) - f) | 0; - a = a >>> 0 > d >>> 0 ? d : a; - ur(f | 0, b | 0, a | 0) | 0; - c[e >> 2] = (c[e >> 2] | 0) + a; - return d | 0; - } - function Jo(a) { - a = a | 0; - var b = 0, c = 0; - b = ((fo(a) | 0) + 1) | 0; - c = dr(b) | 0; - if (!c) - a = 0; - else - a = ur(c | 0, a | 0, b | 0) | 0; - return a | 0; - } - function Ko(b, e) { - b = b | 0; - e = e | 0; - var f = 0, g = 0; - f = 0; - while (1) { - if ((d[(656 + f) >> 0] | 0) == (b | 0)) { - g = 4; - break; - } - f = (f + 1) | 0; - if ((f | 0) == 87) { - b = 87; - g = 5; - break; - } - } - if ((g | 0) == 4) - if (!f) - f = 752; - else { - b = f; - g = 5; - } - if ((g | 0) == 5) { - f = 752; - do { - do { - g = f; - f = (f + 1) | 0; - } while ((a[g >> 0] | 0) != 0); - b = (b + -1) | 0; - } while ((b | 0) != 0); - } - return Lo(f, c[(e + 20) >> 2] | 0) | 0; - } - function Lo(a, b) { - a = a | 0; - b = b | 0; - return ko(a, b) | 0; - } - function Mo(a) { - a = a | 0; - return Ko(a, c[((No() | 0) + 176) >> 2] | 0) | 0; - } - function No() { - return co() | 0; - } - function Oo(b, c, d) { - b = b | 0; - c = c | 0; - d = d | 0; - var e = 0; - e = Mo(b) | 0; - b = fo(e) | 0; - if (b >>> 0 >= d >>> 0) { - b = (d + -1) | 0; - if (!d) - b = 68; - else { - ur(c | 0, e | 0, b | 0) | 0; - a[(c + b) >> 0] = 0; - b = 68; - } - } - else { - ur(c | 0, e | 0, (b + 1) | 0) | 0; - b = 0; - } - return b | 0; - } - function Po() { - var a = 0, b = 0, d = 0, e = 0, f = 0, g = 0, h = 0; - e = V; - V = (V + 48) | 0; - g = (e + 32) | 0; - b = (e + 24) | 0; - h = (e + 16) | 0; - f = e; - e = (e + 36) | 0; - a = Qo() | 0; - if (a | 0 ? ((d = c[a >> 2] | 0), d | 0) : 0) { - a = (d + 48) | 0; - if (!(Ro(a) | 0)) { - c[b >> 2] = 20420; - To(20370, b); - } - b = So(a) | 0; - if (((b | 0) == 1126902529) & ((u() | 0) == 1129074247)) - a = c[(d + 44) >> 2] | 0; - else - a = (d + 80) | 0; - c[e >> 2] = a; - d = c[d >> 2] | 0; - a = c[(d + 4) >> 2] | 0; - if (aa[c[((c[954] | 0) + 16) >> 2] & 7](3816, d, e) | 0) { - h = c[e >> 2] | 0; - h = Z[c[((c[h >> 2] | 0) + 8) >> 2] & 15](h) | 0; - c[f >> 2] = 20420; - c[(f + 4) >> 2] = a; - c[(f + 8) >> 2] = h; - To(20284, f); - } - else { - c[h >> 2] = 20420; - c[(h + 4) >> 2] = a; - To(20329, h); - } - } - To(20408, g); - } - function Qo() { - return 21640; - } - function Ro(a) { - a = a | 0; - a = So(a) | 0; - return ((((a & -256) | 0) == 1126902528) & ((u() | 0) == 1129074247)) | 0; - } - function So(a) { - a = a | 0; - var b = 0; - b = a; - a = c[b >> 2] | 0; - t(c[(b + 4) >> 2] | 0); - return a | 0; - } - function To(a, b) { - a = a | 0; - b = b | 0; - U(); - } - function Uo(a) { - a = a | 0; - return; - } - function Vo(a) { - a = a | 0; - Uo(a); - jp(a); - return; - } - function Wo(a) { - a = a | 0; - return; - } - function Xo(a) { - a = a | 0; - return; - } - function Yo(d, e, f) { - d = d | 0; - e = e | 0; - f = f | 0; - var g = 0, h = 0, i = 0, j = 0, k = 0, l = 0; - l = V; - V = (V + 64) | 0; - j = l; - if (!(ap(d, e, 0) | 0)) - if ((e | 0) != 0 ? ((k = ep(e, 3840, 3824, 0) | 0), (k | 0) != 0) : 0) { - c[j >> 2] = k; - c[(j + 4) >> 2] = 0; - c[(j + 8) >> 2] = d; - c[(j + 12) >> 2] = -1; - d = (j + 16) | 0; - e = (j + 24) | 0; - g = (j + 48) | 0; - h = d; - i = (h + 36) | 0; - do { - c[h >> 2] = 0; - h = (h + 4) | 0; - } while ((h | 0) < (i | 0)); - b[(d + 36) >> 1] = 0; - a[(d + 38) >> 0] = 0; - c[g >> 2] = 1; - fa[c[((c[k >> 2] | 0) + 28) >> 2] & 7](k, j, c[f >> 2] | 0, 1); - if ((c[e >> 2] | 0) == 1) { - c[f >> 2] = c[d >> 2]; - d = 1; - } - else - d = 0; - } - else - d = 0; - else - d = 1; - V = l; - return d | 0; - } - function Zo(a, b, d, e, f, g) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - g = g | 0; - if (ap(a, c[(b + 8) >> 2] | 0, g) | 0) - dp(0, b, d, e, f); - return; - } - function _o(b, d, e, f, g) { - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - g = g | 0; - var h = 0; - do - if (!(ap(b, c[(d + 8) >> 2] | 0, g) | 0)) { - if (ap(b, c[d >> 2] | 0, g) | 0) { - if ((c[(d + 16) >> 2] | 0) != (e | 0) - ? ((h = (d + 20) | 0), (c[h >> 2] | 0) != (e | 0)) - : 0) { - c[(d + 32) >> 2] = f; - c[h >> 2] = e; - g = (d + 40) | 0; - c[g >> 2] = (c[g >> 2] | 0) + 1; - if ((c[(d + 36) >> 2] | 0) == 1 ? (c[(d + 24) >> 2] | 0) == 2 : 0) - a[(d + 54) >> 0] = 1; - c[(d + 44) >> 2] = 4; - break; - } - if ((f | 0) == 1) - c[(d + 32) >> 2] = 1; - } - } - else - cp(0, d, e, f); - while (0); - return; - } - function $o(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - if (ap(a, c[(b + 8) >> 2] | 0, 0) | 0) - bp(0, b, d, e); - return; - } - function ap(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - if (d) - if ((a | 0) == (b | 0)) - a = 1; - else - a = (eo(c[(a + 4) >> 2] | 0, c[(b + 4) >> 2] | 0) | 0) == 0; - else - a = (c[(a + 4) >> 2] | 0) == (c[(b + 4) >> 2] | 0); - return a | 0; - } - function bp(b, d, e, f) { - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - var g = 0; - b = (d + 16) | 0; - g = c[b >> 2] | 0; - do - if (g) { - if ((g | 0) != (e | 0)) { - f = (d + 36) | 0; - c[f >> 2] = (c[f >> 2] | 0) + 1; - c[(d + 24) >> 2] = 2; - a[(d + 54) >> 0] = 1; - break; - } - b = (d + 24) | 0; - if ((c[b >> 2] | 0) == 2) - c[b >> 2] = f; - } - else { - c[b >> 2] = e; - c[(d + 24) >> 2] = f; - c[(d + 36) >> 2] = 1; - } - while (0); - return; - } - function cp(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0; - if ((c[(b + 4) >> 2] | 0) == (d | 0) ? ((f = (b + 28) | 0), (c[f >> 2] | 0) != 1) : 0) - c[f >> 2] = e; - return; - } - function dp(b, d, e, f, g) { - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - g = g | 0; - a[(d + 53) >> 0] = 1; - do - if ((c[(d + 4) >> 2] | 0) == (f | 0)) { - a[(d + 52) >> 0] = 1; - b = (d + 16) | 0; - f = c[b >> 2] | 0; - if (!f) { - c[b >> 2] = e; - c[(d + 24) >> 2] = g; - c[(d + 36) >> 2] = 1; - if (!((g | 0) == 1 ? (c[(d + 48) >> 2] | 0) == 1 : 0)) - break; - a[(d + 54) >> 0] = 1; - break; - } - if ((f | 0) != (e | 0)) { - g = (d + 36) | 0; - c[g >> 2] = (c[g >> 2] | 0) + 1; - a[(d + 54) >> 0] = 1; - break; - } - f = (d + 24) | 0; - b = c[f >> 2] | 0; - if ((b | 0) == 2) { - c[f >> 2] = g; - b = g; - } - if ((b | 0) == 1 ? (c[(d + 48) >> 2] | 0) == 1 : 0) - a[(d + 54) >> 0] = 1; - } - while (0); - return; - } - function ep(d, e, f, g) { - d = d | 0; - e = e | 0; - f = f | 0; - g = g | 0; - var h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0; - p = V; - V = (V + 64) | 0; - n = p; - m = c[d >> 2] | 0; - o = (d + (c[(m + -8) >> 2] | 0)) | 0; - m = c[(m + -4) >> 2] | 0; - c[n >> 2] = f; - c[(n + 4) >> 2] = d; - c[(n + 8) >> 2] = e; - c[(n + 12) >> 2] = g; - d = (n + 16) | 0; - e = (n + 20) | 0; - g = (n + 24) | 0; - h = (n + 28) | 0; - i = (n + 32) | 0; - j = (n + 40) | 0; - k = d; - l = (k + 36) | 0; - do { - c[k >> 2] = 0; - k = (k + 4) | 0; - } while ((k | 0) < (l | 0)); - b[(d + 36) >> 1] = 0; - a[(d + 38) >> 0] = 0; - a: do - if (ap(m, f, 0) | 0) { - c[(n + 48) >> 2] = 1; - ha[c[((c[m >> 2] | 0) + 20) >> 2] & 3](m, n, o, o, 1, 0); - d = (c[g >> 2] | 0) == 1 ? o : 0; - } - else { - ga[c[((c[m >> 2] | 0) + 24) >> 2] & 3](m, n, o, 1, 0); - switch (c[(n + 36) >> 2] | 0) { - case 0: { - d = - ((c[j >> 2] | 0) == 1) & ((c[h >> 2] | 0) == 1) & ((c[i >> 2] | 0) == 1) - ? c[e >> 2] | 0 - : 0; - break a; - } - case 1: - break; - default: { - d = 0; - break a; - } - } - if ((c[g >> 2] | 0) != 1 - ? !(((c[j >> 2] | 0) == 0) & ((c[h >> 2] | 0) == 1) & ((c[i >> 2] | 0) == 1)) - : 0) { - d = 0; - break; - } - d = c[d >> 2] | 0; - } - while (0); - V = p; - return d | 0; - } - function fp(a) { - a = a | 0; - Uo(a); - jp(a); - return; - } - function gp(a, b, d, e, f, g) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - g = g | 0; - if (ap(a, c[(b + 8) >> 2] | 0, g) | 0) - dp(0, b, d, e, f); - else { - a = c[(a + 8) >> 2] | 0; - ha[c[((c[a >> 2] | 0) + 20) >> 2] & 3](a, b, d, e, f, g); - } - return; - } - function hp(b, d, e, f, g) { - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - g = g | 0; - var h = 0, i = 0, j = 0; - a: do - if (!(ap(b, c[(d + 8) >> 2] | 0, g) | 0)) { - if (!(ap(b, c[d >> 2] | 0, g) | 0)) { - i = c[(b + 8) >> 2] | 0; - ga[c[((c[i >> 2] | 0) + 24) >> 2] & 3](i, d, e, f, g); - break; - } - if ((c[(d + 16) >> 2] | 0) != (e | 0) ? ((i = (d + 20) | 0), (c[i >> 2] | 0) != (e | 0)) : 0) { - c[(d + 32) >> 2] = f; - f = (d + 44) | 0; - do - if ((c[f >> 2] | 0) != 4) { - h = (d + 52) | 0; - a[h >> 0] = 0; - j = (d + 53) | 0; - a[j >> 0] = 0; - b = c[(b + 8) >> 2] | 0; - ha[c[((c[b >> 2] | 0) + 20) >> 2] & 3](b, d, e, e, 1, g); - if (a[j >> 0] | 0) { - j = (a[h >> 0] | 0) == 0; - c[f >> 2] = 3; - if (j) - break; - else - break a; - } - else { - c[f >> 2] = 4; - break; - } - } - while (0); - c[i >> 2] = e; - j = (d + 40) | 0; - c[j >> 2] = (c[j >> 2] | 0) + 1; - if ((c[(d + 36) >> 2] | 0) != 1) - break; - if ((c[(d + 24) >> 2] | 0) != 2) - break; - a[(d + 54) >> 0] = 1; - break; - } - if ((f | 0) == 1) - c[(d + 32) >> 2] = 1; - } - else - cp(0, d, e, f); - while (0); - return; - } - function ip(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - if (ap(a, c[(b + 8) >> 2] | 0, 0) | 0) - bp(0, b, d, e); - else { - a = c[(a + 8) >> 2] | 0; - fa[c[((c[a >> 2] | 0) + 28) >> 2] & 7](a, b, d, e); - } - return; - } - function jp(a) { - a = a | 0; - er(a); - return; - } - function kp(a) { - a = a | 0; - return; - } - function lp() { - var a = 0, b = 0; - a = Qo() | 0; - if ((a | 0 ? ((b = c[a >> 2] | 0), b | 0) : 0) ? Ro((b + 48) | 0) | 0 : 0) - mp(c[(b + 12) >> 2] | 0); - mp(np() | 0); - } - function mp(a) { - a = a | 0; - var b = 0; - b = V; - V = (V + 16) | 0; - ba[a & 3](); - To(20559, b); - } - function np() { - return 2; - } - function op(a) { - a = a | 0; - return; - } - function pp(a) { - a = a | 0; - jp(a); - return; - } - function qp(a) { - a = a | 0; - return 20599; - } - function rp(a) { - a = a | 0; - c[a >> 2] = 5916; - vp((a + 4) | 0); - return; - } - function sp(a) { - a = a | 0; - rp(a); - jp(a); - return; - } - function tp(a) { - a = a | 0; - return up((a + 4) | 0) | 0; - } - function up(a) { - a = a | 0; - return c[a >> 2] | 0; - } - function vp(a) { - a = a | 0; - var b = 0, d = 0; - if (wp(a) | 0 - ? ((b = xp(c[a >> 2] | 0) | 0), - (d = (b + 8) | 0), - (a = c[d >> 2] | 0), - (c[d >> 2] = a + -1), - (a | 0) < 1) - : 0) - jp(b); - return; - } - function wp(a) { - a = a | 0; - return 1; - } - function xp(a) { - a = a | 0; - return (a + -12) | 0; - } - function yp(a) { - a = a | 0; - c[a >> 2] = 5936; - vp((a + 4) | 0); - return; - } - function zp(a) { - a = a | 0; - yp(a); - jp(a); - return; - } - function Ap(a) { - a = a | 0; - return up((a + 4) | 0) | 0; - } - function Bp(a) { - a = a | 0; - rp(a); - jp(a); - return; - } - function Cp(a) { - a = a | 0; - rp(a); - jp(a); - return; - } - function Dp() { - var a = 0; - a = V; - V = (V + 16) | 0; - To(20848, a); - } - function Ep(a) { - a = a | 0; - Uo(a); - jp(a); - return; - } - function Fp(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - return ap(a, b, 0) | 0; - } - function Gp(a) { - a = a | 0; - Uo(a); - jp(a); - return; - } - function Hp(d, e, f) { - d = d | 0; - e = e | 0; - f = f | 0; - var g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0; - n = V; - V = (V + 64) | 0; - l = n; - do - if (!(ap(e, 4048, 0) | 0)) { - if (Ip(d, e, 0) | 0) { - e = c[f >> 2] | 0; - if (!e) { - e = 1; - break; - } - c[f >> 2] = c[e >> 2]; - e = 1; - break; - } - if ((e | 0) != 0 ? ((g = ep(e, 3840, 3976, 0) | 0), (g | 0) != 0) : 0) { - e = c[f >> 2] | 0; - if (e | 0) - c[f >> 2] = c[e >> 2]; - e = c[(g + 8) >> 2] | 0; - i = (d + 8) | 0; - h = c[i >> 2] | 0; - if (((e & 7 & (h ^ 7)) | 0) == 0 ? ((((e & 96) ^ 96) & h) | 0) == 0 : 0) { - h = (d + 12) | 0; - d = c[h >> 2] | 0; - g = (g + 12) | 0; - e = c[g >> 2] | 0; - if (!(ap(d, e, 0) | 0)) { - if (ap(d, 4040, 0) | 0) { - if (!e) { - e = 1; - break; - } - e = (ep(e, 3840, 3992, 0) | 0) == 0; - break; - } - if (d) { - e = ep(d, 3840, 3976, 0) | 0; - if (e | 0) { - if (!(c[i >> 2] & 1)) { - e = 0; - break; - } - e = Jp(e, c[g >> 2] | 0) | 0; - break; - } - e = c[h >> 2] | 0; - if (e) { - e = ep(e, 3840, 4008, 0) | 0; - if (e | 0) { - if (!(c[i >> 2] & 1)) { - e = 0; - break; - } - e = Kp(e, c[g >> 2] | 0) | 0; - break; - } - e = c[h >> 2] | 0; - if ((((e | 0) != 0 ? ((j = ep(e, 3840, 3824, 0) | 0), (j | 0) != 0) : 0) - ? ((k = c[g >> 2] | 0), (k | 0) != 0) - : 0) - ? ((m = ep(k, 3840, 3824, 0) | 0), (m | 0) != 0) - : 0) { - c[l >> 2] = m; - c[(l + 4) >> 2] = 0; - c[(l + 8) >> 2] = j; - c[(l + 12) >> 2] = -1; - e = (l + 16) | 0; - d = (l + 24) | 0; - g = (l + 48) | 0; - h = e; - i = (h + 36) | 0; - do { - c[h >> 2] = 0; - h = (h + 4) | 0; - } while ((h | 0) < (i | 0)); - b[(e + 36) >> 1] = 0; - a[(e + 38) >> 0] = 0; - c[g >> 2] = 1; - fa[c[((c[m >> 2] | 0) + 28) >> 2] & 7](m, l, c[f >> 2] | 0, 1); - do - if ((c[d >> 2] | 0) == 1) { - if (!(c[f >> 2] | 0)) { - e = 1; - break; - } - c[f >> 2] = c[e >> 2]; - e = 1; - } - else - e = 0; - while (0); - } - else - e = 0; - } - else - e = 0; - } - else - e = 0; - } - else - e = 1; - } - else - e = 0; - } - else - e = 0; - } - else { - c[f >> 2] = 0; - e = 1; - } - while (0); - V = n; - return e | 0; - } - function Ip(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - if (!(c[(a + 8) >> 2] & 24)) - if ((b | 0) != 0 ? ((e = ep(b, 3840, 3960, 0) | 0), (e | 0) != 0) : 0) { - d = ((c[(e + 8) >> 2] & 24) | 0) != 0; - f = 5; - } - else - d = 0; - else { - d = 1; - f = 5; - } - if ((f | 0) == 5) - d = ap(a, b, d) | 0; - return d | 0; - } - function Jp(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0, g = 0, h = 0; - while (1) { - if (!b) { - b = 0; - break; - } - d = ep(b, 3840, 3976, 0) | 0; - if (!d) { - b = 0; - break; - } - f = c[(a + 8) >> 2] | 0; - if ((c[(d + 8) >> 2] & ~f) | 0) { - b = 0; - break; - } - e = (a + 12) | 0; - b = c[e >> 2] | 0; - d = (d + 12) | 0; - if (ap(b, c[d >> 2] | 0, 0) | 0) { - b = 1; - break; - } - if ((((f & 1) | 0) == 0) | ((b | 0) == 0)) { - b = 0; - break; - } - a = ep(b, 3840, 3976, 0) | 0; - if (!a) { - h = 9; - break; - } - b = c[d >> 2] | 0; - } - if ((h | 0) == 9) { - b = c[e >> 2] | 0; - if ((b | 0) != 0 ? ((g = ep(b, 3840, 4008, 0) | 0), (g | 0) != 0) : 0) - b = Kp(g, c[d >> 2] | 0) | 0; - else - b = 0; - } - return b | 0; - } - function Kp(a, b) { - a = a | 0; - b = b | 0; - var d = 0; - if ((((b | 0) != 0 ? ((d = ep(b, 3840, 4008, 0) | 0), (d | 0) != 0) : 0) - ? ((c[(d + 8) >> 2] & ~c[(a + 8) >> 2]) | 0) == 0 - : 0) - ? ap(c[(a + 12) >> 2] | 0, c[(d + 12) >> 2] | 0, 0) | 0 - : 0) - a = ap(c[(a + 16) >> 2] | 0, c[(d + 16) >> 2] | 0, 0) | 0; - else - a = 0; - return a | 0; - } - function Lp(a) { - a = a | 0; - Uo(a); - jp(a); - return; - } - function Mp(b, d, e, f, g, h) { - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - g = g | 0; - h = h | 0; - var i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, q = 0, r = 0; - if (ap(b, c[(d + 8) >> 2] | 0, h) | 0) - dp(0, d, e, f, g); - else { - r = (d + 52) | 0; - j = a[r >> 0] | 0; - q = (d + 53) | 0; - i = a[q >> 0] | 0; - p = c[(b + 12) >> 2] | 0; - m = (b + 16 + (p << 3)) | 0; - a[r >> 0] = 0; - a[q >> 0] = 0; - Qp((b + 16) | 0, d, e, f, g, h); - k = a[r >> 0] | 0; - j = k | j; - l = a[q >> 0] | 0; - i = l | i; - a: do - if ((p | 0) > 1) { - n = (d + 24) | 0; - o = (b + 8) | 0; - p = (d + 54) | 0; - b = (b + 24) | 0; - do { - i = i & 1; - j = j & 1; - if (a[p >> 0] | 0) - break a; - if (!((k << 24) >> 24)) { - if ((l << 24) >> 24 ? ((c[o >> 2] & 1) | 0) == 0 : 0) - break a; - } - else { - if ((c[n >> 2] | 0) == 1) - break a; - if (!(c[o >> 2] & 2)) - break a; - } - a[r >> 0] = 0; - a[q >> 0] = 0; - Qp(b, d, e, f, g, h); - k = a[r >> 0] | 0; - j = k | j; - l = a[q >> 0] | 0; - i = l | i; - b = (b + 8) | 0; - } while (b >>> 0 < m >>> 0); - } - while (0); - a[r >> 0] = ((j << 24) >> 24 != 0) & 1; - a[q >> 0] = ((i << 24) >> 24 != 0) & 1; - } - return; - } - function Np(b, d, e, f, g) { - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - g = g | 0; - var h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0; - a: do - if (!(ap(b, c[(d + 8) >> 2] | 0, g) | 0)) { - if (!(ap(b, c[d >> 2] | 0, g) | 0)) { - p = c[(b + 12) >> 2] | 0; - k = (b + 16 + (p << 3)) | 0; - Rp((b + 16) | 0, d, e, f, g); - h = (b + 24) | 0; - if ((p | 0) <= 1) - break; - b = c[(b + 8) >> 2] | 0; - if (((b & 2) | 0) == 0 ? ((j = (d + 36) | 0), (c[j >> 2] | 0) != 1) : 0) { - if (!(b & 1)) { - b = (d + 54) | 0; - while (1) { - if (a[b >> 0] | 0) - break a; - if ((c[j >> 2] | 0) == 1) - break a; - Rp(h, d, e, f, g); - h = (h + 8) | 0; - if (h >>> 0 >= k >>> 0) - break a; - } - } - b = (d + 24) | 0; - i = (d + 54) | 0; - while (1) { - if (a[i >> 0] | 0) - break a; - if ((c[j >> 2] | 0) == 1 ? (c[b >> 2] | 0) == 1 : 0) - break a; - Rp(h, d, e, f, g); - h = (h + 8) | 0; - if (h >>> 0 >= k >>> 0) - break a; - } - } - b = (d + 54) | 0; - while (1) { - if (a[b >> 0] | 0) - break a; - Rp(h, d, e, f, g); - h = (h + 8) | 0; - if (h >>> 0 >= k >>> 0) - break a; - } - } - if ((c[(d + 16) >> 2] | 0) != (e | 0) ? ((p = (d + 20) | 0), (c[p >> 2] | 0) != (e | 0)) : 0) { - c[(d + 32) >> 2] = f; - o = (d + 44) | 0; - if ((c[o >> 2] | 0) != 4) { - j = (b + 16 + (c[(b + 12) >> 2] << 3)) | 0; - k = (d + 52) | 0; - f = (d + 53) | 0; - l = (d + 54) | 0; - m = (b + 8) | 0; - n = (d + 24) | 0; - h = 0; - i = (b + 16) | 0; - b = 0; - b: while (1) { - if (i >>> 0 >= j >>> 0) { - i = 18; - break; - } - a[k >> 0] = 0; - a[f >> 0] = 0; - Qp(i, d, e, e, 1, g); - if (a[l >> 0] | 0) { - i = 18; - break; - } - do - if (a[f >> 0] | 0) { - if (!(a[k >> 0] | 0)) - if (!(c[m >> 2] & 1)) { - i = 19; - break b; - } - else { - b = 1; - break; - } - if ((c[n >> 2] | 0) == 1) { - h = 1; - i = 19; - break b; - } - if (!(c[m >> 2] & 2)) { - h = 1; - i = 19; - break b; - } - else { - h = 1; - b = 1; - } - } - while (0); - i = (i + 8) | 0; - } - if ((i | 0) == 18) - if (b) - i = 19; - else - b = 4; - if ((i | 0) == 19) - b = 3; - c[o >> 2] = b; - if (h & 1) - break; - } - c[p >> 2] = e; - e = (d + 40) | 0; - c[e >> 2] = (c[e >> 2] | 0) + 1; - if ((c[(d + 36) >> 2] | 0) != 1) - break; - if ((c[(d + 24) >> 2] | 0) != 2) - break; - a[(d + 54) >> 0] = 1; - break; - } - if ((f | 0) == 1) - c[(d + 32) >> 2] = 1; - } - else - cp(0, d, e, f); - while (0); - return; - } - function Op(b, d, e, f) { - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - var g = 0, h = 0; - a: do - if (!(ap(b, c[(d + 8) >> 2] | 0, 0) | 0)) { - h = c[(b + 12) >> 2] | 0; - g = (b + 16 + (h << 3)) | 0; - Pp((b + 16) | 0, d, e, f); - if ((h | 0) > 1) { - h = (d + 54) | 0; - b = (b + 24) | 0; - do { - Pp(b, d, e, f); - if (a[h >> 0] | 0) - break a; - b = (b + 8) | 0; - } while (b >>> 0 < g >>> 0); - } - } - else - bp(0, d, e, f); - while (0); - return; - } - function Pp(a, b, d, e) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0; - g = c[(a + 4) >> 2] | 0; - if (d) { - f = g >> 8; - if (g & 1) - f = c[((c[d >> 2] | 0) + f) >> 2] | 0; - } - else - f = 0; - a = c[a >> 2] | 0; - fa[c[((c[a >> 2] | 0) + 28) >> 2] & 7](a, b, (d + f) | 0, ((g & 2) | 0) == 0 ? 2 : e); - return; - } - function Qp(a, b, d, e, f, g) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - g = g | 0; - var h = 0, i = 0; - i = c[(a + 4) >> 2] | 0; - h = i >> 8; - if (i & 1) - h = c[((c[e >> 2] | 0) + h) >> 2] | 0; - a = c[a >> 2] | 0; - ha[c[((c[a >> 2] | 0) + 20) >> 2] & 3](a, b, d, (e + h) | 0, ((i & 2) | 0) == 0 ? 2 : f, g); - return; - } - function Rp(a, b, d, e, f) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - var g = 0, h = 0; - h = c[(a + 4) >> 2] | 0; - g = h >> 8; - if (h & 1) - g = c[((c[d >> 2] | 0) + g) >> 2] | 0; - a = c[a >> 2] | 0; - ga[c[((c[a >> 2] | 0) + 24) >> 2] & 3](a, b, (d + g) | 0, ((h & 2) | 0) == 0 ? 2 : e, f); - return; - } - function Sp(a) { - a = a | 0; - c[a >> 2] = 5896; - return; - } - function Tp(a) { - a = a | 0; - var b = 0, c = 0; - b = V; - V = (V + 16) | 0; - c = b; - Up(c, a); - a = Vp(c) | 0; - V = b; - return a | 0; - } - function Up(a, b) { - a = a | 0; - b = b | 0; - _p(a, b); - return; - } - function Vp(a) { - a = a | 0; - var b = 0, d = 0; - b = V; - V = (V + 16) | 0; - d = b; - Wp(d, c[(a + 4) >> 2] | 0); - if (!(((Xp(d) | 0) << 24) >> 24)) - a = Zp(Yp(a) | 0) | 0; - else - a = 0; - V = b; - return a | 0; - } - function Wp(a, b) { - a = a | 0; - b = b | 0; - c[a >> 2] = b; - return; - } - function Xp(b) { - b = b | 0; - return a[c[b >> 2] >> 0] | 0; - } - function Yp(a) { - a = a | 0; - return a | 0; - } - function Zp(b) { - b = b | 0; - var d = 0, e = 0, f = 0, g = 0; - g = V; - V = (V + 16) | 0; - f = g; - b = c[(b + 8) >> 2] | 0; - d = a[b >> 0] | 0; - do - if ((d << 24) >> 24 != 1) - if (!(d & 2)) { - a[b >> 0] = 2; - e = 1; - break; - } - else - To(20985, f); - else - e = 0; - while (0); - V = g; - return e | 0; - } - function _p(a, b) { - a = a | 0; - b = b | 0; - c[a >> 2] = b; - c[(a + 4) >> 2] = b; - c[(a + 8) >> 2] = b + 1; - c[(a + 12) >> 2] = 0; - return; - } - function $p(a) { - a = a | 0; - var b = 0, c = 0; - b = V; - V = (V + 16) | 0; - c = b; - Up(c, a); - aq(c); - V = b; - return; - } - function aq(a) { - a = a | 0; - var b = 0, d = 0; - b = V; - V = (V + 16) | 0; - d = b; - Wp(d, c[(a + 4) >> 2] | 0); - bq(d); - cq(Yp(a) | 0); - V = b; - return; - } - function bq(b) { - b = b | 0; - a[c[b >> 2] >> 0] = 1; - return; - } - function cq(b) { - b = b | 0; - a[c[(b + 8) >> 2] >> 0] = 1; - return; - } - function dq() { - return 0; - } - function eq(a) { - a = a | 0; - var b = 0, c = 0; - c = (a | 0) == 0 ? 1 : a; - while (1) { - b = dr(c) | 0; - if (b | 0) { - a = 6; - break; - } - a = dq() | 0; - if (!a) { - a = 5; - break; - } - ba[a & 3](); - } - if ((a | 0) == 5) { - c = v(4) | 0; - Sp(c); - x(c | 0, 3880, 121); - } - else if ((a | 0) == 6) - return b | 0; - return 0; - } - function fq(a) { - a = a | 0; - return eq(a) | 0; - } - function gq(a) { - a = a | 0; - jp(a); - return; - } - function hq(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - f = V; - V = (V + 16) | 0; - e = f; - c[e >> 2] = c[d >> 2]; - a = aa[c[((c[a >> 2] | 0) + 16) >> 2] & 7](a, b, e) | 0; - if (a) - c[d >> 2] = c[e >> 2]; - V = f; - return (a & 1) | 0; - } - function iq(a) { - a = a | 0; - if (!a) - a = 0; - else - a = ((ep(a, 3840, 3976, 0) | 0) != 0) & 1; - return a | 0; - } - function jq(a) { - a = a | 0; - return 0; - } - function kq() { - return ((lq() | 0) > 0) | 0; - } - function lq() { - return y() | 0; - } - function mq(a) { - a = a | 0; - return; - } - function nq(a) { - a = a | 0; - mq(a); - jp(a); - return; - } - function oq(a) { - a = a | 0; - return 21039; - } - function pq(a) { - a = a | 0; - return; - } - function qq(a) { - a = a | 0; - var b = 0, d = 0; - b = (a + 8) | 0; - if (!((c[b >> 2] | 0) != 0 ? ((d = c[b >> 2] | 0), (c[b >> 2] = d + -1), (d | 0) != 0) : 0)) - ca[c[((c[a >> 2] | 0) + 16) >> 2] & 255](a); - return; - } - function rq(a) { - a = a | 0; - a = jq(a) | 0; - if (!a) - return; - else - br(a, 21145); - } - function sq(a) { - a = a | 0; - return; - } - function tq(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0; - e = fo(b) | 0; - d = eq((e + 13) | 0) | 0; - c[d >> 2] = e; - c[(d + 4) >> 2] = e; - c[(d + 8) >> 2] = 0; - d = uq(d) | 0; - ur(d | 0, b | 0, (e + 1) | 0) | 0; - c[a >> 2] = d; - return; - } - function uq(a) { - a = a | 0; - return (a + 12) | 0; - } - function vq(a, b) { - a = a | 0; - b = b | 0; - c[a >> 2] = 5916; - tq((a + 4) | 0, b); - return; - } - function wq(b, d) { - b = b | 0; - d = d | 0; - c[b >> 2] = 5936; - tq((b + 4) | 0, (a[(d + 11) >> 0] | 0) < 0 ? c[d >> 2] | 0 : d); - return; - } - function xq(a, b) { - a = a | 0; - b = b | 0; - c[a >> 2] = 5936; - tq((a + 4) | 0, b); - return; - } - function yq(a) { - a = a | 0; - a = v(8) | 0; - vq(a, 21163); - c[a >> 2] = 5956; - x(a | 0, 3928, 123); - } - function zq(a) { - a = a | 0; - a = v(8) | 0; - vq(a, 21163); - c[a >> 2] = 5976; - x(a | 0, 3944, 123); - } - function Aq(b, d, e) { - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0, h = 0, i = 0; - g = V; - V = (V + 16) | 0; - f = g; - if (e >>> 0 > 4294967279) - yq(b); - if (e >>> 0 < 11) - a[(b + 11) >> 0] = e; - else { - i = (e + 16) & -16; - h = eq(i) | 0; - c[b >> 2] = h; - c[(b + 8) >> 2] = i | -2147483648; - c[(b + 4) >> 2] = e; - b = h; - } - Bq(b, d, e) | 0; - a[f >> 0] = 0; - nb((b + e) | 0, f); - V = g; - return; - } - function Bq(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - if (c | 0) - ur(a | 0, b | 0, c | 0) | 0; - return a | 0; - } - function Cq(b) { - b = b | 0; - if ((a[(b + 11) >> 0] | 0) < 0) - Da(c[b >> 2] | 0, c[(b + 8) >> 2] & 2147483647); - return; - } - function Dq(b, d, e, f, g, h, i, j) { - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - g = g | 0; - h = h | 0; - i = i | 0; - j = j | 0; - var k = 0, l = 0, m = 0, n = 0, o = 0; - o = V; - V = (V + 16) | 0; - n = o; - if (((-18 - d) | 0) >>> 0 < e >>> 0) - yq(b); - if ((a[(b + 11) >> 0] | 0) < 0) - m = c[b >> 2] | 0; - else - m = b; - if (d >>> 0 < 2147483623) { - k = (e + d) | 0; - l = d << 1; - k = k >>> 0 < l >>> 0 ? l : k; - k = k >>> 0 < 11 ? 11 : (k + 16) & -16; - } - else - k = -17; - l = eq(k) | 0; - if (g | 0) - Bq(l, m, g) | 0; - if (i | 0) - Bq((l + g) | 0, j, i) | 0; - f = (f - h) | 0; - e = (f - g) | 0; - if (e | 0) - Bq((l + g + i) | 0, (m + g + h) | 0, e) | 0; - e = (d + 1) | 0; - if ((e | 0) != 11) - Da(m, e); - c[b >> 2] = l; - c[(b + 8) >> 2] = k | -2147483648; - i = (f + i) | 0; - c[(b + 4) >> 2] = i; - a[n >> 0] = 0; - nb((l + i) | 0, n); - V = o; - return; - } - function Eq(b, d, e) { - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0, h = 0, i = 0, j = 0, k = 0; - k = V; - V = (V + 16) | 0; - i = k; - j = (b + 11) | 0; - f = a[j >> 0] | 0; - h = (f << 24) >> 24 < 0; - if (h) { - g = ((c[(b + 8) >> 2] & 2147483647) + -1) | 0; - f = c[(b + 4) >> 2] | 0; - } - else { - g = 10; - f = f & 255; - } - if (((g - f) | 0) >>> 0 >= e >>> 0) { - if (e | 0) { - if (h) - g = c[b >> 2] | 0; - else - g = b; - Bq((g + f) | 0, d, e) | 0; - f = (f + e) | 0; - if ((a[j >> 0] | 0) < 0) - c[(b + 4) >> 2] = f; - else - a[j >> 0] = f; - a[i >> 0] = 0; - nb((g + f) | 0, i); - } - } - else - Dq(b, g, (f + e - g) | 0, f, f, 0, e, d); - V = k; - return b | 0; - } - function Fq(a, b) { - a = a | 0; - b = b | 0; - return Eq(a, b, lb(b) | 0) | 0; - } - function Gq(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - if (!c) - a = 0; - else - a = Fo(a, b, c) | 0; - return a | 0; - } - function Hq(b, d, e, f, g) { - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - g = g | 0; - var h = 0, i = 0; - h = a[(b + 11) >> 0] | 0; - i = (h << 24) >> 24 < 0; - if (i) - h = c[(b + 4) >> 2] | 0; - else - h = h & 255; - if (((g | 0) == -1) | (h >>> 0 < d >>> 0)) - zq(b); - h = (h - d) | 0; - e = h >>> 0 < e >>> 0 ? h : e; - if (i) - b = c[b >> 2] | 0; - h = e >>> 0 > g >>> 0; - b = Gq((b + d) | 0, f, h ? g : e) | 0; - if (!b) - return (e >>> 0 < g >>> 0 ? -1 : h & 1) | 0; - else - return b | 0; - return 0; - } - function Iq(a) { - a = a | 0; - return; - } - function Jq(a) { - a = a | 0; - jp(a); - return; - } - function Kq(a) { - a = a | 0; - return 21228; - } - function Lq(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - c[a >> 2] = d; - c[(a + 4) >> 2] = b; - return; - } - function Mq(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0; - f = V; - V = (V + 16) | 0; - e = f; - ea[c[((c[a >> 2] | 0) + 12) >> 2] & 15](e, a, b); - if ((c[(e + 4) >> 2] | 0) == (c[(d + 4) >> 2] | 0)) - a = (c[e >> 2] | 0) == (c[d >> 2] | 0); - else - a = 0; - V = f; - return a | 0; - } - function Nq(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - return ((c[b >> 2] | 0) == (d | 0) ? (c[(b + 4) >> 2] | 0) == (a | 0) : 0) | 0; - } - function Oq(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - if ((c | 0) > 256) - Aq(a, 21176, lb(21176) | 0); - else - Pq(a, 0, c); - return; - } - function Pq(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - Qq(a, c); - return; - } - function Qq(b, d) { - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0, h = 0, i = 0; - i = V; - V = (V + 1040) | 0; - g = (i + 1024) | 0; - e = i; - h = c[(ao() | 0) >> 2] | 0; - f = Rq(Oo(d, e, 1024) | 0, e) | 0; - if (!(a[f >> 0] | 0)) { - c[g >> 2] = d; - Go(e, 1024, 21211, g) | 0; - } - else - e = f; - c[(ao() | 0) >> 2] = h; - Aq(b, e, lb(e) | 0); - V = i; - return; - } - function Rq(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0; - switch (a | 0) { - case 0: { - d = b; - break; - } - case -1: { - a = c[(ao() | 0) >> 2] | 0; - e = 3; - break; - } - default: - e = 3; - } - if ((e | 0) == 3) - if ((a | 0) == 28) - d = 22145; - else - P(); - return d | 0; - } - function Sq(a) { - a = a | 0; - jp(a); - return; - } - function Tq(a) { - a = a | 0; - return 21353; - } - function Uq(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - if ((d | 0) > 256) { - Wq() | 0; - b = 6180; - } - else { - Xq() | 0; - b = 6176; - } - c[a >> 2] = d; - c[(a + 4) >> 2] = b; - return; - } - function Vq(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - if ((c | 0) > 256) - Aq(a, 21319, lb(21319) | 0); - else - Pq(a, 0, c); - return; - } - function Wq() { - if ((a[21488] | 0) == 0 ? Tp(21488) | 0 : 0) - $p(21488); - return 6180; - } - function Xq() { - if ((a[21480] | 0) == 0 ? Tp(21480) | 0 : 0) - $p(21480); - return 6176; - } - function Yq(a) { - a = a | 0; - yp(a); - return; - } - function Zq(a) { - a = a | 0; - Yq(a); - jp(a); - return; - } - function _q(a, b) { - a = a | 0; - b = b | 0; - var d = 0; - d = c[(b + 4) >> 2] | 0; - ea[c[((c[d >> 2] | 0) + 24) >> 2] & 15](a, d, c[b >> 2] | 0); - return; - } - function $q(b, d, e) { - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0, h = 0; - h = V; - V = (V + 16) | 0; - g = h; - if (c[d >> 2] | 0) { - f = a[(e + 11) >> 0] | 0; - if ((f << 24) >> 24 < 0) - f = c[(e + 4) >> 2] | 0; - else - f = f & 255; - if (f | 0) - Fq(e, 21417) | 0; - _q(g, d); - d = a[(g + 11) >> 0] | 0; - f = (d << 24) >> 24 < 0; - Eq(e, f ? c[g >> 2] | 0 : g, f ? c[(g + 4) >> 2] | 0 : d & 255) | 0; - Cq(g); - } - c[b >> 2] = c[e >> 2]; - c[(b + 4) >> 2] = c[(e + 4) >> 2]; - c[(b + 8) >> 2] = c[(e + 8) >> 2]; - f = 0; - while (1) { - if ((f | 0) == 3) - break; - c[(e + (f << 2)) >> 2] = 0; - f = (f + 1) | 0; - } - V = h; - return; - } - function ar(a, b, d) { - a = a | 0; - b = b | 0; - d = d | 0; - var e = 0, f = 0, g = 0; - e = V; - V = (V + 32) | 0; - g = (e + 12) | 0; - f = e; - Aq(f, d, lb(d) | 0); - $q(g, b, f); - wq(a, g); - Cq(g); - Cq(f); - c[a >> 2] = 6192; - f = b; - b = c[(f + 4) >> 2] | 0; - d = (a + 8) | 0; - c[d >> 2] = c[f >> 2]; - c[(d + 4) >> 2] = b; - V = e; - return; - } - function br(a, b) { - a = a | 0; - b = b | 0; - var d = 0, e = 0, f = 0; - f = V; - V = (V + 16) | 0; - e = (f + 8) | 0; - d = v(16) | 0; - Wq() | 0; - c[f >> 2] = a; - c[(f + 4) >> 2] = 6180; - c[e >> 2] = c[f >> 2]; - c[(e + 4) >> 2] = c[(f + 4) >> 2]; - ar(d, e, b); - x(d | 0, 4272, 136); - } - function cr(a) { - a = a | 0; - a = v(8) | 0; - vq(a, 21420); - c[a >> 2] = 5956; - x(a | 0, 3928, 123); - } - function dr(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, q = 0, r = 0, s = 0, t = 0, u = 0, v = 0, w = 0; - w = V; - V = (V + 16) | 0; - n = w; - do - if (a >>> 0 < 245) { - k = a >>> 0 < 11 ? 16 : (a + 11) & -8; - a = k >>> 3; - m = c[5412] | 0; - d = m >>> a; - if ((d & 3) | 0) { - b = (((d & 1) ^ 1) + a) | 0; - a = (21688 + ((b << 1) << 2)) | 0; - d = (a + 8) | 0; - e = c[d >> 2] | 0; - f = (e + 8) | 0; - g = c[f >> 2] | 0; - if ((g | 0) == (a | 0)) - c[5412] = m & ~(1 << b); - else { - c[(g + 12) >> 2] = a; - c[d >> 2] = g; - } - v = b << 3; - c[(e + 4) >> 2] = v | 3; - v = (e + v + 4) | 0; - c[v >> 2] = c[v >> 2] | 1; - v = f; - V = w; - return v | 0; - } - l = c[5414] | 0; - if (k >>> 0 > l >>> 0) { - if (d | 0) { - b = 2 << a; - b = (d << a) & (b | (0 - b)); - b = ((b & (0 - b)) + -1) | 0; - i = (b >>> 12) & 16; - b = b >>> i; - d = (b >>> 5) & 8; - b = b >>> d; - g = (b >>> 2) & 4; - b = b >>> g; - a = (b >>> 1) & 2; - b = b >>> a; - e = (b >>> 1) & 1; - e = ((d | i | g | a | e) + (b >>> e)) | 0; - b = (21688 + ((e << 1) << 2)) | 0; - a = (b + 8) | 0; - g = c[a >> 2] | 0; - i = (g + 8) | 0; - d = c[i >> 2] | 0; - if ((d | 0) == (b | 0)) { - a = m & ~(1 << e); - c[5412] = a; - } - else { - c[(d + 12) >> 2] = b; - c[a >> 2] = d; - a = m; - } - v = e << 3; - h = (v - k) | 0; - c[(g + 4) >> 2] = k | 3; - f = (g + k) | 0; - c[(f + 4) >> 2] = h | 1; - c[(g + v) >> 2] = h; - if (l | 0) { - e = c[5417] | 0; - b = l >>> 3; - d = (21688 + ((b << 1) << 2)) | 0; - b = 1 << b; - if (!(a & b)) { - c[5412] = a | b; - b = d; - a = (d + 8) | 0; - } - else { - a = (d + 8) | 0; - b = c[a >> 2] | 0; - } - c[a >> 2] = e; - c[(b + 12) >> 2] = e; - c[(e + 8) >> 2] = b; - c[(e + 12) >> 2] = d; - } - c[5414] = h; - c[5417] = f; - v = i; - V = w; - return v | 0; - } - g = c[5413] | 0; - if (g) { - d = ((g & (0 - g)) + -1) | 0; - f = (d >>> 12) & 16; - d = d >>> f; - e = (d >>> 5) & 8; - d = d >>> e; - h = (d >>> 2) & 4; - d = d >>> h; - i = (d >>> 1) & 2; - d = d >>> i; - j = (d >>> 1) & 1; - j = c[(21952 + (((e | f | h | i | j) + (d >>> j)) << 2)) >> 2] | 0; - d = j; - i = j; - j = ((c[(j + 4) >> 2] & -8) - k) | 0; - while (1) { - a = c[(d + 16) >> 2] | 0; - if (!a) { - a = c[(d + 20) >> 2] | 0; - if (!a) - break; - } - h = ((c[(a + 4) >> 2] & -8) - k) | 0; - f = h >>> 0 < j >>> 0; - d = a; - i = f ? a : i; - j = f ? h : j; - } - h = (i + k) | 0; - if (h >>> 0 > i >>> 0) { - f = c[(i + 24) >> 2] | 0; - b = c[(i + 12) >> 2] | 0; - do - if ((b | 0) == (i | 0)) { - a = (i + 20) | 0; - b = c[a >> 2] | 0; - if (!b) { - a = (i + 16) | 0; - b = c[a >> 2] | 0; - if (!b) { - d = 0; - break; - } - } - while (1) { - e = (b + 20) | 0; - d = c[e >> 2] | 0; - if (!d) { - e = (b + 16) | 0; - d = c[e >> 2] | 0; - if (!d) - break; - else { - b = d; - a = e; - } - } - else { - b = d; - a = e; - } - } - c[a >> 2] = 0; - d = b; - } - else { - d = c[(i + 8) >> 2] | 0; - c[(d + 12) >> 2] = b; - c[(b + 8) >> 2] = d; - d = b; - } - while (0); - do - if (f | 0) { - b = c[(i + 28) >> 2] | 0; - a = (21952 + (b << 2)) | 0; - if ((i | 0) == (c[a >> 2] | 0)) { - c[a >> 2] = d; - if (!d) { - c[5413] = g & ~(1 << b); - break; - } - } - else { - v = (f + 16) | 0; - c[((c[v >> 2] | 0) == (i | 0) ? v : (f + 20) | 0) >> 2] = d; - if (!d) - break; - } - c[(d + 24) >> 2] = f; - b = c[(i + 16) >> 2] | 0; - if (b | 0) { - c[(d + 16) >> 2] = b; - c[(b + 24) >> 2] = d; - } - b = c[(i + 20) >> 2] | 0; - if (b | 0) { - c[(d + 20) >> 2] = b; - c[(b + 24) >> 2] = d; - } - } - while (0); - if (j >>> 0 < 16) { - v = (j + k) | 0; - c[(i + 4) >> 2] = v | 3; - v = (i + v + 4) | 0; - c[v >> 2] = c[v >> 2] | 1; - } - else { - c[(i + 4) >> 2] = k | 3; - c[(h + 4) >> 2] = j | 1; - c[(h + j) >> 2] = j; - if (l | 0) { - e = c[5417] | 0; - b = l >>> 3; - d = (21688 + ((b << 1) << 2)) | 0; - b = 1 << b; - if (!(b & m)) { - c[5412] = b | m; - b = d; - a = (d + 8) | 0; - } - else { - a = (d + 8) | 0; - b = c[a >> 2] | 0; - } - c[a >> 2] = e; - c[(b + 12) >> 2] = e; - c[(e + 8) >> 2] = b; - c[(e + 12) >> 2] = d; - } - c[5414] = j; - c[5417] = h; - } - v = (i + 8) | 0; - V = w; - return v | 0; - } - else - m = k; - } - else - m = k; - } - else - m = k; - } - else if (a >>> 0 <= 4294967231) { - a = (a + 11) | 0; - k = a & -8; - e = c[5413] | 0; - if (e) { - f = (0 - k) | 0; - a = a >>> 8; - if (a) - if (k >>> 0 > 16777215) - j = 31; - else { - m = (((a + 1048320) | 0) >>> 16) & 8; - q = a << m; - i = (((q + 520192) | 0) >>> 16) & 4; - q = q << i; - j = (((q + 245760) | 0) >>> 16) & 2; - j = (14 - (i | m | j) + ((q << j) >>> 15)) | 0; - j = ((k >>> ((j + 7) | 0)) & 1) | (j << 1); - } - else - j = 0; - d = c[(21952 + (j << 2)) >> 2] | 0; - a: do - if (!d) { - d = 0; - a = 0; - q = 61; - } - else { - a = 0; - i = k << ((j | 0) == 31 ? 0 : (25 - (j >>> 1)) | 0); - g = 0; - while (1) { - h = ((c[(d + 4) >> 2] & -8) - k) | 0; - if (h >>> 0 < f >>> 0) - if (!h) { - a = d; - f = 0; - q = 65; - break a; - } - else { - a = d; - f = h; - } - q = c[(d + 20) >> 2] | 0; - d = c[(d + 16 + ((i >>> 31) << 2)) >> 2] | 0; - g = ((q | 0) == 0) | ((q | 0) == (d | 0)) ? g : q; - if (!d) { - d = g; - q = 61; - break; - } - else - i = i << 1; - } - } - while (0); - if ((q | 0) == 61) { - if (((d | 0) == 0) & ((a | 0) == 0)) { - a = 2 << j; - a = (a | (0 - a)) & e; - if (!a) { - m = k; - break; - } - m = ((a & (0 - a)) + -1) | 0; - h = (m >>> 12) & 16; - m = m >>> h; - g = (m >>> 5) & 8; - m = m >>> g; - i = (m >>> 2) & 4; - m = m >>> i; - j = (m >>> 1) & 2; - m = m >>> j; - d = (m >>> 1) & 1; - a = 0; - d = c[(21952 + (((g | h | i | j | d) + (m >>> d)) << 2)) >> 2] | 0; - } - if (!d) { - i = a; - h = f; - } - else - q = 65; - } - if ((q | 0) == 65) { - g = d; - while (1) { - m = ((c[(g + 4) >> 2] & -8) - k) | 0; - d = m >>> 0 < f >>> 0; - f = d ? m : f; - a = d ? g : a; - d = c[(g + 16) >> 2] | 0; - if (!d) - d = c[(g + 20) >> 2] | 0; - if (!d) { - i = a; - h = f; - break; - } - else - g = d; - } - } - if (((i | 0) != 0 ? h >>> 0 < (((c[5414] | 0) - k) | 0) >>> 0 : 0) - ? ((l = (i + k) | 0), l >>> 0 > i >>> 0) - : 0) { - g = c[(i + 24) >> 2] | 0; - b = c[(i + 12) >> 2] | 0; - do - if ((b | 0) == (i | 0)) { - a = (i + 20) | 0; - b = c[a >> 2] | 0; - if (!b) { - a = (i + 16) | 0; - b = c[a >> 2] | 0; - if (!b) { - b = 0; - break; - } - } - while (1) { - f = (b + 20) | 0; - d = c[f >> 2] | 0; - if (!d) { - f = (b + 16) | 0; - d = c[f >> 2] | 0; - if (!d) - break; - else { - b = d; - a = f; - } - } - else { - b = d; - a = f; - } - } - c[a >> 2] = 0; - } - else { - v = c[(i + 8) >> 2] | 0; - c[(v + 12) >> 2] = b; - c[(b + 8) >> 2] = v; - } - while (0); - do - if (g) { - a = c[(i + 28) >> 2] | 0; - d = (21952 + (a << 2)) | 0; - if ((i | 0) == (c[d >> 2] | 0)) { - c[d >> 2] = b; - if (!b) { - e = e & ~(1 << a); - c[5413] = e; - break; - } - } - else { - v = (g + 16) | 0; - c[((c[v >> 2] | 0) == (i | 0) ? v : (g + 20) | 0) >> 2] = b; - if (!b) - break; - } - c[(b + 24) >> 2] = g; - a = c[(i + 16) >> 2] | 0; - if (a | 0) { - c[(b + 16) >> 2] = a; - c[(a + 24) >> 2] = b; - } - a = c[(i + 20) >> 2] | 0; - if (a) { - c[(b + 20) >> 2] = a; - c[(a + 24) >> 2] = b; - } - } - while (0); - b: do - if (h >>> 0 < 16) { - v = (h + k) | 0; - c[(i + 4) >> 2] = v | 3; - v = (i + v + 4) | 0; - c[v >> 2] = c[v >> 2] | 1; - } - else { - c[(i + 4) >> 2] = k | 3; - c[(l + 4) >> 2] = h | 1; - c[(l + h) >> 2] = h; - b = h >>> 3; - if (h >>> 0 < 256) { - d = (21688 + ((b << 1) << 2)) | 0; - a = c[5412] | 0; - b = 1 << b; - if (!(a & b)) { - c[5412] = a | b; - b = d; - a = (d + 8) | 0; - } - else { - a = (d + 8) | 0; - b = c[a >> 2] | 0; - } - c[a >> 2] = l; - c[(b + 12) >> 2] = l; - c[(l + 8) >> 2] = b; - c[(l + 12) >> 2] = d; - break; - } - b = h >>> 8; - if (b) - if (h >>> 0 > 16777215) - d = 31; - else { - u = (((b + 1048320) | 0) >>> 16) & 8; - v = b << u; - t = (((v + 520192) | 0) >>> 16) & 4; - v = v << t; - d = (((v + 245760) | 0) >>> 16) & 2; - d = (14 - (t | u | d) + ((v << d) >>> 15)) | 0; - d = ((h >>> ((d + 7) | 0)) & 1) | (d << 1); - } - else - d = 0; - b = (21952 + (d << 2)) | 0; - c[(l + 28) >> 2] = d; - a = (l + 16) | 0; - c[(a + 4) >> 2] = 0; - c[a >> 2] = 0; - a = 1 << d; - if (!(e & a)) { - c[5413] = e | a; - c[b >> 2] = l; - c[(l + 24) >> 2] = b; - c[(l + 12) >> 2] = l; - c[(l + 8) >> 2] = l; - break; - } - b = c[b >> 2] | 0; - c: do - if (((c[(b + 4) >> 2] & -8) | 0) != (h | 0)) { - e = h << ((d | 0) == 31 ? 0 : (25 - (d >>> 1)) | 0); - while (1) { - d = (b + 16 + ((e >>> 31) << 2)) | 0; - a = c[d >> 2] | 0; - if (!a) - break; - if (((c[(a + 4) >> 2] & -8) | 0) == (h | 0)) { - b = a; - break c; - } - else { - e = e << 1; - b = a; - } - } - c[d >> 2] = l; - c[(l + 24) >> 2] = b; - c[(l + 12) >> 2] = l; - c[(l + 8) >> 2] = l; - break b; - } - while (0); - u = (b + 8) | 0; - v = c[u >> 2] | 0; - c[(v + 12) >> 2] = l; - c[u >> 2] = l; - c[(l + 8) >> 2] = v; - c[(l + 12) >> 2] = b; - c[(l + 24) >> 2] = 0; - } - while (0); - v = (i + 8) | 0; - V = w; - return v | 0; - } - else - m = k; - } - else - m = k; - } - else - m = -1; - while (0); - d = c[5414] | 0; - if (d >>> 0 >= m >>> 0) { - b = (d - m) | 0; - a = c[5417] | 0; - if (b >>> 0 > 15) { - v = (a + m) | 0; - c[5417] = v; - c[5414] = b; - c[(v + 4) >> 2] = b | 1; - c[(a + d) >> 2] = b; - c[(a + 4) >> 2] = m | 3; - } - else { - c[5414] = 0; - c[5417] = 0; - c[(a + 4) >> 2] = d | 3; - v = (a + d + 4) | 0; - c[v >> 2] = c[v >> 2] | 1; - } - v = (a + 8) | 0; - V = w; - return v | 0; - } - h = c[5415] | 0; - if (h >>> 0 > m >>> 0) { - t = (h - m) | 0; - c[5415] = t; - v = c[5418] | 0; - u = (v + m) | 0; - c[5418] = u; - c[(u + 4) >> 2] = t | 1; - c[(v + 4) >> 2] = m | 3; - v = (v + 8) | 0; - V = w; - return v | 0; - } - if (!(c[5530] | 0)) { - c[5532] = 4096; - c[5531] = 4096; - c[5533] = -1; - c[5534] = -1; - c[5535] = 0; - c[5523] = 0; - c[5530] = (n & -16) ^ 1431655768; - a = 4096; - } - else - a = c[5532] | 0; - i = (m + 48) | 0; - j = (m + 47) | 0; - g = (a + j) | 0; - f = (0 - a) | 0; - k = g & f; - if (k >>> 0 <= m >>> 0) { - v = 0; - V = w; - return v | 0; - } - a = c[5522] | 0; - if (a | 0 - ? ((l = c[5520] | 0), (n = (l + k) | 0), (n >>> 0 <= l >>> 0) | (n >>> 0 > a >>> 0)) - : 0) { - v = 0; - V = w; - return v | 0; - } - d: do - if (!(c[5523] & 4)) { - d = c[5418] | 0; - e: do - if (d) { - e = 22096; - while (1) { - n = c[e >> 2] | 0; - if (n >>> 0 <= d >>> 0 ? ((n + (c[(e + 4) >> 2] | 0)) | 0) >>> 0 > d >>> 0 : 0) - break; - a = c[(e + 8) >> 2] | 0; - if (!a) { - q = 128; - break e; - } - else - e = a; - } - b = (g - h) & f; - if (b >>> 0 < 2147483647) { - a = fr(b) | 0; - if ((a | 0) == (((c[e >> 2] | 0) + (c[(e + 4) >> 2] | 0)) | 0)) { - if ((a | 0) != (-1 | 0)) { - h = b; - g = a; - q = 145; - break d; - } - } - else { - e = a; - q = 136; - } - } - else - b = 0; - } - else - q = 128; - while (0); - do - if ((q | 0) == 128) { - d = fr(0) | 0; - if ((d | 0) != (-1 | 0) - ? ((b = d), - (o = c[5531] | 0), - (p = (o + -1) | 0), - (b = ((((p & b) | 0) == 0 ? 0 : (((p + b) & (0 - o)) - b) | 0) + k) | 0), - (o = c[5520] | 0), - (p = (b + o) | 0), - (b >>> 0 > m >>> 0) & (b >>> 0 < 2147483647)) - : 0) { - n = c[5522] | 0; - if (n | 0 ? (p >>> 0 <= o >>> 0) | (p >>> 0 > n >>> 0) : 0) { - b = 0; - break; - } - a = fr(b) | 0; - if ((a | 0) == (d | 0)) { - h = b; - g = d; - q = 145; - break d; - } - else { - e = a; - q = 136; - } - } - else - b = 0; - } - while (0); - do - if ((q | 0) == 136) { - d = (0 - b) | 0; - if (!((i >>> 0 > b >>> 0) & ((b >>> 0 < 2147483647) & ((e | 0) != (-1 | 0))))) - if ((e | 0) == (-1 | 0)) { - b = 0; - break; - } - else { - h = b; - g = e; - q = 145; - break d; - } - a = c[5532] | 0; - a = (j - b + a) & (0 - a); - if (a >>> 0 >= 2147483647) { - h = b; - g = e; - q = 145; - break d; - } - if ((fr(a) | 0) == (-1 | 0)) { - fr(d) | 0; - b = 0; - break; - } - else { - h = (a + b) | 0; - g = e; - q = 145; - break d; - } - } - while (0); - c[5523] = c[5523] | 4; - q = 143; - } - else { - b = 0; - q = 143; - } - while (0); - if (((q | 0) == 143 ? k >>> 0 < 2147483647 : 0) - ? ((t = fr(k) | 0), - (p = fr(0) | 0), - (r = (p - t) | 0), - (s = r >>> 0 > ((m + 40) | 0) >>> 0), - !(((t | 0) == (-1 | 0)) | - (s ^ 1) | - (((t >>> 0 < p >>> 0) & (((t | 0) != (-1 | 0)) & ((p | 0) != (-1 | 0)))) ^ 1))) - : 0) { - h = s ? r : b; - g = t; - q = 145; - } - if ((q | 0) == 145) { - b = ((c[5520] | 0) + h) | 0; - c[5520] = b; - if (b >>> 0 > (c[5521] | 0) >>> 0) - c[5521] = b; - j = c[5418] | 0; - f: do - if (j) { - b = 22096; - while (1) { - a = c[b >> 2] | 0; - d = c[(b + 4) >> 2] | 0; - if ((g | 0) == ((a + d) | 0)) { - q = 154; - break; - } - e = c[(b + 8) >> 2] | 0; - if (!e) - break; - else - b = e; - } - if (((q | 0) == 154 ? ((u = (b + 4) | 0), ((c[(b + 12) >> 2] & 8) | 0) == 0) : 0) - ? (g >>> 0 > j >>> 0) & (a >>> 0 <= j >>> 0) - : 0) { - c[u >> 2] = d + h; - v = ((c[5415] | 0) + h) | 0; - t = (j + 8) | 0; - t = ((t & 7) | 0) == 0 ? 0 : (0 - t) & 7; - u = (j + t) | 0; - t = (v - t) | 0; - c[5418] = u; - c[5415] = t; - c[(u + 4) >> 2] = t | 1; - c[(j + v + 4) >> 2] = 40; - c[5419] = c[5534]; - break; - } - if (g >>> 0 < (c[5416] | 0) >>> 0) - c[5416] = g; - d = (g + h) | 0; - b = 22096; - while (1) { - if ((c[b >> 2] | 0) == (d | 0)) { - q = 162; - break; - } - a = c[(b + 8) >> 2] | 0; - if (!a) - break; - else - b = a; - } - if ((q | 0) == 162 ? ((c[(b + 12) >> 2] & 8) | 0) == 0 : 0) { - c[b >> 2] = g; - l = (b + 4) | 0; - c[l >> 2] = (c[l >> 2] | 0) + h; - l = (g + 8) | 0; - l = (g + (((l & 7) | 0) == 0 ? 0 : (0 - l) & 7)) | 0; - b = (d + 8) | 0; - b = (d + (((b & 7) | 0) == 0 ? 0 : (0 - b) & 7)) | 0; - k = (l + m) | 0; - i = (b - l - m) | 0; - c[(l + 4) >> 2] = m | 3; - g: do - if ((j | 0) == (b | 0)) { - v = ((c[5415] | 0) + i) | 0; - c[5415] = v; - c[5418] = k; - c[(k + 4) >> 2] = v | 1; - } - else { - if ((c[5417] | 0) == (b | 0)) { - v = ((c[5414] | 0) + i) | 0; - c[5414] = v; - c[5417] = k; - c[(k + 4) >> 2] = v | 1; - c[(k + v) >> 2] = v; - break; - } - a = c[(b + 4) >> 2] | 0; - if (((a & 3) | 0) == 1) { - h = a & -8; - e = a >>> 3; - h: do - if (a >>> 0 < 256) { - a = c[(b + 8) >> 2] | 0; - d = c[(b + 12) >> 2] | 0; - if ((d | 0) == (a | 0)) { - c[5412] = c[5412] & ~(1 << e); - break; - } - else { - c[(a + 12) >> 2] = d; - c[(d + 8) >> 2] = a; - break; - } - } - else { - g = c[(b + 24) >> 2] | 0; - a = c[(b + 12) >> 2] | 0; - do - if ((a | 0) == (b | 0)) { - d = (b + 16) | 0; - e = (d + 4) | 0; - a = c[e >> 2] | 0; - if (!a) { - a = c[d >> 2] | 0; - if (!a) { - a = 0; - break; - } - } - else - d = e; - while (1) { - f = (a + 20) | 0; - e = c[f >> 2] | 0; - if (!e) { - f = (a + 16) | 0; - e = c[f >> 2] | 0; - if (!e) - break; - else { - a = e; - d = f; - } - } - else { - a = e; - d = f; - } - } - c[d >> 2] = 0; - } - else { - v = c[(b + 8) >> 2] | 0; - c[(v + 12) >> 2] = a; - c[(a + 8) >> 2] = v; - } - while (0); - if (!g) - break; - d = c[(b + 28) >> 2] | 0; - e = (21952 + (d << 2)) | 0; - do - if ((c[e >> 2] | 0) != (b | 0)) { - v = (g + 16) | 0; - c[((c[v >> 2] | 0) == (b | 0) ? v : (g + 20) | 0) >> 2] = a; - if (!a) - break h; - } - else { - c[e >> 2] = a; - if (a | 0) - break; - c[5413] = c[5413] & ~(1 << d); - break h; - } - while (0); - c[(a + 24) >> 2] = g; - d = (b + 16) | 0; - e = c[d >> 2] | 0; - if (e | 0) { - c[(a + 16) >> 2] = e; - c[(e + 24) >> 2] = a; - } - d = c[(d + 4) >> 2] | 0; - if (!d) - break; - c[(a + 20) >> 2] = d; - c[(d + 24) >> 2] = a; - } - while (0); - b = (b + h) | 0; - f = (h + i) | 0; - } - else - f = i; - b = (b + 4) | 0; - c[b >> 2] = c[b >> 2] & -2; - c[(k + 4) >> 2] = f | 1; - c[(k + f) >> 2] = f; - b = f >>> 3; - if (f >>> 0 < 256) { - d = (21688 + ((b << 1) << 2)) | 0; - a = c[5412] | 0; - b = 1 << b; - if (!(a & b)) { - c[5412] = a | b; - b = d; - a = (d + 8) | 0; - } - else { - a = (d + 8) | 0; - b = c[a >> 2] | 0; - } - c[a >> 2] = k; - c[(b + 12) >> 2] = k; - c[(k + 8) >> 2] = b; - c[(k + 12) >> 2] = d; - break; - } - b = f >>> 8; - do - if (!b) - e = 0; - else { - if (f >>> 0 > 16777215) { - e = 31; - break; - } - u = (((b + 1048320) | 0) >>> 16) & 8; - v = b << u; - t = (((v + 520192) | 0) >>> 16) & 4; - v = v << t; - e = (((v + 245760) | 0) >>> 16) & 2; - e = (14 - (t | u | e) + ((v << e) >>> 15)) | 0; - e = ((f >>> ((e + 7) | 0)) & 1) | (e << 1); - } - while (0); - b = (21952 + (e << 2)) | 0; - c[(k + 28) >> 2] = e; - a = (k + 16) | 0; - c[(a + 4) >> 2] = 0; - c[a >> 2] = 0; - a = c[5413] | 0; - d = 1 << e; - if (!(a & d)) { - c[5413] = a | d; - c[b >> 2] = k; - c[(k + 24) >> 2] = b; - c[(k + 12) >> 2] = k; - c[(k + 8) >> 2] = k; - break; - } - b = c[b >> 2] | 0; - i: do - if (((c[(b + 4) >> 2] & -8) | 0) != (f | 0)) { - e = f << ((e | 0) == 31 ? 0 : (25 - (e >>> 1)) | 0); - while (1) { - d = (b + 16 + ((e >>> 31) << 2)) | 0; - a = c[d >> 2] | 0; - if (!a) - break; - if (((c[(a + 4) >> 2] & -8) | 0) == (f | 0)) { - b = a; - break i; - } - else { - e = e << 1; - b = a; - } - } - c[d >> 2] = k; - c[(k + 24) >> 2] = b; - c[(k + 12) >> 2] = k; - c[(k + 8) >> 2] = k; - break g; - } - while (0); - u = (b + 8) | 0; - v = c[u >> 2] | 0; - c[(v + 12) >> 2] = k; - c[u >> 2] = k; - c[(k + 8) >> 2] = v; - c[(k + 12) >> 2] = b; - c[(k + 24) >> 2] = 0; - } - while (0); - v = (l + 8) | 0; - V = w; - return v | 0; - } - b = 22096; - while (1) { - a = c[b >> 2] | 0; - if (a >>> 0 <= j >>> 0 ? ((v = (a + (c[(b + 4) >> 2] | 0)) | 0), v >>> 0 > j >>> 0) : 0) - break; - b = c[(b + 8) >> 2] | 0; - } - f = (v + -47) | 0; - a = (f + 8) | 0; - a = (f + (((a & 7) | 0) == 0 ? 0 : (0 - a) & 7)) | 0; - f = (j + 16) | 0; - a = a >>> 0 < f >>> 0 ? j : a; - b = (a + 8) | 0; - d = (h + -40) | 0; - t = (g + 8) | 0; - t = ((t & 7) | 0) == 0 ? 0 : (0 - t) & 7; - u = (g + t) | 0; - t = (d - t) | 0; - c[5418] = u; - c[5415] = t; - c[(u + 4) >> 2] = t | 1; - c[(g + d + 4) >> 2] = 40; - c[5419] = c[5534]; - d = (a + 4) | 0; - c[d >> 2] = 27; - c[b >> 2] = c[5524]; - c[(b + 4) >> 2] = c[5525]; - c[(b + 8) >> 2] = c[5526]; - c[(b + 12) >> 2] = c[5527]; - c[5524] = g; - c[5525] = h; - c[5527] = 0; - c[5526] = b; - b = (a + 24) | 0; - do { - u = b; - b = (b + 4) | 0; - c[b >> 2] = 7; - } while (((u + 8) | 0) >>> 0 < v >>> 0); - if ((a | 0) != (j | 0)) { - g = (a - j) | 0; - c[d >> 2] = c[d >> 2] & -2; - c[(j + 4) >> 2] = g | 1; - c[a >> 2] = g; - b = g >>> 3; - if (g >>> 0 < 256) { - d = (21688 + ((b << 1) << 2)) | 0; - a = c[5412] | 0; - b = 1 << b; - if (!(a & b)) { - c[5412] = a | b; - b = d; - a = (d + 8) | 0; - } - else { - a = (d + 8) | 0; - b = c[a >> 2] | 0; - } - c[a >> 2] = j; - c[(b + 12) >> 2] = j; - c[(j + 8) >> 2] = b; - c[(j + 12) >> 2] = d; - break; - } - b = g >>> 8; - if (b) - if (g >>> 0 > 16777215) - e = 31; - else { - u = (((b + 1048320) | 0) >>> 16) & 8; - v = b << u; - t = (((v + 520192) | 0) >>> 16) & 4; - v = v << t; - e = (((v + 245760) | 0) >>> 16) & 2; - e = (14 - (t | u | e) + ((v << e) >>> 15)) | 0; - e = ((g >>> ((e + 7) | 0)) & 1) | (e << 1); - } - else - e = 0; - d = (21952 + (e << 2)) | 0; - c[(j + 28) >> 2] = e; - c[(j + 20) >> 2] = 0; - c[f >> 2] = 0; - b = c[5413] | 0; - a = 1 << e; - if (!(b & a)) { - c[5413] = b | a; - c[d >> 2] = j; - c[(j + 24) >> 2] = d; - c[(j + 12) >> 2] = j; - c[(j + 8) >> 2] = j; - break; - } - b = c[d >> 2] | 0; - j: do - if (((c[(b + 4) >> 2] & -8) | 0) != (g | 0)) { - e = g << ((e | 0) == 31 ? 0 : (25 - (e >>> 1)) | 0); - while (1) { - d = (b + 16 + ((e >>> 31) << 2)) | 0; - a = c[d >> 2] | 0; - if (!a) - break; - if (((c[(a + 4) >> 2] & -8) | 0) == (g | 0)) { - b = a; - break j; - } - else { - e = e << 1; - b = a; - } - } - c[d >> 2] = j; - c[(j + 24) >> 2] = b; - c[(j + 12) >> 2] = j; - c[(j + 8) >> 2] = j; - break f; - } - while (0); - u = (b + 8) | 0; - v = c[u >> 2] | 0; - c[(v + 12) >> 2] = j; - c[u >> 2] = j; - c[(j + 8) >> 2] = v; - c[(j + 12) >> 2] = b; - c[(j + 24) >> 2] = 0; - } - } - else { - v = c[5416] | 0; - if (((v | 0) == 0) | (g >>> 0 < v >>> 0)) - c[5416] = g; - c[5524] = g; - c[5525] = h; - c[5527] = 0; - c[5421] = c[5530]; - c[5420] = -1; - c[5425] = 21688; - c[5424] = 21688; - c[5427] = 21696; - c[5426] = 21696; - c[5429] = 21704; - c[5428] = 21704; - c[5431] = 21712; - c[5430] = 21712; - c[5433] = 21720; - c[5432] = 21720; - c[5435] = 21728; - c[5434] = 21728; - c[5437] = 21736; - c[5436] = 21736; - c[5439] = 21744; - c[5438] = 21744; - c[5441] = 21752; - c[5440] = 21752; - c[5443] = 21760; - c[5442] = 21760; - c[5445] = 21768; - c[5444] = 21768; - c[5447] = 21776; - c[5446] = 21776; - c[5449] = 21784; - c[5448] = 21784; - c[5451] = 21792; - c[5450] = 21792; - c[5453] = 21800; - c[5452] = 21800; - c[5455] = 21808; - c[5454] = 21808; - c[5457] = 21816; - c[5456] = 21816; - c[5459] = 21824; - c[5458] = 21824; - c[5461] = 21832; - c[5460] = 21832; - c[5463] = 21840; - c[5462] = 21840; - c[5465] = 21848; - c[5464] = 21848; - c[5467] = 21856; - c[5466] = 21856; - c[5469] = 21864; - c[5468] = 21864; - c[5471] = 21872; - c[5470] = 21872; - c[5473] = 21880; - c[5472] = 21880; - c[5475] = 21888; - c[5474] = 21888; - c[5477] = 21896; - c[5476] = 21896; - c[5479] = 21904; - c[5478] = 21904; - c[5481] = 21912; - c[5480] = 21912; - c[5483] = 21920; - c[5482] = 21920; - c[5485] = 21928; - c[5484] = 21928; - c[5487] = 21936; - c[5486] = 21936; - v = (h + -40) | 0; - t = (g + 8) | 0; - t = ((t & 7) | 0) == 0 ? 0 : (0 - t) & 7; - u = (g + t) | 0; - t = (v - t) | 0; - c[5418] = u; - c[5415] = t; - c[(u + 4) >> 2] = t | 1; - c[(g + v + 4) >> 2] = 40; - c[5419] = c[5534]; - } - while (0); - b = c[5415] | 0; - if (b >>> 0 > m >>> 0) { - t = (b - m) | 0; - c[5415] = t; - v = c[5418] | 0; - u = (v + m) | 0; - c[5418] = u; - c[(u + 4) >> 2] = t | 1; - c[(v + 4) >> 2] = m | 3; - v = (v + 8) | 0; - V = w; - return v | 0; - } - } - c[(ao() | 0) >> 2] = 48; - v = 0; - V = w; - return v | 0; - } - function er(a) { - a = a | 0; - var b = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0; - if (!a) - return; - d = (a + -8) | 0; - f = c[5416] | 0; - a = c[(a + -4) >> 2] | 0; - b = a & -8; - j = (d + b) | 0; - do - if (!(a & 1)) { - e = c[d >> 2] | 0; - if (!(a & 3)) - return; - h = (d + (0 - e)) | 0; - g = (e + b) | 0; - if (h >>> 0 < f >>> 0) - return; - if ((c[5417] | 0) == (h | 0)) { - a = (j + 4) | 0; - b = c[a >> 2] | 0; - if (((b & 3) | 0) != 3) { - i = h; - b = g; - break; - } - c[5414] = g; - c[a >> 2] = b & -2; - c[(h + 4) >> 2] = g | 1; - c[(h + g) >> 2] = g; - return; - } - d = e >>> 3; - if (e >>> 0 < 256) { - a = c[(h + 8) >> 2] | 0; - b = c[(h + 12) >> 2] | 0; - if ((b | 0) == (a | 0)) { - c[5412] = c[5412] & ~(1 << d); - i = h; - b = g; - break; - } - else { - c[(a + 12) >> 2] = b; - c[(b + 8) >> 2] = a; - i = h; - b = g; - break; - } - } - f = c[(h + 24) >> 2] | 0; - a = c[(h + 12) >> 2] | 0; - do - if ((a | 0) == (h | 0)) { - b = (h + 16) | 0; - d = (b + 4) | 0; - a = c[d >> 2] | 0; - if (!a) { - a = c[b >> 2] | 0; - if (!a) { - a = 0; - break; - } - } - else - b = d; - while (1) { - e = (a + 20) | 0; - d = c[e >> 2] | 0; - if (!d) { - e = (a + 16) | 0; - d = c[e >> 2] | 0; - if (!d) - break; - else { - a = d; - b = e; - } - } - else { - a = d; - b = e; - } - } - c[b >> 2] = 0; - } - else { - i = c[(h + 8) >> 2] | 0; - c[(i + 12) >> 2] = a; - c[(a + 8) >> 2] = i; - } - while (0); - if (f) { - b = c[(h + 28) >> 2] | 0; - d = (21952 + (b << 2)) | 0; - if ((c[d >> 2] | 0) == (h | 0)) { - c[d >> 2] = a; - if (!a) { - c[5413] = c[5413] & ~(1 << b); - i = h; - b = g; - break; - } - } - else { - i = (f + 16) | 0; - c[((c[i >> 2] | 0) == (h | 0) ? i : (f + 20) | 0) >> 2] = a; - if (!a) { - i = h; - b = g; - break; - } - } - c[(a + 24) >> 2] = f; - b = (h + 16) | 0; - d = c[b >> 2] | 0; - if (d | 0) { - c[(a + 16) >> 2] = d; - c[(d + 24) >> 2] = a; - } - b = c[(b + 4) >> 2] | 0; - if (b) { - c[(a + 20) >> 2] = b; - c[(b + 24) >> 2] = a; - i = h; - b = g; - } - else { - i = h; - b = g; - } - } - else { - i = h; - b = g; - } - } - else { - i = d; - h = d; - } - while (0); - if (h >>> 0 >= j >>> 0) - return; - a = (j + 4) | 0; - e = c[a >> 2] | 0; - if (!(e & 1)) - return; - if (!(e & 2)) { - if ((c[5418] | 0) == (j | 0)) { - j = ((c[5415] | 0) + b) | 0; - c[5415] = j; - c[5418] = i; - c[(i + 4) >> 2] = j | 1; - if ((i | 0) != (c[5417] | 0)) - return; - c[5417] = 0; - c[5414] = 0; - return; - } - if ((c[5417] | 0) == (j | 0)) { - j = ((c[5414] | 0) + b) | 0; - c[5414] = j; - c[5417] = h; - c[(i + 4) >> 2] = j | 1; - c[(h + j) >> 2] = j; - return; - } - f = ((e & -8) + b) | 0; - d = e >>> 3; - do - if (e >>> 0 < 256) { - b = c[(j + 8) >> 2] | 0; - a = c[(j + 12) >> 2] | 0; - if ((a | 0) == (b | 0)) { - c[5412] = c[5412] & ~(1 << d); - break; - } - else { - c[(b + 12) >> 2] = a; - c[(a + 8) >> 2] = b; - break; - } - } - else { - g = c[(j + 24) >> 2] | 0; - a = c[(j + 12) >> 2] | 0; - do - if ((a | 0) == (j | 0)) { - b = (j + 16) | 0; - d = (b + 4) | 0; - a = c[d >> 2] | 0; - if (!a) { - a = c[b >> 2] | 0; - if (!a) { - d = 0; - break; - } - } - else - b = d; - while (1) { - e = (a + 20) | 0; - d = c[e >> 2] | 0; - if (!d) { - e = (a + 16) | 0; - d = c[e >> 2] | 0; - if (!d) - break; - else { - a = d; - b = e; - } - } - else { - a = d; - b = e; - } - } - c[b >> 2] = 0; - d = a; - } - else { - d = c[(j + 8) >> 2] | 0; - c[(d + 12) >> 2] = a; - c[(a + 8) >> 2] = d; - d = a; - } - while (0); - if (g | 0) { - a = c[(j + 28) >> 2] | 0; - b = (21952 + (a << 2)) | 0; - if ((c[b >> 2] | 0) == (j | 0)) { - c[b >> 2] = d; - if (!d) { - c[5413] = c[5413] & ~(1 << a); - break; - } - } - else { - e = (g + 16) | 0; - c[((c[e >> 2] | 0) == (j | 0) ? e : (g + 20) | 0) >> 2] = d; - if (!d) - break; - } - c[(d + 24) >> 2] = g; - a = (j + 16) | 0; - b = c[a >> 2] | 0; - if (b | 0) { - c[(d + 16) >> 2] = b; - c[(b + 24) >> 2] = d; - } - a = c[(a + 4) >> 2] | 0; - if (a | 0) { - c[(d + 20) >> 2] = a; - c[(a + 24) >> 2] = d; - } - } - } - while (0); - c[(i + 4) >> 2] = f | 1; - c[(h + f) >> 2] = f; - if ((i | 0) == (c[5417] | 0)) { - c[5414] = f; - return; - } - } - else { - c[a >> 2] = e & -2; - c[(i + 4) >> 2] = b | 1; - c[(h + b) >> 2] = b; - f = b; - } - a = f >>> 3; - if (f >>> 0 < 256) { - d = (21688 + ((a << 1) << 2)) | 0; - b = c[5412] | 0; - a = 1 << a; - if (!(b & a)) { - c[5412] = b | a; - a = d; - b = (d + 8) | 0; - } - else { - b = (d + 8) | 0; - a = c[b >> 2] | 0; - } - c[b >> 2] = i; - c[(a + 12) >> 2] = i; - c[(i + 8) >> 2] = a; - c[(i + 12) >> 2] = d; - return; - } - a = f >>> 8; - if (a) - if (f >>> 0 > 16777215) - e = 31; - else { - h = (((a + 1048320) | 0) >>> 16) & 8; - j = a << h; - g = (((j + 520192) | 0) >>> 16) & 4; - j = j << g; - e = (((j + 245760) | 0) >>> 16) & 2; - e = (14 - (g | h | e) + ((j << e) >>> 15)) | 0; - e = ((f >>> ((e + 7) | 0)) & 1) | (e << 1); - } - else - e = 0; - a = (21952 + (e << 2)) | 0; - c[(i + 28) >> 2] = e; - c[(i + 20) >> 2] = 0; - c[(i + 16) >> 2] = 0; - b = c[5413] | 0; - d = 1 << e; - a: do - if (!(b & d)) { - c[5413] = b | d; - c[a >> 2] = i; - c[(i + 24) >> 2] = a; - c[(i + 12) >> 2] = i; - c[(i + 8) >> 2] = i; - } - else { - a = c[a >> 2] | 0; - b: do - if (((c[(a + 4) >> 2] & -8) | 0) != (f | 0)) { - e = f << ((e | 0) == 31 ? 0 : (25 - (e >>> 1)) | 0); - while (1) { - d = (a + 16 + ((e >>> 31) << 2)) | 0; - b = c[d >> 2] | 0; - if (!b) - break; - if (((c[(b + 4) >> 2] & -8) | 0) == (f | 0)) { - a = b; - break b; - } - else { - e = e << 1; - a = b; - } - } - c[d >> 2] = i; - c[(i + 24) >> 2] = a; - c[(i + 12) >> 2] = i; - c[(i + 8) >> 2] = i; - break a; - } - while (0); - h = (a + 8) | 0; - j = c[h >> 2] | 0; - c[(j + 12) >> 2] = i; - c[h >> 2] = i; - c[(i + 8) >> 2] = j; - c[(i + 12) >> 2] = a; - c[(i + 24) >> 2] = 0; - } - while (0); - j = ((c[5420] | 0) + -1) | 0; - c[5420] = j; - if (j | 0) - return; - a = 22104; - while (1) { - a = c[a >> 2] | 0; - if (!a) - break; - else - a = (a + 8) | 0; - } - c[5420] = -1; - return; - } - function fr(a) { - a = a | 0; - var b = 0, d = 0, e = 0; - e = (a + 3) & -4; - a = sr() | 0; - b = c[a >> 2] | 0; - d = (b + e) | 0; - do - if (((e | 0) < 1) | (d >>> 0 > b >>> 0)) { - if (d >>> 0 > (R() | 0) >>> 0 ? (T(d | 0) | 0) == 0 : 0) - break; - c[a >> 2] = d; - e = b; - return e | 0; - } - while (0); - c[(ao() | 0) >> 2] = 48; - e = -1; - return e | 0; - } - function gr(a) { - a = a | 0; - var b = 0; - b = V; - V = (V + a) | 0; - V = (V + 15) & -16; - return b | 0; - } - function hr(a) { - a = a | 0; - V = a; - } - function ir() { - return V | 0; - } - function jr(a, b) { - a = a | 0; - b = b | 0; - var c = 0, d = 0, e = 0, f = 0; - f = a & 65535; - e = b & 65535; - c = q(e, f) | 0; - d = a >>> 16; - a = ((c >>> 16) + (q(e, d) | 0)) | 0; - e = b >>> 16; - b = q(e, f) | 0; - return ((t(((a >>> 16) + (q(e, d) | 0) + ((((a & 65535) + b) | 0) >>> 16)) | 0), - ((a + b) << 16) | (c & 65535) | 0) | 0); - } - function kr(a, b, c, d) { - a = a | 0; - b = b | 0; - c = c | 0; - d = d | 0; - var e = 0, f = 0; - e = a; - f = c; - c = jr(e, f) | 0; - a = u() | 0; - return (t(((q(b, f) | 0) + (q(d, e) | 0) + a) | (a & 0) | 0), c | 0 | 0) | 0; - } - function lr(a, b, c, d) { - a = a | 0; - b = b | 0; - c = c | 0; - d = d | 0; - c = (a + c) >>> 0; - return (t(((b + d + ((c >>> 0 < a >>> 0) | 0)) >>> 0) | 0), c | 0) | 0; - } - function mr(a, b, c, d) { - a = a | 0; - b = b | 0; - c = c | 0; - d = d | 0; - d = (b - d - ((c >>> 0 > a >>> 0) | 0)) >>> 0; - return (t(d | 0), ((a - c) >>> 0) | 0) | 0; - } - function nr(a) { - a = a | 0; - return (a ? (31 - (r(a ^ (a - 1)) | 0)) | 0 : 32) | 0; - } - function or(a, b, d, e, f) { - a = a | 0; - b = b | 0; - d = d | 0; - e = e | 0; - f = f | 0; - var g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0; - l = a; - j = b; - k = j; - h = d; - n = e; - i = n; - if (!k) { - g = (f | 0) != 0; - if (!i) { - if (g) { - c[f >> 2] = (l >>> 0) % (h >>> 0); - c[(f + 4) >> 2] = 0; - } - n = 0; - f = ((l >>> 0) / (h >>> 0)) >>> 0; - return (t(n | 0), f) | 0; - } - else { - if (!g) { - n = 0; - f = 0; - return (t(n | 0), f) | 0; - } - c[f >> 2] = a | 0; - c[(f + 4) >> 2] = b & 0; - n = 0; - f = 0; - return (t(n | 0), f) | 0; - } - } - g = (i | 0) == 0; - do - if (h) { - if (!g) { - g = ((r(i | 0) | 0) - (r(k | 0) | 0)) | 0; - if (g >>> 0 <= 31) { - m = (g + 1) | 0; - i = (31 - g) | 0; - b = (g - 31) >> 31; - h = m; - a = ((l >>> (m >>> 0)) & b) | (k << i); - b = (k >>> (m >>> 0)) & b; - g = 0; - i = l << i; - break; - } - if (!f) { - n = 0; - f = 0; - return (t(n | 0), f) | 0; - } - c[f >> 2] = a | 0; - c[(f + 4) >> 2] = j | (b & 0); - n = 0; - f = 0; - return (t(n | 0), f) | 0; - } - g = (h - 1) | 0; - if ((g & h) | 0) { - i = ((r(h | 0) | 0) + 33 - (r(k | 0) | 0)) | 0; - p = (64 - i) | 0; - m = (32 - i) | 0; - j = m >> 31; - o = (i - 32) | 0; - b = o >> 31; - h = i; - a = (((m - 1) >> 31) & (k >>> (o >>> 0))) | (((k << m) | (l >>> (i >>> 0))) & b); - b = b & (k >>> (i >>> 0)); - g = (l << p) & j; - i = (((k << p) | (l >>> (o >>> 0))) & j) | ((l << m) & ((i - 33) >> 31)); - break; - } - if (f | 0) { - c[f >> 2] = g & l; - c[(f + 4) >> 2] = 0; - } - if ((h | 0) == 1) { - o = j | (b & 0); - p = a | 0 | 0; - return (t(o | 0), p) | 0; - } - else { - p = nr(h | 0) | 0; - o = (k >>> (p >>> 0)) | 0; - p = (k << (32 - p)) | (l >>> (p >>> 0)) | 0; - return (t(o | 0), p) | 0; - } - } - else { - if (g) { - if (f | 0) { - c[f >> 2] = (k >>> 0) % (h >>> 0); - c[(f + 4) >> 2] = 0; - } - o = 0; - p = ((k >>> 0) / (h >>> 0)) >>> 0; - return (t(o | 0), p) | 0; - } - if (!l) { - if (f | 0) { - c[f >> 2] = 0; - c[(f + 4) >> 2] = (k >>> 0) % (i >>> 0); - } - o = 0; - p = ((k >>> 0) / (i >>> 0)) >>> 0; - return (t(o | 0), p) | 0; - } - g = (i - 1) | 0; - if (!(g & i)) { - if (f | 0) { - c[f >> 2] = a | 0; - c[(f + 4) >> 2] = (g & k) | (b & 0); - } - o = 0; - p = k >>> ((nr(i | 0) | 0) >>> 0); - return (t(o | 0), p) | 0; - } - g = ((r(i | 0) | 0) - (r(k | 0) | 0)) | 0; - if (g >>> 0 <= 30) { - b = (g + 1) | 0; - i = (31 - g) | 0; - h = b; - a = (k << i) | (l >>> (b >>> 0)); - b = k >>> (b >>> 0); - g = 0; - i = l << i; - break; - } - if (!f) { - o = 0; - p = 0; - return (t(o | 0), p) | 0; - } - c[f >> 2] = a | 0; - c[(f + 4) >> 2] = j | (b & 0); - o = 0; - p = 0; - return (t(o | 0), p) | 0; - } - while (0); - if (!h) { - k = i; - j = 0; - i = 0; - } - else { - m = d | 0 | 0; - l = n | (e & 0); - k = lr(m | 0, l | 0, -1, -1) | 0; - d = u() | 0; - j = i; - i = 0; - do { - e = j; - j = (g >>> 31) | (j << 1); - g = i | (g << 1); - e = (a << 1) | (e >>> 31) | 0; - n = (a >>> 31) | (b << 1) | 0; - mr(k | 0, d | 0, e | 0, n | 0) | 0; - p = u() | 0; - o = (p >> 31) | (((p | 0) < 0 ? -1 : 0) << 1); - i = o & 1; - a = - mr(e | 0, n | 0, (o & m) | 0, (((((p | 0) < 0 ? -1 : 0) >> 31) | (((p | 0) < 0 ? -1 : 0) << 1)) & l) | 0) | 0; - b = u() | 0; - h = (h - 1) | 0; - } while ((h | 0) != 0); - k = j; - j = 0; - } - h = 0; - if (f | 0) { - c[f >> 2] = a; - c[(f + 4) >> 2] = b; - } - o = ((g | 0) >>> 31) | ((k | h) << 1) | (((h << 1) | (g >>> 31)) & 0) | j; - p = (((g << 1) | (0 >>> 31)) & -2) | i; - return (t(o | 0), p) | 0; - } - function pr(a, b, c, d) { - a = a | 0; - b = b | 0; - c = c | 0; - d = d | 0; - return or(a, b, c, d, 0) | 0; - } - function qr(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - if ((c | 0) < 32) { - t((b >>> c) | 0); - return (a >>> c) | ((b & ((1 << c) - 1)) << (32 - c)); - } - t(0); - return (b >>> (c - 32)) | 0; - } - function rr(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - if ((c | 0) < 32) { - t((b << c) | ((a & (((1 << c) - 1) << (32 - c))) >>> (32 - c)) | 0); - return a << c; - } - t((a << (c - 32)) | 0); - return 0; - } - function sr() { - return 22176; - } - function tr(a) { - a = a | 0; - return (((a & 255) << 24) | (((a >> 8) & 255) << 16) | (((a >> 16) & 255) << 8) | (a >>> 24) | 0); - } - function ur(b, d, e) { - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0, h = 0; - if ((e | 0) >= 512) { - S(b | 0, d | 0, e | 0) | 0; - return b | 0; - } - h = b | 0; - g = (b + e) | 0; - if ((b & 3) == (d & 3)) { - while (b & 3) { - if (!e) - return h | 0; - a[b >> 0] = a[d >> 0] | 0; - b = (b + 1) | 0; - d = (d + 1) | 0; - e = (e - 1) | 0; - } - e = (g & -4) | 0; - f = (e - 64) | 0; - while ((b | 0) <= (f | 0)) { - c[b >> 2] = c[d >> 2]; - c[(b + 4) >> 2] = c[(d + 4) >> 2]; - c[(b + 8) >> 2] = c[(d + 8) >> 2]; - c[(b + 12) >> 2] = c[(d + 12) >> 2]; - c[(b + 16) >> 2] = c[(d + 16) >> 2]; - c[(b + 20) >> 2] = c[(d + 20) >> 2]; - c[(b + 24) >> 2] = c[(d + 24) >> 2]; - c[(b + 28) >> 2] = c[(d + 28) >> 2]; - c[(b + 32) >> 2] = c[(d + 32) >> 2]; - c[(b + 36) >> 2] = c[(d + 36) >> 2]; - c[(b + 40) >> 2] = c[(d + 40) >> 2]; - c[(b + 44) >> 2] = c[(d + 44) >> 2]; - c[(b + 48) >> 2] = c[(d + 48) >> 2]; - c[(b + 52) >> 2] = c[(d + 52) >> 2]; - c[(b + 56) >> 2] = c[(d + 56) >> 2]; - c[(b + 60) >> 2] = c[(d + 60) >> 2]; - b = (b + 64) | 0; - d = (d + 64) | 0; - } - while ((b | 0) < (e | 0)) { - c[b >> 2] = c[d >> 2]; - b = (b + 4) | 0; - d = (d + 4) | 0; - } - } - else { - e = (g - 4) | 0; - while ((b | 0) < (e | 0)) { - a[b >> 0] = a[d >> 0] | 0; - a[(b + 1) >> 0] = a[(d + 1) >> 0] | 0; - a[(b + 2) >> 0] = a[(d + 2) >> 0] | 0; - a[(b + 3) >> 0] = a[(d + 3) >> 0] | 0; - b = (b + 4) | 0; - d = (d + 4) | 0; - } - } - while ((b | 0) < (g | 0)) { - a[b >> 0] = a[d >> 0] | 0; - b = (b + 1) | 0; - d = (d + 1) | 0; - } - return h | 0; - } - function vr(b, c, d) { - b = b | 0; - c = c | 0; - d = d | 0; - var e = 0; - if (((c | 0) < (b | 0)) & ((b | 0) < ((c + d) | 0))) { - e = b; - c = (c + d) | 0; - b = (b + d) | 0; - while ((d | 0) > 0) { - b = (b - 1) | 0; - c = (c - 1) | 0; - d = (d - 1) | 0; - a[b >> 0] = a[c >> 0] | 0; - } - b = e; - } - else - ur(b, c, d) | 0; - return b | 0; - } - function wr(b, d, e) { - b = b | 0; - d = d | 0; - e = e | 0; - var f = 0, g = 0, h = 0, i = 0; - h = (b + e) | 0; - d = d & 255; - if ((e | 0) >= 67) { - while (b & 3) { - a[b >> 0] = d; - b = (b + 1) | 0; - } - f = (h & -4) | 0; - i = d | (d << 8) | (d << 16) | (d << 24); - g = (f - 64) | 0; - while ((b | 0) <= (g | 0)) { - c[b >> 2] = i; - c[(b + 4) >> 2] = i; - c[(b + 8) >> 2] = i; - c[(b + 12) >> 2] = i; - c[(b + 16) >> 2] = i; - c[(b + 20) >> 2] = i; - c[(b + 24) >> 2] = i; - c[(b + 28) >> 2] = i; - c[(b + 32) >> 2] = i; - c[(b + 36) >> 2] = i; - c[(b + 40) >> 2] = i; - c[(b + 44) >> 2] = i; - c[(b + 48) >> 2] = i; - c[(b + 52) >> 2] = i; - c[(b + 56) >> 2] = i; - c[(b + 60) >> 2] = i; - b = (b + 64) | 0; - } - while ((b | 0) < (f | 0)) { - c[b >> 2] = i; - b = (b + 4) | 0; - } - } - while ((b | 0) < (h | 0)) { - a[b >> 0] = d; - b = (b + 1) | 0; - } - return (h - e) | 0; - } - function xr(a) { - a = a | 0; - return Y[a & 3]() | 0; - } - function yr(a, b) { - a = a | 0; - b = b | 0; - return Z[a & 15](b | 0) | 0; - } - function zr(a, b, c, d, e, f, g) { - a = a | 0; - b = b | 0; - c = +c; - d = d | 0; - e = e | 0; - f = f | 0; - g = g | 0; - return _[a & 1](b | 0, +c, d | 0, e | 0, f | 0, g | 0) | 0; - } - function Ar(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - return $[a & 63](b | 0, c | 0) | 0; - } - function Br(a, b, c, d) { - a = a | 0; - b = b | 0; - c = c | 0; - d = d | 0; - return aa[a & 7](b | 0, c | 0, d | 0) | 0; - } - function Cr(a) { - a = a | 0; - ba[a & 3](); - } - function Dr(a, b) { - a = a | 0; - b = b | 0; - ca[a & 255](b | 0); - } - function Er(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - da[a & 15](b | 0, c | 0); - } - function Fr(a, b, c, d) { - a = a | 0; - b = b | 0; - c = c | 0; - d = d | 0; - ea[a & 15](b | 0, c | 0, d | 0); - } - function Gr(a, b, c, d, e) { - a = a | 0; - b = b | 0; - c = c | 0; - d = d | 0; - e = e | 0; - fa[a & 7](b | 0, c | 0, d | 0, e | 0); - } - function Hr(a, b, c, d, e, f) { - a = a | 0; - b = b | 0; - c = c | 0; - d = d | 0; - e = e | 0; - f = f | 0; - ga[a & 3](b | 0, c | 0, d | 0, e | 0, f | 0); - } - function Ir(a, b, c, d, e, f, g) { - a = a | 0; - b = b | 0; - c = c | 0; - d = d | 0; - e = e | 0; - f = f | 0; - g = g | 0; - ha[a & 3](b | 0, c | 0, d | 0, e | 0, f | 0, g | 0); - } - function Jr() { - s(0); - return 0; - } - function Kr(a) { - a = a | 0; - s(1); - return 0; - } - function Lr(a, b, c, d, e, f) { - a = a | 0; - b = +b; - c = c | 0; - d = d | 0; - e = e | 0; - f = f | 0; - s(2); - return 0; - } - function Mr(a, b) { - a = a | 0; - b = b | 0; - s(3); - return 0; - } - function Nr(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - s(4); - return 0; - } - function Or() { - s(5); - } - function Pr(a) { - a = a | 0; - s(6); - } - function Qr(a, b) { - a = a | 0; - b = b | 0; - s(7); - } - function Rr(a, b, c) { - a = a | 0; - b = b | 0; - c = c | 0; - s(8); - } - function Sr(a, b, c, d) { - a = a | 0; - b = b | 0; - c = c | 0; - d = d | 0; - s(9); - } - function Tr(a, b, c, d, e) { - a = a | 0; - b = b | 0; - c = c | 0; - d = d | 0; - e = e | 0; - s(10); - } - function Ur(a, b, c, d, e, f) { - a = a | 0; - b = b | 0; - c = c | 0; - d = d | 0; - e = e | 0; - f = f | 0; - s(11); - } - // EMSCRIPTEN_END_FUNCS - var Y = [Jr, Mk, Fl, Jr]; - var Z = [Kr, Ap, zb, Fb, qp, tp, oq, Kq, Tq, wk, na, tl, Ok, Hl, Kr, Kr]; - var _ = [Lr, po]; - var $ = [ - Mr, - Ba, - Ka, - Eb, - jd, - Nd, - Xd, - je, - ke, - ne, - _e, - ff, - yf, - Ff, - Of, - Vf, - Hg, - Qg, - Zg, - ch, - lh, - qh, - zh, - Eh, - Nh, - _h, - fi, - ki, - si, - Bi, - Si, - Zi, - fj, - oj, - yj, - Fj, - Pj, - Yj, - ek, - lk, - tk, - ll, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr, - Mr - ]; - var aa = [Nr, Io, Yo, Fp, Hp, Mq, Nq, Nr]; - var ba = [Or, Dp, Po, Or]; - var ca = [ - Pr, - pq, - za, - Aa, - Ca, - Ia, - Ja, - La, - yp, - ob, - Gb, - yb, - Bb, - Cb, - Lb, - Mb, - Xb, - Yb, - sc, - tc, - uc, - Nc, - hd, - id, - kd, - Jd, - Od, - Pd, - Qd, - Rd, - Vd, - Wd, - Yd, - he, - ie, - le, - me, - Ye, - Ze, - $e, - df, - ef, - wf, - xf, - zf, - Df, - Ef, - Mf, - Nf, - Pf, - Tf, - Uf, - Fg, - Gg, - Ig, - Rg, - Sg, - Xg, - Yg, - _g, - dh, - eh, - jh, - kh, - mh, - rh, - sh, - xh, - yh, - Ah, - Fh, - Gh, - Lh, - Mh, - Oh, - Yh, - Zh, - $h, - di, - ei, - gi, - li, - mi, - qi, - ri, - ti, - zi, - Ai, - Qi, - Ri, - Ti, - Xi, - Yi, - dj, - ej, - gj, - mj, - nj, - wj, - xj, - zj, - Dj, - Ej, - Nj, - Oj, - Qj, - Wj, - Xj, - ck, - dk, - fk, - jk, - kk, - rk, - sk, - uk, - Uo, - Vo, - Wo, - Xo, - fp, - op, - pp, - rp, - sp, - zp, - Bp, - Cp, - Ep, - Gp, - Lp, - mq, - nq, - Iq, - Jq, - Sq, - Yq, - Zq, - zk, - wl, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr, - Pr - ]; - var da = [Qr, Ab, Db, ma, pa, qa, ra, sa, qo, Qr, Qr, Qr, Qr, Qr, Qr, Qr]; - var ea = [Rr, Lq, Oq, Uq, Vq, la, oa, dl, Vl, $l, Rr, Rr, Rr, Rr, Rr, Rr]; - var fa = [Sr, $o, ip, Op, Vk, Ol, Sr, Sr]; - var ga = [Tr, _o, hp, Np]; - var ha = [Ur, Zo, gp, Mp]; - return { - __ZSt18uncaught_exceptionv: kq, - ___cxa_can_catch: hq, - ___cxa_is_pointer_type: iq, - ___embind_register_native_and_builtin_types: im, - ___errno_location: ao, - ___getTypeName: $n, - ___muldi3: kr, - ___udivdi3: pr, - _bitshift64Lshr: qr, - _bitshift64Shl: rr, - _emscripten_get_sbrk_ptr: sr, - _free: er, - _i64Add: lr, - _i64Subtract: mr, - _llvm_bswap_i32: tr, - _malloc: dr, - _memcpy: ur, - _memmove: vr, - _memset: wr, - dynCall_i: xr, - dynCall_ii: yr, - dynCall_iidiiii: zr, - dynCall_iii: Ar, - dynCall_iiii: Br, - dynCall_v: Cr, - dynCall_vi: Dr, - dynCall_vii: Er, - dynCall_viii: Fr, - dynCall_viiii: Gr, - dynCall_viiiii: Hr, - dynCall_viiiiii: Ir, - globalCtors: ia, - stackAlloc: gr, - stackRestore: hr, - stackSave: ir - }; - })( - // EMSCRIPTEN_END_ASM - asmGlobalArg, asmLibraryArg, buffer); - var __ZSt18uncaught_exceptionv = (Module['__ZSt18uncaught_exceptionv'] = - asm['__ZSt18uncaught_exceptionv']); - (Module['___cxa_can_catch'] = asm['___cxa_can_catch']); - (Module['___cxa_is_pointer_type'] = asm['___cxa_is_pointer_type']); - (Module['___embind_register_native_and_builtin_types'] = asm['___embind_register_native_and_builtin_types']); - (Module['___errno_location'] = asm['___errno_location']); - var ___getTypeName = (Module['___getTypeName'] = asm['___getTypeName']); - (Module['___muldi3'] = asm['___muldi3']); - (Module['___udivdi3'] = asm['___udivdi3']); - (Module['_bitshift64Lshr'] = asm['_bitshift64Lshr']); - (Module['_bitshift64Shl'] = asm['_bitshift64Shl']); - (Module['_emscripten_get_sbrk_ptr'] = - asm['_emscripten_get_sbrk_ptr']); - var _free = (Module['_free'] = asm['_free']); - (Module['_i64Add'] = asm['_i64Add']); - (Module['_i64Subtract'] = asm['_i64Subtract']); - (Module['_llvm_bswap_i32'] = asm['_llvm_bswap_i32']); - var _malloc = (Module['_malloc'] = asm['_malloc']); - (Module['_memcpy'] = asm['_memcpy']); - (Module['_memmove'] = asm['_memmove']); - (Module['_memset'] = asm['_memset']); - var globalCtors = (Module['globalCtors'] = asm['globalCtors']); - (Module['stackAlloc'] = asm['stackAlloc']); - (Module['stackRestore'] = asm['stackRestore']); - (Module['stackSave'] = asm['stackSave']); - (Module['dynCall_i'] = asm['dynCall_i']); - (Module['dynCall_ii'] = asm['dynCall_ii']); - (Module['dynCall_iidiiii'] = asm['dynCall_iidiiii']); - (Module['dynCall_iii'] = asm['dynCall_iii']); - (Module['dynCall_iiii'] = asm['dynCall_iiii']); - (Module['dynCall_v'] = asm['dynCall_v']); - (Module['dynCall_vi'] = asm['dynCall_vi']); - (Module['dynCall_vii'] = asm['dynCall_vii']); - (Module['dynCall_viii'] = asm['dynCall_viii']); - (Module['dynCall_viiii'] = asm['dynCall_viiii']); - (Module['dynCall_viiiii'] = asm['dynCall_viiiii']); - (Module['dynCall_viiiiii'] = asm['dynCall_viiiiii']); - Module['asm'] = asm; - if (memoryInitializer) { - if (!isDataURI(memoryInitializer)) { - memoryInitializer = locateFile(memoryInitializer); - } - if (ENVIRONMENT_IS_NODE || ENVIRONMENT_IS_SHELL) { - var data = readBinary(memoryInitializer); - HEAPU8.set(data, GLOBAL_BASE); - } - else { - addRunDependency(); - var applyMemoryInitializer = function (data) { - if (data.byteLength) - data = new Uint8Array(data); - HEAPU8.set(data, GLOBAL_BASE); - if (Module['memoryInitializerRequest']) - delete Module['memoryInitializerRequest'].response; - removeRunDependency(); - }; - var doBrowserLoad = function () { - readAsync(memoryInitializer, applyMemoryInitializer, function () { - var e = new Error('could not load memory initializer ' + memoryInitializer); - throw e; - }); - }; - var memoryInitializerBytes = tryParseAsDataURI(memoryInitializer); - if (memoryInitializerBytes) { - applyMemoryInitializer(memoryInitializerBytes.buffer); - } - else if (Module['memoryInitializerRequest']) { - var useRequest = function () { - var request = Module['memoryInitializerRequest']; - var response = request.response; - if (request.status !== 200 && request.status !== 0) { - var data = tryParseAsDataURI(Module['memoryInitializerRequestURL']); - if (data) { - response = data.buffer; - } - else { - console.warn('a problem seems to have happened with Module.memoryInitializerRequest, status: ' + - request.status + - ', retrying ' + - memoryInitializer); - doBrowserLoad(); - return; - } - } - applyMemoryInitializer(response); - }; - if (Module['memoryInitializerRequest'].response) { - setTimeout(useRequest, 0); - } - else { - Module['memoryInitializerRequest'].addEventListener('load', useRequest); - } - } - else { - doBrowserLoad(); - } - } - } - var calledRun; - function ExitStatus(status) { - this.name = 'ExitStatus'; - this.message = 'Program terminated with exit(' + status + ')'; - this.status = status; - } - dependenciesFulfilled = function runCaller() { - if (!calledRun) - run(); - if (!calledRun) - dependenciesFulfilled = runCaller; - }; - function run(args) { - if (runDependencies > 0) { - return; - } - preRun(); - if (runDependencies > 0) - return; - function doRun() { - if (calledRun) - return; - calledRun = true; - Module['calledRun'] = true; - if (ABORT) - return; - initRuntime(); - preMain(); - if (Module['onRuntimeInitialized']) - Module['onRuntimeInitialized'](); - postRun(); - } - if (Module['setStatus']) { - Module['setStatus']('Running...'); - setTimeout(function () { - setTimeout(function () { - Module['setStatus'](''); - }, 1); - doRun(); - }, 1); - } - else { - doRun(); - } - } - Module['run'] = run; - if (Module['preInit']) { - if (typeof Module['preInit'] == 'function') - Module['preInit'] = [Module['preInit']]; - while (Module['preInit'].length > 0) { - Module['preInit'].pop()(); - } - } - run(); - return Module; -} - -let Module = null; -const POINT_FORMAT_READERS = { - 0: (dv) => { - return { - position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)], - intensity: dv.getUint16(12, true), - classification: dv.getUint8(15) - }; - }, - 1: (dv) => { - return { - position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)], - intensity: dv.getUint16(12, true), - classification: dv.getUint8(15) - }; - }, - 2: (dv) => { - return { - position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)], - intensity: dv.getUint16(12, true), - classification: dv.getUint8(15), - color: [dv.getUint16(20, true), dv.getUint16(22, true), dv.getUint16(24, true)] - }; - }, - 3: (dv) => { - return { - position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)], - intensity: dv.getUint16(12, true), - classification: dv.getUint8(15), - color: [dv.getUint16(28, true), dv.getUint16(30, true), dv.getUint16(32, true)] - }; - } -}; -/** - * Reads incoming binary data depends on the Type parameter - * @param buf - * @param Type - * @param offset - * @param count - * @returns number | number[] from incoming binary data - */ -function readAs(buf, Type = {}, offset, count) { - count = count === undefined || count === 0 ? 1 : count; - const sub = buf.slice(offset, offset + Type.BYTES_PER_ELEMENT * count); - const r = new Type(sub); - if (count === 1) { - return r[0]; - } - const ret = []; - for (let i = 0; i < count; i++) { - ret.push(r[i]); - } - return ret; -} -/** - * Parsing of header's attributes - * @param arraybuffer - * @returns header as LASHeader - */ -function parseLASHeader(arraybuffer) { - let start = 32 * 3 + 35; - const o = { - pointsOffset: readAs(arraybuffer, Uint32Array, 32 * 3), - pointsFormatId: readAs(arraybuffer, Uint8Array, 32 * 3 + 8), - pointsStructSize: readAs(arraybuffer, Uint16Array, 32 * 3 + 8 + 1), - pointsCount: readAs(arraybuffer, Uint32Array, 32 * 3 + 11), - scale: readAs(arraybuffer, Float64Array, start, 3) - }; - start += 24; // 8*3 - o.offset = readAs(arraybuffer, Float64Array, start, 3); - start += 24; - const bounds = readAs(arraybuffer, Float64Array, start, 6); - start += 48; // 8*6; - o.maxs = [bounds[0], bounds[2], bounds[4]]; - o.mins = [bounds[1], bounds[3], bounds[5]]; - return o; -} -// LAS Loader -// Loads uncompressed files -// -class LASLoader$1 { - arraybuffer; - readOffset = 0; - header = { - pointsOffset: 0, - pointsFormatId: 0, - pointsStructSize: 0, - pointsCount: 0, - scale: [0, 0, 0], - offset: [0, 0, 0], - maxs: [0], - mins: [0], - totalToRead: 0, - totalRead: 0, - versionAsString: '', - isCompressed: true - }; - constructor(arraybuffer) { - this.arraybuffer = arraybuffer; - } - /** - * @returns boolean - */ - open() { - // Nothing needs to be done to open this - return true; - } - /** - * Parsing of incoming binary - * @returns LASHeader - */ - getHeader() { - this.header = parseLASHeader(this.arraybuffer); - return this.header; - } - /** - * Reading data - * @param count - * @param skip - * @returns new ArrayBuffer, count, hasMoreData - */ - readData(count, skip) { - const { header, arraybuffer } = this; - if (!header) { - throw new Error('Cannot start reading data till a header request is issued'); - } - let { readOffset } = this; - let start; - if (skip <= 1) { - count = Math.min(count, header.pointsCount - readOffset); - start = header.pointsOffset + readOffset * header.pointsStructSize; - const end = start + count * header.pointsStructSize; - readOffset += count; - this.readOffset = readOffset; - return { - buffer: arraybuffer.slice(start, end), - count, - hasMoreData: readOffset < header.pointsCount - }; - } - const pointsToRead = Math.min(count * skip, header.pointsCount - readOffset); - const bufferSize = Math.ceil(pointsToRead / skip); - let pointsRead = 0; - const buf = new Uint8Array(bufferSize * header.pointsStructSize); - for (let i = 0; i < pointsToRead; i++) { - if (i % skip === 0) { - start = header.pointsOffset + readOffset * header.pointsStructSize; - const src = new Uint8Array(arraybuffer, start, header.pointsStructSize); - buf.set(src, pointsRead * header.pointsStructSize); - pointsRead++; - } - readOffset++; - } - this.readOffset = readOffset; - return { - buffer: buf.buffer, - count: pointsRead, - hasMoreData: readOffset < header.pointsCount - }; - } - /** - * Method which brings data to null to close the file - * @returns - */ - close() { - // @ts-ignore Possibly null - this.arraybuffer = null; - return true; - } -} -/** - * LAZ Loader - * Uses NaCL module to load LAZ files - */ -class LAZLoader { - arraybuffer; - instance = null; // LASZip instance - header = null; - constructor(arraybuffer) { - this.arraybuffer = arraybuffer; - if (!Module) { - // Avoid executing laz-perf on import - Module = getModule(); - } - } - /** - * Opens the file - * @returns boolean - */ - open() { - try { - const { arraybuffer } = this; - this.instance = new Module.LASZip(); - const abInt = new Uint8Array(arraybuffer); - const buf = Module._malloc(arraybuffer.byteLength); - this.instance.arraybuffer = arraybuffer; - this.instance.buf = buf; - Module.HEAPU8.set(abInt, buf); - this.instance.open(buf, arraybuffer.byteLength); - this.instance.readOffset = 0; - return true; - } - catch (error) { - throw new Error(`Failed to open file: ${error.message}`); - } - } - getHeader() { - if (!this.instance) { - throw new Error('You need to open the file before trying to read header'); - } - try { - const header = parseLASHeader(this.instance.arraybuffer); - header.pointsFormatId &= 0x3f; - this.header = header; - return header; - } - catch (error) { - throw new Error(`Failed to get header: ${error.message}`); - } - } - /** - * @param count - * @param offset - * @param skip - * @returns Data - */ - readData(count, offset, skip) { - if (!this.instance) { - throw new Error('You need to open the file before trying to read stuff'); - } - const { header, instance } = this; - if (!header) { - throw new Error('You need to query header before reading, I maintain state that way, sorry :('); - } - try { - const pointsToRead = Math.min(count * skip, header.pointsCount - instance.readOffset); - const bufferSize = Math.ceil(pointsToRead / skip); - let pointsRead = 0; - const thisBuf = new Uint8Array(bufferSize * header.pointsStructSize); - const bufRead = Module._malloc(header.pointsStructSize); - for (let i = 0; i < pointsToRead; i++) { - instance.getPoint(bufRead); - if (i % skip === 0) { - const a = new Uint8Array(Module.HEAPU8.buffer, bufRead, header.pointsStructSize); - thisBuf.set(a, pointsRead * header.pointsStructSize); - pointsRead++; - } - instance.readOffset++; - } - Module._free(bufRead); - return { - buffer: thisBuf.buffer, - count: pointsRead, - hasMoreData: instance.readOffset < header.pointsCount - }; - } - catch (error) { - throw new Error(`Failed to read data: ${error.message}`); - } - } - /** - * Deletes the instance - * @returns boolean - */ - close() { - try { - if (this.instance !== null) { - Module._free(this.instance.buf); - this.instance.delete(); - this.instance = null; - } - return true; - } - catch (error) { - throw new Error(`Failed to close file: ${error.message}`); - } - } -} -/** - * Helper class: Decodes LAS records into points - */ -class LASDecoder { - arrayb; - decoder; - pointsCount; - pointSize; - scale; - offset; - mins; - maxs; - constructor(buffer, len, header) { - this.arrayb = buffer; - this.decoder = POINT_FORMAT_READERS[header.pointsFormatId]; - this.pointsCount = len; - this.pointSize = header.pointsStructSize; - this.scale = header.scale; - this.offset = header.offset; - this.mins = header.mins; - this.maxs = header.maxs; - } - /** - * Decodes data depends on this point size - * @param index - * @returns New object - */ - getPoint(index) { - if (index < 0 || index >= this.pointsCount) { - throw new Error('Point index out of range'); - } - const dv = new DataView(this.arrayb, index * this.pointSize, this.pointSize); - return this.decoder(dv); - } -} -/** - * A single consistent interface for loading LAS/LAZ files - */ -class LASFile { - arraybuffer; - formatId = 0; - loader; - isCompressed = true; - isOpen = false; - version = 0; - versionAsString = ''; - constructor(arraybuffer) { - this.arraybuffer = arraybuffer; - if (this.determineVersion() > 13) { - throw new Error('Only file versions <= 1.3 are supported at this time'); - } - this.determineFormat(); - if (POINT_FORMAT_READERS[this.formatId] === undefined) { - throw new Error('The point format ID is not supported'); - } - this.loader = this.isCompressed - ? new LAZLoader(this.arraybuffer) - : new LASLoader$1(this.arraybuffer); - } - /** - * Determines format in parameters of LASHeaer - */ - determineFormat() { - const formatId = readAs(this.arraybuffer, Uint8Array, 32 * 3 + 8); - const bit7 = (formatId & 0x80) >> 7; - const bit6 = (formatId & 0x40) >> 6; - if (bit7 === 1 && bit6 === 1) { - throw new Error('Old style compression not supported'); - } - this.formatId = formatId & 0x3f; - this.isCompressed = bit7 === 1 || bit6 === 1; - } - /** - * Determines version - * @returns version - */ - determineVersion() { - const ver = new Int8Array(this.arraybuffer, 24, 2); - this.version = ver[0] * 10 + ver[1]; - this.versionAsString = `${ver[0]}.${ver[1]}`; - return this.version; - } - /** - * Reads if the file is open - * @returns boolean - */ - open() { - if (this.loader.open()) { - this.isOpen = true; - } - } - /** - * Gets the header - * @returns Header - */ - getHeader() { - return this.loader.getHeader(); - } - /** - * @param count - * @param start - * @param skip - * @returns Data - */ - readData(count, start, skip) { - return this.loader.readData(count, start, skip); - } - /** - * Closes the file - */ - close() { - if (this.loader.close()) { - this.isOpen = false; - } - } - /** - */ - getUnpacker() { - return LASDecoder; - } -} -/* eslint no-use-before-define: 2 */ - -/** - * Gets schema from PLY header - * @param lasHeader - * @param metadata - * @returns Schema - */ -function getLASSchema(lasHeader, attributes) { - const metadataMap = makeMetadataFromLasHeader(lasHeader); - const schema = deduceMeshSchema(attributes, metadataMap); - return schema; -} -/** - * Make arrow like schema metadata by LASHeader properties - * @param lasHeader - * @returns - */ -function makeMetadataFromLasHeader(lasHeader) { - const metadata = {}; - /* eslint-disable camelcase */ - metadata.las_pointsOffset = lasHeader.pointsOffset.toString(10); - metadata.las_pointsFormatId = lasHeader.pointsFormatId.toString(10); - metadata.las_pointsStructSize = lasHeader.pointsStructSize.toString(10); - metadata.las_pointsCount = lasHeader.pointsCount.toString(10); - metadata.las_scale = JSON.stringify(lasHeader.scale); - metadata.las_offset = JSON.stringify(lasHeader.offset); - if (lasHeader.maxs !== undefined) { - metadata.las_maxs = JSON.stringify(lasHeader.maxs); - } - if (lasHeader.mins !== undefined) { - metadata.las_mins = JSON.stringify(lasHeader.mins); - } - metadata.las_totalToRead = lasHeader.totalToRead.toString(10); - metadata.las_pointsFortotalReadmatId = lasHeader.totalRead.toString(10); - if (lasHeader.versionAsString !== undefined) { - metadata.las_versionAsString = lasHeader.versionAsString; - } - if (lasHeader.isCompressed !== undefined) { - metadata.las_isCompressed = lasHeader.isCompressed.toString(); - } - return metadata; -} - -/** - * Parsing of .las file - * @param arrayBuffer - * @param options - * @returns LASHeader - */ -function parseLAS(arrayBuffer, options) { - return parseLASMesh(arrayBuffer, options); - // This code breaks pointcloud example on the website - // const mesh = parseLASMesh(arrayBuffer, options); - // return convertMesh(mesh, options?.las?.shape || 'mesh') as LASMesh | ArrowTable | ColumnarTable; -} -/** - * Parsing of .las file - * @param arrayBuffer - * @param options - * @returns LASHeader - */ -function parseLASMesh(arrayBuffer, options = {}) { - let pointIndex = 0; - let positions; - let colors; - let intensities; - let classifications; - let originalHeader; - const lasMesh = { - loader: 'las', - loaderData: {}, - // shape: 'mesh', - schema: { fields: [], metadata: {} }, - header: { - vertexCount: 0, - boundingBox: [ - [0, 0, 0], - [0, 0, 0] - ] - }, - attributes: {}, - topology: 'point-list', - mode: 0 // GL.POINTS - }; - /* eslint-disable max-statements */ - // @ts-ignore Possibly undefined - parseLASChunked(arrayBuffer, options.las?.skip, (decoder = {}, lasHeader) => { - if (!originalHeader) { - originalHeader = lasHeader; - const total = lasHeader.totalToRead; - const PositionsType = options.las?.fp64 ? Float64Array : Float32Array; - positions = new PositionsType(total * 3); - // laslaz-decoder.js `pointFormatReaders` - colors = lasHeader.pointsFormatId >= 2 ? new Uint8Array(total * 4) : null; - intensities = new Uint16Array(total); - classifications = new Uint8Array(total); - lasMesh.loaderData = lasHeader; - lasMesh.attributes = { - POSITION: { value: positions, size: 3 }, - // non-gltf attributes, use non-capitalized names for now - intensity: { value: intensities, size: 1 }, - classification: { value: classifications, size: 1 } - }; - if (colors) { - lasMesh.attributes.COLOR_0 = { value: colors, size: 4 }; - } - } - const batchSize = decoder.pointsCount; - const { scale: [scaleX, scaleY, scaleZ], offset: [offsetX, offsetY, offsetZ] } = lasHeader; - const twoByteColor = detectTwoByteColors(decoder, batchSize, options.las?.colorDepth); - for (let i = 0; i < batchSize; i++) { - const { position, color, intensity, classification } = decoder.getPoint(i); - positions[pointIndex * 3] = position[0] * scaleX + offsetX; - positions[pointIndex * 3 + 1] = position[1] * scaleY + offsetY; - positions[pointIndex * 3 + 2] = position[2] * scaleZ + offsetZ; - if (color && colors) { - if (twoByteColor) { - colors[pointIndex * 4] = color[0] / 256; - colors[pointIndex * 4 + 1] = color[1] / 256; - colors[pointIndex * 4 + 2] = color[2] / 256; - } - else { - colors[pointIndex * 4] = color[0]; - colors[pointIndex * 4 + 1] = color[1]; - colors[pointIndex * 4 + 2] = color[2]; - } - colors[pointIndex * 4 + 3] = 255; - } - intensities[pointIndex] = intensity; - classifications[pointIndex] = classification; - pointIndex++; - } - const meshBatch = { - ...lasMesh, - header: { - vertexCount: lasHeader.totalRead - }, - progress: lasHeader.totalRead / lasHeader.totalToRead - }; - options?.onProgress?.(meshBatch); - }); - /* eslint-enable max-statements */ - lasMesh.header = { - vertexCount: originalHeader.totalToRead, - boundingBox: getMeshBoundingBox(lasMesh?.attributes || {}) - }; - if (lasMesh) { - lasMesh.schema = getLASSchema(lasMesh.loaderData, lasMesh.attributes); - } - return lasMesh; -} -/** - * parse laz data - * @param rawData - * @param skip - * @param onParseData - * @return parsed point cloud - */ -/* eslint-enable max-statements */ -function parseLASChunked(rawData, skip, onParseData = {}) { - const dataHandler = new LASFile(rawData); - try { - // open data - dataHandler.open(); - const header = dataHandler.getHeader(); - // start loading - const Unpacker = dataHandler.getUnpacker(); - const totalToRead = Math.ceil(header.pointsCount / Math.max(1, skip)); - header.totalToRead = totalToRead; - let totalRead = 0; - /* eslint-disable no-constant-condition */ - while (true) { - const chunk = dataHandler.readData(1000 * 100, 0, skip); - totalRead += chunk.count; - header.totalRead = totalRead; - header.versionAsString = chunk.versionAsString; - header.isCompressed = chunk.isCompressed; - const unpacker = new Unpacker(chunk.buffer, chunk.count, header); - // surface unpacker and progress via call back - // use unpacker.pointsCount and unpacker.getPoint(i) to handle data in app - onParseData(unpacker, header); - if (!chunk.hasMoreData || totalRead >= totalToRead) { - break; - } - } - } - catch (e) { - throw e; - } - finally { - dataHandler.close(); - } -} -/** - * @param decoder - * @param batchSize - * @param colorDepth - * @returns boolean - */ -function detectTwoByteColors(decoder = {}, batchSize, colorDepth) { - let twoByteColor = false; - switch (colorDepth) { - case 8: - twoByteColor = false; - break; - case 16: - twoByteColor = true; - break; - case 'auto': - if (decoder.getPoint(0).color) { - for (let i = 0; i < batchSize; i++) { - const { color } = decoder.getPoint(i); - // eslint-disable-next-line max-depth - if (color[0] > 255 || color[1] > 255 || color[2] > 255) { - twoByteColor = true; - } - } - } - break; - default: - // eslint-disable-next-line - console.warn('las: illegal value for options.las.colorDepth'); - break; - } - return twoByteColor; -} - -/** - * Loader for the LAS (LASer) point cloud format - * @note Does not support LAS v1.4 - */ -const LASLoader = { - ...LASLoader$2, - parse: async (arrayBuffer, options) => parseLAS(arrayBuffer, options), - parseSync: (arrayBuffer, options) => parseLAS(arrayBuffer, options) -}; - -/*! - * html2canvas 1.4.1 - * Copyright (c) 2022 Niklas von Hertzen - * Released under MIT License - */ -/*! ***************************************************************************** -Copyright (c) Microsoft Corporation. - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. -***************************************************************************** */ -/* global Reflect, Promise */ - -var extendStatics = function(d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); -}; - -function __extends(d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); -} - -var __assign = function() { - __assign = Object.assign || function __assign(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; - -function __awaiter(thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -} - -function __generator(thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -} - -function __spreadArray(to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || from); -} - -var Bounds = /** @class */ (function () { - function Bounds(left, top, width, height) { - this.left = left; - this.top = top; - this.width = width; - this.height = height; - } - Bounds.prototype.add = function (x, y, w, h) { - return new Bounds(this.left + x, this.top + y, this.width + w, this.height + h); - }; - Bounds.fromClientRect = function (context, clientRect) { - return new Bounds(clientRect.left + context.windowBounds.left, clientRect.top + context.windowBounds.top, clientRect.width, clientRect.height); - }; - Bounds.fromDOMRectList = function (context, domRectList) { - var domRect = Array.from(domRectList).find(function (rect) { return rect.width !== 0; }); - return domRect - ? new Bounds(domRect.left + context.windowBounds.left, domRect.top + context.windowBounds.top, domRect.width, domRect.height) - : Bounds.EMPTY; - }; - Bounds.EMPTY = new Bounds(0, 0, 0, 0); - return Bounds; -}()); -var parseBounds = function (context, node) { - return Bounds.fromClientRect(context, node.getBoundingClientRect()); -}; -var parseDocumentSize = function (document) { - var body = document.body; - var documentElement = document.documentElement; - if (!body || !documentElement) { - throw new Error("Unable to get document size"); - } - var width = Math.max(Math.max(body.scrollWidth, documentElement.scrollWidth), Math.max(body.offsetWidth, documentElement.offsetWidth), Math.max(body.clientWidth, documentElement.clientWidth)); - var height = Math.max(Math.max(body.scrollHeight, documentElement.scrollHeight), Math.max(body.offsetHeight, documentElement.offsetHeight), Math.max(body.clientHeight, documentElement.clientHeight)); - return new Bounds(0, 0, width, height); -}; - -/* - * css-line-break 2.1.0 - * Copyright (c) 2022 Niklas von Hertzen - * Released under MIT License - */ -var toCodePoints$1 = function (str) { - var codePoints = []; - var i = 0; - var length = str.length; - while (i < length) { - var value = str.charCodeAt(i++); - if (value >= 0xd800 && value <= 0xdbff && i < length) { - var extra = str.charCodeAt(i++); - if ((extra & 0xfc00) === 0xdc00) { - codePoints.push(((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000); - } - else { - codePoints.push(value); - i--; - } - } - else { - codePoints.push(value); - } - } - return codePoints; -}; -var fromCodePoint$1 = function () { - var codePoints = []; - for (var _i = 0; _i < arguments.length; _i++) { - codePoints[_i] = arguments[_i]; - } - if (String.fromCodePoint) { - return String.fromCodePoint.apply(String, codePoints); - } - var length = codePoints.length; - if (!length) { - return ''; - } - var codeUnits = []; - var index = -1; - var result = ''; - while (++index < length) { - var codePoint = codePoints[index]; - if (codePoint <= 0xffff) { - codeUnits.push(codePoint); - } - else { - codePoint -= 0x10000; - codeUnits.push((codePoint >> 10) + 0xd800, (codePoint % 0x400) + 0xdc00); - } - if (index + 1 === length || codeUnits.length > 0x4000) { - result += String.fromCharCode.apply(String, codeUnits); - codeUnits.length = 0; - } - } - return result; -}; -var chars$2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; -// Use a lookup table to find the index. -var lookup$2 = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256); -for (var i$2 = 0; i$2 < chars$2.length; i$2++) { - lookup$2[chars$2.charCodeAt(i$2)] = i$2; -} - -/* - * utrie 1.0.2 - * Copyright (c) 2022 Niklas von Hertzen - * Released under MIT License - */ -var chars$1$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; -// Use a lookup table to find the index. -var lookup$1$1 = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256); -for (var i$1$1 = 0; i$1$1 < chars$1$1.length; i$1$1++) { - lookup$1$1[chars$1$1.charCodeAt(i$1$1)] = i$1$1; -} -var decode$1 = function (base64) { - var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4; - if (base64[base64.length - 1] === '=') { - bufferLength--; - if (base64[base64.length - 2] === '=') { - bufferLength--; - } - } - var buffer = typeof ArrayBuffer !== 'undefined' && - typeof Uint8Array !== 'undefined' && - typeof Uint8Array.prototype.slice !== 'undefined' - ? new ArrayBuffer(bufferLength) - : new Array(bufferLength); - var bytes = Array.isArray(buffer) ? buffer : new Uint8Array(buffer); - for (i = 0; i < len; i += 4) { - encoded1 = lookup$1$1[base64.charCodeAt(i)]; - encoded2 = lookup$1$1[base64.charCodeAt(i + 1)]; - encoded3 = lookup$1$1[base64.charCodeAt(i + 2)]; - encoded4 = lookup$1$1[base64.charCodeAt(i + 3)]; - bytes[p++] = (encoded1 << 2) | (encoded2 >> 4); - bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2); - bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63); - } - return buffer; -}; -var polyUint16Array$1 = function (buffer) { - var length = buffer.length; - var bytes = []; - for (var i = 0; i < length; i += 2) { - bytes.push((buffer[i + 1] << 8) | buffer[i]); - } - return bytes; -}; -var polyUint32Array$1 = function (buffer) { - var length = buffer.length; - var bytes = []; - for (var i = 0; i < length; i += 4) { - bytes.push((buffer[i + 3] << 24) | (buffer[i + 2] << 16) | (buffer[i + 1] << 8) | buffer[i]); - } - return bytes; -}; - -/** Shift size for getting the index-2 table offset. */ -var UTRIE2_SHIFT_2$1 = 5; -/** Shift size for getting the index-1 table offset. */ -var UTRIE2_SHIFT_1$1 = 6 + 5; -/** - * Shift size for shifting left the index array values. - * Increases possible data size with 16-bit index values at the cost - * of compactability. - * This requires data blocks to be aligned by UTRIE2_DATA_GRANULARITY. - */ -var UTRIE2_INDEX_SHIFT$1 = 2; -/** - * Difference between the two shift sizes, - * for getting an index-1 offset from an index-2 offset. 6=11-5 - */ -var UTRIE2_SHIFT_1_2$1 = UTRIE2_SHIFT_1$1 - UTRIE2_SHIFT_2$1; -/** - * The part of the index-2 table for U+D800..U+DBFF stores values for - * lead surrogate code _units_ not code _points_. - * Values for lead surrogate code _points_ are indexed with this portion of the table. - * Length=32=0x20=0x400>>UTRIE2_SHIFT_2. (There are 1024=0x400 lead surrogates.) - */ -var UTRIE2_LSCP_INDEX_2_OFFSET$1 = 0x10000 >> UTRIE2_SHIFT_2$1; -/** Number of entries in a data block. 32=0x20 */ -var UTRIE2_DATA_BLOCK_LENGTH$1 = 1 << UTRIE2_SHIFT_2$1; -/** Mask for getting the lower bits for the in-data-block offset. */ -var UTRIE2_DATA_MASK$1 = UTRIE2_DATA_BLOCK_LENGTH$1 - 1; -var UTRIE2_LSCP_INDEX_2_LENGTH$1 = 0x400 >> UTRIE2_SHIFT_2$1; -/** Count the lengths of both BMP pieces. 2080=0x820 */ -var UTRIE2_INDEX_2_BMP_LENGTH$1 = UTRIE2_LSCP_INDEX_2_OFFSET$1 + UTRIE2_LSCP_INDEX_2_LENGTH$1; -/** - * The 2-byte UTF-8 version of the index-2 table follows at offset 2080=0x820. - * Length 32=0x20 for lead bytes C0..DF, regardless of UTRIE2_SHIFT_2. - */ -var UTRIE2_UTF8_2B_INDEX_2_OFFSET$1 = UTRIE2_INDEX_2_BMP_LENGTH$1; -var UTRIE2_UTF8_2B_INDEX_2_LENGTH$1 = 0x800 >> 6; /* U+0800 is the first code point after 2-byte UTF-8 */ -/** - * The index-1 table, only used for supplementary code points, at offset 2112=0x840. - * Variable length, for code points up to highStart, where the last single-value range starts. - * Maximum length 512=0x200=0x100000>>UTRIE2_SHIFT_1. - * (For 0x100000 supplementary code points U+10000..U+10ffff.) - * - * The part of the index-2 table for supplementary code points starts - * after this index-1 table. - * - * Both the index-1 table and the following part of the index-2 table - * are omitted completely if there is only BMP data. - */ -var UTRIE2_INDEX_1_OFFSET$1 = UTRIE2_UTF8_2B_INDEX_2_OFFSET$1 + UTRIE2_UTF8_2B_INDEX_2_LENGTH$1; -/** - * Number of index-1 entries for the BMP. 32=0x20 - * This part of the index-1 table is omitted from the serialized form. - */ -var UTRIE2_OMITTED_BMP_INDEX_1_LENGTH$1 = 0x10000 >> UTRIE2_SHIFT_1$1; -/** Number of entries in an index-2 block. 64=0x40 */ -var UTRIE2_INDEX_2_BLOCK_LENGTH$1 = 1 << UTRIE2_SHIFT_1_2$1; -/** Mask for getting the lower bits for the in-index-2-block offset. */ -var UTRIE2_INDEX_2_MASK$1 = UTRIE2_INDEX_2_BLOCK_LENGTH$1 - 1; -var slice16$1 = function (view, start, end) { - if (view.slice) { - return view.slice(start, end); - } - return new Uint16Array(Array.prototype.slice.call(view, start, end)); -}; -var slice32$1 = function (view, start, end) { - if (view.slice) { - return view.slice(start, end); - } - return new Uint32Array(Array.prototype.slice.call(view, start, end)); -}; -var createTrieFromBase64$1 = function (base64, _byteLength) { - var buffer = decode$1(base64); - var view32 = Array.isArray(buffer) ? polyUint32Array$1(buffer) : new Uint32Array(buffer); - var view16 = Array.isArray(buffer) ? polyUint16Array$1(buffer) : new Uint16Array(buffer); - var headerLength = 24; - var index = slice16$1(view16, headerLength / 2, view32[4] / 2); - var data = view32[5] === 2 - ? slice16$1(view16, (headerLength + view32[4]) / 2) - : slice32$1(view32, Math.ceil((headerLength + view32[4]) / 4)); - return new Trie$1(view32[0], view32[1], view32[2], view32[3], index, data); -}; -var Trie$1 = /** @class */ (function () { - function Trie(initialValue, errorValue, highStart, highValueIndex, index, data) { - this.initialValue = initialValue; - this.errorValue = errorValue; - this.highStart = highStart; - this.highValueIndex = highValueIndex; - this.index = index; - this.data = data; - } - /** - * Get the value for a code point as stored in the Trie. - * - * @param codePoint the code point - * @return the value - */ - Trie.prototype.get = function (codePoint) { - var ix; - if (codePoint >= 0) { - if (codePoint < 0x0d800 || (codePoint > 0x0dbff && codePoint <= 0x0ffff)) { - // Ordinary BMP code point, excluding leading surrogates. - // BMP uses a single level lookup. BMP index starts at offset 0 in the Trie2 index. - // 16 bit data is stored in the index array itself. - ix = this.index[codePoint >> UTRIE2_SHIFT_2$1]; - ix = (ix << UTRIE2_INDEX_SHIFT$1) + (codePoint & UTRIE2_DATA_MASK$1); - return this.data[ix]; - } - if (codePoint <= 0xffff) { - // Lead Surrogate Code Point. A Separate index section is stored for - // lead surrogate code units and code points. - // The main index has the code unit data. - // For this function, we need the code point data. - // Note: this expression could be refactored for slightly improved efficiency, but - // surrogate code points will be so rare in practice that it's not worth it. - ix = this.index[UTRIE2_LSCP_INDEX_2_OFFSET$1 + ((codePoint - 0xd800) >> UTRIE2_SHIFT_2$1)]; - ix = (ix << UTRIE2_INDEX_SHIFT$1) + (codePoint & UTRIE2_DATA_MASK$1); - return this.data[ix]; - } - if (codePoint < this.highStart) { - // Supplemental code point, use two-level lookup. - ix = UTRIE2_INDEX_1_OFFSET$1 - UTRIE2_OMITTED_BMP_INDEX_1_LENGTH$1 + (codePoint >> UTRIE2_SHIFT_1$1); - ix = this.index[ix]; - ix += (codePoint >> UTRIE2_SHIFT_2$1) & UTRIE2_INDEX_2_MASK$1; - ix = this.index[ix]; - ix = (ix << UTRIE2_INDEX_SHIFT$1) + (codePoint & UTRIE2_DATA_MASK$1); - return this.data[ix]; - } - if (codePoint <= 0x10ffff) { - return this.data[this.highValueIndex]; - } - } - // Fall through. The code point is outside of the legal range of 0..0x10ffff. - return this.errorValue; - }; - return Trie; -}()); - -/* - * base64-arraybuffer 1.0.2 - * Copyright (c) 2022 Niklas von Hertzen - * Released under MIT License - */ -var chars$3 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; -// Use a lookup table to find the index. -var lookup$3 = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256); -for (var i$3 = 0; i$3 < chars$3.length; i$3++) { - lookup$3[chars$3.charCodeAt(i$3)] = i$3; -} - -var base64$1 = 'KwAAAAAAAAAACA4AUD0AADAgAAACAAAAAAAIABAAGABAAEgAUABYAGAAaABgAGgAYgBqAF8AZwBgAGgAcQB5AHUAfQCFAI0AlQCdAKIAqgCyALoAYABoAGAAaABgAGgAwgDKAGAAaADGAM4A0wDbAOEA6QDxAPkAAQEJAQ8BFwF1AH0AHAEkASwBNAE6AUIBQQFJAVEBWQFhAWgBcAF4ATAAgAGGAY4BlQGXAZ8BpwGvAbUBvQHFAc0B0wHbAeMB6wHxAfkBAQIJAvEBEQIZAiECKQIxAjgCQAJGAk4CVgJeAmQCbAJ0AnwCgQKJApECmQKgAqgCsAK4ArwCxAIwAMwC0wLbAjAA4wLrAvMC+AIAAwcDDwMwABcDHQMlAy0DNQN1AD0DQQNJA0kDSQNRA1EDVwNZA1kDdQB1AGEDdQBpA20DdQN1AHsDdQCBA4kDkQN1AHUAmQOhA3UAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AKYDrgN1AHUAtgO+A8YDzgPWAxcD3gPjA+sD8wN1AHUA+wMDBAkEdQANBBUEHQQlBCoEFwMyBDgEYABABBcDSARQBFgEYARoBDAAcAQzAXgEgASIBJAEdQCXBHUAnwSnBK4EtgS6BMIEyAR1AHUAdQB1AHUAdQCVANAEYABgAGAAYABgAGAAYABgANgEYADcBOQEYADsBPQE/AQEBQwFFAUcBSQFLAU0BWQEPAVEBUsFUwVbBWAAYgVgAGoFcgV6BYIFigWRBWAAmQWfBaYFYABgAGAAYABgAKoFYACxBbAFuQW6BcEFwQXHBcEFwQXPBdMF2wXjBeoF8gX6BQIGCgYSBhoGIgYqBjIGOgZgAD4GRgZMBmAAUwZaBmAAYABgAGAAYABgAGAAYABgAGAAYABgAGIGYABpBnAGYABgAGAAYABgAGAAYABgAGAAYAB4Bn8GhQZgAGAAYAB1AHcDFQSLBmAAYABgAJMGdQA9A3UAmwajBqsGqwaVALMGuwbDBjAAywbSBtIG1QbSBtIG0gbSBtIG0gbdBuMG6wbzBvsGAwcLBxMHAwcbByMHJwcsBywHMQcsB9IGOAdAB0gHTgfSBkgHVgfSBtIG0gbSBtIG0gbSBtIG0gbSBiwHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAdgAGAALAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAdbB2MHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsB2kH0gZwB64EdQB1AHUAdQB1AHUAdQB1AHUHfQdgAIUHjQd1AHUAlQedB2AAYAClB6sHYACzB7YHvgfGB3UAzgfWBzMB3gfmB1EB7gf1B/0HlQENAQUIDQh1ABUIHQglCBcDLQg1CD0IRQhNCEEDUwh1AHUAdQBbCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIaQhjCGQIZQhmCGcIaAhpCGMIZAhlCGYIZwhoCGkIYwhkCGUIZghnCGgIcAh3CHoIMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwAIIIggiCCIIIggiCCIIIggiCCIIIggiCCIIIggiCCIIIggiCCIIIggiCCIIIggiCCIIIggiCCIIIggiCCIIIgggwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAALAcsBywHLAcsBywHLAcsBywHLAcsB4oILAcsB44I0gaWCJ4Ipgh1AHUAqgiyCHUAdQB1AHUAdQB1AHUAdQB1AHUAtwh8AXUAvwh1AMUIyQjRCNkI4AjoCHUAdQB1AO4I9gj+CAYJDgkTCS0HGwkjCYIIggiCCIIIggiCCIIIggiCCIIIggiCCIIIggiCCIIIggiCCIIIggiCCIIIggiCCIIIggiCCIIIggiCCIIIggiAAIAAAAFAAYABgAGIAXwBgAHEAdQBFAJUAogCyAKAAYABgAEIA4ABGANMA4QDxAMEBDwE1AFwBLAE6AQEBUQF4QkhCmEKoQrhCgAHIQsAB0MLAAcABwAHAAeDC6ABoAHDCwMMAAcABwAHAAdDDGMMAAcAB6MM4wwjDWMNow3jDaABoAGgAaABoAGgAaABoAGgAaABoAGgAaABoAGgAaABoAGgAaABoAEjDqABWw6bDqABpg6gAaABoAHcDvwOPA+gAaABfA/8DvwO/A78DvwO/A78DvwO/A78DvwO/A78DvwO/A78DvwO/A78DvwO/A78DvwO/A78DvwO/A78DpcPAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcAB9cPKwkyCToJMAB1AHUAdQBCCUoJTQl1AFUJXAljCWcJawkwADAAMAAwAHMJdQB2CX4JdQCECYoJjgmWCXUAngkwAGAAYABxAHUApgn3A64JtAl1ALkJdQDACTAAMAAwADAAdQB1AHUAdQB1AHUAdQB1AHUAowYNBMUIMAAwADAAMADICcsJ0wnZCRUE4QkwAOkJ8An4CTAAMAB1AAAKvwh1AAgKDwoXCh8KdQAwACcKLgp1ADYKqAmICT4KRgowADAAdQB1AE4KMAB1AFYKdQBeCnUAZQowADAAMAAwADAAMAAwADAAMAAVBHUAbQowADAAdQC5CXUKMAAwAHwBxAijBogEMgF9CoQKiASMCpQKmgqIBKIKqgquCogEDQG2Cr4KxgrLCjAAMADTCtsKCgHjCusK8Qr5CgELMAAwADAAMAB1AIsECQsRC3UANAEZCzAAMAAwADAAMAB1ACELKQswAHUANAExCzkLdQBBC0kLMABRC1kLMAAwADAAMAAwADAAdQBhCzAAMAAwAGAAYABpC3ELdwt/CzAAMACHC4sLkwubC58Lpwt1AK4Ltgt1APsDMAAwADAAMAAwADAAMAAwAL4LwwvLC9IL1wvdCzAAMADlC+kL8Qv5C/8LSQswADAAMAAwADAAMAAwADAAMAAHDDAAMAAwADAAMAAODBYMHgx1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1ACYMMAAwADAAdQB1AHUALgx1AHUAdQB1AHUAdQA2DDAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwAHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AD4MdQBGDHUAdQB1AHUAdQB1AEkMdQB1AHUAdQB1AFAMMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwAHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQBYDHUAdQB1AF8MMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAB1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AHUA+wMVBGcMMAAwAHwBbwx1AHcMfwyHDI8MMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAYABgAJcMMAAwADAAdQB1AJ8MlQClDDAAMACtDCwHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsB7UMLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHdQB1AHUAdQB1AHUAdQB1AHUAdQB1AHUAdQB1AA0EMAC9DDAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAsBywHLAcsBywHLAcsBywHLQcwAMEMyAwsBywHLAcsBywHLAcsBywHLAcsBywHzAwwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwAHUAdQB1ANQM2QzhDDAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMABgAGAAYABgAGAAYABgAOkMYADxDGAA+AwADQYNYABhCWAAYAAODTAAMAAwADAAFg1gAGAAHg37AzAAMAAwADAAYABgACYNYAAsDTQNPA1gAEMNPg1LDWAAYABgAGAAYABgAGAAYABgAGAAUg1aDYsGVglhDV0NcQBnDW0NdQ15DWAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAlQCBDZUAiA2PDZcNMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAnw2nDTAAMAAwADAAMAAwAHUArw23DTAAMAAwADAAMAAwADAAMAAwADAAMAB1AL8NMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAB1AHUAdQB1AHUAdQDHDTAAYABgAM8NMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAA1w11ANwNMAAwAD0B5A0wADAAMAAwADAAMADsDfQN/A0EDgwOFA4wABsOMAAwADAAMAAwADAAMAAwANIG0gbSBtIG0gbSBtIG0gYjDigOwQUuDsEFMw7SBjoO0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIGQg5KDlIOVg7SBtIGXg5lDm0OdQ7SBtIGfQ6EDooOjQ6UDtIGmg6hDtIG0gaoDqwO0ga0DrwO0gZgAGAAYADEDmAAYAAkBtIGzA5gANIOYADaDokO0gbSBt8O5w7SBu8O0gb1DvwO0gZgAGAAxA7SBtIG0gbSBtIGYABgAGAAYAAED2AAsAUMD9IG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIGFA8sBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAccD9IGLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHJA8sBywHLAcsBywHLAccDywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywPLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAc0D9IG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIGLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAccD9IG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIGFA8sBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHLAcsBywHPA/SBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gbSBtIG0gYUD0QPlQCVAJUAMAAwADAAMACVAJUAlQCVAJUAlQCVAEwPMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAA//8EAAQABAAEAAQABAAEAAQABAANAAMAAQABAAIABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQACgATABcAHgAbABoAHgAXABYAEgAeABsAGAAPABgAHABLAEsASwBLAEsASwBLAEsASwBLABgAGAAeAB4AHgATAB4AUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQABYAGwASAB4AHgAeAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAWAA0AEQAeAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAAQABAAEAAQABAAFAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAJABYAGgAbABsAGwAeAB0AHQAeAE8AFwAeAA0AHgAeABoAGwBPAE8ADgBQAB0AHQAdAE8ATwAXAE8ATwBPABYAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAB0AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAdAFAAUABQAFAAUABQAFAAUAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAFAAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAeAB4AHgAeAFAATwBAAE8ATwBPAEAATwBQAFAATwBQAB4AHgAeAB4AHgAeAB0AHQAdAB0AHgAdAB4ADgBQAFAAUABQAFAAHgAeAB4AHgAeAB4AHgBQAB4AUAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4ABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAJAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAkACQAJAAkACQAJAAkABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAeAB4AHgAeAFAAHgAeAB4AKwArAFAAUABQAFAAGABQACsAKwArACsAHgAeAFAAHgBQAFAAUAArAFAAKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4ABAAEAAQABAAEAAQABAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAUAAeAB4AHgAeAB4AHgBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAYAA0AKwArAB4AHgAbACsABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQADQAEAB4ABAAEAB4ABAAEABMABAArACsAKwArACsAKwArACsAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAKwArACsAKwBWAFYAVgBWAB4AHgArACsAKwArACsAKwArACsAKwArACsAHgAeAB4AHgAeAB4AHgAeAB4AGgAaABoAGAAYAB4AHgAEAAQABAAEAAQABAAEAAQABAAEAAQAEwAEACsAEwATAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABABLAEsASwBLAEsASwBLAEsASwBLABoAGQAZAB4AUABQAAQAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQABMAUAAEAAQABAAEAAQABAAEAB4AHgAEAAQABAAEAAQABABQAFAABAAEAB4ABAAEAAQABABQAFAASwBLAEsASwBLAEsASwBLAEsASwBQAFAAUAAeAB4AUAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwAeAFAABABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAAEAAQABAAEAFAAKwArACsAKwArACsAKwArACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAAEAAQAUABQAB4AHgAYABMAUAArACsABAAbABsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAFAABAAEAAQABAAEAFAABAAEAAQAUAAEAAQABAAEAAQAKwArAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAArACsAHgArAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwArACsAKwArAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAB4ABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAEAFAABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAUAAEAAQABAAEAAQABAAEAFAAUABQAFAAUABQAFAAUABQAFAABAAEAA0ADQBLAEsASwBLAEsASwBLAEsASwBLAB4AUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAArAFAAUABQAFAAUABQAFAAUAArACsAUABQACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQACsAUAArACsAKwBQAFAAUABQACsAKwAEAFAABAAEAAQABAAEAAQABAArACsABAAEACsAKwAEAAQABABQACsAKwArACsAKwArACsAKwAEACsAKwArACsAUABQACsAUABQAFAABAAEACsAKwBLAEsASwBLAEsASwBLAEsASwBLAFAAUAAaABoAUABQAFAAUABQAEwAHgAbAFAAHgAEACsAKwAEAAQABAArAFAAUABQAFAAUABQACsAKwArACsAUABQACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQACsAUABQACsAUABQACsAUABQACsAKwAEACsABAAEAAQABAAEACsAKwArACsABAAEACsAKwAEAAQABAArACsAKwAEACsAKwArACsAKwArACsAUABQAFAAUAArAFAAKwArACsAKwArACsAKwBLAEsASwBLAEsASwBLAEsASwBLAAQABABQAFAAUAAEAB4AKwArACsAKwArACsAKwArACsAKwAEAAQABAArAFAAUABQAFAAUABQAFAAUABQACsAUABQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQACsAUABQACsAUABQAFAAUABQACsAKwAEAFAABAAEAAQABAAEAAQABAAEACsABAAEAAQAKwAEAAQABAArACsAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQAFAABAAEACsAKwBLAEsASwBLAEsASwBLAEsASwBLAB4AGwArACsAKwArACsAKwArAFAABAAEAAQABAAEAAQAKwAEAAQABAArAFAAUABQAFAAUABQAFAAUAArACsAUABQACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAEAAQABAArACsABAAEACsAKwAEAAQABAArACsAKwArACsAKwArAAQABAAEACsAKwArACsAUABQACsAUABQAFAABAAEACsAKwBLAEsASwBLAEsASwBLAEsASwBLAB4AUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArAAQAUAArAFAAUABQAFAAUABQACsAKwArAFAAUABQACsAUABQAFAAUAArACsAKwBQAFAAKwBQACsAUABQACsAKwArAFAAUAArACsAKwBQAFAAUAArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArAAQABAAEAAQABAArACsAKwAEAAQABAArAAQABAAEAAQAKwArAFAAKwArACsAKwArACsABAArACsAKwArACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAUABQAFAAHgAeAB4AHgAeAB4AGwAeACsAKwArACsAKwAEAAQABAAEAAQAUABQAFAAUABQAFAAUABQACsAUABQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAUAAEAAQABAAEAAQABAAEACsABAAEAAQAKwAEAAQABAAEACsAKwArACsAKwArACsABAAEACsAUABQAFAAKwArACsAKwArAFAAUAAEAAQAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsAKwAOAFAAUABQAFAAUABQAFAAHgBQAAQABAAEAA4AUABQAFAAUABQAFAAUABQACsAUABQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAKwArAAQAUAAEAAQABAAEAAQABAAEACsABAAEAAQAKwAEAAQABAAEACsAKwArACsAKwArACsABAAEACsAKwArACsAKwArACsAUAArAFAAUAAEAAQAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwBQAFAAKwArACsAKwArACsAKwArACsAKwArACsAKwAEAAQABAAEAFAAUABQAFAAUABQAFAAUABQACsAUABQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAFAABAAEAAQABAAEAAQABAArAAQABAAEACsABAAEAAQABABQAB4AKwArACsAKwBQAFAAUAAEAFAAUABQAFAAUABQAFAAUABQAFAABAAEACsAKwBLAEsASwBLAEsASwBLAEsASwBLAFAAUABQAFAAUABQAFAAUABQABoAUABQAFAAUABQAFAAKwAEAAQABAArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAUABQACsAUAArACsAUABQAFAAUABQAFAAUAArACsAKwAEACsAKwArACsABAAEAAQABAAEAAQAKwAEACsABAAEAAQABAAEAAQABAAEACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArAAQABAAeACsAKwArACsAKwArACsAKwArACsAKwArAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXAAqAFwAXAAqACoAKgAqACoAKgAqACsAKwArACsAGwBcAFwAXABcAFwAXABcACoAKgAqACoAKgAqACoAKgAeAEsASwBLAEsASwBLAEsASwBLAEsADQANACsAKwArACsAKwBcAFwAKwBcACsAXABcAFwAXABcACsAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcACsAXAArAFwAXABcAFwAXABcAFwAXABcAFwAKgBcAFwAKgAqACoAKgAqACoAKgAqACoAXAArACsAXABcAFwAXABcACsAXAArACoAKgAqACoAKgAqACsAKwBLAEsASwBLAEsASwBLAEsASwBLACsAKwBcAFwAXABcAFAADgAOAA4ADgAeAA4ADgAJAA4ADgANAAkAEwATABMAEwATAAkAHgATAB4AHgAeAAQABAAeAB4AHgAeAB4AHgBLAEsASwBLAEsASwBLAEsASwBLAFAAUABQAFAAUABQAFAAUABQAFAADQAEAB4ABAAeAAQAFgARABYAEQAEAAQAUABQAFAAUABQAFAAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQADQAEAAQABAAEAAQADQAEAAQAUABQAFAAUABQAAQABAAEAAQABAAEAAQABAAEAAQABAArAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAArAA0ADQAeAB4AHgAeAB4AHgAEAB4AHgAeAB4AHgAeACsAHgAeAA4ADgANAA4AHgAeAB4AHgAeAAkACQArACsAKwArACsAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgBcAEsASwBLAEsASwBLAEsASwBLAEsADQANAB4AHgAeAB4AXABcAFwAXABcAFwAKgAqACoAKgBcAFwAXABcACoAKgAqAFwAKgAqACoAXABcACoAKgAqACoAKgAqACoAXABcAFwAKgAqACoAKgBcAFwAXABcAFwAXABcAFwAXABcAFwAXABcACoAKgAqACoAKgAqACoAKgAqACoAKgAqAFwAKgBLAEsASwBLAEsASwBLAEsASwBLACoAKgAqACoAKgAqAFAAUABQAFAAUABQACsAUAArACsAKwArACsAUAArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAHgBQAFAAUABQAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFAAUABQAFAAUABQAFAAUABQACsAUABQAFAAUAArACsAUABQAFAAUABQAFAAUAArAFAAKwBQAFAAUABQACsAKwBQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAKwArAFAAUABQAFAAUABQAFAAKwBQACsAUABQAFAAUAArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAUABQACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsABAAEAAQAHgANAB4AHgAeAB4AHgAeAB4AUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAHgAeAB4AHgAeAB4AHgAeAB4AHgArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwBQAFAAUABQAFAAUAArACsADQBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAHgAeAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAANAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAWABEAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAA0ADQANAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAAQABAAEACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAANAA0AKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEACsAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAUAArAAQABAArACsAKwArACsAKwArACsAKwArACsAKwBcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqAA0ADQAVAFwADQAeAA0AGwBcACoAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwAeAB4AEwATAA0ADQAOAB4AEwATAB4ABAAEAAQACQArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArAFAAUABQAFAAUAAEAAQAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQAUAArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwAEAAQABAAEAAQABAAEAAQABAAEAAQABAArACsAKwArAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsAKwArACsAHgArACsAKwATABMASwBLAEsASwBLAEsASwBLAEsASwBcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXAArACsAXABcAFwAXABcACsAKwArACsAKwArACsAKwArACsAKwBcAFwAXABcAFwAXABcAFwAXABcAFwAXAArACsAKwArAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAXAArACsAKwAqACoAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAEAAQABAArACsAHgAeAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcACoAKgAqACoAKgAqACoAKgAqACoAKwAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKwArAAQASwBLAEsASwBLAEsASwBLAEsASwArACsAKwArACsAKwBLAEsASwBLAEsASwBLAEsASwBLACsAKwArACsAKwArACoAKgAqACoAKgAqACoAXAAqACoAKgAqACoAKgArACsABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsABAAEAAQABAAEAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAEAAQABABQAFAAUABQAFAAUABQACsAKwArACsASwBLAEsASwBLAEsASwBLAEsASwANAA0AHgANAA0ADQANAB4AHgAeAB4AHgAeAB4AHgAeAB4ABAAEAAQABAAEAAQABAAEAAQAHgAeAB4AHgAeAB4AHgAeAB4AKwArACsABAAEAAQAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAAEAAQABAAEAAQABABQAFAASwBLAEsASwBLAEsASwBLAEsASwBQAFAAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsAKwArACsAKwArACsAKwAeAB4AHgAeAFAAUABQAFAABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsAKwArAA0ADQANAA0ADQBLAEsASwBLAEsASwBLAEsASwBLACsAKwArAFAAUABQAEsASwBLAEsASwBLAEsASwBLAEsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAA0ADQBQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwBQAFAAUAAeAB4AHgAeAB4AHgAeAB4AKwArACsAKwArACsAKwArAAQABAAEAB4ABAAEAAQABAAEAAQABAAEAAQABAAEAAQABABQAFAAUABQAAQAUABQAFAAUABQAFAABABQAFAABAAEAAQAUAArACsAKwArACsABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsABAAEAAQABAAEAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwArAFAAUABQAFAAUABQACsAKwBQAFAAUABQAFAAUABQAFAAKwBQACsAUAArAFAAKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeACsAKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArAB4AHgAeAB4AHgAeAB4AHgBQAB4AHgAeAFAAUABQACsAHgAeAB4AHgAeAB4AHgAeAB4AHgBQAFAAUABQACsAKwAeAB4AHgAeAB4AHgArAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwArAFAAUABQACsAHgAeAB4AHgAeAB4AHgAOAB4AKwANAA0ADQANAA0ADQANAAkADQANAA0ACAAEAAsABAAEAA0ACQANAA0ADAAdAB0AHgAXABcAFgAXABcAFwAWABcAHQAdAB4AHgAUABQAFAANAAEAAQAEAAQABAAEAAQACQAaABoAGgAaABoAGgAaABoAHgAXABcAHQAVABUAHgAeAB4AHgAeAB4AGAAWABEAFQAVABUAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4ADQAeAA0ADQANAA0AHgANAA0ADQAHAB4AHgAeAB4AKwAEAAQABAAEAAQABAAEAAQABAAEAFAAUAArACsATwBQAFAAUABQAFAAHgAeAB4AFgARAE8AUABPAE8ATwBPAFAAUABQAFAAUAAeAB4AHgAWABEAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArABsAGwAbABsAGwAbABsAGgAbABsAGwAbABsAGwAbABsAGwAbABsAGwAbABsAGgAbABsAGwAbABoAGwAbABoAGwAbABsAGwAbABsAGwAbABsAGwAbABsAGwAbABsAGwAbAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAHgAeAFAAGgAeAB0AHgBQAB4AGgAeAB4AHgAeAB4AHgAeAB4AHgBPAB4AUAAbAB4AHgBQAFAAUABQAFAAHgAeAB4AHQAdAB4AUAAeAFAAHgBQAB4AUABPAFAAUAAeAB4AHgAeAB4AHgAeAFAAUABQAFAAUAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAFAAHgBQAFAAUABQAE8ATwBQAFAAUABQAFAATwBQAFAATwBQAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAFAAUABQAFAATwBPAE8ATwBPAE8ATwBPAE8ATwBQAFAAUABQAFAAUABQAFAAUAAeAB4AUABQAFAAUABPAB4AHgArACsAKwArAB0AHQAdAB0AHQAdAB0AHQAdAB0AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB0AHgAdAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAdAB4AHQAdAB4AHgAeAB0AHQAeAB4AHQAeAB4AHgAdAB4AHQAbABsAHgAdAB4AHgAeAB4AHQAeAB4AHQAdAB0AHQAeAB4AHQAeAB0AHgAdAB0AHQAdAB0AHQAeAB0AHgAeAB4AHgAeAB0AHQAdAB0AHgAeAB4AHgAdAB0AHgAeAB4AHgAeAB4AHgAeAB4AHgAdAB4AHgAeAB0AHgAeAB4AHgAeAB0AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAdAB0AHgAeAB0AHQAdAB0AHgAeAB0AHQAeAB4AHQAdAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB0AHQAeAB4AHQAdAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHQAeAB4AHgAdAB4AHgAeAB4AHgAeAB4AHQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB0AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AFAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeABYAEQAWABEAHgAeAB4AHgAeAB4AHQAeAB4AHgAeAB4AHgAeACUAJQAeAB4AHgAeAB4AHgAeAB4AHgAWABEAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AJQAlACUAJQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAFAAHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHgAeAB4AHgAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAeAB4AHQAdAB0AHQAeAB4AHgAeAB4AHgAeAB4AHgAeAB0AHQAeAB0AHQAdAB0AHQAdAB0AHgAeAB4AHgAeAB4AHgAeAB0AHQAeAB4AHQAdAB4AHgAeAB4AHQAdAB4AHgAeAB4AHQAdAB0AHgAeAB0AHgAeAB0AHQAdAB0AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAdAB0AHQAdAB4AHgAeAB4AHgAeAB4AHgAeAB0AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAlACUAJQAlAB4AHQAdAB4AHgAdAB4AHgAeAB4AHQAdAB4AHgAeAB4AJQAlAB0AHQAlAB4AJQAlACUAIAAlACUAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAlACUAJQAeAB4AHgAeAB0AHgAdAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAdAB0AHgAdAB0AHQAeAB0AJQAdAB0AHgAdAB0AHgAdAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeACUAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHQAdAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAlACUAJQAlACUAJQAlACUAJQAlACUAJQAdAB0AHQAdACUAHgAlACUAJQAdACUAJQAdAB0AHQAlACUAHQAdACUAHQAdACUAJQAlAB4AHQAeAB4AHgAeAB0AHQAlAB0AHQAdAB0AHQAdACUAJQAlACUAJQAdACUAJQAgACUAHQAdACUAJQAlACUAJQAlACUAJQAeAB4AHgAlACUAIAAgACAAIAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB0AHgAeAB4AFwAXABcAFwAXABcAHgATABMAJQAeAB4AHgAWABEAFgARABYAEQAWABEAFgARABYAEQAWABEATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeABYAEQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAWABEAFgARABYAEQAWABEAFgARAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AFgARABYAEQAWABEAFgARABYAEQAWABEAFgARABYAEQAWABEAFgARABYAEQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAWABEAFgARAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AFgARAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAdAB0AHQAdAB0AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArACsAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AUABQAFAAUAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAEAAQABAAeAB4AKwArACsAKwArABMADQANAA0AUAATAA0AUABQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAUAANACsAKwArACsAKwArACsAKwArACsAKwArACsAKwAEAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQACsAUABQAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQACsAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXAA0ADQANAA0ADQANAA0ADQAeAA0AFgANAB4AHgAXABcAHgAeABcAFwAWABEAFgARABYAEQAWABEADQANAA0ADQATAFAADQANAB4ADQANAB4AHgAeAB4AHgAMAAwADQANAA0AHgANAA0AFgANAA0ADQANAA0ADQANAA0AHgANAB4ADQANAB4AHgAeACsAKwArACsAKwArACsAKwArACsAKwArACsAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACsAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAKwArACsAKwArACsAKwArACsAKwArACsAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwAlACUAJQAlACUAJQAlACUAJQAlACUAJQArACsAKwArAA0AEQARACUAJQBHAFcAVwAWABEAFgARABYAEQAWABEAFgARACUAJQAWABEAFgARABYAEQAWABEAFQAWABEAEQAlAFcAVwBXAFcAVwBXAFcAVwBXAAQABAAEAAQABAAEACUAVwBXAFcAVwA2ACUAJQBXAFcAVwBHAEcAJQAlACUAKwBRAFcAUQBXAFEAVwBRAFcAUQBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFEAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBRAFcAUQBXAFEAVwBXAFcAVwBXAFcAUQBXAFcAVwBXAFcAVwBRAFEAKwArAAQABAAVABUARwBHAFcAFQBRAFcAUQBXAFEAVwBRAFcAUQBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFEAVwBRAFcAUQBXAFcAVwBXAFcAVwBRAFcAVwBXAFcAVwBXAFEAUQBXAFcAVwBXABUAUQBHAEcAVwArACsAKwArACsAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAKwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAKwAlACUAVwBXAFcAVwAlACUAJQAlACUAJQAlACUAJQAlACsAKwArACsAKwArACsAKwArACsAKwArAFEAUQBRAFEAUQBRAFEAUQBRAFEAUQBRAFEAUQBRAFEAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQArAFcAVwBXAFcAVwBXAFcAVwBXAFcAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQBPAE8ATwBPAE8ATwBPAE8AJQBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXACUAJQAlAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAEcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAKwArACsAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAADQATAA0AUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABLAEsASwBLAEsASwBLAEsASwBLAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAFAABAAEAAQABAAeAAQABAAEAAQABAAEAAQABAAEAAQAHgBQAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AUABQAAQABABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAeAA0ADQANAA0ADQArACsAKwArACsAKwArACsAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAFAAUABQAFAAUABQAFAAUABQAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AUAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgBQAB4AHgAeAB4AHgAeAFAAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArACsAHgAeAB4AHgAeAB4AHgAeAB4AKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwAeAB4AUABQAFAAUABQAFAAUABQAFAAUABQAAQAUABQAFAABABQAFAAUABQAAQAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAEAAQABAAeAB4AHgAeAAQAKwArACsAUABQAFAAUABQAFAAHgAeABoAHgArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAADgAOABMAEwArACsAKwArACsAKwArACsABAAEAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAEAAQABAAEACsAKwArACsAKwArACsAKwANAA0ASwBLAEsASwBLAEsASwBLAEsASwArACsAKwArACsAKwAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABABQAFAAUABQAFAAUAAeAB4AHgBQAA4AUABQAAQAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAAEAA0ADQBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAKwArACsAKwArACsAKwArACsAKwArAB4AWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYAFgAWABYACsAKwArAAQAHgAeAB4AHgAeAB4ADQANAA0AHgAeAB4AHgArAFAASwBLAEsASwBLAEsASwBLAEsASwArACsAKwArAB4AHgBcAFwAXABcAFwAKgBcAFwAXABcAFwAXABcAFwAXABcAEsASwBLAEsASwBLAEsASwBLAEsAXABcAFwAXABcACsAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsAKwArACsAKwArACsAKwArAFAAUABQAAQAUABQAFAAUABQAFAAUABQAAQABAArACsASwBLAEsASwBLAEsASwBLAEsASwArACsAHgANAA0ADQBcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAKgAqACoAXAAqACoAKgBcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXAAqAFwAKgAqACoAXABcACoAKgBcAFwAXABcAFwAKgAqAFwAKgBcACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAFwAXABcACoAKgBQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEAA0ADQBQAFAAUAAEAAQAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUAArACsAUABQAFAAUABQAFAAKwArAFAAUABQAFAAUABQACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAHgAeACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAAQADQAEAAQAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsAVABVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBUAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVAFUAVQBVACsAKwArACsAKwArACsAKwArACsAKwArAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAWQBZAFkAKwArACsAKwBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAWgBaAFoAKwArACsAKwAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYABgAGAAYAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXACUAJQBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAJQAlACUAJQAlACUAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAKwArACsAKwArAFYABABWAFYAVgBWAFYAVgBWAFYAVgBWAB4AVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgArAFYAVgBWAFYAVgArAFYAKwBWAFYAKwBWAFYAKwBWAFYAVgBWAFYAVgBWAFYAVgBWAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAEQAWAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUAAaAB4AKwArAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAGAARABEAGAAYABMAEwAWABEAFAArACsAKwArACsAKwAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACUAJQAlACUAJQAWABEAFgARABYAEQAWABEAFgARABYAEQAlACUAFgARACUAJQAlACUAJQAlACUAEQAlABEAKwAVABUAEwATACUAFgARABYAEQAWABEAJQAlACUAJQAlACUAJQAlACsAJQAbABoAJQArACsAKwArAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArAAcAKwATACUAJQAbABoAJQAlABYAEQAlACUAEQAlABEAJQBXAFcAVwBXAFcAVwBXAFcAVwBXABUAFQAlACUAJQATACUAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXABYAJQARACUAJQAlAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwAWACUAEQAlABYAEQARABYAEQARABUAVwBRAFEAUQBRAFEAUQBRAFEAUQBRAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAEcARwArACsAVwBXAFcAVwBXAFcAKwArAFcAVwBXAFcAVwBXACsAKwBXAFcAVwBXAFcAVwArACsAVwBXAFcAKwArACsAGgAbACUAJQAlABsAGwArAB4AHgAeAB4AHgAeAB4AKwArACsAKwArACsAKwArACsAKwAEAAQABAAQAB0AKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsADQANAA0AKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArAB4AHgAeAB4AHgAeAB4AHgAeAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgBQAFAAHgAeAB4AKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAAQAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwAEAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAA0AUABQAFAAUAArACsAKwArAFAAUABQAFAAUABQAFAAUAANAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAKwArACsAKwAeACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAKwArAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUAArACsAKwBQACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwANAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAeAB4AUABQAFAAUABQAFAAUAArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUAArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArAA0AUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwAeAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAUABQAFAAUABQAAQABAAEACsABAAEACsAKwArACsAKwAEAAQABAAEAFAAUABQAFAAKwBQAFAAUAArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArAAQABAAEACsAKwArACsABABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArAA0ADQANAA0ADQANAA0ADQAeACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAeAFAAUABQAFAAUABQAFAAUAAeAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAArACsAKwArAFAAUABQAFAAUAANAA0ADQANAA0ADQAUACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsADQANAA0ADQANAA0ADQBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArAB4AHgAeAB4AKwArACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArAFAAUABQAFAAUABQAAQABAAEAAQAKwArACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUAArAAQABAANACsAKwBQAFAAKwArACsAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAAQABAAEAAQABAAEAAQABAAEAAQABABQAFAAUABQAB4AHgAeAB4AHgArACsAKwArACsAKwAEAAQABAAEAAQABAAEAA0ADQAeAB4AHgAeAB4AKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsABABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAQABAAEAAQABAAEAAQABAAEAAQABAAeAB4AHgANAA0ADQANACsAKwArACsAKwArACsAKwArACsAKwAeACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwBLAEsASwBLAEsASwBLAEsASwBLACsAKwArACsAKwArAFAAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEACsASwBLAEsASwBLAEsASwBLAEsASwANAA0ADQANAFAABAAEAFAAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAeAA4AUAArACsAKwArACsAKwArACsAKwAEAFAAUABQAFAADQANAB4ADQAEAAQABAAEAB4ABAAEAEsASwBLAEsASwBLAEsASwBLAEsAUAAOAFAADQANAA0AKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAAQABAAEAAQABAANAA0AHgANAA0AHgAEACsAUABQAFAAUABQAFAAUAArAFAAKwBQAFAAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAA0AKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAAQABAAEAAQAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsABAAEAAQABAArAFAAUABQAFAAUABQAFAAUAArACsAUABQACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQACsAUABQACsAUABQAFAAUABQACsABAAEAFAABAAEAAQABAAEAAQABAArACsABAAEACsAKwAEAAQABAArACsAUAArACsAKwArACsAKwAEACsAKwArACsAKwBQAFAAUABQAFAABAAEACsAKwAEAAQABAAEAAQABAAEACsAKwArAAQABAAEAAQABAArACsAKwArACsAKwArACsAKwArACsABAAEAAQABAAEAAQABABQAFAAUABQAA0ADQANAA0AHgBLAEsASwBLAEsASwBLAEsASwBLAA0ADQArAB4ABABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwAEAAQABAAEAFAAUAAeAFAAKwArACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAArACsABAAEAAQABAAEAAQABAAEAAQADgANAA0AEwATAB4AHgAeAA0ADQANAA0ADQANAA0ADQANAA0ADQANAA0ADQANAFAAUABQAFAABAAEACsAKwAEAA0ADQAeAFAAKwArACsAKwArACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAFAAKwArACsAKwArACsAKwBLAEsASwBLAEsASwBLAEsASwBLACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAXABcAFwAKwArACoAKgAqACoAKgAqACoAKgAqACoAKgAqACoAKgAqACsAKwArACsASwBLAEsASwBLAEsASwBLAEsASwBcAFwADQANAA0AKgBQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAeACsAKwArACsASwBLAEsASwBLAEsASwBLAEsASwBQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAKwArAFAAKwArAFAAUABQAFAAUABQAFAAUAArAFAAUAArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEAAQAKwAEAAQAKwArAAQABAAEAAQAUAAEAFAABAAEAA0ADQANACsAKwArACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAArACsABAAEAAQABAAEAAQABABQAA4AUAAEACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAFAABAAEAAQABAAEAAQABAAEAAQABABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAFAABAAEAAQABAAOAB4ADQANAA0ADQAOAB4ABAArACsAKwArACsAKwArACsAUAAEAAQABAAEAAQABAAEAAQABAAEAAQAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAA0ADQANAFAADgAOAA4ADQANACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAEAAQABAAEACsABAAEAAQABAAEAAQABAAEAFAADQANAA0ADQANACsAKwArACsAKwArACsAKwArACsASwBLAEsASwBLAEsASwBLAEsASwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwAOABMAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAArAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQACsAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAArACsAKwAEACsABAAEACsABAAEAAQABAAEAAQABABQAAQAKwArACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsAUABQAFAAUABQAFAAKwBQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQAKwAEAAQAKwAEAAQABAAEAAQAUAArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAABAAEAAQABAAeAB4AKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAB4AHgAeAB4AHgAeAB4AHgAaABoAGgAaAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArACsAKwArACsAKwArACsAKwArACsAKwArAA0AUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsADQANAA0ADQANACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAASABIAEgAQwBDAEMAUABQAFAAUABDAFAAUABQAEgAQwBIAEMAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAASABDAEMAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwAJAAkACQAJAAkACQAJABYAEQArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABIAEMAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwANAA0AKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArAAQABAAEAAQABAANACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEAA0ADQANAB4AHgAeAB4AHgAeAFAAUABQAFAADQAeACsAKwArACsAKwArACsAKwArACsASwBLAEsASwBLAEsASwBLAEsASwArAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAANAA0AHgAeACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwAEAFAABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAKwArACsAKwArACsAKwAEAAQABAAEAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAARwBHABUARwAJACsAKwArACsAKwArACsAKwArACsAKwAEAAQAKwArACsAKwArACsAKwArACsAKwArACsAKwArAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXACsAKwArACsAKwArACsAKwBXAFcAVwBXAFcAVwBXAFcAVwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAUQBRAFEAKwArACsAKwArACsAKwArACsAKwArACsAKwBRAFEAUQBRACsAKwArACsAKwArACsAKwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUAArACsAHgAEAAQADQAEAAQABAAEACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArACsAKwArACsAKwArACsAKwArAB4AHgAeAB4AHgAeAB4AKwArAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAAQABAAEAAQABAAeAB4AHgAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAB4AHgAEAAQABAAEAAQABAAEAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4ABAAEAAQABAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4ABAAEAAQAHgArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwArACsAKwArACsAKwArACsAKwArAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArACsAKwArACsAKwArACsAKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwBQAFAAKwArAFAAKwArAFAAUAArACsAUABQAFAAUAArAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeACsAUAArAFAAUABQAFAAUABQAFAAKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwBQAFAAUABQACsAKwBQAFAAUABQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQACsAHgAeAFAAUABQAFAAUAArAFAAKwArACsAUABQAFAAUABQAFAAUAArAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAHgBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgBQAFAAUABQAFAAUABQAFAAUABQAFAAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAB4AHgAeAB4AHgAeAB4AHgAeACsAKwBLAEsASwBLAEsASwBLAEsASwBLAEsASwBLAEsASwBLAEsASwBLAEsASwBLAEsASwBLAEsASwBLAEsASwBLAEsASwBLAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAeAB4AHgAeAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAeAB4AHgAeAB4AHgAeAB4ABAAeAB4AHgAeAB4AHgAeAB4AHgAeAAQAHgAeAA0ADQANAA0AHgArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwAEAAQABAAEAAQAKwAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAAQABAAEAAQABAAEAAQAKwAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAKwArAAQABAAEAAQABAAEAAQAKwAEAAQAKwAEAAQABAAEAAQAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwAEAAQABAAEAAQABAAEAFAAUABQAFAAUABQAFAAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwBQAB4AKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArABsAUABQAFAAUABQACsAKwBQAFAAUABQAFAAUABQAFAAUAAEAAQABAAEAAQABAAEACsAKwArACsAKwArACsAKwArAB4AHgAeAB4ABAAEAAQABAAEAAQABABQACsAKwArACsASwBLAEsASwBLAEsASwBLAEsASwArACsAKwArABYAFgArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAGgBQAFAAUAAaAFAAUABQAFAAKwArACsAKwArACsAKwArACsAKwArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAeAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQACsAKwBQAFAAUABQACsAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwBQAFAAKwBQACsAKwBQACsAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAKwBQACsAUAArACsAKwArACsAKwBQACsAKwArACsAUAArAFAAKwBQACsAUABQAFAAKwBQAFAAKwBQACsAKwBQACsAUAArAFAAKwBQACsAUAArAFAAUAArAFAAKwArAFAAUABQAFAAKwBQAFAAUABQAFAAUABQACsAUABQAFAAUAArAFAAUABQAFAAKwBQACsAUABQAFAAUABQAFAAUABQAFAAUAArAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAArACsAKwArACsAUABQAFAAKwBQAFAAUABQAFAAKwBQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwAeAB4AKwArACsAKwArACsAKwArACsAKwArACsAKwArAE8ATwBPAE8ATwBPAE8ATwBPAE8ATwBPAE8AJQAlACUAHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHgAeAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB4AHgAeACUAJQAlAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAdAB0AHQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQApACkAKQApACkAKQApACkAKQApACkAKQApACkAKQApACkAKQApACkAKQApACkAKQApACkAJQAlACUAJQAlACAAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAeAB4AJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlAB4AHgAlACUAJQAlACUAHgAlACUAJQAlACUAIAAgACAAJQAlACAAJQAlACAAIAAgACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACEAIQAhACEAIQAlACUAIAAgACUAJQAgACAAIAAgACAAIAAgACAAIAAgACAAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAJQAlACUAIAAlACUAJQAlACAAIAAgACUAIAAgACAAJQAlACUAJQAlACUAJQAgACUAIAAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAHgAlAB4AJQAeACUAJQAlACUAJQAgACUAJQAlACUAHgAlAB4AHgAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlAB4AHgAeAB4AHgAeAB4AJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAeAB4AHgAeAB4AHgAeAB4AHgAeACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACAAIAAlACUAJQAlACAAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACAAJQAlACUAJQAgACAAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAHgAeAB4AHgAeAB4AHgAeACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAeAB4AHgAeAB4AHgAlACUAJQAlACUAJQAlACAAIAAgACUAJQAlACAAIAAgACAAIAAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeABcAFwAXABUAFQAVAB4AHgAeAB4AJQAlACUAIAAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACAAIAAgACUAJQAlACUAJQAlACUAJQAlACAAJQAlACUAJQAlACUAJQAlACUAJQAlACAAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AJQAlACUAJQAlACUAJQAlACUAJQAlACUAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AJQAlACUAJQAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeACUAJQAlACUAJQAlACUAJQAeAB4AHgAeAB4AHgAeAB4AHgAeACUAJQAlACUAJQAlAB4AHgAeAB4AHgAeAB4AHgAlACUAJQAlACUAJQAlACUAHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAgACUAJQAgACUAJQAlACUAJQAlACUAJQAgACAAIAAgACAAIAAgACAAJQAlACUAJQAlACUAIAAlACUAJQAlACUAJQAlACUAJQAgACAAIAAgACAAIAAgACAAIAAgACUAJQAgACAAIAAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAgACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACAAIAAlACAAIAAlACAAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAgACAAIAAlACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAJQAlAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AKwAeAB4AHgAeAB4AHgAeAB4AHgAeAB4AHgArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAEsASwBLAEsASwBLAEsASwBLAEsAKwArACsAKwArACsAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAKwArAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXACUAJQBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwAlACUAJQAlACUAJQAlACUAJQAlACUAVwBXACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQBXAFcAVwBXAFcAVwBXAFcAVwBXAFcAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAJQAlACUAKwAEACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArACsAKwArAA=='; - -var LETTER_NUMBER_MODIFIER = 50; -// Non-tailorable Line Breaking Classes -var BK = 1; // Cause a line break (after) -var CR$1 = 2; // Cause a line break (after), except between CR and LF -var LF$1 = 3; // Cause a line break (after) -var CM = 4; // Prohibit a line break between the character and the preceding character -var NL = 5; // Cause a line break (after) -var WJ = 7; // Prohibit line breaks before and after -var ZW = 8; // Provide a break opportunity -var GL = 9; // Prohibit line breaks before and after -var SP = 10; // Enable indirect line breaks -var ZWJ$1 = 11; // Prohibit line breaks within joiner sequences -// Break Opportunities -var B2 = 12; // Provide a line break opportunity before and after the character -var BA = 13; // Generally provide a line break opportunity after the character -var BB = 14; // Generally provide a line break opportunity before the character -var HY = 15; // Provide a line break opportunity after the character, except in numeric context -var CB = 16; // Provide a line break opportunity contingent on additional information -// Characters Prohibiting Certain Breaks -var CL = 17; // Prohibit line breaks before -var CP = 18; // Prohibit line breaks before -var EX = 19; // Prohibit line breaks before -var IN = 20; // Allow only indirect line breaks between pairs -var NS = 21; // Allow only indirect line breaks before -var OP = 22; // Prohibit line breaks after -var QU = 23; // Act like they are both opening and closing -// Numeric Context -var IS = 24; // Prevent breaks after any and before numeric -var NU = 25; // Form numeric expressions for line breaking purposes -var PO = 26; // Do not break following a numeric expression -var PR = 27; // Do not break in front of a numeric expression -var SY = 28; // Prevent a break before; and allow a break after -// Other Characters -var AI = 29; // Act like AL when the resolvedEAW is N; otherwise; act as ID -var AL = 30; // Are alphabetic characters or symbols that are used with alphabetic characters -var CJ = 31; // Treat as NS or ID for strict or normal breaking. -var EB = 32; // Do not break from following Emoji Modifier -var EM = 33; // Do not break from preceding Emoji Base -var H2 = 34; // Form Korean syllable blocks -var H3 = 35; // Form Korean syllable blocks -var HL = 36; // Do not break around a following hyphen; otherwise act as Alphabetic -var ID = 37; // Break before or after; except in some numeric context -var JL = 38; // Form Korean syllable blocks -var JV = 39; // Form Korean syllable blocks -var JT = 40; // Form Korean syllable blocks -var RI$1 = 41; // Keep pairs together. For pairs; break before and after other classes -var SA = 42; // Provide a line break opportunity contingent on additional, language-specific context analysis -var XX = 43; // Have as yet unknown line breaking behavior or unassigned code positions -var ea_OP = [0x2329, 0xff08]; -var BREAK_MANDATORY = '!'; -var BREAK_NOT_ALLOWED$1 = '×'; -var BREAK_ALLOWED$1 = '÷'; -var UnicodeTrie$1 = createTrieFromBase64$1(base64$1); -var ALPHABETICS = [AL, HL]; -var HARD_LINE_BREAKS = [BK, CR$1, LF$1, NL]; -var SPACE$1 = [SP, ZW]; -var PREFIX_POSTFIX = [PR, PO]; -var LINE_BREAKS = HARD_LINE_BREAKS.concat(SPACE$1); -var KOREAN_SYLLABLE_BLOCK = [JL, JV, JT, H2, H3]; -var HYPHEN = [HY, BA]; -var codePointsToCharacterClasses = function (codePoints, lineBreak) { - if (lineBreak === void 0) { lineBreak = 'strict'; } - var types = []; - var indices = []; - var categories = []; - codePoints.forEach(function (codePoint, index) { - var classType = UnicodeTrie$1.get(codePoint); - if (classType > LETTER_NUMBER_MODIFIER) { - categories.push(true); - classType -= LETTER_NUMBER_MODIFIER; - } - else { - categories.push(false); - } - if (['normal', 'auto', 'loose'].indexOf(lineBreak) !== -1) { - // U+2010, – U+2013, 〜 U+301C, ゠ U+30A0 - if ([0x2010, 0x2013, 0x301c, 0x30a0].indexOf(codePoint) !== -1) { - indices.push(index); - return types.push(CB); - } - } - if (classType === CM || classType === ZWJ$1) { - // LB10 Treat any remaining combining mark or ZWJ as AL. - if (index === 0) { - indices.push(index); - return types.push(AL); - } - // LB9 Do not break a combining character sequence; treat it as if it has the line breaking class of - // the base character in all of the following rules. Treat ZWJ as if it were CM. - var prev = types[index - 1]; - if (LINE_BREAKS.indexOf(prev) === -1) { - indices.push(indices[index - 1]); - return types.push(prev); - } - indices.push(index); - return types.push(AL); - } - indices.push(index); - if (classType === CJ) { - return types.push(lineBreak === 'strict' ? NS : ID); - } - if (classType === SA) { - return types.push(AL); - } - if (classType === AI) { - return types.push(AL); - } - // For supplementary characters, a useful default is to treat characters in the range 10000..1FFFD as AL - // and characters in the ranges 20000..2FFFD and 30000..3FFFD as ID, until the implementation can be revised - // to take into account the actual line breaking properties for these characters. - if (classType === XX) { - if ((codePoint >= 0x20000 && codePoint <= 0x2fffd) || (codePoint >= 0x30000 && codePoint <= 0x3fffd)) { - return types.push(ID); - } - else { - return types.push(AL); - } - } - types.push(classType); - }); - return [indices, types, categories]; -}; -var isAdjacentWithSpaceIgnored = function (a, b, currentIndex, classTypes) { - var current = classTypes[currentIndex]; - if (Array.isArray(a) ? a.indexOf(current) !== -1 : a === current) { - var i = currentIndex; - while (i <= classTypes.length) { - i++; - var next = classTypes[i]; - if (next === b) { - return true; - } - if (next !== SP) { - break; - } - } - } - if (current === SP) { - var i = currentIndex; - while (i > 0) { - i--; - var prev = classTypes[i]; - if (Array.isArray(a) ? a.indexOf(prev) !== -1 : a === prev) { - var n = currentIndex; - while (n <= classTypes.length) { - n++; - var next = classTypes[n]; - if (next === b) { - return true; - } - if (next !== SP) { - break; - } - } - } - if (prev !== SP) { - break; - } - } - } - return false; -}; -var previousNonSpaceClassType = function (currentIndex, classTypes) { - var i = currentIndex; - while (i >= 0) { - var type = classTypes[i]; - if (type === SP) { - i--; - } - else { - return type; - } - } - return 0; -}; -var _lineBreakAtIndex = function (codePoints, classTypes, indicies, index, forbiddenBreaks) { - if (indicies[index] === 0) { - return BREAK_NOT_ALLOWED$1; - } - var currentIndex = index - 1; - if (Array.isArray(forbiddenBreaks) && forbiddenBreaks[currentIndex] === true) { - return BREAK_NOT_ALLOWED$1; - } - var beforeIndex = currentIndex - 1; - var afterIndex = currentIndex + 1; - var current = classTypes[currentIndex]; - // LB4 Always break after hard line breaks. - // LB5 Treat CR followed by LF, as well as CR, LF, and NL as hard line breaks. - var before = beforeIndex >= 0 ? classTypes[beforeIndex] : 0; - var next = classTypes[afterIndex]; - if (current === CR$1 && next === LF$1) { - return BREAK_NOT_ALLOWED$1; - } - if (HARD_LINE_BREAKS.indexOf(current) !== -1) { - return BREAK_MANDATORY; - } - // LB6 Do not break before hard line breaks. - if (HARD_LINE_BREAKS.indexOf(next) !== -1) { - return BREAK_NOT_ALLOWED$1; - } - // LB7 Do not break before spaces or zero width space. - if (SPACE$1.indexOf(next) !== -1) { - return BREAK_NOT_ALLOWED$1; - } - // LB8 Break before any character following a zero-width space, even if one or more spaces intervene. - if (previousNonSpaceClassType(currentIndex, classTypes) === ZW) { - return BREAK_ALLOWED$1; - } - // LB8a Do not break after a zero width joiner. - if (UnicodeTrie$1.get(codePoints[currentIndex]) === ZWJ$1) { - return BREAK_NOT_ALLOWED$1; - } - // zwj emojis - if ((current === EB || current === EM) && UnicodeTrie$1.get(codePoints[afterIndex]) === ZWJ$1) { - return BREAK_NOT_ALLOWED$1; - } - // LB11 Do not break before or after Word joiner and related characters. - if (current === WJ || next === WJ) { - return BREAK_NOT_ALLOWED$1; - } - // LB12 Do not break after NBSP and related characters. - if (current === GL) { - return BREAK_NOT_ALLOWED$1; - } - // LB12a Do not break before NBSP and related characters, except after spaces and hyphens. - if ([SP, BA, HY].indexOf(current) === -1 && next === GL) { - return BREAK_NOT_ALLOWED$1; - } - // LB13 Do not break before ‘]’ or ‘!’ or ‘;’ or ‘/’, even after spaces. - if ([CL, CP, EX, IS, SY].indexOf(next) !== -1) { - return BREAK_NOT_ALLOWED$1; - } - // LB14 Do not break after ‘[’, even after spaces. - if (previousNonSpaceClassType(currentIndex, classTypes) === OP) { - return BREAK_NOT_ALLOWED$1; - } - // LB15 Do not break within ‘”[’, even with intervening spaces. - if (isAdjacentWithSpaceIgnored(QU, OP, currentIndex, classTypes)) { - return BREAK_NOT_ALLOWED$1; - } - // LB16 Do not break between closing punctuation and a nonstarter (lb=NS), even with intervening spaces. - if (isAdjacentWithSpaceIgnored([CL, CP], NS, currentIndex, classTypes)) { - return BREAK_NOT_ALLOWED$1; - } - // LB17 Do not break within ‘——’, even with intervening spaces. - if (isAdjacentWithSpaceIgnored(B2, B2, currentIndex, classTypes)) { - return BREAK_NOT_ALLOWED$1; - } - // LB18 Break after spaces. - if (current === SP) { - return BREAK_ALLOWED$1; - } - // LB19 Do not break before or after quotation marks, such as ‘ ” ’. - if (current === QU || next === QU) { - return BREAK_NOT_ALLOWED$1; - } - // LB20 Break before and after unresolved CB. - if (next === CB || current === CB) { - return BREAK_ALLOWED$1; - } - // LB21 Do not break before hyphen-minus, other hyphens, fixed-width spaces, small kana, and other non-starters, or after acute accents. - if ([BA, HY, NS].indexOf(next) !== -1 || current === BB) { - return BREAK_NOT_ALLOWED$1; - } - // LB21a Don't break after Hebrew + Hyphen. - if (before === HL && HYPHEN.indexOf(current) !== -1) { - return BREAK_NOT_ALLOWED$1; - } - // LB21b Don’t break between Solidus and Hebrew letters. - if (current === SY && next === HL) { - return BREAK_NOT_ALLOWED$1; - } - // LB22 Do not break before ellipsis. - if (next === IN) { - return BREAK_NOT_ALLOWED$1; - } - // LB23 Do not break between digits and letters. - if ((ALPHABETICS.indexOf(next) !== -1 && current === NU) || (ALPHABETICS.indexOf(current) !== -1 && next === NU)) { - return BREAK_NOT_ALLOWED$1; - } - // LB23a Do not break between numeric prefixes and ideographs, or between ideographs and numeric postfixes. - if ((current === PR && [ID, EB, EM].indexOf(next) !== -1) || - ([ID, EB, EM].indexOf(current) !== -1 && next === PO)) { - return BREAK_NOT_ALLOWED$1; - } - // LB24 Do not break between numeric prefix/postfix and letters, or between letters and prefix/postfix. - if ((ALPHABETICS.indexOf(current) !== -1 && PREFIX_POSTFIX.indexOf(next) !== -1) || - (PREFIX_POSTFIX.indexOf(current) !== -1 && ALPHABETICS.indexOf(next) !== -1)) { - return BREAK_NOT_ALLOWED$1; - } - // LB25 Do not break between the following pairs of classes relevant to numbers: - if ( - // (PR | PO) × ( OP | HY )? NU - ([PR, PO].indexOf(current) !== -1 && - (next === NU || ([OP, HY].indexOf(next) !== -1 && classTypes[afterIndex + 1] === NU))) || - // ( OP | HY ) × NU - ([OP, HY].indexOf(current) !== -1 && next === NU) || - // NU × (NU | SY | IS) - (current === NU && [NU, SY, IS].indexOf(next) !== -1)) { - return BREAK_NOT_ALLOWED$1; - } - // NU (NU | SY | IS)* × (NU | SY | IS | CL | CP) - if ([NU, SY, IS, CL, CP].indexOf(next) !== -1) { - var prevIndex = currentIndex; - while (prevIndex >= 0) { - var type = classTypes[prevIndex]; - if (type === NU) { - return BREAK_NOT_ALLOWED$1; - } - else if ([SY, IS].indexOf(type) !== -1) { - prevIndex--; - } - else { - break; - } - } - } - // NU (NU | SY | IS)* (CL | CP)? × (PO | PR)) - if ([PR, PO].indexOf(next) !== -1) { - var prevIndex = [CL, CP].indexOf(current) !== -1 ? beforeIndex : currentIndex; - while (prevIndex >= 0) { - var type = classTypes[prevIndex]; - if (type === NU) { - return BREAK_NOT_ALLOWED$1; - } - else if ([SY, IS].indexOf(type) !== -1) { - prevIndex--; - } - else { - break; - } - } - } - // LB26 Do not break a Korean syllable. - if ((JL === current && [JL, JV, H2, H3].indexOf(next) !== -1) || - ([JV, H2].indexOf(current) !== -1 && [JV, JT].indexOf(next) !== -1) || - ([JT, H3].indexOf(current) !== -1 && next === JT)) { - return BREAK_NOT_ALLOWED$1; - } - // LB27 Treat a Korean Syllable Block the same as ID. - if ((KOREAN_SYLLABLE_BLOCK.indexOf(current) !== -1 && [IN, PO].indexOf(next) !== -1) || - (KOREAN_SYLLABLE_BLOCK.indexOf(next) !== -1 && current === PR)) { - return BREAK_NOT_ALLOWED$1; - } - // LB28 Do not break between alphabetics (“at”). - if (ALPHABETICS.indexOf(current) !== -1 && ALPHABETICS.indexOf(next) !== -1) { - return BREAK_NOT_ALLOWED$1; - } - // LB29 Do not break between numeric punctuation and alphabetics (“e.g.”). - if (current === IS && ALPHABETICS.indexOf(next) !== -1) { - return BREAK_NOT_ALLOWED$1; - } - // LB30 Do not break between letters, numbers, or ordinary symbols and opening or closing parentheses. - if ((ALPHABETICS.concat(NU).indexOf(current) !== -1 && - next === OP && - ea_OP.indexOf(codePoints[afterIndex]) === -1) || - (ALPHABETICS.concat(NU).indexOf(next) !== -1 && current === CP)) { - return BREAK_NOT_ALLOWED$1; - } - // LB30a Break between two regional indicator symbols if and only if there are an even number of regional - // indicators preceding the position of the break. - if (current === RI$1 && next === RI$1) { - var i = indicies[currentIndex]; - var count = 1; - while (i > 0) { - i--; - if (classTypes[i] === RI$1) { - count++; - } - else { - break; - } - } - if (count % 2 !== 0) { - return BREAK_NOT_ALLOWED$1; - } - } - // LB30b Do not break between an emoji base and an emoji modifier. - if (current === EB && next === EM) { - return BREAK_NOT_ALLOWED$1; - } - return BREAK_ALLOWED$1; -}; -var cssFormattedClasses = function (codePoints, options) { - if (!options) { - options = { lineBreak: 'normal', wordBreak: 'normal' }; - } - var _a = codePointsToCharacterClasses(codePoints, options.lineBreak), indicies = _a[0], classTypes = _a[1], isLetterNumber = _a[2]; - if (options.wordBreak === 'break-all' || options.wordBreak === 'break-word') { - classTypes = classTypes.map(function (type) { return ([NU, AL, SA].indexOf(type) !== -1 ? ID : type); }); - } - var forbiddenBreakpoints = options.wordBreak === 'keep-all' - ? isLetterNumber.map(function (letterNumber, i) { - return letterNumber && codePoints[i] >= 0x4e00 && codePoints[i] <= 0x9fff; - }) - : undefined; - return [indicies, classTypes, forbiddenBreakpoints]; -}; -var Break = /** @class */ (function () { - function Break(codePoints, lineBreak, start, end) { - this.codePoints = codePoints; - this.required = lineBreak === BREAK_MANDATORY; - this.start = start; - this.end = end; - } - Break.prototype.slice = function () { - return fromCodePoint$1.apply(void 0, this.codePoints.slice(this.start, this.end)); - }; - return Break; -}()); -var LineBreaker = function (str, options) { - var codePoints = toCodePoints$1(str); - var _a = cssFormattedClasses(codePoints, options), indicies = _a[0], classTypes = _a[1], forbiddenBreakpoints = _a[2]; - var length = codePoints.length; - var lastEnd = 0; - var nextIndex = 0; - return { - next: function () { - if (nextIndex >= length) { - return { done: true, value: null }; - } - var lineBreak = BREAK_NOT_ALLOWED$1; - while (nextIndex < length && - (lineBreak = _lineBreakAtIndex(codePoints, classTypes, indicies, ++nextIndex, forbiddenBreakpoints)) === - BREAK_NOT_ALLOWED$1) { } - if (lineBreak !== BREAK_NOT_ALLOWED$1 || nextIndex === length) { - var value = new Break(codePoints, lineBreak, lastEnd, nextIndex); - lastEnd = nextIndex; - return { value: value, done: false }; - } - return { done: true, value: null }; - }, - }; -}; - -// https://www.w3.org/TR/css-syntax-3 -var FLAG_UNRESTRICTED = 1 << 0; -var FLAG_ID = 1 << 1; -var FLAG_INTEGER = 1 << 2; -var FLAG_NUMBER = 1 << 3; -var LINE_FEED = 0x000a; -var SOLIDUS = 0x002f; -var REVERSE_SOLIDUS = 0x005c; -var CHARACTER_TABULATION = 0x0009; -var SPACE = 0x0020; -var QUOTATION_MARK = 0x0022; -var EQUALS_SIGN = 0x003d; -var NUMBER_SIGN = 0x0023; -var DOLLAR_SIGN = 0x0024; -var PERCENTAGE_SIGN = 0x0025; -var APOSTROPHE = 0x0027; -var LEFT_PARENTHESIS = 0x0028; -var RIGHT_PARENTHESIS = 0x0029; -var LOW_LINE = 0x005f; -var HYPHEN_MINUS = 0x002d; -var EXCLAMATION_MARK = 0x0021; -var LESS_THAN_SIGN = 0x003c; -var GREATER_THAN_SIGN = 0x003e; -var COMMERCIAL_AT = 0x0040; -var LEFT_SQUARE_BRACKET = 0x005b; -var RIGHT_SQUARE_BRACKET = 0x005d; -var CIRCUMFLEX_ACCENT = 0x003d; -var LEFT_CURLY_BRACKET = 0x007b; -var QUESTION_MARK = 0x003f; -var RIGHT_CURLY_BRACKET = 0x007d; -var VERTICAL_LINE = 0x007c; -var TILDE = 0x007e; -var CONTROL = 0x0080; -var REPLACEMENT_CHARACTER = 0xfffd; -var ASTERISK = 0x002a; -var PLUS_SIGN = 0x002b; -var COMMA = 0x002c; -var COLON = 0x003a; -var SEMICOLON = 0x003b; -var FULL_STOP = 0x002e; -var NULL = 0x0000; -var BACKSPACE = 0x0008; -var LINE_TABULATION = 0x000b; -var SHIFT_OUT = 0x000e; -var INFORMATION_SEPARATOR_ONE = 0x001f; -var DELETE = 0x007f; -var EOF = -1; -var ZERO = 0x0030; -var a = 0x0061; -var e = 0x0065; -var f = 0x0066; -var u = 0x0075; -var z = 0x007a; -var A = 0x0041; -var E = 0x0045; -var F = 0x0046; -var U = 0x0055; -var Z = 0x005a; -var isDigit = function (codePoint) { return codePoint >= ZERO && codePoint <= 0x0039; }; -var isSurrogateCodePoint = function (codePoint) { return codePoint >= 0xd800 && codePoint <= 0xdfff; }; -var isHex = function (codePoint) { - return isDigit(codePoint) || (codePoint >= A && codePoint <= F) || (codePoint >= a && codePoint <= f); -}; -var isLowerCaseLetter = function (codePoint) { return codePoint >= a && codePoint <= z; }; -var isUpperCaseLetter = function (codePoint) { return codePoint >= A && codePoint <= Z; }; -var isLetter = function (codePoint) { return isLowerCaseLetter(codePoint) || isUpperCaseLetter(codePoint); }; -var isNonASCIICodePoint = function (codePoint) { return codePoint >= CONTROL; }; -var isWhiteSpace = function (codePoint) { - return codePoint === LINE_FEED || codePoint === CHARACTER_TABULATION || codePoint === SPACE; -}; -var isNameStartCodePoint = function (codePoint) { - return isLetter(codePoint) || isNonASCIICodePoint(codePoint) || codePoint === LOW_LINE; -}; -var isNameCodePoint = function (codePoint) { - return isNameStartCodePoint(codePoint) || isDigit(codePoint) || codePoint === HYPHEN_MINUS; -}; -var isNonPrintableCodePoint = function (codePoint) { - return ((codePoint >= NULL && codePoint <= BACKSPACE) || - codePoint === LINE_TABULATION || - (codePoint >= SHIFT_OUT && codePoint <= INFORMATION_SEPARATOR_ONE) || - codePoint === DELETE); -}; -var isValidEscape = function (c1, c2) { - if (c1 !== REVERSE_SOLIDUS) { - return false; - } - return c2 !== LINE_FEED; -}; -var isIdentifierStart = function (c1, c2, c3) { - if (c1 === HYPHEN_MINUS) { - return isNameStartCodePoint(c2) || isValidEscape(c2, c3); - } - else if (isNameStartCodePoint(c1)) { - return true; - } - else if (c1 === REVERSE_SOLIDUS && isValidEscape(c1, c2)) { - return true; - } - return false; -}; -var isNumberStart = function (c1, c2, c3) { - if (c1 === PLUS_SIGN || c1 === HYPHEN_MINUS) { - if (isDigit(c2)) { - return true; - } - return c2 === FULL_STOP && isDigit(c3); - } - if (c1 === FULL_STOP) { - return isDigit(c2); - } - return isDigit(c1); -}; -var stringToNumber = function (codePoints) { - var c = 0; - var sign = 1; - if (codePoints[c] === PLUS_SIGN || codePoints[c] === HYPHEN_MINUS) { - if (codePoints[c] === HYPHEN_MINUS) { - sign = -1; - } - c++; - } - var integers = []; - while (isDigit(codePoints[c])) { - integers.push(codePoints[c++]); - } - var int = integers.length ? parseInt(fromCodePoint$1.apply(void 0, integers), 10) : 0; - if (codePoints[c] === FULL_STOP) { - c++; - } - var fraction = []; - while (isDigit(codePoints[c])) { - fraction.push(codePoints[c++]); - } - var fracd = fraction.length; - var frac = fracd ? parseInt(fromCodePoint$1.apply(void 0, fraction), 10) : 0; - if (codePoints[c] === E || codePoints[c] === e) { - c++; - } - var expsign = 1; - if (codePoints[c] === PLUS_SIGN || codePoints[c] === HYPHEN_MINUS) { - if (codePoints[c] === HYPHEN_MINUS) { - expsign = -1; - } - c++; - } - var exponent = []; - while (isDigit(codePoints[c])) { - exponent.push(codePoints[c++]); - } - var exp = exponent.length ? parseInt(fromCodePoint$1.apply(void 0, exponent), 10) : 0; - return sign * (int + frac * Math.pow(10, -fracd)) * Math.pow(10, expsign * exp); -}; -var LEFT_PARENTHESIS_TOKEN = { - type: 2 /* LEFT_PARENTHESIS_TOKEN */ -}; -var RIGHT_PARENTHESIS_TOKEN = { - type: 3 /* RIGHT_PARENTHESIS_TOKEN */ -}; -var COMMA_TOKEN = { type: 4 /* COMMA_TOKEN */ }; -var SUFFIX_MATCH_TOKEN = { type: 13 /* SUFFIX_MATCH_TOKEN */ }; -var PREFIX_MATCH_TOKEN = { type: 8 /* PREFIX_MATCH_TOKEN */ }; -var COLUMN_TOKEN = { type: 21 /* COLUMN_TOKEN */ }; -var DASH_MATCH_TOKEN = { type: 9 /* DASH_MATCH_TOKEN */ }; -var INCLUDE_MATCH_TOKEN = { type: 10 /* INCLUDE_MATCH_TOKEN */ }; -var LEFT_CURLY_BRACKET_TOKEN = { - type: 11 /* LEFT_CURLY_BRACKET_TOKEN */ -}; -var RIGHT_CURLY_BRACKET_TOKEN = { - type: 12 /* RIGHT_CURLY_BRACKET_TOKEN */ -}; -var SUBSTRING_MATCH_TOKEN = { type: 14 /* SUBSTRING_MATCH_TOKEN */ }; -var BAD_URL_TOKEN = { type: 23 /* BAD_URL_TOKEN */ }; -var BAD_STRING_TOKEN = { type: 1 /* BAD_STRING_TOKEN */ }; -var CDO_TOKEN = { type: 25 /* CDO_TOKEN */ }; -var CDC_TOKEN = { type: 24 /* CDC_TOKEN */ }; -var COLON_TOKEN = { type: 26 /* COLON_TOKEN */ }; -var SEMICOLON_TOKEN = { type: 27 /* SEMICOLON_TOKEN */ }; -var LEFT_SQUARE_BRACKET_TOKEN = { - type: 28 /* LEFT_SQUARE_BRACKET_TOKEN */ -}; -var RIGHT_SQUARE_BRACKET_TOKEN = { - type: 29 /* RIGHT_SQUARE_BRACKET_TOKEN */ -}; -var WHITESPACE_TOKEN = { type: 31 /* WHITESPACE_TOKEN */ }; -var EOF_TOKEN = { type: 32 /* EOF_TOKEN */ }; -var Tokenizer = /** @class */ (function () { - function Tokenizer() { - this._value = []; - } - Tokenizer.prototype.write = function (chunk) { - this._value = this._value.concat(toCodePoints$1(chunk)); - }; - Tokenizer.prototype.read = function () { - var tokens = []; - var token = this.consumeToken(); - while (token !== EOF_TOKEN) { - tokens.push(token); - token = this.consumeToken(); - } - return tokens; - }; - Tokenizer.prototype.consumeToken = function () { - var codePoint = this.consumeCodePoint(); - switch (codePoint) { - case QUOTATION_MARK: - return this.consumeStringToken(QUOTATION_MARK); - case NUMBER_SIGN: - var c1 = this.peekCodePoint(0); - var c2 = this.peekCodePoint(1); - var c3 = this.peekCodePoint(2); - if (isNameCodePoint(c1) || isValidEscape(c2, c3)) { - var flags = isIdentifierStart(c1, c2, c3) ? FLAG_ID : FLAG_UNRESTRICTED; - var value = this.consumeName(); - return { type: 5 /* HASH_TOKEN */, value: value, flags: flags }; - } - break; - case DOLLAR_SIGN: - if (this.peekCodePoint(0) === EQUALS_SIGN) { - this.consumeCodePoint(); - return SUFFIX_MATCH_TOKEN; - } - break; - case APOSTROPHE: - return this.consumeStringToken(APOSTROPHE); - case LEFT_PARENTHESIS: - return LEFT_PARENTHESIS_TOKEN; - case RIGHT_PARENTHESIS: - return RIGHT_PARENTHESIS_TOKEN; - case ASTERISK: - if (this.peekCodePoint(0) === EQUALS_SIGN) { - this.consumeCodePoint(); - return SUBSTRING_MATCH_TOKEN; - } - break; - case PLUS_SIGN: - if (isNumberStart(codePoint, this.peekCodePoint(0), this.peekCodePoint(1))) { - this.reconsumeCodePoint(codePoint); - return this.consumeNumericToken(); - } - break; - case COMMA: - return COMMA_TOKEN; - case HYPHEN_MINUS: - var e1 = codePoint; - var e2 = this.peekCodePoint(0); - var e3 = this.peekCodePoint(1); - if (isNumberStart(e1, e2, e3)) { - this.reconsumeCodePoint(codePoint); - return this.consumeNumericToken(); - } - if (isIdentifierStart(e1, e2, e3)) { - this.reconsumeCodePoint(codePoint); - return this.consumeIdentLikeToken(); - } - if (e2 === HYPHEN_MINUS && e3 === GREATER_THAN_SIGN) { - this.consumeCodePoint(); - this.consumeCodePoint(); - return CDC_TOKEN; - } - break; - case FULL_STOP: - if (isNumberStart(codePoint, this.peekCodePoint(0), this.peekCodePoint(1))) { - this.reconsumeCodePoint(codePoint); - return this.consumeNumericToken(); - } - break; - case SOLIDUS: - if (this.peekCodePoint(0) === ASTERISK) { - this.consumeCodePoint(); - while (true) { - var c = this.consumeCodePoint(); - if (c === ASTERISK) { - c = this.consumeCodePoint(); - if (c === SOLIDUS) { - return this.consumeToken(); - } - } - if (c === EOF) { - return this.consumeToken(); - } - } - } - break; - case COLON: - return COLON_TOKEN; - case SEMICOLON: - return SEMICOLON_TOKEN; - case LESS_THAN_SIGN: - if (this.peekCodePoint(0) === EXCLAMATION_MARK && - this.peekCodePoint(1) === HYPHEN_MINUS && - this.peekCodePoint(2) === HYPHEN_MINUS) { - this.consumeCodePoint(); - this.consumeCodePoint(); - return CDO_TOKEN; - } - break; - case COMMERCIAL_AT: - var a1 = this.peekCodePoint(0); - var a2 = this.peekCodePoint(1); - var a3 = this.peekCodePoint(2); - if (isIdentifierStart(a1, a2, a3)) { - var value = this.consumeName(); - return { type: 7 /* AT_KEYWORD_TOKEN */, value: value }; - } - break; - case LEFT_SQUARE_BRACKET: - return LEFT_SQUARE_BRACKET_TOKEN; - case REVERSE_SOLIDUS: - if (isValidEscape(codePoint, this.peekCodePoint(0))) { - this.reconsumeCodePoint(codePoint); - return this.consumeIdentLikeToken(); - } - break; - case RIGHT_SQUARE_BRACKET: - return RIGHT_SQUARE_BRACKET_TOKEN; - case CIRCUMFLEX_ACCENT: - if (this.peekCodePoint(0) === EQUALS_SIGN) { - this.consumeCodePoint(); - return PREFIX_MATCH_TOKEN; - } - break; - case LEFT_CURLY_BRACKET: - return LEFT_CURLY_BRACKET_TOKEN; - case RIGHT_CURLY_BRACKET: - return RIGHT_CURLY_BRACKET_TOKEN; - case u: - case U: - var u1 = this.peekCodePoint(0); - var u2 = this.peekCodePoint(1); - if (u1 === PLUS_SIGN && (isHex(u2) || u2 === QUESTION_MARK)) { - this.consumeCodePoint(); - this.consumeUnicodeRangeToken(); - } - this.reconsumeCodePoint(codePoint); - return this.consumeIdentLikeToken(); - case VERTICAL_LINE: - if (this.peekCodePoint(0) === EQUALS_SIGN) { - this.consumeCodePoint(); - return DASH_MATCH_TOKEN; - } - if (this.peekCodePoint(0) === VERTICAL_LINE) { - this.consumeCodePoint(); - return COLUMN_TOKEN; - } - break; - case TILDE: - if (this.peekCodePoint(0) === EQUALS_SIGN) { - this.consumeCodePoint(); - return INCLUDE_MATCH_TOKEN; - } - break; - case EOF: - return EOF_TOKEN; - } - if (isWhiteSpace(codePoint)) { - this.consumeWhiteSpace(); - return WHITESPACE_TOKEN; - } - if (isDigit(codePoint)) { - this.reconsumeCodePoint(codePoint); - return this.consumeNumericToken(); - } - if (isNameStartCodePoint(codePoint)) { - this.reconsumeCodePoint(codePoint); - return this.consumeIdentLikeToken(); - } - return { type: 6 /* DELIM_TOKEN */, value: fromCodePoint$1(codePoint) }; - }; - Tokenizer.prototype.consumeCodePoint = function () { - var value = this._value.shift(); - return typeof value === 'undefined' ? -1 : value; - }; - Tokenizer.prototype.reconsumeCodePoint = function (codePoint) { - this._value.unshift(codePoint); - }; - Tokenizer.prototype.peekCodePoint = function (delta) { - if (delta >= this._value.length) { - return -1; - } - return this._value[delta]; - }; - Tokenizer.prototype.consumeUnicodeRangeToken = function () { - var digits = []; - var codePoint = this.consumeCodePoint(); - while (isHex(codePoint) && digits.length < 6) { - digits.push(codePoint); - codePoint = this.consumeCodePoint(); - } - var questionMarks = false; - while (codePoint === QUESTION_MARK && digits.length < 6) { - digits.push(codePoint); - codePoint = this.consumeCodePoint(); - questionMarks = true; - } - if (questionMarks) { - var start_1 = parseInt(fromCodePoint$1.apply(void 0, digits.map(function (digit) { return (digit === QUESTION_MARK ? ZERO : digit); })), 16); - var end = parseInt(fromCodePoint$1.apply(void 0, digits.map(function (digit) { return (digit === QUESTION_MARK ? F : digit); })), 16); - return { type: 30 /* UNICODE_RANGE_TOKEN */, start: start_1, end: end }; - } - var start = parseInt(fromCodePoint$1.apply(void 0, digits), 16); - if (this.peekCodePoint(0) === HYPHEN_MINUS && isHex(this.peekCodePoint(1))) { - this.consumeCodePoint(); - codePoint = this.consumeCodePoint(); - var endDigits = []; - while (isHex(codePoint) && endDigits.length < 6) { - endDigits.push(codePoint); - codePoint = this.consumeCodePoint(); - } - var end = parseInt(fromCodePoint$1.apply(void 0, endDigits), 16); - return { type: 30 /* UNICODE_RANGE_TOKEN */, start: start, end: end }; - } - else { - return { type: 30 /* UNICODE_RANGE_TOKEN */, start: start, end: start }; - } - }; - Tokenizer.prototype.consumeIdentLikeToken = function () { - var value = this.consumeName(); - if (value.toLowerCase() === 'url' && this.peekCodePoint(0) === LEFT_PARENTHESIS) { - this.consumeCodePoint(); - return this.consumeUrlToken(); - } - else if (this.peekCodePoint(0) === LEFT_PARENTHESIS) { - this.consumeCodePoint(); - return { type: 19 /* FUNCTION_TOKEN */, value: value }; - } - return { type: 20 /* IDENT_TOKEN */, value: value }; - }; - Tokenizer.prototype.consumeUrlToken = function () { - var value = []; - this.consumeWhiteSpace(); - if (this.peekCodePoint(0) === EOF) { - return { type: 22 /* URL_TOKEN */, value: '' }; - } - var next = this.peekCodePoint(0); - if (next === APOSTROPHE || next === QUOTATION_MARK) { - var stringToken = this.consumeStringToken(this.consumeCodePoint()); - if (stringToken.type === 0 /* STRING_TOKEN */) { - this.consumeWhiteSpace(); - if (this.peekCodePoint(0) === EOF || this.peekCodePoint(0) === RIGHT_PARENTHESIS) { - this.consumeCodePoint(); - return { type: 22 /* URL_TOKEN */, value: stringToken.value }; - } - } - this.consumeBadUrlRemnants(); - return BAD_URL_TOKEN; - } - while (true) { - var codePoint = this.consumeCodePoint(); - if (codePoint === EOF || codePoint === RIGHT_PARENTHESIS) { - return { type: 22 /* URL_TOKEN */, value: fromCodePoint$1.apply(void 0, value) }; - } - else if (isWhiteSpace(codePoint)) { - this.consumeWhiteSpace(); - if (this.peekCodePoint(0) === EOF || this.peekCodePoint(0) === RIGHT_PARENTHESIS) { - this.consumeCodePoint(); - return { type: 22 /* URL_TOKEN */, value: fromCodePoint$1.apply(void 0, value) }; - } - this.consumeBadUrlRemnants(); - return BAD_URL_TOKEN; - } - else if (codePoint === QUOTATION_MARK || - codePoint === APOSTROPHE || - codePoint === LEFT_PARENTHESIS || - isNonPrintableCodePoint(codePoint)) { - this.consumeBadUrlRemnants(); - return BAD_URL_TOKEN; - } - else if (codePoint === REVERSE_SOLIDUS) { - if (isValidEscape(codePoint, this.peekCodePoint(0))) { - value.push(this.consumeEscapedCodePoint()); - } - else { - this.consumeBadUrlRemnants(); - return BAD_URL_TOKEN; - } - } - else { - value.push(codePoint); - } - } - }; - Tokenizer.prototype.consumeWhiteSpace = function () { - while (isWhiteSpace(this.peekCodePoint(0))) { - this.consumeCodePoint(); - } - }; - Tokenizer.prototype.consumeBadUrlRemnants = function () { - while (true) { - var codePoint = this.consumeCodePoint(); - if (codePoint === RIGHT_PARENTHESIS || codePoint === EOF) { - return; - } - if (isValidEscape(codePoint, this.peekCodePoint(0))) { - this.consumeEscapedCodePoint(); - } - } - }; - Tokenizer.prototype.consumeStringSlice = function (count) { - var SLICE_STACK_SIZE = 50000; - var value = ''; - while (count > 0) { - var amount = Math.min(SLICE_STACK_SIZE, count); - value += fromCodePoint$1.apply(void 0, this._value.splice(0, amount)); - count -= amount; - } - this._value.shift(); - return value; - }; - Tokenizer.prototype.consumeStringToken = function (endingCodePoint) { - var value = ''; - var i = 0; - do { - var codePoint = this._value[i]; - if (codePoint === EOF || codePoint === undefined || codePoint === endingCodePoint) { - value += this.consumeStringSlice(i); - return { type: 0 /* STRING_TOKEN */, value: value }; - } - if (codePoint === LINE_FEED) { - this._value.splice(0, i); - return BAD_STRING_TOKEN; - } - if (codePoint === REVERSE_SOLIDUS) { - var next = this._value[i + 1]; - if (next !== EOF && next !== undefined) { - if (next === LINE_FEED) { - value += this.consumeStringSlice(i); - i = -1; - this._value.shift(); - } - else if (isValidEscape(codePoint, next)) { - value += this.consumeStringSlice(i); - value += fromCodePoint$1(this.consumeEscapedCodePoint()); - i = -1; - } - } - } - i++; - } while (true); - }; - Tokenizer.prototype.consumeNumber = function () { - var repr = []; - var type = FLAG_INTEGER; - var c1 = this.peekCodePoint(0); - if (c1 === PLUS_SIGN || c1 === HYPHEN_MINUS) { - repr.push(this.consumeCodePoint()); - } - while (isDigit(this.peekCodePoint(0))) { - repr.push(this.consumeCodePoint()); - } - c1 = this.peekCodePoint(0); - var c2 = this.peekCodePoint(1); - if (c1 === FULL_STOP && isDigit(c2)) { - repr.push(this.consumeCodePoint(), this.consumeCodePoint()); - type = FLAG_NUMBER; - while (isDigit(this.peekCodePoint(0))) { - repr.push(this.consumeCodePoint()); - } - } - c1 = this.peekCodePoint(0); - c2 = this.peekCodePoint(1); - var c3 = this.peekCodePoint(2); - if ((c1 === E || c1 === e) && (((c2 === PLUS_SIGN || c2 === HYPHEN_MINUS) && isDigit(c3)) || isDigit(c2))) { - repr.push(this.consumeCodePoint(), this.consumeCodePoint()); - type = FLAG_NUMBER; - while (isDigit(this.peekCodePoint(0))) { - repr.push(this.consumeCodePoint()); - } - } - return [stringToNumber(repr), type]; - }; - Tokenizer.prototype.consumeNumericToken = function () { - var _a = this.consumeNumber(), number = _a[0], flags = _a[1]; - var c1 = this.peekCodePoint(0); - var c2 = this.peekCodePoint(1); - var c3 = this.peekCodePoint(2); - if (isIdentifierStart(c1, c2, c3)) { - var unit = this.consumeName(); - return { type: 15 /* DIMENSION_TOKEN */, number: number, flags: flags, unit: unit }; - } - if (c1 === PERCENTAGE_SIGN) { - this.consumeCodePoint(); - return { type: 16 /* PERCENTAGE_TOKEN */, number: number, flags: flags }; - } - return { type: 17 /* NUMBER_TOKEN */, number: number, flags: flags }; - }; - Tokenizer.prototype.consumeEscapedCodePoint = function () { - var codePoint = this.consumeCodePoint(); - if (isHex(codePoint)) { - var hex = fromCodePoint$1(codePoint); - while (isHex(this.peekCodePoint(0)) && hex.length < 6) { - hex += fromCodePoint$1(this.consumeCodePoint()); - } - if (isWhiteSpace(this.peekCodePoint(0))) { - this.consumeCodePoint(); - } - var hexCodePoint = parseInt(hex, 16); - if (hexCodePoint === 0 || isSurrogateCodePoint(hexCodePoint) || hexCodePoint > 0x10ffff) { - return REPLACEMENT_CHARACTER; - } - return hexCodePoint; - } - if (codePoint === EOF) { - return REPLACEMENT_CHARACTER; - } - return codePoint; - }; - Tokenizer.prototype.consumeName = function () { - var result = ''; - while (true) { - var codePoint = this.consumeCodePoint(); - if (isNameCodePoint(codePoint)) { - result += fromCodePoint$1(codePoint); - } - else if (isValidEscape(codePoint, this.peekCodePoint(0))) { - result += fromCodePoint$1(this.consumeEscapedCodePoint()); - } - else { - this.reconsumeCodePoint(codePoint); - return result; - } - } - }; - return Tokenizer; -}()); - -var Parser = /** @class */ (function () { - function Parser(tokens) { - this._tokens = tokens; - } - Parser.create = function (value) { - var tokenizer = new Tokenizer(); - tokenizer.write(value); - return new Parser(tokenizer.read()); - }; - Parser.parseValue = function (value) { - return Parser.create(value).parseComponentValue(); - }; - Parser.parseValues = function (value) { - return Parser.create(value).parseComponentValues(); - }; - Parser.prototype.parseComponentValue = function () { - var token = this.consumeToken(); - while (token.type === 31 /* WHITESPACE_TOKEN */) { - token = this.consumeToken(); - } - if (token.type === 32 /* EOF_TOKEN */) { - throw new SyntaxError("Error parsing CSS component value, unexpected EOF"); - } - this.reconsumeToken(token); - var value = this.consumeComponentValue(); - do { - token = this.consumeToken(); - } while (token.type === 31 /* WHITESPACE_TOKEN */); - if (token.type === 32 /* EOF_TOKEN */) { - return value; - } - throw new SyntaxError("Error parsing CSS component value, multiple values found when expecting only one"); - }; - Parser.prototype.parseComponentValues = function () { - var values = []; - while (true) { - var value = this.consumeComponentValue(); - if (value.type === 32 /* EOF_TOKEN */) { - return values; - } - values.push(value); - values.push(); - } - }; - Parser.prototype.consumeComponentValue = function () { - var token = this.consumeToken(); - switch (token.type) { - case 11 /* LEFT_CURLY_BRACKET_TOKEN */: - case 28 /* LEFT_SQUARE_BRACKET_TOKEN */: - case 2 /* LEFT_PARENTHESIS_TOKEN */: - return this.consumeSimpleBlock(token.type); - case 19 /* FUNCTION_TOKEN */: - return this.consumeFunction(token); - } - return token; - }; - Parser.prototype.consumeSimpleBlock = function (type) { - var block = { type: type, values: [] }; - var token = this.consumeToken(); - while (true) { - if (token.type === 32 /* EOF_TOKEN */ || isEndingTokenFor(token, type)) { - return block; - } - this.reconsumeToken(token); - block.values.push(this.consumeComponentValue()); - token = this.consumeToken(); - } - }; - Parser.prototype.consumeFunction = function (functionToken) { - var cssFunction = { - name: functionToken.value, - values: [], - type: 18 /* FUNCTION */ - }; - while (true) { - var token = this.consumeToken(); - if (token.type === 32 /* EOF_TOKEN */ || token.type === 3 /* RIGHT_PARENTHESIS_TOKEN */) { - return cssFunction; - } - this.reconsumeToken(token); - cssFunction.values.push(this.consumeComponentValue()); - } - }; - Parser.prototype.consumeToken = function () { - var token = this._tokens.shift(); - return typeof token === 'undefined' ? EOF_TOKEN : token; - }; - Parser.prototype.reconsumeToken = function (token) { - this._tokens.unshift(token); - }; - return Parser; -}()); -var isDimensionToken = function (token) { return token.type === 15 /* DIMENSION_TOKEN */; }; -var isNumberToken = function (token) { return token.type === 17 /* NUMBER_TOKEN */; }; -var isIdentToken = function (token) { return token.type === 20 /* IDENT_TOKEN */; }; -var isStringToken = function (token) { return token.type === 0 /* STRING_TOKEN */; }; -var isIdentWithValue = function (token, value) { - return isIdentToken(token) && token.value === value; -}; -var nonWhiteSpace = function (token) { return token.type !== 31 /* WHITESPACE_TOKEN */; }; -var nonFunctionArgSeparator = function (token) { - return token.type !== 31 /* WHITESPACE_TOKEN */ && token.type !== 4 /* COMMA_TOKEN */; -}; -var parseFunctionArgs = function (tokens) { - var args = []; - var arg = []; - tokens.forEach(function (token) { - if (token.type === 4 /* COMMA_TOKEN */) { - if (arg.length === 0) { - throw new Error("Error parsing function args, zero tokens for arg"); - } - args.push(arg); - arg = []; - return; - } - if (token.type !== 31 /* WHITESPACE_TOKEN */) { - arg.push(token); - } - }); - if (arg.length) { - args.push(arg); - } - return args; -}; -var isEndingTokenFor = function (token, type) { - if (type === 11 /* LEFT_CURLY_BRACKET_TOKEN */ && token.type === 12 /* RIGHT_CURLY_BRACKET_TOKEN */) { - return true; - } - if (type === 28 /* LEFT_SQUARE_BRACKET_TOKEN */ && token.type === 29 /* RIGHT_SQUARE_BRACKET_TOKEN */) { - return true; - } - return type === 2 /* LEFT_PARENTHESIS_TOKEN */ && token.type === 3 /* RIGHT_PARENTHESIS_TOKEN */; -}; - -var isLength = function (token) { - return token.type === 17 /* NUMBER_TOKEN */ || token.type === 15 /* DIMENSION_TOKEN */; -}; - -var isLengthPercentage = function (token) { - return token.type === 16 /* PERCENTAGE_TOKEN */ || isLength(token); -}; -var parseLengthPercentageTuple = function (tokens) { - return tokens.length > 1 ? [tokens[0], tokens[1]] : [tokens[0]]; -}; -var ZERO_LENGTH = { - type: 17 /* NUMBER_TOKEN */, - number: 0, - flags: FLAG_INTEGER -}; -var FIFTY_PERCENT = { - type: 16 /* PERCENTAGE_TOKEN */, - number: 50, - flags: FLAG_INTEGER -}; -var HUNDRED_PERCENT = { - type: 16 /* PERCENTAGE_TOKEN */, - number: 100, - flags: FLAG_INTEGER -}; -var getAbsoluteValueForTuple = function (tuple, width, height) { - var x = tuple[0], y = tuple[1]; - return [getAbsoluteValue(x, width), getAbsoluteValue(typeof y !== 'undefined' ? y : x, height)]; -}; -var getAbsoluteValue = function (token, parent) { - if (token.type === 16 /* PERCENTAGE_TOKEN */) { - return (token.number / 100) * parent; - } - if (isDimensionToken(token)) { - switch (token.unit) { - case 'rem': - case 'em': - return 16 * token.number; // TODO use correct font-size - case 'px': - default: - return token.number; - } - } - return token.number; -}; - -var DEG = 'deg'; -var GRAD = 'grad'; -var RAD = 'rad'; -var TURN = 'turn'; -var angle = { - name: 'angle', - parse: function (_context, value) { - if (value.type === 15 /* DIMENSION_TOKEN */) { - switch (value.unit) { - case DEG: - return (Math.PI * value.number) / 180; - case GRAD: - return (Math.PI / 200) * value.number; - case RAD: - return value.number; - case TURN: - return Math.PI * 2 * value.number; - } - } - throw new Error("Unsupported angle type"); - } -}; -var isAngle = function (value) { - if (value.type === 15 /* DIMENSION_TOKEN */) { - if (value.unit === DEG || value.unit === GRAD || value.unit === RAD || value.unit === TURN) { - return true; - } - } - return false; -}; -var parseNamedSide = function (tokens) { - var sideOrCorner = tokens - .filter(isIdentToken) - .map(function (ident) { return ident.value; }) - .join(' '); - switch (sideOrCorner) { - case 'to bottom right': - case 'to right bottom': - case 'left top': - case 'top left': - return [ZERO_LENGTH, ZERO_LENGTH]; - case 'to top': - case 'bottom': - return deg(0); - case 'to bottom left': - case 'to left bottom': - case 'right top': - case 'top right': - return [ZERO_LENGTH, HUNDRED_PERCENT]; - case 'to right': - case 'left': - return deg(90); - case 'to top left': - case 'to left top': - case 'right bottom': - case 'bottom right': - return [HUNDRED_PERCENT, HUNDRED_PERCENT]; - case 'to bottom': - case 'top': - return deg(180); - case 'to top right': - case 'to right top': - case 'left bottom': - case 'bottom left': - return [HUNDRED_PERCENT, ZERO_LENGTH]; - case 'to left': - case 'right': - return deg(270); - } - return 0; -}; -var deg = function (deg) { return (Math.PI * deg) / 180; }; - -var color$1 = { - name: 'color', - parse: function (context, value) { - if (value.type === 18 /* FUNCTION */) { - var colorFunction = SUPPORTED_COLOR_FUNCTIONS[value.name]; - if (typeof colorFunction === 'undefined') { - throw new Error("Attempting to parse an unsupported color function \"" + value.name + "\""); - } - return colorFunction(context, value.values); - } - if (value.type === 5 /* HASH_TOKEN */) { - if (value.value.length === 3) { - var r = value.value.substring(0, 1); - var g = value.value.substring(1, 2); - var b = value.value.substring(2, 3); - return pack(parseInt(r + r, 16), parseInt(g + g, 16), parseInt(b + b, 16), 1); - } - if (value.value.length === 4) { - var r = value.value.substring(0, 1); - var g = value.value.substring(1, 2); - var b = value.value.substring(2, 3); - var a = value.value.substring(3, 4); - return pack(parseInt(r + r, 16), parseInt(g + g, 16), parseInt(b + b, 16), parseInt(a + a, 16) / 255); - } - if (value.value.length === 6) { - var r = value.value.substring(0, 2); - var g = value.value.substring(2, 4); - var b = value.value.substring(4, 6); - return pack(parseInt(r, 16), parseInt(g, 16), parseInt(b, 16), 1); - } - if (value.value.length === 8) { - var r = value.value.substring(0, 2); - var g = value.value.substring(2, 4); - var b = value.value.substring(4, 6); - var a = value.value.substring(6, 8); - return pack(parseInt(r, 16), parseInt(g, 16), parseInt(b, 16), parseInt(a, 16) / 255); - } - } - if (value.type === 20 /* IDENT_TOKEN */) { - var namedColor = COLORS[value.value.toUpperCase()]; - if (typeof namedColor !== 'undefined') { - return namedColor; - } - } - return COLORS.TRANSPARENT; - } -}; -var isTransparent = function (color) { return (0xff & color) === 0; }; -var asString = function (color) { - var alpha = 0xff & color; - var blue = 0xff & (color >> 8); - var green = 0xff & (color >> 16); - var red = 0xff & (color >> 24); - return alpha < 255 ? "rgba(" + red + "," + green + "," + blue + "," + alpha / 255 + ")" : "rgb(" + red + "," + green + "," + blue + ")"; -}; -var pack = function (r, g, b, a) { - return ((r << 24) | (g << 16) | (b << 8) | (Math.round(a * 255) << 0)) >>> 0; -}; -var getTokenColorValue = function (token, i) { - if (token.type === 17 /* NUMBER_TOKEN */) { - return token.number; - } - if (token.type === 16 /* PERCENTAGE_TOKEN */) { - var max = i === 3 ? 1 : 255; - return i === 3 ? (token.number / 100) * max : Math.round((token.number / 100) * max); - } - return 0; -}; -var rgb = function (_context, args) { - var tokens = args.filter(nonFunctionArgSeparator); - if (tokens.length === 3) { - var _a = tokens.map(getTokenColorValue), r = _a[0], g = _a[1], b = _a[2]; - return pack(r, g, b, 1); - } - if (tokens.length === 4) { - var _b = tokens.map(getTokenColorValue), r = _b[0], g = _b[1], b = _b[2], a = _b[3]; - return pack(r, g, b, a); - } - return 0; -}; -function hue2rgb(t1, t2, hue) { - if (hue < 0) { - hue += 1; - } - if (hue >= 1) { - hue -= 1; - } - if (hue < 1 / 6) { - return (t2 - t1) * hue * 6 + t1; - } - else if (hue < 1 / 2) { - return t2; - } - else if (hue < 2 / 3) { - return (t2 - t1) * 6 * (2 / 3 - hue) + t1; - } - else { - return t1; - } -} -var hsl = function (context, args) { - var tokens = args.filter(nonFunctionArgSeparator); - var hue = tokens[0], saturation = tokens[1], lightness = tokens[2], alpha = tokens[3]; - var h = (hue.type === 17 /* NUMBER_TOKEN */ ? deg(hue.number) : angle.parse(context, hue)) / (Math.PI * 2); - var s = isLengthPercentage(saturation) ? saturation.number / 100 : 0; - var l = isLengthPercentage(lightness) ? lightness.number / 100 : 0; - var a = typeof alpha !== 'undefined' && isLengthPercentage(alpha) ? getAbsoluteValue(alpha, 1) : 1; - if (s === 0) { - return pack(l * 255, l * 255, l * 255, 1); - } - var t2 = l <= 0.5 ? l * (s + 1) : l + s - l * s; - var t1 = l * 2 - t2; - var r = hue2rgb(t1, t2, h + 1 / 3); - var g = hue2rgb(t1, t2, h); - var b = hue2rgb(t1, t2, h - 1 / 3); - return pack(r * 255, g * 255, b * 255, a); -}; -var SUPPORTED_COLOR_FUNCTIONS = { - hsl: hsl, - hsla: hsl, - rgb: rgb, - rgba: rgb -}; -var parseColor = function (context, value) { - return color$1.parse(context, Parser.create(value).parseComponentValue()); -}; -var COLORS = { - ALICEBLUE: 0xf0f8ffff, - ANTIQUEWHITE: 0xfaebd7ff, - AQUA: 0x00ffffff, - AQUAMARINE: 0x7fffd4ff, - AZURE: 0xf0ffffff, - BEIGE: 0xf5f5dcff, - BISQUE: 0xffe4c4ff, - BLACK: 0x000000ff, - BLANCHEDALMOND: 0xffebcdff, - BLUE: 0x0000ffff, - BLUEVIOLET: 0x8a2be2ff, - BROWN: 0xa52a2aff, - BURLYWOOD: 0xdeb887ff, - CADETBLUE: 0x5f9ea0ff, - CHARTREUSE: 0x7fff00ff, - CHOCOLATE: 0xd2691eff, - CORAL: 0xff7f50ff, - CORNFLOWERBLUE: 0x6495edff, - CORNSILK: 0xfff8dcff, - CRIMSON: 0xdc143cff, - CYAN: 0x00ffffff, - DARKBLUE: 0x00008bff, - DARKCYAN: 0x008b8bff, - DARKGOLDENROD: 0xb886bbff, - DARKGRAY: 0xa9a9a9ff, - DARKGREEN: 0x006400ff, - DARKGREY: 0xa9a9a9ff, - DARKKHAKI: 0xbdb76bff, - DARKMAGENTA: 0x8b008bff, - DARKOLIVEGREEN: 0x556b2fff, - DARKORANGE: 0xff8c00ff, - DARKORCHID: 0x9932ccff, - DARKRED: 0x8b0000ff, - DARKSALMON: 0xe9967aff, - DARKSEAGREEN: 0x8fbc8fff, - DARKSLATEBLUE: 0x483d8bff, - DARKSLATEGRAY: 0x2f4f4fff, - DARKSLATEGREY: 0x2f4f4fff, - DARKTURQUOISE: 0x00ced1ff, - DARKVIOLET: 0x9400d3ff, - DEEPPINK: 0xff1493ff, - DEEPSKYBLUE: 0x00bfffff, - DIMGRAY: 0x696969ff, - DIMGREY: 0x696969ff, - DODGERBLUE: 0x1e90ffff, - FIREBRICK: 0xb22222ff, - FLORALWHITE: 0xfffaf0ff, - FORESTGREEN: 0x228b22ff, - FUCHSIA: 0xff00ffff, - GAINSBORO: 0xdcdcdcff, - GHOSTWHITE: 0xf8f8ffff, - GOLD: 0xffd700ff, - GOLDENROD: 0xdaa520ff, - GRAY: 0x808080ff, - GREEN: 0x008000ff, - GREENYELLOW: 0xadff2fff, - GREY: 0x808080ff, - HONEYDEW: 0xf0fff0ff, - HOTPINK: 0xff69b4ff, - INDIANRED: 0xcd5c5cff, - INDIGO: 0x4b0082ff, - IVORY: 0xfffff0ff, - KHAKI: 0xf0e68cff, - LAVENDER: 0xe6e6faff, - LAVENDERBLUSH: 0xfff0f5ff, - LAWNGREEN: 0x7cfc00ff, - LEMONCHIFFON: 0xfffacdff, - LIGHTBLUE: 0xadd8e6ff, - LIGHTCORAL: 0xf08080ff, - LIGHTCYAN: 0xe0ffffff, - LIGHTGOLDENRODYELLOW: 0xfafad2ff, - LIGHTGRAY: 0xd3d3d3ff, - LIGHTGREEN: 0x90ee90ff, - LIGHTGREY: 0xd3d3d3ff, - LIGHTPINK: 0xffb6c1ff, - LIGHTSALMON: 0xffa07aff, - LIGHTSEAGREEN: 0x20b2aaff, - LIGHTSKYBLUE: 0x87cefaff, - LIGHTSLATEGRAY: 0x778899ff, - LIGHTSLATEGREY: 0x778899ff, - LIGHTSTEELBLUE: 0xb0c4deff, - LIGHTYELLOW: 0xffffe0ff, - LIME: 0x00ff00ff, - LIMEGREEN: 0x32cd32ff, - LINEN: 0xfaf0e6ff, - MAGENTA: 0xff00ffff, - MAROON: 0x800000ff, - MEDIUMAQUAMARINE: 0x66cdaaff, - MEDIUMBLUE: 0x0000cdff, - MEDIUMORCHID: 0xba55d3ff, - MEDIUMPURPLE: 0x9370dbff, - MEDIUMSEAGREEN: 0x3cb371ff, - MEDIUMSLATEBLUE: 0x7b68eeff, - MEDIUMSPRINGGREEN: 0x00fa9aff, - MEDIUMTURQUOISE: 0x48d1ccff, - MEDIUMVIOLETRED: 0xc71585ff, - MIDNIGHTBLUE: 0x191970ff, - MINTCREAM: 0xf5fffaff, - MISTYROSE: 0xffe4e1ff, - MOCCASIN: 0xffe4b5ff, - NAVAJOWHITE: 0xffdeadff, - NAVY: 0x000080ff, - OLDLACE: 0xfdf5e6ff, - OLIVE: 0x808000ff, - OLIVEDRAB: 0x6b8e23ff, - ORANGE: 0xffa500ff, - ORANGERED: 0xff4500ff, - ORCHID: 0xda70d6ff, - PALEGOLDENROD: 0xeee8aaff, - PALEGREEN: 0x98fb98ff, - PALETURQUOISE: 0xafeeeeff, - PALEVIOLETRED: 0xdb7093ff, - PAPAYAWHIP: 0xffefd5ff, - PEACHPUFF: 0xffdab9ff, - PERU: 0xcd853fff, - PINK: 0xffc0cbff, - PLUM: 0xdda0ddff, - POWDERBLUE: 0xb0e0e6ff, - PURPLE: 0x800080ff, - REBECCAPURPLE: 0x663399ff, - RED: 0xff0000ff, - ROSYBROWN: 0xbc8f8fff, - ROYALBLUE: 0x4169e1ff, - SADDLEBROWN: 0x8b4513ff, - SALMON: 0xfa8072ff, - SANDYBROWN: 0xf4a460ff, - SEAGREEN: 0x2e8b57ff, - SEASHELL: 0xfff5eeff, - SIENNA: 0xa0522dff, - SILVER: 0xc0c0c0ff, - SKYBLUE: 0x87ceebff, - SLATEBLUE: 0x6a5acdff, - SLATEGRAY: 0x708090ff, - SLATEGREY: 0x708090ff, - SNOW: 0xfffafaff, - SPRINGGREEN: 0x00ff7fff, - STEELBLUE: 0x4682b4ff, - TAN: 0xd2b48cff, - TEAL: 0x008080ff, - THISTLE: 0xd8bfd8ff, - TOMATO: 0xff6347ff, - TRANSPARENT: 0x00000000, - TURQUOISE: 0x40e0d0ff, - VIOLET: 0xee82eeff, - WHEAT: 0xf5deb3ff, - WHITE: 0xffffffff, - WHITESMOKE: 0xf5f5f5ff, - YELLOW: 0xffff00ff, - YELLOWGREEN: 0x9acd32ff -}; - -var backgroundClip = { - name: 'background-clip', - initialValue: 'border-box', - prefix: false, - type: 1 /* LIST */, - parse: function (_context, tokens) { - return tokens.map(function (token) { - if (isIdentToken(token)) { - switch (token.value) { - case 'padding-box': - return 1 /* PADDING_BOX */; - case 'content-box': - return 2 /* CONTENT_BOX */; - } - } - return 0 /* BORDER_BOX */; - }); - } -}; - -var backgroundColor = { - name: "background-color", - initialValue: 'transparent', - prefix: false, - type: 3 /* TYPE_VALUE */, - format: 'color' -}; - -var parseColorStop = function (context, args) { - var color = color$1.parse(context, args[0]); - var stop = args[1]; - return stop && isLengthPercentage(stop) ? { color: color, stop: stop } : { color: color, stop: null }; -}; -var processColorStops = function (stops, lineLength) { - var first = stops[0]; - var last = stops[stops.length - 1]; - if (first.stop === null) { - first.stop = ZERO_LENGTH; - } - if (last.stop === null) { - last.stop = HUNDRED_PERCENT; - } - var processStops = []; - var previous = 0; - for (var i = 0; i < stops.length; i++) { - var stop_1 = stops[i].stop; - if (stop_1 !== null) { - var absoluteValue = getAbsoluteValue(stop_1, lineLength); - if (absoluteValue > previous) { - processStops.push(absoluteValue); - } - else { - processStops.push(previous); - } - previous = absoluteValue; - } - else { - processStops.push(null); - } - } - var gapBegin = null; - for (var i = 0; i < processStops.length; i++) { - var stop_2 = processStops[i]; - if (stop_2 === null) { - if (gapBegin === null) { - gapBegin = i; - } - } - else if (gapBegin !== null) { - var gapLength = i - gapBegin; - var beforeGap = processStops[gapBegin - 1]; - var gapValue = (stop_2 - beforeGap) / (gapLength + 1); - for (var g = 1; g <= gapLength; g++) { - processStops[gapBegin + g - 1] = gapValue * g; - } - gapBegin = null; - } - } - return stops.map(function (_a, i) { - var color = _a.color; - return { color: color, stop: Math.max(Math.min(1, processStops[i] / lineLength), 0) }; - }); -}; -var getAngleFromCorner = function (corner, width, height) { - var centerX = width / 2; - var centerY = height / 2; - var x = getAbsoluteValue(corner[0], width) - centerX; - var y = centerY - getAbsoluteValue(corner[1], height); - return (Math.atan2(y, x) + Math.PI * 2) % (Math.PI * 2); -}; -var calculateGradientDirection = function (angle, width, height) { - var radian = typeof angle === 'number' ? angle : getAngleFromCorner(angle, width, height); - var lineLength = Math.abs(width * Math.sin(radian)) + Math.abs(height * Math.cos(radian)); - var halfWidth = width / 2; - var halfHeight = height / 2; - var halfLineLength = lineLength / 2; - var yDiff = Math.sin(radian - Math.PI / 2) * halfLineLength; - var xDiff = Math.cos(radian - Math.PI / 2) * halfLineLength; - return [lineLength, halfWidth - xDiff, halfWidth + xDiff, halfHeight - yDiff, halfHeight + yDiff]; -}; -var distance = function (a, b) { return Math.sqrt(a * a + b * b); }; -var findCorner = function (width, height, x, y, closest) { - var corners = [ - [0, 0], - [0, height], - [width, 0], - [width, height] - ]; - return corners.reduce(function (stat, corner) { - var cx = corner[0], cy = corner[1]; - var d = distance(x - cx, y - cy); - if (closest ? d < stat.optimumDistance : d > stat.optimumDistance) { - return { - optimumCorner: corner, - optimumDistance: d - }; - } - return stat; - }, { - optimumDistance: closest ? Infinity : -Infinity, - optimumCorner: null - }).optimumCorner; -}; -var calculateRadius = function (gradient, x, y, width, height) { - var rx = 0; - var ry = 0; - switch (gradient.size) { - case 0 /* CLOSEST_SIDE */: - // The ending shape is sized so that that it exactly meets the side of the gradient box closest to the gradient’s center. - // If the shape is an ellipse, it exactly meets the closest side in each dimension. - if (gradient.shape === 0 /* CIRCLE */) { - rx = ry = Math.min(Math.abs(x), Math.abs(x - width), Math.abs(y), Math.abs(y - height)); - } - else if (gradient.shape === 1 /* ELLIPSE */) { - rx = Math.min(Math.abs(x), Math.abs(x - width)); - ry = Math.min(Math.abs(y), Math.abs(y - height)); - } - break; - case 2 /* CLOSEST_CORNER */: - // The ending shape is sized so that that it passes through the corner of the gradient box closest to the gradient’s center. - // If the shape is an ellipse, the ending shape is given the same aspect-ratio it would have if closest-side were specified. - if (gradient.shape === 0 /* CIRCLE */) { - rx = ry = Math.min(distance(x, y), distance(x, y - height), distance(x - width, y), distance(x - width, y - height)); - } - else if (gradient.shape === 1 /* ELLIPSE */) { - // Compute the ratio ry/rx (which is to be the same as for "closest-side") - var c = Math.min(Math.abs(y), Math.abs(y - height)) / Math.min(Math.abs(x), Math.abs(x - width)); - var _a = findCorner(width, height, x, y, true), cx = _a[0], cy = _a[1]; - rx = distance(cx - x, (cy - y) / c); - ry = c * rx; - } - break; - case 1 /* FARTHEST_SIDE */: - // Same as closest-side, except the ending shape is sized based on the farthest side(s) - if (gradient.shape === 0 /* CIRCLE */) { - rx = ry = Math.max(Math.abs(x), Math.abs(x - width), Math.abs(y), Math.abs(y - height)); - } - else if (gradient.shape === 1 /* ELLIPSE */) { - rx = Math.max(Math.abs(x), Math.abs(x - width)); - ry = Math.max(Math.abs(y), Math.abs(y - height)); - } - break; - case 3 /* FARTHEST_CORNER */: - // Same as closest-corner, except the ending shape is sized based on the farthest corner. - // If the shape is an ellipse, the ending shape is given the same aspect ratio it would have if farthest-side were specified. - if (gradient.shape === 0 /* CIRCLE */) { - rx = ry = Math.max(distance(x, y), distance(x, y - height), distance(x - width, y), distance(x - width, y - height)); - } - else if (gradient.shape === 1 /* ELLIPSE */) { - // Compute the ratio ry/rx (which is to be the same as for "farthest-side") - var c = Math.max(Math.abs(y), Math.abs(y - height)) / Math.max(Math.abs(x), Math.abs(x - width)); - var _b = findCorner(width, height, x, y, false), cx = _b[0], cy = _b[1]; - rx = distance(cx - x, (cy - y) / c); - ry = c * rx; - } - break; - } - if (Array.isArray(gradient.size)) { - rx = getAbsoluteValue(gradient.size[0], width); - ry = gradient.size.length === 2 ? getAbsoluteValue(gradient.size[1], height) : rx; - } - return [rx, ry]; -}; - -var linearGradient = function (context, tokens) { - var angle$1 = deg(180); - var stops = []; - parseFunctionArgs(tokens).forEach(function (arg, i) { - if (i === 0) { - var firstToken = arg[0]; - if (firstToken.type === 20 /* IDENT_TOKEN */ && firstToken.value === 'to') { - angle$1 = parseNamedSide(arg); - return; - } - else if (isAngle(firstToken)) { - angle$1 = angle.parse(context, firstToken); - return; - } - } - var colorStop = parseColorStop(context, arg); - stops.push(colorStop); - }); - return { angle: angle$1, stops: stops, type: 1 /* LINEAR_GRADIENT */ }; -}; - -var prefixLinearGradient = function (context, tokens) { - var angle$1 = deg(180); - var stops = []; - parseFunctionArgs(tokens).forEach(function (arg, i) { - if (i === 0) { - var firstToken = arg[0]; - if (firstToken.type === 20 /* IDENT_TOKEN */ && - ['top', 'left', 'right', 'bottom'].indexOf(firstToken.value) !== -1) { - angle$1 = parseNamedSide(arg); - return; - } - else if (isAngle(firstToken)) { - angle$1 = (angle.parse(context, firstToken) + deg(270)) % deg(360); - return; - } - } - var colorStop = parseColorStop(context, arg); - stops.push(colorStop); - }); - return { - angle: angle$1, - stops: stops, - type: 1 /* LINEAR_GRADIENT */ - }; -}; - -var webkitGradient = function (context, tokens) { - var angle = deg(180); - var stops = []; - var type = 1 /* LINEAR_GRADIENT */; - var shape = 0 /* CIRCLE */; - var size = 3 /* FARTHEST_CORNER */; - var position = []; - parseFunctionArgs(tokens).forEach(function (arg, i) { - var firstToken = arg[0]; - if (i === 0) { - if (isIdentToken(firstToken) && firstToken.value === 'linear') { - type = 1 /* LINEAR_GRADIENT */; - return; - } - else if (isIdentToken(firstToken) && firstToken.value === 'radial') { - type = 2 /* RADIAL_GRADIENT */; - return; - } - } - if (firstToken.type === 18 /* FUNCTION */) { - if (firstToken.name === 'from') { - var color = color$1.parse(context, firstToken.values[0]); - stops.push({ stop: ZERO_LENGTH, color: color }); - } - else if (firstToken.name === 'to') { - var color = color$1.parse(context, firstToken.values[0]); - stops.push({ stop: HUNDRED_PERCENT, color: color }); - } - else if (firstToken.name === 'color-stop') { - var values = firstToken.values.filter(nonFunctionArgSeparator); - if (values.length === 2) { - var color = color$1.parse(context, values[1]); - var stop_1 = values[0]; - if (isNumberToken(stop_1)) { - stops.push({ - stop: { type: 16 /* PERCENTAGE_TOKEN */, number: stop_1.number * 100, flags: stop_1.flags }, - color: color - }); - } - } - } - } - }); - return type === 1 /* LINEAR_GRADIENT */ - ? { - angle: (angle + deg(180)) % deg(360), - stops: stops, - type: type - } - : { size: size, shape: shape, stops: stops, position: position, type: type }; -}; - -var CLOSEST_SIDE = 'closest-side'; -var FARTHEST_SIDE = 'farthest-side'; -var CLOSEST_CORNER = 'closest-corner'; -var FARTHEST_CORNER = 'farthest-corner'; -var CIRCLE = 'circle'; -var ELLIPSE = 'ellipse'; -var COVER = 'cover'; -var CONTAIN = 'contain'; -var radialGradient = function (context, tokens) { - var shape = 0 /* CIRCLE */; - var size = 3 /* FARTHEST_CORNER */; - var stops = []; - var position = []; - parseFunctionArgs(tokens).forEach(function (arg, i) { - var isColorStop = true; - if (i === 0) { - var isAtPosition_1 = false; - isColorStop = arg.reduce(function (acc, token) { - if (isAtPosition_1) { - if (isIdentToken(token)) { - switch (token.value) { - case 'center': - position.push(FIFTY_PERCENT); - return acc; - case 'top': - case 'left': - position.push(ZERO_LENGTH); - return acc; - case 'right': - case 'bottom': - position.push(HUNDRED_PERCENT); - return acc; - } - } - else if (isLengthPercentage(token) || isLength(token)) { - position.push(token); - } - } - else if (isIdentToken(token)) { - switch (token.value) { - case CIRCLE: - shape = 0 /* CIRCLE */; - return false; - case ELLIPSE: - shape = 1 /* ELLIPSE */; - return false; - case 'at': - isAtPosition_1 = true; - return false; - case CLOSEST_SIDE: - size = 0 /* CLOSEST_SIDE */; - return false; - case COVER: - case FARTHEST_SIDE: - size = 1 /* FARTHEST_SIDE */; - return false; - case CONTAIN: - case CLOSEST_CORNER: - size = 2 /* CLOSEST_CORNER */; - return false; - case FARTHEST_CORNER: - size = 3 /* FARTHEST_CORNER */; - return false; - } - } - else if (isLength(token) || isLengthPercentage(token)) { - if (!Array.isArray(size)) { - size = []; - } - size.push(token); - return false; - } - return acc; - }, isColorStop); - } - if (isColorStop) { - var colorStop = parseColorStop(context, arg); - stops.push(colorStop); - } - }); - return { size: size, shape: shape, stops: stops, position: position, type: 2 /* RADIAL_GRADIENT */ }; -}; - -var prefixRadialGradient = function (context, tokens) { - var shape = 0 /* CIRCLE */; - var size = 3 /* FARTHEST_CORNER */; - var stops = []; - var position = []; - parseFunctionArgs(tokens).forEach(function (arg, i) { - var isColorStop = true; - if (i === 0) { - isColorStop = arg.reduce(function (acc, token) { - if (isIdentToken(token)) { - switch (token.value) { - case 'center': - position.push(FIFTY_PERCENT); - return false; - case 'top': - case 'left': - position.push(ZERO_LENGTH); - return false; - case 'right': - case 'bottom': - position.push(HUNDRED_PERCENT); - return false; - } - } - else if (isLengthPercentage(token) || isLength(token)) { - position.push(token); - return false; - } - return acc; - }, isColorStop); - } - else if (i === 1) { - isColorStop = arg.reduce(function (acc, token) { - if (isIdentToken(token)) { - switch (token.value) { - case CIRCLE: - shape = 0 /* CIRCLE */; - return false; - case ELLIPSE: - shape = 1 /* ELLIPSE */; - return false; - case CONTAIN: - case CLOSEST_SIDE: - size = 0 /* CLOSEST_SIDE */; - return false; - case FARTHEST_SIDE: - size = 1 /* FARTHEST_SIDE */; - return false; - case CLOSEST_CORNER: - size = 2 /* CLOSEST_CORNER */; - return false; - case COVER: - case FARTHEST_CORNER: - size = 3 /* FARTHEST_CORNER */; - return false; - } - } - else if (isLength(token) || isLengthPercentage(token)) { - if (!Array.isArray(size)) { - size = []; - } - size.push(token); - return false; - } - return acc; - }, isColorStop); - } - if (isColorStop) { - var colorStop = parseColorStop(context, arg); - stops.push(colorStop); - } - }); - return { size: size, shape: shape, stops: stops, position: position, type: 2 /* RADIAL_GRADIENT */ }; -}; - -var isLinearGradient = function (background) { - return background.type === 1 /* LINEAR_GRADIENT */; -}; -var isRadialGradient = function (background) { - return background.type === 2 /* RADIAL_GRADIENT */; -}; -var image$1 = { - name: 'image', - parse: function (context, value) { - if (value.type === 22 /* URL_TOKEN */) { - var image_1 = { url: value.value, type: 0 /* URL */ }; - context.cache.addImage(value.value); - return image_1; - } - if (value.type === 18 /* FUNCTION */) { - var imageFunction = SUPPORTED_IMAGE_FUNCTIONS[value.name]; - if (typeof imageFunction === 'undefined') { - throw new Error("Attempting to parse an unsupported image function \"" + value.name + "\""); - } - return imageFunction(context, value.values); - } - throw new Error("Unsupported image type " + value.type); - } -}; -function isSupportedImage(value) { - return (!(value.type === 20 /* IDENT_TOKEN */ && value.value === 'none') && - (value.type !== 18 /* FUNCTION */ || !!SUPPORTED_IMAGE_FUNCTIONS[value.name])); -} -var SUPPORTED_IMAGE_FUNCTIONS = { - 'linear-gradient': linearGradient, - '-moz-linear-gradient': prefixLinearGradient, - '-ms-linear-gradient': prefixLinearGradient, - '-o-linear-gradient': prefixLinearGradient, - '-webkit-linear-gradient': prefixLinearGradient, - 'radial-gradient': radialGradient, - '-moz-radial-gradient': prefixRadialGradient, - '-ms-radial-gradient': prefixRadialGradient, - '-o-radial-gradient': prefixRadialGradient, - '-webkit-radial-gradient': prefixRadialGradient, - '-webkit-gradient': webkitGradient -}; - -var backgroundImage = { - name: 'background-image', - initialValue: 'none', - type: 1 /* LIST */, - prefix: false, - parse: function (context, tokens) { - if (tokens.length === 0) { - return []; - } - var first = tokens[0]; - if (first.type === 20 /* IDENT_TOKEN */ && first.value === 'none') { - return []; - } - return tokens - .filter(function (value) { return nonFunctionArgSeparator(value) && isSupportedImage(value); }) - .map(function (value) { return image$1.parse(context, value); }); - } -}; - -var backgroundOrigin = { - name: 'background-origin', - initialValue: 'border-box', - prefix: false, - type: 1 /* LIST */, - parse: function (_context, tokens) { - return tokens.map(function (token) { - if (isIdentToken(token)) { - switch (token.value) { - case 'padding-box': - return 1 /* PADDING_BOX */; - case 'content-box': - return 2 /* CONTENT_BOX */; - } - } - return 0 /* BORDER_BOX */; - }); - } -}; - -var backgroundPosition = { - name: 'background-position', - initialValue: '0% 0%', - type: 1 /* LIST */, - prefix: false, - parse: function (_context, tokens) { - return parseFunctionArgs(tokens) - .map(function (values) { return values.filter(isLengthPercentage); }) - .map(parseLengthPercentageTuple); - } -}; - -var backgroundRepeat = { - name: 'background-repeat', - initialValue: 'repeat', - prefix: false, - type: 1 /* LIST */, - parse: function (_context, tokens) { - return parseFunctionArgs(tokens) - .map(function (values) { - return values - .filter(isIdentToken) - .map(function (token) { return token.value; }) - .join(' '); - }) - .map(parseBackgroundRepeat); - } -}; -var parseBackgroundRepeat = function (value) { - switch (value) { - case 'no-repeat': - return 1 /* NO_REPEAT */; - case 'repeat-x': - case 'repeat no-repeat': - return 2 /* REPEAT_X */; - case 'repeat-y': - case 'no-repeat repeat': - return 3 /* REPEAT_Y */; - case 'repeat': - default: - return 0 /* REPEAT */; - } -}; - -var BACKGROUND_SIZE; -(function (BACKGROUND_SIZE) { - BACKGROUND_SIZE["AUTO"] = "auto"; - BACKGROUND_SIZE["CONTAIN"] = "contain"; - BACKGROUND_SIZE["COVER"] = "cover"; -})(BACKGROUND_SIZE || (BACKGROUND_SIZE = {})); -var backgroundSize = { - name: 'background-size', - initialValue: '0', - prefix: false, - type: 1 /* LIST */, - parse: function (_context, tokens) { - return parseFunctionArgs(tokens).map(function (values) { return values.filter(isBackgroundSizeInfoToken); }); - } -}; -var isBackgroundSizeInfoToken = function (value) { - return isIdentToken(value) || isLengthPercentage(value); -}; - -var borderColorForSide = function (side) { return ({ - name: "border-" + side + "-color", - initialValue: 'transparent', - prefix: false, - type: 3 /* TYPE_VALUE */, - format: 'color' -}); }; -var borderTopColor = borderColorForSide('top'); -var borderRightColor = borderColorForSide('right'); -var borderBottomColor = borderColorForSide('bottom'); -var borderLeftColor = borderColorForSide('left'); - -var borderRadiusForSide = function (side) { return ({ - name: "border-radius-" + side, - initialValue: '0 0', - prefix: false, - type: 1 /* LIST */, - parse: function (_context, tokens) { - return parseLengthPercentageTuple(tokens.filter(isLengthPercentage)); - } -}); }; -var borderTopLeftRadius = borderRadiusForSide('top-left'); -var borderTopRightRadius = borderRadiusForSide('top-right'); -var borderBottomRightRadius = borderRadiusForSide('bottom-right'); -var borderBottomLeftRadius = borderRadiusForSide('bottom-left'); - -var borderStyleForSide = function (side) { return ({ - name: "border-" + side + "-style", - initialValue: 'solid', - prefix: false, - type: 2 /* IDENT_VALUE */, - parse: function (_context, style) { - switch (style) { - case 'none': - return 0 /* NONE */; - case 'dashed': - return 2 /* DASHED */; - case 'dotted': - return 3 /* DOTTED */; - case 'double': - return 4 /* DOUBLE */; - } - return 1 /* SOLID */; - } -}); }; -var borderTopStyle = borderStyleForSide('top'); -var borderRightStyle = borderStyleForSide('right'); -var borderBottomStyle = borderStyleForSide('bottom'); -var borderLeftStyle = borderStyleForSide('left'); - -var borderWidthForSide = function (side) { return ({ - name: "border-" + side + "-width", - initialValue: '0', - type: 0 /* VALUE */, - prefix: false, - parse: function (_context, token) { - if (isDimensionToken(token)) { - return token.number; - } - return 0; - } -}); }; -var borderTopWidth = borderWidthForSide('top'); -var borderRightWidth = borderWidthForSide('right'); -var borderBottomWidth = borderWidthForSide('bottom'); -var borderLeftWidth = borderWidthForSide('left'); - -var color = { - name: "color", - initialValue: 'transparent', - prefix: false, - type: 3 /* TYPE_VALUE */, - format: 'color' -}; - -var direction = { - name: 'direction', - initialValue: 'ltr', - prefix: false, - type: 2 /* IDENT_VALUE */, - parse: function (_context, direction) { - switch (direction) { - case 'rtl': - return 1 /* RTL */; - case 'ltr': - default: - return 0 /* LTR */; - } - } -}; - -var display = { - name: 'display', - initialValue: 'inline-block', - prefix: false, - type: 1 /* LIST */, - parse: function (_context, tokens) { - return tokens.filter(isIdentToken).reduce(function (bit, token) { - return bit | parseDisplayValue(token.value); - }, 0 /* NONE */); - } -}; -var parseDisplayValue = function (display) { - switch (display) { - case 'block': - case '-webkit-box': - return 2 /* BLOCK */; - case 'inline': - return 4 /* INLINE */; - case 'run-in': - return 8 /* RUN_IN */; - case 'flow': - return 16 /* FLOW */; - case 'flow-root': - return 32 /* FLOW_ROOT */; - case 'table': - return 64 /* TABLE */; - case 'flex': - case '-webkit-flex': - return 128 /* FLEX */; - case 'grid': - case '-ms-grid': - return 256 /* GRID */; - case 'ruby': - return 512 /* RUBY */; - case 'subgrid': - return 1024 /* SUBGRID */; - case 'list-item': - return 2048 /* LIST_ITEM */; - case 'table-row-group': - return 4096 /* TABLE_ROW_GROUP */; - case 'table-header-group': - return 8192 /* TABLE_HEADER_GROUP */; - case 'table-footer-group': - return 16384 /* TABLE_FOOTER_GROUP */; - case 'table-row': - return 32768 /* TABLE_ROW */; - case 'table-cell': - return 65536 /* TABLE_CELL */; - case 'table-column-group': - return 131072 /* TABLE_COLUMN_GROUP */; - case 'table-column': - return 262144 /* TABLE_COLUMN */; - case 'table-caption': - return 524288 /* TABLE_CAPTION */; - case 'ruby-base': - return 1048576 /* RUBY_BASE */; - case 'ruby-text': - return 2097152 /* RUBY_TEXT */; - case 'ruby-base-container': - return 4194304 /* RUBY_BASE_CONTAINER */; - case 'ruby-text-container': - return 8388608 /* RUBY_TEXT_CONTAINER */; - case 'contents': - return 16777216 /* CONTENTS */; - case 'inline-block': - return 33554432 /* INLINE_BLOCK */; - case 'inline-list-item': - return 67108864 /* INLINE_LIST_ITEM */; - case 'inline-table': - return 134217728 /* INLINE_TABLE */; - case 'inline-flex': - return 268435456 /* INLINE_FLEX */; - case 'inline-grid': - return 536870912 /* INLINE_GRID */; - } - return 0 /* NONE */; -}; - -var float = { - name: 'float', - initialValue: 'none', - prefix: false, - type: 2 /* IDENT_VALUE */, - parse: function (_context, float) { - switch (float) { - case 'left': - return 1 /* LEFT */; - case 'right': - return 2 /* RIGHT */; - case 'inline-start': - return 3 /* INLINE_START */; - case 'inline-end': - return 4 /* INLINE_END */; - } - return 0 /* NONE */; - } -}; - -var letterSpacing = { - name: 'letter-spacing', - initialValue: '0', - prefix: false, - type: 0 /* VALUE */, - parse: function (_context, token) { - if (token.type === 20 /* IDENT_TOKEN */ && token.value === 'normal') { - return 0; - } - if (token.type === 17 /* NUMBER_TOKEN */) { - return token.number; - } - if (token.type === 15 /* DIMENSION_TOKEN */) { - return token.number; - } - return 0; - } -}; - -var LINE_BREAK; -(function (LINE_BREAK) { - LINE_BREAK["NORMAL"] = "normal"; - LINE_BREAK["STRICT"] = "strict"; -})(LINE_BREAK || (LINE_BREAK = {})); -var lineBreak = { - name: 'line-break', - initialValue: 'normal', - prefix: false, - type: 2 /* IDENT_VALUE */, - parse: function (_context, lineBreak) { - switch (lineBreak) { - case 'strict': - return LINE_BREAK.STRICT; - case 'normal': - default: - return LINE_BREAK.NORMAL; - } - } -}; - -var lineHeight = { - name: 'line-height', - initialValue: 'normal', - prefix: false, - type: 4 /* TOKEN_VALUE */ -}; -var computeLineHeight = function (token, fontSize) { - if (isIdentToken(token) && token.value === 'normal') { - return 1.2 * fontSize; - } - else if (token.type === 17 /* NUMBER_TOKEN */) { - return fontSize * token.number; - } - else if (isLengthPercentage(token)) { - return getAbsoluteValue(token, fontSize); - } - return fontSize; -}; - -var listStyleImage = { - name: 'list-style-image', - initialValue: 'none', - type: 0 /* VALUE */, - prefix: false, - parse: function (context, token) { - if (token.type === 20 /* IDENT_TOKEN */ && token.value === 'none') { - return null; - } - return image$1.parse(context, token); - } -}; - -var listStylePosition = { - name: 'list-style-position', - initialValue: 'outside', - prefix: false, - type: 2 /* IDENT_VALUE */, - parse: function (_context, position) { - switch (position) { - case 'inside': - return 0 /* INSIDE */; - case 'outside': - default: - return 1 /* OUTSIDE */; - } - } -}; - -var listStyleType = { - name: 'list-style-type', - initialValue: 'none', - prefix: false, - type: 2 /* IDENT_VALUE */, - parse: function (_context, type) { - switch (type) { - case 'disc': - return 0 /* DISC */; - case 'circle': - return 1 /* CIRCLE */; - case 'square': - return 2 /* SQUARE */; - case 'decimal': - return 3 /* DECIMAL */; - case 'cjk-decimal': - return 4 /* CJK_DECIMAL */; - case 'decimal-leading-zero': - return 5 /* DECIMAL_LEADING_ZERO */; - case 'lower-roman': - return 6 /* LOWER_ROMAN */; - case 'upper-roman': - return 7 /* UPPER_ROMAN */; - case 'lower-greek': - return 8 /* LOWER_GREEK */; - case 'lower-alpha': - return 9 /* LOWER_ALPHA */; - case 'upper-alpha': - return 10 /* UPPER_ALPHA */; - case 'arabic-indic': - return 11 /* ARABIC_INDIC */; - case 'armenian': - return 12 /* ARMENIAN */; - case 'bengali': - return 13 /* BENGALI */; - case 'cambodian': - return 14 /* CAMBODIAN */; - case 'cjk-earthly-branch': - return 15 /* CJK_EARTHLY_BRANCH */; - case 'cjk-heavenly-stem': - return 16 /* CJK_HEAVENLY_STEM */; - case 'cjk-ideographic': - return 17 /* CJK_IDEOGRAPHIC */; - case 'devanagari': - return 18 /* DEVANAGARI */; - case 'ethiopic-numeric': - return 19 /* ETHIOPIC_NUMERIC */; - case 'georgian': - return 20 /* GEORGIAN */; - case 'gujarati': - return 21 /* GUJARATI */; - case 'gurmukhi': - return 22 /* GURMUKHI */; - case 'hebrew': - return 22 /* HEBREW */; - case 'hiragana': - return 23 /* HIRAGANA */; - case 'hiragana-iroha': - return 24 /* HIRAGANA_IROHA */; - case 'japanese-formal': - return 25 /* JAPANESE_FORMAL */; - case 'japanese-informal': - return 26 /* JAPANESE_INFORMAL */; - case 'kannada': - return 27 /* KANNADA */; - case 'katakana': - return 28 /* KATAKANA */; - case 'katakana-iroha': - return 29 /* KATAKANA_IROHA */; - case 'khmer': - return 30 /* KHMER */; - case 'korean-hangul-formal': - return 31 /* KOREAN_HANGUL_FORMAL */; - case 'korean-hanja-formal': - return 32 /* KOREAN_HANJA_FORMAL */; - case 'korean-hanja-informal': - return 33 /* KOREAN_HANJA_INFORMAL */; - case 'lao': - return 34 /* LAO */; - case 'lower-armenian': - return 35 /* LOWER_ARMENIAN */; - case 'malayalam': - return 36 /* MALAYALAM */; - case 'mongolian': - return 37 /* MONGOLIAN */; - case 'myanmar': - return 38 /* MYANMAR */; - case 'oriya': - return 39 /* ORIYA */; - case 'persian': - return 40 /* PERSIAN */; - case 'simp-chinese-formal': - return 41 /* SIMP_CHINESE_FORMAL */; - case 'simp-chinese-informal': - return 42 /* SIMP_CHINESE_INFORMAL */; - case 'tamil': - return 43 /* TAMIL */; - case 'telugu': - return 44 /* TELUGU */; - case 'thai': - return 45 /* THAI */; - case 'tibetan': - return 46 /* TIBETAN */; - case 'trad-chinese-formal': - return 47 /* TRAD_CHINESE_FORMAL */; - case 'trad-chinese-informal': - return 48 /* TRAD_CHINESE_INFORMAL */; - case 'upper-armenian': - return 49 /* UPPER_ARMENIAN */; - case 'disclosure-open': - return 50 /* DISCLOSURE_OPEN */; - case 'disclosure-closed': - return 51 /* DISCLOSURE_CLOSED */; - case 'none': - default: - return -1 /* NONE */; - } - } -}; - -var marginForSide = function (side) { return ({ - name: "margin-" + side, - initialValue: '0', - prefix: false, - type: 4 /* TOKEN_VALUE */ -}); }; -var marginTop = marginForSide('top'); -var marginRight = marginForSide('right'); -var marginBottom = marginForSide('bottom'); -var marginLeft = marginForSide('left'); - -var overflow = { - name: 'overflow', - initialValue: 'visible', - prefix: false, - type: 1 /* LIST */, - parse: function (_context, tokens) { - return tokens.filter(isIdentToken).map(function (overflow) { - switch (overflow.value) { - case 'hidden': - return 1 /* HIDDEN */; - case 'scroll': - return 2 /* SCROLL */; - case 'clip': - return 3 /* CLIP */; - case 'auto': - return 4 /* AUTO */; - case 'visible': - default: - return 0 /* VISIBLE */; - } - }); - } -}; - -var overflowWrap = { - name: 'overflow-wrap', - initialValue: 'normal', - prefix: false, - type: 2 /* IDENT_VALUE */, - parse: function (_context, overflow) { - switch (overflow) { - case 'break-word': - return "break-word" /* BREAK_WORD */; - case 'normal': - default: - return "normal" /* NORMAL */; - } - } -}; - -var paddingForSide = function (side) { return ({ - name: "padding-" + side, - initialValue: '0', - prefix: false, - type: 3 /* TYPE_VALUE */, - format: 'length-percentage' -}); }; -var paddingTop = paddingForSide('top'); -var paddingRight = paddingForSide('right'); -var paddingBottom = paddingForSide('bottom'); -var paddingLeft = paddingForSide('left'); - -var textAlign = { - name: 'text-align', - initialValue: 'left', - prefix: false, - type: 2 /* IDENT_VALUE */, - parse: function (_context, textAlign) { - switch (textAlign) { - case 'right': - return 2 /* RIGHT */; - case 'center': - case 'justify': - return 1 /* CENTER */; - case 'left': - default: - return 0 /* LEFT */; - } - } -}; - -var position = { - name: 'position', - initialValue: 'static', - prefix: false, - type: 2 /* IDENT_VALUE */, - parse: function (_context, position) { - switch (position) { - case 'relative': - return 1 /* RELATIVE */; - case 'absolute': - return 2 /* ABSOLUTE */; - case 'fixed': - return 3 /* FIXED */; - case 'sticky': - return 4 /* STICKY */; - } - return 0 /* STATIC */; - } -}; - -var textShadow = { - name: 'text-shadow', - initialValue: 'none', - type: 1 /* LIST */, - prefix: false, - parse: function (context, tokens) { - if (tokens.length === 1 && isIdentWithValue(tokens[0], 'none')) { - return []; - } - return parseFunctionArgs(tokens).map(function (values) { - var shadow = { - color: COLORS.TRANSPARENT, - offsetX: ZERO_LENGTH, - offsetY: ZERO_LENGTH, - blur: ZERO_LENGTH - }; - var c = 0; - for (var i = 0; i < values.length; i++) { - var token = values[i]; - if (isLength(token)) { - if (c === 0) { - shadow.offsetX = token; - } - else if (c === 1) { - shadow.offsetY = token; - } - else { - shadow.blur = token; - } - c++; - } - else { - shadow.color = color$1.parse(context, token); - } - } - return shadow; - }); - } -}; - -var textTransform = { - name: 'text-transform', - initialValue: 'none', - prefix: false, - type: 2 /* IDENT_VALUE */, - parse: function (_context, textTransform) { - switch (textTransform) { - case 'uppercase': - return 2 /* UPPERCASE */; - case 'lowercase': - return 1 /* LOWERCASE */; - case 'capitalize': - return 3 /* CAPITALIZE */; - } - return 0 /* NONE */; - } -}; - -var transform$1 = { - name: 'transform', - initialValue: 'none', - prefix: true, - type: 0 /* VALUE */, - parse: function (_context, token) { - if (token.type === 20 /* IDENT_TOKEN */ && token.value === 'none') { - return null; - } - if (token.type === 18 /* FUNCTION */) { - var transformFunction = SUPPORTED_TRANSFORM_FUNCTIONS[token.name]; - if (typeof transformFunction === 'undefined') { - throw new Error("Attempting to parse an unsupported transform function \"" + token.name + "\""); - } - return transformFunction(token.values); - } - return null; - } -}; -var matrix = function (args) { - var values = args.filter(function (arg) { return arg.type === 17 /* NUMBER_TOKEN */; }).map(function (arg) { return arg.number; }); - return values.length === 6 ? values : null; -}; -// doesn't support 3D transforms at the moment -var matrix3d = function (args) { - var values = args.filter(function (arg) { return arg.type === 17 /* NUMBER_TOKEN */; }).map(function (arg) { return arg.number; }); - var a1 = values[0], b1 = values[1]; values[2]; values[3]; var a2 = values[4], b2 = values[5]; values[6]; values[7]; values[8]; values[9]; values[10]; values[11]; var a4 = values[12], b4 = values[13]; values[14]; values[15]; - return values.length === 16 ? [a1, b1, a2, b2, a4, b4] : null; -}; -var SUPPORTED_TRANSFORM_FUNCTIONS = { - matrix: matrix, - matrix3d: matrix3d -}; - -var DEFAULT_VALUE = { - type: 16 /* PERCENTAGE_TOKEN */, - number: 50, - flags: FLAG_INTEGER -}; -var DEFAULT = [DEFAULT_VALUE, DEFAULT_VALUE]; -var transformOrigin = { - name: 'transform-origin', - initialValue: '50% 50%', - prefix: true, - type: 1 /* LIST */, - parse: function (_context, tokens) { - var origins = tokens.filter(isLengthPercentage); - if (origins.length !== 2) { - return DEFAULT; - } - return [origins[0], origins[1]]; - } -}; - -var visibility = { - name: 'visible', - initialValue: 'none', - prefix: false, - type: 2 /* IDENT_VALUE */, - parse: function (_context, visibility) { - switch (visibility) { - case 'hidden': - return 1 /* HIDDEN */; - case 'collapse': - return 2 /* COLLAPSE */; - case 'visible': - default: - return 0 /* VISIBLE */; - } - } -}; - -var WORD_BREAK; -(function (WORD_BREAK) { - WORD_BREAK["NORMAL"] = "normal"; - WORD_BREAK["BREAK_ALL"] = "break-all"; - WORD_BREAK["KEEP_ALL"] = "keep-all"; -})(WORD_BREAK || (WORD_BREAK = {})); -var wordBreak = { - name: 'word-break', - initialValue: 'normal', - prefix: false, - type: 2 /* IDENT_VALUE */, - parse: function (_context, wordBreak) { - switch (wordBreak) { - case 'break-all': - return WORD_BREAK.BREAK_ALL; - case 'keep-all': - return WORD_BREAK.KEEP_ALL; - case 'normal': - default: - return WORD_BREAK.NORMAL; - } - } -}; - -var zIndex = { - name: 'z-index', - initialValue: 'auto', - prefix: false, - type: 0 /* VALUE */, - parse: function (_context, token) { - if (token.type === 20 /* IDENT_TOKEN */) { - return { auto: true, order: 0 }; - } - if (isNumberToken(token)) { - return { auto: false, order: token.number }; - } - throw new Error("Invalid z-index number parsed"); - } -}; - -var time = { - name: 'time', - parse: function (_context, value) { - if (value.type === 15 /* DIMENSION_TOKEN */) { - switch (value.unit.toLowerCase()) { - case 's': - return 1000 * value.number; - case 'ms': - return value.number; - } - } - throw new Error("Unsupported time type"); - } -}; - -var opacity = { - name: 'opacity', - initialValue: '1', - type: 0 /* VALUE */, - prefix: false, - parse: function (_context, token) { - if (isNumberToken(token)) { - return token.number; - } - return 1; - } -}; - -var textDecorationColor = { - name: "text-decoration-color", - initialValue: 'transparent', - prefix: false, - type: 3 /* TYPE_VALUE */, - format: 'color' -}; - -var textDecorationLine = { - name: 'text-decoration-line', - initialValue: 'none', - prefix: false, - type: 1 /* LIST */, - parse: function (_context, tokens) { - return tokens - .filter(isIdentToken) - .map(function (token) { - switch (token.value) { - case 'underline': - return 1 /* UNDERLINE */; - case 'overline': - return 2 /* OVERLINE */; - case 'line-through': - return 3 /* LINE_THROUGH */; - case 'none': - return 4 /* BLINK */; - } - return 0 /* NONE */; - }) - .filter(function (line) { return line !== 0 /* NONE */; }); - } -}; - -var fontFamily = { - name: "font-family", - initialValue: '', - prefix: false, - type: 1 /* LIST */, - parse: function (_context, tokens) { - var accumulator = []; - var results = []; - tokens.forEach(function (token) { - switch (token.type) { - case 20 /* IDENT_TOKEN */: - case 0 /* STRING_TOKEN */: - accumulator.push(token.value); - break; - case 17 /* NUMBER_TOKEN */: - accumulator.push(token.number.toString()); - break; - case 4 /* COMMA_TOKEN */: - results.push(accumulator.join(' ')); - accumulator.length = 0; - break; - } - }); - if (accumulator.length) { - results.push(accumulator.join(' ')); - } - return results.map(function (result) { return (result.indexOf(' ') === -1 ? result : "'" + result + "'"); }); - } -}; - -var fontSize = { - name: "font-size", - initialValue: '0', - prefix: false, - type: 3 /* TYPE_VALUE */, - format: 'length' -}; - -var fontWeight = { - name: 'font-weight', - initialValue: 'normal', - type: 0 /* VALUE */, - prefix: false, - parse: function (_context, token) { - if (isNumberToken(token)) { - return token.number; - } - if (isIdentToken(token)) { - switch (token.value) { - case 'bold': - return 700; - case 'normal': - default: - return 400; - } - } - return 400; - } -}; - -var fontVariant = { - name: 'font-variant', - initialValue: 'none', - type: 1 /* LIST */, - prefix: false, - parse: function (_context, tokens) { - return tokens.filter(isIdentToken).map(function (token) { return token.value; }); - } -}; - -var fontStyle = { - name: 'font-style', - initialValue: 'normal', - prefix: false, - type: 2 /* IDENT_VALUE */, - parse: function (_context, overflow) { - switch (overflow) { - case 'oblique': - return "oblique" /* OBLIQUE */; - case 'italic': - return "italic" /* ITALIC */; - case 'normal': - default: - return "normal" /* NORMAL */; - } - } -}; - -var contains = function (bit, value) { return (bit & value) !== 0; }; - -var content = { - name: 'content', - initialValue: 'none', - type: 1 /* LIST */, - prefix: false, - parse: function (_context, tokens) { - if (tokens.length === 0) { - return []; - } - var first = tokens[0]; - if (first.type === 20 /* IDENT_TOKEN */ && first.value === 'none') { - return []; - } - return tokens; - } -}; - -var counterIncrement = { - name: 'counter-increment', - initialValue: 'none', - prefix: true, - type: 1 /* LIST */, - parse: function (_context, tokens) { - if (tokens.length === 0) { - return null; - } - var first = tokens[0]; - if (first.type === 20 /* IDENT_TOKEN */ && first.value === 'none') { - return null; - } - var increments = []; - var filtered = tokens.filter(nonWhiteSpace); - for (var i = 0; i < filtered.length; i++) { - var counter = filtered[i]; - var next = filtered[i + 1]; - if (counter.type === 20 /* IDENT_TOKEN */) { - var increment = next && isNumberToken(next) ? next.number : 1; - increments.push({ counter: counter.value, increment: increment }); - } - } - return increments; - } -}; - -var counterReset = { - name: 'counter-reset', - initialValue: 'none', - prefix: true, - type: 1 /* LIST */, - parse: function (_context, tokens) { - if (tokens.length === 0) { - return []; - } - var resets = []; - var filtered = tokens.filter(nonWhiteSpace); - for (var i = 0; i < filtered.length; i++) { - var counter = filtered[i]; - var next = filtered[i + 1]; - if (isIdentToken(counter) && counter.value !== 'none') { - var reset = next && isNumberToken(next) ? next.number : 0; - resets.push({ counter: counter.value, reset: reset }); - } - } - return resets; - } -}; - -var duration = { - name: 'duration', - initialValue: '0s', - prefix: false, - type: 1 /* LIST */, - parse: function (context, tokens) { - return tokens.filter(isDimensionToken).map(function (token) { return time.parse(context, token); }); - } -}; - -var quotes = { - name: 'quotes', - initialValue: 'none', - prefix: true, - type: 1 /* LIST */, - parse: function (_context, tokens) { - if (tokens.length === 0) { - return null; - } - var first = tokens[0]; - if (first.type === 20 /* IDENT_TOKEN */ && first.value === 'none') { - return null; - } - var quotes = []; - var filtered = tokens.filter(isStringToken); - if (filtered.length % 2 !== 0) { - return null; - } - for (var i = 0; i < filtered.length; i += 2) { - var open_1 = filtered[i].value; - var close_1 = filtered[i + 1].value; - quotes.push({ open: open_1, close: close_1 }); - } - return quotes; - } -}; -var getQuote = function (quotes, depth, open) { - if (!quotes) { - return ''; - } - var quote = quotes[Math.min(depth, quotes.length - 1)]; - if (!quote) { - return ''; - } - return open ? quote.open : quote.close; -}; - -var boxShadow = { - name: 'box-shadow', - initialValue: 'none', - type: 1 /* LIST */, - prefix: false, - parse: function (context, tokens) { - if (tokens.length === 1 && isIdentWithValue(tokens[0], 'none')) { - return []; - } - return parseFunctionArgs(tokens).map(function (values) { - var shadow = { - color: 0x000000ff, - offsetX: ZERO_LENGTH, - offsetY: ZERO_LENGTH, - blur: ZERO_LENGTH, - spread: ZERO_LENGTH, - inset: false - }; - var c = 0; - for (var i = 0; i < values.length; i++) { - var token = values[i]; - if (isIdentWithValue(token, 'inset')) { - shadow.inset = true; - } - else if (isLength(token)) { - if (c === 0) { - shadow.offsetX = token; - } - else if (c === 1) { - shadow.offsetY = token; - } - else if (c === 2) { - shadow.blur = token; - } - else { - shadow.spread = token; - } - c++; - } - else { - shadow.color = color$1.parse(context, token); - } - } - return shadow; - }); - } -}; - -var paintOrder = { - name: 'paint-order', - initialValue: 'normal', - prefix: false, - type: 1 /* LIST */, - parse: function (_context, tokens) { - var DEFAULT_VALUE = [0 /* FILL */, 1 /* STROKE */, 2 /* MARKERS */]; - var layers = []; - tokens.filter(isIdentToken).forEach(function (token) { - switch (token.value) { - case 'stroke': - layers.push(1 /* STROKE */); - break; - case 'fill': - layers.push(0 /* FILL */); - break; - case 'markers': - layers.push(2 /* MARKERS */); - break; - } - }); - DEFAULT_VALUE.forEach(function (value) { - if (layers.indexOf(value) === -1) { - layers.push(value); - } - }); - return layers; - } -}; - -var webkitTextStrokeColor = { - name: "-webkit-text-stroke-color", - initialValue: 'currentcolor', - prefix: false, - type: 3 /* TYPE_VALUE */, - format: 'color' -}; - -var webkitTextStrokeWidth = { - name: "-webkit-text-stroke-width", - initialValue: '0', - type: 0 /* VALUE */, - prefix: false, - parse: function (_context, token) { - if (isDimensionToken(token)) { - return token.number; - } - return 0; - } -}; - -var CSSParsedDeclaration = /** @class */ (function () { - function CSSParsedDeclaration(context, declaration) { - var _a, _b; - this.animationDuration = parse$1(context, duration, declaration.animationDuration); - this.backgroundClip = parse$1(context, backgroundClip, declaration.backgroundClip); - this.backgroundColor = parse$1(context, backgroundColor, declaration.backgroundColor); - this.backgroundImage = parse$1(context, backgroundImage, declaration.backgroundImage); - this.backgroundOrigin = parse$1(context, backgroundOrigin, declaration.backgroundOrigin); - this.backgroundPosition = parse$1(context, backgroundPosition, declaration.backgroundPosition); - this.backgroundRepeat = parse$1(context, backgroundRepeat, declaration.backgroundRepeat); - this.backgroundSize = parse$1(context, backgroundSize, declaration.backgroundSize); - this.borderTopColor = parse$1(context, borderTopColor, declaration.borderTopColor); - this.borderRightColor = parse$1(context, borderRightColor, declaration.borderRightColor); - this.borderBottomColor = parse$1(context, borderBottomColor, declaration.borderBottomColor); - this.borderLeftColor = parse$1(context, borderLeftColor, declaration.borderLeftColor); - this.borderTopLeftRadius = parse$1(context, borderTopLeftRadius, declaration.borderTopLeftRadius); - this.borderTopRightRadius = parse$1(context, borderTopRightRadius, declaration.borderTopRightRadius); - this.borderBottomRightRadius = parse$1(context, borderBottomRightRadius, declaration.borderBottomRightRadius); - this.borderBottomLeftRadius = parse$1(context, borderBottomLeftRadius, declaration.borderBottomLeftRadius); - this.borderTopStyle = parse$1(context, borderTopStyle, declaration.borderTopStyle); - this.borderRightStyle = parse$1(context, borderRightStyle, declaration.borderRightStyle); - this.borderBottomStyle = parse$1(context, borderBottomStyle, declaration.borderBottomStyle); - this.borderLeftStyle = parse$1(context, borderLeftStyle, declaration.borderLeftStyle); - this.borderTopWidth = parse$1(context, borderTopWidth, declaration.borderTopWidth); - this.borderRightWidth = parse$1(context, borderRightWidth, declaration.borderRightWidth); - this.borderBottomWidth = parse$1(context, borderBottomWidth, declaration.borderBottomWidth); - this.borderLeftWidth = parse$1(context, borderLeftWidth, declaration.borderLeftWidth); - this.boxShadow = parse$1(context, boxShadow, declaration.boxShadow); - this.color = parse$1(context, color, declaration.color); - this.direction = parse$1(context, direction, declaration.direction); - this.display = parse$1(context, display, declaration.display); - this.float = parse$1(context, float, declaration.cssFloat); - this.fontFamily = parse$1(context, fontFamily, declaration.fontFamily); - this.fontSize = parse$1(context, fontSize, declaration.fontSize); - this.fontStyle = parse$1(context, fontStyle, declaration.fontStyle); - this.fontVariant = parse$1(context, fontVariant, declaration.fontVariant); - this.fontWeight = parse$1(context, fontWeight, declaration.fontWeight); - this.letterSpacing = parse$1(context, letterSpacing, declaration.letterSpacing); - this.lineBreak = parse$1(context, lineBreak, declaration.lineBreak); - this.lineHeight = parse$1(context, lineHeight, declaration.lineHeight); - this.listStyleImage = parse$1(context, listStyleImage, declaration.listStyleImage); - this.listStylePosition = parse$1(context, listStylePosition, declaration.listStylePosition); - this.listStyleType = parse$1(context, listStyleType, declaration.listStyleType); - this.marginTop = parse$1(context, marginTop, declaration.marginTop); - this.marginRight = parse$1(context, marginRight, declaration.marginRight); - this.marginBottom = parse$1(context, marginBottom, declaration.marginBottom); - this.marginLeft = parse$1(context, marginLeft, declaration.marginLeft); - this.opacity = parse$1(context, opacity, declaration.opacity); - var overflowTuple = parse$1(context, overflow, declaration.overflow); - this.overflowX = overflowTuple[0]; - this.overflowY = overflowTuple[overflowTuple.length > 1 ? 1 : 0]; - this.overflowWrap = parse$1(context, overflowWrap, declaration.overflowWrap); - this.paddingTop = parse$1(context, paddingTop, declaration.paddingTop); - this.paddingRight = parse$1(context, paddingRight, declaration.paddingRight); - this.paddingBottom = parse$1(context, paddingBottom, declaration.paddingBottom); - this.paddingLeft = parse$1(context, paddingLeft, declaration.paddingLeft); - this.paintOrder = parse$1(context, paintOrder, declaration.paintOrder); - this.position = parse$1(context, position, declaration.position); - this.textAlign = parse$1(context, textAlign, declaration.textAlign); - this.textDecorationColor = parse$1(context, textDecorationColor, (_a = declaration.textDecorationColor) !== null && _a !== void 0 ? _a : declaration.color); - this.textDecorationLine = parse$1(context, textDecorationLine, (_b = declaration.textDecorationLine) !== null && _b !== void 0 ? _b : declaration.textDecoration); - this.textShadow = parse$1(context, textShadow, declaration.textShadow); - this.textTransform = parse$1(context, textTransform, declaration.textTransform); - this.transform = parse$1(context, transform$1, declaration.transform); - this.transformOrigin = parse$1(context, transformOrigin, declaration.transformOrigin); - this.visibility = parse$1(context, visibility, declaration.visibility); - this.webkitTextStrokeColor = parse$1(context, webkitTextStrokeColor, declaration.webkitTextStrokeColor); - this.webkitTextStrokeWidth = parse$1(context, webkitTextStrokeWidth, declaration.webkitTextStrokeWidth); - this.wordBreak = parse$1(context, wordBreak, declaration.wordBreak); - this.zIndex = parse$1(context, zIndex, declaration.zIndex); - } - CSSParsedDeclaration.prototype.isVisible = function () { - return this.display > 0 && this.opacity > 0 && this.visibility === 0 /* VISIBLE */; - }; - CSSParsedDeclaration.prototype.isTransparent = function () { - return isTransparent(this.backgroundColor); - }; - CSSParsedDeclaration.prototype.isTransformed = function () { - return this.transform !== null; - }; - CSSParsedDeclaration.prototype.isPositioned = function () { - return this.position !== 0 /* STATIC */; - }; - CSSParsedDeclaration.prototype.isPositionedWithZIndex = function () { - return this.isPositioned() && !this.zIndex.auto; - }; - CSSParsedDeclaration.prototype.isFloating = function () { - return this.float !== 0 /* NONE */; - }; - CSSParsedDeclaration.prototype.isInlineLevel = function () { - return (contains(this.display, 4 /* INLINE */) || - contains(this.display, 33554432 /* INLINE_BLOCK */) || - contains(this.display, 268435456 /* INLINE_FLEX */) || - contains(this.display, 536870912 /* INLINE_GRID */) || - contains(this.display, 67108864 /* INLINE_LIST_ITEM */) || - contains(this.display, 134217728 /* INLINE_TABLE */)); - }; - return CSSParsedDeclaration; -}()); -var CSSParsedPseudoDeclaration = /** @class */ (function () { - function CSSParsedPseudoDeclaration(context, declaration) { - this.content = parse$1(context, content, declaration.content); - this.quotes = parse$1(context, quotes, declaration.quotes); - } - return CSSParsedPseudoDeclaration; -}()); -var CSSParsedCounterDeclaration = /** @class */ (function () { - function CSSParsedCounterDeclaration(context, declaration) { - this.counterIncrement = parse$1(context, counterIncrement, declaration.counterIncrement); - this.counterReset = parse$1(context, counterReset, declaration.counterReset); - } - return CSSParsedCounterDeclaration; -}()); -// eslint-disable-next-line @typescript-eslint/no-explicit-any -var parse$1 = function (context, descriptor, style) { - var tokenizer = new Tokenizer(); - var value = style !== null && typeof style !== 'undefined' ? style.toString() : descriptor.initialValue; - tokenizer.write(value); - var parser = new Parser(tokenizer.read()); - switch (descriptor.type) { - case 2 /* IDENT_VALUE */: - var token = parser.parseComponentValue(); - return descriptor.parse(context, isIdentToken(token) ? token.value : descriptor.initialValue); - case 0 /* VALUE */: - return descriptor.parse(context, parser.parseComponentValue()); - case 1 /* LIST */: - return descriptor.parse(context, parser.parseComponentValues()); - case 4 /* TOKEN_VALUE */: - return parser.parseComponentValue(); - case 3 /* TYPE_VALUE */: - switch (descriptor.format) { - case 'angle': - return angle.parse(context, parser.parseComponentValue()); - case 'color': - return color$1.parse(context, parser.parseComponentValue()); - case 'image': - return image$1.parse(context, parser.parseComponentValue()); - case 'length': - var length_1 = parser.parseComponentValue(); - return isLength(length_1) ? length_1 : ZERO_LENGTH; - case 'length-percentage': - var value_1 = parser.parseComponentValue(); - return isLengthPercentage(value_1) ? value_1 : ZERO_LENGTH; - case 'time': - return time.parse(context, parser.parseComponentValue()); - } - break; - } -}; - -var elementDebuggerAttribute = 'data-html2canvas-debug'; -var getElementDebugType = function (element) { - var attribute = element.getAttribute(elementDebuggerAttribute); - switch (attribute) { - case 'all': - return 1 /* ALL */; - case 'clone': - return 2 /* CLONE */; - case 'parse': - return 3 /* PARSE */; - case 'render': - return 4 /* RENDER */; - default: - return 0 /* NONE */; - } -}; -var isDebugging = function (element, type) { - var elementType = getElementDebugType(element); - return elementType === 1 /* ALL */ || type === elementType; -}; - -var ElementContainer = /** @class */ (function () { - function ElementContainer(context, element) { - this.context = context; - this.textNodes = []; - this.elements = []; - this.flags = 0; - if (isDebugging(element, 3 /* PARSE */)) { - debugger; - } - this.styles = new CSSParsedDeclaration(context, window.getComputedStyle(element, null)); - if (isHTMLElementNode(element)) { - if (this.styles.animationDuration.some(function (duration) { return duration > 0; })) { - element.style.animationDuration = '0s'; - } - if (this.styles.transform !== null) { - // getBoundingClientRect takes transforms into account - element.style.transform = 'none'; - } - } - this.bounds = parseBounds(this.context, element); - if (isDebugging(element, 4 /* RENDER */)) { - this.flags |= 16 /* DEBUG_RENDER */; - } - } - return ElementContainer; -}()); - -/* - * text-segmentation 1.0.3 - * Copyright (c) 2022 Niklas von Hertzen - * Released under MIT License - */ -var base64 = 'AAAAAAAAAAAAEA4AGBkAAFAaAAACAAAAAAAIABAAGAAwADgACAAQAAgAEAAIABAACAAQAAgAEAAIABAACAAQAAgAEAAIABAAQABIAEQATAAIABAACAAQAAgAEAAIABAAVABcAAgAEAAIABAACAAQAGAAaABwAHgAgACIAI4AlgAIABAAmwCjAKgAsAC2AL4AvQDFAMoA0gBPAVYBWgEIAAgACACMANoAYgFkAWwBdAF8AX0BhQGNAZUBlgGeAaMBlQGWAasBswF8AbsBwwF0AcsBYwHTAQgA2wG/AOMBdAF8AekB8QF0AfkB+wHiAHQBfAEIAAMC5gQIAAsCEgIIAAgAFgIeAggAIgIpAggAMQI5AkACygEIAAgASAJQAlgCYAIIAAgACAAKBQoFCgUTBRMFGQUrBSsFCAAIAAgACAAIAAgACAAIAAgACABdAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACABoAmgCrwGvAQgAbgJ2AggAHgEIAAgACADnAXsCCAAIAAgAgwIIAAgACAAIAAgACACKAggAkQKZAggAPADJAAgAoQKkAqwCsgK6AsICCADJAggA0AIIAAgACAAIANYC3gIIAAgACAAIAAgACABAAOYCCAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAkASoB+QIEAAgACAA8AEMCCABCBQgACABJBVAFCAAIAAgACAAIAAgACAAIAAgACABTBVoFCAAIAFoFCABfBWUFCAAIAAgACAAIAAgAbQUIAAgACAAIAAgACABzBXsFfQWFBYoFigWKBZEFigWKBYoFmAWfBaYFrgWxBbkFCAAIAAgACAAIAAgACAAIAAgACAAIAMEFCAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAMgFCADQBQgACAAIAAgACAAIAAgACAAIAAgACAAIAO4CCAAIAAgAiQAIAAgACABAAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAD0AggACAD8AggACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIANYFCAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAMDvwAIAAgAJAIIAAgACAAIAAgACAAIAAgACwMTAwgACAB9BOsEGwMjAwgAKwMyAwsFYgE3A/MEPwMIAEUDTQNRAwgAWQOsAGEDCAAIAAgACAAIAAgACABpAzQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFOgU0BTUFNgU3BTgFOQU6BTQFNQU2BTcFOAU5BToFNAU1BTYFNwU4BTkFIQUoBSwFCAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACABtAwgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACABMAEwACAAIAAgACAAIABgACAAIAAgACAC/AAgACAAyAQgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACACAAIAAwAAgACAAIAAgACAAIAAgACAAIAAAARABIAAgACAAIABQASAAIAAgAIABwAEAAjgCIABsAqAC2AL0AigDQAtwC+IJIQqVAZUBWQqVAZUBlQGVAZUBlQGrC5UBlQGVAZUBlQGVAZUBlQGVAXsKlQGVAbAK6wsrDGUMpQzlDJUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAZUBlQGVAfAKAAuZA64AtwCJALoC6ADwAAgAuACgA/oEpgO6AqsD+AAIAAgAswMIAAgACAAIAIkAuwP5AfsBwwPLAwgACAAIAAgACADRA9kDCAAIAOED6QMIAAgACAAIAAgACADuA/YDCAAIAP4DyQAIAAgABgQIAAgAXQAOBAgACAAIAAgACAAIABMECAAIAAgACAAIAAgACAD8AAQBCAAIAAgAGgQiBCoECAExBAgAEAEIAAgACAAIAAgACAAIAAgACAAIAAgACAA4BAgACABABEYECAAIAAgATAQYAQgAVAQIAAgACAAIAAgACAAIAAgACAAIAFoECAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgAOQEIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAB+BAcACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAEABhgSMBAgACAAIAAgAlAQIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAwAEAAQABAADAAMAAwADAAQABAAEAAQABAAEAAQABHATAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgAdQMIAAgACAAIAAgACAAIAMkACAAIAAgAfQMIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACACFA4kDCAAIAAgACAAIAOcBCAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAIcDCAAIAAgACAAIAAgACAAIAAgACAAIAJEDCAAIAAgACADFAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACABgBAgAZgQIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgAbAQCBXIECAAIAHkECAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACABAAJwEQACjBKoEsgQIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAC6BMIECAAIAAgACAAIAAgACABmBAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgAxwQIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAGYECAAIAAgAzgQIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgAigWKBYoFigWKBYoFigWKBd0FXwUIAOIF6gXxBYoF3gT5BQAGCAaKBYoFigWKBYoFigWKBYoFigWKBYoFigXWBIoFigWKBYoFigWKBYoFigWKBYsFEAaKBYoFigWKBYoFigWKBRQGCACKBYoFigWKBQgACAAIANEECAAIABgGigUgBggAJgYIAC4GMwaKBYoF0wQ3Bj4GigWKBYoFigWKBYoFigWKBYoFigWKBYoFigUIAAgACAAIAAgACAAIAAgAigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWKBYoFigWLBf///////wQABAAEAAQABAAEAAQABAAEAAQAAwAEAAQAAgAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAQADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAUABQAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAAAUAAAAFAAUAAAAFAAUAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEAAQABAAEAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAUABQAFAAUABQAFAAUABQAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAUABQAFAAUAAQAAAAUABQAFAAUABQAFAAAAAAAFAAUAAAAFAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAFAAUABQAFAAUABQAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAFAAUABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAFAAUAAQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABwAFAAUABQAFAAAABwAHAAcAAAAHAAcABwAFAAEAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAcABwAFAAUABQAFAAcABwAFAAUAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAAAAQABAAAAAAAAAAAAAAAFAAUABQAFAAAABwAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAHAAcABwAHAAcAAAAHAAcAAAAAAAUABQAHAAUAAQAHAAEABwAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAUABQAFAAUABwABAAUABQAFAAUAAAAAAAAAAAAAAAEAAQABAAEAAQABAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABwAFAAUAAAAAAAAAAAAAAAAABQAFAAUABQAFAAUAAQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQABQANAAQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQABAAEAAQABAAEAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEAAQABAAEAAQABAAEAAQABAAEAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAQABAAEAAQABAAEAAQABAAAAAAAAAAAAAAAAAAAAAAABQAHAAUABQAFAAAAAAAAAAcABQAFAAUABQAFAAQABAAEAAQABAAEAAQABAAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAEAAQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAUAAAAFAAUABQAFAAUAAAAFAAUABQAAAAUABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAAAAAAAAAAAAUABQAFAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAHAAUAAAAHAAcABwAFAAUABQAFAAUABQAFAAUABwAHAAcABwAFAAcABwAAAAUABQAFAAUABQAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABwAHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAUABwAHAAUABQAFAAUAAAAAAAcABwAAAAAABwAHAAUAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAABQAFAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAABwAHAAcABQAFAAAAAAAAAAAABQAFAAAAAAAFAAUABQAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAABwAFAAUABQAFAAUAAAAFAAUABwAAAAcABwAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAFAAUABwAFAAUABQAFAAAAAAAHAAcAAAAAAAcABwAFAAAAAAAAAAAAAAAAAAAABQAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAcABwAAAAAAAAAHAAcABwAAAAcABwAHAAUAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAABQAHAAcABwAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABwAHAAcABwAAAAUABQAFAAAABQAFAAUABQAAAAAAAAAAAAAAAAAAAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAcABQAHAAcABQAHAAcAAAAFAAcABwAAAAcABwAFAAUAAAAAAAAAAAAAAAAAAAAFAAUAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAcABwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAAAAUABwAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAFAAcABwAFAAUABQAAAAUAAAAHAAcABwAHAAcABwAHAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAHAAUABQAFAAUABQAFAAUAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAUABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAABwAFAAUABQAFAAUABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAUABQAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAUAAAAFAAAAAAAAAAAABwAHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABwAFAAUABQAFAAUAAAAFAAUAAAAAAAAAAAAAAAUABQAFAAUABQAFAAUABQAFAAUABQAAAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAUABwAFAAUABQAFAAUABQAAAAUABQAHAAcABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAcABQAFAAAAAAAAAAAABQAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAcABQAFAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAHAAUABQAFAAUABQAFAAUABwAHAAcABwAHAAcABwAHAAUABwAHAAUABQAFAAUABQAFAAUABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAUABwAHAAcABwAFAAUABwAHAAcAAAAAAAAAAAAHAAcABQAHAAcABwAHAAcABwAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAcABwAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcABQAHAAUABQAFAAUABQAFAAUAAAAFAAAABQAAAAAABQAFAAUABQAFAAUABQAFAAcABwAHAAcABwAHAAUABQAFAAUABQAFAAUABQAFAAUAAAAAAAUABQAFAAUABQAHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAUABQAFAAUABwAFAAcABwAHAAcABwAFAAcABwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAFAAUABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAUABQAFAAUABwAHAAUABQAHAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAcABQAFAAcABwAHAAUABwAFAAUABQAHAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwAHAAcABwAHAAcABwAHAAUABQAFAAUABQAFAAUABQAHAAcABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAUAAAAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAcABQAFAAUABQAFAAUABQAAAAAAAAAAAAUAAAAAAAAAAAAAAAAABQAAAAAABwAFAAUAAAAAAAAAAAAAAAAABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAAABQAFAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAUABQAFAAUADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAUAAAAFAAUABQAFAAUABQAFAAUABQAFAAAAAAAAAAAABQAAAAAAAAAFAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwAHAAUABQAHAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcABwAHAAcABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAAABQAFAAUABQAFAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAUABQAFAAUABQAFAAUABQAHAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAcABwAFAAUABQAFAAcABwAFAAUABwAHAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAUABQAFAAcABwAFAAUABwAHAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAFAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAFAAUABQAAAAAABQAFAAAAAAAAAAAAAAAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcABQAFAAcABwAAAAAAAAAAAAAABwAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcABwAFAAcABwAFAAcABwAAAAcABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAUABQAAAAAAAAAAAAAAAAAFAAUABQAAAAUABQAAAAAAAAAAAAAABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAAAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcABQAHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAFAAUABwAFAAUABQAFAAUABQAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwAHAAcABQAFAAUABQAFAAUABQAFAAUABwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAcABwAFAAUABQAHAAcABQAHAAUABQAAAAAAAAAAAAAAAAAFAAAABwAHAAcABQAFAAUABQAFAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABwAHAAcABwAAAAAABwAHAAAAAAAHAAcABwAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAABwAHAAAAAAAFAAUABQAFAAUABQAFAAAAAAAAAAUABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAcABwAFAAUABQAFAAUABQAFAAUABwAHAAUABQAFAAcABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAHAAcABQAFAAUABQAFAAUABwAFAAcABwAFAAcABQAFAAcABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAHAAcABQAFAAUABQAAAAAABwAHAAcABwAFAAUABwAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcABwAHAAUABQAFAAUABQAFAAUABQAHAAcABQAHAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABwAFAAcABwAFAAUABQAFAAUABQAHAAUAAAAAAAAAAAAAAAAAAAAAAAcABwAFAAUABQAFAAcABQAFAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAcABwAFAAUABQAFAAUABQAFAAUABQAHAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAcABwAFAAUABQAFAAAAAAAFAAUABwAHAAcABwAFAAAAAAAAAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAFAAUABQAFAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAUABQAFAAUABwAHAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcABQAFAAUABQAFAAUABQAAAAUABQAFAAUABQAFAAcABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUAAAAHAAUABQAFAAUABQAFAAUABwAFAAUABwAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAUABQAFAAUAAAAAAAAABQAAAAUABQAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAcABwAHAAcAAAAFAAUAAAAHAAcABQAHAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABwAHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAFAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAAAAAAAAAAAAAAAAAAABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcABwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAAAAUABQAFAAAAAAAFAAUABQAFAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAAAAAAAAAAABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUABQAFAAUABQAAAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAUABQAFAAUABQAAAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAFAAUABQAAAAAABQAFAAUABQAFAAUABQAAAAUABQAAAAUABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUABQAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAFAAUABQAFAAUABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAFAAUABQAFAAUADgAOAA4ADgAOAA4ADwAPAA8ADwAPAA8ADwAPAA8ADwAPAA8ADwAPAA8ADwAPAA8ADwAPAA8ADwAPAA8ADwAPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcABwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwAHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAcABwAHAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAAAAAAAAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAKAAoACgAKAAoACgAKAAoACgAKAAoACgAKAAoACgAKAAoACgAKAAoACgAKAAoACgAMAAwADAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkAAAAAAAAAAAAKAAoACgAKAAoACgAKAAoACgAKAAoACgAKAAoACgAKAAoACgAKAAoACgAKAAoACgAKAAoACgAKAAoACgAKAAoACgAAAAAAAAAAAAsADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwACwAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAMAAwADAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAA4ADgAOAA4ADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4ADgAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAOAA4ADgAOAA4ADgAOAA4ADgAOAAAAAAAAAAAADgAOAA4AAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAOAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAOAA4ADgAAAA4ADgAOAA4ADgAOAAAADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4AAAAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4AAAAAAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAAAA4AAAAOAAAAAAAAAAAAAAAAAA4AAAAAAAAAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAA4ADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAADgAAAAAAAAAAAA4AAAAOAAAAAAAAAAAADgAOAA4AAAAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAA4ADgAOAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAA4ADgAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4ADgAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAA4ADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4ADgAOAA4ADgAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4ADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAADgAOAA4ADgAOAA4ADgAOAA4ADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAAAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4AAAAAAA4ADgAOAA4ADgAOAA4ADgAOAAAADgAOAA4ADgAAAAAAAAAAAAAAAAAAAAAAAAAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4AAAAAAAAAAAAAAAAADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAA4ADgAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAOAA4ADgAOAA4ADgAOAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAOAA4ADgAOAA4AAAAAAAAAAAAAAAAAAAAAAA4ADgAOAA4ADgAOAA4ADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4AAAAOAA4ADgAOAA4ADgAAAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4ADgAOAA4AAAAAAAAAAAA='; - -/* - * utrie 1.0.2 - * Copyright (c) 2022 Niklas von Hertzen - * Released under MIT License - */ -var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; -// Use a lookup table to find the index. -var lookup$1 = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256); -for (var i$1 = 0; i$1 < chars$1.length; i$1++) { - lookup$1[chars$1.charCodeAt(i$1)] = i$1; -} -var decode = function (base64) { - var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4; - if (base64[base64.length - 1] === '=') { - bufferLength--; - if (base64[base64.length - 2] === '=') { - bufferLength--; - } - } - var buffer = typeof ArrayBuffer !== 'undefined' && - typeof Uint8Array !== 'undefined' && - typeof Uint8Array.prototype.slice !== 'undefined' - ? new ArrayBuffer(bufferLength) - : new Array(bufferLength); - var bytes = Array.isArray(buffer) ? buffer : new Uint8Array(buffer); - for (i = 0; i < len; i += 4) { - encoded1 = lookup$1[base64.charCodeAt(i)]; - encoded2 = lookup$1[base64.charCodeAt(i + 1)]; - encoded3 = lookup$1[base64.charCodeAt(i + 2)]; - encoded4 = lookup$1[base64.charCodeAt(i + 3)]; - bytes[p++] = (encoded1 << 2) | (encoded2 >> 4); - bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2); - bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63); - } - return buffer; -}; -var polyUint16Array = function (buffer) { - var length = buffer.length; - var bytes = []; - for (var i = 0; i < length; i += 2) { - bytes.push((buffer[i + 1] << 8) | buffer[i]); - } - return bytes; -}; -var polyUint32Array = function (buffer) { - var length = buffer.length; - var bytes = []; - for (var i = 0; i < length; i += 4) { - bytes.push((buffer[i + 3] << 24) | (buffer[i + 2] << 16) | (buffer[i + 1] << 8) | buffer[i]); - } - return bytes; -}; - -/** Shift size for getting the index-2 table offset. */ -var UTRIE2_SHIFT_2 = 5; -/** Shift size for getting the index-1 table offset. */ -var UTRIE2_SHIFT_1 = 6 + 5; -/** - * Shift size for shifting left the index array values. - * Increases possible data size with 16-bit index values at the cost - * of compactability. - * This requires data blocks to be aligned by UTRIE2_DATA_GRANULARITY. - */ -var UTRIE2_INDEX_SHIFT = 2; -/** - * Difference between the two shift sizes, - * for getting an index-1 offset from an index-2 offset. 6=11-5 - */ -var UTRIE2_SHIFT_1_2 = UTRIE2_SHIFT_1 - UTRIE2_SHIFT_2; -/** - * The part of the index-2 table for U+D800..U+DBFF stores values for - * lead surrogate code _units_ not code _points_. - * Values for lead surrogate code _points_ are indexed with this portion of the table. - * Length=32=0x20=0x400>>UTRIE2_SHIFT_2. (There are 1024=0x400 lead surrogates.) - */ -var UTRIE2_LSCP_INDEX_2_OFFSET = 0x10000 >> UTRIE2_SHIFT_2; -/** Number of entries in a data block. 32=0x20 */ -var UTRIE2_DATA_BLOCK_LENGTH = 1 << UTRIE2_SHIFT_2; -/** Mask for getting the lower bits for the in-data-block offset. */ -var UTRIE2_DATA_MASK = UTRIE2_DATA_BLOCK_LENGTH - 1; -var UTRIE2_LSCP_INDEX_2_LENGTH = 0x400 >> UTRIE2_SHIFT_2; -/** Count the lengths of both BMP pieces. 2080=0x820 */ -var UTRIE2_INDEX_2_BMP_LENGTH = UTRIE2_LSCP_INDEX_2_OFFSET + UTRIE2_LSCP_INDEX_2_LENGTH; -/** - * The 2-byte UTF-8 version of the index-2 table follows at offset 2080=0x820. - * Length 32=0x20 for lead bytes C0..DF, regardless of UTRIE2_SHIFT_2. - */ -var UTRIE2_UTF8_2B_INDEX_2_OFFSET = UTRIE2_INDEX_2_BMP_LENGTH; -var UTRIE2_UTF8_2B_INDEX_2_LENGTH = 0x800 >> 6; /* U+0800 is the first code point after 2-byte UTF-8 */ -/** - * The index-1 table, only used for supplementary code points, at offset 2112=0x840. - * Variable length, for code points up to highStart, where the last single-value range starts. - * Maximum length 512=0x200=0x100000>>UTRIE2_SHIFT_1. - * (For 0x100000 supplementary code points U+10000..U+10ffff.) - * - * The part of the index-2 table for supplementary code points starts - * after this index-1 table. - * - * Both the index-1 table and the following part of the index-2 table - * are omitted completely if there is only BMP data. - */ -var UTRIE2_INDEX_1_OFFSET = UTRIE2_UTF8_2B_INDEX_2_OFFSET + UTRIE2_UTF8_2B_INDEX_2_LENGTH; -/** - * Number of index-1 entries for the BMP. 32=0x20 - * This part of the index-1 table is omitted from the serialized form. - */ -var UTRIE2_OMITTED_BMP_INDEX_1_LENGTH = 0x10000 >> UTRIE2_SHIFT_1; -/** Number of entries in an index-2 block. 64=0x40 */ -var UTRIE2_INDEX_2_BLOCK_LENGTH = 1 << UTRIE2_SHIFT_1_2; -/** Mask for getting the lower bits for the in-index-2-block offset. */ -var UTRIE2_INDEX_2_MASK = UTRIE2_INDEX_2_BLOCK_LENGTH - 1; -var slice16 = function (view, start, end) { - if (view.slice) { - return view.slice(start, end); - } - return new Uint16Array(Array.prototype.slice.call(view, start, end)); -}; -var slice32 = function (view, start, end) { - if (view.slice) { - return view.slice(start, end); - } - return new Uint32Array(Array.prototype.slice.call(view, start, end)); -}; -var createTrieFromBase64 = function (base64, _byteLength) { - var buffer = decode(base64); - var view32 = Array.isArray(buffer) ? polyUint32Array(buffer) : new Uint32Array(buffer); - var view16 = Array.isArray(buffer) ? polyUint16Array(buffer) : new Uint16Array(buffer); - var headerLength = 24; - var index = slice16(view16, headerLength / 2, view32[4] / 2); - var data = view32[5] === 2 - ? slice16(view16, (headerLength + view32[4]) / 2) - : slice32(view32, Math.ceil((headerLength + view32[4]) / 4)); - return new Trie(view32[0], view32[1], view32[2], view32[3], index, data); -}; -var Trie = /** @class */ (function () { - function Trie(initialValue, errorValue, highStart, highValueIndex, index, data) { - this.initialValue = initialValue; - this.errorValue = errorValue; - this.highStart = highStart; - this.highValueIndex = highValueIndex; - this.index = index; - this.data = data; - } - /** - * Get the value for a code point as stored in the Trie. - * - * @param codePoint the code point - * @return the value - */ - Trie.prototype.get = function (codePoint) { - var ix; - if (codePoint >= 0) { - if (codePoint < 0x0d800 || (codePoint > 0x0dbff && codePoint <= 0x0ffff)) { - // Ordinary BMP code point, excluding leading surrogates. - // BMP uses a single level lookup. BMP index starts at offset 0 in the Trie2 index. - // 16 bit data is stored in the index array itself. - ix = this.index[codePoint >> UTRIE2_SHIFT_2]; - ix = (ix << UTRIE2_INDEX_SHIFT) + (codePoint & UTRIE2_DATA_MASK); - return this.data[ix]; - } - if (codePoint <= 0xffff) { - // Lead Surrogate Code Point. A Separate index section is stored for - // lead surrogate code units and code points. - // The main index has the code unit data. - // For this function, we need the code point data. - // Note: this expression could be refactored for slightly improved efficiency, but - // surrogate code points will be so rare in practice that it's not worth it. - ix = this.index[UTRIE2_LSCP_INDEX_2_OFFSET + ((codePoint - 0xd800) >> UTRIE2_SHIFT_2)]; - ix = (ix << UTRIE2_INDEX_SHIFT) + (codePoint & UTRIE2_DATA_MASK); - return this.data[ix]; - } - if (codePoint < this.highStart) { - // Supplemental code point, use two-level lookup. - ix = UTRIE2_INDEX_1_OFFSET - UTRIE2_OMITTED_BMP_INDEX_1_LENGTH + (codePoint >> UTRIE2_SHIFT_1); - ix = this.index[ix]; - ix += (codePoint >> UTRIE2_SHIFT_2) & UTRIE2_INDEX_2_MASK; - ix = this.index[ix]; - ix = (ix << UTRIE2_INDEX_SHIFT) + (codePoint & UTRIE2_DATA_MASK); - return this.data[ix]; - } - if (codePoint <= 0x10ffff) { - return this.data[this.highValueIndex]; - } - } - // Fall through. The code point is outside of the legal range of 0..0x10ffff. - return this.errorValue; - }; - return Trie; -}()); - -/* - * base64-arraybuffer 1.0.2 - * Copyright (c) 2022 Niklas von Hertzen - * Released under MIT License - */ -var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; -// Use a lookup table to find the index. -var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256); -for (var i = 0; i < chars.length; i++) { - lookup[chars.charCodeAt(i)] = i; -} - -var Prepend = 1; -var CR = 2; -var LF = 3; -var Control = 4; -var Extend = 5; -var SpacingMark = 7; -var L = 8; -var V = 9; -var T = 10; -var LV = 11; -var LVT = 12; -var ZWJ = 13; -var Extended_Pictographic = 14; -var RI = 15; -var toCodePoints = function (str) { - var codePoints = []; - var i = 0; - var length = str.length; - while (i < length) { - var value = str.charCodeAt(i++); - if (value >= 0xd800 && value <= 0xdbff && i < length) { - var extra = str.charCodeAt(i++); - if ((extra & 0xfc00) === 0xdc00) { - codePoints.push(((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000); - } - else { - codePoints.push(value); - i--; - } - } - else { - codePoints.push(value); - } - } - return codePoints; -}; -var fromCodePoint = function () { - var codePoints = []; - for (var _i = 0; _i < arguments.length; _i++) { - codePoints[_i] = arguments[_i]; - } - if (String.fromCodePoint) { - return String.fromCodePoint.apply(String, codePoints); - } - var length = codePoints.length; - if (!length) { - return ''; - } - var codeUnits = []; - var index = -1; - var result = ''; - while (++index < length) { - var codePoint = codePoints[index]; - if (codePoint <= 0xffff) { - codeUnits.push(codePoint); - } - else { - codePoint -= 0x10000; - codeUnits.push((codePoint >> 10) + 0xd800, (codePoint % 0x400) + 0xdc00); - } - if (index + 1 === length || codeUnits.length > 0x4000) { - result += String.fromCharCode.apply(String, codeUnits); - codeUnits.length = 0; - } - } - return result; -}; -var UnicodeTrie = createTrieFromBase64(base64); -var BREAK_NOT_ALLOWED = '×'; -var BREAK_ALLOWED = '÷'; -var codePointToClass = function (codePoint) { return UnicodeTrie.get(codePoint); }; -var _graphemeBreakAtIndex = function (_codePoints, classTypes, index) { - var prevIndex = index - 2; - var prev = classTypes[prevIndex]; - var current = classTypes[index - 1]; - var next = classTypes[index]; - // GB3 Do not break between a CR and LF - if (current === CR && next === LF) { - return BREAK_NOT_ALLOWED; - } - // GB4 Otherwise, break before and after controls. - if (current === CR || current === LF || current === Control) { - return BREAK_ALLOWED; - } - // GB5 - if (next === CR || next === LF || next === Control) { - return BREAK_ALLOWED; - } - // Do not break Hangul syllable sequences. - // GB6 - if (current === L && [L, V, LV, LVT].indexOf(next) !== -1) { - return BREAK_NOT_ALLOWED; - } - // GB7 - if ((current === LV || current === V) && (next === V || next === T)) { - return BREAK_NOT_ALLOWED; - } - // GB8 - if ((current === LVT || current === T) && next === T) { - return BREAK_NOT_ALLOWED; - } - // GB9 Do not break before extending characters or ZWJ. - if (next === ZWJ || next === Extend) { - return BREAK_NOT_ALLOWED; - } - // Do not break before SpacingMarks, or after Prepend characters. - // GB9a - if (next === SpacingMark) { - return BREAK_NOT_ALLOWED; - } - // GB9a - if (current === Prepend) { - return BREAK_NOT_ALLOWED; - } - // GB11 Do not break within emoji modifier sequences or emoji zwj sequences. - if (current === ZWJ && next === Extended_Pictographic) { - while (prev === Extend) { - prev = classTypes[--prevIndex]; - } - if (prev === Extended_Pictographic) { - return BREAK_NOT_ALLOWED; - } - } - // GB12 Do not break within emoji flag sequences. - // That is, do not break between regional indicator (RI) symbols - // if there is an odd number of RI characters before the break point. - if (current === RI && next === RI) { - var countRI = 0; - while (prev === RI) { - countRI++; - prev = classTypes[--prevIndex]; - } - if (countRI % 2 === 0) { - return BREAK_NOT_ALLOWED; - } - } - return BREAK_ALLOWED; -}; -var GraphemeBreaker = function (str) { - var codePoints = toCodePoints(str); - var length = codePoints.length; - var index = 0; - var lastEnd = 0; - var classTypes = codePoints.map(codePointToClass); - return { - next: function () { - if (index >= length) { - return { done: true, value: null }; - } - var graphemeBreak = BREAK_NOT_ALLOWED; - while (index < length && - (graphemeBreak = _graphemeBreakAtIndex(codePoints, classTypes, ++index)) === BREAK_NOT_ALLOWED) { } - if (graphemeBreak !== BREAK_NOT_ALLOWED || index === length) { - var value = fromCodePoint.apply(null, codePoints.slice(lastEnd, index)); - lastEnd = index; - return { value: value, done: false }; - } - return { done: true, value: null }; - }, - }; -}; -var splitGraphemes = function (str) { - var breaker = GraphemeBreaker(str); - var graphemes = []; - var bk; - while (!(bk = breaker.next()).done) { - if (bk.value) { - graphemes.push(bk.value.slice()); - } - } - return graphemes; -}; - -var testRangeBounds = function (document) { - var TEST_HEIGHT = 123; - if (document.createRange) { - var range = document.createRange(); - if (range.getBoundingClientRect) { - var testElement = document.createElement('boundtest'); - testElement.style.height = TEST_HEIGHT + "px"; - testElement.style.display = 'block'; - document.body.appendChild(testElement); - range.selectNode(testElement); - var rangeBounds = range.getBoundingClientRect(); - var rangeHeight = Math.round(rangeBounds.height); - document.body.removeChild(testElement); - if (rangeHeight === TEST_HEIGHT) { - return true; - } - } - } - return false; -}; -var testIOSLineBreak = function (document) { - var testElement = document.createElement('boundtest'); - testElement.style.width = '50px'; - testElement.style.display = 'block'; - testElement.style.fontSize = '12px'; - testElement.style.letterSpacing = '0px'; - testElement.style.wordSpacing = '0px'; - document.body.appendChild(testElement); - var range = document.createRange(); - testElement.innerHTML = typeof ''.repeat === 'function' ? '👨'.repeat(10) : ''; - var node = testElement.firstChild; - var textList = toCodePoints$1(node.data).map(function (i) { return fromCodePoint$1(i); }); - var offset = 0; - var prev = {}; - // ios 13 does not handle range getBoundingClientRect line changes correctly #2177 - var supports = textList.every(function (text, i) { - range.setStart(node, offset); - range.setEnd(node, offset + text.length); - var rect = range.getBoundingClientRect(); - offset += text.length; - var boundAhead = rect.x > prev.x || rect.y > prev.y; - prev = rect; - if (i === 0) { - return true; - } - return boundAhead; - }); - document.body.removeChild(testElement); - return supports; -}; -var testCORS = function () { return typeof new Image().crossOrigin !== 'undefined'; }; -var testResponseType = function () { return typeof new XMLHttpRequest().responseType === 'string'; }; -var testSVG = function (document) { - var img = new Image(); - var canvas = document.createElement('canvas'); - var ctx = canvas.getContext('2d'); - if (!ctx) { - return false; - } - img.src = "data:image/svg+xml,"; - try { - ctx.drawImage(img, 0, 0); - canvas.toDataURL(); - } - catch (e) { - return false; - } - return true; -}; -var isGreenPixel = function (data) { - return data[0] === 0 && data[1] === 255 && data[2] === 0 && data[3] === 255; -}; -var testForeignObject = function (document) { - var canvas = document.createElement('canvas'); - var size = 100; - canvas.width = size; - canvas.height = size; - var ctx = canvas.getContext('2d'); - if (!ctx) { - return Promise.reject(false); - } - ctx.fillStyle = 'rgb(0, 255, 0)'; - ctx.fillRect(0, 0, size, size); - var img = new Image(); - var greenImageSrc = canvas.toDataURL(); - img.src = greenImageSrc; - var svg = createForeignObjectSVG(size, size, 0, 0, img); - ctx.fillStyle = 'red'; - ctx.fillRect(0, 0, size, size); - return loadSerializedSVG$1(svg) - .then(function (img) { - ctx.drawImage(img, 0, 0); - var data = ctx.getImageData(0, 0, size, size).data; - ctx.fillStyle = 'red'; - ctx.fillRect(0, 0, size, size); - var node = document.createElement('div'); - node.style.backgroundImage = "url(" + greenImageSrc + ")"; - node.style.height = size + "px"; - // Firefox 55 does not render inline tags - return isGreenPixel(data) - ? loadSerializedSVG$1(createForeignObjectSVG(size, size, 0, 0, node)) - : Promise.reject(false); - }) - .then(function (img) { - ctx.drawImage(img, 0, 0); - // Edge does not render background-images - return isGreenPixel(ctx.getImageData(0, 0, size, size).data); - }) - .catch(function () { return false; }); -}; -var createForeignObjectSVG = function (width, height, x, y, node) { - var xmlns = 'http://www.w3.org/2000/svg'; - var svg = document.createElementNS(xmlns, 'svg'); - var foreignObject = document.createElementNS(xmlns, 'foreignObject'); - svg.setAttributeNS(null, 'width', width.toString()); - svg.setAttributeNS(null, 'height', height.toString()); - foreignObject.setAttributeNS(null, 'width', '100%'); - foreignObject.setAttributeNS(null, 'height', '100%'); - foreignObject.setAttributeNS(null, 'x', x.toString()); - foreignObject.setAttributeNS(null, 'y', y.toString()); - foreignObject.setAttributeNS(null, 'externalResourcesRequired', 'true'); - svg.appendChild(foreignObject); - foreignObject.appendChild(node); - return svg; -}; -var loadSerializedSVG$1 = function (svg) { - return new Promise(function (resolve, reject) { - var img = new Image(); - img.onload = function () { return resolve(img); }; - img.onerror = reject; - img.src = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(new XMLSerializer().serializeToString(svg)); - }); -}; -var FEATURES = { - get SUPPORT_RANGE_BOUNDS() { - var value = testRangeBounds(document); - Object.defineProperty(FEATURES, 'SUPPORT_RANGE_BOUNDS', { value: value }); - return value; - }, - get SUPPORT_WORD_BREAKING() { - var value = FEATURES.SUPPORT_RANGE_BOUNDS && testIOSLineBreak(document); - Object.defineProperty(FEATURES, 'SUPPORT_WORD_BREAKING', { value: value }); - return value; - }, - get SUPPORT_SVG_DRAWING() { - var value = testSVG(document); - Object.defineProperty(FEATURES, 'SUPPORT_SVG_DRAWING', { value: value }); - return value; - }, - get SUPPORT_FOREIGNOBJECT_DRAWING() { - var value = typeof Array.from === 'function' && typeof window.fetch === 'function' - ? testForeignObject(document) - : Promise.resolve(false); - Object.defineProperty(FEATURES, 'SUPPORT_FOREIGNOBJECT_DRAWING', { value: value }); - return value; - }, - get SUPPORT_CORS_IMAGES() { - var value = testCORS(); - Object.defineProperty(FEATURES, 'SUPPORT_CORS_IMAGES', { value: value }); - return value; - }, - get SUPPORT_RESPONSE_TYPE() { - var value = testResponseType(); - Object.defineProperty(FEATURES, 'SUPPORT_RESPONSE_TYPE', { value: value }); - return value; - }, - get SUPPORT_CORS_XHR() { - var value = 'withCredentials' in new XMLHttpRequest(); - Object.defineProperty(FEATURES, 'SUPPORT_CORS_XHR', { value: value }); - return value; - }, - get SUPPORT_NATIVE_TEXT_SEGMENTATION() { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - var value = !!(typeof Intl !== 'undefined' && Intl.Segmenter); - Object.defineProperty(FEATURES, 'SUPPORT_NATIVE_TEXT_SEGMENTATION', { value: value }); - return value; - } -}; - -var TextBounds = /** @class */ (function () { - function TextBounds(text, bounds) { - this.text = text; - this.bounds = bounds; - } - return TextBounds; -}()); -var parseTextBounds = function (context, value, styles, node) { - var textList = breakText(value, styles); - var textBounds = []; - var offset = 0; - textList.forEach(function (text) { - if (styles.textDecorationLine.length || text.trim().length > 0) { - if (FEATURES.SUPPORT_RANGE_BOUNDS) { - var clientRects = createRange(node, offset, text.length).getClientRects(); - if (clientRects.length > 1) { - var subSegments = segmentGraphemes(text); - var subOffset_1 = 0; - subSegments.forEach(function (subSegment) { - textBounds.push(new TextBounds(subSegment, Bounds.fromDOMRectList(context, createRange(node, subOffset_1 + offset, subSegment.length).getClientRects()))); - subOffset_1 += subSegment.length; - }); - } - else { - textBounds.push(new TextBounds(text, Bounds.fromDOMRectList(context, clientRects))); - } - } - else { - var replacementNode = node.splitText(text.length); - textBounds.push(new TextBounds(text, getWrapperBounds(context, node))); - node = replacementNode; - } - } - else if (!FEATURES.SUPPORT_RANGE_BOUNDS) { - node = node.splitText(text.length); - } - offset += text.length; - }); - return textBounds; -}; -var getWrapperBounds = function (context, node) { - var ownerDocument = node.ownerDocument; - if (ownerDocument) { - var wrapper = ownerDocument.createElement('html2canvaswrapper'); - wrapper.appendChild(node.cloneNode(true)); - var parentNode = node.parentNode; - if (parentNode) { - parentNode.replaceChild(wrapper, node); - var bounds = parseBounds(context, wrapper); - if (wrapper.firstChild) { - parentNode.replaceChild(wrapper.firstChild, wrapper); - } - return bounds; - } - } - return Bounds.EMPTY; -}; -var createRange = function (node, offset, length) { - var ownerDocument = node.ownerDocument; - if (!ownerDocument) { - throw new Error('Node has no owner document'); - } - var range = ownerDocument.createRange(); - range.setStart(node, offset); - range.setEnd(node, offset + length); - return range; -}; -var segmentGraphemes = function (value) { - if (FEATURES.SUPPORT_NATIVE_TEXT_SEGMENTATION) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - var segmenter = new Intl.Segmenter(void 0, { granularity: 'grapheme' }); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return Array.from(segmenter.segment(value)).map(function (segment) { return segment.segment; }); - } - return splitGraphemes(value); -}; -var segmentWords = function (value, styles) { - if (FEATURES.SUPPORT_NATIVE_TEXT_SEGMENTATION) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - var segmenter = new Intl.Segmenter(void 0, { - granularity: 'word' - }); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return Array.from(segmenter.segment(value)).map(function (segment) { return segment.segment; }); - } - return breakWords(value, styles); -}; -var breakText = function (value, styles) { - return styles.letterSpacing !== 0 ? segmentGraphemes(value) : segmentWords(value, styles); -}; -// https://drafts.csswg.org/css-text/#word-separator -var wordSeparators = [0x0020, 0x00a0, 0x1361, 0x10100, 0x10101, 0x1039, 0x1091]; -var breakWords = function (str, styles) { - var breaker = LineBreaker(str, { - lineBreak: styles.lineBreak, - wordBreak: styles.overflowWrap === "break-word" /* BREAK_WORD */ ? 'break-word' : styles.wordBreak - }); - var words = []; - var bk; - var _loop_1 = function () { - if (bk.value) { - var value = bk.value.slice(); - var codePoints = toCodePoints$1(value); - var word_1 = ''; - codePoints.forEach(function (codePoint) { - if (wordSeparators.indexOf(codePoint) === -1) { - word_1 += fromCodePoint$1(codePoint); - } - else { - if (word_1.length) { - words.push(word_1); - } - words.push(fromCodePoint$1(codePoint)); - word_1 = ''; - } - }); - if (word_1.length) { - words.push(word_1); - } - } - }; - while (!(bk = breaker.next()).done) { - _loop_1(); - } - return words; -}; - -var TextContainer = /** @class */ (function () { - function TextContainer(context, node, styles) { - this.text = transform(node.data, styles.textTransform); - this.textBounds = parseTextBounds(context, this.text, styles, node); - } - return TextContainer; -}()); -var transform = function (text, transform) { - switch (transform) { - case 1 /* LOWERCASE */: - return text.toLowerCase(); - case 3 /* CAPITALIZE */: - return text.replace(CAPITALIZE, capitalize); - case 2 /* UPPERCASE */: - return text.toUpperCase(); - default: - return text; - } -}; -var CAPITALIZE = /(^|\s|:|-|\(|\))([a-z])/g; -var capitalize = function (m, p1, p2) { - if (m.length > 0) { - return p1 + p2.toUpperCase(); - } - return m; -}; - -var ImageElementContainer = /** @class */ (function (_super) { - __extends(ImageElementContainer, _super); - function ImageElementContainer(context, img) { - var _this = _super.call(this, context, img) || this; - _this.src = img.currentSrc || img.src; - _this.intrinsicWidth = img.naturalWidth; - _this.intrinsicHeight = img.naturalHeight; - _this.context.cache.addImage(_this.src); - return _this; - } - return ImageElementContainer; -}(ElementContainer)); - -var CanvasElementContainer = /** @class */ (function (_super) { - __extends(CanvasElementContainer, _super); - function CanvasElementContainer(context, canvas) { - var _this = _super.call(this, context, canvas) || this; - _this.canvas = canvas; - _this.intrinsicWidth = canvas.width; - _this.intrinsicHeight = canvas.height; - return _this; - } - return CanvasElementContainer; -}(ElementContainer)); - -var SVGElementContainer = /** @class */ (function (_super) { - __extends(SVGElementContainer, _super); - function SVGElementContainer(context, img) { - var _this = _super.call(this, context, img) || this; - var s = new XMLSerializer(); - var bounds = parseBounds(context, img); - img.setAttribute('width', bounds.width + "px"); - img.setAttribute('height', bounds.height + "px"); - _this.svg = "data:image/svg+xml," + encodeURIComponent(s.serializeToString(img)); - _this.intrinsicWidth = img.width.baseVal.value; - _this.intrinsicHeight = img.height.baseVal.value; - _this.context.cache.addImage(_this.svg); - return _this; - } - return SVGElementContainer; -}(ElementContainer)); - -var LIElementContainer = /** @class */ (function (_super) { - __extends(LIElementContainer, _super); - function LIElementContainer(context, element) { - var _this = _super.call(this, context, element) || this; - _this.value = element.value; - return _this; - } - return LIElementContainer; -}(ElementContainer)); - -var OLElementContainer = /** @class */ (function (_super) { - __extends(OLElementContainer, _super); - function OLElementContainer(context, element) { - var _this = _super.call(this, context, element) || this; - _this.start = element.start; - _this.reversed = typeof element.reversed === 'boolean' && element.reversed === true; - return _this; - } - return OLElementContainer; -}(ElementContainer)); - -var CHECKBOX_BORDER_RADIUS = [ - { - type: 15 /* DIMENSION_TOKEN */, - flags: 0, - unit: 'px', - number: 3 - } -]; -var RADIO_BORDER_RADIUS = [ - { - type: 16 /* PERCENTAGE_TOKEN */, - flags: 0, - number: 50 - } -]; -var reformatInputBounds = function (bounds) { - if (bounds.width > bounds.height) { - return new Bounds(bounds.left + (bounds.width - bounds.height) / 2, bounds.top, bounds.height, bounds.height); - } - else if (bounds.width < bounds.height) { - return new Bounds(bounds.left, bounds.top + (bounds.height - bounds.width) / 2, bounds.width, bounds.width); - } - return bounds; -}; -var getInputValue = function (node) { - var value = node.type === PASSWORD ? new Array(node.value.length + 1).join('\u2022') : node.value; - return value.length === 0 ? node.placeholder || '' : value; -}; -var CHECKBOX = 'checkbox'; -var RADIO = 'radio'; -var PASSWORD = 'password'; -var INPUT_COLOR = 0x2a2a2aff; -var InputElementContainer = /** @class */ (function (_super) { - __extends(InputElementContainer, _super); - function InputElementContainer(context, input) { - var _this = _super.call(this, context, input) || this; - _this.type = input.type.toLowerCase(); - _this.checked = input.checked; - _this.value = getInputValue(input); - if (_this.type === CHECKBOX || _this.type === RADIO) { - _this.styles.backgroundColor = 0xdededeff; - _this.styles.borderTopColor = - _this.styles.borderRightColor = - _this.styles.borderBottomColor = - _this.styles.borderLeftColor = - 0xa5a5a5ff; - _this.styles.borderTopWidth = - _this.styles.borderRightWidth = - _this.styles.borderBottomWidth = - _this.styles.borderLeftWidth = - 1; - _this.styles.borderTopStyle = - _this.styles.borderRightStyle = - _this.styles.borderBottomStyle = - _this.styles.borderLeftStyle = - 1 /* SOLID */; - _this.styles.backgroundClip = [0 /* BORDER_BOX */]; - _this.styles.backgroundOrigin = [0 /* BORDER_BOX */]; - _this.bounds = reformatInputBounds(_this.bounds); - } - switch (_this.type) { - case CHECKBOX: - _this.styles.borderTopRightRadius = - _this.styles.borderTopLeftRadius = - _this.styles.borderBottomRightRadius = - _this.styles.borderBottomLeftRadius = - CHECKBOX_BORDER_RADIUS; - break; - case RADIO: - _this.styles.borderTopRightRadius = - _this.styles.borderTopLeftRadius = - _this.styles.borderBottomRightRadius = - _this.styles.borderBottomLeftRadius = - RADIO_BORDER_RADIUS; - break; - } - return _this; - } - return InputElementContainer; -}(ElementContainer)); - -var SelectElementContainer = /** @class */ (function (_super) { - __extends(SelectElementContainer, _super); - function SelectElementContainer(context, element) { - var _this = _super.call(this, context, element) || this; - var option = element.options[element.selectedIndex || 0]; - _this.value = option ? option.text || '' : ''; - return _this; - } - return SelectElementContainer; -}(ElementContainer)); - -var TextareaElementContainer = /** @class */ (function (_super) { - __extends(TextareaElementContainer, _super); - function TextareaElementContainer(context, element) { - var _this = _super.call(this, context, element) || this; - _this.value = element.value; - return _this; - } - return TextareaElementContainer; -}(ElementContainer)); - -var IFrameElementContainer = /** @class */ (function (_super) { - __extends(IFrameElementContainer, _super); - function IFrameElementContainer(context, iframe) { - var _this = _super.call(this, context, iframe) || this; - _this.src = iframe.src; - _this.width = parseInt(iframe.width, 10) || 0; - _this.height = parseInt(iframe.height, 10) || 0; - _this.backgroundColor = _this.styles.backgroundColor; - try { - if (iframe.contentWindow && - iframe.contentWindow.document && - iframe.contentWindow.document.documentElement) { - _this.tree = parseTree(context, iframe.contentWindow.document.documentElement); - // http://www.w3.org/TR/css3-background/#special-backgrounds - var documentBackgroundColor = iframe.contentWindow.document.documentElement - ? parseColor(context, getComputedStyle(iframe.contentWindow.document.documentElement).backgroundColor) - : COLORS.TRANSPARENT; - var bodyBackgroundColor = iframe.contentWindow.document.body - ? parseColor(context, getComputedStyle(iframe.contentWindow.document.body).backgroundColor) - : COLORS.TRANSPARENT; - _this.backgroundColor = isTransparent(documentBackgroundColor) - ? isTransparent(bodyBackgroundColor) - ? _this.styles.backgroundColor - : bodyBackgroundColor - : documentBackgroundColor; - } - } - catch (e) { } - return _this; - } - return IFrameElementContainer; -}(ElementContainer)); - -var LIST_OWNERS = ['OL', 'UL', 'MENU']; -var parseNodeTree = function (context, node, parent, root) { - for (var childNode = node.firstChild, nextNode = void 0; childNode; childNode = nextNode) { - nextNode = childNode.nextSibling; - if (isTextNode(childNode) && childNode.data.trim().length > 0) { - parent.textNodes.push(new TextContainer(context, childNode, parent.styles)); - } - else if (isElementNode(childNode)) { - if (isSlotElement(childNode) && childNode.assignedNodes) { - childNode.assignedNodes().forEach(function (childNode) { return parseNodeTree(context, childNode, parent, root); }); - } - else { - var container = createContainer(context, childNode); - if (container.styles.isVisible()) { - if (createsRealStackingContext(childNode, container, root)) { - container.flags |= 4 /* CREATES_REAL_STACKING_CONTEXT */; - } - else if (createsStackingContext(container.styles)) { - container.flags |= 2 /* CREATES_STACKING_CONTEXT */; - } - if (LIST_OWNERS.indexOf(childNode.tagName) !== -1) { - container.flags |= 8 /* IS_LIST_OWNER */; - } - parent.elements.push(container); - childNode.slot; - if (childNode.shadowRoot) { - parseNodeTree(context, childNode.shadowRoot, container, root); - } - else if (!isTextareaElement(childNode) && - !isSVGElement(childNode) && - !isSelectElement(childNode)) { - parseNodeTree(context, childNode, container, root); - } - } - } - } - } -}; -var createContainer = function (context, element) { - if (isImageElement(element)) { - return new ImageElementContainer(context, element); - } - if (isCanvasElement(element)) { - return new CanvasElementContainer(context, element); - } - if (isSVGElement(element)) { - return new SVGElementContainer(context, element); - } - if (isLIElement(element)) { - return new LIElementContainer(context, element); - } - if (isOLElement(element)) { - return new OLElementContainer(context, element); - } - if (isInputElement(element)) { - return new InputElementContainer(context, element); - } - if (isSelectElement(element)) { - return new SelectElementContainer(context, element); - } - if (isTextareaElement(element)) { - return new TextareaElementContainer(context, element); - } - if (isIFrameElement(element)) { - return new IFrameElementContainer(context, element); - } - return new ElementContainer(context, element); -}; -var parseTree = function (context, element) { - var container = createContainer(context, element); - container.flags |= 4 /* CREATES_REAL_STACKING_CONTEXT */; - parseNodeTree(context, element, container, container); - return container; -}; -var createsRealStackingContext = function (node, container, root) { - return (container.styles.isPositionedWithZIndex() || - container.styles.opacity < 1 || - container.styles.isTransformed() || - (isBodyElement(node) && root.styles.isTransparent())); -}; -var createsStackingContext = function (styles) { return styles.isPositioned() || styles.isFloating(); }; -var isTextNode = function (node) { return node.nodeType === Node.TEXT_NODE; }; -var isElementNode = function (node) { return node.nodeType === Node.ELEMENT_NODE; }; -var isHTMLElementNode = function (node) { - return isElementNode(node) && typeof node.style !== 'undefined' && !isSVGElementNode(node); -}; -var isSVGElementNode = function (element) { - return typeof element.className === 'object'; -}; -var isLIElement = function (node) { return node.tagName === 'LI'; }; -var isOLElement = function (node) { return node.tagName === 'OL'; }; -var isInputElement = function (node) { return node.tagName === 'INPUT'; }; -var isHTMLElement = function (node) { return node.tagName === 'HTML'; }; -var isSVGElement = function (node) { return node.tagName === 'svg'; }; -var isBodyElement = function (node) { return node.tagName === 'BODY'; }; -var isCanvasElement = function (node) { return node.tagName === 'CANVAS'; }; -var isVideoElement = function (node) { return node.tagName === 'VIDEO'; }; -var isImageElement = function (node) { return node.tagName === 'IMG'; }; -var isIFrameElement = function (node) { return node.tagName === 'IFRAME'; }; -var isStyleElement = function (node) { return node.tagName === 'STYLE'; }; -var isScriptElement = function (node) { return node.tagName === 'SCRIPT'; }; -var isTextareaElement = function (node) { return node.tagName === 'TEXTAREA'; }; -var isSelectElement = function (node) { return node.tagName === 'SELECT'; }; -var isSlotElement = function (node) { return node.tagName === 'SLOT'; }; -// https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name -var isCustomElement = function (node) { return node.tagName.indexOf('-') > 0; }; - -var CounterState = /** @class */ (function () { - function CounterState() { - this.counters = {}; - } - CounterState.prototype.getCounterValue = function (name) { - var counter = this.counters[name]; - if (counter && counter.length) { - return counter[counter.length - 1]; - } - return 1; - }; - CounterState.prototype.getCounterValues = function (name) { - var counter = this.counters[name]; - return counter ? counter : []; - }; - CounterState.prototype.pop = function (counters) { - var _this = this; - counters.forEach(function (counter) { return _this.counters[counter].pop(); }); - }; - CounterState.prototype.parse = function (style) { - var _this = this; - var counterIncrement = style.counterIncrement; - var counterReset = style.counterReset; - var canReset = true; - if (counterIncrement !== null) { - counterIncrement.forEach(function (entry) { - var counter = _this.counters[entry.counter]; - if (counter && entry.increment !== 0) { - canReset = false; - if (!counter.length) { - counter.push(1); - } - counter[Math.max(0, counter.length - 1)] += entry.increment; - } - }); - } - var counterNames = []; - if (canReset) { - counterReset.forEach(function (entry) { - var counter = _this.counters[entry.counter]; - counterNames.push(entry.counter); - if (!counter) { - counter = _this.counters[entry.counter] = []; - } - counter.push(entry.reset); - }); - } - return counterNames; - }; - return CounterState; -}()); -var ROMAN_UPPER = { - integers: [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1], - values: ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'] -}; -var ARMENIAN = { - integers: [ - 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 90, 80, 70, - 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 - ], - values: [ - 'Ք', - 'Փ', - 'Ւ', - 'Ց', - 'Ր', - 'Տ', - 'Վ', - 'Ս', - 'Ռ', - 'Ջ', - 'Պ', - 'Չ', - 'Ո', - 'Շ', - 'Ն', - 'Յ', - 'Մ', - 'Ճ', - 'Ղ', - 'Ձ', - 'Հ', - 'Կ', - 'Ծ', - 'Խ', - 'Լ', - 'Ի', - 'Ժ', - 'Թ', - 'Ը', - 'Է', - 'Զ', - 'Ե', - 'Դ', - 'Գ', - 'Բ', - 'Ա' - ] -}; -var HEBREW = { - integers: [ - 10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 400, 300, 200, 100, 90, 80, 70, 60, 50, 40, 30, 20, - 19, 18, 17, 16, 15, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 - ], - values: [ - 'י׳', - 'ט׳', - 'ח׳', - 'ז׳', - 'ו׳', - 'ה׳', - 'ד׳', - 'ג׳', - 'ב׳', - 'א׳', - 'ת', - 'ש', - 'ר', - 'ק', - 'צ', - 'פ', - 'ע', - 'ס', - 'נ', - 'מ', - 'ל', - 'כ', - 'יט', - 'יח', - 'יז', - 'טז', - 'טו', - 'י', - 'ט', - 'ח', - 'ז', - 'ו', - 'ה', - 'ד', - 'ג', - 'ב', - 'א' - ] -}; -var GEORGIAN = { - integers: [ - 10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 90, - 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 - ], - values: [ - 'ჵ', - 'ჰ', - 'ჯ', - 'ჴ', - 'ხ', - 'ჭ', - 'წ', - 'ძ', - 'ც', - 'ჩ', - 'შ', - 'ყ', - 'ღ', - 'ქ', - 'ფ', - 'ჳ', - 'ტ', - 'ს', - 'რ', - 'ჟ', - 'პ', - 'ო', - 'ჲ', - 'ნ', - 'მ', - 'ლ', - 'კ', - 'ი', - 'თ', - 'ჱ', - 'ზ', - 'ვ', - 'ე', - 'დ', - 'გ', - 'ბ', - 'ა' - ] -}; -var createAdditiveCounter = function (value, min, max, symbols, fallback, suffix) { - if (value < min || value > max) { - return createCounterText(value, fallback, suffix.length > 0); - } - return (symbols.integers.reduce(function (string, integer, index) { - while (value >= integer) { - value -= integer; - string += symbols.values[index]; - } - return string; - }, '') + suffix); -}; -var createCounterStyleWithSymbolResolver = function (value, codePointRangeLength, isNumeric, resolver) { - var string = ''; - do { - if (!isNumeric) { - value--; - } - string = resolver(value) + string; - value /= codePointRangeLength; - } while (value * codePointRangeLength >= codePointRangeLength); - return string; -}; -var createCounterStyleFromRange = function (value, codePointRangeStart, codePointRangeEnd, isNumeric, suffix) { - var codePointRangeLength = codePointRangeEnd - codePointRangeStart + 1; - return ((value < 0 ? '-' : '') + - (createCounterStyleWithSymbolResolver(Math.abs(value), codePointRangeLength, isNumeric, function (codePoint) { - return fromCodePoint$1(Math.floor(codePoint % codePointRangeLength) + codePointRangeStart); - }) + - suffix)); -}; -var createCounterStyleFromSymbols = function (value, symbols, suffix) { - if (suffix === void 0) { suffix = '. '; } - var codePointRangeLength = symbols.length; - return (createCounterStyleWithSymbolResolver(Math.abs(value), codePointRangeLength, false, function (codePoint) { return symbols[Math.floor(codePoint % codePointRangeLength)]; }) + suffix); -}; -var CJK_ZEROS = 1 << 0; -var CJK_TEN_COEFFICIENTS = 1 << 1; -var CJK_TEN_HIGH_COEFFICIENTS = 1 << 2; -var CJK_HUNDRED_COEFFICIENTS = 1 << 3; -var createCJKCounter = function (value, numbers, multipliers, negativeSign, suffix, flags) { - if (value < -9999 || value > 9999) { - return createCounterText(value, 4 /* CJK_DECIMAL */, suffix.length > 0); - } - var tmp = Math.abs(value); - var string = suffix; - if (tmp === 0) { - return numbers[0] + string; - } - for (var digit = 0; tmp > 0 && digit <= 4; digit++) { - var coefficient = tmp % 10; - if (coefficient === 0 && contains(flags, CJK_ZEROS) && string !== '') { - string = numbers[coefficient] + string; - } - else if (coefficient > 1 || - (coefficient === 1 && digit === 0) || - (coefficient === 1 && digit === 1 && contains(flags, CJK_TEN_COEFFICIENTS)) || - (coefficient === 1 && digit === 1 && contains(flags, CJK_TEN_HIGH_COEFFICIENTS) && value > 100) || - (coefficient === 1 && digit > 1 && contains(flags, CJK_HUNDRED_COEFFICIENTS))) { - string = numbers[coefficient] + (digit > 0 ? multipliers[digit - 1] : '') + string; - } - else if (coefficient === 1 && digit > 0) { - string = multipliers[digit - 1] + string; - } - tmp = Math.floor(tmp / 10); - } - return (value < 0 ? negativeSign : '') + string; -}; -var CHINESE_INFORMAL_MULTIPLIERS = '十百千萬'; -var CHINESE_FORMAL_MULTIPLIERS = '拾佰仟萬'; -var JAPANESE_NEGATIVE = 'マイナス'; -var KOREAN_NEGATIVE = '마이너스'; -var createCounterText = function (value, type, appendSuffix) { - var defaultSuffix = appendSuffix ? '. ' : ''; - var cjkSuffix = appendSuffix ? '、' : ''; - var koreanSuffix = appendSuffix ? ', ' : ''; - var spaceSuffix = appendSuffix ? ' ' : ''; - switch (type) { - case 0 /* DISC */: - return '•' + spaceSuffix; - case 1 /* CIRCLE */: - return '◦' + spaceSuffix; - case 2 /* SQUARE */: - return '◾' + spaceSuffix; - case 5 /* DECIMAL_LEADING_ZERO */: - var string = createCounterStyleFromRange(value, 48, 57, true, defaultSuffix); - return string.length < 4 ? "0" + string : string; - case 4 /* CJK_DECIMAL */: - return createCounterStyleFromSymbols(value, '〇一二三四五六七八九', cjkSuffix); - case 6 /* LOWER_ROMAN */: - return createAdditiveCounter(value, 1, 3999, ROMAN_UPPER, 3 /* DECIMAL */, defaultSuffix).toLowerCase(); - case 7 /* UPPER_ROMAN */: - return createAdditiveCounter(value, 1, 3999, ROMAN_UPPER, 3 /* DECIMAL */, defaultSuffix); - case 8 /* LOWER_GREEK */: - return createCounterStyleFromRange(value, 945, 969, false, defaultSuffix); - case 9 /* LOWER_ALPHA */: - return createCounterStyleFromRange(value, 97, 122, false, defaultSuffix); - case 10 /* UPPER_ALPHA */: - return createCounterStyleFromRange(value, 65, 90, false, defaultSuffix); - case 11 /* ARABIC_INDIC */: - return createCounterStyleFromRange(value, 1632, 1641, true, defaultSuffix); - case 12 /* ARMENIAN */: - case 49 /* UPPER_ARMENIAN */: - return createAdditiveCounter(value, 1, 9999, ARMENIAN, 3 /* DECIMAL */, defaultSuffix); - case 35 /* LOWER_ARMENIAN */: - return createAdditiveCounter(value, 1, 9999, ARMENIAN, 3 /* DECIMAL */, defaultSuffix).toLowerCase(); - case 13 /* BENGALI */: - return createCounterStyleFromRange(value, 2534, 2543, true, defaultSuffix); - case 14 /* CAMBODIAN */: - case 30 /* KHMER */: - return createCounterStyleFromRange(value, 6112, 6121, true, defaultSuffix); - case 15 /* CJK_EARTHLY_BRANCH */: - return createCounterStyleFromSymbols(value, '子丑寅卯辰巳午未申酉戌亥', cjkSuffix); - case 16 /* CJK_HEAVENLY_STEM */: - return createCounterStyleFromSymbols(value, '甲乙丙丁戊己庚辛壬癸', cjkSuffix); - case 17 /* CJK_IDEOGRAPHIC */: - case 48 /* TRAD_CHINESE_INFORMAL */: - return createCJKCounter(value, '零一二三四五六七八九', CHINESE_INFORMAL_MULTIPLIERS, '負', cjkSuffix, CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS); - case 47 /* TRAD_CHINESE_FORMAL */: - return createCJKCounter(value, '零壹貳參肆伍陸柒捌玖', CHINESE_FORMAL_MULTIPLIERS, '負', cjkSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS); - case 42 /* SIMP_CHINESE_INFORMAL */: - return createCJKCounter(value, '零一二三四五六七八九', CHINESE_INFORMAL_MULTIPLIERS, '负', cjkSuffix, CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS); - case 41 /* SIMP_CHINESE_FORMAL */: - return createCJKCounter(value, '零壹贰叁肆伍陆柒捌玖', CHINESE_FORMAL_MULTIPLIERS, '负', cjkSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS | CJK_HUNDRED_COEFFICIENTS); - case 26 /* JAPANESE_INFORMAL */: - return createCJKCounter(value, '〇一二三四五六七八九', '十百千万', JAPANESE_NEGATIVE, cjkSuffix, 0); - case 25 /* JAPANESE_FORMAL */: - return createCJKCounter(value, '零壱弐参四伍六七八九', '拾百千万', JAPANESE_NEGATIVE, cjkSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS); - case 31 /* KOREAN_HANGUL_FORMAL */: - return createCJKCounter(value, '영일이삼사오육칠팔구', '십백천만', KOREAN_NEGATIVE, koreanSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS); - case 33 /* KOREAN_HANJA_INFORMAL */: - return createCJKCounter(value, '零一二三四五六七八九', '十百千萬', KOREAN_NEGATIVE, koreanSuffix, 0); - case 32 /* KOREAN_HANJA_FORMAL */: - return createCJKCounter(value, '零壹貳參四五六七八九', '拾百千', KOREAN_NEGATIVE, koreanSuffix, CJK_ZEROS | CJK_TEN_COEFFICIENTS | CJK_TEN_HIGH_COEFFICIENTS); - case 18 /* DEVANAGARI */: - return createCounterStyleFromRange(value, 0x966, 0x96f, true, defaultSuffix); - case 20 /* GEORGIAN */: - return createAdditiveCounter(value, 1, 19999, GEORGIAN, 3 /* DECIMAL */, defaultSuffix); - case 21 /* GUJARATI */: - return createCounterStyleFromRange(value, 0xae6, 0xaef, true, defaultSuffix); - case 22 /* GURMUKHI */: - return createCounterStyleFromRange(value, 0xa66, 0xa6f, true, defaultSuffix); - case 22 /* HEBREW */: - return createAdditiveCounter(value, 1, 10999, HEBREW, 3 /* DECIMAL */, defaultSuffix); - case 23 /* HIRAGANA */: - return createCounterStyleFromSymbols(value, 'あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわゐゑをん'); - case 24 /* HIRAGANA_IROHA */: - return createCounterStyleFromSymbols(value, 'いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせす'); - case 27 /* KANNADA */: - return createCounterStyleFromRange(value, 0xce6, 0xcef, true, defaultSuffix); - case 28 /* KATAKANA */: - return createCounterStyleFromSymbols(value, 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヰヱヲン', cjkSuffix); - case 29 /* KATAKANA_IROHA */: - return createCounterStyleFromSymbols(value, 'イロハニホヘトチリヌルヲワカヨタレソツネナラムウヰノオクヤマケフコエテアサキユメミシヱヒモセス', cjkSuffix); - case 34 /* LAO */: - return createCounterStyleFromRange(value, 0xed0, 0xed9, true, defaultSuffix); - case 37 /* MONGOLIAN */: - return createCounterStyleFromRange(value, 0x1810, 0x1819, true, defaultSuffix); - case 38 /* MYANMAR */: - return createCounterStyleFromRange(value, 0x1040, 0x1049, true, defaultSuffix); - case 39 /* ORIYA */: - return createCounterStyleFromRange(value, 0xb66, 0xb6f, true, defaultSuffix); - case 40 /* PERSIAN */: - return createCounterStyleFromRange(value, 0x6f0, 0x6f9, true, defaultSuffix); - case 43 /* TAMIL */: - return createCounterStyleFromRange(value, 0xbe6, 0xbef, true, defaultSuffix); - case 44 /* TELUGU */: - return createCounterStyleFromRange(value, 0xc66, 0xc6f, true, defaultSuffix); - case 45 /* THAI */: - return createCounterStyleFromRange(value, 0xe50, 0xe59, true, defaultSuffix); - case 46 /* TIBETAN */: - return createCounterStyleFromRange(value, 0xf20, 0xf29, true, defaultSuffix); - case 3 /* DECIMAL */: - default: - return createCounterStyleFromRange(value, 48, 57, true, defaultSuffix); - } -}; - -var IGNORE_ATTRIBUTE = 'data-html2canvas-ignore'; -var DocumentCloner = /** @class */ (function () { - function DocumentCloner(context, element, options) { - this.context = context; - this.options = options; - this.scrolledElements = []; - this.referenceElement = element; - this.counters = new CounterState(); - this.quoteDepth = 0; - if (!element.ownerDocument) { - throw new Error('Cloned element does not have an owner document'); - } - this.documentElement = this.cloneNode(element.ownerDocument.documentElement, false); - } - DocumentCloner.prototype.toIFrame = function (ownerDocument, windowSize) { - var _this = this; - var iframe = createIFrameContainer(ownerDocument, windowSize); - if (!iframe.contentWindow) { - return Promise.reject("Unable to find iframe window"); - } - var scrollX = ownerDocument.defaultView.pageXOffset; - var scrollY = ownerDocument.defaultView.pageYOffset; - var cloneWindow = iframe.contentWindow; - var documentClone = cloneWindow.document; - /* Chrome doesn't detect relative background-images assigned in inline