@xeokit/xeokit-sdk 2.6.93 → 2.6.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  /**
2
- * xeokit-sdk v2.6.93
3
- * Commit: 00a09510b0b8d1b5f72f56ee2cefec7f33616748
4
- * Built: 2025-10-20T10:22:18.716Z
2
+ * xeokit-sdk v2.6.94
3
+ * Commit: 32b1b9841f49a7817cfc809cbbee180486784356
4
+ * Built: 2025-11-03T13:06:26.987Z
5
5
  */
6
6
 
7
- var e,t,n,r=A().mark(Dh),i=A().mark(Qh),s=A().mark(_v);function a(e){var t="function"==typeof Map?new Map:void 0;return a=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return o(e,arguments,C(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),y(r,e)},a(e)}function o(e,t,n){return o=B()?Reflect.construct.bind():function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&y(i,n.prototype),i},o.apply(null,arguments)}function A(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */A=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",s=r.asyncIterator||"@@asyncIterator",a=r.toStringTag||"@@toStringTag";function o(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{o({},"")}catch(e){o=function(e,t,n){return e[t]=n}}function c(e,t,n,r){var i=t&&t.prototype instanceof h?t:h,s=Object.create(i.prototype),a=new C(r||[]);return s._invoke=function(e,t,n){var r="suspendedStart";return function(i,s){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw s;return E()}for(n.method=i,n.arg=s;;){var a=n.delegate;if(a){var o=b(a,n);if(o){if(o===u)continue;return o}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var A=l(e,t,n);if("normal"===A.type){if(r=n.done?"completed":"suspendedYield",A.arg===u)continue;return{value:A.arg,done:n.done}}"throw"===A.type&&(r="completed",n.method="throw",n.arg=A.arg)}}}(e,n,a),s}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var u={};function h(){}function d(){}function f(){}var p={};o(p,i,(function(){return this}));var v=Object.getPrototypeOf,g=v&&v(v(k([])));g&&g!==t&&n.call(g,i)&&(p=g);var m=f.prototype=h.prototype=Object.create(p);function y(e){["next","throw","return"].forEach((function(t){o(e,t,(function(e){return this._invoke(t,e)}))}))}function _(e,t){function r(i,s,a,o){var A=l(e[i],e,s);if("throw"!==A.type){var c=A.arg,u=c.value;return u&&"object"==M(u)&&n.call(u,"__await")?t.resolve(u.__await).then((function(e){r("next",e,a,o)}),(function(e){r("throw",e,a,o)})):t.resolve(u).then((function(e){c.value=e,a(c)}),(function(e){return r("throw",e,a,o)}))}o(A.arg)}var i;this._invoke=function(e,n){function s(){return new t((function(t,i){r(e,n,t,i)}))}return i=i?i.then(s,s):s()}}function b(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,b(e,t),"throw"===t.method))return u;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return u}var r=l(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,u;var i=r.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,u):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,u)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function B(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function C(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function k(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,s=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return s.next=s}}return{next:E}}function E(){return{value:void 0,done:!0}}return d.prototype=f,o(m,"constructor",f),o(f,"constructor",d),d.displayName=o(f,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,f):(e.__proto__=f,o(e,a,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},y(_.prototype),o(_.prototype,s,(function(){return this})),e.AsyncIterator=_,e.async=function(t,n,r,i,s){void 0===s&&(s=Promise);var a=new _(c(t,n,r,i),s);return e.isGeneratorFunction(n)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},y(m),o(m,a,"Generator"),o(m,i,(function(){return this})),o(m,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=k,C.prototype={constructor:C,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(B),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return a.type="throw",a.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var s=this.tryEntries[i],a=s.completion;if("root"===s.tryLoc)return r("end");if(s.tryLoc<=this.prev){var o=n.call(s,"catchLoc"),A=n.call(s,"finallyLoc");if(o&&A){if(this.prev<s.catchLoc)return r(s.catchLoc,!0);if(this.prev<s.finallyLoc)return r(s.finallyLoc)}else if(o){if(this.prev<s.catchLoc)return r(s.catchLoc,!0)}else{if(!A)throw new Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return r(s.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var s=i;break}}s&&("break"===e||"continue"===e)&&s.tryLoc<=t&&t<=s.finallyLoc&&(s=null);var a=s?s.completion:{};return a.type=e,a.arg=t,s?(this.method="next",this.next=s.finallyLoc,u):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),u},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),B(n),u}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;B(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),u}},e}function c(e,t,n,r,i,s,a){try{var o=e[s](a),A=o.value}catch(e){return void n(e)}o.done?t(A):Promise.resolve(A).then(r,i)}function l(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var s=e.apply(t,n);function a(e){c(s,r,i,a,o,"next",e)}function o(e){c(s,r,i,a,o,"throw",e)}a(void 0)}))}}function u(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=E(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){o=!0,s=e},f:function(){try{a||null==n.return||n.return()}finally{if(o)throw s}}}}function h(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function d(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?h(Object(n),!0).forEach((function(t){f(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):h(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function f(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function p(e){return function(e){if(Array.isArray(e))return F(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||E(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(){return v="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var r=g(e,t);if(r){var i=Object.getOwnPropertyDescriptor(r,t);return i.get?i.get.call(arguments.length<3?e:n):i.value}},v.apply(this,arguments)}function g(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=C(e)););return e}function m(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&y(e,t)}function y(e,t){return y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},y(e,t)}function _(e){var t=B();return function(){var n,r=C(e);if(t){var i=C(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return b(this,n)}}function b(e,t){if(t&&("object"===M(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return w(e)}function w(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function B(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function C(e){return C=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},C(e)}function M(e){return M="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},M(e)}function k(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,i,s=[],a=!0,o=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(s.push(r.value),!t||s.length!==t);a=!0);}catch(e){o=!0,i=e}finally{try{a||null==n.return||n.return()}finally{if(o)throw i}}return s}(e,t)||E(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function E(e,t){if(e){if("string"==typeof e)return F(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?F(e,t):void 0}}function F(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function x(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function U(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function I(e,t,n){return t&&U(e.prototype,t),n&&U(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function T(e){return new D(e)}function P(e){return function(){return new S(e.apply(this,arguments))}}function S(e){var t,n;function r(t,n){try{var s=e[t](n),a=s.value,o=a instanceof D;Promise.resolve(o?a.wrapped:a).then((function(e){o?r("return"===t?"return":"next",e):i(s.done?"return":"normal",e)}),(function(e){r("throw",e)}))}catch(e){i("throw",e)}}function i(e,i){switch(e){case"return":t.resolve({value:i,done:!0});break;case"throw":t.reject(i);break;default:t.resolve({value:i,done:!1})}(t=t.next)?r(t.key,t.arg):n=null}this._invoke=function(e,i){return new Promise((function(s,a){var o={key:e,arg:i,resolve:s,reject:a,next:null};n?n=n.next=o:(t=n=o,r(e,i))}))},"function"!=typeof e.return&&(this.return=void 0)}function D(e){this.wrapped=e}function Q(e){var t,n,r,i=2;for("undefined"!=typeof Symbol&&(n=Symbol.asyncIterator,r=Symbol.iterator);i--;){if(n&&null!=(t=e[n]))return t.call(e);if(r&&null!=(t=e[r]))return new R(t.call(e));n="@@asyncIterator",r="@@iterator"}throw new TypeError("Object is not async iterable")}function R(e){function t(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));var t=e.done;return Promise.resolve(e.value).then((function(e){return{value:e,done:t}}))}return R=function(e){this.s=e,this.n=e.next},R.prototype={s:null,n:null,next:function(){return t(this.n.apply(this.s,arguments))},return:function(e){var n=this.s.return;return void 0===n?Promise.resolve({value:e,done:!0}):t(n.apply(this.s,arguments))},throw:function(e){var n=this.s.return;return void 0===n?Promise.reject(e):t(n.apply(this.s,arguments))}},new R(e)}S.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},S.prototype.next=function(e){return this._invoke("next",e)},S.prototype.throw=function(e){return this._invoke("throw",e)},S.prototype.return=function(e){return this._invoke("return",e)},"undefined"!=typeof window&&(window.__XEOKIT__={version:"2.6.93",commit:"00a09510b0b8d1b5f72f56ee2cefec7f33616748",built:"2025-10-20T10:22:18.716Z"});var O,V,L,H,N,G,j,W,z,X,K,Z=function(){function e(t,n){x(this,e),this.items=t||[],this._lastUniqueId=(n||0)+1}return I(e,[{key:"addItem",value:function(){var e;if(2===arguments.length){var t=arguments[0];if(e=arguments[1],this.items[t])throw"ID clash: '"+t+"'";return this.items[t]=e,t}for(e=arguments[0]||{};;){var n=this._lastUniqueId++;if(!this.items[n])return this.items[n]=e,n}}},{key:"removeItem",value:function(e){var t=this.items[e];return delete this.items[e],t}}]),e}(),J=new Z,Y=I((function e(t){x(this,e),this.id=t,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0})),q=I((function e(){x(this,e),this.items=[]})),$=I((function e(t,n,r,i,s){x(this,e),this.id=t,this.getTitle=n,this.doAction=r,this.getEnabled=i,this.getShown=s,this.itemElement=null,this.subMenu=null,this.enabled=!0})),ee=function(){function e(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};x(this,e),this._id=J.addItem(),this._context=null,this._enabled=!1,this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={},this._shown=!1,this._nextId=0,this._parentNode=n.parentNode||document.body,this._offsetParent=this._parentNode instanceof ShadowRoot?this._parentNode.host:this._parentNode,this._eventSubs={},!1!==n.hideOnMouseDown&&(this._parentNode.addEventListener("mousedown",(function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),this._parentNode.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),n.items&&(this.items=n.items),this._hideOnAction=!1!==n.hideOnAction,this.context=n.context,this.enabled=!1!==n.enabled,this.hide()}return I(e,[{key:"on",value:function(e,t){var n=this._eventSubs[e];n||(n=[],this._eventSubs[e]=n),n.push(t)}},{key:"fire",value:function(e,t){var n=this._eventSubs[e];if(n)for(var r=0,i=n.length;r<i;r++)n[r](t)}},{key:"items",get:function(){return this._itemsCfg},set:function(e){this._clear(),this._itemsCfg=e||[],this._parseItems(e),this._createUI()}},{key:"enabled",get:function(){return this._enabled},set:function(e){(e=!!e)!==this._enabled&&(this._enabled=e,this._enabled||this.hide())}},{key:"context",get:function(){return this._context},set:function(e){this._context=e}},{key:"show",value:function(e,t){this._context?this._enabled&&(this._shown||(this._hideAllMenus(),this._updateItemsTitles(),this._updateItemsEnabledStatus(),this._showMenu(this._rootMenu.id,e,t),this._updateSubMenuInfo(),this._shown=!0,this.fire("shown",{}))):console.error("ContextMenu cannot be shown without a context - set context first")}},{key:"shown",get:function(){return this._shown}},{key:"hide",value:function(){this._enabled&&this._shown&&(this._hideAllMenus(),this._shown=!1,this.fire("hidden",{}))}},{key:"destroy",value:function(){this._context=null,this._clear(),null!==this._id&&(J.removeItem(this._id),this._id=null)}},{key:"_clear",value:function(){for(var e=0,t=this._menuList.length;e<t;e++){this._menuList[e].menuElement.remove()}this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={}}},{key:"_parseItems",value:function(e){var t=this;this._rootMenu=function e(n){for(var r=t._getNextId(),i=new Y(r),s=0,a=n.length;s<a;s++){var o=n[s],A=new q;i.groups.push(A);for(var c=function(n,r){var s=o[n],a=s.items,c=a&&a.length>0,l=t._getNextId(),u=s.getTitle||function(){return s.title||""},h=s.doAction||s.callback||function(){},d=s.getEnabled||function(){return!0},f=s.getShown||function(){return!0},p=new $(l,u,h,d,f);if(p.parentMenu=i,A.items.push(p),c){var v=e(a);p.subMenu=v,v.parentItem=p}t._itemList.push(p),t._itemMap[p.id]=p},l=0,u=o.length;l<u;l++)c(l)}return t._menuList.push(i),t._menuMap[i.id]=i,i}(e)}},{key:"_getNextId",value:function(){return"ContextMenu_"+this._id+"_"+this._nextId++}},{key:"_createUI",value:function(){var e=this;!function t(n){e._createMenuUI(n);for(var r=n.groups,i=0,s=r.length;i<s;i++)for(var a=r[i].items,o=0,A=a.length;o<A;o++){var c=a[o].subMenu;c&&t(c)}}(this._rootMenu)}},{key:"_createMenuUI",value:function(e){var t=this,n=e.groups,r=[],i=document.createElement("div");if(i.classList.add("xeokit-context-menu",e.id),i.style.zIndex=3e5,i.style.position="absolute",r.push("<ul>"),n)for(var s=0,a=n.length;s<a;s++){var o=s,A=a,c=n[s].items;if(c)for(var l=0,u=c.length;l<u;l++){var h=c[l],d=h.subMenu,f=h.title||"";d?(r.push('<li id="'+h.id+'" class="xeokit-context-menu-item xeokit-context-menu-submenu">'+f+"</li>"),o===A-1||l<u-1||r.push('<li id="'+h.id+'" class="xeokit-context-menu-item-separator"></li>')):(r.push('<li id="'+h.id+'" class="xeokit-context-menu-item">'+f+"</li>"),o===A-1||l<u-1||r.push('<li id="'+h.id+'" class="xeokit-context-menu-item-separator"></li>'))}}r.push("</ul>");var p=r.join("");i.innerHTML=p,this._parentNode.appendChild(i),e.menuElement=i,i.style["border-radius"]="4px",i.style.display="none",i.style["z-index"]=3e5,i.style.background="white",i.style.border="1px solid black",i.style["box-shadow"]="0 4px 5px 0 gray",i.oncontextmenu=function(e){e.preventDefault()};var v=this,g=null;if(n)for(var m=0,y=n.length;m<y;m++){var _=n[m].items;if(_)for(var b=function(e,n){var r=_[e],i=r.subMenu;if(r.itemElement=t._parentNode.querySelector("#".concat(r.id)),!r.itemElement)return console.error("ContextMenu item element not found: "+r.id),"continue";r.itemElement.addEventListener("mouseenter",(function(e){e.preventDefault();var t=r.subMenu;if(t){if(g&&g.id!==t.id&&(v._hideMenu(g.id),g=null),!1!==r.enabled){var n=r.itemElement,i=t.menuElement,s=n.getBoundingClientRect();i.getBoundingClientRect();var a=v._offsetParent.getBoundingClientRect(),o=200,A=s.right+o<a.right,c=s.left-o>a.left;if(A)v._showMenu(t.id,s.right+window.scrollX-5,s.top+window.scrollY-1);else if(c)v._showMenu(t.id,s.left-o+window.scrollX,s.top+window.scrollY-1);else{var l=s.left-a.left,u=a.right-s.right;u>l?v._showMenu(t.id,s.right-5-(o-u),s.top+window.scrollY-1):v._showMenu(t.id,s.left-l,s.top+window.scrollY-1)}g=t}}else g&&(v._hideMenu(g.id),g=null)})),i||(r.itemElement.addEventListener("click",(function(e){e.preventDefault(),v._context&&!1!==r.enabled&&(r.doAction&&r.doAction(v._context),t._hideOnAction?v.hide():(v._updateItemsTitles(),v._updateItemsEnabledStatus()))})),r.itemElement.addEventListener("mouseup",(function(e){3===e.which&&(e.preventDefault(),v._context&&!1!==r.enabled&&(r.doAction&&r.doAction(v._context),t._hideOnAction?v.hide():(v._updateItemsTitles(),v._updateItemsEnabledStatus())))})),r.itemElement.addEventListener("mouseenter",(function(e){e.preventDefault(),!1!==r.enabled&&r.doHover&&r.doHover(v._context)})))},w=0,B=_.length;w<B;w++)b(w)}}},{key:"_updateItemsTitles",value:function(){if(this._context)for(var e=0,t=this._itemList.length;e<t;e++){var n=this._itemList[e],r=n.itemElement;if(r){var i=n.getShown;if(i&&i(this._context)){var s=n.getTitle(this._context);n.subMenu,r.innerText=s}}}}},{key:"_updateItemsEnabledStatus",value:function(){if(this._context)for(var e=0,t=this._itemList.length;e<t;e++){var n=this._itemList[e],r=n.itemElement;if(r){var i=n.getEnabled;if(i){var s=n.getShown;if(s){var a=s(this._context);if(n.shown=a,a){r.style.display="";var o=i(this._context);n.enabled=o,o?r.classList.remove("disabled"):r.classList.add("disabled")}else r.style.display="none"}}}}}},{key:"_updateSubMenuInfo",value:function(){var e,t,n,r,i,s;this._context&&this._itemList.forEach((function(a){a.subMenu&&(e=a.itemElement,t=e.getBoundingClientRect(),n=a.subMenu.menuElement,r={visibility:n.style.visibility,display:n.style.display},n.style.display="block",n.style.visibility="hidden",s=a.subMenu.menuElement.getBoundingClientRect().width,n.style.visibility=r.visibility,n.style.display=r.display,i=t.right+s>window.innerWidth,e.setAttribute("data-submenuposition",i?"left":"right"))}))}},{key:"_showMenu",value:function(e,t,n){var r=this._menuMap[e];if(r){if(!r.shown){var i=r.menuElement;i&&(this._showMenuElement(i,t,n),r.shown=!0)}}else console.error("Menu not found: "+e)}},{key:"_hideMenu",value:function(e){var t=this._menuMap[e];if(t){if(t.shown){var n=t.menuElement;n&&(this._hideMenuElement(n),t.shown=!1)}}else console.error("Menu not found: "+e)}},{key:"_hideAllMenus",value:function(){for(var e=0,t=this._menuList.length;e<t;e++){var n=this._menuList[e];this._hideMenu(n.id)}}},{key:"_showMenuElement",value:function(e,t,n){e.style.display="block";var r=e.offsetHeight,i=e.offsetWidth,s=this._offsetParent.getBoundingClientRect(),a=this._offsetParent===window.document.body&&0===s.bottom?window.innerHeight:s.bottom+window.scrollY,o=s.right+window.scrollX;n+r>a&&(n=a-r),t+i>o&&(t=o-i),e.style.left=t-s.left-window.scrollX+"px",e.style.top=n-s.top-window.scrollY+"px"}},{key:"_hideMenuElement",value:function(e){e.style.display="none"}}]),e}(),te=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this.viewer=t,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=r.containerId||"xeokit-lens",this._lensContainer.setAttribute("id",this._lensContainerId),this._lensContainer.style.border="1px solid black",this._lensContainer.style.background="white",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="".concat(this._lensContainerId,"-canvas"),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=r.lensPosToggle||!0,this._lensPosToggleAmount=r.lensPosToggleAmount||85,this._lensPosMarginLeft=r.lensPosMarginLeft||85,this._lensPosMarginTop=r.lensPosMarginTop||25,this._lensContainer.style.marginTop="".concat(this._lensPosMarginTop,"px"),this._lensContainer.style.marginLeft="".concat(this._lensPosMarginLeft,"px"),this._zoomLevel=r.zoomLevel||2,this._active=!1!==r.active,this._visible=!1,this.snapped=!1,this._onViewerRendering=this.viewer.scene.on("rendering",(function(){n._active&&n._visible&&n.update()}))}return I(e,[{key:"update",value:function(){if(this._active&&this._visible&&this._canvasPos){var e=this._lensContainer.getBoundingClientRect(),t=this._canvasElement.getBoundingClientRect(),n=this._canvasPos[0]<e.right&&this._canvasPos[0]>e.left&&this._canvasPos[1]<e.bottom&&this._canvasPos[1]>e.top;this._lensContainer.style.marginLeft="".concat(this._lensPosMarginLeft,"px"),n&&(this._lensPosToggle?this._lensContainer.style.marginTop="".concat(t.bottom-t.top-this._lensCanvas.height-this._lensPosToggleAmount,"px"):this._lensContainer.style.marginTop="".concat(this._lensPosMarginTop,"px"),this._lensPosToggle=!this._lensPosToggle),this._lensCanvasContext.clearRect(0,0,this._lensCanvas.width,this._lensCanvas.height);var r=Math.max(this._lensCanvas.width,this._lensCanvas.height)/this._zoomLevel;this._lensCanvasContext.drawImage(this._canvasElement,this._canvasPos[0]-r/2,this._canvasPos[1]-r/2,r,r,0,0,this._lensCanvas.width,this._lensCanvas.height);var i=this._lensParams.canvasSize/2-this._lensParams.cursorSize/2-this._lensParams.cursorBorder,s=this._snappedCanvasPos?this._snappedCanvasPos[0]-this._canvasPos[0]:0,a=this._snappedCanvasPos?this._snappedCanvasPos[1]-this._canvasPos[1]:0;this._lensCursorDiv.style.left="".concat(i+s*this._zoomLevel,"px"),this._lensCursorDiv.style.top="".concat(i+a*this._zoomLevel,"px")}}},{key:"zoomFactor",get:function(){return this._zoomFactor},set:function(e){this._zoomFactor=e,this.update()}},{key:"canvasPos",get:function(){return this._canvasPos},set:function(e){this._canvasPos=e,this.update()}},{key:"snappedCanvasPos",get:function(){return this._snappedCanvasPos},set:function(e){this._snappedCanvasPos=e,this.update()}},{key:"snapped",get:function(){return this._snapped},set:function(e){this._snapped=e;var t=k(e?["greenyellow","green"]:["pink","red"],2),n=t[0],r=t[1];this._lensCursorDiv.style.background=n,this._lensCursorDiv.style.border=this._lensParams.cursorBorder+"px solid "+r}},{key:"_updateActiveVisible",value:function(){this._lensContainer.style.visibility=this._active&&this._visible?"visible":"hidden",this.update()}},{key:"active",get:function(){return this._active},set:function(e){this._active=e,this._updateActiveVisible()}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=e,this._updateActiveVisible()}},{key:"destroy",value:function(){this._destroyed||(this.viewer.scene.off(this._onViewerRendering),this._lensContainer.removeChild(this._lensCanvas),document.body.removeChild(this._lensContainer),this._destroyed=!0)}}]),e}(),ne=!0,re=ne?Float64Array:Float32Array,ie=new re(3),se=new re(16),ae=new re(16),oe=new re(4),Ae={setDoublePrecisionEnabled:function(e){re=(ne=e)?Float64Array:Float32Array},getDoublePrecisionEnabled:function(){return ne},MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId:function(e,t){var n=t.indexOf("#");return n===e.length&&t.startsWith(e)?t.substring(n+1):t},globalizeObjectId:function(e,t){return e+"#"+t},safeInv:function(e){var t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:function(e){return new re(e||2)},vec3:function(e){return new re(e||3)},vec4:function(e){return new re(e||4)},mat3:function(e){return new re(e||9)},mat3ToMat4:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new re(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},mat4:function(e){return new re(e||16)},mat4ToMat3:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new re(9);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t},doublesToFloats:function(e,t,n){for(var r=new re(2),i=0,s=e.length;i<s;i++)Ae.splitDouble(e[i],r),t[i]=r[0],n[i]=r[1]},splitDouble:function(e,t){var n=re.from([e])[0],r=e-n;t[0]=n,t[1]=r},createUUID:function(){for(var e=[],t=0;t<256;t++)e[t]=(t<16?"0":"")+t.toString(16);return function(){var t=4294967295*Math.random()|0,n=4294967295*Math.random()|0,r=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return"".concat(e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255],"-").concat(e[255&n]).concat(e[n>>8&255],"-").concat(e[n>>16&15|64]).concat(e[n>>24&255],"-").concat(e[63&r|128]).concat(e[r>>8&255],"-").concat(e[r>>16&255]).concat(e[r>>24&255]).concat(e[255&i]).concat(e[i>>8&255]).concat(e[i>>16&255]).concat(e[i>>24&255])}}(),clamp:function(e,t,n){return Math.max(t,Math.min(n,e))},fmod:function(e,t){if(e<t)return console.error("math.fmod : Attempting to find modulus within negative range - would be infinite loop - ignoring"),e;for(;t<=e;)e-=t;return e},compareVec3:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]},compareVec4:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]},negateVec3:function(e,t){return t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t},negateVec4:function(e,t){return t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t},addVec4:function(e,t,n){return n||(n=e),n[0]=e[0]+t[0],n[1]=e[1]+t[1],n[2]=e[2]+t[2],n[3]=e[3]+t[3],n},addVec4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]+t,n[1]=e[1]+t,n[2]=e[2]+t,n[3]=e[3]+t,n},addVec3:function(e,t,n){return n||(n=e),n[0]=e[0]+t[0],n[1]=e[1]+t[1],n[2]=e[2]+t[2],n},addVec3Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]+t,n[1]=e[1]+t,n[2]=e[2]+t,n},subVec4:function(e,t,n){return n||(n=e),n[0]=e[0]-t[0],n[1]=e[1]-t[1],n[2]=e[2]-t[2],n[3]=e[3]-t[3],n},subVec3:function(e,t,n){return n||(n=e),n[0]=e[0]-t[0],n[1]=e[1]-t[1],n[2]=e[2]-t[2],n},subVec2:function(e,t,n){return n||(n=e),n[0]=e[0]-t[0],n[1]=e[1]-t[1],n},geometricMeanVec2:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=new re(t[0]),i=1;i<t.length;i++)r[0]+=t[i][0],r[1]+=t[i][1];return r[0]/=t.length,r[1]/=t.length,r},subVec4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]-t,n[1]=e[1]-t,n[2]=e[2]-t,n[3]=e[3]-t,n},subScalarVec4:function(e,t,n){return n||(n=e),n[0]=t-e[0],n[1]=t-e[1],n[2]=t-e[2],n[3]=t-e[3],n},mulVec4:function(e,t,n){return n||(n=e),n[0]=e[0]*t[0],n[1]=e[1]*t[1],n[2]=e[2]*t[2],n[3]=e[3]*t[3],n},mulVec4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]*t,n[1]=e[1]*t,n[2]=e[2]*t,n[3]=e[3]*t,n},mulVec3Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]*t,n[1]=e[1]*t,n[2]=e[2]*t,n},mulVec2Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]*t,n[1]=e[1]*t,n},divVec3:function(e,t,n){return n||(n=e),n[0]=e[0]/t[0],n[1]=e[1]/t[1],n[2]=e[2]/t[2],n},divVec4:function(e,t,n){return n||(n=e),n[0]=e[0]/t[0],n[1]=e[1]/t[1],n[2]=e[2]/t[2],n[3]=e[3]/t[3],n},divScalarVec3:function(e,t,n){return n||(n=t),n[0]=e/t[0],n[1]=e/t[1],n[2]=e/t[2],n},divVec3Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]/t,n[1]=e[1]/t,n[2]=e[2]/t,n},divVec4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]/t,n[1]=e[1]/t,n[2]=e[2]/t,n[3]=e[3]/t,n},divScalarVec4:function(e,t,n){return n||(n=t),n[0]=e/t[0],n[1]=e/t[1],n[2]=e/t[2],n[3]=e/t[3],n},dotVec4:function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]},cross3Vec4:function(e,t){var n=e[0],r=e[1],i=e[2],s=t[0],a=t[1],o=t[2];return[r*o-i*a,i*s-n*o,n*a-r*s,0]},cross3Vec3:function(e,t,n){n||(n=e);var r=e[0],i=e[1],s=e[2],a=t[0],o=t[1],A=t[2];return n[0]=i*A-s*o,n[1]=s*a-r*A,n[2]=r*o-i*a,n},sqLenVec4:function(e){return Ae.dotVec4(e,e)},lenVec4:function(e){return Math.sqrt(Ae.sqLenVec4(e))},dotVec3:function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]},dotVec2:function(e,t){return e[0]*t[0]+e[1]*t[1]},sqLenVec3:function(e){return Ae.dotVec3(e,e)},sqLenVec2:function(e){return Ae.dotVec2(e,e)},lenVec3:function(e){return Math.sqrt(Ae.sqLenVec3(e))},distVec3:(K=new re(3),function(e,t){return Ae.lenVec3(Ae.subVec3(e,t,K))}),lenVec2:function(e){return Math.sqrt(Ae.sqLenVec2(e))},distVec2:function(){var e=new re(2);return function(t,n){return Ae.lenVec2(Ae.subVec2(t,n,e))}}(),rcpVec3:function(e,t){return Ae.divScalarVec3(1,e,t)},normalizeVec4:function(e,t){var n=1/Ae.lenVec4(e);return Ae.mulVec4Scalar(e,n,t)},normalizeVec3:function(e,t){var n=1/Ae.lenVec3(e);return Ae.mulVec3Scalar(e,n,t)},normalizeVec2:function(e,t){var n=1/Ae.lenVec2(e);return Ae.mulVec2Scalar(e,n,t)},angleVec3:function(e,t){var n=Ae.dotVec3(e,t)/Math.sqrt(Ae.sqLenVec3(e)*Ae.sqLenVec3(t));return n=n<-1?-1:n>1?1:n,Math.acos(n)},vec3FromMat4Scale:function(){var e=new re(3);return function(t,n){return e[0]=t[0],e[1]=t[1],e[2]=t[2],n[0]=Ae.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],n[1]=Ae.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],n[2]=Ae.lenVec3(e),n}}(),vecToArray:function(){function e(e){return Math.round(1e5*e)/1e5}return function(t){for(var n=0,r=(t=Array.prototype.slice.call(t)).length;n<r;n++)t[n]=e(t[n]);return t}}(),xyzArrayToObject:function(e){return{x:e[0],y:e[1],z:e[2]}},xyzObjectToArray:function(e,t){return(t=t||Ae.vec3())[0]=e.x,t[1]=e.y,t[2]=e.z,t},dupMat4:function(e){return e.slice(0,16)},mat4To3:function(e){return[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]]},m4s:function(e){return[e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e]},setMat4ToZeroes:function(){return Ae.m4s(0)},setMat4ToOnes:function(){return Ae.m4s(1)},diagonalMat4v:function(e){return new re([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]])},diagonalMat4c:function(e,t,n,r){return Ae.diagonalMat4v([e,t,n,r])},diagonalMat4s:function(e){return Ae.diagonalMat4c(e,e,e,e)},identityMat4:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new re(16);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},identityMat3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new re(9);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e},isIdentityMat4:function(e){return 1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15]},negateMat4:function(e,t){return t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t},addMat4:function(e,t,n){return n||(n=e),n[0]=e[0]+t[0],n[1]=e[1]+t[1],n[2]=e[2]+t[2],n[3]=e[3]+t[3],n[4]=e[4]+t[4],n[5]=e[5]+t[5],n[6]=e[6]+t[6],n[7]=e[7]+t[7],n[8]=e[8]+t[8],n[9]=e[9]+t[9],n[10]=e[10]+t[10],n[11]=e[11]+t[11],n[12]=e[12]+t[12],n[13]=e[13]+t[13],n[14]=e[14]+t[14],n[15]=e[15]+t[15],n},addMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]+t,n[1]=e[1]+t,n[2]=e[2]+t,n[3]=e[3]+t,n[4]=e[4]+t,n[5]=e[5]+t,n[6]=e[6]+t,n[7]=e[7]+t,n[8]=e[8]+t,n[9]=e[9]+t,n[10]=e[10]+t,n[11]=e[11]+t,n[12]=e[12]+t,n[13]=e[13]+t,n[14]=e[14]+t,n[15]=e[15]+t,n},addScalarMat4:function(e,t,n){return Ae.addMat4Scalar(t,e,n)},subMat4:function(e,t,n){return n||(n=e),n[0]=e[0]-t[0],n[1]=e[1]-t[1],n[2]=e[2]-t[2],n[3]=e[3]-t[3],n[4]=e[4]-t[4],n[5]=e[5]-t[5],n[6]=e[6]-t[6],n[7]=e[7]-t[7],n[8]=e[8]-t[8],n[9]=e[9]-t[9],n[10]=e[10]-t[10],n[11]=e[11]-t[11],n[12]=e[12]-t[12],n[13]=e[13]-t[13],n[14]=e[14]-t[14],n[15]=e[15]-t[15],n},subMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]-t,n[1]=e[1]-t,n[2]=e[2]-t,n[3]=e[3]-t,n[4]=e[4]-t,n[5]=e[5]-t,n[6]=e[6]-t,n[7]=e[7]-t,n[8]=e[8]-t,n[9]=e[9]-t,n[10]=e[10]-t,n[11]=e[11]-t,n[12]=e[12]-t,n[13]=e[13]-t,n[14]=e[14]-t,n[15]=e[15]-t,n},subScalarMat4:function(e,t,n){return n||(n=t),n[0]=e-t[0],n[1]=e-t[1],n[2]=e-t[2],n[3]=e-t[3],n[4]=e-t[4],n[5]=e-t[5],n[6]=e-t[6],n[7]=e-t[7],n[8]=e-t[8],n[9]=e-t[9],n[10]=e-t[10],n[11]=e-t[11],n[12]=e-t[12],n[13]=e-t[13],n[14]=e-t[14],n[15]=e-t[15],n},mulMat4:function(e,t,n){n||(n=e);var r=e[0],i=e[1],s=e[2],a=e[3],o=e[4],A=e[5],c=e[6],l=e[7],u=e[8],h=e[9],d=e[10],f=e[11],p=e[12],v=e[13],g=e[14],m=e[15],y=t[0],_=t[1],b=t[2],w=t[3],B=t[4],C=t[5],M=t[6],k=t[7],E=t[8],F=t[9],x=t[10],U=t[11],I=t[12],T=t[13],P=t[14],S=t[15];return n[0]=y*r+_*o+b*u+w*p,n[1]=y*i+_*A+b*h+w*v,n[2]=y*s+_*c+b*d+w*g,n[3]=y*a+_*l+b*f+w*m,n[4]=B*r+C*o+M*u+k*p,n[5]=B*i+C*A+M*h+k*v,n[6]=B*s+C*c+M*d+k*g,n[7]=B*a+C*l+M*f+k*m,n[8]=E*r+F*o+x*u+U*p,n[9]=E*i+F*A+x*h+U*v,n[10]=E*s+F*c+x*d+U*g,n[11]=E*a+F*l+x*f+U*m,n[12]=I*r+T*o+P*u+S*p,n[13]=I*i+T*A+P*h+S*v,n[14]=I*s+T*c+P*d+S*g,n[15]=I*a+T*l+P*f+S*m,n},mulMat3:function(e,t,n){n||(n=new re(9));var r=e[0],i=e[3],s=e[6],a=e[1],o=e[4],A=e[7],c=e[2],l=e[5],u=e[8],h=t[0],d=t[3],f=t[6],p=t[1],v=t[4],g=t[7],m=t[2],y=t[5],_=t[8];return n[0]=r*h+i*p+s*m,n[3]=r*d+i*v+s*y,n[6]=r*f+i*g+s*_,n[1]=a*h+o*p+A*m,n[4]=a*d+o*v+A*y,n[7]=a*f+o*g+A*_,n[2]=c*h+l*p+u*m,n[5]=c*d+l*v+u*y,n[8]=c*f+l*g+u*_,n},mulMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]*t,n[1]=e[1]*t,n[2]=e[2]*t,n[3]=e[3]*t,n[4]=e[4]*t,n[5]=e[5]*t,n[6]=e[6]*t,n[7]=e[7]*t,n[8]=e[8]*t,n[9]=e[9]*t,n[10]=e[10]*t,n[11]=e[11]*t,n[12]=e[12]*t,n[13]=e[13]*t,n[14]=e[14]*t,n[15]=e[15]*t,n},mulMat4v4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec4(),r=t[0],i=t[1],s=t[2],a=t[3];return n[0]=e[0]*r+e[4]*i+e[8]*s+e[12]*a,n[1]=e[1]*r+e[5]*i+e[9]*s+e[13]*a,n[2]=e[2]*r+e[6]*i+e[10]*s+e[14]*a,n[3]=e[3]*r+e[7]*i+e[11]*s+e[15]*a,n},transposeMat4:function(e,t){var n=e[4],r=e[14],i=e[8],s=e[13],a=e[12],o=e[9];if(!t||e===t){var A=e[1],c=e[2],l=e[3],u=e[6],h=e[7],d=e[11];return e[1]=n,e[2]=i,e[3]=a,e[4]=A,e[6]=o,e[7]=s,e[8]=c,e[9]=u,e[11]=r,e[12]=l,e[13]=h,e[14]=d,e}return t[0]=e[0],t[1]=n,t[2]=i,t[3]=a,t[4]=e[1],t[5]=e[5],t[6]=o,t[7]=s,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=r,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3:function(e,t){if(t===e){var n=e[1],r=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=n,t[5]=e[7],t[6]=r,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4:function(e){var t=e[0],n=e[1],r=e[2],i=e[3],s=e[4],a=e[5],o=e[6],A=e[7],c=e[8],l=e[9],u=e[10],h=e[11],d=e[12],f=e[13],p=e[14],v=e[15];return d*l*o*i-c*f*o*i-d*a*u*i+s*f*u*i+c*a*p*i-s*l*p*i-d*l*r*A+c*f*r*A+d*n*u*A-t*f*u*A-c*n*p*A+t*l*p*A+d*a*r*h-s*f*r*h-d*n*o*h+t*f*o*h+s*n*p*h-t*a*p*h-c*a*r*v+s*l*r*v+c*n*o*v-t*l*o*v-s*n*u*v+t*a*u*v},inverseMat4:function(e,t){t||(t=e);var n=e[0],r=e[1],i=e[2],s=e[3],a=e[4],o=e[5],A=e[6],c=e[7],l=e[8],u=e[9],h=e[10],d=e[11],f=e[12],p=e[13],v=e[14],g=e[15],m=n*o-r*a,y=n*A-i*a,_=n*c-s*a,b=r*A-i*o,w=r*c-s*o,B=i*c-s*A,C=l*p-u*f,M=l*v-h*f,k=l*g-d*f,E=u*v-h*p,F=u*g-d*p,x=h*g-d*v,U=1/(m*x-y*F+_*E+b*k-w*M+B*C);return t[0]=(o*x-A*F+c*E)*U,t[1]=(-r*x+i*F-s*E)*U,t[2]=(p*B-v*w+g*b)*U,t[3]=(-u*B+h*w-d*b)*U,t[4]=(-a*x+A*k-c*M)*U,t[5]=(n*x-i*k+s*M)*U,t[6]=(-f*B+v*_-g*y)*U,t[7]=(l*B-h*_+d*y)*U,t[8]=(a*F-o*k+c*C)*U,t[9]=(-n*F+r*k-s*C)*U,t[10]=(f*w-p*_+g*m)*U,t[11]=(-l*w+u*_-d*m)*U,t[12]=(-a*E+o*M-A*C)*U,t[13]=(n*E-r*M+i*C)*U,t[14]=(-f*b+p*y-v*m)*U,t[15]=(l*b-u*y+h*m)*U,t},traceMat4:function(e){return e[0]+e[5]+e[10]+e[15]},translationMat4v:function(e,t){var n=t||Ae.identityMat4();return n[12]=e[0],n[13]=e[1],n[14]=e[2],n},translationMat3v:function(e,t){var n=t||Ae.identityMat3();return n[6]=e[0],n[7]=e[1],n},translationMat4c:(X=new re(3),function(e,t,n,r){return X[0]=e,X[1]=t,X[2]=n,Ae.translationMat4v(X,r)}),translationMat4s:function(e,t){return Ae.translationMat4c(e,e,e,t)},translateMat4v:function(e,t){return Ae.translateMat4c(e[0],e[1],e[2],t)},translateMat4c:function(e,t,n,r){var i=r[3];r[0]+=i*e,r[1]+=i*t,r[2]+=i*n;var s=r[7];r[4]+=s*e,r[5]+=s*t,r[6]+=s*n;var a=r[11];r[8]+=a*e,r[9]+=a*t,r[10]+=a*n;var o=r[15];return r[12]+=o*e,r[13]+=o*t,r[14]+=o*n,r},setMat4Translation:function(e,t,n){return n[0]=e[0],n[1]=e[1],n[2]=e[2],n[3]=e[3],n[4]=e[4],n[5]=e[5],n[6]=e[6],n[7]=e[7],n[8]=e[8],n[9]=e[9],n[10]=e[10],n[11]=e[11],n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=e[15],n},rotationMat4v:function(e,t,n){var r,i,s,a,o,A,c=Ae.normalizeVec4([t[0],t[1],t[2],0],[]),l=Math.sin(e),u=Math.cos(e),h=1-u,d=c[0],f=c[1],p=c[2];return r=d*f,i=f*p,s=p*d,a=d*l,o=f*l,A=p*l,(n=n||Ae.mat4())[0]=h*d*d+u,n[1]=h*r+A,n[2]=h*s-o,n[3]=0,n[4]=h*r-A,n[5]=h*f*f+u,n[6]=h*i+a,n[7]=0,n[8]=h*s+o,n[9]=h*i-a,n[10]=h*p*p+u,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},rotationMat4c:function(e,t,n,r,i){return Ae.rotationMat4v(e,[t,n,r],i)},scalingMat4v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.identityMat4();return t[0]=e[0],t[5]=e[1],t[10]=e[2],t},scalingMat3v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.identityMat3();return t[0]=e[0],t[4]=e[1],t},scalingMat4c:function(){var e=new re(3);return function(t,n,r,i){return e[0]=t,e[1]=n,e[2]=r,Ae.scalingMat4v(e,i)}}(),scaleMat4c:function(e,t,n,r){return r[0]*=e,r[4]*=t,r[8]*=n,r[1]*=e,r[5]*=t,r[9]*=n,r[2]*=e,r[6]*=t,r[10]*=n,r[3]*=e,r[7]*=t,r[11]*=n,r},scaleMat4v:function(e,t){var n=e[0],r=e[1],i=e[2];return t[0]*=n,t[4]*=r,t[8]*=i,t[1]*=n,t[5]*=r,t[9]*=i,t[2]*=n,t[6]*=r,t[10]*=i,t[3]*=n,t[7]*=r,t[11]*=i,t},scalingMat4s:function(e){return Ae.scalingMat4c(e,e,e)},rotationTranslationMat4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.mat4(),r=e[0],i=e[1],s=e[2],a=e[3],o=r+r,A=i+i,c=s+s,l=r*o,u=r*A,h=r*c,d=i*A,f=i*c,p=s*c,v=a*o,g=a*A,m=a*c;return n[0]=1-(d+p),n[1]=u+m,n[2]=h-g,n[3]=0,n[4]=u-m,n[5]=1-(l+p),n[6]=f+v,n[7]=0,n[8]=h+g,n[9]=f-v,n[10]=1-(l+d),n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n},mat4ToEuler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec4(),r=Ae.clamp,i=e[0],s=e[4],a=e[8],o=e[1],A=e[5],c=e[9],l=e[2],u=e[6],h=e[10];return"XYZ"===t?(n[1]=Math.asin(r(a,-1,1)),Math.abs(a)<.99999?(n[0]=Math.atan2(-c,h),n[2]=Math.atan2(-s,i)):(n[0]=Math.atan2(u,A),n[2]=0)):"YXZ"===t?(n[0]=Math.asin(-r(c,-1,1)),Math.abs(c)<.99999?(n[1]=Math.atan2(a,h),n[2]=Math.atan2(o,A)):(n[1]=Math.atan2(-l,i),n[2]=0)):"ZXY"===t?(n[0]=Math.asin(r(u,-1,1)),Math.abs(u)<.99999?(n[1]=Math.atan2(-l,h),n[2]=Math.atan2(-s,A)):(n[1]=0,n[2]=Math.atan2(o,i))):"ZYX"===t?(n[1]=Math.asin(-r(l,-1,1)),Math.abs(l)<.99999?(n[0]=Math.atan2(u,h),n[2]=Math.atan2(o,i)):(n[0]=0,n[2]=Math.atan2(-s,A))):"YZX"===t?(n[2]=Math.asin(r(o,-1,1)),Math.abs(o)<.99999?(n[0]=Math.atan2(-c,A),n[1]=Math.atan2(-l,i)):(n[0]=0,n[1]=Math.atan2(a,h))):"XZY"===t&&(n[2]=Math.asin(-r(s,-1,1)),Math.abs(s)<.99999?(n[0]=Math.atan2(u,A),n[1]=Math.atan2(a,i)):(n[0]=Math.atan2(-c,h),n[1]=0)),n[0]*=Ae.RADTODEG,n[1]*=Ae.RADTODEG,n[2]*=Ae.RADTODEG,n},composeMat4:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Ae.mat4();return Ae.quaternionToRotationMat4(t,r),Ae.scaleMat4v(n,r),Ae.translateMat4v(e,r),r},decomposeMat4:function(){var e=new re(3),t=new re(16);return function(n,r,i,s){e[0]=n[0],e[1]=n[1],e[2]=n[2];var a=Ae.lenVec3(e);e[0]=n[4],e[1]=n[5],e[2]=n[6];var o=Ae.lenVec3(e);e[8]=n[8],e[9]=n[9],e[10]=n[10];var A=Ae.lenVec3(e);Ae.determinantMat4(n)<0&&(a=-a),r[0]=n[12],r[1]=n[13],r[2]=n[14],t.set(n);var c=1/a,l=1/o,u=1/A;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=l,t[5]*=l,t[6]*=l,t[8]*=u,t[9]*=u,t[10]*=u,Ae.mat4ToQuaternion(t,i),s[0]=a,s[1]=o,s[2]=A,this}}(),getColMat4:function(e,t){var n=4*t;return[e[n],e[n+1],e[n+2],e[n+3]]},setRowMat4:function(e,t,n){e[t]=n[0],e[t+4]=n[1],e[t+8]=n[2],e[t+12]=n[3]},lookAtMat4v:function(e,t,n,r){r||(r=Ae.mat4());var i,s,a,o,A,c,l,u,h,d,f=e[0],p=e[1],v=e[2],g=n[0],m=n[1],y=n[2],_=t[0],b=t[1],w=t[2];return f===_&&p===b&&v===w?Ae.identityMat4():(i=f-_,s=p-b,a=v-w,o=m*(a*=d=1/Math.sqrt(i*i+s*s+a*a))-y*(s*=d),A=y*(i*=d)-g*a,c=g*s-m*i,(d=Math.sqrt(o*o+A*A+c*c))?(o*=d=1/d,A*=d,c*=d):(o=0,A=0,c=0),l=s*c-a*A,u=a*o-i*c,h=i*A-s*o,(d=Math.sqrt(l*l+u*u+h*h))?(l*=d=1/d,u*=d,h*=d):(l=0,u=0,h=0),r[0]=o,r[1]=l,r[2]=i,r[3]=0,r[4]=A,r[5]=u,r[6]=s,r[7]=0,r[8]=c,r[9]=h,r[10]=a,r[11]=0,r[12]=-(o*f+A*p+c*v),r[13]=-(l*f+u*p+h*v),r[14]=-(i*f+s*p+a*v),r[15]=1,r)},lookAtMat4c:function(e,t,n,r,i,s,a,o,A){return Ae.lookAtMat4v([e,t,n],[r,i,s],[a,o,A],[])},orthoMat4c:function(e,t,n,r,i,s,a){a||(a=Ae.mat4());var o=t-e,A=r-n,c=s-i;return a[0]=2/o,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=2/A,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=-2/c,a[11]=0,a[12]=-(e+t)/o,a[13]=-(r+n)/A,a[14]=-(s+i)/c,a[15]=1,a},frustumMat4v:function(e,t,n){n||(n=Ae.mat4());var r=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];Ae.addVec4(i,r,se),Ae.subVec4(i,r,ae);var s=2*r[2],a=ae[0],o=ae[1],A=ae[2];return n[0]=s/a,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=s/o,n[6]=0,n[7]=0,n[8]=se[0]/a,n[9]=se[1]/o,n[10]=-se[2]/A,n[11]=-1,n[12]=0,n[13]=0,n[14]=-s*i[2]/A,n[15]=0,n},frustumMat4:function(e,t,n,r,i,s,a){a||(a=Ae.mat4());var o=t-e,A=r-n,c=s-i;return a[0]=2*i/o,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=2*i/A,a[6]=0,a[7]=0,a[8]=(t+e)/o,a[9]=(r+n)/A,a[10]=-(s+i)/c,a[11]=-1,a[12]=0,a[13]=0,a[14]=-s*i*2/c,a[15]=0,a},perspectiveMat4:function(e,t,n,r,i){var s=[],a=[];return s[2]=n,a[2]=r,a[1]=s[2]*Math.tan(e/2),s[1]=-a[1],a[0]=a[1]*t,s[0]=-a[0],Ae.frustumMat4v(s,a,i)},compareMat4:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15]},transformPoint3:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec3(),r=t[0],i=t[1],s=t[2];return n[0]=e[0]*r+e[4]*i+e[8]*s+e[12],n[1]=e[1]*r+e[5]*i+e[9]*s+e[13],n[2]=e[2]*r+e[6]*i+e[10]*s+e[14],n},transformPoint4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec4();return n[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],n[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],n[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],n[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],n},transformPoints3:function(e,t,n){for(var r,i,s,a,o,A=n||[],c=t.length,l=e[0],u=e[1],h=e[2],d=e[3],f=e[4],p=e[5],v=e[6],g=e[7],m=e[8],y=e[9],_=e[10],b=e[11],w=e[12],B=e[13],C=e[14],M=e[15],k=0;k<c;++k)r=(a=t[k])[0],i=a[1],s=a[2],(o=A[k]||(A[k]=[0,0,0]))[0]=l*r+f*i+m*s+w,o[1]=u*r+p*i+y*s+B,o[2]=h*r+v*i+_*s+C,o[3]=d*r+g*i+b*s+M;return A.length=c,A},transformPositions3:function(e,t){var n,r,i,s,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,A=e[0],c=e[1],l=e[2];e[3];var u=e[4],h=e[5],d=e[6];e[7];var f=e[8],p=e[9],v=e[10];e[11];var g=e[12],m=e[13],y=e[14];for(e[15],n=0;n<o;n+=3)r=t[n+0],i=t[n+1],s=t[n+2],a[n+0]=A*r+u*i+f*s+g,a[n+1]=c*r+h*i+p*s+m,a[n+2]=l*r+d*i+v*s+y;return a},transformPositions4:function(e,t){var n,r,i,s,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,A=e[0],c=e[1],l=e[2],u=e[3],h=e[4],d=e[5],f=e[6],p=e[7],v=e[8],g=e[9],m=e[10],y=e[11],_=e[12],b=e[13],w=e[14],B=e[15];for(n=0;n<o;n+=4)r=t[n+0],i=t[n+1],s=t[n+2],a[n+0]=A*r+h*i+v*s+_,a[n+1]=c*r+d*i+g*s+b,a[n+2]=l*r+f*i+m*s+w,a[n+3]=u*r+p*i+y*s+B;return a},transformVec3:function(e,t,n){var r=t[0],i=t[1],s=t[2];return(n=n||this.vec3())[0]=e[0]*r+e[4]*i+e[8]*s,n[1]=e[1]*r+e[5]*i+e[9]*s,n[2]=e[2]*r+e[6]*i+e[10]*s,n},transformVec4:function(e,t,n){var r=t[0],i=t[1],s=t[2],a=t[3];return(n=n||Ae.vec4())[0]=e[0]*r+e[4]*i+e[8]*s+e[12]*a,n[1]=e[1]*r+e[5]*i+e[9]*s+e[13]*a,n[2]=e[2]*r+e[6]*i+e[10]*s+e[14]*a,n[3]=e[3]*r+e[7]*i+e[11]*s+e[15]*a,n},rotateVec2:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e,i=Math.cos(n),s=Math.sin(n),a=e[0]-t[0],o=e[1]-t[1];return r[0]=a*i-o*s+t[0],r[1]=a*s+o*i+t[1],e},rotateVec3X:function(e,t,n,r){var i=[],s=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],s[0]=i[0],s[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),s[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),r[0]=s[0]+t[0],r[1]=s[1]+t[1],r[2]=s[2]+t[2],r},rotateVec3Y:function(e,t,n,r){var i=[],s=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],s[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),s[1]=i[1],s[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),r[0]=s[0]+t[0],r[1]=s[1]+t[1],r[2]=s[2]+t[2],r},rotateVec3Z:function(e,t,n,r){var i=[],s=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],s[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),s[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),s[2]=i[2],r[0]=s[0]+t[0],r[1]=s[1]+t[1],r[2]=s[2]+t[2],r},projectVec4:function(e,t){var n=1/e[3];return(t=t||Ae.vec2())[0]=e[0]*n,t[1]=e[1]*n,t},unprojectVec3:(j=new re(16),W=new re(16),z=new re(16),function(e,t,n,r){return this.transformVec3(this.mulMat4(this.inverseMat4(t,j),this.inverseMat4(n,W),z),e,r)}),lerpVec3:function(e,t,n,r,i,s){var a=s||Ae.vec3(),o=(e-t)/(n-t);return a[0]=r[0]+o*(i[0]-r[0]),a[1]=r[1]+o*(i[1]-r[1]),a[2]=r[2]+o*(i[2]-r[2]),a},lerpMat4:function(e,t,n,r,i,s){var a=s||Ae.mat4(),o=(e-t)/(n-t);return a[0]=r[0]+o*(i[0]-r[0]),a[1]=r[1]+o*(i[1]-r[1]),a[2]=r[2]+o*(i[2]-r[2]),a[3]=r[3]+o*(i[3]-r[3]),a[4]=r[4]+o*(i[4]-r[4]),a[5]=r[5]+o*(i[5]-r[5]),a[6]=r[6]+o*(i[6]-r[6]),a[7]=r[7]+o*(i[7]-r[7]),a[8]=r[8]+o*(i[8]-r[8]),a[9]=r[9]+o*(i[9]-r[9]),a[10]=r[10]+o*(i[10]-r[10]),a[11]=r[11]+o*(i[11]-r[11]),a[12]=r[12]+o*(i[12]-r[12]),a[13]=r[13]+o*(i[13]-r[13]),a[14]=r[14]+o*(i[14]-r[14]),a[15]=r[15]+o*(i[15]-r[15]),a},flatten:function(e){var t,n,r,i,s,a=[];for(t=0,n=e.length;t<n;t++)for(r=0,i=(s=e[t]).length;r<i;r++)a.push(s[r]);return a},identityQuaternion:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Ae.vec4();return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},eulerToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec4(),r=e[0]*Ae.DEGTORAD/2,i=e[1]*Ae.DEGTORAD/2,s=e[2]*Ae.DEGTORAD/2,a=Math.cos(r),o=Math.cos(i),A=Math.cos(s),c=Math.sin(r),l=Math.sin(i),u=Math.sin(s);return"XYZ"===t?(n[0]=c*o*A+a*l*u,n[1]=a*l*A-c*o*u,n[2]=a*o*u+c*l*A,n[3]=a*o*A-c*l*u):"YXZ"===t?(n[0]=c*o*A+a*l*u,n[1]=a*l*A-c*o*u,n[2]=a*o*u-c*l*A,n[3]=a*o*A+c*l*u):"ZXY"===t?(n[0]=c*o*A-a*l*u,n[1]=a*l*A+c*o*u,n[2]=a*o*u+c*l*A,n[3]=a*o*A-c*l*u):"ZYX"===t?(n[0]=c*o*A-a*l*u,n[1]=a*l*A+c*o*u,n[2]=a*o*u-c*l*A,n[3]=a*o*A+c*l*u):"YZX"===t?(n[0]=c*o*A+a*l*u,n[1]=a*l*A+c*o*u,n[2]=a*o*u-c*l*A,n[3]=a*o*A-c*l*u):"XZY"===t&&(n[0]=c*o*A-a*l*u,n[1]=a*l*A-c*o*u,n[2]=a*o*u+c*l*A,n[3]=a*o*A+c*l*u),n},mat4ToQuaternion:function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.vec4(),r=e[0],i=e[4],s=e[8],a=e[1],o=e[5],A=e[9],c=e[2],l=e[6],u=e[10],h=r+o+u;return h>0?(t=.5/Math.sqrt(h+1),n[3]=.25/t,n[0]=(l-A)*t,n[1]=(s-c)*t,n[2]=(a-i)*t):r>o&&r>u?(t=2*Math.sqrt(1+r-o-u),n[3]=(l-A)/t,n[0]=.25*t,n[1]=(i+a)/t,n[2]=(s+c)/t):o>u?(t=2*Math.sqrt(1+o-r-u),n[3]=(s-c)/t,n[0]=(i+a)/t,n[1]=.25*t,n[2]=(A+l)/t):(t=2*Math.sqrt(1+u-r-o),n[3]=(a-i)/t,n[0]=(s+c)/t,n[1]=(A+l)/t,n[2]=.25*t),n},vec3PairToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec4(),r=Math.sqrt(Ae.dotVec3(e,e)*Ae.dotVec3(t,t)),i=r+Ae.dotVec3(e,t);return i<1e-8*r?(i=0,Math.abs(e[0])>Math.abs(e[2])?(n[0]=-e[1],n[1]=e[0],n[2]=0):(n[0]=0,n[1]=-e[2],n[2]=e[1])):Ae.cross3Vec3(e,t,n),n[3]=i,Ae.normalizeQuaternion(n)},angleAxisToQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.vec4(),n=e[3]/2,r=Math.sin(n);return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=Math.cos(n),t},quaternionToEuler:function(){var e=new re(16);return function(t,n,r){return r=r||Ae.vec3(),Ae.quaternionToRotationMat4(t,e),Ae.mat4ToEuler(e,n,r),r}}(),mulQuaternions:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec4(),r=e[0],i=e[1],s=e[2],a=e[3],o=t[0],A=t[1],c=t[2],l=t[3];return n[0]=a*o+r*l+i*c-s*A,n[1]=a*A+i*l+s*o-r*c,n[2]=a*c+s*l+r*A-i*o,n[3]=a*l-r*o-i*A-s*c,n},vec3ApplyQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec3(),r=t[0],i=t[1],s=t[2],a=e[0],o=e[1],A=e[2],c=e[3],l=c*r+o*s-A*i,u=c*i+A*r-a*s,h=c*s+a*i-o*r,d=-a*r-o*i-A*s;return n[0]=l*c+d*-a+u*-A-h*-o,n[1]=u*c+d*-o+h*-a-l*-A,n[2]=h*c+d*-A+l*-o-u*-a,n},quaternionToMat4:function(e,t){t=Ae.identityMat4(t);var n=e[0],r=e[1],i=e[2],s=e[3],a=2*n,o=2*r,A=2*i,c=a*s,l=o*s,u=A*s,h=a*n,d=o*n,f=A*n,p=o*r,v=A*r,g=A*i;return t[0]=1-(p+g),t[1]=d+u,t[2]=f-l,t[4]=d-u,t[5]=1-(h+g),t[6]=v+c,t[8]=f+l,t[9]=v-c,t[10]=1-(h+p),t},quaternionToRotationMat4:function(e,t){var n=e[0],r=e[1],i=e[2],s=e[3],a=n+n,o=r+r,A=i+i,c=n*a,l=n*o,u=n*A,h=r*o,d=r*A,f=i*A,p=s*a,v=s*o,g=s*A;return t[0]=1-(h+f),t[4]=l-g,t[8]=u+v,t[1]=l+g,t[5]=1-(c+f),t[9]=d-p,t[2]=u-v,t[6]=d+p,t[10]=1-(c+h),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=Ae.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/n,t[1]=e[1]/n,t[2]=e[2]/n,t[3]=e[3]/n,t},conjugateQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e;return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},inverseQuaternion:function(e,t){return Ae.normalizeQuaternion(Ae.conjugateQuaternion(e,t))},quaternionToAngleAxis:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.vec4(),n=(e=Ae.normalizeQuaternion(e,oe))[3],r=2*Math.acos(n),i=Math.sqrt(1-n*n);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=r,t},AABB3:function(e){return new re(e||6)},AABB2:function(e){return new re(e||4)},OBB3:function(e){return new re(e||32)},OBB2:function(e){return new re(e||16)},Sphere3:function(e,t,n,r){return new re([e,t,n,r])},transformOBB3:function(e,t){var n,r,i,s,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,A=e[0],c=e[1],l=e[2],u=e[3],h=e[4],d=e[5],f=e[6],p=e[7],v=e[8],g=e[9],m=e[10],y=e[11],_=e[12],b=e[13],w=e[14],B=e[15];for(n=0;n<o;n+=4)r=t[n+0],i=t[n+1],s=t[n+2],a[n+0]=A*r+h*i+v*s+_,a[n+1]=c*r+d*i+g*s+b,a[n+2]=l*r+f*i+m*s+w,a[n+3]=u*r+p*i+y*s+B;return a},containsAABB3:function(e,t){return e[0]<=t[0]&&t[3]<=e[3]&&e[1]<=t[1]&&t[4]<=e[4]&&e[2]<=t[2]&&t[5]<=e[5]},getAABB3Diag:function(){var e=new re(3),t=new re(3),n=new re(3);return function(r){return e[0]=r[0],e[1]=r[1],e[2]=r[2],t[0]=r[3],t[1]=r[4],t[2]=r[5],Ae.subVec3(t,e,n),Math.abs(Ae.lenVec3(n))}}(),getAABB3DiagPoint:function(){var e=new re(3),t=new re(3),n=new re(3);return function(r,i){e[0]=r[0],e[1]=r[1],e[2]=r[2],t[0]=r[3],t[1]=r[4],t[2]=r[5];var s=Ae.subVec3(t,e,n),a=i[0]-r[0],o=r[3]-i[0],A=i[1]-r[1],c=r[4]-i[1],l=i[2]-r[2],u=r[5]-i[2];return s[0]+=a>o?a:o,s[1]+=A>c?A:c,s[2]+=l>u?l:u,Math.abs(Ae.lenVec3(s))}}(),getAABB3Area:function(e){return(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2])},getAABB3Center:function(e,t){var n=t||Ae.vec3();return n[0]=(e[0]+e[3])/2,n[1]=(e[1]+e[4])/2,n[2]=(e[2]+e[5])/2,n},getAABB2Center:function(e,t){var n=t||Ae.vec2();return n[0]=(e[2]+e[0])/2,n[1]=(e[3]+e[1])/2,n},collapseAABB3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Ae.AABB3();return e[0]=Ae.MAX_DOUBLE,e[1]=Ae.MAX_DOUBLE,e[2]=Ae.MAX_DOUBLE,e[3]=Ae.MIN_DOUBLE,e[4]=Ae.MIN_DOUBLE,e[5]=Ae.MIN_DOUBLE,e},AABB3ToOBB3:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.OBB3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t},positions3ToAABB3:function(){var e=new re(3);return function(t,n,r){n=n||Ae.AABB3();for(var i,s,a,o=Ae.MAX_DOUBLE,A=Ae.MAX_DOUBLE,c=Ae.MAX_DOUBLE,l=Ae.MIN_DOUBLE,u=Ae.MIN_DOUBLE,h=Ae.MIN_DOUBLE,d=0,f=t.length;d<f;d+=3)r?(e[0]=t[d+0],e[1]=t[d+1],e[2]=t[d+2],Ae.decompressPosition(e,r,e),i=e[0],s=e[1],a=e[2]):(i=t[d+0],s=t[d+1],a=t[d+2]),i<o&&(o=i),s<A&&(A=s),a<c&&(c=a),i>l&&(l=i),s>u&&(u=s),a>h&&(h=a);return n[0]=o,n[1]=A,n[2]=c,n[3]=l,n[4]=u,n[5]=h,n}}(),OBB3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.AABB3(),s=Ae.MAX_DOUBLE,a=Ae.MAX_DOUBLE,o=Ae.MAX_DOUBLE,A=Ae.MIN_DOUBLE,c=Ae.MIN_DOUBLE,l=Ae.MIN_DOUBLE,u=0,h=e.length;u<h;u+=4)(t=e[u+0])<s&&(s=t),(n=e[u+1])<a&&(a=n),(r=e[u+2])<o&&(o=r),t>A&&(A=t),n>c&&(c=n),r>l&&(l=r);return i[0]=s,i[1]=a,i[2]=o,i[3]=A,i[4]=c,i[5]=l,i},points3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.AABB3(),s=Ae.MAX_DOUBLE,a=Ae.MAX_DOUBLE,o=Ae.MAX_DOUBLE,A=Ae.MIN_DOUBLE,c=Ae.MIN_DOUBLE,l=Ae.MIN_DOUBLE,u=0,h=e.length;u<h;u++)(t=e[u][0])<s&&(s=t),(n=e[u][1])<a&&(a=n),(r=e[u][2])<o&&(o=r),t>A&&(A=t),n>c&&(c=n),r>l&&(l=r);return i[0]=s,i[1]=a,i[2]=o,i[3]=A,i[4]=c,i[5]=l,i},points3ToSphere3:function(){var e=new re(3);return function(t,n){n=n||Ae.vec4();var r,i=0,s=0,a=0,o=t.length;for(r=0;r<o;r++)i+=t[r][0],s+=t[r][1],a+=t[r][2];n[0]=i/o,n[1]=s/o,n[2]=a/o;var A,c=0;for(r=0;r<o;r++)(A=Math.abs(Ae.lenVec3(Ae.subVec3(t[r],n,e))))>c&&(c=A);return n[3]=c,n}}(),positions3ToSphere3:function(){var e=new re(3),t=new re(3);return function(n,r){r=r||Ae.vec4();var i,s=0,a=0,o=0,A=n.length,c=0;for(i=0;i<A;i+=3)s+=n[i],a+=n[i+1],o+=n[i+2];var l,u=A/3;for(r[0]=s/u,r[1]=a/u,r[2]=o/u,i=0;i<A;i+=3)e[0]=n[i],e[1]=n[i+1],e[2]=n[i+2],(l=Math.abs(Ae.lenVec3(Ae.subVec3(e,r,t))))>c&&(c=l);return r[3]=c,r}}(),OBB3ToSphere3:function(){var e=new re(3),t=new re(3);return function(n,r){r=r||Ae.vec4();var i,s=0,a=0,o=0,A=n.length,c=A/4;for(i=0;i<A;i+=4)s+=n[i+0],a+=n[i+1],o+=n[i+2];r[0]=s/c,r[1]=a/c,r[2]=o/c;var l,u=0;for(i=0;i<A;i+=4)e[0]=n[i+0],e[1]=n[i+1],e[2]=n[i+2],(l=Math.abs(Ae.lenVec3(Ae.subVec3(e,r,t))))>u&&(u=l);return r[3]=u,r}}(),getSphere3Center:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.vec3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},getPositionsCenter:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.vec3(),n=0,r=0,i=0,s=0,a=e.length;s<a;s+=3)n+=e[s+0],r+=e[s+1],i+=e[s+2];var o=e.length/3;return t[0]=n/o,t[1]=r/o,t[2]=i/o,t},expandAABB3:function(e,t){return e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]<t[3]&&(e[3]=t[3]),e[4]<t[4]&&(e[4]=t[4]),e[5]<t[5]&&(e[5]=t[5]),e},expandAABB3Point3:function(e,t){return e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]<t[0]&&(e[3]=t[0]),e[4]<t[1]&&(e[4]=t[1]),e[5]<t[2]&&(e[5]=t[2]),e},expandAABB3Points3:function(e,t){for(var n,r,i,s=0,a=t.length;s<a;s+=3)n=t[s],r=t[s+1],i=t[s+2],e[0]>n&&(e[0]=n),e[1]>r&&(e[1]=r),e[2]>i&&(e[2]=i),e[3]<n&&(e[3]=n),e[4]<r&&(e[4]=r),e[5]<i&&(e[5]=i);return e},collapseAABB2:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Ae.AABB2();return e[0]=Ae.MAX_DOUBLE,e[1]=Ae.MAX_DOUBLE,e[2]=Ae.MIN_DOUBLE,e[3]=Ae.MIN_DOUBLE,e},point3AABB3Intersect:function(e,t){return e[0]>t[0]||e[3]<t[0]||e[1]>t[1]||e[4]<t[1]||e[2]>t[2]||e[5]<t[2]},point3AABB3AbsoluteIntersect:function(e,t){return e[0]<=t[0]&&e[3]>=t[0]&&e[1]<=t[1]&&e[4]>=t[1]&&e[2]<=t[2]&&e[5]>=t[2]},planeAABB3Intersect:function(e,t,n){var r,i;return e[0]>0?(r=e[0]*n[0],i=e[0]*n[3]):(r=e[0]*n[3],i=e[0]*n[0]),e[1]>0?(r+=e[1]*n[1],i+=e[1]*n[4]):(r+=e[1]*n[4],i+=e[1]*n[1]),e[2]>0?(r+=e[2]*n[2],i+=e[2]*n[5]):(r+=e[2]*n[5],i+=e[2]*n[2]),r<=-t&&i<=-t?-1:r>=-t&&i>=-t?1:0},OBB3ToAABB2:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.AABB2(),s=Ae.MAX_DOUBLE,a=Ae.MAX_DOUBLE,o=Ae.MIN_DOUBLE,A=Ae.MIN_DOUBLE,c=0,l=e.length;c<l;c+=4)t=e[c+0],n=e[c+1],(t*=r=1/(e[c+3]||1))<s&&(s=t),(n*=r)<a&&(a=n),t>o&&(o=t),n>A&&(A=n);return i[0]=s,i[1]=a,i[2]=o,i[3]=A,i},expandAABB2:function(e,t){return e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]<t[2]&&(e[2]=t[2]),e[3]<t[3]&&(e[3]=t[3]),e},expandAABB2Point2:function(e,t){return e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]<t[0]&&(e[2]=t[0]),e[3]<t[1]&&(e[3]=t[1]),e},AABB2ToCanvas:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e,i=.5*(e[0]+1),s=.5*(e[1]+1),a=.5*(e[2]+1),o=.5*(e[3]+1);return r[0]=Math.floor(i*t),r[1]=n-Math.floor(o*n),r[2]=Math.floor(a*t),r[3]=n-Math.floor(s*n),r},tangentQuadraticBezier:function(e,t,n,r){return 2*(1-e)*(n-t)+2*e*(r-n)},tangentQuadraticBezier3:function(e,t,n,r,i){return-3*t*(1-e)*(1-e)+3*n*(1-e)*(1-e)-6*e*n*(1-e)+6*e*r*(1-e)-3*e*e*r+3*e*e*i},tangentSpline:function(e){return 6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e)},catmullRomInterpolate:function(e,t,n,r,i){var s=.5*(n-e),a=.5*(r-t),o=i*i;return(2*t-2*n+s+a)*(i*o)+(-3*t+3*n-2*s-a)*o+s*i+t},b2p0:function(e,t){var n=1-e;return n*n*t},b2p1:function(e,t){return 2*(1-e)*e*t},b2p2:function(e,t){return e*e*t},b2:function(e,t,n,r){return this.b2p0(e,t)+this.b2p1(e,n)+this.b2p2(e,r)},b3p0:function(e,t){var n=1-e;return n*n*n*t},b3p1:function(e,t){var n=1-e;return 3*n*n*e*t},b3p2:function(e,t){return 3*(1-e)*e*e*t},b3p3:function(e,t){return e*e*e*t},b3:function(e,t,n,r,i){return this.b3p0(e,t)+this.b3p1(e,n)+this.b3p2(e,r)+this.b3p3(e,i)},triangleNormal:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Ae.vec3(),i=t[0]-e[0],s=t[1]-e[1],a=t[2]-e[2],o=n[0]-e[0],A=n[1]-e[1],c=n[2]-e[2],l=s*c-a*A,u=a*o-i*c,h=i*A-s*o,d=Math.sqrt(l*l+u*u+h*h);return 0===d?(r[0]=0,r[1]=0,r[2]=0):(r[0]=l/d,r[1]=u/d,r[2]=h/d),r},rayTriangleIntersect:function(){var e=new re(3),t=new re(3),n=new re(3),r=new re(3),i=new re(3);return function(s,a,o,A,c,l){l=l||Ae.vec3();var u=Ae.subVec3(A,o,e),h=Ae.subVec3(c,o,t),d=Ae.cross3Vec3(a,h,n),f=Ae.dotVec3(u,d);if(f<1e-6)return null;var p=Ae.subVec3(s,o,r),v=Ae.dotVec3(p,d);if(v<0||v>f)return null;var g=Ae.cross3Vec3(p,u,i),m=Ae.dotVec3(a,g);if(m<0||v+m>f)return null;var y=Ae.dotVec3(h,g)/f;return l[0]=s[0]+y*a[0],l[1]=s[1]+y*a[1],l[2]=s[2]+y*a[2],l}}(),rayPlaneIntersect:function(){var e=new re(3),t=new re(3),n=new re(3),r=new re(3);return function(i,s,a,o,A,c){c=c||Ae.vec3(),s=Ae.normalizeVec3(s,e);var l=Ae.subVec3(o,a,t),u=Ae.subVec3(A,a,n),h=Ae.cross3Vec3(l,u,r);Ae.normalizeVec3(h,h);var d=-Ae.dotVec3(a,h),f=-(Ae.dotVec3(i,h)+d)/Ae.dotVec3(s,h);return c[0]=i[0]+f*s[0],c[1]=i[1]+f*s[1],c[2]=i[2]+f*s[2],c}}(),cartesianToBarycentric:function(){var e=new re(3),t=new re(3),n=new re(3);return function(r,i,s,a,o){var A=Ae.subVec3(a,i,e),c=Ae.subVec3(s,i,t),l=Ae.subVec3(r,i,n),u=Ae.dotVec3(A,A),h=Ae.dotVec3(A,c),d=Ae.dotVec3(A,l),f=Ae.dotVec3(c,c),p=Ae.dotVec3(c,l),v=u*f-h*h;if(0===v)return null;var g=1/v,m=(f*d-h*p)*g,y=(u*p-h*d)*g;return o[0]=1-m-y,o[1]=y,o[2]=m,o}}(),barycentricInsideTriangle:function(e){var t=e[1],n=e[2];return n>=0&&t>=0&&n+t<1},barycentricToCartesian:function(e,t,n,r){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Ae.vec3(),s=e[0],a=e[1],o=e[2];return i[0]=t[0]*s+n[0]*a+r[0]*o,i[1]=t[1]*s+n[1]*a+r[1]*o,i[2]=t[2]*s+n[2]*a+r[2]*o,i},mergeVertices:function(e,t,n,r){var i,s,a,o,A,c,l={},u=[],h=[],d=t?[]:null,f=n?[]:null,p=[],v=Math.pow(10,4),g=0;for(A=0,c=e.length;A<c;A+=3)i=e[A],s=e[A+1],a=e[A+2],void 0===l[o="".concat(Math.round(i*v),"_").concat(Math.round(s*v),"_").concat(Math.round(a*v))]&&(l[o]=h.length/3,h.push(i),h.push(s),h.push(a),t&&(d.push(t[A]),d.push(t[A+1]),d.push(t[A+2])),n&&(f.push(n[g]),f.push(n[g+1]))),u[A/3]=l[o],g+=2;for(A=0,c=r.length;A<c;A++)p[A]=u[r[A]];var m={positions:h,indices:p};return d&&(m.normals=d),f&&(m.uv=f),m},buildNormals:function(){var e=new re(3),t=new re(3),n=new re(3),r=new re(3),i=new re(3),s=new re(3);return function(a,o,A){var c,l,u,h,d,f,p,v,g,m=new Array(a.length/3);for(c=0,l=o.length;c<l;c+=3){u=o[c],h=o[c+1],d=o[c+2],e[0]=a[3*u],e[1]=a[3*u+1],e[2]=a[3*u+2],t[0]=a[3*h],t[1]=a[3*h+1],t[2]=a[3*h+2],n[0]=a[3*d],n[1]=a[3*d+1],n[2]=a[3*d+2],Ae.subVec3(t,e,r),Ae.subVec3(n,e,i);var y=Ae.vec3();Ae.normalizeVec3(Ae.cross3Vec3(r,i,s),y),m[u]||(m[u]=[]),m[h]||(m[h]=[]),m[d]||(m[d]=[]),m[u].push(y),m[h].push(y),m[d].push(y)}for(A=A&&A.length===a.length?A:new Float32Array(a.length),c=0,l=m.length;c<l;c++){f=m[c].length,p=0,v=0,g=0;for(var _=0;_<f;_++)p+=m[c][_][0],v+=m[c][_][1],g+=m[c][_][2];A[3*c]=p/f,A[3*c+1]=v/f,A[3*c+2]=g/f}return A}}(),buildTangents:function(){var e=new re(3),t=new re(3),n=new re(3),r=new re(3),i=new re(3),s=new re(3),a=new re(3);return function(o,A,c){for(var l=new Float32Array(o.length),u=0;u<A.length;u+=3){var h=A[u],d=o.subarray(3*h,3*h+3),f=c.subarray(2*h,2*h+2);h=A[u+1];var p=o.subarray(3*h,3*h+3),v=c.subarray(2*h,2*h+2);h=A[u+2];for(var g=o.subarray(3*h,3*h+3),m=c.subarray(2*h,2*h+2),y=Ae.subVec3(p,d,e),_=Ae.subVec3(g,d,t),b=Ae.subVec2(v,f,n),w=Ae.subVec2(m,f,r),B=1/(b[0]*w[1]-b[1]*w[0]),C=Ae.mulVec3Scalar(Ae.subVec3(Ae.mulVec3Scalar(y,w[1],i),Ae.mulVec3Scalar(_,b[1],s),a),B,s),M=void 0,k=0;k<3;k++)l[M=3*A[u+k]]+=C[0],l[M+1]+=C[1],l[M+2]+=C[2]}return l}}(),buildPickTriangles:function(e,t,n){for(var r,i,s,a,o,A=t.length,c=n?new Uint16Array(9*A):new Float32Array(9*A),l=new Uint8Array(12*A),u=0,h=0,d=0,f=0;f<A;f+=3)o=u>>24&255,a=u>>16&255,s=u>>8&255,i=255&u,r=3*t[f],c[h++]=e[r],c[h++]=e[r+1],c[h++]=e[r+2],l[d++]=i,l[d++]=s,l[d++]=a,l[d++]=o,r=3*t[f+1],c[h++]=e[r],c[h++]=e[r+1],c[h++]=e[r+2],l[d++]=i,l[d++]=s,l[d++]=a,l[d++]=o,r=3*t[f+2],c[h++]=e[r],c[h++]=e[r+1],c[h++]=e[r+2],l[d++]=i,l[d++]=s,l[d++]=a,l[d++]=o,u++;return{positions:c,colors:l}},faceToVertexNormals:function(e,t){var n,r,i,s,a,o,A,c,l,u,h,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},f=d.smoothNormalsAngleThreshold||20,p={},v=[],g={},m=4,y=Math.pow(10,m);for(A=0,l=e.length;A<l;A+=3){o=A/3,r=e[A],i=e[A+1],s=e[A+2],void 0===p[a="".concat(Math.round(r*y),"_").concat(Math.round(i*y),"_").concat(Math.round(s*y))]?p[a]=[o]:p[a].push(o);var _=Ae.normalizeVec3([t[A],t[A+1],t[A+2]]);v[o]=_,n=Ae.vec4([_[0],_[1],_[2],1]),g[o]=n}for(a in p)if(p.hasOwnProperty(a)){var b=p[a],w=b.length;for(A=0;A<w;A++){var B=b[A];for(n=g[B],c=0;c<w;c++)if(A!==c){var C=b[c];u=v[B],h=v[C];var M=Math.abs(Ae.angleVec3(u,h)/Ae.DEGTORAD);M<f&&(n[0]+=h[0],n[1]+=h[1],n[2]+=h[2],n[3]+=1)}}}for(A=0,l=t.length;A<l;A+=3)n=g[A/3],t[A+0]=n[0]/n[3],t[A+1]=n[1]/n[3],t[A+2]=n[2]/n[3]},transformRay:function(){var e=new re(4),t=new re(4);return function(n,r,i,s,a){e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=1,Ae.transformVec4(n,e,t),s[0]=t[0],s[1]=t[1],s[2]=t[2],e[0]=i[0],e[1]=i[1],e[2]=i[2],Ae.transformVec3(n,e,t),Ae.normalizeVec3(t),a[0]=t[0],a[1]=t[1],a[2]=t[2]}}(),canvasPosToWorldRay:(L=new re(16),H=new re(4),N=new re(4),G=function(e,t,n,r,i){i[0]=e,i[1]=t,i[2]=n,i[3]=1,Ae.transformVec4(L,i,i),r||Ae.mulVec4Scalar(i,1/i[3])},function(e,t,n,r,i,s,a){var o="ortho"===r;Ae.mulMat4(n,t,L),Ae.inverseMat4(L,L);var A=2*i[0]/e.clientWidth-1,c=1-2*i[1]/e.clientHeight;G(A,c,-1,o,H),G(A,c,1,o,N),s[0]=H[0],s[1]=H[1],s[2]=H[2],Ae.subVec3(N,H,a),Ae.normalizeVec3(a)}),canvasPosToLocalRay:(O=new re(3),V=new re(3),function(e,t,n,r,i,s,a,o){Ae.canvasPosToWorldRay(e,t,n,r,s,O,V),Ae.worldRayToLocalRay(i,O,V,a,o)}),worldRayToLocalRay:function(){var e=new re(16),t=new re(4),n=new re(4);return function(r,i,s,a,o){var A=Ae.inverseMat4(r,e);t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,Ae.transformVec4(A,t,n),a[0]=n[0],a[1]=n[1],a[2]=n[2],Ae.transformVec3(A,s,o)}}(),buildKDTree:function(){var e=new Float32Array;function t(n,r,i,s){var a,o,A=new re(6),c={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:A};for(A[0]=A[1]=A[2]=Number.POSITIVE_INFINITY,A[3]=A[4]=A[5]=Number.NEGATIVE_INFINITY,a=0,o=n.length;a<o;++a)for(var l=3*n[a],u=0;u<3;++u){var h=3*r[l+u];i[h]<A[0]&&(A[0]=i[h]),i[h]>A[3]&&(A[3]=i[h]),i[h+1]<A[1]&&(A[1]=i[h+1]),i[h+1]>A[4]&&(A[4]=i[h+1]),i[h+2]<A[2]&&(A[2]=i[h+2]),i[h+2]>A[5]&&(A[5]=i[h+2])}if(n.length<20||s>10)return c.triangles=n,c.leaf=!0,c;e[0]=A[3]-A[0],e[1]=A[4]-A[1],e[2]=A[5]-A[2];var d=0;e[1]>e[d]&&(d=1),e[2]>e[d]&&(d=2),c.splitDim=d;var f=(A[d]+A[d+3])/2,p=new Array(n.length),v=0,g=new Array(n.length),m=0;for(a=0,o=n.length;a<o;++a){var y=r[l=3*n[a]],_=3*r[l+1],b=3*r[l+2];i[3*y+d]<=f||i[_+d]<=f||i[b+d]<=f?p[v++]=n[a]:g[m++]=n[a]}return p.length=v,g.length=m,c.left=t(p,r,i,s+1),c.right=t(g,r,i,s+1),c}return function(e,n){for(var r=e.length/3,i=new Array(r),s=0;s<r;++s)i[s]=s;return t(i,e,n,0)}}(),decompressPosition:function(e,t,n){(n=n||e)[0]=e[0]*t[0]+t[12],n[1]=e[1]*t[5]+t[13],n[2]=e[2]*t[10]+t[14]},decompressPositions:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r<i;r+=3)n[r+0]=e[r+0]*t[0]+t[12],n[r+1]=e[r+1]*t[5]+t[13],n[r+2]=e[r+2]*t[10]+t[14];return n},decompressUV:function(e,t,n){n[0]=e[0]*t[0]+t[6],n[1]=e[1]*t[4]+t[7]},decompressUVs:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r<i;r+=3)n[r+0]=e[r+0]*t[0]+t[6],n[r+1]=e[r+1]*t[4]+t[7];return n},octDecodeVec2:function(e,t){var n=e[0],r=e[1];n=(2*n+1)/255,r=(2*r+1)/255;var i=1-Math.abs(n)-Math.abs(r);i<0&&(n=(1-Math.abs(r))*(n>=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var s=Math.sqrt(n*n+r*r+i*i);return t[0]=n/s,t[1]=r/s,t[2]=i/s,t},octDecodeVec2s:function(e,t){for(var n=0,r=0,i=e.length;n<i;n+=2){var s=e[n+0],a=e[n+1];s=(2*s+1)/255,a=(2*a+1)/255;var o=1-Math.abs(s)-Math.abs(a);o<0&&(s=(1-Math.abs(a))*(s>=0?1:-1),a=(1-Math.abs(s))*(a>=0?1:-1));var A=Math.sqrt(s*s+a*a+o*o);t[r+0]=s/A,t[r+1]=a/A,t[r+2]=o/A,r+=3}return t}};Ae.buildEdgeIndices=function(){var e=[],t=[],n=[],r=[],i=[],s=0,a=new Uint16Array(3),o=new Uint16Array(3),A=new Uint16Array(3),c=Ae.vec3(),l=Ae.vec3(),u=Ae.vec3(),h=Ae.vec3(),d=Ae.vec3(),f=Ae.vec3(),p=Ae.vec3();return function(v,g,m,y){!function(i,s){var a,o,A,c,l,u,h={},d=Math.pow(10,4),f=0;for(l=0,u=i.length;l<u;l+=3)a=i[l],o=i[l+1],A=i[l+2],void 0===h[c=Math.round(a*d)+"_"+Math.round(o*d)+"_"+Math.round(A*d)]&&(h[c]=f/3,e[f++]=a,e[f++]=o,e[f++]=A),t[l/3]=h[c];for(l=0,u=s.length;l<u;l++)r[l]=t[s[l]],n[r[l]]=s[l]}(v,g),function(t,n){s=0;for(var v=0,g=t;v<g;v+=3){var m=3*r[v],y=3*r[v+1],_=3*r[v+2];n?(a[0]=e[m],a[1]=e[m+1],a[2]=e[m+2],o[0]=e[y],o[1]=e[y+1],o[2]=e[y+2],A[0]=e[_],A[1]=e[_+1],A[2]=e[_+2],Ae.decompressPosition(a,n,c),Ae.decompressPosition(o,n,l),Ae.decompressPosition(A,n,u)):(c[0]=e[m],c[1]=e[m+1],c[2]=e[m+2],l[0]=e[y],l[1]=e[y+1],l[2]=e[y+2],u[0]=e[_],u[1]=e[_+1],u[2]=e[_+2]),Ae.subVec3(u,l,h),Ae.subVec3(c,l,d),Ae.cross3Vec3(h,d,f),Ae.normalizeVec3(f,p);var b=i[s]||(i[s]={normal:Ae.vec3()});b.normal[0]=p[0],b.normal[1]=p[1],b.normal[2]=p[2],s++}}(g.length,m);for(var _,b,w,B,C,M,k,E,F,x,U=[],I=Math.cos(Ae.DEGTORAD*y),T={},P=!1,S=0,D=g.length;S<D;S+=3)for(var Q=S/3,R=0;R<3;R++)_=r[S+R],b=r[S+(R+1)%3],void 0===T[C=(w=Math.min(_,b))+","+(B=Math.max(_,b))]?T[C]={index1:w,index2:B,face1:Q,face2:void 0}:T[C].face2=Q;for(C in T)void 0!==(M=T[C]).face2&&(k=i[M.face1].normal,E=i[M.face2].normal,Ae.dotVec3(k,E)>I)||(F=n[M.index1],x=n[M.index2],(!P&&F>65535||x>65535)&&(P=!0),U.push(F),U.push(x));return P?new Uint32Array(U):new Uint16Array(U)}}(),Ae.planeClipsPositions3=function(e,t,n){for(var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:3,i=0,s=n.length;i<s;i+=r){ie[0]=n[i+0]-e[0],ie[1]=n[i+1]-e[1],ie[2]=n[i+2]-e[2];var a=ie[0]*t[0]+ie[1]*t[1]+ie[2]*t[2];if(a<0)return!0}return!1};var ce=new Float32Array(3),le=function(){function e(t){var n=this;if(x(this,e),!t)throw"Parameter expected: cfg";if(!t.viewer)throw"Parameter expected: cfg.viewer";this.viewer=t.viewer,this._maxTreeDepth=t.maxTreeDepth||15,this._root=null,this._needsRebuild=!0,this._onModelLoaded=this.viewer.scene.on("modelLoaded",(function(e){n._needsRebuild=!0})),this._onModelUnloaded=this.viewer.scene.on("modelUnloaded",(function(e){n._needsRebuild=!0}))}return I(e,[{key:"root",get:function(){return this._needsRebuild&&this._rebuild(),this._root}},{key:"_rebuild",value:function(){var e=this.viewer.scene;for(var t in this._root={aabb:e.getAABB()},e.objects){var n=e.objects[t];this._insertEntity(this._root,n,1)}this._needsRebuild=!1}},{key:"_insertEntity",value:function(e,t,n){var r=t.aabb;if(n>=this._maxTreeDepth)return e.entities=e.entities||[],void e.entities.push(t);if(e.left&&Ae.containsAABB3(e.left.aabb,r))this._insertEntity(e.left,t,n+1);else if(e.right&&Ae.containsAABB3(e.right.aabb,r))this._insertEntity(e.right,t,n+1);else{var i=e.aabb;ce[0]=i[3]-i[0],ce[1]=i[4]-i[1],ce[2]=i[5]-i[2];var s=0;if(ce[1]>ce[s]&&(s=1),ce[2]>ce[s]&&(s=2),!e.left){var a=i.slice();if(a[s+3]=(i[s]+i[s+3])/2,e.left={aabb:a},Ae.containsAABB3(a,r))return void this._insertEntity(e.left,t,n+1)}if(!e.right){var o=i.slice();if(o[s]=(i[s]+i[s+3])/2,e.right={aabb:o},Ae.containsAABB3(o,r))return void this._insertEntity(e.right,t,n+1)}e.entities=e.entities||[],e.entities.push(t)}}},{key:"destroy",value:function(){var e=this.viewer.scene;e.off(this._onModelLoaded),e.off(this._onModelUnloaded),this._root=null,this._needsRebuild=!0}}]),e}(),ue=function(){function e(){x(this,e),this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}return I(e,[{key:"length",get:function(){return this._length}},{key:"shift",value:function(){if(this._index>=this._headLength){var e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}var t=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,t}},{key:"push",value:function(e){return this._length++,this._tail.push(e),this}},{key:"unshift",value:function(e){return this._head[--this._index]=e,this._length++,this}}]),e}(),he={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}};var de=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],n=e[0].charCodeAt(0),r=n+e[1],i=n;i<r;++i)t.push(i);return String.fromCharCode.apply(null,t)})).join("");function fe(e,t){return(t&&4!==t?[0,6]:[0,6,12,18]).map((function(t){return de.substr(parseInt(e/(1<<t))%64,1)})).reverse().join("")}var pe=function(){for(var e={},t=window.location.search.substring(1).split("&"),n=0;n<t.length;n++){var r=t[n].split("=");if(void 0===e[r[0]])e[r[0]]=decodeURIComponent(r[1]);else if("string"==typeof e[r[0]]){var i=[e[r[0]],decodeURIComponent(r[1])];e[r[0]]=i}else e[r[0]].push(decodeURIComponent(r[1]))}return e}();var ve,ge={xmlToJson:function e(t,n){if(t.nodeType===t.TEXT_NODE){var r=t.nodeValue;if(null===r.match(/^\s+$/))return r}else if(t.nodeType===t.ELEMENT_NODE||t.nodeType===t.DOCUMENT_NODE){var i={type:t.nodeName,children:[]};if(t.nodeType===t.ELEMENT_NODE)for(var s=0;s<t.attributes.length;s++){var a=t.attributes[s];i[n[a.nodeName]||a.nodeName]=a.nodeValue}for(var o=0;o<t.childNodes.length;o++){(s=e(t.childNodes[o],n))&&i.children.push(s)}return i}},clone:function(e){return JSON.parse(JSON.stringify(e))},compressGuid:function(e){var t=[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30].map((function(t){return parseInt(e.substr(t,2),16)}));return fe(t[0],2)+[1,4,7,10,13].map((function(e){return fe((t[e]<<16)+(t[e+1]<<8)+t[e+2])})).join("")},findNodeOfType:function(e,t){var n=[];return function e(r){r.type===t&&n.push(r),(r.children||[]).forEach((function(t){e(t)}))}(e),n},timeout:function(e){return new Promise((function(t,n){setTimeout(t,e)}))},httpRequest:function(e){return new Promise((function(t,n){var r=new XMLHttpRequest;r.open(e.method||"GET",e.url,!0),r.onload=function(e){4===r.readyState&&(200===r.status?t(r.responseXML):n(r.statusText))},r.send(null)}))},loadJSON:function(e,t,n){var r=function(e){};t=t||r,n=n||r;var i=new XMLHttpRequest;i.overrideMimeType("application/json"),i.open("GET",e,!0),i.addEventListener("load",(function(e){var r=e.target.response;if(200===this.status){var i;try{i=JSON.parse(r)}catch(e){n("utils.loadJSON(): Failed to parse JSON response - ".concat(e))}t(i)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(r))}catch(e){n("utils.loadJSON(): Failed to parse JSON response - ".concat(e))}}else n(e)}),!1),i.addEventListener("error",(function(e){n(e)}),!1),i.send(null)},loadArraybuffer:function(e,t,n){var r=function(e){};t=t||r,n=n||r;var i=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(i){var s=!!i[2],a=i[3];a=window.decodeURIComponent(a),s&&(a=window.atob(a));try{for(var o=new ArrayBuffer(a.length),A=new Uint8Array(o),c=0;c<a.length;c++)A[c]=a.charCodeAt(c);Fe.scheduleTask((function(){t(o)}))}catch(e){Fe.scheduleTask((function(){n(e)}))}}else{var l=new XMLHttpRequest;l.open("GET",e,!0),l.responseType="arraybuffer",l.onreadystatechange=function(){4===l.readyState&&(200===l.status?t(l.response):n("loadArrayBuffer error : "+l.response))},l.send(null)}},queryString:pe,isArray:function(e){return e&&!e.propertyIsEnumerable("length")&&"object"===M(e)&&"number"==typeof e.length},isString:function(e){return"string"==typeof e||e instanceof String},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},isID:function(e){return ge.isString(e)||ge.isNumeric(e)},isSameComponent:function(e,t){return!(!e||!t)&&(ge.isNumeric(e)||ge.isString(e)?"".concat(e):e.id)===(ge.isNumeric(t)||ge.isString(t)?"".concat(t):t.id)},isFunction:function(e){return"function"==typeof e},isObject:function(e){var t={}.constructor;return!!e&&e.constructor===t},copy:function(e){return ge.apply(e,{})},apply:function(e,t){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t},apply2:function(e,t){for(var n in e)e.hasOwnProperty(n)&&void 0!==e[n]&&null!==e[n]&&(t[n]=e[n]);return t},applyIf:function(e,t){for(var n in e)e.hasOwnProperty(n)&&(void 0!==t[n]&&null!==t[n]||(t[n]=e[n]));return t},isEmptyObject:function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return!0},inQuotes:function(e){return ge.isNumeric(e)?"".concat(e):"'".concat(e,"'")},concat:function(e,t){var n=new e.constructor(e.length+t.length);return n.set(e),n.set(t,e.length),n},flattenParentChildHierarchy:function(e){var t=[];return function e(n){n.id=n.uuid,delete n.oid,t.push(n);var r=n.children;if(r)for(var i=0,s=r.length;i<s;i++){r[i].parent=n.id,e(r[i])}n.children=[]}(e),t}},me={},ye=new Z,_e=new ue,be={sceneId:null,time:null,startTime:null,prevTime:null,deltaTime:null},we=[],Be=0,Ce=0;var Me,ke,Ee,Fe=new function(){this.version="1.0.0",this.scenes={},this._superTypes={},this._addScene=function(e){if(e.id){if(Fe.scenes[e.id])return void console.error("[ERROR] Scene ".concat(ge.inQuotes(e.id)," already exists"))}else e.id=ye.addItem({});Fe.scenes[e.id]=e;var t=e.ticksPerOcclusionTest,n=e.ticksPerRender;me[e.id]={ticksPerOcclusionTest:t,ticksPerRender:n,renderCountdown:n},he.components.scenes++,e.once("destroyed",(function(){ye.removeItem(e.id),delete Fe.scenes[e.id],delete me[e.id],he.components.scenes--}))},this.clear=function(){var e;for(var t in Fe.scenes)Fe.scenes.hasOwnProperty(t)&&(e=Fe.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete Fe.scenes[e.id]))},this.scheduleTask=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;_e.push(e),_e.push(t)},this.runTasks=function(){for(var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:-1,r=(new Date).getTime(),i=0;_e.length>0&&(n<0||r<n);)e=_e.shift(),(t=_e.shift())?e.call(t):e(),r=(new Date).getTime(),i++;return i},this.getNumTasks=function(){return _e.length}},xe=function(){var e=Date.now();if(ve=e-Be,Be>0&&ve>0){var t=1e3/ve;Ce+=t,we.push(t),we.length>=30&&(Ce-=we.shift()),he.frame.fps=Math.round(Ce/we.length)}for(var n in Fe.scenes)Fe.scenes[n].compile();Ue(e),Be=e};Me=function(){xe()},ke=100,Ee=Date.now()+ke,function e(){var t=Date.now()-Ee;Me(),Ee+=ke,setTimeout(e,Math.max(0,ke-t))}();function Ue(e){var t=Fe.runTasks(e+10),n=Fe.getNumTasks();he.frame.tasksRun=t,he.frame.tasksScheduled=n,he.frame.tasksBudget=10}!function e(){var t=Date.now();if(ve=t-Be,Be>0&&ve>0){var n=1e3/ve;Ce+=n,we.push(n),we.length>=30&&(Ce-=we.shift()),he.frame.fps=Math.round(Ce/we.length)}Ue(t),function(e){for(var t in be.time=e,Fe.scenes)if(Fe.scenes.hasOwnProperty(t)){var n=Fe.scenes[t];be.sceneId=t,be.startTime=n.startTime,be.deltaTime=null!=be.prevTime?be.time-be.prevTime:0,n.fire("tick",be,!0)}be.prevTime=e}(t),function(){var e,t,n,r,i,s=Fe.scenes,a=!1;for(i in s)s.hasOwnProperty(i)&&(e=s[i],(t=me[i])||(t=me[i]={}),n=e.ticksPerOcclusionTest,t.ticksPerOcclusionTest!==n&&(t.ticksPerOcclusionTest=n,t.renderCountdown=n),--e.occlusionTestCountdown<=0&&(e.doOcclusionTest(),e.occlusionTestCountdown=n),r=e.ticksPerRender,t.ticksPerRender!==r&&(t.ticksPerRender=r,t.renderCountdown=r),0==--t.renderCountdown&&(e.render(a),t.renderCountdown=r))}(),void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(xe):requestAnimationFrame(e)}();var Ie=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,e),this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=n.viewer;else{if("Scene"===t.type)this.scene=t;else{if(!(t instanceof e))throw"Invalid param: owner must be a Component";this.scene=t.scene}this._owner=t}this._dontClear=!!n.dontClear,this._renderer=this.scene._renderer,this.meta=n.meta||{},this.id=n.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,t&&t._own(this)}return I(e,[{key:"type",get:function(){return"Component"}},{key:"isComponent",get:function(){return!0}},{key:"glRedraw",value:function(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}},{key:"glResort",value:function(){this._renderer&&this._renderer.needStateSort()}},{key:"owner",get:function(){return this._owner}},{key:"isType",value:function(e){return this.type===e}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==n&&(this._events[e]=t||!0);var r,i=this._eventSubs[e];if(i)for(var s in i)i.hasOwnProperty(s)&&(r=i[s],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new Z),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var r=this._eventSubs[e];r?this._eventSubsNum[e]++:(r={},this._eventSubs[e]=r,this._eventSubsNum[e]=1);var i=this._subIdMap.addItem();r[i]={callback:t,scope:n||this},this._subIdEvents[i]=e;var s=this._events[e];return void 0!==s&&t.call(n||this,s),i}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var n=this._eventSubs[t];n&&(delete n[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,n){var r=this,i=this.on(e,(function(e){r.off(i),t.call(n||this,e)}),n)}},{key:"hasSubs",value:function(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}},{key:"log",value:function(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}},{key:"_message",value:function(e){return" ["+this.type+" "+ge.inQuotes(this.id)+"]: "+e}},{key:"warn",value:function(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}},{key:"error",value:function(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}},{key:"_attach",value:function(e){var t=e.name;if(t){var n=e.component,r=e.sceneDefault,i=e.sceneSingleton,s=e.type,a=e.on,o=!1!==e.recompiles;if(n&&(ge.isNumeric(n)||ge.isString(n))){var A=n;if(!(n=this.scene.components[A]))return void this.error("Component not found: "+ge.inQuotes(A))}if(!n)if(!0===i){var c=this.scene.types[s];for(var l in c)if(c.hasOwnProperty){n=c[l];break}if(!n)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===r&&!(n=this.scene[t]))return this.error("Scene has no default component for '"+t+"'"),null;if(n){if(n.scene.id!==this.scene.id)return void this.error("Not in same scene: "+n.type+" "+ge.inQuotes(n.id));if(s&&!n.isType(s))return void this.error("Expected a "+s+" type or subtype: "+n.type+" "+ge.inQuotes(n.id))}this._attachments||(this._attachments={});var u,h,d,f=this._attached[t];if(f){if(n&&f.id===n.id)return;var p=this._attachments[f.id];for(h=0,d=(u=p.subs).length;h<d;h++)f.off(u[h]);delete this._attached[t],delete this._attachments[f.id];var v=p.params.onDetached;v&&(ge.isFunction(v)?v(f):v.scope?v.callback.call(v.scope,f):v.callback(f)),p.managingLifecycle&&f.destroy()}if(n){var g={params:e,component:n,subs:[],managingLifecycle:!1};g.subs.push(n.once("destroyed",(function(){g.params.component=null,this._attach(g.params)}),this)),o&&g.subs.push(n.on("dirty",(function(){this.fire("dirty",this)}),this)),this._attached[t]=n,this._attachments[n.id]=g;var m,y,_,b,w=e.onAttached;if(w&&(ge.isFunction(w)?w(n):w.scope?w.callback.call(w.scope,n):w.callback(n)),a)for(m in a)if(a.hasOwnProperty(m)){if(y=a[m],ge.isFunction(y)?(_=y,b=null):(_=y.callback,b=y.scope),!_)continue;g.subs.push(n.on(m,_,b))}}return o&&this.fire("dirty",this),this.fire(t,n),n}this.error("Component 'name' expected")}},{key:"_checkComponent",value:function(e,t){if(!t.isComponent){if(!ge.isID(t))return void this.error("Expected a Component or ID");var n=t;if(!(t=this.scene.components[n]))return void this.error("Component not found: "+n)}if(e===t.type){if(t.scene.id===this.scene.id)return t;this.error("Not in same scene: "+t.type)}else this.error("Expected a "+e+" Component")}},{key:"_checkComponent2",value:function(e,t){if(!t.isComponent){if(!ge.isID(t))return void this.error("Expected a Component or ID");var n=t;if(!(t=this.scene.components[n]))return void this.error("Component not found: "+n)}if(t.scene.id===this.scene.id){for(var r=0,i=e.length;r<i;r++)if(e[r]===t.type)return t;return this.error("Expected component types: "+e),null}this.error("Not in same scene: "+t.type)}},{key:"_own",value:function(e){var t=this;this._ownedComponents||(this._ownedComponents={}),this._ownedComponents[e.id]||(this._ownedComponents[e.id]=e),e.once("destroyed",(function(){delete t._ownedComponents[e.id]}),this)}},{key:"_needUpdate",value:function(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():Fe.scheduleTask(this._doUpdate,this))}},{key:"_doUpdate",value:function(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}},{key:"scheduleTask",value:function(e){Fe.scheduleTask(e,null)}},{key:"_update",value:function(){}},{key:"clear",value:function(){if(this._ownedComponents)for(var e in this._ownedComponents){if(this._ownedComponents.hasOwnProperty(e))this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}},{key:"destroy",value:function(){if(!this.destroyed){var e,t,n,r,i,s;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(n=(t=this._attachments[e]).component,i=0,s=(r=t.subs).length;i<s;i++)n.off(r[i]);t.managingLifecycle&&n.destroy()}if(this._ownedComponents)for(e in this._ownedComponents)this._ownedComponents.hasOwnProperty(e)&&((n=this._ownedComponents[e]).destroy(),delete this._ownedComponents[e]);this.scene._removeComponent(this),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=!1}}}]),e}(),Te=Ae.vec3(),Pe=Ae.vec3(),Se=Ae.mat4(),De=function(){function e(){x(this,e),this.normal=Ae.vec3(),this.offset=0,this.testVertex=Ae.vec3()}return I(e,[{key:"set",value:function(e,t,n,r){var i=1/Math.sqrt(e*e+t*t+n*n);this.normal[0]=e*i,this.normal[1]=t*i,this.normal[2]=n*i,this.offset=r*i,this.testVertex[0]=this.normal[0]>=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}]),e}(),Qe=I((function e(){x(this,e),this.planes=[new De,new De,new De,new De,new De,new De]}));function Re(e,t,n){var r=Ae.mulMat4(n,t,Se),i=r[0],s=r[1],a=r[2],o=r[3],A=r[4],c=r[5],l=r[6],u=r[7],h=r[8],d=r[9],f=r[10],p=r[11],v=r[12],g=r[13],m=r[14],y=r[15];e.planes[0].set(o-i,u-A,p-h,y-v),e.planes[1].set(o+i,u+A,p+h,y+v),e.planes[2].set(o-s,u-c,p-d,y-g),e.planes[3].set(o+s,u+c,p+d,y+g),e.planes[4].set(o-a,u-l,p-f,y-m),e.planes[5].set(o+a,u+l,p+f,y+m)}function Oe(e,t){var n=Qe.INSIDE,r=Te,i=Pe;r[0]=t[0],r[1]=t[1],r[2]=t[2],i[0]=t[3],i[1]=t[4],i[2]=t[5];for(var s=[r,i],a=0;a<6;++a){var o=e.planes[a];if(o.normal[0]*s[o.testVertex[0]][0]+o.normal[1]*s[o.testVertex[1]][1]+o.normal[2]*s[o.testVertex[2]][2]+o.offset<0)return Qe.OUTSIDE;o.normal[0]*s[1-o.testVertex[0]][0]+o.normal[1]*s[1-o.testVertex[1]][1]+o.normal[2]*s[1-o.testVertex[2]][2]+o.offset<0&&(n=Qe.INTERSECT)}return n}Qe.INSIDE=0,Qe.INTERSECT=1,Qe.OUTSIDE=2;var Ve=function(e){m(n,Ie);var t=_(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(x(this,n),!r.viewer)throw"[MarqueePicker] Missing config: viewer";if(!r.objectsKdTree3)throw"[MarqueePicker] Missing config: objectsKdTree3";return(e=t.call(this,r.viewer.scene,r)).viewer=r.viewer,e._objectsKdTree3=r.objectsKdTree3,e._canvasMarqueeCorner1=Ae.vec2(),e._canvasMarqueeCorner2=Ae.vec2(),e._canvasMarquee=Ae.AABB2(),e._marqueeFrustum=new Qe,e._marqueeFrustumProjMat=Ae.mat4(),e._pickMode=!1,e._marqueeElement=document.createElement("div"),document.body.appendChild(e._marqueeElement),e._marqueeElement.style.position="absolute",e._marqueeElement.style["z-index"]="40000005",e._marqueeElement.style.width="8px",e._marqueeElement.style.height="8px",e._marqueeElement.style.visibility="hidden",e._marqueeElement.style.top="0px",e._marqueeElement.style.left="0px",e._marqueeElement.style["box-shadow"]="0 2px 5px 0 #182A3D;",e._marqueeElement.style.opacity=1,e._marqueeElement.style["pointer-events"]="none",e}return I(n,[{key:"setMarqueeCorner1",value:function(e){this._canvasMarqueeCorner1.set(e),this._canvasMarqueeCorner2.set(e),this._updateMarquee()}},{key:"setMarqueeCorner2",value:function(e){this._canvasMarqueeCorner2.set(e),this._updateMarquee()}},{key:"setMarquee",value:function(e,t){this._canvasMarqueeCorner1.set(e),this._canvasMarqueeCorner2.set(t),this._updateMarquee()}},{key:"setMarqueeVisible",value:function(e){this._marqueVisible=e,this._marqueeElement.style.visibility=e?"visible":"hidden"}},{key:"getMarqueeVisible",value:function(){return this._marqueVisible}},{key:"setPickMode",value:function(e){if(e!==n.PICK_MODE_INSIDE&&e!==n.PICK_MODE_INTERSECTS)throw"Illegal MarqueePicker pickMode: must be MarqueePicker.PICK_MODE_INSIDE or MarqueePicker.PICK_MODE_INTERSECTS";e!==this._pickMode&&(this._marqueeElement.style["background-image"]=e===n.PICK_MODE_INSIDE?"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\")":"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=e)}},{key:"getPickMode",value:function(){return this._pickMode}},{key:"clear",value:function(){this.fire("clear",{})}},{key:"pick",value:function(){var e=this;this._updateMarquee(),this._buildMarqueeFrustum();var t=[];return(this._canvasMarquee[2]-this._canvasMarquee[0]>3||this._canvasMarquee[3]-this._canvasMarquee[1]>3)&&function r(i){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Qe.INTERSECT;if(s===Qe.INTERSECT&&(s=Oe(e._marqueeFrustum,i.aabb)),s!==Qe.OUTSIDE){if(i.entities)for(var a=i.entities,o=0,A=a.length;o<A;o++){var c=a[o];if(c.visible){var l=c.aabb;if(e._pickMode===n.PICK_MODE_INSIDE)Oe(e._marqueeFrustum,l)===Qe.INSIDE&&t.push(c.id);else Oe(e._marqueeFrustum,l)!==Qe.OUTSIDE&&t.push(c.id)}}i.left&&r(i.left,s),i.right&&r(i.right,s)}}(this._objectsKdTree3.root),this.fire("picked",t),t}},{key:"_updateMarquee",value:function(){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="".concat(this._canvasMarquee[2]-this._canvasMarquee[0],"px"),this._marqueeElement.style.height="".concat(this._canvasMarquee[3]-this._canvasMarquee[1],"px"),this._marqueeElement.style.left="".concat(this._canvasMarquee[0],"px"),this._marqueeElement.style.top="".concat(this._canvasMarquee[1],"px")}},{key:"_buildMarqueeFrustum",value:function(){var e=this.viewer.scene.canvas.canvas,t=e.clientWidth,n=e.clientHeight,r=e.clientLeft,i=e.clientTop,s=2/t,a=2/n,o=e.clientHeight/e.clientWidth,A=(this._canvasMarquee[0]-r)*s-1,c=(this._canvasMarquee[2]-r)*s-1,l=-(this._canvasMarquee[3]-i)*a+1,u=-(this._canvasMarquee[1]-i)*a+1,h=this.viewer.scene.camera.frustum.near*(17*o);Ae.frustumMat4(A,c,l*o,u*o,h,1e4,this._marqueeFrustumProjMat),Re(this._marqueeFrustum,this.viewer.scene.camera.viewMatrix,this._marqueeFrustumProjMat)}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._marqueeElement.parentElement&&(this._marqueeElement.parentElement.removeChild(this._marqueeElement),this._marqueeElement=null,this._objectsKdTree3=null)}}]),n}();Ve.PICK_MODE_INTERSECTS=0,Ve.PICK_MODE_INSIDE=1;var Le=function(e){m(n,Ie);var t=_(n);function n(e){var r;x(this,n),r=t.call(this,e.marqueePicker,e);var i,s,a,o,A,c,l,u=e.marqueePicker,h=u.viewer.scene.canvas.canvas,d=!1,f=!1,p=!1;return h.addEventListener("mousedown",(function(e){r.getActive()&&0===e.button&&(l=setTimeout((function(){var t=u.viewer.scene.input;t.keyDown[t.KEY_CTRL]||u.clear(),i=e.pageX,s=e.pageY,A=e.offsetX,u.setMarqueeCorner1([i,s]),d=!0,u.viewer.cameraControl.pointerEnabled=!1,u.setMarqueeVisible(!0),h.style.cursor="crosshair"}),400),f=!0)})),h.addEventListener("mouseup",(function(e){if(r.getActive()&&(d||p)&&0===e.button){clearTimeout(l),a=e.pageX,o=e.pageY;var t=Math.abs(a-i),n=Math.abs(o-s);d=!1,u.viewer.cameraControl.pointerEnabled=!0,p&&(p=!1),(t>3||n>3)&&u.pick()}})),document.addEventListener("mouseup",(function(e){r.getActive()&&0===e.button&&(clearTimeout(l),d&&(u.setMarqueeVisible(!1),d=!1,f=!1,p=!0,u.viewer.cameraControl.pointerEnabled=!0))}),!0),h.addEventListener("mousemove",(function(e){r.getActive()&&0===e.button&&f&&(clearTimeout(l),d&&(a=e.pageX,o=e.pageY,c=e.offsetX,u.setMarqueeVisible(!0),u.setMarqueeCorner2([a,o]),u.setPickMode(A<c?Ve.PICK_MODE_INSIDE:Ve.PICK_MODE_INTERSECTS)))})),r}return I(n,[{key:"setActive",value:function(e){this._active!==e&&(this._active=e,this.fire("active",this._active))}},{key:"getActive",value:function(){return this._active}},{key:"destroy",value:function(){}}]),n}(),He=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this.viewer=t,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=!1!==n.active,this._visible=!1,this._running=!1,this._destroyed=!1}return I(e,[{key:"start",value:function(e){var t=this;if(!this._destroyed){this._circlePos=e,this._running=!1,this._circleRadius=this._circleMaxRadius,this._circleDiv.style.borderRadius="".concat(this._circleRadius,"px"),this._circleDiv.style.marginLeft="".concat(this._circlePos[0]-this._circleRadius,"px"),this._circleDiv.style.marginTop="".concat(this._circlePos[1]-this._circleRadius,"px");var n,r=this._circleMaxRadius;this._running=!0,requestAnimationFrame((function e(i){if(t._running){n||(n=i);var s=i-n,a=Math.min(s/300,1),o=r+(2-r)*a;t._circleRadius=o,t._circleDiv.style.width="".concat(t._circleRadius,"px"),t._circleDiv.style.height="".concat(t._circleRadius,"px"),t._circleDiv.style.marginLeft="".concat(t._circlePos[0]-t._circleRadius/2,"px"),t._circleDiv.style.marginTop="".concat(t._circlePos[1]-t._circleRadius/2,"px"),a<1&&requestAnimationFrame(e)}})),this._circleDiv.style.visibility="visible"}}},{key:"stop",value:function(){this._destroyed||(this._running=!1,this._circleRadius=this._circleMaxRadius,this._circleDiv.style.borderRadius="".concat(this._circleRadius,"px"),this._circleDiv.style.visibility="hidden")}},{key:"durationMs",get:function(){return this._durationMs},set:function(e){this.stop(),this._durationMs=e}},{key:"destroy",value:function(){this._destroyed||(this.stop(),this._circleDiv.parentElement.removeChild(this._circleDiv),this._destroyed=!0)}}]),e}(),Ne=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};x(this,e),this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=t.messages,this.locale=t.locale}return I(e,[{key:"messages",set:function(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}},{key:"loadMessages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var t in e)this._messages[t]=e[t];this.messages=this._messages}},{key:"clearMessages",value:function(){this.messages={}}},{key:"locales",get:function(){return this._locales}},{key:"locale",get:function(){return this._locale},set:function(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}},{key:"translate",value:function(e,t){var n=this._messages[this._locale];if(!n)return null;var r=Ge(e,n);return r?t?je(r,t):r:null}},{key:"translatePlurals",value:function(e,t,n){var r=this._messages[this._locale];if(!r)return null;var i=Ge(e,r);return(i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one)?(i=je(i,[t]),n&&(i=je(i,n)),i):null}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==n&&(this._events[e]=t||!0);var r=this._eventSubs[e];if(r)for(var i in r){if(r.hasOwnProperty(i))r[i].callback(t)}}},{key:"on",value:function(e,t){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new Z),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});var n=this._eventSubs[e];n||(n={},this._eventSubs[e]=n);var r=this._eventSubIDMap.addItem();n[r]={callback:t},this._eventSubEvents[r]=e;var i=this._events[e];return void 0!==i&&t(i),r}},{key:"off",value:function(e){if(null!=e&&this._eventSubEvents){var t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];var n=this._eventSubs[t];n&&delete n[e],this._eventSubIDMap.removeItem(e)}}}}]),e}();function Ge(e,t){if(t[e])return t[e];for(var n=e.split("."),r=t,i=0,s=n.length;r&&i<s;i++){r=r[n[i]]}return r}function je(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,n){return"{{"===e?"{":"}}"===e?"}":t[n]}))}var We=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i)).t=i.t,r}return I(n,[{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"tangent",get:function(){return this.getTangent(this._t)}},{key:"length",get:function(){var e=this._getLengths();return e[e.length-1]}},{key:"getTangent",value:function(e){var t=1e-4;void 0===e&&(e=this._t);var n=e-t,r=e+t;n<0&&(n=0),r>1&&(r=1);var i=this.getPoint(n),s=this.getPoint(r),a=Ae.subVec3(s,i,[]);return Ae.normalizeVec3(a,[])}},{key:"getPointAt",value:function(e){var t=this.getUToTMapping(e);return this.getPoint(t)}},{key:"getPoints",value:function(e){e||(e=5);var t,n=[];for(t=0;t<=e;t++)n.push(this.getPoint(t/e));return n}},{key:"_getLengths",value:function(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,n,r=[],i=this.getPoint(0),s=0;for(r.push(0),n=1;n<=e;n++)t=this.getPoint(n/e),s+=Ae.lenVec3(Ae.subVec3(t,i,[])),r.push(s),i=t;return this.cacheArcLengths=r,r}},{key:"_updateArcLengths",value:function(){this.needsUpdate=!0,this._getLengths()}},{key:"getUToTMapping",value:function(e,t){var n,r=this._getLengths(),i=0,s=r.length;n=t||e*r[s-1];for(var a,o=0,A=s-1;o<=A;)if((a=r[i=Math.floor(o+(A-o)/2)]-n)<0)o=i+1;else{if(!(a>0)){A=i;break}A=i-1}if(r[i=A]===n)return i/(s-1);var c=r[i];return(i+(n-c)/(r[i+1]-c))/(s-1)}}]),n}(),ze=function(e){m(n,We);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i)).points=i.points,r.t=i.t,r}return I(n,[{key:"points",get:function(){return this._points},set:function(e){this._points=e||[]}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=this.points;if(!(t.length<3)){var n=(t.length-1)*e,r=Math.floor(n),i=n-r,s=t[0===r?r:r-1],a=t[r],o=t[r>t.length-2?t.length-1:r+1],A=t[r>t.length-3?t.length-1:r+2],c=Ae.vec3();return c[0]=Ae.catmullRomInterpolate(s[0],a[0],o[0],A[0],i),c[1]=Ae.catmullRomInterpolate(s[1],a[1],o[1],A[1],i),c[2]=Ae.catmullRomInterpolate(s[2],a[2],o[2],A[2],i),c}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}},{key:"getJSON",value:function(){return{points:points,t:this._t}}}]),n}(),Xe=Ae.vec3(),Ke=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._frames=[],r._eyeCurve=new ze(w(r)),r._lookCurve=new ze(w(r)),r._upCurve=new ze(w(r)),i.frames&&(r.addFrames(i.frames),r.smoothFrameTimes(1)),r}return I(n,[{key:"type",get:function(){return"CameraPath"}},{key:"frames",get:function(){return this._frames}},{key:"eyeCurve",get:function(){return this._eyeCurve}},{key:"lookCurve",get:function(){return this._lookCurve}},{key:"upCurve",get:function(){return this._upCurve}},{key:"saveFrame",value:function(e){var t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}},{key:"addFrame",value:function(e,t,n,r){var i={t:e,eye:t.slice(0),look:n.slice(0),up:r.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}},{key:"addFrames",value:function(e){for(var t,n=0,r=e.length;n<r;n++)t=e[n],this.addFrame(t.t||0,t.eye,t.look,t.up)}},{key:"loadFrame",value:function(e){var t=this.scene.camera;e=(e/=this._frames[this._frames.length-1].t-this._frames[0].t)<0?0:e>1?1:e,t.eye=this._eyeCurve.getPoint(e,Xe),t.look=this._lookCurve.getPoint(e,Xe),t.up=this._upCurve.getPoint(e,Xe)}},{key:"sampleFrame",value:function(e,t,n,r){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,n),this._upCurve.getPoint(e,r)}},{key:"smoothFrameTimes",value:function(e){if(0!==this._frames.length){var t=Ae.vec3(),n=0;this._frames[0].t=0;for(var r=[],i=1,s=this._frames.length;i<s;i++){var a=Ae.lenVec3(Ae.subVec3(this._frames[i].eye,this._frames[i-1].eye,t));r[i]=a,n+=a}for(var o=1,A=this._frames.length;o<A;o++){var c=r[o]/n*e;this._frames[o].t=this._frames[o-1].t+c}}}},{key:"clearFrames",value:function(){this._frames=[],this._eyeCurve.points=[],this._lookCurve.points=[],this._upCurve.points=[]}}]),n}(),Ze=Ae.vec3(),Je=Ae.vec3(),Ye=Ae.vec3(),qe=Ae.vec3(),$e=Ae.vec3(),et=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._look1=Ae.vec3(),r._eye1=Ae.vec3(),r._up1=Ae.vec3(),r._look2=Ae.vec3(),r._eye2=Ae.vec3(),r._up2=Ae.vec3(),r._orthoScale1=1,r._orthoScale2=1,r._flying=!1,r._flyEyeLookUp=!1,r._flyingEye=!1,r._flyingLook=!1,r._callback=null,r._callbackScope=null,r._time1=null,r._time2=null,r.easing=!1!==i.easing,r.duration=i.duration,r.fit=i.fit,r.fitFOV=i.fitFOV,r.trail=i.trail,r}return I(n,[{key:"type",get:function(){return"CameraFlightAnimation"}},{key:"flyTo",value:function(e,t,n){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=n;var r,i,s,a,o,A=this.scene.camera,c=!!e.projection&&e.projection!==A.projection;if(this._eye1[0]=A.eye[0],this._eye1[1]=A.eye[1],this._eye1[2]=A.eye[2],this._look1[0]=A.look[0],this._look1[1]=A.look[1],this._look1[2]=A.look[2],this._up1[0]=A.up[0],this._up1[1]=A.up[1],this._up1[2]=A.up[2],this._orthoScale1=A.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)i=e.eye,s=e.look,a=e.up;else if(e.eye)i=e.eye;else if(e.look)s=e.look;else{var l=e;if((ge.isNumeric(l)||ge.isString(l))&&(o=l,!(l=this.scene.components[o])))return this.error("Component not found: "+ge.inQuotes(o)),void(t&&(n?t.call(n):t()));c||(r=l.aabb||this.scene.aabb)}var u=e.poi;if(r){if(r[3]<r[0]||r[4]<r[1]||r[5]<r[2])return;if(r[3]===r[0]&&r[4]===r[1]&&r[5]===r[2])return;r=r.slice();var h=Ae.getAABB3Center(r);this._look2=u||h;var d=Ae.subVec3(this._eye1,this._look1,Ze),f=Ae.normalizeVec3(d),p=u?Ae.getAABB3DiagPoint(r,u):Ae.getAABB3Diag(r),v=e.fitFOV||this._fitFOV,g=Math.abs(p/Math.tan(v*Ae.DEGTORAD));this._orthoScale2=1.1*p,this._eye2[0]=this._look2[0]+f[0]*g,this._eye2[1]=this._look2[1]+f[1]*g,this._eye2[2]=this._look2[2]+f[2]*g,this._up2[0]=this._up1[0],this._up2[1]=this._up1[1],this._up2[2]=this._up1[2],this._flyingEyeLookUp=!0}else(i||s||a)&&(this._flyingEyeLookUp=!!i&&!!s&&!!a,this._flyingEye=!!i&&!s,this._flyingLook=!!s&&!i,i&&(this._eye2[0]=i[0],this._eye2[1]=i[1],this._eye2[2]=i[2]),s&&(this._look2[0]=s[0],this._look2[1]=s[1],this._look2[2]=s[2]),a&&(this._up2[0]=a[0],this._up2[1]=a[1],this._up2[2]=a[2]));c?("ortho"===e.projection&&"ortho"!==A.projection&&(this._projection2="ortho",this._projMatrix1=A.projMatrix.slice(),this._projMatrix2=A.ortho.matrix.slice(),A.projection="customProjection"),"perspective"===e.projection&&"perspective"!==A.projection&&(this._projection2="perspective",this._projMatrix1=A.projMatrix.slice(),this._projMatrix2=A.perspective.matrix.slice(),A.projection="customProjection")):this._projection2=null,this.fire("started",e,!0),this._time1=Date.now(),this._time2=this._time1+(Number.isFinite(e.duration)?1e3*e.duration:this._duration),this._flying=!0,Fe.scheduleTask(this._update,this)}},{key:"jumpTo",value:function(e){this._jumpTo(e)}},{key:"_jumpTo",value:function(e){this._flying&&this.stop();var t,n,r,i,s,a=this.scene.camera;if(e.aabb)t=e.aabb;else if(6===e.length)t=e;else if(e.eye||e.look||e.up)r=e.eye,i=e.look,s=e.up;else{var o=e;if((ge.isNumeric(o)||ge.isString(o))&&(n=o,!(o=this.scene.components[n])))return void this.error("Component not found: "+ge.inQuotes(n));t=o.aabb||this.scene.aabb}var A=e.poi;if(t){if(t[3]<=t[0]||t[4]<=t[1]||t[5]<=t[2])return;var c,l=A?Ae.getAABB3DiagPoint(t,A):Ae.getAABB3Diag(t);i=A||Ae.getAABB3Center(t,i),this._trail?Ae.subVec3(a.look,i,$e):Ae.subVec3(a.eye,a.look,$e),Ae.normalizeVec3($e),c=(void 0!==e.fit?e.fit:this._fit)?Math.abs(l/Math.tan((e.fitFOV||this._fitFOV)*Ae.DEGTORAD)):Ae.lenVec3(Ae.subVec3(a.eye,a.look,Ze)),Ae.mulVec3Scalar($e,c),a.eye=Ae.addVec3(i,$e,Ze),a.look=i,this.scene.camera.ortho.scale=1.1*l}else(r||i||s)&&(r&&(a.eye=r),i&&(a.look=i),s&&(a.up=s));e.projection&&(a.projection=e.projection)}},{key:"_update",value:function(){if(this._flying){var e=(Date.now()-this._time1)/(this._time2-this._time1),t=e>=1;e>1&&(e=1);var r=this.easing?n._ease(e,0,1,1):e,i=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(Ae.subVec3(i.eye,i.look,$e),i.eye=Ae.lerpVec3(r,0,1,this._eye1,this._eye2,Ye),i.look=Ae.subVec3(Ye,$e,Je)):this._flyingLook&&(i.look=Ae.lerpVec3(r,0,1,this._look1,this._look2,Je),i.up=Ae.lerpVec3(r,0,1,this._up1,this._up2,qe)):this._flyingEyeLookUp&&(i.eye=Ae.lerpVec3(r,0,1,this._eye1,this._eye2,Ye),i.look=Ae.lerpVec3(r,0,1,this._look1,this._look2,Je),i.up=Ae.lerpVec3(r,0,1,this._up1,this._up2,qe)),this._projection2){var s="ortho"===this._projection2?n._easeOutExpo(e,0,1,1):n._easeInCubic(e,0,1,1);i.customProjection.matrix=Ae.lerpMat4(s,0,1,this._projMatrix1,this._projMatrix2)}else i.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return i.ortho.scale=this._orthoScale2,void this.stop();Fe.scheduleTask(this._update,this)}}},{key:"stop",value:function(){if(this._flying){this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);var e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}}},{key:"cancel",value:function(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}},{key:"duration",get:function(){return this._duration/1e3},set:function(e){this._duration=Number.isFinite(e)?1e3*e:500,this.stop()}},{key:"fit",get:function(){return this._fit},set:function(e){this._fit=!1!==e}},{key:"fitFOV",get:function(){return this._fitFOV},set:function(e){this._fitFOV=e||45}},{key:"trail",get:function(){return this._trail},set:function(e){this._trail=!!e}},{key:"destroy",value:function(){this.stop(),v(C(n.prototype),"destroy",this).call(this)}}],[{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"_easeInCubic",value:function(e,t,n,r){return n*(e/=r)*e*e+t}},{key:"_easeOutExpo",value:function(e,t,n,r){return n*(1-Math.pow(2,-10*e/r))+t}}]),n}(),tt=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._cameraFlightAnimation=new et(w(r)),r._t=0,r.state=n.SCRUBBING,r._playingFromT=0,r._playingToT=0,r._playingRate=i.playingRate||1,r._playingDir=1,r._lastTime=null,r.cameraPath=i.cameraPath,r._tick=r.scene.on("tick",r._updateT,w(r)),r}return I(n,[{key:"type",get:function(){return"CameraPathAnimation"}},{key:"_updateT",value:function(){var e=this._cameraPath;if(e){var t,r,i=performance.now(),s=this._lastTime?.001*(i-this._lastTime):0;if(this._lastTime=i,0!==s)switch(this.state){case n.SCRUBBING:return;case n.PLAYING:if(this._t+=this._playingRate*s,0===(t=this._cameraPath.frames.length)||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=n.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case n.PLAYING_TO:r=this._t+this._playingRate*s*this._playingDir,(this._playingDir<0&&r<=this._playingToT||this._playingDir>0&&r>=this._playingToT)&&(r=this._playingToT,this.state=n.SCRUBBING,this.fire("stopped")),this._t=r,e.loadFrame(this._t)}}}},{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"cameraPath",get:function(){return this._cameraPath},set:function(e){this._cameraPath=e}},{key:"rate",get:function(){return this._playingRate},set:function(e){this._playingRate=e}},{key:"play",value:function(){this._cameraPath&&(this._lastTime=null,this.state=n.PLAYING)}},{key:"playToT",value:function(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=n.PLAYING_TO)}},{key:"playToFrame",value:function(e){var t=this._cameraPath;if(t){var n=t.frames[e];n?this.playToT(n.t):this.error("playToFrame - frame index out of range: "+e)}}},{key:"flyToFrame",value:function(e,t){var r=this._cameraPath;if(r){var i=r.frames[e];i?(this.state=n.SCRUBBING,this._cameraFlightAnimation.flyTo(i,t)):this.error("flyToFrame - frame index out of range: "+e)}}},{key:"scrubToT",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=n.SCRUBBING))}},{key:"scrubToFrame",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(t.frames[e]?(t.loadFrame(this._t),this.state=n.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)))}},{key:"stop",value:function(){this.state=n.SCRUBBING,this.fire("stopped")}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this.scene.off(this._tick)}}]),n}();tt.STOPPED=0,tt.SCRUBBING=1,tt.PLAYING=2,tt.PLAYING_TO=3;var nt=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),r=t.call(this,e,i),he.memory.meshes++,r}return I(n,[{key:"type",get:function(){return"Geometry"}},{key:"isGeometry",get:function(){return!0}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),he.memory.meshes--}}]),n}(),rt=new Z({}),it=function(){function e(t){for(var n in x(this,e),this.id=rt.addItem({}),t)t.hasOwnProperty(n)&&(this[n]=t[n])}return I(e,[{key:"destroy",value:function(){rt.removeItem(this.id)}}]),e}(),st=function(){function e(t,n,r,i,s,a,o,A,c){switch(x(this,e),this._gl=t,this.type=n,this.allocated=!1,r.constructor){case Uint8Array:this.itemType=t.UNSIGNED_BYTE,this.itemByteSize=1;break;case Int8Array:this.itemType=t.BYTE,this.itemByteSize=1;break;case Uint16Array:this.itemType=t.UNSIGNED_SHORT,this.itemByteSize=2;break;case Int16Array:this.itemType=t.SHORT,this.itemByteSize=2;break;case Uint32Array:this.itemType=t.UNSIGNED_INT,this.itemByteSize=4;break;case Int32Array:this.itemType=t.INT,this.itemByteSize=4;break;default:this.itemType=t.FLOAT,this.itemByteSize=4}this.usage=a,this.length=0,this.dataLength=i,this.numItems=0,this.itemSize=s,this.normalized=!!o,this.stride=A||0,this.offset=c||0,this._allocate(r)}return I(e,[{key:"_allocate",value:function(e){if(this.allocated=!1,this._handle=this._gl.createBuffer(),!this._handle)throw"Failed to allocate WebGL ArrayBuffer";this._handle&&(this._gl.bindBuffer(this.type,this._handle),this._gl.bufferData(this.type,e.length>this.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}},{key:"setData",value:function(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}},{key:"bind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}},{key:"unbind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,null)}},{key:"bindAtLocation",value:function(e){this.bind(),this._gl.vertexAttribPointer(e,this.itemSize,this.itemType,this.normalized,0,0)}},{key:"destroy",value:function(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}]),e}(),at=function(){var e=[],t=[],n=[],r=[],i=[],s=0,a=new Uint16Array(3),o=new Uint16Array(3),A=new Uint16Array(3),c=Ae.vec3(),l=Ae.vec3(),u=Ae.vec3(),h=Ae.vec3(),d=Ae.vec3(),f=Ae.vec3(),p=Ae.vec3();return function(v,g,m,y){!function(i,s){var a,o,A,c,l,u,h={},d=Math.pow(10,4),f=0;for(l=0,u=i.length;l<u;l+=3)a=i[l],o=i[l+1],A=i[l+2],void 0===h[c=Math.round(a*d)+"_"+Math.round(o*d)+"_"+Math.round(A*d)]&&(h[c]=f/3,e[f++]=a,e[f++]=o,e[f++]=A),t[l/3]=h[c];for(l=0,u=s.length;l<u;l++)r[l]=t[s[l]],n[r[l]]=s[l]}(v,g),function(t,n){s=0;for(var v=0,g=t;v<g;v+=3){var m=3*r[v],y=3*r[v+1],_=3*r[v+2];n?(a[0]=e[m],a[1]=e[m+1],a[2]=e[m+2],o[0]=e[y],o[1]=e[y+1],o[2]=e[y+2],A[0]=e[_],A[1]=e[_+1],A[2]=e[_+2],Ae.decompressPosition(a,n,c),Ae.decompressPosition(o,n,l),Ae.decompressPosition(A,n,u)):(c[0]=e[m],c[1]=e[m+1],c[2]=e[m+2],l[0]=e[y],l[1]=e[y+1],l[2]=e[y+2],u[0]=e[_],u[1]=e[_+1],u[2]=e[_+2]),Ae.subVec3(u,l,h),Ae.subVec3(c,l,d),Ae.cross3Vec3(h,d,f),Ae.normalizeVec3(f,p);var b=i[s]||(i[s]={normal:Ae.vec3()});b.normal[0]=p[0],b.normal[1]=p[1],b.normal[2]=p[2],s++}}(g.length,m);for(var _,b,w,B,C,M,k,E,F,x,U=[],I=Math.cos(Ae.DEGTORAD*y),T={},P=!1,S=0,D=g.length;S<D;S+=3)for(var Q=S/3,R=0;R<3;R++)_=r[S+R],b=r[S+(R+1)%3],void 0===T[C=(w=Math.min(_,b))+","+(B=Math.max(_,b))]?T[C]={index1:w,index2:B,face1:Q,face2:void 0}:T[C].face2=Q;for(C in T)void 0!==(M=T[C]).face2&&(k=i[M.face1].normal,E=i[M.face2].normal,Ae.dotVec3(k,E)>I)||(F=n[M.index1],x=n[M.index2],(!P&&F>65535||x>65535)&&(P=!0),U.push(F),U.push(x));return P?new Uint32Array(U):new Uint16Array(U)}}();var ot,At,ct=(ot=Ae.mat4(),At=Ae.mat4(),function(e,t){t=t||Ae.mat4();var n=e[0],r=e[1],i=e[2],s=e[3]-n,a=e[4]-r,o=e[5]-i,A=65535;return Ae.identityMat4(ot),Ae.translationMat4v(e,ot),Ae.identityMat4(At),Ae.scalingMat4v([s/A,a/A,o/A],At),Ae.mulMat4(ot,At,t),t}),lt=function(){var e=Ae.mat4(),t=Ae.mat4();return function(n,r,i){var s,a=new Uint16Array(n.length),o=new Float32Array([i[0]!==r[0]?65535/(i[0]-r[0]):0,i[1]!==r[1]?65535/(i[1]-r[1]):0,i[2]!==r[2]?65535/(i[2]-r[2]):0]);for(s=0;s<n.length;s+=3)a[s+0]=Math.max(0,Math.min(65535,Math.floor((n[s+0]-r[0])*o[0]))),a[s+1]=Math.max(0,Math.min(65535,Math.floor((n[s+1]-r[1])*o[1]))),a[s+2]=Math.max(0,Math.min(65535,Math.floor((n[s+2]-r[2])*o[2])));return Ae.identityMat4(e),Ae.translationMat4v(r,e),Ae.identityMat4(t),Ae.scalingMat4v([(i[0]-r[0])/65535,(i[1]-r[1])/65535,(i[2]-r[2])/65535],t),{quantized:a,decodeMatrix:Ae.mulMat4(e,t,Ae.identityMat4())}}}();var ut=function(){var e=Ae.mat3(),t=Ae.mat3();return function(n,r,i){var s,a=new Uint16Array(n.length),o=new Float32Array([65535/(i[0]-r[0]),65535/(i[1]-r[1])]);for(s=0;s<n.length;s+=2)a[s+0]=Math.max(0,Math.min(65535,Math.floor((n[s+0]-r[0])*o[0]))),a[s+1]=Math.max(0,Math.min(65535,Math.floor((n[s+1]-r[1])*o[1])));return Ae.identityMat3(e),Ae.translationMat3v(r,e),Ae.identityMat3(t),Ae.scalingMat3v([(i[0]-r[0])/65535,(i[1]-r[1])/65535],t),{quantized:a,decodeMatrix:Ae.mulMat3(e,t,Ae.identityMat3())}}}();function ht(e,t,n,r){var i=e[t]/(Math.abs(e[t])+Math.abs(e[t+1])+Math.abs(e[t+2])),s=e[t+1]/(Math.abs(e[t])+Math.abs(e[t+1])+Math.abs(e[t+2]));if(e[t+2]<0){var a=(1-Math.abs(s))*(i>=0?1:-1),o=(1-Math.abs(i))*(s>=0?1:-1);i=a,s=o}return new Int8Array([Math[n](127.5*i+(i<0?-1:0)),Math[r](127.5*s+(s<0?-1:0))])}function dt(e){var t=e[0],n=e[1];t/=t<0?127:128,n/=n<0?127:128;var r=1-Math.abs(t)-Math.abs(n);r<0&&(t=(1-Math.abs(n))*(t>=0?1:-1),n=(1-Math.abs(t))*(n>=0?1:-1));var i=Math.sqrt(t*t+n*n+r*r);return[t/i,n/i,r/i]}function ft(e,t,n){return e[t]*n[0]+e[t+1]*n[1]+e[t+2]*n[2]}var pt={getPositionsBounds:function(e){var t,n,r=new Float32Array(3),i=new Float32Array(3);for(t=0;t<3;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t<e.length;t+=3)for(n=0;n<3;n++)r[n]=Math.min(r[n],e[t+n]),i[n]=Math.max(i[n],e[t+n]);return{min:r,max:i}},createPositionsDecodeMatrix:ct,compressPositions:lt,compressPosition:function(e,t,n){var r=new Float32Array([t[3]!==t[0]?65535/(t[3]-t[0]):0,t[4]!==t[1]?65535/(t[4]-t[1]):0,t[5]!==t[2]?65535/(t[5]-t[2]):0]);n[0]=Math.max(0,Math.min(65535,Math.floor((e[0]-t[0])*r[0]))),n[1]=Math.max(0,Math.min(65535,Math.floor((e[1]-t[1])*r[1]))),n[2]=Math.max(0,Math.min(65535,Math.floor((e[2]-t[2])*r[2])))},decompressPositions:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r<i;r+=3)n[r+0]=e[r+0]*t[0]+t[12],n[r+1]=e[r+1]*t[5]+t[13],n[r+2]=e[r+2]*t[10]+t[14];return n},decompressPosition:function(e,t,n){return n[0]=e[0]*t[0]+t[12],n[1]=e[1]*t[5]+t[13],n[2]=e[2]*t[10]+t[14],n},decompressAABB:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e;return n[0]=e[0]*t[0]+t[12],n[1]=e[1]*t[5]+t[13],n[2]=e[2]*t[10]+t[14],n[3]=e[3]*t[0]+t[12],n[4]=e[4]*t[5]+t[13],n[5]=e[5]*t[10]+t[14],n},getUVBounds:function(e){var t,n,r=new Float32Array(2),i=new Float32Array(2);for(t=0;t<2;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t<e.length;t+=2)for(n=0;n<2;n++)r[n]=Math.min(r[n],e[t+n]),i[n]=Math.max(i[n],e[t+n]);return{min:r,max:i}},compressUVs:ut,decompressUVs:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r<i;r+=3)n[r+0]=e[r+0]*t[0]+t[6],n[r+1]=e[r+1]*t[4]+t[7];return n},decompressUV:function(e,t,n){n[0]=e[0]*t[0]+t[6],n[1]=e[1]*t[4]+t[7]},compressNormals:function(e){for(var t,n,r,i,s=new Int8Array(e.length),a=0;a<e.length;a+=3)n=t=ht(e,a,"floor","floor"),r=i=ft(e,a,dt(t)),(r=ft(e,a,dt(t=ht(e,a,"ceil","floor"))))>i&&(n=t,i=r),(r=ft(e,a,dt(t=ht(e,a,"floor","ceil"))))>i&&(n=t,i=r),(r=ft(e,a,dt(t=ht(e,a,"ceil","ceil"))))>i&&(n=t,i=r),s[a]=n[0],s[a+1]=n[1];return s},decompressNormals:function(e,t){for(var n=0,r=0,i=e.length;n<i;n+=2){var s=e[n+0],a=e[n+1];s=(2*s+1)/255,a=(2*a+1)/255;var o=1-Math.abs(s)-Math.abs(a);o<0&&(s=(1-Math.abs(a))*(s>=0?1:-1),a=(1-Math.abs(s))*(a>=0?1:-1));var A=Math.sqrt(s*s+a*a+o*o);t[r+0]=s/A,t[r+1]=a/A,t[r+2]=o/A,r+=3}return t},decompressNormal:function(e,t){var n=e[0],r=e[1];n=(2*n+1)/255,r=(2*r+1)/255;var i=1-Math.abs(n)-Math.abs(r);i<0&&(n=(1-Math.abs(r))*(n>=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var s=Math.sqrt(n*n+r*r+i*i);return t[0]=n/s,t[1]=r/s,t[2]=i/s,t}},vt=he.memory,gt=Ae.AABB3(),mt=function(e){m(n,nt);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,n),(r=t.call(this,e,i))._state=new it({compressGeometry:!!i.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),r._numTriangles=0,r._edgeThreshold=i.edgeThreshold||10,r._edgeIndicesBuf=null,r._pickTrianglePositionsBuf=null,r._pickTriangleColorsBuf=null,r._aabbDirty=!0,r._boundingSphere=!0,r._aabb=null,r._aabbDirty=!0,r._obb=null,r._obbDirty=!0;var s=r._state,a=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":s.primitive=a.POINTS,s.primitiveName=i.primitive;break;case"lines":s.primitive=a.LINES,s.primitiveName=i.primitive;break;case"line-loop":s.primitive=a.LINE_LOOP,s.primitiveName=i.primitive;break;case"line-strip":s.primitive=a.LINE_STRIP,s.primitiveName=i.primitive;break;case"triangles":s.primitive=a.TRIANGLES,s.primitiveName=i.primitive;break;case"triangle-strip":s.primitive=a.TRIANGLE_STRIP,s.primitiveName=i.primitive;break;case"triangle-fan":s.primitive=a.TRIANGLE_FAN,s.primitiveName=i.primitive;break;default:r.error("Unsupported value for 'primitive': '"+i.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=a.TRIANGLES,s.primitiveName=i.primitive}if(i.positions)if(r._state.compressGeometry){var o=pt.getPositionsBounds(i.positions),A=pt.compressPositions(i.positions,o.min,o.max);s.positions=A.quantized,s.positionsDecodeMatrix=A.decodeMatrix}else s.positions=i.positions.constructor===Float32Array?i.positions:new Float32Array(i.positions);if(i.colors&&(s.colors=i.colors.constructor===Float32Array?i.colors:new Float32Array(i.colors)),i.uv)if(r._state.compressGeometry){var c=pt.getUVBounds(i.uv),l=pt.compressUVs(i.uv,c.min,c.max);s.uv=l.quantized,s.uvDecodeMatrix=l.decodeMatrix}else s.uv=i.uv.constructor===Float32Array?i.uv:new Float32Array(i.uv);if(i.normals&&(r._state.compressGeometry?s.normals=pt.compressNormals(i.normals):s.normals=i.normals.constructor===Float32Array?i.normals:new Float32Array(i.normals)),i.indices&&(s.indices=i.indices.constructor===Uint32Array||i.indices.constructor===Uint16Array?i.indices:new Uint32Array(i.indices),"triangles"===r._state.primitiveName&&(r._numTriangles=i.indices.length/3)),r._buildHash(),vt.meshes++,s.indices&&(s.indicesBuf=new st(a,a.ELEMENT_ARRAY_BUFFER,s.indices,s.indices.length,1,a.STATIC_DRAW),vt.indices+=s.indicesBuf.numItems),s.positions&&(s.positionsBuf=new st(a,a.ARRAY_BUFFER,s.positions,s.positions.length,3,a.STATIC_DRAW),vt.positions+=s.positionsBuf.numItems),s.normals){var u=s.compressGeometry;s.normalsBuf=new st(a,a.ARRAY_BUFFER,s.normals,s.normals.length,3,a.STATIC_DRAW,u),vt.normals+=s.normalsBuf.numItems}return s.colors&&(s.colorsBuf=new st(a,a.ARRAY_BUFFER,s.colors,s.colors.length,4,a.STATIC_DRAW),vt.colors+=s.colorsBuf.numItems),s.uv&&(s.uvBuf=new st(a,a.ARRAY_BUFFER,s.uv,s.uv.length,2,a.STATIC_DRAW),vt.uvs+=s.uvBuf.numItems),r}return I(n,[{key:"type",get:function(){return"ReadableGeometry"}},{key:"isReadableGeometry",get:function(){return!0}},{key:"_buildHash",value:function(){var e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}},{key:"_getEdgeIndices",value:function(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}},{key:"_getPickTrianglePositions",value:function(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}},{key:"_getPickTriangleColors",value:function(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}},{key:"_buildEdgeIndices",value:function(){var e=this._state;if(e.positions&&e.indices){var t=this.scene.canvas.gl,n=at(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new st(t,t.ELEMENT_ARRAY_BUFFER,n,n.length,1,t.STATIC_DRAW),vt.indices+=this._edgeIndicesBuf.numItems}}},{key:"_buildPickTriangleVBOs",value:function(){var e=this._state;if(e.positions&&e.indices){var t=this.scene.canvas.gl,n=Ae.buildPickTriangles(e.positions,e.indices,e.compressGeometry),r=n.positions,i=n.colors;this._pickTrianglePositionsBuf=new st(t,t.ARRAY_BUFFER,r,r.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new st(t,t.ARRAY_BUFFER,i,i.length,4,t.STATIC_DRAW,!0),vt.positions+=this._pickTrianglePositionsBuf.numItems,vt.colors+=this._pickTriangleColorsBuf.numItems}}},{key:"_buildPickVertexVBOs",value:function(){}},{key:"primitive",get:function(){return this._state.primitiveName}},{key:"compressGeometry",get:function(){return this._state.compressGeometry}},{key:"positions",get:function(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),pt.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null},set:function(e){var t=this._state,n=t.positions;if(n)if(n.length===e.length){if(this._state.compressGeometry){var r=pt.getPositionsBounds(e),i=pt.compressPositions(e,r.min,r.max);e=i.quantized,t.positionsDecodeMatrix=i.decodeMatrix}n.set(e),t.positionsBuf&&t.positionsBuf.setData(n),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}},{key:"normals",get:function(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){var e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),pt.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry normals - quantized geometry is immutable");else{var t=this._state,n=t.normals;n?n.length===e.length?(n.set(e),t.normalsBuf&&t.normalsBuf.setData(n),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}}},{key:"uv",get:function(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),pt.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry UVs - quantized geometry is immutable");else{var t=this._state,n=t.uv;n?n.length===e.length?(n.set(e),t.uvBuf&&t.uvBuf.setData(n),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}}},{key:"colors",get:function(){return this._state.colors},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry colors - quantized geometry is immutable");else{var t=this._state,n=t.colors;n?n.length===e.length?(n.set(e),t.colorsBuf&&t.colorsBuf.setData(n),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}}},{key:"indices",get:function(){return this._state.indices}},{key:"aabb",get:function(){return this._aabbDirty&&(this._aabb||(this._aabb=Ae.AABB3()),Ae.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}},{key:"obb",get:function(){return this._obbDirty&&(this._obb||(this._obb=Ae.OBB3()),Ae.positions3ToAABB3(this._state.positions,gt,this._state.positionsDecodeMatrix),Ae.AABB3ToOBB3(gt,this._obb),this._obbDirty=!1),this._obb}},{key:"_getMetrics",value:function(){if(!("_metrics"in this))switch(this._state.primitiveName){case"solid":case"surface":case"triangles":for(var e=this._state.indices,t=this._state.positions,n=function(n,r){for(var i=3*e[n],s=0;s<3;++s)r[s]=t[i+s];return r},r=[Ae.vec3(),Ae.vec3(),Ae.vec3(),Ae.vec3()],i=0,s=Ae.vec3([0,0,0]),a=0;a<e.length;a+=3){var o=n(a,r[0]),A=n(a+1,r[1]),c=n(a+2,r[2]);Ae.addVec3(o,A,r[3]),Ae.addVec3(c,r[3],r[3]);var l=Ae.lenVec3(Ae.cross3Vec3(Ae.subVec3(A,o,r[1]),Ae.subVec3(c,o,r[2]),r[0]))/2;i+=l,Ae.mulVec3Scalar(r[3],l,r[3]),Ae.addVec3(s,r[3],s)}this._metrics={surfaceArea:i,centroid:Ae.mulVec3Scalar(s,1/i/3,s)};break;default:this._metrics={surfaceArea:0}}return this._metrics}},{key:"surfaceArea",get:function(){return this._getMetrics().surfaceArea}},{key:"centroid",get:function(){return this._getMetrics().centroid}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"_setAABBDirty",value:function(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this);var e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),vt.meshes--}}]),n}(),yt=he.memory,_t=Ae.AABB3(),bt=function(e){m(n,nt);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,n),(r=t.call(this,e,i))._state=new it({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),r._numTriangles=0,r._edgeThreshold=i.edgeThreshold||10,r._aabb=null,r._obb=Ae.OBB3();var s,a=r._state,o=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":a.primitive=o.POINTS,a.primitiveName=i.primitive;break;case"lines":a.primitive=o.LINES,a.primitiveName=i.primitive;break;case"line-loop":a.primitive=o.LINE_LOOP,a.primitiveName=i.primitive;break;case"line-strip":a.primitive=o.LINE_STRIP,a.primitiveName=i.primitive;break;case"triangles":a.primitive=o.TRIANGLES,a.primitiveName=i.primitive;break;case"triangle-strip":a.primitive=o.TRIANGLE_STRIP,a.primitiveName=i.primitive;break;case"triangle-fan":a.primitive=o.TRIANGLE_FAN,a.primitiveName=i.primitive;break;default:r.error("Unsupported value for 'primitive': '"+i.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),a.primitive=o.TRIANGLES,a.primitiveName=i.primitive}if(!i.positions)return r.error("Config expected: positions"),b(r);if(!i.indices)return r.error("Config expected: indices"),b(r);var A=i.positionsDecodeMatrix;if(A);else{var c=pt.getPositionsBounds(i.positions),l=pt.compressPositions(i.positions,c.min,c.max);s=l.quantized,a.positionsDecodeMatrix=l.decodeMatrix,a.positionsBuf=new st(o,o.ARRAY_BUFFER,s,s.length,3,o.STATIC_DRAW),yt.positions+=a.positionsBuf.numItems,Ae.positions3ToAABB3(i.positions,r._aabb),Ae.positions3ToAABB3(s,_t,a.positionsDecodeMatrix),Ae.AABB3ToOBB3(_t,r._obb)}if(i.colors){var u=i.colors.constructor===Float32Array?i.colors:new Float32Array(i.colors);a.colorsBuf=new st(o,o.ARRAY_BUFFER,u,u.length,4,o.STATIC_DRAW),yt.colors+=a.colorsBuf.numItems}if(i.uv){var h=pt.getUVBounds(i.uv),d=pt.compressUVs(i.uv,h.min,h.max),f=d.quantized;a.uvDecodeMatrix=d.decodeMatrix,a.uvBuf=new st(o,o.ARRAY_BUFFER,f,f.length,2,o.STATIC_DRAW),yt.uvs+=a.uvBuf.numItems}if(i.normals){var p=pt.compressNormals(i.normals),v=a.compressGeometry;a.normalsBuf=new st(o,o.ARRAY_BUFFER,p,p.length,3,o.STATIC_DRAW,v),yt.normals+=a.normalsBuf.numItems}var g=i.indices.constructor===Uint32Array||i.indices.constructor===Uint16Array?i.indices:new Uint32Array(i.indices);a.indicesBuf=new st(o,o.ELEMENT_ARRAY_BUFFER,g,g.length,1,o.STATIC_DRAW),yt.indices+=a.indicesBuf.numItems;var m=at(s,g,a.positionsDecodeMatrix,r._edgeThreshold);return r._edgeIndicesBuf=new st(o,o.ELEMENT_ARRAY_BUFFER,m,m.length,1,o.STATIC_DRAW),"triangles"===r._state.primitiveName&&(r._numTriangles=i.indices.length/3),r._buildHash(),yt.meshes++,r}return I(n,[{key:"type",get:function(){return"VBOGeometry"}},{key:"isVBOGeometry",get:function(){return!0}},{key:"_buildHash",value:function(){var e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}},{key:"_getEdgeIndices",value:function(){return this._edgeIndicesBuf}},{key:"primitive",get:function(){return this._state.primitiveName}},{key:"aabb",get:function(){return this._aabb}},{key:"obb",get:function(){return this._obb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this);var e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),yt.meshes--}}]),n}(),wt={};function Bt(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(n,r){t.src||(console.error("load3DSGeometry: Parameter expected: src"),r());var i=e.canvas.spinner;i.processes++,ge.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("load3DSGeometry: no data loaded"),i.processes--,r());var s=wt.parse.from3DS(e).edit.objects[0].mesh,a=s.vertices,o=s.uvt,A=s.indices;i.processes--,n(ge.apply(t,{primitive:"triangles",positions:a,normals:null,uv:o,indices:A}))}),(function(e){console.error("load3DSGeometry: "+e),i.processes--,r()}))}))}function Ct(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(n,r){t.src||(console.error("loadOBJGeometry: Parameter expected: src"),r());var i=e.canvas.spinner;i.processes++,ge.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("loadOBJGeometry: no data loaded"),i.processes--,r());for(var s=wt.parse.fromOBJ(e),a=wt.edit.unwrap(s.i_verts,s.c_verts,3),o=wt.edit.unwrap(s.i_norms,s.c_norms,3),A=wt.edit.unwrap(s.i_uvt,s.c_uvt,2),c=new Int32Array(s.i_verts.length),l=0;l<s.i_verts.length;l++)c[l]=l;i.processes--,n(ge.apply(t,{primitive:"triangles",positions:a,normals:o.length>0?o:null,autoNormals:0===o.length,uv:A,indices:c}))}),(function(e){console.error("loadOBJGeometry: "+e),i.processes--,r()}))}))}function Mt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.ySize||1;n<0&&(console.error("negative ySize not allowed - will invert"),n*=-1);var r=e.zSize||1;r<0&&(console.error("negative zSize not allowed - will invert"),r*=-1);var i=e.center,s=i?i[0]:0,a=i?i[1]:0,o=i?i[2]:0,A=-t+s,c=-n+a,l=-r+o,u=t+s,h=n+a,d=r+o;return ge.apply(e,{positions:[u,h,d,A,h,d,A,c,d,u,c,d,u,h,d,u,c,d,u,c,l,u,h,l,u,h,d,u,h,l,A,h,l,A,h,d,A,h,d,A,h,l,A,c,l,A,c,d,A,c,l,u,c,l,u,c,d,A,c,d,u,c,l,A,c,l,A,h,l,u,h,l],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}function kt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.ySize||1;n<0&&(console.error("negative ySize not allowed - will invert"),n*=-1);var r=e.zSize||1;r<0&&(console.error("negative zSize not allowed - will invert"),r*=-1);var i=e.center,s=i?i[0]:0,a=i?i[1]:0,o=i?i[2]:0,A=-t+s,c=-n+a,l=-r+o,u=t+s,h=n+a,d=r+o;return ge.apply(e,{primitive:"lines",positions:[A,c,l,A,c,d,A,h,l,A,h,d,u,c,l,u,c,d,u,h,l,u,h,d],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]})}function Et(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return kt({id:e.id,center:[(e.aabb[0]+e.aabb[3])/2,(e.aabb[1]+e.aabb[4])/2,(e.aabb[2]+e.aabb[5])/2],xSize:Math.abs(e.aabb[3]-e.aabb[0])/2,ySize:Math.abs(e.aabb[4]-e.aabb[1])/2,zSize:Math.abs(e.aabb[5]-e.aabb[2])/2})}function Ft(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);var n=e.radiusBottom||1;n<0&&(console.error("negative radiusBottom not allowed - will invert"),n*=-1);var r=e.height||1;r<0&&(console.error("negative height not allowed - will invert"),r*=-1);var i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<3&&(i=3);var s=e.heightSegments||1;s<0&&(console.error("negative heightSegments not allowed - will invert"),s*=-1),s<1&&(s=1);var a,o,A,c,l,u,h,d,f,p,v,g=!!e.openEnded,m=e.center,y=m?m[0]:0,_=m?m[1]:0,b=m?m[2]:0,w=r/2,B=r/s,C=2*Math.PI/i,M=1/i,k=(t-n)/s,E=[],F=[],x=[],U=[],I=(90-180*Math.atan(r/(n-t))/Math.PI)/90;for(a=0;a<=s;a++)for(l=t-a*k,u=w-a*B,o=0;o<=i;o++)A=Math.sin(o*C),c=Math.cos(o*C),F.push(l*A),F.push(I),F.push(l*c),x.push(o*M),x.push(1*a/s),E.push(l*A+y),E.push(u+_),E.push(l*c+b);for(a=0;a<s;a++)for(o=0;o<=i;o++)d=(h=a*(i+1)+o)+i,U.push(h),U.push(d),U.push(d+1),U.push(h),U.push(d+1),U.push(h+1);if(!g&&t>0){for(f=E.length/3,F.push(0),F.push(1),F.push(0),x.push(.5),x.push(.5),E.push(0+y),E.push(w+_),E.push(0+b),o=0;o<=i;o++)A=Math.sin(o*C),c=Math.cos(o*C),p=.5*Math.sin(o*C)+.5,v=.5*Math.cos(o*C)+.5,F.push(t*A),F.push(1),F.push(t*c),x.push(p),x.push(v),E.push(t*A+y),E.push(w+_),E.push(t*c+b);for(o=0;o<i;o++)m=f,h=f+1+o,U.push(h),U.push(h+1),U.push(m)}if(!g&&n>0){for(f=E.length/3,F.push(0),F.push(-1),F.push(0),x.push(.5),x.push(.5),E.push(0+y),E.push(0-w+_),E.push(0+b),o=0;o<=i;o++)A=Math.sin(o*C),c=Math.cos(o*C),p=.5*Math.sin(o*C)+.5,v=.5*Math.cos(o*C)+.5,F.push(n*A),F.push(-1),F.push(n*c),x.push(p),x.push(v),E.push(n*A+y),E.push(0-w+_),E.push(n*c+b);for(o=0;o<i;o++)m=f,h=f+1+o,U.push(m),U.push(h+1),U.push(h)}return ge.apply(e,{positions:E,normals:F,uv:x,indices:U})}function xt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);var n=e.divisions||1;n<0&&(console.error("negative divisions not allowed - will invert"),n*=-1),n<1&&(n=1);for(var r=(t=t||10)/(n=n||10),i=t/2,s=[],a=[],o=0,A=0,c=-i;A<=n;A++,c+=r)s.push(-i),s.push(0),s.push(c),s.push(i),s.push(0),s.push(c),s.push(c),s.push(0),s.push(-i),s.push(c),s.push(0),s.push(i),a.push(o++),a.push(o++),a.push(o++),a.push(o++);return ge.apply(e,{primitive:"lines",positions:s,indices:a})}function Ut(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);var r=e.xSegments||1;r<0&&(console.error("negative xSegments not allowed - will invert"),r*=-1),r<1&&(r=1);var i=e.xSegments||1;i<0&&(console.error("negative zSegments not allowed - will invert"),i*=-1),i<1&&(i=1);var s,a,o,A,c,l,u,h=e.center,d=h?h[0]:0,f=h?h[1]:0,p=h?h[2]:0,v=t/2,g=n/2,m=Math.floor(r)||1,y=Math.floor(i)||1,_=m+1,b=y+1,w=t/m,B=n/y,C=new Float32Array(_*b*3),M=new Float32Array(_*b*3),k=new Float32Array(_*b*2),E=0,F=0;for(s=0;s<b;s++){var x=s*B-g;for(a=0;a<_;a++)o=a*w-v,C[E]=o+d,C[E+1]=f,C[E+2]=-x+p,M[E+1]=1,k[F]=a/m,k[F+1]=(y-s)/y,E+=3,F+=2}E=0;var U=new(C.length/3>65535?Uint32Array:Uint16Array)(m*y*6);for(s=0;s<y;s++)for(a=0;a<m;a++)A=a+_*s,c=a+_*(s+1),l=a+1+_*(s+1),u=a+1+_*s,U[E]=u,U[E+1]=c,U[E+2]=A,U[E+3]=u,U[E+4]=l,U[E+5]=c,E+=6;return ge.apply(e,{positions:C,normals:M,uv:k,indices:U})}function It(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.lod||1,n=e.center?e.center[0]:0,r=e.center?e.center[1]:0,i=e.center?e.center[2]:0,s=e.radius||1;s<0&&(console.error("negative radius not allowed - will invert"),s*=-1);var a=e.heightSegments||18;a<0&&(console.error("negative heightSegments not allowed - will invert"),a*=-1),(a=Math.floor(t*a))<18&&(a=18);var o=e.widthSegments||18;o<0&&(console.error("negative widthSegments not allowed - will invert"),o*=-1),(o=Math.floor(t*o))<18&&(o=18);var A,c,l,u,h,d,f,p,v,g,m,y,_,b,w=[],B=[],C=[],M=[];for(A=0;A<=a;A++)for(l=A*Math.PI/a,u=Math.sin(l),h=Math.cos(l),c=0;c<=o;c++)d=2*c*Math.PI/o,f=Math.sin(d),p=Math.cos(d)*u,v=h,g=f*u,m=1-c/o,y=A/a,B.push(p),B.push(v),B.push(g),C.push(m),C.push(y),w.push(n+s*p),w.push(r+s*v),w.push(i+s*g);for(A=0;A<a;A++)for(c=0;c<o;c++)b=(_=A*(o+1)+c)+o+1,M.push(_+1),M.push(b+1),M.push(b),M.push(_+1),M.push(b),M.push(_);return ge.apply(e,{positions:w,normals:B,uv:C,indices:M})}function Tt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.radius||1;t<0&&(console.error("negative radius not allowed - will invert"),t*=-1),t*=.5;var n=e.tube||.3;n<0&&(console.error("negative tube not allowed - will invert"),n*=-1);var r=e.radialSegments||32;r<0&&(console.error("negative radialSegments not allowed - will invert"),r*=-1),r<4&&(r=4);var i=e.tubeSegments||24;i<0&&(console.error("negative tubeSegments not allowed - will invert"),i*=-1),i<4&&(i=4);var s=e.arc||2*Math.PI;s<0&&(console.warn("negative arc not allowed - will invert"),s*=-1),s>360&&(s=360);var a,o,A,c,l,u,h,d,f,p,v,g,m=e.center,y=m?m[0]:0,_=m?m[1]:0,b=m?m[2]:0,w=[],B=[],C=[],M=[];for(d=0;d<=i;d++)for(h=0;h<=r;h++)a=h/r*s,o=.785398+d/i*Math.PI*2,y=t*Math.cos(a),_=t*Math.sin(a),A=(t+n*Math.cos(o))*Math.cos(a),c=(t+n*Math.cos(o))*Math.sin(a),l=n*Math.sin(o),w.push(A+y),w.push(c+_),w.push(l+b),C.push(1-h/r),C.push(d/i),u=Ae.normalizeVec3(Ae.subVec3([A,c,l],[y,_,b],[]),[]),B.push(u[0]),B.push(u[1]),B.push(u[2]);for(d=1;d<=i;d++)for(h=1;h<=r;h++)f=(r+1)*d+h-1,p=(r+1)*(d-1)+h-1,v=(r+1)*(d-1)+h,g=(r+1)*d+h,M.push(f),M.push(p),M.push(v),M.push(v),M.push(g),M.push(f);return ge.apply(e,{positions:w,normals:B,uv:C,indices:M})}wt.load=function(e,t){var n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=function(e){t(e.target.response)},n.send()},wt.save=function(e,t){var n="data:application/octet-stream;base64,"+btoa(wt.parse._buffToStr(e));window.location.href=n},wt.clone=function(e){return JSON.parse(JSON.stringify(e))},wt.bin={},wt.bin.f=new Float32Array(1),wt.bin.fb=new Uint8Array(wt.bin.f.buffer),wt.bin.rf=function(e,t){for(var n=wt.bin.f,r=wt.bin.fb,i=0;i<4;i++)r[i]=e[t+i];return n[0]},wt.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},wt.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},wt.bin.rASCII0=function(e,t){for(var n="";0!=e[t];)n+=String.fromCharCode(e[t++]);return n},wt.bin.wf=function(e,t,n){new Float32Array(e.buffer,t,1)[0]=n},wt.bin.wsl=function(e,t,n){e[t]=n,e[t+1]=n>>8},wt.bin.wil=function(e,t,n){e[t]=n,e[t+1]=n>>8,e[t+2]=n>>16,e[t+3]},wt.parse={},wt.parse._buffToStr=function(e){for(var t=new Uint8Array(e),n="",r=0;r<t.length;r++)n=n.concat(String.fromCharCode(t[r]));return n},wt.parse._strToBuff=function(e){for(var t=new ArrayBuffer(e.length),n=new Uint8Array(t),r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return t},wt.parse._readLine=function(e,t){for(var n="";10!=e[t];)n+=String.fromCharCode(e[t++]);return n},wt.parse.fromJSON=function(e){return JSON.parse(wt.parse._buffToStr(e))},wt.parse.toJSON=function(e){var t=JSON.stringify(e);return wt.parse._strToBuff(t)},wt.parse.fromOBJ=function(e){for(var t={groups:{},c_verts:[],c_uvt:[],c_norms:[],i_verts:[],i_uvt:[],i_norms:[]},n={from:0,to:0},r=0,i=new Uint8Array(e);r<i.length;){var s=wt.parse._readLine(i,r);r+=s.length+1;var a=(s=(s=s.replace(/ +(?= )/g,"")).replace(/(^\s+|\s+$)/g,"")).split(" ");if("g"==a[0]&&(n.to=t.i_verts.length,null==t.groups[a[1]]&&(t.groups[a[1]]={from:t.i_verts.length,to:0}),n=t.groups[a[1]]),"v"==a[0]){var o=parseFloat(a[1]),A=parseFloat(a[2]),c=parseFloat(a[3]);t.c_verts.push(o,A,c)}if("vt"==a[0]){o=parseFloat(a[1]),A=1-parseFloat(a[2]);t.c_uvt.push(o,A)}if("vn"==a[0]){o=parseFloat(a[1]),A=parseFloat(a[2]),c=parseFloat(a[3]);t.c_norms.push(o,A,c)}if("f"==a[0]){var l=a[1].split("/"),u=a[2].split("/"),h=a[3].split("/"),d=parseInt(l[0])-1,f=parseInt(u[0])-1,p=parseInt(h[0])-1,v=parseInt(l[1])-1,g=parseInt(u[1])-1,m=parseInt(h[1])-1,y=parseInt(l[2])-1,_=parseInt(u[2])-1,b=parseInt(h[2])-1,w=t.c_verts.length/3,B=t.c_uvt.length/2,C=t.c_norms.length/3;if(d<0&&(d=w+d+1),f<0&&(f=w+f+1),p<0&&(p=w+p+1),v<0&&(v=B+v+1),g<0&&(g=B+g+1),m<0&&(m=B+m+1),y<0&&(y=C+y+1),_<0&&(_=C+_+1),b<0&&(b=C+b+1),t.i_verts.push(d,f,p),t.i_uvt.push(v,g,m),t.i_norms.push(y,_,b),5==a.length){var M=a[4].split("/"),k=parseInt(M[0])-1,E=parseInt(M[1])-1,F=parseInt(M[2])-1;k<0&&(k=w+k+1),E<0&&(E=B+E+1),F<0&&(F=C+F+1),t.i_verts.push(d,p,k),t.i_uvt.push(v,m,E),t.i_norms.push(y,b,F)}}}return n.to=t.i_verts.length,t},wt.parse.fromMD2=function(e){e=new Uint8Array(e);var t={},n={};n.ident=wt.bin.ril(e,0),n.version=wt.bin.ril(e,4),n.skinwidth=wt.bin.ril(e,8),n.skinheight=wt.bin.ril(e,12),n.framesize=wt.bin.ril(e,16),n.num_skins=wt.bin.ril(e,20),n.num_vertices=wt.bin.ril(e,24),n.num_st=wt.bin.ril(e,28),n.num_tris=wt.bin.ril(e,32),n.num_glcmds=wt.bin.ril(e,36),n.num_frames=wt.bin.ril(e,40),n.offset_skins=wt.bin.ril(e,44),n.offset_st=wt.bin.ril(e,48),n.offset_tris=wt.bin.ril(e,52),n.offset_frames=wt.bin.ril(e,56),n.offset_glcmds=wt.bin.ril(e,60),n.offset_end=wt.bin.ril(e,64);var r=n.offset_st;t.c_uvt=[];for(var i=0;i<n.num_st;i++){var s=wt.bin.rsl(e,r)/n.skinwidth,a=wt.bin.rsl(e,r+2)/n.skinheight;t.c_uvt.push(s,a),r+=4}r=n.offset_tris;var o=[],A=[];t.i_verts=o,t.i_uvt=A;for(i=0;i<n.num_tris;i++)o.push(wt.bin.rsl(e,r),wt.bin.rsl(e,r+2),wt.bin.rsl(e,r+4)),A.push(wt.bin.rsl(e,r+6),wt.bin.rsl(e,r+8),wt.bin.rsl(e,r+10)),r+=12;r=n.offset_skins;t.skins=[];for(i=0;i<n.num_skins;i++)t.skins.push(wt.bin.rASCII0(e,r)),r+=64;r=n.offset_frames;t.frames=[];var c=wt.parse.fromMD2._normals;for(i=0;i<n.num_frames;i++){var l={},u=wt.bin.rf(e,r),h=wt.bin.rf(e,r+4),d=wt.bin.rf(e,r+8);r+=12;var f=wt.bin.rf(e,r),p=wt.bin.rf(e,r+4),v=wt.bin.rf(e,r+8);r+=12,l.name=wt.bin.rASCII0(e,r),r+=16,l.verts=[],l.norms=[];for(var g=0;g<n.num_vertices;g++)l.verts.push(e[r]*u+f,e[r+1]*h+p,e[r+2]*d+v),l.norms.push(c[3*e[r+3]],c[3*e[r+3]+1],c[3*e[r+3]+2]),r+=4;t.frames.push(l)}return t},wt.parse.fromMD2._normals=[-.525731,0,.850651,-.442863,.238856,.864188,-.295242,0,.955423,-.309017,.5,.809017,-.16246,.262866,.951056,0,0,1,0,.850651,.525731,-.147621,.716567,.681718,.147621,.716567,.681718,0,.525731,.850651,.309017,.5,.809017,.525731,0,.850651,.295242,0,.955423,.442863,.238856,.864188,.16246,.262866,.951056,-.681718,.147621,.716567,-.809017,.309017,.5,-.587785,.425325,.688191,-.850651,.525731,0,-.864188,.442863,.238856,-.716567,.681718,.147621,-.688191,.587785,.425325,-.5,.809017,.309017,-.238856,.864188,.442863,-.425325,.688191,.587785,-.716567,.681718,-.147621,-.5,.809017,-.309017,-.525731,.850651,0,0,.850651,-.525731,-.238856,.864188,-.442863,0,.955423,-.295242,-.262866,.951056,-.16246,0,1,0,0,.955423,.295242,-.262866,.951056,.16246,.238856,.864188,.442863,.262866,.951056,.16246,.5,.809017,.309017,.238856,.864188,-.442863,.262866,.951056,-.16246,.5,.809017,-.309017,.850651,.525731,0,.716567,.681718,.147621,.716567,.681718,-.147621,.525731,.850651,0,.425325,.688191,.587785,.864188,.442863,.238856,.688191,.587785,.425325,.809017,.309017,.5,.681718,.147621,.716567,.587785,.425325,.688191,.955423,.295242,0,1,0,0,.951056,.16246,.262866,.850651,-.525731,0,.955423,-.295242,0,.864188,-.442863,.238856,.951056,-.16246,.262866,.809017,-.309017,.5,.681718,-.147621,.716567,.850651,0,.525731,.864188,.442863,-.238856,.809017,.309017,-.5,.951056,.16246,-.262866,.525731,0,-.850651,.681718,.147621,-.716567,.681718,-.147621,-.716567,.850651,0,-.525731,.809017,-.309017,-.5,.864188,-.442863,-.238856,.951056,-.16246,-.262866,.147621,.716567,-.681718,.309017,.5,-.809017,.425325,.688191,-.587785,.442863,.238856,-.864188,.587785,.425325,-.688191,.688191,.587785,-.425325,-.147621,.716567,-.681718,-.309017,.5,-.809017,0,.525731,-.850651,-.525731,0,-.850651,-.442863,.238856,-.864188,-.295242,0,-.955423,-.16246,.262866,-.951056,0,0,-1,.295242,0,-.955423,.16246,.262866,-.951056,-.442863,-.238856,-.864188,-.309017,-.5,-.809017,-.16246,-.262866,-.951056,0,-.850651,-.525731,-.147621,-.716567,-.681718,.147621,-.716567,-.681718,0,-.525731,-.850651,.309017,-.5,-.809017,.442863,-.238856,-.864188,.16246,-.262866,-.951056,.238856,-.864188,-.442863,.5,-.809017,-.309017,.425325,-.688191,-.587785,.716567,-.681718,-.147621,.688191,-.587785,-.425325,.587785,-.425325,-.688191,0,-.955423,-.295242,0,-1,0,.262866,-.951056,-.16246,0,-.850651,.525731,0,-.955423,.295242,.238856,-.864188,.442863,.262866,-.951056,.16246,.5,-.809017,.309017,.716567,-.681718,.147621,.525731,-.850651,0,-.238856,-.864188,-.442863,-.5,-.809017,-.309017,-.262866,-.951056,-.16246,-.850651,-.525731,0,-.716567,-.681718,-.147621,-.716567,-.681718,.147621,-.525731,-.850651,0,-.5,-.809017,.309017,-.238856,-.864188,.442863,-.262866,-.951056,.16246,-.864188,-.442863,.238856,-.809017,-.309017,.5,-.688191,-.587785,.425325,-.681718,-.147621,.716567,-.442863,-.238856,.864188,-.587785,-.425325,.688191,-.309017,-.5,.809017,-.147621,-.716567,.681718,-.425325,-.688191,.587785,-.16246,-.262866,.951056,.442863,-.238856,.864188,.16246,-.262866,.951056,.309017,-.5,.809017,.147621,-.716567,.681718,0,-.525731,.850651,.425325,-.688191,.587785,.587785,-.425325,.688191,.688191,-.587785,.425325,-.955423,.295242,0,-.951056,.16246,.262866,-1,0,0,-.850651,0,.525731,-.955423,-.295242,0,-.951056,-.16246,.262866,-.864188,.442863,-.238856,-.951056,.16246,-.262866,-.809017,.309017,-.5,-.864188,-.442863,-.238856,-.951056,-.16246,-.262866,-.809017,-.309017,-.5,-.681718,.147621,-.716567,-.681718,-.147621,-.716567,-.850651,0,-.525731,-.688191,.587785,-.425325,-.587785,.425325,-.688191,-.425325,.688191,-.587785,-.425325,-.688191,-.587785,-.587785,-.425325,-.688191,-.688191,-.587785,-.425325],wt.parse.fromCollada=function(e){var t=wt.parse._buffToStr(e),n=(new DOMParser).parseFromString(t,"text/xml"),r={},i=(n=n.childNodes[0]).getElementsByTagName("asset")[0],s=n.getElementsByTagName("library_geometries")[0],a=n.getElementsByTagName("library_images")[0],o=n.getElementsByTagName("library_materials")[0],A=n.getElementsByTagName("library_effects")[0];return i&&(r.asset=wt.parse.fromCollada._asset(i)),s&&(r.geometries=wt.parse.fromCollada._libGeometries(s)),a&&(r.images=wt.parse.fromCollada._libImages(a)),o&&(r.materials=wt.parse.fromCollada._libMaterials(o)),A&&(r.effects=wt.parse.fromCollada._libEffects(A)),r},wt.parse.fromCollada._asset=function(e){return{created:e.getElementsByTagName("created")[0].textContent,modified:e.getElementsByTagName("modified")[0].textContent,up_axis:e.getElementsByTagName("up_axis")[0].textContent}},wt.parse.fromCollada._libGeometries=function(e){e=e.getElementsByTagName("geometry");for(var t=[],n=0;n<e.length;n++){var r=e[n],i=wt.parse.fromCollada._getMesh(r.getElementsByTagName("mesh")[0]);t.push(i)}return t},wt.parse.fromCollada._getMesh=function(e){for(var t={},n=e.getElementsByTagName("source"),r=t.sources={},i=0;i<n.length;i++){for(var s=n[i].getElementsByTagName("float_array")[0].textContent.split(" "),a=s.length-(""==s[s.length-1]?1:0),o=new Array(a),A=0;A<a;A++)o[A]=parseFloat(s[A]);r[n[i].getAttribute("id")]=o}t.triangles=[];var c=e.getElementsByTagName("triangles");if(null==c)return t;for(i=0;i<c.length;i++){var l={},u=c[i];l.material=u.getAttribute("material");var h=u.getElementsByTagName("input"),d=[];for(A=0;A<h.length;A++){var f=h[A];o=[];d[parseInt(f.getAttribute("offset"))]=o;var p=f.getAttribute("semantic");l["s_"+p]="VERTEX"==p?e.getElementsByTagName("vertices")[0].getElementsByTagName("input")[0].getAttribute("source").substring(1):f.getAttribute("source").substring(1),l["i_"+p]=o,r[l["s_"+p]]}var v=u.getElementsByTagName("p")[0].textContent.split(" "),g=3*Math.floor(v.length/3);for(A=0;A<g;A++)d[A%h.length].push(parseInt(v[A]));t.triangles.push(l)}return t},wt.parse.fromCollada._libImages=function(e){e=e.getElementsByTagName("image");for(var t={},n=0;n<e.length;n++)t[e[n].getAttribute("id")]=e[n].getElementsByTagName("init_from")[0].textContent;return t},wt.parse.fromCollada._libMaterials=function(e){e=e.getElementsByTagName("material");for(var t={},n=0;n<e.length;n++)t[e[n].getAttribute("name")]=e[n].getElementsByTagName("instance_effect")[0].getAttribute("url").substring(1);return t},wt.parse.fromCollada._libEffects=function(e){e=e.getElementsByTagName("effect");for(var t={},n=0;n<e.length;n++){for(var r={},i=e[n].getElementsByTagName("newparam"),s=0;s<i.length;s++){var a=i[s].getElementsByTagName("surface")[0];a&&(r.surface=a.getElementsByTagName("init_from")[0].textContent)}t[e[n].getAttribute("id")]=r}return t},wt.parse.from3DS=function(e){e=new Uint8Array(e);var t={};if(19789!=wt.bin.rsl(e,0))return null;for(var n=wt.bin.ril(e,2),r=6;r<n;){var i=wt.bin.rsl(e,r),s=wt.bin.ril(e,r+2);15677==i&&(t.edit=wt.parse.from3DS._edit3ds(e,r,s)),45056==i&&(t.keyf=wt.parse.from3DS._keyf3ds(e,r,s)),r+=s}return t},wt.parse.from3DS._edit3ds=function(e,t,n){for(var r={},i=t+6;i<t+n;){var s=wt.bin.rsl(e,i),a=wt.bin.ril(e,i+2);16384==s&&(null==r.objects&&(r.objects=[]),r.objects.push(wt.parse.from3DS._edit_object(e,i,a))),i+=a}return r},wt.parse.from3DS._keyf3ds=function(e,t,n){for(var r={},i=t+6;i<t+n;){var s=wt.bin.rsl(e,i),a=wt.bin.ril(e,i+2);45058==s&&(null==r.desc&&(r.desc=[]),r.desc.push(wt.parse.from3DS._keyf_objdes(e,i,a))),i+=a}return r},wt.parse.from3DS._keyf_objdes=function(e,t,n){for(var r={},i=t+6;i<t+n;){var s=wt.bin.rsl(e,i),a=wt.bin.ril(e,i+2);45072==s&&(r.hierarchy=wt.parse.from3DS._keyf_objhierarch(e,i,a)),45073==s&&(r.dummy_name=wt.bin.rASCII0(e,i+6)),i+=a}return r},wt.parse.from3DS._keyf_objhierarch=function(e,t,n){var r={},i=t+6;return r.name=wt.bin.rASCII0(e,i),i+=r.name.length+1,r.hierarchy=wt.bin.rsl(e,i+4),r},wt.parse.from3DS._edit_object=function(e,t,n){var r={},i=t+6;for(r.name=wt.bin.rASCII0(e,i),i+=r.name.length+1;i<t+n;){var s=wt.bin.rsl(e,i),a=wt.bin.ril(e,i+2);16640==s&&(r.mesh=wt.parse.from3DS._obj_trimesh(e,i,a)),i+=a}return r},wt.parse.from3DS._obj_trimesh=function(e,t,n){for(var r={},i=t+6;i<t+n;){var s=wt.bin.rsl(e,i),a=wt.bin.ril(e,i+2);16656==s&&(r.vertices=wt.parse.from3DS._tri_vertexl(e,i,a)),16672==s&&(r.indices=wt.parse.from3DS._tri_facel1(e,i,a)),16704==s&&(r.uvt=wt.parse.from3DS._tri_mappingcoors(e,i,a)),16736==s&&(r.local=wt.parse.from3DS._tri_local(e,i,a)),i+=a}return r},wt.parse.from3DS._tri_vertexl=function(e,t,n){var r=[],i=t+6,s=wt.bin.rsl(e,i);i+=2;for(var a=0;a<s;a++)r.push(wt.bin.rf(e,i)),r.push(wt.bin.rf(e,i+4)),r.push(wt.bin.rf(e,i+8)),i+=12;return r},wt.parse.from3DS._tri_facel1=function(e,t,n){var r=[],i=t+6,s=wt.bin.rsl(e,i);i+=2;for(var a=0;a<s;a++)r.push(wt.bin.rsl(e,i)),r.push(wt.bin.rsl(e,i+2)),r.push(wt.bin.rsl(e,i+4)),i+=8;return r},wt.parse.from3DS._tri_mappingcoors=function(e,t,n){var r=[],i=t+6,s=wt.bin.rsl(e,i);i+=2;for(var a=0;a<s;a++)r.push(wt.bin.rf(e,i)),r.push(1-wt.bin.rf(e,i+4)),i+=8;return r},wt.parse.from3DS._tri_local=function(e,t,n){var r={},i=t+6;return r.X=[wt.bin.rf(e,i),wt.bin.rf(e,i+4),wt.bin.rf(e,i+8)],i+=12,r.Y=[wt.bin.rf(e,i),wt.bin.rf(e,i+4),wt.bin.rf(e,i+8)],i+=12,r.Z=[wt.bin.rf(e,i),wt.bin.rf(e,i+4),wt.bin.rf(e,i+8)],i+=12,r.C=[wt.bin.rf(e,i),wt.bin.rf(e,i+4),wt.bin.rf(e,i+8)],i+=12,r},wt.parse.fromBIV=function(e){e=new Uint8Array(e);var t={},n={};return n.id=wt.bin.ril(e,0),n.verS=wt.bin.ril(e,4),n.texS=wt.bin.ril(e,8),n.indS=wt.bin.ril(e,12),n.verO=wt.bin.ril(e,16),n.verL=wt.bin.ril(e,20),n.texO=wt.bin.ril(e,24),n.texL=wt.bin.ril(e,28),n.indO=wt.bin.ril(e,32),n.indL=wt.bin.ril(e,36),0!=n.verO&&(t.vertices=wt.parse.fromBIV._readFloats(e,n.verO,n.verL)),0!=n.texO&&(t.uvt=wt.parse.fromBIV._readFloats(e,n.texO,n.texL)),0!=n.indO&&(t.indices=wt.parse.fromBIV._readInts(e,n.indO,n.indL,n.indS)),t},wt.parse.toBIV=function(e){for(var t=0,n=0;n<e.indices.length;n++)t=Math.max(t,e.indices[n]);var r=32;t<=65535&&(r=16);var i=40;e.vertices&&(i+=4*e.vertices.length),e.uvt&&(i+=4*e.uvt.length),e.indices&&(i+=e.indices.length*r/8);var s=new Uint8Array(i);wt.bin.wil(s,0,1769365870),wt.bin.wil(s,4,32),wt.bin.wil(s,8,32),wt.bin.wil(s,12,r);var a=40;return e.vertices&&(wt.bin.wil(s,16,a),wt.bin.wil(s,20,4*e.vertices.length),wt.parse.fromBIV._writeFloats(s,a,e.vertices),a+=4*e.vertices.length),e.uvt&&(wt.bin.wil(s,24,a),wt.bin.wil(s,28,4*e.uvt.length),wt.parse.fromBIV._writeFloats(s,a,e.uvt),a+=4*e.uvt.length),e.indices&&(wt.bin.wil(s,32,a),wt.bin.wil(s,36,4*e.indices.length),wt.parse.fromBIV._writeInts(s,a,e.indices,r)),s.buffer},wt.parse.fromBIV._readFloats=function(e,t,n){for(var r=[],i=0;i<n/4;i++)r.push(wt.bin.rf(e,t+4*i));return r},wt.parse.fromBIV._writeFloats=function(e,t,n){for(var r=0;r<n.length;r++)wt.bin.wf(e,t+4*r,n[r])},wt.parse.fromBIV._readInts=function(e,t,n,r){for(var i=[],s=0;s<n/4;s++)16==r&&i.push(wt.bin.rsl(e,t+2*s)),32==r&&i.push(wt.bin.ril(e,t+4*s));return i},wt.parse.fromBIV._writeInts=function(e,t,n,r){for(var i=0;i<n.length;i++)16==r&&wt.bin.wsl(e,t+2*i,n[i]),32==r&&wt.bin.wil(e,t+4*i,n[i])},wt.gen={},wt.gen.Plane=function(e,t,n,r){n||(n=1),r||(r=1);for(var i={verts:[],inds:[],uvt:[]},s=e+1,a=t+1,o=0;o<a;o++)for(var A=0;A<s;A++){var c=A*(2/e)-1,l=o*(2/t)-1;i.verts.push(c,l,0),i.uvt.push(n*A/e,r*o/t),o<t&&A<e&&i.inds.push(o*s+A,o*s+A+1,(o+1)*s+A,o*s+A+1,(o+1)*s+A,(o+1)*s+A+1)}return i},wt.gen.Cube=function(){return{verts:[-1,1,-1,1,1,-1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,1,-1,-1,1,1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,1,-1,1,-1,1,1,-1,-1,-1,1,-1,1,1,-1,-1,1,1,1,1,1,-1,-1,-1,1,-1,-1,-1,-1,1,1,-1,1],inds:[0,1,2,1,2,3,4,5,6,5,6,7,8,9,10,9,10,11,12,13,14,13,14,15,16,17,18,17,18,19,20,21,22,21,22,23],uvt:[1/4,1/4,.5,1/4,1/4,.5,.5,.5,1,1/4,3/4,1/4,1,.5,3/4,.5,0,1/4,1/4,1/4,0,.5,1/4,.5,3/4,1/4,.5,1/4,3/4,.5,.5,.5,1/4,1/4,.5,1/4,1/4,0,.5,0,1/4,.5,.5,.5,1/4,3/4,.5,3/4]}},wt.gen.Sphere=function(e,t){for(var n={verts:[],inds:[],uvt:[]},r=e+1,i=t+1,s=0;s<i;s++)for(var a=0;a<r;a++){var o=-Math.PI/2+s*Math.PI/t,A=2*a*Math.PI/e,c=Math.cos(o)*Math.cos(A),l=Math.sin(o),u=Math.cos(o)*Math.sin(A);n.verts.push(c,l,u),n.uvt.push(a/e,s/t),s<t&&a<e&&n.inds.push(r*s+a,r*s+a+1,r*(s+1)+a,r*s+a+1,r*(s+1)+a,r*(s+1)+a+1)}return n},wt.mat={},wt.mat.scale=function(e,t,n){return[e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1]},wt.mat.translate=function(e,t,n){return[1,0,0,0,0,1,0,0,0,0,1,0,e,t,n,1]},wt.mat.rotateDeg=function(e,t,n){var r=Math.PI/180;return wt.mat.rotate(e*r,t*r,n*r)},wt.mat.rotate=function(e,t,n){var r=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],i=e,s=t,a=n,o=Math.cos(i),A=Math.cos(s),c=Math.cos(a),l=Math.sin(i),u=Math.sin(s),h=Math.sin(a);return r[0]=A*c,r[1]=-A*h,r[2]=u,r[4]=o*h+l*u*c,r[5]=o*c-l*u*h,r[6]=-l*A,r[8]=l*h-o*u*c,r[9]=l*c+o*u*h,r[10]=o*A,r},wt.edit={},wt.edit.interpolate=function(e,t,n,r){for(var i=0;i<e.length;i++)n[i]=e[i]+r*(t[i]-e[i])},wt.edit.transform=function(e,t){for(var n=0;n<e.length;n+=3){var r=e[n],i=e[n+1],s=e[n+2];e[n+0]=t[0]*r+t[4]*i+t[8]*s+t[12],e[n+1]=t[1]*r+t[5]*i+t[9]*s+t[13],e[n+2]=t[2]*r+t[6]*i+t[10]*s+t[14]}},wt.edit.unwrap=function(e,t,n){for(var r=new Array(Math.floor(e.length/3)*n),i=0;i<e.length;i++)for(var s=0;s<n;s++)r[i*n+s]=t[e[i]*n+s];return r},wt.edit.remap=function(e,t,n,r){for(var i=new Array(n.length),s=0;s<e.length;s++)for(var a=0;a<r;a++)i[t[s]*r+a]=n[e[s]*r+a];return i},wt.utils={},wt.utils.getAABB=function(e){var t,n,r,i,s,a;i=s=a=-(t=n=r=999999999);for(var o=0;o<e.length;o+=3){var A=e[o+0],c=e[o+1],l=e[o+2];A<t&&(t=A),A>i&&(i=A),c<n&&(n=c),c>s&&(s=c),l<r&&(r=l),c>a&&(a=l)}return{min:{x:t,y:n,z:r},max:{x:i,y:s,z:a}}};var Pt={" ":{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]]}};function St(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.origin||[0,0,0],n=t[0],r=t[1],i=t[2],s=e.size||1,a=[],o=[],A=e.text;ge.isNumeric(A)&&(A=""+A);for(var c,l,u,h,d,f,p,v,g,m=(A||"").split("\n"),y=0,_=0,b=.04,w=0;w<m.length;w++){c=0,u=(l=m[w]).length;for(var B=0;B<u;B++)if(h=Pt[l.charAt(B)]){d=1,f=-1,p=-1,v=h.points.length;for(var C=0;C<v;C++)-1!==(g=h.points[C])[0]||-1!==g[1]?(a.push(c+g[0]*s*b+n),a.push(_+g[1]*s*b+r),a.push(0+i),-1===f?f=y:(-1===p||(f=p),p=y),y++,d?d=!1:(o.push(f),o.push(p))):d=1;c+=h.width*b*s}_-=35*b*s}return ge.apply(e,{primitive:"lines",positions:a,indices:o})}function Dt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e.points.length%3!=0)throw"Size of points array for given polyline should be divisible by 3";var t=e.points.length/3;if(t<2)throw"There should be at least 2 points to create a polyline";for(var n=[],r=0;r<t-1;r++)n.push(r),n.push(r+1);return ge.apply(e,{primitive:"lines",positions:e.points,indices:n})}function Qt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.curve.getPoints(e.divisions).map((function(e){return p(e)})).flat();return Dt({id:e.id,points:t})}function Rt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(3!==e.startPoint.length)throw"Start point should contain 3 elements in array: x, y and z";if(3!==e.endPoint.length)throw"End point should contain 3 elements in array: x, y and z";var t=[],n=[],r=e.startPoint[0],i=e.startPoint[1],s=e.startPoint[2],a=e.endPoint[0],o=e.endPoint[1],A=e.endPoint[2],c=Math.sqrt(Math.pow(a-r,2)+Math.pow(o-i,2)+Math.pow(A-s,2)),l=[(a-r)/c,(o-i)/c,(A-s)/c];if(e.pattern){var u=e.pattern.length,h=!1,d=0,f=0,p=0,v=[r,i,s],g=e.pattern[f];for(n.push(v[0],v[1],v[2]);g<=c-d;){var m=[l[0]*g,l[1]*g,l[2]*g],y=[v[0]+m[0],v[1]+m[1],v[2]+m[2]];n.push(y[0],y[1],y[2]),h||(t.push(p),t.push(p+1)),h=!h,p+=1,v=y,(f+=1)>=u&&(f=0),d+=g,g=e.pattern[f]}e.extendToEnd&&(n.push(a,o,A),t.push(t.length-2),t.push(t.length-1))}else t.push(0),t.push(1),n.push(r,i,s,a,o,A);return ge.apply(e,{primitive:"lines",positions:n,indices:t})}var Ot=Ae.vec4(4),Vt=Ae.vec4(),Lt=Ae.vec4(),Ht=Ae.vec3([1,0,0]),Nt=Ae.vec3([0,1,0]),Gt=Ae.vec3([0,0,1]),jt=Ae.vec3(3),Wt=Ae.vec3(3),zt=Ae.identityMat4(),Xt=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,n),(r=t.call(this,e,i))._parentNode=null,r._children=[],r._aabb=null,r._aabbDirty=!0,r.scene._aabbDirty=!0,r._numTriangles=0,r._scale=Ae.vec3(),r._quaternion=Ae.identityQuaternion(),r._rotation=Ae.vec3(),r._position=Ae.vec3(),r._offset=Ae.vec3(),r._localMatrix=Ae.identityMat4(),r._worldMatrix=Ae.identityMat4(),r._localMatrixDirty=!0,r._worldMatrixDirty=!0,i.matrix?r.matrix=i.matrix:(r.scale=i.scale,r.position=i.position,i.quaternion||(r.rotation=i.rotation)),r._isModel=i.isModel,r._isModel&&r.scene._registerModel(w(r)),r._isObject=i.isObject,r._isObject&&r.scene._registerObject(w(r)),r.origin=i.origin,r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.colorize=i.colorize,r.opacity=i.opacity,r.offset=i.offset,i.children)for(var s=i.children,a=0,o=s.length;a<o;a++)r.addChild(s[a],i.inheritStates);if(i.parentId){var A=r.scene.components[i.parentId];A?A.isNode?A.addChild(w(r)):r.error("Parent is not a Node: '"+i.parentId+"'"):r.error("Parent not found: '"+i.parentId+"'")}else i.parent&&(i.parent.isNode||r.error("Parent is not a Node"),i.parent.addChild(w(r)));return r}return I(n,[{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return this._isObject}},{key:"aabb",get:function(){return this._aabbDirty&&this._updateAABB(),this._aabb}},{key:"origin",get:function(){return this._origin},set:function(e){e?(this._origin||(this._origin=Ae.vec3()),this._origin.set(e)):this._origin&&(this._origin=null);for(var t=0,n=this._children.length;t<n;t++)this._children[t].origin=e;this.glRedraw()}},{key:"rtcCenter",get:function(){return this.origin},set:function(e){this.origin=e}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"visible",get:function(){return this._visible},set:function(e){e=!1!==e,this._visible=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].visible=e;this._isObject&&this.scene._objectVisibilityUpdated(this,e)}},{key:"xrayed",get:function(){return this._xrayed},set:function(e){e=!!e,this._xrayed=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].xrayed=e;this._isObject&&this.scene._objectXRayedUpdated(this,e)}},{key:"highlighted",get:function(){return this._highlighted},set:function(e){e=!!e,this._highlighted=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].highlighted=e;this._isObject&&this.scene._objectHighlightedUpdated(this,e)}},{key:"selected",get:function(){return this._selected},set:function(e){e=!!e,this._selected=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].selected=e;this._isObject&&this.scene._objectSelectedUpdated(this,e)}},{key:"edges",get:function(){return this._edges},set:function(e){e=!!e,this._edges=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].edges=e}},{key:"culled",get:function(){return this._culled},set:function(e){e=!!e,this._culled=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].culled=e}},{key:"clippable",get:function(){return this._clippable},set:function(e){e=!1!==e,this._clippable=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].clippable=e}},{key:"collidable",get:function(){return this._collidable},set:function(e){e=!1!==e,this._collidable=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].collidable=e}},{key:"pickable",get:function(){return this._pickable},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].pickable=e}},{key:"colorize",get:function(){return this._colorize.slice(0,3)},set:function(e){var t=this._colorize;t||((t=this._colorize=new Float32Array(4))[3]=1),e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1);for(var n=0,r=this._children.length;n<r;n++)this._children[n].colorize=t;if(this._isObject){var i=!!e;this.scene._objectColorizeUpdated(this,i)}}},{key:"opacity",get:function(){return this._colorize[3]},set:function(e){var t=this._colorize;t||((t=this._colorize=new Float32Array(4))[0]=1,t[1]=1,t[2]=1),t[3]=null!=e?e:1;for(var n=0,r=this._children.length;n<r;n++)this._children[n].opacity=e;if(this._isObject){var i=null!=e;this.scene._objectOpacityUpdated(this,i)}}},{key:"castsShadow",get:function(){return this._castsShadow},set:function(e){e=!!e,this._castsShadow=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].castsShadow=e}},{key:"receivesShadow",get:function(){return this._receivesShadow},set:function(e){e=!!e,this._receivesShadow=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].receivesShadow=e}},{key:"saoEnabled",get:function(){return!1}},{key:"offset",get:function(){return this._offset},set:function(e){e?(this._offset[0]=e[0],this._offset[1]=e[1],this._offset[2]=e[2]):(this._offset[0]=0,this._offset[1]=0,this._offset[2]=0);for(var t=0,n=this._children.length;t<n;t++)this._children[t].offset=this._offset;this._isObject&&this.scene._objectOffsetUpdated(this,e)}},{key:"isNode",get:function(){return!0}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}},{key:"_setWorldMatrixDirty",value:function(){this._worldMatrixDirty=!0;for(var e=0,t=this._children.length;e<t;e++)this._children[e]._setWorldMatrixDirty()}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentNode)Ae.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(var t=0,n=e.length;t<n;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}},{key:"_setSubtreeAABBsDirty",value:function(e){if(e._aabbDirty=!0,e._children)for(var t=0,n=e._children.length;t<n;t++)this._setSubtreeAABBsDirty(e._children[t])}},{key:"_setAABBDirty",value:function(){if(this._setSubtreeAABBsDirty(this),this.collidable)for(var e=this;e;e=e._parentNode)e._aabbDirty=!0}},{key:"_updateAABB",value:function(){if(this.scene._aabbDirty=!0,this._aabb||(this._aabb=Ae.AABB3()),this._buildAABB)this._buildAABB(this.worldMatrix,this._aabb);else{var e;Ae.collapseAABB3(this._aabb);for(var t=0,n=this._children.length;t<n;t++)(e=this._children[t]).collidable&&Ae.expandAABB3(this._aabb,e.aabb)}this._aabbDirty=!1}},{key:"addChild",value:function(e,t){if(ge.isNumeric(e)||ge.isString(e)){var n=e;if(!(e=this.scene.component[n]))return void this.warn("Component not found: "+ge.inQuotes(n));if(!e.isNode&&!e.isMesh)return void this.error("Not a Node or Mesh: "+n)}else{if(!e.isNode&&!e.isMesh)return void this.error("Not a Node or Mesh: "+e.id);if(e._parentNode){if(e._parentNode.id===this.id)return void this.warn("Already a child: "+e.id);e._parentNode.removeChild(e)}}if(e.id,e.scene.id===this.scene.id)return this._children.push(e),e._parentNode=this,t&&(e.visible=this.visible,e.culled=this.culled,e.xrayed=this.xrayed,e.highlited=this.highlighted,e.selected=this.selected,e.edges=this.edges,e.clippable=this.clippable,e.pickable=this.pickable,e.collidable=this.collidable,e.castsShadow=this.castsShadow,e.receivesShadow=this.receivesShadow,e.colorize=this.colorize,e.opacity=this.opacity,e.offset=this.offset),e._setWorldMatrixDirty(),e._setAABBDirty(),this._numTriangles+=e.numTriangles,e;this.error("Child not in same Scene: "+e.id)}},{key:"removeChild",value:function(e){for(var t=0,n=this._children.length;t<n;t++)if(this._children[t].id===e.id)return e._parentNode=null,this._children=this._children.splice(t,1),e._setWorldMatrixDirty(),e._setAABBDirty(),this._setAABBDirty(),void(this._numTriangles-=e.numTriangles)}},{key:"removeChildren",value:function(){for(var e,t=0,n=this._children.length;t<n;t++)(e=this._children[t])._parentNode=null,e._setWorldMatrixDirty(),e._setAABBDirty(),this._numTriangles-=e.numTriangles;this._children=[],this._setAABBDirty()}},{key:"numChildren",get:function(){return this._children.length}},{key:"children",get:function(){return this._children}},{key:"parent",get:function(){return this._parentNode},set:function(e){if(ge.isNumeric(e)||ge.isString(e)){var t=e;if(!(e=this.scene.components[t]))return void this.warn("Node not found: "+ge.inQuotes(t));if(!e.isNode)return void this.error("Not a Node: "+e.id)}e.scene.id===this.scene.id?this._parentNode&&this._parentNode.id===e.id?this.warn("Already a child of Node: "+e.id):e.addChild(this):this.error("Node not in same Scene: "+e.id)}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),Ae.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),Ae.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"matrix",get:function(){return this._localMatrixDirty&&(this._localMatrix||(this._localMatrix=Ae.identityMat4()),Ae.composeMat4(this._position,this._quaternion,this._scale,this._localMatrix),this._localMatrixDirty=!1),this._localMatrix},set:function(e){this._localMatrix||(this._localMatrix=Ae.identityMat4()),this._localMatrix.set(e||zt),Ae.decomposeMat4(this._localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._setWorldMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"rotate",value:function(e,t){return Ot[0]=e[0],Ot[1]=e[1],Ot[2]=e[2],Ot[3]=t*Ae.DEGTORAD,Ae.angleAxisToQuaternion(Ot,Vt),Ae.mulQuaternions(this.quaternion,Vt,Lt),this.quaternion=Lt,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"rotateOnWorldAxis",value:function(e,t){return Ot[0]=e[0],Ot[1]=e[1],Ot[2]=e[2],Ot[3]=t*Ae.DEGTORAD,Ae.angleAxisToQuaternion(Ot,Vt),Ae.mulQuaternions(Vt,this.quaternion,Vt),this}},{key:"rotateX",value:function(e){return this.rotate(Ht,e)}},{key:"rotateY",value:function(e){return this.rotate(Nt,e)}},{key:"rotateZ",value:function(e){return this.rotate(Gt,e)}},{key:"translate",value:function(e,t){return Ae.vec3ApplyQuaternion(this.quaternion,e,jt),Ae.mulVec3Scalar(jt,t,Wt),Ae.addVec3(this.position,Wt,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"translateX",value:function(e){return this.translate(Ht,e)}},{key:"translateY",value:function(e){return this.translate(Nt,e)}},{key:"translateZ",value:function(e){return this.translate(Gt,e)}},{key:"type",get:function(){return"Node"}},{key:"destroy",value:function(){if(v(C(n.prototype),"destroy",this).call(this),this._parentNode&&this._parentNode.removeChild(this),this._isObject&&(this.scene._deregisterObject(this),this._visible&&this.scene._objectVisibilityUpdated(this,!1,!1),this._xrayed&&this.scene._objectXRayedUpdated(this,!1,!1),this._selected&&this.scene._objectSelectedUpdated(this,!1,!1),this._highlighted&&this.scene._objectHighlightedUpdated(this,!1,!1),this.scene._objectColorizeUpdated(this,!1),this.scene._objectOpacityUpdated(this,!1),this.offset.some((function(e){return 0!==e}))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this._children.length)for(var e=this._children.splice(0),t=0,r=e.length;t<r;t++)e[t].destroy();this._children=[],this._setAABBDirty(),this.scene._aabbDirty=!0}}]),n}(),Kt=Ae.vec3(),Zt=function(){var e=new Float64Array(16),t=new Float64Array(4),n=new Float64Array(4);return function(r,i,s){return s=s||e,t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,Ae.transformVec4(r,t,n),Ae.setMat4Translation(r,n,s),s.slice()}}();function Jt(e,t,n){var r=Float32Array.from([e[0]])[0],i=e[0]-r,s=Float32Array.from([e[1]])[0],a=e[1]-s,o=Float32Array.from([e[2]])[0],A=e[2]-o;t[0]=r,t[1]=s,t[2]=o,n[0]=i,n[1]=a,n[2]=A}function Yt(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1e3,i=Ae.getPositionsCenter(e,Kt),s=Math.round(i[0]/r)*r,a=Math.round(i[1]/r)*r,o=Math.round(i[2]/r)*r;n[0]=s,n[1]=a,n[2]=o;var A=0!==n[0]||0!==n[1]||0!==n[2];if(A)for(var c=0,l=e.length;c<l;c+=3)t[c+0]=e[c+0]-s,t[c+1]=e[c+1]-a,t[c+2]=e[c+2]-o;return A}var qt=1e3,$t=1001,en=1002,tn=1003,nn=1004,rn=1004,sn=1005,an=1005,on=1006,An=1007,cn=1007,ln=1008,un=1008,hn=1009,dn=1010,fn=1011,pn=1012,vn=1013,gn=1014,mn=1015,yn=1016,_n=1017,bn=1018,wn=1020,Bn=1021,Cn=1022,Mn=1023,kn=1024,En=1025,Fn=1026,xn=1027,Un=1028,In=1029,Tn=1030,Pn=1031,Sn=1033,Dn=33776,Qn=33777,Rn=33778,On=33779,Vn=35840,Ln=35841,Hn=35842,Nn=35843,Gn=36196,jn=37492,Wn=37496,zn=37808,Xn=37809,Kn=37810,Zn=37811,Jn=37812,Yn=37813,qn=37814,$n=37815,er=37816,tr=37817,nr=37818,rr=37819,ir=37820,sr=37821,ar=36492,or=3e3,Ar=3001,cr=1e4,lr=10001,ur=10002,hr=10003,dr=new Z({}),fr=Ae.vec3(),pr=Ae.vec4(),vr=f({},3001,"sRGBToLinear"),gr=function(){var e=this,t=[],n=[],r=[],i=[],s=[],a=[],o=[],A=function(e,n){var r=!1;return t.push((function(t){return r&&n(e,t)})),{toString:function(){return r=!0,e}}},c={createAttribute:function(e,n){var r=!1;t.push((function(t){return r&&t.push("in ".concat(e," ").concat(n,";"))}));var i={toString:function(){return r=!0,n}};return s.push((function(e){var t=r&&e(n);return t&&a.push(t.attributeHash),i.setInputValue=t,null})),i},createFragmentDefinition:function(e,t){var n=!1;return i.push((function(r){return n&&t(e,r)})),{toString:function(){return n=!0,e}}},createOutput:function(e,t,n){var i=!1;return r.push((function(r){return i&&r.push("layout(location = ".concat(n||0,") out ").concat(e," ").concat(t,";"))})),{toString:function(){return i=!0,t}}},createUniform:function(e,n,i){var s=!1,a=function(t){return s&&t.push("uniform ".concat(e," ").concat(n,";"))};t.push(a),r.push(a);var A={toString:function(){return s=!0,n}};return o.push((function(e){var t=s&&e(n);return i?t&&function(e){return i(t,e)}:(A.setInputValue=t,null)})),A},createUniformArray:function(e,n,i){var s=!1,a=function(t){return s&&t.push("uniform ".concat(e," ").concat(n,"[").concat(i,"];"))};t.push(a),r.push(a);var A={toString:function(){return s=!0,n}};return o.push((function(e){return A.setInputValue=s&&e(n),null})),A},createUniformBlock:function(e,n,i){var s=!1,a=Object.keys(n),A=function(t){s&&(t.push("uniform ".concat(e," {")),a.forEach((function(e){return t.push(" ".concat(n[e]," ").concat(e,";"))})),t.push("};"))};t.push(A),r.push(A);var c={};return a.forEach((function(e){return c[e]={toString:function(){return s=!0,e}}})),o.push((function(t){var n=s&&t(e);return i?n&&function(e){return i(n,e)}:(c.setInputValue=n,null)})),c},createVarying:function(e,i,s,a){var o=!1,A=a?a+" ":"";return t.push((function(t){return o&&t.push("".concat(A,"out ").concat(e," ").concat(i,";"))})),n.push((function(e){return o&&e.push("".concat(i," = ").concat(s(),";"))})),r.push((function(t){return o&&t.push("".concat(A,"in ").concat(e," ").concat(i,";"))})),{toString:function(){return o=!0,i}}},createVertexDefinition:A,commonLibrary:{octDecode:A("octDecode",(function(e,t){t.push("vec3 ".concat(e,"(vec2 oct) {")),t.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),t.push(" if (v.z < 0.0) {"),t.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);"),t.push(" }"),t.push(" return normalize(v);"),t.push("}")}))}};return{programVariables:c,buildProgram:function(A,l,u){var h,d,f=u.getLogDepth,v=u.clipPos,g=u.usePickClipPos&&(h=c.createUniform("vec2","pickClipPos"),d=c.createUniform("vec2","pickClipPosInv"),{setClipPosInputValue:function(e){h.setInputValue(e.pickClipPos),d.setInputValue(e.pickClipPosInv)},transformedClipPos:function(){return"vec4((".concat(v,".xy / ").concat(v,".w - ").concat(h,") * ").concat(d," * ").concat(v,".w, ").concat(v,".zw)")}}),m=g?g.transformedClipPos():v,y=[],_=c.createVarying("float","isPerspective",(function(){return"(".concat(u.projMatrix,"[2][3] == -1.0) ? 1.0 : 0.0")})),b=c.createUniform("float","logDepthBufFC",(function(e,t){return e(2/(Math.log(t.view.far+1)/Math.LN2))})),w=c.createVarying("float","vFragDepth",(function(){return"1.0 + clipPos.w"}));f?y.push("gl_FragDepth = ".concat(u.testPerspectiveForGl_FragDepth?"".concat(_," == 0.0 ? gl_FragCoord.z : "):"","log2(").concat(f(w),") * ").concat(b," * 0.5;")):u.cleanerEdges&&y.push("gl_FragDepth = gl_FragCoord.z + length(vec2(dFdx(gl_FragCoord.z), dFdy(gl_FragCoord.z)));");var B,C,M=c.createFragmentDefinition("linearToGamma",(function(e,t){t.push("vec4 ".concat(e,"(in vec4 value, in float gammaFactor) {")),t.push(" return vec4(pow(value.xyz, vec3(1.0 / gammaFactor)), value.w);"),t.push("}")})),E=u.sectionPlanesState,F=E&&(B=function(e){for(var t=[],n=0;n<e;++n)t.push(n);return t}(E.getNumAllocatedSectionPlanes()).map((function(e){var t=function(t,n,r){return c.createUniform(t,"sectionPlane".concat(n).concat(e),(function(t,n){var i=E.sectionPlanes,s=i.length,a=(n.mesh.layerIndex||0)*s,o=e<s&&n.mesh.renderFlags.sectionPlanesActivePerLayer[a+e];return r(t,o,i[e],n.mesh.origin)}))};return{act:t("bool","Active",(function(e,t){return e(t?1:0)})),dir:t("vec3","Dir",(function(e,t,n){return t&&e(n.dir)})),pos:t("vec3","Pos",(function(e,t,n,r){return t&&e(r?Ae.mulVec3Scalar(Ae.normalizeVec3(n.dir,fr),-(Ae.dotVec3(n.dir,r)+n.dist),fr):n.pos)}))}})),B.length>0&&function(e){return B.map((function(t){return"(".concat(t.act," ? clamp(dot(-").concat(t.dir,", ").concat(e," - ").concat(t.pos,"), 0.0, 1000.0) : 0.0)")})).join(" + ")}),x=u.crossSections,U=F?(C=c.createUniform("vec4","sliceColor",(function(e){return e(x.sliceColor)})),function e(t){return e.needed=!0,"(sliced ? ".concat(C," : ").concat(t,")")}):function(e){return e},I=u.getGammaFactor,T=c.createUniform("float","gammaFactor",(function(e){return e(I())}));u.appendFragmentOutputs(y,I&&function(e){return"".concat(M,"(").concat(e,", ").concat(T,")")},"gl_FragCoord",U);var P,S=function(){var e=[],t=c.createUniform("float","sliceThickness",(function(e){return e(x.sliceThickness)}));if(F){U.needed&&e.push(" bool sliced = false;"),e.push(" if (".concat(u.clippableTest(),") {"));var n=c.createVarying("highp vec3","vHighpWorldPosition",(function(){return"".concat(u.worldPositionAttribute,".xyz")}));if(e.push(" float dist = ".concat(F(n),";")),u.clippingCaps){var r=c.createVarying("float","vClipPositionW",(function(){return"gl_Position.w"}));e.push(" if (dist > (0.002 * ".concat(r,")) { discard; }")),e.push(" if (dist > 0.0) { "),e.push(" ".concat(u.clippingCaps," = vec4(1.0, 0.0, 0.0, 1.0);")),f&&e.push(" gl_FragDepth = log2(".concat(f(w),") * ").concat(b," * 0.5;")),e.push(" return;"),e.push(" }")}else e.push(" if (dist > ".concat(U.needed?t:"0.0",") { discard; }"));U.needed&&e.push(" sliced = dist > 0.0;"),e.push(" }")}return e}(),D=(P=[],i.forEach((function(e){return e(P)})),P),Q=[].concat(p(function(){var e=[];return r.forEach((function(t){return t(e)})),e}()),p(D),["void main(void) {"],p(u.discardPoints?[" vec2 cxy = 2.0 * gl_PointCoord - 1.0;"," if (dot(cxy, cxy) > 1.0) { discard; }"]:[]),p(S),y,["}"]),R=["gl_Position = ".concat(m,";")].concat(p(u.getPointSize?["gl_PointSize = ".concat(u.getPointSize(),";")]:[]),p(function(){var e=[];return n.forEach((function(t){return t(e)})),e}())),O=u.getVertexData?u.getVertexData():[],V=[].concat(p(function(){var e=[];return t.forEach((function(t){return t(e)})),e}()),["void main(void) {"],p(O),p(R),["}"]),L=function(e){return["#version 300 es","// "+l+" "+e+" 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"]},H=L("vertex").concat(V),N=L("fragment").concat(["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(Q),G=function(e,t){var n=t.join("\n"),r=A.createShader(e);return A.shaderSource(r,n),A.compileShader(r),A.getShaderParameter(r,A.COMPILE_STATUS)?[r]:[null,["Failed to compile",A.getShaderInfoLog(r),n.split("\n").map((function(e,t){return t+1+": "+e+"\n"})).join("")]]},j=k(G(A.VERTEX_SHADER,H),2),W=j[0],z=j[1],X=k(G(A.FRAGMENT_SHADER,N),2),K=X[0],Z=X[1],J=function(e){return console.error(e.join("\n")),[null,e]};if(z)return J(["Vertex shader error"].concat(z));if(Z)return J(["Fragment shader error"].concat(Z));var Y=A.createProgram();if(Y){if(A.attachShader(Y,W),A.attachShader(Y,K),A.linkProgram(Y),A.getProgramParameter(Y,A.LINK_STATUS)){var q=_r(A,Y);s.forEach((function(e){return e(q)}));var $=o.map((function(e){return e(q)})).filter((function(e){return e})),ee=dr.addItem({});return[{id:ee,bind:function(){return A.useProgram(Y)},inputSetters:{attributesHash:a.sort().join(", "),setUniforms:function(e,t){g&&g.setClipPosInputValue(e),$.forEach((function(e){return e(t)}))}},destroy:function(){dr.removeItem(ee),A.deleteProgram(Y),A.deleteShader(W),A.deleteShader(K)}}]}return J(["",A.getProgramInfoLog(e.program),"","Vertex shader:",""].concat(p(H),["","Fragment shader:",""],p(N)))}return J(["Failed to allocate program"])}}},mr=function(e,t){var n=e.createUniform("vec4","lightAmbient",(function(e){return e(t.getAmbientColorAndIntensity())})),r=t.lights,i=r.map((function(t,n){var i={color:e.createUniform("vec4","lightColor".concat(n),(function(e){var t=r[n];pr[0]=t.color[0],pr[1]=t.color[1],pr[2]=t.color[2],pr[3]=t.intensity,e(pr)})),position:e.createUniform("vec3","lightPos".concat(n),(function(e){return e(r[n].pos)})),direction:e.createUniform("vec3","lightDir".concat(n),(function(e){return e(r[n].dir)})),shadowProjMatrix:e.createUniform("mat4","shadowProjMatrix".concat(n),(function(e){return e(r[n].getShadowViewMatrix())})),shadowViewMatrix:e.createUniform("mat4","shadowViewMatrix".concat(n),(function(e){return e(r[n].getShadowViewMatrix())})),shadowMap:e.createUniform("sampler2D","shadowMap".concat(n),(function(e){return e(r[n].getShadowRenderBuf().colorTextures[0])}))},s=function(e){return{glslLight:{isWorldSpace:"world"===t.space,getColor:function(){return"".concat(i.color,".rgb * ").concat(i.color,".a")},getDirection:function(t,n){return"normalize(".concat(e(t,n),")")},shadowParameters:t.castsShadow&&{getShadowProjMatrix:function(){return i.shadowProjMatrix},getShadowViewMatrix:function(){return i.shadowViewMatrix},getShadowMap:function(){return i.shadowMap}}},setupLightsInputs:function(){var e=Object.values(i).map((function(e){return e.setupLightsInputs()})).filter((function(e){return e}));return function(){return e.forEach((function(e){return e()}))}}}};return"dir"===t.type?"view"===t.space?s((function(e,t){return"-".concat(i.direction)})):s((function(e,t){return"-(".concat(e," * vec4(").concat(i.direction,", 0.0)).xyz")})):"point"===t.type?"view"===t.space?s((function(e,t){return"".concat(i.position," - ").concat(t)})):s((function(e,t){return"(".concat(e," * vec4(").concat(i.position,", 1.0)).xyz - ").concat(t)})):null})).filter((function(e){return e})),s=function(t,n){var r=function(){var e=n();return e.length>0&&e[0]},i=r();return i&&yr(e,"samplerCube",t,i.encoding,(function(e){var t=r();t&&e(t.texture)}))},a=s("light",(function(){return t.lightMaps})),o=s("reflection",(function(){return t.reflectionMaps}));return{getHash:function(){return t.getHash()},getAmbientColor:function(){return"".concat(n,".rgb * ").concat(n,".a")},directionalLights:i.map((function(e){return e.glslLight})),getIrradiance:a&&function(e){return"".concat(a(e),".rgb")},getReflection:o&&function(e,t){return"".concat(o(e,t),".rgb")}}},yr=function(e,t,n,r,i){var s=e.createUniform(t,n+"Map",i);return function(e,t){var n=t?"texture(".concat(s,", ").concat(e,", ").concat(t,")"):"texture(".concat(s,", ").concat(e,")");return 3e3!==r?"".concat(vr[r],"(").concat(n,")"):n}},_r=function(e,t){for(var n={},r=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES),i=function(i){var s=e.getActiveAttrib(t,i),a=e.getAttribLocation(t,s.name);n[s.name]=function(t){t.bindAtLocation(a),e.enableVertexAttribArray(a);var n=t.attributeDivisor;n&&e.vertexAttribDivisor(a,n)},n[s.name].attributeHash="".concat(a.toString().padStart(1+Math.floor(Math.log10(r)),"0"),":").concat(s.name)},s=0;s<r;++s)i(s);for(var a=e.getProgramParameter(t,e.ACTIVE_UNIFORM_BLOCKS),o=function(r){var i=e.getActiveUniformBlockName(t,r),s=e.getUniformBlockIndex(t,i),a=r;e.uniformBlockBinding(t,s,a);var o=e.createBuffer();n[i]=function(t){e.bindBuffer(e.UNIFORM_BUFFER,o),e.bufferData(e.UNIFORM_BUFFER,t,e.DYNAMIC_DRAW),e.bindBufferBase(e.UNIFORM_BUFFER,a,o)}},A=0;A<a;++A)o(A);for(var c=e.getProgramParameter(t,e.ACTIVE_UNIFORMS),l=0,u=function(r){var i=e.getActiveUniform(t,r),s=i.name;s.endsWith("[0]")&&(s=s.substr(0,s.length-3)),"\0"===s[s.length-1]&&(s=s.substr(0,s.length-1));var a=e.getUniformLocation(t,s);if(function(){for(var t in e)if(i.type===e[t])return t}(),i.type===e.SAMPLER_2D||i.type===e.SAMPLER_CUBE||i.type===e.SAMPLER_2D_SHADOW||e instanceof window.WebGL2RenderingContext&&(i.type===e.UNSIGNED_INT_SAMPLER_2D||i.type===e.INT_SAMPLER_2D)){var o=l++;n[s]=function(t){var n=t.bind(o);return n&&e.uniform1i(a,o),n}}else n[s]=function(){if(1===i.size)switch(i.type){case e.BOOL:case e.INT:return function(t){return e.uniform1i(a,t)};case e.FLOAT:return function(t){return e.uniform1f(a,t)};case e.FLOAT_VEC2:return function(t){return e.uniform2fv(a,t)};case e.FLOAT_VEC3:return function(t){return e.uniform3fv(a,t)};case e.FLOAT_VEC4:return function(t){return e.uniform4fv(a,t)};case e.FLOAT_MAT3:return function(t){return e.uniformMatrix3fv(a,!1,t)};case e.FLOAT_MAT4:return function(t){return e.uniformMatrix4fv(a,!1,t)}}else if(i.size>1)switch(i.type){case e.FLOAT:return function(t){return e.uniform1fv(a,t)};case e.FLOAT_VEC2:return function(t){return e.uniform2fv(a,t)};case e.FLOAT_VEC3:return function(t){return e.uniform3fv(a,t)};case e.FLOAT_VEC4:return function(t){return e.uniform4fv(a,t)}}throw"Unhandled uniform ".concat(s)}()},h=0;h<c;++h)u(h);return function(e){var t=n[e];if(!t)throw'Missing input "'.concat(e,'"');return t}},br=Ae.vec4(),wr=function(e,t,n,r,i){var s=r._state,a="PhongMaterial"===s.type,o="MetallicMaterial"===s.type,A="SpecularMaterial"===s.type,c=n.attributes,l=mr(t,i._lightsState),u=t.createUniform("vec4","colorize",(function(e,t){return e(t.meshColorize)})),h=t.createFragmentDefinition("fresnel",(function(e,t){t.push("float ".concat(e,"(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {")),t.push(" float fr = abs(dot(eyeDir, normal));"),t.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),t.push(" return pow(finalFr, power);"),t.push("}")})),d=function(e,n,i){var s=function(n,r,s){return t.createUniform(n,e+"Fresnel"+r,(function(e,t){return e(s(i(t.material)))}))},a=s("float","EdgeBias",(function(e){return e.edgeBias})),o=s("float","CenterBias",(function(e){return e.centerBias})),A=s("float","Power",(function(e){return e.power})),c=s("vec3","EdgeColor",(function(e){return e.edgeColor})),l=s("vec3","CenterColor",(function(e){return e.centerColor}));return i(r)&&function(e,t){var r="".concat(h,"(").concat(e,", ").concat(t,", ").concat(a,", ").concat(o,", ").concat(A,")");return"mix(".concat(c+n,", ").concat(l+n,", ").concat(r,")")}},f=d("diffuse","",(function(e){return e._diffuseFresnel})),p=d("specular","",(function(e){return e._specularFresnel})),v=d("emissive","",(function(e){return e._emissiveFresnel})),g=d("alpha",".r",(function(e){return e._alphaFresnel})),m=function(e,n){var i=c.uv&&n(r),s=i&&yr(t,"sampler2D",e,i.encoding,(function(e,t){return e(n(t.material)._state.texture)}));return s&&function(){var r=i._state.matrix&&t.createUniform("mat4",e+"MapMatrix",(function(e,t){return e(n(t.material)._state.matrix)})),a=r?function(e){return"(".concat(r," * ").concat(e,").st")}:function(e){return"".concat(e,".st")},o=function(e,t){return s(a(e))};return o.getTexCoordExpression=a,o}()},y=m("ambient",(function(e){return e._ambientMap})),_=m("baseColor",(function(e){return e._baseColorMap})),b=m("diffuse",(function(e){return e._diffuseMap})),w=m("emissive",(function(e){return e._emissiveMap})),B=m("occlusion",(function(e){return e._occlusionMap})),C=m("alpha",(function(e){return e._alphaMap})),M=m("metallic",(function(e){return e._metallicMap})),k=m("roughness",(function(e){return e._roughnessMap})),E=m("metallicRoughness",(function(e){return e._metallicRoughnessMap})),F=m("specular",(function(e){return e._specularMap})),x=m("glossiness",(function(e){return e._glossinessMap})),U=m("specularGlossiness",(function(e){return e._specularGlossinessMap})),I=m("normal",(function(e){return e._normalMap})),T=function(e,n,i){var s=i(r);return("float"===n?null!=s:s)&&t.createUniform(n,e,(function(e,t){return e(i(t.material))}))},P=T("materialAmbient","vec3",(function(e){return e.ambient})),S=T("materialDiffuse","vec3",(function(e){return e.diffuse})),D=T("materialBaseColor","vec3",(function(e){return e.baseColor})),Q=T("materialEmissive","vec3",(function(e){return e.emissive})),R=T("materialSpecular","vec3",(function(e){return e.specular})),O=T("materialGlossiness","float",(function(e){return e.glossiness})),V=T("materialMetallic","float",(function(e){return e.metallic})),L=T("materialRoughness","float",(function(e){return e.roughness})),H=T("materialShininess","float",(function(e){return e.shininess})),N=T("materialSpecularF0","float",(function(e){return e.specularF0})),G=T("materialAlphaModeCutoff","vec4",(function(e){var t=e.alpha;return null!=t?(br[0]=t,br[1]=1===e.alphaMode?1:0,br[2]=e.alphaCutoff,br):null})),j=t.createVarying("vec3","vViewPosition",(function(){return"".concat(c.position.view,".xyz")})),W=t.createVarying("vec4","texturePos",(function(){return"vec4(".concat(c.uv,", 1.0, 1.0)")})),z=c.color&&t.createVarying("vec4","vColor",(function(){return c.color})),X=t.createVarying("vec3","vViewNormal",(function(){return c.normal.view})),K=l.directionalLights.map((function(e,r){return{vViewLightReverseDir:t.createVarying("vec3","vViewLightReverseDir".concat(r),(function(){return e.getDirection(n.viewMatrix,null)})),vShadowPosFromLight:t.createVarying("vec3","vShadowPosFromLight".concat(r),(function(){return"(".concat("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)"," * ").concat(e.shadowParameters.getShadowProjMatrix()," * (").concat(e.shadowParameters.getShadowViewMatrix()," * ").concat(c.position.world,")).xyz")}))}})),Z=t.createVarying("vec3","vWorldNormal",(function(){return c.normal.world})),J=t.createOutput("vec4","outColor"),Y=t.createFragmentDefinition("saturate",(function(e,t){return t.push("float ".concat(e,"(const in float a) { return clamp(a, 0.0, 1.0); }"))})),q=t.createFragmentDefinition("BRDF_Specular_GGX",(function(e,t){t.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),t.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),t.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),t.push("}"),t.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" return 1.0 / ( gl * gv );"),t.push("}"),t.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" return 0.5 / max( gv + gl, 1e-6 );"),t.push("}"),t.push("float D_GGX(const in float alpha, const in float dotNH) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),t.push(" return 0.31830988618 * a2 / ( denom * denom);"),t.push("}"),t.push("vec3 ".concat(e,"(const in vec3 incidentLightDirection, const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {")),t.push(" float alpha = ( roughness * roughness );"),t.push(" vec3 halfDir = normalize( incidentLightDirection + viewEyeDir );"),t.push(" float dotNL = ".concat(Y,"( dot( viewNormal, incidentLightDirection ) );")),t.push(" float dotNV = ".concat(Y,"( dot( viewNormal, viewEyeDir ) );")),t.push(" float dotNH = ".concat(Y,"( dot( viewNormal, halfDir ) );")),t.push(" float dotLH = ".concat(Y,"( dot( incidentLightDirection, halfDir ) );")),t.push(" vec3 F = F_Schlick( specularColor, dotLH );"),t.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),t.push(" float D = D_GGX( alpha, dotNH );"),t.push(" return F * (G * D);"),t.push("}")})),$=t.createFragmentDefinition("BRDF_Specular_GGX_Environment",(function(e,t){t.push("vec3 ".concat(e,"(const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {")),t.push(" float dotNV = ".concat(Y,"(dot(viewNormal, viewEyeDir));")),t.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),t.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),t.push(" vec4 r = roughness * c0 + c1;"),t.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),t.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),t.push(" return specularColor * AB.x + AB.y;"),t.push("}")})),ee=t.createFragmentDefinition("perturbNormal2Arb",(function(e,t){t.push("vec3 ".concat(e,"( vec3 eye_pos, vec3 surf_norm, vec2 uv, vec4 texel ) {")),t.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),t.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),t.push(" vec2 st0 = dFdx( uv.st );"),t.push(" vec2 st1 = dFdy( uv.st );"),t.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),t.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),t.push(" vec3 N = normalize( surf_norm );"),t.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),t.push(" mat3 tsn = mat3( S, T, N );"),t.push(" return normalize( tsn * mapN );"),t.push("}")}));return{getHash:function(){return[e,i.gammaOutput?"go":"",l.getHash(),r._state.hash]},programName:"Draw",canActAsBackground:!0,discardPoints:!0,setupPointSize:!0,setsLineWidth:!0,appendFragmentOutputs:function(e,t,r){var i,s,h,d,m=c.normal&&(l.directionalLights.length>0||l.getIrradiance||l.getReflection);if(e.push("vec3 diffuseColor = ".concat(m&&(a||A)&&S||o&&D||"vec3(1.0)",";")),e.push("vec4 alphaModeCutoff = ".concat((a||o||A)&&G||"vec4(1.0, 0.0, 0.0, 0.0)",";")),e.push("float alpha = alphaModeCutoff[0];"),(a||o||A)&&C&&e.push("alpha *= ".concat(C(W),".r;")),z&&(e.push("diffuseColor *= ".concat(z,".rgb;")),e.push("alpha *= ".concat(z,".a;"))),o&&_&&(e.push("vec4 baseColorTexel = "+_(W)+";"),e.push("diffuseColor *= baseColorTexel.rgb;"),e.push("alpha *= baseColorTexel.a;")),(a||A)&&b&&(e.push("vec4 diffuseTexel = "+b(W)+";"),e.push("diffuseColor *= diffuseTexel.rgb;"),e.push("alpha *= diffuseTexel.a;")),e.push("vec3 emissiveColor = ".concat((a||o||A)&&Q||"vec3(0.0)",";")),(a||o||A)&&w&&e.push("emissiveColor = ".concat(w(W),".rgb;")),m){e.push("vec3 specular = ".concat((a||A)&&R||"vec3(1.0)",";")),e.push("float glossiness = ".concat(A&&O||"1.0",";")),e.push("float metallic = ".concat(o&&V||"1.0",";")),e.push("float roughness = ".concat((o||A)&&L||"1.0",";")),e.push("float shininess = ".concat(a&&H||"1.0",";")),e.push("float specularF0 = ".concat(o&&N||"1.0",";")),e.push("float occlusion = ".concat((a||o||A)&&B?"".concat(B(W),".r"):"1.0",";")),o&&M&&e.push("metallic *= ".concat(M(W),".r;")),o&&k&&e.push("roughness *= ".concat(k(W),".r;")),o&&E&&(e.push("vec4 metalRoughTexel = "+E(W)+";"),e.push("metallic *= metalRoughTexel.b;"),e.push("roughness *= metalRoughTexel.g;")),(a||A)&&F&&e.push("specular *= ".concat(F(W),".rgb;")),A&&x&&e.push("glossiness *= ".concat(x(W),".r;")),A&&U&&(e.push("vec4 specGlossTexel = "+U(W)+";"),e.push("specular *= specGlossTexel.rgb;"),e.push("glossiness *= specGlossTexel.a;"));var T="normalize(".concat(X,")"),te=(a||o||A)&&I?"".concat(ee,"(").concat(j,", ").concat(T,", ").concat(I.getTexCoordExpression(W),", ").concat(I(W),")"):T;if(e.push("vec3 viewNormal = ".concat(te,";")),e.push("vec3 viewEyeDir = normalize(-".concat(j,");")),f&&e.push("diffuseColor *= ".concat(f("viewEyeDir","viewNormal"),";")),p&&e.push("specular *= ".concat(p("viewEyeDir","viewNormal"),";")),v&&e.push("emissiveColor *= ".concat(v("viewEyeDir","viewNormal"),";")),g&&e.push("alpha *= ".concat(g("viewEyeDir","viewNormal"),";")),e.push("if (alphaModeCutoff[1] == 1.0 && alpha < alphaModeCutoff[2]) {"),e.push(" discard;"),e.push("}"),e.push("vec3 material_diffuseColor;"),a&&(e.push("material_diffuseColor = diffuseColor;"),e.push("roughness = 0.0;")),A&&(e.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),e.push("material_diffuseColor = diffuseColor * oneMinusSpecularStrength;"),e.push("roughness = clamp(1.0 - glossiness, 0.04, 1.0);")),o&&(e.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),e.push("material_diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),e.push("roughness = clamp(roughness, 0.04, 1.0);"),e.push("specular = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),a||o||A){if(e.push("const float PI = 3.14159265359;"),e.push("vec3 reflDiff = vec3(0.0);"),e.push("vec3 reflSpec = vec3(0.0);"),l.getIrradiance&&e.push("reflDiff += ".concat(l.getIrradiance("normalize(".concat(Z,")")),";")),l.getReflection){var ne="reflect(-viewEyeDir, viewNormal)",re=a?"0.2 * PI * ".concat(l.getReflection(ne)):(i="".concat($,"(viewNormal, viewEyeDir, specular, roughness)"),s="normalize((vec4(".concat(ne,", 0.0) * ").concat(n.viewMatrix,").xyz)"),h="".concat("4.0"," - 0.39624 - 0.25 * log2(pow(").concat("2.0 / pow(roughness + 0.0001, 2.0) - 2.0",", 2.0) + 1.0)"),d="clamp(".concat(h,", 0.0, ").concat("4.0",")"),"".concat(i," * ").concat(l.getReflection(s,d)));e.push("reflSpec += ".concat(re,";"))}l.directionalLights.some((function(e){return e.shadowParameters}))&&(e.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));"),e.push("const float texelSize = 1.0 / 1024.0;"),e.push("float shadow;"),e.push("float fragmentDepth;")),l.directionalLights.forEach((function(t,n){if(t.shadowParameters){e.push("fragmentDepth = ".concat(K[n].vShadowPosFromLight,".z - ").concat("0.007",";")),e.push("shadow = 0.0;"),e.push("for (int x = -3; x <= 3; x++) {"),e.push(" for (int y = -3; y <= 3; y++) {"),e.push(" float texelDepth = dot(texture(".concat(t.getShadowMap(),", ").concat(K[n].vShadowPosFromLight,".xy + vec2(x, y) * texelSize), bitShift);")),e.push(" if (fragmentDepth < texelDepth) {"),e.push(" shadow += 1.0;"),e.push(" }"),e.push(" }"),e.push("}"),e.push("shadow /= 9.0;")}e.push("vec3 lightColor".concat(n," = ").concat(t.getColor()).concat(t.shadowParameters?" * shadow":"",";")),e.push("vec3 lightDirection".concat(n," = ").concat(t.isWorldSpace?K[n].vViewLightReverseDir:t.getDirection(null,j),";"));var r="".concat(Y,"(dot(viewNormal, lightDirection").concat(n,"))");e.push("vec3 irradiance".concat(n," = ").concat(r," * lightColor").concat(n,";")),e.push("reflDiff += irradiance".concat(n,";"));var i=a?"lightColor".concat(n," * specular * pow(max(dot(reflect(-lightDirection").concat(n,", -viewNormal), viewEyeDir), 0.0), shininess)"):"irradiance".concat(n," * PI * ").concat(q,"(lightDirection").concat(n,", viewNormal, viewEyeDir, specular, roughness)");e.push("reflSpec += ".concat(i,";"))}))}var ie=a&&"".concat(l.getAmbientColor()," * diffuseColor");e.push("vec3 outgoingLight = emissiveColor + occlusion * (reflDiff * material_diffuseColor + reflSpec)"+(ie?" + "+ie:"")+";")}else e.push("vec3 ambientColor = ".concat(a&&P||"vec3(1.0)",";")),a&&y&&e.push("ambientColor *= ".concat(y(W),".rgb;")),e.push("ambientColor *= ".concat(l.getAmbientColor(),";")),e.push("vec3 outgoingLight = emissiveColor + ambientColor;");e.push("vec4 fragColor = ".concat(u," * vec4(outgoingLight, alpha);")),e.push("".concat(J," = ").concat(t?t("fragColor"):"fragColor",";"))}}},Br=function(e,t,n,r,i){var s=mr(t,i._lightsState),a=t.createUniform("vec4","colorize",(function(e,t){return e(t.meshColorize)})),o=t.createUniform("float","materialAlpha",(function(e,t){return e(t.material.alpha)})),A=t.createUniform("vec3","materialColor",(function(e,t){return e(t.material.color)})),c=t.createUniform("vec3","materialEmissive",(function(e,t){return e(t.material.emissive)})),l=t.createVarying("vec4","vColor",(function(){var e=n.attributes,t=[s.getAmbientColor()].concat(e.normal?s.directionalLights.map((function(t){return"(max(dot(".concat(e.normal.view,", ").concat(t.getDirection(n.viewMatrix,e.position.view),"), 0.0) * ").concat(t.getColor(),")")})):[]);return"".concat(a," * vec4((").concat(t.join(" + "),") * ").concat(A," + ").concat(c,", ").concat(o,");")})),u=t.createOutput("vec4","outColor");return{getHash:function(){return[e,i.gammaOutput?"go":"",s.getHash(),r._state.hash]},programName:"Lambert",canActAsBackground:!0,discardPoints:!0,setupPointSize:!0,setsLineWidth:!0,appendFragmentOutputs:function(e,t){return e.push("".concat(u," = ").concat(t?t(l):l,";"))}}},Cr=function(e,t,n,r,i){var s=i&&mr(t,r._lightsState),a=t.createUniform("vec3","uColor",(function(e,t){return e(i?t.material.fillColor:t.material.edgeColor)})),o=t.createUniform("float","uAlpha",(function(e,t){return e(i?t.material.fillAlpha:t.material.edgeAlpha)})),A=t.createVarying("vec4","vColor",(function(){var e=n.attributes,t=i&&[s.getAmbientColor()].concat(e.normal?s.directionalLights.map((function(t){return"(max(dot(".concat(e.normal.view,", ").concat(t.getDirection(n.viewMatrix,e.position.view),"), 0.0) * ").concat(t.getColor(),")")})):[]);return"vec4(".concat(a).concat(t?" * (".concat(t.join(" + "),")"):"",", ").concat(o,")")})),c=t.createOutput("vec4","outColor");return{getHash:function(){return[e,r.gammaOutput?"go":"",s&&s.getHash()]},programName:i?"EmphasisFill":"EmphasisEdges",dontSetFrontFace:!0,discardPoints:i,drawEdges:!i,appendFragmentOutputs:function(e,t){return e.push("".concat(c," = ").concat(t?t(A):A,";"))}}},Mr=Ae.vec4(),kr=function(e,t){var n=t.createUniform("vec4","pickColor",(function(e,t){var n=t.meshPickID;Mr[0]=255&n,Mr[1]=n>>8&255,Mr[2]=n>>16&255,Mr[3]=n>>24&255,Ae.mulVec4Scalar(Mr,1/255,Mr),e(Mr)})),r=t.createOutput("vec4","outColor");return{getHash:function(){return[e]},programName:"PickMesh",isPick:!0,dontBillboardAnything:!0,appendFragmentOutputs:function(e){return e.push("".concat(r," = ").concat(n,";"))}}},Er=function(e,t,n){var r=t.createVarying("vec4","vColor",(function(){return n.attributes.pickColor})),i=t.createOutput("vec4","outColor");return{getHash:function(){return[e]},programName:"PickTriangle",isPick:!0,trianglePick:!0,dontBillboardAnything:!0,appendFragmentOutputs:function(e){return e.push("".concat(i," = ").concat(r,";"))}}},Fr=function(e,t){var n=t.createOutput("vec4","outColor");return{getHash:function(){return[e]},programName:"Occlusion",skipIfTransparent:!0,appendFragmentOutputs:function(e){return e.push("".concat(n," = vec4(0.0, 0.0, 1.0, 1.0);"))}}},xr=function(e,t){var n=t.createFragmentDefinition("encodeFloat",(function(e,t){t.push("vec4 ".concat(e,"( const in float depth ) {")),t.push(" const vec4 bitShift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);"),t.push(" const vec4 bitMask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);"),t.push(" vec4 comp = fract(depth * bitShift);"),t.push(" comp -= comp.xxyz * bitMask;"),t.push(" return comp;"),t.push("}")})),r=t.createOutput("vec4","outColor");return{getHash:function(){return[e]},programName:"Shadow",setsLineWidth:!0,useShadowView:!0,dontBillboardAnything:!0,dontGetLogDepth:!0,appendFragmentOutputs:function(e,t,i){return e.push("".concat(r," = ").concat(n,"(").concat(i,".z);"))}}},Ur=function(){function e(){x(this,e),this.visibleLayers=[],this.sectionPlanesActivePerLayer=[],this.reset()}return I(e,[{key:"reset",value:function(){this.culled=!1,this.sectioned=!1,this.numLayers=0,this.numVisibleLayers=0,this.colorOpaque=!1,this.colorTransparent=!1,this.edgesOpaque=!1,this.edgesTransparent=!1,this.xrayedSilhouetteOpaque=!1,this.xrayedEdgesOpaque=!1,this.xrayedSilhouetteTransparent=!1,this.xrayedEdgesTransparent=!1,this.highlightedSilhouetteOpaque=!1,this.highlightedEdgesOpaque=!1,this.highlightedSilhouetteTransparent=!1,this.highlightedEdgesTransparent=!1,this.selectedSilhouetteOpaque=!1,this.selectedEdgesOpaque=!1,this.selectedSilhouetteTransparent=!1,this.selectedEdgesTransparent=!1}}]),e}(),Ir=Ae.OBB3(),Tr=Ae.vec4(),Pr=Ae.vec4(),Sr=Ae.vec4(),Dr=Ae.vec3([1,0,0]),Qr=Ae.vec3([0,1,0]),Rr=Ae.vec3([0,0,1]),Or=Ae.vec3(3),Vr=Ae.vec3(3),Lr=Ae.identityMat4(),Hr=new Z({}),Nr={},Gr=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,n),(r=t.call(this,e,i)).renderOrder=i.renderOrder||0,r.originalSystemId=i.originalSystemId||r.id,r.renderFlags=new Ur,r._state=new it({visible:!0,culled:!1,pickable:null,clippable:null,collidable:null,occluder:!1!==i.occluder,castsShadow:null,receivesShadow:null,xrayed:!1,highlighted:!1,selected:!1,edges:!1,stationary:!!i.stationary,background:!!i.background,billboard:r._checkBillboard(i.billboard),layer:null,colorize:null,pickID:r.scene._renderer.getPickID(w(r)),drawHash:"",pickOcclusionHash:"",offset:Ae.vec3(),origin:null,originHash:null,isUI:i.isUI});var s=i.material?r._checkComponent2(["PhongMaterial","MetallicMaterial","SpecularMaterial","LambertMaterial"],i.material):r.scene.material,a=w(r),o=function(e){var t=null,n=function(){if(!t){var n=gr(),r=n.programVariables.createAttribute,i=a._geometry._state,s={position:r("vec3","position"),color:i.colorsBuf&&r("vec4","color"),pickColor:r("vec4","pickColor"),uv:i.uvBuf&&r("vec2","uv"),normal:(i.autoVertexNormals||i.normalsBuf)&&["triangles","triangle-strip","triangle-fan"].includes(i.primitiveName)&&r("vec3","normal")},o=function(e){var t={toString:function(){return t.needed=!0,e}};return t},A=s.normal&&o("worldNormal"),c=A&&o("viewNormal"),l=s.uv&&o("decodedUv"),u=e(n.programVariables,{attributes:{position:{world:"worldPosition",view:"viewPosition"},color:s.color,pickColor:s.pickColor,uv:l,normal:s.normal&&{world:A,view:c}},viewMatrix:"viewMatrix2"}),h=[u.programName,a.scene.canvas.canvas.id,a.scene._sectionPlanesState.getHash(),a._geometry._state.hash].concat(u.getHash()).join(";");if(!(h in Nr)){var d=Wr(a,s,{decodedUv:l,worldNormal:A,viewNormal:c},u,n);if(d.errors)return void console.log(d.errors.join("\n"));var f=Hr.addItem({});Nr[h]={drawMesh:d.drawMesh,id:f,useCount:0,delete:function(){Hr.removeItem(f),d.destroy(),delete Nr[h],he.memory.programs--}},he.memory.programs++}(t=Nr[h]).useCount++}};return{get:n,getId:function(){return t.id},put:function(){t&&(0==--t.useCount&&t.delete(),t=null)},drawMesh:function(e,r,i){n(),t&&t.drawMesh(e,r,i)}}},A=a.scene,c=function(e){return function(t,n){return Cr(a._state.hash,t,n,A,e)}};r._renderers={_drawRenderer:o((function(e,t){return"LambertMaterial"===s.type?Br(a._state.drawHash,e,t,s,A):wr(a._state.drawHash,e,t,s,A)})),_shadowRenderer:o((function(e){return xr(a._state.hash,e)})),_emphasisEdgesRenderer:o(c(!1)),_emphasisFillRenderer:o(c(!0)),_pickMeshRenderer:o((function(e){return kr(a._state.hash,e)})),_pickTriangleRenderer:o((function(e,t){return Er(a._state.hash,e,t)})),_occlusionRenderer:o((function(e){return Fr(a._state.pickOcclusionHash,e)}))},r._geometry=i.geometry?r._checkComponent2(["ReadableGeometry","VBOGeometry"],i.geometry):r.scene.geometry,r._material=s,r._xrayMaterial=i.xrayMaterial?r._checkComponent("EmphasisMaterial",i.xrayMaterial):r.scene.xrayMaterial,r._highlightMaterial=i.highlightMaterial?r._checkComponent("EmphasisMaterial",i.highlightMaterial):r.scene.highlightMaterial,r._selectedMaterial=i.selectedMaterial?r._checkComponent("EmphasisMaterial",i.selectedMaterial):r.scene.selectedMaterial,r._edgeMaterial=i.edgeMaterial?r._checkComponent("EdgeMaterial",i.edgeMaterial):r.scene.edgeMaterial,r._parentNode=null,r._aabb=null,r._aabbDirty=!0,r._numTriangles=r._geometry?r._geometry.numTriangles:0,r.scene._aabbDirty=!0,r._scale=Ae.vec3(),r._quaternion=Ae.identityQuaternion(),r._rotation=Ae.vec3(),r._position=Ae.vec3(),r._worldMatrix=Ae.identityMat4(),r._worldNormalMatrix=Ae.identityMat4(),r._localMatrixDirty=!0,r._worldMatrixDirty=!0,r._worldNormalMatrixDirty=!0;var l=i.origin||i.rtcCenter;if(l&&(r._state.origin=Ae.vec3(l),r._state.originHash=l.join()),i.matrix?r.matrix=i.matrix:(r.scale=i.scale,r.position=i.position,i.quaternion||(r.rotation=i.rotation)),r._isObject=i.isObject,r._isObject&&r.scene._registerObject(w(r)),r._isModel=i.isModel,r._isModel&&r.scene._registerModel(w(r)),r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.layer=i.layer,r.colorize=i.colorize,r.opacity=i.opacity,r.offset=i.offset,i.parentId){var u=r.scene.components[i.parentId];u?u.isNode?u.addChild(w(r)):r.error("Parent is not a Node: '"+i.parentId+"'"):r.error("Parent not found: '"+i.parentId+"'"),r._parentNode=u}else i.parent&&(i.parent.isNode||r.error("Parent is not a Node"),i.parent.addChild(w(r)),r._parentNode=i.parent);return r.compile(),r}return I(n,[{key:"type",get:function(){return"Mesh"}},{key:"isMesh",get:function(){return!0}},{key:"parent",get:function(){return this._parentNode}},{key:"geometry",get:function(){return this._geometry}},{key:"material",get:function(){return this._material}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),Ae.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),Ae.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"matrix",get:function(){return this._localMatrixDirty&&(this.__localMatrix||(this.__localMatrix=Ae.identityMat4()),Ae.composeMat4(this._position,this._quaternion,this._scale,this.__localMatrix),this._localMatrixDirty=!1),this.__localMatrix},set:function(e){this.__localMatrix||(this.__localMatrix=Ae.identityMat4()),this.__localMatrix.set(e||Lr),Ae.decomposeMat4(this.__localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._setWorldMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"worldNormalMatrix",get:function(){return this._worldNormalMatrixDirty&&this._buildWorldNormalMatrix(),this._worldNormalMatrix}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return this._isObject}},{key:"isUI",get:function(){return this._state.isUI}},{key:"aabb",get:function(){return this._aabbDirty&&this._updateAABB(),this._aabb}},{key:"origin",get:function(){return this._state.origin},set:function(e){e?(this._state.origin||(this._state.origin=Ae.vec3()),this._state.origin.set(e),this._state.originHash=e.join(),this._setAABBDirty(),this.scene._aabbDirty=!0):this._state.origin&&(this._state.origin=null,this._state.originHash=null,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"rtcCenter",get:function(){return this.origin},set:function(e){this.origin=e}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"visible",get:function(){return this._state.visible},set:function(e){e=!1!==e,this._state.visible=e,this._isObject&&this.scene._objectVisibilityUpdated(this,e),this.glRedraw()}},{key:"xrayed",get:function(){return this._state.xrayed},set:function(e){e=!!e,this._state.xrayed!==e&&(this._state.xrayed=e,this._isObject&&this.scene._objectXRayedUpdated(this,e),this.glRedraw())}},{key:"highlighted",get:function(){return this._state.highlighted},set:function(e){(e=!!e)!==this._state.highlighted&&(this._state.highlighted=e,this._isObject&&this.scene._objectHighlightedUpdated(this,e),this.glRedraw())}},{key:"selected",get:function(){return this._state.selected},set:function(e){(e=!!e)!==this._state.selected&&(this._state.selected=e,this._isObject&&this.scene._objectSelectedUpdated(this,e),this.glRedraw())}},{key:"edges",get:function(){return this._state.edges},set:function(e){(e=!!e)!==this._state.edges&&(this._state.edges=e,this.glRedraw())}},{key:"culled",get:function(){return this._state.culled},set:function(e){this._state.culled=!!e,this.glRedraw()}},{key:"clippable",get:function(){return this._state.clippable},set:function(e){e=!1!==e,this._state.clippable!==e&&(this._state.clippable=e,this.glRedraw())}},{key:"collidable",get:function(){return this._state.collidable},set:function(e){(e=!1!==e)!==this._state.collidable&&(this._state.collidable=e,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"pickable",get:function(){return this._state.pickable},set:function(e){e=!1!==e,this._state.pickable!==e&&(this._state.pickable=e)}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){(e=!1!==e)!==this._state.castsShadow&&(this._state.castsShadow=e,this.glRedraw())}},{key:"receivesShadow",get:function(){return this._state.receivesShadow},set:function(e){(e=!1!==e)!==this._state.receivesShadow&&(this._state.receivesShadow=e,this._state.hash=e?"/mod/rs;":"/mod;",this.fire("dirty",this))}},{key:"saoEnabled",get:function(){return!1}},{key:"colorize",get:function(){return this._state.colorize},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[3]=1),e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1);var n=!!e;this.scene._objectColorizeUpdated(this,n),this.glRedraw()}},{key:"opacity",get:function(){return this._state.colorize[3]},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[0]=1,t[1]=1,t[2]=1);var n=null!=e;t[3]=n?e:1,this.scene._objectOpacityUpdated(this,n),this.glRedraw()}},{key:"transparent",get:function(){return 2===this._material.alphaMode||this._state.colorize[3]<1}},{key:"layer",get:function(){return this._state.layer},set:function(e){e=e||0,(e=Math.round(e))!==this._state.layer&&(this._state.layer=e,this._renderer.needStateSort())}},{key:"stationary",get:function(){return this._state.stationary}},{key:"billboard",get:function(){return this._state.billboard}},{key:"offset",get:function(){return this._state.offset},set:function(e){this._state.offset.set(e||[0,0,0]),this._setAABBDirty(),this.glRedraw()}},{key:"isDrawable",get:function(){return!0}},{key:"isStateSortable",get:function(){return!0}},{key:"xrayMaterial",get:function(){return this._xrayMaterial}},{key:"highlightMaterial",get:function(){return this._highlightMaterial}},{key:"selectedMaterial",get:function(){return this._selectedMaterial}},{key:"edgeMaterial",get:function(){return this._edgeMaterial}},{key:"_checkBillboard",value:function(e){return"spherical"!==(e=e||"none")&&"cylindrical"!==e&&"none"!==e&&(this.error("Unsupported value for 'billboard': "+e+" - accepted values are 'spherical', 'cylindrical' and 'none' - defaulting to 'none'."),e="none"),e}},{key:"compile",value:function(){var e=this.scene,t=this._state,n=[e.canvas.canvas.id,e._sectionPlanesState.getHash()];t.stationary&&n.push("/s"),"none"===t.billboard?n.push("/n"):"spherical"===t.billboard?n.push("/s"):"cylindrical"===t.billboard&&n.push("/c"),n.push(";");var r=n.concat([e.gammaOutput?"go":"",e._lightsState.getHash(),t.receivesShadow?"/rs":""]).join("");this._state.drawHash!==r&&(this._state.drawHash=r,this._renderers._drawRenderer.put(),this._renderers._shadowRenderer.put(),this._renderers._emphasisFillRenderer.put(),this._renderers._emphasisEdgesRenderer.put(),this._renderers._drawRenderer.get(),this._renderers._emphasisFillRenderer.get(),this._renderers._emphasisEdgesRenderer.get());var i=n.join("");this._state.pickOcclusionHash!==i&&(this._state.pickOcclusionHash=i,this._renderers._pickMeshRenderer.put(),this._renderers._pickTriangleRenderer.put(),this._renderers._pickMeshRenderer.get(),this._state.occluder&&(this._renderers._occlusionRenderer.put(),this._renderers._occlusionRenderer.get()))}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}},{key:"_setWorldMatrixDirty",value:function(){this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentNode)Ae.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(var t=0,n=e.length;t<n;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}},{key:"_buildWorldNormalMatrix",value:function(){this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldNormalMatrix||(this._worldNormalMatrix=Ae.mat4()),Ae.transposeMat4(this._worldMatrix,this._worldNormalMatrix),Ae.inverseMat4(this._worldNormalMatrix),this._worldNormalMatrixDirty=!1}},{key:"_setAABBDirty",value:function(){if(this.collidable)for(var e=this;e;e=e._parentNode)e._aabbDirty=!0}},{key:"_updateAABB",value:function(){this.scene._aabbDirty=!0,this._aabb||(this._aabb=Ae.AABB3()),this._buildAABB(this.worldMatrix,this._aabb),this._aabbDirty=!1}},{key:"_buildAABB",value:function(e,t){Ae.transformOBB3(e,this._geometry.obb,Ir),Ae.OBB3ToAABB3(Ir,t);var n=this._state.offset;if(t[0]+=n[0],t[1]+=n[1],t[2]+=n[2],t[3]+=n[0],t[4]+=n[1],t[5]+=n[2],this._state.origin){var r=this._state.origin;t[0]+=r[0],t[1]+=r[1],t[2]+=r[2],t[3]+=r[0],t[4]+=r[1],t[5]+=r[2]}}},{key:"rotate",value:function(e,t){return Tr[0]=e[0],Tr[1]=e[1],Tr[2]=e[2],Tr[3]=t*Ae.DEGTORAD,Ae.angleAxisToQuaternion(Tr,Pr),Ae.mulQuaternions(this.quaternion,Pr,Sr),this.quaternion=Sr,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"rotateOnWorldAxis",value:function(e,t){return Tr[0]=e[0],Tr[1]=e[1],Tr[2]=e[2],Tr[3]=t*Ae.DEGTORAD,Ae.angleAxisToQuaternion(Tr,Pr),Ae.mulQuaternions(Pr,this.quaternion,Pr),this}},{key:"rotateX",value:function(e){return this.rotate(Dr,e)}},{key:"rotateY",value:function(e){return this.rotate(Qr,e)}},{key:"rotateZ",value:function(e){return this.rotate(Rr,e)}},{key:"translate",value:function(e,t){return Ae.vec3ApplyQuaternion(this.quaternion,e,Or),Ae.mulVec3Scalar(Or,t,Vr),Ae.addVec3(this.position,Vr,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"translateX",value:function(e){return this.translate(Dr,e)}},{key:"translateY",value:function(e){return this.translate(Qr,e)}},{key:"translateZ",value:function(e){return this.translate(Rr,e)}},{key:"stateSortCompare",value:function(e,t){return e._state.layer-t._state.layer||e._renderers._drawRenderer.getId()-t._renderers._drawRenderer.getId()||e._material._state.id-t._material._state.id||e._geometry._state.id-t._geometry._state.id}},{key:"rebuildRenderFlags",value:function(){this.renderFlags.reset(),this._getActiveSectionPlanes()?(this.renderFlags.numLayers=1,this.renderFlags.numVisibleLayers=1,this.renderFlags.visibleLayers[0]=0,this._updateRenderFlags()):this.renderFlags.culled=!0}},{key:"_updateRenderFlags",value:function(){var e=this.renderFlags,t=this._state;if(t.xrayed){var n=this._xrayMaterial._state;n.fill&&(n.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),n.edges&&(n.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}else{if(this._material._state.alpha<1||t.colorize[3]<1?e.colorTransparent=!0:e.colorOpaque=!0,t.edges)this._edgeMaterial._state.alpha<1?e.edgesTransparent=!0:e.edgesOpaque=!0;if(t.selected){var r=this._selectedMaterial._state;r.fill&&(r.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),r.edges&&(r.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}else if(t.highlighted){var i=this._highlightMaterial._state;i.fill&&(i.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),i.edges&&(i.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}},{key:"_getActiveSectionPlanes",value:function(){if(this._state.clippable){var e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(var n=0;n<t;n++){var r=e[n],i=this.renderFlags;if(r.active)if(this._state.origin){var s=Ae.planeAABB3Intersect(r.dir,r.dist,this.aabb);if(-1===s)return!1;var a=0===s;i.sectionPlanesActivePerLayer[n]=a}else i.sectionPlanesActivePerLayer[n]=!0;else i.sectionPlanesActivePerLayer[n]=!1}}return!0}},{key:"drawColorOpaque",value:function(e){this._renderers._drawRenderer.drawMesh(e,this,this._material)}},{key:"drawColorTransparent",value:function(e){this._renderers._drawRenderer.drawMesh(e,this,this._material)}},{key:"drawSilhouetteXRayed",value:function(e){this._renderers._emphasisFillRenderer.drawMesh(e,this,this._xrayMaterial)}},{key:"drawSilhouetteHighlighted",value:function(e){this._renderers._emphasisFillRenderer.drawMesh(e,this,this._highlightMaterial)}},{key:"drawSilhouetteSelected",value:function(e){this._renderers._emphasisFillRenderer.drawMesh(e,this,this._selectedMaterial)}},{key:"drawEdgesColorOpaque",value:function(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._edgeMaterial)}},{key:"drawEdgesColorTransparent",value:function(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._edgeMaterial)}},{key:"drawEdgesXRayed",value:function(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._xrayMaterial)}},{key:"drawEdgesHighlighted",value:function(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._highlightMaterial)}},{key:"drawEdgesSelected",value:function(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._selectedMaterial)}},{key:"drawOcclusion",value:function(e){this._renderers._occlusionRenderer.drawMesh(e,this,this._material)}},{key:"drawShadow",value:function(e){this._renderers._shadowRenderer.drawMesh(e,this,this._material)}},{key:"drawPickMesh",value:function(e){this._renderers._pickMeshRenderer.drawMesh(e,this,this._material)}},{key:"canPickTriangle",value:function(){return this._geometry.isReadableGeometry}},{key:"drawPickTriangles",value:function(e){this._renderers._pickTriangleRenderer.drawMesh(e,this,this._material)}},{key:"pickTriangleSurface",value:function(e,t,n,r){jr(this,e,t,n,r)}},{key:"drawPickVertices",value:function(e){}},{key:"delegatePickedEntity",value:function(){return this}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),Object.values(this._renderers).forEach((function(e){return e.put()})),this.scene._renderer.putPickID(this._state.pickID),this._isObject&&(this.scene._deregisterObject(this),this._visible&&this.scene._objectVisibilityUpdated(this,!1,!1),this._xrayed&&this.scene._objectXRayedUpdated(this,!1,!1),this._selected&&this.scene._objectSelectedUpdated(this,!1,!1),this._highlighted&&this.scene._objectHighlightedUpdated(this,!1,!1),this.scene._objectColorizeUpdated(this,!1),this.scene._objectOpacityUpdated(this,!1),this.offset.some((function(e){return 0!==e}))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this.glRedraw()}}]),n}(),jr=function(){var e=Ae.vec3(),t=Ae.vec3(),n=Ae.vec3(),r=Ae.vec3(),i=Ae.vec3(),s=Ae.vec3(),a=Ae.vec4(),o=Ae.vec3(),A=Ae.vec3(),c=Ae.vec3(),l=Ae.vec3(),u=Ae.vec3(),h=Ae.vec3(),d=Ae.vec3(),f=Ae.vec3(),p=Ae.vec3(),v=Ae.vec4(),g=Ae.vec4(),m=Ae.vec4(),y=Ae.vec3(),_=Ae.vec3(),b=Ae.vec3(),w=Ae.vec3(),B=Ae.vec3(),C=Ae.vec3(),M=Ae.vec3(),k=Ae.vec3(),E=Ae.vec3(),F=Ae.vec3(),x=Ae.vec3();return function(U,I,T,P,S){var D=S.primIndex;if(null!=D&&D>-1){var Q=U.geometry._state,R=U.scene,O=R.camera,V=R.canvas;if("triangles"===Q.primitiveName){S.primitive="triangle";var L,H,N,G=D,j=Q.indices,W=Q.positions;if(j){var z=j[G+0],X=j[G+1],K=j[G+2];s[0]=z,s[1]=X,s[2]=K,S.indices=s,L=3*z,H=3*X,N=3*K}else N=(H=(L=3*G)+3)+3;if(n[0]=W[L+0],n[1]=W[L+1],n[2]=W[L+2],r[0]=W[H+0],r[1]=W[H+1],r[2]=W[H+2],i[0]=W[N+0],i[1]=W[N+1],i[2]=W[N+2],Q.compressGeometry){var Z=Q.positionsDecodeMatrix;Z&&(pt.decompressPosition(n,Z,n),pt.decompressPosition(r,Z,r),pt.decompressPosition(i,Z,i))}S.canvasPos?Ae.canvasPosToLocalRay(V.canvas,U.origin?Zt(I,U.origin):I,T,P,U.worldMatrix,S.canvasPos,e,t):S.origin&&S.direction&&Ae.worldRayToLocalRay(U.worldMatrix,S.origin,S.direction,e,t),Ae.normalizeVec3(t),Ae.rayPlaneIntersect(e,t,n,r,i,a),S.localPos=a,S.position=a,v[0]=a[0],v[1]=a[1],v[2]=a[2],v[3]=1,Ae.transformVec4(U.worldMatrix,v,g),o[0]=g[0],o[1]=g[1],o[2]=g[2],S.canvasPos&&U.origin&&(o[0]+=U.origin[0],o[1]+=U.origin[1],o[2]+=U.origin[2]),S.worldPos=o,Ae.transformVec4(O.matrix,g,m),A[0]=m[0],A[1]=m[1],A[2]=m[2],S.viewPos=A,Ae.cartesianToBarycentric(a,n,r,i,c),S.bary=c;var J=Q.normals;if(J){if(Q.compressGeometry){var Y=3*z,q=3*X,$=3*K;pt.decompressNormal(J.subarray(Y,Y+2),l),pt.decompressNormal(J.subarray(q,q+2),u),pt.decompressNormal(J.subarray($,$+2),h)}else l[0]=J[L],l[1]=J[L+1],l[2]=J[L+2],u[0]=J[H],u[1]=J[H+1],u[2]=J[H+2],h[0]=J[N],h[1]=J[N+1],h[2]=J[N+2];var ee=Ae.addVec3(Ae.addVec3(Ae.mulVec3Scalar(l,c[0],y),Ae.mulVec3Scalar(u,c[1],_),b),Ae.mulVec3Scalar(h,c[2],w),B);S.worldNormal=Ae.normalizeVec3(Ae.transformVec3(U.worldNormalMatrix,ee,C))}var te=Q.uv;if(te){if(d[0]=te[2*z],d[1]=te[2*z+1],f[0]=te[2*X],f[1]=te[2*X+1],p[0]=te[2*K],p[1]=te[2*K+1],Q.compressGeometry){var ne=Q.uvDecodeMatrix;ne&&(pt.decompressUV(d,ne,d),pt.decompressUV(f,ne,f),pt.decompressUV(p,ne,p))}S.uv=Ae.addVec3(Ae.addVec3(Ae.mulVec2Scalar(d,c[0],M),Ae.mulVec2Scalar(f,c[1],k),E),Ae.mulVec2Scalar(p,c[2],F),x)}}}}}(),Wr=function(e,t,n,r,i){var s,a,o=i.programVariables,A=n.decodedUv,c=n.worldNormal,l=n.viewNormal,u=e.scene,h=u.canvas.gl,d=e._state.background,f=e._geometry._state,v=f.compressGeometry,g="points"===f.primitiveName,m=o.createUniform("float","pointSize"),y=o.createUniform("mat4","modelMatrix"),_=o.createUniform("mat4","modelNormalMatrix"),b=o.createUniform("vec3","offset"),w=o.createUniform("vec3","scale"),B=o.createUniform("mat4","positionsDecodeMatrix"),C=o.createUniform("mat3","uvDecodeMatrix"),M=o.createUniform("mat4","viewMatrix"),E=o.createUniform("mat4","viewNormalMatrix"),F=o.createUniform("mat4","projMatrix"),x=e.billboard,U=!r.dontBillboardAnything&&("spherical"===x||"cylindrical"===x),I=e.stationary,T=U&&function(e,t){return["mat4 ".concat(e,"(in mat4 matIn) {")," mat4 mat = matIn;"," mat[0].xyz = vec3(".concat(w,"[0], 0.0, 0.0);")].concat(p("spherical"===x?[" mat[1].xyz = vec3(0.0, ".concat(w,"[1], 0.0);")]:[]),[" mat[2].xyz = vec3(0.0, 0.0, 1.0);"," return mat;","}"]).forEach((function(e){return t.push(e)}))},P=(s=T&&o.createVertexDefinition("billboard",T),function(e){return s?"".concat(s,"(").concat(e,")"):e}),S=(a=T&&o.createFragmentDefinition("billboard",T),function(e){return a?"".concat(a,"(").concat(e,")"):e}),D=[];r.dontBillboardAnything?D.push("mat4 viewMatrix2 = ".concat(M,";")):(D.push("mat4 viewMatrix1 = ".concat(M,";")),I?D.push("viewMatrix1[3].xyz = vec3(0.0, 0.0, 0.0);"):d&&D.push("viewMatrix1[3] = vec4(0.0, 0.0, 0.0, 1.0);"),D.push("mat4 viewMatrix2 = ".concat(S("viewMatrix1"),";")));var Q="clipPos",R=o.createUniform("bool","clippable"),O=k(i.buildProgram(h,r.programName,{appendFragmentOutputs:function(e,t,n,i){D.forEach((function(t){return e.push(t)})),r.appendFragmentOutputs(e,t,n,i)},clippableTest:function(){return R},clippingCaps:r.clippingCaps,clipPos:d?"".concat(Q,".xyww"):Q,crossSections:u.crossSections,discardPoints:g&&r.discardPoints,getGammaFactor:u.gammaOutput&&function(){return u.gammaFactor},getLogDepth:!r.dontGetLogDepth&&u.logarithmicDepthBufferEnabled&&function(e){return e},getPointSize:r.setupPointSize&&g&&function(){return m},getVertexData:function(){var e=l&&l.needed&&"vec3 ".concat(l," = normalize((").concat(P(E)," * vec4(").concat(c,", 0.0)).xyz);"),n=[];if(n.push("vec4 localPosition = vec4(".concat(t.position,", 1.0);")),v&&n.push("localPosition = ".concat(B," * localPosition;")),n.push("vec4 worldPosition = ".concat(P(y)," * localPosition;")),n.push("worldPosition.xyz = worldPosition.xyz + ".concat(b,";")),r.dontBillboardAnything?n.push("vec4 viewPosition = ".concat(M," * worldPosition;")):(n.push("mat4 viewMatrix1 = ".concat(M,";")),I?n.push("viewMatrix1[3].xyz = vec3(0.0, 0.0, 0.0);"):d&&n.push("viewMatrix1[3] = vec4(0.0, 0.0, 0.0, 1.0);"),n.push("mat4 viewMatrix2 = ".concat(P("viewMatrix1"),";")),n.push("vec4 viewPosition = ".concat(U?"".concat(P("viewMatrix1 * ".concat(y))," * localPosition"):"viewMatrix2 * worldPosition",";"))),A&&A.needed&&n.push("vec2 ".concat(A," = ").concat(v?"(".concat(C," * vec3(").concat(t.uv,", 1.0)).xy"):t.uv,";")),c&&c.needed){var i=v?"".concat(o.commonLibrary.octDecode,"(").concat(t.normal,".xy)"):t.normal;n.push("vec3 ".concat(c," = (").concat(P(_)," * vec4(").concat(i,", 0.0)).xyz;"))}return e&&n.push(e),n.push("vec4 ".concat(Q," = ").concat(F," * viewPosition;")),n},projMatrix:F,sectionPlanesState:u._sectionPlanesState,testPerspectiveForGl_FragDepth:!0,usePickClipPos:r.isPick,worldPositionAttribute:"worldPosition"}),2),V=O[0],L=O[1];if(L)return{errors:L};var H=V.inputSetters,N=null,G=null;return{destroy:function(){return V.destroy()},drawMesh:function(e,n,i){if(!(r.skipIfTransparent&&i.alpha<1)){var s=i._state,a=n._state,o=n._geometry,A=o._state,c=e.viewParams,l=r.canActAsBackground&&d;e.lastProgramId!==V.id&&(e.lastProgramId=V.id,V.bind(),e.useProgram++,N=null,G=null,l&&h.depthFunc(h.LEQUAL)),s.id!==N&&(e.backfaces!==s.backfaces&&(s.backfaces?h.disable(h.CULL_FACE):h.enable(h.CULL_FACE),e.backfaces=s.backfaces),r.dontSetFrontFace||e.frontface===s.frontface||(h.frontFace(s.frontface?h.CCW:h.CW),e.frontface=s.frontface),r.drawEdges&&e.lineWidth!==s.edgeWidth&&(h.lineWidth(s.edgeWidth),e.lineWidth=s.edgeWidth),r.setsLineWidth&&e.lineWidth!==s.lineWidth&&(h.lineWidth(s.lineWidth),e.lineWidth=s.lineWidth),N=s.id);var u,f,p,v=!r.useShadowView&&n.origin;u=c.projMatrix,f=v?e.getRTCViewMatrix(a.originHash,v):c.viewMatrix,p=function(e,t){return e.setInputValue&&e.setInputValue(t)},p(m,i.pointSize),p(y,n.worldMatrix),p(_,n.worldNormalMatrix),p(b,n.offset),p(w,n.scale),p(B,A.positionsDecodeMatrix),p(C,A.uvDecodeMatrix),p(M,f),p(E,c.viewNormalMatrix),p(F,u),p(R,n.clippable),H.setUniforms(e,{material:i,meshColorize:n.colorize,meshPickID:n._state.pickID,mesh:{origin:n.origin,renderFlags:{sectionPlanesActivePerLayer:n.renderFlags.sectionPlanesActivePerLayer}},view:{far:c.far}});var g=function(n){var r=function(t,n){t&&t.setInputValue&&n&&(t.setInputValue(n),e.bindArray++)};r(t.position,(n||A).positionsBuf),r(t.color,A.colorsBuf),r(t.pickColor,n&&n.pickColorsBuf),r(t.uv,A.uvBuf),r(t.normal,A.normalsBuf)};if(r.trianglePick){var k=o._getPickTrianglePositions();A.id!==G&&(g({positionsBuf:k,pickColorsBuf:o._getPickTriangleColors()}),G=A.id),h.drawArrays(A.primitive,0,k.numItems/3)}else if(r.drawEdges){var x=A.primitive===h.TRIANGLES?o._getEdgeIndices():A.primitive===h.LINES&&A.indicesBuf;x&&(A.id!==G&&(g(),x.bind(),e.bindArray++,G=A.id),h.drawElements(h.LINES,x.numItems,x.itemType,0),e.drawElements++)}else A.id!==G&&(g(),A.indicesBuf&&(A.indicesBuf.bind(),e.bindArray++),G=A.id),A.indicesBuf?(h.drawElements(A.primitive,A.indicesBuf.numItems,A.indicesBuf.itemType,0),e.drawElements++):A.positionsBuf&&(h.drawArrays(h.TRIANGLES,0,A.positionsBuf.numItems),e.drawArrays++);l&&h.depthFunc(h.LESS)}}}},zr=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),r=t.call(this,e,i),he.memory.materials++,r}return I(n,[{key:"type",get:function(){return"Material"}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),he.memory.materials--}}]),n}(),Xr={opaque:0,mask:1,blend:2},Kr=["opaque","mask","blend"],Zr=function(e){m(n,zr);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({type:"PhongMaterial",ambient:Ae.vec3([1,1,1]),diffuse:Ae.vec3([1,1,1]),specular:Ae.vec3([1,1,1]),emissive:Ae.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.ambient=i.ambient,r.diffuse=i.diffuse,r.specular=i.specular,r.emissive=i.emissive,r.alpha=i.alpha,r.shininess=i.shininess,r.reflectivity=i.reflectivity,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,i.ambientMap&&(r._ambientMap=r._checkComponent("Texture",i.ambientMap)),i.diffuseMap&&(r._diffuseMap=r._checkComponent("Texture",i.diffuseMap)),i.specularMap&&(r._specularMap=r._checkComponent("Texture",i.specularMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.reflectivityMap&&(r._reflectivityMap=r._checkComponent("Texture",i.reflectivityMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.diffuseFresnel&&(r._diffuseFresnel=r._checkComponent("Fresnel",i.diffuseFresnel)),i.specularFresnel&&(r._specularFresnel=r._checkComponent("Fresnel",i.specularFresnel)),i.emissiveFresnel&&(r._emissiveFresnel=r._checkComponent("Fresnel",i.emissiveFresnel)),i.alphaFresnel&&(r._alphaFresnel=r._checkComponent("Fresnel",i.alphaFresnel)),i.reflectivityFresnel&&(r._reflectivityFresnel=r._checkComponent("Fresnel",i.reflectivityFresnel)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r._makeHash(),r}return I(n,[{key:"type",get:function(){return"PhongMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}},{key:"ambient",get:function(){return this._state.ambient},set:function(e){var t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"diffuse",get:function(){return this._state.diffuse},set:function(e){var t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"specular",get:function(){return this._state.specular},set:function(e){var t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"shininess",get:function(){return this._state.shininess},set:function(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"reflectivity",get:function(){return this._state.reflectivity},set:function(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}},{key:"normalMap",get:function(){return this._normalMap}},{key:"ambientMap",get:function(){return this._ambientMap}},{key:"diffuseMap",get:function(){return this._diffuseMap}},{key:"specularMap",get:function(){return this._specularMap}},{key:"emissiveMap",get:function(){return this._emissiveMap}},{key:"alphaMap",get:function(){return this._alphaMap}},{key:"reflectivityMap",get:function(){return this._reflectivityMap}},{key:"occlusionMap",get:function(){return this._occlusionMap}},{key:"diffuseFresnel",get:function(){return this._diffuseFresnel}},{key:"specularFresnel",get:function(){return this._specularFresnel}},{key:"emissiveFresnel",get:function(){return this._emissiveFresnel}},{key:"alphaFresnel",get:function(){return this._alphaFresnel}},{key:"reflectivityFresnel",get:function(){return this._reflectivityFresnel}},{key:"alphaMode",get:function(){return Kr[this._state.alphaMode]},set:function(e){var t=Xr[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}();function Jr(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];var n;switch(t){case"WEBGL_depth_texture":n=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":n=e.getExtension("EXT_texture_filter_anisotropic")||e.getExtension("MOZ_EXT_texture_filter_anisotropic")||e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":n=e.getExtension("WEBGL_compressed_texture_s3tc")||e.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":n=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:n=e.getExtension(t)}return e._cachedExtensions[t]=n,n}function Yr(e,t){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=t;if(1009===i)return e.UNSIGNED_BYTE;if(1017===i)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return e.BYTE;if(1011===i)return e.SHORT;if(1012===i)return e.UNSIGNED_SHORT;if(1013===i)return e.INT;if(1014===i)return e.UNSIGNED_INT;if(1015===i)return e.FLOAT;if(1016===i)return e.HALF_FLOAT;if(1021===i)return e.ALPHA;if(1023===i)return e.RGBA;if(1024===i)return e.LUMINANCE;if(1025===i)return e.LUMINANCE_ALPHA;if(1026===i)return e.DEPTH_COMPONENT;if(1027===i)return e.DEPTH_STENCIL;if(1028===i)return e.RED;if(1022===i)return e.RGBA;if(1029===i)return e.RED_INTEGER;if(1030===i)return e.RG;if(1031===i)return e.RG_INTEGER;if(1033===i)return e.RGBA_INTEGER;if(33776===i||33777===i||33778===i||33779===i)if(3001===r){var s=Jr(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===s)return null;if(33776===i)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===i)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===i)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===i)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(null===(n=Jr(e,"WEBGL_compressed_texture_s3tc")))return null;if(33776===i)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===i)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===i)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===i)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){var a=Jr(e,"WEBGL_compressed_texture_pvrtc");if(null===a)return null;if(35840===i)return a.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return a.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return a.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return a.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){var o=Jr(e,"WEBGL_compressed_texture_etc1");return null!==o?o.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===i||37496===i){var A=Jr(e,"WEBGL_compressed_texture_etc");if(null===A)return null;if(37492===i)return 3001===r?A.COMPRESSED_SRGB8_ETC2:A.COMPRESSED_RGB8_ETC2;if(37496===i)return 3001===r?A.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:A.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){var c=Jr(e,"WEBGL_compressed_texture_astc");if(null===c)return null;if(37808===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:c.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:c.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:c.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:c.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:c.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:c.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:c.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:c.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:c.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:c.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:c.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:c.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:c.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:c.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===i){var l=Jr(e,"EXT_texture_compression_bptc");if(null===l)return null;if(36492===i)return 3001===r?l.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:l.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===i?e.UNSIGNED_INT_24_8:1e3===i?e.REPEAT:1001===i?e.CLAMP_TO_EDGE:1004===i||1005===i?e.NEAREST_MIPMAP_LINEAR:1007===i?e.LINEAR_MIPMAP_NEAREST:1008===i?e.LINEAR_MIPMAP_LINEAR:1003===i?e.NEAREST:1006===i?e.LINEAR:null}var qr=new Uint8Array([0,0,0,1]),$r=function(){function e(t){var n=t.gl,r=t.target,i=t.format,s=t.type,a=t.wrapS,o=t.wrapT,A=t.wrapR,c=t.encoding,l=t.preloadColor,u=t.premultiplyAlpha,h=t.flipY;x(this,e),this.gl=n,this.target=r||n.TEXTURE_2D,this.format=i||1023,this.type=s||1009,this.internalFormat=null,this.premultiplyAlpha=!!u,this.flipY=!!h,this.unpackAlignment=4,this.wrapS=a||1e3,this.wrapT=o||1e3,this.wrapR=A||1e3,this.encoding=c||3001,this.texture=n.createTexture(),l&&this.setPreloadColor(l),this.allocated=!0}return I(e,[{key:"setPreloadColor",value:function(e){e?(qr[0]=Math.floor(255*e[0]),qr[1]=Math.floor(255*e[1]),qr[2]=Math.floor(255*e[2]),qr[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(qr[0]=0,qr[1]=0,qr[2]=0,qr[3]=255);var t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP)for(var n=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z],r=0,i=n.length;r<i;r++)t.texImage2D(n[r],0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,qr);else t.texImage2D(this.target,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,qr);t.bindTexture(this.target,null)}},{key:"setTarget",value:function(e){this.target=e||this.gl.TEXTURE_2D}},{key:"setImage",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this.gl;void 0!==t.format&&(this.format=t.format),void 0!==t.internalFormat&&(this.internalFormat=t.internalFormat),void 0!==t.encoding&&(this.encoding=t.encoding),void 0!==t.type&&(this.type=t.type),void 0!==t.flipY&&(this.flipY=t.flipY),void 0!==t.premultiplyAlpha&&(this.premultiplyAlpha=t.premultiplyAlpha),void 0!==t.unpackAlignment&&(this.unpackAlignment=t.unpackAlignment),void 0!==t.minFilter&&(this.minFilter=t.minFilter),void 0!==t.magFilter&&(this.magFilter=t.magFilter),void 0!==t.wrapS&&(this.wrapS=t.wrapS),void 0!==t.wrapT&&(this.wrapT=t.wrapT),void 0!==t.wrapR&&(this.wrapR=t.wrapR);var r=!1;n.bindTexture(this.target,this.texture);var i=n.getParameter(n.UNPACK_FLIP_Y_WEBGL);n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,this.flipY);var s=n.getParameter(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL);n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha);var a=n.getParameter(n.UNPACK_ALIGNMENT);n.pixelStorei(n.UNPACK_ALIGNMENT,this.unpackAlignment);var o=n.getParameter(n.UNPACK_COLORSPACE_CONVERSION_WEBGL);n.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,n.NONE);var A=Yr(n,this.minFilter);n.texParameteri(this.target,n.TEXTURE_MIN_FILTER,A),A!==n.NEAREST_MIPMAP_NEAREST&&A!==n.LINEAR_MIPMAP_NEAREST&&A!==n.NEAREST_MIPMAP_LINEAR&&A!==n.LINEAR_MIPMAP_LINEAR||(r=!0);var c=Yr(n,this.magFilter);c&&n.texParameteri(this.target,n.TEXTURE_MAG_FILTER,c);var l=Yr(n,this.wrapS);l&&n.texParameteri(this.target,n.TEXTURE_WRAP_S,l);var u=Yr(n,this.wrapT);u&&n.texParameteri(this.target,n.TEXTURE_WRAP_T,u);var h=Yr(n,this.format,this.encoding),d=Yr(n,this.type),f=ei(n,this.internalFormat,h,d,this.encoding,!1);if(this.target===n.TEXTURE_CUBE_MAP){if(ge.isArray(e))for(var p=e,v=[n.TEXTURE_CUBE_MAP_POSITIVE_X,n.TEXTURE_CUBE_MAP_NEGATIVE_X,n.TEXTURE_CUBE_MAP_POSITIVE_Y,n.TEXTURE_CUBE_MAP_NEGATIVE_Y,n.TEXTURE_CUBE_MAP_POSITIVE_Z,n.TEXTURE_CUBE_MAP_NEGATIVE_Z],g=0,m=v.length;g<m;g++)n.texImage2D(v[g],0,f,h,d,p[g])}else n.texImage2D(n.TEXTURE_2D,0,f,h,d,e);r&&n.generateMipmap(this.target),n.bindTexture(this.target,null),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,i),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s),n.pixelStorei(n.UNPACK_ALIGNMENT,a),n.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,o)}},{key:"setCompressedData",value:function(e){var t=e.mipmaps,n=e.props,r=void 0===n?{}:n,i=this.gl,s=t.length;void 0!==r.format&&(this.format=r.format),void 0!==r.internalFormat&&(this.internalFormat=r.internalFormat),void 0!==r.encoding&&(this.encoding=r.encoding),void 0!==r.type&&(this.type=r.type),void 0!==r.flipY&&(this.flipY=r.flipY),void 0!==r.premultiplyAlpha&&(this.premultiplyAlpha=r.premultiplyAlpha),void 0!==r.unpackAlignment&&(this.unpackAlignment=r.unpackAlignment),void 0!==r.minFilter&&(this.minFilter=r.minFilter),void 0!==r.magFilter&&(this.magFilter=r.magFilter),void 0!==r.wrapS&&(this.wrapS=r.wrapS),void 0!==r.wrapT&&(this.wrapT=r.wrapT),void 0!==r.wrapR&&(this.wrapR=r.wrapR),i.activeTexture(i.TEXTURE0+0),i.bindTexture(this.target,this.texture);var a=t.length>1;i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,this.flipY),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),i.pixelStorei(i.UNPACK_ALIGNMENT,this.unpackAlignment),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,i.NONE);var o=Yr(i,this.wrapS);o&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,o);var A=Yr(i,this.wrapT);if(A&&i.texParameteri(this.target,i.TEXTURE_WRAP_T,A),this.type===i.TEXTURE_3D||this.type===i.TEXTURE_2D_ARRAY){var c=Yr(i,this.wrapR);c&&i.texParameteri(this.target,i.TEXTURE_WRAP_R,c),i.texParameteri(this.type,i.TEXTURE_WRAP_R,c)}a?(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,ti(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,ti(i,this.magFilter))):(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,Yr(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,Yr(i,this.magFilter)));var l=Yr(i,this.format,this.encoding),u=Yr(i,this.type),h=ei(i,this.internalFormat,l,u,this.encoding,!1);i.texStorage2D(i.TEXTURE_2D,s,h,t[0].width,t[0].height);for(var d=0,f=t.length;d<f;d++){var p=t[d];1023!==this.format?null!==l?i.compressedTexSubImage2D(i.TEXTURE_2D,d,0,0,p.width,p.height,l,p.data):console.warn("Attempt to load unsupported compressed texture format in .setCompressedData()"):i.texSubImage2D(i.TEXTURE_2D,d,0,0,p.width,p.height,l,u,p.data)}i.bindTexture(this.target,null)}},{key:"setProps",value:function(e){var t=this.gl;t.bindTexture(this.target,this.texture),this._uploadProps(e),t.bindTexture(this.target,null)}},{key:"_uploadProps",value:function(e){var t=this.gl;if(void 0!==e.format&&(this.format=e.format),void 0!==e.internalFormat&&(this.internalFormat=e.internalFormat),void 0!==e.encoding&&(this.encoding=e.encoding),void 0!==e.type&&(this.type=e.type),void 0!==e.minFilter){var n=Yr(t,e.minFilter);n&&(this.minFilter=e.minFilter,t.texParameteri(this.target,t.TEXTURE_MIN_FILTER,n),n!==t.NEAREST_MIPMAP_NEAREST&&n!==t.LINEAR_MIPMAP_NEAREST&&n!==t.NEAREST_MIPMAP_LINEAR&&n!==t.LINEAR_MIPMAP_LINEAR||t.generateMipmap(this.target))}if(void 0!==e.magFilter){var r=Yr(t,e.magFilter);r&&(this.magFilter=e.magFilter,t.texParameteri(this.target,t.TEXTURE_MAG_FILTER,r))}if(void 0!==e.wrapS){var i=Yr(t,e.wrapS);i&&(this.wrapS=e.wrapS,t.texParameteri(this.target,t.TEXTURE_WRAP_S,i))}if(void 0!==e.wrapT){var s=Yr(t,e.wrapT);s&&(this.wrapT=e.wrapT,t.texParameteri(this.target,t.TEXTURE_WRAP_T,s))}}},{key:"bind",value:function(e){if(this.allocated){if(this.texture){var t=this.gl;return t.activeTexture(t["TEXTURE"+e]),t.bindTexture(this.target,this.texture),!0}return!1}}},{key:"unbind",value:function(e){if(this.allocated&&this.texture){var t=this.gl;t.activeTexture(t["TEXTURE"+e]),t.bindTexture(this.target,null)}}},{key:"destroy",value:function(){this.allocated&&this.texture&&(this.gl.deleteTexture(this.texture),this.texture=null)}}]),e}();function ei(e,t,n,r,i){var s=arguments.length>5&&void 0!==arguments[5]&&arguments[5];if(null!==t){if(void 0!==e[t])return e[t];console.warn("Attempt to use non-existing WebGL internal format '"+t+"'")}var a=n;return n===e.RED&&(r===e.FLOAT&&(a=e.R32F),r===e.HALF_FLOAT&&(a=e.R16F),r===e.UNSIGNED_BYTE&&(a=e.R8)),n===e.RG&&(r===e.FLOAT&&(a=e.RG32F),r===e.HALF_FLOAT&&(a=e.RG16F),r===e.UNSIGNED_BYTE&&(a=e.RG8)),n===e.RGBA&&(r===e.FLOAT&&(a=e.RGBA32F),r===e.HALF_FLOAT&&(a=e.RGBA16F),r===e.UNSIGNED_BYTE&&(a=3001===i&&!1===s?e.SRGB8_ALPHA8:e.RGBA8),r===e.UNSIGNED_SHORT_4_4_4_4&&(a=e.RGBA4),r===e.UNSIGNED_SHORT_5_5_5_1&&(a=e.RGB5_A1)),a!==e.R16F&&a!==e.R32F&&a!==e.RG16F&&a!==e.RG32F&&a!==e.RGBA16F&&a!==e.RGBA32F||Jr(e,"EXT_color_buffer_float"),a}function ti(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}function ni(e){if(!ri(e.width)||!ri(e.height)){var t=document.createElement("canvas");t.width=ii(e.width),t.height=ii(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function ri(e){return 0==(e&e-1)}function ii(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var si=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({texture:new $r({gl:r.scene.canvas.gl}),matrix:Ae.identityMat4(),hasMatrix:i.translate&&(0!==i.translate[0]||0!==i.translate[1])||!!i.rotate||i.scale&&(0!==i.scale[0]||0!==i.scale[1]),minFilter:r._checkMinFilter(i.minFilter),magFilter:r._checkMagFilter(i.magFilter),wrapS:r._checkWrapS(i.wrapS),wrapT:r._checkWrapT(i.wrapT),flipY:r._checkFlipY(i.flipY),encoding:r._checkEncoding(i.encoding)}),r._src=null,r._image=null,r._translate=Ae.vec2([0,0]),r._scale=Ae.vec2([1,1]),r._rotate=Ae.vec2([0,0]),r._matrixDirty=!1,r.translate=i.translate,r.scale=i.scale,r.rotate=i.rotate,i.src?r.src=i.src:i.image&&(r.image=i.image),he.memory.textures++,r}return I(n,[{key:"type",get:function(){return"Texture"}},{key:"_checkMinFilter",value:function(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}},{key:"_checkMagFilter",value:function(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}},{key:"_checkWrapS",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkWrapT",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_update",value:function(){var e,t,n=this._state;this._matrixDirty&&(0===this._translate[0]&&0===this._translate[1]||(e=Ae.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(t=Ae.scalingMat4v([this._scale[0],this._scale[1],1]),e=e?Ae.mulMat4(e,t):t),0!==this._rotate&&(t=Ae.rotationMat4v(.0174532925*this._rotate,[0,0,1]),e=e?Ae.mulMat4(e,t):t),e&&(n.matrix=e),this._matrixDirty=!1);this.glRedraw()}},{key:"image",get:function(){return this._image},set:function(e){this._image=ni(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}},{key:"src",get:function(){return this._src},set:function(e){this.scene.loading++,this.scene.canvas.spinner.processes++;var t=this,n=new Image;n.onload=function(){n=ni(n),t._state.texture.setImage(n,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},n.src=e,this._src=e,this._image=null}},{key:"translate",get:function(){return this._translate},set:function(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}},{key:"rotate",get:function(){return this._rotate},set:function(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}},{key:"minFilter",get:function(){return this._state.minFilter}},{key:"magFilter",get:function(){return this._state.magFilter}},{key:"wrapS",get:function(){return this._state.wrapS}},{key:"wrapT",get:function(){return this._state.wrapT}},{key:"flipY",get:function(){return this._state.flipY}},{key:"encoding",get:function(){return this._state.encoding}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),he.memory.textures--}}]),n}(),ai=Ae.vec3(),oi=Ae.vec3();Ae.vec3();var Ai,ci=Ae.vec3([0,-1,0]),li=Ae.vec4([0,0,0,1]),ui=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._src=null,r._image=null,r._pos=Ae.vec3(),r._origin=Ae.vec3(),r._rtcPos=Ae.vec3(),r._dir=Ae.vec3(),r._size=1,r._imageSize=Ae.vec2(),r._texture=new si(w(r)),r._plane=new Gr(w(r),{geometry:new mt(w(r),Ut({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new Zr(w(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0}),clippable:i.clippable}),r._grid=new Gr(w(r),{geometry:new mt(w(r),xt({size:1,divisions:10})),material:new Zr(w(r),{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:i.clippable}),r._node=new Xt(w(r),{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[r._plane,r._grid]}),r._gridVisible=!1,r.visible=!0,r.gridVisible=i.gridVisible,r.position=i.position,r.rotation=i.rotation,r.dir=i.dir,r.size=i.size,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,i.image?r.image=i.image:r.src=i.src,r}return I(n,[{key:"visible",get:function(){return this._plane.visible},set:function(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}},{key:"gridVisible",get:function(){return this._gridVisible},set:function(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"position",get:function(){return this._pos},set:function(e){this._pos.set(e||[0,0,0]),Jt(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}},{key:"rotation",get:function(){return this._node.rotation},set:function(e){this._node.rotation=e}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"dir",get:function(){return this._dir},set:function(e){if(this._dir.set(e||[0,0,-1]),e){var t=this.scene.center,n=[-this._dir[0],-this._dir[1],-this._dir[2]];Ae.subVec3(t,this.position,ai);var r=-Ae.dotVec3(n,ai);Ae.normalizeVec3(n),Ae.mulVec3Scalar(n,r,oi),Ae.vec3PairToQuaternion(ci,e,li),this._node.quaternion=li}}},{key:"collidable",get:function(){return this._node.collidable},set:function(e){this._node.collidable=!1!==e}},{key:"clippable",get:function(){return this._node.clippable},set:function(e){this._node.clippable=!1!==e}},{key:"pickable",get:function(){return this._node.pickable},set:function(e){this._node.pickable=!1!==e}},{key:"opacity",get:function(){return this._node.opacity},set:function(e){this._node.opacity=e}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this)}},{key:"_updatePlaneSizeFromImage",value:function(){var e=this._size,t=this._imageSize[0],n=this._imageSize[1];if(t>n){var r=n/t;this._node.scale=[e,1,e*r]}else{var i=t/n;this._node.scale=[e*i,1,e]}}}]),n}(),hi=function(e){m(n,zr);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({type:"LambertMaterial",ambient:Ae.vec3([1,1,1]),color:Ae.vec3([1,1,1]),emissive:Ae.vec3([0,0,0]),alpha:null,alphaMode:0,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:"/lam;"}),r.ambient=i.ambient,r.color=i.color,r.emissive=i.emissive,r.alpha=i.alpha,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r.backfaces=i.backfaces,r.frontface=i.frontface,r}return I(n,[{key:"type",get:function(){return"LambertMaterial"}},{key:"ambient",get:function(){return this._state.ambient},set:function(e){var t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){var t=this._state.color;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.color=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this._state.alphaMode=e<1?2:0,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),di={opaque:0,mask:1,blend:2},fi=["opaque","mask","blend"],pi=function(e){m(n,zr);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({type:"MetallicMaterial",baseColor:Ae.vec4([1,1,1]),emissive:Ae.vec4([0,0,0]),metallic:null,roughness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.baseColor=i.baseColor,r.metallic=i.metallic,r.roughness=i.roughness,r.specularF0=i.specularF0,r.emissive=i.emissive,r.alpha=i.alpha,i.baseColorMap&&(r._baseColorMap=r._checkComponent("Texture",i.baseColorMap)),i.metallicMap&&(r._metallicMap=r._checkComponent("Texture",i.metallicMap)),i.roughnessMap&&(r._roughnessMap=r._checkComponent("Texture",i.roughnessMap)),i.metallicRoughnessMap&&(r._metallicRoughnessMap=r._checkComponent("Texture",i.metallicRoughnessMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r._makeHash(),r}return I(n,[{key:"type",get:function(){return"MetallicMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/met"];this._baseColorMap&&(t.push("/bm"),this._baseColorMap._state.hasMatrix&&t.push("/mat"),t.push("/"+this._baseColorMap._state.encoding)),this._metallicMap&&(t.push("/mm"),this._metallicMap._state.hasMatrix&&t.push("/mat")),this._roughnessMap&&(t.push("/rm"),this._roughnessMap._state.hasMatrix&&t.push("/mat")),this._metallicRoughnessMap&&(t.push("/mrm"),this._metallicRoughnessMap._state.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap._state.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap._state.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/am"),this._alphaMap._state.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap._state.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{key:"baseColor",get:function(){return this._state.baseColor},set:function(e){var t=this._state.baseColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.baseColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"baseColorMap",get:function(){return this._baseColorMap}},{key:"metallic",get:function(){return this._state.metallic},set:function(e){e=null!=e?e:1,this._state.metallic!==e&&(this._state.metallic=e,this.glRedraw())}},{key:"metallicMap",get:function(){return this._attached.metallicMap}},{key:"roughness",get:function(){return this._state.roughness},set:function(e){e=null!=e?e:1,this._state.roughness!==e&&(this._state.roughness=e,this.glRedraw())}},{key:"roughnessMap",get:function(){return this._attached.roughnessMap}},{key:"metallicRoughnessMap",get:function(){return this._attached.metallicRoughnessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"emissiveMap",get:function(){return this._attached.emissiveMap}},{key:"occlusionMap",get:function(){return this._attached.occlusionMap}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"alphaMap",get:function(){return this._attached.alphaMap}},{key:"normalMap",get:function(){return this._attached.normalMap}},{key:"alphaMode",get:function(){return fi[this._state.alphaMode]},set:function(e){var t=di[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),vi={opaque:0,mask:1,blend:2},gi=["opaque","mask","blend"],mi=function(e){m(n,zr);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({type:"SpecularMaterial",diffuse:Ae.vec3([1,1,1]),emissive:Ae.vec3([0,0,0]),specular:Ae.vec3([1,1,1]),glossiness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.diffuse=i.diffuse,r.specular=i.specular,r.glossiness=i.glossiness,r.specularF0=i.specularF0,r.emissive=i.emissive,r.alpha=i.alpha,i.diffuseMap&&(r._diffuseMap=r._checkComponent("Texture",i.diffuseMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.specularMap&&(r._specularMap=r._checkComponent("Texture",i.specularMap)),i.glossinessMap&&(r._glossinessMap=r._checkComponent("Texture",i.glossinessMap)),i.specularGlossinessMap&&(r._specularGlossinessMap=r._checkComponent("Texture",i.specularGlossinessMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r._makeHash(),r}return I(n,[{key:"type",get:function(){return"SpecularMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/spe"];this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat")),this._glossinessMap&&(t.push("/gm"),this._glossinessMap.hasMatrix&&t.push("/mat")),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._specularGlossinessMap&&(t.push("/sgm"),this._specularGlossinessMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{key:"diffuse",get:function(){return this._state.diffuse},set:function(e){var t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"diffuseMap",get:function(){return this._diffuseMap}},{key:"specular",get:function(){return this._state.specular},set:function(e){var t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"specularMap",get:function(){return this._specularMap}},{key:"specularGlossinessMap",get:function(){return this._specularGlossinessMap}},{key:"glossiness",get:function(){return this._state.glossiness},set:function(e){e=null!=e?e:1,this._state.glossiness!==e&&(this._state.glossiness=e,this.glRedraw())}},{key:"glossinessMap",get:function(){return this._glossinessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"emissiveMap",get:function(){return this._emissiveMap}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"alphaMap",get:function(){return this._alphaMap}},{key:"normalMap",get:function(){return this._normalMap}},{key:"occlusionMap",get:function(){return this._occlusionMap}},{key:"alphaMode",get:function(){return gi[this._state.alphaMode]},set:function(e){var t=vi[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),yi={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}},_i=function(e){m(n,zr);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),r._preset="default",i.preset?(r.preset=i.preset,void 0!==i.fill&&(r.fill=i.fill),i.fillColor&&(r.fillColor=i.fillColor),void 0!==i.fillAlpha&&(r.fillAlpha=i.fillAlpha),void 0!==i.edges&&(r.edges=i.edges),i.edgeColor&&(r.edgeColor=i.edgeColor),void 0!==i.edgeAlpha&&(r.edgeAlpha=i.edgeAlpha),void 0!==i.edgeWidth&&(r.edgeWidth=i.edgeWidth),void 0!==i.backfaces&&(r.backfaces=i.backfaces),void 0!==i.glowThrough&&(r.glowThrough=i.glowThrough)):(r.fill=i.fill,r.fillColor=i.fillColor,r.fillAlpha=i.fillAlpha,r.edges=i.edges,r.edgeColor=i.edgeColor,r.edgeAlpha=i.edgeAlpha,r.edgeWidth=i.edgeWidth,r.backfaces=i.backfaces,r.glowThrough=i.glowThrough),r}return I(n,[{key:"type",get:function(){return"EmphasisMaterial"}},{key:"presets",get:function(){return yi}},{key:"fill",get:function(){return this._state.fill},set:function(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}},{key:"fillColor",get:function(){return this._state.fillColor},set:function(e){var t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}},{key:"fillAlpha",get:function(){return this._state.fillAlpha},set:function(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}},{key:"edges",get:function(){return this._state.edges},set:function(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){var t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"edgeAlpha",get:function(){return this._state.edgeAlpha},set:function(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}},{key:"edgeWidth",get:function(){return this._state.edgeWidth},set:function(e){this._state.edgeWidth=e||1,this.glRedraw()}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"glowThrough",get:function(){return this._state.glowThrough},set:function(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}},{key:"preset",get:function(){return console.warn("EmphasisMaterial.preset is deprecated and will be removed in future versions."),this._preset},set:function(e){if(console.warn("EmphasisMaterial.preset is deprecated and will be removed in future versions."),e=e||"default",this._preset!==e){var t=yi[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(yi).join(", "))}}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),bi={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}},wi=function(e){m(n,zr);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),r._preset="default",i.preset?(r.preset=i.preset,i.edgeColor&&(r.edgeColor=i.edgeColor),void 0!==i.edgeAlpha&&(r.edgeAlpha=i.edgeAlpha),void 0!==i.edgeWidth&&(r.edgeWidth=i.edgeWidth)):(r.edgeColor=i.edgeColor,r.edgeAlpha=i.edgeAlpha,r.edgeWidth=i.edgeWidth),r.edges=!1!==i.edges,r}return I(n,[{key:"type",get:function(){return"EdgeMaterial"}},{key:"presets",get:function(){return bi}},{key:"edges",get:function(){return this._state.edges},set:function(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){var t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"edgeAlpha",get:function(){return this._state.edgeAlpha},set:function(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}},{key:"edgeWidth",get:function(){return this._state.edgeWidth},set:function(e){this._state.edgeWidth=e||1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=bi[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(bi).join(", "))}}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Bi=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({edgeColor:Ae.vec3([0,0,0]),centerColor:Ae.vec3([1,1,1]),edgeBias:0,centerBias:1,power:1}),r.edgeColor=i.edgeColor,r.centerColor=i.centerColor,r.edgeBias=i.edgeBias,r.centerBias=i.centerBias,r.power=i.power,r}return I(n,[{key:"type",get:function(){return"Fresnel"}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){this._state.edgeColor.set(e||[0,0,0]),this.glRedraw()}},{key:"centerColor",get:function(){return this._state.centerColor},set:function(e){this._state.centerColor.set(e||[1,1,1]),this.glRedraw()}},{key:"edgeBias",get:function(){return this._state.edgeBias},set:function(e){this._state.edgeBias=e||0,this.glRedraw()}},{key:"centerBias",get:function(){return this._state.centerBias},set:function(e){this._state.centerBias=null!=e?e:1,this.glRedraw()}},{key:"power",get:function(){return this._state.power},set:function(e){this._state.power=null!=e?e:1,this.glRedraw()}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Ci=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._type=i.type||(i.src?i.src.split(".").pop():null)||"jpg",r._pos=Ae.vec3(i.pos||[0,0,0]),r._up=Ae.vec3(i.up||[0,1,0]),r._normal=Ae.vec3(i.normal||[0,0,1]),r._height=i.height||1,r._origin=Ae.vec3(),r._rtcPos=Ae.vec3(),r._imageSize=Ae.vec2(),r._texture=new si(w(r),{flipY:!0}),r._image=new Image,"jpg"!==r._type&&"png"!==r._type&&(r.error('Unsupported type - defaulting to "jpg"'),r._type="jpg"),r._node=new Xt(w(r),{matrix:Ae.inverseMat4(Ae.lookAtMat4v(r._pos,Ae.subVec3(r._pos,r._normal,Ae.mat4()),r._up,Ae.mat4())),children:[r._bitmapMesh=new Gr(w(r),{scale:[1,1,1],rotation:[-90,0,0],collidable:i.collidable,pickable:i.pickable,opacity:i.opacity,clippable:i.clippable,geometry:new mt(w(r),Ut({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new Zr(w(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0})})]}),i.image?r.image=i.image:i.src?r.src=i.src:i.imageData&&(r.imageData=i.imageData),r.scene._bitmapCreated(w(r)),r}return I(n,[{key:"visible",get:function(){return this._bitmapMesh.visible},set:function(e){this._bitmapMesh.visible=e}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}},{key:"src",get:function(){return this._image.src},set:function(e){var t=this;if(e)switch(this._image.onload=function(){t._texture.image=t._image,t._imageSize[0]=t._image.width,t._imageSize[1]=t._image.height,t._updateBitmapMeshScale()},this._image.src=e,e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}},{key:"imageData",get:function(){var e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")},set:function(e){var t=this;this._image.onload=function(){t._texture.image=image,t._imageSize[0]=image.width,t._imageSize[1]=image.height,t._updateBitmapMeshScale()},this._image.src=e}},{key:"type",get:function(){return this._type},set:function(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}},{key:"pos",get:function(){return this._pos}},{key:"normal",get:function(){return this._normal}},{key:"up",get:function(){return this._up}},{key:"height",get:function(){return this._height},set:function(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}},{key:"collidable",get:function(){return this._bitmapMesh.collidable},set:function(e){this._bitmapMesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._bitmapMesh.clippable},set:function(e){this._bitmapMesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._bitmapMesh.pickable},set:function(e){this._bitmapMesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._bitmapMesh.opacity},set:function(e){this._bitmapMesh.opacity=e}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this.scene._bitmapDestroyed(this)}},{key:"_updateBitmapMeshScale",value:function(){var e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height/e,1,this._height]}}]),n}(),Mi=function(e,t){var n=[],r=[];function i(e,n){for(var r,i,s=0;s<3;s++)if((r=t[3*e+s])!==(i=t[3*n+s]))return i-r;return 0}for(var s=e.slice().sort(i),a=null,o=0,A=s.length;o<A;o++)0!==o&&0===i(s[o],s[o-1])||(a=s[o]),n[s[o]]=a;for(var c=0,l=e.length;c<l;c+=3){var u=n[e[c]],h=n[e[c+1]],d=n[e[c+2]],f=u,p=h,v=d;if(u>h&&u>d?h>d?(f=u,p=h,v=d):(f=u,p=d,v=h):h>u&&h>d?u>d?(f=h,p=u,v=d):(f=h,p=d,v=u):d>u&&d>h&&(u>h?(f=d,p=u,v=h):(f=d,p=h,v=u)),r[c+0]=[f,p],r[c+1]=[p,v],f>v){var g=v;v=f,f=g}r[c+2]=[v,f]}function m(e,t){for(var n,r,i=0;i<2;i++)if(n=e[i],(r=t[i])!==n)return r-n;return 0}(r=r.slice(0,e.length)).sort(m);for(var y=0,_=0;_<r.length;_++)if(0===_||0!==m(r[_],r[_-1])){if(0!==_&&2!==y)return!1;y=1}else y++;return!(r.length>0&&2!==y)},ki=Ae.vec3(),Ei=Ae.vec3(),Fi=Ae.vec3(),xi=function(){function e(){x(this,e),this.vertices=[],this.indices=[],this.reset()}return I(e,[{key:"reset",value:function(){this.lenVertices=0,this.lenIndices=0,this.primitive=null}},{key:"setPrimitive",value:function(e){this.primitive=e}},{key:"addVertex",value:function(e){this.vertices[this.lenVertices++]=e[0],this.vertices[this.lenVertices++]=e[1],this.vertices[this.lenVertices++]=e[2]}},{key:"addIndex",value:function(e){this.indices[this.lenIndices++]=e}},{key:"volume",get:function(){var e=this.vertices,t=this.indices;if("solid"!==this.primitive&&"surface"!==this.primitive&&"triangles"!==this.primitive)return-1;if("solid"!==this.primitive&&!Mi(t,e))return-1;for(var n=0,r=0;r<this.lenIndices;r+=3){var i=3*t[r],s=3*t[r+1],a=3*t[r+2];ki[0]=e[i],ki[1]=e[i+1],ki[2]=e[i+2],Ei[0]=e[s],Ei[1]=e[s+1],Ei[2]=e[s+2],Fi[0]=e[a],Fi[1]=e[a+1],Fi[2]=e[a+2],Ae.cross3Vec3(ki,Ei,ki),n+=Ae.dotVec3(ki,Fi)}return n/6}}]),e}(),Ui=new xi,Ii=Ae.vec3(),Ti=Ae.vec3(),Pi=Ae.vec3(),Si=Ae.vec3(),Di=Ae.vec3(),Qi=Ae.vec3(),Ri=function(){function e(){x(this,e),this.vertices=[],this.indices=[],this.reset()}return I(e,[{key:"reset",value:function(){this.lenVertices=0,this.lenIndices=0}},{key:"addVertex",value:function(e){this.vertices[this.lenVertices++]=e[0],this.vertices[this.lenVertices++]=e[1],this.vertices[this.lenVertices++]=e[2]}},{key:"addIndex",value:function(e){this.indices[this.lenIndices++]=e}},{key:"surfaceArea",get:function(){for(var e=this.vertices,t=this.indices,n=0,r=0;r<this.lenIndices;r+=3){var i=3*t[r],s=3*t[r+1],a=3*t[r+2];Ii[0]=e[i],Ii[1]=e[i+1],Ii[2]=e[i+2],Ti[0]=e[s],Ti[1]=e[s+1],Ti[2]=e[s+2],Pi[0]=e[a],Pi[1]=e[a+1],Pi[2]=e[a+2],Ae.subVec3(Ii,Ti,Si),Ae.subVec3(Pi,Ti,Di),n+=.5*Ae.lenVec3(Ae.cross3Vec3(Si,Di,Qi))}return n}}]),e}(),Oi=new Ri,Vi=Ae.OBB3(),Li=Ae.OBB3(),Hi=Ae.OBB3(),Ni=function(){function e(t,n,r,i,s,a){var o=arguments.length>6&&void 0!==arguments[6]?arguments[6]:null,A=arguments.length>7&&void 0!==arguments[7]?arguments[7]:0;x(this,e),this.model=t,this.object=null,this.parent=null,this.transform=s,this.textureSet=a,this._matrixDirty=!1,this._matrixUpdateScheduled=!1,this.id=n,this.obb=null,this._aabbLocal=null,this._aabbWorld=Ae.AABB3(),this._aabbWorldDirty=!1,this.layer=o,this.portionId=A,this._color=new Uint8Array([r[0],r[1],r[2],i]),this._colorize=new Uint8Array([r[0],r[1],r[2],i]),this._colorizing=!1,this._transparent=i<255,this.numTriangles=0,this.origin=null,this.entity=null,s&&s._addMesh(this),this._volume=null,this._surfaceArea=null}return I(e,[{key:"_sceneModelDirty",value:function(){this._aabbWorldDirty=!0,this.layer.aabbChanged()}},{key:"_transformDirty",value:function(){this._matrixDirty||this._matrixUpdateScheduled||(this.model._meshMatrixDirty(this),this._matrixDirty=!0,this._matrixUpdateScheduled=!0),this._aabbWorldDirty=!0,this.layer.aabbChanged(),this.entity&&this.entity._transformDirty()}},{key:"_updateMatrix",value:function(){this.transform&&this._matrixDirty&&this.layer.setMatrix(this.portionId,this.transform.worldMatrix),this._matrixDirty=!1,this._matrixUpdateScheduled=!1}},{key:"_finalize",value:function(e){this.layer.initFlags(this.portionId,e,this._transparent)}},{key:"_finalize2",value:function(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}},{key:"_setVisible",value:function(e){this.layer.setVisible(this.portionId,e,this._transparent)}},{key:"_setColor",value:function(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}},{key:"_setColorize",value:function(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}},{key:"_setOpacity",value:function(e,t){var n=e<255,r=this._transparent!==n;this._color[3]=e,this._colorize[3]=e,this._transparent=n,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),r&&this.layer.setTransparent(this.portionId,t,n)}},{key:"_setOffset",value:function(e){this.layer.setOffset(this.portionId,e)}},{key:"_setHighlighted",value:function(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}},{key:"_setXRayed",value:function(e){this.layer.setXRayed(this.portionId,e,this._transparent)}},{key:"_setSelected",value:function(e){this.layer.setSelected(this.portionId,e,this._transparent)}},{key:"_setEdges",value:function(e){this.layer.setEdges(this.portionId,e,this._transparent)}},{key:"_setClippable",value:function(e){this.layer.setClippable(this.portionId,e,this._transparent)}},{key:"_setCollidable",value:function(e){this.layer.setCollidable(this.portionId,e)}},{key:"_setPickable",value:function(e){this.layer.setPickable(this.portionId,e,this._transparent)}},{key:"_setCulled",value:function(e){this.layer.setCulled(this.portionId,e,this._transparent)}},{key:"canPickTriangle",value:function(){return!1}},{key:"drawPickTriangles",value:function(e,t){}},{key:"pickTriangleSurface",value:function(e){}},{key:"precisionRayPickSurface",value:function(e,t,n,r){return this.layer.precisionRayPickSurface(this.portionId,e,t,n,r)}},{key:"canPickWorldPos",value:function(){return!0}},{key:"drawPickDepths",value:function(e){this.model.drawPickDepths(e)}},{key:"drawPickNormals",value:function(e){this.model.drawPickNormals(e)}},{key:"delegatePickedEntity",value:function(){return this.parent}},{key:"getEachVertex",value:function(e){this.layer.getEachVertex&&this.layer.getEachVertex(this.portionId,e)}},{key:"getEachIndex",value:function(e){this.layer.getEachIndex&&this.layer.getEachIndex(this.portionId,e)}},{key:"isSolid",value:function(){return this.layer.solid}},{key:"volume",get:function(){if(null!==this._volume)return this._volume;switch(this.layer.primitive){case"solid":case"surface":case"triangles":Ui.reset(),Ui.setPrimitive(this.layer.primitive),this.getEachVertex((function(e){Ui.addVertex(e)})),this.getEachIndex((function(e){Ui.addIndex(e)})),this._volume=Ui.volume;break;default:this._volume=0}return this._volume}},{key:"surfaceArea",get:function(){if(null!==this._surfaceArea)return this._surfaceArea;switch(this.layer.primitive){case"solid":case"surface":case"triangles":Oi.reset(),this.getEachVertex((function(e){Oi.addVertex(e)})),this.getEachIndex((function(e){Oi.addIndex(e)})),this._surfaceArea=Oi.surfaceArea;break;default:this._surfaceArea=0}return this._surfaceArea}},{key:"aabb",get:function(){return this._aabbWorldDirty&&(Ae.AABB3ToOBB3(this._aabbLocal,Vi),this.transform?(Ae.transformOBB3(this.transform.worldMatrix,Vi,Li),Ae.transformOBB3(this.model.worldMatrix,Li,Hi),Ae.OBB3ToAABB3(Hi,this._aabbWorld)):(Ae.transformOBB3(this.model.worldMatrix,Vi,Li),Ae.OBB3ToAABB3(Li,this._aabbWorld)),this._aabbWorldDirty=!1),this._aabbWorld},set:function(e){if(this._aabbLocal=e,this.origin){this._aabbLocal=e.slice(0);var t=this.origin;this._aabbLocal[0]+=t[0],this._aabbLocal[1]+=t[1],this._aabbLocal[2]+=t[2],this._aabbLocal[3]+=t[0],this._aabbLocal[4]+=t[1],this._aabbLocal[5]+=t[2]}}},{key:"_destroy",value:function(){this.model.scene._renderer.putPickID(this.pickId)}}]),e}(),Gi=1,ji=4,Wi=8,zi=16,Xi=32,Ki=256,Zi=512,Ji=1024,Yi=2048,qi=function(e,t,n,r){var i=r&&e.createUniform("vec4","edgeColor",(function(e,t){return e(t.legacyFrameCtx.programColor)})),s=t.attributes.color,a=!r&&e.createVarying("vec4","vColor",(function(){return"vec4(".concat(s,".rgb * 0.5, ").concat(s,".a)")})),o=e.createOutput("vec4","outColor");return{programName:r?"Edges":"EdgesColor",getLogDepth:n&&function(e){return e},renderPassFlag:2,appendFragmentOutputs:function(e){return e.push("".concat(o," = ").concat(i||a,";"))}}},$i=function(e,t){var n=e.createOutput("vec4","outColor");return{programName:"Occlusion",getLogDepth:!1,renderPassFlag:0,appendFragmentOutputs:function(e){return e.push("".concat(n," = vec4(0.0, 0.0, 1.0, 1.0);"))}}},es=function(e,t,n,r){var i=e.createUniform("vec4","silhouetteColor",(function(e,t){return e(t.legacyFrameCtx.programColor)})),s=e.createVarying("float","vAlpha",(function(){return"".concat(t.attributes.color,".a")})),a=e.createOutput("vec4","outColor");return{programName:"Silhouette",getLogDepth:n&&function(e){return e},renderPassFlag:1,appendFragmentOutputs:function(e,t,n,o){e.push("".concat(a," = ").concat(r?i:o("vec4(".concat(i,".rgb, min(").concat(i,".a, ").concat(s,"))")),";"))}}},ts=Ae.vec2(),ns=Ae.vec3(),rs=Ae.vec4(),is=Ae.mat4(),ss=Ae.vec3([0,0,0]),as=0,os=1,As=2,cs=3,ls=4,us=5,hs=6,ds=7,fs=8,ps=9,vs=10,gs=11,ms=function(e){return[Ae.safeInv(e[0]),Ae.safeInv(e[1]),Ae.safeInv(e[2])]},ys=function(e,t,n,r,i){var s,a,o=!!(e&Gi),A=!!(e&Ki),c=!!(e&Zi),l=!!(e&Ji),u=!!(e&Yi),h=!!(e&Wi),d=!!(e&ji);s=!o||d||A||c&&!r.highlightMaterial.glowThrough||l&&!r.selectedMaterial.glowThrough?as:t?As:os,a=!o||d?as:l?ls:c?cs:A?us:as;var f=0;f=n&&o&&!d?l?ps:c?fs:A?vs:u?t?ds:hs:as:as;var p=o&&!d&&h?gs:as;i[0]=s,i[1]=a,i[2]=f,i[3]=p},_s=(Ai={},function(e,t,n,r,i,s,a,o){var A=[t,"points"===n||"lines"===n?n:"triangles",!!r,!!i,!!s,!!a].join(":");A in Ai||(Ai[A]={});var c,l,u,h=Ai[A],d=e.id;if(!(d in h)){var f=e.canvas.gl,p=function(r,i,s){var a=function(){var s=gr(),a=s.programVariables,A=o(a,i);return r(a,A.geometryParameters,(function(r,o){var c,l=e.pointsMaterial,u="points"===n&&!i,h=function(){return[e._sectionPlanesState.getHash()].concat(u?[l.hash]:[]).concat(r.getHash?r.getHash():[]).join(";")},d=h(),p=function(){return d===h()},v=A.geometryParameters,g=r.incrementDrawState,m=r.isShadowProgram,y=v.attributes,_=y.position.world,b="clipPos",w=k(s.buildProgram(f,t+" "+n+" "+r.programName,{appendFragmentOutputs:r.appendFragmentOutputs,cleanerEdges:r.cleanerEdges,clipPos:b,clippableTest:(c=a.createVarying("float","vClippable",(function(){return"".concat(y.clippable," ? 1.0 : 0.0")}),"flat"),function(){return"".concat(c," > 0.0")}),clippingCaps:r.clippingCaps,crossSections:e.crossSections,discardPoints:u&&l.roundPoints,getGammaFactor:e.gammaOutput&&function(){return e.gammaFactor},getLogDepth:r.getLogDepth,getPointSize:function(){var e=[];if(u){var t=a.createUniform("float","pointSize",(function(e){return e(l.pointSize)}));if(l.perspectivePoints){var s=a.createUniform("float","nearPlaneHeight",(function(e,t){return e(t.legacyFrameCtx.nearPlaneHeight)})),o="".concat(Math.floor(l.minPerspectivePointSize),".0"),A="".concat(Math.floor(l.maxPerspectivePointSize),".0");e.push("clamp((".concat(s," * ").concat(t,") / gl_Position.w, ").concat(o,", ").concat(A,")"))}else e.push(t)}else i&&i.vertices&&e.push("1.0");return r.incPointSizeBy10&&"points"===n&&e.push("10.0"),e.length>0&&function(){return e.join(" + ")}}(),getVertexData:function(){var e,t=y.color,i=y.flags[r.renderPassFlag],s=a.createUniform("int","renderPass",(function(e,t){return e(t.renderPass)})),o=m?"(".concat(i," <= 0) || (").concat(t,".a < 1.0)"):"".concat(i," != ").concat(s),c=["if (".concat(o,") {")," gl_Position = vec4(".concat(r.vertexCullX||0,", 0.0, 0.0, 0.0);")," return;","}"].concat(A.dontCullOnAlphaZero||r.dontCullOnAlphaZero?[]:["if (".concat(t,".a == 0.0) {")," gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"," return;","}"]).concat(r.filterIntensityRange&&"points"===n&&l.filterIntensity?(e=a.createUniform("vec2","intensityRange",(function(e){ts[0]=l.minIntensity,ts[1]=l.maxIntensity,e(ts)})),["if ((".concat(t,".a < ").concat(e,"[0]) || (").concat(t,".a > ").concat(e,"[1])) {")," gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"," return;","}"]):[]),u=[];A.ensureColorAndFlagAvailable&&A.ensureColorAndFlagAvailable(u),c.forEach((function(e){return u.push(e)})),A.appendVertexData(u);var h=v.attributes.position.view;return u.push("vec4 ".concat(h," = ").concat(v.viewMatrix," * ").concat(_,";")),u.push("vec4 ".concat(b," = ").concat(v.projMatrix," * ").concat(h,";")),u},projMatrix:v.projMatrix,sectionPlanesState:e._sectionPlanesState,testPerspectiveForGl_FragDepth:"points"!==n&&"lines"!==n||i,usePickClipPos:o,worldPositionAttribute:_}),2),B=w[0],C=w[1];return C?(console.error(C),{getValid:p,destroy:function(){},drawLayer:function(e,t,n){}}):{getValid:p,destroy:function(){return B.destroy()},drawLayer:function(e,t,n){e.lastProgramId!==B.id&&(e.lastProgramId=B.id,B.bind());var r=t.origin,s=t.model,a=e.viewParams,o=ns;Ae.transformPoint3(s.matrix,r,o);var c=a.viewMatrix,l=a.projMatrix;e.snapPickOrigin&&(e.snapPickOrigin[0]=o[0],e.snapPickOrigin[1]=o[1],e.snapPickOrigin[2]=o[2]);var u={legacyFrameCtx:e,layerTextureSet:t.layerTextureSet,mesh:{layerIndex:t.layerIndex,origin:o,renderFlags:{sectionPlanesActivePerLayer:s.renderFlags.sectionPlanesActivePerLayer}},renderPass:n,view:{eye:a.eye,far:a.far,projMatrix:l,viewMatrix:Ae.compareVec3(o,ss)?c:Zt(c,o,is),viewNormalMatrix:a.viewNormalMatrix}};B.inputSetters.setUniforms(e,u),t.drawCalls[i?i.vertices?"drawVertices":"drawEdges":"drawSurface"](B.inputSetters.attributesHash,A.layerTypeInputs,{projMatrix:l,viewMatrix:Ae.compareVec3(o,ss)?c:Zt(c,o,is),viewNormalMatrix:a.viewNormalMatrix,eye:a.eye}),g&&e.drawElements++}}}))},A=s&&a();return{drawLayer:function(e,t,n){A||(A=a()),A.drawLayer(e,t,n)},revalidate:function(e){!A||!e&&A.getValid()||(A.destroy(),A=s&&a())}}},v=function(e,t){return p(e,t,!0)},g=function(e,t){return p(e,t,!1)},m=function(t,r,i,s){return function(e,t,n,r,i,s){var a=e.createVarying("vec4","vColor",(function(){var e=t.attributes,n="points"===s?"vec4(".concat(e.color,".rgb, 1.0)"):"".concat(e.color);if(r){var i=[r.getAmbientColor()].concat(r.directionalLights.map((function(n){return"max(dot(".concat(e.normal.view,", ").concat(n.getDirection(t.viewMatrix,e.position.view),"), 0.0) * ").concat(n.getColor())})));return"vec4(".concat(i.join(" + "),", 1) * ").concat(n)}return n})),o=e.createOutput("vec4","outColor");return{programName:"Color",getHash:function(){return[r?r.getHash():"-",i?"sao":"nosao"]},cleanerEdges:!0,getLogDepth:n&&function(e){return"points"!==s&&"lines"!==s?"".concat(e," + length(vec2(dFdx(").concat(e,"), dFdy(").concat(e,")))"):e},renderPassFlag:0,appendFragmentOutputs:function(e,t,n,r){"points"===s||"lines"===s?e.push("".concat(o," = ").concat(a,";")):(e.push("vec4 fragColor = ".concat(r(a),";")),e.push("".concat(o," = ").concat(i?"vec4(fragColor.rgb * ".concat(i.getAmbient(n),", fragColor.a)"):"fragColor",";")))},filterIntensityRange:!0,incrementDrawState:!0}}(t,r,e.logarithmicDepthBufferEnabled,i,s,n)},y=function(t,n,r){return r((i=t,s=n,a=e.logarithmicDepthBufferEnabled,o=i.createUniform("float","far",(function(e,t){return e(t.legacyFrameCtx.viewParams.far)})),A=i.createUniform("float","near",(function(e,t){return e(t.legacyFrameCtx.viewParams.near)})),c=i.createVarying("vec3","vViewPosition",(function(){return"".concat(s.attributes.position.view,".xyz")})),l=i.createOutput("vec4","outPackedDepth"),u=i.createFragmentDefinition("packDepth",(function(e,t){t.push("vec4 ".concat(e,"(const in float depth) {")),t.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),t.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),t.push(" vec4 res = fract(depth * bitShift);"),t.push(" res -= res.xxyz * bitMask;"),t.push(" return res;"),t.push("}")})),{programName:"PickDepth",getLogDepth:a&&function(e){return e},renderPassFlag:3,incPointSizeBy10:!0,appendFragmentOutputs:function(e){e.push("float zNormalizedDepth = abs((".concat(A," + ").concat(c,".z) / (").concat(o," - ").concat(A,"));")),e.push("".concat(l," = ").concat(u,"(zNormalizedDepth);"))}}),!0);var i,s,a,o,A,c,l,u},_=function(t,n,r){return r((i=t,s=n,a=e.logarithmicDepthBufferEnabled,o=i.createVarying("vec4","vPickColor",(function(){return"".concat(s.attributes.pickColor," / 255.0")})),A=i.createOutput("vec4","outPickColor"),{programName:"PickMesh",getLogDepth:a&&function(e){return e},renderPassFlag:3,incPointSizeBy10:!0,dontCullOnAlphaZero:!0,appendFragmentOutputs:function(e){return e.push("".concat(A," = ").concat(o,";"))}}),!0);var i,s,a,o,A},b=function(t,n,r,i){return r(function(e,t,n,r){var i=e.createVarying("vec3","vWorldPosition",(function(){return"".concat(t.attributes.position.world,".xyz")})),s=e.createVarying("vec3","vWorldNormal",(function(){return t.attributes.normal.world})),a=e.createOutput("highp ivec4","outNormal");return{programName:r?"PickNormalsFlat":"PickNormals",getLogDepth:n&&function(e){return e},renderPassFlag:3,appendFragmentOutputs:function(e){var t=r?"normalize(cross(dFdx(".concat(i,"), dFdy(").concat(i,")))"):s;e.push("".concat(a," = ivec4(").concat(t," * float(").concat(Ae.MAX_INT,"), 1.0);"))}}}(t,n,e.logarithmicDepthBufferEnabled,i),!0)},w=function(e,t,n,r,i){return n(function(e,t,n,r){var i=e.createUniform("int","layerNumber",(function(e,t){return e(t.legacyFrameCtx.snapPickLayerParams.length)})),s=e.createUniform("vec3","coordinateScaler",(function(e,t){return e(t.legacyFrameCtx.snapPickCoordinateScale)})),a=e.createVarying("vec3","vWorldPosition",(function(){return"".concat(t.attributes.position.world,".xyz")})),o=e.createVarying("vec4","vPickColor",(function(){return t.attributes.pickColor}),"flat"),A=e.createOutput("highp ivec4","outCoords",0),c=e.createOutput("highp ivec4","outNormal",1),l=e.createOutput("lowp uvec4","outPickColor",2);return{programName:n?"SnapInit":"Snap",getLogDepth:function(e){return n?"".concat(e," + length(vec2(dFdx(").concat(e,"), dFdy(").concat(e,")))"):e},renderPassFlag:3,vertexCullX:!n&&"2.0",dontCullOnAlphaZero:!n,appendFragmentOutputs:function(e){e.push("".concat(A," = ivec4(").concat(a," * ").concat(s,".xyz, ").concat(n?"-":"").concat(i,");")),n&&(e.push("".concat(c," = ").concat(r?"ivec4(1.0)":"ivec4(normalize(cross(dFdx(".concat(a,"), dFdy(").concat(a,"))) * float(").concat(Ae.MAX_INT,"), 1.0)"),";")),e.push("".concat(l," = uvec4(").concat(o,");")))}}}(e,t,r,i),!0)};h[d]="points"===n?{colorRenderers:{"sao-":{vertex:g((function(e,t,n){return n(m(e,t,null,null))}))}},occlusionRenderer:g((function(t,n,r){return r($i(t,e.logarithmicDepthBufferEnabled))})),pickDepthRenderer:g(y),pickMeshRenderer:g(_),silhouetteRenderer:g((function(t,n,r){return r(es(t,n,e.logarithmicDepthBufferEnabled,!0))})),snapInitRenderer:g((function(e,t,n){return w(e,t,n,!0,!0)})),snapVertexRenderer:g((function(e,t,n){return w(e,t,n,!1,!0)}),{vertices:!0})}:"lines"===n?{colorRenderers:{"sao-":{vertex:g((function(e,t,n){return n(m(e,t,null,null))}))}},silhouetteRenderer:g((function(t,n,r){return r(es(t,n,e.logarithmicDepthBufferEnabled,!0))})),snapInitRenderer:g((function(e,t,n){return w(e,t,n,!0,!1)})),snapEdgeRenderer:g((function(e,t,n){return w(e,t,n,!1,!1)}),{vertices:!1}),snapVertexRenderer:g((function(e,t,n){return w(e,t,n,!1,!1)}),{vertices:!0})}:{colorRenderers:(c=function(t){return mr(t,e._lightsState)},l=function(e){var t=e.createUniform("vec4","uSAOParams",(function(e,t){return e(t.legacyFrameCtx.saoParams)})),n=yr(e,"sampler2D","uOcclusionTexture",3e3,(function(e,t){return e(t.legacyFrameCtx.occlusionTexture)}));return{getAmbient:function(e){var r="".concat(e,".xy / ").concat(t,".xy"),i="".concat(t,".z"),s="".concat(t,".w");return"(smoothstep(".concat(i,", 1.0, dot(").concat(n(r),", ").concat("(255. / 256.) / vec4(256. * 256. * 256., 256. * 256., 256., 1.)",")) * ").concat(s,")")}}},u=function(t){var n=function(n,r,i){return function(e,t,n,r,i,s,a){var o=yr(e,"sampler2D","uColorMap",3001,(function(e,t){var n=t.layerTextureSet.colorTexture;n&&e(n.texture)})),A=s&&e.createUniform("float","materialAlphaCutoff",(function(e,t){return e(t.layerTextureSet.alphaCutoff)})),c=t.attributes,l=e.createVarying("vec3","vViewPosition",(function(){return"".concat(c.position.view,".xyz")})),u=e.createVarying("vec2","vUV",(function(){return c.uv})),h=e.createVarying("vec4","vColor",(function(){return c.color})),d=e.createOutput("vec4","outColor");return{programName:"ColorTexture",getHash:function(){return[r.getHash(),i?"sao":"nosao",!!a,s?"alphaCutoffYes":"alphaCutoffNo"]},getLogDepth:n.logarithmicDepthBufferEnabled&&function(e){return e},renderPassFlag:0,appendFragmentOutputs:function(e,n,s,a){e.push("vec3 viewNormal = normalize(cross(dFdx(".concat(l,"), dFdy(").concat(l,")));")),e.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),r.directionalLights.forEach((function(n){e.push("reflectedColor += max(dot(viewNormal, ".concat(n.getDirection(t.viewMatrix,l),"), 0.0) * ").concat(n.getColor(),";"))})),e.push("vec4 color = vec4(".concat(r.getAmbientColor()," + reflectedColor, 1) * ").concat(a(h),";")),e.push("vec4 sampleColor = ".concat(o(u),";")),A&&e.push("if (sampleColor.a < ".concat(A,") { discard; }")),e.push("vec4 colorTexel = color * sampleColor;"),e.push("".concat(d," = vec4(colorTexel.rgb").concat(i?" * "+i.getAmbient(s):"",", color.a);")),n&&e.push("".concat(d," = ").concat(n(d),";"))},incrementDrawState:!0}}(n,r,e,c(n),t&&l(n),i,e.gammaOutput)};return{PBR:i&&g((function(n,r,i){return i(function(e,t,n,r,i){var s=function(t,n,r){return yr(e,"sampler2D",t,n?3001:3e3,(function(e,t){var n=r(t.layerTextureSet);n&&e(n.texture)}))},a=t.attributes,o=r.getIrradiance,A=s("uColorMap",!0,(function(e){return e.colorTexture})),c=s("uMetallicRoughMap",!1,(function(e){return e.metallicRoughnessTexture})),l=s("uEmissiveMap",!0,(function(e){return e.emissiveTexture})),u=s("uNormalMap",!1,(function(e){return e.normalsTexture})),h=s("uAOMap",!1,(function(e){return e.occlusionTexture})),d=e.createVarying("vec3","vViewPosition",(function(){return"".concat(a.position.view,".xyz")})),f=e.createVarying("vec3","vViewNormal",(function(){return a.normal.view})),p=e.createVarying("vec4","vColor",(function(){return a.color})),v=e.createVarying("vec2","vUV",(function(){return a.uv})),g=e.createVarying("vec2","vMetallicRoughness",(function(){return a.metallicRoughness})),m=e.createVarying("vec3","vWorldNormal",(function(){return"".concat(a.normal.world,".xyz")})),y=e.createOutput("vec4","outColor"),_=e.createFragmentDefinition("saturate",(function(e,t){return t.push("float ".concat(e,"(const in float a) { return clamp(a, 0.0, 1.0); }"))})),b=e.createFragmentDefinition("BRDF_Specular_GGX",(function(e,t){t.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),t.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),t.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),t.push("}"),t.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" return 1.0 / ( gl * gv );"),t.push("}"),t.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" return 0.5 / max( gv + gl, 1e-6 );"),t.push("}"),t.push("float D_GGX(const in float alpha, const in float dotNH) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),t.push(" return 0.31830988618 * a2 / ( denom * denom);"),t.push("}"),t.push("vec3 ".concat(e,"(const in vec3 incidentLightDirection, const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {")),t.push(" float alpha = ( roughness * roughness );"),t.push(" vec3 halfDir = normalize( incidentLightDirection + viewEyeDir );"),t.push(" float dotNL = ".concat(_,"( dot( viewNormal, incidentLightDirection ) );")),t.push(" float dotNV = ".concat(_,"( dot( viewNormal, viewEyeDir ) );")),t.push(" float dotNH = ".concat(_,"( dot( viewNormal, halfDir ) );")),t.push(" float dotLH = ".concat(_,"( dot( incidentLightDirection, halfDir ) );")),t.push(" vec3 F = F_Schlick( specularColor, dotLH );"),t.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),t.push(" float D = D_GGX( alpha, dotNH );"),t.push(" return F * (G * D);"),t.push("}")})),w=e.createFragmentDefinition("BRDF_Specular_GGX_Environment",(function(e,t){t.push("vec3 ".concat(e,"(const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {")),t.push(" float dotNV = ".concat(_,"(dot(viewNormal, viewEyeDir));")),t.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),t.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),t.push(" vec4 r = roughness * c0 + c1;"),t.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),t.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),t.push(" return specularColor * AB.x + AB.y;"),t.push("}")})),B=e.createFragmentDefinition("perturbNormal2Arb",(function(e,t){t.push("vec3 ".concat(e,"( vec3 eye_pos, vec3 surf_norm, vec2 uv, vec4 texel ) {")),t.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),t.push(" return surf_norm;"),t.push(" }"),t.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),t.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),t.push(" vec2 st0 = dFdx( uv.st );"),t.push(" vec2 st1 = dFdy( uv.st );"),t.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),t.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),t.push(" vec3 N = normalize( surf_norm );"),t.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),t.push(" mat3 tsn = mat3( S, T, N );"),t.push(" return normalize( tsn * mapN );"),t.push("}")}));return{programName:"PBR",getHash:function(){return[r.getHash(),i?"sao":"nosao",!!n.gammaOutput]},getLogDepth:n.logarithmicDepthBufferEnabled&&function(e){return e},renderPassFlag:0,clippingCaps:n._sectionPlanesState.clippingCaps&&y,incrementDrawState:!0,appendFragmentOutputs:function(e,n,s){if(e.push("const float PI = 3.14159265359;"),e.push("vec3 reflDiff = vec3(0.0);"),e.push("vec3 reflSpec = vec3(0.0);"),e.push("vec3 rgb = ".concat(p,".rgb;")),e.push("float opacity = ".concat(p,".a;")),e.push("vec3 baseColor = rgb;"),e.push("float specularF0 = 1.0;"),e.push("float metallic = float(".concat(g,".r) / 255.0;")),e.push("float roughness = float(".concat(g,".g) / 255.0;")),e.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),e.push("vec4 colorTexel = ".concat(A(v),";")),e.push("baseColor *= colorTexel.rgb;"),e.push("vec3 metalRoughTexel = ".concat(c(v),".rgb;")),e.push("metallic *= metalRoughTexel.b;"),e.push("roughness *= metalRoughTexel.g;"),e.push("vec3 diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),e.push("float specularRoughness = clamp(roughness, 0.04, 1.0);"),e.push("vec3 specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),e.push("vec3 viewNormal = -".concat(B,"(").concat(d,", normalize(").concat(f,"), ").concat(v,", ").concat(u(v),");")),e.push("vec3 viewEyeDir = normalize(".concat(d,");")),o&&e.push("reflDiff += ".concat(o("normalize(".concat(m,")")),";")),r.getReflection){var a="normalize((vec4(".concat("reflect(viewEyeDir, viewNormal)",", 0.0) * ").concat(t.viewMatrix,").xyz)"),C="".concat("8.0"," - 0.79248 - 0.5 * log2(pow(").concat("(2.0 / pow(specularRoughness + 0.0001, 2.0) - 2.0)",", 2.0) + 1.0)"),M="0.5 * clamp(".concat(C,", 0.0, ").concat("8.0",")"),k=r.getReflection(a,M),E="".concat(w,"(viewNormal, viewEyeDir, specularColor, specularRoughness)");e.push("reflSpec += ".concat(k," * ").concat(E,";"))}r.directionalLights.forEach((function(n,r){e.push("vec3 lightDirection".concat(r," = -").concat(n.getDirection(t.viewMatrix,d),";"));var i="".concat(_,"(dot(viewNormal, lightDirection").concat(r,"))");e.push("vec3 irradiance".concat(r," = ").concat(i," * ").concat(n.getColor(),";")),e.push("reflDiff += irradiance".concat(r,";")),e.push("reflSpec += irradiance".concat(r," * PI * ").concat(b,"(lightDirection").concat(r,", viewNormal, viewEyeDir, specularColor, specularRoughness);"))})),e.push("vec3 emissiveColor = ".concat(l(v),".rgb;")),e.push("float aoFactor = ".concat(h(v),".r;"));var F="".concat(r.getAmbientColor()," * baseColor * opacity * rgb");e.push("vec3 outgoingLight = emissiveColor + reflDiff * diffuseColor + reflSpec + ".concat(F,";")),e.push("".concat(y," = vec4(outgoingLight * aoFactor").concat(i?" * ".concat(i.getAmbient(s)):"",", opacity);")),n&&e.push("".concat(y," = ").concat(n(y),";"))}}}(n,r,e,c(n),t&&l(n)))})),texture:s&&{"alphaCutoff-":g((function(e,t,r){return r(n(e,t,!1))})),"alphaCutoff+":g((function(e,t,r){return r(n(e,t,!0))}))},vertex:g(a?function(e,n,r){return r(m(e,n,c(e),t&&l(e)))}:function(n,r,i){return i((s=n,a=r,o=e.logarithmicDepthBufferEnabled,A=c(n),u=t&&l(n),h=a.attributes,d=s.createVarying("vec3","vViewPosition",(function(){return"".concat(h.position.view,".xyz")})),f=s.createVarying("vec4","vColor",(function(){return h.color})),p=s.createOutput("vec4","outColor"),{programName:"FlatColor",getHash:function(){return[A.getHash(),u?"sao":"nosao"]},cleanerEdges:!0,getLogDepth:o&&function(e){return e},renderPassFlag:0,appendFragmentOutputs:function(e,t,n,r){e.push("vec3 viewNormal = normalize(cross(dFdx(".concat(d,"), dFdy(").concat(d,")));"));var i=[A.getAmbientColor()].concat(A.directionalLights.map((function(e){return"max(dot(viewNormal, ".concat(e.getDirection(a.viewMatrix,d),"), 0.0) * ").concat(e.getColor())})));e.push("vec4 fragColor = vec4(".concat(i.join(" + "),", 1) * ").concat(r(f),";")),e.push("".concat(p," = ").concat(u?"vec4(fragColor.rgb * ".concat(u.getAmbient(n),", fragColor.a)"):"fragColor",";"))}}));var s,a,o,A,u,h,d,f,p})}},{"sao-":u(!1),"sao+":r&&u(!0)}),depthRenderer:g((function(t,n,r){return r((i=t,s=n,a=e.logarithmicDepthBufferEnabled,o=i.createVarying("highp vec2","vHighPrecisionZW",(function(){return"".concat(s.attributes.position.clip,".zw")})),A=i.createOutput("vec4","outColor"),{programName:"Depth",getLogDepth:a&&function(e){return e},renderPassFlag:0,appendFragmentOutputs:function(e){return e.push("".concat(A," = vec4(vec3((1.0 - ").concat(o,"[0] / ").concat(o,"[1]) / 2.0), 1.0);"))}}));var i,s,a,o,A})),edgesRenderers:{uniform:g((function(t,n,r){return r(qi(t,n,e.logarithmicDepthBufferEnabled,!0))}),{vertices:!1}),vertex:g((function(t,n,r){return r(qi(t,n,e.logarithmicDepthBufferEnabled,!1))}),{vertices:!1})},occlusionRenderer:g((function(t,n,r){return r($i(t,e.logarithmicDepthBufferEnabled))})),pickDepthRenderer:v(y),pickMeshRenderer:v(_),pickNormalsFlatRenderer:v((function(e,t,n){return b(e,t,n,!0)})),pickNormalsRenderer:v((function(e,t,n){return b(e,t,n,!1)})),shadowRenderer:g((function(t,n,r){return r((s=e,a=(i=t).createOutput("vec4","outColor"),o=i.createFragmentDefinition("encodeFloat",(function(e,t){t.push("vec4 ".concat(e,"(const in float v) {")),t.push(" const vec4 bitShift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);"),t.push(" const vec4 bitMask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);"),t.push(" vec4 comp = fract(v * bitShift);"),t.push(" comp -= comp.xxyz * bitMask;"),t.push(" return comp;"),t.push("}")})),{programName:"Shadow",getLogDepth:s&&function(e){return e},renderPassFlag:0,isShadowProgram:!0,appendFragmentOutputs:function(e,t,n){return e.push("".concat(a," = ").concat(o,"(").concat(n,".z);"))}}));var i,s,a,o})),silhouetteRenderer:v((function(t,n,r){return r(es(t,n,e.logarithmicDepthBufferEnabled,!1))})),snapInitRenderer:v((function(e,t,n){return w(e,t,n,!0,!1)})),snapEdgeRenderer:v((function(e,t,n){return w(e,t,n,!1,!1)}),{vertices:!1}),snapVertexRenderer:v((function(e,t,n){return w(e,t,n,!1,!1)}),{vertices:!0})};var B=function(){return e=!1,void function t(n){n.revalidate?n.revalidate(e):Object.values(n).forEach((function(e){return e&&t(e)}))}(h[d]);var e};B(),e.on("compile",B),e.on("destroyed",(function(){delete h[d]}))}return h[d]}),bs=function(){function e(t,n,r){x(this,e),this.model=t,this.primitive=n,this.origin=r,this._meshes=[],this._aabb=Ae.collapseAABB3(),this._aabbDirty=!0}return I(e,[{key:"finalize",value:function(){var e=this;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,this._countsByFlag={};var t=function(t,n){var r={count:0,fromFlags:function(i,s){i&t?(r.count++,e.model[n]++):s||(r.count--,e.model[n]--)}};e._countsByFlag[t]=r};t(Gi,"numVisibleLayerPortions"),t(ji,"numCulledLayerPortions"),t(Wi,"numPickableLayerPortions"),t(zi,"numClippableLayerPortions"),t(Ki,"numXRayedLayerPortions"),t(Zi,"numHighlightedLayerPortions"),t(Ji,"numSelectedLayerPortions"),this._renderers.edgesRenderers&&t(Yi,"numEdgesLayerPortions"),this._countsByFlagArr=Object.values(this._countsByFlag),this._numTransparentLayerPortions=0}}},{key:"aabbChanged",value:function(){this._aabbDirty=!0}},{key:"__drawLayer",value:function(e,t,n,r){if(this._countsByFlag[ji].count<this._portions.length&&this._countsByFlag[Gi].count>0){var i="points"!==this.primitive&&"lines"!==this.primitive&&[os,As,gs,cs,ls,us];if(i&&i.includes(r)){if(true!==t.backfaces){var s=this.model.scene.canvas.gl;s.disable(s.CULL_FACE),t.backfaces=true}}t.textureUnit=0,n.drawLayer(t,this,r)}}},{key:"__setVec4FromMaterialColorAlpha",value:function(e,t,n){return n[0]=e[0],n[1]=e[1],n[2]=e[2],n[3]=t,n}},{key:"__drawColor",value:function(e,t,n){if((n?this._numTransparentLayerPortions<this._portions.length:this._numTransparentLayerPortions>0)&&this._countsByFlag[Ki].count<this._portions.length){var r=n&&t.withSAO&&this._renderers.colorRenderers["sao+"]||this._renderers.colorRenderers["sao-"],i=t.pbrEnabled&&r.PBR?r.PBR:t.colorTextureEnabled&&r.texture?r.texture[this.layerTextureSet&&"number"==typeof this.layerTextureSet.alphaCutoff?"alphaCutoff+":"alphaCutoff-"]:r.vertex,s=n?os:As;this.__drawLayer(e,t,i,s)}}},{key:"drawColorOpaque",value:function(e,t){this.__drawColor(e,t,!0)}},{key:"drawColorTransparent",value:function(e,t){this.__drawColor(e,t,!1)}},{key:"drawDepth",value:function(e,t){var n=this._renderers.depthRenderer;n&&this._numTransparentLayerPortions<this._portions.length&&this._countsByFlag[Ki].count<this._portions.length&&this.__drawLayer(e,t,n,os)}},{key:"__drawSilhouette",value:function(e,t,n,r){t.programColor=this.__setVec4FromMaterialColorAlpha(n.fillColor,n.fillAlpha,rs),this.__drawLayer(e,t,this._renderers.silhouetteRenderer,r)}},{key:"drawSilhouetteXRayed",value:function(e,t){this._countsByFlag[Ki].count>0&&this.__drawSilhouette(e,t,this.model.scene.xrayMaterial,us)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._countsByFlag[Zi].count>0&&this.__drawSilhouette(e,t,this.model.scene.highlightMaterial,cs)}},{key:"drawSilhouetteSelected",value:function(e,t){this._countsByFlag[Ji].count>0&&this.__drawSilhouette(e,t,this.model.scene.selectedMaterial,ls)}},{key:"__drawVertexEdges",value:function(e,t,n){var r=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.vertex;r&&this._countsByFlag[Yi].count>0&&this.__drawLayer(e,t,r,n)}},{key:"drawEdgesColorOpaque",value:function(e,t){this._compiledPortions.edgesColorOpaqueAllowed()&&this.__drawVertexEdges(e,t,hs)}},{key:"drawEdgesColorTransparent",value:function(e,t){this._numTransparentLayerPortions>0&&this.__drawVertexEdges(e,t,ds)}},{key:"__drawUniformEdges",value:function(e,t,n,r){var i=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.uniform;i&&(t.programColor=this.__setVec4FromMaterialColorAlpha(n.edgeColor,n.edgeAlpha,rs),this.__drawLayer(e,t,i,r))}},{key:"drawEdgesHighlighted",value:function(e,t){this._countsByFlag[Zi].count>0&&this.__drawUniformEdges(e,t,this.model.scene.highlightMaterial,fs)}},{key:"drawEdgesSelected",value:function(e,t){this._countsByFlag[Ji].count>0&&this.__drawUniformEdges(e,t,this.model.scene.selectedMaterial,ps)}},{key:"drawEdgesXRayed",value:function(e,t){this._countsByFlag[Ki].count>0&&this.__drawUniformEdges(e,t,this.model.scene.xrayMaterial,vs)}},{key:"__drawPick",value:function(e,t,n){n&&this.__drawLayer(e,t,n,gs)}},{key:"drawPickMesh",value:function(e,t){this.__drawPick(e,t,this._renderers.pickMeshRenderer)}},{key:"drawPickDepths",value:function(e,t){this.__drawPick(e,t,this._renderers.pickDepthRenderer)}},{key:"drawPickNormals",value:function(e,t){var n=this._renderers.pickNormalsFlatRenderer;this.__drawPick(e,t,n)}},{key:"drawSnap",value:function(e,t,n){var r=this;t.snapPickOrigin=[0,0,0],this._aabbDirty&&(Ae.collapseAABB3(this._aabb),this._meshes.forEach((function(e){return Ae.expandAABB3(r._aabb,e.aabb)})),this._aabbDirty=!1);var i=this._aabb;t.snapPickCoordinateScale=Ae.mulVec3Scalar(ms([i[3]-i[0],i[4]-i[1],i[5]-i[2]]),Ae.MAX_INT);var s=n?this._renderers.snapInitRenderer:"edge"===t.snapMode?this._renderers.snapEdgeRenderer:this._renderers.snapVertexRenderer;this.__drawPick(e,t,s),t.snapPickLayerParams.push({origin:t.snapPickOrigin.slice(),coordinateScale:ms(t.snapPickCoordinateScale)})}},{key:"drawOcclusion",value:function(e,t){var n=this._renderers.occlusionRenderer;n&&this.__drawLayer(e,t,n,os)}},{key:"drawShadow",value:function(e,t){var n=this._renderers.shadowRenderer;n&&this.__drawLayer(e,t,n,os)}},{key:"initFlags",value:function(e,t,n){this._countsByFlagArr.forEach((function(e){return e.fromFlags(t,!0)})),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);var r="points"!==this.primitive;this._setFlags(e,t,n,r),this._compiledPortions.setFlags2(e,t,r)}},{key:"flushInitFlags",value:function(){this._compiledPortions.setDeferredFlags()}},{key:"setVisible",value:function(e,t,n){this._countsByFlag[Gi].fromFlags(t),this._setFlags(e,t,n)}},{key:"setCulled",value:function(e,t,n){this._countsByFlag[ji].fromFlags(t),this._setFlags(e,t,n)}},{key:"setPickable",value:function(e,t,n){this._countsByFlag[Wi].fromFlags(t),this._setFlags(e,t,n)}},{key:"setClippable",value:function(e,t){this._countsByFlag[zi].fromFlags(t),this._compiledPortions.setClippableFlags(e,t)}},{key:"setCollidable",value:function(e,t){}},{key:"setXRayed",value:function(e,t,n){this._countsByFlag[Ki].fromFlags(t),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){this._countsByFlag[Zi].fromFlags(t),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){this._countsByFlag[Ji].fromFlags(t),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){this._countsByFlag[Yi]&&(this._countsByFlag[Yi].fromFlags(t),this._setFlags(e,t,n))}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"destroy",value:function(){this._compiledPortions&&this._compiledPortions.destroy()}}]),e}(),ws=65536,Bs=5e6,Cs=function(){function e(){x(this,e)}return I(e,[{key:"doublePrecisionEnabled",get:function(){return Ae.getDoublePrecisionEnabled()},set:function(e){Ae.setDoublePrecisionEnabled(e)}},{key:"maxDataTextureHeight",get:function(){return ws},set:function(e){(e=1024*Math.ceil(e/1024))>4096?e=4096:e<1024&&(e=1024),ws=e}},{key:"maxGeometryBatchSize",get:function(){return Bs},set:function(e){e<1e5?e=1e5:e>5e6&&(e=5e6),Bs=e}}]),e}(),Ms=function(e){for(var t=[],n=0;n<e;++n)t.push(n);return t},ks={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(ks,null,4));var e=0;Object.keys(ks).forEach((function(t){t.startsWith("size")&&(e+=ks[t])})),console.log("Total size ".concat(e," bytes (").concat((e/1e3/1e3).toFixed(2)," MB)")),console.log("Avg bytes / triangle: ".concat((e/ks.totalPolygons).toFixed(2)));var t={};Object.keys(ks).forEach((function(n){n.startsWith("size")&&(t[n]="".concat((ks[n]/e*100).toFixed(2)," % of total"))})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};var Es=new Cs,Fs=Es.maxDataTextureHeight,xs=Ae.vec3(),Us=Ae.vec3(),Is=Ae.vec4();Ae.vec4();var Ts=new Float32Array(16),Ps=new Uint8Array(4),Ss=Ae.identityMat4(),Ds=function(e){m(n,bs);var t=_(n);function n(e,r,i){var s;x(this,n),s=t.call(this,e,r,i),ks.numberOfLayers++,s._sortId="TriDTX-".concat(ks.numberOfLayers);var a=e.scene.canvas.gl,o=function(e,t){var n=[],r=0,i=[],s=0,o=[],c=0,l=[],u=0;return{len:function(){return s},accumulateIndices:function(a,h){var d=a&&a.length>0&&function(){var t=r/3;r+=a.length,n.push(a);var o=a.length/3;return function(n){var r=s;s+=3*o,A.perObjectIndexBaseOffsets.push(r/3-t);for(var a=0;a<o;a+=8)i.push(n);ks[e]+=o,ks.totalPolygons+=o}}(),f=h&&function(){var e=c/2;c+=h.length,o.push(h);var n=h.length/2;return function(r){var i=u;u+=2*n,A.perObjectEdgeIndexBaseOffsets.push(i/2-e);for(var s=0;s<n;s+=8)l.push(r);ks[t]+=n,ks.totalEdges+=n}}();return ks.numberOfGeometries++,{numTriangles:a?a.length/3:0,accumulateSubPortionId:function(e){d&&d(e),f&&f(e)}}},createDrawers:function(e,t){var A=function(t,n){return t.length>0?e([t],t.length,1,a.UNSIGNED_SHORT,"sizeDataTexturePortionIds"):n},h=A(i,{texture:null}),d=r>0&&e(n,r,3,t,"sizeDataTextureIndices"),f=A(l),p=c>0&&e(o,c,2,t,"sizeDataTextureEdgeIndices");return{indices:function(e,t){s>0&&(e.perPrimIndices.setInputValue(d),e.perPrimIdPorIds.setInputValue(h),a.drawArrays(t,0,s))},edges:function(e,t){u>0&&(e.perPrimIndices.setInputValue(p),e.perPrimIdPorIds.setInputValue(f),a.drawArrays(t,0,u))}}}}},A=s._buffer={positionsCompressed:[],lenPositionsCompressed:0,geometry8Bits:o("totalPolygons8Bits","totalEdges8Bits"),geometry16Bits:o("totalPolygons16Bits","totalEdges16Bits"),geometry32Bits:o("totalPolygons32Bits","totalEdges32Bits"),perObjectColors:[],perObjectPickColors:[],perObjectSolid:[],perObjectPositionsDecodeMatrices:[],perObjectInstancePositioningMatrices:[],perObjectVertexBases:[],perObjectIndexBaseOffsets:[],perObjectEdgeIndexBaseOffsets:[]};return s._numVertices=0,s._portions=[],s._subPortionReadableGeometries=s.model.scene.readableGeometryEnabled&&{},s._portionToSubPortionsMap=[],s._bucketGeometries={},s._primitive=r,s}return I(n,[{key:"canCreatePortion",value:function(e){var t=e.buckets.length;this._portions.length+t>65536&&ks.cannotCreatePortion.because10BitsObjectId++;var n=this._portions.length+t<=65536,r=void 0!==e.geometryId&&null!==e.geometryId?"".concat(e.geometryId,"#").concat(0):"".concat(e.id,"#").concat(0);if(!this._bucketGeometries[r]){var i=this._buffer,s=Math.max(i.geometry8Bits.len(),i.geometry16Bits.len(),i.geometry32Bits.len()),a=0,o=0;e.buckets.forEach((function(e){a+=e.positionsCompressed.length/3,o+=e.indices.length/3})),(this._numVertices+a>4096*Fs||s+o>4096*Fs)&&ks.cannotCreatePortion.becauseTextureSize++,n&&(n=this._numVertices+a<=4096*Fs&&s+o<=4096*Fs)}return n}},{key:"createPortion",value:function(e,t){var n=this,r=this._buffer,i=t.buckets.map((function(e,i){var s,a,o,A=(null!==(s=t.geometryId)&&void 0!==s?s:t.id)+"#"+i;if(!(A in n._bucketGeometries)){var c=function(e,t,n){if(e){var r=8*Math.ceil(e.length/t/8)*t,i=new Uint32Array(r);return i.set(e),ks[n]+=2*(i.length-e.length),i}return e};e.indices=c(e.indices,3,"overheadSizeAlignementIndices"),e.edgeIndices=c(e.edgeIndices,2,"overheadSizeAlignementEdgeIndices");var l=e.positionsCompressed;r.positionsCompressed.push(l);var u=l.length/3;n._numVertices+=u;var h=r.lenPositionsCompressed/3;r.lenPositionsCompressed+=l.length,n._bucketGeometries[A]={vertexBase:h,geometryData:(a=e.indices,o=e.edgeIndices,u<=256?r.geometry8Bits.accumulateIndices(a,o):u<=65536?r.geometry16Bits.accumulateIndices(a,o):r.geometry32Bits.accumulateIndices(a,o))}}var d=n._bucketGeometries[A];r.perObjectPositionsDecodeMatrices.push(t.positionsDecodeMatrix),r.perObjectInstancePositioningMatrices.push(t.meshMatrix||Ss),r.perObjectSolid.push(!!t.solid),r.perObjectPickColors.push(t.pickColor),r.perObjectVertexBases.push(d.vertexBase);var f=t.colors,p=t.color;r.perObjectColors.push(f?[255*f[0],255*f[1],255*f[2],255]:[p[0],p[1],p[2],t.opacity]);var v=n._portions.length;return n._portions.push({}),d.geometryData.accumulateSubPortionId(v),n._subPortionReadableGeometries&&(n._subPortionReadableGeometries[v]={indices:e.indices,positionsCompressed:e.positionsCompressed,positionsDecodeMatrix:t.positionsDecodeMatrix}),ks.numberOfPortions++,v})),s=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(i),this.model.numPortions++,this._meshes.push(e),s}},{key:"compilePortions",value:function(){var e=this._buffer,t=this.model,n=this._portions.length,r=this.origin,i=this._portionToSubPortionsMap,s=this._primitive,a=this._sortId,o=this._subPortionReadableGeometries,A=t.scene,c=A.canvas.gl,l=Qs(c,n,32,c.UNSIGNED_BYTE,512,(function(t){for(var r=function(e){return[e>>24&255,e>>16&255,e>>8&255,255&e]},i=0;i<n;i++)t.set(e.perObjectColors[i],32*i+0),t.set(e.perObjectPickColors[i],32*i+4),t.set([0,0,0,0],32*i+8),t.set([0,0,0,0],32*i+12),t.set(r(e.perObjectVertexBases[i]),32*i+16),t.set(r(e.perObjectIndexBaseOffsets[i]),32*i+20),t.set(r(e.perObjectEdgeIndexBaseOffsets[i]),32*i+24),t.set([e.perObjectSolid[i]?1:0,0,0,0],32*i+28)}),"sizeDataColorsAndFlags",!0),u=l.textureData,h=function(e,t,n,r,i,s,a){return Qs(c,t,n,r,i,(function(t){for(var n=0,r=0,i=e.length;n<i;n++){var s=e[n];t.set(s,r),r+=s.length}}),s,a)},d=function(e,t,n){var r=e.length;if(0===r)throw"num "+t+" matrices===0";return h(e,r,16,c.FLOAT,512,t,n)},f=d(e.perObjectInstancePositioningMatrices,"sizeDataInstancesMatrices",!0),p=f.textureData,v=d(e.perObjectPositionsDecodeMatrices,"sizeDataPositionDecodeMatrices",!1),g=function(e,t,n,r,i){return h(e,t/n,n,r,4096,i,!1)},m=g(e.positionsCompressed,e.lenPositionsCompressed,3,c.UNSIGNED_SHORT,"sizeDataTexturePositions"),y=e.geometry8Bits.createDrawers(g,c.UNSIGNED_BYTE),_=e.geometry16Bits.createDrawers(g,c.UNSIGNED_SHORT),b=e.geometry32Bits.createDrawers(g,c.UNSIGNED_INT);this._buffer=null;var w,B,C=!1,M=!1,k=!1,E=0,F=function(){C=!0},x=A.on("rendering",(function(){M&&(C=!1,M=!1,u.reloadData()),E=0})),U=function(e,n){var r=i[e];if(r)for(var s=0,a=r.length;s<a;s++)n(r[s]);else t.error("portion not found: "+e)},I=function(e,t,n,r){var i=C||r;i?M=!0:++E>=10&&F(),u.setData(n,e,t,!i)},T=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];Ps.set([t&zi?255:0,0,1,2]),U(e,(function(e){return I(e,3,Ps,n)}))};return{edgesColorOpaqueAllowed:function(){return!A.logarithmicDepthBufferEnabled||(A._loggedWarning||(console.log("Edge enhancement for SceneModel data texture layers currently disabled with logarithmic depth buffer"),A._loggedWarning=!0),!1)},sortId:a,setClippableFlags:T,setFlags:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];ys(t,n,!0,A,Ps),U(e,(function(e){return I(e,2,Ps,r)}))},setFlags2:T,setDeferredFlags:function(){},setColor:function(e,t){Ps.set(t),U(e,(function(e){return I(e,0,Ps,!1)}))},setMatrix:function(e,t){U(e,(function(e){var n=C;n?M=!0:++E>=10&&F(),Ts.set(t),p.setData(Ts,e,0,!n)}))},setOffset:function(e,t){},getEachIndex:function(e,t){o&&U(e,(function(e){return o[e].indices.forEach((function(e){return t(e)}))}))},getEachVertex:function(e,n){o&&U(e,(function(e){for(var i=o[e],s=i.positionsCompressed,a=i.positionsDecodeMatrix,A=Is,c=0,l=s.length;c<l;c+=3)A[0]=s[c],A[1]=s[c+1],A[2]=s[c+2],A[3]=1,Ae.decompressPosition(A,a),Ae.mulMat4v4(t.worldMatrix,A,A),Ae.addVec3(r,A,A),n(A)}))},precisionRayPickSurface:function(e,t,n,r,i){return!1},renderers:_s(A,"dtx",s,t.saoEnabled,!1,!1,!0,(function(e,t){return Rs(e,!t)})),drawCalls:(w=function(e){var n=function(e,t){return e.setInputValue&&e.setInputValue(t)};return function(i,s,a){n(s.worldMatrix,t.rotationMatrix),n(s.viewMatrix,a.viewMatrix),n(s.projMatrix,a.projMatrix);var o=Ae.transformPoint3(t.matrix,r,xs);n(s.uCameraEyeRtc,Ae.subVec3(a.eye,o,Us)),n(s.perObjPosDecode,v),n(s.perVertIdCoords,m),n(s.perObjColsFlags,l),n(s.perObjectMatrix,f),e(s)}},B=function(e){return w((function(t){y.edges(t,e),_.edges(t,e),b.edges(t,e)}))},{drawVertices:B(c.POINTS),drawEdges:B(c.LINES),drawSurface:w((function(e){var t=c.TRIANGLES;y.indices(e,t),_.indices(e,t),b.indices(e,t)}))}),destroy:function(){k||(A.off(x),k=!0)}}}}]),n}(),Qs=function(e,t,n,r,i,s,a,o){if(n>4&&n%4>0)throw"Unhandled data size "+n;var A=Math.ceil(n/4),c=n/A,l=k(function(){switch(r){case e.UNSIGNED_BYTE:return[Uint8Array].concat(p(1===c?[e.R8UI,e.RED_INTEGER]:2===c?[e.RG8UI,e.RG_INTEGER]:3===c?[e.RGB8UI,e.RGB_INTEGER]:[e.RGBA8UI,e.RGBA_INTEGER]));case e.UNSIGNED_SHORT:return[Uint16Array].concat(p(1===c?[e.R16UI,e.RED_INTEGER]:2===c?[e.RG16UI,e.RG_INTEGER]:3===c?[e.RGB16UI,e.RGB_INTEGER]:[e.RGBA16UI,e.RGBA_INTEGER]));case e.UNSIGNED_INT:return[Uint32Array].concat(p(1===c?[e.R32UI,e.RED_INTEGER]:2===c?[e.RG32UI,e.RG_INTEGER]:3===c?[e.RGB32UI,e.RGB_INTEGER]:[e.RGBA32UI,e.RGBA_INTEGER]));case e.FLOAT:return[Float32Array].concat(p(1===c?[e.R32F,e.RED]:2===c?[e.RG32F,e.RG]:3===c?[e.RGB32F,e.RGB]:[e.RGBA32F,e.RGBA]));default:throw"Unhandled data type "+r}}(),3),u=l[0],h=l[1],d=l[2],f=i*A,v=Math.ceil(t/i);if(0===v)throw"texture height===0";var g=new u(f*v*c);ks[a]+=g.byteLength,ks.numberOfTextures++,s(g);var m=e.createTexture();return e.bindTexture(e.TEXTURE_2D,m),e.texStorage2D(e.TEXTURE_2D,1,h,f,v),e.texSubImage2D(e.TEXTURE_2D,0,0,0,f,v,d,r,g),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),{bind:function(t){return e.activeTexture(e["TEXTURE"+t]),e.bindTexture(e.TEXTURE_2D,m),!0},unbind:function(e){},textureData:o&&{setData:function(t,s){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,o=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(g.set(t,s*n+a*c),o){e.bindTexture(e.TEXTURE_2D,m);var l=s%i*A+a,u=Math.floor(s/i),h=t.length/c;e.texSubImage2D(e.TEXTURE_2D,0,l,u,h,1,d,r,t)}},reloadData:function(){e.bindTexture(e.TEXTURE_2D,m),e.texSubImage2D(e.TEXTURE_2D,0,0,0,f,v,d,r,g)}}}},Rs=function(e,t){var n=function(t,n){var r=e.createUniform(t,n),i=function(e){return"texelFetch(".concat(r,", ").concat(e,", 0)")};return i.map=r,i},r=n("highp usampler2D","perPrimIndices"),i=n("mediump usampler2D","perPrimIdPorIds"),s=n("highp sampler2D","perObjPosDecode"),a=n("mediump usampler2D","perVertIdCoords"),o=n("lowp usampler2D","perObjColsFlags"),A=n("highp sampler2D","perObjectMatrix"),c=e.createUniform("mat4","worldMatrix"),l=e.createUniform("mat4","viewMatrix"),u=e.createUniform("mat4","projMatrix"),h=e.createUniform("vec3","uCameraEyeRtc"),d=function(e){var t={toString:function(){return t.needed=!0,e}};return t},f=d("colorA"),p=d("pickColor"),v=d("worldNormal"),g=d("viewNormal"),m=function(e){return o("ivec2(objectIndexCoords.x*8+".concat(e,", objectIndexCoords.y)"))};return{geometryParameters:{attributes:{clippable:"(flags2.r > 0u)",color:f,flags:Ms(4).map((function(e){return"int(flags[".concat(e,"])")})),metallicRoughness:null,normal:{view:g,world:v},pickColor:p,position:{clip:"gl_Position",view:"viewPosition",world:"worldPosition"},uv:null},projMatrix:u,viewMatrix:l},ensureColorAndFlagAvailable:function(e){e.push("int primitiveIndex = gl_VertexID / "+(t?3:2)+";"),e.push("int h_packed_object_id_index = (primitiveIndex >> 3) & 4095;"),e.push("int v_packed_object_id_index = (primitiveIndex >> 3) >> 12;"),e.push("int objectIndex = int(".concat(i("ivec2(h_packed_object_id_index, v_packed_object_id_index)"),".r);")),e.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),e.push("uvec4 flags = ".concat(m(2),";")),e.push("uvec4 flags2 = ".concat(m(3),";")),f.needed&&e.push("vec4 ".concat(f," = vec4(").concat(m(0),") / 255.0;"))},appendVertexData:function(e){var n=function(e){return A("ivec2(objectIndexCoords.x*4+".concat(e,", objectIndexCoords.y)"))};e.push("mat4 objectInstanceMatrix = mat4(".concat(n(0),", ").concat(n(1),", ").concat(n(2),", ").concat(n(3),");"));var i=function(e){return s("ivec2(objectIndexCoords.x*4+".concat(e,", objectIndexCoords.y)"))};if(e.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4(".concat(i(0),", ").concat(i(1),", ").concat(i(2),", ").concat(i(3),");")),e.push("ivec4 packedVertexBase = ivec4(".concat(m(4),");")),e.push("ivec4 packedIndexBaseOffset = ivec4(".concat(m(t?5:6),");")),e.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),e.push("int h_index = (primitiveIndex - indexBaseOffset) & 4095;"),e.push("int v_index = (primitiveIndex - indexBaseOffset) >> 12;"),e.push("ivec3 vertexIndices = ivec3(".concat(r("ivec2(h_index, v_index)"),");")),e.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),t){e.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),e.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),e.push("uint solid = ".concat(m(7),".r;"));var o=function(e){return"vec3(".concat(a("ivec2(indexPositionH[".concat(e,"], indexPositionV[").concat(e,"])")),")")};e.push("vec3 positions[] = vec3[](".concat(o(0),", ").concat(o(1),", ").concat(o(2),");")),e.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),e.push("vec3 position = positions[gl_VertexID % 3];"),v.needed&&e.push("vec3 worldNormal = -normalize((transpose(inverse(".concat(c," * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);")),g.needed&&e.push("vec3 viewNormal = -normalize((transpose(inverse(".concat(l," * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);")),e.push("if (solid != 1u) {"),e.push(" if (".concat("(".concat(u,"[2][3] == - 1.0)"),") {")),e.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(".concat(c," * objectDecodeAndInstanceMatrix) * vec4(").concat(h,", 1)).xyz;")),e.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),e.push(" position = positions[2 - (gl_VertexID % 3)];"),v.needed&&e.push(" worldNormal = -worldNormal;"),g.needed&&e.push(" viewNormal = -viewNormal;"),e.push(" }"),e.push(" } else {"),g.needed||e.push(" vec3 viewNormal = -normalize((transpose(inverse(".concat(l," * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);")),e.push(" if (viewNormal.z < 0.0) {"),e.push(" position = positions[2 - (gl_VertexID % 3)];"),v.needed&&e.push(" worldNormal = -worldNormal;"),g.needed&&e.push(" viewNormal = -viewNormal;"),e.push(" }"),e.push(" }"),e.push("}")}else e.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),e.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),e.push("vec3 position = vec3(".concat(a("ivec2(indexPositionH, indexPositionV)"),");"));p.needed&&e.push("vec4 pickColor = vec4(".concat(m(1),");")),e.push("vec4 worldPosition = ".concat(c," * (objectDecodeAndInstanceMatrix * vec4(position, 1.0));"))},layerTypeInputs:{perPrimIndices:r.map,perPrimIdPorIds:i.map,perObjPosDecode:s.map,perVertIdCoords:a.map,perObjColsFlags:o.map,perObjectMatrix:A.map,worldMatrix:c,viewMatrix:l,projMatrix:u,uCameraEyeRtc:h}}},Os=Ae.mat4(),Vs=Ae.mat4();function Ls(e,t,n){for(var r=e.length,i=new Uint16Array(r),s=t[0],a=t[1],o=t[2],A=t[3]-s,c=t[4]-a,l=t[5]-o,u=65525,h=u/A,d=u/c,f=u/l,p=function(e){return e>=0?e:0},v=0;v<r;v+=3)i[v+0]=Math.floor(p(e[v+0]-s)*h),i[v+1]=Math.floor(p(e[v+1]-a)*d),i[v+2]=Math.floor(p(e[v+2]-o)*f);return Ae.identityMat4(Os),Ae.translationMat4v(t,Os),Ae.identityMat4(Vs),Ae.scalingMat4v([A/u,c/u,l/u],Vs),Ae.mulMat4(Os,Vs,n),i}function Hs(e,t){var n=e[0],r=e[1],i=e[2],s=e[3]-n,a=e[4]-r,o=e[5]-i,A=65525;return Ae.identityMat4(Os),Ae.translationMat4v(e,Os),Ae.identityMat4(Vs),Ae.scalingMat4v([s/A,a/A,o/A],Vs),Ae.mulMat4(Os,Vs,t),t}function Ns(e,t,n){var r=e[0]/(Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2])),i=e[1]/(Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2]));if(e[2]<0){var s,a;s=(1-Math.abs(i))*(r>=0?1:-1),a=(1-Math.abs(r))*(i>=0?1:-1),r=s,i=a}return new Int8Array([Math[t](127.5*r+(r<0?-1:0)),Math[n](127.5*i+(i<0?-1:0))])}function Gs(e){var t=e[0],n=e[1];t/=t<0?127:128,n/=n<0?127:128;var r=1-Math.abs(t)-Math.abs(n);r<0&&(t=(1-Math.abs(n))*(t>=0?1:-1),n=(1-Math.abs(t))*(n>=0?1:-1));var i=Math.sqrt(t*t+n*n+r*r);return[t/i,n/i,r/i]}var js,Ws,zs=new Float32Array(1),Xs=new Float32Array(4),Ks=new Float32Array(3),Zs=Ae.mat4(),Js=Ae.vec4([0,0,0,1]),Ys=Ae.vec4(),qs=Ae.vec3(),$s=Ae.vec3(),ea=Ae.vec3(),ta=Ae.vec3(),na=Ae.vec3(),ra=Ae.vec3(),ia=Ae.vec3(),sa=new Uint8Array(4),aa=new Float32Array(96),oa=function(e){for(var t=[],n=0;n<e;++n)t.push(n);return t},Aa=function(e,t){e.set(t);for(var n=t.length,r=e.length;n<r;){var i=Math.min(n,r-n);e.set(e.subarray(0,i),n),n+=i}},ca=(js=0,Ws=new Map,{acquire:function(){return js++},release:function(){0==--js&&Ws.clear()},getTypeArray:function(e,t){Ws.has(e)||Ws.set(e,{});var n=Ws.get(e);return t in n||(n[t]=new e(t)),n[t]}}),la=function(e){m(n,bs);var t=_(n);function n(e,r,i,s){var a;x(this,n),a=t.call(this,e,r,i);var o=!!s.geometry;a._maxVerts=s.maxGeometryBatchSize;var A=o?s.geometry.positionsDecodeMatrix:s.positionsDecodeMatrix;a._positionsDecodeMatrix=A&&Ae.mat4(A),a._cfgUvDecodeMatrix=s.uvDecodeMatrix&&Ae.mat3(s.uvDecodeMatrix),a._instancedGeometry=s.geometry,a._textureSet=s.textureSet,a._modelAABB=!o&&Ae.collapseAABB3(),a._portions=[];var c=function(){var e=0,t=[];return{length:function(){return e},append:function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;e+=r*n.length,t.push({data:n,times:r,denormalizeScale:i,increment:s})},compileBuffer:function(e){var n=0;t.forEach((function(e){n+=e.times*e.data.length}));var r=new e(n),i=0;return t.forEach((function(e){var t=e.data,n=e.denormalizeScale,s=e.increment,a=r.subarray(i);if(1===n&&0===s)a.set(t);else for(var o=0;o<t.length;++o)a[o]=s+t[o]*n;for(var A=t.length,c=e.times*t.length;A<c;){var l=Math.min(A,c-A);a.set(a.subarray(0,l),A),A+=l}i+=A})),r}}};return a._buffer=d({colors:c(),metallicRoughness:c(),pickColors:c()},o?{modelMatrixCol:[c(),c(),c()],modelNormalMatrixCol:[c(),c(),c()]}:{positions:c(),indices:c(),uv:c(),normals:c(),edgeIndices:c()}),a}return I(n,[{key:"canCreatePortion",value:function(e,t){return this._instancedGeometry||this._buffer.positions.length()+e<=3*this._maxVerts&&this._buffer.indices.length()+t<=3*this._maxVerts}},{key:"createPortion",value:function(e,t){var n=this,r=this._buffer,i=this._instancedGeometry,s=this.model,a=this._portions.length,o=this.primitive,A=!!this._positionsDecodeMatrix,c=s.scene,l=t.meshMatrix,u=function(i,A,l,u,h){var d,f,p=n._portions.length>0&&n._portions[n._portions.length-1],v={indicesBaseIndex:p?p.indicesBaseIndex+p.numIndices:0,numIndices:l?l.length:0,portionBase:i,portionSize:A,retainedGeometry:c.readableGeometryEnabled&&"points"!==o&&"lines"!==o&&{indices:l,quantizedPositions:u,offset:c.entityOffsetsEnabled&&Ae.vec3(),matrix:h&&h.slice(),inverseMatrix:null,normalMatrix:null}};"points"!==o&&"lines"!==o&&r.metallicRoughness.append([null!==(d=t.metallic)&&void 0!==d?d:0,null!==(f=t.roughness)&&void 0!==f?f:255],A);return"lines"!==o&&r.pickColors.append(t.pickColor.slice(0,4),A),n._portions.push(v),s.numPortions++,n._meshes.push(e),a};if(i){if(r.modelMatrixCol.forEach((function(e,t){return e.append([l[t+0],l[t+4],l[t+8],l[t+12]])})),"points"!==o){var h,d=t.color;r.colors.append([d[0],d[1],d[2],null!==(h=t.opacity)&&void 0!==h?h:255])}if("points"!==o&&"lines"!==o&&i.normals){var f=Ae.inverseMat4(Ae.transposeMat4(l,Ae.mat4()));r.modelNormalMatrixCol.forEach((function(e,t){return e.append([f[t+0],f[t+4],f[t+8],f[t+12]])}))}return u(a,1,i.indices,i.positionsCompressed,l)}var p=r.positions.length()/3,v=A?t.positionsCompressed:t.positions;if(!v)throw(A?"positionsCompressed":"positions")+" expected";r.positions.append(v);var g=v.length/3,m=t.indices;m&&r.indices.append(m,1,1,p);var y=t.normalsCompressed,_=t.normals;if(y&&y.length>0)r.normals.append(y);else if(_&&_.length>0){var b=Zs;l?(Ae.transposeMat4(l,b),Ae.inverseMat4(b,b)):Ae.identityMat4(b);var w=[];!function(e,t,n,r,i){function s(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}var a,o,A,c,l,u=new Float32Array([0,0,0,0]),h=new Float32Array([0,0,0,0]);for(l=0;l<n;l+=3)u[0]=t[l],u[1]=t[l+1],u[2]=t[l+2],Ae.transformVec3(e,u,h),Ae.normalizeVec3(h,h),o=a=Ns(h,"floor","floor"),A=c=s(h,Gs(a)),(A=s(h,Gs(a=Ns(h,"ceil","floor"))))>c&&(o=a,c=A),(A=s(h,Gs(a=Ns(h,"floor","ceil"))))>c&&(o=a,c=A),(A=s(h,Gs(a=Ns(h,"ceil","ceil"))))>c&&(o=a,c=A),r[i+l+0]=o[0],r[i+l+1]=o[1],r[i+l+2]=0}(b,_,_.length,w,0),r.normals.append(w)}var B=t.colors,C=t.colorsCompressed,M=t.color;if(B)if("points"===o)r.colors.append(B,1,255);else{for(var k=[],E=0,F=B.length;E<F;E+=3)k.push(255*B[E]),k.push(255*B[E+1]),k.push(255*B[E+2]),k.push(255);r.colors.append(k)}else if(C)if("points"===o)r.colors.append(C);else{for(var x=[],U=0,I=C.length;U<I;U+=3)x.push(C[U]),x.push(C[U+1]),x.push(C[U+2]),x.push(255);r.colors.append(x)}else M&&r.colors.append([M[0],M[1],M[2],"points"===o?1:t.opacity],g);var T=function(e){return e&&e.length>0&&e},P=T(t.uv)||T(t.uvCompressed);P&&r.uv.append(P);var S=t.edgeIndices;return S&&r.edgeIndices.append(S,1,1,p),Ae.expandAABB3(this._modelAABB,t.aabb),u(p,g,m)}},{key:"compilePortions",value:function(){var e=this._buffer,t=this._instancedGeometry,n=this.model,r=this._modelAABB,i=this.origin,s=this._portions,a=this.primitive,o=this._textureSet,A=this._positionsDecodeMatrix,c=this._cfgUvDecodeMatrix,l=n.scene,u=l.canvas.gl,h=!!t,d=[],p=function(e,t,n,r){if(t.length>0){var i,s=t.constructor,a=k((i={},f(i,Uint8Array,[1,u.UNSIGNED_BYTE]),f(i,Int8Array,[1,u.BYTE]),f(i,Uint16Array,[2,u.UNSIGNED_SHORT]),f(i,Int16Array,[2,u.SHORT]),f(i,Uint32Array,[4,u.UNSIGNED_INT]),f(i,Int32Array,[4,u.INT]),f(i,Float32Array,[4,u.FLOAT]),i)[s],2),o=a[0],A=a[1],c=u.createBuffer();d.push((function(){return u.deleteBuffer(c)}));var l=function(){return u.bindBuffer(e,c)},h=function(t){l(),u.bufferData(e,t,r)};h(t);var p=t.BYTES_PER_ELEMENT,v=t.length/n;return{bindBuffer:l,getData:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:v-t;l();var i=new s(r*n);return u.getBufferSubData(e,t*o*n,i,0,r*n),i},numItems:v,setData:h,setSubData:function(t,n){l(),u.bufferSubData(e,n*p,t)},type:A}}return null},v=function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=arguments.length>4&&void 0!==arguments[4]&&arguments[4],s=p(u.ARRAY_BUFFER,e,t,n);return s&&{getData:s.getData,numItems:s.numItems,setData:s.setData,setSubData:s.setSubData,attributeDivisor:r&&1,bindAtLocation:function(e){s.bindBuffer(),u.vertexAttribPointer(e,t,s.type,!!i,0,0)}}},g=function(e){var t=p(u.ELEMENT_ARRAY_BUFFER,e,1,u.STATIC_DRAW);return t&&{getData:t.getData,bindIndicesBuffer:t.bindBuffer,indicesCount:e.length,indicesType:t.type}},m=s.reduce((function(e,t){return e+t.portionSize}),0),y=v(new Float32Array(m),1,u.DYNAMIC_DRAW,h),_=function(e,t){return v(e,4,t,h&&"points"!==a,!0)},b=h&&t.colorsCompressed?_(new Uint8Array(t.colorsCompressed),u.STATIC_DRAW):_(e.colors.compileBuffer(Uint8Array),u.DYNAMIC_DRAW),w=l.entityOffsetsEnabled&&v(new Float32Array(3*m),3,u.DYNAMIC_DRAW,h),B=v(e.metallicRoughness.compileBuffer(Uint8Array),2,u.STATIC_DRAW,h),C=v(e.pickColors.compileBuffer(Uint8Array),4,u.STATIC_DRAW,h),M=g(h?new Uint32Array(t.edgeIndices):e.edgeIndices.compileBuffer(Uint32Array)),E=h?"points"!==a&&t.indices&&new Uint32Array(t.indices):e.indices.compileBuffer(Uint32Array),F=E&&g(E),x=h?t.positionsCompressed:A?e.positions.compileBuffer(Uint16Array):Ls(e.positions.compileBuffer(Float64Array),r,A=Ae.mat4()),U=x&&v(x,3,u.STATIC_DRAW);h||s.forEach((function(e){if(e.retainedGeometry){var t=3*e.portionBase;e.retainedGeometry.quantizedPositions=x.subarray(t,t+3*e.portionSize)}}));var I=h&&e.modelMatrixCol.map((function(e){return v(e.compileBuffer(Float32Array),4,u.STATIC_DRAW,!0)})),T=!h&&e.normals.compileBuffer(Int8Array),P=T&&v(T,3,u.STATIC_DRAW,!1,!0),S=I&&P&&e.modelNormalMatrixCol.map((function(e){return v(e.compileBuffer(Float32Array),4,u.STATIC_DRAW,!0)})),D=h?"points"!==a&&"lines"!==a&&t.uvCompressed&&{buf:v(t.uvCompressed,2,u.STATIC_DRAW),mat:t.uvDecodeMatrix}:function(){var t=e.uv.compileBuffer(Float32Array);if(0===t.length)return null;if(c)return{buf:v(t,2,u.STATIC_DRAW),mat:c};var n=pt.getUVBounds(t),r=pt.compressUVs(t,n.min,n.max);return{buf:v(r.quantized,2,u.STATIC_DRAW),mat:Ae.mat3(r.decodeMatrix)}}();this._buffer=null,ca.acquire(),d.push((function(){return ca.release()}));var Q,R,O=null,V=function(e,n,r){var i=arguments.length>3&&void 0!==arguments[3]&&arguments[3];ys(n,r,"points"!==a&&"lines"!==a,l,sa);var o=n&zi?1:0,A=0;A|=sa[0],A|=sa[1]<<4,A|=sa[2]<<8,A|=sa[3]<<12,A|=o<<16,zs[0]=A;var c=s[e],u=c.portionBase,h=c.portionSize;if(i&&!t)O||(O=new Float32Array(m)),Aa(O.subarray(u,u+h),zs);else if(y){var d=ca.getTypeArray(Float32Array,h);Aa(d,zs),y.setSubData(d,u)}},L="solid"===a;return{edgesColorOpaqueAllowed:function(){return!0},solid:L,sortId:("points"===a?"Points":"lines"===a?"Lines":"Triangles")+(h?"Instancing":"Batching")+"Layer"+("points"!==a&&"lines"!==a?(L?"-solid":"-surface")+"-autoNormals"+(h?"":(o&&o.colorTexture?"-colorTexture":"")+(o&&o.metallicRoughnessTexture?"-metallicRoughnessTexture":"")):""),setClippableFlags:V,setFlags:V,setFlags2:function(e,t,n){},setDeferredFlags:function(){O&&(y.setData(O),O=null)},setColor:function(e,t){if(b){var n=s[e],r=ca.getTypeArray(Uint8Array,4*n.portionSize);Aa(r,t.slice(0,4)),b.setSubData(r,4*n.portionBase)}},setMatrix:function(e,t){I&&I.forEach((function(n,r){Xs[0]=t[r+0],Xs[1]=t[r+4],Xs[2]=t[r+8],Xs[3]=t[r+12],n.setSubData(Xs,4*e)}))},setOffset:function(e,t){if(l.entityOffsetsEnabled){var r=s[e];if(w){Ks.set(t);var i=ca.getTypeArray(Float32Array,3*r.portionSize);Aa(i,Ks),w.setSubData(i,3*r.portionBase)}r.retainedGeometry&&r.retainedGeometry.offset.set(t)}else n.error("Entity#offset not enabled for this Viewer")},getEachIndex:function(e,t){var n=s[e].retainedGeometry;n&&n.indices.forEach((function(e){return t(e)}))},getEachVertex:function(e,t){var r=s[e].retainedGeometry;if(r){var a=Ys;i?a.set(i,0):a[0]=a[1]=a[2]=0,a[3]=1;var o=n.matrix;Ae.mulMat4v4(o,a,a);for(var c=r.quantizedPositions,l=Js,u=0,h=c.length;u<h;u+=3)l[0]=c[u],l[1]=c[u+1],l[2]=c[u+2],Ae.decompressPosition(l,A),r.matrix&&Ae.transformPoint3(r.matrix,l,l),l[3]=1,Ae.mulMat4v4(o,l,l),Ae.addVec3(a,l,l),t(l)}},readGeometryData:"points"!==a&&"lines"!==a&&function(e){var t=!h&&s[e],r=t?F.getData(t.indicesBaseIndex,t.numIndices).map((function(e){return e-t.portionBase})):F.getData(),a=n.matrix,o=Ae.vec4();o.set(i,0),o[3]=1,Ae.mulMat4v4(a,o,o);var c=I&&Ae.mat4();if(c){var l=I[0].getData(e,1),u=I[1].getData(e,1),d=I[2].getData(e,1);c.set([l[0],u[0],d[0],0,l[1],u[1],d[1],0,l[2],u[2],d[2],0,l[3],u[3],d[3],1])}var f=Ae.mat4();Ae.mulMat4(a,c?Ae.mulMat4(c,A,f):A,f),f[12]+=o[0],f[13]+=o[1],f[14]+=o[2];var p=t?U.getData(t.portionBase,t.portionSize):U.getData();return{indices:r,positions:Ae.transformPositions3(f,p,new Float64Array(p.length))}},precisionRayPickSurface:function(e,t,r,a,o){var c=s[e].retainedGeometry;if(c){c.matrix&&!c.inverseMatrix&&(c.inverseMatrix=Ae.inverseMat4(c.matrix,Ae.mat4())),o&&c.inverseMatrix&&!c.normalMatrix&&(c.normalMatrix=Ae.transposeMat4(c.inverseMatrix,Ae.mat4()));var l=c.quantizedPositions,u=c.indices,h=c.offset,d=qs,f=$s;d.set(i?Ae.subVec3(t,i,ea):t),f.set(r),h&&Ae.subVec3(d,h),Ae.transformRay(n.worldNormalMatrix,d,f,d,f),c.inverseMatrix&&Ae.transformRay(c.inverseMatrix,d,f,d,f);for(var p=ta,v=na,g=ra,m=!1,y=0,_=ia,b=0,w=u.length;b<w;b+=3){var B=3*u[b],C=3*u[b+1],M=3*u[b+2];if(p[0]=l[B],p[1]=l[B+1],p[2]=l[B+2],v[0]=l[C],v[1]=l[C+1],v[2]=l[C+2],g[0]=l[M],g[1]=l[M+1],g[2]=l[M+2],Ae.decompressPosition(p,A),Ae.decompressPosition(v,A),Ae.decompressPosition(g,A),Ae.rayTriangleIntersect(d,f,p,v,g,_)){c.matrix&&Ae.transformPoint3(c.matrix,_,_),Ae.transformPoint3(n.worldMatrix,_,_),h&&Ae.addVec3(_,h),i&&Ae.addVec3(_,i);var k=Math.abs(Ae.lenVec3(Ae.subVec3(_,t,[])));(!m||k>y)&&(y=k,a.set(_),o&&Ae.triangleNormal(p,v,g,o),m=!0)}}return m&&o&&(c.normalMatrix&&Ae.transformVec3(c.normalMatrix,o,o),Ae.transformVec3(n.worldNormalMatrix,o,o),Ae.normalizeVec3(o)),m}return!1},layerTextureSet:o,renderers:_s(l,h?"instancing":"batching",a,n.saoEnabled,n.pbrEnabled&&D&&o&&o.colorTexture&&P&&B&&o.metallicRoughnessTexture,n.colorTextureEnabled&&D&&o&&o.colorTexture,!!P,(function(e){return ha(e,h&&{hasModelNormalMat:!!S},l.entityOffsetsEnabled)})),drawCalls:(Q={},R=function(e){return function(t,r,i){var o=0;aa.set(n.rotationMatrix,0),aa.set(i.viewMatrix,o+=16),aa.set(i.projMatrix,o+=16),aa.set(A,o+=16),r.needNormal()&&(aa.set(n.worldNormalMatrix,o+=16),aa.set(i.viewNormalMatrix,o+=16)),r.matrices.setInputValue(aa),r.uvDecodeMatrix.setInputValue&&r.uvDecodeMatrix.setInputValue(D.mat),t in Q||(Q[t]=[null,null,null]);var c,l,f=Q[t],p=e?e.vertices?0:1:2;if(!f[p]){var v=u.createVertexArray();u.bindVertexArray(v);var g=function(e,t){e&&e.setInputValue&&t&&e.setInputValue(t)},m=r.attributes;g(m.position,U),g(m.normal,P),g(m.color,b),g(m.pickColor,C),g(m.uV,D&&D.buf),g(m.metallicRoughness,B),g(m.flags,y),g(m.offset,w),m.modelMatrixCol&&m.modelMatrixCol.forEach((function(e,t){return g(e,I[t])})),m.modelNormalMatrixCol&&m.modelNormalMatrixCol.forEach((function(e,t){return g(e,S[t])}));var _=(c=function(){h?u.drawArraysInstanced(u.POINTS,0,U.numItems,s.length):u.drawArrays(u.POINTS,0,U.numItems)},l=function(e,t){t.bindIndicesBuffer();var n=t.indicesCount,r=t.indicesType;return function(){h?u.drawElementsInstanced(e,n,r,0,s.length):u.drawElements(e,n,r,0)}},"points"===a?c:"lines"===a?e&&e.vertices?c:l(u.LINES,F):e&&e.vertices?c:e&&M?l(u.LINES,M):l(u.TRIANGLES,F));u.bindVertexArray(null),d.push((function(){return u.deleteVertexArray(v)})),f[p]=function(){u.bindVertexArray(v),_(),u.bindVertexArray(null)}}f[p]()}},{drawVertices:R({vertices:!0}),drawEdges:R({}),drawSurface:R(null)}),destroy:function(){d.forEach((function(e){return e()})),d.length=0}}}}]),n}(),ua=function(e){var t={toString:function(){return t.needed=!0,e}};return t},ha=function(e,t,n){var r=e.createAttribute,i={position:r("vec3","positionA"),normal:r("vec3","normalA"),color:r("vec4","colorA"),pickColor:r("vec4","pickColor"),uV:r("vec2","uvApremul"),metallicRoughness:r("vec2","metallicRoughness"),flags:r("float","flagsA"),offset:n&&r("vec3","offset"),modelMatrixCol:t&&oa(3).map((function(e){return r("vec4","modelMatrixCol"+e)})),modelNormalMatrixCol:t&&t.hasModelNormalMat&&oa(3).map((function(e){return r("vec4","modelNormalMatrixCol"+e)}))},s=ua("aUv"),a=ua("viewNormal"),o=ua("worldNormal"),A=e.createUniform("mat3","uvDecodeMatrix"),c=function(){return a.needed||o.needed},l=e.createUniformBlock("Matrices",{worldMatrix:"mat4",viewMatrix:"mat4",projMatrix:"mat4",positionsDecodeMatrix:"mat4",worldNormalMatrix:"mat4",viewNormalMatrix:"mat4"});return{dontCullOnAlphaZero:!0,geometryParameters:{attributes:{clippable:"((int(".concat(i.flags,") >> 16 & 0xF) == 1)"),color:i.color,flags:oa(4).map((function(e){return{toString:function(){return"(int(".concat(i.flags,") >> ").concat(4*e," & 0xF)")}}})),metallicRoughness:i.metallicRoughness,normal:{view:a,world:o},pickColor:i.pickColor,position:{clip:"gl_Position",view:"viewPosition",world:"worldPosition"},uv:s},projMatrix:l.projMatrix,viewMatrix:l.viewMatrix},appendVertexData:function(t){s.needed&&t.push("vec2 ".concat(s," = (").concat(A," * vec3(").concat(i.uV,", 1.0)).xy;"));var n=i.modelMatrixCol&&"mat4(".concat(i.modelMatrixCol[0],", ").concat(i.modelMatrixCol[1],", ").concat(i.modelMatrixCol[2],", vec4(0.0,0.0,0.0,1.0))");if(t.push("vec4 worldPosition = ".concat(l.worldMatrix," * (").concat(l.positionsDecodeMatrix," * vec4(").concat(i.position,", 1.0)").concat(n?" * "+n:"",");")),i.offset&&t.push("worldPosition.xyz = worldPosition.xyz + ".concat(i.offset,";")),c()){var r=i.modelNormalMatrixCol&&"* mat4(".concat(i.modelNormalMatrixCol[0],", ").concat(i.modelNormalMatrixCol[1],", ").concat(i.modelNormalMatrixCol[2],", vec4(0.0,0.0,0.0,1.0))");t.push("vec4 modelNormal = vec4(".concat(e.commonLibrary.octDecode,"(").concat(i.normal,".xy), 0.0)").concat(r||"",";")),t.push("vec3 ".concat(o," = (").concat(l.worldNormalMatrix," * modelNormal).xyz;")),a.needed&&t.push("vec3 ".concat(a," = normalize((").concat(l.viewNormalMatrix," * vec4(").concat(o,", 0.0)).xyz);"))}},layerTypeInputs:{attributes:i,matrices:l,uvDecodeMatrix:A,needNormal:c}}},da=function(){function e(t){x(this,e),this.id=t.id,this.colorTexture=t.colorTexture,this.alphaCutoff=t.alphaCutoff,this.metallicRoughnessTexture=t.metallicRoughnessTexture,this.normalsTexture=t.normalsTexture,this.emissiveTexture=t.emissiveTexture,this.occlusionTexture=t.occlusionTexture}return I(e,[{key:"destroy",value:function(){}}]),e}(),fa=function(){function e(t){x(this,e),this.id=t.id,this.texture=t.texture}return I(e,[{key:"destroy",value:function(){this.texture&&(this.texture.destroy(),this.texture=null)}}]),e}(),pa={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}},va=function(){function e(t,n,r){x(this,e),this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=t,this.onProgress=n,this.onError=r}return I(e,[{key:"itemStart",value:function(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}},{key:"itemEnd",value:function(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}},{key:"itemError",value:function(e){void 0!==this.onError&&this.onError(e)}},{key:"resolveURL",value:function(e){return this.urlModifier?this.urlModifier(e):e}},{key:"setURLModifier",value:function(e){return this.urlModifier=e,this}},{key:"addHandler",value:function(e,t){return this.handlers.push(e,t),this}},{key:"removeHandler",value:function(e){var t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}},{key:"getHandler",value:function(e){for(var t=0,n=this.handlers.length;t<n;t+=2){var r=this.handlers[t],i=this.handlers[t+1];if(r.global&&(r.lastIndex=0),r.test(e))return i}return null}}]),e}(),ga=new va,ma=function(){function e(t){x(this,e),this.manager=void 0!==t?t:ga,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={}}return I(e,[{key:"load",value:function(){}},{key:"loadAsync",value:function(e,t){var n=this;return new Promise((function(r,i){n.load(e,r,t,i)}))}},{key:"parse",value:function(){}},{key:"setCrossOrigin",value:function(e){return this.crossOrigin=e,this}},{key:"setWithCredentials",value:function(e){return this.withCredentials=e,this}},{key:"setPath",value:function(e){return this.path=e,this}},{key:"setResourcePath",value:function(e){return this.resourcePath=e,this}},{key:"setRequestHeader",value:function(e){return this.requestHeader=e,this}}]),e}(),ya={},_a=function(e){m(n,ma);var t=_(n);function n(e){return x(this,n),t.call(this,e)}return I(n,[{key:"load",value:function(e,t,n,r){var i=this;void 0===e&&(e=""),void 0!==this.path&&(e=this.path+e),e=this.manager.resolveURL(e);var s=pa.get(e);if(void 0!==s)return this.manager.itemStart(e),Fe.scheduleTask((function(){t&&t(s),i.manager.itemEnd(e)}),0),s;if(void 0===ya[e]){ya[e]=[],ya[e].push({onLoad:t,onProgress:n,onError:r});var a=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),o=this.mimeType,A=this.responseType;fetch(a).then((function(t){if(200===t.status||0===t.status){if(0===t.status&&console.warn("FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===t.body.getReader)return t;var n=ya[e],r=t.body.getReader(),i=t.headers.get("Content-Length"),s=i?parseInt(i):0,a=0!==s,o=0,A=new ReadableStream({start:function(e){!function t(){r.read().then((function(r){var i=r.done,A=r.value;if(i)e.close();else{o+=A.byteLength;for(var c=new ProgressEvent("progress",{lengthComputable:a,loaded:o,total:s}),l=0,u=n.length;l<u;l++){var h=n[l];h.onProgress&&h.onProgress(c)}e.enqueue(A),t()}}))}()}});return new Response(A)}throw Error('fetch for "'.concat(t.url,'" responded with ').concat(t.status,": ").concat(t.statusText))})).then((function(e){switch(A){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then((function(e){return(new DOMParser).parseFromString(e,o)}));case"json":return e.json();default:if(void 0===o)return e.text();var t=/charset="?([^;"\s]*)"?/i.exec(o),n=t&&t[1]?t[1].toLowerCase():void 0,r=new TextDecoder(n);return e.arrayBuffer().then((function(e){return r.decode(e)}))}})).then((function(t){pa.add(e,t);var n=ya[e];delete ya[e];for(var r=0,i=n.length;r<i;r++){var s=n[r];s.onLoad&&s.onLoad(t)}})).catch((function(t){var n=ya[e];if(void 0===n)throw i.manager.itemError(e),t;delete ya[e];for(var r=0,s=n.length;r<s;r++){var a=n[r];a.onError&&a.onError(t)}i.manager.itemError(e)})).finally((function(){i.manager.itemEnd(e)})),this.manager.itemStart(e)}else ya[e].push({onLoad:t,onProgress:n,onError:r})}},{key:"setResponseType",value:function(e){return this.responseType=e,this}},{key:"setMimeType",value:function(e){return this.mimeType=e,this}}]),n}(),ba=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:4;x(this,e),this.pool=t,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}return I(e,[{key:"_initWorker",value:function(e){if(!this.workers[e]){var t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}},{key:"_getIdleWorker",value:function(){for(var e=0;e<this.pool;e++)if(!(this.workerStatus&1<<e))return e;return-1}},{key:"_onMessage",value:function(e,t){var n=this.workersResolve[e];if(n&&n(t),this.queue.length){var r=this.queue.shift(),i=r.resolve,s=r.msg,a=r.transfer;this.workersResolve[e]=i,this.workers[e].postMessage(s,a)}else this.workerStatus^=1<<e}},{key:"setWorkerCreator",value:function(e){this.workerCreator=e}},{key:"setWorkerLimit",value:function(e){this.pool=e}},{key:"postMessage",value:function(e,t){var n=this;return new Promise((function(r){var i=n._getIdleWorker();-1!==i?(n._initWorker(i),n.workerStatus|=1<<i,n.workersResolve[i]=r,n.workers[i].postMessage(e,t)):n.queue.push({resolve:r,msg:e,transfer:t})}))}},{key:"destroy",value:function(){this.workers.forEach((function(e){return e.terminate()})),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}]),e}(),wa=0,Ba=function(){function e(t){var n=t.viewer,r=t.transcoderPath,i=t.workerLimit;x(this,e),this._transcoderPath=r||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new ba,this._workerSourceURL="",i&&this._workerPool.setWorkerLimit(i);var s=n.capabilities;this._workerConfig={astcSupported:s.astcSupported,etc1Supported:s.etc1Supported,etc2Supported:s.etc2Supported,dxtSupported:s.dxtSupported,bptcSupported:s.bptcSupported,pvrtcSupported:s.pvrtcSupported},this._supportedFileTypes=["xkt2"]}return I(e,[{key:"_init",value:function(){var t=this;if(!this._transcoderPending){var n=new _a;n.setPath(this._transcoderPath),n.setWithCredentials(this.withCredentials);var r=n.loadAsync("basis_transcoder.js"),i=new _a;i.setPath(this._transcoderPath),i.setResponseType("arraybuffer"),i.setWithCredentials(this.withCredentials);var s=i.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([r,s]).then((function(n){var r=k(n,2),i=r[0],s=r[1],a=e.BasisWorker.toString(),o=["/* constants */","let _EngineFormat = "+JSON.stringify(e.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(e.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(e.BasisFormat),"/* basis_transcoder.js */",i,"/* worker */",a.substring(a.indexOf("{")+1,a.lastIndexOf("}"))].join("\n");t._workerSourceURL=URL.createObjectURL(new Blob([o])),t._transcoderBinary=s,t._workerPool.setWorkerCreator((function(){var e=new Worker(t._workerSourceURL),n=t._transcoderBinary.slice(0);return e.postMessage({type:"init",config:t._workerConfig,transcoderBinary:n},[n]),e}))})),wa>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),wa++}return this._transcoderPending}},{key:"transcode",value:function(e,t){var n=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,s){var a=r;n._init().then((function(){return n._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:a},e)})).then((function(e){var n=e.data,r=n.mipmaps,a=(n.width,n.height,n.format),o=n.type,A=n.error,c=n.dfdTransferFn,l=n.dfdFlags;if("error"===o)return s(A);t.setCompressedData({mipmaps:r,props:{format:a,minFilter:1===r.length?1006:1008,magFilter:1===r.length?1006:1008,encoding:2===c?3001:3e3,premultiplyAlpha:!!(1&l)}}),i()}))}))}},{key:"destroy",value:function(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),wa--}}]),e}();Ba.BasisFormat={ETC1S:0,UASTC_4x4:1},Ba.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},Ba.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},Ba.BasisWorker=function(){var e,t,n,r=_EngineFormat,i=_TranscoderFormat,s=_BasisFormat;self.addEventListener("message",(function(a){var l,u=a.data;switch(u.type){case"init":e=u.config,l=u.transcoderBinary,t=new Promise((function(e){n={wasmBinary:l,onRuntimeInitialized:e},BASIS(n)})).then((function(){n.initializeBasis(),void 0===n.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((function(){try{for(var t=function(t){var a=new n.KTX2File(new Uint8Array(t));function l(){a.close(),a.delete()}if(!a.isValid())throw l(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");var u=a.isUASTC()?s.UASTC_4x4:s.ETC1S,h=a.getWidth(),d=a.getHeight(),f=a.getLevels(),p=a.getHasAlpha(),v=a.getDFDTransferFunc(),g=a.getDFDFlags(),m=function(t,n,a,l){for(var u,h,d=t===s.ETC1S?o:A,f=0;f<d.length;f++){var p=d[f];if(e[p.if]&&(p.basisFormat.includes(t)&&!(l&&p.transcoderFormat.length<2)&&(!p.needsPowerOfTwo||c(n)&&c(a))))return{transcoderFormat:u=p.transcoderFormat[l?1:0],engineFormat:h=p.engineFormat[l?1:0]}}return console.warn("KTX2TextureTranscoder: No suitable compressed texture format found. Decoding to RGBA32."),u=i.RGBA32,h=r.RGBAFormat,{transcoderFormat:u,engineFormat:h}}(u,h,d,p),y=m.transcoderFormat,_=m.engineFormat;if(!h||!d||!f)throw l(),new Error("KTX2TextureTranscoder: Invalid texture");if(!a.startTranscoding())throw l(),new Error("KTX2TextureTranscoder: .startTranscoding failed");for(var b=[],w=0;w<f;w++){var B=a.getImageLevelInfo(w,0,0),C=B.origWidth,M=B.origHeight,k=new Uint8Array(a.getImageTranscodedSizeInBytes(w,0,0,y));if(!a.transcodeImage(k,w,0,0,y,0,-1,-1))throw l(),new Error("KTX2TextureTranscoder: .transcodeImage failed.");b.push({data:k,width:C,height:M})}return l(),{width:h,height:d,hasAlpha:p,mipmaps:b,format:_,dfdTransferFn:v,dfdFlags:g}}(u.buffers[0]),a=t.width,l=t.height,h=t.hasAlpha,d=t.mipmaps,f=t.format,p=t.dfdTransferFn,v=t.dfdFlags,g=[],m=0;m<d.length;++m)g.push(d[m].data.buffer);self.postMessage({type:"transcode",id:u.id,width:a,height:l,hasAlpha:h,mipmaps:d,format:f,dfdTransferFn:p,dfdFlags:v},g)}catch(e){console.error("[KTX2TextureTranscoder.BasisWorker]: ".concat(e)),self.postMessage({type:"error",id:u.id,error:e.message})}}))}}));var a=[{if:"astcSupported",basisFormat:[s.UASTC_4x4],transcoderFormat:[i.ASTC_4x4,i.ASTC_4x4],engineFormat:[r.RGBA_ASTC_4x4_Format,r.RGBA_ASTC_4x4_Format],priorityETC1S:1/0,priorityUASTC:1,needsPowerOfTwo:!1},{if:"bptcSupported",basisFormat:[s.ETC1S,s.UASTC_4x4],transcoderFormat:[i.BC7_M5,i.BC7_M5],engineFormat:[r.RGBA_BPTC_Format,r.RGBA_BPTC_Format],priorityETC1S:3,priorityUASTC:2,needsPowerOfTwo:!1},{if:"dxtSupported",basisFormat:[s.ETC1S,s.UASTC_4x4],transcoderFormat:[i.BC1,i.BC3],engineFormat:[r.RGB_S3TC_DXT1_Format,r.RGBA_S3TC_DXT5_Format],priorityETC1S:4,priorityUASTC:5,needsPowerOfTwo:!1},{if:"etc2Supported",basisFormat:[s.ETC1S,s.UASTC_4x4],transcoderFormat:[i.ETC1,i.ETC2],engineFormat:[r.RGB_ETC2_Format,r.RGBA_ETC2_EAC_Format],priorityETC1S:1,priorityUASTC:3,needsPowerOfTwo:!1},{if:"etc1Supported",basisFormat:[s.ETC1S,s.UASTC_4x4],transcoderFormat:[i.ETC1],engineFormat:[r.RGB_ETC1_Format],priorityETC1S:2,priorityUASTC:4,needsPowerOfTwo:!1},{if:"pvrtcSupported",basisFormat:[s.ETC1S,s.UASTC_4x4],transcoderFormat:[i.PVRTC1_4_RGB,i.PVRTC1_4_RGBA],engineFormat:[r.RGB_PVRTC_4BPPV1_Format,r.RGBA_PVRTC_4BPPV1_Format],priorityETC1S:5,priorityUASTC:6,needsPowerOfTwo:!0}],o=a.sort((function(e,t){return e.priorityETC1S-t.priorityETC1S})),A=a.sort((function(e,t){return e.priorityUASTC-t.priorityUASTC}));function c(e){return e<=2||0==(e&e-1)&&0!==e}};var Ca={};function Ma(e){var t=e.scene.id,n=Ca[t];return n||(n=new Ba({viewer:e}),Ca[t]=n,e.scene.on("destroyed",(function(){delete Ca[t],n.destroy()}))),n}
7
+ var e,t,n,r=A().mark(Dh),i=A().mark(Qh),s=A().mark(_v);function a(e){var t="function"==typeof Map?new Map:void 0;return a=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return o(e,arguments,C(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),y(r,e)},a(e)}function o(e,t,n){return o=B()?Reflect.construct.bind():function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&y(i,n.prototype),i},o.apply(null,arguments)}function A(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */A=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",s=r.asyncIterator||"@@asyncIterator",a=r.toStringTag||"@@toStringTag";function o(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{o({},"")}catch(e){o=function(e,t,n){return e[t]=n}}function c(e,t,n,r){var i=t&&t.prototype instanceof h?t:h,s=Object.create(i.prototype),a=new C(r||[]);return s._invoke=function(e,t,n){var r="suspendedStart";return function(i,s){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw s;return E()}for(n.method=i,n.arg=s;;){var a=n.delegate;if(a){var o=b(a,n);if(o){if(o===u)continue;return o}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var A=l(e,t,n);if("normal"===A.type){if(r=n.done?"completed":"suspendedYield",A.arg===u)continue;return{value:A.arg,done:n.done}}"throw"===A.type&&(r="completed",n.method="throw",n.arg=A.arg)}}}(e,n,a),s}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var u={};function h(){}function d(){}function f(){}var p={};o(p,i,(function(){return this}));var v=Object.getPrototypeOf,g=v&&v(v(k([])));g&&g!==t&&n.call(g,i)&&(p=g);var m=f.prototype=h.prototype=Object.create(p);function y(e){["next","throw","return"].forEach((function(t){o(e,t,(function(e){return this._invoke(t,e)}))}))}function _(e,t){function r(i,s,a,o){var A=l(e[i],e,s);if("throw"!==A.type){var c=A.arg,u=c.value;return u&&"object"==M(u)&&n.call(u,"__await")?t.resolve(u.__await).then((function(e){r("next",e,a,o)}),(function(e){r("throw",e,a,o)})):t.resolve(u).then((function(e){c.value=e,a(c)}),(function(e){return r("throw",e,a,o)}))}o(A.arg)}var i;this._invoke=function(e,n){function s(){return new t((function(t,i){r(e,n,t,i)}))}return i=i?i.then(s,s):s()}}function b(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,b(e,t),"throw"===t.method))return u;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return u}var r=l(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,u;var i=r.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,u):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,u)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function B(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function C(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function k(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,s=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return s.next=s}}return{next:E}}function E(){return{value:void 0,done:!0}}return d.prototype=f,o(m,"constructor",f),o(f,"constructor",d),d.displayName=o(f,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,f):(e.__proto__=f,o(e,a,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},y(_.prototype),o(_.prototype,s,(function(){return this})),e.AsyncIterator=_,e.async=function(t,n,r,i,s){void 0===s&&(s=Promise);var a=new _(c(t,n,r,i),s);return e.isGeneratorFunction(n)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},y(m),o(m,a,"Generator"),o(m,i,(function(){return this})),o(m,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=k,C.prototype={constructor:C,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(B),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return a.type="throw",a.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var s=this.tryEntries[i],a=s.completion;if("root"===s.tryLoc)return r("end");if(s.tryLoc<=this.prev){var o=n.call(s,"catchLoc"),A=n.call(s,"finallyLoc");if(o&&A){if(this.prev<s.catchLoc)return r(s.catchLoc,!0);if(this.prev<s.finallyLoc)return r(s.finallyLoc)}else if(o){if(this.prev<s.catchLoc)return r(s.catchLoc,!0)}else{if(!A)throw new Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return r(s.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var s=i;break}}s&&("break"===e||"continue"===e)&&s.tryLoc<=t&&t<=s.finallyLoc&&(s=null);var a=s?s.completion:{};return a.type=e,a.arg=t,s?(this.method="next",this.next=s.finallyLoc,u):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),u},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),B(n),u}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;B(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),u}},e}function c(e,t,n,r,i,s,a){try{var o=e[s](a),A=o.value}catch(e){return void n(e)}o.done?t(A):Promise.resolve(A).then(r,i)}function l(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var s=e.apply(t,n);function a(e){c(s,r,i,a,o,"next",e)}function o(e){c(s,r,i,a,o,"throw",e)}a(void 0)}))}}function u(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=E(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){o=!0,s=e},f:function(){try{a||null==n.return||n.return()}finally{if(o)throw s}}}}function h(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function d(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?h(Object(n),!0).forEach((function(t){f(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):h(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function f(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function p(e){return function(e){if(Array.isArray(e))return F(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||E(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(){return v="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var r=g(e,t);if(r){var i=Object.getOwnPropertyDescriptor(r,t);return i.get?i.get.call(arguments.length<3?e:n):i.value}},v.apply(this,arguments)}function g(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=C(e)););return e}function m(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&y(e,t)}function y(e,t){return y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},y(e,t)}function _(e){var t=B();return function(){var n,r=C(e);if(t){var i=C(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return b(this,n)}}function b(e,t){if(t&&("object"===M(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return w(e)}function w(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function B(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function C(e){return C=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},C(e)}function M(e){return M="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},M(e)}function k(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,i,s=[],a=!0,o=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(s.push(r.value),!t||s.length!==t);a=!0);}catch(e){o=!0,i=e}finally{try{a||null==n.return||n.return()}finally{if(o)throw i}}return s}(e,t)||E(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function E(e,t){if(e){if("string"==typeof e)return F(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?F(e,t):void 0}}function F(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function x(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function U(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function I(e,t,n){return t&&U(e.prototype,t),n&&U(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function T(e){return new D(e)}function P(e){return function(){return new S(e.apply(this,arguments))}}function S(e){var t,n;function r(t,n){try{var s=e[t](n),a=s.value,o=a instanceof D;Promise.resolve(o?a.wrapped:a).then((function(e){o?r("return"===t?"return":"next",e):i(s.done?"return":"normal",e)}),(function(e){r("throw",e)}))}catch(e){i("throw",e)}}function i(e,i){switch(e){case"return":t.resolve({value:i,done:!0});break;case"throw":t.reject(i);break;default:t.resolve({value:i,done:!1})}(t=t.next)?r(t.key,t.arg):n=null}this._invoke=function(e,i){return new Promise((function(s,a){var o={key:e,arg:i,resolve:s,reject:a,next:null};n?n=n.next=o:(t=n=o,r(e,i))}))},"function"!=typeof e.return&&(this.return=void 0)}function D(e){this.wrapped=e}function Q(e){var t,n,r,i=2;for("undefined"!=typeof Symbol&&(n=Symbol.asyncIterator,r=Symbol.iterator);i--;){if(n&&null!=(t=e[n]))return t.call(e);if(r&&null!=(t=e[r]))return new R(t.call(e));n="@@asyncIterator",r="@@iterator"}throw new TypeError("Object is not async iterable")}function R(e){function t(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));var t=e.done;return Promise.resolve(e.value).then((function(e){return{value:e,done:t}}))}return R=function(e){this.s=e,this.n=e.next},R.prototype={s:null,n:null,next:function(){return t(this.n.apply(this.s,arguments))},return:function(e){var n=this.s.return;return void 0===n?Promise.resolve({value:e,done:!0}):t(n.apply(this.s,arguments))},throw:function(e){var n=this.s.return;return void 0===n?Promise.reject(e):t(n.apply(this.s,arguments))}},new R(e)}S.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},S.prototype.next=function(e){return this._invoke("next",e)},S.prototype.throw=function(e){return this._invoke("throw",e)},S.prototype.return=function(e){return this._invoke("return",e)},"undefined"!=typeof window&&(window.__XEOKIT__={version:"2.6.94",commit:"32b1b9841f49a7817cfc809cbbee180486784356",built:"2025-11-03T13:06:26.987Z"});var O,V,L,H,N,G,j,W,z,X,K,Z=function(){function e(t,n){x(this,e),this.items=t||[],this._lastUniqueId=(n||0)+1}return I(e,[{key:"addItem",value:function(){var e;if(2===arguments.length){var t=arguments[0];if(e=arguments[1],this.items[t])throw"ID clash: '"+t+"'";return this.items[t]=e,t}for(e=arguments[0]||{};;){var n=this._lastUniqueId++;if(!this.items[n])return this.items[n]=e,n}}},{key:"removeItem",value:function(e){var t=this.items[e];return delete this.items[e],t}}]),e}(),J=new Z,Y=I((function e(t){x(this,e),this.id=t,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0})),q=I((function e(){x(this,e),this.items=[]})),$=I((function e(t,n,r,i,s){x(this,e),this.id=t,this.getTitle=n,this.doAction=r,this.getEnabled=i,this.getShown=s,this.itemElement=null,this.subMenu=null,this.enabled=!0})),ee=function(){function e(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};x(this,e),this._id=J.addItem(),this._context=null,this._enabled=!1,this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={},this._shown=!1,this._nextId=0,this._parentNode=n.parentNode||document.body,this._offsetParent=this._parentNode instanceof ShadowRoot?this._parentNode.host:this._parentNode,this._eventSubs={},!1!==n.hideOnMouseDown&&(this._parentNode.addEventListener("mousedown",(function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),this._parentNode.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),n.items&&(this.items=n.items),this._hideOnAction=!1!==n.hideOnAction,this.context=n.context,this.enabled=!1!==n.enabled,this.hide()}return I(e,[{key:"on",value:function(e,t){var n=this._eventSubs[e];n||(n=[],this._eventSubs[e]=n),n.push(t)}},{key:"fire",value:function(e,t){var n=this._eventSubs[e];if(n)for(var r=0,i=n.length;r<i;r++)n[r](t)}},{key:"items",get:function(){return this._itemsCfg},set:function(e){this._clear(),this._itemsCfg=e||[],this._parseItems(e),this._createUI()}},{key:"enabled",get:function(){return this._enabled},set:function(e){(e=!!e)!==this._enabled&&(this._enabled=e,this._enabled||this.hide())}},{key:"context",get:function(){return this._context},set:function(e){this._context=e}},{key:"show",value:function(e,t){this._context?this._enabled&&(this._shown||(this._hideAllMenus(),this._updateItemsTitles(),this._updateItemsEnabledStatus(),this._showMenu(this._rootMenu.id,e,t),this._updateSubMenuInfo(),this._shown=!0,this.fire("shown",{}))):console.error("ContextMenu cannot be shown without a context - set context first")}},{key:"shown",get:function(){return this._shown}},{key:"hide",value:function(){this._enabled&&this._shown&&(this._hideAllMenus(),this._shown=!1,this.fire("hidden",{}))}},{key:"destroy",value:function(){this._context=null,this._clear(),null!==this._id&&(J.removeItem(this._id),this._id=null)}},{key:"_clear",value:function(){for(var e=0,t=this._menuList.length;e<t;e++){this._menuList[e].menuElement.remove()}this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={}}},{key:"_parseItems",value:function(e){var t=this;this._rootMenu=function e(n){for(var r=t._getNextId(),i=new Y(r),s=0,a=n.length;s<a;s++){var o=n[s],A=new q;i.groups.push(A);for(var c=function(n,r){var s=o[n],a=s.items,c=a&&a.length>0,l=t._getNextId(),u=s.getTitle||function(){return s.title||""},h=s.doAction||s.callback||function(){},d=s.getEnabled||function(){return!0},f=s.getShown||function(){return!0},p=new $(l,u,h,d,f);if(p.parentMenu=i,A.items.push(p),c){var v=e(a);p.subMenu=v,v.parentItem=p}t._itemList.push(p),t._itemMap[p.id]=p},l=0,u=o.length;l<u;l++)c(l)}return t._menuList.push(i),t._menuMap[i.id]=i,i}(e)}},{key:"_getNextId",value:function(){return"ContextMenu_"+this._id+"_"+this._nextId++}},{key:"_createUI",value:function(){var e=this;!function t(n){e._createMenuUI(n);for(var r=n.groups,i=0,s=r.length;i<s;i++)for(var a=r[i].items,o=0,A=a.length;o<A;o++){var c=a[o].subMenu;c&&t(c)}}(this._rootMenu)}},{key:"_createMenuUI",value:function(e){var t=this,n=e.groups,r=[],i=document.createElement("div");if(i.classList.add("xeokit-context-menu",e.id),i.style.zIndex=3e5,i.style.position="absolute",r.push("<ul>"),n)for(var s=0,a=n.length;s<a;s++){var o=s,A=a,c=n[s].items;if(c)for(var l=0,u=c.length;l<u;l++){var h=c[l],d=h.subMenu,f=h.title||"";d?(r.push('<li id="'+h.id+'" class="xeokit-context-menu-item xeokit-context-menu-submenu">'+f+"</li>"),o===A-1||l<u-1||r.push('<li id="'+h.id+'" class="xeokit-context-menu-item-separator"></li>')):(r.push('<li id="'+h.id+'" class="xeokit-context-menu-item">'+f+"</li>"),o===A-1||l<u-1||r.push('<li id="'+h.id+'" class="xeokit-context-menu-item-separator"></li>'))}}r.push("</ul>");var p=r.join("");i.innerHTML=p,this._parentNode.appendChild(i),e.menuElement=i,i.style["border-radius"]="4px",i.style.display="none",i.style["z-index"]=3e5,i.style.background="white",i.style.border="1px solid black",i.style["box-shadow"]="0 4px 5px 0 gray",i.oncontextmenu=function(e){e.preventDefault()};var v=this,g=null;if(n)for(var m=0,y=n.length;m<y;m++){var _=n[m].items;if(_)for(var b=function(e,n){var r=_[e],i=r.subMenu;if(r.itemElement=t._parentNode.querySelector("#".concat(r.id)),!r.itemElement)return console.error("ContextMenu item element not found: "+r.id),"continue";r.itemElement.addEventListener("mouseenter",(function(e){e.preventDefault();var t=r.subMenu;if(t){if(g&&g.id!==t.id&&(v._hideMenu(g.id),g=null),!1!==r.enabled){var n=r.itemElement,i=t.menuElement,s=n.getBoundingClientRect();i.getBoundingClientRect();var a=v._offsetParent.getBoundingClientRect(),o=200,A=s.right+o<a.right,c=s.left-o>a.left;if(A)v._showMenu(t.id,s.right+window.scrollX-5,s.top+window.scrollY-1);else if(c)v._showMenu(t.id,s.left-o+window.scrollX,s.top+window.scrollY-1);else{var l=s.left-a.left,u=a.right-s.right;u>l?v._showMenu(t.id,s.right-5-(o-u),s.top+window.scrollY-1):v._showMenu(t.id,s.left-l,s.top+window.scrollY-1)}g=t}}else g&&(v._hideMenu(g.id),g=null)})),i||(r.itemElement.addEventListener("click",(function(e){e.preventDefault(),v._context&&!1!==r.enabled&&(r.doAction&&r.doAction(v._context),t._hideOnAction?v.hide():(v._updateItemsTitles(),v._updateItemsEnabledStatus()))})),r.itemElement.addEventListener("mouseup",(function(e){3===e.which&&(e.preventDefault(),v._context&&!1!==r.enabled&&(r.doAction&&r.doAction(v._context),t._hideOnAction?v.hide():(v._updateItemsTitles(),v._updateItemsEnabledStatus())))})),r.itemElement.addEventListener("mouseenter",(function(e){e.preventDefault(),!1!==r.enabled&&r.doHover&&r.doHover(v._context)})))},w=0,B=_.length;w<B;w++)b(w)}}},{key:"_updateItemsTitles",value:function(){if(this._context)for(var e=0,t=this._itemList.length;e<t;e++){var n=this._itemList[e],r=n.itemElement;if(r){var i=n.getShown;if(i&&i(this._context)){var s=n.getTitle(this._context);n.subMenu,r.innerText=s}}}}},{key:"_updateItemsEnabledStatus",value:function(){if(this._context)for(var e=0,t=this._itemList.length;e<t;e++){var n=this._itemList[e],r=n.itemElement;if(r){var i=n.getEnabled;if(i){var s=n.getShown;if(s){var a=s(this._context);if(n.shown=a,a){r.style.display="";var o=i(this._context);n.enabled=o,o?r.classList.remove("disabled"):r.classList.add("disabled")}else r.style.display="none"}}}}}},{key:"_updateSubMenuInfo",value:function(){var e,t,n,r,i,s;this._context&&this._itemList.forEach((function(a){a.subMenu&&(e=a.itemElement,t=e.getBoundingClientRect(),n=a.subMenu.menuElement,r={visibility:n.style.visibility,display:n.style.display},n.style.display="block",n.style.visibility="hidden",s=a.subMenu.menuElement.getBoundingClientRect().width,n.style.visibility=r.visibility,n.style.display=r.display,i=t.right+s>window.innerWidth,e.setAttribute("data-submenuposition",i?"left":"right"))}))}},{key:"_showMenu",value:function(e,t,n){var r=this._menuMap[e];if(r){if(!r.shown){var i=r.menuElement;i&&(this._showMenuElement(i,t,n),r.shown=!0)}}else console.error("Menu not found: "+e)}},{key:"_hideMenu",value:function(e){var t=this._menuMap[e];if(t){if(t.shown){var n=t.menuElement;n&&(this._hideMenuElement(n),t.shown=!1)}}else console.error("Menu not found: "+e)}},{key:"_hideAllMenus",value:function(){for(var e=0,t=this._menuList.length;e<t;e++){var n=this._menuList[e];this._hideMenu(n.id)}}},{key:"_showMenuElement",value:function(e,t,n){e.style.display="block";var r=e.offsetHeight,i=e.offsetWidth,s=this._offsetParent.getBoundingClientRect(),a=this._offsetParent===window.document.body&&0===s.bottom?window.innerHeight:s.bottom+window.scrollY,o=s.right+window.scrollX;n+r>a&&(n=a-r),t+i>o&&(t=o-i),e.style.left=t-s.left-window.scrollX+"px",e.style.top=n-s.top-window.scrollY+"px"}},{key:"_hideMenuElement",value:function(e){e.style.display="none"}}]),e}(),te=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this.viewer=t,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=r.containerId||"xeokit-lens",this._lensContainer.setAttribute("id",this._lensContainerId),this._lensContainer.style.border="1px solid black",this._lensContainer.style.background="white",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="".concat(this._lensContainerId,"-canvas"),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=r.lensPosToggle||!0,this._lensPosToggleAmount=r.lensPosToggleAmount||85,this._lensPosMarginLeft=r.lensPosMarginLeft||85,this._lensPosMarginTop=r.lensPosMarginTop||25,this._lensContainer.style.marginTop="".concat(this._lensPosMarginTop,"px"),this._lensContainer.style.marginLeft="".concat(this._lensPosMarginLeft,"px"),this._zoomLevel=r.zoomLevel||2,this._active=!1!==r.active,this._visible=!1,this.snapped=!1,this._onViewerRendering=this.viewer.scene.on("rendering",(function(){n._active&&n._visible&&n.update()}))}return I(e,[{key:"update",value:function(){if(this._active&&this._visible&&this._canvasPos){var e=this._lensContainer.getBoundingClientRect(),t=this._canvasElement.getBoundingClientRect(),n=this._canvasPos[0]<e.right&&this._canvasPos[0]>e.left&&this._canvasPos[1]<e.bottom&&this._canvasPos[1]>e.top;this._lensContainer.style.marginLeft="".concat(this._lensPosMarginLeft,"px"),n&&(this._lensPosToggle?this._lensContainer.style.marginTop="".concat(t.bottom-t.top-this._lensCanvas.height-this._lensPosToggleAmount,"px"):this._lensContainer.style.marginTop="".concat(this._lensPosMarginTop,"px"),this._lensPosToggle=!this._lensPosToggle),this._lensCanvasContext.clearRect(0,0,this._lensCanvas.width,this._lensCanvas.height);var r=Math.max(this._lensCanvas.width,this._lensCanvas.height)/this._zoomLevel;this._lensCanvasContext.drawImage(this._canvasElement,this._canvasPos[0]-r/2,this._canvasPos[1]-r/2,r,r,0,0,this._lensCanvas.width,this._lensCanvas.height);var i=this._lensParams.canvasSize/2-this._lensParams.cursorSize/2-this._lensParams.cursorBorder,s=this._snappedCanvasPos?this._snappedCanvasPos[0]-this._canvasPos[0]:0,a=this._snappedCanvasPos?this._snappedCanvasPos[1]-this._canvasPos[1]:0;this._lensCursorDiv.style.left="".concat(i+s*this._zoomLevel,"px"),this._lensCursorDiv.style.top="".concat(i+a*this._zoomLevel,"px")}}},{key:"zoomFactor",get:function(){return this._zoomFactor},set:function(e){this._zoomFactor=e,this.update()}},{key:"canvasPos",get:function(){return this._canvasPos},set:function(e){this._canvasPos=e,this.update()}},{key:"snappedCanvasPos",get:function(){return this._snappedCanvasPos},set:function(e){this._snappedCanvasPos=e,this.update()}},{key:"snapped",get:function(){return this._snapped},set:function(e){this._snapped=e;var t=k(e?["greenyellow","green"]:["pink","red"],2),n=t[0],r=t[1];this._lensCursorDiv.style.background=n,this._lensCursorDiv.style.border=this._lensParams.cursorBorder+"px solid "+r}},{key:"_updateActiveVisible",value:function(){this._lensContainer.style.visibility=this._active&&this._visible?"visible":"hidden",this.update()}},{key:"active",get:function(){return this._active},set:function(e){this._active=e,this._updateActiveVisible()}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=e,this._updateActiveVisible()}},{key:"destroy",value:function(){this._destroyed||(this.viewer.scene.off(this._onViewerRendering),this._lensContainer.removeChild(this._lensCanvas),document.body.removeChild(this._lensContainer),this._destroyed=!0)}}]),e}(),ne=!0,re=ne?Float64Array:Float32Array,ie=new re(3),se=new re(16),ae=new re(16),oe=new re(4),Ae={setDoublePrecisionEnabled:function(e){re=(ne=e)?Float64Array:Float32Array},getDoublePrecisionEnabled:function(){return ne},MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId:function(e,t){var n=t.indexOf("#");return n===e.length&&t.startsWith(e)?t.substring(n+1):t},globalizeObjectId:function(e,t){return e+"#"+t},safeInv:function(e){var t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:function(e){return new re(e||2)},vec3:function(e){return new re(e||3)},vec4:function(e){return new re(e||4)},mat3:function(e){return new re(e||9)},mat3ToMat4:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new re(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},mat4:function(e){return new re(e||16)},mat4ToMat3:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new re(9);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t},doublesToFloats:function(e,t,n){for(var r=new re(2),i=0,s=e.length;i<s;i++)Ae.splitDouble(e[i],r),t[i]=r[0],n[i]=r[1]},splitDouble:function(e,t){var n=re.from([e])[0],r=e-n;t[0]=n,t[1]=r},createUUID:function(){for(var e=[],t=0;t<256;t++)e[t]=(t<16?"0":"")+t.toString(16);return function(){var t=4294967295*Math.random()|0,n=4294967295*Math.random()|0,r=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return"".concat(e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255],"-").concat(e[255&n]).concat(e[n>>8&255],"-").concat(e[n>>16&15|64]).concat(e[n>>24&255],"-").concat(e[63&r|128]).concat(e[r>>8&255],"-").concat(e[r>>16&255]).concat(e[r>>24&255]).concat(e[255&i]).concat(e[i>>8&255]).concat(e[i>>16&255]).concat(e[i>>24&255])}}(),clamp:function(e,t,n){return Math.max(t,Math.min(n,e))},fmod:function(e,t){if(e<t)return console.error("math.fmod : Attempting to find modulus within negative range - would be infinite loop - ignoring"),e;for(;t<=e;)e-=t;return e},compareVec3:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]},compareVec4:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]},negateVec3:function(e,t){return t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t},negateVec4:function(e,t){return t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t},addVec4:function(e,t,n){return n||(n=e),n[0]=e[0]+t[0],n[1]=e[1]+t[1],n[2]=e[2]+t[2],n[3]=e[3]+t[3],n},addVec4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]+t,n[1]=e[1]+t,n[2]=e[2]+t,n[3]=e[3]+t,n},addVec3:function(e,t,n){return n||(n=e),n[0]=e[0]+t[0],n[1]=e[1]+t[1],n[2]=e[2]+t[2],n},addVec3Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]+t,n[1]=e[1]+t,n[2]=e[2]+t,n},subVec4:function(e,t,n){return n||(n=e),n[0]=e[0]-t[0],n[1]=e[1]-t[1],n[2]=e[2]-t[2],n[3]=e[3]-t[3],n},subVec3:function(e,t,n){return n||(n=e),n[0]=e[0]-t[0],n[1]=e[1]-t[1],n[2]=e[2]-t[2],n},subVec2:function(e,t,n){return n||(n=e),n[0]=e[0]-t[0],n[1]=e[1]-t[1],n},geometricMeanVec2:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=new re(t[0]),i=1;i<t.length;i++)r[0]+=t[i][0],r[1]+=t[i][1];return r[0]/=t.length,r[1]/=t.length,r},subVec4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]-t,n[1]=e[1]-t,n[2]=e[2]-t,n[3]=e[3]-t,n},subScalarVec4:function(e,t,n){return n||(n=e),n[0]=t-e[0],n[1]=t-e[1],n[2]=t-e[2],n[3]=t-e[3],n},mulVec4:function(e,t,n){return n||(n=e),n[0]=e[0]*t[0],n[1]=e[1]*t[1],n[2]=e[2]*t[2],n[3]=e[3]*t[3],n},mulVec4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]*t,n[1]=e[1]*t,n[2]=e[2]*t,n[3]=e[3]*t,n},mulVec3Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]*t,n[1]=e[1]*t,n[2]=e[2]*t,n},mulVec2Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]*t,n[1]=e[1]*t,n},divVec3:function(e,t,n){return n||(n=e),n[0]=e[0]/t[0],n[1]=e[1]/t[1],n[2]=e[2]/t[2],n},divVec4:function(e,t,n){return n||(n=e),n[0]=e[0]/t[0],n[1]=e[1]/t[1],n[2]=e[2]/t[2],n[3]=e[3]/t[3],n},divScalarVec3:function(e,t,n){return n||(n=t),n[0]=e/t[0],n[1]=e/t[1],n[2]=e/t[2],n},divVec3Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]/t,n[1]=e[1]/t,n[2]=e[2]/t,n},divVec4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]/t,n[1]=e[1]/t,n[2]=e[2]/t,n[3]=e[3]/t,n},divScalarVec4:function(e,t,n){return n||(n=t),n[0]=e/t[0],n[1]=e/t[1],n[2]=e/t[2],n[3]=e/t[3],n},dotVec4:function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]},cross3Vec4:function(e,t){var n=e[0],r=e[1],i=e[2],s=t[0],a=t[1],o=t[2];return[r*o-i*a,i*s-n*o,n*a-r*s,0]},cross3Vec3:function(e,t,n){n||(n=e);var r=e[0],i=e[1],s=e[2],a=t[0],o=t[1],A=t[2];return n[0]=i*A-s*o,n[1]=s*a-r*A,n[2]=r*o-i*a,n},sqLenVec4:function(e){return Ae.dotVec4(e,e)},lenVec4:function(e){return Math.sqrt(Ae.sqLenVec4(e))},dotVec3:function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]},dotVec2:function(e,t){return e[0]*t[0]+e[1]*t[1]},sqLenVec3:function(e){return Ae.dotVec3(e,e)},sqLenVec2:function(e){return Ae.dotVec2(e,e)},lenVec3:function(e){return Math.sqrt(Ae.sqLenVec3(e))},distVec3:(K=new re(3),function(e,t){return Ae.lenVec3(Ae.subVec3(e,t,K))}),lenVec2:function(e){return Math.sqrt(Ae.sqLenVec2(e))},distVec2:function(){var e=new re(2);return function(t,n){return Ae.lenVec2(Ae.subVec2(t,n,e))}}(),rcpVec3:function(e,t){return Ae.divScalarVec3(1,e,t)},normalizeVec4:function(e,t){var n=1/Ae.lenVec4(e);return Ae.mulVec4Scalar(e,n,t)},normalizeVec3:function(e,t){var n=1/Ae.lenVec3(e);return Ae.mulVec3Scalar(e,n,t)},normalizeVec2:function(e,t){var n=1/Ae.lenVec2(e);return Ae.mulVec2Scalar(e,n,t)},angleVec3:function(e,t){var n=Ae.dotVec3(e,t)/Math.sqrt(Ae.sqLenVec3(e)*Ae.sqLenVec3(t));return n=n<-1?-1:n>1?1:n,Math.acos(n)},vec3FromMat4Scale:function(){var e=new re(3);return function(t,n){return e[0]=t[0],e[1]=t[1],e[2]=t[2],n[0]=Ae.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],n[1]=Ae.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],n[2]=Ae.lenVec3(e),n}}(),vecToArray:function(){function e(e){return Math.round(1e5*e)/1e5}return function(t){for(var n=0,r=(t=Array.prototype.slice.call(t)).length;n<r;n++)t[n]=e(t[n]);return t}}(),xyzArrayToObject:function(e){return{x:e[0],y:e[1],z:e[2]}},xyzObjectToArray:function(e,t){return(t=t||Ae.vec3())[0]=e.x,t[1]=e.y,t[2]=e.z,t},dupMat4:function(e){return e.slice(0,16)},mat4To3:function(e){return[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]]},m4s:function(e){return[e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e]},setMat4ToZeroes:function(){return Ae.m4s(0)},setMat4ToOnes:function(){return Ae.m4s(1)},diagonalMat4v:function(e){return new re([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]])},diagonalMat4c:function(e,t,n,r){return Ae.diagonalMat4v([e,t,n,r])},diagonalMat4s:function(e){return Ae.diagonalMat4c(e,e,e,e)},identityMat4:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new re(16);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},identityMat3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new re(9);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e},isIdentityMat4:function(e){return 1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15]},negateMat4:function(e,t){return t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t},addMat4:function(e,t,n){return n||(n=e),n[0]=e[0]+t[0],n[1]=e[1]+t[1],n[2]=e[2]+t[2],n[3]=e[3]+t[3],n[4]=e[4]+t[4],n[5]=e[5]+t[5],n[6]=e[6]+t[6],n[7]=e[7]+t[7],n[8]=e[8]+t[8],n[9]=e[9]+t[9],n[10]=e[10]+t[10],n[11]=e[11]+t[11],n[12]=e[12]+t[12],n[13]=e[13]+t[13],n[14]=e[14]+t[14],n[15]=e[15]+t[15],n},addMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]+t,n[1]=e[1]+t,n[2]=e[2]+t,n[3]=e[3]+t,n[4]=e[4]+t,n[5]=e[5]+t,n[6]=e[6]+t,n[7]=e[7]+t,n[8]=e[8]+t,n[9]=e[9]+t,n[10]=e[10]+t,n[11]=e[11]+t,n[12]=e[12]+t,n[13]=e[13]+t,n[14]=e[14]+t,n[15]=e[15]+t,n},addScalarMat4:function(e,t,n){return Ae.addMat4Scalar(t,e,n)},subMat4:function(e,t,n){return n||(n=e),n[0]=e[0]-t[0],n[1]=e[1]-t[1],n[2]=e[2]-t[2],n[3]=e[3]-t[3],n[4]=e[4]-t[4],n[5]=e[5]-t[5],n[6]=e[6]-t[6],n[7]=e[7]-t[7],n[8]=e[8]-t[8],n[9]=e[9]-t[9],n[10]=e[10]-t[10],n[11]=e[11]-t[11],n[12]=e[12]-t[12],n[13]=e[13]-t[13],n[14]=e[14]-t[14],n[15]=e[15]-t[15],n},subMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]-t,n[1]=e[1]-t,n[2]=e[2]-t,n[3]=e[3]-t,n[4]=e[4]-t,n[5]=e[5]-t,n[6]=e[6]-t,n[7]=e[7]-t,n[8]=e[8]-t,n[9]=e[9]-t,n[10]=e[10]-t,n[11]=e[11]-t,n[12]=e[12]-t,n[13]=e[13]-t,n[14]=e[14]-t,n[15]=e[15]-t,n},subScalarMat4:function(e,t,n){return n||(n=t),n[0]=e-t[0],n[1]=e-t[1],n[2]=e-t[2],n[3]=e-t[3],n[4]=e-t[4],n[5]=e-t[5],n[6]=e-t[6],n[7]=e-t[7],n[8]=e-t[8],n[9]=e-t[9],n[10]=e-t[10],n[11]=e-t[11],n[12]=e-t[12],n[13]=e-t[13],n[14]=e-t[14],n[15]=e-t[15],n},mulMat4:function(e,t,n){n||(n=e);var r=e[0],i=e[1],s=e[2],a=e[3],o=e[4],A=e[5],c=e[6],l=e[7],u=e[8],h=e[9],d=e[10],f=e[11],p=e[12],v=e[13],g=e[14],m=e[15],y=t[0],_=t[1],b=t[2],w=t[3],B=t[4],C=t[5],M=t[6],k=t[7],E=t[8],F=t[9],x=t[10],U=t[11],I=t[12],T=t[13],P=t[14],S=t[15];return n[0]=y*r+_*o+b*u+w*p,n[1]=y*i+_*A+b*h+w*v,n[2]=y*s+_*c+b*d+w*g,n[3]=y*a+_*l+b*f+w*m,n[4]=B*r+C*o+M*u+k*p,n[5]=B*i+C*A+M*h+k*v,n[6]=B*s+C*c+M*d+k*g,n[7]=B*a+C*l+M*f+k*m,n[8]=E*r+F*o+x*u+U*p,n[9]=E*i+F*A+x*h+U*v,n[10]=E*s+F*c+x*d+U*g,n[11]=E*a+F*l+x*f+U*m,n[12]=I*r+T*o+P*u+S*p,n[13]=I*i+T*A+P*h+S*v,n[14]=I*s+T*c+P*d+S*g,n[15]=I*a+T*l+P*f+S*m,n},mulMat3:function(e,t,n){n||(n=new re(9));var r=e[0],i=e[3],s=e[6],a=e[1],o=e[4],A=e[7],c=e[2],l=e[5],u=e[8],h=t[0],d=t[3],f=t[6],p=t[1],v=t[4],g=t[7],m=t[2],y=t[5],_=t[8];return n[0]=r*h+i*p+s*m,n[3]=r*d+i*v+s*y,n[6]=r*f+i*g+s*_,n[1]=a*h+o*p+A*m,n[4]=a*d+o*v+A*y,n[7]=a*f+o*g+A*_,n[2]=c*h+l*p+u*m,n[5]=c*d+l*v+u*y,n[8]=c*f+l*g+u*_,n},mulMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]*t,n[1]=e[1]*t,n[2]=e[2]*t,n[3]=e[3]*t,n[4]=e[4]*t,n[5]=e[5]*t,n[6]=e[6]*t,n[7]=e[7]*t,n[8]=e[8]*t,n[9]=e[9]*t,n[10]=e[10]*t,n[11]=e[11]*t,n[12]=e[12]*t,n[13]=e[13]*t,n[14]=e[14]*t,n[15]=e[15]*t,n},mulMat4v4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec4(),r=t[0],i=t[1],s=t[2],a=t[3];return n[0]=e[0]*r+e[4]*i+e[8]*s+e[12]*a,n[1]=e[1]*r+e[5]*i+e[9]*s+e[13]*a,n[2]=e[2]*r+e[6]*i+e[10]*s+e[14]*a,n[3]=e[3]*r+e[7]*i+e[11]*s+e[15]*a,n},transposeMat4:function(e,t){var n=e[4],r=e[14],i=e[8],s=e[13],a=e[12],o=e[9];if(!t||e===t){var A=e[1],c=e[2],l=e[3],u=e[6],h=e[7],d=e[11];return e[1]=n,e[2]=i,e[3]=a,e[4]=A,e[6]=o,e[7]=s,e[8]=c,e[9]=u,e[11]=r,e[12]=l,e[13]=h,e[14]=d,e}return t[0]=e[0],t[1]=n,t[2]=i,t[3]=a,t[4]=e[1],t[5]=e[5],t[6]=o,t[7]=s,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=r,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3:function(e,t){if(t===e){var n=e[1],r=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=n,t[5]=e[7],t[6]=r,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4:function(e){var t=e[0],n=e[1],r=e[2],i=e[3],s=e[4],a=e[5],o=e[6],A=e[7],c=e[8],l=e[9],u=e[10],h=e[11],d=e[12],f=e[13],p=e[14],v=e[15];return d*l*o*i-c*f*o*i-d*a*u*i+s*f*u*i+c*a*p*i-s*l*p*i-d*l*r*A+c*f*r*A+d*n*u*A-t*f*u*A-c*n*p*A+t*l*p*A+d*a*r*h-s*f*r*h-d*n*o*h+t*f*o*h+s*n*p*h-t*a*p*h-c*a*r*v+s*l*r*v+c*n*o*v-t*l*o*v-s*n*u*v+t*a*u*v},inverseMat4:function(e,t){t||(t=e);var n=e[0],r=e[1],i=e[2],s=e[3],a=e[4],o=e[5],A=e[6],c=e[7],l=e[8],u=e[9],h=e[10],d=e[11],f=e[12],p=e[13],v=e[14],g=e[15],m=n*o-r*a,y=n*A-i*a,_=n*c-s*a,b=r*A-i*o,w=r*c-s*o,B=i*c-s*A,C=l*p-u*f,M=l*v-h*f,k=l*g-d*f,E=u*v-h*p,F=u*g-d*p,x=h*g-d*v,U=1/(m*x-y*F+_*E+b*k-w*M+B*C);return t[0]=(o*x-A*F+c*E)*U,t[1]=(-r*x+i*F-s*E)*U,t[2]=(p*B-v*w+g*b)*U,t[3]=(-u*B+h*w-d*b)*U,t[4]=(-a*x+A*k-c*M)*U,t[5]=(n*x-i*k+s*M)*U,t[6]=(-f*B+v*_-g*y)*U,t[7]=(l*B-h*_+d*y)*U,t[8]=(a*F-o*k+c*C)*U,t[9]=(-n*F+r*k-s*C)*U,t[10]=(f*w-p*_+g*m)*U,t[11]=(-l*w+u*_-d*m)*U,t[12]=(-a*E+o*M-A*C)*U,t[13]=(n*E-r*M+i*C)*U,t[14]=(-f*b+p*y-v*m)*U,t[15]=(l*b-u*y+h*m)*U,t},traceMat4:function(e){return e[0]+e[5]+e[10]+e[15]},translationMat4v:function(e,t){var n=t||Ae.identityMat4();return n[12]=e[0],n[13]=e[1],n[14]=e[2],n},translationMat3v:function(e,t){var n=t||Ae.identityMat3();return n[6]=e[0],n[7]=e[1],n},translationMat4c:(X=new re(3),function(e,t,n,r){return X[0]=e,X[1]=t,X[2]=n,Ae.translationMat4v(X,r)}),translationMat4s:function(e,t){return Ae.translationMat4c(e,e,e,t)},translateMat4v:function(e,t){return Ae.translateMat4c(e[0],e[1],e[2],t)},translateMat4c:function(e,t,n,r){var i=r[3];r[0]+=i*e,r[1]+=i*t,r[2]+=i*n;var s=r[7];r[4]+=s*e,r[5]+=s*t,r[6]+=s*n;var a=r[11];r[8]+=a*e,r[9]+=a*t,r[10]+=a*n;var o=r[15];return r[12]+=o*e,r[13]+=o*t,r[14]+=o*n,r},setMat4Translation:function(e,t,n){return n[0]=e[0],n[1]=e[1],n[2]=e[2],n[3]=e[3],n[4]=e[4],n[5]=e[5],n[6]=e[6],n[7]=e[7],n[8]=e[8],n[9]=e[9],n[10]=e[10],n[11]=e[11],n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=e[15],n},rotationMat4v:function(e,t,n){var r,i,s,a,o,A,c=Ae.normalizeVec4([t[0],t[1],t[2],0],[]),l=Math.sin(e),u=Math.cos(e),h=1-u,d=c[0],f=c[1],p=c[2];return r=d*f,i=f*p,s=p*d,a=d*l,o=f*l,A=p*l,(n=n||Ae.mat4())[0]=h*d*d+u,n[1]=h*r+A,n[2]=h*s-o,n[3]=0,n[4]=h*r-A,n[5]=h*f*f+u,n[6]=h*i+a,n[7]=0,n[8]=h*s+o,n[9]=h*i-a,n[10]=h*p*p+u,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},rotationMat4c:function(e,t,n,r,i){return Ae.rotationMat4v(e,[t,n,r],i)},scalingMat4v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.identityMat4();return t[0]=e[0],t[5]=e[1],t[10]=e[2],t},scalingMat3v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.identityMat3();return t[0]=e[0],t[4]=e[1],t},scalingMat4c:function(){var e=new re(3);return function(t,n,r,i){return e[0]=t,e[1]=n,e[2]=r,Ae.scalingMat4v(e,i)}}(),scaleMat4c:function(e,t,n,r){return r[0]*=e,r[4]*=t,r[8]*=n,r[1]*=e,r[5]*=t,r[9]*=n,r[2]*=e,r[6]*=t,r[10]*=n,r[3]*=e,r[7]*=t,r[11]*=n,r},scaleMat4v:function(e,t){var n=e[0],r=e[1],i=e[2];return t[0]*=n,t[4]*=r,t[8]*=i,t[1]*=n,t[5]*=r,t[9]*=i,t[2]*=n,t[6]*=r,t[10]*=i,t[3]*=n,t[7]*=r,t[11]*=i,t},scalingMat4s:function(e){return Ae.scalingMat4c(e,e,e)},rotationTranslationMat4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.mat4(),r=e[0],i=e[1],s=e[2],a=e[3],o=r+r,A=i+i,c=s+s,l=r*o,u=r*A,h=r*c,d=i*A,f=i*c,p=s*c,v=a*o,g=a*A,m=a*c;return n[0]=1-(d+p),n[1]=u+m,n[2]=h-g,n[3]=0,n[4]=u-m,n[5]=1-(l+p),n[6]=f+v,n[7]=0,n[8]=h+g,n[9]=f-v,n[10]=1-(l+d),n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n},mat4ToEuler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec4(),r=Ae.clamp,i=e[0],s=e[4],a=e[8],o=e[1],A=e[5],c=e[9],l=e[2],u=e[6],h=e[10];return"XYZ"===t?(n[1]=Math.asin(r(a,-1,1)),Math.abs(a)<.99999?(n[0]=Math.atan2(-c,h),n[2]=Math.atan2(-s,i)):(n[0]=Math.atan2(u,A),n[2]=0)):"YXZ"===t?(n[0]=Math.asin(-r(c,-1,1)),Math.abs(c)<.99999?(n[1]=Math.atan2(a,h),n[2]=Math.atan2(o,A)):(n[1]=Math.atan2(-l,i),n[2]=0)):"ZXY"===t?(n[0]=Math.asin(r(u,-1,1)),Math.abs(u)<.99999?(n[1]=Math.atan2(-l,h),n[2]=Math.atan2(-s,A)):(n[1]=0,n[2]=Math.atan2(o,i))):"ZYX"===t?(n[1]=Math.asin(-r(l,-1,1)),Math.abs(l)<.99999?(n[0]=Math.atan2(u,h),n[2]=Math.atan2(o,i)):(n[0]=0,n[2]=Math.atan2(-s,A))):"YZX"===t?(n[2]=Math.asin(r(o,-1,1)),Math.abs(o)<.99999?(n[0]=Math.atan2(-c,A),n[1]=Math.atan2(-l,i)):(n[0]=0,n[1]=Math.atan2(a,h))):"XZY"===t&&(n[2]=Math.asin(-r(s,-1,1)),Math.abs(s)<.99999?(n[0]=Math.atan2(u,A),n[1]=Math.atan2(a,i)):(n[0]=Math.atan2(-c,h),n[1]=0)),n[0]*=Ae.RADTODEG,n[1]*=Ae.RADTODEG,n[2]*=Ae.RADTODEG,n},composeMat4:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Ae.mat4();return Ae.quaternionToRotationMat4(t,r),Ae.scaleMat4v(n,r),Ae.translateMat4v(e,r),r},decomposeMat4:function(){var e=new re(3),t=new re(16);return function(n,r,i,s){e[0]=n[0],e[1]=n[1],e[2]=n[2];var a=Ae.lenVec3(e);e[0]=n[4],e[1]=n[5],e[2]=n[6];var o=Ae.lenVec3(e);e[8]=n[8],e[9]=n[9],e[10]=n[10];var A=Ae.lenVec3(e);Ae.determinantMat4(n)<0&&(a=-a),r[0]=n[12],r[1]=n[13],r[2]=n[14],t.set(n);var c=1/a,l=1/o,u=1/A;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=l,t[5]*=l,t[6]*=l,t[8]*=u,t[9]*=u,t[10]*=u,Ae.mat4ToQuaternion(t,i),s[0]=a,s[1]=o,s[2]=A,this}}(),getColMat4:function(e,t){var n=4*t;return[e[n],e[n+1],e[n+2],e[n+3]]},setRowMat4:function(e,t,n){e[t]=n[0],e[t+4]=n[1],e[t+8]=n[2],e[t+12]=n[3]},lookAtMat4v:function(e,t,n,r){r||(r=Ae.mat4());var i,s,a,o,A,c,l,u,h,d,f=e[0],p=e[1],v=e[2],g=n[0],m=n[1],y=n[2],_=t[0],b=t[1],w=t[2];return f===_&&p===b&&v===w?Ae.identityMat4():(i=f-_,s=p-b,a=v-w,o=m*(a*=d=1/Math.sqrt(i*i+s*s+a*a))-y*(s*=d),A=y*(i*=d)-g*a,c=g*s-m*i,(d=Math.sqrt(o*o+A*A+c*c))?(o*=d=1/d,A*=d,c*=d):(o=0,A=0,c=0),l=s*c-a*A,u=a*o-i*c,h=i*A-s*o,(d=Math.sqrt(l*l+u*u+h*h))?(l*=d=1/d,u*=d,h*=d):(l=0,u=0,h=0),r[0]=o,r[1]=l,r[2]=i,r[3]=0,r[4]=A,r[5]=u,r[6]=s,r[7]=0,r[8]=c,r[9]=h,r[10]=a,r[11]=0,r[12]=-(o*f+A*p+c*v),r[13]=-(l*f+u*p+h*v),r[14]=-(i*f+s*p+a*v),r[15]=1,r)},lookAtMat4c:function(e,t,n,r,i,s,a,o,A){return Ae.lookAtMat4v([e,t,n],[r,i,s],[a,o,A],[])},orthoMat4c:function(e,t,n,r,i,s,a){a||(a=Ae.mat4());var o=t-e,A=r-n,c=s-i;return a[0]=2/o,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=2/A,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=-2/c,a[11]=0,a[12]=-(e+t)/o,a[13]=-(r+n)/A,a[14]=-(s+i)/c,a[15]=1,a},frustumMat4v:function(e,t,n){n||(n=Ae.mat4());var r=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];Ae.addVec4(i,r,se),Ae.subVec4(i,r,ae);var s=2*r[2],a=ae[0],o=ae[1],A=ae[2];return n[0]=s/a,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=s/o,n[6]=0,n[7]=0,n[8]=se[0]/a,n[9]=se[1]/o,n[10]=-se[2]/A,n[11]=-1,n[12]=0,n[13]=0,n[14]=-s*i[2]/A,n[15]=0,n},frustumMat4:function(e,t,n,r,i,s,a){a||(a=Ae.mat4());var o=t-e,A=r-n,c=s-i;return a[0]=2*i/o,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=2*i/A,a[6]=0,a[7]=0,a[8]=(t+e)/o,a[9]=(r+n)/A,a[10]=-(s+i)/c,a[11]=-1,a[12]=0,a[13]=0,a[14]=-s*i*2/c,a[15]=0,a},perspectiveMat4:function(e,t,n,r,i){var s=[],a=[];return s[2]=n,a[2]=r,a[1]=s[2]*Math.tan(e/2),s[1]=-a[1],a[0]=a[1]*t,s[0]=-a[0],Ae.frustumMat4v(s,a,i)},compareMat4:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15]},transformPoint3:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec3(),r=t[0],i=t[1],s=t[2];return n[0]=e[0]*r+e[4]*i+e[8]*s+e[12],n[1]=e[1]*r+e[5]*i+e[9]*s+e[13],n[2]=e[2]*r+e[6]*i+e[10]*s+e[14],n},transformPoint4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec4();return n[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],n[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],n[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],n[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],n},transformPoints3:function(e,t,n){for(var r,i,s,a,o,A=n||[],c=t.length,l=e[0],u=e[1],h=e[2],d=e[3],f=e[4],p=e[5],v=e[6],g=e[7],m=e[8],y=e[9],_=e[10],b=e[11],w=e[12],B=e[13],C=e[14],M=e[15],k=0;k<c;++k)r=(a=t[k])[0],i=a[1],s=a[2],(o=A[k]||(A[k]=[0,0,0]))[0]=l*r+f*i+m*s+w,o[1]=u*r+p*i+y*s+B,o[2]=h*r+v*i+_*s+C,o[3]=d*r+g*i+b*s+M;return A.length=c,A},transformPositions3:function(e,t){var n,r,i,s,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,A=e[0],c=e[1],l=e[2];e[3];var u=e[4],h=e[5],d=e[6];e[7];var f=e[8],p=e[9],v=e[10];e[11];var g=e[12],m=e[13],y=e[14];for(e[15],n=0;n<o;n+=3)r=t[n+0],i=t[n+1],s=t[n+2],a[n+0]=A*r+u*i+f*s+g,a[n+1]=c*r+h*i+p*s+m,a[n+2]=l*r+d*i+v*s+y;return a},transformPositions4:function(e,t){var n,r,i,s,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,A=e[0],c=e[1],l=e[2],u=e[3],h=e[4],d=e[5],f=e[6],p=e[7],v=e[8],g=e[9],m=e[10],y=e[11],_=e[12],b=e[13],w=e[14],B=e[15];for(n=0;n<o;n+=4)r=t[n+0],i=t[n+1],s=t[n+2],a[n+0]=A*r+h*i+v*s+_,a[n+1]=c*r+d*i+g*s+b,a[n+2]=l*r+f*i+m*s+w,a[n+3]=u*r+p*i+y*s+B;return a},transformVec3:function(e,t,n){var r=t[0],i=t[1],s=t[2];return(n=n||this.vec3())[0]=e[0]*r+e[4]*i+e[8]*s,n[1]=e[1]*r+e[5]*i+e[9]*s,n[2]=e[2]*r+e[6]*i+e[10]*s,n},transformVec4:function(e,t,n){var r=t[0],i=t[1],s=t[2],a=t[3];return(n=n||Ae.vec4())[0]=e[0]*r+e[4]*i+e[8]*s+e[12]*a,n[1]=e[1]*r+e[5]*i+e[9]*s+e[13]*a,n[2]=e[2]*r+e[6]*i+e[10]*s+e[14]*a,n[3]=e[3]*r+e[7]*i+e[11]*s+e[15]*a,n},rotateVec2:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e,i=Math.cos(n),s=Math.sin(n),a=e[0]-t[0],o=e[1]-t[1];return r[0]=a*i-o*s+t[0],r[1]=a*s+o*i+t[1],e},rotateVec3X:function(e,t,n,r){var i=[],s=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],s[0]=i[0],s[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),s[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),r[0]=s[0]+t[0],r[1]=s[1]+t[1],r[2]=s[2]+t[2],r},rotateVec3Y:function(e,t,n,r){var i=[],s=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],s[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),s[1]=i[1],s[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),r[0]=s[0]+t[0],r[1]=s[1]+t[1],r[2]=s[2]+t[2],r},rotateVec3Z:function(e,t,n,r){var i=[],s=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],s[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),s[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),s[2]=i[2],r[0]=s[0]+t[0],r[1]=s[1]+t[1],r[2]=s[2]+t[2],r},projectVec4:function(e,t){var n=1/e[3];return(t=t||Ae.vec2())[0]=e[0]*n,t[1]=e[1]*n,t},unprojectVec3:(j=new re(16),W=new re(16),z=new re(16),function(e,t,n,r){return this.transformVec3(this.mulMat4(this.inverseMat4(t,j),this.inverseMat4(n,W),z),e,r)}),lerpVec3:function(e,t,n,r,i,s){var a=s||Ae.vec3(),o=(e-t)/(n-t);return a[0]=r[0]+o*(i[0]-r[0]),a[1]=r[1]+o*(i[1]-r[1]),a[2]=r[2]+o*(i[2]-r[2]),a},lerpMat4:function(e,t,n,r,i,s){var a=s||Ae.mat4(),o=(e-t)/(n-t);return a[0]=r[0]+o*(i[0]-r[0]),a[1]=r[1]+o*(i[1]-r[1]),a[2]=r[2]+o*(i[2]-r[2]),a[3]=r[3]+o*(i[3]-r[3]),a[4]=r[4]+o*(i[4]-r[4]),a[5]=r[5]+o*(i[5]-r[5]),a[6]=r[6]+o*(i[6]-r[6]),a[7]=r[7]+o*(i[7]-r[7]),a[8]=r[8]+o*(i[8]-r[8]),a[9]=r[9]+o*(i[9]-r[9]),a[10]=r[10]+o*(i[10]-r[10]),a[11]=r[11]+o*(i[11]-r[11]),a[12]=r[12]+o*(i[12]-r[12]),a[13]=r[13]+o*(i[13]-r[13]),a[14]=r[14]+o*(i[14]-r[14]),a[15]=r[15]+o*(i[15]-r[15]),a},flatten:function(e){var t,n,r,i,s,a=[];for(t=0,n=e.length;t<n;t++)for(r=0,i=(s=e[t]).length;r<i;r++)a.push(s[r]);return a},identityQuaternion:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Ae.vec4();return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},eulerToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec4(),r=e[0]*Ae.DEGTORAD/2,i=e[1]*Ae.DEGTORAD/2,s=e[2]*Ae.DEGTORAD/2,a=Math.cos(r),o=Math.cos(i),A=Math.cos(s),c=Math.sin(r),l=Math.sin(i),u=Math.sin(s);return"XYZ"===t?(n[0]=c*o*A+a*l*u,n[1]=a*l*A-c*o*u,n[2]=a*o*u+c*l*A,n[3]=a*o*A-c*l*u):"YXZ"===t?(n[0]=c*o*A+a*l*u,n[1]=a*l*A-c*o*u,n[2]=a*o*u-c*l*A,n[3]=a*o*A+c*l*u):"ZXY"===t?(n[0]=c*o*A-a*l*u,n[1]=a*l*A+c*o*u,n[2]=a*o*u+c*l*A,n[3]=a*o*A-c*l*u):"ZYX"===t?(n[0]=c*o*A-a*l*u,n[1]=a*l*A+c*o*u,n[2]=a*o*u-c*l*A,n[3]=a*o*A+c*l*u):"YZX"===t?(n[0]=c*o*A+a*l*u,n[1]=a*l*A+c*o*u,n[2]=a*o*u-c*l*A,n[3]=a*o*A-c*l*u):"XZY"===t&&(n[0]=c*o*A-a*l*u,n[1]=a*l*A-c*o*u,n[2]=a*o*u+c*l*A,n[3]=a*o*A+c*l*u),n},mat4ToQuaternion:function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.vec4(),r=e[0],i=e[4],s=e[8],a=e[1],o=e[5],A=e[9],c=e[2],l=e[6],u=e[10],h=r+o+u;return h>0?(t=.5/Math.sqrt(h+1),n[3]=.25/t,n[0]=(l-A)*t,n[1]=(s-c)*t,n[2]=(a-i)*t):r>o&&r>u?(t=2*Math.sqrt(1+r-o-u),n[3]=(l-A)/t,n[0]=.25*t,n[1]=(i+a)/t,n[2]=(s+c)/t):o>u?(t=2*Math.sqrt(1+o-r-u),n[3]=(s-c)/t,n[0]=(i+a)/t,n[1]=.25*t,n[2]=(A+l)/t):(t=2*Math.sqrt(1+u-r-o),n[3]=(a-i)/t,n[0]=(s+c)/t,n[1]=(A+l)/t,n[2]=.25*t),n},vec3PairToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec4(),r=Math.sqrt(Ae.dotVec3(e,e)*Ae.dotVec3(t,t)),i=r+Ae.dotVec3(e,t);return i<1e-8*r?(i=0,Math.abs(e[0])>Math.abs(e[2])?(n[0]=-e[1],n[1]=e[0],n[2]=0):(n[0]=0,n[1]=-e[2],n[2]=e[1])):Ae.cross3Vec3(e,t,n),n[3]=i,Ae.normalizeQuaternion(n)},angleAxisToQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.vec4(),n=e[3]/2,r=Math.sin(n);return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=Math.cos(n),t},quaternionToEuler:function(){var e=new re(16);return function(t,n,r){return r=r||Ae.vec3(),Ae.quaternionToRotationMat4(t,e),Ae.mat4ToEuler(e,n,r),r}}(),mulQuaternions:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec4(),r=e[0],i=e[1],s=e[2],a=e[3],o=t[0],A=t[1],c=t[2],l=t[3];return n[0]=a*o+r*l+i*c-s*A,n[1]=a*A+i*l+s*o-r*c,n[2]=a*c+s*l+r*A-i*o,n[3]=a*l-r*o-i*A-s*c,n},vec3ApplyQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ae.vec3(),r=t[0],i=t[1],s=t[2],a=e[0],o=e[1],A=e[2],c=e[3],l=c*r+o*s-A*i,u=c*i+A*r-a*s,h=c*s+a*i-o*r,d=-a*r-o*i-A*s;return n[0]=l*c+d*-a+u*-A-h*-o,n[1]=u*c+d*-o+h*-a-l*-A,n[2]=h*c+d*-A+l*-o-u*-a,n},quaternionToMat4:function(e,t){t=Ae.identityMat4(t);var n=e[0],r=e[1],i=e[2],s=e[3],a=2*n,o=2*r,A=2*i,c=a*s,l=o*s,u=A*s,h=a*n,d=o*n,f=A*n,p=o*r,v=A*r,g=A*i;return t[0]=1-(p+g),t[1]=d+u,t[2]=f-l,t[4]=d-u,t[5]=1-(h+g),t[6]=v+c,t[8]=f+l,t[9]=v-c,t[10]=1-(h+p),t},quaternionToRotationMat4:function(e,t){var n=e[0],r=e[1],i=e[2],s=e[3],a=n+n,o=r+r,A=i+i,c=n*a,l=n*o,u=n*A,h=r*o,d=r*A,f=i*A,p=s*a,v=s*o,g=s*A;return t[0]=1-(h+f),t[4]=l-g,t[8]=u+v,t[1]=l+g,t[5]=1-(c+f),t[9]=d-p,t[2]=u-v,t[6]=d+p,t[10]=1-(c+h),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=Ae.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/n,t[1]=e[1]/n,t[2]=e[2]/n,t[3]=e[3]/n,t},conjugateQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e;return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},inverseQuaternion:function(e,t){return Ae.normalizeQuaternion(Ae.conjugateQuaternion(e,t))},quaternionToAngleAxis:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.vec4(),n=(e=Ae.normalizeQuaternion(e,oe))[3],r=2*Math.acos(n),i=Math.sqrt(1-n*n);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=r,t},AABB3:function(e){return new re(e||6)},AABB2:function(e){return new re(e||4)},OBB3:function(e){return new re(e||32)},OBB2:function(e){return new re(e||16)},Sphere3:function(e,t,n,r){return new re([e,t,n,r])},transformOBB3:function(e,t){var n,r,i,s,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,A=e[0],c=e[1],l=e[2],u=e[3],h=e[4],d=e[5],f=e[6],p=e[7],v=e[8],g=e[9],m=e[10],y=e[11],_=e[12],b=e[13],w=e[14],B=e[15];for(n=0;n<o;n+=4)r=t[n+0],i=t[n+1],s=t[n+2],a[n+0]=A*r+h*i+v*s+_,a[n+1]=c*r+d*i+g*s+b,a[n+2]=l*r+f*i+m*s+w,a[n+3]=u*r+p*i+y*s+B;return a},containsAABB3:function(e,t){return e[0]<=t[0]&&t[3]<=e[3]&&e[1]<=t[1]&&t[4]<=e[4]&&e[2]<=t[2]&&t[5]<=e[5]},getAABB3Diag:function(){var e=new re(3),t=new re(3),n=new re(3);return function(r){return e[0]=r[0],e[1]=r[1],e[2]=r[2],t[0]=r[3],t[1]=r[4],t[2]=r[5],Ae.subVec3(t,e,n),Math.abs(Ae.lenVec3(n))}}(),getAABB3DiagPoint:function(){var e=new re(3),t=new re(3),n=new re(3);return function(r,i){e[0]=r[0],e[1]=r[1],e[2]=r[2],t[0]=r[3],t[1]=r[4],t[2]=r[5];var s=Ae.subVec3(t,e,n),a=i[0]-r[0],o=r[3]-i[0],A=i[1]-r[1],c=r[4]-i[1],l=i[2]-r[2],u=r[5]-i[2];return s[0]+=a>o?a:o,s[1]+=A>c?A:c,s[2]+=l>u?l:u,Math.abs(Ae.lenVec3(s))}}(),getAABB3Area:function(e){return(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2])},getAABB3Center:function(e,t){var n=t||Ae.vec3();return n[0]=(e[0]+e[3])/2,n[1]=(e[1]+e[4])/2,n[2]=(e[2]+e[5])/2,n},getAABB2Center:function(e,t){var n=t||Ae.vec2();return n[0]=(e[2]+e[0])/2,n[1]=(e[3]+e[1])/2,n},collapseAABB3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Ae.AABB3();return e[0]=Ae.MAX_DOUBLE,e[1]=Ae.MAX_DOUBLE,e[2]=Ae.MAX_DOUBLE,e[3]=Ae.MIN_DOUBLE,e[4]=Ae.MIN_DOUBLE,e[5]=Ae.MIN_DOUBLE,e},AABB3ToOBB3:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.OBB3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t},positions3ToAABB3:function(){var e=new re(3);return function(t,n,r){n=n||Ae.AABB3();for(var i,s,a,o=Ae.MAX_DOUBLE,A=Ae.MAX_DOUBLE,c=Ae.MAX_DOUBLE,l=Ae.MIN_DOUBLE,u=Ae.MIN_DOUBLE,h=Ae.MIN_DOUBLE,d=0,f=t.length;d<f;d+=3)r?(e[0]=t[d+0],e[1]=t[d+1],e[2]=t[d+2],Ae.decompressPosition(e,r,e),i=e[0],s=e[1],a=e[2]):(i=t[d+0],s=t[d+1],a=t[d+2]),i<o&&(o=i),s<A&&(A=s),a<c&&(c=a),i>l&&(l=i),s>u&&(u=s),a>h&&(h=a);return n[0]=o,n[1]=A,n[2]=c,n[3]=l,n[4]=u,n[5]=h,n}}(),OBB3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.AABB3(),s=Ae.MAX_DOUBLE,a=Ae.MAX_DOUBLE,o=Ae.MAX_DOUBLE,A=Ae.MIN_DOUBLE,c=Ae.MIN_DOUBLE,l=Ae.MIN_DOUBLE,u=0,h=e.length;u<h;u+=4)(t=e[u+0])<s&&(s=t),(n=e[u+1])<a&&(a=n),(r=e[u+2])<o&&(o=r),t>A&&(A=t),n>c&&(c=n),r>l&&(l=r);return i[0]=s,i[1]=a,i[2]=o,i[3]=A,i[4]=c,i[5]=l,i},points3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.AABB3(),s=Ae.MAX_DOUBLE,a=Ae.MAX_DOUBLE,o=Ae.MAX_DOUBLE,A=Ae.MIN_DOUBLE,c=Ae.MIN_DOUBLE,l=Ae.MIN_DOUBLE,u=0,h=e.length;u<h;u++)(t=e[u][0])<s&&(s=t),(n=e[u][1])<a&&(a=n),(r=e[u][2])<o&&(o=r),t>A&&(A=t),n>c&&(c=n),r>l&&(l=r);return i[0]=s,i[1]=a,i[2]=o,i[3]=A,i[4]=c,i[5]=l,i},points3ToSphere3:function(){var e=new re(3);return function(t,n){n=n||Ae.vec4();var r,i=0,s=0,a=0,o=t.length;for(r=0;r<o;r++)i+=t[r][0],s+=t[r][1],a+=t[r][2];n[0]=i/o,n[1]=s/o,n[2]=a/o;var A,c=0;for(r=0;r<o;r++)(A=Math.abs(Ae.lenVec3(Ae.subVec3(t[r],n,e))))>c&&(c=A);return n[3]=c,n}}(),positions3ToSphere3:function(){var e=new re(3),t=new re(3);return function(n,r){r=r||Ae.vec4();var i,s=0,a=0,o=0,A=n.length,c=0;for(i=0;i<A;i+=3)s+=n[i],a+=n[i+1],o+=n[i+2];var l,u=A/3;for(r[0]=s/u,r[1]=a/u,r[2]=o/u,i=0;i<A;i+=3)e[0]=n[i],e[1]=n[i+1],e[2]=n[i+2],(l=Math.abs(Ae.lenVec3(Ae.subVec3(e,r,t))))>c&&(c=l);return r[3]=c,r}}(),OBB3ToSphere3:function(){var e=new re(3),t=new re(3);return function(n,r){r=r||Ae.vec4();var i,s=0,a=0,o=0,A=n.length,c=A/4;for(i=0;i<A;i+=4)s+=n[i+0],a+=n[i+1],o+=n[i+2];r[0]=s/c,r[1]=a/c,r[2]=o/c;var l,u=0;for(i=0;i<A;i+=4)e[0]=n[i+0],e[1]=n[i+1],e[2]=n[i+2],(l=Math.abs(Ae.lenVec3(Ae.subVec3(e,r,t))))>u&&(u=l);return r[3]=u,r}}(),getSphere3Center:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.vec3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},getPositionsCenter:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.vec3(),n=0,r=0,i=0,s=0,a=e.length;s<a;s+=3)n+=e[s+0],r+=e[s+1],i+=e[s+2];var o=e.length/3;return t[0]=n/o,t[1]=r/o,t[2]=i/o,t},expandAABB3:function(e,t){return e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]<t[3]&&(e[3]=t[3]),e[4]<t[4]&&(e[4]=t[4]),e[5]<t[5]&&(e[5]=t[5]),e},expandAABB3Point3:function(e,t){return e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]<t[0]&&(e[3]=t[0]),e[4]<t[1]&&(e[4]=t[1]),e[5]<t[2]&&(e[5]=t[2]),e},expandAABB3Points3:function(e,t){for(var n,r,i,s=0,a=t.length;s<a;s+=3)n=t[s],r=t[s+1],i=t[s+2],e[0]>n&&(e[0]=n),e[1]>r&&(e[1]=r),e[2]>i&&(e[2]=i),e[3]<n&&(e[3]=n),e[4]<r&&(e[4]=r),e[5]<i&&(e[5]=i);return e},collapseAABB2:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Ae.AABB2();return e[0]=Ae.MAX_DOUBLE,e[1]=Ae.MAX_DOUBLE,e[2]=Ae.MIN_DOUBLE,e[3]=Ae.MIN_DOUBLE,e},point3AABB3Intersect:function(e,t){return e[0]>t[0]||e[3]<t[0]||e[1]>t[1]||e[4]<t[1]||e[2]>t[2]||e[5]<t[2]},point3AABB3AbsoluteIntersect:function(e,t){return e[0]<=t[0]&&e[3]>=t[0]&&e[1]<=t[1]&&e[4]>=t[1]&&e[2]<=t[2]&&e[5]>=t[2]},planeAABB3Intersect:function(e,t,n){var r,i;return e[0]>0?(r=e[0]*n[0],i=e[0]*n[3]):(r=e[0]*n[3],i=e[0]*n[0]),e[1]>0?(r+=e[1]*n[1],i+=e[1]*n[4]):(r+=e[1]*n[4],i+=e[1]*n[1]),e[2]>0?(r+=e[2]*n[2],i+=e[2]*n[5]):(r+=e[2]*n[5],i+=e[2]*n[2]),r<=-t&&i<=-t?-1:r>=-t&&i>=-t?1:0},OBB3ToAABB2:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.AABB2(),s=Ae.MAX_DOUBLE,a=Ae.MAX_DOUBLE,o=Ae.MIN_DOUBLE,A=Ae.MIN_DOUBLE,c=0,l=e.length;c<l;c+=4)t=e[c+0],n=e[c+1],(t*=r=1/(e[c+3]||1))<s&&(s=t),(n*=r)<a&&(a=n),t>o&&(o=t),n>A&&(A=n);return i[0]=s,i[1]=a,i[2]=o,i[3]=A,i},expandAABB2:function(e,t){return e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]<t[2]&&(e[2]=t[2]),e[3]<t[3]&&(e[3]=t[3]),e},expandAABB2Point2:function(e,t){return e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]<t[0]&&(e[2]=t[0]),e[3]<t[1]&&(e[3]=t[1]),e},AABB2ToCanvas:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:e,i=.5*(e[0]+1),s=.5*(e[1]+1),a=.5*(e[2]+1),o=.5*(e[3]+1);return r[0]=Math.floor(i*t),r[1]=n-Math.floor(o*n),r[2]=Math.floor(a*t),r[3]=n-Math.floor(s*n),r},tangentQuadraticBezier:function(e,t,n,r){return 2*(1-e)*(n-t)+2*e*(r-n)},tangentQuadraticBezier3:function(e,t,n,r,i){return-3*t*(1-e)*(1-e)+3*n*(1-e)*(1-e)-6*e*n*(1-e)+6*e*r*(1-e)-3*e*e*r+3*e*e*i},tangentSpline:function(e){return 6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e)},catmullRomInterpolate:function(e,t,n,r,i){var s=.5*(n-e),a=.5*(r-t),o=i*i;return(2*t-2*n+s+a)*(i*o)+(-3*t+3*n-2*s-a)*o+s*i+t},b2p0:function(e,t){var n=1-e;return n*n*t},b2p1:function(e,t){return 2*(1-e)*e*t},b2p2:function(e,t){return e*e*t},b2:function(e,t,n,r){return this.b2p0(e,t)+this.b2p1(e,n)+this.b2p2(e,r)},b3p0:function(e,t){var n=1-e;return n*n*n*t},b3p1:function(e,t){var n=1-e;return 3*n*n*e*t},b3p2:function(e,t){return 3*(1-e)*e*e*t},b3p3:function(e,t){return e*e*e*t},b3:function(e,t,n,r,i){return this.b3p0(e,t)+this.b3p1(e,n)+this.b3p2(e,r)+this.b3p3(e,i)},triangleNormal:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Ae.vec3(),i=t[0]-e[0],s=t[1]-e[1],a=t[2]-e[2],o=n[0]-e[0],A=n[1]-e[1],c=n[2]-e[2],l=s*c-a*A,u=a*o-i*c,h=i*A-s*o,d=Math.sqrt(l*l+u*u+h*h);return 0===d?(r[0]=0,r[1]=0,r[2]=0):(r[0]=l/d,r[1]=u/d,r[2]=h/d),r},rayTriangleIntersect:function(){var e=new re(3),t=new re(3),n=new re(3),r=new re(3),i=new re(3);return function(s,a,o,A,c,l){l=l||Ae.vec3();var u=Ae.subVec3(A,o,e),h=Ae.subVec3(c,o,t),d=Ae.cross3Vec3(a,h,n),f=Ae.dotVec3(u,d);if(f<1e-6)return null;var p=Ae.subVec3(s,o,r),v=Ae.dotVec3(p,d);if(v<0||v>f)return null;var g=Ae.cross3Vec3(p,u,i),m=Ae.dotVec3(a,g);if(m<0||v+m>f)return null;var y=Ae.dotVec3(h,g)/f;return l[0]=s[0]+y*a[0],l[1]=s[1]+y*a[1],l[2]=s[2]+y*a[2],l}}(),rayPlaneIntersect:function(){var e=new re(3),t=new re(3),n=new re(3),r=new re(3);return function(i,s,a,o,A,c){c=c||Ae.vec3(),s=Ae.normalizeVec3(s,e);var l=Ae.subVec3(o,a,t),u=Ae.subVec3(A,a,n),h=Ae.cross3Vec3(l,u,r);Ae.normalizeVec3(h,h);var d=-Ae.dotVec3(a,h),f=-(Ae.dotVec3(i,h)+d)/Ae.dotVec3(s,h);return c[0]=i[0]+f*s[0],c[1]=i[1]+f*s[1],c[2]=i[2]+f*s[2],c}}(),cartesianToBarycentric:function(){var e=new re(3),t=new re(3),n=new re(3);return function(r,i,s,a,o){var A=Ae.subVec3(a,i,e),c=Ae.subVec3(s,i,t),l=Ae.subVec3(r,i,n),u=Ae.dotVec3(A,A),h=Ae.dotVec3(A,c),d=Ae.dotVec3(A,l),f=Ae.dotVec3(c,c),p=Ae.dotVec3(c,l),v=u*f-h*h;if(0===v)return null;var g=1/v,m=(f*d-h*p)*g,y=(u*p-h*d)*g;return o[0]=1-m-y,o[1]=y,o[2]=m,o}}(),barycentricInsideTriangle:function(e){var t=e[1],n=e[2];return n>=0&&t>=0&&n+t<1},barycentricToCartesian:function(e,t,n,r){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Ae.vec3(),s=e[0],a=e[1],o=e[2];return i[0]=t[0]*s+n[0]*a+r[0]*o,i[1]=t[1]*s+n[1]*a+r[1]*o,i[2]=t[2]*s+n[2]*a+r[2]*o,i},mergeVertices:function(e,t,n,r){var i,s,a,o,A,c,l={},u=[],h=[],d=t?[]:null,f=n?[]:null,p=[],v=Math.pow(10,4),g=0;for(A=0,c=e.length;A<c;A+=3)i=e[A],s=e[A+1],a=e[A+2],void 0===l[o="".concat(Math.round(i*v),"_").concat(Math.round(s*v),"_").concat(Math.round(a*v))]&&(l[o]=h.length/3,h.push(i),h.push(s),h.push(a),t&&(d.push(t[A]),d.push(t[A+1]),d.push(t[A+2])),n&&(f.push(n[g]),f.push(n[g+1]))),u[A/3]=l[o],g+=2;for(A=0,c=r.length;A<c;A++)p[A]=u[r[A]];var m={positions:h,indices:p};return d&&(m.normals=d),f&&(m.uv=f),m},buildNormals:function(){var e=new re(3),t=new re(3),n=new re(3),r=new re(3),i=new re(3),s=new re(3);return function(a,o,A){var c,l,u,h,d,f,p,v,g,m=new Array(a.length/3);for(c=0,l=o.length;c<l;c+=3){u=o[c],h=o[c+1],d=o[c+2],e[0]=a[3*u],e[1]=a[3*u+1],e[2]=a[3*u+2],t[0]=a[3*h],t[1]=a[3*h+1],t[2]=a[3*h+2],n[0]=a[3*d],n[1]=a[3*d+1],n[2]=a[3*d+2],Ae.subVec3(t,e,r),Ae.subVec3(n,e,i);var y=Ae.vec3();Ae.normalizeVec3(Ae.cross3Vec3(r,i,s),y),m[u]||(m[u]=[]),m[h]||(m[h]=[]),m[d]||(m[d]=[]),m[u].push(y),m[h].push(y),m[d].push(y)}for(A=A&&A.length===a.length?A:new Float32Array(a.length),c=0,l=m.length;c<l;c++){f=m[c].length,p=0,v=0,g=0;for(var _=0;_<f;_++)p+=m[c][_][0],v+=m[c][_][1],g+=m[c][_][2];A[3*c]=p/f,A[3*c+1]=v/f,A[3*c+2]=g/f}return A}}(),buildTangents:function(){var e=new re(3),t=new re(3),n=new re(3),r=new re(3),i=new re(3),s=new re(3),a=new re(3);return function(o,A,c){for(var l=new Float32Array(o.length),u=0;u<A.length;u+=3){var h=A[u],d=o.subarray(3*h,3*h+3),f=c.subarray(2*h,2*h+2);h=A[u+1];var p=o.subarray(3*h,3*h+3),v=c.subarray(2*h,2*h+2);h=A[u+2];for(var g=o.subarray(3*h,3*h+3),m=c.subarray(2*h,2*h+2),y=Ae.subVec3(p,d,e),_=Ae.subVec3(g,d,t),b=Ae.subVec2(v,f,n),w=Ae.subVec2(m,f,r),B=1/(b[0]*w[1]-b[1]*w[0]),C=Ae.mulVec3Scalar(Ae.subVec3(Ae.mulVec3Scalar(y,w[1],i),Ae.mulVec3Scalar(_,b[1],s),a),B,s),M=void 0,k=0;k<3;k++)l[M=3*A[u+k]]+=C[0],l[M+1]+=C[1],l[M+2]+=C[2]}return l}}(),buildPickTriangles:function(e,t,n){for(var r,i,s,a,o,A=t.length,c=n?new Uint16Array(9*A):new Float32Array(9*A),l=new Uint8Array(12*A),u=0,h=0,d=0,f=0;f<A;f+=3)o=u>>24&255,a=u>>16&255,s=u>>8&255,i=255&u,r=3*t[f],c[h++]=e[r],c[h++]=e[r+1],c[h++]=e[r+2],l[d++]=i,l[d++]=s,l[d++]=a,l[d++]=o,r=3*t[f+1],c[h++]=e[r],c[h++]=e[r+1],c[h++]=e[r+2],l[d++]=i,l[d++]=s,l[d++]=a,l[d++]=o,r=3*t[f+2],c[h++]=e[r],c[h++]=e[r+1],c[h++]=e[r+2],l[d++]=i,l[d++]=s,l[d++]=a,l[d++]=o,u++;return{positions:c,colors:l}},faceToVertexNormals:function(e,t){var n,r,i,s,a,o,A,c,l,u,h,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},f=d.smoothNormalsAngleThreshold||20,p={},v=[],g={},m=4,y=Math.pow(10,m);for(A=0,l=e.length;A<l;A+=3){o=A/3,r=e[A],i=e[A+1],s=e[A+2],void 0===p[a="".concat(Math.round(r*y),"_").concat(Math.round(i*y),"_").concat(Math.round(s*y))]?p[a]=[o]:p[a].push(o);var _=Ae.normalizeVec3([t[A],t[A+1],t[A+2]]);v[o]=_,n=Ae.vec4([_[0],_[1],_[2],1]),g[o]=n}for(a in p)if(p.hasOwnProperty(a)){var b=p[a],w=b.length;for(A=0;A<w;A++){var B=b[A];for(n=g[B],c=0;c<w;c++)if(A!==c){var C=b[c];u=v[B],h=v[C];var M=Math.abs(Ae.angleVec3(u,h)/Ae.DEGTORAD);M<f&&(n[0]+=h[0],n[1]+=h[1],n[2]+=h[2],n[3]+=1)}}}for(A=0,l=t.length;A<l;A+=3)n=g[A/3],t[A+0]=n[0]/n[3],t[A+1]=n[1]/n[3],t[A+2]=n[2]/n[3]},transformRay:function(){var e=new re(4),t=new re(4);return function(n,r,i,s,a){e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=1,Ae.transformVec4(n,e,t),s[0]=t[0],s[1]=t[1],s[2]=t[2],e[0]=i[0],e[1]=i[1],e[2]=i[2],Ae.transformVec3(n,e,t),Ae.normalizeVec3(t),a[0]=t[0],a[1]=t[1],a[2]=t[2]}}(),canvasPosToWorldRay:(L=new re(16),H=new re(4),N=new re(4),G=function(e,t,n,r,i){i[0]=e,i[1]=t,i[2]=n,i[3]=1,Ae.transformVec4(L,i,i),r||Ae.mulVec4Scalar(i,1/i[3])},function(e,t,n,r,i,s,a){var o="ortho"===r;Ae.mulMat4(n,t,L),Ae.inverseMat4(L,L);var A=2*i[0]/e.clientWidth-1,c=1-2*i[1]/e.clientHeight;G(A,c,-1,o,H),G(A,c,1,o,N),s[0]=H[0],s[1]=H[1],s[2]=H[2],Ae.subVec3(N,H,a),Ae.normalizeVec3(a)}),canvasPosToLocalRay:(O=new re(3),V=new re(3),function(e,t,n,r,i,s,a,o){Ae.canvasPosToWorldRay(e,t,n,r,s,O,V),Ae.worldRayToLocalRay(i,O,V,a,o)}),worldRayToLocalRay:function(){var e=new re(16),t=new re(4),n=new re(4);return function(r,i,s,a,o){var A=Ae.inverseMat4(r,e);t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,Ae.transformVec4(A,t,n),a[0]=n[0],a[1]=n[1],a[2]=n[2],Ae.transformVec3(A,s,o)}}(),buildKDTree:function(){var e=new Float32Array;function t(n,r,i,s){var a,o,A=new re(6),c={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:A};for(A[0]=A[1]=A[2]=Number.POSITIVE_INFINITY,A[3]=A[4]=A[5]=Number.NEGATIVE_INFINITY,a=0,o=n.length;a<o;++a)for(var l=3*n[a],u=0;u<3;++u){var h=3*r[l+u];i[h]<A[0]&&(A[0]=i[h]),i[h]>A[3]&&(A[3]=i[h]),i[h+1]<A[1]&&(A[1]=i[h+1]),i[h+1]>A[4]&&(A[4]=i[h+1]),i[h+2]<A[2]&&(A[2]=i[h+2]),i[h+2]>A[5]&&(A[5]=i[h+2])}if(n.length<20||s>10)return c.triangles=n,c.leaf=!0,c;e[0]=A[3]-A[0],e[1]=A[4]-A[1],e[2]=A[5]-A[2];var d=0;e[1]>e[d]&&(d=1),e[2]>e[d]&&(d=2),c.splitDim=d;var f=(A[d]+A[d+3])/2,p=new Array(n.length),v=0,g=new Array(n.length),m=0;for(a=0,o=n.length;a<o;++a){var y=r[l=3*n[a]],_=3*r[l+1],b=3*r[l+2];i[3*y+d]<=f||i[_+d]<=f||i[b+d]<=f?p[v++]=n[a]:g[m++]=n[a]}return p.length=v,g.length=m,c.left=t(p,r,i,s+1),c.right=t(g,r,i,s+1),c}return function(e,n){for(var r=e.length/3,i=new Array(r),s=0;s<r;++s)i[s]=s;return t(i,e,n,0)}}(),decompressPosition:function(e,t,n){(n=n||e)[0]=e[0]*t[0]+t[12],n[1]=e[1]*t[5]+t[13],n[2]=e[2]*t[10]+t[14]},decompressPositions:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r<i;r+=3)n[r+0]=e[r+0]*t[0]+t[12],n[r+1]=e[r+1]*t[5]+t[13],n[r+2]=e[r+2]*t[10]+t[14];return n},decompressUV:function(e,t,n){n[0]=e[0]*t[0]+t[6],n[1]=e[1]*t[4]+t[7]},decompressUVs:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r<i;r+=3)n[r+0]=e[r+0]*t[0]+t[6],n[r+1]=e[r+1]*t[4]+t[7];return n},octDecodeVec2:function(e,t){var n=e[0],r=e[1];n=(2*n+1)/255,r=(2*r+1)/255;var i=1-Math.abs(n)-Math.abs(r);i<0&&(n=(1-Math.abs(r))*(n>=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var s=Math.sqrt(n*n+r*r+i*i);return t[0]=n/s,t[1]=r/s,t[2]=i/s,t},octDecodeVec2s:function(e,t){for(var n=0,r=0,i=e.length;n<i;n+=2){var s=e[n+0],a=e[n+1];s=(2*s+1)/255,a=(2*a+1)/255;var o=1-Math.abs(s)-Math.abs(a);o<0&&(s=(1-Math.abs(a))*(s>=0?1:-1),a=(1-Math.abs(s))*(a>=0?1:-1));var A=Math.sqrt(s*s+a*a+o*o);t[r+0]=s/A,t[r+1]=a/A,t[r+2]=o/A,r+=3}return t}};Ae.buildEdgeIndices=function(){var e=[],t=[],n=[],r=[],i=[],s=0,a=new Uint16Array(3),o=new Uint16Array(3),A=new Uint16Array(3),c=Ae.vec3(),l=Ae.vec3(),u=Ae.vec3(),h=Ae.vec3(),d=Ae.vec3(),f=Ae.vec3(),p=Ae.vec3();return function(v,g,m,y){!function(i,s){var a,o,A,c,l,u,h={},d=Math.pow(10,4),f=0;for(l=0,u=i.length;l<u;l+=3)a=i[l],o=i[l+1],A=i[l+2],void 0===h[c=Math.round(a*d)+"_"+Math.round(o*d)+"_"+Math.round(A*d)]&&(h[c]=f/3,e[f++]=a,e[f++]=o,e[f++]=A),t[l/3]=h[c];for(l=0,u=s.length;l<u;l++)r[l]=t[s[l]],n[r[l]]=s[l]}(v,g),function(t,n){s=0;for(var v=0,g=t;v<g;v+=3){var m=3*r[v],y=3*r[v+1],_=3*r[v+2];n?(a[0]=e[m],a[1]=e[m+1],a[2]=e[m+2],o[0]=e[y],o[1]=e[y+1],o[2]=e[y+2],A[0]=e[_],A[1]=e[_+1],A[2]=e[_+2],Ae.decompressPosition(a,n,c),Ae.decompressPosition(o,n,l),Ae.decompressPosition(A,n,u)):(c[0]=e[m],c[1]=e[m+1],c[2]=e[m+2],l[0]=e[y],l[1]=e[y+1],l[2]=e[y+2],u[0]=e[_],u[1]=e[_+1],u[2]=e[_+2]),Ae.subVec3(u,l,h),Ae.subVec3(c,l,d),Ae.cross3Vec3(h,d,f),Ae.normalizeVec3(f,p);var b=i[s]||(i[s]={normal:Ae.vec3()});b.normal[0]=p[0],b.normal[1]=p[1],b.normal[2]=p[2],s++}}(g.length,m);for(var _,b,w,B,C,M,k,E,F,x,U=[],I=Math.cos(Ae.DEGTORAD*y),T={},P=!1,S=0,D=g.length;S<D;S+=3)for(var Q=S/3,R=0;R<3;R++)_=r[S+R],b=r[S+(R+1)%3],void 0===T[C=(w=Math.min(_,b))+","+(B=Math.max(_,b))]?T[C]={index1:w,index2:B,face1:Q,face2:void 0}:T[C].face2=Q;for(C in T)void 0!==(M=T[C]).face2&&(k=i[M.face1].normal,E=i[M.face2].normal,Ae.dotVec3(k,E)>I)||(F=n[M.index1],x=n[M.index2],(!P&&F>65535||x>65535)&&(P=!0),U.push(F),U.push(x));return P?new Uint32Array(U):new Uint16Array(U)}}(),Ae.planeClipsPositions3=function(e,t,n){for(var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:3,i=0,s=n.length;i<s;i+=r){ie[0]=n[i+0]-e[0],ie[1]=n[i+1]-e[1],ie[2]=n[i+2]-e[2];var a=ie[0]*t[0]+ie[1]*t[1]+ie[2]*t[2];if(a<0)return!0}return!1};var ce=new Float32Array(3),le=function(){function e(t){var n=this;if(x(this,e),!t)throw"Parameter expected: cfg";if(!t.viewer)throw"Parameter expected: cfg.viewer";this.viewer=t.viewer,this._maxTreeDepth=t.maxTreeDepth||15,this._root=null,this._needsRebuild=!0,this._onModelLoaded=this.viewer.scene.on("modelLoaded",(function(e){n._needsRebuild=!0})),this._onModelUnloaded=this.viewer.scene.on("modelUnloaded",(function(e){n._needsRebuild=!0}))}return I(e,[{key:"root",get:function(){return this._needsRebuild&&this._rebuild(),this._root}},{key:"_rebuild",value:function(){var e=this.viewer.scene;for(var t in this._root={aabb:e.getAABB()},e.objects){var n=e.objects[t];this._insertEntity(this._root,n,1)}this._needsRebuild=!1}},{key:"_insertEntity",value:function(e,t,n){var r=t.aabb;if(n>=this._maxTreeDepth)return e.entities=e.entities||[],void e.entities.push(t);if(e.left&&Ae.containsAABB3(e.left.aabb,r))this._insertEntity(e.left,t,n+1);else if(e.right&&Ae.containsAABB3(e.right.aabb,r))this._insertEntity(e.right,t,n+1);else{var i=e.aabb;ce[0]=i[3]-i[0],ce[1]=i[4]-i[1],ce[2]=i[5]-i[2];var s=0;if(ce[1]>ce[s]&&(s=1),ce[2]>ce[s]&&(s=2),!e.left){var a=i.slice();if(a[s+3]=(i[s]+i[s+3])/2,e.left={aabb:a},Ae.containsAABB3(a,r))return void this._insertEntity(e.left,t,n+1)}if(!e.right){var o=i.slice();if(o[s]=(i[s]+i[s+3])/2,e.right={aabb:o},Ae.containsAABB3(o,r))return void this._insertEntity(e.right,t,n+1)}e.entities=e.entities||[],e.entities.push(t)}}},{key:"destroy",value:function(){var e=this.viewer.scene;e.off(this._onModelLoaded),e.off(this._onModelUnloaded),this._root=null,this._needsRebuild=!0}}]),e}(),ue=function(){function e(){x(this,e),this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}return I(e,[{key:"length",get:function(){return this._length}},{key:"shift",value:function(){if(this._index>=this._headLength){var e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}var t=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,t}},{key:"push",value:function(e){return this._length++,this._tail.push(e),this}},{key:"unshift",value:function(e){return this._head[--this._index]=e,this._length++,this}}]),e}(),he={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}};var de=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],n=e[0].charCodeAt(0),r=n+e[1],i=n;i<r;++i)t.push(i);return String.fromCharCode.apply(null,t)})).join("");function fe(e,t){return(t&&4!==t?[0,6]:[0,6,12,18]).map((function(t){return de.substr(parseInt(e/(1<<t))%64,1)})).reverse().join("")}var pe=function(){for(var e={},t=window.location.search.substring(1).split("&"),n=0;n<t.length;n++){var r=t[n].split("=");if(void 0===e[r[0]])e[r[0]]=decodeURIComponent(r[1]);else if("string"==typeof e[r[0]]){var i=[e[r[0]],decodeURIComponent(r[1])];e[r[0]]=i}else e[r[0]].push(decodeURIComponent(r[1]))}return e}();var ve,ge={xmlToJson:function e(t,n){if(t.nodeType===t.TEXT_NODE){var r=t.nodeValue;if(null===r.match(/^\s+$/))return r}else if(t.nodeType===t.ELEMENT_NODE||t.nodeType===t.DOCUMENT_NODE){var i={type:t.nodeName,children:[]};if(t.nodeType===t.ELEMENT_NODE)for(var s=0;s<t.attributes.length;s++){var a=t.attributes[s];i[n[a.nodeName]||a.nodeName]=a.nodeValue}for(var o=0;o<t.childNodes.length;o++){(s=e(t.childNodes[o],n))&&i.children.push(s)}return i}},clone:function(e){return JSON.parse(JSON.stringify(e))},compressGuid:function(e){var t=[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30].map((function(t){return parseInt(e.substr(t,2),16)}));return fe(t[0],2)+[1,4,7,10,13].map((function(e){return fe((t[e]<<16)+(t[e+1]<<8)+t[e+2])})).join("")},findNodeOfType:function(e,t){var n=[];return function e(r){r.type===t&&n.push(r),(r.children||[]).forEach((function(t){e(t)}))}(e),n},timeout:function(e){return new Promise((function(t,n){setTimeout(t,e)}))},httpRequest:function(e){return new Promise((function(t,n){var r=new XMLHttpRequest;r.open(e.method||"GET",e.url,!0),r.onload=function(e){4===r.readyState&&(200===r.status?t(r.responseXML):n(r.statusText))},r.send(null)}))},loadJSON:function(e,t,n){var r=function(e){};t=t||r,n=n||r;var i=new XMLHttpRequest;i.overrideMimeType("application/json"),i.open("GET",e,!0),i.addEventListener("load",(function(e){var r=e.target.response;if(200===this.status){var i;try{i=JSON.parse(r)}catch(e){n("utils.loadJSON(): Failed to parse JSON response - ".concat(e))}t(i)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(r))}catch(e){n("utils.loadJSON(): Failed to parse JSON response - ".concat(e))}}else n(e)}),!1),i.addEventListener("error",(function(e){n(e)}),!1),i.send(null)},loadArraybuffer:function(e,t,n){var r=function(e){};t=t||r,n=n||r;var i=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(i){var s=!!i[2],a=i[3];a=window.decodeURIComponent(a),s&&(a=window.atob(a));try{for(var o=new ArrayBuffer(a.length),A=new Uint8Array(o),c=0;c<a.length;c++)A[c]=a.charCodeAt(c);Fe.scheduleTask((function(){t(o)}))}catch(e){Fe.scheduleTask((function(){n(e)}))}}else{var l=new XMLHttpRequest;l.open("GET",e,!0),l.responseType="arraybuffer",l.onreadystatechange=function(){4===l.readyState&&(200===l.status?t(l.response):n("loadArrayBuffer error : "+l.response))},l.send(null)}},queryString:pe,isArray:function(e){return e&&!e.propertyIsEnumerable("length")&&"object"===M(e)&&"number"==typeof e.length},isString:function(e){return"string"==typeof e||e instanceof String},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},isID:function(e){return ge.isString(e)||ge.isNumeric(e)},isSameComponent:function(e,t){return!(!e||!t)&&(ge.isNumeric(e)||ge.isString(e)?"".concat(e):e.id)===(ge.isNumeric(t)||ge.isString(t)?"".concat(t):t.id)},isFunction:function(e){return"function"==typeof e},isObject:function(e){var t={}.constructor;return!!e&&e.constructor===t},copy:function(e){return ge.apply(e,{})},apply:function(e,t){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t},apply2:function(e,t){for(var n in e)e.hasOwnProperty(n)&&void 0!==e[n]&&null!==e[n]&&(t[n]=e[n]);return t},applyIf:function(e,t){for(var n in e)e.hasOwnProperty(n)&&(void 0!==t[n]&&null!==t[n]||(t[n]=e[n]));return t},isEmptyObject:function(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return!0},inQuotes:function(e){return ge.isNumeric(e)?"".concat(e):"'".concat(e,"'")},concat:function(e,t){var n=new e.constructor(e.length+t.length);return n.set(e),n.set(t,e.length),n},flattenParentChildHierarchy:function(e){var t=[];return function e(n){n.id=n.uuid,delete n.oid,t.push(n);var r=n.children;if(r)for(var i=0,s=r.length;i<s;i++){r[i].parent=n.id,e(r[i])}n.children=[]}(e),t}},me={},ye=new Z,_e=new ue,be={sceneId:null,time:null,startTime:null,prevTime:null,deltaTime:null},we=[],Be=0,Ce=0;var Me,ke,Ee,Fe=new function(){this.version="1.0.0",this.scenes={},this._superTypes={},this._addScene=function(e){if(e.id){if(Fe.scenes[e.id])return void console.error("[ERROR] Scene ".concat(ge.inQuotes(e.id)," already exists"))}else e.id=ye.addItem({});Fe.scenes[e.id]=e;var t=e.ticksPerOcclusionTest,n=e.ticksPerRender;me[e.id]={ticksPerOcclusionTest:t,ticksPerRender:n,renderCountdown:n},he.components.scenes++,e.once("destroyed",(function(){ye.removeItem(e.id),delete Fe.scenes[e.id],delete me[e.id],he.components.scenes--}))},this.clear=function(){var e;for(var t in Fe.scenes)Fe.scenes.hasOwnProperty(t)&&(e=Fe.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete Fe.scenes[e.id]))},this.scheduleTask=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;_e.push(e),_e.push(t)},this.runTasks=function(){for(var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:-1,r=(new Date).getTime(),i=0;_e.length>0&&(n<0||r<n);)e=_e.shift(),(t=_e.shift())?e.call(t):e(),r=(new Date).getTime(),i++;return i},this.getNumTasks=function(){return _e.length}},xe=function(){var e=Date.now();if(ve=e-Be,Be>0&&ve>0){var t=1e3/ve;Ce+=t,we.push(t),we.length>=30&&(Ce-=we.shift()),he.frame.fps=Math.round(Ce/we.length)}for(var n in Fe.scenes)Fe.scenes[n].compile();Ue(e),Be=e};Me=function(){xe()},ke=100,Ee=Date.now()+ke,function e(){var t=Date.now()-Ee;Me(),Ee+=ke,setTimeout(e,Math.max(0,ke-t))}();function Ue(e){var t=Fe.runTasks(e+10),n=Fe.getNumTasks();he.frame.tasksRun=t,he.frame.tasksScheduled=n,he.frame.tasksBudget=10}!function e(){var t=Date.now();if(ve=t-Be,Be>0&&ve>0){var n=1e3/ve;Ce+=n,we.push(n),we.length>=30&&(Ce-=we.shift()),he.frame.fps=Math.round(Ce/we.length)}Ue(t),function(e){for(var t in be.time=e,Fe.scenes)if(Fe.scenes.hasOwnProperty(t)){var n=Fe.scenes[t];be.sceneId=t,be.startTime=n.startTime,be.deltaTime=null!=be.prevTime?be.time-be.prevTime:0,n.fire("tick",be,!0)}be.prevTime=e}(t),function(){var e,t,n,r,i,s=Fe.scenes,a=!1;for(i in s)s.hasOwnProperty(i)&&(e=s[i],(t=me[i])||(t=me[i]={}),n=e.ticksPerOcclusionTest,t.ticksPerOcclusionTest!==n&&(t.ticksPerOcclusionTest=n,t.renderCountdown=n),--e.occlusionTestCountdown<=0&&(e.doOcclusionTest(),e.occlusionTestCountdown=n),r=e.ticksPerRender,t.ticksPerRender!==r&&(t.ticksPerRender=r,t.renderCountdown=r),0==--t.renderCountdown&&(e.render(a),t.renderCountdown=r))}(),void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(xe):requestAnimationFrame(e)}();var Ie=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,e),this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=n.viewer;else{if("Scene"===t.type)this.scene=t;else{if(!(t instanceof e))throw"Invalid param: owner must be a Component";this.scene=t.scene}this._owner=t}this._dontClear=!!n.dontClear,this._renderer=this.scene._renderer,this.meta=n.meta||{},this.id=n.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,t&&t._own(this)}return I(e,[{key:"type",get:function(){return"Component"}},{key:"isComponent",get:function(){return!0}},{key:"glRedraw",value:function(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}},{key:"glResort",value:function(){this._renderer&&this._renderer.needStateSort()}},{key:"owner",get:function(){return this._owner}},{key:"isType",value:function(e){return this.type===e}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==n&&(this._events[e]=t||!0);var r,i=this._eventSubs[e];if(i)for(var s in i)i.hasOwnProperty(s)&&(r=i[s],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new Z),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var r=this._eventSubs[e];r?this._eventSubsNum[e]++:(r={},this._eventSubs[e]=r,this._eventSubsNum[e]=1);var i=this._subIdMap.addItem();r[i]={callback:t,scope:n||this},this._subIdEvents[i]=e;var s=this._events[e];return void 0!==s&&t.call(n||this,s),i}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var n=this._eventSubs[t];n&&(delete n[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,n){var r=this,i=this.on(e,(function(e){r.off(i),t.call(n||this,e)}),n)}},{key:"hasSubs",value:function(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}},{key:"log",value:function(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}},{key:"_message",value:function(e){return" ["+this.type+" "+ge.inQuotes(this.id)+"]: "+e}},{key:"warn",value:function(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}},{key:"error",value:function(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}},{key:"_attach",value:function(e){var t=e.name;if(t){var n=e.component,r=e.sceneDefault,i=e.sceneSingleton,s=e.type,a=e.on,o=!1!==e.recompiles;if(n&&(ge.isNumeric(n)||ge.isString(n))){var A=n;if(!(n=this.scene.components[A]))return void this.error("Component not found: "+ge.inQuotes(A))}if(!n)if(!0===i){var c=this.scene.types[s];for(var l in c)if(c.hasOwnProperty){n=c[l];break}if(!n)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===r&&!(n=this.scene[t]))return this.error("Scene has no default component for '"+t+"'"),null;if(n){if(n.scene.id!==this.scene.id)return void this.error("Not in same scene: "+n.type+" "+ge.inQuotes(n.id));if(s&&!n.isType(s))return void this.error("Expected a "+s+" type or subtype: "+n.type+" "+ge.inQuotes(n.id))}this._attachments||(this._attachments={});var u,h,d,f=this._attached[t];if(f){if(n&&f.id===n.id)return;var p=this._attachments[f.id];for(h=0,d=(u=p.subs).length;h<d;h++)f.off(u[h]);delete this._attached[t],delete this._attachments[f.id];var v=p.params.onDetached;v&&(ge.isFunction(v)?v(f):v.scope?v.callback.call(v.scope,f):v.callback(f)),p.managingLifecycle&&f.destroy()}if(n){var g={params:e,component:n,subs:[],managingLifecycle:!1};g.subs.push(n.once("destroyed",(function(){g.params.component=null,this._attach(g.params)}),this)),o&&g.subs.push(n.on("dirty",(function(){this.fire("dirty",this)}),this)),this._attached[t]=n,this._attachments[n.id]=g;var m,y,_,b,w=e.onAttached;if(w&&(ge.isFunction(w)?w(n):w.scope?w.callback.call(w.scope,n):w.callback(n)),a)for(m in a)if(a.hasOwnProperty(m)){if(y=a[m],ge.isFunction(y)?(_=y,b=null):(_=y.callback,b=y.scope),!_)continue;g.subs.push(n.on(m,_,b))}}return o&&this.fire("dirty",this),this.fire(t,n),n}this.error("Component 'name' expected")}},{key:"_checkComponent",value:function(e,t){if(!t.isComponent){if(!ge.isID(t))return void this.error("Expected a Component or ID");var n=t;if(!(t=this.scene.components[n]))return void this.error("Component not found: "+n)}if(e===t.type){if(t.scene.id===this.scene.id)return t;this.error("Not in same scene: "+t.type)}else this.error("Expected a "+e+" Component")}},{key:"_checkComponent2",value:function(e,t){if(!t.isComponent){if(!ge.isID(t))return void this.error("Expected a Component or ID");var n=t;if(!(t=this.scene.components[n]))return void this.error("Component not found: "+n)}if(t.scene.id===this.scene.id){for(var r=0,i=e.length;r<i;r++)if(e[r]===t.type)return t;return this.error("Expected component types: "+e),null}this.error("Not in same scene: "+t.type)}},{key:"_own",value:function(e){var t=this;this._ownedComponents||(this._ownedComponents={}),this._ownedComponents[e.id]||(this._ownedComponents[e.id]=e),e.once("destroyed",(function(){delete t._ownedComponents[e.id]}),this)}},{key:"_needUpdate",value:function(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():Fe.scheduleTask(this._doUpdate,this))}},{key:"_doUpdate",value:function(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}},{key:"scheduleTask",value:function(e){Fe.scheduleTask(e,null)}},{key:"_update",value:function(){}},{key:"clear",value:function(){if(this._ownedComponents)for(var e in this._ownedComponents){if(this._ownedComponents.hasOwnProperty(e))this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}},{key:"destroy",value:function(){if(!this.destroyed){var e,t,n,r,i,s;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(n=(t=this._attachments[e]).component,i=0,s=(r=t.subs).length;i<s;i++)n.off(r[i]);t.managingLifecycle&&n.destroy()}if(this._ownedComponents)for(e in this._ownedComponents)this._ownedComponents.hasOwnProperty(e)&&((n=this._ownedComponents[e]).destroy(),delete this._ownedComponents[e]);this.scene._removeComponent(this),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=!1}}}]),e}(),Te=Ae.vec3(),Pe=Ae.vec3(),Se=Ae.mat4(),De=function(){function e(){x(this,e),this.normal=Ae.vec3(),this.offset=0,this.testVertex=Ae.vec3()}return I(e,[{key:"set",value:function(e,t,n,r){var i=1/Math.sqrt(e*e+t*t+n*n);this.normal[0]=e*i,this.normal[1]=t*i,this.normal[2]=n*i,this.offset=r*i,this.testVertex[0]=this.normal[0]>=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}]),e}(),Qe=I((function e(){x(this,e),this.planes=[new De,new De,new De,new De,new De,new De]}));function Re(e,t,n){var r=Ae.mulMat4(n,t,Se),i=r[0],s=r[1],a=r[2],o=r[3],A=r[4],c=r[5],l=r[6],u=r[7],h=r[8],d=r[9],f=r[10],p=r[11],v=r[12],g=r[13],m=r[14],y=r[15];e.planes[0].set(o-i,u-A,p-h,y-v),e.planes[1].set(o+i,u+A,p+h,y+v),e.planes[2].set(o-s,u-c,p-d,y-g),e.planes[3].set(o+s,u+c,p+d,y+g),e.planes[4].set(o-a,u-l,p-f,y-m),e.planes[5].set(o+a,u+l,p+f,y+m)}function Oe(e,t){var n=Qe.INSIDE,r=Te,i=Pe;r[0]=t[0],r[1]=t[1],r[2]=t[2],i[0]=t[3],i[1]=t[4],i[2]=t[5];for(var s=[r,i],a=0;a<6;++a){var o=e.planes[a];if(o.normal[0]*s[o.testVertex[0]][0]+o.normal[1]*s[o.testVertex[1]][1]+o.normal[2]*s[o.testVertex[2]][2]+o.offset<0)return Qe.OUTSIDE;o.normal[0]*s[1-o.testVertex[0]][0]+o.normal[1]*s[1-o.testVertex[1]][1]+o.normal[2]*s[1-o.testVertex[2]][2]+o.offset<0&&(n=Qe.INTERSECT)}return n}Qe.INSIDE=0,Qe.INTERSECT=1,Qe.OUTSIDE=2;var Ve=function(e){m(n,Ie);var t=_(n);function n(){var e,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(x(this,n),!r.viewer)throw"[MarqueePicker] Missing config: viewer";if(!r.objectsKdTree3)throw"[MarqueePicker] Missing config: objectsKdTree3";return(e=t.call(this,r.viewer.scene,r)).viewer=r.viewer,e._objectsKdTree3=r.objectsKdTree3,e._canvasMarqueeCorner1=Ae.vec2(),e._canvasMarqueeCorner2=Ae.vec2(),e._canvasMarquee=Ae.AABB2(),e._marqueeFrustum=new Qe,e._marqueeFrustumProjMat=Ae.mat4(),e._pickMode=!1,e._marqueeElement=document.createElement("div"),document.body.appendChild(e._marqueeElement),e._marqueeElement.style.position="absolute",e._marqueeElement.style["z-index"]="40000005",e._marqueeElement.style.width="8px",e._marqueeElement.style.height="8px",e._marqueeElement.style.visibility="hidden",e._marqueeElement.style.top="0px",e._marqueeElement.style.left="0px",e._marqueeElement.style["box-shadow"]="0 2px 5px 0 #182A3D;",e._marqueeElement.style.opacity=1,e._marqueeElement.style["pointer-events"]="none",e}return I(n,[{key:"setMarqueeCorner1",value:function(e){this._canvasMarqueeCorner1.set(e),this._canvasMarqueeCorner2.set(e),this._updateMarquee()}},{key:"setMarqueeCorner2",value:function(e){this._canvasMarqueeCorner2.set(e),this._updateMarquee()}},{key:"setMarquee",value:function(e,t){this._canvasMarqueeCorner1.set(e),this._canvasMarqueeCorner2.set(t),this._updateMarquee()}},{key:"setMarqueeVisible",value:function(e){this._marqueVisible=e,this._marqueeElement.style.visibility=e?"visible":"hidden"}},{key:"getMarqueeVisible",value:function(){return this._marqueVisible}},{key:"setPickMode",value:function(e){if(e!==n.PICK_MODE_INSIDE&&e!==n.PICK_MODE_INTERSECTS)throw"Illegal MarqueePicker pickMode: must be MarqueePicker.PICK_MODE_INSIDE or MarqueePicker.PICK_MODE_INTERSECTS";e!==this._pickMode&&(this._marqueeElement.style["background-image"]=e===n.PICK_MODE_INSIDE?"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\")":"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=e)}},{key:"getPickMode",value:function(){return this._pickMode}},{key:"clear",value:function(){this.fire("clear",{})}},{key:"pick",value:function(){var e=this;this._updateMarquee(),this._buildMarqueeFrustum();var t=[];return(this._canvasMarquee[2]-this._canvasMarquee[0]>3||this._canvasMarquee[3]-this._canvasMarquee[1]>3)&&function r(i){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Qe.INTERSECT;if(s===Qe.INTERSECT&&(s=Oe(e._marqueeFrustum,i.aabb)),s!==Qe.OUTSIDE){if(i.entities)for(var a=i.entities,o=0,A=a.length;o<A;o++){var c=a[o];if(c.visible){var l=c.aabb;if(e._pickMode===n.PICK_MODE_INSIDE)Oe(e._marqueeFrustum,l)===Qe.INSIDE&&t.push(c.id);else Oe(e._marqueeFrustum,l)!==Qe.OUTSIDE&&t.push(c.id)}}i.left&&r(i.left,s),i.right&&r(i.right,s)}}(this._objectsKdTree3.root),this.fire("picked",t),t}},{key:"_updateMarquee",value:function(){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="".concat(this._canvasMarquee[2]-this._canvasMarquee[0],"px"),this._marqueeElement.style.height="".concat(this._canvasMarquee[3]-this._canvasMarquee[1],"px"),this._marqueeElement.style.left="".concat(this._canvasMarquee[0],"px"),this._marqueeElement.style.top="".concat(this._canvasMarquee[1],"px")}},{key:"_buildMarqueeFrustum",value:function(){var e=this.viewer.scene.canvas.canvas,t=e.clientWidth,n=e.clientHeight,r=e.clientLeft,i=e.clientTop,s=2/t,a=2/n,o=e.clientHeight/e.clientWidth,A=(this._canvasMarquee[0]-r)*s-1,c=(this._canvasMarquee[2]-r)*s-1,l=-(this._canvasMarquee[3]-i)*a+1,u=-(this._canvasMarquee[1]-i)*a+1,h=this.viewer.scene.camera.frustum.near*(17*o);Ae.frustumMat4(A,c,l*o,u*o,h,1e4,this._marqueeFrustumProjMat),Re(this._marqueeFrustum,this.viewer.scene.camera.viewMatrix,this._marqueeFrustumProjMat)}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._marqueeElement.parentElement&&(this._marqueeElement.parentElement.removeChild(this._marqueeElement),this._marqueeElement=null,this._objectsKdTree3=null)}}]),n}();Ve.PICK_MODE_INTERSECTS=0,Ve.PICK_MODE_INSIDE=1;var Le=function(e){m(n,Ie);var t=_(n);function n(e){var r;x(this,n),r=t.call(this,e.marqueePicker,e);var i,s,a,o,A,c,l,u=e.marqueePicker,h=u.viewer.scene.canvas.canvas,d=!1,f=!1,p=!1;return h.addEventListener("mousedown",(function(e){r.getActive()&&0===e.button&&(l=setTimeout((function(){var t=u.viewer.scene.input;t.keyDown[t.KEY_CTRL]||u.clear(),i=e.pageX,s=e.pageY,A=e.offsetX,u.setMarqueeCorner1([i,s]),d=!0,u.viewer.cameraControl.pointerEnabled=!1,u.setMarqueeVisible(!0),h.style.cursor="crosshair"}),400),f=!0)})),h.addEventListener("mouseup",(function(e){if(r.getActive()&&(d||p)&&0===e.button){clearTimeout(l),a=e.pageX,o=e.pageY;var t=Math.abs(a-i),n=Math.abs(o-s);d=!1,u.viewer.cameraControl.pointerEnabled=!0,p&&(p=!1),(t>3||n>3)&&u.pick()}})),document.addEventListener("mouseup",(function(e){r.getActive()&&0===e.button&&(clearTimeout(l),d&&(u.setMarqueeVisible(!1),d=!1,f=!1,p=!0,u.viewer.cameraControl.pointerEnabled=!0))}),!0),h.addEventListener("mousemove",(function(e){r.getActive()&&0===e.button&&f&&(clearTimeout(l),d&&(a=e.pageX,o=e.pageY,c=e.offsetX,u.setMarqueeVisible(!0),u.setMarqueeCorner2([a,o]),u.setPickMode(A<c?Ve.PICK_MODE_INSIDE:Ve.PICK_MODE_INTERSECTS)))})),r}return I(n,[{key:"setActive",value:function(e){this._active!==e&&(this._active=e,this.fire("active",this._active))}},{key:"getActive",value:function(){return this._active}},{key:"destroy",value:function(){}}]),n}(),He=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,e),this.viewer=t,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=!1!==n.active,this._visible=!1,this._running=!1,this._destroyed=!1}return I(e,[{key:"start",value:function(e){var t=this;if(!this._destroyed){this._circlePos=e,this._running=!1,this._circleRadius=this._circleMaxRadius,this._circleDiv.style.borderRadius="".concat(this._circleRadius,"px"),this._circleDiv.style.marginLeft="".concat(this._circlePos[0]-this._circleRadius,"px"),this._circleDiv.style.marginTop="".concat(this._circlePos[1]-this._circleRadius,"px");var n,r=this._circleMaxRadius;this._running=!0,requestAnimationFrame((function e(i){if(t._running){n||(n=i);var s=i-n,a=Math.min(s/300,1),o=r+(2-r)*a;t._circleRadius=o,t._circleDiv.style.width="".concat(t._circleRadius,"px"),t._circleDiv.style.height="".concat(t._circleRadius,"px"),t._circleDiv.style.marginLeft="".concat(t._circlePos[0]-t._circleRadius/2,"px"),t._circleDiv.style.marginTop="".concat(t._circlePos[1]-t._circleRadius/2,"px"),a<1&&requestAnimationFrame(e)}})),this._circleDiv.style.visibility="visible"}}},{key:"stop",value:function(){this._destroyed||(this._running=!1,this._circleRadius=this._circleMaxRadius,this._circleDiv.style.borderRadius="".concat(this._circleRadius,"px"),this._circleDiv.style.visibility="hidden")}},{key:"durationMs",get:function(){return this._durationMs},set:function(e){this.stop(),this._durationMs=e}},{key:"destroy",value:function(){this._destroyed||(this.stop(),this._circleDiv.parentElement.removeChild(this._circleDiv),this._destroyed=!0)}}]),e}(),Ne=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};x(this,e),this._eventSubIDMap=null,this._eventSubEvents=null,this._eventSubs=null,this._events=null,this._locale="en",this._messages={},this._locales=[],this._locale="en",this.messages=t.messages,this.locale=t.locale}return I(e,[{key:"messages",set:function(e){this._messages=e||{},this._locales=Object.keys(this._messages),this.fire("updated",this)}},{key:"loadMessages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};for(var t in e)this._messages[t]=e[t];this.messages=this._messages}},{key:"clearMessages",value:function(){this.messages={}}},{key:"locales",get:function(){return this._locales}},{key:"locale",get:function(){return this._locale},set:function(e){e=e||"de",this._locale!==e&&(this._locale=e,this.fire("updated",e))}},{key:"translate",value:function(e,t){var n=this._messages[this._locale];if(!n)return null;var r=Ge(e,n);return r?t?je(r,t):r:null}},{key:"translatePlurals",value:function(e,t,n){var r=this._messages[this._locale];if(!r)return null;var i=Ge(e,r);return(i=0===(t=parseInt(""+t,10))?i.zero:t>1?i.other:i.one)?(i=je(i,[t]),n&&(i=je(i,n)),i):null}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==n&&(this._events[e]=t||!0);var r=this._eventSubs[e];if(r)for(var i in r){if(r.hasOwnProperty(i))r[i].callback(t)}}},{key:"on",value:function(e,t){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new Z),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});var n=this._eventSubs[e];n||(n={},this._eventSubs[e]=n);var r=this._eventSubIDMap.addItem();n[r]={callback:t},this._eventSubEvents[r]=e;var i=this._events[e];return void 0!==i&&t(i),r}},{key:"off",value:function(e){if(null!=e&&this._eventSubEvents){var t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];var n=this._eventSubs[t];n&&delete n[e],this._eventSubIDMap.removeItem(e)}}}}]),e}();function Ge(e,t){if(t[e])return t[e];for(var n=e.split("."),r=t,i=0,s=n.length;r&&i<s;i++){r=r[n[i]]}return r}function je(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,n){return"{{"===e?"{":"}}"===e?"}":t[n]}))}var We=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i)).t=i.t,r}return I(n,[{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"tangent",get:function(){return this.getTangent(this._t)}},{key:"length",get:function(){var e=this._getLengths();return e[e.length-1]}},{key:"getTangent",value:function(e){var t=1e-4;void 0===e&&(e=this._t);var n=e-t,r=e+t;n<0&&(n=0),r>1&&(r=1);var i=this.getPoint(n),s=this.getPoint(r),a=Ae.subVec3(s,i,[]);return Ae.normalizeVec3(a,[])}},{key:"getPointAt",value:function(e){var t=this.getUToTMapping(e);return this.getPoint(t)}},{key:"getPoints",value:function(e){e||(e=5);var t,n=[];for(t=0;t<=e;t++)n.push(this.getPoint(t/e));return n}},{key:"_getLengths",value:function(e){if(e||(e=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var t,n,r=[],i=this.getPoint(0),s=0;for(r.push(0),n=1;n<=e;n++)t=this.getPoint(n/e),s+=Ae.lenVec3(Ae.subVec3(t,i,[])),r.push(s),i=t;return this.cacheArcLengths=r,r}},{key:"_updateArcLengths",value:function(){this.needsUpdate=!0,this._getLengths()}},{key:"getUToTMapping",value:function(e,t){var n,r=this._getLengths(),i=0,s=r.length;n=t||e*r[s-1];for(var a,o=0,A=s-1;o<=A;)if((a=r[i=Math.floor(o+(A-o)/2)]-n)<0)o=i+1;else{if(!(a>0)){A=i;break}A=i-1}if(r[i=A]===n)return i/(s-1);var c=r[i];return(i+(n-c)/(r[i+1]-c))/(s-1)}}]),n}(),ze=function(e){m(n,We);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i)).points=i.points,r.t=i.t,r}return I(n,[{key:"points",get:function(){return this._points},set:function(e){this._points=e||[]}},{key:"t",get:function(){return this._t},set:function(e){e=e||0,this._t=e<0?0:e>1?1:e}},{key:"point",get:function(){return this.getPoint(this._t)}},{key:"getPoint",value:function(e){var t=this.points;if(!(t.length<3)){var n=(t.length-1)*e,r=Math.floor(n),i=n-r,s=t[0===r?r:r-1],a=t[r],o=t[r>t.length-2?t.length-1:r+1],A=t[r>t.length-3?t.length-1:r+2],c=Ae.vec3();return c[0]=Ae.catmullRomInterpolate(s[0],a[0],o[0],A[0],i),c[1]=Ae.catmullRomInterpolate(s[1],a[1],o[1],A[1],i),c[2]=Ae.catmullRomInterpolate(s[2],a[2],o[2],A[2],i),c}this.error("Can't sample point from SplineCurve - not enough points on curve - returning [0,0,0].")}},{key:"getJSON",value:function(){return{points:points,t:this._t}}}]),n}(),Xe=Ae.vec3(),Ke=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._frames=[],r._eyeCurve=new ze(w(r)),r._lookCurve=new ze(w(r)),r._upCurve=new ze(w(r)),i.frames&&(r.addFrames(i.frames),r.smoothFrameTimes(1)),r}return I(n,[{key:"type",get:function(){return"CameraPath"}},{key:"frames",get:function(){return this._frames}},{key:"eyeCurve",get:function(){return this._eyeCurve}},{key:"lookCurve",get:function(){return this._lookCurve}},{key:"upCurve",get:function(){return this._upCurve}},{key:"saveFrame",value:function(e){var t=this.scene.camera;this.addFrame(e,t.eye,t.look,t.up)}},{key:"addFrame",value:function(e,t,n,r){var i={t:e,eye:t.slice(0),look:n.slice(0),up:r.slice(0)};this._frames.push(i),this._eyeCurve.points.push(i.eye),this._lookCurve.points.push(i.look),this._upCurve.points.push(i.up)}},{key:"addFrames",value:function(e){for(var t,n=0,r=e.length;n<r;n++)t=e[n],this.addFrame(t.t||0,t.eye,t.look,t.up)}},{key:"loadFrame",value:function(e){var t=this.scene.camera;e=(e/=this._frames[this._frames.length-1].t-this._frames[0].t)<0?0:e>1?1:e,t.eye=this._eyeCurve.getPoint(e,Xe),t.look=this._lookCurve.getPoint(e,Xe),t.up=this._upCurve.getPoint(e,Xe)}},{key:"sampleFrame",value:function(e,t,n,r){e=e<0?0:e>1?1:e,this._eyeCurve.getPoint(e,t),this._lookCurve.getPoint(e,n),this._upCurve.getPoint(e,r)}},{key:"smoothFrameTimes",value:function(e){if(0!==this._frames.length){var t=Ae.vec3(),n=0;this._frames[0].t=0;for(var r=[],i=1,s=this._frames.length;i<s;i++){var a=Ae.lenVec3(Ae.subVec3(this._frames[i].eye,this._frames[i-1].eye,t));r[i]=a,n+=a}for(var o=1,A=this._frames.length;o<A;o++){var c=r[o]/n*e;this._frames[o].t=this._frames[o-1].t+c}}}},{key:"clearFrames",value:function(){this._frames=[],this._eyeCurve.points=[],this._lookCurve.points=[],this._upCurve.points=[]}}]),n}(),Ze=Ae.vec3(),Je=Ae.vec3(),Ye=Ae.vec3(),qe=Ae.vec3(),$e=Ae.vec3(),et=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._look1=Ae.vec3(),r._eye1=Ae.vec3(),r._up1=Ae.vec3(),r._look2=Ae.vec3(),r._eye2=Ae.vec3(),r._up2=Ae.vec3(),r._orthoScale1=1,r._orthoScale2=1,r._flying=!1,r._flyEyeLookUp=!1,r._flyingEye=!1,r._flyingLook=!1,r._callback=null,r._callbackScope=null,r._time1=null,r._time2=null,r.easing=!1!==i.easing,r.duration=i.duration,r.fit=i.fit,r.fitFOV=i.fitFOV,r.trail=i.trail,r}return I(n,[{key:"type",get:function(){return"CameraFlightAnimation"}},{key:"flyTo",value:function(e,t,n){e=e||this.scene,this._flying&&this.stop(),this._flying=!1,this._flyingEye=!1,this._flyingLook=!1,this._flyingEyeLookUp=!1,this._callback=t,this._callbackScope=n;var r,i,s,a,o,A=this.scene.camera,c=!!e.projection&&e.projection!==A.projection;if(this._eye1[0]=A.eye[0],this._eye1[1]=A.eye[1],this._eye1[2]=A.eye[2],this._look1[0]=A.look[0],this._look1[1]=A.look[1],this._look1[2]=A.look[2],this._up1[0]=A.up[0],this._up1[1]=A.up[1],this._up1[2]=A.up[2],this._orthoScale1=A.ortho.scale,this._orthoScale2=e.orthoScale||this._orthoScale1,e.aabb)r=e.aabb;else if(6===e.length)r=e;else if(e.eye&&e.look||e.up)i=e.eye,s=e.look,a=e.up;else if(e.eye)i=e.eye;else if(e.look)s=e.look;else{var l=e;if((ge.isNumeric(l)||ge.isString(l))&&(o=l,!(l=this.scene.components[o])))return this.error("Component not found: "+ge.inQuotes(o)),void(t&&(n?t.call(n):t()));c||(r=l.aabb||this.scene.aabb)}var u=e.poi;if(r){if(r[3]<r[0]||r[4]<r[1]||r[5]<r[2])return;if(r[3]===r[0]&&r[4]===r[1]&&r[5]===r[2])return;r=r.slice();var h=Ae.getAABB3Center(r);this._look2=u||h;var d=Ae.subVec3(this._eye1,this._look1,Ze),f=Ae.normalizeVec3(d),p=u?Ae.getAABB3DiagPoint(r,u):Ae.getAABB3Diag(r),v=e.fitFOV||this._fitFOV,g=Math.abs(p/Math.tan(v*Ae.DEGTORAD));this._orthoScale2=1.1*p,this._eye2[0]=this._look2[0]+f[0]*g,this._eye2[1]=this._look2[1]+f[1]*g,this._eye2[2]=this._look2[2]+f[2]*g,this._up2[0]=this._up1[0],this._up2[1]=this._up1[1],this._up2[2]=this._up1[2],this._flyingEyeLookUp=!0}else(i||s||a)&&(this._flyingEyeLookUp=!!i&&!!s&&!!a,this._flyingEye=!!i&&!s,this._flyingLook=!!s&&!i,i&&(this._eye2[0]=i[0],this._eye2[1]=i[1],this._eye2[2]=i[2]),s&&(this._look2[0]=s[0],this._look2[1]=s[1],this._look2[2]=s[2]),a&&(this._up2[0]=a[0],this._up2[1]=a[1],this._up2[2]=a[2]));c?("ortho"===e.projection&&"ortho"!==A.projection&&(this._projection2="ortho",this._projMatrix1=A.projMatrix.slice(),this._projMatrix2=A.ortho.matrix.slice(),A.projection="customProjection"),"perspective"===e.projection&&"perspective"!==A.projection&&(this._projection2="perspective",this._projMatrix1=A.projMatrix.slice(),this._projMatrix2=A.perspective.matrix.slice(),A.projection="customProjection")):this._projection2=null,this.fire("started",e,!0),this._time1=Date.now(),this._time2=this._time1+(Number.isFinite(e.duration)?1e3*e.duration:this._duration),this._flying=!0,Fe.scheduleTask(this._update,this)}},{key:"jumpTo",value:function(e){this._jumpTo(e)}},{key:"_jumpTo",value:function(e){this._flying&&this.stop();var t,n,r,i,s,a=this.scene.camera;if(e.aabb)t=e.aabb;else if(6===e.length)t=e;else if(e.eye||e.look||e.up)r=e.eye,i=e.look,s=e.up;else{var o=e;if((ge.isNumeric(o)||ge.isString(o))&&(n=o,!(o=this.scene.components[n])))return void this.error("Component not found: "+ge.inQuotes(n));t=o.aabb||this.scene.aabb}var A=e.poi;if(t){if(t[3]<=t[0]||t[4]<=t[1]||t[5]<=t[2])return;var c,l=A?Ae.getAABB3DiagPoint(t,A):Ae.getAABB3Diag(t);i=A||Ae.getAABB3Center(t,i),this._trail?Ae.subVec3(a.look,i,$e):Ae.subVec3(a.eye,a.look,$e),Ae.normalizeVec3($e),c=(void 0!==e.fit?e.fit:this._fit)?Math.abs(l/Math.tan((e.fitFOV||this._fitFOV)*Ae.DEGTORAD)):Ae.lenVec3(Ae.subVec3(a.eye,a.look,Ze)),Ae.mulVec3Scalar($e,c),a.eye=Ae.addVec3(i,$e,Ze),a.look=i,this.scene.camera.ortho.scale=1.1*l}else(r||i||s)&&(r&&(a.eye=r),i&&(a.look=i),s&&(a.up=s));e.projection&&(a.projection=e.projection)}},{key:"_update",value:function(){if(this._flying){var e=(Date.now()-this._time1)/(this._time2-this._time1),t=e>=1;e>1&&(e=1);var r=this.easing?n._ease(e,0,1,1):e,i=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(Ae.subVec3(i.eye,i.look,$e),i.eye=Ae.lerpVec3(r,0,1,this._eye1,this._eye2,Ye),i.look=Ae.subVec3(Ye,$e,Je)):this._flyingLook&&(i.look=Ae.lerpVec3(r,0,1,this._look1,this._look2,Je),i.up=Ae.lerpVec3(r,0,1,this._up1,this._up2,qe)):this._flyingEyeLookUp&&(i.eye=Ae.lerpVec3(r,0,1,this._eye1,this._eye2,Ye),i.look=Ae.lerpVec3(r,0,1,this._look1,this._look2,Je),i.up=Ae.lerpVec3(r,0,1,this._up1,this._up2,qe)),this._projection2){var s="ortho"===this._projection2?n._easeOutExpo(e,0,1,1):n._easeInCubic(e,0,1,1);i.customProjection.matrix=Ae.lerpMat4(s,0,1,this._projMatrix1,this._projMatrix2)}else i.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return i.ortho.scale=this._orthoScale2,void this.stop();Fe.scheduleTask(this._update,this)}}},{key:"stop",value:function(){if(this._flying){this._flying=!1,this._time1=null,this._time2=null,this._projection2&&(this.scene.camera.projection=this._projection2);var e=this._callback;e&&(this._callback=null,this._callbackScope?e.call(this._callbackScope):e()),this.fire("stopped",!0,!0)}}},{key:"cancel",value:function(){this._flying&&(this._flying=!1,this._time1=null,this._time2=null,this._callback&&(this._callback=null),this.fire("canceled",!0,!0))}},{key:"duration",get:function(){return this._duration/1e3},set:function(e){this._duration=Number.isFinite(e)?1e3*e:500,this.stop()}},{key:"fit",get:function(){return this._fit},set:function(e){this._fit=!1!==e}},{key:"fitFOV",get:function(){return this._fitFOV},set:function(e){this._fitFOV=e||45}},{key:"trail",get:function(){return this._trail},set:function(e){this._trail=!!e}},{key:"destroy",value:function(){this.stop(),v(C(n.prototype),"destroy",this).call(this)}}],[{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"_easeInCubic",value:function(e,t,n,r){return n*(e/=r)*e*e+t}},{key:"_easeOutExpo",value:function(e,t,n,r){return n*(1-Math.pow(2,-10*e/r))+t}}]),n}(),tt=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._cameraFlightAnimation=new et(w(r)),r._t=0,r.state=n.SCRUBBING,r._playingFromT=0,r._playingToT=0,r._playingRate=i.playingRate||1,r._playingDir=1,r._lastTime=null,r.cameraPath=i.cameraPath,r._tick=r.scene.on("tick",r._updateT,w(r)),r}return I(n,[{key:"type",get:function(){return"CameraPathAnimation"}},{key:"_updateT",value:function(){var e=this._cameraPath;if(e){var t,r,i=performance.now(),s=this._lastTime?.001*(i-this._lastTime):0;if(this._lastTime=i,0!==s)switch(this.state){case n.SCRUBBING:return;case n.PLAYING:if(this._t+=this._playingRate*s,0===(t=this._cameraPath.frames.length)||this._playingDir<0&&this._t<=0||this._playingDir>0&&this._t>=this._cameraPath.frames[t-1].t)return this.state=n.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case n.PLAYING_TO:r=this._t+this._playingRate*s*this._playingDir,(this._playingDir<0&&r<=this._playingToT||this._playingDir>0&&r>=this._playingToT)&&(r=this._playingToT,this.state=n.SCRUBBING,this.fire("stopped")),this._t=r,e.loadFrame(this._t)}}}},{key:"_ease",value:function(e,t,n,r){return-n*(e/=r)*(e-2)+t}},{key:"cameraPath",get:function(){return this._cameraPath},set:function(e){this._cameraPath=e}},{key:"rate",get:function(){return this._playingRate},set:function(e){this._playingRate=e}},{key:"play",value:function(){this._cameraPath&&(this._lastTime=null,this.state=n.PLAYING)}},{key:"playToT",value:function(e){this._cameraPath&&(this._playingFromT=this._t,this._playingToT=e,this._playingDir=this._playingToT-this._playingFromT<0?-1:1,this._lastTime=null,this.state=n.PLAYING_TO)}},{key:"playToFrame",value:function(e){var t=this._cameraPath;if(t){var n=t.frames[e];n?this.playToT(n.t):this.error("playToFrame - frame index out of range: "+e)}}},{key:"flyToFrame",value:function(e,t){var r=this._cameraPath;if(r){var i=r.frames[e];i?(this.state=n.SCRUBBING,this._cameraFlightAnimation.flyTo(i,t)):this.error("flyToFrame - frame index out of range: "+e)}}},{key:"scrubToT",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(this._t=e,t.loadFrame(this._t),this.state=n.SCRUBBING))}},{key:"scrubToFrame",value:function(e){var t=this._cameraPath;t&&(this.scene.camera&&(t.frames[e]?(t.loadFrame(this._t),this.state=n.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)))}},{key:"stop",value:function(){this.state=n.SCRUBBING,this.fire("stopped")}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this.scene.off(this._tick)}}]),n}();tt.STOPPED=0,tt.SCRUBBING=1,tt.PLAYING=2,tt.PLAYING_TO=3;var nt=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),r=t.call(this,e,i),he.memory.meshes++,r}return I(n,[{key:"type",get:function(){return"Geometry"}},{key:"isGeometry",get:function(){return!0}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),he.memory.meshes--}}]),n}(),rt=new Z({}),it=function(){function e(t){for(var n in x(this,e),this.id=rt.addItem({}),t)t.hasOwnProperty(n)&&(this[n]=t[n])}return I(e,[{key:"destroy",value:function(){rt.removeItem(this.id)}}]),e}(),st=function(){function e(t,n,r,i,s,a,o,A,c){switch(x(this,e),this._gl=t,this.type=n,this.allocated=!1,r.constructor){case Uint8Array:this.itemType=t.UNSIGNED_BYTE,this.itemByteSize=1;break;case Int8Array:this.itemType=t.BYTE,this.itemByteSize=1;break;case Uint16Array:this.itemType=t.UNSIGNED_SHORT,this.itemByteSize=2;break;case Int16Array:this.itemType=t.SHORT,this.itemByteSize=2;break;case Uint32Array:this.itemType=t.UNSIGNED_INT,this.itemByteSize=4;break;case Int32Array:this.itemType=t.INT,this.itemByteSize=4;break;default:this.itemType=t.FLOAT,this.itemByteSize=4}this.usage=a,this.length=0,this.dataLength=i,this.numItems=0,this.itemSize=s,this.normalized=!!o,this.stride=A||0,this.offset=c||0,this._allocate(r)}return I(e,[{key:"_allocate",value:function(e){if(this.allocated=!1,this._handle=this._gl.createBuffer(),!this._handle)throw"Failed to allocate WebGL ArrayBuffer";this._handle&&(this._gl.bindBuffer(this.type,this._handle),this._gl.bufferData(this.type,e.length>this.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}},{key:"setData",value:function(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}},{key:"bind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}},{key:"unbind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,null)}},{key:"bindAtLocation",value:function(e){this.bind(),this._gl.vertexAttribPointer(e,this.itemSize,this.itemType,this.normalized,0,0)}},{key:"destroy",value:function(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}]),e}(),at=function(){var e=[],t=[],n=[],r=[],i=[],s=0,a=new Uint16Array(3),o=new Uint16Array(3),A=new Uint16Array(3),c=Ae.vec3(),l=Ae.vec3(),u=Ae.vec3(),h=Ae.vec3(),d=Ae.vec3(),f=Ae.vec3(),p=Ae.vec3();return function(v,g,m,y){!function(i,s){var a,o,A,c,l,u,h={},d=Math.pow(10,4),f=0;for(l=0,u=i.length;l<u;l+=3)a=i[l],o=i[l+1],A=i[l+2],void 0===h[c=Math.round(a*d)+"_"+Math.round(o*d)+"_"+Math.round(A*d)]&&(h[c]=f/3,e[f++]=a,e[f++]=o,e[f++]=A),t[l/3]=h[c];for(l=0,u=s.length;l<u;l++)r[l]=t[s[l]],n[r[l]]=s[l]}(v,g),function(t,n){s=0;for(var v=0,g=t;v<g;v+=3){var m=3*r[v],y=3*r[v+1],_=3*r[v+2];n?(a[0]=e[m],a[1]=e[m+1],a[2]=e[m+2],o[0]=e[y],o[1]=e[y+1],o[2]=e[y+2],A[0]=e[_],A[1]=e[_+1],A[2]=e[_+2],Ae.decompressPosition(a,n,c),Ae.decompressPosition(o,n,l),Ae.decompressPosition(A,n,u)):(c[0]=e[m],c[1]=e[m+1],c[2]=e[m+2],l[0]=e[y],l[1]=e[y+1],l[2]=e[y+2],u[0]=e[_],u[1]=e[_+1],u[2]=e[_+2]),Ae.subVec3(u,l,h),Ae.subVec3(c,l,d),Ae.cross3Vec3(h,d,f),Ae.normalizeVec3(f,p);var b=i[s]||(i[s]={normal:Ae.vec3()});b.normal[0]=p[0],b.normal[1]=p[1],b.normal[2]=p[2],s++}}(g.length,m);for(var _,b,w,B,C,M,k,E,F,x,U=[],I=Math.cos(Ae.DEGTORAD*y),T={},P=!1,S=0,D=g.length;S<D;S+=3)for(var Q=S/3,R=0;R<3;R++)_=r[S+R],b=r[S+(R+1)%3],void 0===T[C=(w=Math.min(_,b))+","+(B=Math.max(_,b))]?T[C]={index1:w,index2:B,face1:Q,face2:void 0}:T[C].face2=Q;for(C in T)void 0!==(M=T[C]).face2&&(k=i[M.face1].normal,E=i[M.face2].normal,Ae.dotVec3(k,E)>I)||(F=n[M.index1],x=n[M.index2],(!P&&F>65535||x>65535)&&(P=!0),U.push(F),U.push(x));return P?new Uint32Array(U):new Uint16Array(U)}}();var ot,At,ct=(ot=Ae.mat4(),At=Ae.mat4(),function(e,t){t=t||Ae.mat4();var n=e[0],r=e[1],i=e[2],s=e[3]-n,a=e[4]-r,o=e[5]-i,A=65535;return Ae.identityMat4(ot),Ae.translationMat4v(e,ot),Ae.identityMat4(At),Ae.scalingMat4v([s/A,a/A,o/A],At),Ae.mulMat4(ot,At,t),t}),lt=function(){var e=Ae.mat4(),t=Ae.mat4();return function(n,r,i){var s,a=new Uint16Array(n.length),o=new Float32Array([i[0]!==r[0]?65535/(i[0]-r[0]):0,i[1]!==r[1]?65535/(i[1]-r[1]):0,i[2]!==r[2]?65535/(i[2]-r[2]):0]);for(s=0;s<n.length;s+=3)a[s+0]=Math.max(0,Math.min(65535,Math.floor((n[s+0]-r[0])*o[0]))),a[s+1]=Math.max(0,Math.min(65535,Math.floor((n[s+1]-r[1])*o[1]))),a[s+2]=Math.max(0,Math.min(65535,Math.floor((n[s+2]-r[2])*o[2])));return Ae.identityMat4(e),Ae.translationMat4v(r,e),Ae.identityMat4(t),Ae.scalingMat4v([(i[0]-r[0])/65535,(i[1]-r[1])/65535,(i[2]-r[2])/65535],t),{quantized:a,decodeMatrix:Ae.mulMat4(e,t,Ae.identityMat4())}}}();var ut=function(){var e=Ae.mat3(),t=Ae.mat3();return function(n,r,i){var s,a=new Uint16Array(n.length),o=new Float32Array([65535/(i[0]-r[0]),65535/(i[1]-r[1])]);for(s=0;s<n.length;s+=2)a[s+0]=Math.max(0,Math.min(65535,Math.floor((n[s+0]-r[0])*o[0]))),a[s+1]=Math.max(0,Math.min(65535,Math.floor((n[s+1]-r[1])*o[1])));return Ae.identityMat3(e),Ae.translationMat3v(r,e),Ae.identityMat3(t),Ae.scalingMat3v([(i[0]-r[0])/65535,(i[1]-r[1])/65535],t),{quantized:a,decodeMatrix:Ae.mulMat3(e,t,Ae.identityMat3())}}}();function ht(e,t,n,r){var i=e[t]/(Math.abs(e[t])+Math.abs(e[t+1])+Math.abs(e[t+2])),s=e[t+1]/(Math.abs(e[t])+Math.abs(e[t+1])+Math.abs(e[t+2]));if(e[t+2]<0){var a=(1-Math.abs(s))*(i>=0?1:-1),o=(1-Math.abs(i))*(s>=0?1:-1);i=a,s=o}return new Int8Array([Math[n](127.5*i+(i<0?-1:0)),Math[r](127.5*s+(s<0?-1:0))])}function dt(e){var t=e[0],n=e[1];t/=t<0?127:128,n/=n<0?127:128;var r=1-Math.abs(t)-Math.abs(n);r<0&&(t=(1-Math.abs(n))*(t>=0?1:-1),n=(1-Math.abs(t))*(n>=0?1:-1));var i=Math.sqrt(t*t+n*n+r*r);return[t/i,n/i,r/i]}function ft(e,t,n){return e[t]*n[0]+e[t+1]*n[1]+e[t+2]*n[2]}var pt={getPositionsBounds:function(e){var t,n,r=new Float32Array(3),i=new Float32Array(3);for(t=0;t<3;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t<e.length;t+=3)for(n=0;n<3;n++)r[n]=Math.min(r[n],e[t+n]),i[n]=Math.max(i[n],e[t+n]);return{min:r,max:i}},createPositionsDecodeMatrix:ct,compressPositions:lt,compressPosition:function(e,t,n){var r=new Float32Array([t[3]!==t[0]?65535/(t[3]-t[0]):0,t[4]!==t[1]?65535/(t[4]-t[1]):0,t[5]!==t[2]?65535/(t[5]-t[2]):0]);n[0]=Math.max(0,Math.min(65535,Math.floor((e[0]-t[0])*r[0]))),n[1]=Math.max(0,Math.min(65535,Math.floor((e[1]-t[1])*r[1]))),n[2]=Math.max(0,Math.min(65535,Math.floor((e[2]-t[2])*r[2])))},decompressPositions:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r<i;r+=3)n[r+0]=e[r+0]*t[0]+t[12],n[r+1]=e[r+1]*t[5]+t[13],n[r+2]=e[r+2]*t[10]+t[14];return n},decompressPosition:function(e,t,n){return n[0]=e[0]*t[0]+t[12],n[1]=e[1]*t[5]+t[13],n[2]=e[2]*t[10]+t[14],n},decompressAABB:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e;return n[0]=e[0]*t[0]+t[12],n[1]=e[1]*t[5]+t[13],n[2]=e[2]*t[10]+t[14],n[3]=e[3]*t[0]+t[12],n[4]=e[4]*t[5]+t[13],n[5]=e[5]*t[10]+t[14],n},getUVBounds:function(e){var t,n,r=new Float32Array(2),i=new Float32Array(2);for(t=0;t<2;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t<e.length;t+=2)for(n=0;n<2;n++)r[n]=Math.min(r[n],e[t+n]),i[n]=Math.max(i[n],e[t+n]);return{min:r,max:i}},compressUVs:ut,decompressUVs:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r<i;r+=3)n[r+0]=e[r+0]*t[0]+t[6],n[r+1]=e[r+1]*t[4]+t[7];return n},decompressUV:function(e,t,n){n[0]=e[0]*t[0]+t[6],n[1]=e[1]*t[4]+t[7]},compressNormals:function(e){for(var t,n,r,i,s=new Int8Array(e.length),a=0;a<e.length;a+=3)n=t=ht(e,a,"floor","floor"),r=i=ft(e,a,dt(t)),(r=ft(e,a,dt(t=ht(e,a,"ceil","floor"))))>i&&(n=t,i=r),(r=ft(e,a,dt(t=ht(e,a,"floor","ceil"))))>i&&(n=t,i=r),(r=ft(e,a,dt(t=ht(e,a,"ceil","ceil"))))>i&&(n=t,i=r),s[a]=n[0],s[a+1]=n[1];return s},decompressNormals:function(e,t){for(var n=0,r=0,i=e.length;n<i;n+=2){var s=e[n+0],a=e[n+1];s=(2*s+1)/255,a=(2*a+1)/255;var o=1-Math.abs(s)-Math.abs(a);o<0&&(s=(1-Math.abs(a))*(s>=0?1:-1),a=(1-Math.abs(s))*(a>=0?1:-1));var A=Math.sqrt(s*s+a*a+o*o);t[r+0]=s/A,t[r+1]=a/A,t[r+2]=o/A,r+=3}return t},decompressNormal:function(e,t){var n=e[0],r=e[1];n=(2*n+1)/255,r=(2*r+1)/255;var i=1-Math.abs(n)-Math.abs(r);i<0&&(n=(1-Math.abs(r))*(n>=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var s=Math.sqrt(n*n+r*r+i*i);return t[0]=n/s,t[1]=r/s,t[2]=i/s,t}},vt=he.memory,gt=Ae.AABB3(),mt=function(e){m(n,nt);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,n),(r=t.call(this,e,i))._state=new it({compressGeometry:!!i.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),r._numTriangles=0,r._edgeThreshold=i.edgeThreshold||10,r._edgeIndicesBuf=null,r._pickTrianglePositionsBuf=null,r._pickTriangleColorsBuf=null,r._aabbDirty=!0,r._boundingSphere=!0,r._aabb=null,r._aabbDirty=!0,r._obb=null,r._obbDirty=!0;var s=r._state,a=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":s.primitive=a.POINTS,s.primitiveName=i.primitive;break;case"lines":s.primitive=a.LINES,s.primitiveName=i.primitive;break;case"line-loop":s.primitive=a.LINE_LOOP,s.primitiveName=i.primitive;break;case"line-strip":s.primitive=a.LINE_STRIP,s.primitiveName=i.primitive;break;case"triangles":s.primitive=a.TRIANGLES,s.primitiveName=i.primitive;break;case"triangle-strip":s.primitive=a.TRIANGLE_STRIP,s.primitiveName=i.primitive;break;case"triangle-fan":s.primitive=a.TRIANGLE_FAN,s.primitiveName=i.primitive;break;default:r.error("Unsupported value for 'primitive': '"+i.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=a.TRIANGLES,s.primitiveName=i.primitive}if(i.positions)if(r._state.compressGeometry){var o=pt.getPositionsBounds(i.positions),A=pt.compressPositions(i.positions,o.min,o.max);s.positions=A.quantized,s.positionsDecodeMatrix=A.decodeMatrix}else s.positions=i.positions.constructor===Float32Array?i.positions:new Float32Array(i.positions);if(i.colors&&(s.colors=i.colors.constructor===Float32Array?i.colors:new Float32Array(i.colors)),i.uv)if(r._state.compressGeometry){var c=pt.getUVBounds(i.uv),l=pt.compressUVs(i.uv,c.min,c.max);s.uv=l.quantized,s.uvDecodeMatrix=l.decodeMatrix}else s.uv=i.uv.constructor===Float32Array?i.uv:new Float32Array(i.uv);if(i.normals&&(r._state.compressGeometry?s.normals=pt.compressNormals(i.normals):s.normals=i.normals.constructor===Float32Array?i.normals:new Float32Array(i.normals)),i.indices&&(s.indices=i.indices.constructor===Uint32Array||i.indices.constructor===Uint16Array?i.indices:new Uint32Array(i.indices),"triangles"===r._state.primitiveName&&(r._numTriangles=i.indices.length/3)),r._buildHash(),vt.meshes++,s.indices&&(s.indicesBuf=new st(a,a.ELEMENT_ARRAY_BUFFER,s.indices,s.indices.length,1,a.STATIC_DRAW),vt.indices+=s.indicesBuf.numItems),s.positions&&(s.positionsBuf=new st(a,a.ARRAY_BUFFER,s.positions,s.positions.length,3,a.STATIC_DRAW),vt.positions+=s.positionsBuf.numItems),s.normals){var u=s.compressGeometry;s.normalsBuf=new st(a,a.ARRAY_BUFFER,s.normals,s.normals.length,3,a.STATIC_DRAW,u),vt.normals+=s.normalsBuf.numItems}return s.colors&&(s.colorsBuf=new st(a,a.ARRAY_BUFFER,s.colors,s.colors.length,4,a.STATIC_DRAW),vt.colors+=s.colorsBuf.numItems),s.uv&&(s.uvBuf=new st(a,a.ARRAY_BUFFER,s.uv,s.uv.length,2,a.STATIC_DRAW),vt.uvs+=s.uvBuf.numItems),r}return I(n,[{key:"type",get:function(){return"ReadableGeometry"}},{key:"isReadableGeometry",get:function(){return!0}},{key:"_buildHash",value:function(){var e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}},{key:"_getEdgeIndices",value:function(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}},{key:"_getPickTrianglePositions",value:function(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}},{key:"_getPickTriangleColors",value:function(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}},{key:"_buildEdgeIndices",value:function(){var e=this._state;if(e.positions&&e.indices){var t=this.scene.canvas.gl,n=at(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new st(t,t.ELEMENT_ARRAY_BUFFER,n,n.length,1,t.STATIC_DRAW),vt.indices+=this._edgeIndicesBuf.numItems}}},{key:"_buildPickTriangleVBOs",value:function(){var e=this._state;if(e.positions&&e.indices){var t=this.scene.canvas.gl,n=Ae.buildPickTriangles(e.positions,e.indices,e.compressGeometry),r=n.positions,i=n.colors;this._pickTrianglePositionsBuf=new st(t,t.ARRAY_BUFFER,r,r.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new st(t,t.ARRAY_BUFFER,i,i.length,4,t.STATIC_DRAW,!0),vt.positions+=this._pickTrianglePositionsBuf.numItems,vt.colors+=this._pickTriangleColorsBuf.numItems}}},{key:"_buildPickVertexVBOs",value:function(){}},{key:"primitive",get:function(){return this._state.primitiveName}},{key:"compressGeometry",get:function(){return this._state.compressGeometry}},{key:"positions",get:function(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),pt.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null},set:function(e){var t=this._state,n=t.positions;if(n)if(n.length===e.length){if(this._state.compressGeometry){var r=pt.getPositionsBounds(e),i=pt.compressPositions(e,r.min,r.max);e=i.quantized,t.positionsDecodeMatrix=i.decodeMatrix}n.set(e),t.positionsBuf&&t.positionsBuf.setData(n),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}},{key:"normals",get:function(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){var e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),pt.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry normals - quantized geometry is immutable");else{var t=this._state,n=t.normals;n?n.length===e.length?(n.set(e),t.normalsBuf&&t.normalsBuf.setData(n),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}}},{key:"uv",get:function(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),pt.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry UVs - quantized geometry is immutable");else{var t=this._state,n=t.uv;n?n.length===e.length?(n.set(e),t.uvBuf&&t.uvBuf.setData(n),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}}},{key:"colors",get:function(){return this._state.colors},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry colors - quantized geometry is immutable");else{var t=this._state,n=t.colors;n?n.length===e.length?(n.set(e),t.colorsBuf&&t.colorsBuf.setData(n),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}}},{key:"indices",get:function(){return this._state.indices}},{key:"aabb",get:function(){return this._aabbDirty&&(this._aabb||(this._aabb=Ae.AABB3()),Ae.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}},{key:"obb",get:function(){return this._obbDirty&&(this._obb||(this._obb=Ae.OBB3()),Ae.positions3ToAABB3(this._state.positions,gt,this._state.positionsDecodeMatrix),Ae.AABB3ToOBB3(gt,this._obb),this._obbDirty=!1),this._obb}},{key:"_getMetrics",value:function(){if(!("_metrics"in this))switch(this._state.primitiveName){case"solid":case"surface":case"triangles":for(var e=this._state.indices,t=this._state.positions,n=function(n,r){for(var i=3*e[n],s=0;s<3;++s)r[s]=t[i+s];return r},r=[Ae.vec3(),Ae.vec3(),Ae.vec3(),Ae.vec3()],i=0,s=Ae.vec3([0,0,0]),a=0;a<e.length;a+=3){var o=n(a,r[0]),A=n(a+1,r[1]),c=n(a+2,r[2]);Ae.addVec3(o,A,r[3]),Ae.addVec3(c,r[3],r[3]);var l=Ae.lenVec3(Ae.cross3Vec3(Ae.subVec3(A,o,r[1]),Ae.subVec3(c,o,r[2]),r[0]))/2;i+=l,Ae.mulVec3Scalar(r[3],l,r[3]),Ae.addVec3(s,r[3],s)}this._metrics={surfaceArea:i,centroid:Ae.mulVec3Scalar(s,1/i/3,s)};break;default:this._metrics={surfaceArea:0}}return this._metrics}},{key:"surfaceArea",get:function(){return this._getMetrics().surfaceArea}},{key:"centroid",get:function(){return this._getMetrics().centroid}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"_setAABBDirty",value:function(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this);var e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),vt.meshes--}}]),n}(),yt=he.memory,_t=Ae.AABB3(),bt=function(e){m(n,nt);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,n),(r=t.call(this,e,i))._state=new it({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),r._numTriangles=0,r._edgeThreshold=i.edgeThreshold||10,r._aabb=null,r._obb=Ae.OBB3();var s,a=r._state,o=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":a.primitive=o.POINTS,a.primitiveName=i.primitive;break;case"lines":a.primitive=o.LINES,a.primitiveName=i.primitive;break;case"line-loop":a.primitive=o.LINE_LOOP,a.primitiveName=i.primitive;break;case"line-strip":a.primitive=o.LINE_STRIP,a.primitiveName=i.primitive;break;case"triangles":a.primitive=o.TRIANGLES,a.primitiveName=i.primitive;break;case"triangle-strip":a.primitive=o.TRIANGLE_STRIP,a.primitiveName=i.primitive;break;case"triangle-fan":a.primitive=o.TRIANGLE_FAN,a.primitiveName=i.primitive;break;default:r.error("Unsupported value for 'primitive': '"+i.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),a.primitive=o.TRIANGLES,a.primitiveName=i.primitive}if(!i.positions)return r.error("Config expected: positions"),b(r);if(!i.indices)return r.error("Config expected: indices"),b(r);var A=i.positionsDecodeMatrix;if(A);else{var c=pt.getPositionsBounds(i.positions),l=pt.compressPositions(i.positions,c.min,c.max);s=l.quantized,a.positionsDecodeMatrix=l.decodeMatrix,a.positionsBuf=new st(o,o.ARRAY_BUFFER,s,s.length,3,o.STATIC_DRAW),yt.positions+=a.positionsBuf.numItems,Ae.positions3ToAABB3(i.positions,r._aabb),Ae.positions3ToAABB3(s,_t,a.positionsDecodeMatrix),Ae.AABB3ToOBB3(_t,r._obb)}if(i.colors){var u=i.colors.constructor===Float32Array?i.colors:new Float32Array(i.colors);a.colorsBuf=new st(o,o.ARRAY_BUFFER,u,u.length,4,o.STATIC_DRAW),yt.colors+=a.colorsBuf.numItems}if(i.uv){var h=pt.getUVBounds(i.uv),d=pt.compressUVs(i.uv,h.min,h.max),f=d.quantized;a.uvDecodeMatrix=d.decodeMatrix,a.uvBuf=new st(o,o.ARRAY_BUFFER,f,f.length,2,o.STATIC_DRAW),yt.uvs+=a.uvBuf.numItems}if(i.normals){var p=pt.compressNormals(i.normals),v=a.compressGeometry;a.normalsBuf=new st(o,o.ARRAY_BUFFER,p,p.length,3,o.STATIC_DRAW,v),yt.normals+=a.normalsBuf.numItems}var g=i.indices.constructor===Uint32Array||i.indices.constructor===Uint16Array?i.indices:new Uint32Array(i.indices);a.indicesBuf=new st(o,o.ELEMENT_ARRAY_BUFFER,g,g.length,1,o.STATIC_DRAW),yt.indices+=a.indicesBuf.numItems;var m=at(s,g,a.positionsDecodeMatrix,r._edgeThreshold);return r._edgeIndicesBuf=new st(o,o.ELEMENT_ARRAY_BUFFER,m,m.length,1,o.STATIC_DRAW),"triangles"===r._state.primitiveName&&(r._numTriangles=i.indices.length/3),r._buildHash(),yt.meshes++,r}return I(n,[{key:"type",get:function(){return"VBOGeometry"}},{key:"isVBOGeometry",get:function(){return!0}},{key:"_buildHash",value:function(){var e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positionsBuf&&t.push("p"),e.colorsBuf&&t.push("c"),(e.normalsBuf||e.autoVertexNormals)&&t.push("n"),e.uvBuf&&t.push("u"),t.push("cp"),t.push(";"),e.hash=t.join("")}},{key:"_getEdgeIndices",value:function(){return this._edgeIndicesBuf}},{key:"primitive",get:function(){return this._state.primitiveName}},{key:"aabb",get:function(){return this._aabb}},{key:"obb",get:function(){return this._obb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this);var e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),e.destroy(),yt.meshes--}}]),n}(),wt={};function Bt(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(n,r){t.src||(console.error("load3DSGeometry: Parameter expected: src"),r());var i=e.canvas.spinner;i.processes++,ge.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("load3DSGeometry: no data loaded"),i.processes--,r());var s=wt.parse.from3DS(e).edit.objects[0].mesh,a=s.vertices,o=s.uvt,A=s.indices;i.processes--,n(ge.apply(t,{primitive:"triangles",positions:a,normals:null,uv:o,indices:A}))}),(function(e){console.error("load3DSGeometry: "+e),i.processes--,r()}))}))}function Ct(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(n,r){t.src||(console.error("loadOBJGeometry: Parameter expected: src"),r());var i=e.canvas.spinner;i.processes++,ge.loadArraybuffer(t.src,(function(e){e.byteLength||(console.error("loadOBJGeometry: no data loaded"),i.processes--,r());for(var s=wt.parse.fromOBJ(e),a=wt.edit.unwrap(s.i_verts,s.c_verts,3),o=wt.edit.unwrap(s.i_norms,s.c_norms,3),A=wt.edit.unwrap(s.i_uvt,s.c_uvt,2),c=new Int32Array(s.i_verts.length),l=0;l<s.i_verts.length;l++)c[l]=l;i.processes--,n(ge.apply(t,{primitive:"triangles",positions:a,normals:o.length>0?o:null,autoNormals:0===o.length,uv:A,indices:c}))}),(function(e){console.error("loadOBJGeometry: "+e),i.processes--,r()}))}))}function Mt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.ySize||1;n<0&&(console.error("negative ySize not allowed - will invert"),n*=-1);var r=e.zSize||1;r<0&&(console.error("negative zSize not allowed - will invert"),r*=-1);var i=e.center,s=i?i[0]:0,a=i?i[1]:0,o=i?i[2]:0,A=-t+s,c=-n+a,l=-r+o,u=t+s,h=n+a,d=r+o;return ge.apply(e,{positions:[u,h,d,A,h,d,A,c,d,u,c,d,u,h,d,u,c,d,u,c,l,u,h,l,u,h,d,u,h,l,A,h,l,A,h,d,A,h,d,A,h,l,A,c,l,A,c,d,A,c,l,u,c,l,u,c,d,A,c,d,u,c,l,A,c,l,A,h,l,u,h,l],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}function kt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.ySize||1;n<0&&(console.error("negative ySize not allowed - will invert"),n*=-1);var r=e.zSize||1;r<0&&(console.error("negative zSize not allowed - will invert"),r*=-1);var i=e.center,s=i?i[0]:0,a=i?i[1]:0,o=i?i[2]:0,A=-t+s,c=-n+a,l=-r+o,u=t+s,h=n+a,d=r+o;return ge.apply(e,{primitive:"lines",positions:[A,c,l,A,c,d,A,h,l,A,h,d,u,c,l,u,c,d,u,h,l,u,h,d],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]})}function Et(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return kt({id:e.id,center:[(e.aabb[0]+e.aabb[3])/2,(e.aabb[1]+e.aabb[4])/2,(e.aabb[2]+e.aabb[5])/2],xSize:Math.abs(e.aabb[3]-e.aabb[0])/2,ySize:Math.abs(e.aabb[4]-e.aabb[1])/2,zSize:Math.abs(e.aabb[5]-e.aabb[2])/2})}function Ft(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);var n=e.radiusBottom||1;n<0&&(console.error("negative radiusBottom not allowed - will invert"),n*=-1);var r=e.height||1;r<0&&(console.error("negative height not allowed - will invert"),r*=-1);var i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<3&&(i=3);var s=e.heightSegments||1;s<0&&(console.error("negative heightSegments not allowed - will invert"),s*=-1),s<1&&(s=1);var a,o,A,c,l,u,h,d,f,p,v,g=!!e.openEnded,m=e.center,y=m?m[0]:0,_=m?m[1]:0,b=m?m[2]:0,w=r/2,B=r/s,C=2*Math.PI/i,M=1/i,k=(t-n)/s,E=[],F=[],x=[],U=[],I=(90-180*Math.atan(r/(n-t))/Math.PI)/90;for(a=0;a<=s;a++)for(l=t-a*k,u=w-a*B,o=0;o<=i;o++)A=Math.sin(o*C),c=Math.cos(o*C),F.push(l*A),F.push(I),F.push(l*c),x.push(o*M),x.push(1*a/s),E.push(l*A+y),E.push(u+_),E.push(l*c+b);for(a=0;a<s;a++)for(o=0;o<=i;o++)d=(h=a*(i+1)+o)+i,U.push(h),U.push(d),U.push(d+1),U.push(h),U.push(d+1),U.push(h+1);if(!g&&t>0){for(f=E.length/3,F.push(0),F.push(1),F.push(0),x.push(.5),x.push(.5),E.push(0+y),E.push(w+_),E.push(0+b),o=0;o<=i;o++)A=Math.sin(o*C),c=Math.cos(o*C),p=.5*Math.sin(o*C)+.5,v=.5*Math.cos(o*C)+.5,F.push(t*A),F.push(1),F.push(t*c),x.push(p),x.push(v),E.push(t*A+y),E.push(w+_),E.push(t*c+b);for(o=0;o<i;o++)m=f,h=f+1+o,U.push(h),U.push(h+1),U.push(m)}if(!g&&n>0){for(f=E.length/3,F.push(0),F.push(-1),F.push(0),x.push(.5),x.push(.5),E.push(0+y),E.push(0-w+_),E.push(0+b),o=0;o<=i;o++)A=Math.sin(o*C),c=Math.cos(o*C),p=.5*Math.sin(o*C)+.5,v=.5*Math.cos(o*C)+.5,F.push(n*A),F.push(-1),F.push(n*c),x.push(p),x.push(v),E.push(n*A+y),E.push(0-w+_),E.push(n*c+b);for(o=0;o<i;o++)m=f,h=f+1+o,U.push(m),U.push(h+1),U.push(h)}return ge.apply(e,{positions:E,normals:F,uv:x,indices:U})}function xt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);var n=e.divisions||1;n<0&&(console.error("negative divisions not allowed - will invert"),n*=-1),n<1&&(n=1);for(var r=(t=t||10)/(n=n||10),i=t/2,s=[],a=[],o=0,A=0,c=-i;A<=n;A++,c+=r)s.push(-i),s.push(0),s.push(c),s.push(i),s.push(0),s.push(c),s.push(c),s.push(0),s.push(-i),s.push(c),s.push(0),s.push(i),a.push(o++),a.push(o++),a.push(o++),a.push(o++);return ge.apply(e,{primitive:"lines",positions:s,indices:a})}function Ut(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);var r=e.xSegments||1;r<0&&(console.error("negative xSegments not allowed - will invert"),r*=-1),r<1&&(r=1);var i=e.xSegments||1;i<0&&(console.error("negative zSegments not allowed - will invert"),i*=-1),i<1&&(i=1);var s,a,o,A,c,l,u,h=e.center,d=h?h[0]:0,f=h?h[1]:0,p=h?h[2]:0,v=t/2,g=n/2,m=Math.floor(r)||1,y=Math.floor(i)||1,_=m+1,b=y+1,w=t/m,B=n/y,C=new Float32Array(_*b*3),M=new Float32Array(_*b*3),k=new Float32Array(_*b*2),E=0,F=0;for(s=0;s<b;s++){var x=s*B-g;for(a=0;a<_;a++)o=a*w-v,C[E]=o+d,C[E+1]=f,C[E+2]=-x+p,M[E+1]=1,k[F]=a/m,k[F+1]=(y-s)/y,E+=3,F+=2}E=0;var U=new(C.length/3>65535?Uint32Array:Uint16Array)(m*y*6);for(s=0;s<y;s++)for(a=0;a<m;a++)A=a+_*s,c=a+_*(s+1),l=a+1+_*(s+1),u=a+1+_*s,U[E]=u,U[E+1]=c,U[E+2]=A,U[E+3]=u,U[E+4]=l,U[E+5]=c,E+=6;return ge.apply(e,{positions:C,normals:M,uv:k,indices:U})}function It(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.lod||1,n=e.center?e.center[0]:0,r=e.center?e.center[1]:0,i=e.center?e.center[2]:0,s=e.radius||1;s<0&&(console.error("negative radius not allowed - will invert"),s*=-1);var a=e.heightSegments||18;a<0&&(console.error("negative heightSegments not allowed - will invert"),a*=-1),(a=Math.floor(t*a))<18&&(a=18);var o=e.widthSegments||18;o<0&&(console.error("negative widthSegments not allowed - will invert"),o*=-1),(o=Math.floor(t*o))<18&&(o=18);var A,c,l,u,h,d,f,p,v,g,m,y,_,b,w=[],B=[],C=[],M=[];for(A=0;A<=a;A++)for(l=A*Math.PI/a,u=Math.sin(l),h=Math.cos(l),c=0;c<=o;c++)d=2*c*Math.PI/o,f=Math.sin(d),p=Math.cos(d)*u,v=h,g=f*u,m=1-c/o,y=A/a,B.push(p),B.push(v),B.push(g),C.push(m),C.push(y),w.push(n+s*p),w.push(r+s*v),w.push(i+s*g);for(A=0;A<a;A++)for(c=0;c<o;c++)b=(_=A*(o+1)+c)+o+1,M.push(_+1),M.push(b+1),M.push(b),M.push(_+1),M.push(b),M.push(_);return ge.apply(e,{positions:w,normals:B,uv:C,indices:M})}function Tt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.radius||1;t<0&&(console.error("negative radius not allowed - will invert"),t*=-1),t*=.5;var n=e.tube||.3;n<0&&(console.error("negative tube not allowed - will invert"),n*=-1);var r=e.radialSegments||32;r<0&&(console.error("negative radialSegments not allowed - will invert"),r*=-1),r<4&&(r=4);var i=e.tubeSegments||24;i<0&&(console.error("negative tubeSegments not allowed - will invert"),i*=-1),i<4&&(i=4);var s=e.arc||2*Math.PI;s<0&&(console.warn("negative arc not allowed - will invert"),s*=-1),s>360&&(s=360);var a,o,A,c,l,u,h,d,f,p,v,g,m=e.center,y=m?m[0]:0,_=m?m[1]:0,b=m?m[2]:0,w=[],B=[],C=[],M=[];for(d=0;d<=i;d++)for(h=0;h<=r;h++)a=h/r*s,o=.785398+d/i*Math.PI*2,y=t*Math.cos(a),_=t*Math.sin(a),A=(t+n*Math.cos(o))*Math.cos(a),c=(t+n*Math.cos(o))*Math.sin(a),l=n*Math.sin(o),w.push(A+y),w.push(c+_),w.push(l+b),C.push(1-h/r),C.push(d/i),u=Ae.normalizeVec3(Ae.subVec3([A,c,l],[y,_,b],[]),[]),B.push(u[0]),B.push(u[1]),B.push(u[2]);for(d=1;d<=i;d++)for(h=1;h<=r;h++)f=(r+1)*d+h-1,p=(r+1)*(d-1)+h-1,v=(r+1)*(d-1)+h,g=(r+1)*d+h,M.push(f),M.push(p),M.push(v),M.push(v),M.push(g),M.push(f);return ge.apply(e,{positions:w,normals:B,uv:C,indices:M})}wt.load=function(e,t){var n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=function(e){t(e.target.response)},n.send()},wt.save=function(e,t){var n="data:application/octet-stream;base64,"+btoa(wt.parse._buffToStr(e));window.location.href=n},wt.clone=function(e){return JSON.parse(JSON.stringify(e))},wt.bin={},wt.bin.f=new Float32Array(1),wt.bin.fb=new Uint8Array(wt.bin.f.buffer),wt.bin.rf=function(e,t){for(var n=wt.bin.f,r=wt.bin.fb,i=0;i<4;i++)r[i]=e[t+i];return n[0]},wt.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},wt.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},wt.bin.rASCII0=function(e,t){for(var n="";0!=e[t];)n+=String.fromCharCode(e[t++]);return n},wt.bin.wf=function(e,t,n){new Float32Array(e.buffer,t,1)[0]=n},wt.bin.wsl=function(e,t,n){e[t]=n,e[t+1]=n>>8},wt.bin.wil=function(e,t,n){e[t]=n,e[t+1]=n>>8,e[t+2]=n>>16,e[t+3]},wt.parse={},wt.parse._buffToStr=function(e){for(var t=new Uint8Array(e),n="",r=0;r<t.length;r++)n=n.concat(String.fromCharCode(t[r]));return n},wt.parse._strToBuff=function(e){for(var t=new ArrayBuffer(e.length),n=new Uint8Array(t),r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return t},wt.parse._readLine=function(e,t){for(var n="";10!=e[t];)n+=String.fromCharCode(e[t++]);return n},wt.parse.fromJSON=function(e){return JSON.parse(wt.parse._buffToStr(e))},wt.parse.toJSON=function(e){var t=JSON.stringify(e);return wt.parse._strToBuff(t)},wt.parse.fromOBJ=function(e){for(var t={groups:{},c_verts:[],c_uvt:[],c_norms:[],i_verts:[],i_uvt:[],i_norms:[]},n={from:0,to:0},r=0,i=new Uint8Array(e);r<i.length;){var s=wt.parse._readLine(i,r);r+=s.length+1;var a=(s=(s=s.replace(/ +(?= )/g,"")).replace(/(^\s+|\s+$)/g,"")).split(" ");if("g"==a[0]&&(n.to=t.i_verts.length,null==t.groups[a[1]]&&(t.groups[a[1]]={from:t.i_verts.length,to:0}),n=t.groups[a[1]]),"v"==a[0]){var o=parseFloat(a[1]),A=parseFloat(a[2]),c=parseFloat(a[3]);t.c_verts.push(o,A,c)}if("vt"==a[0]){o=parseFloat(a[1]),A=1-parseFloat(a[2]);t.c_uvt.push(o,A)}if("vn"==a[0]){o=parseFloat(a[1]),A=parseFloat(a[2]),c=parseFloat(a[3]);t.c_norms.push(o,A,c)}if("f"==a[0]){var l=a[1].split("/"),u=a[2].split("/"),h=a[3].split("/"),d=parseInt(l[0])-1,f=parseInt(u[0])-1,p=parseInt(h[0])-1,v=parseInt(l[1])-1,g=parseInt(u[1])-1,m=parseInt(h[1])-1,y=parseInt(l[2])-1,_=parseInt(u[2])-1,b=parseInt(h[2])-1,w=t.c_verts.length/3,B=t.c_uvt.length/2,C=t.c_norms.length/3;if(d<0&&(d=w+d+1),f<0&&(f=w+f+1),p<0&&(p=w+p+1),v<0&&(v=B+v+1),g<0&&(g=B+g+1),m<0&&(m=B+m+1),y<0&&(y=C+y+1),_<0&&(_=C+_+1),b<0&&(b=C+b+1),t.i_verts.push(d,f,p),t.i_uvt.push(v,g,m),t.i_norms.push(y,_,b),5==a.length){var M=a[4].split("/"),k=parseInt(M[0])-1,E=parseInt(M[1])-1,F=parseInt(M[2])-1;k<0&&(k=w+k+1),E<0&&(E=B+E+1),F<0&&(F=C+F+1),t.i_verts.push(d,p,k),t.i_uvt.push(v,m,E),t.i_norms.push(y,b,F)}}}return n.to=t.i_verts.length,t},wt.parse.fromMD2=function(e){e=new Uint8Array(e);var t={},n={};n.ident=wt.bin.ril(e,0),n.version=wt.bin.ril(e,4),n.skinwidth=wt.bin.ril(e,8),n.skinheight=wt.bin.ril(e,12),n.framesize=wt.bin.ril(e,16),n.num_skins=wt.bin.ril(e,20),n.num_vertices=wt.bin.ril(e,24),n.num_st=wt.bin.ril(e,28),n.num_tris=wt.bin.ril(e,32),n.num_glcmds=wt.bin.ril(e,36),n.num_frames=wt.bin.ril(e,40),n.offset_skins=wt.bin.ril(e,44),n.offset_st=wt.bin.ril(e,48),n.offset_tris=wt.bin.ril(e,52),n.offset_frames=wt.bin.ril(e,56),n.offset_glcmds=wt.bin.ril(e,60),n.offset_end=wt.bin.ril(e,64);var r=n.offset_st;t.c_uvt=[];for(var i=0;i<n.num_st;i++){var s=wt.bin.rsl(e,r)/n.skinwidth,a=wt.bin.rsl(e,r+2)/n.skinheight;t.c_uvt.push(s,a),r+=4}r=n.offset_tris;var o=[],A=[];t.i_verts=o,t.i_uvt=A;for(i=0;i<n.num_tris;i++)o.push(wt.bin.rsl(e,r),wt.bin.rsl(e,r+2),wt.bin.rsl(e,r+4)),A.push(wt.bin.rsl(e,r+6),wt.bin.rsl(e,r+8),wt.bin.rsl(e,r+10)),r+=12;r=n.offset_skins;t.skins=[];for(i=0;i<n.num_skins;i++)t.skins.push(wt.bin.rASCII0(e,r)),r+=64;r=n.offset_frames;t.frames=[];var c=wt.parse.fromMD2._normals;for(i=0;i<n.num_frames;i++){var l={},u=wt.bin.rf(e,r),h=wt.bin.rf(e,r+4),d=wt.bin.rf(e,r+8);r+=12;var f=wt.bin.rf(e,r),p=wt.bin.rf(e,r+4),v=wt.bin.rf(e,r+8);r+=12,l.name=wt.bin.rASCII0(e,r),r+=16,l.verts=[],l.norms=[];for(var g=0;g<n.num_vertices;g++)l.verts.push(e[r]*u+f,e[r+1]*h+p,e[r+2]*d+v),l.norms.push(c[3*e[r+3]],c[3*e[r+3]+1],c[3*e[r+3]+2]),r+=4;t.frames.push(l)}return t},wt.parse.fromMD2._normals=[-.525731,0,.850651,-.442863,.238856,.864188,-.295242,0,.955423,-.309017,.5,.809017,-.16246,.262866,.951056,0,0,1,0,.850651,.525731,-.147621,.716567,.681718,.147621,.716567,.681718,0,.525731,.850651,.309017,.5,.809017,.525731,0,.850651,.295242,0,.955423,.442863,.238856,.864188,.16246,.262866,.951056,-.681718,.147621,.716567,-.809017,.309017,.5,-.587785,.425325,.688191,-.850651,.525731,0,-.864188,.442863,.238856,-.716567,.681718,.147621,-.688191,.587785,.425325,-.5,.809017,.309017,-.238856,.864188,.442863,-.425325,.688191,.587785,-.716567,.681718,-.147621,-.5,.809017,-.309017,-.525731,.850651,0,0,.850651,-.525731,-.238856,.864188,-.442863,0,.955423,-.295242,-.262866,.951056,-.16246,0,1,0,0,.955423,.295242,-.262866,.951056,.16246,.238856,.864188,.442863,.262866,.951056,.16246,.5,.809017,.309017,.238856,.864188,-.442863,.262866,.951056,-.16246,.5,.809017,-.309017,.850651,.525731,0,.716567,.681718,.147621,.716567,.681718,-.147621,.525731,.850651,0,.425325,.688191,.587785,.864188,.442863,.238856,.688191,.587785,.425325,.809017,.309017,.5,.681718,.147621,.716567,.587785,.425325,.688191,.955423,.295242,0,1,0,0,.951056,.16246,.262866,.850651,-.525731,0,.955423,-.295242,0,.864188,-.442863,.238856,.951056,-.16246,.262866,.809017,-.309017,.5,.681718,-.147621,.716567,.850651,0,.525731,.864188,.442863,-.238856,.809017,.309017,-.5,.951056,.16246,-.262866,.525731,0,-.850651,.681718,.147621,-.716567,.681718,-.147621,-.716567,.850651,0,-.525731,.809017,-.309017,-.5,.864188,-.442863,-.238856,.951056,-.16246,-.262866,.147621,.716567,-.681718,.309017,.5,-.809017,.425325,.688191,-.587785,.442863,.238856,-.864188,.587785,.425325,-.688191,.688191,.587785,-.425325,-.147621,.716567,-.681718,-.309017,.5,-.809017,0,.525731,-.850651,-.525731,0,-.850651,-.442863,.238856,-.864188,-.295242,0,-.955423,-.16246,.262866,-.951056,0,0,-1,.295242,0,-.955423,.16246,.262866,-.951056,-.442863,-.238856,-.864188,-.309017,-.5,-.809017,-.16246,-.262866,-.951056,0,-.850651,-.525731,-.147621,-.716567,-.681718,.147621,-.716567,-.681718,0,-.525731,-.850651,.309017,-.5,-.809017,.442863,-.238856,-.864188,.16246,-.262866,-.951056,.238856,-.864188,-.442863,.5,-.809017,-.309017,.425325,-.688191,-.587785,.716567,-.681718,-.147621,.688191,-.587785,-.425325,.587785,-.425325,-.688191,0,-.955423,-.295242,0,-1,0,.262866,-.951056,-.16246,0,-.850651,.525731,0,-.955423,.295242,.238856,-.864188,.442863,.262866,-.951056,.16246,.5,-.809017,.309017,.716567,-.681718,.147621,.525731,-.850651,0,-.238856,-.864188,-.442863,-.5,-.809017,-.309017,-.262866,-.951056,-.16246,-.850651,-.525731,0,-.716567,-.681718,-.147621,-.716567,-.681718,.147621,-.525731,-.850651,0,-.5,-.809017,.309017,-.238856,-.864188,.442863,-.262866,-.951056,.16246,-.864188,-.442863,.238856,-.809017,-.309017,.5,-.688191,-.587785,.425325,-.681718,-.147621,.716567,-.442863,-.238856,.864188,-.587785,-.425325,.688191,-.309017,-.5,.809017,-.147621,-.716567,.681718,-.425325,-.688191,.587785,-.16246,-.262866,.951056,.442863,-.238856,.864188,.16246,-.262866,.951056,.309017,-.5,.809017,.147621,-.716567,.681718,0,-.525731,.850651,.425325,-.688191,.587785,.587785,-.425325,.688191,.688191,-.587785,.425325,-.955423,.295242,0,-.951056,.16246,.262866,-1,0,0,-.850651,0,.525731,-.955423,-.295242,0,-.951056,-.16246,.262866,-.864188,.442863,-.238856,-.951056,.16246,-.262866,-.809017,.309017,-.5,-.864188,-.442863,-.238856,-.951056,-.16246,-.262866,-.809017,-.309017,-.5,-.681718,.147621,-.716567,-.681718,-.147621,-.716567,-.850651,0,-.525731,-.688191,.587785,-.425325,-.587785,.425325,-.688191,-.425325,.688191,-.587785,-.425325,-.688191,-.587785,-.587785,-.425325,-.688191,-.688191,-.587785,-.425325],wt.parse.fromCollada=function(e){var t=wt.parse._buffToStr(e),n=(new DOMParser).parseFromString(t,"text/xml"),r={},i=(n=n.childNodes[0]).getElementsByTagName("asset")[0],s=n.getElementsByTagName("library_geometries")[0],a=n.getElementsByTagName("library_images")[0],o=n.getElementsByTagName("library_materials")[0],A=n.getElementsByTagName("library_effects")[0];return i&&(r.asset=wt.parse.fromCollada._asset(i)),s&&(r.geometries=wt.parse.fromCollada._libGeometries(s)),a&&(r.images=wt.parse.fromCollada._libImages(a)),o&&(r.materials=wt.parse.fromCollada._libMaterials(o)),A&&(r.effects=wt.parse.fromCollada._libEffects(A)),r},wt.parse.fromCollada._asset=function(e){return{created:e.getElementsByTagName("created")[0].textContent,modified:e.getElementsByTagName("modified")[0].textContent,up_axis:e.getElementsByTagName("up_axis")[0].textContent}},wt.parse.fromCollada._libGeometries=function(e){e=e.getElementsByTagName("geometry");for(var t=[],n=0;n<e.length;n++){var r=e[n],i=wt.parse.fromCollada._getMesh(r.getElementsByTagName("mesh")[0]);t.push(i)}return t},wt.parse.fromCollada._getMesh=function(e){for(var t={},n=e.getElementsByTagName("source"),r=t.sources={},i=0;i<n.length;i++){for(var s=n[i].getElementsByTagName("float_array")[0].textContent.split(" "),a=s.length-(""==s[s.length-1]?1:0),o=new Array(a),A=0;A<a;A++)o[A]=parseFloat(s[A]);r[n[i].getAttribute("id")]=o}t.triangles=[];var c=e.getElementsByTagName("triangles");if(null==c)return t;for(i=0;i<c.length;i++){var l={},u=c[i];l.material=u.getAttribute("material");var h=u.getElementsByTagName("input"),d=[];for(A=0;A<h.length;A++){var f=h[A];o=[];d[parseInt(f.getAttribute("offset"))]=o;var p=f.getAttribute("semantic");l["s_"+p]="VERTEX"==p?e.getElementsByTagName("vertices")[0].getElementsByTagName("input")[0].getAttribute("source").substring(1):f.getAttribute("source").substring(1),l["i_"+p]=o,r[l["s_"+p]]}var v=u.getElementsByTagName("p")[0].textContent.split(" "),g=3*Math.floor(v.length/3);for(A=0;A<g;A++)d[A%h.length].push(parseInt(v[A]));t.triangles.push(l)}return t},wt.parse.fromCollada._libImages=function(e){e=e.getElementsByTagName("image");for(var t={},n=0;n<e.length;n++)t[e[n].getAttribute("id")]=e[n].getElementsByTagName("init_from")[0].textContent;return t},wt.parse.fromCollada._libMaterials=function(e){e=e.getElementsByTagName("material");for(var t={},n=0;n<e.length;n++)t[e[n].getAttribute("name")]=e[n].getElementsByTagName("instance_effect")[0].getAttribute("url").substring(1);return t},wt.parse.fromCollada._libEffects=function(e){e=e.getElementsByTagName("effect");for(var t={},n=0;n<e.length;n++){for(var r={},i=e[n].getElementsByTagName("newparam"),s=0;s<i.length;s++){var a=i[s].getElementsByTagName("surface")[0];a&&(r.surface=a.getElementsByTagName("init_from")[0].textContent)}t[e[n].getAttribute("id")]=r}return t},wt.parse.from3DS=function(e){e=new Uint8Array(e);var t={};if(19789!=wt.bin.rsl(e,0))return null;for(var n=wt.bin.ril(e,2),r=6;r<n;){var i=wt.bin.rsl(e,r),s=wt.bin.ril(e,r+2);15677==i&&(t.edit=wt.parse.from3DS._edit3ds(e,r,s)),45056==i&&(t.keyf=wt.parse.from3DS._keyf3ds(e,r,s)),r+=s}return t},wt.parse.from3DS._edit3ds=function(e,t,n){for(var r={},i=t+6;i<t+n;){var s=wt.bin.rsl(e,i),a=wt.bin.ril(e,i+2);16384==s&&(null==r.objects&&(r.objects=[]),r.objects.push(wt.parse.from3DS._edit_object(e,i,a))),i+=a}return r},wt.parse.from3DS._keyf3ds=function(e,t,n){for(var r={},i=t+6;i<t+n;){var s=wt.bin.rsl(e,i),a=wt.bin.ril(e,i+2);45058==s&&(null==r.desc&&(r.desc=[]),r.desc.push(wt.parse.from3DS._keyf_objdes(e,i,a))),i+=a}return r},wt.parse.from3DS._keyf_objdes=function(e,t,n){for(var r={},i=t+6;i<t+n;){var s=wt.bin.rsl(e,i),a=wt.bin.ril(e,i+2);45072==s&&(r.hierarchy=wt.parse.from3DS._keyf_objhierarch(e,i,a)),45073==s&&(r.dummy_name=wt.bin.rASCII0(e,i+6)),i+=a}return r},wt.parse.from3DS._keyf_objhierarch=function(e,t,n){var r={},i=t+6;return r.name=wt.bin.rASCII0(e,i),i+=r.name.length+1,r.hierarchy=wt.bin.rsl(e,i+4),r},wt.parse.from3DS._edit_object=function(e,t,n){var r={},i=t+6;for(r.name=wt.bin.rASCII0(e,i),i+=r.name.length+1;i<t+n;){var s=wt.bin.rsl(e,i),a=wt.bin.ril(e,i+2);16640==s&&(r.mesh=wt.parse.from3DS._obj_trimesh(e,i,a)),i+=a}return r},wt.parse.from3DS._obj_trimesh=function(e,t,n){for(var r={},i=t+6;i<t+n;){var s=wt.bin.rsl(e,i),a=wt.bin.ril(e,i+2);16656==s&&(r.vertices=wt.parse.from3DS._tri_vertexl(e,i,a)),16672==s&&(r.indices=wt.parse.from3DS._tri_facel1(e,i,a)),16704==s&&(r.uvt=wt.parse.from3DS._tri_mappingcoors(e,i,a)),16736==s&&(r.local=wt.parse.from3DS._tri_local(e,i,a)),i+=a}return r},wt.parse.from3DS._tri_vertexl=function(e,t,n){var r=[],i=t+6,s=wt.bin.rsl(e,i);i+=2;for(var a=0;a<s;a++)r.push(wt.bin.rf(e,i)),r.push(wt.bin.rf(e,i+4)),r.push(wt.bin.rf(e,i+8)),i+=12;return r},wt.parse.from3DS._tri_facel1=function(e,t,n){var r=[],i=t+6,s=wt.bin.rsl(e,i);i+=2;for(var a=0;a<s;a++)r.push(wt.bin.rsl(e,i)),r.push(wt.bin.rsl(e,i+2)),r.push(wt.bin.rsl(e,i+4)),i+=8;return r},wt.parse.from3DS._tri_mappingcoors=function(e,t,n){var r=[],i=t+6,s=wt.bin.rsl(e,i);i+=2;for(var a=0;a<s;a++)r.push(wt.bin.rf(e,i)),r.push(1-wt.bin.rf(e,i+4)),i+=8;return r},wt.parse.from3DS._tri_local=function(e,t,n){var r={},i=t+6;return r.X=[wt.bin.rf(e,i),wt.bin.rf(e,i+4),wt.bin.rf(e,i+8)],i+=12,r.Y=[wt.bin.rf(e,i),wt.bin.rf(e,i+4),wt.bin.rf(e,i+8)],i+=12,r.Z=[wt.bin.rf(e,i),wt.bin.rf(e,i+4),wt.bin.rf(e,i+8)],i+=12,r.C=[wt.bin.rf(e,i),wt.bin.rf(e,i+4),wt.bin.rf(e,i+8)],i+=12,r},wt.parse.fromBIV=function(e){e=new Uint8Array(e);var t={},n={};return n.id=wt.bin.ril(e,0),n.verS=wt.bin.ril(e,4),n.texS=wt.bin.ril(e,8),n.indS=wt.bin.ril(e,12),n.verO=wt.bin.ril(e,16),n.verL=wt.bin.ril(e,20),n.texO=wt.bin.ril(e,24),n.texL=wt.bin.ril(e,28),n.indO=wt.bin.ril(e,32),n.indL=wt.bin.ril(e,36),0!=n.verO&&(t.vertices=wt.parse.fromBIV._readFloats(e,n.verO,n.verL)),0!=n.texO&&(t.uvt=wt.parse.fromBIV._readFloats(e,n.texO,n.texL)),0!=n.indO&&(t.indices=wt.parse.fromBIV._readInts(e,n.indO,n.indL,n.indS)),t},wt.parse.toBIV=function(e){for(var t=0,n=0;n<e.indices.length;n++)t=Math.max(t,e.indices[n]);var r=32;t<=65535&&(r=16);var i=40;e.vertices&&(i+=4*e.vertices.length),e.uvt&&(i+=4*e.uvt.length),e.indices&&(i+=e.indices.length*r/8);var s=new Uint8Array(i);wt.bin.wil(s,0,1769365870),wt.bin.wil(s,4,32),wt.bin.wil(s,8,32),wt.bin.wil(s,12,r);var a=40;return e.vertices&&(wt.bin.wil(s,16,a),wt.bin.wil(s,20,4*e.vertices.length),wt.parse.fromBIV._writeFloats(s,a,e.vertices),a+=4*e.vertices.length),e.uvt&&(wt.bin.wil(s,24,a),wt.bin.wil(s,28,4*e.uvt.length),wt.parse.fromBIV._writeFloats(s,a,e.uvt),a+=4*e.uvt.length),e.indices&&(wt.bin.wil(s,32,a),wt.bin.wil(s,36,4*e.indices.length),wt.parse.fromBIV._writeInts(s,a,e.indices,r)),s.buffer},wt.parse.fromBIV._readFloats=function(e,t,n){for(var r=[],i=0;i<n/4;i++)r.push(wt.bin.rf(e,t+4*i));return r},wt.parse.fromBIV._writeFloats=function(e,t,n){for(var r=0;r<n.length;r++)wt.bin.wf(e,t+4*r,n[r])},wt.parse.fromBIV._readInts=function(e,t,n,r){for(var i=[],s=0;s<n/4;s++)16==r&&i.push(wt.bin.rsl(e,t+2*s)),32==r&&i.push(wt.bin.ril(e,t+4*s));return i},wt.parse.fromBIV._writeInts=function(e,t,n,r){for(var i=0;i<n.length;i++)16==r&&wt.bin.wsl(e,t+2*i,n[i]),32==r&&wt.bin.wil(e,t+4*i,n[i])},wt.gen={},wt.gen.Plane=function(e,t,n,r){n||(n=1),r||(r=1);for(var i={verts:[],inds:[],uvt:[]},s=e+1,a=t+1,o=0;o<a;o++)for(var A=0;A<s;A++){var c=A*(2/e)-1,l=o*(2/t)-1;i.verts.push(c,l,0),i.uvt.push(n*A/e,r*o/t),o<t&&A<e&&i.inds.push(o*s+A,o*s+A+1,(o+1)*s+A,o*s+A+1,(o+1)*s+A,(o+1)*s+A+1)}return i},wt.gen.Cube=function(){return{verts:[-1,1,-1,1,1,-1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,1,-1,-1,1,1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,-1,1,1,1,1,1,-1,1,-1,1,1,-1,-1,-1,1,-1,1,1,-1,-1,1,1,1,1,1,-1,-1,-1,1,-1,-1,-1,-1,1,1,-1,1],inds:[0,1,2,1,2,3,4,5,6,5,6,7,8,9,10,9,10,11,12,13,14,13,14,15,16,17,18,17,18,19,20,21,22,21,22,23],uvt:[1/4,1/4,.5,1/4,1/4,.5,.5,.5,1,1/4,3/4,1/4,1,.5,3/4,.5,0,1/4,1/4,1/4,0,.5,1/4,.5,3/4,1/4,.5,1/4,3/4,.5,.5,.5,1/4,1/4,.5,1/4,1/4,0,.5,0,1/4,.5,.5,.5,1/4,3/4,.5,3/4]}},wt.gen.Sphere=function(e,t){for(var n={verts:[],inds:[],uvt:[]},r=e+1,i=t+1,s=0;s<i;s++)for(var a=0;a<r;a++){var o=-Math.PI/2+s*Math.PI/t,A=2*a*Math.PI/e,c=Math.cos(o)*Math.cos(A),l=Math.sin(o),u=Math.cos(o)*Math.sin(A);n.verts.push(c,l,u),n.uvt.push(a/e,s/t),s<t&&a<e&&n.inds.push(r*s+a,r*s+a+1,r*(s+1)+a,r*s+a+1,r*(s+1)+a,r*(s+1)+a+1)}return n},wt.mat={},wt.mat.scale=function(e,t,n){return[e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1]},wt.mat.translate=function(e,t,n){return[1,0,0,0,0,1,0,0,0,0,1,0,e,t,n,1]},wt.mat.rotateDeg=function(e,t,n){var r=Math.PI/180;return wt.mat.rotate(e*r,t*r,n*r)},wt.mat.rotate=function(e,t,n){var r=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],i=e,s=t,a=n,o=Math.cos(i),A=Math.cos(s),c=Math.cos(a),l=Math.sin(i),u=Math.sin(s),h=Math.sin(a);return r[0]=A*c,r[1]=-A*h,r[2]=u,r[4]=o*h+l*u*c,r[5]=o*c-l*u*h,r[6]=-l*A,r[8]=l*h-o*u*c,r[9]=l*c+o*u*h,r[10]=o*A,r},wt.edit={},wt.edit.interpolate=function(e,t,n,r){for(var i=0;i<e.length;i++)n[i]=e[i]+r*(t[i]-e[i])},wt.edit.transform=function(e,t){for(var n=0;n<e.length;n+=3){var r=e[n],i=e[n+1],s=e[n+2];e[n+0]=t[0]*r+t[4]*i+t[8]*s+t[12],e[n+1]=t[1]*r+t[5]*i+t[9]*s+t[13],e[n+2]=t[2]*r+t[6]*i+t[10]*s+t[14]}},wt.edit.unwrap=function(e,t,n){for(var r=new Array(Math.floor(e.length/3)*n),i=0;i<e.length;i++)for(var s=0;s<n;s++)r[i*n+s]=t[e[i]*n+s];return r},wt.edit.remap=function(e,t,n,r){for(var i=new Array(n.length),s=0;s<e.length;s++)for(var a=0;a<r;a++)i[t[s]*r+a]=n[e[s]*r+a];return i},wt.utils={},wt.utils.getAABB=function(e){var t,n,r,i,s,a;i=s=a=-(t=n=r=999999999);for(var o=0;o<e.length;o+=3){var A=e[o+0],c=e[o+1],l=e[o+2];A<t&&(t=A),A>i&&(i=A),c<n&&(n=c),c>s&&(s=c),l<r&&(r=l),c>a&&(a=l)}return{min:{x:t,y:n,z:r},max:{x:i,y:s,z:a}}};var Pt={" ":{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]]}};function St(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.origin||[0,0,0],n=t[0],r=t[1],i=t[2],s=e.size||1,a=[],o=[],A=e.text;ge.isNumeric(A)&&(A=""+A);for(var c,l,u,h,d,f,p,v,g,m=(A||"").split("\n"),y=0,_=0,b=.04,w=0;w<m.length;w++){c=0,u=(l=m[w]).length;for(var B=0;B<u;B++)if(h=Pt[l.charAt(B)]){d=1,f=-1,p=-1,v=h.points.length;for(var C=0;C<v;C++)-1!==(g=h.points[C])[0]||-1!==g[1]?(a.push(c+g[0]*s*b+n),a.push(_+g[1]*s*b+r),a.push(0+i),-1===f?f=y:(-1===p||(f=p),p=y),y++,d?d=!1:(o.push(f),o.push(p))):d=1;c+=h.width*b*s}_-=35*b*s}return ge.apply(e,{primitive:"lines",positions:a,indices:o})}function Dt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e.points.length%3!=0)throw"Size of points array for given polyline should be divisible by 3";var t=e.points.length/3;if(t<2)throw"There should be at least 2 points to create a polyline";for(var n=[],r=0;r<t-1;r++)n.push(r),n.push(r+1);return ge.apply(e,{primitive:"lines",positions:e.points,indices:n})}function Qt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.curve.getPoints(e.divisions).map((function(e){return p(e)})).flat();return Dt({id:e.id,points:t})}function Rt(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(3!==e.startPoint.length)throw"Start point should contain 3 elements in array: x, y and z";if(3!==e.endPoint.length)throw"End point should contain 3 elements in array: x, y and z";var t=[],n=[],r=e.startPoint[0],i=e.startPoint[1],s=e.startPoint[2],a=e.endPoint[0],o=e.endPoint[1],A=e.endPoint[2],c=Math.sqrt(Math.pow(a-r,2)+Math.pow(o-i,2)+Math.pow(A-s,2)),l=[(a-r)/c,(o-i)/c,(A-s)/c];if(e.pattern){var u=e.pattern.length,h=!1,d=0,f=0,p=0,v=[r,i,s],g=e.pattern[f];for(n.push(v[0],v[1],v[2]);g<=c-d;){var m=[l[0]*g,l[1]*g,l[2]*g],y=[v[0]+m[0],v[1]+m[1],v[2]+m[2]];n.push(y[0],y[1],y[2]),h||(t.push(p),t.push(p+1)),h=!h,p+=1,v=y,(f+=1)>=u&&(f=0),d+=g,g=e.pattern[f]}e.extendToEnd&&(n.push(a,o,A),t.push(t.length-2),t.push(t.length-1))}else t.push(0),t.push(1),n.push(r,i,s,a,o,A);return ge.apply(e,{primitive:"lines",positions:n,indices:t})}var Ot=Ae.vec4(4),Vt=Ae.vec4(),Lt=Ae.vec4(),Ht=Ae.vec3([1,0,0]),Nt=Ae.vec3([0,1,0]),Gt=Ae.vec3([0,0,1]),jt=Ae.vec3(3),Wt=Ae.vec3(3),zt=Ae.identityMat4(),Xt=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(x(this,n),(r=t.call(this,e,i))._parentNode=null,r._children=[],r._aabb=null,r._aabbDirty=!0,r.scene._aabbDirty=!0,r._numTriangles=0,r._scale=Ae.vec3(),r._quaternion=Ae.identityQuaternion(),r._rotation=Ae.vec3(),r._position=Ae.vec3(),r._offset=Ae.vec3(),r._localMatrix=Ae.identityMat4(),r._worldMatrix=Ae.identityMat4(),r._localMatrixDirty=!0,r._worldMatrixDirty=!0,i.matrix?r.matrix=i.matrix:(r.scale=i.scale,r.position=i.position,i.quaternion||(r.rotation=i.rotation)),r._isModel=i.isModel,r._isModel&&r.scene._registerModel(w(r)),r._isObject=i.isObject,r._isObject&&r.scene._registerObject(w(r)),r.origin=i.origin,r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.colorize=i.colorize,r.opacity=i.opacity,r.offset=i.offset,i.children)for(var s=i.children,a=0,o=s.length;a<o;a++)r.addChild(s[a],i.inheritStates);if(i.parentId){var A=r.scene.components[i.parentId];A?A.isNode?A.addChild(w(r)):r.error("Parent is not a Node: '"+i.parentId+"'"):r.error("Parent not found: '"+i.parentId+"'")}else i.parent&&(i.parent.isNode||r.error("Parent is not a Node"),i.parent.addChild(w(r)));return r}return I(n,[{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return this._isObject}},{key:"aabb",get:function(){return this._aabbDirty&&this._updateAABB(),this._aabb}},{key:"origin",get:function(){return this._origin},set:function(e){e?(this._origin||(this._origin=Ae.vec3()),this._origin.set(e)):this._origin&&(this._origin=null);for(var t=0,n=this._children.length;t<n;t++)this._children[t].origin=e;this.glRedraw()}},{key:"rtcCenter",get:function(){return this.origin},set:function(e){this.origin=e}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"visible",get:function(){return this._visible},set:function(e){e=!1!==e,this._visible=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].visible=e;this._isObject&&this.scene._objectVisibilityUpdated(this,e)}},{key:"xrayed",get:function(){return this._xrayed},set:function(e){e=!!e,this._xrayed=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].xrayed=e;this._isObject&&this.scene._objectXRayedUpdated(this,e)}},{key:"highlighted",get:function(){return this._highlighted},set:function(e){e=!!e,this._highlighted=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].highlighted=e;this._isObject&&this.scene._objectHighlightedUpdated(this,e)}},{key:"selected",get:function(){return this._selected},set:function(e){e=!!e,this._selected=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].selected=e;this._isObject&&this.scene._objectSelectedUpdated(this,e)}},{key:"edges",get:function(){return this._edges},set:function(e){e=!!e,this._edges=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].edges=e}},{key:"culled",get:function(){return this._culled},set:function(e){e=!!e,this._culled=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].culled=e}},{key:"clippable",get:function(){return this._clippable},set:function(e){e=!1!==e,this._clippable=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].clippable=e}},{key:"collidable",get:function(){return this._collidable},set:function(e){e=!1!==e,this._collidable=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].collidable=e}},{key:"pickable",get:function(){return this._pickable},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].pickable=e}},{key:"colorize",get:function(){return this._colorize.slice(0,3)},set:function(e){var t=this._colorize;t||((t=this._colorize=new Float32Array(4))[3]=1),e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1);for(var n=0,r=this._children.length;n<r;n++)this._children[n].colorize=t;if(this._isObject){var i=!!e;this.scene._objectColorizeUpdated(this,i)}}},{key:"opacity",get:function(){return this._colorize[3]},set:function(e){var t=this._colorize;t||((t=this._colorize=new Float32Array(4))[0]=1,t[1]=1,t[2]=1),t[3]=null!=e?e:1;for(var n=0,r=this._children.length;n<r;n++)this._children[n].opacity=e;if(this._isObject){var i=null!=e;this.scene._objectOpacityUpdated(this,i)}}},{key:"castsShadow",get:function(){return this._castsShadow},set:function(e){e=!!e,this._castsShadow=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].castsShadow=e}},{key:"receivesShadow",get:function(){return this._receivesShadow},set:function(e){e=!!e,this._receivesShadow=e;for(var t=0,n=this._children.length;t<n;t++)this._children[t].receivesShadow=e}},{key:"saoEnabled",get:function(){return!1}},{key:"offset",get:function(){return this._offset},set:function(e){e?(this._offset[0]=e[0],this._offset[1]=e[1],this._offset[2]=e[2]):(this._offset[0]=0,this._offset[1]=0,this._offset[2]=0);for(var t=0,n=this._children.length;t<n;t++)this._children[t].offset=this._offset;this._isObject&&this.scene._objectOffsetUpdated(this,e)}},{key:"isNode",get:function(){return!0}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}},{key:"_setWorldMatrixDirty",value:function(){this._worldMatrixDirty=!0;for(var e=0,t=this._children.length;e<t;e++)this._children[e]._setWorldMatrixDirty()}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentNode)Ae.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(var t=0,n=e.length;t<n;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}},{key:"_setSubtreeAABBsDirty",value:function(e){if(e._aabbDirty=!0,e._children)for(var t=0,n=e._children.length;t<n;t++)this._setSubtreeAABBsDirty(e._children[t])}},{key:"_setAABBDirty",value:function(){if(this._setSubtreeAABBsDirty(this),this.collidable)for(var e=this;e;e=e._parentNode)e._aabbDirty=!0}},{key:"_updateAABB",value:function(){if(this.scene._aabbDirty=!0,this._aabb||(this._aabb=Ae.AABB3()),this._buildAABB)this._buildAABB(this.worldMatrix,this._aabb);else{var e;Ae.collapseAABB3(this._aabb);for(var t=0,n=this._children.length;t<n;t++)(e=this._children[t]).collidable&&Ae.expandAABB3(this._aabb,e.aabb)}this._aabbDirty=!1}},{key:"addChild",value:function(e,t){if(ge.isNumeric(e)||ge.isString(e)){var n=e;if(!(e=this.scene.component[n]))return void this.warn("Component not found: "+ge.inQuotes(n));if(!e.isNode&&!e.isMesh)return void this.error("Not a Node or Mesh: "+n)}else{if(!e.isNode&&!e.isMesh)return void this.error("Not a Node or Mesh: "+e.id);if(e._parentNode){if(e._parentNode.id===this.id)return void this.warn("Already a child: "+e.id);e._parentNode.removeChild(e)}}if(e.id,e.scene.id===this.scene.id)return this._children.push(e),e._parentNode=this,t&&(e.visible=this.visible,e.culled=this.culled,e.xrayed=this.xrayed,e.highlited=this.highlighted,e.selected=this.selected,e.edges=this.edges,e.clippable=this.clippable,e.pickable=this.pickable,e.collidable=this.collidable,e.castsShadow=this.castsShadow,e.receivesShadow=this.receivesShadow,e.colorize=this.colorize,e.opacity=this.opacity,e.offset=this.offset),e._setWorldMatrixDirty(),e._setAABBDirty(),this._numTriangles+=e.numTriangles,e;this.error("Child not in same Scene: "+e.id)}},{key:"removeChild",value:function(e){for(var t=0,n=this._children.length;t<n;t++)if(this._children[t].id===e.id)return e._parentNode=null,this._children=this._children.splice(t,1),e._setWorldMatrixDirty(),e._setAABBDirty(),this._setAABBDirty(),void(this._numTriangles-=e.numTriangles)}},{key:"removeChildren",value:function(){for(var e,t=0,n=this._children.length;t<n;t++)(e=this._children[t])._parentNode=null,e._setWorldMatrixDirty(),e._setAABBDirty(),this._numTriangles-=e.numTriangles;this._children=[],this._setAABBDirty()}},{key:"numChildren",get:function(){return this._children.length}},{key:"children",get:function(){return this._children}},{key:"parent",get:function(){return this._parentNode},set:function(e){if(ge.isNumeric(e)||ge.isString(e)){var t=e;if(!(e=this.scene.components[t]))return void this.warn("Node not found: "+ge.inQuotes(t));if(!e.isNode)return void this.error("Not a Node: "+e.id)}e.scene.id===this.scene.id?this._parentNode&&this._parentNode.id===e.id?this.warn("Already a child of Node: "+e.id):e.addChild(this):this.error("Node not in same Scene: "+e.id)}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),Ae.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),Ae.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"matrix",get:function(){return this._localMatrixDirty&&(this._localMatrix||(this._localMatrix=Ae.identityMat4()),Ae.composeMat4(this._position,this._quaternion,this._scale,this._localMatrix),this._localMatrixDirty=!1),this._localMatrix},set:function(e){this._localMatrix||(this._localMatrix=Ae.identityMat4()),this._localMatrix.set(e||zt),Ae.decomposeMat4(this._localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._setWorldMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"rotate",value:function(e,t){return Ot[0]=e[0],Ot[1]=e[1],Ot[2]=e[2],Ot[3]=t*Ae.DEGTORAD,Ae.angleAxisToQuaternion(Ot,Vt),Ae.mulQuaternions(this.quaternion,Vt,Lt),this.quaternion=Lt,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"rotateOnWorldAxis",value:function(e,t){return Ot[0]=e[0],Ot[1]=e[1],Ot[2]=e[2],Ot[3]=t*Ae.DEGTORAD,Ae.angleAxisToQuaternion(Ot,Vt),Ae.mulQuaternions(Vt,this.quaternion,Vt),this}},{key:"rotateX",value:function(e){return this.rotate(Ht,e)}},{key:"rotateY",value:function(e){return this.rotate(Nt,e)}},{key:"rotateZ",value:function(e){return this.rotate(Gt,e)}},{key:"translate",value:function(e,t){return Ae.vec3ApplyQuaternion(this.quaternion,e,jt),Ae.mulVec3Scalar(jt,t,Wt),Ae.addVec3(this.position,Wt,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"translateX",value:function(e){return this.translate(Ht,e)}},{key:"translateY",value:function(e){return this.translate(Nt,e)}},{key:"translateZ",value:function(e){return this.translate(Gt,e)}},{key:"type",get:function(){return"Node"}},{key:"destroy",value:function(){if(v(C(n.prototype),"destroy",this).call(this),this._parentNode&&this._parentNode.removeChild(this),this._isObject&&(this.scene._deregisterObject(this),this._visible&&this.scene._objectVisibilityUpdated(this,!1,!1),this._xrayed&&this.scene._objectXRayedUpdated(this,!1,!1),this._selected&&this.scene._objectSelectedUpdated(this,!1,!1),this._highlighted&&this.scene._objectHighlightedUpdated(this,!1,!1),this.scene._objectColorizeUpdated(this,!1),this.scene._objectOpacityUpdated(this,!1),this.offset.some((function(e){return 0!==e}))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this._children.length)for(var e=this._children.splice(0),t=0,r=e.length;t<r;t++)e[t].destroy();this._children=[],this._setAABBDirty(),this.scene._aabbDirty=!0}}]),n}(),Kt=Ae.vec3(),Zt=function(){var e=new Float64Array(16),t=new Float64Array(4),n=new Float64Array(4);return function(r,i,s){return s=s||e,t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,Ae.transformVec4(r,t,n),Ae.setMat4Translation(r,n,s),s.slice()}}();function Jt(e,t,n){var r=Float32Array.from([e[0]])[0],i=e[0]-r,s=Float32Array.from([e[1]])[0],a=e[1]-s,o=Float32Array.from([e[2]])[0],A=e[2]-o;t[0]=r,t[1]=s,t[2]=o,n[0]=i,n[1]=a,n[2]=A}function Yt(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1e3,i=Ae.getPositionsCenter(e,Kt),s=Math.round(i[0]/r)*r,a=Math.round(i[1]/r)*r,o=Math.round(i[2]/r)*r;n[0]=s,n[1]=a,n[2]=o;var A=0!==n[0]||0!==n[1]||0!==n[2];if(A)for(var c=0,l=e.length;c<l;c+=3)t[c+0]=e[c+0]-s,t[c+1]=e[c+1]-a,t[c+2]=e[c+2]-o;return A}var qt=1e3,$t=1001,en=1002,tn=1003,nn=1004,rn=1004,sn=1005,an=1005,on=1006,An=1007,cn=1007,ln=1008,un=1008,hn=1009,dn=1010,fn=1011,pn=1012,vn=1013,gn=1014,mn=1015,yn=1016,_n=1017,bn=1018,wn=1020,Bn=1021,Cn=1022,Mn=1023,kn=1024,En=1025,Fn=1026,xn=1027,Un=1028,In=1029,Tn=1030,Pn=1031,Sn=1033,Dn=33776,Qn=33777,Rn=33778,On=33779,Vn=35840,Ln=35841,Hn=35842,Nn=35843,Gn=36196,jn=37492,Wn=37496,zn=37808,Xn=37809,Kn=37810,Zn=37811,Jn=37812,Yn=37813,qn=37814,$n=37815,er=37816,tr=37817,nr=37818,rr=37819,ir=37820,sr=37821,ar=36492,or=3e3,Ar=3001,cr=1e4,lr=10001,ur=10002,hr=10003,dr=new Z({}),fr=Ae.vec3(),pr=Ae.vec4(),vr=f({},3001,"sRGBToLinear"),gr=function(){var e=this,t=[],n=[],r=[],i=[],s=[],a=[],o=[],A=function(e,n){var r=!1;return t.push((function(t){return r&&n(e,t)})),{toString:function(){return r=!0,e}}},c={createAttribute:function(e,n){var r=!1;t.push((function(t){return r&&t.push("in ".concat(e," ").concat(n,";"))}));var i={toString:function(){return r=!0,n}};return s.push((function(e){var t=r&&e(n);return t&&a.push(t.attributeHash),i.setInputValue=t,null})),i},createFragmentDefinition:function(e,t){var n=!1;return i.push((function(r){return n&&t(e,r)})),{toString:function(){return n=!0,e}}},createOutput:function(e,t,n){var i=!1;return r.push((function(r){return i&&r.push("layout(location = ".concat(n||0,") out ").concat(e," ").concat(t,";"))})),{toString:function(){return i=!0,t}}},createUniform:function(e,n,i){var s=!1,a=function(t){return s&&t.push("uniform ".concat(e," ").concat(n,";"))};t.push(a),r.push(a);var A={toString:function(){return s=!0,n}};return o.push((function(e){var t=s&&e(n);return i?t&&function(e){return i(t,e)}:(A.setInputValue=t,null)})),A},createUniformArray:function(e,n,i){var s=!1,a=function(t){return s&&t.push("uniform ".concat(e," ").concat(n,"[").concat(i,"];"))};t.push(a),r.push(a);var A={toString:function(){return s=!0,n}};return o.push((function(e){return A.setInputValue=s&&e(n),null})),A},createUniformBlock:function(e,n,i){var s=!1,a=Object.keys(n),A=function(t){s&&(t.push("uniform ".concat(e," {")),a.forEach((function(e){return t.push(" ".concat(n[e]," ").concat(e,";"))})),t.push("};"))};t.push(A),r.push(A);var c={};return a.forEach((function(e){return c[e]={toString:function(){return s=!0,e}}})),o.push((function(t){var n=s&&t(e);return i?n&&function(e){return i(n,e)}:(c.setInputValue=n,null)})),c},createVarying:function(e,i,s,a){var o=!1,A=a?a+" ":"";return t.push((function(t){return o&&t.push("".concat(A,"out ").concat(e," ").concat(i,";"))})),n.push((function(e){return o&&e.push("".concat(i," = ").concat(s(),";"))})),r.push((function(t){return o&&t.push("".concat(A,"in ").concat(e," ").concat(i,";"))})),{toString:function(){return o=!0,i}}},createVertexDefinition:A,commonLibrary:{octDecode:A("octDecode",(function(e,t){t.push("vec3 ".concat(e,"(vec2 oct) {")),t.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));"),t.push(" if (v.z < 0.0) {"),t.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);"),t.push(" }"),t.push(" return normalize(v);"),t.push("}")}))}};return{programVariables:c,buildProgram:function(A,l,u){var h,d,f=u.getLogDepth,v=u.clipPos,g=u.usePickClipPos&&(h=c.createUniform("vec2","pickClipPos"),d=c.createUniform("vec2","pickClipPosInv"),{setClipPosInputValue:function(e){h.setInputValue(e.pickClipPos),d.setInputValue(e.pickClipPosInv)},transformedClipPos:function(){return"vec4((".concat(v,".xy / ").concat(v,".w - ").concat(h,") * ").concat(d," * ").concat(v,".w, ").concat(v,".zw)")}}),m=g?g.transformedClipPos():v,y=[],_=c.createVarying("float","isPerspective",(function(){return"(".concat(u.projMatrix,"[2][3] == -1.0) ? 1.0 : 0.0")})),b=c.createUniform("float","logDepthBufFC",(function(e,t){return e(2/(Math.log(t.view.far+1)/Math.LN2))})),w=c.createVarying("float","vFragDepth",(function(){return"1.0 + clipPos.w"}));f?y.push("gl_FragDepth = ".concat(u.testPerspectiveForGl_FragDepth?"".concat(_," == 0.0 ? gl_FragCoord.z : "):"","log2(").concat(f(w),") * ").concat(b," * 0.5;")):u.cleanerEdges&&y.push("gl_FragDepth = gl_FragCoord.z + length(vec2(dFdx(gl_FragCoord.z), dFdy(gl_FragCoord.z)));");var B,C,M=c.createFragmentDefinition("linearToGamma",(function(e,t){t.push("vec4 ".concat(e,"(in vec4 value, in float gammaFactor) {")),t.push(" return vec4(pow(value.xyz, vec3(1.0 / gammaFactor)), value.w);"),t.push("}")})),E=u.sectionPlanesState,F=E&&(B=function(e){for(var t=[],n=0;n<e;++n)t.push(n);return t}(E.getNumAllocatedSectionPlanes()).map((function(e){var t=function(t,n,r){return c.createUniform(t,"sectionPlane".concat(n).concat(e),(function(t,n){var i=E.sectionPlanes,s=i.length,a=(n.mesh.layerIndex||0)*s,o=e<s&&n.mesh.renderFlags.sectionPlanesActivePerLayer[a+e];return r(t,o,i[e],n.mesh.origin)}))};return{act:t("bool","Active",(function(e,t){return e(t?1:0)})),dir:t("vec3","Dir",(function(e,t,n){return t&&e(n.dir)})),pos:t("vec3","Pos",(function(e,t,n,r){return t&&e(r?Ae.mulVec3Scalar(Ae.normalizeVec3(n.dir,fr),-(Ae.dotVec3(n.dir,r)+n.dist),fr):n.pos)}))}})),B.length>0&&function(e){return B.map((function(t){return"(".concat(t.act," ? clamp(dot(-").concat(t.dir,", ").concat(e," - ").concat(t.pos,"), 0.0, 1000.0) : 0.0)")})).join(" + ")}),x=u.crossSections,U=F?(C=c.createUniform("vec4","sliceColor",(function(e){return e(x.sliceColor)})),function e(t){return e.needed=!0,"(sliced ? ".concat(C," : ").concat(t,")")}):function(e){return e},I=u.getGammaFactor,T=c.createUniform("float","gammaFactor",(function(e){return e(I())}));u.appendFragmentOutputs(y,I&&function(e){return"".concat(M,"(").concat(e,", ").concat(T,")")},"gl_FragCoord",U);var P,S=function(){var e=[],t=c.createUniform("float","sliceThickness",(function(e){return e(x.sliceThickness)}));if(F){U.needed&&e.push(" bool sliced = false;"),e.push(" if (".concat(u.clippableTest(),") {"));var n=c.createVarying("highp vec3","vHighpWorldPosition",(function(){return"".concat(u.worldPositionAttribute,".xyz")}));if(e.push(" float dist = ".concat(F(n),";")),u.clippingCaps){var r=c.createVarying("float","vClipPositionW",(function(){return"gl_Position.w"}));e.push(" if (dist > (0.002 * ".concat(r,")) { discard; }")),e.push(" if (dist > 0.0) { "),e.push(" ".concat(u.clippingCaps," = vec4(1.0, 0.0, 0.0, 1.0);")),f&&e.push(" gl_FragDepth = log2(".concat(f(w),") * ").concat(b," * 0.5;")),e.push(" return;"),e.push(" }")}else e.push(" if (dist > ".concat(U.needed?t:"0.0",") { discard; }"));U.needed&&e.push(" sliced = dist > 0.0;"),e.push(" }")}return e}(),D=(P=[],i.forEach((function(e){return e(P)})),P),Q=[].concat(p(function(){var e=[];return r.forEach((function(t){return t(e)})),e}()),p(D),["void main(void) {"],p(u.discardPoints?[" vec2 cxy = 2.0 * gl_PointCoord - 1.0;"," if (dot(cxy, cxy) > 1.0) { discard; }"]:[]),p(S),y,["}"]),R=["gl_Position = ".concat(m,";")].concat(p(u.getPointSize?["gl_PointSize = ".concat(u.getPointSize(),";")]:[]),p(function(){var e=[];return n.forEach((function(t){return t(e)})),e}())),O=u.getVertexData?u.getVertexData():[],V=[].concat(p(function(){var e=[];return t.forEach((function(t){return t(e)})),e}()),["void main(void) {"],p(O),p(R),["}"]),L=function(e){return["#version 300 es","// "+l+" "+e+" 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"]},H=L("vertex").concat(V),N=L("fragment").concat(["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(Q),G=function(e,t){var n=t.join("\n"),r=A.createShader(e);return A.shaderSource(r,n),A.compileShader(r),A.getShaderParameter(r,A.COMPILE_STATUS)?[r]:[null,["Failed to compile",A.getShaderInfoLog(r),n.split("\n").map((function(e,t){return t+1+": "+e+"\n"})).join("")]]},j=k(G(A.VERTEX_SHADER,H),2),W=j[0],z=j[1],X=k(G(A.FRAGMENT_SHADER,N),2),K=X[0],Z=X[1],J=function(e){return console.error(e.join("\n")),[null,e]};if(z)return J(["Vertex shader error"].concat(z));if(Z)return J(["Fragment shader error"].concat(Z));var Y=A.createProgram();if(Y){if(A.attachShader(Y,W),A.attachShader(Y,K),A.linkProgram(Y),A.getProgramParameter(Y,A.LINK_STATUS)){var q=_r(A,Y);s.forEach((function(e){return e(q)}));var $=o.map((function(e){return e(q)})).filter((function(e){return e})),ee=dr.addItem({});return[{id:ee,bind:function(){return A.useProgram(Y)},inputSetters:{attributesHash:a.sort().join(", "),setUniforms:function(e,t){g&&g.setClipPosInputValue(e),$.forEach((function(e){return e(t)}))}},destroy:function(){dr.removeItem(ee),A.deleteProgram(Y),A.deleteShader(W),A.deleteShader(K)}}]}return J(["",A.getProgramInfoLog(e.program),"","Vertex shader:",""].concat(p(H),["","Fragment shader:",""],p(N)))}return J(["Failed to allocate program"])}}},mr=function(e,t){var n=e.createUniform("vec4","lightAmbient",(function(e){return e(t.getAmbientColorAndIntensity())})),r=t.lights,i=r.map((function(t,n){var i={color:e.createUniform("vec4","lightColor".concat(n),(function(e){var t=r[n];pr[0]=t.color[0],pr[1]=t.color[1],pr[2]=t.color[2],pr[3]=t.intensity,e(pr)})),position:e.createUniform("vec3","lightPos".concat(n),(function(e){return e(r[n].pos)})),direction:e.createUniform("vec3","lightDir".concat(n),(function(e){return e(r[n].dir)})),shadowProjMatrix:e.createUniform("mat4","shadowProjMatrix".concat(n),(function(e){return e(r[n].getShadowViewMatrix())})),shadowViewMatrix:e.createUniform("mat4","shadowViewMatrix".concat(n),(function(e){return e(r[n].getShadowViewMatrix())})),shadowMap:e.createUniform("sampler2D","shadowMap".concat(n),(function(e){return e(r[n].getShadowRenderBuf().colorTextures[0])}))},s=function(e){return{glslLight:{isViewSpace:"view"===t.space,getColor:function(){return"".concat(i.color,".rgb * ").concat(i.color,".a")},getDirection:function(t,n){return"normalize(".concat(e(t,n),")")},shadowParameters:t.castsShadow&&{getShadowProjMatrix:function(){return i.shadowProjMatrix},getShadowViewMatrix:function(){return i.shadowViewMatrix},getShadowMap:function(){return i.shadowMap}}},setupLightsInputs:function(){var e=Object.values(i).map((function(e){return e.setupLightsInputs()})).filter((function(e){return e}));return function(){return e.forEach((function(e){return e()}))}}}};return"dir"===t.type?"view"===t.space?s((function(e,t){return"-".concat(i.direction)})):s((function(e,t){return"-(".concat(e," * vec4(").concat(i.direction,", 0.0)).xyz")})):"point"===t.type?"view"===t.space?s((function(e,t){return"".concat(i.position," - ").concat(t)})):s((function(e,t){return"(".concat(e," * vec4(").concat(i.position,", 1.0)).xyz - ").concat(t)})):null})).filter((function(e){return e})),s=function(t,n){var r=function(){var e=n();return e.length>0&&e[0]},i=r();return i&&yr(e,"samplerCube",t,i.encoding,(function(e){var t=r();t&&e(t.texture)}))},a=s("light",(function(){return t.lightMaps})),o=s("reflection",(function(){return t.reflectionMaps}));return{getHash:function(){return t.getHash()},getAmbientColor:function(){return"".concat(n,".rgb * ").concat(n,".a")},directionalLights:i.map((function(e){return e.glslLight})),getIrradiance:a&&function(e){return"".concat(a(e),".rgb")},getReflection:o&&function(e,t){return"".concat(o(e,t),".rgb")}}},yr=function(e,t,n,r,i){var s=e.createUniform(t,n+"Map",i);return function(e,t){var n=t?"texture(".concat(s,", ").concat(e,", ").concat(t,")"):"texture(".concat(s,", ").concat(e,")");return 3e3!==r?"".concat(vr[r],"(").concat(n,")"):n}},_r=function(e,t){for(var n={},r=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES),i=function(i){var s=e.getActiveAttrib(t,i),a=e.getAttribLocation(t,s.name);n[s.name]=function(t){t.bindAtLocation(a),e.enableVertexAttribArray(a);var n=t.attributeDivisor;n&&e.vertexAttribDivisor(a,n)},n[s.name].attributeHash="".concat(a.toString().padStart(1+Math.floor(Math.log10(r)),"0"),":").concat(s.name)},s=0;s<r;++s)i(s);for(var a=e.getProgramParameter(t,e.ACTIVE_UNIFORM_BLOCKS),o=function(r){var i=e.getActiveUniformBlockName(t,r),s=e.getUniformBlockIndex(t,i),a=r;e.uniformBlockBinding(t,s,a);var o=e.createBuffer();n[i]=function(t){e.bindBuffer(e.UNIFORM_BUFFER,o),e.bufferData(e.UNIFORM_BUFFER,t,e.DYNAMIC_DRAW),e.bindBufferBase(e.UNIFORM_BUFFER,a,o)}},A=0;A<a;++A)o(A);for(var c=e.getProgramParameter(t,e.ACTIVE_UNIFORMS),l=0,u=function(r){var i=e.getActiveUniform(t,r),s=i.name;s.endsWith("[0]")&&(s=s.substr(0,s.length-3)),"\0"===s[s.length-1]&&(s=s.substr(0,s.length-1));var a=e.getUniformLocation(t,s);if(function(){for(var t in e)if(i.type===e[t])return t}(),i.type===e.SAMPLER_2D||i.type===e.SAMPLER_CUBE||i.type===e.SAMPLER_2D_SHADOW||e instanceof window.WebGL2RenderingContext&&(i.type===e.UNSIGNED_INT_SAMPLER_2D||i.type===e.INT_SAMPLER_2D)){var o=l++;n[s]=function(t){var n=t.bind(o);return n&&e.uniform1i(a,o),n}}else n[s]=function(){if(1===i.size)switch(i.type){case e.BOOL:case e.INT:return function(t){return e.uniform1i(a,t)};case e.FLOAT:return function(t){return e.uniform1f(a,t)};case e.FLOAT_VEC2:return function(t){return e.uniform2fv(a,t)};case e.FLOAT_VEC3:return function(t){return e.uniform3fv(a,t)};case e.FLOAT_VEC4:return function(t){return e.uniform4fv(a,t)};case e.FLOAT_MAT3:return function(t){return e.uniformMatrix3fv(a,!1,t)};case e.FLOAT_MAT4:return function(t){return e.uniformMatrix4fv(a,!1,t)}}else if(i.size>1)switch(i.type){case e.FLOAT:return function(t){return e.uniform1fv(a,t)};case e.FLOAT_VEC2:return function(t){return e.uniform2fv(a,t)};case e.FLOAT_VEC3:return function(t){return e.uniform3fv(a,t)};case e.FLOAT_VEC4:return function(t){return e.uniform4fv(a,t)}}throw"Unhandled uniform ".concat(s)}()},h=0;h<c;++h)u(h);return function(e){var t=n[e];if(!t)throw'Missing input "'.concat(e,'"');return t}},br=Ae.vec4(),wr=function(e,t,n,r,i){var s=r._state,a="PhongMaterial"===s.type,o="MetallicMaterial"===s.type,A="SpecularMaterial"===s.type,c=n.attributes,l=mr(t,i._lightsState),u=t.createUniform("vec4","colorize",(function(e,t){return e(t.meshColorize)})),h=t.createFragmentDefinition("fresnel",(function(e,t){t.push("float ".concat(e,"(vec3 eyeDir, vec3 normal, float edgeBias, float centerBias, float power) {")),t.push(" float fr = abs(dot(eyeDir, normal));"),t.push(" float finalFr = clamp((fr - edgeBias) / (centerBias - edgeBias), 0.0, 1.0);"),t.push(" return pow(finalFr, power);"),t.push("}")})),d=function(e,n,i){var s=function(n,r,s){return t.createUniform(n,e+"Fresnel"+r,(function(e,t){return e(s(i(t.material)))}))},a=s("float","EdgeBias",(function(e){return e.edgeBias})),o=s("float","CenterBias",(function(e){return e.centerBias})),A=s("float","Power",(function(e){return e.power})),c=s("vec3","EdgeColor",(function(e){return e.edgeColor})),l=s("vec3","CenterColor",(function(e){return e.centerColor}));return i(r)&&function(e,t){var r="".concat(h,"(").concat(e,", ").concat(t,", ").concat(a,", ").concat(o,", ").concat(A,")");return"mix(".concat(c+n,", ").concat(l+n,", ").concat(r,")")}},f=d("diffuse","",(function(e){return e._diffuseFresnel})),p=d("specular","",(function(e){return e._specularFresnel})),v=d("emissive","",(function(e){return e._emissiveFresnel})),g=d("alpha",".r",(function(e){return e._alphaFresnel})),m=function(e,n){var i=c.uv&&n(r),s=i&&yr(t,"sampler2D",e,i.encoding,(function(e,t){return e(n(t.material)._state.texture)}));return s&&function(){var r=i._state.matrix&&t.createUniform("mat4",e+"MapMatrix",(function(e,t){return e(n(t.material)._state.matrix)})),a=r?function(e){return"(".concat(r," * ").concat(e,").st")}:function(e){return"".concat(e,".st")},o=function(e,t){return s(a(e))};return o.getTexCoordExpression=a,o}()},y=m("ambient",(function(e){return e._ambientMap})),_=m("baseColor",(function(e){return e._baseColorMap})),b=m("diffuse",(function(e){return e._diffuseMap})),w=m("emissive",(function(e){return e._emissiveMap})),B=m("occlusion",(function(e){return e._occlusionMap})),C=m("alpha",(function(e){return e._alphaMap})),M=m("metallic",(function(e){return e._metallicMap})),k=m("roughness",(function(e){return e._roughnessMap})),E=m("metallicRoughness",(function(e){return e._metallicRoughnessMap})),F=m("specular",(function(e){return e._specularMap})),x=m("glossiness",(function(e){return e._glossinessMap})),U=m("specularGlossiness",(function(e){return e._specularGlossinessMap})),I=m("normal",(function(e){return e._normalMap})),T=function(e,n,i){var s=i(r);return("float"===n?null!=s:s)&&t.createUniform(n,e,(function(e,t){return e(i(t.material))}))},P=T("materialAmbient","vec3",(function(e){return e.ambient})),S=T("materialDiffuse","vec3",(function(e){return e.diffuse})),D=T("materialBaseColor","vec3",(function(e){return e.baseColor})),Q=T("materialEmissive","vec3",(function(e){return e.emissive})),R=T("materialSpecular","vec3",(function(e){return e.specular})),O=T("materialGlossiness","float",(function(e){return e.glossiness})),V=T("materialMetallic","float",(function(e){return e.metallic})),L=T("materialRoughness","float",(function(e){return e.roughness})),H=T("materialShininess","float",(function(e){return e.shininess})),N=T("materialSpecularF0","float",(function(e){return e.specularF0})),G=T("materialAlphaModeCutoff","vec4",(function(e){var t=e.alpha;return null!=t?(br[0]=t,br[1]=1===e.alphaMode?1:0,br[2]=e.alphaCutoff,br):null})),j=t.createVarying("vec3","vViewPosition",(function(){return"".concat(c.position.view,".xyz")})),W=t.createVarying("vec4","texturePos",(function(){return"vec4(".concat(c.uv,", 1.0, 1.0)")})),z=c.color&&t.createVarying("vec4","vColor",(function(){return c.color})),X=t.createVarying("vec3","vViewNormal",(function(){return c.normal.view})),K=l.directionalLights.map((function(e,r){return{vViewLightReverseDir:t.createVarying("vec3","vViewLightReverseDir".concat(r),(function(){return e.getDirection(n.viewMatrix,null)})),vShadowPosFromLight:t.createVarying("vec3","vShadowPosFromLight".concat(r),(function(){return"(".concat("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)"," * ").concat(e.shadowParameters.getShadowProjMatrix()," * (").concat(e.shadowParameters.getShadowViewMatrix()," * ").concat(c.position.world,")).xyz")}))}})),Z=t.createVarying("vec3","vWorldNormal",(function(){return c.normal.world})),J=t.createOutput("vec4","outColor"),Y=t.createFragmentDefinition("saturate",(function(e,t){return t.push("float ".concat(e,"(const in float a) { return clamp(a, 0.0, 1.0); }"))})),q=t.createFragmentDefinition("BRDF_Specular_GGX",(function(e,t){t.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),t.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),t.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),t.push("}"),t.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" return 1.0 / ( gl * gv );"),t.push("}"),t.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" return 0.5 / max( gv + gl, 1e-6 );"),t.push("}"),t.push("float D_GGX(const in float alpha, const in float dotNH) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),t.push(" return 0.31830988618 * a2 / ( denom * denom);"),t.push("}"),t.push("vec3 ".concat(e,"(const in vec3 incidentLightDirection, const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {")),t.push(" float alpha = ( roughness * roughness );"),t.push(" vec3 halfDir = normalize( incidentLightDirection + viewEyeDir );"),t.push(" float dotNL = ".concat(Y,"( dot( viewNormal, incidentLightDirection ) );")),t.push(" float dotNV = ".concat(Y,"( dot( viewNormal, viewEyeDir ) );")),t.push(" float dotNH = ".concat(Y,"( dot( viewNormal, halfDir ) );")),t.push(" float dotLH = ".concat(Y,"( dot( incidentLightDirection, halfDir ) );")),t.push(" vec3 F = F_Schlick( specularColor, dotLH );"),t.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),t.push(" float D = D_GGX( alpha, dotNH );"),t.push(" return F * (G * D);"),t.push("}")})),$=t.createFragmentDefinition("BRDF_Specular_GGX_Environment",(function(e,t){t.push("vec3 ".concat(e,"(const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {")),t.push(" float dotNV = ".concat(Y,"(dot(viewNormal, viewEyeDir));")),t.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),t.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),t.push(" vec4 r = roughness * c0 + c1;"),t.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),t.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),t.push(" return specularColor * AB.x + AB.y;"),t.push("}")})),ee=t.createFragmentDefinition("perturbNormal2Arb",(function(e,t){t.push("vec3 ".concat(e,"( vec3 eye_pos, vec3 surf_norm, vec2 uv, vec4 texel ) {")),t.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),t.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),t.push(" vec2 st0 = dFdx( uv.st );"),t.push(" vec2 st1 = dFdy( uv.st );"),t.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),t.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),t.push(" vec3 N = normalize( surf_norm );"),t.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),t.push(" mat3 tsn = mat3( S, T, N );"),t.push(" return normalize( tsn * mapN );"),t.push("}")}));return{getHash:function(){return[e,i.gammaOutput?"go":"",l.getHash(),r._state.hash]},programName:"Draw",canActAsBackground:!0,discardPoints:!0,setupPointSize:!0,setsLineWidth:!0,appendFragmentOutputs:function(e,t,r){var i,s,h,d,m=c.normal&&(l.directionalLights.length>0||l.getIrradiance||l.getReflection);if(e.push("vec3 diffuseColor = ".concat(m&&(a||A)&&S||o&&D||"vec3(1.0)",";")),e.push("vec4 alphaModeCutoff = ".concat((a||o||A)&&G||"vec4(1.0, 0.0, 0.0, 0.0)",";")),e.push("float alpha = alphaModeCutoff[0];"),(a||o||A)&&C&&e.push("alpha *= ".concat(C(W),".r;")),z&&(e.push("diffuseColor *= ".concat(z,".rgb;")),e.push("alpha *= ".concat(z,".a;"))),o&&_&&(e.push("vec4 baseColorTexel = "+_(W)+";"),e.push("diffuseColor *= baseColorTexel.rgb;"),e.push("alpha *= baseColorTexel.a;")),(a||A)&&b&&(e.push("vec4 diffuseTexel = "+b(W)+";"),e.push("diffuseColor *= diffuseTexel.rgb;"),e.push("alpha *= diffuseTexel.a;")),e.push("vec3 emissiveColor = ".concat((a||o||A)&&Q||"vec3(0.0)",";")),(a||o||A)&&w&&e.push("emissiveColor = ".concat(w(W),".rgb;")),m){e.push("vec3 specular = ".concat((a||A)&&R||"vec3(1.0)",";")),e.push("float glossiness = ".concat(A&&O||"1.0",";")),e.push("float metallic = ".concat(o&&V||"1.0",";")),e.push("float roughness = ".concat((o||A)&&L||"1.0",";")),e.push("float shininess = ".concat(a&&H||"1.0",";")),e.push("float specularF0 = ".concat(o&&N||"1.0",";")),e.push("float occlusion = ".concat((a||o||A)&&B?"".concat(B(W),".r"):"1.0",";")),o&&M&&e.push("metallic *= ".concat(M(W),".r;")),o&&k&&e.push("roughness *= ".concat(k(W),".r;")),o&&E&&(e.push("vec4 metalRoughTexel = "+E(W)+";"),e.push("metallic *= metalRoughTexel.b;"),e.push("roughness *= metalRoughTexel.g;")),(a||A)&&F&&e.push("specular *= ".concat(F(W),".rgb;")),A&&x&&e.push("glossiness *= ".concat(x(W),".r;")),A&&U&&(e.push("vec4 specGlossTexel = "+U(W)+";"),e.push("specular *= specGlossTexel.rgb;"),e.push("glossiness *= specGlossTexel.a;"));var T="normalize(".concat(X,")"),te=(a||o||A)&&I?"".concat(ee,"(").concat(j,", ").concat(T,", ").concat(I.getTexCoordExpression(W),", ").concat(I(W),")"):T;if(e.push("vec3 viewNormal = ".concat(te,";")),e.push("vec3 viewEyeDir = normalize(-".concat(j,");")),f&&e.push("diffuseColor *= ".concat(f("viewEyeDir","viewNormal"),";")),p&&e.push("specular *= ".concat(p("viewEyeDir","viewNormal"),";")),v&&e.push("emissiveColor *= ".concat(v("viewEyeDir","viewNormal"),";")),g&&e.push("alpha *= ".concat(g("viewEyeDir","viewNormal"),";")),e.push("if (alphaModeCutoff[1] == 1.0 && alpha < alphaModeCutoff[2]) {"),e.push(" discard;"),e.push("}"),e.push("vec3 material_diffuseColor;"),a&&(e.push("material_diffuseColor = diffuseColor;"),e.push("roughness = 0.0;")),A&&(e.push("float oneMinusSpecularStrength = 1.0 - max(max(specular.r, specular.g ),specular.b);"),e.push("material_diffuseColor = diffuseColor * oneMinusSpecularStrength;"),e.push("roughness = clamp(1.0 - glossiness, 0.04, 1.0);")),o&&(e.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),e.push("material_diffuseColor = diffuseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),e.push("roughness = clamp(roughness, 0.04, 1.0);"),e.push("specular = mix(vec3(dielectricSpecular), diffuseColor, metallic);")),a||o||A){if(e.push("const float PI = 3.14159265359;"),e.push("vec3 reflDiff = vec3(0.0);"),e.push("vec3 reflSpec = vec3(0.0);"),l.getIrradiance&&e.push("reflDiff += ".concat(l.getIrradiance("normalize(".concat(Z,")")),";")),l.getReflection){var ne="reflect(-viewEyeDir, viewNormal)",re=a?"0.2 * PI * ".concat(l.getReflection(ne)):(i="".concat($,"(viewNormal, viewEyeDir, specular, roughness)"),s="normalize((vec4(".concat(ne,", 0.0) * ").concat(n.viewMatrix,").xyz)"),h="".concat("4.0"," - 0.39624 - 0.25 * log2(pow(").concat("2.0 / pow(roughness + 0.0001, 2.0) - 2.0",", 2.0) + 1.0)"),d="clamp(".concat(h,", 0.0, ").concat("4.0",")"),"".concat(i," * ").concat(l.getReflection(s,d)));e.push("reflSpec += ".concat(re,";"))}l.directionalLights.some((function(e){return e.shadowParameters}))&&(e.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));"),e.push("const float texelSize = 1.0 / 1024.0;"),e.push("float shadow;"),e.push("float fragmentDepth;")),l.directionalLights.forEach((function(t,n){if(t.shadowParameters){e.push("fragmentDepth = ".concat(K[n].vShadowPosFromLight,".z - ").concat("0.007",";")),e.push("shadow = 0.0;"),e.push("for (int x = -3; x <= 3; x++) {"),e.push(" for (int y = -3; y <= 3; y++) {"),e.push(" float texelDepth = dot(texture(".concat(t.getShadowMap(),", ").concat(K[n].vShadowPosFromLight,".xy + vec2(x, y) * texelSize), bitShift);")),e.push(" if (fragmentDepth < texelDepth) {"),e.push(" shadow += 1.0;"),e.push(" }"),e.push(" }"),e.push("}"),e.push("shadow /= 9.0;")}e.push("vec3 lightColor".concat(n," = ").concat(t.getColor()).concat(t.shadowParameters?" * shadow":"",";")),e.push("vec3 lightDirection".concat(n," = ").concat(t.isViewSpace?t.getDirection(null,j):K[n].vViewLightReverseDir,";"));var r="".concat(Y,"(dot(viewNormal, lightDirection").concat(n,"))");e.push("vec3 irradiance".concat(n," = ").concat(r," * lightColor").concat(n,";")),e.push("reflDiff += irradiance".concat(n,";"));var i=a?"lightColor".concat(n," * specular * pow(max(dot(reflect(-lightDirection").concat(n,", -viewNormal), viewEyeDir), 0.0), shininess)"):"irradiance".concat(n," * PI * ").concat(q,"(lightDirection").concat(n,", viewNormal, viewEyeDir, specular, roughness)");e.push("reflSpec += ".concat(i,";"))}))}var ie=a&&"".concat(l.getAmbientColor()," * diffuseColor");e.push("vec3 outgoingLight = emissiveColor + occlusion * (reflDiff * material_diffuseColor + reflSpec)"+(ie?" + "+ie:"")+";")}else e.push("vec3 ambientColor = ".concat(a&&P||"vec3(1.0)",";")),a&&y&&e.push("ambientColor *= ".concat(y(W),".rgb;")),e.push("ambientColor *= ".concat(l.getAmbientColor(),";")),e.push("vec3 outgoingLight = emissiveColor + ambientColor;");e.push("vec4 fragColor = ".concat(u," * vec4(outgoingLight, alpha);")),e.push("".concat(J," = ").concat(t?t("fragColor"):"fragColor",";"))}}},Br=function(e,t,n,r,i){var s=mr(t,i._lightsState),a=t.createUniform("vec4","colorize",(function(e,t){return e(t.meshColorize)})),o=t.createUniform("float","materialAlpha",(function(e,t){return e(t.material.alpha)})),A=t.createUniform("vec3","materialColor",(function(e,t){return e(t.material.color)})),c=t.createUniform("vec3","materialEmissive",(function(e,t){return e(t.material.emissive)})),l=t.createVarying("vec4","vColor",(function(){var e=n.attributes,t=[s.getAmbientColor()].concat(e.normal?s.directionalLights.map((function(t){return"(max(dot(".concat(e.normal.view,", ").concat(t.getDirection(n.viewMatrix,e.position.view),"), 0.0) * ").concat(t.getColor(),")")})):[]);return"".concat(a," * vec4((").concat(t.join(" + "),") * ").concat(A," + ").concat(c,", ").concat(o,");")})),u=t.createOutput("vec4","outColor");return{getHash:function(){return[e,i.gammaOutput?"go":"",s.getHash(),r._state.hash]},programName:"Lambert",canActAsBackground:!0,discardPoints:!0,setupPointSize:!0,setsLineWidth:!0,appendFragmentOutputs:function(e,t){return e.push("".concat(u," = ").concat(t?t(l):l,";"))}}},Cr=function(e,t,n,r,i){var s=i&&mr(t,r._lightsState),a=t.createUniform("vec3","uColor",(function(e,t){return e(i?t.material.fillColor:t.material.edgeColor)})),o=t.createUniform("float","uAlpha",(function(e,t){return e(i?t.material.fillAlpha:t.material.edgeAlpha)})),A=t.createVarying("vec4","vColor",(function(){var e=n.attributes,t=i&&[s.getAmbientColor()].concat(e.normal?s.directionalLights.map((function(t){return"(max(dot(".concat(e.normal.view,", ").concat(t.getDirection(n.viewMatrix,e.position.view),"), 0.0) * ").concat(t.getColor(),")")})):[]);return"vec4(".concat(a).concat(t?" * (".concat(t.join(" + "),")"):"",", ").concat(o,")")})),c=t.createOutput("vec4","outColor");return{getHash:function(){return[e,r.gammaOutput?"go":"",s&&s.getHash()]},programName:i?"EmphasisFill":"EmphasisEdges",dontSetFrontFace:!0,discardPoints:i,drawEdges:!i,appendFragmentOutputs:function(e,t){return e.push("".concat(c," = ").concat(t?t(A):A,";"))}}},Mr=Ae.vec4(),kr=function(e,t){var n=t.createUniform("vec4","pickColor",(function(e,t){var n=t.meshPickID;Mr[0]=255&n,Mr[1]=n>>8&255,Mr[2]=n>>16&255,Mr[3]=n>>24&255,Ae.mulVec4Scalar(Mr,1/255,Mr),e(Mr)})),r=t.createOutput("vec4","outColor");return{getHash:function(){return[e]},programName:"PickMesh",isPick:!0,dontBillboardAnything:!0,appendFragmentOutputs:function(e){return e.push("".concat(r," = ").concat(n,";"))}}},Er=function(e,t,n){var r=t.createVarying("vec4","vColor",(function(){return n.attributes.pickColor})),i=t.createOutput("vec4","outColor");return{getHash:function(){return[e]},programName:"PickTriangle",isPick:!0,trianglePick:!0,dontBillboardAnything:!0,appendFragmentOutputs:function(e){return e.push("".concat(i," = ").concat(r,";"))}}},Fr=function(e,t){var n=t.createOutput("vec4","outColor");return{getHash:function(){return[e]},programName:"Occlusion",skipIfTransparent:!0,appendFragmentOutputs:function(e){return e.push("".concat(n," = vec4(0.0, 0.0, 1.0, 1.0);"))}}},xr=function(e,t){var n=t.createFragmentDefinition("encodeFloat",(function(e,t){t.push("vec4 ".concat(e,"( const in float depth ) {")),t.push(" const vec4 bitShift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);"),t.push(" const vec4 bitMask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);"),t.push(" vec4 comp = fract(depth * bitShift);"),t.push(" comp -= comp.xxyz * bitMask;"),t.push(" return comp;"),t.push("}")})),r=t.createOutput("vec4","outColor");return{getHash:function(){return[e]},programName:"Shadow",setsLineWidth:!0,useShadowView:!0,dontBillboardAnything:!0,dontGetLogDepth:!0,appendFragmentOutputs:function(e,t,i){return e.push("".concat(r," = ").concat(n,"(").concat(i,".z);"))}}},Ur=function(){function e(){x(this,e),this.visibleLayers=[],this.sectionPlanesActivePerLayer=[],this.reset()}return I(e,[{key:"reset",value:function(){this.culled=!1,this.sectioned=!1,this.numLayers=0,this.numVisibleLayers=0,this.colorOpaque=!1,this.colorTransparent=!1,this.edgesOpaque=!1,this.edgesTransparent=!1,this.xrayedSilhouetteOpaque=!1,this.xrayedEdgesOpaque=!1,this.xrayedSilhouetteTransparent=!1,this.xrayedEdgesTransparent=!1,this.highlightedSilhouetteOpaque=!1,this.highlightedEdgesOpaque=!1,this.highlightedSilhouetteTransparent=!1,this.highlightedEdgesTransparent=!1,this.selectedSilhouetteOpaque=!1,this.selectedEdgesOpaque=!1,this.selectedSilhouetteTransparent=!1,this.selectedEdgesTransparent=!1}}]),e}(),Ir=Ae.OBB3(),Tr=Ae.vec4(),Pr=Ae.vec4(),Sr=Ae.vec4(),Dr=Ae.vec3([1,0,0]),Qr=Ae.vec3([0,1,0]),Rr=Ae.vec3([0,0,1]),Or=Ae.vec3(3),Vr=Ae.vec3(3),Lr=Ae.identityMat4(),Hr=new Z({}),Nr={},Gr=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,n),(r=t.call(this,e,i)).renderOrder=i.renderOrder||0,r.originalSystemId=i.originalSystemId||r.id,r.renderFlags=new Ur,r._state=new it({visible:!0,culled:!1,pickable:null,clippable:null,collidable:null,occluder:!1!==i.occluder,castsShadow:null,receivesShadow:null,xrayed:!1,highlighted:!1,selected:!1,edges:!1,stationary:!!i.stationary,background:!!i.background,billboard:r._checkBillboard(i.billboard),layer:null,colorize:null,pickID:r.scene._renderer.getPickID(w(r)),drawHash:"",pickOcclusionHash:"",offset:Ae.vec3(),origin:null,originHash:null,isUI:i.isUI});var s=i.material?r._checkComponent2(["PhongMaterial","MetallicMaterial","SpecularMaterial","LambertMaterial"],i.material):r.scene.material,a=w(r),o=function(e){var t=null,n=function(){if(!t){var n=gr(),r=n.programVariables.createAttribute,i=a._geometry._state,s={position:r("vec3","position"),color:i.colorsBuf&&r("vec4","color"),pickColor:r("vec4","pickColor"),uv:i.uvBuf&&r("vec2","uv"),normal:(i.autoVertexNormals||i.normalsBuf)&&["triangles","triangle-strip","triangle-fan"].includes(i.primitiveName)&&r("vec3","normal")},o=function(e){var t={toString:function(){return t.needed=!0,e}};return t},A=s.normal&&o("worldNormal"),c=A&&o("viewNormal"),l=s.uv&&o("decodedUv"),u=e(n.programVariables,{attributes:{position:{world:"worldPosition",view:"viewPosition"},color:s.color,pickColor:s.pickColor,uv:l,normal:s.normal&&{world:A,view:c}},viewMatrix:"viewMatrix2"}),h=[u.programName,a.scene.canvas.canvas.id,a.scene._sectionPlanesState.getHash(),a._geometry._state.hash].concat(u.getHash()).join(";");if(!(h in Nr)){var d=Wr(a,s,{decodedUv:l,worldNormal:A,viewNormal:c},u,n);if(d.errors)return void console.log(d.errors.join("\n"));var f=Hr.addItem({});Nr[h]={drawMesh:d.drawMesh,id:f,useCount:0,delete:function(){Hr.removeItem(f),d.destroy(),delete Nr[h],he.memory.programs--}},he.memory.programs++}(t=Nr[h]).useCount++}};return{get:n,getId:function(){return t.id},put:function(){t&&(0==--t.useCount&&t.delete(),t=null)},drawMesh:function(e,r,i){n(),t&&t.drawMesh(e,r,i)}}},A=a.scene,c=function(e){return function(t,n){return Cr(a._state.hash,t,n,A,e)}};r._renderers={_drawRenderer:o((function(e,t){return"LambertMaterial"===s.type?Br(a._state.drawHash,e,t,s,A):wr(a._state.drawHash,e,t,s,A)})),_shadowRenderer:o((function(e){return xr(a._state.hash,e)})),_emphasisEdgesRenderer:o(c(!1)),_emphasisFillRenderer:o(c(!0)),_pickMeshRenderer:o((function(e){return kr(a._state.hash,e)})),_pickTriangleRenderer:o((function(e,t){return Er(a._state.hash,e,t)})),_occlusionRenderer:o((function(e){return Fr(a._state.pickOcclusionHash,e)}))},r._geometry=i.geometry?r._checkComponent2(["ReadableGeometry","VBOGeometry"],i.geometry):r.scene.geometry,r._material=s,r._xrayMaterial=i.xrayMaterial?r._checkComponent("EmphasisMaterial",i.xrayMaterial):r.scene.xrayMaterial,r._highlightMaterial=i.highlightMaterial?r._checkComponent("EmphasisMaterial",i.highlightMaterial):r.scene.highlightMaterial,r._selectedMaterial=i.selectedMaterial?r._checkComponent("EmphasisMaterial",i.selectedMaterial):r.scene.selectedMaterial,r._edgeMaterial=i.edgeMaterial?r._checkComponent("EdgeMaterial",i.edgeMaterial):r.scene.edgeMaterial,r._parentNode=null,r._aabb=null,r._aabbDirty=!0,r._numTriangles=r._geometry?r._geometry.numTriangles:0,r.scene._aabbDirty=!0,r._scale=Ae.vec3(),r._quaternion=Ae.identityQuaternion(),r._rotation=Ae.vec3(),r._position=Ae.vec3(),r._worldMatrix=Ae.identityMat4(),r._worldNormalMatrix=Ae.identityMat4(),r._localMatrixDirty=!0,r._worldMatrixDirty=!0,r._worldNormalMatrixDirty=!0;var l=i.origin||i.rtcCenter;if(l&&(r._state.origin=Ae.vec3(l),r._state.originHash=l.join()),i.matrix?r.matrix=i.matrix:(r.scale=i.scale,r.position=i.position,i.quaternion||(r.rotation=i.rotation)),r._isObject=i.isObject,r._isObject&&r.scene._registerObject(w(r)),r._isModel=i.isModel,r._isModel&&r.scene._registerModel(w(r)),r.visible=i.visible,r.culled=i.culled,r.pickable=i.pickable,r.clippable=i.clippable,r.collidable=i.collidable,r.castsShadow=i.castsShadow,r.receivesShadow=i.receivesShadow,r.xrayed=i.xrayed,r.highlighted=i.highlighted,r.selected=i.selected,r.edges=i.edges,r.layer=i.layer,r.colorize=i.colorize,r.opacity=i.opacity,r.offset=i.offset,i.parentId){var u=r.scene.components[i.parentId];u?u.isNode?u.addChild(w(r)):r.error("Parent is not a Node: '"+i.parentId+"'"):r.error("Parent not found: '"+i.parentId+"'"),r._parentNode=u}else i.parent&&(i.parent.isNode||r.error("Parent is not a Node"),i.parent.addChild(w(r)),r._parentNode=i.parent);return r.compile(),r}return I(n,[{key:"type",get:function(){return"Mesh"}},{key:"isMesh",get:function(){return!0}},{key:"parent",get:function(){return this._parentNode}},{key:"geometry",get:function(){return this._geometry}},{key:"material",get:function(){return this._material}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"rotation",get:function(){return this._rotation},set:function(e){this._rotation.set(e||[0,0,0]),Ae.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"quaternion",get:function(){return this._quaternion},set:function(e){this._quaternion.set(e||[0,0,0,1]),Ae.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"matrix",get:function(){return this._localMatrixDirty&&(this.__localMatrix||(this.__localMatrix=Ae.identityMat4()),Ae.composeMat4(this._position,this._quaternion,this._scale,this.__localMatrix),this._localMatrixDirty=!1),this.__localMatrix},set:function(e){this.__localMatrix||(this.__localMatrix=Ae.identityMat4()),this.__localMatrix.set(e||Lr),Ae.decomposeMat4(this.__localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._setWorldMatrixDirty(),this._setAABBDirty(),this.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"worldNormalMatrix",get:function(){return this._worldNormalMatrixDirty&&this._buildWorldNormalMatrix(),this._worldNormalMatrix}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return this._isObject}},{key:"isUI",get:function(){return this._state.isUI}},{key:"aabb",get:function(){return this._aabbDirty&&this._updateAABB(),this._aabb}},{key:"origin",get:function(){return this._state.origin},set:function(e){e?(this._state.origin||(this._state.origin=Ae.vec3()),this._state.origin.set(e),this._state.originHash=e.join(),this._setAABBDirty(),this.scene._aabbDirty=!0):this._state.origin&&(this._state.origin=null,this._state.originHash=null,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"rtcCenter",get:function(){return this.origin},set:function(e){this.origin=e}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"visible",get:function(){return this._state.visible},set:function(e){e=!1!==e,this._state.visible=e,this._isObject&&this.scene._objectVisibilityUpdated(this,e),this.glRedraw()}},{key:"xrayed",get:function(){return this._state.xrayed},set:function(e){e=!!e,this._state.xrayed!==e&&(this._state.xrayed=e,this._isObject&&this.scene._objectXRayedUpdated(this,e),this.glRedraw())}},{key:"highlighted",get:function(){return this._state.highlighted},set:function(e){(e=!!e)!==this._state.highlighted&&(this._state.highlighted=e,this._isObject&&this.scene._objectHighlightedUpdated(this,e),this.glRedraw())}},{key:"selected",get:function(){return this._state.selected},set:function(e){(e=!!e)!==this._state.selected&&(this._state.selected=e,this._isObject&&this.scene._objectSelectedUpdated(this,e),this.glRedraw())}},{key:"edges",get:function(){return this._state.edges},set:function(e){(e=!!e)!==this._state.edges&&(this._state.edges=e,this.glRedraw())}},{key:"culled",get:function(){return this._state.culled},set:function(e){this._state.culled=!!e,this.glRedraw()}},{key:"clippable",get:function(){return this._state.clippable},set:function(e){e=!1!==e,this._state.clippable!==e&&(this._state.clippable=e,this.glRedraw())}},{key:"collidable",get:function(){return this._state.collidable},set:function(e){(e=!1!==e)!==this._state.collidable&&(this._state.collidable=e,this._setAABBDirty(),this.scene._aabbDirty=!0)}},{key:"pickable",get:function(){return this._state.pickable},set:function(e){e=!1!==e,this._state.pickable!==e&&(this._state.pickable=e)}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){(e=!1!==e)!==this._state.castsShadow&&(this._state.castsShadow=e,this.glRedraw())}},{key:"receivesShadow",get:function(){return this._state.receivesShadow},set:function(e){(e=!1!==e)!==this._state.receivesShadow&&(this._state.receivesShadow=e,this._state.hash=e?"/mod/rs;":"/mod;",this.fire("dirty",this))}},{key:"saoEnabled",get:function(){return!1}},{key:"colorize",get:function(){return this._state.colorize},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[3]=1),e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1);var n=!!e;this.scene._objectColorizeUpdated(this,n),this.glRedraw()}},{key:"opacity",get:function(){return this._state.colorize[3]},set:function(e){var t=this._state.colorize;t||((t=this._state.colorize=new Float32Array(4))[0]=1,t[1]=1,t[2]=1);var n=null!=e;t[3]=n?e:1,this.scene._objectOpacityUpdated(this,n),this.glRedraw()}},{key:"transparent",get:function(){return 2===this._material.alphaMode||this._state.colorize[3]<1}},{key:"layer",get:function(){return this._state.layer},set:function(e){e=e||0,(e=Math.round(e))!==this._state.layer&&(this._state.layer=e,this._renderer.needStateSort())}},{key:"stationary",get:function(){return this._state.stationary}},{key:"billboard",get:function(){return this._state.billboard}},{key:"offset",get:function(){return this._state.offset},set:function(e){this._state.offset.set(e||[0,0,0]),this._setAABBDirty(),this.glRedraw()}},{key:"isDrawable",get:function(){return!0}},{key:"isStateSortable",get:function(){return!0}},{key:"xrayMaterial",get:function(){return this._xrayMaterial}},{key:"highlightMaterial",get:function(){return this._highlightMaterial}},{key:"selectedMaterial",get:function(){return this._selectedMaterial}},{key:"edgeMaterial",get:function(){return this._edgeMaterial}},{key:"_checkBillboard",value:function(e){return"spherical"!==(e=e||"none")&&"cylindrical"!==e&&"none"!==e&&(this.error("Unsupported value for 'billboard': "+e+" - accepted values are 'spherical', 'cylindrical' and 'none' - defaulting to 'none'."),e="none"),e}},{key:"compile",value:function(){var e=this.scene,t=this._state,n=[e.canvas.canvas.id,e._sectionPlanesState.getHash()];t.stationary&&n.push("/s"),"none"===t.billboard?n.push("/n"):"spherical"===t.billboard?n.push("/s"):"cylindrical"===t.billboard&&n.push("/c"),n.push(";");var r=n.concat([e.gammaOutput?"go":"",e._lightsState.getHash(),t.receivesShadow?"/rs":""]).join("");this._state.drawHash!==r&&(this._state.drawHash=r,this._renderers._drawRenderer.put(),this._renderers._shadowRenderer.put(),this._renderers._emphasisFillRenderer.put(),this._renderers._emphasisEdgesRenderer.put(),this._renderers._drawRenderer.get(),this._renderers._emphasisFillRenderer.get(),this._renderers._emphasisEdgesRenderer.get());var i=n.join("");this._state.pickOcclusionHash!==i&&(this._state.pickOcclusionHash=i,this._renderers._pickMeshRenderer.put(),this._renderers._pickTriangleRenderer.put(),this._renderers._pickMeshRenderer.get(),this._state.occluder&&(this._renderers._occlusionRenderer.put(),this._renderers._occlusionRenderer.get()))}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._setWorldMatrixDirty()}},{key:"_setWorldMatrixDirty",value:function(){this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentNode)Ae.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(var t=0,n=e.length;t<n;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}},{key:"_buildWorldNormalMatrix",value:function(){this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldNormalMatrix||(this._worldNormalMatrix=Ae.mat4()),Ae.transposeMat4(this._worldMatrix,this._worldNormalMatrix),Ae.inverseMat4(this._worldNormalMatrix),this._worldNormalMatrixDirty=!1}},{key:"_setAABBDirty",value:function(){if(this.collidable)for(var e=this;e;e=e._parentNode)e._aabbDirty=!0}},{key:"_updateAABB",value:function(){this.scene._aabbDirty=!0,this._aabb||(this._aabb=Ae.AABB3()),this._buildAABB(this.worldMatrix,this._aabb),this._aabbDirty=!1}},{key:"_buildAABB",value:function(e,t){Ae.transformOBB3(e,this._geometry.obb,Ir),Ae.OBB3ToAABB3(Ir,t);var n=this._state.offset;if(t[0]+=n[0],t[1]+=n[1],t[2]+=n[2],t[3]+=n[0],t[4]+=n[1],t[5]+=n[2],this._state.origin){var r=this._state.origin;t[0]+=r[0],t[1]+=r[1],t[2]+=r[2],t[3]+=r[0],t[4]+=r[1],t[5]+=r[2]}}},{key:"rotate",value:function(e,t){return Tr[0]=e[0],Tr[1]=e[1],Tr[2]=e[2],Tr[3]=t*Ae.DEGTORAD,Ae.angleAxisToQuaternion(Tr,Pr),Ae.mulQuaternions(this.quaternion,Pr,Sr),this.quaternion=Sr,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"rotateOnWorldAxis",value:function(e,t){return Tr[0]=e[0],Tr[1]=e[1],Tr[2]=e[2],Tr[3]=t*Ae.DEGTORAD,Ae.angleAxisToQuaternion(Tr,Pr),Ae.mulQuaternions(Pr,this.quaternion,Pr),this}},{key:"rotateX",value:function(e){return this.rotate(Dr,e)}},{key:"rotateY",value:function(e){return this.rotate(Qr,e)}},{key:"rotateZ",value:function(e){return this.rotate(Rr,e)}},{key:"translate",value:function(e,t){return Ae.vec3ApplyQuaternion(this.quaternion,e,Or),Ae.mulVec3Scalar(Or,t,Vr),Ae.addVec3(this.position,Vr,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}},{key:"translateX",value:function(e){return this.translate(Dr,e)}},{key:"translateY",value:function(e){return this.translate(Qr,e)}},{key:"translateZ",value:function(e){return this.translate(Rr,e)}},{key:"stateSortCompare",value:function(e,t){return e._state.layer-t._state.layer||e._renderers._drawRenderer.getId()-t._renderers._drawRenderer.getId()||e._material._state.id-t._material._state.id||e._geometry._state.id-t._geometry._state.id}},{key:"rebuildRenderFlags",value:function(){this.renderFlags.reset(),this._getActiveSectionPlanes()?(this.renderFlags.numLayers=1,this.renderFlags.numVisibleLayers=1,this.renderFlags.visibleLayers[0]=0,this._updateRenderFlags()):this.renderFlags.culled=!0}},{key:"_updateRenderFlags",value:function(){var e=this.renderFlags,t=this._state;if(t.xrayed){var n=this._xrayMaterial._state;n.fill&&(n.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),n.edges&&(n.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}else{if(this._material._state.alpha<1||t.colorize[3]<1?e.colorTransparent=!0:e.colorOpaque=!0,t.edges)this._edgeMaterial._state.alpha<1?e.edgesTransparent=!0:e.edgesOpaque=!0;if(t.selected){var r=this._selectedMaterial._state;r.fill&&(r.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),r.edges&&(r.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}else if(t.highlighted){var i=this._highlightMaterial._state;i.fill&&(i.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),i.edges&&(i.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}},{key:"_getActiveSectionPlanes",value:function(){if(this._state.clippable){var e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(var n=0;n<t;n++){var r=e[n],i=this.renderFlags;if(r.active)if(this._state.origin){var s=Ae.planeAABB3Intersect(r.dir,r.dist,this.aabb);if(-1===s)return!1;var a=0===s;i.sectionPlanesActivePerLayer[n]=a}else i.sectionPlanesActivePerLayer[n]=!0;else i.sectionPlanesActivePerLayer[n]=!1}}return!0}},{key:"drawColorOpaque",value:function(e){this._renderers._drawRenderer.drawMesh(e,this,this._material)}},{key:"drawColorTransparent",value:function(e){this._renderers._drawRenderer.drawMesh(e,this,this._material)}},{key:"drawSilhouetteXRayed",value:function(e){this._renderers._emphasisFillRenderer.drawMesh(e,this,this._xrayMaterial)}},{key:"drawSilhouetteHighlighted",value:function(e){this._renderers._emphasisFillRenderer.drawMesh(e,this,this._highlightMaterial)}},{key:"drawSilhouetteSelected",value:function(e){this._renderers._emphasisFillRenderer.drawMesh(e,this,this._selectedMaterial)}},{key:"drawEdgesColorOpaque",value:function(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._edgeMaterial)}},{key:"drawEdgesColorTransparent",value:function(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._edgeMaterial)}},{key:"drawEdgesXRayed",value:function(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._xrayMaterial)}},{key:"drawEdgesHighlighted",value:function(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._highlightMaterial)}},{key:"drawEdgesSelected",value:function(e){this._renderers._emphasisEdgesRenderer.drawMesh(e,this,this._selectedMaterial)}},{key:"drawOcclusion",value:function(e){this._renderers._occlusionRenderer.drawMesh(e,this,this._material)}},{key:"drawShadow",value:function(e){this._renderers._shadowRenderer.drawMesh(e,this,this._material)}},{key:"drawPickMesh",value:function(e){this._renderers._pickMeshRenderer.drawMesh(e,this,this._material)}},{key:"canPickTriangle",value:function(){return this._geometry.isReadableGeometry}},{key:"drawPickTriangles",value:function(e){this._renderers._pickTriangleRenderer.drawMesh(e,this,this._material)}},{key:"pickTriangleSurface",value:function(e,t,n,r){jr(this,e,t,n,r)}},{key:"drawPickVertices",value:function(e){}},{key:"delegatePickedEntity",value:function(){return this}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),Object.values(this._renderers).forEach((function(e){return e.put()})),this.scene._renderer.putPickID(this._state.pickID),this._isObject&&(this.scene._deregisterObject(this),this._visible&&this.scene._objectVisibilityUpdated(this,!1,!1),this._xrayed&&this.scene._objectXRayedUpdated(this,!1,!1),this._selected&&this.scene._objectSelectedUpdated(this,!1,!1),this._highlighted&&this.scene._objectHighlightedUpdated(this,!1,!1),this.scene._objectColorizeUpdated(this,!1),this.scene._objectOpacityUpdated(this,!1),this.offset.some((function(e){return 0!==e}))&&this.scene._objectOffsetUpdated(this,!1)),this._isModel&&this.scene._deregisterModel(this),this.glRedraw()}}]),n}(),jr=function(){var e=Ae.vec3(),t=Ae.vec3(),n=Ae.vec3(),r=Ae.vec3(),i=Ae.vec3(),s=Ae.vec3(),a=Ae.vec4(),o=Ae.vec3(),A=Ae.vec3(),c=Ae.vec3(),l=Ae.vec3(),u=Ae.vec3(),h=Ae.vec3(),d=Ae.vec3(),f=Ae.vec3(),p=Ae.vec3(),v=Ae.vec4(),g=Ae.vec4(),m=Ae.vec4(),y=Ae.vec3(),_=Ae.vec3(),b=Ae.vec3(),w=Ae.vec3(),B=Ae.vec3(),C=Ae.vec3(),M=Ae.vec3(),k=Ae.vec3(),E=Ae.vec3(),F=Ae.vec3(),x=Ae.vec3();return function(U,I,T,P,S){var D=S.primIndex;if(null!=D&&D>-1){var Q=U.geometry._state,R=U.scene,O=R.camera,V=R.canvas;if("triangles"===Q.primitiveName){S.primitive="triangle";var L,H,N,G=D,j=Q.indices,W=Q.positions;if(j){var z=j[G+0],X=j[G+1],K=j[G+2];s[0]=z,s[1]=X,s[2]=K,S.indices=s,L=3*z,H=3*X,N=3*K}else N=(H=(L=3*G)+3)+3;if(n[0]=W[L+0],n[1]=W[L+1],n[2]=W[L+2],r[0]=W[H+0],r[1]=W[H+1],r[2]=W[H+2],i[0]=W[N+0],i[1]=W[N+1],i[2]=W[N+2],Q.compressGeometry){var Z=Q.positionsDecodeMatrix;Z&&(pt.decompressPosition(n,Z,n),pt.decompressPosition(r,Z,r),pt.decompressPosition(i,Z,i))}S.canvasPos?Ae.canvasPosToLocalRay(V.canvas,U.origin?Zt(I,U.origin):I,T,P,U.worldMatrix,S.canvasPos,e,t):S.origin&&S.direction&&Ae.worldRayToLocalRay(U.worldMatrix,S.origin,S.direction,e,t),Ae.normalizeVec3(t),Ae.rayPlaneIntersect(e,t,n,r,i,a),S.localPos=a,S.position=a,v[0]=a[0],v[1]=a[1],v[2]=a[2],v[3]=1,Ae.transformVec4(U.worldMatrix,v,g),o[0]=g[0],o[1]=g[1],o[2]=g[2],S.canvasPos&&U.origin&&(o[0]+=U.origin[0],o[1]+=U.origin[1],o[2]+=U.origin[2]),S.worldPos=o,Ae.transformVec4(O.matrix,g,m),A[0]=m[0],A[1]=m[1],A[2]=m[2],S.viewPos=A,Ae.cartesianToBarycentric(a,n,r,i,c),S.bary=c;var J=Q.normals;if(J){if(Q.compressGeometry){var Y=3*z,q=3*X,$=3*K;pt.decompressNormal(J.subarray(Y,Y+2),l),pt.decompressNormal(J.subarray(q,q+2),u),pt.decompressNormal(J.subarray($,$+2),h)}else l[0]=J[L],l[1]=J[L+1],l[2]=J[L+2],u[0]=J[H],u[1]=J[H+1],u[2]=J[H+2],h[0]=J[N],h[1]=J[N+1],h[2]=J[N+2];var ee=Ae.addVec3(Ae.addVec3(Ae.mulVec3Scalar(l,c[0],y),Ae.mulVec3Scalar(u,c[1],_),b),Ae.mulVec3Scalar(h,c[2],w),B);S.worldNormal=Ae.normalizeVec3(Ae.transformVec3(U.worldNormalMatrix,ee,C))}var te=Q.uv;if(te){if(d[0]=te[2*z],d[1]=te[2*z+1],f[0]=te[2*X],f[1]=te[2*X+1],p[0]=te[2*K],p[1]=te[2*K+1],Q.compressGeometry){var ne=Q.uvDecodeMatrix;ne&&(pt.decompressUV(d,ne,d),pt.decompressUV(f,ne,f),pt.decompressUV(p,ne,p))}S.uv=Ae.addVec3(Ae.addVec3(Ae.mulVec2Scalar(d,c[0],M),Ae.mulVec2Scalar(f,c[1],k),E),Ae.mulVec2Scalar(p,c[2],F),x)}}}}}(),Wr=function(e,t,n,r,i){var s,a,o=i.programVariables,A=n.decodedUv,c=n.worldNormal,l=n.viewNormal,u=e.scene,h=u.canvas.gl,d=e._state.background,f=e._geometry._state,v=f.compressGeometry,g="points"===f.primitiveName,m=o.createUniform("float","pointSize"),y=o.createUniform("mat4","modelMatrix"),_=o.createUniform("mat4","modelNormalMatrix"),b=o.createUniform("vec3","offset"),w=o.createUniform("vec3","scale"),B=o.createUniform("mat4","positionsDecodeMatrix"),C=o.createUniform("mat3","uvDecodeMatrix"),M=o.createUniform("mat4","viewMatrix"),E=o.createUniform("mat4","viewNormalMatrix"),F=o.createUniform("mat4","projMatrix"),x=e.billboard,U=!r.dontBillboardAnything&&("spherical"===x||"cylindrical"===x),I=e.stationary,T=U&&function(e,t){return["mat4 ".concat(e,"(in mat4 matIn) {")," mat4 mat = matIn;"," mat[0].xyz = vec3(".concat(w,"[0], 0.0, 0.0);")].concat(p("spherical"===x?[" mat[1].xyz = vec3(0.0, ".concat(w,"[1], 0.0);")]:[]),[" mat[2].xyz = vec3(0.0, 0.0, 1.0);"," return mat;","}"]).forEach((function(e){return t.push(e)}))},P=(s=T&&o.createVertexDefinition("billboard",T),function(e){return s?"".concat(s,"(").concat(e,")"):e}),S=(a=T&&o.createFragmentDefinition("billboard",T),function(e){return a?"".concat(a,"(").concat(e,")"):e}),D=[];r.dontBillboardAnything?D.push("mat4 viewMatrix2 = ".concat(M,";")):(D.push("mat4 viewMatrix1 = ".concat(M,";")),I?D.push("viewMatrix1[3].xyz = vec3(0.0, 0.0, 0.0);"):d&&D.push("viewMatrix1[3] = vec4(0.0, 0.0, 0.0, 1.0);"),D.push("mat4 viewMatrix2 = ".concat(S("viewMatrix1"),";")));var Q="clipPos",R=o.createUniform("bool","clippable"),O=k(i.buildProgram(h,r.programName,{appendFragmentOutputs:function(e,t,n,i){D.forEach((function(t){return e.push(t)})),r.appendFragmentOutputs(e,t,n,i)},clippableTest:function(){return R},clippingCaps:r.clippingCaps,clipPos:d?"".concat(Q,".xyww"):Q,crossSections:u.crossSections,discardPoints:g&&r.discardPoints,getGammaFactor:u.gammaOutput&&function(){return u.gammaFactor},getLogDepth:!r.dontGetLogDepth&&u.logarithmicDepthBufferEnabled&&function(e){return e},getPointSize:r.setupPointSize&&g&&function(){return m},getVertexData:function(){var e=l&&l.needed&&"vec3 ".concat(l," = normalize((").concat(P(E)," * vec4(").concat(c,", 0.0)).xyz);"),n=[];if(n.push("vec4 localPosition = vec4(".concat(t.position,", 1.0);")),v&&n.push("localPosition = ".concat(B," * localPosition;")),n.push("vec4 worldPosition = ".concat(P(y)," * localPosition;")),n.push("worldPosition.xyz = worldPosition.xyz + ".concat(b,";")),r.dontBillboardAnything?n.push("vec4 viewPosition = ".concat(M," * worldPosition;")):(n.push("mat4 viewMatrix1 = ".concat(M,";")),I?n.push("viewMatrix1[3].xyz = vec3(0.0, 0.0, 0.0);"):d&&n.push("viewMatrix1[3] = vec4(0.0, 0.0, 0.0, 1.0);"),n.push("mat4 viewMatrix2 = ".concat(P("viewMatrix1"),";")),n.push("vec4 viewPosition = ".concat(U?"".concat(P("viewMatrix1 * ".concat(y))," * localPosition"):"viewMatrix2 * worldPosition",";"))),A&&A.needed&&n.push("vec2 ".concat(A," = ").concat(v?"(".concat(C," * vec3(").concat(t.uv,", 1.0)).xy"):t.uv,";")),c&&c.needed){var i=v?"".concat(o.commonLibrary.octDecode,"(").concat(t.normal,".xy)"):t.normal;n.push("vec3 ".concat(c," = (").concat(P(_)," * vec4(").concat(i,", 0.0)).xyz;"))}return e&&n.push(e),n.push("vec4 ".concat(Q," = ").concat(F," * viewPosition;")),n},projMatrix:F,sectionPlanesState:u._sectionPlanesState,testPerspectiveForGl_FragDepth:!0,usePickClipPos:r.isPick,worldPositionAttribute:"worldPosition"}),2),V=O[0],L=O[1];if(L)return{errors:L};var H=V.inputSetters,N=null,G=null;return{destroy:function(){return V.destroy()},drawMesh:function(e,n,i){if(!(r.skipIfTransparent&&i.alpha<1)){var s=i._state,a=n._state,o=n._geometry,A=o._state,c=e.viewParams,l=r.canActAsBackground&&d;e.lastProgramId!==V.id&&(e.lastProgramId=V.id,V.bind(),e.useProgram++,N=null,G=null,l&&h.depthFunc(h.LEQUAL)),s.id!==N&&(e.backfaces!==s.backfaces&&(s.backfaces?h.disable(h.CULL_FACE):h.enable(h.CULL_FACE),e.backfaces=s.backfaces),r.dontSetFrontFace||e.frontface===s.frontface||(h.frontFace(s.frontface?h.CCW:h.CW),e.frontface=s.frontface),r.drawEdges&&e.lineWidth!==s.edgeWidth&&(h.lineWidth(s.edgeWidth),e.lineWidth=s.edgeWidth),r.setsLineWidth&&e.lineWidth!==s.lineWidth&&(h.lineWidth(s.lineWidth),e.lineWidth=s.lineWidth),N=s.id);var u,f,p,v=!r.useShadowView&&n.origin;u=c.projMatrix,f=v?e.getRTCViewMatrix(a.originHash,v):c.viewMatrix,p=function(e,t){return e.setInputValue&&e.setInputValue(t)},p(m,i.pointSize),p(y,n.worldMatrix),p(_,n.worldNormalMatrix),p(b,n.offset),p(w,n.scale),p(B,A.positionsDecodeMatrix),p(C,A.uvDecodeMatrix),p(M,f),p(E,c.viewNormalMatrix),p(F,u),p(R,n.clippable),H.setUniforms(e,{material:i,meshColorize:n.colorize,meshPickID:n._state.pickID,mesh:{origin:n.origin,renderFlags:{sectionPlanesActivePerLayer:n.renderFlags.sectionPlanesActivePerLayer}},view:{far:c.far}});var g=function(n){var r=function(t,n){t&&t.setInputValue&&n&&(t.setInputValue(n),e.bindArray++)};r(t.position,(n||A).positionsBuf),r(t.color,A.colorsBuf),r(t.pickColor,n&&n.pickColorsBuf),r(t.uv,A.uvBuf),r(t.normal,A.normalsBuf)};if(r.trianglePick){var k=o._getPickTrianglePositions();A.id!==G&&(g({positionsBuf:k,pickColorsBuf:o._getPickTriangleColors()}),G=A.id),h.drawArrays(A.primitive,0,k.numItems/3)}else if(r.drawEdges){var x=A.primitive===h.TRIANGLES?o._getEdgeIndices():A.primitive===h.LINES&&A.indicesBuf;x&&(A.id!==G&&(g(),x.bind(),e.bindArray++,G=A.id),h.drawElements(h.LINES,x.numItems,x.itemType,0),e.drawElements++)}else A.id!==G&&(g(),A.indicesBuf&&(A.indicesBuf.bind(),e.bindArray++),G=A.id),A.indicesBuf?(h.drawElements(A.primitive,A.indicesBuf.numItems,A.indicesBuf.itemType,0),e.drawElements++):A.positionsBuf&&(h.drawArrays(h.TRIANGLES,0,A.positionsBuf.numItems),e.drawArrays++);l&&h.depthFunc(h.LESS)}}}},zr=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),r=t.call(this,e,i),he.memory.materials++,r}return I(n,[{key:"type",get:function(){return"Material"}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),he.memory.materials--}}]),n}(),Xr={opaque:0,mask:1,blend:2},Kr=["opaque","mask","blend"],Zr=function(e){m(n,zr);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({type:"PhongMaterial",ambient:Ae.vec3([1,1,1]),diffuse:Ae.vec3([1,1,1]),specular:Ae.vec3([1,1,1]),emissive:Ae.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.ambient=i.ambient,r.diffuse=i.diffuse,r.specular=i.specular,r.emissive=i.emissive,r.alpha=i.alpha,r.shininess=i.shininess,r.reflectivity=i.reflectivity,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,i.ambientMap&&(r._ambientMap=r._checkComponent("Texture",i.ambientMap)),i.diffuseMap&&(r._diffuseMap=r._checkComponent("Texture",i.diffuseMap)),i.specularMap&&(r._specularMap=r._checkComponent("Texture",i.specularMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.reflectivityMap&&(r._reflectivityMap=r._checkComponent("Texture",i.reflectivityMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.diffuseFresnel&&(r._diffuseFresnel=r._checkComponent("Fresnel",i.diffuseFresnel)),i.specularFresnel&&(r._specularFresnel=r._checkComponent("Fresnel",i.specularFresnel)),i.emissiveFresnel&&(r._emissiveFresnel=r._checkComponent("Fresnel",i.emissiveFresnel)),i.alphaFresnel&&(r._alphaFresnel=r._checkComponent("Fresnel",i.alphaFresnel)),i.reflectivityFresnel&&(r._reflectivityFresnel=r._checkComponent("Fresnel",i.reflectivityFresnel)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r._makeHash(),r}return I(n,[{key:"type",get:function(){return"PhongMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}},{key:"ambient",get:function(){return this._state.ambient},set:function(e){var t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"diffuse",get:function(){return this._state.diffuse},set:function(e){var t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"specular",get:function(){return this._state.specular},set:function(e){var t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"shininess",get:function(){return this._state.shininess},set:function(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"reflectivity",get:function(){return this._state.reflectivity},set:function(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}},{key:"normalMap",get:function(){return this._normalMap}},{key:"ambientMap",get:function(){return this._ambientMap}},{key:"diffuseMap",get:function(){return this._diffuseMap}},{key:"specularMap",get:function(){return this._specularMap}},{key:"emissiveMap",get:function(){return this._emissiveMap}},{key:"alphaMap",get:function(){return this._alphaMap}},{key:"reflectivityMap",get:function(){return this._reflectivityMap}},{key:"occlusionMap",get:function(){return this._occlusionMap}},{key:"diffuseFresnel",get:function(){return this._diffuseFresnel}},{key:"specularFresnel",get:function(){return this._specularFresnel}},{key:"emissiveFresnel",get:function(){return this._emissiveFresnel}},{key:"alphaFresnel",get:function(){return this._alphaFresnel}},{key:"reflectivityFresnel",get:function(){return this._reflectivityFresnel}},{key:"alphaMode",get:function(){return Kr[this._state.alphaMode]},set:function(e){var t=Xr[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}();function Jr(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];var n;switch(t){case"WEBGL_depth_texture":n=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":n=e.getExtension("EXT_texture_filter_anisotropic")||e.getExtension("MOZ_EXT_texture_filter_anisotropic")||e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":n=e.getExtension("WEBGL_compressed_texture_s3tc")||e.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":n=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:n=e.getExtension(t)}return e._cachedExtensions[t]=n,n}function Yr(e,t){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=t;if(1009===i)return e.UNSIGNED_BYTE;if(1017===i)return e.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return e.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return e.BYTE;if(1011===i)return e.SHORT;if(1012===i)return e.UNSIGNED_SHORT;if(1013===i)return e.INT;if(1014===i)return e.UNSIGNED_INT;if(1015===i)return e.FLOAT;if(1016===i)return e.HALF_FLOAT;if(1021===i)return e.ALPHA;if(1023===i)return e.RGBA;if(1024===i)return e.LUMINANCE;if(1025===i)return e.LUMINANCE_ALPHA;if(1026===i)return e.DEPTH_COMPONENT;if(1027===i)return e.DEPTH_STENCIL;if(1028===i)return e.RED;if(1022===i)return e.RGBA;if(1029===i)return e.RED_INTEGER;if(1030===i)return e.RG;if(1031===i)return e.RG_INTEGER;if(1033===i)return e.RGBA_INTEGER;if(33776===i||33777===i||33778===i||33779===i)if(3001===r){var s=Jr(e,"WEBGL_compressed_texture_s3tc_srgb");if(null===s)return null;if(33776===i)return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(33777===i)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(33778===i)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(33779===i)return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(null===(n=Jr(e,"WEBGL_compressed_texture_s3tc")))return null;if(33776===i)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===i)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===i)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===i)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){var a=Jr(e,"WEBGL_compressed_texture_pvrtc");if(null===a)return null;if(35840===i)return a.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return a.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return a.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return a.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){var o=Jr(e,"WEBGL_compressed_texture_etc1");return null!==o?o.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===i||37496===i){var A=Jr(e,"WEBGL_compressed_texture_etc");if(null===A)return null;if(37492===i)return 3001===r?A.COMPRESSED_SRGB8_ETC2:A.COMPRESSED_RGB8_ETC2;if(37496===i)return 3001===r?A.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:A.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){var c=Jr(e,"WEBGL_compressed_texture_astc");if(null===c)return null;if(37808===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:c.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:c.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:c.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:c.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:c.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:c.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:c.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:c.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:c.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:c.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:c.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:c.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:c.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return 3001===r?c.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:c.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===i){var l=Jr(e,"EXT_texture_compression_bptc");if(null===l)return null;if(36492===i)return 3001===r?l.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:l.COMPRESSED_RGBA_BPTC_UNORM_EXT}return 1020===i?e.UNSIGNED_INT_24_8:1e3===i?e.REPEAT:1001===i?e.CLAMP_TO_EDGE:1004===i||1005===i?e.NEAREST_MIPMAP_LINEAR:1007===i?e.LINEAR_MIPMAP_NEAREST:1008===i?e.LINEAR_MIPMAP_LINEAR:1003===i?e.NEAREST:1006===i?e.LINEAR:null}var qr=new Uint8Array([0,0,0,1]),$r=function(){function e(t){var n=t.gl,r=t.target,i=t.format,s=t.type,a=t.wrapS,o=t.wrapT,A=t.wrapR,c=t.encoding,l=t.preloadColor,u=t.premultiplyAlpha,h=t.flipY;x(this,e),this.gl=n,this.target=r||n.TEXTURE_2D,this.format=i||1023,this.type=s||1009,this.internalFormat=null,this.premultiplyAlpha=!!u,this.flipY=!!h,this.unpackAlignment=4,this.wrapS=a||1e3,this.wrapT=o||1e3,this.wrapR=A||1e3,this.encoding=c||3001,this.texture=n.createTexture(),l&&this.setPreloadColor(l),this.allocated=!0}return I(e,[{key:"setPreloadColor",value:function(e){e?(qr[0]=Math.floor(255*e[0]),qr[1]=Math.floor(255*e[1]),qr[2]=Math.floor(255*e[2]),qr[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(qr[0]=0,qr[1]=0,qr[2]=0,qr[3]=255);var t=this.gl;if(t.bindTexture(this.target,this.texture),this.target===t.TEXTURE_CUBE_MAP)for(var n=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z],r=0,i=n.length;r<i;r++)t.texImage2D(n[r],0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,qr);else t.texImage2D(this.target,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,qr);t.bindTexture(this.target,null)}},{key:"setTarget",value:function(e){this.target=e||this.gl.TEXTURE_2D}},{key:"setImage",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this.gl;void 0!==t.format&&(this.format=t.format),void 0!==t.internalFormat&&(this.internalFormat=t.internalFormat),void 0!==t.encoding&&(this.encoding=t.encoding),void 0!==t.type&&(this.type=t.type),void 0!==t.flipY&&(this.flipY=t.flipY),void 0!==t.premultiplyAlpha&&(this.premultiplyAlpha=t.premultiplyAlpha),void 0!==t.unpackAlignment&&(this.unpackAlignment=t.unpackAlignment),void 0!==t.minFilter&&(this.minFilter=t.minFilter),void 0!==t.magFilter&&(this.magFilter=t.magFilter),void 0!==t.wrapS&&(this.wrapS=t.wrapS),void 0!==t.wrapT&&(this.wrapT=t.wrapT),void 0!==t.wrapR&&(this.wrapR=t.wrapR);var r=!1;n.bindTexture(this.target,this.texture);var i=n.getParameter(n.UNPACK_FLIP_Y_WEBGL);n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,this.flipY);var s=n.getParameter(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL);n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha);var a=n.getParameter(n.UNPACK_ALIGNMENT);n.pixelStorei(n.UNPACK_ALIGNMENT,this.unpackAlignment);var o=n.getParameter(n.UNPACK_COLORSPACE_CONVERSION_WEBGL);n.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,n.NONE);var A=Yr(n,this.minFilter);n.texParameteri(this.target,n.TEXTURE_MIN_FILTER,A),A!==n.NEAREST_MIPMAP_NEAREST&&A!==n.LINEAR_MIPMAP_NEAREST&&A!==n.NEAREST_MIPMAP_LINEAR&&A!==n.LINEAR_MIPMAP_LINEAR||(r=!0);var c=Yr(n,this.magFilter);c&&n.texParameteri(this.target,n.TEXTURE_MAG_FILTER,c);var l=Yr(n,this.wrapS);l&&n.texParameteri(this.target,n.TEXTURE_WRAP_S,l);var u=Yr(n,this.wrapT);u&&n.texParameteri(this.target,n.TEXTURE_WRAP_T,u);var h=Yr(n,this.format,this.encoding),d=Yr(n,this.type),f=ei(n,this.internalFormat,h,d,this.encoding,!1);if(this.target===n.TEXTURE_CUBE_MAP){if(ge.isArray(e))for(var p=e,v=[n.TEXTURE_CUBE_MAP_POSITIVE_X,n.TEXTURE_CUBE_MAP_NEGATIVE_X,n.TEXTURE_CUBE_MAP_POSITIVE_Y,n.TEXTURE_CUBE_MAP_NEGATIVE_Y,n.TEXTURE_CUBE_MAP_POSITIVE_Z,n.TEXTURE_CUBE_MAP_NEGATIVE_Z],g=0,m=v.length;g<m;g++)n.texImage2D(v[g],0,f,h,d,p[g])}else n.texImage2D(n.TEXTURE_2D,0,f,h,d,e);r&&n.generateMipmap(this.target),n.bindTexture(this.target,null),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,i),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s),n.pixelStorei(n.UNPACK_ALIGNMENT,a),n.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,o)}},{key:"setCompressedData",value:function(e){var t=e.mipmaps,n=e.props,r=void 0===n?{}:n,i=this.gl,s=t.length;void 0!==r.format&&(this.format=r.format),void 0!==r.internalFormat&&(this.internalFormat=r.internalFormat),void 0!==r.encoding&&(this.encoding=r.encoding),void 0!==r.type&&(this.type=r.type),void 0!==r.flipY&&(this.flipY=r.flipY),void 0!==r.premultiplyAlpha&&(this.premultiplyAlpha=r.premultiplyAlpha),void 0!==r.unpackAlignment&&(this.unpackAlignment=r.unpackAlignment),void 0!==r.minFilter&&(this.minFilter=r.minFilter),void 0!==r.magFilter&&(this.magFilter=r.magFilter),void 0!==r.wrapS&&(this.wrapS=r.wrapS),void 0!==r.wrapT&&(this.wrapT=r.wrapT),void 0!==r.wrapR&&(this.wrapR=r.wrapR),i.activeTexture(i.TEXTURE0+0),i.bindTexture(this.target,this.texture);var a=t.length>1;i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,this.flipY),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),i.pixelStorei(i.UNPACK_ALIGNMENT,this.unpackAlignment),i.pixelStorei(i.UNPACK_COLORSPACE_CONVERSION_WEBGL,i.NONE);var o=Yr(i,this.wrapS);o&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,o);var A=Yr(i,this.wrapT);if(A&&i.texParameteri(this.target,i.TEXTURE_WRAP_T,A),this.type===i.TEXTURE_3D||this.type===i.TEXTURE_2D_ARRAY){var c=Yr(i,this.wrapR);c&&i.texParameteri(this.target,i.TEXTURE_WRAP_R,c),i.texParameteri(this.type,i.TEXTURE_WRAP_R,c)}a?(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,ti(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,ti(i,this.magFilter))):(i.texParameteri(this.target,i.TEXTURE_MIN_FILTER,Yr(i,this.minFilter)),i.texParameteri(this.target,i.TEXTURE_MAG_FILTER,Yr(i,this.magFilter)));var l=Yr(i,this.format,this.encoding),u=Yr(i,this.type),h=ei(i,this.internalFormat,l,u,this.encoding,!1);i.texStorage2D(i.TEXTURE_2D,s,h,t[0].width,t[0].height);for(var d=0,f=t.length;d<f;d++){var p=t[d];1023!==this.format?null!==l?i.compressedTexSubImage2D(i.TEXTURE_2D,d,0,0,p.width,p.height,l,p.data):console.warn("Attempt to load unsupported compressed texture format in .setCompressedData()"):i.texSubImage2D(i.TEXTURE_2D,d,0,0,p.width,p.height,l,u,p.data)}i.bindTexture(this.target,null)}},{key:"setProps",value:function(e){var t=this.gl;t.bindTexture(this.target,this.texture),this._uploadProps(e),t.bindTexture(this.target,null)}},{key:"_uploadProps",value:function(e){var t=this.gl;if(void 0!==e.format&&(this.format=e.format),void 0!==e.internalFormat&&(this.internalFormat=e.internalFormat),void 0!==e.encoding&&(this.encoding=e.encoding),void 0!==e.type&&(this.type=e.type),void 0!==e.minFilter){var n=Yr(t,e.minFilter);n&&(this.minFilter=e.minFilter,t.texParameteri(this.target,t.TEXTURE_MIN_FILTER,n),n!==t.NEAREST_MIPMAP_NEAREST&&n!==t.LINEAR_MIPMAP_NEAREST&&n!==t.NEAREST_MIPMAP_LINEAR&&n!==t.LINEAR_MIPMAP_LINEAR||t.generateMipmap(this.target))}if(void 0!==e.magFilter){var r=Yr(t,e.magFilter);r&&(this.magFilter=e.magFilter,t.texParameteri(this.target,t.TEXTURE_MAG_FILTER,r))}if(void 0!==e.wrapS){var i=Yr(t,e.wrapS);i&&(this.wrapS=e.wrapS,t.texParameteri(this.target,t.TEXTURE_WRAP_S,i))}if(void 0!==e.wrapT){var s=Yr(t,e.wrapT);s&&(this.wrapT=e.wrapT,t.texParameteri(this.target,t.TEXTURE_WRAP_T,s))}}},{key:"bind",value:function(e){if(this.allocated){if(this.texture){var t=this.gl;return t.activeTexture(t["TEXTURE"+e]),t.bindTexture(this.target,this.texture),!0}return!1}}},{key:"unbind",value:function(e){if(this.allocated&&this.texture){var t=this.gl;t.activeTexture(t["TEXTURE"+e]),t.bindTexture(this.target,null)}}},{key:"destroy",value:function(){this.allocated&&this.texture&&(this.gl.deleteTexture(this.texture),this.texture=null)}}]),e}();function ei(e,t,n,r,i){var s=arguments.length>5&&void 0!==arguments[5]&&arguments[5];if(null!==t){if(void 0!==e[t])return e[t];console.warn("Attempt to use non-existing WebGL internal format '"+t+"'")}var a=n;return n===e.RED&&(r===e.FLOAT&&(a=e.R32F),r===e.HALF_FLOAT&&(a=e.R16F),r===e.UNSIGNED_BYTE&&(a=e.R8)),n===e.RG&&(r===e.FLOAT&&(a=e.RG32F),r===e.HALF_FLOAT&&(a=e.RG16F),r===e.UNSIGNED_BYTE&&(a=e.RG8)),n===e.RGBA&&(r===e.FLOAT&&(a=e.RGBA32F),r===e.HALF_FLOAT&&(a=e.RGBA16F),r===e.UNSIGNED_BYTE&&(a=3001===i&&!1===s?e.SRGB8_ALPHA8:e.RGBA8),r===e.UNSIGNED_SHORT_4_4_4_4&&(a=e.RGBA4),r===e.UNSIGNED_SHORT_5_5_5_1&&(a=e.RGB5_A1)),a!==e.R16F&&a!==e.R32F&&a!==e.RG16F&&a!==e.RG32F&&a!==e.RGBA16F&&a!==e.RGBA32F||Jr(e,"EXT_color_buffer_float"),a}function ti(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}function ni(e){if(!ri(e.width)||!ri(e.height)){var t=document.createElement("canvas");t.width=ii(e.width),t.height=ii(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function ri(e){return 0==(e&e-1)}function ii(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var si=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({texture:new $r({gl:r.scene.canvas.gl}),matrix:Ae.identityMat4(),hasMatrix:i.translate&&(0!==i.translate[0]||0!==i.translate[1])||!!i.rotate||i.scale&&(0!==i.scale[0]||0!==i.scale[1]),minFilter:r._checkMinFilter(i.minFilter),magFilter:r._checkMagFilter(i.magFilter),wrapS:r._checkWrapS(i.wrapS),wrapT:r._checkWrapT(i.wrapT),flipY:r._checkFlipY(i.flipY),encoding:r._checkEncoding(i.encoding)}),r._src=null,r._image=null,r._translate=Ae.vec2([0,0]),r._scale=Ae.vec2([1,1]),r._rotate=Ae.vec2([0,0]),r._matrixDirty=!1,r.translate=i.translate,r.scale=i.scale,r.rotate=i.rotate,i.src?r.src=i.src:i.image&&(r.image=i.image),he.memory.textures++,r}return I(n,[{key:"type",get:function(){return"Texture"}},{key:"_checkMinFilter",value:function(e){return 1006!==(e=e||1008)&&1007!==e&&1008!==e&&1005!==e&&1004!==e&&(this.error("Unsupported value for 'minFilter' - supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Defaulting to LinearMipMapLinearFilter."),e=1008),e}},{key:"_checkMagFilter",value:function(e){return 1006!==(e=e||1006)&&1003!==e&&(this.error("Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),e=1006),e}},{key:"_checkWrapS",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkWrapT",value:function(e){return 1001!==(e=e||1e3)&&1002!==e&&1e3!==e&&(this.error("Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),e=1e3),e}},{key:"_checkFlipY",value:function(e){return!!e}},{key:"_checkEncoding",value:function(e){return 3e3!==(e=e||3e3)&&3001!==e&&(this.error("Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),e=3e3),e}},{key:"_update",value:function(){var e,t,n=this._state;this._matrixDirty&&(0===this._translate[0]&&0===this._translate[1]||(e=Ae.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(t=Ae.scalingMat4v([this._scale[0],this._scale[1],1]),e=e?Ae.mulMat4(e,t):t),0!==this._rotate&&(t=Ae.rotationMat4v(.0174532925*this._rotate,[0,0,1]),e=e?Ae.mulMat4(e,t):t),e&&(n.matrix=e),this._matrixDirty=!1);this.glRedraw()}},{key:"image",get:function(){return this._image},set:function(e){this._image=ni(e),this._image.crossOrigin="Anonymous",this._state.texture.setImage(this._image,this._state),this._src=null,this.glRedraw()}},{key:"src",get:function(){return this._src},set:function(e){this.scene.loading++,this.scene.canvas.spinner.processes++;var t=this,n=new Image;n.onload=function(){n=ni(n),t._state.texture.setImage(n,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},n.src=e,this._src=e,this._image=null}},{key:"translate",get:function(){return this._translate},set:function(e){this._translate.set(e||[0,0]),this._matrixDirty=!0,this._needUpdate()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1]),this._matrixDirty=!0,this._needUpdate()}},{key:"rotate",get:function(){return this._rotate},set:function(e){e=e||0,this._rotate!==e&&(this._rotate=e,this._matrixDirty=!0,this._needUpdate())}},{key:"minFilter",get:function(){return this._state.minFilter}},{key:"magFilter",get:function(){return this._state.magFilter}},{key:"wrapS",get:function(){return this._state.wrapS}},{key:"wrapT",get:function(){return this._state.wrapT}},{key:"flipY",get:function(){return this._state.flipY}},{key:"encoding",get:function(){return this._state.encoding}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.texture&&this._state.texture.destroy(),this._state.destroy(),he.memory.textures--}}]),n}(),ai=Ae.vec3(),oi=Ae.vec3();Ae.vec3();var Ai,ci=Ae.vec3([0,-1,0]),li=Ae.vec4([0,0,0,1]),ui=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._src=null,r._image=null,r._pos=Ae.vec3(),r._origin=Ae.vec3(),r._rtcPos=Ae.vec3(),r._dir=Ae.vec3(),r._size=1,r._imageSize=Ae.vec2(),r._texture=new si(w(r)),r._plane=new Gr(w(r),{geometry:new mt(w(r),Ut({center:[0,0,0],xSize:1,zSize:1,xSegments:10,zSegments:10})),material:new Zr(w(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0}),clippable:i.clippable}),r._grid=new Gr(w(r),{geometry:new mt(w(r),xt({size:1,divisions:10})),material:new Zr(w(r),{diffuse:[0,0,0],ambient:[0,0,0],emissive:[.2,.8,.2]}),position:[0,.001,0],clippable:i.clippable}),r._node=new Xt(w(r),{rotation:[0,0,0],position:[0,0,0],scale:[1,1,1],clippable:!1,children:[r._plane,r._grid]}),r._gridVisible=!1,r.visible=!0,r.gridVisible=i.gridVisible,r.position=i.position,r.rotation=i.rotation,r.dir=i.dir,r.size=i.size,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,i.image?r.image=i.image:r.src=i.src,r}return I(n,[{key:"visible",get:function(){return this._plane.visible},set:function(e){this._plane.visible=e,this._grid.visible=this._gridVisible&&e}},{key:"gridVisible",get:function(){return this._gridVisible},set:function(e){e=!1!==e,this._gridVisible=e,this._grid.visible=this._gridVisible&&this.visible}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=e.width,this._imageSize[1]=e.height,this._updatePlaneSizeFromImage(),this._src=null,this._texture.image=this._image)}},{key:"src",get:function(){return this._src},set:function(e){var t=this;if(this._src=e,this._src){this._image=null;var n=new Image;n.onload=function(){t._texture.image=n,t._imageSize[0]=n.width,t._imageSize[1]=n.height,t._updatePlaneSizeFromImage()},n.src=this._src}}},{key:"position",get:function(){return this._pos},set:function(e){this._pos.set(e||[0,0,0]),Jt(this._pos,this._origin,this._rtcPos),this._node.origin=this._origin,this._node.position=this._rtcPos}},{key:"rotation",get:function(){return this._node.rotation},set:function(e){this._node.rotation=e}},{key:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"dir",get:function(){return this._dir},set:function(e){if(this._dir.set(e||[0,0,-1]),e){var t=this.scene.center,n=[-this._dir[0],-this._dir[1],-this._dir[2]];Ae.subVec3(t,this.position,ai);var r=-Ae.dotVec3(n,ai);Ae.normalizeVec3(n),Ae.mulVec3Scalar(n,r,oi),Ae.vec3PairToQuaternion(ci,e,li),this._node.quaternion=li}}},{key:"collidable",get:function(){return this._node.collidable},set:function(e){this._node.collidable=!1!==e}},{key:"clippable",get:function(){return this._node.clippable},set:function(e){this._node.clippable=!1!==e}},{key:"pickable",get:function(){return this._node.pickable},set:function(e){this._node.pickable=!1!==e}},{key:"opacity",get:function(){return this._node.opacity},set:function(e){this._node.opacity=e}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this)}},{key:"_updatePlaneSizeFromImage",value:function(){var e=this._size,t=this._imageSize[0],n=this._imageSize[1];if(t>n){var r=n/t;this._node.scale=[e,1,e*r]}else{var i=t/n;this._node.scale=[e*i,1,e]}}}]),n}(),hi=function(e){m(n,zr);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({type:"LambertMaterial",ambient:Ae.vec3([1,1,1]),color:Ae.vec3([1,1,1]),emissive:Ae.vec3([0,0,0]),alpha:null,alphaMode:0,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:"/lam;"}),r.ambient=i.ambient,r.color=i.color,r.emissive=i.emissive,r.alpha=i.alpha,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r.backfaces=i.backfaces,r.frontface=i.frontface,r}return I(n,[{key:"type",get:function(){return"LambertMaterial"}},{key:"ambient",get:function(){return this._state.ambient},set:function(e){var t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){var t=this._state.color;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.color=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this._state.alphaMode=e<1?2:0,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),di={opaque:0,mask:1,blend:2},fi=["opaque","mask","blend"],pi=function(e){m(n,zr);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({type:"MetallicMaterial",baseColor:Ae.vec4([1,1,1]),emissive:Ae.vec4([0,0,0]),metallic:null,roughness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.baseColor=i.baseColor,r.metallic=i.metallic,r.roughness=i.roughness,r.specularF0=i.specularF0,r.emissive=i.emissive,r.alpha=i.alpha,i.baseColorMap&&(r._baseColorMap=r._checkComponent("Texture",i.baseColorMap)),i.metallicMap&&(r._metallicMap=r._checkComponent("Texture",i.metallicMap)),i.roughnessMap&&(r._roughnessMap=r._checkComponent("Texture",i.roughnessMap)),i.metallicRoughnessMap&&(r._metallicRoughnessMap=r._checkComponent("Texture",i.metallicRoughnessMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r._makeHash(),r}return I(n,[{key:"type",get:function(){return"MetallicMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/met"];this._baseColorMap&&(t.push("/bm"),this._baseColorMap._state.hasMatrix&&t.push("/mat"),t.push("/"+this._baseColorMap._state.encoding)),this._metallicMap&&(t.push("/mm"),this._metallicMap._state.hasMatrix&&t.push("/mat")),this._roughnessMap&&(t.push("/rm"),this._roughnessMap._state.hasMatrix&&t.push("/mat")),this._metallicRoughnessMap&&(t.push("/mrm"),this._metallicRoughnessMap._state.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap._state.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap._state.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/am"),this._alphaMap._state.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap._state.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{key:"baseColor",get:function(){return this._state.baseColor},set:function(e){var t=this._state.baseColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.baseColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"baseColorMap",get:function(){return this._baseColorMap}},{key:"metallic",get:function(){return this._state.metallic},set:function(e){e=null!=e?e:1,this._state.metallic!==e&&(this._state.metallic=e,this.glRedraw())}},{key:"metallicMap",get:function(){return this._attached.metallicMap}},{key:"roughness",get:function(){return this._state.roughness},set:function(e){e=null!=e?e:1,this._state.roughness!==e&&(this._state.roughness=e,this.glRedraw())}},{key:"roughnessMap",get:function(){return this._attached.roughnessMap}},{key:"metallicRoughnessMap",get:function(){return this._attached.metallicRoughnessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"emissiveMap",get:function(){return this._attached.emissiveMap}},{key:"occlusionMap",get:function(){return this._attached.occlusionMap}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"alphaMap",get:function(){return this._attached.alphaMap}},{key:"normalMap",get:function(){return this._attached.normalMap}},{key:"alphaMode",get:function(){return fi[this._state.alphaMode]},set:function(e){var t=di[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),vi={opaque:0,mask:1,blend:2},gi=["opaque","mask","blend"],mi=function(e){m(n,zr);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({type:"SpecularMaterial",diffuse:Ae.vec3([1,1,1]),emissive:Ae.vec3([0,0,0]),specular:Ae.vec3([1,1,1]),glossiness:null,specularF0:null,alpha:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.diffuse=i.diffuse,r.specular=i.specular,r.glossiness=i.glossiness,r.specularF0=i.specularF0,r.emissive=i.emissive,r.alpha=i.alpha,i.diffuseMap&&(r._diffuseMap=r._checkComponent("Texture",i.diffuseMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.specularMap&&(r._specularMap=r._checkComponent("Texture",i.specularMap)),i.glossinessMap&&(r._glossinessMap=r._checkComponent("Texture",i.glossinessMap)),i.specularGlossinessMap&&(r._specularGlossinessMap=r._checkComponent("Texture",i.specularGlossinessMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,r._makeHash(),r}return I(n,[{key:"type",get:function(){return"SpecularMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/spe"];this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat")),this._glossinessMap&&(t.push("/gm"),this._glossinessMap.hasMatrix&&t.push("/mat")),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._specularGlossinessMap&&(t.push("/sgm"),this._specularGlossinessMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),t.push(";"),e.hash=t.join("")}},{key:"diffuse",get:function(){return this._state.diffuse},set:function(e){var t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"diffuseMap",get:function(){return this._diffuseMap}},{key:"specular",get:function(){return this._state.specular},set:function(e){var t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"specularMap",get:function(){return this._specularMap}},{key:"specularGlossinessMap",get:function(){return this._specularGlossinessMap}},{key:"glossiness",get:function(){return this._state.glossiness},set:function(e){e=null!=e?e:1,this._state.glossiness!==e&&(this._state.glossiness=e,this.glRedraw())}},{key:"glossinessMap",get:function(){return this._glossinessMap}},{key:"specularF0",get:function(){return this._state.specularF0},set:function(e){e=null!=e?e:0,this._state.specularF0!==e&&(this._state.specularF0=e,this.glRedraw())}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"emissiveMap",get:function(){return this._emissiveMap}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"alphaMap",get:function(){return this._alphaMap}},{key:"normalMap",get:function(){return this._normalMap}},{key:"occlusionMap",get:function(){return this._occlusionMap}},{key:"alphaMode",get:function(){return gi[this._state.alphaMode]},set:function(e){var t=vi[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),yi={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}},_i=function(e){m(n,zr);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),r._preset="default",i.preset?(r.preset=i.preset,void 0!==i.fill&&(r.fill=i.fill),i.fillColor&&(r.fillColor=i.fillColor),void 0!==i.fillAlpha&&(r.fillAlpha=i.fillAlpha),void 0!==i.edges&&(r.edges=i.edges),i.edgeColor&&(r.edgeColor=i.edgeColor),void 0!==i.edgeAlpha&&(r.edgeAlpha=i.edgeAlpha),void 0!==i.edgeWidth&&(r.edgeWidth=i.edgeWidth),void 0!==i.backfaces&&(r.backfaces=i.backfaces),void 0!==i.glowThrough&&(r.glowThrough=i.glowThrough)):(r.fill=i.fill,r.fillColor=i.fillColor,r.fillAlpha=i.fillAlpha,r.edges=i.edges,r.edgeColor=i.edgeColor,r.edgeAlpha=i.edgeAlpha,r.edgeWidth=i.edgeWidth,r.backfaces=i.backfaces,r.glowThrough=i.glowThrough),r}return I(n,[{key:"type",get:function(){return"EmphasisMaterial"}},{key:"presets",get:function(){return yi}},{key:"fill",get:function(){return this._state.fill},set:function(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}},{key:"fillColor",get:function(){return this._state.fillColor},set:function(e){var t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}},{key:"fillAlpha",get:function(){return this._state.fillAlpha},set:function(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}},{key:"edges",get:function(){return this._state.edges},set:function(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){var t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"edgeAlpha",get:function(){return this._state.edgeAlpha},set:function(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}},{key:"edgeWidth",get:function(){return this._state.edgeWidth},set:function(e){this._state.edgeWidth=e||1,this.glRedraw()}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"glowThrough",get:function(){return this._state.glowThrough},set:function(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}},{key:"preset",get:function(){return console.warn("EmphasisMaterial.preset is deprecated and will be removed in future versions."),this._preset},set:function(e){if(console.warn("EmphasisMaterial.preset is deprecated and will be removed in future versions."),e=e||"default",this._preset!==e){var t=yi[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(yi).join(", "))}}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),bi={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}},wi=function(e){m(n,zr);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),r._preset="default",i.preset?(r.preset=i.preset,i.edgeColor&&(r.edgeColor=i.edgeColor),void 0!==i.edgeAlpha&&(r.edgeAlpha=i.edgeAlpha),void 0!==i.edgeWidth&&(r.edgeWidth=i.edgeWidth)):(r.edgeColor=i.edgeColor,r.edgeAlpha=i.edgeAlpha,r.edgeWidth=i.edgeWidth),r.edges=!1!==i.edges,r}return I(n,[{key:"type",get:function(){return"EdgeMaterial"}},{key:"presets",get:function(){return bi}},{key:"edges",get:function(){return this._state.edges},set:function(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){var t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"edgeAlpha",get:function(){return this._state.edgeAlpha},set:function(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}},{key:"edgeWidth",get:function(){return this._state.edgeWidth},set:function(e){this._state.edgeWidth=e||1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=bi[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(bi).join(", "))}}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Bi=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._state=new it({edgeColor:Ae.vec3([0,0,0]),centerColor:Ae.vec3([1,1,1]),edgeBias:0,centerBias:1,power:1}),r.edgeColor=i.edgeColor,r.centerColor=i.centerColor,r.edgeBias=i.edgeBias,r.centerBias=i.centerBias,r.power=i.power,r}return I(n,[{key:"type",get:function(){return"Fresnel"}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){this._state.edgeColor.set(e||[0,0,0]),this.glRedraw()}},{key:"centerColor",get:function(){return this._state.centerColor},set:function(e){this._state.centerColor.set(e||[1,1,1]),this.glRedraw()}},{key:"edgeBias",get:function(){return this._state.edgeBias},set:function(e){this._state.edgeBias=e||0,this.glRedraw()}},{key:"centerBias",get:function(){return this._state.centerBias},set:function(e){this._state.centerBias=null!=e?e:1,this.glRedraw()}},{key:"power",get:function(){return this._state.power},set:function(e){this._state.power=null!=e?e:1,this.glRedraw()}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Ci=function(e){m(n,Ie);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),(r=t.call(this,e,i))._type=i.type||(i.src?i.src.split(".").pop():null)||"jpg",r._pos=Ae.vec3(i.pos||[0,0,0]),r._up=Ae.vec3(i.up||[0,1,0]),r._normal=Ae.vec3(i.normal||[0,0,1]),r._height=i.height||1,r._origin=Ae.vec3(),r._rtcPos=Ae.vec3(),r._imageSize=Ae.vec2(),r._texture=new si(w(r),{flipY:!0}),r._image=new Image,"jpg"!==r._type&&"png"!==r._type&&(r.error('Unsupported type - defaulting to "jpg"'),r._type="jpg"),r._node=new Xt(w(r),{matrix:Ae.inverseMat4(Ae.lookAtMat4v(r._pos,Ae.subVec3(r._pos,r._normal,Ae.mat4()),r._up,Ae.mat4())),children:[r._bitmapMesh=new Gr(w(r),{scale:[1,1,1],rotation:[-90,0,0],collidable:i.collidable,pickable:i.pickable,opacity:i.opacity,clippable:i.clippable,geometry:new mt(w(r),Ut({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new Zr(w(r),{diffuse:[0,0,0],ambient:[0,0,0],specular:[0,0,0],diffuseMap:r._texture,emissiveMap:r._texture,backfaces:!0})})]}),i.image?r.image=i.image:i.src?r.src=i.src:i.imageData&&(r.imageData=i.imageData),r.scene._bitmapCreated(w(r)),r}return I(n,[{key:"visible",get:function(){return this._bitmapMesh.visible},set:function(e){this._bitmapMesh.visible=e}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._texture.image=this._image,this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.height,this._updateBitmapMeshScale())}},{key:"src",get:function(){return this._image.src},set:function(e){var t=this;if(e)switch(this._image.onload=function(){t._texture.image=t._image,t._imageSize[0]=t._image.width,t._imageSize[1]=t._image.height,t._updateBitmapMeshScale()},this._image.src=e,e.split(".").pop()){case"jpeg":case"jpg":this._type="jpg";break;case"png":this._type="png"}}},{key:"imageData",get:function(){var e=document.createElement("canvas"),t=e.getContext("2d");return e.width=this._image.width,e.height=this._image.height,t.drawImage(this._image,0,0),e.toDataURL("jpg"===this._type?"image/jpeg":"image/png")},set:function(e){var t=this;this._image.onload=function(){t._texture.image=image,t._imageSize[0]=image.width,t._imageSize[1]=image.height,t._updateBitmapMeshScale()},this._image.src=e}},{key:"type",get:function(){return this._type},set:function(e){"png"===(e=e||"jpg")&&"jpg"===e||(this.error("Unsupported value for `type` - supported types are `jpg` and `png` - defaulting to `jpg`"),e="jpg"),this._type=e}},{key:"pos",get:function(){return this._pos}},{key:"normal",get:function(){return this._normal}},{key:"up",get:function(){return this._up}},{key:"height",get:function(){return this._height},set:function(e){this._height=null==e?1:e,this._image&&this._updateBitmapMeshScale()}},{key:"collidable",get:function(){return this._bitmapMesh.collidable},set:function(e){this._bitmapMesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._bitmapMesh.clippable},set:function(e){this._bitmapMesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._bitmapMesh.pickable},set:function(e){this._bitmapMesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._bitmapMesh.opacity},set:function(e){this._bitmapMesh.opacity=e}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this.scene._bitmapDestroyed(this)}},{key:"_updateBitmapMeshScale",value:function(){var e=this._imageSize[1]/this._imageSize[0];this._bitmapMesh.scale=[this._height/e,1,this._height]}}]),n}(),Mi=function(e,t){var n=[],r=[];function i(e,n){for(var r,i,s=0;s<3;s++)if((r=t[3*e+s])!==(i=t[3*n+s]))return i-r;return 0}for(var s=e.slice().sort(i),a=null,o=0,A=s.length;o<A;o++)0!==o&&0===i(s[o],s[o-1])||(a=s[o]),n[s[o]]=a;for(var c=0,l=e.length;c<l;c+=3){var u=n[e[c]],h=n[e[c+1]],d=n[e[c+2]],f=u,p=h,v=d;if(u>h&&u>d?h>d?(f=u,p=h,v=d):(f=u,p=d,v=h):h>u&&h>d?u>d?(f=h,p=u,v=d):(f=h,p=d,v=u):d>u&&d>h&&(u>h?(f=d,p=u,v=h):(f=d,p=h,v=u)),r[c+0]=[f,p],r[c+1]=[p,v],f>v){var g=v;v=f,f=g}r[c+2]=[v,f]}function m(e,t){for(var n,r,i=0;i<2;i++)if(n=e[i],(r=t[i])!==n)return r-n;return 0}(r=r.slice(0,e.length)).sort(m);for(var y=0,_=0;_<r.length;_++)if(0===_||0!==m(r[_],r[_-1])){if(0!==_&&2!==y)return!1;y=1}else y++;return!(r.length>0&&2!==y)},ki=Ae.vec3(),Ei=Ae.vec3(),Fi=Ae.vec3(),xi=function(){function e(){x(this,e),this.vertices=[],this.indices=[],this.reset()}return I(e,[{key:"reset",value:function(){this.lenVertices=0,this.lenIndices=0,this.primitive=null}},{key:"setPrimitive",value:function(e){this.primitive=e}},{key:"addVertex",value:function(e){this.vertices[this.lenVertices++]=e[0],this.vertices[this.lenVertices++]=e[1],this.vertices[this.lenVertices++]=e[2]}},{key:"addIndex",value:function(e){this.indices[this.lenIndices++]=e}},{key:"volume",get:function(){var e=this.vertices,t=this.indices;if("solid"!==this.primitive&&"surface"!==this.primitive&&"triangles"!==this.primitive)return-1;if("solid"!==this.primitive&&!Mi(t,e))return-1;for(var n=0,r=0;r<this.lenIndices;r+=3){var i=3*t[r],s=3*t[r+1],a=3*t[r+2];ki[0]=e[i],ki[1]=e[i+1],ki[2]=e[i+2],Ei[0]=e[s],Ei[1]=e[s+1],Ei[2]=e[s+2],Fi[0]=e[a],Fi[1]=e[a+1],Fi[2]=e[a+2],Ae.cross3Vec3(ki,Ei,ki),n+=Ae.dotVec3(ki,Fi)}return n/6}}]),e}(),Ui=new xi,Ii=Ae.vec3(),Ti=Ae.vec3(),Pi=Ae.vec3(),Si=Ae.vec3(),Di=Ae.vec3(),Qi=Ae.vec3(),Ri=function(){function e(){x(this,e),this.vertices=[],this.indices=[],this.reset()}return I(e,[{key:"reset",value:function(){this.lenVertices=0,this.lenIndices=0}},{key:"addVertex",value:function(e){this.vertices[this.lenVertices++]=e[0],this.vertices[this.lenVertices++]=e[1],this.vertices[this.lenVertices++]=e[2]}},{key:"addIndex",value:function(e){this.indices[this.lenIndices++]=e}},{key:"surfaceArea",get:function(){for(var e=this.vertices,t=this.indices,n=0,r=0;r<this.lenIndices;r+=3){var i=3*t[r],s=3*t[r+1],a=3*t[r+2];Ii[0]=e[i],Ii[1]=e[i+1],Ii[2]=e[i+2],Ti[0]=e[s],Ti[1]=e[s+1],Ti[2]=e[s+2],Pi[0]=e[a],Pi[1]=e[a+1],Pi[2]=e[a+2],Ae.subVec3(Ii,Ti,Si),Ae.subVec3(Pi,Ti,Di),n+=.5*Ae.lenVec3(Ae.cross3Vec3(Si,Di,Qi))}return n}}]),e}(),Oi=new Ri,Vi=Ae.OBB3(),Li=Ae.OBB3(),Hi=Ae.OBB3(),Ni=function(){function e(t,n,r,i,s,a){var o=arguments.length>6&&void 0!==arguments[6]?arguments[6]:null,A=arguments.length>7&&void 0!==arguments[7]?arguments[7]:0;x(this,e),this.model=t,this.object=null,this.parent=null,this.transform=s,this.textureSet=a,this._matrixDirty=!1,this._matrixUpdateScheduled=!1,this.id=n,this.obb=null,this._aabbLocal=null,this._aabbWorld=Ae.AABB3(),this._aabbWorldDirty=!1,this.layer=o,this.portionId=A,this._color=new Uint8Array([r[0],r[1],r[2],i]),this._colorize=new Uint8Array([r[0],r[1],r[2],i]),this._colorizing=!1,this._transparent=i<255,this.numTriangles=0,this.origin=null,this.entity=null,s&&s._addMesh(this),this._volume=null,this._surfaceArea=null}return I(e,[{key:"_sceneModelDirty",value:function(){this._aabbWorldDirty=!0,this.layer.aabbChanged()}},{key:"_transformDirty",value:function(){this._matrixDirty||this._matrixUpdateScheduled||(this.model._meshMatrixDirty(this),this._matrixDirty=!0,this._matrixUpdateScheduled=!0),this._aabbWorldDirty=!0,this.layer.aabbChanged(),this.entity&&this.entity._transformDirty()}},{key:"_updateMatrix",value:function(){this.transform&&this._matrixDirty&&this.layer.setMatrix(this.portionId,this.transform.worldMatrix),this._matrixDirty=!1,this._matrixUpdateScheduled=!1}},{key:"_finalize",value:function(e){this.layer.initFlags(this.portionId,e,this._transparent)}},{key:"_finalize2",value:function(){this.layer.flushInitFlags&&this.layer.flushInitFlags()}},{key:"_setVisible",value:function(e){this.layer.setVisible(this.portionId,e,this._transparent)}},{key:"_setColor",value:function(e){this._color[0]=e[0],this._color[1]=e[1],this._color[2]=e[2],this._colorizing||this.layer.setColor(this.portionId,this._color,!1)}},{key:"_setColorize",value:function(e){e?(this._colorize[0]=e[0],this._colorize[1]=e[1],this._colorize[2]=e[2],this.layer.setColor(this.portionId,this._colorize,false),this._colorizing=!0):(this.layer.setColor(this.portionId,this._color,false),this._colorizing=!1)}},{key:"_setOpacity",value:function(e,t){var n=e<255,r=this._transparent!==n;this._color[3]=e,this._colorize[3]=e,this._transparent=n,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),r&&this.layer.setTransparent(this.portionId,t,n)}},{key:"_setOffset",value:function(e){this.layer.setOffset(this.portionId,e)}},{key:"_setHighlighted",value:function(e){this.layer.setHighlighted(this.portionId,e,this._transparent)}},{key:"_setXRayed",value:function(e){this.layer.setXRayed(this.portionId,e,this._transparent)}},{key:"_setSelected",value:function(e){this.layer.setSelected(this.portionId,e,this._transparent)}},{key:"_setEdges",value:function(e){this.layer.setEdges(this.portionId,e,this._transparent)}},{key:"_setClippable",value:function(e){this.layer.setClippable(this.portionId,e,this._transparent)}},{key:"_setCollidable",value:function(e){this.layer.setCollidable(this.portionId,e)}},{key:"_setPickable",value:function(e){this.layer.setPickable(this.portionId,e,this._transparent)}},{key:"_setCulled",value:function(e){this.layer.setCulled(this.portionId,e,this._transparent)}},{key:"canPickTriangle",value:function(){return!1}},{key:"drawPickTriangles",value:function(e,t){}},{key:"pickTriangleSurface",value:function(e){}},{key:"precisionRayPickSurface",value:function(e,t,n,r){return this.layer.precisionRayPickSurface(this.portionId,e,t,n,r)}},{key:"canPickWorldPos",value:function(){return!0}},{key:"drawPickDepths",value:function(e){this.model.drawPickDepths(e)}},{key:"drawPickNormals",value:function(e){this.model.drawPickNormals(e)}},{key:"delegatePickedEntity",value:function(){return this.parent}},{key:"getEachVertex",value:function(e){this.layer.getEachVertex&&this.layer.getEachVertex(this.portionId,e)}},{key:"getEachIndex",value:function(e){this.layer.getEachIndex&&this.layer.getEachIndex(this.portionId,e)}},{key:"isSolid",value:function(){return this.layer.solid}},{key:"volume",get:function(){if(null!==this._volume)return this._volume;switch(this.layer.primitive){case"solid":case"surface":case"triangles":Ui.reset(),Ui.setPrimitive(this.layer.primitive),this.getEachVertex((function(e){Ui.addVertex(e)})),this.getEachIndex((function(e){Ui.addIndex(e)})),this._volume=Ui.volume;break;default:this._volume=0}return this._volume}},{key:"surfaceArea",get:function(){if(null!==this._surfaceArea)return this._surfaceArea;switch(this.layer.primitive){case"solid":case"surface":case"triangles":Oi.reset(),this.getEachVertex((function(e){Oi.addVertex(e)})),this.getEachIndex((function(e){Oi.addIndex(e)})),this._surfaceArea=Oi.surfaceArea;break;default:this._surfaceArea=0}return this._surfaceArea}},{key:"aabb",get:function(){return this._aabbWorldDirty&&(Ae.AABB3ToOBB3(this._aabbLocal,Vi),this.transform?(Ae.transformOBB3(this.transform.worldMatrix,Vi,Li),Ae.transformOBB3(this.model.worldMatrix,Li,Hi),Ae.OBB3ToAABB3(Hi,this._aabbWorld)):(Ae.transformOBB3(this.model.worldMatrix,Vi,Li),Ae.OBB3ToAABB3(Li,this._aabbWorld)),this._aabbWorldDirty=!1),this._aabbWorld},set:function(e){if(this._aabbLocal=e,this.origin){this._aabbLocal=e.slice(0);var t=this.origin;this._aabbLocal[0]+=t[0],this._aabbLocal[1]+=t[1],this._aabbLocal[2]+=t[2],this._aabbLocal[3]+=t[0],this._aabbLocal[4]+=t[1],this._aabbLocal[5]+=t[2]}}},{key:"_destroy",value:function(){this.model.scene._renderer.putPickID(this.pickId)}}]),e}(),Gi=1,ji=4,Wi=8,zi=16,Xi=32,Ki=256,Zi=512,Ji=1024,Yi=2048,qi=function(e,t,n,r){var i=r&&e.createUniform("vec4","edgeColor",(function(e,t){return e(t.legacyFrameCtx.programColor)})),s=t.attributes.color,a=!r&&e.createVarying("vec4","vColor",(function(){return"vec4(".concat(s,".rgb * 0.5, ").concat(s,".a)")})),o=e.createOutput("vec4","outColor");return{programName:r?"Edges":"EdgesColor",getLogDepth:n&&function(e){return e},renderPassFlag:2,appendFragmentOutputs:function(e){return e.push("".concat(o," = ").concat(i||a,";"))}}},$i=function(e,t){var n=e.createOutput("vec4","outColor");return{programName:"Occlusion",getLogDepth:!1,renderPassFlag:0,appendFragmentOutputs:function(e){return e.push("".concat(n," = vec4(0.0, 0.0, 1.0, 1.0);"))}}},es=function(e,t,n,r){var i=e.createUniform("vec4","silhouetteColor",(function(e,t){return e(t.legacyFrameCtx.programColor)})),s=e.createVarying("float","vAlpha",(function(){return"".concat(t.attributes.color,".a")})),a=e.createOutput("vec4","outColor");return{programName:"Silhouette",getLogDepth:n&&function(e){return e},renderPassFlag:1,appendFragmentOutputs:function(e,t,n,o){e.push("".concat(a," = ").concat(r?i:o("vec4(".concat(i,".rgb, min(").concat(i,".a, ").concat(s,"))")),";"))}}},ts=Ae.vec2(),ns=Ae.vec3(),rs=Ae.vec4(),is=Ae.mat4(),ss=Ae.vec3([0,0,0]),as=0,os=1,As=2,cs=3,ls=4,us=5,hs=6,ds=7,fs=8,ps=9,vs=10,gs=11,ms=function(e){return[Ae.safeInv(e[0]),Ae.safeInv(e[1]),Ae.safeInv(e[2])]},ys=function(e,t,n,r,i){var s,a,o=!!(e&Gi),A=!!(e&Ki),c=!!(e&Zi),l=!!(e&Ji),u=!!(e&Yi),h=!!(e&Wi),d=!!(e&ji);s=!o||d||A||c&&!r.highlightMaterial.glowThrough||l&&!r.selectedMaterial.glowThrough?as:t?As:os,a=!o||d?as:l?ls:c?cs:A?us:as;var f=0;f=n&&o&&!d?l?ps:c?fs:A?vs:u?t?ds:hs:as:as;var p=o&&!d&&h?gs:as;i[0]=s,i[1]=a,i[2]=f,i[3]=p},_s=(Ai={},function(e,t,n,r,i,s,a,o){var A=[t,"points"===n||"lines"===n?n:"triangles",!!r,!!i,!!s,!!a].join(":");A in Ai||(Ai[A]={});var c,l,u,h=Ai[A],d=e.id;if(!(d in h)){var f=e.canvas.gl,p=function(r,i,s){var a=function(){var s=gr(),a=s.programVariables,A=o(a,i);return r(a,A.geometryParameters,(function(r,o){var c,l=e.pointsMaterial,u="points"===n&&!i,h=function(){return[e._sectionPlanesState.getHash()].concat(u?[l.hash]:[]).concat(r.getHash?r.getHash():[]).join(";")},d=h(),p=function(){return d===h()},v=A.geometryParameters,g=r.incrementDrawState,m=r.isShadowProgram,y=v.attributes,_=y.position.world,b="clipPos",w=k(s.buildProgram(f,t+" "+n+" "+r.programName,{appendFragmentOutputs:r.appendFragmentOutputs,cleanerEdges:r.cleanerEdges,clipPos:b,clippableTest:(c=a.createVarying("float","vClippable",(function(){return"".concat(y.clippable," ? 1.0 : 0.0")}),"flat"),function(){return"".concat(c," > 0.0")}),clippingCaps:r.clippingCaps,crossSections:e.crossSections,discardPoints:u&&l.roundPoints,getGammaFactor:e.gammaOutput&&function(){return e.gammaFactor},getLogDepth:r.getLogDepth,getPointSize:function(){var e=[];if(u){var t=a.createUniform("float","pointSize",(function(e){return e(l.pointSize)}));if(l.perspectivePoints){var s=a.createUniform("float","nearPlaneHeight",(function(e,t){return e(t.legacyFrameCtx.nearPlaneHeight)})),o="".concat(Math.floor(l.minPerspectivePointSize),".0"),A="".concat(Math.floor(l.maxPerspectivePointSize),".0");e.push("clamp((".concat(s," * ").concat(t,") / gl_Position.w, ").concat(o,", ").concat(A,")"))}else e.push(t)}else i&&i.vertices&&e.push("1.0");return r.incPointSizeBy10&&"points"===n&&e.push("10.0"),e.length>0&&function(){return e.join(" + ")}}(),getVertexData:function(){var e,t=y.color,i=y.flags[r.renderPassFlag],s=a.createUniform("int","renderPass",(function(e,t){return e(t.renderPass)})),o=m?"(".concat(i," <= 0) || (").concat(t,".a < 1.0)"):"".concat(i," != ").concat(s),c=["if (".concat(o,") {")," gl_Position = vec4(".concat(r.vertexCullX||0,", 0.0, 0.0, 0.0);")," return;","}"].concat(A.dontCullOnAlphaZero||r.dontCullOnAlphaZero?[]:["if (".concat(t,".a == 0.0) {")," gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"," return;","}"]).concat(r.filterIntensityRange&&"points"===n&&l.filterIntensity?(e=a.createUniform("vec2","intensityRange",(function(e){ts[0]=l.minIntensity,ts[1]=l.maxIntensity,e(ts)})),["if ((".concat(t,".a < ").concat(e,"[0]) || (").concat(t,".a > ").concat(e,"[1])) {")," gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"," return;","}"]):[]),u=[];A.ensureColorAndFlagAvailable&&A.ensureColorAndFlagAvailable(u),c.forEach((function(e){return u.push(e)})),A.appendVertexData(u);var h=v.attributes.position.view;return u.push("vec4 ".concat(h," = ").concat(v.viewMatrix," * ").concat(_,";")),u.push("vec4 ".concat(b," = ").concat(v.projMatrix," * ").concat(h,";")),u},projMatrix:v.projMatrix,sectionPlanesState:e._sectionPlanesState,testPerspectiveForGl_FragDepth:"points"!==n&&"lines"!==n||i,usePickClipPos:o,worldPositionAttribute:_}),2),B=w[0],C=w[1];return C?(console.error(C),{getValid:p,destroy:function(){},drawLayer:function(e,t,n){}}):{getValid:p,destroy:function(){return B.destroy()},drawLayer:function(e,t,n){e.lastProgramId!==B.id&&(e.lastProgramId=B.id,B.bind());var r=t.origin,s=t.model,a=e.viewParams,o=ns;Ae.transformPoint3(s.matrix,r,o);var c=a.viewMatrix,l=a.projMatrix;e.snapPickOrigin&&(e.snapPickOrigin[0]=o[0],e.snapPickOrigin[1]=o[1],e.snapPickOrigin[2]=o[2]);var u={legacyFrameCtx:e,layerTextureSet:t.layerTextureSet,mesh:{layerIndex:t.layerIndex,origin:o,renderFlags:{sectionPlanesActivePerLayer:s.renderFlags.sectionPlanesActivePerLayer}},renderPass:n,view:{eye:a.eye,far:a.far,projMatrix:l,viewMatrix:Ae.compareVec3(o,ss)?c:Zt(c,o,is),viewNormalMatrix:a.viewNormalMatrix}};B.inputSetters.setUniforms(e,u),t.drawCalls[i?i.vertices?"drawVertices":"drawEdges":"drawSurface"](B.inputSetters.attributesHash,A.layerTypeInputs,{projMatrix:l,viewMatrix:Ae.compareVec3(o,ss)?c:Zt(c,o,is),viewNormalMatrix:a.viewNormalMatrix,eye:a.eye}),g&&e.drawElements++}}}))},A=s&&a();return{drawLayer:function(e,t,n){A||(A=a()),A.drawLayer(e,t,n)},revalidate:function(e){!A||!e&&A.getValid()||(A.destroy(),A=s&&a())}}},v=function(e,t){return p(e,t,!0)},g=function(e,t){return p(e,t,!1)},m=function(t,r,i,s){return function(e,t,n,r,i,s){var a=e.createVarying("vec4","vColor",(function(){var e=t.attributes,n="points"===s?"vec4(".concat(e.color,".rgb, 1.0)"):"".concat(e.color);if(r){var i=[r.getAmbientColor()].concat(r.directionalLights.map((function(n){return"max(dot(".concat(e.normal.view,", ").concat(n.getDirection(t.viewMatrix,e.position.view),"), 0.0) * ").concat(n.getColor())})));return"vec4(".concat(i.join(" + "),", 1) * ").concat(n)}return n})),o=e.createOutput("vec4","outColor");return{programName:"Color",getHash:function(){return[r?r.getHash():"-",i?"sao":"nosao"]},cleanerEdges:!0,getLogDepth:n&&function(e){return"points"!==s&&"lines"!==s?"".concat(e," + length(vec2(dFdx(").concat(e,"), dFdy(").concat(e,")))"):e},renderPassFlag:0,appendFragmentOutputs:function(e,t,n,r){"points"===s||"lines"===s?e.push("".concat(o," = ").concat(a,";")):(e.push("vec4 fragColor = ".concat(r(a),";")),e.push("".concat(o," = ").concat(i?"vec4(fragColor.rgb * ".concat(i.getAmbient(n),", fragColor.a)"):"fragColor",";")))},filterIntensityRange:!0,incrementDrawState:!0}}(t,r,e.logarithmicDepthBufferEnabled,i,s,n)},y=function(t,n,r){return r((i=t,s=n,a=e.logarithmicDepthBufferEnabled,o=i.createUniform("float","far",(function(e,t){return e(t.legacyFrameCtx.viewParams.far)})),A=i.createUniform("float","near",(function(e,t){return e(t.legacyFrameCtx.viewParams.near)})),c=i.createVarying("vec3","vViewPosition",(function(){return"".concat(s.attributes.position.view,".xyz")})),l=i.createOutput("vec4","outPackedDepth"),u=i.createFragmentDefinition("packDepth",(function(e,t){t.push("vec4 ".concat(e,"(const in float depth) {")),t.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);"),t.push(" const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);"),t.push(" vec4 res = fract(depth * bitShift);"),t.push(" res -= res.xxyz * bitMask;"),t.push(" return res;"),t.push("}")})),{programName:"PickDepth",getLogDepth:a&&function(e){return e},renderPassFlag:3,incPointSizeBy10:!0,appendFragmentOutputs:function(e){e.push("float zNormalizedDepth = abs((".concat(A," + ").concat(c,".z) / (").concat(o," - ").concat(A,"));")),e.push("".concat(l," = ").concat(u,"(zNormalizedDepth);"))}}),!0);var i,s,a,o,A,c,l,u},_=function(t,n,r){return r((i=t,s=n,a=e.logarithmicDepthBufferEnabled,o=i.createVarying("vec4","vPickColor",(function(){return"".concat(s.attributes.pickColor," / 255.0")})),A=i.createOutput("vec4","outPickColor"),{programName:"PickMesh",getLogDepth:a&&function(e){return e},renderPassFlag:3,incPointSizeBy10:!0,dontCullOnAlphaZero:!0,appendFragmentOutputs:function(e){return e.push("".concat(A," = ").concat(o,";"))}}),!0);var i,s,a,o,A},b=function(t,n,r,i){return r(function(e,t,n,r){var i=e.createVarying("vec3","vWorldPosition",(function(){return"".concat(t.attributes.position.world,".xyz")})),s=e.createVarying("vec3","vWorldNormal",(function(){return t.attributes.normal.world})),a=e.createOutput("highp ivec4","outNormal");return{programName:r?"PickNormalsFlat":"PickNormals",getLogDepth:n&&function(e){return e},renderPassFlag:3,appendFragmentOutputs:function(e){var t=r?"normalize(cross(dFdx(".concat(i,"), dFdy(").concat(i,")))"):s;e.push("".concat(a," = ivec4(").concat(t," * float(").concat(Ae.MAX_INT,"), 1.0);"))}}}(t,n,e.logarithmicDepthBufferEnabled,i),!0)},w=function(e,t,n,r,i){return n(function(e,t,n,r){var i=e.createUniform("int","layerNumber",(function(e,t){return e(t.legacyFrameCtx.snapPickLayerParams.length)})),s=e.createUniform("vec3","coordinateScaler",(function(e,t){return e(t.legacyFrameCtx.snapPickCoordinateScale)})),a=e.createVarying("vec3","vWorldPosition",(function(){return"".concat(t.attributes.position.world,".xyz")})),o=e.createVarying("vec4","vPickColor",(function(){return t.attributes.pickColor}),"flat"),A=e.createOutput("highp ivec4","outCoords",0),c=e.createOutput("highp ivec4","outNormal",1),l=e.createOutput("lowp uvec4","outPickColor",2);return{programName:n?"SnapInit":"Snap",getLogDepth:function(e){return n?"".concat(e," + length(vec2(dFdx(").concat(e,"), dFdy(").concat(e,")))"):e},renderPassFlag:3,vertexCullX:!n&&"2.0",dontCullOnAlphaZero:!n,appendFragmentOutputs:function(e){e.push("".concat(A," = ivec4(").concat(a," * ").concat(s,".xyz, ").concat(n?"-":"").concat(i,");")),n&&(e.push("".concat(c," = ").concat(r?"ivec4(1.0)":"ivec4(normalize(cross(dFdx(".concat(a,"), dFdy(").concat(a,"))) * float(").concat(Ae.MAX_INT,"), 1.0)"),";")),e.push("".concat(l," = uvec4(").concat(o,");")))}}}(e,t,r,i),!0)};h[d]="points"===n?{colorRenderers:{"sao-":{vertex:g((function(e,t,n){return n(m(e,t,null,null))}))}},occlusionRenderer:g((function(t,n,r){return r($i(t,e.logarithmicDepthBufferEnabled))})),pickDepthRenderer:g(y),pickMeshRenderer:g(_),silhouetteRenderer:g((function(t,n,r){return r(es(t,n,e.logarithmicDepthBufferEnabled,!0))})),snapInitRenderer:g((function(e,t,n){return w(e,t,n,!0,!0)})),snapVertexRenderer:g((function(e,t,n){return w(e,t,n,!1,!0)}),{vertices:!0})}:"lines"===n?{colorRenderers:{"sao-":{vertex:g((function(e,t,n){return n(m(e,t,null,null))}))}},silhouetteRenderer:g((function(t,n,r){return r(es(t,n,e.logarithmicDepthBufferEnabled,!0))})),snapInitRenderer:g((function(e,t,n){return w(e,t,n,!0,!1)})),snapEdgeRenderer:g((function(e,t,n){return w(e,t,n,!1,!1)}),{vertices:!1}),snapVertexRenderer:g((function(e,t,n){return w(e,t,n,!1,!1)}),{vertices:!0})}:{colorRenderers:(c=function(t){return mr(t,e._lightsState)},l=function(e){var t=e.createUniform("vec4","uSAOParams",(function(e,t){return e(t.legacyFrameCtx.saoParams)})),n=yr(e,"sampler2D","uOcclusionTexture",3e3,(function(e,t){return e(t.legacyFrameCtx.occlusionTexture)}));return{getAmbient:function(e){var r="".concat(e,".xy / ").concat(t,".xy"),i="".concat(t,".z"),s="".concat(t,".w");return"(smoothstep(".concat(i,", 1.0, dot(").concat(n(r),", ").concat("(255. / 256.) / vec4(256. * 256. * 256., 256. * 256., 256., 1.)",")) * ").concat(s,")")}}},u=function(t){var n=function(n,r,i){return function(e,t,n,r,i,s,a){var o=yr(e,"sampler2D","uColorMap",3001,(function(e,t){var n=t.layerTextureSet.colorTexture;n&&e(n.texture)})),A=s&&e.createUniform("float","materialAlphaCutoff",(function(e,t){return e(t.layerTextureSet.alphaCutoff)})),c=t.attributes,l=e.createVarying("vec3","vViewPosition",(function(){return"".concat(c.position.view,".xyz")})),u=e.createVarying("vec2","vUV",(function(){return c.uv})),h=e.createVarying("vec4","vColor",(function(){return c.color})),d=e.createOutput("vec4","outColor");return{programName:"ColorTexture",getHash:function(){return[r.getHash(),i?"sao":"nosao",!!a,s?"alphaCutoffYes":"alphaCutoffNo"]},getLogDepth:n.logarithmicDepthBufferEnabled&&function(e){return e},renderPassFlag:0,appendFragmentOutputs:function(e,n,s,a){e.push("vec3 viewNormal = normalize(cross(dFdx(".concat(l,"), dFdy(").concat(l,")));")),e.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),r.directionalLights.forEach((function(n){e.push("reflectedColor += max(dot(viewNormal, ".concat(n.getDirection(t.viewMatrix,l),"), 0.0) * ").concat(n.getColor(),";"))})),e.push("vec4 color = vec4(".concat(r.getAmbientColor()," + reflectedColor, 1) * ").concat(a(h),";")),e.push("vec4 sampleColor = ".concat(o(u),";")),A&&e.push("if (sampleColor.a < ".concat(A,") { discard; }")),e.push("vec4 colorTexel = color * sampleColor;"),e.push("".concat(d," = vec4(colorTexel.rgb").concat(i?" * "+i.getAmbient(s):"",", color.a);")),n&&e.push("".concat(d," = ").concat(n(d),";"))},incrementDrawState:!0}}(n,r,e,c(n),t&&l(n),i,e.gammaOutput)};return{PBR:i&&g((function(n,r,i){return i(function(e,t,n,r,i){var s=function(t,n,r){return yr(e,"sampler2D",t,n?3001:3e3,(function(e,t){var n=r(t.layerTextureSet);n&&e(n.texture)}))},a=t.attributes,o=r.getIrradiance,A=s("uColorMap",!0,(function(e){return e.colorTexture})),c=s("uMetallicRoughMap",!1,(function(e){return e.metallicRoughnessTexture})),l=s("uEmissiveMap",!0,(function(e){return e.emissiveTexture})),u=s("uNormalMap",!1,(function(e){return e.normalsTexture})),h=s("uAOMap",!1,(function(e){return e.occlusionTexture})),d=e.createVarying("vec3","vViewPosition",(function(){return"".concat(a.position.view,".xyz")})),f=e.createVarying("vec3","vViewNormal",(function(){return a.normal.view})),p=e.createVarying("vec4","vColor",(function(){return a.color})),v=e.createVarying("vec2","vUV",(function(){return a.uv})),g=e.createVarying("vec2","vMetallicRoughness",(function(){return a.metallicRoughness})),m=e.createVarying("vec3","vWorldNormal",(function(){return"".concat(a.normal.world,".xyz")})),y=e.createOutput("vec4","outColor"),_=e.createFragmentDefinition("saturate",(function(e,t){return t.push("float ".concat(e,"(const in float a) { return clamp(a, 0.0, 1.0); }"))})),b=e.createFragmentDefinition("BRDF_Specular_GGX",(function(e,t){t.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),t.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),t.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),t.push("}"),t.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" return 1.0 / ( gl * gv );"),t.push("}"),t.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" return 0.5 / max( gv + gl, 1e-6 );"),t.push("}"),t.push("float D_GGX(const in float alpha, const in float dotNH) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),t.push(" return 0.31830988618 * a2 / ( denom * denom);"),t.push("}"),t.push("vec3 ".concat(e,"(const in vec3 incidentLightDirection, const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {")),t.push(" float alpha = ( roughness * roughness );"),t.push(" vec3 halfDir = normalize( incidentLightDirection + viewEyeDir );"),t.push(" float dotNL = ".concat(_,"( dot( viewNormal, incidentLightDirection ) );")),t.push(" float dotNV = ".concat(_,"( dot( viewNormal, viewEyeDir ) );")),t.push(" float dotNH = ".concat(_,"( dot( viewNormal, halfDir ) );")),t.push(" float dotLH = ".concat(_,"( dot( incidentLightDirection, halfDir ) );")),t.push(" vec3 F = F_Schlick( specularColor, dotLH );"),t.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),t.push(" float D = D_GGX( alpha, dotNH );"),t.push(" return F * (G * D);"),t.push("}")})),w=e.createFragmentDefinition("BRDF_Specular_GGX_Environment",(function(e,t){t.push("vec3 ".concat(e,"(const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {")),t.push(" float dotNV = ".concat(_,"(dot(viewNormal, viewEyeDir));")),t.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),t.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),t.push(" vec4 r = roughness * c0 + c1;"),t.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),t.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),t.push(" return specularColor * AB.x + AB.y;"),t.push("}")})),B=e.createFragmentDefinition("perturbNormal2Arb",(function(e,t){t.push("vec3 ".concat(e,"( vec3 eye_pos, vec3 surf_norm, vec2 uv, vec4 texel ) {")),t.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),t.push(" return surf_norm;"),t.push(" }"),t.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),t.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),t.push(" vec2 st0 = dFdx( uv.st );"),t.push(" vec2 st1 = dFdy( uv.st );"),t.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),t.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),t.push(" vec3 N = normalize( surf_norm );"),t.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),t.push(" mat3 tsn = mat3( S, T, N );"),t.push(" return normalize( tsn * mapN );"),t.push("}")}));return{programName:"PBR",getHash:function(){return[r.getHash(),i?"sao":"nosao",!!n.gammaOutput]},getLogDepth:n.logarithmicDepthBufferEnabled&&function(e){return e},renderPassFlag:0,clippingCaps:n._sectionPlanesState.clippingCaps&&y,incrementDrawState:!0,appendFragmentOutputs:function(e,n,s){if(e.push("const float PI = 3.14159265359;"),e.push("vec3 reflDiff = vec3(0.0);"),e.push("vec3 reflSpec = vec3(0.0);"),e.push("vec3 rgb = ".concat(p,".rgb;")),e.push("float opacity = ".concat(p,".a;")),e.push("vec3 baseColor = rgb;"),e.push("float specularF0 = 1.0;"),e.push("float metallic = float(".concat(g,".r) / 255.0;")),e.push("float roughness = float(".concat(g,".g) / 255.0;")),e.push("float dielectricSpecular = 0.16 * specularF0 * specularF0;"),e.push("vec4 colorTexel = ".concat(A(v),";")),e.push("baseColor *= colorTexel.rgb;"),e.push("vec3 metalRoughTexel = ".concat(c(v),".rgb;")),e.push("metallic *= metalRoughTexel.b;"),e.push("roughness *= metalRoughTexel.g;"),e.push("vec3 diffuseColor = baseColor * (1.0 - dielectricSpecular) * (1.0 - metallic);"),e.push("float specularRoughness = clamp(roughness, 0.04, 1.0);"),e.push("vec3 specularColor = mix(vec3(dielectricSpecular), baseColor, metallic);"),e.push("vec3 viewNormal = -".concat(B,"(").concat(d,", normalize(").concat(f,"), ").concat(v,", ").concat(u(v),");")),e.push("vec3 viewEyeDir = normalize(".concat(d,");")),o&&e.push("reflDiff += ".concat(o("normalize(".concat(m,")")),";")),r.getReflection){var a="normalize((vec4(".concat("reflect(viewEyeDir, viewNormal)",", 0.0) * ").concat(t.viewMatrix,").xyz)"),C="".concat("8.0"," - 0.79248 - 0.5 * log2(pow(").concat("(2.0 / pow(specularRoughness + 0.0001, 2.0) - 2.0)",", 2.0) + 1.0)"),M="0.5 * clamp(".concat(C,", 0.0, ").concat("8.0",")"),k=r.getReflection(a,M),E="".concat(w,"(viewNormal, viewEyeDir, specularColor, specularRoughness)");e.push("reflSpec += ".concat(k," * ").concat(E,";"))}r.directionalLights.forEach((function(n,r){e.push("vec3 lightDirection".concat(r," = -").concat(n.getDirection(t.viewMatrix,d),";"));var i="".concat(_,"(dot(viewNormal, lightDirection").concat(r,"))");e.push("vec3 irradiance".concat(r," = ").concat(i," * ").concat(n.getColor(),";")),e.push("reflDiff += irradiance".concat(r,";")),e.push("reflSpec += irradiance".concat(r," * PI * ").concat(b,"(lightDirection").concat(r,", viewNormal, viewEyeDir, specularColor, specularRoughness);"))})),e.push("vec3 emissiveColor = ".concat(l(v),".rgb;")),e.push("float aoFactor = ".concat(h(v),".r;"));var F="".concat(r.getAmbientColor()," * baseColor * opacity * rgb");e.push("vec3 outgoingLight = emissiveColor + reflDiff * diffuseColor + reflSpec + ".concat(F,";")),e.push("".concat(y," = vec4(outgoingLight * aoFactor").concat(i?" * ".concat(i.getAmbient(s)):"",", opacity);")),n&&e.push("".concat(y," = ").concat(n(y),";"))}}}(n,r,e,c(n),t&&l(n)))})),texture:s&&{"alphaCutoff-":g((function(e,t,r){return r(n(e,t,!1))})),"alphaCutoff+":g((function(e,t,r){return r(n(e,t,!0))}))},vertex:g(a?function(e,n,r){return r(m(e,n,c(e),t&&l(e)))}:function(n,r,i){return i((s=n,a=r,o=e.logarithmicDepthBufferEnabled,A=c(n),u=t&&l(n),h=a.attributes,d=s.createVarying("vec3","vViewPosition",(function(){return"".concat(h.position.view,".xyz")})),f=s.createVarying("vec4","vColor",(function(){return h.color})),p=s.createOutput("vec4","outColor"),{programName:"FlatColor",getHash:function(){return[A.getHash(),u?"sao":"nosao"]},cleanerEdges:!0,getLogDepth:o&&function(e){return e},renderPassFlag:0,appendFragmentOutputs:function(e,t,n,r){e.push("vec3 viewNormal = normalize(cross(dFdx(".concat(d,"), dFdy(").concat(d,")));"));var i=[A.getAmbientColor()].concat(A.directionalLights.map((function(e){return"max(dot(viewNormal, ".concat(e.getDirection(a.viewMatrix,d),"), 0.0) * ").concat(e.getColor())})));e.push("vec4 fragColor = vec4(".concat(i.join(" + "),", 1) * ").concat(r(f),";")),e.push("".concat(p," = ").concat(u?"vec4(fragColor.rgb * ".concat(u.getAmbient(n),", fragColor.a)"):"fragColor",";"))}}));var s,a,o,A,u,h,d,f,p})}},{"sao-":u(!1),"sao+":r&&u(!0)}),depthRenderer:g((function(t,n,r){return r((i=t,s=n,a=e.logarithmicDepthBufferEnabled,o=i.createVarying("highp vec2","vHighPrecisionZW",(function(){return"".concat(s.attributes.position.clip,".zw")})),A=i.createOutput("vec4","outColor"),{programName:"Depth",getLogDepth:a&&function(e){return e},renderPassFlag:0,appendFragmentOutputs:function(e){return e.push("".concat(A," = vec4(vec3((1.0 - ").concat(o,"[0] / ").concat(o,"[1]) / 2.0), 1.0);"))}}));var i,s,a,o,A})),edgesRenderers:{uniform:g((function(t,n,r){return r(qi(t,n,e.logarithmicDepthBufferEnabled,!0))}),{vertices:!1}),vertex:g((function(t,n,r){return r(qi(t,n,e.logarithmicDepthBufferEnabled,!1))}),{vertices:!1})},occlusionRenderer:g((function(t,n,r){return r($i(t,e.logarithmicDepthBufferEnabled))})),pickDepthRenderer:v(y),pickMeshRenderer:v(_),pickNormalsFlatRenderer:v((function(e,t,n){return b(e,t,n,!0)})),pickNormalsRenderer:v((function(e,t,n){return b(e,t,n,!1)})),shadowRenderer:g((function(t,n,r){return r((s=e,a=(i=t).createOutput("vec4","outColor"),o=i.createFragmentDefinition("encodeFloat",(function(e,t){t.push("vec4 ".concat(e,"(const in float v) {")),t.push(" const vec4 bitShift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);"),t.push(" const vec4 bitMask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);"),t.push(" vec4 comp = fract(v * bitShift);"),t.push(" comp -= comp.xxyz * bitMask;"),t.push(" return comp;"),t.push("}")})),{programName:"Shadow",getLogDepth:s&&function(e){return e},renderPassFlag:0,isShadowProgram:!0,appendFragmentOutputs:function(e,t,n){return e.push("".concat(a," = ").concat(o,"(").concat(n,".z);"))}}));var i,s,a,o})),silhouetteRenderer:v((function(t,n,r){return r(es(t,n,e.logarithmicDepthBufferEnabled,!1))})),snapInitRenderer:v((function(e,t,n){return w(e,t,n,!0,!1)})),snapEdgeRenderer:v((function(e,t,n){return w(e,t,n,!1,!1)}),{vertices:!1}),snapVertexRenderer:v((function(e,t,n){return w(e,t,n,!1,!1)}),{vertices:!0})};var B=function(){return e=!1,void function t(n){n.revalidate?n.revalidate(e):Object.values(n).forEach((function(e){return e&&t(e)}))}(h[d]);var e};B(),e.on("compile",B),e.on("destroyed",(function(){delete h[d]}))}return h[d]}),bs=function(){function e(t,n,r){x(this,e),this.model=t,this.primitive=n,this.origin=r,this._meshes=[],this._aabb=Ae.collapseAABB3(),this._aabbDirty=!0}return I(e,[{key:"finalize",value:function(){var e=this;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,this._countsByFlag={};var t=function(t,n){var r={count:0,fromFlags:function(i,s){i&t?(r.count++,e.model[n]++):s||(r.count--,e.model[n]--)}};e._countsByFlag[t]=r};t(Gi,"numVisibleLayerPortions"),t(ji,"numCulledLayerPortions"),t(Wi,"numPickableLayerPortions"),t(zi,"numClippableLayerPortions"),t(Ki,"numXRayedLayerPortions"),t(Zi,"numHighlightedLayerPortions"),t(Ji,"numSelectedLayerPortions"),this._renderers.edgesRenderers&&t(Yi,"numEdgesLayerPortions"),this._countsByFlagArr=Object.values(this._countsByFlag),this._numTransparentLayerPortions=0}}},{key:"aabbChanged",value:function(){this._aabbDirty=!0}},{key:"__drawLayer",value:function(e,t,n,r){if(this._countsByFlag[ji].count<this._portions.length&&this._countsByFlag[Gi].count>0){var i="points"!==this.primitive&&"lines"!==this.primitive&&[os,As,gs,cs,ls,us];if(i&&i.includes(r)){if(true!==t.backfaces){var s=this.model.scene.canvas.gl;s.disable(s.CULL_FACE),t.backfaces=true}}t.textureUnit=0,n.drawLayer(t,this,r)}}},{key:"__setVec4FromMaterialColorAlpha",value:function(e,t,n){return n[0]=e[0],n[1]=e[1],n[2]=e[2],n[3]=t,n}},{key:"__drawColor",value:function(e,t,n){if((n?this._numTransparentLayerPortions<this._portions.length:this._numTransparentLayerPortions>0)&&this._countsByFlag[Ki].count<this._portions.length){var r=n&&t.withSAO&&this._renderers.colorRenderers["sao+"]||this._renderers.colorRenderers["sao-"],i=t.pbrEnabled&&r.PBR?r.PBR:t.colorTextureEnabled&&r.texture?r.texture[this.layerTextureSet&&"number"==typeof this.layerTextureSet.alphaCutoff?"alphaCutoff+":"alphaCutoff-"]:r.vertex,s=n?os:As;this.__drawLayer(e,t,i,s)}}},{key:"drawColorOpaque",value:function(e,t){this.__drawColor(e,t,!0)}},{key:"drawColorTransparent",value:function(e,t){this.__drawColor(e,t,!1)}},{key:"drawDepth",value:function(e,t){var n=this._renderers.depthRenderer;n&&this._numTransparentLayerPortions<this._portions.length&&this._countsByFlag[Ki].count<this._portions.length&&this.__drawLayer(e,t,n,os)}},{key:"__drawSilhouette",value:function(e,t,n,r){t.programColor=this.__setVec4FromMaterialColorAlpha(n.fillColor,n.fillAlpha,rs),this.__drawLayer(e,t,this._renderers.silhouetteRenderer,r)}},{key:"drawSilhouetteXRayed",value:function(e,t){this._countsByFlag[Ki].count>0&&this.__drawSilhouette(e,t,this.model.scene.xrayMaterial,us)}},{key:"drawSilhouetteHighlighted",value:function(e,t){this._countsByFlag[Zi].count>0&&this.__drawSilhouette(e,t,this.model.scene.highlightMaterial,cs)}},{key:"drawSilhouetteSelected",value:function(e,t){this._countsByFlag[Ji].count>0&&this.__drawSilhouette(e,t,this.model.scene.selectedMaterial,ls)}},{key:"__drawVertexEdges",value:function(e,t,n){var r=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.vertex;r&&this._countsByFlag[Yi].count>0&&this.__drawLayer(e,t,r,n)}},{key:"drawEdgesColorOpaque",value:function(e,t){this._compiledPortions.edgesColorOpaqueAllowed()&&this.__drawVertexEdges(e,t,hs)}},{key:"drawEdgesColorTransparent",value:function(e,t){this._numTransparentLayerPortions>0&&this.__drawVertexEdges(e,t,ds)}},{key:"__drawUniformEdges",value:function(e,t,n,r){var i=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.uniform;i&&(t.programColor=this.__setVec4FromMaterialColorAlpha(n.edgeColor,n.edgeAlpha,rs),this.__drawLayer(e,t,i,r))}},{key:"drawEdgesHighlighted",value:function(e,t){this._countsByFlag[Zi].count>0&&this.__drawUniformEdges(e,t,this.model.scene.highlightMaterial,fs)}},{key:"drawEdgesSelected",value:function(e,t){this._countsByFlag[Ji].count>0&&this.__drawUniformEdges(e,t,this.model.scene.selectedMaterial,ps)}},{key:"drawEdgesXRayed",value:function(e,t){this._countsByFlag[Ki].count>0&&this.__drawUniformEdges(e,t,this.model.scene.xrayMaterial,vs)}},{key:"__drawPick",value:function(e,t,n){n&&this.__drawLayer(e,t,n,gs)}},{key:"drawPickMesh",value:function(e,t){this.__drawPick(e,t,this._renderers.pickMeshRenderer)}},{key:"drawPickDepths",value:function(e,t){this.__drawPick(e,t,this._renderers.pickDepthRenderer)}},{key:"drawPickNormals",value:function(e,t){var n=this._renderers.pickNormalsFlatRenderer;this.__drawPick(e,t,n)}},{key:"drawSnap",value:function(e,t,n){var r=this;t.snapPickOrigin=[0,0,0],this._aabbDirty&&(Ae.collapseAABB3(this._aabb),this._meshes.forEach((function(e){return Ae.expandAABB3(r._aabb,e.aabb)})),this._aabbDirty=!1);var i=this._aabb;t.snapPickCoordinateScale=Ae.mulVec3Scalar(ms([i[3]-i[0],i[4]-i[1],i[5]-i[2]]),Ae.MAX_INT);var s=n?this._renderers.snapInitRenderer:"edge"===t.snapMode?this._renderers.snapEdgeRenderer:this._renderers.snapVertexRenderer;this.__drawPick(e,t,s),t.snapPickLayerParams.push({origin:t.snapPickOrigin.slice(),coordinateScale:ms(t.snapPickCoordinateScale)})}},{key:"drawOcclusion",value:function(e,t){var n=this._renderers.occlusionRenderer;n&&this.__drawLayer(e,t,n,os)}},{key:"drawShadow",value:function(e,t){var n=this._renderers.shadowRenderer;n&&this.__drawLayer(e,t,n,os)}},{key:"initFlags",value:function(e,t,n){this._countsByFlagArr.forEach((function(e){return e.fromFlags(t,!0)})),n&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);var r="points"!==this.primitive;this._setFlags(e,t,n,r),this._compiledPortions.setFlags2(e,t,r)}},{key:"flushInitFlags",value:function(){this._compiledPortions.setDeferredFlags()}},{key:"setVisible",value:function(e,t,n){this._countsByFlag[Gi].fromFlags(t),this._setFlags(e,t,n)}},{key:"setCulled",value:function(e,t,n){this._countsByFlag[ji].fromFlags(t),this._setFlags(e,t,n)}},{key:"setPickable",value:function(e,t,n){this._countsByFlag[Wi].fromFlags(t),this._setFlags(e,t,n)}},{key:"setClippable",value:function(e,t){this._countsByFlag[zi].fromFlags(t),this._compiledPortions.setClippableFlags(e,t)}},{key:"setCollidable",value:function(e,t){}},{key:"setXRayed",value:function(e,t,n){this._countsByFlag[Ki].fromFlags(t),this._setFlags(e,t,n)}},{key:"setHighlighted",value:function(e,t,n){this._countsByFlag[Zi].fromFlags(t),this._setFlags(e,t,n)}},{key:"setSelected",value:function(e,t,n){this._countsByFlag[Ji].fromFlags(t),this._setFlags(e,t,n)}},{key:"setEdges",value:function(e,t,n){this._countsByFlag[Yi]&&(this._countsByFlag[Yi].fromFlags(t),this._setFlags(e,t,n))}},{key:"setTransparent",value:function(e,t,n){n?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,n)}},{key:"destroy",value:function(){this._compiledPortions&&this._compiledPortions.destroy()}}]),e}(),ws=65536,Bs=5e6,Cs=function(){function e(){x(this,e)}return I(e,[{key:"doublePrecisionEnabled",get:function(){return Ae.getDoublePrecisionEnabled()},set:function(e){Ae.setDoublePrecisionEnabled(e)}},{key:"maxDataTextureHeight",get:function(){return ws},set:function(e){(e=1024*Math.ceil(e/1024))>4096?e=4096:e<1024&&(e=1024),ws=e}},{key:"maxGeometryBatchSize",get:function(){return Bs},set:function(e){e<1e5?e=1e5:e>5e6&&(e=5e6),Bs=e}}]),e}(),Ms=function(e){for(var t=[],n=0;n<e;++n)t.push(n);return t},ks={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(ks,null,4));var e=0;Object.keys(ks).forEach((function(t){t.startsWith("size")&&(e+=ks[t])})),console.log("Total size ".concat(e," bytes (").concat((e/1e3/1e3).toFixed(2)," MB)")),console.log("Avg bytes / triangle: ".concat((e/ks.totalPolygons).toFixed(2)));var t={};Object.keys(ks).forEach((function(n){n.startsWith("size")&&(t[n]="".concat((ks[n]/e*100).toFixed(2)," % of total"))})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};var Es=new Cs,Fs=Es.maxDataTextureHeight,xs=Ae.vec3(),Us=Ae.vec3(),Is=Ae.vec4();Ae.vec4();var Ts=new Float32Array(16),Ps=new Uint8Array(4),Ss=Ae.identityMat4(),Ds=function(e){m(n,bs);var t=_(n);function n(e,r,i){var s;x(this,n),s=t.call(this,e,r,i),ks.numberOfLayers++,s._sortId="TriDTX-".concat(ks.numberOfLayers);var a=e.scene.canvas.gl,o=function(e,t){var n=[],r=0,i=[],s=0,o=[],c=0,l=[],u=0;return{len:function(){return s},accumulateIndices:function(a,h){var d=a&&a.length>0&&function(){var t=r/3;r+=a.length,n.push(a);var o=a.length/3;return function(n){var r=s;s+=3*o,A.perObjectIndexBaseOffsets.push(r/3-t);for(var a=0;a<o;a+=8)i.push(n);ks[e]+=o,ks.totalPolygons+=o}}(),f=h&&function(){var e=c/2;c+=h.length,o.push(h);var n=h.length/2;return function(r){var i=u;u+=2*n,A.perObjectEdgeIndexBaseOffsets.push(i/2-e);for(var s=0;s<n;s+=8)l.push(r);ks[t]+=n,ks.totalEdges+=n}}();return ks.numberOfGeometries++,{numTriangles:a?a.length/3:0,accumulateSubPortionId:function(e){d&&d(e),f&&f(e)}}},createDrawers:function(e,t){var A=function(t,n){return t.length>0?e([t],t.length,1,a.UNSIGNED_SHORT,"sizeDataTexturePortionIds"):n},h=A(i,{texture:null}),d=r>0&&e(n,r,3,t,"sizeDataTextureIndices"),f=A(l),p=c>0&&e(o,c,2,t,"sizeDataTextureEdgeIndices");return{indices:function(e,t){s>0&&(e.perPrimIndices.setInputValue(d),e.perPrimIdPorIds.setInputValue(h),a.drawArrays(t,0,s))},edges:function(e,t){u>0&&(e.perPrimIndices.setInputValue(p),e.perPrimIdPorIds.setInputValue(f),a.drawArrays(t,0,u))}}}}},A=s._buffer={positionsCompressed:[],lenPositionsCompressed:0,geometry8Bits:o("totalPolygons8Bits","totalEdges8Bits"),geometry16Bits:o("totalPolygons16Bits","totalEdges16Bits"),geometry32Bits:o("totalPolygons32Bits","totalEdges32Bits"),perObjectColors:[],perObjectPickColors:[],perObjectSolid:[],perObjectPositionsDecodeMatrices:[],perObjectInstancePositioningMatrices:[],perObjectVertexBases:[],perObjectIndexBaseOffsets:[],perObjectEdgeIndexBaseOffsets:[]};return s._numVertices=0,s._portions=[],s._subPortionReadableGeometries=s.model.scene.readableGeometryEnabled&&{},s._portionToSubPortionsMap=[],s._bucketGeometries={},s._primitive=r,s}return I(n,[{key:"canCreatePortion",value:function(e){var t=e.buckets.length;this._portions.length+t>65536&&ks.cannotCreatePortion.because10BitsObjectId++;var n=this._portions.length+t<=65536,r=void 0!==e.geometryId&&null!==e.geometryId?"".concat(e.geometryId,"#").concat(0):"".concat(e.id,"#").concat(0);if(!this._bucketGeometries[r]){var i=this._buffer,s=Math.max(i.geometry8Bits.len(),i.geometry16Bits.len(),i.geometry32Bits.len()),a=0,o=0;e.buckets.forEach((function(e){a+=e.positionsCompressed.length/3,o+=e.indices.length/3})),(this._numVertices+a>4096*Fs||s+o>4096*Fs)&&ks.cannotCreatePortion.becauseTextureSize++,n&&(n=this._numVertices+a<=4096*Fs&&s+o<=4096*Fs)}return n}},{key:"createPortion",value:function(e,t){var n=this,r=this._buffer,i=t.buckets.map((function(e,i){var s,a,o,A=(null!==(s=t.geometryId)&&void 0!==s?s:t.id)+"#"+i;if(!(A in n._bucketGeometries)){var c=function(e,t,n){if(e){var r=8*Math.ceil(e.length/t/8)*t,i=new Uint32Array(r);return i.set(e),ks[n]+=2*(i.length-e.length),i}return e};e.indices=c(e.indices,3,"overheadSizeAlignementIndices"),e.edgeIndices=c(e.edgeIndices,2,"overheadSizeAlignementEdgeIndices");var l=e.positionsCompressed;r.positionsCompressed.push(l);var u=l.length/3;n._numVertices+=u;var h=r.lenPositionsCompressed/3;r.lenPositionsCompressed+=l.length,n._bucketGeometries[A]={vertexBase:h,geometryData:(a=e.indices,o=e.edgeIndices,u<=256?r.geometry8Bits.accumulateIndices(a,o):u<=65536?r.geometry16Bits.accumulateIndices(a,o):r.geometry32Bits.accumulateIndices(a,o))}}var d=n._bucketGeometries[A];r.perObjectPositionsDecodeMatrices.push(t.positionsDecodeMatrix),r.perObjectInstancePositioningMatrices.push(t.meshMatrix||Ss),r.perObjectSolid.push(!!t.solid),r.perObjectPickColors.push(t.pickColor),r.perObjectVertexBases.push(d.vertexBase);var f=t.colors,p=t.color;r.perObjectColors.push(f?[255*f[0],255*f[1],255*f[2],255]:[p[0],p[1],p[2],t.opacity]);var v=n._portions.length;return n._portions.push({}),d.geometryData.accumulateSubPortionId(v),n._subPortionReadableGeometries&&(n._subPortionReadableGeometries[v]={indices:e.indices,positionsCompressed:e.positionsCompressed,positionsDecodeMatrix:t.positionsDecodeMatrix}),ks.numberOfPortions++,v})),s=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(i),this.model.numPortions++,this._meshes.push(e),s}},{key:"compilePortions",value:function(){var e=this._buffer,t=this.model,n=this._portions.length,r=this.origin,i=this._portionToSubPortionsMap,s=this._primitive,a=this._sortId,o=this._subPortionReadableGeometries,A=t.scene,c=A.canvas.gl,l=Qs(c,n,32,c.UNSIGNED_BYTE,512,(function(t){for(var r=function(e){return[e>>24&255,e>>16&255,e>>8&255,255&e]},i=0;i<n;i++)t.set(e.perObjectColors[i],32*i+0),t.set(e.perObjectPickColors[i],32*i+4),t.set([0,0,0,0],32*i+8),t.set([0,0,0,0],32*i+12),t.set(r(e.perObjectVertexBases[i]),32*i+16),t.set(r(e.perObjectIndexBaseOffsets[i]),32*i+20),t.set(r(e.perObjectEdgeIndexBaseOffsets[i]),32*i+24),t.set([e.perObjectSolid[i]?1:0,0,0,0],32*i+28)}),"sizeDataColorsAndFlags",!0),u=l.textureData,h=function(e,t,n,r,i,s,a){return Qs(c,t,n,r,i,(function(t){for(var n=0,r=0,i=e.length;n<i;n++){var s=e[n];t.set(s,r),r+=s.length}}),s,a)},d=function(e,t,n){var r=e.length;if(0===r)throw"num "+t+" matrices===0";return h(e,r,16,c.FLOAT,512,t,n)},f=d(e.perObjectInstancePositioningMatrices,"sizeDataInstancesMatrices",!0),p=f.textureData,v=d(e.perObjectPositionsDecodeMatrices,"sizeDataPositionDecodeMatrices",!1),g=function(e,t,n,r,i){return h(e,t/n,n,r,4096,i,!1)},m=g(e.positionsCompressed,e.lenPositionsCompressed,3,c.UNSIGNED_SHORT,"sizeDataTexturePositions"),y=e.geometry8Bits.createDrawers(g,c.UNSIGNED_BYTE),_=e.geometry16Bits.createDrawers(g,c.UNSIGNED_SHORT),b=e.geometry32Bits.createDrawers(g,c.UNSIGNED_INT);this._buffer=null;var w,B,C=!1,M=!1,k=!1,E=0,F=function(){C=!0},x=A.on("rendering",(function(){M&&(C=!1,M=!1,u.reloadData()),E=0})),U=function(e,n){var r=i[e];if(r)for(var s=0,a=r.length;s<a;s++)n(r[s]);else t.error("portion not found: "+e)},I=function(e,t,n,r){var i=C||r;i?M=!0:++E>=10&&F(),u.setData(n,e,t,!i)},T=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];Ps.set([t&zi?255:0,0,1,2]),U(e,(function(e){return I(e,3,Ps,n)}))};return{edgesColorOpaqueAllowed:function(){return!A.logarithmicDepthBufferEnabled||(A._loggedWarning||(console.log("Edge enhancement for SceneModel data texture layers currently disabled with logarithmic depth buffer"),A._loggedWarning=!0),!1)},sortId:a,setClippableFlags:T,setFlags:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];ys(t,n,!0,A,Ps),U(e,(function(e){return I(e,2,Ps,r)}))},setFlags2:T,setDeferredFlags:function(){},setColor:function(e,t){Ps.set(t),U(e,(function(e){return I(e,0,Ps,!1)}))},setMatrix:function(e,t){U(e,(function(e){var n=C;n?M=!0:++E>=10&&F(),Ts.set(t),p.setData(Ts,e,0,!n)}))},setOffset:function(e,t){},getEachIndex:function(e,t){o&&U(e,(function(e){return o[e].indices.forEach((function(e){return t(e)}))}))},getEachVertex:function(e,n){o&&U(e,(function(e){for(var i=o[e],s=i.positionsCompressed,a=i.positionsDecodeMatrix,A=Is,c=0,l=s.length;c<l;c+=3)A[0]=s[c],A[1]=s[c+1],A[2]=s[c+2],A[3]=1,Ae.decompressPosition(A,a),Ae.mulMat4v4(t.worldMatrix,A,A),Ae.addVec3(r,A,A),n(A)}))},precisionRayPickSurface:function(e,t,n,r,i){return!1},renderers:_s(A,"dtx",s,t.saoEnabled,!1,!1,!0,(function(e,t){return Rs(e,!t)})),drawCalls:(w=function(e){var n=function(e,t){return e.setInputValue&&e.setInputValue(t)};return function(i,s,a){n(s.worldMatrix,t.rotationMatrix),n(s.viewMatrix,a.viewMatrix),n(s.projMatrix,a.projMatrix);var o=Ae.transformPoint3(t.matrix,r,xs);n(s.uCameraEyeRtc,Ae.subVec3(a.eye,o,Us)),n(s.perObjPosDecode,v),n(s.perVertIdCoords,m),n(s.perObjColsFlags,l),n(s.perObjectMatrix,f),e(s)}},B=function(e){return w((function(t){y.edges(t,e),_.edges(t,e),b.edges(t,e)}))},{drawVertices:B(c.POINTS),drawEdges:B(c.LINES),drawSurface:w((function(e){var t=c.TRIANGLES;y.indices(e,t),_.indices(e,t),b.indices(e,t)}))}),destroy:function(){k||(A.off(x),k=!0)}}}}]),n}(),Qs=function(e,t,n,r,i,s,a,o){if(n>4&&n%4>0)throw"Unhandled data size "+n;var A=Math.ceil(n/4),c=n/A,l=k(function(){switch(r){case e.UNSIGNED_BYTE:return[Uint8Array].concat(p(1===c?[e.R8UI,e.RED_INTEGER]:2===c?[e.RG8UI,e.RG_INTEGER]:3===c?[e.RGB8UI,e.RGB_INTEGER]:[e.RGBA8UI,e.RGBA_INTEGER]));case e.UNSIGNED_SHORT:return[Uint16Array].concat(p(1===c?[e.R16UI,e.RED_INTEGER]:2===c?[e.RG16UI,e.RG_INTEGER]:3===c?[e.RGB16UI,e.RGB_INTEGER]:[e.RGBA16UI,e.RGBA_INTEGER]));case e.UNSIGNED_INT:return[Uint32Array].concat(p(1===c?[e.R32UI,e.RED_INTEGER]:2===c?[e.RG32UI,e.RG_INTEGER]:3===c?[e.RGB32UI,e.RGB_INTEGER]:[e.RGBA32UI,e.RGBA_INTEGER]));case e.FLOAT:return[Float32Array].concat(p(1===c?[e.R32F,e.RED]:2===c?[e.RG32F,e.RG]:3===c?[e.RGB32F,e.RGB]:[e.RGBA32F,e.RGBA]));default:throw"Unhandled data type "+r}}(),3),u=l[0],h=l[1],d=l[2],f=i*A,v=Math.ceil(t/i);if(0===v)throw"texture height===0";var g=new u(f*v*c);ks[a]+=g.byteLength,ks.numberOfTextures++,s(g);var m=e.createTexture();return e.bindTexture(e.TEXTURE_2D,m),e.texStorage2D(e.TEXTURE_2D,1,h,f,v),e.texSubImage2D(e.TEXTURE_2D,0,0,0,f,v,d,r,g),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),{bind:function(t){return e.activeTexture(e["TEXTURE"+t]),e.bindTexture(e.TEXTURE_2D,m),!0},unbind:function(e){},textureData:o&&{setData:function(t,s){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,o=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(g.set(t,s*n+a*c),o){e.bindTexture(e.TEXTURE_2D,m);var l=s%i*A+a,u=Math.floor(s/i),h=t.length/c;e.texSubImage2D(e.TEXTURE_2D,0,l,u,h,1,d,r,t)}},reloadData:function(){e.bindTexture(e.TEXTURE_2D,m),e.texSubImage2D(e.TEXTURE_2D,0,0,0,f,v,d,r,g)}}}},Rs=function(e,t){var n=function(t,n){var r=e.createUniform(t,n),i=function(e){return"texelFetch(".concat(r,", ").concat(e,", 0)")};return i.map=r,i},r=n("highp usampler2D","perPrimIndices"),i=n("mediump usampler2D","perPrimIdPorIds"),s=n("highp sampler2D","perObjPosDecode"),a=n("mediump usampler2D","perVertIdCoords"),o=n("lowp usampler2D","perObjColsFlags"),A=n("highp sampler2D","perObjectMatrix"),c=e.createUniform("mat4","worldMatrix"),l=e.createUniform("mat4","viewMatrix"),u=e.createUniform("mat4","projMatrix"),h=e.createUniform("vec3","uCameraEyeRtc"),d=function(e){var t={toString:function(){return t.needed=!0,e}};return t},f=d("colorA"),p=d("pickColor"),v=d("worldNormal"),g=d("viewNormal"),m=function(e){return o("ivec2(objectIndexCoords.x*8+".concat(e,", objectIndexCoords.y)"))};return{geometryParameters:{attributes:{clippable:"(flags2.r > 0u)",color:f,flags:Ms(4).map((function(e){return"int(flags[".concat(e,"])")})),metallicRoughness:null,normal:{view:g,world:v},pickColor:p,position:{clip:"gl_Position",view:"viewPosition",world:"worldPosition"},uv:null},projMatrix:u,viewMatrix:l},ensureColorAndFlagAvailable:function(e){e.push("int primitiveIndex = gl_VertexID / "+(t?3:2)+";"),e.push("int h_packed_object_id_index = (primitiveIndex >> 3) & 4095;"),e.push("int v_packed_object_id_index = (primitiveIndex >> 3) >> 12;"),e.push("int objectIndex = int(".concat(i("ivec2(h_packed_object_id_index, v_packed_object_id_index)"),".r);")),e.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);"),e.push("uvec4 flags = ".concat(m(2),";")),e.push("uvec4 flags2 = ".concat(m(3),";")),f.needed&&e.push("vec4 ".concat(f," = vec4(").concat(m(0),") / 255.0;"))},appendVertexData:function(e){var n=function(e){return A("ivec2(objectIndexCoords.x*4+".concat(e,", objectIndexCoords.y)"))};e.push("mat4 objectInstanceMatrix = mat4(".concat(n(0),", ").concat(n(1),", ").concat(n(2),", ").concat(n(3),");"));var i=function(e){return s("ivec2(objectIndexCoords.x*4+".concat(e,", objectIndexCoords.y)"))};if(e.push("mat4 objectDecodeAndInstanceMatrix = objectInstanceMatrix * mat4(".concat(i(0),", ").concat(i(1),", ").concat(i(2),", ").concat(i(3),");")),e.push("ivec4 packedVertexBase = ivec4(".concat(m(4),");")),e.push("ivec4 packedIndexBaseOffset = ivec4(".concat(m(t?5:6),");")),e.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;"),e.push("int h_index = (primitiveIndex - indexBaseOffset) & 4095;"),e.push("int v_index = (primitiveIndex - indexBaseOffset) >> 12;"),e.push("ivec3 vertexIndices = ivec3(".concat(r("ivec2(h_index, v_index)"),");")),e.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;"),t){e.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;"),e.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;"),e.push("uint solid = ".concat(m(7),".r;"));var o=function(e){return"vec3(".concat(a("ivec2(indexPositionH[".concat(e,"], indexPositionV[").concat(e,"])")),")")};e.push("vec3 positions[] = vec3[](".concat(o(0),", ").concat(o(1),", ").concat(o(2),");")),e.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));"),e.push("vec3 position = positions[gl_VertexID % 3];"),v.needed&&e.push("vec3 worldNormal = -normalize((transpose(inverse(".concat(c," * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);")),g.needed&&e.push("vec3 viewNormal = -normalize((transpose(inverse(".concat(l," * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);")),e.push("if (solid != 1u) {"),e.push(" if (".concat("(".concat(u,"[2][3] == - 1.0)"),") {")),e.push(" vec3 uCameraEyeRtcInQuantizedSpace = (inverse(".concat(c," * objectDecodeAndInstanceMatrix) * vec4(").concat(h,", 1)).xyz;")),e.push(" if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {"),e.push(" position = positions[2 - (gl_VertexID % 3)];"),v.needed&&e.push(" worldNormal = -worldNormal;"),g.needed&&e.push(" viewNormal = -viewNormal;"),e.push(" }"),e.push(" } else {"),g.needed||e.push(" vec3 viewNormal = -normalize((transpose(inverse(".concat(l," * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);")),e.push(" if (viewNormal.z < 0.0) {"),e.push(" position = positions[2 - (gl_VertexID % 3)];"),v.needed&&e.push(" worldNormal = -worldNormal;"),g.needed&&e.push(" viewNormal = -viewNormal;"),e.push(" }"),e.push(" }"),e.push("}")}else e.push("int indexPositionH = uniqueVertexIndexes[gl_VertexID % 2] & 4095;"),e.push("int indexPositionV = uniqueVertexIndexes[gl_VertexID % 2] >> 12;"),e.push("vec3 position = vec3(".concat(a("ivec2(indexPositionH, indexPositionV)"),");"));p.needed&&e.push("vec4 pickColor = vec4(".concat(m(1),");")),e.push("vec4 worldPosition = ".concat(c," * (objectDecodeAndInstanceMatrix * vec4(position, 1.0));"))},layerTypeInputs:{perPrimIndices:r.map,perPrimIdPorIds:i.map,perObjPosDecode:s.map,perVertIdCoords:a.map,perObjColsFlags:o.map,perObjectMatrix:A.map,worldMatrix:c,viewMatrix:l,projMatrix:u,uCameraEyeRtc:h}}},Os=Ae.mat4(),Vs=Ae.mat4();function Ls(e,t,n){for(var r=e.length,i=new Uint16Array(r),s=t[0],a=t[1],o=t[2],A=t[3]-s,c=t[4]-a,l=t[5]-o,u=65525,h=u/A,d=u/c,f=u/l,p=function(e){return e>=0?e:0},v=0;v<r;v+=3)i[v+0]=Math.floor(p(e[v+0]-s)*h),i[v+1]=Math.floor(p(e[v+1]-a)*d),i[v+2]=Math.floor(p(e[v+2]-o)*f);return Ae.identityMat4(Os),Ae.translationMat4v(t,Os),Ae.identityMat4(Vs),Ae.scalingMat4v([A/u,c/u,l/u],Vs),Ae.mulMat4(Os,Vs,n),i}function Hs(e,t){var n=e[0],r=e[1],i=e[2],s=e[3]-n,a=e[4]-r,o=e[5]-i,A=65525;return Ae.identityMat4(Os),Ae.translationMat4v(e,Os),Ae.identityMat4(Vs),Ae.scalingMat4v([s/A,a/A,o/A],Vs),Ae.mulMat4(Os,Vs,t),t}function Ns(e,t,n){var r=e[0]/(Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2])),i=e[1]/(Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2]));if(e[2]<0){var s,a;s=(1-Math.abs(i))*(r>=0?1:-1),a=(1-Math.abs(r))*(i>=0?1:-1),r=s,i=a}return new Int8Array([Math[t](127.5*r+(r<0?-1:0)),Math[n](127.5*i+(i<0?-1:0))])}function Gs(e){var t=e[0],n=e[1];t/=t<0?127:128,n/=n<0?127:128;var r=1-Math.abs(t)-Math.abs(n);r<0&&(t=(1-Math.abs(n))*(t>=0?1:-1),n=(1-Math.abs(t))*(n>=0?1:-1));var i=Math.sqrt(t*t+n*n+r*r);return[t/i,n/i,r/i]}var js,Ws,zs=new Float32Array(1),Xs=new Float32Array(4),Ks=new Float32Array(3),Zs=Ae.mat4(),Js=Ae.vec4([0,0,0,1]),Ys=Ae.vec4(),qs=Ae.vec3(),$s=Ae.vec3(),ea=Ae.vec3(),ta=Ae.vec3(),na=Ae.vec3(),ra=Ae.vec3(),ia=Ae.vec3(),sa=new Uint8Array(4),aa=new Float32Array(96),oa=function(e){for(var t=[],n=0;n<e;++n)t.push(n);return t},Aa=function(e,t){e.set(t);for(var n=t.length,r=e.length;n<r;){var i=Math.min(n,r-n);e.set(e.subarray(0,i),n),n+=i}},ca=(js=0,Ws=new Map,{acquire:function(){return js++},release:function(){0==--js&&Ws.clear()},getTypeArray:function(e,t){Ws.has(e)||Ws.set(e,{});var n=Ws.get(e);return t in n||(n[t]=new e(t)),n[t]}}),la=function(e){m(n,bs);var t=_(n);function n(e,r,i,s){var a;x(this,n),a=t.call(this,e,r,i);var o=!!s.geometry;a._maxVerts=s.maxGeometryBatchSize;var A=o?s.geometry.positionsDecodeMatrix:s.positionsDecodeMatrix;a._positionsDecodeMatrix=A&&Ae.mat4(A),a._cfgUvDecodeMatrix=s.uvDecodeMatrix&&Ae.mat3(s.uvDecodeMatrix),a._instancedGeometry=s.geometry,a._textureSet=s.textureSet,a._modelAABB=!o&&Ae.collapseAABB3(),a._portions=[];var c=function(){var e=0,t=[];return{length:function(){return e},append:function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;e+=r*n.length,t.push({data:n,times:r,denormalizeScale:i,increment:s})},compileBuffer:function(e){var n=0;t.forEach((function(e){n+=e.times*e.data.length}));var r=new e(n),i=0;return t.forEach((function(e){var t=e.data,n=e.denormalizeScale,s=e.increment,a=r.subarray(i);if(1===n&&0===s)a.set(t);else for(var o=0;o<t.length;++o)a[o]=s+t[o]*n;for(var A=t.length,c=e.times*t.length;A<c;){var l=Math.min(A,c-A);a.set(a.subarray(0,l),A),A+=l}i+=A})),r}}};return a._buffer=d({colors:c(),metallicRoughness:c(),pickColors:c()},o?{modelMatrixCol:[c(),c(),c()],modelNormalMatrixCol:[c(),c(),c()]}:{positions:c(),indices:c(),uv:c(),normals:c(),edgeIndices:c()}),a}return I(n,[{key:"canCreatePortion",value:function(e,t){return this._instancedGeometry||this._buffer.positions.length()+e<=3*this._maxVerts&&this._buffer.indices.length()+t<=3*this._maxVerts}},{key:"createPortion",value:function(e,t){var n=this,r=this._buffer,i=this._instancedGeometry,s=this.model,a=this._portions.length,o=this.primitive,A=!!this._positionsDecodeMatrix,c=s.scene,l=t.meshMatrix,u=function(i,A,l,u,h){var d,f,p=n._portions.length>0&&n._portions[n._portions.length-1],v={indicesBaseIndex:p?p.indicesBaseIndex+p.numIndices:0,numIndices:l?l.length:0,portionBase:i,portionSize:A,retainedGeometry:c.readableGeometryEnabled&&"points"!==o&&"lines"!==o&&{indices:l,quantizedPositions:u,offset:c.entityOffsetsEnabled&&Ae.vec3(),matrix:h&&h.slice(),inverseMatrix:null,normalMatrix:null}};"points"!==o&&"lines"!==o&&r.metallicRoughness.append([null!==(d=t.metallic)&&void 0!==d?d:0,null!==(f=t.roughness)&&void 0!==f?f:255],A);return"lines"!==o&&r.pickColors.append(t.pickColor.slice(0,4),A),n._portions.push(v),s.numPortions++,n._meshes.push(e),a};if(i){if(r.modelMatrixCol.forEach((function(e,t){return e.append([l[t+0],l[t+4],l[t+8],l[t+12]])})),"points"!==o){var h,d=t.color;r.colors.append([d[0],d[1],d[2],null!==(h=t.opacity)&&void 0!==h?h:255])}if("points"!==o&&"lines"!==o&&i.normals){var f=Ae.inverseMat4(Ae.transposeMat4(l,Ae.mat4()));r.modelNormalMatrixCol.forEach((function(e,t){return e.append([f[t+0],f[t+4],f[t+8],f[t+12]])}))}return u(a,1,i.indices,i.positionsCompressed,l)}var p=r.positions.length()/3,v=A?t.positionsCompressed:t.positions;if(!v)throw(A?"positionsCompressed":"positions")+" expected";r.positions.append(v);var g=v.length/3,m=t.indices;m&&r.indices.append(m,1,1,p);var y=t.normalsCompressed,_=t.normals;if(y&&y.length>0)r.normals.append(y);else if(_&&_.length>0){var b=Zs;l?(Ae.transposeMat4(l,b),Ae.inverseMat4(b,b)):Ae.identityMat4(b);var w=[];!function(e,t,n,r,i){function s(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}var a,o,A,c,l,u=new Float32Array([0,0,0,0]),h=new Float32Array([0,0,0,0]);for(l=0;l<n;l+=3)u[0]=t[l],u[1]=t[l+1],u[2]=t[l+2],Ae.transformVec3(e,u,h),Ae.normalizeVec3(h,h),o=a=Ns(h,"floor","floor"),A=c=s(h,Gs(a)),(A=s(h,Gs(a=Ns(h,"ceil","floor"))))>c&&(o=a,c=A),(A=s(h,Gs(a=Ns(h,"floor","ceil"))))>c&&(o=a,c=A),(A=s(h,Gs(a=Ns(h,"ceil","ceil"))))>c&&(o=a,c=A),r[i+l+0]=o[0],r[i+l+1]=o[1],r[i+l+2]=0}(b,_,_.length,w,0),r.normals.append(w)}var B=t.colors,C=t.colorsCompressed,M=t.color;if(B)if("points"===o)r.colors.append(B,1,255);else{for(var k=[],E=0,F=B.length;E<F;E+=3)k.push(255*B[E]),k.push(255*B[E+1]),k.push(255*B[E+2]),k.push(255);r.colors.append(k)}else if(C)if("points"===o)r.colors.append(C);else{for(var x=[],U=0,I=C.length;U<I;U+=3)x.push(C[U]),x.push(C[U+1]),x.push(C[U+2]),x.push(255);r.colors.append(x)}else M&&r.colors.append([M[0],M[1],M[2],"points"===o?1:t.opacity],g);var T=function(e){return e&&e.length>0&&e},P=T(t.uv)||T(t.uvCompressed);P&&r.uv.append(P);var S=t.edgeIndices;return S&&r.edgeIndices.append(S,1,1,p),Ae.expandAABB3(this._modelAABB,t.aabb),u(p,g,m)}},{key:"compilePortions",value:function(){var e=this._buffer,t=this._instancedGeometry,n=this.model,r=this._modelAABB,i=this.origin,s=this._portions,a=this.primitive,o=this._textureSet,A=this._positionsDecodeMatrix,c=this._cfgUvDecodeMatrix,l=n.scene,u=l.canvas.gl,h=!!t,d=[],p=function(e,t,n,r){if(t.length>0){var i,s=t.constructor,a=k((i={},f(i,Uint8Array,[1,u.UNSIGNED_BYTE]),f(i,Int8Array,[1,u.BYTE]),f(i,Uint16Array,[2,u.UNSIGNED_SHORT]),f(i,Int16Array,[2,u.SHORT]),f(i,Uint32Array,[4,u.UNSIGNED_INT]),f(i,Int32Array,[4,u.INT]),f(i,Float32Array,[4,u.FLOAT]),i)[s],2),o=a[0],A=a[1],c=u.createBuffer();d.push((function(){return u.deleteBuffer(c)}));var l=function(){return u.bindBuffer(e,c)},h=function(t){l(),u.bufferData(e,t,r)};h(t);var p=t.BYTES_PER_ELEMENT,v=t.length/n;return{bindBuffer:l,getData:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:v-t;l();var i=new s(r*n);return u.getBufferSubData(e,t*o*n,i,0,r*n),i},numItems:v,setData:h,setSubData:function(t,n){l(),u.bufferSubData(e,n*p,t)},type:A}}return null},v=function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=arguments.length>4&&void 0!==arguments[4]&&arguments[4],s=p(u.ARRAY_BUFFER,e,t,n);return s&&{getData:s.getData,numItems:s.numItems,setData:s.setData,setSubData:s.setSubData,attributeDivisor:r&&1,bindAtLocation:function(e){s.bindBuffer(),u.vertexAttribPointer(e,t,s.type,!!i,0,0)}}},g=function(e){var t=p(u.ELEMENT_ARRAY_BUFFER,e,1,u.STATIC_DRAW);return t&&{getData:t.getData,bindIndicesBuffer:t.bindBuffer,indicesCount:e.length,indicesType:t.type}},m=s.reduce((function(e,t){return e+t.portionSize}),0),y=v(new Float32Array(m),1,u.DYNAMIC_DRAW,h),_=function(e,t){return v(e,4,t,h&&"points"!==a,!0)},b=h&&t.colorsCompressed?_(new Uint8Array(t.colorsCompressed),u.STATIC_DRAW):_(e.colors.compileBuffer(Uint8Array),u.DYNAMIC_DRAW),w=l.entityOffsetsEnabled&&v(new Float32Array(3*m),3,u.DYNAMIC_DRAW,h),B=v(e.metallicRoughness.compileBuffer(Uint8Array),2,u.STATIC_DRAW,h),C=v(e.pickColors.compileBuffer(Uint8Array),4,u.STATIC_DRAW,h),M=g(h?new Uint32Array(t.edgeIndices):e.edgeIndices.compileBuffer(Uint32Array)),E=h?"points"!==a&&t.indices&&new Uint32Array(t.indices):e.indices.compileBuffer(Uint32Array),F=E&&g(E),x=h?t.positionsCompressed:A?e.positions.compileBuffer(Uint16Array):Ls(e.positions.compileBuffer(Float64Array),r,A=Ae.mat4()),U=x&&v(x,3,u.STATIC_DRAW);h||s.forEach((function(e){if(e.retainedGeometry){var t=3*e.portionBase;e.retainedGeometry.quantizedPositions=x.subarray(t,t+3*e.portionSize)}}));var I=h&&e.modelMatrixCol.map((function(e){return v(e.compileBuffer(Float32Array),4,u.STATIC_DRAW,!0)})),T=!h&&e.normals.compileBuffer(Int8Array),P=T&&v(T,3,u.STATIC_DRAW,!1,!0),S=I&&P&&e.modelNormalMatrixCol.map((function(e){return v(e.compileBuffer(Float32Array),4,u.STATIC_DRAW,!0)})),D=h?"points"!==a&&"lines"!==a&&t.uvCompressed&&{buf:v(t.uvCompressed,2,u.STATIC_DRAW),mat:t.uvDecodeMatrix}:function(){var t=e.uv.compileBuffer(Float32Array);if(0===t.length)return null;if(c)return{buf:v(t,2,u.STATIC_DRAW),mat:c};var n=pt.getUVBounds(t),r=pt.compressUVs(t,n.min,n.max);return{buf:v(r.quantized,2,u.STATIC_DRAW),mat:Ae.mat3(r.decodeMatrix)}}();this._buffer=null,ca.acquire(),d.push((function(){return ca.release()}));var Q,R,O=null,V=function(e,n,r){var i=arguments.length>3&&void 0!==arguments[3]&&arguments[3];ys(n,r,"points"!==a&&"lines"!==a,l,sa);var o=n&zi?1:0,A=0;A|=sa[0],A|=sa[1]<<4,A|=sa[2]<<8,A|=sa[3]<<12,A|=o<<16,zs[0]=A;var c=s[e],u=c.portionBase,h=c.portionSize;if(i&&!t)O||(O=new Float32Array(m)),Aa(O.subarray(u,u+h),zs);else if(y){var d=ca.getTypeArray(Float32Array,h);Aa(d,zs),y.setSubData(d,u)}},L="solid"===a;return{edgesColorOpaqueAllowed:function(){return!0},solid:L,sortId:("points"===a?"Points":"lines"===a?"Lines":"Triangles")+(h?"Instancing":"Batching")+"Layer"+("points"!==a&&"lines"!==a?(L?"-solid":"-surface")+"-autoNormals"+(h?"":(o&&o.colorTexture?"-colorTexture":"")+(o&&o.metallicRoughnessTexture?"-metallicRoughnessTexture":"")):""),setClippableFlags:V,setFlags:V,setFlags2:function(e,t,n){},setDeferredFlags:function(){O&&(y.setData(O),O=null)},setColor:function(e,t){if(b){var n=s[e],r=ca.getTypeArray(Uint8Array,4*n.portionSize);Aa(r,t.slice(0,4)),b.setSubData(r,4*n.portionBase)}},setMatrix:function(e,t){I&&I.forEach((function(n,r){Xs[0]=t[r+0],Xs[1]=t[r+4],Xs[2]=t[r+8],Xs[3]=t[r+12],n.setSubData(Xs,4*e)}))},setOffset:function(e,t){if(l.entityOffsetsEnabled){var r=s[e];if(w){Ks.set(t);var i=ca.getTypeArray(Float32Array,3*r.portionSize);Aa(i,Ks),w.setSubData(i,3*r.portionBase)}r.retainedGeometry&&r.retainedGeometry.offset.set(t)}else n.error("Entity#offset not enabled for this Viewer")},getEachIndex:function(e,t){var n=s[e].retainedGeometry;n&&n.indices.forEach((function(e){return t(e)}))},getEachVertex:function(e,t){var r=s[e].retainedGeometry;if(r){var a=Ys;i?a.set(i,0):a[0]=a[1]=a[2]=0,a[3]=1;var o=n.matrix;Ae.mulMat4v4(o,a,a);for(var c=r.quantizedPositions,l=Js,u=0,h=c.length;u<h;u+=3)l[0]=c[u],l[1]=c[u+1],l[2]=c[u+2],Ae.decompressPosition(l,A),r.matrix&&Ae.transformPoint3(r.matrix,l,l),l[3]=1,Ae.mulMat4v4(o,l,l),Ae.addVec3(a,l,l),t(l)}},readGeometryData:"points"!==a&&"lines"!==a&&function(e){var t=!h&&s[e],r=t?F.getData(t.indicesBaseIndex,t.numIndices).map((function(e){return e-t.portionBase})):F.getData(),a=n.matrix,o=Ae.vec4();o.set(i,0),o[3]=1,Ae.mulMat4v4(a,o,o);var c=I&&Ae.mat4();if(c){var l=I[0].getData(e,1),u=I[1].getData(e,1),d=I[2].getData(e,1);c.set([l[0],u[0],d[0],0,l[1],u[1],d[1],0,l[2],u[2],d[2],0,l[3],u[3],d[3],1])}var f=Ae.mat4();Ae.mulMat4(a,c?Ae.mulMat4(c,A,f):A,f),f[12]+=o[0],f[13]+=o[1],f[14]+=o[2];var p=t?U.getData(t.portionBase,t.portionSize):U.getData();return{indices:r,positions:Ae.transformPositions3(f,p,new Float64Array(p.length))}},precisionRayPickSurface:function(e,t,r,a,o){var c=s[e].retainedGeometry;if(c){c.matrix&&!c.inverseMatrix&&(c.inverseMatrix=Ae.inverseMat4(c.matrix,Ae.mat4())),o&&c.inverseMatrix&&!c.normalMatrix&&(c.normalMatrix=Ae.transposeMat4(c.inverseMatrix,Ae.mat4()));var l=c.quantizedPositions,u=c.indices,h=c.offset,d=qs,f=$s;d.set(i?Ae.subVec3(t,i,ea):t),f.set(r),h&&Ae.subVec3(d,h),Ae.transformRay(n.worldNormalMatrix,d,f,d,f),c.inverseMatrix&&Ae.transformRay(c.inverseMatrix,d,f,d,f);for(var p=ta,v=na,g=ra,m=!1,y=0,_=ia,b=0,w=u.length;b<w;b+=3){var B=3*u[b],C=3*u[b+1],M=3*u[b+2];if(p[0]=l[B],p[1]=l[B+1],p[2]=l[B+2],v[0]=l[C],v[1]=l[C+1],v[2]=l[C+2],g[0]=l[M],g[1]=l[M+1],g[2]=l[M+2],Ae.decompressPosition(p,A),Ae.decompressPosition(v,A),Ae.decompressPosition(g,A),Ae.rayTriangleIntersect(d,f,p,v,g,_)){c.matrix&&Ae.transformPoint3(c.matrix,_,_),Ae.transformPoint3(n.worldMatrix,_,_),h&&Ae.addVec3(_,h),i&&Ae.addVec3(_,i);var k=Math.abs(Ae.lenVec3(Ae.subVec3(_,t,[])));(!m||k>y)&&(y=k,a.set(_),o&&Ae.triangleNormal(p,v,g,o),m=!0)}}return m&&o&&(c.normalMatrix&&Ae.transformVec3(c.normalMatrix,o,o),Ae.transformVec3(n.worldNormalMatrix,o,o),Ae.normalizeVec3(o)),m}return!1},layerTextureSet:o,renderers:_s(l,h?"instancing":"batching",a,n.saoEnabled,n.pbrEnabled&&D&&o&&o.colorTexture&&P&&B&&o.metallicRoughnessTexture,n.colorTextureEnabled&&D&&o&&o.colorTexture,!!P,(function(e){return ha(e,h&&{hasModelNormalMat:!!S},l.entityOffsetsEnabled)})),drawCalls:(Q={},R=function(e){return function(t,r,i){var o=0;aa.set(n.rotationMatrix,0),aa.set(i.viewMatrix,o+=16),aa.set(i.projMatrix,o+=16),aa.set(A,o+=16),r.needNormal()&&(aa.set(n.worldNormalMatrix,o+=16),aa.set(i.viewNormalMatrix,o+=16)),r.matrices.setInputValue(aa),r.uvDecodeMatrix.setInputValue&&r.uvDecodeMatrix.setInputValue(D.mat),t in Q||(Q[t]=[null,null,null]);var c,l,f=Q[t],p=e?e.vertices?0:1:2;if(!f[p]){var v=u.createVertexArray();u.bindVertexArray(v);var g=function(e,t){e&&e.setInputValue&&t&&e.setInputValue(t)},m=r.attributes;g(m.position,U),g(m.normal,P),g(m.color,b),g(m.pickColor,C),g(m.uV,D&&D.buf),g(m.metallicRoughness,B),g(m.flags,y),g(m.offset,w),m.modelMatrixCol&&m.modelMatrixCol.forEach((function(e,t){return g(e,I[t])})),m.modelNormalMatrixCol&&m.modelNormalMatrixCol.forEach((function(e,t){return g(e,S[t])}));var _=(c=function(){h?u.drawArraysInstanced(u.POINTS,0,U.numItems,s.length):u.drawArrays(u.POINTS,0,U.numItems)},l=function(e,t){t.bindIndicesBuffer();var n=t.indicesCount,r=t.indicesType;return function(){h?u.drawElementsInstanced(e,n,r,0,s.length):u.drawElements(e,n,r,0)}},"points"===a?c:"lines"===a?e&&e.vertices?c:l(u.LINES,F):e&&e.vertices?c:e&&M?l(u.LINES,M):l(u.TRIANGLES,F));u.bindVertexArray(null),d.push((function(){return u.deleteVertexArray(v)})),f[p]=function(){u.bindVertexArray(v),_(),u.bindVertexArray(null)}}f[p]()}},{drawVertices:R({vertices:!0}),drawEdges:R({}),drawSurface:R(null)}),destroy:function(){d.forEach((function(e){return e()})),d.length=0}}}}]),n}(),ua=function(e){var t={toString:function(){return t.needed=!0,e}};return t},ha=function(e,t,n){var r=e.createAttribute,i={position:r("vec3","positionA"),normal:r("vec3","normalA"),color:r("vec4","colorA"),pickColor:r("vec4","pickColor"),uV:r("vec2","uvApremul"),metallicRoughness:r("vec2","metallicRoughness"),flags:r("float","flagsA"),offset:n&&r("vec3","offset"),modelMatrixCol:t&&oa(3).map((function(e){return r("vec4","modelMatrixCol"+e)})),modelNormalMatrixCol:t&&t.hasModelNormalMat&&oa(3).map((function(e){return r("vec4","modelNormalMatrixCol"+e)}))},s=ua("aUv"),a=ua("viewNormal"),o=ua("worldNormal"),A=e.createUniform("mat3","uvDecodeMatrix"),c=function(){return a.needed||o.needed},l=e.createUniformBlock("Matrices",{worldMatrix:"mat4",viewMatrix:"mat4",projMatrix:"mat4",positionsDecodeMatrix:"mat4",worldNormalMatrix:"mat4",viewNormalMatrix:"mat4"});return{dontCullOnAlphaZero:!0,geometryParameters:{attributes:{clippable:"((int(".concat(i.flags,") >> 16 & 0xF) == 1)"),color:i.color,flags:oa(4).map((function(e){return{toString:function(){return"(int(".concat(i.flags,") >> ").concat(4*e," & 0xF)")}}})),metallicRoughness:i.metallicRoughness,normal:{view:a,world:o},pickColor:i.pickColor,position:{clip:"gl_Position",view:"viewPosition",world:"worldPosition"},uv:s},projMatrix:l.projMatrix,viewMatrix:l.viewMatrix},appendVertexData:function(t){s.needed&&t.push("vec2 ".concat(s," = (").concat(A," * vec3(").concat(i.uV,", 1.0)).xy;"));var n=i.modelMatrixCol&&"mat4(".concat(i.modelMatrixCol[0],", ").concat(i.modelMatrixCol[1],", ").concat(i.modelMatrixCol[2],", vec4(0.0,0.0,0.0,1.0))");if(t.push("vec4 worldPosition = ".concat(l.worldMatrix," * (").concat(l.positionsDecodeMatrix," * vec4(").concat(i.position,", 1.0)").concat(n?" * "+n:"",");")),i.offset&&t.push("worldPosition.xyz = worldPosition.xyz + ".concat(i.offset,";")),c()){var r=i.modelNormalMatrixCol&&"* mat4(".concat(i.modelNormalMatrixCol[0],", ").concat(i.modelNormalMatrixCol[1],", ").concat(i.modelNormalMatrixCol[2],", vec4(0.0,0.0,0.0,1.0))");t.push("vec4 modelNormal = vec4(".concat(e.commonLibrary.octDecode,"(").concat(i.normal,".xy), 0.0)").concat(r||"",";")),t.push("vec3 ".concat(o," = (").concat(l.worldNormalMatrix," * modelNormal).xyz;")),a.needed&&t.push("vec3 ".concat(a," = normalize((").concat(l.viewNormalMatrix," * vec4(").concat(o,", 0.0)).xyz);"))}},layerTypeInputs:{attributes:i,matrices:l,uvDecodeMatrix:A,needNormal:c}}},da=function(){function e(t){x(this,e),this.id=t.id,this.colorTexture=t.colorTexture,this.alphaCutoff=t.alphaCutoff,this.metallicRoughnessTexture=t.metallicRoughnessTexture,this.normalsTexture=t.normalsTexture,this.emissiveTexture=t.emissiveTexture,this.occlusionTexture=t.occlusionTexture}return I(e,[{key:"destroy",value:function(){}}]),e}(),fa=function(){function e(t){x(this,e),this.id=t.id,this.texture=t.texture}return I(e,[{key:"destroy",value:function(){this.texture&&(this.texture.destroy(),this.texture=null)}}]),e}(),pa={enabled:!1,files:{},add:function(e,t){!1!==this.enabled&&(this.files[e]=t)},get:function(e){if(!1!==this.enabled)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}},va=function(){function e(t,n,r){x(this,e),this.isLoading=!1,this.itemsLoaded=0,this.itemsTotal=0,this.urlModifier=void 0,this.handlers=[],this.onStart=void 0,this.onLoad=t,this.onProgress=n,this.onError=r}return I(e,[{key:"itemStart",value:function(e){this.itemsTotal++,!1===this.isLoading&&void 0!==this.onStart&&this.onStart(e,this.itemsLoaded,this.itemsTotal),this.isLoading=!0}},{key:"itemEnd",value:function(e){this.itemsLoaded++,void 0!==this.onProgress&&this.onProgress(e,this.itemsLoaded,this.itemsTotal),this.itemsLoaded===this.itemsTotal&&(this.isLoading=!1,void 0!==this.onLoad&&this.onLoad())}},{key:"itemError",value:function(e){void 0!==this.onError&&this.onError(e)}},{key:"resolveURL",value:function(e){return this.urlModifier?this.urlModifier(e):e}},{key:"setURLModifier",value:function(e){return this.urlModifier=e,this}},{key:"addHandler",value:function(e,t){return this.handlers.push(e,t),this}},{key:"removeHandler",value:function(e){var t=this.handlers.indexOf(e);return-1!==t&&this.handlers.splice(t,2),this}},{key:"getHandler",value:function(e){for(var t=0,n=this.handlers.length;t<n;t+=2){var r=this.handlers[t],i=this.handlers[t+1];if(r.global&&(r.lastIndex=0),r.test(e))return i}return null}}]),e}(),ga=new va,ma=function(){function e(t){x(this,e),this.manager=void 0!==t?t:ga,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={}}return I(e,[{key:"load",value:function(){}},{key:"loadAsync",value:function(e,t){var n=this;return new Promise((function(r,i){n.load(e,r,t,i)}))}},{key:"parse",value:function(){}},{key:"setCrossOrigin",value:function(e){return this.crossOrigin=e,this}},{key:"setWithCredentials",value:function(e){return this.withCredentials=e,this}},{key:"setPath",value:function(e){return this.path=e,this}},{key:"setResourcePath",value:function(e){return this.resourcePath=e,this}},{key:"setRequestHeader",value:function(e){return this.requestHeader=e,this}}]),e}(),ya={},_a=function(e){m(n,ma);var t=_(n);function n(e){return x(this,n),t.call(this,e)}return I(n,[{key:"load",value:function(e,t,n,r){var i=this;void 0===e&&(e=""),void 0!==this.path&&(e=this.path+e),e=this.manager.resolveURL(e);var s=pa.get(e);if(void 0!==s)return this.manager.itemStart(e),Fe.scheduleTask((function(){t&&t(s),i.manager.itemEnd(e)}),0),s;if(void 0===ya[e]){ya[e]=[],ya[e].push({onLoad:t,onProgress:n,onError:r});var a=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),o=this.mimeType,A=this.responseType;fetch(a).then((function(t){if(200===t.status||0===t.status){if(0===t.status&&console.warn("FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===t.body.getReader)return t;var n=ya[e],r=t.body.getReader(),i=t.headers.get("Content-Length"),s=i?parseInt(i):0,a=0!==s,o=0,A=new ReadableStream({start:function(e){!function t(){r.read().then((function(r){var i=r.done,A=r.value;if(i)e.close();else{o+=A.byteLength;for(var c=new ProgressEvent("progress",{lengthComputable:a,loaded:o,total:s}),l=0,u=n.length;l<u;l++){var h=n[l];h.onProgress&&h.onProgress(c)}e.enqueue(A),t()}}))}()}});return new Response(A)}throw Error('fetch for "'.concat(t.url,'" responded with ').concat(t.status,": ").concat(t.statusText))})).then((function(e){switch(A){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then((function(e){return(new DOMParser).parseFromString(e,o)}));case"json":return e.json();default:if(void 0===o)return e.text();var t=/charset="?([^;"\s]*)"?/i.exec(o),n=t&&t[1]?t[1].toLowerCase():void 0,r=new TextDecoder(n);return e.arrayBuffer().then((function(e){return r.decode(e)}))}})).then((function(t){pa.add(e,t);var n=ya[e];delete ya[e];for(var r=0,i=n.length;r<i;r++){var s=n[r];s.onLoad&&s.onLoad(t)}})).catch((function(t){var n=ya[e];if(void 0===n)throw i.manager.itemError(e),t;delete ya[e];for(var r=0,s=n.length;r<s;r++){var a=n[r];a.onError&&a.onError(t)}i.manager.itemError(e)})).finally((function(){i.manager.itemEnd(e)})),this.manager.itemStart(e)}else ya[e].push({onLoad:t,onProgress:n,onError:r})}},{key:"setResponseType",value:function(e){return this.responseType=e,this}},{key:"setMimeType",value:function(e){return this.mimeType=e,this}}]),n}(),ba=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:4;x(this,e),this.pool=t,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}return I(e,[{key:"_initWorker",value:function(e){if(!this.workers[e]){var t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}},{key:"_getIdleWorker",value:function(){for(var e=0;e<this.pool;e++)if(!(this.workerStatus&1<<e))return e;return-1}},{key:"_onMessage",value:function(e,t){var n=this.workersResolve[e];if(n&&n(t),this.queue.length){var r=this.queue.shift(),i=r.resolve,s=r.msg,a=r.transfer;this.workersResolve[e]=i,this.workers[e].postMessage(s,a)}else this.workerStatus^=1<<e}},{key:"setWorkerCreator",value:function(e){this.workerCreator=e}},{key:"setWorkerLimit",value:function(e){this.pool=e}},{key:"postMessage",value:function(e,t){var n=this;return new Promise((function(r){var i=n._getIdleWorker();-1!==i?(n._initWorker(i),n.workerStatus|=1<<i,n.workersResolve[i]=r,n.workers[i].postMessage(e,t)):n.queue.push({resolve:r,msg:e,transfer:t})}))}},{key:"destroy",value:function(){this.workers.forEach((function(e){return e.terminate()})),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}]),e}(),wa=0,Ba=function(){function e(t){var n=t.viewer,r=t.transcoderPath,i=t.workerLimit;x(this,e),this._transcoderPath=r||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new ba,this._workerSourceURL="",i&&this._workerPool.setWorkerLimit(i);var s=n.capabilities;this._workerConfig={astcSupported:s.astcSupported,etc1Supported:s.etc1Supported,etc2Supported:s.etc2Supported,dxtSupported:s.dxtSupported,bptcSupported:s.bptcSupported,pvrtcSupported:s.pvrtcSupported},this._supportedFileTypes=["xkt2"]}return I(e,[{key:"_init",value:function(){var t=this;if(!this._transcoderPending){var n=new _a;n.setPath(this._transcoderPath),n.setWithCredentials(this.withCredentials);var r=n.loadAsync("basis_transcoder.js"),i=new _a;i.setPath(this._transcoderPath),i.setResponseType("arraybuffer"),i.setWithCredentials(this.withCredentials);var s=i.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([r,s]).then((function(n){var r=k(n,2),i=r[0],s=r[1],a=e.BasisWorker.toString(),o=["/* constants */","let _EngineFormat = "+JSON.stringify(e.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(e.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(e.BasisFormat),"/* basis_transcoder.js */",i,"/* worker */",a.substring(a.indexOf("{")+1,a.lastIndexOf("}"))].join("\n");t._workerSourceURL=URL.createObjectURL(new Blob([o])),t._transcoderBinary=s,t._workerPool.setWorkerCreator((function(){var e=new Worker(t._workerSourceURL),n=t._transcoderBinary.slice(0);return e.postMessage({type:"init",config:t._workerConfig,transcoderBinary:n},[n]),e}))})),wa>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),wa++}return this._transcoderPending}},{key:"transcode",value:function(e,t){var n=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new Promise((function(i,s){var a=r;n._init().then((function(){return n._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:a},e)})).then((function(e){var n=e.data,r=n.mipmaps,a=(n.width,n.height,n.format),o=n.type,A=n.error,c=n.dfdTransferFn,l=n.dfdFlags;if("error"===o)return s(A);t.setCompressedData({mipmaps:r,props:{format:a,minFilter:1===r.length?1006:1008,magFilter:1===r.length?1006:1008,encoding:2===c?3001:3e3,premultiplyAlpha:!!(1&l)}}),i()}))}))}},{key:"destroy",value:function(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),wa--}}]),e}();Ba.BasisFormat={ETC1S:0,UASTC_4x4:1},Ba.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},Ba.EngineFormat={RGBAFormat:1023,RGBA_ASTC_4x4_Format:37808,RGBA_BPTC_Format:36492,RGBA_ETC2_EAC_Format:37496,RGBA_PVRTC_4BPPV1_Format:35842,RGBA_S3TC_DXT5_Format:33779,RGB_ETC1_Format:36196,RGB_ETC2_Format:37492,RGB_PVRTC_4BPPV1_Format:35840,RGB_S3TC_DXT1_Format:33776},Ba.BasisWorker=function(){var e,t,n,r=_EngineFormat,i=_TranscoderFormat,s=_BasisFormat;self.addEventListener("message",(function(a){var l,u=a.data;switch(u.type){case"init":e=u.config,l=u.transcoderBinary,t=new Promise((function(e){n={wasmBinary:l,onRuntimeInitialized:e},BASIS(n)})).then((function(){n.initializeBasis(),void 0===n.KTX2File&&console.warn("KTX2TextureTranscoder: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((function(){try{for(var t=function(t){var a=new n.KTX2File(new Uint8Array(t));function l(){a.close(),a.delete()}if(!a.isValid())throw l(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");var u=a.isUASTC()?s.UASTC_4x4:s.ETC1S,h=a.getWidth(),d=a.getHeight(),f=a.getLevels(),p=a.getHasAlpha(),v=a.getDFDTransferFunc(),g=a.getDFDFlags(),m=function(t,n,a,l){for(var u,h,d=t===s.ETC1S?o:A,f=0;f<d.length;f++){var p=d[f];if(e[p.if]&&(p.basisFormat.includes(t)&&!(l&&p.transcoderFormat.length<2)&&(!p.needsPowerOfTwo||c(n)&&c(a))))return{transcoderFormat:u=p.transcoderFormat[l?1:0],engineFormat:h=p.engineFormat[l?1:0]}}return console.warn("KTX2TextureTranscoder: No suitable compressed texture format found. Decoding to RGBA32."),u=i.RGBA32,h=r.RGBAFormat,{transcoderFormat:u,engineFormat:h}}(u,h,d,p),y=m.transcoderFormat,_=m.engineFormat;if(!h||!d||!f)throw l(),new Error("KTX2TextureTranscoder: Invalid texture");if(!a.startTranscoding())throw l(),new Error("KTX2TextureTranscoder: .startTranscoding failed");for(var b=[],w=0;w<f;w++){var B=a.getImageLevelInfo(w,0,0),C=B.origWidth,M=B.origHeight,k=new Uint8Array(a.getImageTranscodedSizeInBytes(w,0,0,y));if(!a.transcodeImage(k,w,0,0,y,0,-1,-1))throw l(),new Error("KTX2TextureTranscoder: .transcodeImage failed.");b.push({data:k,width:C,height:M})}return l(),{width:h,height:d,hasAlpha:p,mipmaps:b,format:_,dfdTransferFn:v,dfdFlags:g}}(u.buffers[0]),a=t.width,l=t.height,h=t.hasAlpha,d=t.mipmaps,f=t.format,p=t.dfdTransferFn,v=t.dfdFlags,g=[],m=0;m<d.length;++m)g.push(d[m].data.buffer);self.postMessage({type:"transcode",id:u.id,width:a,height:l,hasAlpha:h,mipmaps:d,format:f,dfdTransferFn:p,dfdFlags:v},g)}catch(e){console.error("[KTX2TextureTranscoder.BasisWorker]: ".concat(e)),self.postMessage({type:"error",id:u.id,error:e.message})}}))}}));var a=[{if:"astcSupported",basisFormat:[s.UASTC_4x4],transcoderFormat:[i.ASTC_4x4,i.ASTC_4x4],engineFormat:[r.RGBA_ASTC_4x4_Format,r.RGBA_ASTC_4x4_Format],priorityETC1S:1/0,priorityUASTC:1,needsPowerOfTwo:!1},{if:"bptcSupported",basisFormat:[s.ETC1S,s.UASTC_4x4],transcoderFormat:[i.BC7_M5,i.BC7_M5],engineFormat:[r.RGBA_BPTC_Format,r.RGBA_BPTC_Format],priorityETC1S:3,priorityUASTC:2,needsPowerOfTwo:!1},{if:"dxtSupported",basisFormat:[s.ETC1S,s.UASTC_4x4],transcoderFormat:[i.BC1,i.BC3],engineFormat:[r.RGB_S3TC_DXT1_Format,r.RGBA_S3TC_DXT5_Format],priorityETC1S:4,priorityUASTC:5,needsPowerOfTwo:!1},{if:"etc2Supported",basisFormat:[s.ETC1S,s.UASTC_4x4],transcoderFormat:[i.ETC1,i.ETC2],engineFormat:[r.RGB_ETC2_Format,r.RGBA_ETC2_EAC_Format],priorityETC1S:1,priorityUASTC:3,needsPowerOfTwo:!1},{if:"etc1Supported",basisFormat:[s.ETC1S,s.UASTC_4x4],transcoderFormat:[i.ETC1],engineFormat:[r.RGB_ETC1_Format],priorityETC1S:2,priorityUASTC:4,needsPowerOfTwo:!1},{if:"pvrtcSupported",basisFormat:[s.ETC1S,s.UASTC_4x4],transcoderFormat:[i.PVRTC1_4_RGB,i.PVRTC1_4_RGBA],engineFormat:[r.RGB_PVRTC_4BPPV1_Format,r.RGBA_PVRTC_4BPPV1_Format],priorityETC1S:5,priorityUASTC:6,needsPowerOfTwo:!0}],o=a.sort((function(e,t){return e.priorityETC1S-t.priorityETC1S})),A=a.sort((function(e,t){return e.priorityUASTC-t.priorityUASTC}));function c(e){return e<=2||0==(e&e-1)&&0!==e}};var Ca={};function Ma(e){var t=e.scene.id,n=Ca[t];return n||(n=new Ba({viewer:e}),Ca[t]=n,e.scene.on("destroyed",(function(){delete Ca[t],n.destroy()}))),n}
8
8
  /**
9
9
  * @author https://github.com/tmarti, with support from https://tribia.com/
10
10
  * @license MIT