@xeokit/xeokit-sdk 2.6.87-renderers-refactor-v3 → 2.6.87-renderers-refactor-v4
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.
- package/dist/xeokit-sdk.cjs.js +19 -5
- package/dist/xeokit-sdk.es.js +19 -5
- package/dist/xeokit-sdk.es5.js +197 -195
- package/dist/xeokit-sdk.min.cjs.js +5 -5
- package/dist/xeokit-sdk.min.es.js +5 -5
- package/dist/xeokit-sdk.min.es5.js +5 -5
- package/package.json +1 -1
- package/src/viewer/scene/model/SceneModel.js +13 -1
- package/src/viewer/scene/model/layer/Layer.js +3 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* xeokit-sdk v2.6.87-renderers-refactor-
|
|
3
|
-
* Commit:
|
|
4
|
-
* Built: 2025-08-
|
|
2
|
+
* xeokit-sdk v2.6.87-renderers-refactor-v4
|
|
3
|
+
* Commit: 5caed07165a5e87253766624958029a6267642df
|
|
4
|
+
* Built: 2025-08-04T16:36:05.420Z
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
var e,t,n,r=A().mark(ob),i=A().mark(ab),s=A().mark(jC);function o(e){var t="function"==typeof Map?new Map:void 0;return o=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 a(e,arguments,C(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),y(r,e)},o(e)}function a(e,t,n){return a=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},a.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",o=r.toStringTag||"@@toStringTag";function a(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{a({},"")}catch(e){a=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),o=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 o=n.delegate;if(o){var a=b(o,n);if(a){if(a===l)continue;return a}}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=u(e,t,n);if("normal"===A.type){if(r=n.done?"completed":"suspendedYield",A.arg===l)continue;return{value:A.arg,done:n.done}}"throw"===A.type&&(r="completed",n.method="throw",n.arg=A.arg)}}}(e,n,o),s}function u(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var l={};function h(){}function d(){}function f(){}var p={};a(p,i,(function(){return this}));var v=Object.getPrototypeOf,g=v&&v(v(M([])));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){a(e,t,(function(e){return this._invoke(t,e)}))}))}function _(e,t){function r(i,s,o,a){var A=u(e[i],e,s);if("throw"!==A.type){var c=A.arg,l=c.value;return l&&"object"==k(l)&&n.call(l,"__await")?t.resolve(l.__await).then((function(e){r("next",e,o,a)}),(function(e){r("throw",e,o,a)})):t.resolve(l).then((function(e){c.value=e,o(c)}),(function(e){return r("throw",e,o,a)}))}a(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 l;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var r=u(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,l;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,l):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}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 M(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,a(m,"constructor",f),a(f,"constructor",d),d.displayName=a(f,o,"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,a(e,o,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},y(_.prototype),a(_.prototype,s,(function(){return this})),e.AsyncIterator=_,e.async=function(t,n,r,i,s){void 0===s&&(s=Promise);var o=new _(c(t,n,r,i),s);return e.isGeneratorFunction(n)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},y(m),a(m,o,"Generator"),a(m,i,(function(){return this})),a(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=M,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 o.type="throw",o.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],o=s.completion;if("root"===s.tryLoc)return r("end");if(s.tryLoc<=this.prev){var a=n.call(s,"catchLoc"),A=n.call(s,"finallyLoc");if(a&&A){if(this.prev<s.catchLoc)return r(s.catchLoc,!0);if(this.prev<s.finallyLoc)return r(s.finallyLoc)}else if(a){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 o=s?s.completion:{};return o.type=e,o.arg=t,s?(this.method="next",this.next=s.finallyLoc,l):this.complete(o)},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),l},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),l}},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:M(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),l}},e}function c(e,t,n,r,i,s,o){try{var a=e[s](o),A=a.value}catch(e){return void n(e)}a.done?t(A):Promise.resolve(A).then(r,i)}function u(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var s=e.apply(t,n);function o(e){c(s,r,i,o,a,"next",e)}function a(e){c(s,r,i,o,a,"throw",e)}o(void 0)}))}}function l(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,o=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){a=!0,s=e},f:function(){try{o||null==n.return||n.return()}finally{if(a)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"===k(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 k(e){return k="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},k(e)}function M(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=[],o=!0,a=!1;try{for(n=n.call(e);!(o=(r=n.next()).done)&&(s.push(r.value),!t||s.length!==t);o=!0);}catch(e){a=!0,i=e}finally{try{o||null==n.return||n.return()}finally{if(a)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),o=s.value,a=o instanceof D;Promise.resolve(a?o.wrapped:o).then((function(e){a?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,o){var a={key:e,arg:i,resolve:s,reject:o,next:null};n?n=n.next=a:(t=n=a,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)};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,o=n.length;s<o;s++){var a=n[s],A=new q;i.groups.push(A);for(var c=function(n,r){var s=a[n],o=s.items,c=o&&o.length>0,u=t._getNextId(),l=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 $(u,l,h,d,f);if(p.parentMenu=i,A.items.push(p),c){var v=e(o);p.subMenu=v,v.parentItem=p}t._itemList.push(p),t._itemMap[p.id]=p},u=0,l=a.length;u<l;u++)c(u)}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 o=r[i].items,a=0,A=o.length;a<A;a++){var c=o[a].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,o=n.length;s<o;s++){var a=s,A=o,c=n[s].items;if(c)for(var u=0,l=c.length;u<l;u++){var h=c[u],d=h.subMenu,f=h.title||"";d?(r.push('<li id="'+h.id+'" class="xeokit-context-menu-item xeokit-context-menu-submenu">'+f+"</li>"),a===A-1||u<l-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>"),a===A-1||u<l-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 o=v._offsetParent.getBoundingClientRect(),a=200,A=s.right+a<o.right,c=s.left-a>o.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-a+window.scrollX,s.top+window.scrollY-1);else{var u=s.left-o.left,l=o.right-s.right;l>u?v._showMenu(t.id,s.right-5-(a-l),s.top+window.scrollY-1):v._showMenu(t.id,s.left-u,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 o=s(this._context);if(n.shown=o,o){r.style.display="";var a=i(this._context);n.enabled=a,a?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(o){o.subMenu&&(e=o.itemElement,t=e.getBoundingClientRect(),n=o.subMenu.menuElement,r={visibility:n.style.visibility,display:n.style.display},n.style.display="block",n.style.visibility="hidden",s=o.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(),o=this._offsetParent===window.document.body&&0===s.bottom?window.innerHeight:s.bottom+window.scrollY,a=s.right+window.scrollX;n+r>o&&(n=o-r),t+i>a&&(t=a-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,o=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+o*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=M(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),oe=new re(16),ae=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],o=t[1],a=t[2];return[r*a-i*o,i*s-n*a,n*o-r*s,0]},cross3Vec3:function(e,t,n){n||(n=e);var r=e[0],i=e[1],s=e[2],o=t[0],a=t[1],A=t[2];return n[0]=i*A-s*a,n[1]=s*o-r*A,n[2]=r*a-i*o,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],o=e[3],a=e[4],A=e[5],c=e[6],u=e[7],l=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],k=t[6],M=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+_*a+b*l+w*p,n[1]=y*i+_*A+b*h+w*v,n[2]=y*s+_*c+b*d+w*g,n[3]=y*o+_*u+b*f+w*m,n[4]=B*r+C*a+k*l+M*p,n[5]=B*i+C*A+k*h+M*v,n[6]=B*s+C*c+k*d+M*g,n[7]=B*o+C*u+k*f+M*m,n[8]=E*r+F*a+x*l+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*o+F*u+x*f+U*m,n[12]=I*r+T*a+P*l+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*o+T*u+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],o=e[1],a=e[4],A=e[7],c=e[2],u=e[5],l=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]=o*h+a*p+A*m,n[4]=o*d+a*v+A*y,n[7]=o*f+a*g+A*_,n[2]=c*h+u*p+l*m,n[5]=c*d+u*v+l*y,n[8]=c*f+u*g+l*_,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],o=t[3];return n[0]=e[0]*r+e[4]*i+e[8]*s+e[12]*o,n[1]=e[1]*r+e[5]*i+e[9]*s+e[13]*o,n[2]=e[2]*r+e[6]*i+e[10]*s+e[14]*o,n[3]=e[3]*r+e[7]*i+e[11]*s+e[15]*o,n},transposeMat4:function(e,t){var n=e[4],r=e[14],i=e[8],s=e[13],o=e[12],a=e[9];if(!t||e===t){var A=e[1],c=e[2],u=e[3],l=e[6],h=e[7],d=e[11];return e[1]=n,e[2]=i,e[3]=o,e[4]=A,e[6]=a,e[7]=s,e[8]=c,e[9]=l,e[11]=r,e[12]=u,e[13]=h,e[14]=d,e}return t[0]=e[0],t[1]=n,t[2]=i,t[3]=o,t[4]=e[1],t[5]=e[5],t[6]=a,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],o=e[5],a=e[6],A=e[7],c=e[8],u=e[9],l=e[10],h=e[11],d=e[12],f=e[13],p=e[14],v=e[15];return d*u*a*i-c*f*a*i-d*o*l*i+s*f*l*i+c*o*p*i-s*u*p*i-d*u*r*A+c*f*r*A+d*n*l*A-t*f*l*A-c*n*p*A+t*u*p*A+d*o*r*h-s*f*r*h-d*n*a*h+t*f*a*h+s*n*p*h-t*o*p*h-c*o*r*v+s*u*r*v+c*n*a*v-t*u*a*v-s*n*l*v+t*o*l*v},inverseMat4:function(e,t){t||(t=e);var n=e[0],r=e[1],i=e[2],s=e[3],o=e[4],a=e[5],A=e[6],c=e[7],u=e[8],l=e[9],h=e[10],d=e[11],f=e[12],p=e[13],v=e[14],g=e[15],m=n*a-r*o,y=n*A-i*o,_=n*c-s*o,b=r*A-i*a,w=r*c-s*a,B=i*c-s*A,C=u*p-l*f,k=u*v-h*f,M=u*g-d*f,E=l*v-h*p,F=l*g-d*p,x=h*g-d*v,U=1/(m*x-y*F+_*E+b*M-w*k+B*C);return t[0]=(a*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]=(-l*B+h*w-d*b)*U,t[4]=(-o*x+A*M-c*k)*U,t[5]=(n*x-i*M+s*k)*U,t[6]=(-f*B+v*_-g*y)*U,t[7]=(u*B-h*_+d*y)*U,t[8]=(o*F-a*M+c*C)*U,t[9]=(-n*F+r*M-s*C)*U,t[10]=(f*w-p*_+g*m)*U,t[11]=(-u*w+l*_-d*m)*U,t[12]=(-o*E+a*k-A*C)*U,t[13]=(n*E-r*k+i*C)*U,t[14]=(-f*b+p*y-v*m)*U,t[15]=(u*b-l*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 o=r[11];r[8]+=o*e,r[9]+=o*t,r[10]+=o*n;var a=r[15];return r[12]+=a*e,r[13]+=a*t,r[14]+=a*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,o,a,A,c=Ae.normalizeVec4([t[0],t[1],t[2],0],[]),u=Math.sin(e),l=Math.cos(e),h=1-l,d=c[0],f=c[1],p=c[2];return r=d*f,i=f*p,s=p*d,o=d*u,a=f*u,A=p*u,(n=n||Ae.mat4())[0]=h*d*d+l,n[1]=h*r+A,n[2]=h*s-a,n[3]=0,n[4]=h*r-A,n[5]=h*f*f+l,n[6]=h*i+o,n[7]=0,n[8]=h*s+a,n[9]=h*i-o,n[10]=h*p*p+l,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],o=e[3],a=r+r,A=i+i,c=s+s,u=r*a,l=r*A,h=r*c,d=i*A,f=i*c,p=s*c,v=o*a,g=o*A,m=o*c;return n[0]=1-(d+p),n[1]=l+m,n[2]=h-g,n[3]=0,n[4]=l-m,n[5]=1-(u+p),n[6]=f+v,n[7]=0,n[8]=h+g,n[9]=f-v,n[10]=1-(u+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],o=e[8],a=e[1],A=e[5],c=e[9],u=e[2],l=e[6],h=e[10];return"XYZ"===t?(n[1]=Math.asin(r(o,-1,1)),Math.abs(o)<.99999?(n[0]=Math.atan2(-c,h),n[2]=Math.atan2(-s,i)):(n[0]=Math.atan2(l,A),n[2]=0)):"YXZ"===t?(n[0]=Math.asin(-r(c,-1,1)),Math.abs(c)<.99999?(n[1]=Math.atan2(o,h),n[2]=Math.atan2(a,A)):(n[1]=Math.atan2(-u,i),n[2]=0)):"ZXY"===t?(n[0]=Math.asin(r(l,-1,1)),Math.abs(l)<.99999?(n[1]=Math.atan2(-u,h),n[2]=Math.atan2(-s,A)):(n[1]=0,n[2]=Math.atan2(a,i))):"ZYX"===t?(n[1]=Math.asin(-r(u,-1,1)),Math.abs(u)<.99999?(n[0]=Math.atan2(l,h),n[2]=Math.atan2(a,i)):(n[0]=0,n[2]=Math.atan2(-s,A))):"YZX"===t?(n[2]=Math.asin(r(a,-1,1)),Math.abs(a)<.99999?(n[0]=Math.atan2(-c,A),n[1]=Math.atan2(-u,i)):(n[0]=0,n[1]=Math.atan2(o,h))):"XZY"===t&&(n[2]=Math.asin(-r(s,-1,1)),Math.abs(s)<.99999?(n[0]=Math.atan2(l,A),n[1]=Math.atan2(o,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 o=Ae.lenVec3(e);e[0]=n[4],e[1]=n[5],e[2]=n[6];var a=Ae.lenVec3(e);e[8]=n[8],e[9]=n[9],e[10]=n[10];var A=Ae.lenVec3(e);Ae.determinantMat4(n)<0&&(o=-o),r[0]=n[12],r[1]=n[13],r[2]=n[14],t.set(n);var c=1/o,u=1/a,l=1/A;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=u,t[5]*=u,t[6]*=u,t[8]*=l,t[9]*=l,t[10]*=l,Ae.mat4ToQuaternion(t,i),s[0]=o,s[1]=a,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,o,a,A,c,u,l,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,o=v-w,a=m*(o*=d=1/Math.sqrt(i*i+s*s+o*o))-y*(s*=d),A=y*(i*=d)-g*o,c=g*s-m*i,(d=Math.sqrt(a*a+A*A+c*c))?(a*=d=1/d,A*=d,c*=d):(a=0,A=0,c=0),u=s*c-o*A,l=o*a-i*c,h=i*A-s*a,(d=Math.sqrt(u*u+l*l+h*h))?(u*=d=1/d,l*=d,h*=d):(u=0,l=0,h=0),r[0]=a,r[1]=u,r[2]=i,r[3]=0,r[4]=A,r[5]=l,r[6]=s,r[7]=0,r[8]=c,r[9]=h,r[10]=o,r[11]=0,r[12]=-(a*f+A*p+c*v),r[13]=-(u*f+l*p+h*v),r[14]=-(i*f+s*p+o*v),r[15]=1,r)},lookAtMat4c:function(e,t,n,r,i,s,o,a,A){return Ae.lookAtMat4v([e,t,n],[r,i,s],[o,a,A],[])},orthoMat4c:function(e,t,n,r,i,s,o){o||(o=Ae.mat4());var a=t-e,A=r-n,c=s-i;return o[0]=2/a,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2/A,o[6]=0,o[7]=0,o[8]=0,o[9]=0,o[10]=-2/c,o[11]=0,o[12]=-(e+t)/a,o[13]=-(r+n)/A,o[14]=-(s+i)/c,o[15]=1,o},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,oe);var s=2*r[2],o=oe[0],a=oe[1],A=oe[2];return n[0]=s/o,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=s/a,n[6]=0,n[7]=0,n[8]=se[0]/o,n[9]=se[1]/a,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,o){o||(o=Ae.mat4());var a=t-e,A=r-n,c=s-i;return o[0]=2*i/a,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2*i/A,o[6]=0,o[7]=0,o[8]=(t+e)/a,o[9]=(r+n)/A,o[10]=-(s+i)/c,o[11]=-1,o[12]=0,o[13]=0,o[14]=-s*i*2/c,o[15]=0,o},perspectiveMat4:function(e,t,n,r,i){var s=[],o=[];return s[2]=n,o[2]=r,o[1]=s[2]*Math.tan(e/2),s[1]=-o[1],o[0]=o[1]*t,s[0]=-o[0],Ae.frustumMat4v(s,o,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,o,a,A=n||[],c=t.length,u=e[0],l=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],k=e[15],M=0;M<c;++M)r=(o=t[M])[0],i=o[1],s=o[2],(a=A[M]||(A[M]=[0,0,0]))[0]=u*r+f*i+m*s+w,a[1]=l*r+p*i+y*s+B,a[2]=h*r+v*i+_*s+C,a[3]=d*r+g*i+b*s+k;return A.length=c,A},transformPositions3:function(e,t){var n,r,i,s,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,a=t.length,A=e[0],c=e[1],u=e[2];e[3];var l=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<a;n+=3)r=t[n+0],i=t[n+1],s=t[n+2],o[n+0]=A*r+l*i+f*s+g,o[n+1]=c*r+h*i+p*s+m,o[n+2]=u*r+d*i+v*s+y;return o},transformPositions4:function(e,t){var n,r,i,s,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,a=t.length,A=e[0],c=e[1],u=e[2],l=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<a;n+=4)r=t[n+0],i=t[n+1],s=t[n+2],o[n+0]=A*r+h*i+v*s+_,o[n+1]=c*r+d*i+g*s+b,o[n+2]=u*r+f*i+m*s+w,o[n+3]=l*r+p*i+y*s+B;return o},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],o=t[3];return(n=n||Ae.vec4())[0]=e[0]*r+e[4]*i+e[8]*s+e[12]*o,n[1]=e[1]*r+e[5]*i+e[9]*s+e[13]*o,n[2]=e[2]*r+e[6]*i+e[10]*s+e[14]*o,n[3]=e[3]*r+e[7]*i+e[11]*s+e[15]*o,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),o=e[0]-t[0],a=e[1]-t[1];return r[0]=o*i-a*s+t[0],r[1]=o*s+a*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 o=s||Ae.vec3(),a=(e-t)/(n-t);return o[0]=r[0]+a*(i[0]-r[0]),o[1]=r[1]+a*(i[1]-r[1]),o[2]=r[2]+a*(i[2]-r[2]),o},lerpMat4:function(e,t,n,r,i,s){var o=s||Ae.mat4(),a=(e-t)/(n-t);return o[0]=r[0]+a*(i[0]-r[0]),o[1]=r[1]+a*(i[1]-r[1]),o[2]=r[2]+a*(i[2]-r[2]),o[3]=r[3]+a*(i[3]-r[3]),o[4]=r[4]+a*(i[4]-r[4]),o[5]=r[5]+a*(i[5]-r[5]),o[6]=r[6]+a*(i[6]-r[6]),o[7]=r[7]+a*(i[7]-r[7]),o[8]=r[8]+a*(i[8]-r[8]),o[9]=r[9]+a*(i[9]-r[9]),o[10]=r[10]+a*(i[10]-r[10]),o[11]=r[11]+a*(i[11]-r[11]),o[12]=r[12]+a*(i[12]-r[12]),o[13]=r[13]+a*(i[13]-r[13]),o[14]=r[14]+a*(i[14]-r[14]),o[15]=r[15]+a*(i[15]-r[15]),o},flatten:function(e){var t,n,r,i,s,o=[];for(t=0,n=e.length;t<n;t++)for(r=0,i=(s=e[t]).length;r<i;r++)o.push(s[r]);return o},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,o=Math.cos(r),a=Math.cos(i),A=Math.cos(s),c=Math.sin(r),u=Math.sin(i),l=Math.sin(s);return"XYZ"===t?(n[0]=c*a*A+o*u*l,n[1]=o*u*A-c*a*l,n[2]=o*a*l+c*u*A,n[3]=o*a*A-c*u*l):"YXZ"===t?(n[0]=c*a*A+o*u*l,n[1]=o*u*A-c*a*l,n[2]=o*a*l-c*u*A,n[3]=o*a*A+c*u*l):"ZXY"===t?(n[0]=c*a*A-o*u*l,n[1]=o*u*A+c*a*l,n[2]=o*a*l+c*u*A,n[3]=o*a*A-c*u*l):"ZYX"===t?(n[0]=c*a*A-o*u*l,n[1]=o*u*A+c*a*l,n[2]=o*a*l-c*u*A,n[3]=o*a*A+c*u*l):"YZX"===t?(n[0]=c*a*A+o*u*l,n[1]=o*u*A+c*a*l,n[2]=o*a*l-c*u*A,n[3]=o*a*A-c*u*l):"XZY"===t&&(n[0]=c*a*A-o*u*l,n[1]=o*u*A-c*a*l,n[2]=o*a*l+c*u*A,n[3]=o*a*A+c*u*l),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],o=e[1],a=e[5],A=e[9],c=e[2],u=e[6],l=e[10],h=r+a+l;return h>0?(t=.5/Math.sqrt(h+1),n[3]=.25/t,n[0]=(u-A)*t,n[1]=(s-c)*t,n[2]=(o-i)*t):r>a&&r>l?(t=2*Math.sqrt(1+r-a-l),n[3]=(u-A)/t,n[0]=.25*t,n[1]=(i+o)/t,n[2]=(s+c)/t):a>l?(t=2*Math.sqrt(1+a-r-l),n[3]=(s-c)/t,n[0]=(i+o)/t,n[1]=.25*t,n[2]=(A+u)/t):(t=2*Math.sqrt(1+l-r-a),n[3]=(o-i)/t,n[0]=(s+c)/t,n[1]=(A+u)/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],o=e[3],a=t[0],A=t[1],c=t[2],u=t[3];return n[0]=o*a+r*u+i*c-s*A,n[1]=o*A+i*u+s*a-r*c,n[2]=o*c+s*u+r*A-i*a,n[3]=o*u-r*a-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],o=e[0],a=e[1],A=e[2],c=e[3],u=c*r+a*s-A*i,l=c*i+A*r-o*s,h=c*s+o*i-a*r,d=-o*r-a*i-A*s;return n[0]=u*c+d*-o+l*-A-h*-a,n[1]=l*c+d*-a+h*-o-u*-A,n[2]=h*c+d*-A+u*-a-l*-o,n},quaternionToMat4:function(e,t){t=Ae.identityMat4(t);var n=e[0],r=e[1],i=e[2],s=e[3],o=2*n,a=2*r,A=2*i,c=o*s,u=a*s,l=A*s,h=o*n,d=a*n,f=A*n,p=a*r,v=A*r,g=A*i;return t[0]=1-(p+g),t[1]=d+l,t[2]=f-u,t[4]=d-l,t[5]=1-(h+g),t[6]=v+c,t[8]=f+u,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],o=n+n,a=r+r,A=i+i,c=n*o,u=n*a,l=n*A,h=r*a,d=r*A,f=i*A,p=s*o,v=s*a,g=s*A;return t[0]=1-(h+f),t[4]=u-g,t[8]=l+v,t[1]=u+g,t[5]=1-(c+f),t[9]=d-p,t[2]=l-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,ae))[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,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,a=t.length,A=e[0],c=e[1],u=e[2],l=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<a;n+=4)r=t[n+0],i=t[n+1],s=t[n+2],o[n+0]=A*r+h*i+v*s+_,o[n+1]=c*r+d*i+g*s+b,o[n+2]=u*r+f*i+m*s+w,o[n+3]=l*r+p*i+y*s+B;return o},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),o=i[0]-r[0],a=r[3]-i[0],A=i[1]-r[1],c=r[4]-i[1],u=i[2]-r[2],l=r[5]-i[2];return s[0]+=o>a?o:a,s[1]+=A>c?A:c,s[2]+=u>l?u:l,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,o,a=Ae.MAX_DOUBLE,A=Ae.MAX_DOUBLE,c=Ae.MAX_DOUBLE,u=Ae.MIN_DOUBLE,l=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],o=e[2]):(i=t[d+0],s=t[d+1],o=t[d+2]),i<a&&(a=i),s<A&&(A=s),o<c&&(c=o),i>u&&(u=i),s>l&&(l=s),o>h&&(h=o);return n[0]=a,n[1]=A,n[2]=c,n[3]=u,n[4]=l,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,o=Ae.MAX_DOUBLE,a=Ae.MAX_DOUBLE,A=Ae.MIN_DOUBLE,c=Ae.MIN_DOUBLE,u=Ae.MIN_DOUBLE,l=0,h=e.length;l<h;l+=4)(t=e[l+0])<s&&(s=t),(n=e[l+1])<o&&(o=n),(r=e[l+2])<a&&(a=r),t>A&&(A=t),n>c&&(c=n),r>u&&(u=r);return i[0]=s,i[1]=o,i[2]=a,i[3]=A,i[4]=c,i[5]=u,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,o=Ae.MAX_DOUBLE,a=Ae.MAX_DOUBLE,A=Ae.MIN_DOUBLE,c=Ae.MIN_DOUBLE,u=Ae.MIN_DOUBLE,l=0,h=e.length;l<h;l++)(t=e[l][0])<s&&(s=t),(n=e[l][1])<o&&(o=n),(r=e[l][2])<a&&(a=r),t>A&&(A=t),n>c&&(c=n),r>u&&(u=r);return i[0]=s,i[1]=o,i[2]=a,i[3]=A,i[4]=c,i[5]=u,i},points3ToSphere3:function(){var e=new re(3);return function(t,n){n=n||Ae.vec4();var r,i=0,s=0,o=0,a=t.length;for(r=0;r<a;r++)i+=t[r][0],s+=t[r][1],o+=t[r][2];n[0]=i/a,n[1]=s/a,n[2]=o/a;var A,c=0;for(r=0;r<a;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,o=0,a=0,A=n.length,c=0;for(i=0;i<A;i+=3)s+=n[i],o+=n[i+1],a+=n[i+2];var u,l=A/3;for(r[0]=s/l,r[1]=o/l,r[2]=a/l,i=0;i<A;i+=3)e[0]=n[i],e[1]=n[i+1],e[2]=n[i+2],(u=Math.abs(Ae.lenVec3(Ae.subVec3(e,r,t))))>c&&(c=u);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,o=0,a=0,A=n.length,c=A/4;for(i=0;i<A;i+=4)s+=n[i+0],o+=n[i+1],a+=n[i+2];r[0]=s/c,r[1]=o/c,r[2]=a/c;var u,l=0;for(i=0;i<A;i+=4)e[0]=n[i+0],e[1]=n[i+1],e[2]=n[i+2],(u=Math.abs(Ae.lenVec3(Ae.subVec3(e,r,t))))>l&&(l=u);return r[3]=l,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,o=e.length;s<o;s+=3)n+=e[s+0],r+=e[s+1],i+=e[s+2];var a=e.length/3;return t[0]=n/a,t[1]=r/a,t[2]=i/a,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,o=t.length;s<o;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,o=Ae.MAX_DOUBLE,a=Ae.MIN_DOUBLE,A=Ae.MIN_DOUBLE,c=0,u=e.length;c<u;c+=4)t=e[c+0],n=e[c+1],(t*=r=1/(e[c+3]||1))<s&&(s=t),(n*=r)<o&&(o=n),t>a&&(a=t),n>A&&(A=n);return i[0]=s,i[1]=o,i[2]=a,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),o=.5*(e[2]+1),a=.5*(e[3]+1);return r[0]=Math.floor(i*t),r[1]=n-Math.floor(a*n),r[2]=Math.floor(o*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),o=.5*(r-t),a=i*i;return(2*t-2*n+s+o)*(i*a)+(-3*t+3*n-2*s-o)*a+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],o=t[2]-e[2],a=n[0]-e[0],A=n[1]-e[1],c=n[2]-e[2],u=s*c-o*A,l=o*a-i*c,h=i*A-s*a,d=Math.sqrt(u*u+l*l+h*h);return 0===d?(r[0]=0,r[1]=0,r[2]=0):(r[0]=u/d,r[1]=l/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,o,a,A,c,u){u=u||Ae.vec3();var l=Ae.subVec3(A,a,e),h=Ae.subVec3(c,a,t),d=Ae.cross3Vec3(o,h,n),f=Ae.dotVec3(l,d);if(f<1e-6)return null;var p=Ae.subVec3(s,a,r),v=Ae.dotVec3(p,d);if(v<0||v>f)return null;var g=Ae.cross3Vec3(p,l,i),m=Ae.dotVec3(o,g);if(m<0||v+m>f)return null;var y=Ae.dotVec3(h,g)/f;return u[0]=s[0]+y*o[0],u[1]=s[1]+y*o[1],u[2]=s[2]+y*o[2],u}}(),rayPlaneIntersect:function(){var e=new re(3),t=new re(3),n=new re(3),r=new re(3);return function(i,s,o,a,A,c){c=c||Ae.vec3(),s=Ae.normalizeVec3(s,e);var u=Ae.subVec3(a,o,t),l=Ae.subVec3(A,o,n),h=Ae.cross3Vec3(u,l,r);Ae.normalizeVec3(h,h);var d=-Ae.dotVec3(o,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,o,a){var A=Ae.subVec3(o,i,e),c=Ae.subVec3(s,i,t),u=Ae.subVec3(r,i,n),l=Ae.dotVec3(A,A),h=Ae.dotVec3(A,c),d=Ae.dotVec3(A,u),f=Ae.dotVec3(c,c),p=Ae.dotVec3(c,u),v=l*f-h*h;if(0===v)return null;var g=1/v,m=(f*d-h*p)*g,y=(l*p-h*d)*g;return a[0]=1-m-y,a[1]=y,a[2]=m,a}}(),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],o=e[1],a=e[2];return i[0]=t[0]*s+n[0]*o+r[0]*a,i[1]=t[1]*s+n[1]*o+r[1]*a,i[2]=t[2]*s+n[2]*o+r[2]*a,i},mergeVertices:function(e,t,n,r){var i,s,o,a,A,c,u={},l=[],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],o=e[A+2],void 0===u[a="".concat(Math.round(i*v),"_").concat(Math.round(s*v),"_").concat(Math.round(o*v))]&&(u[a]=h.length/3,h.push(i),h.push(s),h.push(o),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]))),l[A/3]=u[a],g+=2;for(A=0,c=r.length;A<c;A++)p[A]=l[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(o,a,A){var c,u,l,h,d,f,p,v,g,m=new Array(o.length/3);for(c=0,u=a.length;c<u;c+=3){l=a[c],h=a[c+1],d=a[c+2],e[0]=o[3*l],e[1]=o[3*l+1],e[2]=o[3*l+2],t[0]=o[3*h],t[1]=o[3*h+1],t[2]=o[3*h+2],n[0]=o[3*d],n[1]=o[3*d+1],n[2]=o[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[l]||(m[l]=[]),m[h]||(m[h]=[]),m[d]||(m[d]=[]),m[l].push(y),m[h].push(y),m[d].push(y)}for(A=A&&A.length===o.length?A:new Float32Array(o.length),c=0,u=m.length;c<u;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),o=new re(3);return function(a,A,c){for(var u=new Float32Array(a.length),l=0;l<A.length;l+=3){var h=A[l],d=a.subarray(3*h,3*h+3),f=c.subarray(2*h,2*h+2);h=A[l+1];var p=a.subarray(3*h,3*h+3),v=c.subarray(2*h,2*h+2);h=A[l+2];for(var g=a.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),o),B,s),k=void 0,M=0;M<3;M++)u[k=3*A[l+M]]+=C[0],u[k+1]+=C[1],u[k+2]+=C[2]}return u}}(),buildPickTriangles:function(e,t,n){for(var r,i,s,o,a,A=t.length,c=n?new Uint16Array(9*A):new Float32Array(9*A),u=new Uint8Array(12*A),l=0,h=0,d=0,f=0;f<A;f+=3)a=l>>24&255,o=l>>16&255,s=l>>8&255,i=255&l,r=3*t[f],c[h++]=e[r],c[h++]=e[r+1],c[h++]=e[r+2],u[d++]=i,u[d++]=s,u[d++]=o,u[d++]=a,r=3*t[f+1],c[h++]=e[r],c[h++]=e[r+1],c[h++]=e[r+2],u[d++]=i,u[d++]=s,u[d++]=o,u[d++]=a,r=3*t[f+2],c[h++]=e[r],c[h++]=e[r+1],c[h++]=e[r+2],u[d++]=i,u[d++]=s,u[d++]=o,u[d++]=a,l++;return{positions:c,colors:u}},faceToVertexNormals:function(e,t){var n,r,i,s,o,a,A,c,u,l,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,u=e.length;A<u;A+=3){a=A/3,r=e[A],i=e[A+1],s=e[A+2],void 0===p[o="".concat(Math.round(r*y),"_").concat(Math.round(i*y),"_").concat(Math.round(s*y))]?p[o]=[a]:p[o].push(a);var _=Ae.normalizeVec3([t[A],t[A+1],t[A+2]]);v[a]=_,n=Ae.vec4([_[0],_[1],_[2],1]),g[a]=n}for(o in p)if(p.hasOwnProperty(o)){var b=p[o],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];l=v[B],h=v[C];var k=Math.abs(Ae.angleVec3(l,h)/Ae.DEGTORAD);k<f&&(n[0]+=h[0],n[1]+=h[1],n[2]+=h[2],n[3]+=1)}}}for(A=0,u=t.length;A<u;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,o){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),o[0]=t[0],o[1]=t[1],o[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,o){var a="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,a,H),G(A,c,1,a,N),s[0]=H[0],s[1]=H[1],s[2]=H[2],Ae.subVec3(N,H,o),Ae.normalizeVec3(o)}),canvasPosToLocalRay:(O=new re(3),V=new re(3),function(e,t,n,r,i,s,o,a){Ae.canvasPosToWorldRay(e,t,n,r,s,O,V),Ae.worldRayToLocalRay(i,O,V,o,a)}),worldRayToLocalRay:function(){var e=new re(16),t=new re(4),n=new re(4);return function(r,i,s,o,a){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),o[0]=n[0],o[1]=n[1],o[2]=n[2],Ae.transformVec3(A,s,a)}}(),buildKDTree:function(){var e=new Float32Array;function t(n,r,i,s){var o,a,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,o=0,a=n.length;o<a;++o)for(var u=3*n[o],l=0;l<3;++l){var h=3*r[u+l];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(o=0,a=n.length;o<a;++o){var y=r[u=3*n[o]],_=3*r[u+1],b=3*r[u+2];i[3*y+d]<=f||i[_+d]<=f||i[b+d]<=f?p[v++]=n[o]:g[m++]=n[o]}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],o=e[n+1];s=(2*s+1)/255,o=(2*o+1)/255;var a=1-Math.abs(s)-Math.abs(o);a<0&&(s=(1-Math.abs(o))*(s>=0?1:-1),o=(1-Math.abs(s))*(o>=0?1:-1));var A=Math.sqrt(s*s+o*o+a*a);t[r+0]=s/A,t[r+1]=o/A,t[r+2]=a/A,r+=3}return t}};Ae.buildEdgeIndices=function(){var e=[],t=[],n=[],r=[],i=[],s=0,o=new Uint16Array(3),a=new Uint16Array(3),A=new Uint16Array(3),c=Ae.vec3(),u=Ae.vec3(),l=Ae.vec3(),h=Ae.vec3(),d=Ae.vec3(),f=Ae.vec3(),p=Ae.vec3();return function(v,g,m,y){!function(i,s){var o,a,A,c,u,l,h={},d=Math.pow(10,4),f=0;for(u=0,l=i.length;u<l;u+=3)o=i[u],a=i[u+1],A=i[u+2],void 0===h[c=Math.round(o*d)+"_"+Math.round(a*d)+"_"+Math.round(A*d)]&&(h[c]=f/3,e[f++]=o,e[f++]=a,e[f++]=A),t[u/3]=h[c];for(u=0,l=s.length;u<l;u++)r[u]=t[s[u]],n[r[u]]=s[u]}(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?(o[0]=e[m],o[1]=e[m+1],o[2]=e[m+2],a[0]=e[y],a[1]=e[y+1],a[2]=e[y+2],A[0]=e[_],A[1]=e[_+1],A[2]=e[_+2],Ae.decompressPosition(o,n,c),Ae.decompressPosition(a,n,u),Ae.decompressPosition(A,n,l)):(c[0]=e[m],c[1]=e[m+1],c[2]=e[m+2],u[0]=e[y],u[1]=e[y+1],u[2]=e[y+2],l[0]=e[_],l[1]=e[_+1],l[2]=e[_+2]),Ae.subVec3(l,u,h),Ae.subVec3(c,u,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,k,M,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!==(k=T[C]).face2&&(M=i[k.face1].normal,E=i[k.face2].normal,Ae.dotVec3(M,E)>I)||(F=n[k.index1],x=n[k.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 o=ie[0]*t[0]+ie[1]*t[1]+ie[2]*t[2];if(o<0)return!0}return!1};var ce=new Float32Array(3),ue=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 o=i.slice();if(o[s+3]=(i[s]+i[s+3])/2,e.left={aabb:o},Ae.containsAABB3(o,r))return void this._insertEntity(e.left,t,n+1)}if(!e.right){var a=i.slice();if(a[s]=(i[s]+i[s+3])/2,e.right={aabb:a},Ae.containsAABB3(a,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}(),le=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 o=t.attributes[s];i[n[o.nodeName]||o.nodeName]=o.nodeValue}for(var a=0;a<t.childNodes.length;a++){(s=e(t.childNodes[a],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],o=i[3];o=window.decodeURIComponent(o),s&&(o=window.atob(o));try{for(var a=new ArrayBuffer(o.length),A=new Uint8Array(a),c=0;c<o.length;c++)A[c]=o.charCodeAt(c);Fe.scheduleTask((function(){t(a)}))}catch(e){Fe.scheduleTask((function(){n(e)}))}}else{var u=new XMLHttpRequest;u.open("GET",e,!0),u.responseType="arraybuffer",u.onreadystatechange=function(){4===u.readyState&&(200===u.status?t(u.response):n("loadArrayBuffer error : "+u.response))},u.send(null)}},queryString:pe,isArray:function(e){return e&&!e.propertyIsEnumerable("length")&&"object"===k(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 le,be={sceneId:null,time:null,startTime:null,prevTime:null,deltaTime:null},we=[],Be=0,Ce=0;var ke,Me,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};ke=function(){xe()},Me=100,Ee=Date.now()+Me,function e(){var t=Date.now()-Ee;ke(),Ee+=Me,setTimeout(e,Math.max(0,Me-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,o=!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(o),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,o=e.on,a=!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 u in c)if(c.hasOwnProperty){n=c[u];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 l,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=(l=p.subs).length;h<d;h++)f.off(l[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)),a&&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)),o)for(m in o)if(o.hasOwnProperty(m)){if(y=o[m],ge.isFunction(y)?(_=y,b=null):(_=y.callback,b=y.scope),!_)continue;g.subs.push(n.on(m,_,b))}}return a&&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],o=r[2],a=r[3],A=r[4],c=r[5],u=r[6],l=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(a-i,l-A,p-h,y-v),e.planes[1].set(a+i,l+A,p+h,y+v),e.planes[2].set(a-s,l-c,p-d,y-g),e.planes[3].set(a+s,l+c,p+d,y+g),e.planes[4].set(a-o,l-u,p-f,y-m),e.planes[5].set(a+o,l+u,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],o=0;o<6;++o){var a=e.planes[o];if(a.normal[0]*s[a.testVertex[0]][0]+a.normal[1]*s[a.testVertex[1]][1]+a.normal[2]*s[a.testVertex[2]][2]+a.offset<0)return Qe.OUTSIDE;a.normal[0]*s[1-a.testVertex[0]][0]+a.normal[1]*s[1-a.testVertex[1]][1]+a.normal[2]*s[1-a.testVertex[2]][2]+a.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 o=i.entities,a=0,A=o.length;a<A;a++){var c=o[a];if(c.visible){var u=c.aabb;if(e._pickMode===n.PICK_MODE_INSIDE)Oe(e._marqueeFrustum,u)===Qe.INSIDE&&t.push(c.id);else Oe(e._marqueeFrustum,u)!==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,o=2/n,a=e.clientHeight/e.clientWidth,A=(this._canvasMarquee[0]-r)*s-1,c=(this._canvasMarquee[2]-r)*s-1,u=-(this._canvasMarquee[3]-i)*o+1,l=-(this._canvasMarquee[1]-i)*o+1,h=this.viewer.scene.camera.frustum.near*(17*a);Ae.frustumMat4(A,c,u*a,l*a,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,o,a,A,c,u,l=e.marqueePicker,h=l.viewer.scene.canvas.canvas,d=!1,f=!1,p=!1;return h.addEventListener("mousedown",(function(e){r.getActive()&&0===e.button&&(u=setTimeout((function(){var t=l.viewer.scene.input;t.keyDown[t.KEY_CTRL]||l.clear(),i=e.pageX,s=e.pageY,A=e.offsetX,l.setMarqueeCorner1([i,s]),d=!0,l.viewer.cameraControl.pointerEnabled=!1,l.setMarqueeVisible(!0),h.style.cursor="crosshair"}),400),f=!0)})),h.addEventListener("mouseup",(function(e){if(r.getActive()&&(d||p)&&0===e.button){clearTimeout(u),o=e.pageX,a=e.pageY;var t=Math.abs(o-i),n=Math.abs(a-s);d=!1,l.viewer.cameraControl.pointerEnabled=!0,p&&(p=!1),(t>3||n>3)&&l.pick()}})),document.addEventListener("mouseup",(function(e){r.getActive()&&0===e.button&&(clearTimeout(u),d&&(l.setMarqueeVisible(!1),d=!1,f=!1,p=!0,l.viewer.cameraControl.pointerEnabled=!0))}),!0),h.addEventListener("mousemove",(function(e){r.getActive()&&0===e.button&&f&&(clearTimeout(u),d&&(o=e.pageX,a=e.pageY,c=e.offsetX,l.setMarqueeVisible(!0),l.setMarqueeCorner2([o,a]),l.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,o=Math.min(s/300,1),a=r+(2-r)*o;t._circleRadius=a,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"),o<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),o=Ae.subVec3(s,i,[]);return Ae.normalizeVec3(o,[])}},{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 o,a=0,A=s-1;a<=A;)if((o=r[i=Math.floor(a+(A-a)/2)]-n)<0)a=i+1;else{if(!(o>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],o=t[r],a=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],o[0],a[0],A[0],i),c[1]=Ae.catmullRomInterpolate(s[1],o[1],a[1],A[1],i),c[2]=Ae.catmullRomInterpolate(s[2],o[2],a[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 o=Ae.lenVec3(Ae.subVec3(this._frames[i].eye,this._frames[i-1].eye,t));r[i]=o,n+=o}for(var a=1,A=this._frames.length;a<A;a++){var c=r[a]/n*e;this._frames[a].t=this._frames[a-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,o,a,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,o=e.up;else if(e.eye)i=e.eye;else if(e.look)s=e.look;else{var u=e;if((ge.isNumeric(u)||ge.isString(u))&&(a=u,!(u=this.scene.components[a])))return this.error("Component not found: "+ge.inQuotes(a)),void(t&&(n?t.call(n):t()));c||(r=u.aabb||this.scene.aabb)}var l=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=l||h;var d=Ae.subVec3(this._eye1,this._look1,Ze),f=Ae.normalizeVec3(d),p=l?Ae.getAABB3DiagPoint(r,l):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||o)&&(this._flyingEyeLookUp=!!i&&!!s&&!!o,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]),o&&(this._up2[0]=o[0],this._up2[1]=o[1],this._up2[2]=o[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,o=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 a=e;if((ge.isNumeric(a)||ge.isString(a))&&(n=a,!(a=this.scene.components[n])))return void this.error("Component not found: "+ge.inQuotes(n));t=a.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,u=A?Ae.getAABB3DiagPoint(t,A):Ae.getAABB3Diag(t);i=A||Ae.getAABB3Center(t,i),this._trail?Ae.subVec3(o.look,i,$e):Ae.subVec3(o.eye,o.look,$e),Ae.normalizeVec3($e),c=(void 0!==e.fit?e.fit:this._fit)?Math.abs(u/Math.tan((e.fitFOV||this._fitFOV)*Ae.DEGTORAD)):Ae.lenVec3(Ae.subVec3(o.eye,o.look,Ze)),Ae.mulVec3Scalar($e,c),o.eye=Ae.addVec3(i,$e,Ze),o.look=i,this.scene.camera.ortho.scale=1.1*u}else(r||i||s)&&(r&&(o.eye=r),i&&(o.look=i),s&&(o.up=s));e.projection&&(o.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,o,a,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=o,this.length=0,this.dataLength=i,this.numItems=0,this.itemSize=s,this.normalized=!!a,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}(),ot=function(){var e=[],t=[],n=[],r=[],i=[],s=0,o=new Uint16Array(3),a=new Uint16Array(3),A=new Uint16Array(3),c=Ae.vec3(),u=Ae.vec3(),l=Ae.vec3(),h=Ae.vec3(),d=Ae.vec3(),f=Ae.vec3(),p=Ae.vec3();return function(v,g,m,y){!function(i,s){var o,a,A,c,u,l,h={},d=Math.pow(10,4),f=0;for(u=0,l=i.length;u<l;u+=3)o=i[u],a=i[u+1],A=i[u+2],void 0===h[c=Math.round(o*d)+"_"+Math.round(a*d)+"_"+Math.round(A*d)]&&(h[c]=f/3,e[f++]=o,e[f++]=a,e[f++]=A),t[u/3]=h[c];for(u=0,l=s.length;u<l;u++)r[u]=t[s[u]],n[r[u]]=s[u]}(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?(o[0]=e[m],o[1]=e[m+1],o[2]=e[m+2],a[0]=e[y],a[1]=e[y+1],a[2]=e[y+2],A[0]=e[_],A[1]=e[_+1],A[2]=e[_+2],Ae.decompressPosition(o,n,c),Ae.decompressPosition(a,n,u),Ae.decompressPosition(A,n,l)):(c[0]=e[m],c[1]=e[m+1],c[2]=e[m+2],u[0]=e[y],u[1]=e[y+1],u[2]=e[y+2],l[0]=e[_],l[1]=e[_+1],l[2]=e[_+2]),Ae.subVec3(l,u,h),Ae.subVec3(c,u,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,k,M,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!==(k=T[C]).face2&&(M=i[k.face1].normal,E=i[k.face2].normal,Ae.dotVec3(M,E)>I)||(F=n[k.index1],x=n[k.index2],(!P&&F>65535||x>65535)&&(P=!0),U.push(F),U.push(x));return P?new Uint32Array(U):new Uint16Array(U)}}();var at,At,ct=(at=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,o=e[4]-r,a=e[5]-i,A=65535;return Ae.identityMat4(at),Ae.translationMat4v(e,at),Ae.identityMat4(At),Ae.scalingMat4v([s/A,o/A,a/A],At),Ae.mulMat4(at,At,t),t}),ut=function(){var e=Ae.mat4(),t=Ae.mat4();return function(n,r,i){var s,o=new Uint16Array(n.length),a=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)o[s+0]=Math.max(0,Math.min(65535,Math.floor((n[s+0]-r[0])*a[0]))),o[s+1]=Math.max(0,Math.min(65535,Math.floor((n[s+1]-r[1])*a[1]))),o[s+2]=Math.max(0,Math.min(65535,Math.floor((n[s+2]-r[2])*a[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:o,decodeMatrix:Ae.mulMat4(e,t,Ae.identityMat4())}}}();var lt=function(){var e=Ae.mat3(),t=Ae.mat3();return function(n,r,i){var s,o=new Uint16Array(n.length),a=new Float32Array([65535/(i[0]-r[0]),65535/(i[1]-r[1])]);for(s=0;s<n.length;s+=2)o[s+0]=Math.max(0,Math.min(65535,Math.floor((n[s+0]-r[0])*a[0]))),o[s+1]=Math.max(0,Math.min(65535,Math.floor((n[s+1]-r[1])*a[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:o,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 o=(1-Math.abs(s))*(i>=0?1:-1),a=(1-Math.abs(i))*(s>=0?1:-1);i=o,s=a}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:ut,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:lt,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),o=0;o<e.length;o+=3)n=t=ht(e,o,"floor","floor"),r=i=ft(e,o,dt(t)),(r=ft(e,o,dt(t=ht(e,o,"ceil","floor"))))>i&&(n=t,i=r),(r=ft(e,o,dt(t=ht(e,o,"floor","ceil"))))>i&&(n=t,i=r),(r=ft(e,o,dt(t=ht(e,o,"ceil","ceil"))))>i&&(n=t,i=r),s[o]=n[0],s[o+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],o=e[n+1];s=(2*s+1)/255,o=(2*o+1)/255;var a=1-Math.abs(s)-Math.abs(o);a<0&&(s=(1-Math.abs(o))*(s>=0?1:-1),o=(1-Math.abs(s))*(o>=0?1:-1));var A=Math.sqrt(s*s+o*o+a*a);t[r+0]=s/A,t[r+1]=o/A,t[r+2]=a/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,o=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":s.primitive=o.POINTS,s.primitiveName=i.primitive;break;case"lines":s.primitive=o.LINES,s.primitiveName=i.primitive;break;case"line-loop":s.primitive=o.LINE_LOOP,s.primitiveName=i.primitive;break;case"line-strip":s.primitive=o.LINE_STRIP,s.primitiveName=i.primitive;break;case"triangles":s.primitive=o.TRIANGLES,s.primitiveName=i.primitive;break;case"triangle-strip":s.primitive=o.TRIANGLE_STRIP,s.primitiveName=i.primitive;break;case"triangle-fan":s.primitive=o.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=o.TRIANGLES,s.primitiveName=i.primitive}if(i.positions)if(r._state.compressGeometry){var a=pt.getPositionsBounds(i.positions),A=pt.compressPositions(i.positions,a.min,a.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),u=pt.compressUVs(i.uv,c.min,c.max);s.uv=u.quantized,s.uvDecodeMatrix=u.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(o,o.ELEMENT_ARRAY_BUFFER,s.indices,s.indices.length,1,o.STATIC_DRAW),vt.indices+=s.indicesBuf.numItems),s.positions&&(s.positionsBuf=new st(o,o.ARRAY_BUFFER,s.positions,s.positions.length,3,o.STATIC_DRAW),vt.positions+=s.positionsBuf.numItems),s.normals){var l=s.compressGeometry;s.normalsBuf=new st(o,o.ARRAY_BUFFER,s.normals,s.normals.length,3,o.STATIC_DRAW,l),vt.normals+=s.normalsBuf.numItems}return s.colors&&(s.colorsBuf=new st(o,o.ARRAY_BUFFER,s.colors,s.colors.length,4,o.STATIC_DRAW),vt.colors+=s.colorsBuf.numItems),s.uv&&(s.uvBuf=new st(o,o.ARRAY_BUFFER,s.uv,s.uv.length,2,o.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=ot(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]),o=0;o<e.length;o+=3){var a=n(o,r[0]),A=n(o+1,r[1]),c=n(o+2,r[2]);Ae.addVec3(a,A,r[3]),Ae.addVec3(c,r[3],r[3]);var u=Ae.lenVec3(Ae.cross3Vec3(Ae.subVec3(A,a,r[1]),Ae.subVec3(c,a,r[2]),r[0]))/2;i+=u,Ae.mulVec3Scalar(r[3],u,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,o=r._state,a=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":o.primitive=a.POINTS,o.primitiveName=i.primitive;break;case"lines":o.primitive=a.LINES,o.primitiveName=i.primitive;break;case"line-loop":o.primitive=a.LINE_LOOP,o.primitiveName=i.primitive;break;case"line-strip":o.primitive=a.LINE_STRIP,o.primitiveName=i.primitive;break;case"triangles":o.primitive=a.TRIANGLES,o.primitiveName=i.primitive;break;case"triangle-strip":o.primitive=a.TRIANGLE_STRIP,o.primitiveName=i.primitive;break;case"triangle-fan":o.primitive=a.TRIANGLE_FAN,o.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'."),o.primitive=a.TRIANGLES,o.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),u=pt.compressPositions(i.positions,c.min,c.max);s=u.quantized,o.positionsDecodeMatrix=u.decodeMatrix,o.positionsBuf=new st(a,a.ARRAY_BUFFER,s,s.length,3,a.STATIC_DRAW),yt.positions+=o.positionsBuf.numItems,Ae.positions3ToAABB3(i.positions,r._aabb),Ae.positions3ToAABB3(s,_t,o.positionsDecodeMatrix),Ae.AABB3ToOBB3(_t,r._obb)}if(i.colors){var l=i.colors.constructor===Float32Array?i.colors:new Float32Array(i.colors);o.colorsBuf=new st(a,a.ARRAY_BUFFER,l,l.length,4,a.STATIC_DRAW),yt.colors+=o.colorsBuf.numItems}if(i.uv){var h=pt.getUVBounds(i.uv),d=pt.compressUVs(i.uv,h.min,h.max),f=d.quantized;o.uvDecodeMatrix=d.decodeMatrix,o.uvBuf=new st(a,a.ARRAY_BUFFER,f,f.length,2,a.STATIC_DRAW),yt.uvs+=o.uvBuf.numItems}if(i.normals){var p=pt.compressNormals(i.normals),v=o.compressGeometry;o.normalsBuf=new st(a,a.ARRAY_BUFFER,p,p.length,3,a.STATIC_DRAW,v),yt.normals+=o.normalsBuf.numItems}var g=i.indices.constructor===Uint32Array||i.indices.constructor===Uint16Array?i.indices:new Uint32Array(i.indices);o.indicesBuf=new st(a,a.ELEMENT_ARRAY_BUFFER,g,g.length,1,a.STATIC_DRAW),yt.indices+=o.indicesBuf.numItems;var m=ot(s,g,o.positionsDecodeMatrix,r._edgeThreshold);return r._edgeIndicesBuf=new st(a,a.ELEMENT_ARRAY_BUFFER,m,m.length,1,a.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,o=s.vertices,a=s.uvt,A=s.indices;i.processes--,n(ge.apply(t,{primitive:"triangles",positions:o,normals:null,uv:a,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),o=wt.edit.unwrap(s.i_verts,s.c_verts,3),a=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),u=0;u<s.i_verts.length;u++)c[u]=u;i.processes--,n(ge.apply(t,{primitive:"triangles",positions:o,normals:a.length>0?a:null,autoNormals:0===a.length,uv:A,indices:c}))}),(function(e){console.error("loadOBJGeometry: "+e),i.processes--,r()}))}))}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,o=i?i[1]:0,a=i?i[2]:0,A=-t+s,c=-n+o,u=-r+a,l=t+s,h=n+o,d=r+a;return ge.apply(e,{positions:[l,h,d,A,h,d,A,c,d,l,c,d,l,h,d,l,c,d,l,c,u,l,h,u,l,h,d,l,h,u,A,h,u,A,h,d,A,h,d,A,h,u,A,c,u,A,c,d,A,c,u,l,c,u,l,c,d,A,c,d,l,c,u,A,c,u,A,h,u,l,h,u],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 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,o=i?i[1]:0,a=i?i[2]:0,A=-t+s,c=-n+o,u=-r+a,l=t+s,h=n+o,d=r+a;return ge.apply(e,{primitive:"lines",positions:[A,c,u,A,c,d,A,h,u,A,h,d,l,c,u,l,c,d,l,h,u,l,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 Mt({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 o,a,A,c,u,l,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,k=1/i,M=(t-n)/s,E=[],F=[],x=[],U=[],I=(90-180*Math.atan(r/(n-t))/Math.PI)/90;for(o=0;o<=s;o++)for(u=t-o*M,l=w-o*B,a=0;a<=i;a++)A=Math.sin(a*C),c=Math.cos(a*C),F.push(u*A),F.push(I),F.push(u*c),x.push(a*k),x.push(1*o/s),E.push(u*A+y),E.push(l+_),E.push(u*c+b);for(o=0;o<s;o++)for(a=0;a<=i;a++)d=(h=o*(i+1)+a)+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),a=0;a<=i;a++)A=Math.sin(a*C),c=Math.cos(a*C),p=.5*Math.sin(a*C)+.5,v=.5*Math.cos(a*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(a=0;a<i;a++)m=f,h=f+1+a,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),a=0;a<=i;a++)A=Math.sin(a*C),c=Math.cos(a*C),p=.5*Math.sin(a*C)+.5,v=.5*Math.cos(a*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(a=0;a<i;a++)m=f,h=f+1+a,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=[],o=[],a=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),o.push(a++),o.push(a++),o.push(a++),o.push(a++);return ge.apply(e,{primitive:"lines",positions:s,indices:o})}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,o,a,A,c,u,l,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),k=new Float32Array(_*b*3),M=new Float32Array(_*b*2),E=0,F=0;for(s=0;s<b;s++){var x=s*B-g;for(o=0;o<_;o++)a=o*w-v,C[E]=a+d,C[E+1]=f,C[E+2]=-x+p,k[E+1]=1,M[F]=o/m,M[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(o=0;o<m;o++)A=o+_*s,c=o+_*(s+1),u=o+1+_*(s+1),l=o+1+_*s,U[E]=l,U[E+1]=c,U[E+2]=A,U[E+3]=l,U[E+4]=u,U[E+5]=c,E+=6;return ge.apply(e,{positions:C,normals:k,uv:M,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 o=e.heightSegments||18;o<0&&(console.error("negative heightSegments not allowed - will invert"),o*=-1),(o=Math.floor(t*o))<18&&(o=18);var a=e.widthSegments||18;a<0&&(console.error("negative widthSegments not allowed - will invert"),a*=-1),(a=Math.floor(t*a))<18&&(a=18);var A,c,u,l,h,d,f,p,v,g,m,y,_,b,w=[],B=[],C=[],k=[];for(A=0;A<=o;A++)for(u=A*Math.PI/o,l=Math.sin(u),h=Math.cos(u),c=0;c<=a;c++)d=2*c*Math.PI/a,f=Math.sin(d),p=Math.cos(d)*l,v=h,g=f*l,m=1-c/a,y=A/o,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<o;A++)for(c=0;c<a;c++)b=(_=A*(a+1)+c)+a+1,k.push(_+1),k.push(b+1),k.push(b),k.push(_+1),k.push(b),k.push(_);return ge.apply(e,{positions:w,normals:B,uv:C,indices:k})}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 o,a,A,c,u,l,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=[],k=[];for(d=0;d<=i;d++)for(h=0;h<=r;h++)o=h/r*s,a=.785398+d/i*Math.PI*2,y=t*Math.cos(o),_=t*Math.sin(o),A=(t+n*Math.cos(a))*Math.cos(o),c=(t+n*Math.cos(a))*Math.sin(o),u=n*Math.sin(a),w.push(A+y),w.push(c+_),w.push(u+b),C.push(1-h/r),C.push(d/i),l=Ae.normalizeVec3(Ae.subVec3([A,c,u],[y,_,b],[]),[]),B.push(l[0]),B.push(l[1]),B.push(l[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,k.push(f),k.push(p),k.push(v),k.push(v),k.push(g),k.push(f);return ge.apply(e,{positions:w,normals:B,uv:C,indices:k})}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 o=(s=(s=s.replace(/ +(?= )/g,"")).replace(/(^\s+|\s+$)/g,"")).split(" ");if("g"==o[0]&&(n.to=t.i_verts.length,null==t.groups[o[1]]&&(t.groups[o[1]]={from:t.i_verts.length,to:0}),n=t.groups[o[1]]),"v"==o[0]){var a=parseFloat(o[1]),A=parseFloat(o[2]),c=parseFloat(o[3]);t.c_verts.push(a,A,c)}if("vt"==o[0]){a=parseFloat(o[1]),A=1-parseFloat(o[2]);t.c_uvt.push(a,A)}if("vn"==o[0]){a=parseFloat(o[1]),A=parseFloat(o[2]),c=parseFloat(o[3]);t.c_norms.push(a,A,c)}if("f"==o[0]){var u=o[1].split("/"),l=o[2].split("/"),h=o[3].split("/"),d=parseInt(u[0])-1,f=parseInt(l[0])-1,p=parseInt(h[0])-1,v=parseInt(u[1])-1,g=parseInt(l[1])-1,m=parseInt(h[1])-1,y=parseInt(u[2])-1,_=parseInt(l[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==o.length){var k=o[4].split("/"),M=parseInt(k[0])-1,E=parseInt(k[1])-1,F=parseInt(k[2])-1;M<0&&(M=w+M+1),E<0&&(E=B+E+1),F<0&&(F=C+F+1),t.i_verts.push(d,p,M),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,o=wt.bin.rsl(e,r+2)/n.skinheight;t.c_uvt.push(s,o),r+=4}r=n.offset_tris;var a=[],A=[];t.i_verts=a,t.i_uvt=A;for(i=0;i<n.num_tris;i++)a.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 u={},l=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,u.name=wt.bin.rASCII0(e,r),r+=16,u.verts=[],u.norms=[];for(var g=0;g<n.num_vertices;g++)u.verts.push(e[r]*l+f,e[r+1]*h+p,e[r+2]*d+v),u.norms.push(c[3*e[r+3]],c[3*e[r+3]+1],c[3*e[r+3]+2]),r+=4;t.frames.push(u)}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],o=n.getElementsByTagName("library_images")[0],a=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)),o&&(r.images=wt.parse.fromCollada._libImages(o)),a&&(r.materials=wt.parse.fromCollada._libMaterials(a)),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(" "),o=s.length-(""==s[s.length-1]?1:0),a=new Array(o),A=0;A<o;A++)a[A]=parseFloat(s[A]);r[n[i].getAttribute("id")]=a}t.triangles=[];var c=e.getElementsByTagName("triangles");if(null==c)return t;for(i=0;i<c.length;i++){var u={},l=c[i];u.material=l.getAttribute("material");var h=l.getElementsByTagName("input"),d=[];for(A=0;A<h.length;A++){var f=h[A];a=[];d[parseInt(f.getAttribute("offset"))]=a;var p=f.getAttribute("semantic");u["s_"+p]="VERTEX"==p?e.getElementsByTagName("vertices")[0].getElementsByTagName("input")[0].getAttribute("source").substring(1):f.getAttribute("source").substring(1),u["i_"+p]=a,r[u["s_"+p]]}var v=l.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(u)}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 o=i[s].getElementsByTagName("surface")[0];o&&(r.surface=o.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),o=wt.bin.ril(e,i+2);16384==s&&(null==r.objects&&(r.objects=[]),r.objects.push(wt.parse.from3DS._edit_object(e,i,o))),i+=o}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),o=wt.bin.ril(e,i+2);45058==s&&(null==r.desc&&(r.desc=[]),r.desc.push(wt.parse.from3DS._keyf_objdes(e,i,o))),i+=o}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),o=wt.bin.ril(e,i+2);45072==s&&(r.hierarchy=wt.parse.from3DS._keyf_objhierarch(e,i,o)),45073==s&&(r.dummy_name=wt.bin.rASCII0(e,i+6)),i+=o}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),o=wt.bin.ril(e,i+2);16640==s&&(r.mesh=wt.parse.from3DS._obj_trimesh(e,i,o)),i+=o}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),o=wt.bin.ril(e,i+2);16656==s&&(r.vertices=wt.parse.from3DS._tri_vertexl(e,i,o)),16672==s&&(r.indices=wt.parse.from3DS._tri_facel1(e,i,o)),16704==s&&(r.uvt=wt.parse.from3DS._tri_mappingcoors(e,i,o)),16736==s&&(r.local=wt.parse.from3DS._tri_local(e,i,o)),i+=o}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 o=0;o<s;o++)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 o=0;o<s;o++)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 o=0;o<s;o++)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 o=40;return e.vertices&&(wt.bin.wil(s,16,o),wt.bin.wil(s,20,4*e.vertices.length),wt.parse.fromBIV._writeFloats(s,o,e.vertices),o+=4*e.vertices.length),e.uvt&&(wt.bin.wil(s,24,o),wt.bin.wil(s,28,4*e.uvt.length),wt.parse.fromBIV._writeFloats(s,o,e.uvt),o+=4*e.uvt.length),e.indices&&(wt.bin.wil(s,32,o),wt.bin.wil(s,36,4*e.indices.length),wt.parse.fromBIV._writeInts(s,o,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,o=t+1,a=0;a<o;a++)for(var A=0;A<s;A++){var c=A*(2/e)-1,u=a*(2/t)-1;i.verts.push(c,u,0),i.uvt.push(n*A/e,r*a/t),a<t&&A<e&&i.inds.push(a*s+A,a*s+A+1,(a+1)*s+A,a*s+A+1,(a+1)*s+A,(a+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 o=0;o<r;o++){var a=-Math.PI/2+s*Math.PI/t,A=2*o*Math.PI/e,c=Math.cos(a)*Math.cos(A),u=Math.sin(a),l=Math.cos(a)*Math.sin(A);n.verts.push(c,u,l),n.uvt.push(o/e,s/t),s<t&&o<e&&n.inds.push(r*s+o,r*s+o+1,r*(s+1)+o,r*s+o+1,r*(s+1)+o,r*(s+1)+o+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,o=n,a=Math.cos(i),A=Math.cos(s),c=Math.cos(o),u=Math.sin(i),l=Math.sin(s),h=Math.sin(o);return r[0]=A*c,r[1]=-A*h,r[2]=l,r[4]=a*h+u*l*c,r[5]=a*c-u*l*h,r[6]=-u*A,r[8]=u*h-a*l*c,r[9]=u*c+a*l*h,r[10]=a*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 o=0;o<r;o++)i[t[s]*r+o]=n[e[s]*r+o];return i},wt.utils={},wt.utils.getAABB=function(e){var t,n,r,i,s,o;i=s=o=-(t=n=r=999999999);for(var a=0;a<e.length;a+=3){var A=e[a+0],c=e[a+1],u=e[a+2];A<t&&(t=A),A>i&&(i=A),c<n&&(n=c),c>s&&(s=c),u<r&&(r=u),c>o&&(o=u)}return{min:{x:t,y:n,z:r},max:{x:i,y:s,z:o}}};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,o=[],a=[],A=e.text;ge.isNumeric(A)&&(A=""+A);for(var c,u,l,h,d,f,p,v,g,m=(A||"").split("\n"),y=0,_=0,b=.04,w=0;w<m.length;w++){c=0,l=(u=m[w]).length;for(var B=0;B<l;B++)if(h=Pt[u.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]?(o.push(c+g[0]*s*b+n),o.push(_+g[1]*s*b+r),o.push(0+i),-1===f?f=y:(-1===p||(f=p),p=y),y++,d?d=!1:(a.push(f),a.push(p))):d=1;c+=h.width*b*s}_-=35*b*s}return ge.apply(e,{primitive:"lines",positions:o,indices:a})}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],o=e.endPoint[0],a=e.endPoint[1],A=e.endPoint[2],c=Math.sqrt(Math.pow(o-r,2)+Math.pow(a-i,2)+Math.pow(A-s,2)),u=[(o-r)/c,(a-i)/c,(A-s)/c];if(e.pattern){var l=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=[u[0]*g,u[1]*g,u[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)>=l&&(f=0),d+=g,g=e.pattern[f]}e.extendToEnd&&(n.push(o,a,A),t.push(t.length-2),t.push(t.length-1))}else t.push(0),t.push(1),n.push(r,i,s,o,a,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,o=0,a=s.length;o<a;o++)r.addChild(s[o],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],o=e[1]-s,a=Float32Array.from([e[2]])[0],A=e[2]-a;t[0]=r,t[1]=s,t[2]=a,n[0]=i,n[1]=o,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,o=Math.round(i[1]/r)*r,a=Math.round(i[2]/r)*r;n[0]=s,n[1]=o,n[2]=a;var A=0!==n[0]||0!==n[1]||0!==n[2];if(A)for(var c=0,u=e.length;c<u;c+=3)t[c+0]=e[c+0]-s,t[c+1]=e[c+1]-o,t[c+2]=e[c+2]-a;return A}var qt=1e3,$t=1001,en=1002,tn=1003,nn=1004,rn=1004,sn=1005,on=1005,an=1006,An=1007,cn=1007,un=1008,ln=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,kn=1023,Mn=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,or=36492,ar=3e3,Ar=3001,cr=1e4,ur=10001,lr=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=[],o=[],a=[],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&&o.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,o=function(t){return s&&t.push("uniform ".concat(e," ").concat(n,";"))};t.push(o),r.push(o);var A={toString:function(){return s=!0,n}};return a.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,o=function(t){return s&&t.push("uniform ".concat(e," ").concat(n,"[").concat(i,"];"))};t.push(o),r.push(o);var A={toString:function(){return s=!0,n}};return a.push((function(e){return A.setInputValue=s&&e(n),null})),A},createUniformBlock:function(e,n,i){var s=!1,o=Object.keys(n),A=function(t){s&&(t.push("uniform ".concat(e," {")),o.forEach((function(e){return t.push(" ".concat(n[e]," ").concat(e,";"))})),t.push("};"))};t.push(A),r.push(A);var c={};return o.forEach((function(e){return c[e]={toString:function(){return s=!0,e}}})),a.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,o){var a=!1,A=o?o+" ":"";return t.push((function(t){return a&&t.push("".concat(A,"out ").concat(e," ").concat(i,";"))})),n.push((function(e){return a&&e.push("".concat(i," = ").concat(s(),";"))})),r.push((function(t){return a&&t.push("".concat(A,"in ").concat(e," ").concat(i,";"))})),{toString:function(){return a=!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,u,l){var h,d,f=l.getLogDepth,v=l.clipPos,g=l.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(l.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(l.testPerspectiveForGl_FragDepth?"".concat(_," == 0.0 ? gl_FragCoord.z : "):"","log2(").concat(f(w),") * ").concat(b," * 0.5;")):l.cleanerEdges&&y.push("gl_FragDepth = gl_FragCoord.z + length(vec2(dFdx(gl_FragCoord.z), dFdy(gl_FragCoord.z)));");var B,C,k=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=l.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,o=(n.mesh.layerIndex||0)*s,a=e<s&&n.mesh.renderFlags.sectionPlanesActivePerLayer[o+e];return r(t,a,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=l.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=l.getGammaFactor,T=c.createUniform("float","gammaFactor",(function(e){return e(I())}));l.appendFragmentOutputs(y,I&&function(e){return"".concat(k,"(").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(l.clippableTest(),") {"));var n=c.createVarying("highp vec3","vHighpWorldPosition",(function(){return"".concat(l.worldPositionAttribute,".xyz")}));if(e.push(" float dist = ".concat(F(n),";")),l.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(l.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(l.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(l.getPointSize?["gl_PointSize = ".concat(l.getPointSize(),";")]:[]),p(function(){var e=[];return n.forEach((function(t){return t(e)})),e}())),O=l.getVertexData?l.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","// "+u+" "+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=M(G(A.VERTEX_SHADER,H),2),W=j[0],z=j[1],X=M(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 $=a.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:o.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)}))},o=s("light",(function(){return t.lightMaps})),a=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:o&&function(e){return"".concat(o(e),".rgb")},getReflection:a&&function(e,t){return"".concat(a(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),o=e.getAttribLocation(t,s.name);n[s.name]=function(t){t.bindAtLocation(o),e.enableVertexAttribArray(o);var n=t.attributeDivisor;n&&e.vertexAttribDivisor(o,n)},n[s.name].attributeHash="".concat(o.toString().padStart(1+Math.floor(Math.log10(r)),"0"),":").concat(s.name)},s=0;s<r;++s)i(s);for(var o=e.getProgramParameter(t,e.ACTIVE_UNIFORM_BLOCKS),a=function(r){var i=e.getActiveUniformBlockName(t,r),s=e.getUniformBlockIndex(t,i),o=r;e.uniformBlockBinding(t,s,o);var a=e.createBuffer();n[i]=function(t){e.bindBuffer(e.UNIFORM_BUFFER,a),e.bufferData(e.UNIFORM_BUFFER,t,e.DYNAMIC_DRAW),e.bindBufferBase(e.UNIFORM_BUFFER,o,a)}},A=0;A<o;++A)a(A);for(var c=e.getProgramParameter(t,e.ACTIVE_UNIFORMS),u=0,l=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 o=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 a=u++;n[s]=function(t){var n=t.bind(a);return n&&e.uniform1i(o,a),n}}else n[s]=function(){if(1===i.size)switch(i.type){case e.BOOL:case e.INT:return function(t){return e.uniform1i(o,t)};case e.FLOAT:return function(t){return e.uniform1f(o,t)};case e.FLOAT_VEC2:return function(t){return e.uniform2fv(o,t)};case e.FLOAT_VEC3:return function(t){return e.uniform3fv(o,t)};case e.FLOAT_VEC4:return function(t){return e.uniform4fv(o,t)};case e.FLOAT_MAT3:return function(t){return e.uniformMatrix3fv(o,!1,t)};case e.FLOAT_MAT4:return function(t){return e.uniformMatrix4fv(o,!1,t)}}else if(i.size>1)switch(i.type){case e.FLOAT:return function(t){return e.uniform1fv(o,t)};case e.FLOAT_VEC2:return function(t){return e.uniform2fv(o,t)};case e.FLOAT_VEC3:return function(t){return e.uniform3fv(o,t)};case e.FLOAT_VEC4:return function(t){return e.uniform4fv(o,t)}}throw"Unhandled uniform ".concat(s)}()},h=0;h<c;++h)l(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,o="PhongMaterial"===s.type,a="MetallicMaterial"===s.type,A="SpecularMaterial"===s.type,c=n.attributes,u=mr(t,i._lightsState),l=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)))}))},o=s("float","EdgeBias",(function(e){return e.edgeBias})),a=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})),u=s("vec3","CenterColor",(function(e){return e.centerColor}));return i(r)&&function(e,t){var r="".concat(h,"(").concat(e,", ").concat(t,", ").concat(o,", ").concat(a,", ").concat(A,")");return"mix(".concat(c+n,", ").concat(u+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)})),o=r?function(e){return"(".concat(r," * ").concat(e,").st")}:function(e){return"".concat(e,".st")},a=function(e,t){return s(o(e))};return a.getTexCoordExpression=o,a}()},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})),k=m("metallic",(function(e){return e._metallicMap})),M=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=u.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":"",u.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&&(u.directionalLights.length>0||u.getIrradiance||u.getReflection);if(e.push("vec3 diffuseColor = ".concat(m&&(o||A)&&S||a&&D||"vec3(1.0)",";")),e.push("vec4 alphaModeCutoff = ".concat((o||a||A)&&G||"vec4(1.0, 0.0, 0.0, 0.0)",";")),e.push("float alpha = alphaModeCutoff[0];"),(o||a||A)&&C&&e.push("alpha *= ".concat(C(W),".r;")),z&&(e.push("diffuseColor *= ".concat(z,".rgb;")),e.push("alpha *= ".concat(z,".a;"))),a&&_&&(e.push("vec4 baseColorTexel = "+_(W)+";"),e.push("diffuseColor *= baseColorTexel.rgb;"),e.push("alpha *= baseColorTexel.a;")),(o||A)&&b&&(e.push("vec4 diffuseTexel = "+b(W)+";"),e.push("diffuseColor *= diffuseTexel.rgb;"),e.push("alpha *= diffuseTexel.a;")),e.push("vec3 emissiveColor = ".concat((o||a||A)&&Q||"vec3(0.0)",";")),(o||a||A)&&w&&e.push("emissiveColor = ".concat(w(W),".rgb;")),m){e.push("vec3 specular = ".concat((o||A)&&R||"vec3(1.0)",";")),e.push("float glossiness = ".concat(A&&O||"1.0",";")),e.push("float metallic = ".concat(a&&V||"1.0",";")),e.push("float roughness = ".concat((a||A)&&L||"1.0",";")),e.push("float shininess = ".concat(o&&H||"1.0",";")),e.push("float specularF0 = ".concat(a&&N||"1.0",";")),e.push("float occlusion = ".concat((o||a||A)&&B?"".concat(B(W),".r"):"1.0",";")),a&&k&&e.push("metallic *= ".concat(k(W),".r;")),a&&M&&e.push("roughness *= ".concat(M(W),".r;")),a&&E&&(e.push("vec4 metalRoughTexel = "+E(W)+";"),e.push("metallic *= metalRoughTexel.b;"),e.push("roughness *= metalRoughTexel.g;")),(o||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=(o||a||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;"),o&&(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);")),a&&(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);")),o||a||A){if(e.push("const float PI = 3.14159265359;"),e.push("vec3 reflDiff = vec3(0.0);"),e.push("vec3 reflSpec = vec3(0.0);"),u.getIrradiance&&e.push("reflDiff += ".concat(u.getIrradiance("normalize(".concat(Z,")")),";")),u.getReflection){var ne="reflect(-viewEyeDir, viewNormal)",re=o?"0.2 * PI * ".concat(u.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(u.getReflection(s,d)));e.push("reflSpec += ".concat(re,";"))}u.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;")),u.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=o?"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=o&&"".concat(u.getAmbientColor()," * diffuseColor");e.push("vec3 outgoingLight = emissiveColor + occlusion * (reflDiff * material_diffuseColor + reflSpec)"+(ie?" + "+ie:"")+";")}else e.push("vec3 ambientColor = ".concat(o&&P||"vec3(1.0)",";")),o&&y&&e.push("ambientColor *= ".concat(y(W),".rgb;")),e.push("ambientColor *= ".concat(u.getAmbientColor(),";")),e.push("vec3 outgoingLight = emissiveColor + ambientColor;");e.push("vec4 fragColor = ".concat(l," * 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),o=t.createUniform("vec4","colorize",(function(e,t){return e(t.meshColorize)})),a=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)})),u=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(o," * vec4((").concat(t.join(" + "),") * ").concat(A," + ").concat(c,", ").concat(a,");")})),l=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(l," = ").concat(t?t(u):u,";"))}}},Cr=function(e,t,n,r,i){var s=i&&mr(t,r._lightsState),o=t.createUniform("vec3","uColor",(function(e,t){return e(i?t.material.fillColor:t.material.edgeColor)})),a=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(o).concat(t?" * (".concat(t.join(" + "),")"):"",", ").concat(a,")")})),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,";"))}}},kr=Ae.vec4(),Mr=function(e,t){var n=t.createUniform("vec4","pickColor",(function(e,t){var n=t.meshPickID;kr[0]=255&n,kr[1]=n>>8&255,kr[2]=n>>16&255,kr[3]=n>>24&255,Ae.mulVec4Scalar(kr,1/255,kr),e(kr)})),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,o=w(r),a=function(e){var t=null,n=function(){if(!t){var n=gr(),r=n.programVariables.createAttribute,i=o._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")},a=function(e){var t={toString:function(){return t.needed=!0,e}};return t},A=s.normal&&a("worldNormal"),c=A&&a("viewNormal"),u=s.uv&&a("decodedUv"),l=e(n.programVariables,{attributes:{position:{world:"worldPosition",view:"viewPosition"},color:s.color,pickColor:s.pickColor,uv:u,normal:s.normal&&{world:A,view:c}},viewMatrix:"viewMatrix2"}),h=[l.programName,o.scene.canvas.canvas.id,o.scene._sectionPlanesState.getHash(),o._geometry._state.hash].concat(l.getHash()).join(";");if(!(h in Nr)){var d=Wr(o,s,{decodedUv:u,worldNormal:A,viewNormal:c},l,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=o.scene,c=function(e){return function(t,n){return Cr(o._state.hash,t,n,A,e)}};r._renderers={_drawRenderer:a((function(e,t){return"LambertMaterial"===s.type?Br(o._state.drawHash,e,t,s,A):wr(o._state.drawHash,e,t,s,A)})),_shadowRenderer:a((function(e){return xr(o._state.hash,e)})),_emphasisEdgesRenderer:a(c(!1)),_emphasisFillRenderer:a(c(!0)),_pickMeshRenderer:a((function(e){return Mr(o._state.hash,e)})),_pickTriangleRenderer:a((function(e,t){return Er(o._state.hash,e,t)})),_occlusionRenderer:a((function(e){return Fr(o._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 u=i.origin||i.rtcCenter;if(u&&(r._state.origin=Ae.vec3(u),r._state.originHash=u.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 l=r.scene.components[i.parentId];l?l.isNode?l.addChild(w(r)):r.error("Parent is not a Node: '"+i.parentId+"'"):r.error("Parent not found: '"+i.parentId+"'"),r._parentNode=l}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 o=0===s;i.sectionPlanesActivePerLayer[n]=o}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(),o=Ae.vec4(),a=Ae.vec3(),A=Ae.vec3(),c=Ae.vec3(),u=Ae.vec3(),l=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(),k=Ae.vec3(),M=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,o),S.localPos=o,S.position=o,v[0]=o[0],v[1]=o[1],v[2]=o[2],v[3]=1,Ae.transformVec4(U.worldMatrix,v,g),a[0]=g[0],a[1]=g[1],a[2]=g[2],S.canvasPos&&U.origin&&(a[0]+=U.origin[0],a[1]+=U.origin[1],a[2]+=U.origin[2]),S.worldPos=a,Ae.transformVec4(O.matrix,g,m),A[0]=m[0],A[1]=m[1],A[2]=m[2],S.viewPos=A,Ae.cartesianToBarycentric(o,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),u),pt.decompressNormal(J.subarray(q,q+2),l),pt.decompressNormal(J.subarray($,$+2),h)}else u[0]=J[L],u[1]=J[L+1],u[2]=J[L+2],l[0]=J[H],l[1]=J[H+1],l[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(u,c[0],y),Ae.mulVec3Scalar(l,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],k),Ae.mulVec2Scalar(f,c[1],M),E),Ae.mulVec2Scalar(p,c[2],F),x)}}}}}(),Wr=function(e,t,n,r,i){var s,o,a=i.programVariables,A=n.decodedUv,c=n.worldNormal,u=n.viewNormal,l=e.scene,h=l.canvas.gl,d=e._state.background,f=e._geometry._state,v=f.compressGeometry,g="points"===f.primitiveName,m=a.createUniform("float","pointSize"),y=a.createUniform("mat4","modelMatrix"),_=a.createUniform("mat4","modelNormalMatrix"),b=a.createUniform("vec3","offset"),w=a.createUniform("vec3","scale"),B=a.createUniform("mat4","positionsDecodeMatrix"),C=a.createUniform("mat3","uvDecodeMatrix"),k=a.createUniform("mat4","viewMatrix"),E=a.createUniform("mat4","viewNormalMatrix"),F=a.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&&a.createVertexDefinition("billboard",T),function(e){return s?"".concat(s,"(").concat(e,")"):e}),S=(o=T&&a.createFragmentDefinition("billboard",T),function(e){return o?"".concat(o,"(").concat(e,")"):e}),D=[];r.dontBillboardAnything?D.push("mat4 viewMatrix2 = ".concat(k,";")):(D.push("mat4 viewMatrix1 = ".concat(k,";")),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=a.createUniform("bool","clippable"),O=M(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:l.crossSections,discardPoints:g&&r.discardPoints,getGammaFactor:l.gammaOutput&&function(){return l.gammaFactor},getLogDepth:!r.dontGetLogDepth&&l.logarithmicDepthBufferEnabled&&function(e){return e},getPointSize:r.setupPointSize&&g&&function(){return m},getVertexData:function(){var e=u&&u.needed&&"vec3 ".concat(u," = 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(k," * worldPosition;")):(n.push("mat4 viewMatrix1 = ".concat(k,";")),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(a.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:l._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,o=n._state,a=n._geometry,A=a._state,c=e.viewParams,u=r.canActAsBackground&&d;e.lastProgramId!==V.id&&(e.lastProgramId=V.id,V.bind(),e.useProgram++,N=null,G=null,u&&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 l,f,p,v=!r.useShadowView&&n.origin;l=c.projMatrix,f=v?e.getRTCViewMatrix(o.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(k,f),p(E,c.viewNormalMatrix),p(F,l),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 M=a._getPickTrianglePositions();A.id!==G&&(g({positionsBuf:M,pickColorsBuf:a._getPickTriangleColors()}),G=A.id),h.drawArrays(A.primitive,0,M.numItems/3)}else if(r.drawEdges){var x=A.primitive===h.TRIANGLES?a._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++);u&&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 o=Jr(e,"WEBGL_compressed_texture_pvrtc");if(null===o)return null;if(35840===i)return o.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return o.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return o.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return o.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){var a=Jr(e,"WEBGL_compressed_texture_etc1");return null!==a?a.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 u=Jr(e,"EXT_texture_compression_bptc");if(null===u)return null;if(36492===i)return 3001===r?u.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:u.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,o=t.wrapS,a=t.wrapT,A=t.wrapR,c=t.encoding,u=t.preloadColor,l=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=!!l,this.flipY=!!h,this.unpackAlignment=4,this.wrapS=o||1e3,this.wrapT=a||1e3,this.wrapR=A||1e3,this.encoding=c||3001,this.texture=n.createTexture(),u&&this.setPreloadColor(u),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 o=n.getParameter(n.UNPACK_ALIGNMENT);n.pixelStorei(n.UNPACK_ALIGNMENT,this.unpackAlignment);var a=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 u=Yr(n,this.wrapS);u&&n.texParameteri(this.target,n.TEXTURE_WRAP_S,u);var l=Yr(n,this.wrapT);l&&n.texParameteri(this.target,n.TEXTURE_WRAP_T,l);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,o),n.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,a)}},{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 o=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 a=Yr(i,this.wrapS);a&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,a);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)}o?(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 u=Yr(i,this.format,this.encoding),l=Yr(i,this.type),h=ei(i,this.internalFormat,u,l,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!==u?i.compressedTexSubImage2D(i.TEXTURE_2D,d,0,0,p.width,p.height,u,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,u,l,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 o=n;return n===e.RED&&(r===e.FLOAT&&(o=e.R32F),r===e.HALF_FLOAT&&(o=e.R16F),r===e.UNSIGNED_BYTE&&(o=e.R8)),n===e.RG&&(r===e.FLOAT&&(o=e.RG32F),r===e.HALF_FLOAT&&(o=e.RG16F),r===e.UNSIGNED_BYTE&&(o=e.RG8)),n===e.RGBA&&(r===e.FLOAT&&(o=e.RGBA32F),r===e.HALF_FLOAT&&(o=e.RGBA16F),r===e.UNSIGNED_BYTE&&(o=3001===i&&!1===s?e.SRGB8_ALPHA8:e.RGBA8),r===e.UNSIGNED_SHORT_4_4_4_4&&(o=e.RGBA4),r===e.UNSIGNED_SHORT_5_5_5_1&&(o=e.RGB5_A1)),o!==e.R16F&&o!==e.R32F&&o!==e.RG16F&&o!==e.RG32F&&o!==e.RGBA16F&&o!==e.RGBA32F||Jr(e,"EXT_color_buffer_float"),o}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}(),oi=Ae.vec3(),ai=Ae.vec3();Ae.vec3();var Ai,ci=Ae.vec3([0,-1,0]),ui=Ae.vec4([0,0,0,1]),li=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,oi);var r=-Ae.dotVec3(n,oi);Ae.normalizeVec3(n),Ae.mulVec3Scalar(n,r,ai),Ae.vec3PairToQuaternion(ci,e,ui),this._node.quaternion=ui}}},{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}(),ki=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),o=null,a=0,A=s.length;a<A;a++)0!==a&&0===i(s[a],s[a-1])||(o=s[a]),n[s[a]]=o;for(var c=0,u=e.length;c<u;c+=3){var l=n[e[c]],h=n[e[c+1]],d=n[e[c+2]],f=l,p=h,v=d;if(l>h&&l>d?h>d?(f=l,p=h,v=d):(f=l,p=d,v=h):h>l&&h>d?l>d?(f=h,p=l,v=d):(f=h,p=d,v=l):d>l&&d>h&&(l>h?(f=d,p=l,v=h):(f=d,p=h,v=l)),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)},Mi=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&&!ki(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],o=3*t[r+2];Mi[0]=e[i],Mi[1]=e[i+1],Mi[2]=e[i+2],Ei[0]=e[s],Ei[1]=e[s+1],Ei[2]=e[s+2],Fi[0]=e[o],Fi[1]=e[o+1],Fi[2]=e[o+2],Ae.cross3Vec3(Mi,Ei,Mi),n+=Ae.dotVec3(Mi,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],o=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[o],Pi[1]=e[o+1],Pi[2]=e[o+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,o){var a=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=o,this._matrixDirty=!1,this._matrixUpdateScheduled=!1,this.id=n,this.obb=null,this._aabbLocal=null,this._aabbWorld=Ae.AABB3(),this._aabbWorldDirty=!1,this.layer=a,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,o=!r&&e.createVarying("vec4","vColor",(function(){return"vec4(".concat(s,".rgb * 0.5, ").concat(s,".a)")})),a=e.createOutput("vec4","outColor");return{programName:r?"Edges":"EdgesColor",getLogDepth:n&&function(e){return e},renderPassFlag:2,appendFragmentOutputs:function(e){return e.push("".concat(a," = ").concat(i||o,";"))}}},$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")})),o=e.createOutput("vec4","outColor");return{programName:"Silhouette",getLogDepth:n&&function(e){return e},renderPassFlag:1,appendFragmentOutputs:function(e,t,n,a){e.push("".concat(o," = ").concat(r?i:a("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]),os=0,as=1,As=2,cs=3,us=4,ls=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,o,a=!!(e&Gi),A=!!(e&Ki),c=!!(e&Zi),u=!!(e&Ji),l=!!(e&Yi),h=!!(e&Wi),d=!!(e&ji);s=!a||d||A||c&&!r.highlightMaterial.glowThrough||u&&!r.selectedMaterial.glowThrough?os:t?As:as,o=!a||d?os:u?us:c?cs:A?ls:os;var f=0;f=n&&a&&!d?u?ps:c?fs:A?vs:l?t?ds:hs:os:os;var p=a&&!d&&h?gs:os;i[0]=s,i[1]=o,i[2]=f,i[3]=p},_s=(Ai={},function(e,t,n,r,i,s,o,a){var A=[t,"points"===n||"lines"===n?n:"triangles",!!r,!!i,!!s,!!o].join(":");A in Ai||(Ai[A]={});var c,u,l,h=Ai[A],d=e.id;if(!(d in h)){var f=e.canvas.gl,p=function(r,i,s){var o=function(){var s=gr(),o=s.programVariables,A=a(o,i);return r(o,A.geometryParameters,(function(r,a){var c,u=e.pointsMaterial,l="points"===n&&!i,h=function(){return[e._sectionPlanesState.getHash()].concat(l?[u.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=M(s.buildProgram(f,t+" "+n+" "+r.programName,{appendFragmentOutputs:r.appendFragmentOutputs,cleanerEdges:r.cleanerEdges,clipPos:b,clippableTest:(c=o.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:l&&u.roundPoints,getGammaFactor:e.gammaOutput&&function(){return e.gammaFactor},getLogDepth:r.getLogDepth,getPointSize:function(){var e=[];if(l){var t=o.createUniform("float","pointSize",(function(e){return e(u.pointSize)}));if(u.perspectivePoints){var s=o.createUniform("float","nearPlaneHeight",(function(e,t){return e(t.legacyFrameCtx.nearPlaneHeight)})),a="".concat(Math.floor(u.minPerspectivePointSize),".0"),A="".concat(Math.floor(u.maxPerspectivePointSize),".0");e.push("clamp((".concat(s," * ").concat(t,") / gl_Position.w, ").concat(a,", ").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=o.createUniform("int","renderPass",(function(e,t){return e(t.renderPass)})),a=m?"(".concat(i," <= 0) || (").concat(t,".a < 1.0)"):"".concat(i," != ").concat(s),c=["if (".concat(a,") {")," gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"," return;","}"].concat(A.dontCullOnAlphaZero||r.dontCullOnAlphaZero?[]:["if (".concat(t,".a == 0.0) {")," gl_Position = vec4(0.0, 0.0, 0.0, 1.0);"," return;","}"]).concat(r.filterIntensityRange&&"points"===n&&u.filterIntensity?(e=o.createUniform("vec2","intensityRange",(function(e){ts[0]=u.minIntensity,ts[1]=u.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;","}"]):[]),l=[];A.ensureColorAndFlagAvailable&&A.ensureColorAndFlagAvailable(l),c.forEach((function(e){return l.push(e)})),A.appendVertexData(l);var h=v.attributes.position.view;return l.push("vec4 ".concat(h," = ").concat(v.viewMatrix," * ").concat(_,";")),l.push("vec4 ".concat(b," = ").concat(v.projMatrix," * ").concat(h,";")),l},projMatrix:v.projMatrix,sectionPlanesState:e._sectionPlanesState,testPerspectiveForGl_FragDepth:"points"!==n&&"lines"!==n||i,usePickClipPos:a,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,o=e.viewParams,a=ns;Ae.transformPoint3(s.matrix,r,a);var c=o.viewMatrix,u=o.projMatrix;e.snapPickOrigin&&(e.snapPickOrigin[0]=a[0],e.snapPickOrigin[1]=a[1],e.snapPickOrigin[2]=a[2]);var l={legacyFrameCtx:e,layerTextureSet:t.layerTextureSet,mesh:{layerIndex:t.layerIndex,origin:a,renderFlags:{sectionPlanesActivePerLayer:s.renderFlags.sectionPlanesActivePerLayer}},renderPass:n,view:{eye:o.eye,far:o.far,projMatrix:u,viewMatrix:Ae.compareVec3(a,ss)?c:Zt(c,a,is),viewNormalMatrix:o.viewNormalMatrix}};B.inputSetters.setUniforms(e,l),t.drawCalls[i?i.vertices?"drawVertices":"drawEdges":"drawSurface"](B.inputSetters.attributesHash,A.layerTypeInputs,{projMatrix:u,viewMatrix:Ae.compareVec3(a,ss)?c:Zt(c,a,is),viewNormalMatrix:o.viewNormalMatrix,eye:o.eye}),g&&e.drawElements++}}}))},A=s&&o();return{drawLayer:function(e,t,n){A||(A=o()),A.drawLayer(e,t,n)},revalidate:function(e){!A||!e&&A.getValid()||(A.destroy(),A=s&&o())}}},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 o=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})),a=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(a," = ").concat(o,";")):(e.push("vec4 fragColor = ".concat(r(o),";")),e.push("".concat(a," = ").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,o=e.logarithmicDepthBufferEnabled,a=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")})),u=i.createOutput("vec4","outPackedDepth"),l=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:o&&function(e){return e},renderPassFlag:3,incPointSizeBy10:!0,appendFragmentOutputs:function(e){e.push("float zNormalizedDepth = abs((".concat(A," + ").concat(c,".z) / (").concat(a," - ").concat(A,"));")),e.push("".concat(u," = ").concat(l,"(zNormalizedDepth);"))}}),!0);var i,s,o,a,A,c,u,l},_=function(t,n,r){return r((i=t,s=n,o=e.logarithmicDepthBufferEnabled,a=i.createVarying("vec4","vPickColor",(function(){return"".concat(s.attributes.pickColor," / 255.0")})),A=i.createOutput("vec4","outPickColor"),{programName:"PickMesh",getLogDepth:o&&function(e){return e},renderPassFlag:3,incPointSizeBy10:!0,dontCullOnAlphaZero:!0,appendFragmentOutputs:function(e){return e.push("".concat(A," = ").concat(a,";"))}}),!0);var i,s,o,a,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})),o=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(o," = 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)})),o=e.createVarying("vec3","vWorldPosition",(function(){return"".concat(t.attributes.position.world,".xyz")})),a=e.createVarying("vec4","vPickColor",(function(){return t.attributes.pickColor}),"flat"),A=e.createOutput("highp ivec4","outCoords",0),c=e.createOutput("highp ivec4","outNormal",1),u=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,dontCullOnAlphaZero:!n,appendFragmentOutputs:function(e){e.push("".concat(A," = ivec4(").concat(o," * ").concat(s,".xyz, ").concat(n?"-":"").concat(i,");")),n&&(e.push("".concat(c," = ").concat(r?"ivec4(1.0)":"ivec4(normalize(cross(dFdx(".concat(o,"), dFdy(").concat(o,"))) * float(").concat(Ae.MAX_INT,"), 1.0)"),";")),e.push("".concat(u," = uvec4(").concat(a,");")))}}}(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)},u=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,")")}}},l=function(t){var n=function(n,r,i){return function(e,t,n,r,i,s,o){var a=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,u=e.createVarying("vec3","vViewPosition",(function(){return"".concat(c.position.view,".xyz")})),l=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",!!o,s?"alphaCutoffYes":"alphaCutoffNo"]},getLogDepth:n.logarithmicDepthBufferEnabled&&function(e){return e},renderPassFlag:0,appendFragmentOutputs:function(e,n,s,o){e.push("vec3 viewNormal = normalize(cross(dFdx(".concat(u,"), dFdy(").concat(u,")));")),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,u),"), 0.0) * ").concat(n.getColor(),";"))})),e.push("vec4 color = vec4(".concat(r.getAmbientColor()," + reflectedColor, 1) * ").concat(o(h),";")),e.push("vec4 sampleColor = ".concat(a(l),";")),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&&u(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)}))},o=t.attributes,a=r.getIrradiance,A=s("uColorMap",!0,(function(e){return e.colorTexture})),c=s("uMetallicRoughMap",!1,(function(e){return e.metallicRoughnessTexture})),u=s("uEmissiveMap",!0,(function(e){return e.emissiveTexture})),l=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(o.position.view,".xyz")})),f=e.createVarying("vec3","vViewNormal",(function(){return o.normal.view})),p=e.createVarying("vec4","vColor",(function(){return o.color})),v=e.createVarying("vec2","vUV",(function(){return o.uv})),g=e.createVarying("vec2","vMetallicRoughness",(function(){return o.metallicRoughness})),m=e.createVarying("vec3","vWorldNormal",(function(){return"".concat(o.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(l(v),");")),e.push("vec3 viewEyeDir = normalize(".concat(d,");")),a&&e.push("reflDiff += ".concat(a("normalize(".concat(m,")")),";")),r.getReflection){var o="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)"),k="0.5 * clamp(".concat(C,", 0.0, ").concat("8.0",")"),M=r.getReflection(o,k),E="".concat(w,"(viewNormal, viewEyeDir, specularColor, specularRoughness)");e.push("reflSpec += ".concat(M," * ").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(u(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&&u(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(o?function(e,n,r){return r(m(e,n,c(e),t&&u(e)))}:function(n,r,i){return i((s=n,o=r,a=e.logarithmicDepthBufferEnabled,A=c(n),l=t&&u(n),h=o.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(),l?"sao":"nosao"]},cleanerEdges:!0,getLogDepth:a&&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(o.viewMatrix,d),"), 0.0) * ").concat(e.getColor())})));e.push("vec4 fragColor = vec4(".concat(i.join(" + "),", 1) * ").concat(r(f),";")),e.push("".concat(p," = ").concat(l?"vec4(fragColor.rgb * ".concat(l.getAmbient(n),", fragColor.a)"):"fragColor",";"))}}));var s,o,a,A,l,h,d,f,p})}},{"sao-":l(!1),"sao+":r&&l(!0)}),depthRenderer:g((function(t,n,r){return r((i=t,s=n,o=e.logarithmicDepthBufferEnabled,a=i.createVarying("highp vec2","vHighPrecisionZW",(function(){return"".concat(s.attributes.position.clip,".zw")})),A=i.createOutput("vec4","outColor"),{programName:"Depth",getLogDepth:o&&function(e){return e},renderPassFlag:0,appendFragmentOutputs:function(e){return e.push("".concat(A," = vec4(vec3((1.0 - ").concat(a,"[0] / ").concat(a,"[1]) / 2.0), 1.0);"))}}));var i,s,o,a,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,o=(i=t).createOutput("vec4","outColor"),a=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(o," = ").concat(a,"(").concat(n,".z);"))}}));var i,s,o,a})),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._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&&[as,As,gs,cs,us,ls];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?as: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,as)}},{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,ls)}},{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,us)}},{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,as)}},{key:"drawShadow",value:function(e,t){var n=this._renderers.shadowRenderer;n&&this.__drawLayer(e,t,n,as)}},{key:"initFlags",value:function(e,t,n){Object.values(this._countsByFlag).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}(),ks=function(e){for(var t=[],n=0;n<e;++n)t.push(n);return t},Ms={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(Ms,null,4));var e=0;Object.keys(Ms).forEach((function(t){t.startsWith("size")&&(e+=Ms[t])})),console.log("Total size ".concat(e," bytes (").concat((e/1e3/1e3).toFixed(2)," MB)")),console.log("Avg bytes / triangle: ".concat((e/Ms.totalPolygons).toFixed(2)));var t={};Object.keys(Ms).forEach((function(n){n.startsWith("size")&&(t[n]="".concat((Ms[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),Ms.numberOfLayers++,s._sortId="TriDTX-".concat(Ms.numberOfLayers);var o=e.scene.canvas.gl,a=function(e,t){var n=[],r=0,i=[],s=0,a=[],c=0,u=[],l=0;return{len:function(){return s},accumulateIndices:function(o,h){var d=o&&o.length>0&&function(){var t=r/3;r+=o.length,n.push(o);var a=o.length/3;return function(n){var r=s;s+=3*a,A.perObjectIndexBaseOffsets.push(r/3-t);for(var o=0;o<a;o+=8)i.push(n);Ms[e]+=a,Ms.totalPolygons+=a}}(),f=h&&h.length>0&&function(){var e=c/2;c+=h.length,a.push(h);var n=h.length/2;return function(r){var i=l;l+=2*n,A.perObjectEdgeIndexBaseOffsets.push(i/2-e);for(var s=0;s<n;s+=8)u.push(r);Ms[t]+=n,Ms.totalEdges+=n}}();return Ms.numberOfGeometries++,{numTriangles:o?o.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,o.UNSIGNED_SHORT,"sizeDataTexturePortionIds"):n},h=A(i,{texture:null}),d=r>0&&e(n,r,3,t,"sizeDataTextureIndices"),f=A(u),p=c>0&&e(a,c,2,t,"sizeDataTextureEdgeIndices");return{indices:function(e,t){s>0&&(e.perPrimIndices.setInputValue(d),e.perPrimIdPorIds.setInputValue(h),o.drawArrays(t,0,s))},edges:function(e,t){l>0&&(e.perPrimIndices.setInputValue(p),e.perPrimIdPorIds.setInputValue(f),o.drawArrays(t,0,l))}}}}},A=s._buffer={positionsCompressed:[],lenPositionsCompressed:0,geometry8Bits:a("totalPolygons8Bits","totalEdges8Bits"),geometry16Bits:a("totalPolygons16Bits","totalEdges16Bits"),geometry32Bits:a("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&&Ms.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()),o=0,a=0;e.buckets.forEach((function(e){o+=e.positionsCompressed.length/3,a+=e.indices.length/3})),(this._numVertices+o>4096*Fs||s+a>4096*Fs)&&Ms.cannotCreatePortion.becauseTextureSize++,n&&(n=this._numVertices+o<=4096*Fs&&s+a<=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,o,a,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),Ms[n]+=2*(i.length-e.length),i}return e};e.indices=c(e.indices,3,"overheadSizeAlignementIndices"),e.edgeIndices=c(e.edgeIndices,2,"overheadSizeAlignementEdgeIndices");var u=e.positionsCompressed;r.positionsCompressed.push(u);var l=u.length/3;n._numVertices+=l;var h=r.lenPositionsCompressed/3;r.lenPositionsCompressed+=u.length,n._bucketGeometries[A]={vertexBase:h,geometryData:(o=e.indices,a=e.edgeIndices,l<=256?r.geometry8Bits.accumulateIndices(o,a):l<=65536?r.geometry16Bits.accumulateIndices(o,a):r.geometry32Bits.accumulateIndices(o,a))}}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}),Ms.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,o=this._sortId,a=this._subPortionReadableGeometries,A=t.scene,c=A.canvas.gl,u=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),l=u.textureData,h=function(e,t,n,r,i,s,o){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,o)},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,k=!1,M=!1,E=0,F=function(){C=!0},x=A.on("rendering",(function(){k&&(C=!1,k=!1,l.reloadData()),E=0})),U=function(e,n){var r=i[e];if(r)for(var s=0,o=r.length;s<o;s++)n(r[s]);else t.error("portion not found: "+e)},I=function(e,t,n,r){var i=C||r;i?k=!0:++E>=10&&F(),l.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:o,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?k=!0:++E>=10&&F(),Ts.set(t),p.setData(Ts,e,0,!n)}))},setOffset:function(e,t){},getEachIndex:function(e,t){a&&U(e,(function(e){return a[e].indices.forEach((function(e){return t(e)}))}))},getEachVertex:function(e,n){a&&U(e,(function(e){for(var i=a[e],s=i.positionsCompressed,o=i.positionsDecodeMatrix,A=Is,c=0,u=s.length;c<u;c+=3)A[0]=s[c],A[1]=s[c+1],A[2]=s[c+2],A[3]=1,Ae.decompressPosition(A,o),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,o){n(s.worldMatrix,t.rotationMatrix),n(s.viewMatrix,o.viewMatrix),n(s.projMatrix,o.projMatrix);var a=Ae.transformPoint3(t.matrix,r,xs);n(s.uCameraEyeRtc,Ae.subVec3(o.eye,a,Us)),n(s.perObjPosDecode,v),n(s.perVertIdCoords,m),n(s.perObjColsFlags,u),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(){M||(A.off(x),M=!0)}}}}]),n}(),Qs=function(e,t,n,r,i,s,o,a){if(n>4&&n%4>0)throw"Unhandled data size "+n;var A=Math.ceil(n/4),c=n/A,u=M(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),l=u[0],h=u[1],d=u[2],f=i*A,v=Math.ceil(t/i);if(0===v)throw"texture height===0";var g=new l(f*v*c);Ms[o]+=g.byteLength,Ms.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:a&&{setData:function(t,s){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(g.set(t,s*n+o*c),a){e.bindTexture(e.TEXTURE_2D,m);var u=s%i*A+o,l=Math.floor(s/i),h=t.length/c;e.texSubImage2D(e.TEXTURE_2D,0,u,l,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"),o=n("mediump usampler2D","perVertIdCoords"),a=n("lowp usampler2D","perObjColsFlags"),A=n("highp sampler2D","perObjectMatrix"),c=e.createUniform("mat4","worldMatrix"),u=e.createUniform("mat4","viewMatrix"),l=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 a("ivec2(objectIndexCoords.x*8+".concat(e,", objectIndexCoords.y)"))};return{geometryParameters:{attributes:{clippable:"(flags2.r > 0u)",color:f,flags:ks(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:l,viewMatrix:u},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 a=function(e){return"vec3(".concat(o("ivec2(indexPositionH[".concat(e,"], indexPositionV[").concat(e,"])")),")")};e.push("vec3 positions[] = vec3[](".concat(a(0),", ").concat(a(1),", ").concat(a(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(u," * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);")),e.push("if (solid != 1u) {"),e.push(" if (".concat("(".concat(l,"[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(u," * 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(o("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:o.map,perObjColsFlags:a.map,perObjectMatrix:A.map,worldMatrix:c,viewMatrix:u,projMatrix:l,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],o=t[1],a=t[2],A=t[3]-s,c=t[4]-o,u=t[5]-a,l=65525,h=l/A,d=l/c,f=l/u,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]-o)*d),i[v+2]=Math.floor(p(e[v+2]-a)*f);return Ae.identityMat4(Os),Ae.translationMat4v(t,Os),Ae.identityMat4(Vs),Ae.scalingMat4v([A/l,c/l,u/l],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,o=e[4]-r,a=e[5]-i,A=65525;return Ae.identityMat4(Os),Ae.translationMat4v(e,Os),Ae.identityMat4(Vs),Ae.scalingMat4v([s/A,o/A,a/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,o;s=(1-Math.abs(i))*(r>=0?1:-1),o=(1-Math.abs(r))*(i>=0?1:-1),r=s,i=o}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(),eo=Ae.vec3(),to=Ae.vec3(),no=Ae.vec3(),ro=Ae.vec3(),io=Ae.vec3(),so=new Uint8Array(4),oo=new Float32Array(96),ao=function(e){for(var t=[],n=0;n<e;++n)t.push(n);return t},Ao=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}},co=(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]}}),uo=function(e){m(n,bs);var t=_(n);function n(e,r,i,s){var o;x(this,n),o=t.call(this,e,r,i);var a=!!s.geometry;o._maxVerts=s.maxGeometryBatchSize;var A=a?s.geometry.positionsDecodeMatrix:s.positionsDecodeMatrix;o._positionsDecodeMatrix=A&&Ae.mat4(A),o._cfgUvDecodeMatrix=s.uvDecodeMatrix&&Ae.mat3(s.uvDecodeMatrix),o._instancedGeometry=s.geometry,o._textureSet=s.textureSet,o._modelAABB=!a&&Ae.collapseAABB3(),o._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,o=r.subarray(i);if(1===n&&0===s)o.set(t);else for(var a=0;a<t.length;++a)o[a]=s+t[a]*n;for(var A=t.length,c=e.times*t.length;A<c;){var u=Math.min(A,c-A);o.set(o.subarray(0,u),A),A+=u}i+=A})),r}}};return o._buffer=d({colors:c(),metallicRoughness:c(),pickColors:c()},a?{modelMatrixCol:[c(),c(),c()],modelNormalMatrixCol:[c(),c(),c()]}:{positions:c(),indices:c(),uv:c(),normals:c(),edgeIndices:c()}),o}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,o=this._portions.length,a=this.primitive,A=!!this._positionsDecodeMatrix,c=s.scene,u=t.meshMatrix,l=function(i,A,u,l,h){var d,f,p=n._portions.length>0&&n._portions[n._portions.length-1],v={indicesBaseIndex:p?p.indicesBaseIndex+p.numIndices:0,numIndices:u?u.length:0,portionBase:i,portionSize:A,retainedGeometry:c.readableGeometryEnabled&&"points"!==a&&"lines"!==a&&{indices:u,quantizedPositions:l,offset:c.entityOffsetsEnabled&&Ae.vec3(),matrix:h&&h.slice(),inverseMatrix:null,normalMatrix:null}};"points"!==a&&"lines"!==a&&r.metallicRoughness.append([null!==(d=t.metallic)&&void 0!==d?d:0,null!==(f=t.roughness)&&void 0!==f?f:255],A);return"lines"!==a&&r.pickColors.append(t.pickColor.slice(0,4),A),n._portions.push(v),s.numPortions++,n._meshes.push(e),o};if(i){if(r.modelMatrixCol.forEach((function(e,t){return e.append([u[t+0],u[t+4],u[t+8],u[t+12]])})),"points"!==a){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"!==a&&"lines"!==a&&i.normals){var f=Ae.inverseMat4(Ae.transposeMat4(u,Ae.mat4()));r.modelNormalMatrixCol.forEach((function(e,t){return e.append([f[t+0],f[t+4],f[t+8],f[t+12]])}))}return l(o,1,i.indices,i.positionsCompressed,u)}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;u?(Ae.transposeMat4(u,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 o,a,A,c,u,l=new Float32Array([0,0,0,0]),h=new Float32Array([0,0,0,0]);for(u=0;u<n;u+=3)l[0]=t[u],l[1]=t[u+1],l[2]=t[u+2],Ae.transformVec3(e,l,h),Ae.normalizeVec3(h,h),a=o=Ns(h,"floor","floor"),A=c=s(h,Gs(o)),(A=s(h,Gs(o=Ns(h,"ceil","floor"))))>c&&(a=o,c=A),(A=s(h,Gs(o=Ns(h,"floor","ceil"))))>c&&(a=o,c=A),(A=s(h,Gs(o=Ns(h,"ceil","ceil"))))>c&&(a=o,c=A),r[i+u+0]=a[0],r[i+u+1]=a[1],r[i+u+2]=0}(b,_,_.length,w,0),r.normals.append(w)}var B=t.colors,C=t.colorsCompressed,k=t.color;if(B)if("points"===a)r.colors.append(B,1,255);else{for(var M=[],E=0,F=B.length;E<F;E+=3)M.push(255*B[E]),M.push(255*B[E+1]),M.push(255*B[E+2]),M.push(255);r.colors.append(M)}else if(C)if("points"===a)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 k&&r.colors.append([k[0],k[1],k[2],"points"===a?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),l(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,o=this.primitive,a=this._textureSet,A=this._positionsDecodeMatrix,c=this._cfgUvDecodeMatrix,u=n.scene,l=u.canvas.gl,h=!!t,d=[],p=function(e,t,n,r){if(t.length>0){var i,s=t.constructor,o=M((i={},f(i,Uint8Array,[1,l.UNSIGNED_BYTE]),f(i,Int8Array,[1,l.BYTE]),f(i,Uint16Array,[2,l.UNSIGNED_SHORT]),f(i,Int16Array,[2,l.SHORT]),f(i,Uint32Array,[4,l.UNSIGNED_INT]),f(i,Int32Array,[4,l.INT]),f(i,Float32Array,[4,l.FLOAT]),i)[s],2),a=o[0],A=o[1],c=l.createBuffer();d.push((function(){return l.deleteBuffer(c)}));var u=function(){return l.bindBuffer(e,c)},h=function(t){u(),l.bufferData(e,t,r)};h(t);var p=t.BYTES_PER_ELEMENT,v=t.length/n;return{bindBuffer:u,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;u();var i=new s(r*n);return l.getBufferSubData(e,t*a*n,i,0,r*n),i},numItems:v,setData:h,setSubData:function(t,n){u(),l.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(l.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(),l.vertexAttribPointer(e,t,s.type,!!i,0,0)}}},g=function(e){var t=p(l.ELEMENT_ARRAY_BUFFER,e,1,l.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,l.DYNAMIC_DRAW,h),_=function(e,t){return v(e,4,t,h&&"points"!==o,!0)},b=h&&t.colorsCompressed?_(new Uint8Array(t.colorsCompressed),l.STATIC_DRAW):_(e.colors.compileBuffer(Uint8Array),l.DYNAMIC_DRAW),w=u.entityOffsetsEnabled&&v(new Float32Array(3*m),3,l.DYNAMIC_DRAW,h),B=v(e.metallicRoughness.compileBuffer(Uint8Array),2,l.STATIC_DRAW,h),C=v(e.pickColors.compileBuffer(Uint8Array),4,l.STATIC_DRAW,h),k=g(h?new Uint32Array(t.edgeIndices):e.edgeIndices.compileBuffer(Uint32Array)),E=h?"points"!==o&&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,l.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,l.STATIC_DRAW,!0)})),T=!h&&e.normals.compileBuffer(Int8Array),P=T&&v(T,3,l.STATIC_DRAW,!1,!0),S=I&&P&&e.modelNormalMatrixCol.map((function(e){return v(e.compileBuffer(Float32Array),4,l.STATIC_DRAW,!0)})),D=h?"points"!==o&&"lines"!==o&&t.uvCompressed&&{buf:v(t.uvCompressed,2,l.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,l.STATIC_DRAW),mat:c};var n=pt.getUVBounds(t),r=pt.compressUVs(t,n.min,n.max);return{buf:v(r.quantized,2,l.STATIC_DRAW),mat:Ae.mat3(r.decodeMatrix)}}();this._buffer=null,co.acquire(),d.push((function(){return co.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"!==o&&"lines"!==o,u,so);var a=n&zi?1:0,A=0;A|=so[0],A|=so[1]<<4,A|=so[2]<<8,A|=so[3]<<12,A|=a<<16,zs[0]=A;var c=s[e],l=c.portionBase,h=c.portionSize;if(i&&!t)O||(O=new Float32Array(m)),Ao(O.subarray(l,l+h),zs);else if(y){var d=co.getTypeArray(Float32Array,h);Ao(d,zs),y.setSubData(d,l)}},L="solid"===o;return{edgesColorOpaqueAllowed:function(){return!0},solid:L,sortId:("points"===o?"Points":"lines"===o?"Lines":"Triangles")+(h?"Instancing":"Batching")+"Layer"+("points"!==o&&"lines"!==o?(L?"-solid":"-surface")+"-autoNormals"+(h?"":(a&&a.colorTexture?"-colorTexture":"")+(a&&a.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=co.getTypeArray(Uint8Array,4*n.portionSize);Ao(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(u.entityOffsetsEnabled){var r=s[e];if(w){Ks.set(t);var i=co.getTypeArray(Float32Array,3*r.portionSize);Ao(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 o=Ys;i?o.set(i,0):o[0]=o[1]=o[2]=0,o[3]=1;var a=n.matrix;Ae.mulMat4v4(a,o,o);for(var c=r.quantizedPositions,u=Js,l=0,h=c.length;l<h;l+=3)u[0]=c[l],u[1]=c[l+1],u[2]=c[l+2],Ae.decompressPosition(u,A),r.matrix&&Ae.transformPoint3(r.matrix,u,u),u[3]=1,Ae.mulMat4v4(a,u,u),Ae.addVec3(o,u,u),t(u)}},readGeometryData:"points"!==o&&"lines"!==o&&function(e){var t=!h&&s[e],r=t?F.getData(t.indicesBaseIndex,t.numIndices).map((function(e){return e-t.portionBase})):F.getData(),o=n.matrix,a=Ae.vec4();a.set(i,0),a[3]=1,Ae.mulMat4v4(o,a,a);var c=I&&Ae.mat4();if(c){var u=I[0].getData(e,1),l=I[1].getData(e,1),d=I[2].getData(e,1);c.set([u[0],l[0],d[0],0,u[1],l[1],d[1],0,u[2],l[2],d[2],0,u[3],l[3],d[3],1])}var f=Ae.mat4();Ae.mulMat4(o,c?Ae.mulMat4(c,A,f):A,f),f[12]+=a[0],f[13]+=a[1],f[14]+=a[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,o,a){var c=s[e].retainedGeometry;if(c){c.matrix&&!c.inverseMatrix&&(c.inverseMatrix=Ae.inverseMat4(c.matrix,Ae.mat4())),a&&c.inverseMatrix&&!c.normalMatrix&&(c.normalMatrix=Ae.transposeMat4(c.inverseMatrix,Ae.mat4()));var u=c.quantizedPositions,l=c.indices,h=c.offset,d=qs,f=$s;d.set(i?Ae.subVec3(t,i,eo):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=to,v=no,g=ro,m=!1,y=0,_=io,b=0,w=l.length;b<w;b+=3){var B=3*l[b],C=3*l[b+1],k=3*l[b+2];if(p[0]=u[B],p[1]=u[B+1],p[2]=u[B+2],v[0]=u[C],v[1]=u[C+1],v[2]=u[C+2],g[0]=u[k],g[1]=u[k+1],g[2]=u[k+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 M=Math.abs(Ae.lenVec3(Ae.subVec3(_,t,[])));(!m||M>y)&&(y=M,o.set(_),a&&Ae.triangleNormal(p,v,g,a),m=!0)}}return m&&a&&(c.normalMatrix&&Ae.transformVec3(c.normalMatrix,a,a),Ae.transformVec3(n.worldNormalMatrix,a,a),Ae.normalizeVec3(a)),m}return!1},layerTextureSet:a,renderers:_s(u,h?"instancing":"batching",o,n.saoEnabled,n.pbrEnabled&&D&&a&&a.colorTexture&&P&&B&&a.metallicRoughnessTexture,n.colorTextureEnabled&&D&&a&&a.colorTexture,!!P,(function(e){return ho(e,h&&{hasModelNormalMat:!!S},u.entityOffsetsEnabled)})),drawCalls:(Q={},R=function(e){return function(t,r,i){var a=0;oo.set(n.rotationMatrix,0),oo.set(i.viewMatrix,a+=16),oo.set(i.projMatrix,a+=16),oo.set(A,a+=16),r.needNormal()&&(oo.set(n.worldNormalMatrix,a+=16),oo.set(i.viewNormalMatrix,a+=16)),r.matrices.setInputValue(oo),r.uvDecodeMatrix.setInputValue&&r.uvDecodeMatrix.setInputValue(D.mat),t in Q||(Q[t]=[null,null,null]);var c,u,f=Q[t],p=e?e.vertices?0:1:2;if(!f[p]){var v=l.createVertexArray();l.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?l.drawArraysInstanced(l.POINTS,0,U.numItems,s.length):l.drawArrays(l.POINTS,0,U.numItems)},u=function(e,t){t.bindIndicesBuffer();var n=t.indicesCount,r=t.indicesType;return function(){h?l.drawElementsInstanced(e,n,r,0,s.length):l.drawElements(e,n,r,0)}},"points"===o?c:"lines"===o?e&&e.vertices?c:u(l.LINES,F):e&&e.vertices?c:e&&k?u(l.LINES,k):u(l.TRIANGLES,F));l.bindVertexArray(null),d.push((function(){return l.deleteVertexArray(v)})),f[p]=function(){l.bindVertexArray(v),_(),l.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}(),lo=function(e){var t={toString:function(){return t.needed=!0,e}};return t},ho=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&&ao(3).map((function(e){return r("vec4","modelMatrixCol"+e)})),modelNormalMatrixCol:t&&t.hasModelNormalMat&&ao(3).map((function(e){return r("vec4","modelNormalMatrixCol"+e)}))},s=lo("aUv"),o=lo("viewNormal"),a=lo("worldNormal"),A=e.createUniform("mat3","uvDecodeMatrix"),c=function(){return o.needed||a.needed},u=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:ao(4).map((function(e){return{toString:function(){return"(int(".concat(i.flags,") >> ").concat(4*e," & 0xF)")}}})),metallicRoughness:i.metallicRoughness,normal:{view:o,world:a},pickColor:i.pickColor,position:{clip:"gl_Position",view:"viewPosition",world:"worldPosition"},uv:s},projMatrix:u.projMatrix,viewMatrix:u.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(u.worldMatrix," * (").concat(u.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(a," = (").concat(u.worldNormalMatrix," * modelNormal).xyz;")),o.needed&&t.push("vec3 ".concat(o," = normalize((").concat(u.viewNormalMatrix," * vec4(").concat(a,", 0.0)).xyz);"))}},layerTypeInputs:{attributes:i,matrices:u,uvDecodeMatrix:A,needNormal:c}}},fo=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}(),po=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}(),vo={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={}}},go=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}(),mo=new go,yo=function(){function e(t){x(this,e),this.manager=void 0!==t?t:mo,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}(),_o={},bo=function(e){m(n,yo);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=vo.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===_o[e]){_o[e]=[],_o[e].push({onLoad:t,onProgress:n,onError:r});var o=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),a=this.mimeType,A=this.responseType;fetch(o).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=_o[e],r=t.body.getReader(),i=t.headers.get("Content-Length"),s=i?parseInt(i):0,o=0!==s,a=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{a+=A.byteLength;for(var c=new ProgressEvent("progress",{lengthComputable:o,loaded:a,total:s}),u=0,l=n.length;u<l;u++){var h=n[u];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,a)}));case"json":return e.json();default:if(void 0===a)return e.text();var t=/charset="?([^;"\s]*)"?/i.exec(a),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){vo.add(e,t);var n=_o[e];delete _o[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=_o[e];if(void 0===n)throw i.manager.itemError(e),t;delete _o[e];for(var r=0,s=n.length;r<s;r++){var o=n[r];o.onError&&o.onError(t)}i.manager.itemError(e)})).finally((function(){i.manager.itemEnd(e)})),this.manager.itemStart(e)}else _o[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}(),wo=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,o=r.transfer;this.workersResolve[e]=i,this.workers[e].postMessage(s,o)}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}(),Bo=0,Co=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 wo,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 bo;n.setPath(this._transcoderPath),n.setWithCredentials(this.withCredentials);var r=n.loadAsync("basis_transcoder.js"),i=new bo;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=M(n,2),i=r[0],s=r[1],o=e.BasisWorker.toString(),a=["/* constants */","let _EngineFormat = "+JSON.stringify(e.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(e.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(e.BasisFormat),"/* basis_transcoder.js */",i,"/* worker */",o.substring(o.indexOf("{")+1,o.lastIndexOf("}"))].join("\n");t._workerSourceURL=URL.createObjectURL(new Blob([a])),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}))})),Bo>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),Bo++}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 o=r;n._init().then((function(){return n._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:o},e)})).then((function(e){var n=e.data,r=n.mipmaps,o=(n.width,n.height,n.format),a=n.type,A=n.error,c=n.dfdTransferFn,u=n.dfdFlags;if("error"===a)return s(A);t.setCompressedData({mipmaps:r,props:{format:o,minFilter:1===r.length?1006:1008,magFilter:1===r.length?1006:1008,encoding:2===c?3001:3e3,premultiplyAlpha:!!(1&u)}}),i()}))}))}},{key:"destroy",value:function(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),Bo--}}]),e}();Co.BasisFormat={ETC1S:0,UASTC_4x4:1},Co.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},Co.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},Co.BasisWorker=function(){var e,t,n,r=_EngineFormat,i=_TranscoderFormat,s=_BasisFormat;self.addEventListener("message",(function(o){var u,l=o.data;switch(l.type){case"init":e=l.config,u=l.transcoderBinary,t=new Promise((function(e){n={wasmBinary:u,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 o=new n.KTX2File(new Uint8Array(t));function u(){o.close(),o.delete()}if(!o.isValid())throw u(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");var l=o.isUASTC()?s.UASTC_4x4:s.ETC1S,h=o.getWidth(),d=o.getHeight(),f=o.getLevels(),p=o.getHasAlpha(),v=o.getDFDTransferFunc(),g=o.getDFDFlags(),m=function(t,n,o,u){for(var l,h,d=t===s.ETC1S?a:A,f=0;f<d.length;f++){var p=d[f];if(e[p.if]&&(p.basisFormat.includes(t)&&!(u&&p.transcoderFormat.length<2)&&(!p.needsPowerOfTwo||c(n)&&c(o))))return{transcoderFormat:l=p.transcoderFormat[u?1:0],engineFormat:h=p.engineFormat[u?1:0]}}return console.warn("KTX2TextureTranscoder: No suitable compressed texture format found. Decoding to RGBA32."),l=i.RGBA32,h=r.RGBAFormat,{transcoderFormat:l,engineFormat:h}}(l,h,d,p),y=m.transcoderFormat,_=m.engineFormat;if(!h||!d||!f)throw u(),new Error("KTX2TextureTranscoder: Invalid texture");if(!o.startTranscoding())throw u(),new Error("KTX2TextureTranscoder: .startTranscoding failed");for(var b=[],w=0;w<f;w++){var B=o.getImageLevelInfo(w,0,0),C=B.origWidth,k=B.origHeight,M=new Uint8Array(o.getImageTranscodedSizeInBytes(w,0,0,y));if(!o.transcodeImage(M,w,0,0,y,0,-1,-1))throw u(),new Error("KTX2TextureTranscoder: .transcodeImage failed.");b.push({data:M,width:C,height:k})}return u(),{width:h,height:d,hasAlpha:p,mipmaps:b,format:_,dfdTransferFn:v,dfdFlags:g}}(l.buffers[0]),o=t.width,u=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:l.id,width:o,height:u,hasAlpha:h,mipmaps:d,format:f,dfdTransferFn:p,dfdFlags:v},g)}catch(e){console.error("[KTX2TextureTranscoder.BasisWorker]: ".concat(e)),self.postMessage({type:"error",id:l.id,error:e.message})}}))}}));var o=[{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}],a=o.sort((function(e,t){return e.priorityETC1S-t.priorityETC1S})),A=o.sort((function(e,t){return e.priorityUASTC-t.priorityUASTC}));function c(e){return e<=2||0==(e&e-1)&&0!==e}};var ko={};function Mo(e){var t=e.scene.id,n=ko[t];return n||(n=new Co({viewer:e}),ko[t]=n,e.scene.on("destroyed",(function(){delete ko[t],n.destroy()}))),n}
|
|
7
|
+
var e,t,n,r=A().mark(ob),i=A().mark(ab),s=A().mark(jC);function o(e){var t="function"==typeof Map?new Map:void 0;return o=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 a(e,arguments,C(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),y(r,e)},o(e)}function a(e,t,n){return a=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},a.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",o=r.toStringTag||"@@toStringTag";function a(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{a({},"")}catch(e){a=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),o=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 o=n.delegate;if(o){var a=b(o,n);if(a){if(a===l)continue;return a}}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=u(e,t,n);if("normal"===A.type){if(r=n.done?"completed":"suspendedYield",A.arg===l)continue;return{value:A.arg,done:n.done}}"throw"===A.type&&(r="completed",n.method="throw",n.arg=A.arg)}}}(e,n,o),s}function u(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var l={};function h(){}function d(){}function f(){}var p={};a(p,i,(function(){return this}));var v=Object.getPrototypeOf,g=v&&v(v(M([])));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){a(e,t,(function(e){return this._invoke(t,e)}))}))}function _(e,t){function r(i,s,o,a){var A=u(e[i],e,s);if("throw"!==A.type){var c=A.arg,l=c.value;return l&&"object"==k(l)&&n.call(l,"__await")?t.resolve(l.__await).then((function(e){r("next",e,o,a)}),(function(e){r("throw",e,o,a)})):t.resolve(l).then((function(e){c.value=e,o(c)}),(function(e){return r("throw",e,o,a)}))}a(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 l;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var r=u(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,l;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,l):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}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 M(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,a(m,"constructor",f),a(f,"constructor",d),d.displayName=a(f,o,"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,a(e,o,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},y(_.prototype),a(_.prototype,s,(function(){return this})),e.AsyncIterator=_,e.async=function(t,n,r,i,s){void 0===s&&(s=Promise);var o=new _(c(t,n,r,i),s);return e.isGeneratorFunction(n)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},y(m),a(m,o,"Generator"),a(m,i,(function(){return this})),a(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=M,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 o.type="throw",o.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],o=s.completion;if("root"===s.tryLoc)return r("end");if(s.tryLoc<=this.prev){var a=n.call(s,"catchLoc"),A=n.call(s,"finallyLoc");if(a&&A){if(this.prev<s.catchLoc)return r(s.catchLoc,!0);if(this.prev<s.finallyLoc)return r(s.finallyLoc)}else if(a){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 o=s?s.completion:{};return o.type=e,o.arg=t,s?(this.method="next",this.next=s.finallyLoc,l):this.complete(o)},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),l},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),l}},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:M(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),l}},e}function c(e,t,n,r,i,s,o){try{var a=e[s](o),A=a.value}catch(e){return void n(e)}a.done?t(A):Promise.resolve(A).then(r,i)}function u(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var s=e.apply(t,n);function o(e){c(s,r,i,o,a,"next",e)}function a(e){c(s,r,i,o,a,"throw",e)}o(void 0)}))}}function l(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,o=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){a=!0,s=e},f:function(){try{o||null==n.return||n.return()}finally{if(a)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"===k(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 k(e){return k="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},k(e)}function M(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=[],o=!0,a=!1;try{for(n=n.call(e);!(o=(r=n.next()).done)&&(s.push(r.value),!t||s.length!==t);o=!0);}catch(e){a=!0,i=e}finally{try{o||null==n.return||n.return()}finally{if(a)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),o=s.value,a=o instanceof D;Promise.resolve(a?o.wrapped:o).then((function(e){a?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,o){var a={key:e,arg:i,resolve:s,reject:o,next:null};n?n=n.next=a:(t=n=a,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)};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,o=n.length;s<o;s++){var a=n[s],A=new q;i.groups.push(A);for(var c=function(n,r){var s=a[n],o=s.items,c=o&&o.length>0,u=t._getNextId(),l=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 $(u,l,h,d,f);if(p.parentMenu=i,A.items.push(p),c){var v=e(o);p.subMenu=v,v.parentItem=p}t._itemList.push(p),t._itemMap[p.id]=p},u=0,l=a.length;u<l;u++)c(u)}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 o=r[i].items,a=0,A=o.length;a<A;a++){var c=o[a].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,o=n.length;s<o;s++){var a=s,A=o,c=n[s].items;if(c)for(var u=0,l=c.length;u<l;u++){var h=c[u],d=h.subMenu,f=h.title||"";d?(r.push('<li id="'+h.id+'" class="xeokit-context-menu-item xeokit-context-menu-submenu">'+f+"</li>"),a===A-1||u<l-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>"),a===A-1||u<l-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 o=v._offsetParent.getBoundingClientRect(),a=200,A=s.right+a<o.right,c=s.left-a>o.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-a+window.scrollX,s.top+window.scrollY-1);else{var u=s.left-o.left,l=o.right-s.right;l>u?v._showMenu(t.id,s.right-5-(a-l),s.top+window.scrollY-1):v._showMenu(t.id,s.left-u,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 o=s(this._context);if(n.shown=o,o){r.style.display="";var a=i(this._context);n.enabled=a,a?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(o){o.subMenu&&(e=o.itemElement,t=e.getBoundingClientRect(),n=o.subMenu.menuElement,r={visibility:n.style.visibility,display:n.style.display},n.style.display="block",n.style.visibility="hidden",s=o.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(),o=this._offsetParent===window.document.body&&0===s.bottom?window.innerHeight:s.bottom+window.scrollY,a=s.right+window.scrollX;n+r>o&&(n=o-r),t+i>a&&(t=a-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,o=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+o*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=M(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),oe=new re(16),ae=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],o=t[1],a=t[2];return[r*a-i*o,i*s-n*a,n*o-r*s,0]},cross3Vec3:function(e,t,n){n||(n=e);var r=e[0],i=e[1],s=e[2],o=t[0],a=t[1],A=t[2];return n[0]=i*A-s*a,n[1]=s*o-r*A,n[2]=r*a-i*o,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],o=e[3],a=e[4],A=e[5],c=e[6],u=e[7],l=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],k=t[6],M=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+_*a+b*l+w*p,n[1]=y*i+_*A+b*h+w*v,n[2]=y*s+_*c+b*d+w*g,n[3]=y*o+_*u+b*f+w*m,n[4]=B*r+C*a+k*l+M*p,n[5]=B*i+C*A+k*h+M*v,n[6]=B*s+C*c+k*d+M*g,n[7]=B*o+C*u+k*f+M*m,n[8]=E*r+F*a+x*l+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*o+F*u+x*f+U*m,n[12]=I*r+T*a+P*l+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*o+T*u+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],o=e[1],a=e[4],A=e[7],c=e[2],u=e[5],l=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]=o*h+a*p+A*m,n[4]=o*d+a*v+A*y,n[7]=o*f+a*g+A*_,n[2]=c*h+u*p+l*m,n[5]=c*d+u*v+l*y,n[8]=c*f+u*g+l*_,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],o=t[3];return n[0]=e[0]*r+e[4]*i+e[8]*s+e[12]*o,n[1]=e[1]*r+e[5]*i+e[9]*s+e[13]*o,n[2]=e[2]*r+e[6]*i+e[10]*s+e[14]*o,n[3]=e[3]*r+e[7]*i+e[11]*s+e[15]*o,n},transposeMat4:function(e,t){var n=e[4],r=e[14],i=e[8],s=e[13],o=e[12],a=e[9];if(!t||e===t){var A=e[1],c=e[2],u=e[3],l=e[6],h=e[7],d=e[11];return e[1]=n,e[2]=i,e[3]=o,e[4]=A,e[6]=a,e[7]=s,e[8]=c,e[9]=l,e[11]=r,e[12]=u,e[13]=h,e[14]=d,e}return t[0]=e[0],t[1]=n,t[2]=i,t[3]=o,t[4]=e[1],t[5]=e[5],t[6]=a,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],o=e[5],a=e[6],A=e[7],c=e[8],u=e[9],l=e[10],h=e[11],d=e[12],f=e[13],p=e[14],v=e[15];return d*u*a*i-c*f*a*i-d*o*l*i+s*f*l*i+c*o*p*i-s*u*p*i-d*u*r*A+c*f*r*A+d*n*l*A-t*f*l*A-c*n*p*A+t*u*p*A+d*o*r*h-s*f*r*h-d*n*a*h+t*f*a*h+s*n*p*h-t*o*p*h-c*o*r*v+s*u*r*v+c*n*a*v-t*u*a*v-s*n*l*v+t*o*l*v},inverseMat4:function(e,t){t||(t=e);var n=e[0],r=e[1],i=e[2],s=e[3],o=e[4],a=e[5],A=e[6],c=e[7],u=e[8],l=e[9],h=e[10],d=e[11],f=e[12],p=e[13],v=e[14],g=e[15],m=n*a-r*o,y=n*A-i*o,_=n*c-s*o,b=r*A-i*a,w=r*c-s*a,B=i*c-s*A,C=u*p-l*f,k=u*v-h*f,M=u*g-d*f,E=l*v-h*p,F=l*g-d*p,x=h*g-d*v,U=1/(m*x-y*F+_*E+b*M-w*k+B*C);return t[0]=(a*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]=(-l*B+h*w-d*b)*U,t[4]=(-o*x+A*M-c*k)*U,t[5]=(n*x-i*M+s*k)*U,t[6]=(-f*B+v*_-g*y)*U,t[7]=(u*B-h*_+d*y)*U,t[8]=(o*F-a*M+c*C)*U,t[9]=(-n*F+r*M-s*C)*U,t[10]=(f*w-p*_+g*m)*U,t[11]=(-u*w+l*_-d*m)*U,t[12]=(-o*E+a*k-A*C)*U,t[13]=(n*E-r*k+i*C)*U,t[14]=(-f*b+p*y-v*m)*U,t[15]=(u*b-l*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 o=r[11];r[8]+=o*e,r[9]+=o*t,r[10]+=o*n;var a=r[15];return r[12]+=a*e,r[13]+=a*t,r[14]+=a*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,o,a,A,c=Ae.normalizeVec4([t[0],t[1],t[2],0],[]),u=Math.sin(e),l=Math.cos(e),h=1-l,d=c[0],f=c[1],p=c[2];return r=d*f,i=f*p,s=p*d,o=d*u,a=f*u,A=p*u,(n=n||Ae.mat4())[0]=h*d*d+l,n[1]=h*r+A,n[2]=h*s-a,n[3]=0,n[4]=h*r-A,n[5]=h*f*f+l,n[6]=h*i+o,n[7]=0,n[8]=h*s+a,n[9]=h*i-o,n[10]=h*p*p+l,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],o=e[3],a=r+r,A=i+i,c=s+s,u=r*a,l=r*A,h=r*c,d=i*A,f=i*c,p=s*c,v=o*a,g=o*A,m=o*c;return n[0]=1-(d+p),n[1]=l+m,n[2]=h-g,n[3]=0,n[4]=l-m,n[5]=1-(u+p),n[6]=f+v,n[7]=0,n[8]=h+g,n[9]=f-v,n[10]=1-(u+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],o=e[8],a=e[1],A=e[5],c=e[9],u=e[2],l=e[6],h=e[10];return"XYZ"===t?(n[1]=Math.asin(r(o,-1,1)),Math.abs(o)<.99999?(n[0]=Math.atan2(-c,h),n[2]=Math.atan2(-s,i)):(n[0]=Math.atan2(l,A),n[2]=0)):"YXZ"===t?(n[0]=Math.asin(-r(c,-1,1)),Math.abs(c)<.99999?(n[1]=Math.atan2(o,h),n[2]=Math.atan2(a,A)):(n[1]=Math.atan2(-u,i),n[2]=0)):"ZXY"===t?(n[0]=Math.asin(r(l,-1,1)),Math.abs(l)<.99999?(n[1]=Math.atan2(-u,h),n[2]=Math.atan2(-s,A)):(n[1]=0,n[2]=Math.atan2(a,i))):"ZYX"===t?(n[1]=Math.asin(-r(u,-1,1)),Math.abs(u)<.99999?(n[0]=Math.atan2(l,h),n[2]=Math.atan2(a,i)):(n[0]=0,n[2]=Math.atan2(-s,A))):"YZX"===t?(n[2]=Math.asin(r(a,-1,1)),Math.abs(a)<.99999?(n[0]=Math.atan2(-c,A),n[1]=Math.atan2(-u,i)):(n[0]=0,n[1]=Math.atan2(o,h))):"XZY"===t&&(n[2]=Math.asin(-r(s,-1,1)),Math.abs(s)<.99999?(n[0]=Math.atan2(l,A),n[1]=Math.atan2(o,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 o=Ae.lenVec3(e);e[0]=n[4],e[1]=n[5],e[2]=n[6];var a=Ae.lenVec3(e);e[8]=n[8],e[9]=n[9],e[10]=n[10];var A=Ae.lenVec3(e);Ae.determinantMat4(n)<0&&(o=-o),r[0]=n[12],r[1]=n[13],r[2]=n[14],t.set(n);var c=1/o,u=1/a,l=1/A;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=u,t[5]*=u,t[6]*=u,t[8]*=l,t[9]*=l,t[10]*=l,Ae.mat4ToQuaternion(t,i),s[0]=o,s[1]=a,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,o,a,A,c,u,l,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,o=v-w,a=m*(o*=d=1/Math.sqrt(i*i+s*s+o*o))-y*(s*=d),A=y*(i*=d)-g*o,c=g*s-m*i,(d=Math.sqrt(a*a+A*A+c*c))?(a*=d=1/d,A*=d,c*=d):(a=0,A=0,c=0),u=s*c-o*A,l=o*a-i*c,h=i*A-s*a,(d=Math.sqrt(u*u+l*l+h*h))?(u*=d=1/d,l*=d,h*=d):(u=0,l=0,h=0),r[0]=a,r[1]=u,r[2]=i,r[3]=0,r[4]=A,r[5]=l,r[6]=s,r[7]=0,r[8]=c,r[9]=h,r[10]=o,r[11]=0,r[12]=-(a*f+A*p+c*v),r[13]=-(u*f+l*p+h*v),r[14]=-(i*f+s*p+o*v),r[15]=1,r)},lookAtMat4c:function(e,t,n,r,i,s,o,a,A){return Ae.lookAtMat4v([e,t,n],[r,i,s],[o,a,A],[])},orthoMat4c:function(e,t,n,r,i,s,o){o||(o=Ae.mat4());var a=t-e,A=r-n,c=s-i;return o[0]=2/a,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2/A,o[6]=0,o[7]=0,o[8]=0,o[9]=0,o[10]=-2/c,o[11]=0,o[12]=-(e+t)/a,o[13]=-(r+n)/A,o[14]=-(s+i)/c,o[15]=1,o},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,oe);var s=2*r[2],o=oe[0],a=oe[1],A=oe[2];return n[0]=s/o,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=s/a,n[6]=0,n[7]=0,n[8]=se[0]/o,n[9]=se[1]/a,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,o){o||(o=Ae.mat4());var a=t-e,A=r-n,c=s-i;return o[0]=2*i/a,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2*i/A,o[6]=0,o[7]=0,o[8]=(t+e)/a,o[9]=(r+n)/A,o[10]=-(s+i)/c,o[11]=-1,o[12]=0,o[13]=0,o[14]=-s*i*2/c,o[15]=0,o},perspectiveMat4:function(e,t,n,r,i){var s=[],o=[];return s[2]=n,o[2]=r,o[1]=s[2]*Math.tan(e/2),s[1]=-o[1],o[0]=o[1]*t,s[0]=-o[0],Ae.frustumMat4v(s,o,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,o,a,A=n||[],c=t.length,u=e[0],l=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],k=e[15],M=0;M<c;++M)r=(o=t[M])[0],i=o[1],s=o[2],(a=A[M]||(A[M]=[0,0,0]))[0]=u*r+f*i+m*s+w,a[1]=l*r+p*i+y*s+B,a[2]=h*r+v*i+_*s+C,a[3]=d*r+g*i+b*s+k;return A.length=c,A},transformPositions3:function(e,t){var n,r,i,s,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,a=t.length,A=e[0],c=e[1],u=e[2];e[3];var l=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<a;n+=3)r=t[n+0],i=t[n+1],s=t[n+2],o[n+0]=A*r+l*i+f*s+g,o[n+1]=c*r+h*i+p*s+m,o[n+2]=u*r+d*i+v*s+y;return o},transformPositions4:function(e,t){var n,r,i,s,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,a=t.length,A=e[0],c=e[1],u=e[2],l=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<a;n+=4)r=t[n+0],i=t[n+1],s=t[n+2],o[n+0]=A*r+h*i+v*s+_,o[n+1]=c*r+d*i+g*s+b,o[n+2]=u*r+f*i+m*s+w,o[n+3]=l*r+p*i+y*s+B;return o},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],o=t[3];return(n=n||Ae.vec4())[0]=e[0]*r+e[4]*i+e[8]*s+e[12]*o,n[1]=e[1]*r+e[5]*i+e[9]*s+e[13]*o,n[2]=e[2]*r+e[6]*i+e[10]*s+e[14]*o,n[3]=e[3]*r+e[7]*i+e[11]*s+e[15]*o,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),o=e[0]-t[0],a=e[1]-t[1];return r[0]=o*i-a*s+t[0],r[1]=o*s+a*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 o=s||Ae.vec3(),a=(e-t)/(n-t);return o[0]=r[0]+a*(i[0]-r[0]),o[1]=r[1]+a*(i[1]-r[1]),o[2]=r[2]+a*(i[2]-r[2]),o},lerpMat4:function(e,t,n,r,i,s){var o=s||Ae.mat4(),a=(e-t)/(n-t);return o[0]=r[0]+a*(i[0]-r[0]),o[1]=r[1]+a*(i[1]-r[1]),o[2]=r[2]+a*(i[2]-r[2]),o[3]=r[3]+a*(i[3]-r[3]),o[4]=r[4]+a*(i[4]-r[4]),o[5]=r[5]+a*(i[5]-r[5]),o[6]=r[6]+a*(i[6]-r[6]),o[7]=r[7]+a*(i[7]-r[7]),o[8]=r[8]+a*(i[8]-r[8]),o[9]=r[9]+a*(i[9]-r[9]),o[10]=r[10]+a*(i[10]-r[10]),o[11]=r[11]+a*(i[11]-r[11]),o[12]=r[12]+a*(i[12]-r[12]),o[13]=r[13]+a*(i[13]-r[13]),o[14]=r[14]+a*(i[14]-r[14]),o[15]=r[15]+a*(i[15]-r[15]),o},flatten:function(e){var t,n,r,i,s,o=[];for(t=0,n=e.length;t<n;t++)for(r=0,i=(s=e[t]).length;r<i;r++)o.push(s[r]);return o},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,o=Math.cos(r),a=Math.cos(i),A=Math.cos(s),c=Math.sin(r),u=Math.sin(i),l=Math.sin(s);return"XYZ"===t?(n[0]=c*a*A+o*u*l,n[1]=o*u*A-c*a*l,n[2]=o*a*l+c*u*A,n[3]=o*a*A-c*u*l):"YXZ"===t?(n[0]=c*a*A+o*u*l,n[1]=o*u*A-c*a*l,n[2]=o*a*l-c*u*A,n[3]=o*a*A+c*u*l):"ZXY"===t?(n[0]=c*a*A-o*u*l,n[1]=o*u*A+c*a*l,n[2]=o*a*l+c*u*A,n[3]=o*a*A-c*u*l):"ZYX"===t?(n[0]=c*a*A-o*u*l,n[1]=o*u*A+c*a*l,n[2]=o*a*l-c*u*A,n[3]=o*a*A+c*u*l):"YZX"===t?(n[0]=c*a*A+o*u*l,n[1]=o*u*A+c*a*l,n[2]=o*a*l-c*u*A,n[3]=o*a*A-c*u*l):"XZY"===t&&(n[0]=c*a*A-o*u*l,n[1]=o*u*A-c*a*l,n[2]=o*a*l+c*u*A,n[3]=o*a*A+c*u*l),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],o=e[1],a=e[5],A=e[9],c=e[2],u=e[6],l=e[10],h=r+a+l;return h>0?(t=.5/Math.sqrt(h+1),n[3]=.25/t,n[0]=(u-A)*t,n[1]=(s-c)*t,n[2]=(o-i)*t):r>a&&r>l?(t=2*Math.sqrt(1+r-a-l),n[3]=(u-A)/t,n[0]=.25*t,n[1]=(i+o)/t,n[2]=(s+c)/t):a>l?(t=2*Math.sqrt(1+a-r-l),n[3]=(s-c)/t,n[0]=(i+o)/t,n[1]=.25*t,n[2]=(A+u)/t):(t=2*Math.sqrt(1+l-r-a),n[3]=(o-i)/t,n[0]=(s+c)/t,n[1]=(A+u)/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],o=e[3],a=t[0],A=t[1],c=t[2],u=t[3];return n[0]=o*a+r*u+i*c-s*A,n[1]=o*A+i*u+s*a-r*c,n[2]=o*c+s*u+r*A-i*a,n[3]=o*u-r*a-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],o=e[0],a=e[1],A=e[2],c=e[3],u=c*r+a*s-A*i,l=c*i+A*r-o*s,h=c*s+o*i-a*r,d=-o*r-a*i-A*s;return n[0]=u*c+d*-o+l*-A-h*-a,n[1]=l*c+d*-a+h*-o-u*-A,n[2]=h*c+d*-A+u*-a-l*-o,n},quaternionToMat4:function(e,t){t=Ae.identityMat4(t);var n=e[0],r=e[1],i=e[2],s=e[3],o=2*n,a=2*r,A=2*i,c=o*s,u=a*s,l=A*s,h=o*n,d=a*n,f=A*n,p=a*r,v=A*r,g=A*i;return t[0]=1-(p+g),t[1]=d+l,t[2]=f-u,t[4]=d-l,t[5]=1-(h+g),t[6]=v+c,t[8]=f+u,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],o=n+n,a=r+r,A=i+i,c=n*o,u=n*a,l=n*A,h=r*a,d=r*A,f=i*A,p=s*o,v=s*a,g=s*A;return t[0]=1-(h+f),t[4]=u-g,t[8]=l+v,t[1]=u+g,t[5]=1-(c+f),t[9]=d-p,t[2]=l-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,ae))[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,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,a=t.length,A=e[0],c=e[1],u=e[2],l=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<a;n+=4)r=t[n+0],i=t[n+1],s=t[n+2],o[n+0]=A*r+h*i+v*s+_,o[n+1]=c*r+d*i+g*s+b,o[n+2]=u*r+f*i+m*s+w,o[n+3]=l*r+p*i+y*s+B;return o},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),o=i[0]-r[0],a=r[3]-i[0],A=i[1]-r[1],c=r[4]-i[1],u=i[2]-r[2],l=r[5]-i[2];return s[0]+=o>a?o:a,s[1]+=A>c?A:c,s[2]+=u>l?u:l,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,o,a=Ae.MAX_DOUBLE,A=Ae.MAX_DOUBLE,c=Ae.MAX_DOUBLE,u=Ae.MIN_DOUBLE,l=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],o=e[2]):(i=t[d+0],s=t[d+1],o=t[d+2]),i<a&&(a=i),s<A&&(A=s),o<c&&(c=o),i>u&&(u=i),s>l&&(l=s),o>h&&(h=o);return n[0]=a,n[1]=A,n[2]=c,n[3]=u,n[4]=l,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,o=Ae.MAX_DOUBLE,a=Ae.MAX_DOUBLE,A=Ae.MIN_DOUBLE,c=Ae.MIN_DOUBLE,u=Ae.MIN_DOUBLE,l=0,h=e.length;l<h;l+=4)(t=e[l+0])<s&&(s=t),(n=e[l+1])<o&&(o=n),(r=e[l+2])<a&&(a=r),t>A&&(A=t),n>c&&(c=n),r>u&&(u=r);return i[0]=s,i[1]=o,i[2]=a,i[3]=A,i[4]=c,i[5]=u,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,o=Ae.MAX_DOUBLE,a=Ae.MAX_DOUBLE,A=Ae.MIN_DOUBLE,c=Ae.MIN_DOUBLE,u=Ae.MIN_DOUBLE,l=0,h=e.length;l<h;l++)(t=e[l][0])<s&&(s=t),(n=e[l][1])<o&&(o=n),(r=e[l][2])<a&&(a=r),t>A&&(A=t),n>c&&(c=n),r>u&&(u=r);return i[0]=s,i[1]=o,i[2]=a,i[3]=A,i[4]=c,i[5]=u,i},points3ToSphere3:function(){var e=new re(3);return function(t,n){n=n||Ae.vec4();var r,i=0,s=0,o=0,a=t.length;for(r=0;r<a;r++)i+=t[r][0],s+=t[r][1],o+=t[r][2];n[0]=i/a,n[1]=s/a,n[2]=o/a;var A,c=0;for(r=0;r<a;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,o=0,a=0,A=n.length,c=0;for(i=0;i<A;i+=3)s+=n[i],o+=n[i+1],a+=n[i+2];var u,l=A/3;for(r[0]=s/l,r[1]=o/l,r[2]=a/l,i=0;i<A;i+=3)e[0]=n[i],e[1]=n[i+1],e[2]=n[i+2],(u=Math.abs(Ae.lenVec3(Ae.subVec3(e,r,t))))>c&&(c=u);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,o=0,a=0,A=n.length,c=A/4;for(i=0;i<A;i+=4)s+=n[i+0],o+=n[i+1],a+=n[i+2];r[0]=s/c,r[1]=o/c,r[2]=a/c;var u,l=0;for(i=0;i<A;i+=4)e[0]=n[i+0],e[1]=n[i+1],e[2]=n[i+2],(u=Math.abs(Ae.lenVec3(Ae.subVec3(e,r,t))))>l&&(l=u);return r[3]=l,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,o=e.length;s<o;s+=3)n+=e[s+0],r+=e[s+1],i+=e[s+2];var a=e.length/3;return t[0]=n/a,t[1]=r/a,t[2]=i/a,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,o=t.length;s<o;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,o=Ae.MAX_DOUBLE,a=Ae.MIN_DOUBLE,A=Ae.MIN_DOUBLE,c=0,u=e.length;c<u;c+=4)t=e[c+0],n=e[c+1],(t*=r=1/(e[c+3]||1))<s&&(s=t),(n*=r)<o&&(o=n),t>a&&(a=t),n>A&&(A=n);return i[0]=s,i[1]=o,i[2]=a,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),o=.5*(e[2]+1),a=.5*(e[3]+1);return r[0]=Math.floor(i*t),r[1]=n-Math.floor(a*n),r[2]=Math.floor(o*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),o=.5*(r-t),a=i*i;return(2*t-2*n+s+o)*(i*a)+(-3*t+3*n-2*s-o)*a+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],o=t[2]-e[2],a=n[0]-e[0],A=n[1]-e[1],c=n[2]-e[2],u=s*c-o*A,l=o*a-i*c,h=i*A-s*a,d=Math.sqrt(u*u+l*l+h*h);return 0===d?(r[0]=0,r[1]=0,r[2]=0):(r[0]=u/d,r[1]=l/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,o,a,A,c,u){u=u||Ae.vec3();var l=Ae.subVec3(A,a,e),h=Ae.subVec3(c,a,t),d=Ae.cross3Vec3(o,h,n),f=Ae.dotVec3(l,d);if(f<1e-6)return null;var p=Ae.subVec3(s,a,r),v=Ae.dotVec3(p,d);if(v<0||v>f)return null;var g=Ae.cross3Vec3(p,l,i),m=Ae.dotVec3(o,g);if(m<0||v+m>f)return null;var y=Ae.dotVec3(h,g)/f;return u[0]=s[0]+y*o[0],u[1]=s[1]+y*o[1],u[2]=s[2]+y*o[2],u}}(),rayPlaneIntersect:function(){var e=new re(3),t=new re(3),n=new re(3),r=new re(3);return function(i,s,o,a,A,c){c=c||Ae.vec3(),s=Ae.normalizeVec3(s,e);var u=Ae.subVec3(a,o,t),l=Ae.subVec3(A,o,n),h=Ae.cross3Vec3(u,l,r);Ae.normalizeVec3(h,h);var d=-Ae.dotVec3(o,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,o,a){var A=Ae.subVec3(o,i,e),c=Ae.subVec3(s,i,t),u=Ae.subVec3(r,i,n),l=Ae.dotVec3(A,A),h=Ae.dotVec3(A,c),d=Ae.dotVec3(A,u),f=Ae.dotVec3(c,c),p=Ae.dotVec3(c,u),v=l*f-h*h;if(0===v)return null;var g=1/v,m=(f*d-h*p)*g,y=(l*p-h*d)*g;return a[0]=1-m-y,a[1]=y,a[2]=m,a}}(),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],o=e[1],a=e[2];return i[0]=t[0]*s+n[0]*o+r[0]*a,i[1]=t[1]*s+n[1]*o+r[1]*a,i[2]=t[2]*s+n[2]*o+r[2]*a,i},mergeVertices:function(e,t,n,r){var i,s,o,a,A,c,u={},l=[],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],o=e[A+2],void 0===u[a="".concat(Math.round(i*v),"_").concat(Math.round(s*v),"_").concat(Math.round(o*v))]&&(u[a]=h.length/3,h.push(i),h.push(s),h.push(o),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]))),l[A/3]=u[a],g+=2;for(A=0,c=r.length;A<c;A++)p[A]=l[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(o,a,A){var c,u,l,h,d,f,p,v,g,m=new Array(o.length/3);for(c=0,u=a.length;c<u;c+=3){l=a[c],h=a[c+1],d=a[c+2],e[0]=o[3*l],e[1]=o[3*l+1],e[2]=o[3*l+2],t[0]=o[3*h],t[1]=o[3*h+1],t[2]=o[3*h+2],n[0]=o[3*d],n[1]=o[3*d+1],n[2]=o[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[l]||(m[l]=[]),m[h]||(m[h]=[]),m[d]||(m[d]=[]),m[l].push(y),m[h].push(y),m[d].push(y)}for(A=A&&A.length===o.length?A:new Float32Array(o.length),c=0,u=m.length;c<u;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),o=new re(3);return function(a,A,c){for(var u=new Float32Array(a.length),l=0;l<A.length;l+=3){var h=A[l],d=a.subarray(3*h,3*h+3),f=c.subarray(2*h,2*h+2);h=A[l+1];var p=a.subarray(3*h,3*h+3),v=c.subarray(2*h,2*h+2);h=A[l+2];for(var g=a.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),o),B,s),k=void 0,M=0;M<3;M++)u[k=3*A[l+M]]+=C[0],u[k+1]+=C[1],u[k+2]+=C[2]}return u}}(),buildPickTriangles:function(e,t,n){for(var r,i,s,o,a,A=t.length,c=n?new Uint16Array(9*A):new Float32Array(9*A),u=new Uint8Array(12*A),l=0,h=0,d=0,f=0;f<A;f+=3)a=l>>24&255,o=l>>16&255,s=l>>8&255,i=255&l,r=3*t[f],c[h++]=e[r],c[h++]=e[r+1],c[h++]=e[r+2],u[d++]=i,u[d++]=s,u[d++]=o,u[d++]=a,r=3*t[f+1],c[h++]=e[r],c[h++]=e[r+1],c[h++]=e[r+2],u[d++]=i,u[d++]=s,u[d++]=o,u[d++]=a,r=3*t[f+2],c[h++]=e[r],c[h++]=e[r+1],c[h++]=e[r+2],u[d++]=i,u[d++]=s,u[d++]=o,u[d++]=a,l++;return{positions:c,colors:u}},faceToVertexNormals:function(e,t){var n,r,i,s,o,a,A,c,u,l,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,u=e.length;A<u;A+=3){a=A/3,r=e[A],i=e[A+1],s=e[A+2],void 0===p[o="".concat(Math.round(r*y),"_").concat(Math.round(i*y),"_").concat(Math.round(s*y))]?p[o]=[a]:p[o].push(a);var _=Ae.normalizeVec3([t[A],t[A+1],t[A+2]]);v[a]=_,n=Ae.vec4([_[0],_[1],_[2],1]),g[a]=n}for(o in p)if(p.hasOwnProperty(o)){var b=p[o],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];l=v[B],h=v[C];var k=Math.abs(Ae.angleVec3(l,h)/Ae.DEGTORAD);k<f&&(n[0]+=h[0],n[1]+=h[1],n[2]+=h[2],n[3]+=1)}}}for(A=0,u=t.length;A<u;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,o){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),o[0]=t[0],o[1]=t[1],o[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,o){var a="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,a,H),G(A,c,1,a,N),s[0]=H[0],s[1]=H[1],s[2]=H[2],Ae.subVec3(N,H,o),Ae.normalizeVec3(o)}),canvasPosToLocalRay:(O=new re(3),V=new re(3),function(e,t,n,r,i,s,o,a){Ae.canvasPosToWorldRay(e,t,n,r,s,O,V),Ae.worldRayToLocalRay(i,O,V,o,a)}),worldRayToLocalRay:function(){var e=new re(16),t=new re(4),n=new re(4);return function(r,i,s,o,a){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),o[0]=n[0],o[1]=n[1],o[2]=n[2],Ae.transformVec3(A,s,a)}}(),buildKDTree:function(){var e=new Float32Array;function t(n,r,i,s){var o,a,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,o=0,a=n.length;o<a;++o)for(var u=3*n[o],l=0;l<3;++l){var h=3*r[u+l];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(o=0,a=n.length;o<a;++o){var y=r[u=3*n[o]],_=3*r[u+1],b=3*r[u+2];i[3*y+d]<=f||i[_+d]<=f||i[b+d]<=f?p[v++]=n[o]:g[m++]=n[o]}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],o=e[n+1];s=(2*s+1)/255,o=(2*o+1)/255;var a=1-Math.abs(s)-Math.abs(o);a<0&&(s=(1-Math.abs(o))*(s>=0?1:-1),o=(1-Math.abs(s))*(o>=0?1:-1));var A=Math.sqrt(s*s+o*o+a*a);t[r+0]=s/A,t[r+1]=o/A,t[r+2]=a/A,r+=3}return t}};Ae.buildEdgeIndices=function(){var e=[],t=[],n=[],r=[],i=[],s=0,o=new Uint16Array(3),a=new Uint16Array(3),A=new Uint16Array(3),c=Ae.vec3(),u=Ae.vec3(),l=Ae.vec3(),h=Ae.vec3(),d=Ae.vec3(),f=Ae.vec3(),p=Ae.vec3();return function(v,g,m,y){!function(i,s){var o,a,A,c,u,l,h={},d=Math.pow(10,4),f=0;for(u=0,l=i.length;u<l;u+=3)o=i[u],a=i[u+1],A=i[u+2],void 0===h[c=Math.round(o*d)+"_"+Math.round(a*d)+"_"+Math.round(A*d)]&&(h[c]=f/3,e[f++]=o,e[f++]=a,e[f++]=A),t[u/3]=h[c];for(u=0,l=s.length;u<l;u++)r[u]=t[s[u]],n[r[u]]=s[u]}(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?(o[0]=e[m],o[1]=e[m+1],o[2]=e[m+2],a[0]=e[y],a[1]=e[y+1],a[2]=e[y+2],A[0]=e[_],A[1]=e[_+1],A[2]=e[_+2],Ae.decompressPosition(o,n,c),Ae.decompressPosition(a,n,u),Ae.decompressPosition(A,n,l)):(c[0]=e[m],c[1]=e[m+1],c[2]=e[m+2],u[0]=e[y],u[1]=e[y+1],u[2]=e[y+2],l[0]=e[_],l[1]=e[_+1],l[2]=e[_+2]),Ae.subVec3(l,u,h),Ae.subVec3(c,u,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,k,M,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!==(k=T[C]).face2&&(M=i[k.face1].normal,E=i[k.face2].normal,Ae.dotVec3(M,E)>I)||(F=n[k.index1],x=n[k.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 o=ie[0]*t[0]+ie[1]*t[1]+ie[2]*t[2];if(o<0)return!0}return!1};var ce=new Float32Array(3),ue=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 o=i.slice();if(o[s+3]=(i[s]+i[s+3])/2,e.left={aabb:o},Ae.containsAABB3(o,r))return void this._insertEntity(e.left,t,n+1)}if(!e.right){var a=i.slice();if(a[s]=(i[s]+i[s+3])/2,e.right={aabb:a},Ae.containsAABB3(a,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}(),le=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 o=t.attributes[s];i[n[o.nodeName]||o.nodeName]=o.nodeValue}for(var a=0;a<t.childNodes.length;a++){(s=e(t.childNodes[a],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],o=i[3];o=window.decodeURIComponent(o),s&&(o=window.atob(o));try{for(var a=new ArrayBuffer(o.length),A=new Uint8Array(a),c=0;c<o.length;c++)A[c]=o.charCodeAt(c);Fe.scheduleTask((function(){t(a)}))}catch(e){Fe.scheduleTask((function(){n(e)}))}}else{var u=new XMLHttpRequest;u.open("GET",e,!0),u.responseType="arraybuffer",u.onreadystatechange=function(){4===u.readyState&&(200===u.status?t(u.response):n("loadArrayBuffer error : "+u.response))},u.send(null)}},queryString:pe,isArray:function(e){return e&&!e.propertyIsEnumerable("length")&&"object"===k(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 le,be={sceneId:null,time:null,startTime:null,prevTime:null,deltaTime:null},we=[],Be=0,Ce=0;var ke,Me,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};ke=function(){xe()},Me=100,Ee=Date.now()+Me,function e(){var t=Date.now()-Ee;ke(),Ee+=Me,setTimeout(e,Math.max(0,Me-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,o=!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(o),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,o=e.on,a=!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 u in c)if(c.hasOwnProperty){n=c[u];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 l,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=(l=p.subs).length;h<d;h++)f.off(l[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)),a&&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)),o)for(m in o)if(o.hasOwnProperty(m)){if(y=o[m],ge.isFunction(y)?(_=y,b=null):(_=y.callback,b=y.scope),!_)continue;g.subs.push(n.on(m,_,b))}}return a&&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],o=r[2],a=r[3],A=r[4],c=r[5],u=r[6],l=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(a-i,l-A,p-h,y-v),e.planes[1].set(a+i,l+A,p+h,y+v),e.planes[2].set(a-s,l-c,p-d,y-g),e.planes[3].set(a+s,l+c,p+d,y+g),e.planes[4].set(a-o,l-u,p-f,y-m),e.planes[5].set(a+o,l+u,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],o=0;o<6;++o){var a=e.planes[o];if(a.normal[0]*s[a.testVertex[0]][0]+a.normal[1]*s[a.testVertex[1]][1]+a.normal[2]*s[a.testVertex[2]][2]+a.offset<0)return Qe.OUTSIDE;a.normal[0]*s[1-a.testVertex[0]][0]+a.normal[1]*s[1-a.testVertex[1]][1]+a.normal[2]*s[1-a.testVertex[2]][2]+a.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 o=i.entities,a=0,A=o.length;a<A;a++){var c=o[a];if(c.visible){var u=c.aabb;if(e._pickMode===n.PICK_MODE_INSIDE)Oe(e._marqueeFrustum,u)===Qe.INSIDE&&t.push(c.id);else Oe(e._marqueeFrustum,u)!==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,o=2/n,a=e.clientHeight/e.clientWidth,A=(this._canvasMarquee[0]-r)*s-1,c=(this._canvasMarquee[2]-r)*s-1,u=-(this._canvasMarquee[3]-i)*o+1,l=-(this._canvasMarquee[1]-i)*o+1,h=this.viewer.scene.camera.frustum.near*(17*a);Ae.frustumMat4(A,c,u*a,l*a,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,o,a,A,c,u,l=e.marqueePicker,h=l.viewer.scene.canvas.canvas,d=!1,f=!1,p=!1;return h.addEventListener("mousedown",(function(e){r.getActive()&&0===e.button&&(u=setTimeout((function(){var t=l.viewer.scene.input;t.keyDown[t.KEY_CTRL]||l.clear(),i=e.pageX,s=e.pageY,A=e.offsetX,l.setMarqueeCorner1([i,s]),d=!0,l.viewer.cameraControl.pointerEnabled=!1,l.setMarqueeVisible(!0),h.style.cursor="crosshair"}),400),f=!0)})),h.addEventListener("mouseup",(function(e){if(r.getActive()&&(d||p)&&0===e.button){clearTimeout(u),o=e.pageX,a=e.pageY;var t=Math.abs(o-i),n=Math.abs(a-s);d=!1,l.viewer.cameraControl.pointerEnabled=!0,p&&(p=!1),(t>3||n>3)&&l.pick()}})),document.addEventListener("mouseup",(function(e){r.getActive()&&0===e.button&&(clearTimeout(u),d&&(l.setMarqueeVisible(!1),d=!1,f=!1,p=!0,l.viewer.cameraControl.pointerEnabled=!0))}),!0),h.addEventListener("mousemove",(function(e){r.getActive()&&0===e.button&&f&&(clearTimeout(u),d&&(o=e.pageX,a=e.pageY,c=e.offsetX,l.setMarqueeVisible(!0),l.setMarqueeCorner2([o,a]),l.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,o=Math.min(s/300,1),a=r+(2-r)*o;t._circleRadius=a,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"),o<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),o=Ae.subVec3(s,i,[]);return Ae.normalizeVec3(o,[])}},{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 o,a=0,A=s-1;a<=A;)if((o=r[i=Math.floor(a+(A-a)/2)]-n)<0)a=i+1;else{if(!(o>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],o=t[r],a=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],o[0],a[0],A[0],i),c[1]=Ae.catmullRomInterpolate(s[1],o[1],a[1],A[1],i),c[2]=Ae.catmullRomInterpolate(s[2],o[2],a[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 o=Ae.lenVec3(Ae.subVec3(this._frames[i].eye,this._frames[i-1].eye,t));r[i]=o,n+=o}for(var a=1,A=this._frames.length;a<A;a++){var c=r[a]/n*e;this._frames[a].t=this._frames[a-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,o,a,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,o=e.up;else if(e.eye)i=e.eye;else if(e.look)s=e.look;else{var u=e;if((ge.isNumeric(u)||ge.isString(u))&&(a=u,!(u=this.scene.components[a])))return this.error("Component not found: "+ge.inQuotes(a)),void(t&&(n?t.call(n):t()));c||(r=u.aabb||this.scene.aabb)}var l=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=l||h;var d=Ae.subVec3(this._eye1,this._look1,Ze),f=Ae.normalizeVec3(d),p=l?Ae.getAABB3DiagPoint(r,l):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||o)&&(this._flyingEyeLookUp=!!i&&!!s&&!!o,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]),o&&(this._up2[0]=o[0],this._up2[1]=o[1],this._up2[2]=o[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,o=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 a=e;if((ge.isNumeric(a)||ge.isString(a))&&(n=a,!(a=this.scene.components[n])))return void this.error("Component not found: "+ge.inQuotes(n));t=a.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,u=A?Ae.getAABB3DiagPoint(t,A):Ae.getAABB3Diag(t);i=A||Ae.getAABB3Center(t,i),this._trail?Ae.subVec3(o.look,i,$e):Ae.subVec3(o.eye,o.look,$e),Ae.normalizeVec3($e),c=(void 0!==e.fit?e.fit:this._fit)?Math.abs(u/Math.tan((e.fitFOV||this._fitFOV)*Ae.DEGTORAD)):Ae.lenVec3(Ae.subVec3(o.eye,o.look,Ze)),Ae.mulVec3Scalar($e,c),o.eye=Ae.addVec3(i,$e,Ze),o.look=i,this.scene.camera.ortho.scale=1.1*u}else(r||i||s)&&(r&&(o.eye=r),i&&(o.look=i),s&&(o.up=s));e.projection&&(o.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,o,a,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=o,this.length=0,this.dataLength=i,this.numItems=0,this.itemSize=s,this.normalized=!!a,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}(),ot=function(){var e=[],t=[],n=[],r=[],i=[],s=0,o=new Uint16Array(3),a=new Uint16Array(3),A=new Uint16Array(3),c=Ae.vec3(),u=Ae.vec3(),l=Ae.vec3(),h=Ae.vec3(),d=Ae.vec3(),f=Ae.vec3(),p=Ae.vec3();return function(v,g,m,y){!function(i,s){var o,a,A,c,u,l,h={},d=Math.pow(10,4),f=0;for(u=0,l=i.length;u<l;u+=3)o=i[u],a=i[u+1],A=i[u+2],void 0===h[c=Math.round(o*d)+"_"+Math.round(a*d)+"_"+Math.round(A*d)]&&(h[c]=f/3,e[f++]=o,e[f++]=a,e[f++]=A),t[u/3]=h[c];for(u=0,l=s.length;u<l;u++)r[u]=t[s[u]],n[r[u]]=s[u]}(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?(o[0]=e[m],o[1]=e[m+1],o[2]=e[m+2],a[0]=e[y],a[1]=e[y+1],a[2]=e[y+2],A[0]=e[_],A[1]=e[_+1],A[2]=e[_+2],Ae.decompressPosition(o,n,c),Ae.decompressPosition(a,n,u),Ae.decompressPosition(A,n,l)):(c[0]=e[m],c[1]=e[m+1],c[2]=e[m+2],u[0]=e[y],u[1]=e[y+1],u[2]=e[y+2],l[0]=e[_],l[1]=e[_+1],l[2]=e[_+2]),Ae.subVec3(l,u,h),Ae.subVec3(c,u,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,k,M,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!==(k=T[C]).face2&&(M=i[k.face1].normal,E=i[k.face2].normal,Ae.dotVec3(M,E)>I)||(F=n[k.index1],x=n[k.index2],(!P&&F>65535||x>65535)&&(P=!0),U.push(F),U.push(x));return P?new Uint32Array(U):new Uint16Array(U)}}();var at,At,ct=(at=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,o=e[4]-r,a=e[5]-i,A=65535;return Ae.identityMat4(at),Ae.translationMat4v(e,at),Ae.identityMat4(At),Ae.scalingMat4v([s/A,o/A,a/A],At),Ae.mulMat4(at,At,t),t}),ut=function(){var e=Ae.mat4(),t=Ae.mat4();return function(n,r,i){var s,o=new Uint16Array(n.length),a=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)o[s+0]=Math.max(0,Math.min(65535,Math.floor((n[s+0]-r[0])*a[0]))),o[s+1]=Math.max(0,Math.min(65535,Math.floor((n[s+1]-r[1])*a[1]))),o[s+2]=Math.max(0,Math.min(65535,Math.floor((n[s+2]-r[2])*a[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:o,decodeMatrix:Ae.mulMat4(e,t,Ae.identityMat4())}}}();var lt=function(){var e=Ae.mat3(),t=Ae.mat3();return function(n,r,i){var s,o=new Uint16Array(n.length),a=new Float32Array([65535/(i[0]-r[0]),65535/(i[1]-r[1])]);for(s=0;s<n.length;s+=2)o[s+0]=Math.max(0,Math.min(65535,Math.floor((n[s+0]-r[0])*a[0]))),o[s+1]=Math.max(0,Math.min(65535,Math.floor((n[s+1]-r[1])*a[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:o,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 o=(1-Math.abs(s))*(i>=0?1:-1),a=(1-Math.abs(i))*(s>=0?1:-1);i=o,s=a}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:ut,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:lt,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),o=0;o<e.length;o+=3)n=t=ht(e,o,"floor","floor"),r=i=ft(e,o,dt(t)),(r=ft(e,o,dt(t=ht(e,o,"ceil","floor"))))>i&&(n=t,i=r),(r=ft(e,o,dt(t=ht(e,o,"floor","ceil"))))>i&&(n=t,i=r),(r=ft(e,o,dt(t=ht(e,o,"ceil","ceil"))))>i&&(n=t,i=r),s[o]=n[0],s[o+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],o=e[n+1];s=(2*s+1)/255,o=(2*o+1)/255;var a=1-Math.abs(s)-Math.abs(o);a<0&&(s=(1-Math.abs(o))*(s>=0?1:-1),o=(1-Math.abs(s))*(o>=0?1:-1));var A=Math.sqrt(s*s+o*o+a*a);t[r+0]=s/A,t[r+1]=o/A,t[r+2]=a/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,o=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":s.primitive=o.POINTS,s.primitiveName=i.primitive;break;case"lines":s.primitive=o.LINES,s.primitiveName=i.primitive;break;case"line-loop":s.primitive=o.LINE_LOOP,s.primitiveName=i.primitive;break;case"line-strip":s.primitive=o.LINE_STRIP,s.primitiveName=i.primitive;break;case"triangles":s.primitive=o.TRIANGLES,s.primitiveName=i.primitive;break;case"triangle-strip":s.primitive=o.TRIANGLE_STRIP,s.primitiveName=i.primitive;break;case"triangle-fan":s.primitive=o.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=o.TRIANGLES,s.primitiveName=i.primitive}if(i.positions)if(r._state.compressGeometry){var a=pt.getPositionsBounds(i.positions),A=pt.compressPositions(i.positions,a.min,a.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),u=pt.compressUVs(i.uv,c.min,c.max);s.uv=u.quantized,s.uvDecodeMatrix=u.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(o,o.ELEMENT_ARRAY_BUFFER,s.indices,s.indices.length,1,o.STATIC_DRAW),vt.indices+=s.indicesBuf.numItems),s.positions&&(s.positionsBuf=new st(o,o.ARRAY_BUFFER,s.positions,s.positions.length,3,o.STATIC_DRAW),vt.positions+=s.positionsBuf.numItems),s.normals){var l=s.compressGeometry;s.normalsBuf=new st(o,o.ARRAY_BUFFER,s.normals,s.normals.length,3,o.STATIC_DRAW,l),vt.normals+=s.normalsBuf.numItems}return s.colors&&(s.colorsBuf=new st(o,o.ARRAY_BUFFER,s.colors,s.colors.length,4,o.STATIC_DRAW),vt.colors+=s.colorsBuf.numItems),s.uv&&(s.uvBuf=new st(o,o.ARRAY_BUFFER,s.uv,s.uv.length,2,o.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=ot(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]),o=0;o<e.length;o+=3){var a=n(o,r[0]),A=n(o+1,r[1]),c=n(o+2,r[2]);Ae.addVec3(a,A,r[3]),Ae.addVec3(c,r[3],r[3]);var u=Ae.lenVec3(Ae.cross3Vec3(Ae.subVec3(A,a,r[1]),Ae.subVec3(c,a,r[2]),r[0]))/2;i+=u,Ae.mulVec3Scalar(r[3],u,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,o=r._state,a=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":o.primitive=a.POINTS,o.primitiveName=i.primitive;break;case"lines":o.primitive=a.LINES,o.primitiveName=i.primitive;break;case"line-loop":o.primitive=a.LINE_LOOP,o.primitiveName=i.primitive;break;case"line-strip":o.primitive=a.LINE_STRIP,o.primitiveName=i.primitive;break;case"triangles":o.primitive=a.TRIANGLES,o.primitiveName=i.primitive;break;case"triangle-strip":o.primitive=a.TRIANGLE_STRIP,o.primitiveName=i.primitive;break;case"triangle-fan":o.primitive=a.TRIANGLE_FAN,o.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'."),o.primitive=a.TRIANGLES,o.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),u=pt.compressPositions(i.positions,c.min,c.max);s=u.quantized,o.positionsDecodeMatrix=u.decodeMatrix,o.positionsBuf=new st(a,a.ARRAY_BUFFER,s,s.length,3,a.STATIC_DRAW),yt.positions+=o.positionsBuf.numItems,Ae.positions3ToAABB3(i.positions,r._aabb),Ae.positions3ToAABB3(s,_t,o.positionsDecodeMatrix),Ae.AABB3ToOBB3(_t,r._obb)}if(i.colors){var l=i.colors.constructor===Float32Array?i.colors:new Float32Array(i.colors);o.colorsBuf=new st(a,a.ARRAY_BUFFER,l,l.length,4,a.STATIC_DRAW),yt.colors+=o.colorsBuf.numItems}if(i.uv){var h=pt.getUVBounds(i.uv),d=pt.compressUVs(i.uv,h.min,h.max),f=d.quantized;o.uvDecodeMatrix=d.decodeMatrix,o.uvBuf=new st(a,a.ARRAY_BUFFER,f,f.length,2,a.STATIC_DRAW),yt.uvs+=o.uvBuf.numItems}if(i.normals){var p=pt.compressNormals(i.normals),v=o.compressGeometry;o.normalsBuf=new st(a,a.ARRAY_BUFFER,p,p.length,3,a.STATIC_DRAW,v),yt.normals+=o.normalsBuf.numItems}var g=i.indices.constructor===Uint32Array||i.indices.constructor===Uint16Array?i.indices:new Uint32Array(i.indices);o.indicesBuf=new st(a,a.ELEMENT_ARRAY_BUFFER,g,g.length,1,a.STATIC_DRAW),yt.indices+=o.indicesBuf.numItems;var m=ot(s,g,o.positionsDecodeMatrix,r._edgeThreshold);return r._edgeIndicesBuf=new st(a,a.ELEMENT_ARRAY_BUFFER,m,m.length,1,a.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,o=s.vertices,a=s.uvt,A=s.indices;i.processes--,n(ge.apply(t,{primitive:"triangles",positions:o,normals:null,uv:a,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),o=wt.edit.unwrap(s.i_verts,s.c_verts,3),a=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),u=0;u<s.i_verts.length;u++)c[u]=u;i.processes--,n(ge.apply(t,{primitive:"triangles",positions:o,normals:a.length>0?a:null,autoNormals:0===a.length,uv:A,indices:c}))}),(function(e){console.error("loadOBJGeometry: "+e),i.processes--,r()}))}))}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,o=i?i[1]:0,a=i?i[2]:0,A=-t+s,c=-n+o,u=-r+a,l=t+s,h=n+o,d=r+a;return ge.apply(e,{positions:[l,h,d,A,h,d,A,c,d,l,c,d,l,h,d,l,c,d,l,c,u,l,h,u,l,h,d,l,h,u,A,h,u,A,h,d,A,h,d,A,h,u,A,c,u,A,c,d,A,c,u,l,c,u,l,c,d,A,c,d,l,c,u,A,c,u,A,h,u,l,h,u],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 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,o=i?i[1]:0,a=i?i[2]:0,A=-t+s,c=-n+o,u=-r+a,l=t+s,h=n+o,d=r+a;return ge.apply(e,{primitive:"lines",positions:[A,c,u,A,c,d,A,h,u,A,h,d,l,c,u,l,c,d,l,h,u,l,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 Mt({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 o,a,A,c,u,l,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,k=1/i,M=(t-n)/s,E=[],F=[],x=[],U=[],I=(90-180*Math.atan(r/(n-t))/Math.PI)/90;for(o=0;o<=s;o++)for(u=t-o*M,l=w-o*B,a=0;a<=i;a++)A=Math.sin(a*C),c=Math.cos(a*C),F.push(u*A),F.push(I),F.push(u*c),x.push(a*k),x.push(1*o/s),E.push(u*A+y),E.push(l+_),E.push(u*c+b);for(o=0;o<s;o++)for(a=0;a<=i;a++)d=(h=o*(i+1)+a)+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),a=0;a<=i;a++)A=Math.sin(a*C),c=Math.cos(a*C),p=.5*Math.sin(a*C)+.5,v=.5*Math.cos(a*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(a=0;a<i;a++)m=f,h=f+1+a,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),a=0;a<=i;a++)A=Math.sin(a*C),c=Math.cos(a*C),p=.5*Math.sin(a*C)+.5,v=.5*Math.cos(a*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(a=0;a<i;a++)m=f,h=f+1+a,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=[],o=[],a=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),o.push(a++),o.push(a++),o.push(a++),o.push(a++);return ge.apply(e,{primitive:"lines",positions:s,indices:o})}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,o,a,A,c,u,l,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),k=new Float32Array(_*b*3),M=new Float32Array(_*b*2),E=0,F=0;for(s=0;s<b;s++){var x=s*B-g;for(o=0;o<_;o++)a=o*w-v,C[E]=a+d,C[E+1]=f,C[E+2]=-x+p,k[E+1]=1,M[F]=o/m,M[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(o=0;o<m;o++)A=o+_*s,c=o+_*(s+1),u=o+1+_*(s+1),l=o+1+_*s,U[E]=l,U[E+1]=c,U[E+2]=A,U[E+3]=l,U[E+4]=u,U[E+5]=c,E+=6;return ge.apply(e,{positions:C,normals:k,uv:M,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 o=e.heightSegments||18;o<0&&(console.error("negative heightSegments not allowed - will invert"),o*=-1),(o=Math.floor(t*o))<18&&(o=18);var a=e.widthSegments||18;a<0&&(console.error("negative widthSegments not allowed - will invert"),a*=-1),(a=Math.floor(t*a))<18&&(a=18);var A,c,u,l,h,d,f,p,v,g,m,y,_,b,w=[],B=[],C=[],k=[];for(A=0;A<=o;A++)for(u=A*Math.PI/o,l=Math.sin(u),h=Math.cos(u),c=0;c<=a;c++)d=2*c*Math.PI/a,f=Math.sin(d),p=Math.cos(d)*l,v=h,g=f*l,m=1-c/a,y=A/o,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<o;A++)for(c=0;c<a;c++)b=(_=A*(a+1)+c)+a+1,k.push(_+1),k.push(b+1),k.push(b),k.push(_+1),k.push(b),k.push(_);return ge.apply(e,{positions:w,normals:B,uv:C,indices:k})}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 o,a,A,c,u,l,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=[],k=[];for(d=0;d<=i;d++)for(h=0;h<=r;h++)o=h/r*s,a=.785398+d/i*Math.PI*2,y=t*Math.cos(o),_=t*Math.sin(o),A=(t+n*Math.cos(a))*Math.cos(o),c=(t+n*Math.cos(a))*Math.sin(o),u=n*Math.sin(a),w.push(A+y),w.push(c+_),w.push(u+b),C.push(1-h/r),C.push(d/i),l=Ae.normalizeVec3(Ae.subVec3([A,c,u],[y,_,b],[]),[]),B.push(l[0]),B.push(l[1]),B.push(l[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,k.push(f),k.push(p),k.push(v),k.push(v),k.push(g),k.push(f);return ge.apply(e,{positions:w,normals:B,uv:C,indices:k})}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 o=(s=(s=s.replace(/ +(?= )/g,"")).replace(/(^\s+|\s+$)/g,"")).split(" ");if("g"==o[0]&&(n.to=t.i_verts.length,null==t.groups[o[1]]&&(t.groups[o[1]]={from:t.i_verts.length,to:0}),n=t.groups[o[1]]),"v"==o[0]){var a=parseFloat(o[1]),A=parseFloat(o[2]),c=parseFloat(o[3]);t.c_verts.push(a,A,c)}if("vt"==o[0]){a=parseFloat(o[1]),A=1-parseFloat(o[2]);t.c_uvt.push(a,A)}if("vn"==o[0]){a=parseFloat(o[1]),A=parseFloat(o[2]),c=parseFloat(o[3]);t.c_norms.push(a,A,c)}if("f"==o[0]){var u=o[1].split("/"),l=o[2].split("/"),h=o[3].split("/"),d=parseInt(u[0])-1,f=parseInt(l[0])-1,p=parseInt(h[0])-1,v=parseInt(u[1])-1,g=parseInt(l[1])-1,m=parseInt(h[1])-1,y=parseInt(u[2])-1,_=parseInt(l[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==o.length){var k=o[4].split("/"),M=parseInt(k[0])-1,E=parseInt(k[1])-1,F=parseInt(k[2])-1;M<0&&(M=w+M+1),E<0&&(E=B+E+1),F<0&&(F=C+F+1),t.i_verts.push(d,p,M),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,o=wt.bin.rsl(e,r+2)/n.skinheight;t.c_uvt.push(s,o),r+=4}r=n.offset_tris;var a=[],A=[];t.i_verts=a,t.i_uvt=A;for(i=0;i<n.num_tris;i++)a.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 u={},l=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,u.name=wt.bin.rASCII0(e,r),r+=16,u.verts=[],u.norms=[];for(var g=0;g<n.num_vertices;g++)u.verts.push(e[r]*l+f,e[r+1]*h+p,e[r+2]*d+v),u.norms.push(c[3*e[r+3]],c[3*e[r+3]+1],c[3*e[r+3]+2]),r+=4;t.frames.push(u)}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],o=n.getElementsByTagName("library_images")[0],a=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)),o&&(r.images=wt.parse.fromCollada._libImages(o)),a&&(r.materials=wt.parse.fromCollada._libMaterials(a)),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(" "),o=s.length-(""==s[s.length-1]?1:0),a=new Array(o),A=0;A<o;A++)a[A]=parseFloat(s[A]);r[n[i].getAttribute("id")]=a}t.triangles=[];var c=e.getElementsByTagName("triangles");if(null==c)return t;for(i=0;i<c.length;i++){var u={},l=c[i];u.material=l.getAttribute("material");var h=l.getElementsByTagName("input"),d=[];for(A=0;A<h.length;A++){var f=h[A];a=[];d[parseInt(f.getAttribute("offset"))]=a;var p=f.getAttribute("semantic");u["s_"+p]="VERTEX"==p?e.getElementsByTagName("vertices")[0].getElementsByTagName("input")[0].getAttribute("source").substring(1):f.getAttribute("source").substring(1),u["i_"+p]=a,r[u["s_"+p]]}var v=l.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(u)}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 o=i[s].getElementsByTagName("surface")[0];o&&(r.surface=o.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),o=wt.bin.ril(e,i+2);16384==s&&(null==r.objects&&(r.objects=[]),r.objects.push(wt.parse.from3DS._edit_object(e,i,o))),i+=o}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),o=wt.bin.ril(e,i+2);45058==s&&(null==r.desc&&(r.desc=[]),r.desc.push(wt.parse.from3DS._keyf_objdes(e,i,o))),i+=o}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),o=wt.bin.ril(e,i+2);45072==s&&(r.hierarchy=wt.parse.from3DS._keyf_objhierarch(e,i,o)),45073==s&&(r.dummy_name=wt.bin.rASCII0(e,i+6)),i+=o}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),o=wt.bin.ril(e,i+2);16640==s&&(r.mesh=wt.parse.from3DS._obj_trimesh(e,i,o)),i+=o}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),o=wt.bin.ril(e,i+2);16656==s&&(r.vertices=wt.parse.from3DS._tri_vertexl(e,i,o)),16672==s&&(r.indices=wt.parse.from3DS._tri_facel1(e,i,o)),16704==s&&(r.uvt=wt.parse.from3DS._tri_mappingcoors(e,i,o)),16736==s&&(r.local=wt.parse.from3DS._tri_local(e,i,o)),i+=o}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 o=0;o<s;o++)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 o=0;o<s;o++)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 o=0;o<s;o++)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 o=40;return e.vertices&&(wt.bin.wil(s,16,o),wt.bin.wil(s,20,4*e.vertices.length),wt.parse.fromBIV._writeFloats(s,o,e.vertices),o+=4*e.vertices.length),e.uvt&&(wt.bin.wil(s,24,o),wt.bin.wil(s,28,4*e.uvt.length),wt.parse.fromBIV._writeFloats(s,o,e.uvt),o+=4*e.uvt.length),e.indices&&(wt.bin.wil(s,32,o),wt.bin.wil(s,36,4*e.indices.length),wt.parse.fromBIV._writeInts(s,o,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,o=t+1,a=0;a<o;a++)for(var A=0;A<s;A++){var c=A*(2/e)-1,u=a*(2/t)-1;i.verts.push(c,u,0),i.uvt.push(n*A/e,r*a/t),a<t&&A<e&&i.inds.push(a*s+A,a*s+A+1,(a+1)*s+A,a*s+A+1,(a+1)*s+A,(a+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 o=0;o<r;o++){var a=-Math.PI/2+s*Math.PI/t,A=2*o*Math.PI/e,c=Math.cos(a)*Math.cos(A),u=Math.sin(a),l=Math.cos(a)*Math.sin(A);n.verts.push(c,u,l),n.uvt.push(o/e,s/t),s<t&&o<e&&n.inds.push(r*s+o,r*s+o+1,r*(s+1)+o,r*s+o+1,r*(s+1)+o,r*(s+1)+o+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,o=n,a=Math.cos(i),A=Math.cos(s),c=Math.cos(o),u=Math.sin(i),l=Math.sin(s),h=Math.sin(o);return r[0]=A*c,r[1]=-A*h,r[2]=l,r[4]=a*h+u*l*c,r[5]=a*c-u*l*h,r[6]=-u*A,r[8]=u*h-a*l*c,r[9]=u*c+a*l*h,r[10]=a*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 o=0;o<r;o++)i[t[s]*r+o]=n[e[s]*r+o];return i},wt.utils={},wt.utils.getAABB=function(e){var t,n,r,i,s,o;i=s=o=-(t=n=r=999999999);for(var a=0;a<e.length;a+=3){var A=e[a+0],c=e[a+1],u=e[a+2];A<t&&(t=A),A>i&&(i=A),c<n&&(n=c),c>s&&(s=c),u<r&&(r=u),c>o&&(o=u)}return{min:{x:t,y:n,z:r},max:{x:i,y:s,z:o}}};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,o=[],a=[],A=e.text;ge.isNumeric(A)&&(A=""+A);for(var c,u,l,h,d,f,p,v,g,m=(A||"").split("\n"),y=0,_=0,b=.04,w=0;w<m.length;w++){c=0,l=(u=m[w]).length;for(var B=0;B<l;B++)if(h=Pt[u.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]?(o.push(c+g[0]*s*b+n),o.push(_+g[1]*s*b+r),o.push(0+i),-1===f?f=y:(-1===p||(f=p),p=y),y++,d?d=!1:(a.push(f),a.push(p))):d=1;c+=h.width*b*s}_-=35*b*s}return ge.apply(e,{primitive:"lines",positions:o,indices:a})}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],o=e.endPoint[0],a=e.endPoint[1],A=e.endPoint[2],c=Math.sqrt(Math.pow(o-r,2)+Math.pow(a-i,2)+Math.pow(A-s,2)),u=[(o-r)/c,(a-i)/c,(A-s)/c];if(e.pattern){var l=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=[u[0]*g,u[1]*g,u[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)>=l&&(f=0),d+=g,g=e.pattern[f]}e.extendToEnd&&(n.push(o,a,A),t.push(t.length-2),t.push(t.length-1))}else t.push(0),t.push(1),n.push(r,i,s,o,a,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,o=0,a=s.length;o<a;o++)r.addChild(s[o],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],o=e[1]-s,a=Float32Array.from([e[2]])[0],A=e[2]-a;t[0]=r,t[1]=s,t[2]=a,n[0]=i,n[1]=o,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,o=Math.round(i[1]/r)*r,a=Math.round(i[2]/r)*r;n[0]=s,n[1]=o,n[2]=a;var A=0!==n[0]||0!==n[1]||0!==n[2];if(A)for(var c=0,u=e.length;c<u;c+=3)t[c+0]=e[c+0]-s,t[c+1]=e[c+1]-o,t[c+2]=e[c+2]-a;return A}var qt=1e3,$t=1001,en=1002,tn=1003,nn=1004,rn=1004,sn=1005,on=1005,an=1006,An=1007,cn=1007,un=1008,ln=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,kn=1023,Mn=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,or=36492,ar=3e3,Ar=3001,cr=1e4,ur=10001,lr=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=[],o=[],a=[],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&&o.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,o=function(t){return s&&t.push("uniform ".concat(e," ").concat(n,";"))};t.push(o),r.push(o);var A={toString:function(){return s=!0,n}};return a.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,o=function(t){return s&&t.push("uniform ".concat(e," ").concat(n,"[").concat(i,"];"))};t.push(o),r.push(o);var A={toString:function(){return s=!0,n}};return a.push((function(e){return A.setInputValue=s&&e(n),null})),A},createUniformBlock:function(e,n,i){var s=!1,o=Object.keys(n),A=function(t){s&&(t.push("uniform ".concat(e," {")),o.forEach((function(e){return t.push(" ".concat(n[e]," ").concat(e,";"))})),t.push("};"))};t.push(A),r.push(A);var c={};return o.forEach((function(e){return c[e]={toString:function(){return s=!0,e}}})),a.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,o){var a=!1,A=o?o+" ":"";return t.push((function(t){return a&&t.push("".concat(A,"out ").concat(e," ").concat(i,";"))})),n.push((function(e){return a&&e.push("".concat(i," = ").concat(s(),";"))})),r.push((function(t){return a&&t.push("".concat(A,"in ").concat(e," ").concat(i,";"))})),{toString:function(){return a=!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,u,l){var h,d,f=l.getLogDepth,v=l.clipPos,g=l.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(l.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(l.testPerspectiveForGl_FragDepth?"".concat(_," == 0.0 ? gl_FragCoord.z : "):"","log2(").concat(f(w),") * ").concat(b," * 0.5;")):l.cleanerEdges&&y.push("gl_FragDepth = gl_FragCoord.z + length(vec2(dFdx(gl_FragCoord.z), dFdy(gl_FragCoord.z)));");var B,C,k=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=l.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,o=(n.mesh.layerIndex||0)*s,a=e<s&&n.mesh.renderFlags.sectionPlanesActivePerLayer[o+e];return r(t,a,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=l.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=l.getGammaFactor,T=c.createUniform("float","gammaFactor",(function(e){return e(I())}));l.appendFragmentOutputs(y,I&&function(e){return"".concat(k,"(").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(l.clippableTest(),") {"));var n=c.createVarying("highp vec3","vHighpWorldPosition",(function(){return"".concat(l.worldPositionAttribute,".xyz")}));if(e.push(" float dist = ".concat(F(n),";")),l.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(l.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(l.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(l.getPointSize?["gl_PointSize = ".concat(l.getPointSize(),";")]:[]),p(function(){var e=[];return n.forEach((function(t){return t(e)})),e}())),O=l.getVertexData?l.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","// "+u+" "+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=M(G(A.VERTEX_SHADER,H),2),W=j[0],z=j[1],X=M(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 $=a.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:o.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)}))},o=s("light",(function(){return t.lightMaps})),a=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:o&&function(e){return"".concat(o(e),".rgb")},getReflection:a&&function(e,t){return"".concat(a(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),o=e.getAttribLocation(t,s.name);n[s.name]=function(t){t.bindAtLocation(o),e.enableVertexAttribArray(o);var n=t.attributeDivisor;n&&e.vertexAttribDivisor(o,n)},n[s.name].attributeHash="".concat(o.toString().padStart(1+Math.floor(Math.log10(r)),"0"),":").concat(s.name)},s=0;s<r;++s)i(s);for(var o=e.getProgramParameter(t,e.ACTIVE_UNIFORM_BLOCKS),a=function(r){var i=e.getActiveUniformBlockName(t,r),s=e.getUniformBlockIndex(t,i),o=r;e.uniformBlockBinding(t,s,o);var a=e.createBuffer();n[i]=function(t){e.bindBuffer(e.UNIFORM_BUFFER,a),e.bufferData(e.UNIFORM_BUFFER,t,e.DYNAMIC_DRAW),e.bindBufferBase(e.UNIFORM_BUFFER,o,a)}},A=0;A<o;++A)a(A);for(var c=e.getProgramParameter(t,e.ACTIVE_UNIFORMS),u=0,l=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 o=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 a=u++;n[s]=function(t){var n=t.bind(a);return n&&e.uniform1i(o,a),n}}else n[s]=function(){if(1===i.size)switch(i.type){case e.BOOL:case e.INT:return function(t){return e.uniform1i(o,t)};case e.FLOAT:return function(t){return e.uniform1f(o,t)};case e.FLOAT_VEC2:return function(t){return e.uniform2fv(o,t)};case e.FLOAT_VEC3:return function(t){return e.uniform3fv(o,t)};case e.FLOAT_VEC4:return function(t){return e.uniform4fv(o,t)};case e.FLOAT_MAT3:return function(t){return e.uniformMatrix3fv(o,!1,t)};case e.FLOAT_MAT4:return function(t){return e.uniformMatrix4fv(o,!1,t)}}else if(i.size>1)switch(i.type){case e.FLOAT:return function(t){return e.uniform1fv(o,t)};case e.FLOAT_VEC2:return function(t){return e.uniform2fv(o,t)};case e.FLOAT_VEC3:return function(t){return e.uniform3fv(o,t)};case e.FLOAT_VEC4:return function(t){return e.uniform4fv(o,t)}}throw"Unhandled uniform ".concat(s)}()},h=0;h<c;++h)l(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,o="PhongMaterial"===s.type,a="MetallicMaterial"===s.type,A="SpecularMaterial"===s.type,c=n.attributes,u=mr(t,i._lightsState),l=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)))}))},o=s("float","EdgeBias",(function(e){return e.edgeBias})),a=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})),u=s("vec3","CenterColor",(function(e){return e.centerColor}));return i(r)&&function(e,t){var r="".concat(h,"(").concat(e,", ").concat(t,", ").concat(o,", ").concat(a,", ").concat(A,")");return"mix(".concat(c+n,", ").concat(u+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)})),o=r?function(e){return"(".concat(r," * ").concat(e,").st")}:function(e){return"".concat(e,".st")},a=function(e,t){return s(o(e))};return a.getTexCoordExpression=o,a}()},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})),k=m("metallic",(function(e){return e._metallicMap})),M=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=u.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":"",u.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&&(u.directionalLights.length>0||u.getIrradiance||u.getReflection);if(e.push("vec3 diffuseColor = ".concat(m&&(o||A)&&S||a&&D||"vec3(1.0)",";")),e.push("vec4 alphaModeCutoff = ".concat((o||a||A)&&G||"vec4(1.0, 0.0, 0.0, 0.0)",";")),e.push("float alpha = alphaModeCutoff[0];"),(o||a||A)&&C&&e.push("alpha *= ".concat(C(W),".r;")),z&&(e.push("diffuseColor *= ".concat(z,".rgb;")),e.push("alpha *= ".concat(z,".a;"))),a&&_&&(e.push("vec4 baseColorTexel = "+_(W)+";"),e.push("diffuseColor *= baseColorTexel.rgb;"),e.push("alpha *= baseColorTexel.a;")),(o||A)&&b&&(e.push("vec4 diffuseTexel = "+b(W)+";"),e.push("diffuseColor *= diffuseTexel.rgb;"),e.push("alpha *= diffuseTexel.a;")),e.push("vec3 emissiveColor = ".concat((o||a||A)&&Q||"vec3(0.0)",";")),(o||a||A)&&w&&e.push("emissiveColor = ".concat(w(W),".rgb;")),m){e.push("vec3 specular = ".concat((o||A)&&R||"vec3(1.0)",";")),e.push("float glossiness = ".concat(A&&O||"1.0",";")),e.push("float metallic = ".concat(a&&V||"1.0",";")),e.push("float roughness = ".concat((a||A)&&L||"1.0",";")),e.push("float shininess = ".concat(o&&H||"1.0",";")),e.push("float specularF0 = ".concat(a&&N||"1.0",";")),e.push("float occlusion = ".concat((o||a||A)&&B?"".concat(B(W),".r"):"1.0",";")),a&&k&&e.push("metallic *= ".concat(k(W),".r;")),a&&M&&e.push("roughness *= ".concat(M(W),".r;")),a&&E&&(e.push("vec4 metalRoughTexel = "+E(W)+";"),e.push("metallic *= metalRoughTexel.b;"),e.push("roughness *= metalRoughTexel.g;")),(o||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=(o||a||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;"),o&&(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);")),a&&(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);")),o||a||A){if(e.push("const float PI = 3.14159265359;"),e.push("vec3 reflDiff = vec3(0.0);"),e.push("vec3 reflSpec = vec3(0.0);"),u.getIrradiance&&e.push("reflDiff += ".concat(u.getIrradiance("normalize(".concat(Z,")")),";")),u.getReflection){var ne="reflect(-viewEyeDir, viewNormal)",re=o?"0.2 * PI * ".concat(u.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(u.getReflection(s,d)));e.push("reflSpec += ".concat(re,";"))}u.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;")),u.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=o?"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=o&&"".concat(u.getAmbientColor()," * diffuseColor");e.push("vec3 outgoingLight = emissiveColor + occlusion * (reflDiff * material_diffuseColor + reflSpec)"+(ie?" + "+ie:"")+";")}else e.push("vec3 ambientColor = ".concat(o&&P||"vec3(1.0)",";")),o&&y&&e.push("ambientColor *= ".concat(y(W),".rgb;")),e.push("ambientColor *= ".concat(u.getAmbientColor(),";")),e.push("vec3 outgoingLight = emissiveColor + ambientColor;");e.push("vec4 fragColor = ".concat(l," * 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),o=t.createUniform("vec4","colorize",(function(e,t){return e(t.meshColorize)})),a=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)})),u=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(o," * vec4((").concat(t.join(" + "),") * ").concat(A," + ").concat(c,", ").concat(a,");")})),l=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(l," = ").concat(t?t(u):u,";"))}}},Cr=function(e,t,n,r,i){var s=i&&mr(t,r._lightsState),o=t.createUniform("vec3","uColor",(function(e,t){return e(i?t.material.fillColor:t.material.edgeColor)})),a=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(o).concat(t?" * (".concat(t.join(" + "),")"):"",", ").concat(a,")")})),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,";"))}}},kr=Ae.vec4(),Mr=function(e,t){var n=t.createUniform("vec4","pickColor",(function(e,t){var n=t.meshPickID;kr[0]=255&n,kr[1]=n>>8&255,kr[2]=n>>16&255,kr[3]=n>>24&255,Ae.mulVec4Scalar(kr,1/255,kr),e(kr)})),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,o=w(r),a=function(e){var t=null,n=function(){if(!t){var n=gr(),r=n.programVariables.createAttribute,i=o._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")},a=function(e){var t={toString:function(){return t.needed=!0,e}};return t},A=s.normal&&a("worldNormal"),c=A&&a("viewNormal"),u=s.uv&&a("decodedUv"),l=e(n.programVariables,{attributes:{position:{world:"worldPosition",view:"viewPosition"},color:s.color,pickColor:s.pickColor,uv:u,normal:s.normal&&{world:A,view:c}},viewMatrix:"viewMatrix2"}),h=[l.programName,o.scene.canvas.canvas.id,o.scene._sectionPlanesState.getHash(),o._geometry._state.hash].concat(l.getHash()).join(";");if(!(h in Nr)){var d=Wr(o,s,{decodedUv:u,worldNormal:A,viewNormal:c},l,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=o.scene,c=function(e){return function(t,n){return Cr(o._state.hash,t,n,A,e)}};r._renderers={_drawRenderer:a((function(e,t){return"LambertMaterial"===s.type?Br(o._state.drawHash,e,t,s,A):wr(o._state.drawHash,e,t,s,A)})),_shadowRenderer:a((function(e){return xr(o._state.hash,e)})),_emphasisEdgesRenderer:a(c(!1)),_emphasisFillRenderer:a(c(!0)),_pickMeshRenderer:a((function(e){return Mr(o._state.hash,e)})),_pickTriangleRenderer:a((function(e,t){return Er(o._state.hash,e,t)})),_occlusionRenderer:a((function(e){return Fr(o._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 u=i.origin||i.rtcCenter;if(u&&(r._state.origin=Ae.vec3(u),r._state.originHash=u.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 l=r.scene.components[i.parentId];l?l.isNode?l.addChild(w(r)):r.error("Parent is not a Node: '"+i.parentId+"'"):r.error("Parent not found: '"+i.parentId+"'"),r._parentNode=l}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 o=0===s;i.sectionPlanesActivePerLayer[n]=o}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(),o=Ae.vec4(),a=Ae.vec3(),A=Ae.vec3(),c=Ae.vec3(),u=Ae.vec3(),l=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(),k=Ae.vec3(),M=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,o),S.localPos=o,S.position=o,v[0]=o[0],v[1]=o[1],v[2]=o[2],v[3]=1,Ae.transformVec4(U.worldMatrix,v,g),a[0]=g[0],a[1]=g[1],a[2]=g[2],S.canvasPos&&U.origin&&(a[0]+=U.origin[0],a[1]+=U.origin[1],a[2]+=U.origin[2]),S.worldPos=a,Ae.transformVec4(O.matrix,g,m),A[0]=m[0],A[1]=m[1],A[2]=m[2],S.viewPos=A,Ae.cartesianToBarycentric(o,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),u),pt.decompressNormal(J.subarray(q,q+2),l),pt.decompressNormal(J.subarray($,$+2),h)}else u[0]=J[L],u[1]=J[L+1],u[2]=J[L+2],l[0]=J[H],l[1]=J[H+1],l[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(u,c[0],y),Ae.mulVec3Scalar(l,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],k),Ae.mulVec2Scalar(f,c[1],M),E),Ae.mulVec2Scalar(p,c[2],F),x)}}}}}(),Wr=function(e,t,n,r,i){var s,o,a=i.programVariables,A=n.decodedUv,c=n.worldNormal,u=n.viewNormal,l=e.scene,h=l.canvas.gl,d=e._state.background,f=e._geometry._state,v=f.compressGeometry,g="points"===f.primitiveName,m=a.createUniform("float","pointSize"),y=a.createUniform("mat4","modelMatrix"),_=a.createUniform("mat4","modelNormalMatrix"),b=a.createUniform("vec3","offset"),w=a.createUniform("vec3","scale"),B=a.createUniform("mat4","positionsDecodeMatrix"),C=a.createUniform("mat3","uvDecodeMatrix"),k=a.createUniform("mat4","viewMatrix"),E=a.createUniform("mat4","viewNormalMatrix"),F=a.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&&a.createVertexDefinition("billboard",T),function(e){return s?"".concat(s,"(").concat(e,")"):e}),S=(o=T&&a.createFragmentDefinition("billboard",T),function(e){return o?"".concat(o,"(").concat(e,")"):e}),D=[];r.dontBillboardAnything?D.push("mat4 viewMatrix2 = ".concat(k,";")):(D.push("mat4 viewMatrix1 = ".concat(k,";")),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=a.createUniform("bool","clippable"),O=M(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:l.crossSections,discardPoints:g&&r.discardPoints,getGammaFactor:l.gammaOutput&&function(){return l.gammaFactor},getLogDepth:!r.dontGetLogDepth&&l.logarithmicDepthBufferEnabled&&function(e){return e},getPointSize:r.setupPointSize&&g&&function(){return m},getVertexData:function(){var e=u&&u.needed&&"vec3 ".concat(u," = 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(k," * worldPosition;")):(n.push("mat4 viewMatrix1 = ".concat(k,";")),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(a.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:l._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,o=n._state,a=n._geometry,A=a._state,c=e.viewParams,u=r.canActAsBackground&&d;e.lastProgramId!==V.id&&(e.lastProgramId=V.id,V.bind(),e.useProgram++,N=null,G=null,u&&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 l,f,p,v=!r.useShadowView&&n.origin;l=c.projMatrix,f=v?e.getRTCViewMatrix(o.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(k,f),p(E,c.viewNormalMatrix),p(F,l),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 M=a._getPickTrianglePositions();A.id!==G&&(g({positionsBuf:M,pickColorsBuf:a._getPickTriangleColors()}),G=A.id),h.drawArrays(A.primitive,0,M.numItems/3)}else if(r.drawEdges){var x=A.primitive===h.TRIANGLES?a._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++);u&&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 o=Jr(e,"WEBGL_compressed_texture_pvrtc");if(null===o)return null;if(35840===i)return o.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return o.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return o.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return o.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i){var a=Jr(e,"WEBGL_compressed_texture_etc1");return null!==a?a.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 u=Jr(e,"EXT_texture_compression_bptc");if(null===u)return null;if(36492===i)return 3001===r?u.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:u.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,o=t.wrapS,a=t.wrapT,A=t.wrapR,c=t.encoding,u=t.preloadColor,l=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=!!l,this.flipY=!!h,this.unpackAlignment=4,this.wrapS=o||1e3,this.wrapT=a||1e3,this.wrapR=A||1e3,this.encoding=c||3001,this.texture=n.createTexture(),u&&this.setPreloadColor(u),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 o=n.getParameter(n.UNPACK_ALIGNMENT);n.pixelStorei(n.UNPACK_ALIGNMENT,this.unpackAlignment);var a=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 u=Yr(n,this.wrapS);u&&n.texParameteri(this.target,n.TEXTURE_WRAP_S,u);var l=Yr(n,this.wrapT);l&&n.texParameteri(this.target,n.TEXTURE_WRAP_T,l);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,o),n.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,a)}},{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 o=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 a=Yr(i,this.wrapS);a&&i.texParameteri(this.target,i.TEXTURE_WRAP_S,a);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)}o?(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 u=Yr(i,this.format,this.encoding),l=Yr(i,this.type),h=ei(i,this.internalFormat,u,l,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!==u?i.compressedTexSubImage2D(i.TEXTURE_2D,d,0,0,p.width,p.height,u,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,u,l,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 o=n;return n===e.RED&&(r===e.FLOAT&&(o=e.R32F),r===e.HALF_FLOAT&&(o=e.R16F),r===e.UNSIGNED_BYTE&&(o=e.R8)),n===e.RG&&(r===e.FLOAT&&(o=e.RG32F),r===e.HALF_FLOAT&&(o=e.RG16F),r===e.UNSIGNED_BYTE&&(o=e.RG8)),n===e.RGBA&&(r===e.FLOAT&&(o=e.RGBA32F),r===e.HALF_FLOAT&&(o=e.RGBA16F),r===e.UNSIGNED_BYTE&&(o=3001===i&&!1===s?e.SRGB8_ALPHA8:e.RGBA8),r===e.UNSIGNED_SHORT_4_4_4_4&&(o=e.RGBA4),r===e.UNSIGNED_SHORT_5_5_5_1&&(o=e.RGB5_A1)),o!==e.R16F&&o!==e.R32F&&o!==e.RG16F&&o!==e.RG32F&&o!==e.RGBA16F&&o!==e.RGBA32F||Jr(e,"EXT_color_buffer_float"),o}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}(),oi=Ae.vec3(),ai=Ae.vec3();Ae.vec3();var Ai,ci=Ae.vec3([0,-1,0]),ui=Ae.vec4([0,0,0,1]),li=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,oi);var r=-Ae.dotVec3(n,oi);Ae.normalizeVec3(n),Ae.mulVec3Scalar(n,r,ai),Ae.vec3PairToQuaternion(ci,e,ui),this._node.quaternion=ui}}},{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}(),ki=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),o=null,a=0,A=s.length;a<A;a++)0!==a&&0===i(s[a],s[a-1])||(o=s[a]),n[s[a]]=o;for(var c=0,u=e.length;c<u;c+=3){var l=n[e[c]],h=n[e[c+1]],d=n[e[c+2]],f=l,p=h,v=d;if(l>h&&l>d?h>d?(f=l,p=h,v=d):(f=l,p=d,v=h):h>l&&h>d?l>d?(f=h,p=l,v=d):(f=h,p=d,v=l):d>l&&d>h&&(l>h?(f=d,p=l,v=h):(f=d,p=h,v=l)),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)},Mi=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&&!ki(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],o=3*t[r+2];Mi[0]=e[i],Mi[1]=e[i+1],Mi[2]=e[i+2],Ei[0]=e[s],Ei[1]=e[s+1],Ei[2]=e[s+2],Fi[0]=e[o],Fi[1]=e[o+1],Fi[2]=e[o+2],Ae.cross3Vec3(Mi,Ei,Mi),n+=Ae.dotVec3(Mi,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],o=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[o],Pi[1]=e[o+1],Pi[2]=e[o+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,o){var a=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=o,this._matrixDirty=!1,this._matrixUpdateScheduled=!1,this.id=n,this.obb=null,this._aabbLocal=null,this._aabbWorld=Ae.AABB3(),this._aabbWorldDirty=!1,this.layer=a,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,o=!r&&e.createVarying("vec4","vColor",(function(){return"vec4(".concat(s,".rgb * 0.5, ").concat(s,".a)")})),a=e.createOutput("vec4","outColor");return{programName:r?"Edges":"EdgesColor",getLogDepth:n&&function(e){return e},renderPassFlag:2,appendFragmentOutputs:function(e){return e.push("".concat(a," = ").concat(i||o,";"))}}},$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")})),o=e.createOutput("vec4","outColor");return{programName:"Silhouette",getLogDepth:n&&function(e){return e},renderPassFlag:1,appendFragmentOutputs:function(e,t,n,a){e.push("".concat(o," = ").concat(r?i:a("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]),os=0,as=1,As=2,cs=3,us=4,ls=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,o,a=!!(e&Gi),A=!!(e&Ki),c=!!(e&Zi),u=!!(e&Ji),l=!!(e&Yi),h=!!(e&Wi),d=!!(e&ji);s=!a||d||A||c&&!r.highlightMaterial.glowThrough||u&&!r.selectedMaterial.glowThrough?os:t?As:as,o=!a||d?os:u?us:c?cs:A?ls:os;var f=0;f=n&&a&&!d?u?ps:c?fs:A?vs:l?t?ds:hs:os:os;var p=a&&!d&&h?gs:os;i[0]=s,i[1]=o,i[2]=f,i[3]=p},_s=(Ai={},function(e,t,n,r,i,s,o,a){var A=[t,"points"===n||"lines"===n?n:"triangles",!!r,!!i,!!s,!!o].join(":");A in Ai||(Ai[A]={});var c,u,l,h=Ai[A],d=e.id;if(!(d in h)){var f=e.canvas.gl,p=function(r,i,s){var o=function(){var s=gr(),o=s.programVariables,A=a(o,i);return r(o,A.geometryParameters,(function(r,a){var c,u=e.pointsMaterial,l="points"===n&&!i,h=function(){return[e._sectionPlanesState.getHash()].concat(l?[u.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=M(s.buildProgram(f,t+" "+n+" "+r.programName,{appendFragmentOutputs:r.appendFragmentOutputs,cleanerEdges:r.cleanerEdges,clipPos:b,clippableTest:(c=o.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:l&&u.roundPoints,getGammaFactor:e.gammaOutput&&function(){return e.gammaFactor},getLogDepth:r.getLogDepth,getPointSize:function(){var e=[];if(l){var t=o.createUniform("float","pointSize",(function(e){return e(u.pointSize)}));if(u.perspectivePoints){var s=o.createUniform("float","nearPlaneHeight",(function(e,t){return e(t.legacyFrameCtx.nearPlaneHeight)})),a="".concat(Math.floor(u.minPerspectivePointSize),".0"),A="".concat(Math.floor(u.maxPerspectivePointSize),".0");e.push("clamp((".concat(s," * ").concat(t,") / gl_Position.w, ").concat(a,", ").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=o.createUniform("int","renderPass",(function(e,t){return e(t.renderPass)})),a=m?"(".concat(i," <= 0) || (").concat(t,".a < 1.0)"):"".concat(i," != ").concat(s),c=["if (".concat(a,") {")," gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"," return;","}"].concat(A.dontCullOnAlphaZero||r.dontCullOnAlphaZero?[]:["if (".concat(t,".a == 0.0) {")," gl_Position = vec4(0.0, 0.0, 0.0, 1.0);"," return;","}"]).concat(r.filterIntensityRange&&"points"===n&&u.filterIntensity?(e=o.createUniform("vec2","intensityRange",(function(e){ts[0]=u.minIntensity,ts[1]=u.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;","}"]):[]),l=[];A.ensureColorAndFlagAvailable&&A.ensureColorAndFlagAvailable(l),c.forEach((function(e){return l.push(e)})),A.appendVertexData(l);var h=v.attributes.position.view;return l.push("vec4 ".concat(h," = ").concat(v.viewMatrix," * ").concat(_,";")),l.push("vec4 ".concat(b," = ").concat(v.projMatrix," * ").concat(h,";")),l},projMatrix:v.projMatrix,sectionPlanesState:e._sectionPlanesState,testPerspectiveForGl_FragDepth:"points"!==n&&"lines"!==n||i,usePickClipPos:a,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,o=e.viewParams,a=ns;Ae.transformPoint3(s.matrix,r,a);var c=o.viewMatrix,u=o.projMatrix;e.snapPickOrigin&&(e.snapPickOrigin[0]=a[0],e.snapPickOrigin[1]=a[1],e.snapPickOrigin[2]=a[2]);var l={legacyFrameCtx:e,layerTextureSet:t.layerTextureSet,mesh:{layerIndex:t.layerIndex,origin:a,renderFlags:{sectionPlanesActivePerLayer:s.renderFlags.sectionPlanesActivePerLayer}},renderPass:n,view:{eye:o.eye,far:o.far,projMatrix:u,viewMatrix:Ae.compareVec3(a,ss)?c:Zt(c,a,is),viewNormalMatrix:o.viewNormalMatrix}};B.inputSetters.setUniforms(e,l),t.drawCalls[i?i.vertices?"drawVertices":"drawEdges":"drawSurface"](B.inputSetters.attributesHash,A.layerTypeInputs,{projMatrix:u,viewMatrix:Ae.compareVec3(a,ss)?c:Zt(c,a,is),viewNormalMatrix:o.viewNormalMatrix,eye:o.eye}),g&&e.drawElements++}}}))},A=s&&o();return{drawLayer:function(e,t,n){A||(A=o()),A.drawLayer(e,t,n)},revalidate:function(e){!A||!e&&A.getValid()||(A.destroy(),A=s&&o())}}},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 o=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})),a=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(a," = ").concat(o,";")):(e.push("vec4 fragColor = ".concat(r(o),";")),e.push("".concat(a," = ").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,o=e.logarithmicDepthBufferEnabled,a=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")})),u=i.createOutput("vec4","outPackedDepth"),l=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:o&&function(e){return e},renderPassFlag:3,incPointSizeBy10:!0,appendFragmentOutputs:function(e){e.push("float zNormalizedDepth = abs((".concat(A," + ").concat(c,".z) / (").concat(a," - ").concat(A,"));")),e.push("".concat(u," = ").concat(l,"(zNormalizedDepth);"))}}),!0);var i,s,o,a,A,c,u,l},_=function(t,n,r){return r((i=t,s=n,o=e.logarithmicDepthBufferEnabled,a=i.createVarying("vec4","vPickColor",(function(){return"".concat(s.attributes.pickColor," / 255.0")})),A=i.createOutput("vec4","outPickColor"),{programName:"PickMesh",getLogDepth:o&&function(e){return e},renderPassFlag:3,incPointSizeBy10:!0,dontCullOnAlphaZero:!0,appendFragmentOutputs:function(e){return e.push("".concat(A," = ").concat(a,";"))}}),!0);var i,s,o,a,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})),o=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(o," = 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)})),o=e.createVarying("vec3","vWorldPosition",(function(){return"".concat(t.attributes.position.world,".xyz")})),a=e.createVarying("vec4","vPickColor",(function(){return t.attributes.pickColor}),"flat"),A=e.createOutput("highp ivec4","outCoords",0),c=e.createOutput("highp ivec4","outNormal",1),u=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,dontCullOnAlphaZero:!n,appendFragmentOutputs:function(e){e.push("".concat(A," = ivec4(").concat(o," * ").concat(s,".xyz, ").concat(n?"-":"").concat(i,");")),n&&(e.push("".concat(c," = ").concat(r?"ivec4(1.0)":"ivec4(normalize(cross(dFdx(".concat(o,"), dFdy(").concat(o,"))) * float(").concat(Ae.MAX_INT,"), 1.0)"),";")),e.push("".concat(u," = uvec4(").concat(a,");")))}}}(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)},u=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,")")}}},l=function(t){var n=function(n,r,i){return function(e,t,n,r,i,s,o){var a=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,u=e.createVarying("vec3","vViewPosition",(function(){return"".concat(c.position.view,".xyz")})),l=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",!!o,s?"alphaCutoffYes":"alphaCutoffNo"]},getLogDepth:n.logarithmicDepthBufferEnabled&&function(e){return e},renderPassFlag:0,appendFragmentOutputs:function(e,n,s,o){e.push("vec3 viewNormal = normalize(cross(dFdx(".concat(u,"), dFdy(").concat(u,")));")),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,u),"), 0.0) * ").concat(n.getColor(),";"))})),e.push("vec4 color = vec4(".concat(r.getAmbientColor()," + reflectedColor, 1) * ").concat(o(h),";")),e.push("vec4 sampleColor = ".concat(a(l),";")),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&&u(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)}))},o=t.attributes,a=r.getIrradiance,A=s("uColorMap",!0,(function(e){return e.colorTexture})),c=s("uMetallicRoughMap",!1,(function(e){return e.metallicRoughnessTexture})),u=s("uEmissiveMap",!0,(function(e){return e.emissiveTexture})),l=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(o.position.view,".xyz")})),f=e.createVarying("vec3","vViewNormal",(function(){return o.normal.view})),p=e.createVarying("vec4","vColor",(function(){return o.color})),v=e.createVarying("vec2","vUV",(function(){return o.uv})),g=e.createVarying("vec2","vMetallicRoughness",(function(){return o.metallicRoughness})),m=e.createVarying("vec3","vWorldNormal",(function(){return"".concat(o.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(l(v),");")),e.push("vec3 viewEyeDir = normalize(".concat(d,");")),a&&e.push("reflDiff += ".concat(a("normalize(".concat(m,")")),";")),r.getReflection){var o="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)"),k="0.5 * clamp(".concat(C,", 0.0, ").concat("8.0",")"),M=r.getReflection(o,k),E="".concat(w,"(viewNormal, viewEyeDir, specularColor, specularRoughness)");e.push("reflSpec += ".concat(M," * ").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(u(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&&u(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(o?function(e,n,r){return r(m(e,n,c(e),t&&u(e)))}:function(n,r,i){return i((s=n,o=r,a=e.logarithmicDepthBufferEnabled,A=c(n),l=t&&u(n),h=o.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(),l?"sao":"nosao"]},cleanerEdges:!0,getLogDepth:a&&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(o.viewMatrix,d),"), 0.0) * ").concat(e.getColor())})));e.push("vec4 fragColor = vec4(".concat(i.join(" + "),", 1) * ").concat(r(f),";")),e.push("".concat(p," = ").concat(l?"vec4(fragColor.rgb * ".concat(l.getAmbient(n),", fragColor.a)"):"fragColor",";"))}}));var s,o,a,A,l,h,d,f,p})}},{"sao-":l(!1),"sao+":r&&l(!0)}),depthRenderer:g((function(t,n,r){return r((i=t,s=n,o=e.logarithmicDepthBufferEnabled,a=i.createVarying("highp vec2","vHighPrecisionZW",(function(){return"".concat(s.attributes.position.clip,".zw")})),A=i.createOutput("vec4","outColor"),{programName:"Depth",getLogDepth:o&&function(e){return e},renderPassFlag:0,appendFragmentOutputs:function(e){return e.push("".concat(A," = vec4(vec3((1.0 - ").concat(a,"[0] / ").concat(a,"[1]) / 2.0), 1.0);"))}}));var i,s,o,a,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,o=(i=t).createOutput("vec4","outColor"),a=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(o," = ").concat(a,"(").concat(n,".z);"))}}));var i,s,o,a})),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&&[as,As,gs,cs,us,ls];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?as: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,as)}},{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,ls)}},{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,us)}},{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,as)}},{key:"drawShadow",value:function(e,t){var n=this._renderers.shadowRenderer;n&&this.__drawLayer(e,t,n,as)}},{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}(),ks=function(e){for(var t=[],n=0;n<e;++n)t.push(n);return t},Ms={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(Ms,null,4));var e=0;Object.keys(Ms).forEach((function(t){t.startsWith("size")&&(e+=Ms[t])})),console.log("Total size ".concat(e," bytes (").concat((e/1e3/1e3).toFixed(2)," MB)")),console.log("Avg bytes / triangle: ".concat((e/Ms.totalPolygons).toFixed(2)));var t={};Object.keys(Ms).forEach((function(n){n.startsWith("size")&&(t[n]="".concat((Ms[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),Ms.numberOfLayers++,s._sortId="TriDTX-".concat(Ms.numberOfLayers);var o=e.scene.canvas.gl,a=function(e,t){var n=[],r=0,i=[],s=0,a=[],c=0,u=[],l=0;return{len:function(){return s},accumulateIndices:function(o,h){var d=o&&o.length>0&&function(){var t=r/3;r+=o.length,n.push(o);var a=o.length/3;return function(n){var r=s;s+=3*a,A.perObjectIndexBaseOffsets.push(r/3-t);for(var o=0;o<a;o+=8)i.push(n);Ms[e]+=a,Ms.totalPolygons+=a}}(),f=h&&h.length>0&&function(){var e=c/2;c+=h.length,a.push(h);var n=h.length/2;return function(r){var i=l;l+=2*n,A.perObjectEdgeIndexBaseOffsets.push(i/2-e);for(var s=0;s<n;s+=8)u.push(r);Ms[t]+=n,Ms.totalEdges+=n}}();return Ms.numberOfGeometries++,{numTriangles:o?o.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,o.UNSIGNED_SHORT,"sizeDataTexturePortionIds"):n},h=A(i,{texture:null}),d=r>0&&e(n,r,3,t,"sizeDataTextureIndices"),f=A(u),p=c>0&&e(a,c,2,t,"sizeDataTextureEdgeIndices");return{indices:function(e,t){s>0&&(e.perPrimIndices.setInputValue(d),e.perPrimIdPorIds.setInputValue(h),o.drawArrays(t,0,s))},edges:function(e,t){l>0&&(e.perPrimIndices.setInputValue(p),e.perPrimIdPorIds.setInputValue(f),o.drawArrays(t,0,l))}}}}},A=s._buffer={positionsCompressed:[],lenPositionsCompressed:0,geometry8Bits:a("totalPolygons8Bits","totalEdges8Bits"),geometry16Bits:a("totalPolygons16Bits","totalEdges16Bits"),geometry32Bits:a("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&&Ms.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()),o=0,a=0;e.buckets.forEach((function(e){o+=e.positionsCompressed.length/3,a+=e.indices.length/3})),(this._numVertices+o>4096*Fs||s+a>4096*Fs)&&Ms.cannotCreatePortion.becauseTextureSize++,n&&(n=this._numVertices+o<=4096*Fs&&s+a<=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,o,a,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),Ms[n]+=2*(i.length-e.length),i}return e};e.indices=c(e.indices,3,"overheadSizeAlignementIndices"),e.edgeIndices=c(e.edgeIndices,2,"overheadSizeAlignementEdgeIndices");var u=e.positionsCompressed;r.positionsCompressed.push(u);var l=u.length/3;n._numVertices+=l;var h=r.lenPositionsCompressed/3;r.lenPositionsCompressed+=u.length,n._bucketGeometries[A]={vertexBase:h,geometryData:(o=e.indices,a=e.edgeIndices,l<=256?r.geometry8Bits.accumulateIndices(o,a):l<=65536?r.geometry16Bits.accumulateIndices(o,a):r.geometry32Bits.accumulateIndices(o,a))}}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}),Ms.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,o=this._sortId,a=this._subPortionReadableGeometries,A=t.scene,c=A.canvas.gl,u=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),l=u.textureData,h=function(e,t,n,r,i,s,o){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,o)},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,k=!1,M=!1,E=0,F=function(){C=!0},x=A.on("rendering",(function(){k&&(C=!1,k=!1,l.reloadData()),E=0})),U=function(e,n){var r=i[e];if(r)for(var s=0,o=r.length;s<o;s++)n(r[s]);else t.error("portion not found: "+e)},I=function(e,t,n,r){var i=C||r;i?k=!0:++E>=10&&F(),l.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:o,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?k=!0:++E>=10&&F(),Ts.set(t),p.setData(Ts,e,0,!n)}))},setOffset:function(e,t){},getEachIndex:function(e,t){a&&U(e,(function(e){return a[e].indices.forEach((function(e){return t(e)}))}))},getEachVertex:function(e,n){a&&U(e,(function(e){for(var i=a[e],s=i.positionsCompressed,o=i.positionsDecodeMatrix,A=Is,c=0,u=s.length;c<u;c+=3)A[0]=s[c],A[1]=s[c+1],A[2]=s[c+2],A[3]=1,Ae.decompressPosition(A,o),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,o){n(s.worldMatrix,t.rotationMatrix),n(s.viewMatrix,o.viewMatrix),n(s.projMatrix,o.projMatrix);var a=Ae.transformPoint3(t.matrix,r,xs);n(s.uCameraEyeRtc,Ae.subVec3(o.eye,a,Us)),n(s.perObjPosDecode,v),n(s.perVertIdCoords,m),n(s.perObjColsFlags,u),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(){M||(A.off(x),M=!0)}}}}]),n}(),Qs=function(e,t,n,r,i,s,o,a){if(n>4&&n%4>0)throw"Unhandled data size "+n;var A=Math.ceil(n/4),c=n/A,u=M(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),l=u[0],h=u[1],d=u[2],f=i*A,v=Math.ceil(t/i);if(0===v)throw"texture height===0";var g=new l(f*v*c);Ms[o]+=g.byteLength,Ms.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:a&&{setData:function(t,s){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,a=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(g.set(t,s*n+o*c),a){e.bindTexture(e.TEXTURE_2D,m);var u=s%i*A+o,l=Math.floor(s/i),h=t.length/c;e.texSubImage2D(e.TEXTURE_2D,0,u,l,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"),o=n("mediump usampler2D","perVertIdCoords"),a=n("lowp usampler2D","perObjColsFlags"),A=n("highp sampler2D","perObjectMatrix"),c=e.createUniform("mat4","worldMatrix"),u=e.createUniform("mat4","viewMatrix"),l=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 a("ivec2(objectIndexCoords.x*8+".concat(e,", objectIndexCoords.y)"))};return{geometryParameters:{attributes:{clippable:"(flags2.r > 0u)",color:f,flags:ks(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:l,viewMatrix:u},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 a=function(e){return"vec3(".concat(o("ivec2(indexPositionH[".concat(e,"], indexPositionV[").concat(e,"])")),")")};e.push("vec3 positions[] = vec3[](".concat(a(0),", ").concat(a(1),", ").concat(a(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(u," * objectDecodeAndInstanceMatrix)) * vec4(normal,1)).xyz);")),e.push("if (solid != 1u) {"),e.push(" if (".concat("(".concat(l,"[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(u," * 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(o("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:o.map,perObjColsFlags:a.map,perObjectMatrix:A.map,worldMatrix:c,viewMatrix:u,projMatrix:l,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],o=t[1],a=t[2],A=t[3]-s,c=t[4]-o,u=t[5]-a,l=65525,h=l/A,d=l/c,f=l/u,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]-o)*d),i[v+2]=Math.floor(p(e[v+2]-a)*f);return Ae.identityMat4(Os),Ae.translationMat4v(t,Os),Ae.identityMat4(Vs),Ae.scalingMat4v([A/l,c/l,u/l],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,o=e[4]-r,a=e[5]-i,A=65525;return Ae.identityMat4(Os),Ae.translationMat4v(e,Os),Ae.identityMat4(Vs),Ae.scalingMat4v([s/A,o/A,a/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,o;s=(1-Math.abs(i))*(r>=0?1:-1),o=(1-Math.abs(r))*(i>=0?1:-1),r=s,i=o}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(),eo=Ae.vec3(),to=Ae.vec3(),no=Ae.vec3(),ro=Ae.vec3(),io=Ae.vec3(),so=new Uint8Array(4),oo=new Float32Array(96),ao=function(e){for(var t=[],n=0;n<e;++n)t.push(n);return t},Ao=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}},co=(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]}}),uo=function(e){m(n,bs);var t=_(n);function n(e,r,i,s){var o;x(this,n),o=t.call(this,e,r,i);var a=!!s.geometry;o._maxVerts=s.maxGeometryBatchSize;var A=a?s.geometry.positionsDecodeMatrix:s.positionsDecodeMatrix;o._positionsDecodeMatrix=A&&Ae.mat4(A),o._cfgUvDecodeMatrix=s.uvDecodeMatrix&&Ae.mat3(s.uvDecodeMatrix),o._instancedGeometry=s.geometry,o._textureSet=s.textureSet,o._modelAABB=!a&&Ae.collapseAABB3(),o._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,o=r.subarray(i);if(1===n&&0===s)o.set(t);else for(var a=0;a<t.length;++a)o[a]=s+t[a]*n;for(var A=t.length,c=e.times*t.length;A<c;){var u=Math.min(A,c-A);o.set(o.subarray(0,u),A),A+=u}i+=A})),r}}};return o._buffer=d({colors:c(),metallicRoughness:c(),pickColors:c()},a?{modelMatrixCol:[c(),c(),c()],modelNormalMatrixCol:[c(),c(),c()]}:{positions:c(),indices:c(),uv:c(),normals:c(),edgeIndices:c()}),o}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,o=this._portions.length,a=this.primitive,A=!!this._positionsDecodeMatrix,c=s.scene,u=t.meshMatrix,l=function(i,A,u,l,h){var d,f,p=n._portions.length>0&&n._portions[n._portions.length-1],v={indicesBaseIndex:p?p.indicesBaseIndex+p.numIndices:0,numIndices:u?u.length:0,portionBase:i,portionSize:A,retainedGeometry:c.readableGeometryEnabled&&"points"!==a&&"lines"!==a&&{indices:u,quantizedPositions:l,offset:c.entityOffsetsEnabled&&Ae.vec3(),matrix:h&&h.slice(),inverseMatrix:null,normalMatrix:null}};"points"!==a&&"lines"!==a&&r.metallicRoughness.append([null!==(d=t.metallic)&&void 0!==d?d:0,null!==(f=t.roughness)&&void 0!==f?f:255],A);return"lines"!==a&&r.pickColors.append(t.pickColor.slice(0,4),A),n._portions.push(v),s.numPortions++,n._meshes.push(e),o};if(i){if(r.modelMatrixCol.forEach((function(e,t){return e.append([u[t+0],u[t+4],u[t+8],u[t+12]])})),"points"!==a){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"!==a&&"lines"!==a&&i.normals){var f=Ae.inverseMat4(Ae.transposeMat4(u,Ae.mat4()));r.modelNormalMatrixCol.forEach((function(e,t){return e.append([f[t+0],f[t+4],f[t+8],f[t+12]])}))}return l(o,1,i.indices,i.positionsCompressed,u)}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;u?(Ae.transposeMat4(u,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 o,a,A,c,u,l=new Float32Array([0,0,0,0]),h=new Float32Array([0,0,0,0]);for(u=0;u<n;u+=3)l[0]=t[u],l[1]=t[u+1],l[2]=t[u+2],Ae.transformVec3(e,l,h),Ae.normalizeVec3(h,h),a=o=Ns(h,"floor","floor"),A=c=s(h,Gs(o)),(A=s(h,Gs(o=Ns(h,"ceil","floor"))))>c&&(a=o,c=A),(A=s(h,Gs(o=Ns(h,"floor","ceil"))))>c&&(a=o,c=A),(A=s(h,Gs(o=Ns(h,"ceil","ceil"))))>c&&(a=o,c=A),r[i+u+0]=a[0],r[i+u+1]=a[1],r[i+u+2]=0}(b,_,_.length,w,0),r.normals.append(w)}var B=t.colors,C=t.colorsCompressed,k=t.color;if(B)if("points"===a)r.colors.append(B,1,255);else{for(var M=[],E=0,F=B.length;E<F;E+=3)M.push(255*B[E]),M.push(255*B[E+1]),M.push(255*B[E+2]),M.push(255);r.colors.append(M)}else if(C)if("points"===a)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 k&&r.colors.append([k[0],k[1],k[2],"points"===a?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),l(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,o=this.primitive,a=this._textureSet,A=this._positionsDecodeMatrix,c=this._cfgUvDecodeMatrix,u=n.scene,l=u.canvas.gl,h=!!t,d=[],p=function(e,t,n,r){if(t.length>0){var i,s=t.constructor,o=M((i={},f(i,Uint8Array,[1,l.UNSIGNED_BYTE]),f(i,Int8Array,[1,l.BYTE]),f(i,Uint16Array,[2,l.UNSIGNED_SHORT]),f(i,Int16Array,[2,l.SHORT]),f(i,Uint32Array,[4,l.UNSIGNED_INT]),f(i,Int32Array,[4,l.INT]),f(i,Float32Array,[4,l.FLOAT]),i)[s],2),a=o[0],A=o[1],c=l.createBuffer();d.push((function(){return l.deleteBuffer(c)}));var u=function(){return l.bindBuffer(e,c)},h=function(t){u(),l.bufferData(e,t,r)};h(t);var p=t.BYTES_PER_ELEMENT,v=t.length/n;return{bindBuffer:u,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;u();var i=new s(r*n);return l.getBufferSubData(e,t*a*n,i,0,r*n),i},numItems:v,setData:h,setSubData:function(t,n){u(),l.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(l.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(),l.vertexAttribPointer(e,t,s.type,!!i,0,0)}}},g=function(e){var t=p(l.ELEMENT_ARRAY_BUFFER,e,1,l.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,l.DYNAMIC_DRAW,h),_=function(e,t){return v(e,4,t,h&&"points"!==o,!0)},b=h&&t.colorsCompressed?_(new Uint8Array(t.colorsCompressed),l.STATIC_DRAW):_(e.colors.compileBuffer(Uint8Array),l.DYNAMIC_DRAW),w=u.entityOffsetsEnabled&&v(new Float32Array(3*m),3,l.DYNAMIC_DRAW,h),B=v(e.metallicRoughness.compileBuffer(Uint8Array),2,l.STATIC_DRAW,h),C=v(e.pickColors.compileBuffer(Uint8Array),4,l.STATIC_DRAW,h),k=g(h?new Uint32Array(t.edgeIndices):e.edgeIndices.compileBuffer(Uint32Array)),E=h?"points"!==o&&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,l.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,l.STATIC_DRAW,!0)})),T=!h&&e.normals.compileBuffer(Int8Array),P=T&&v(T,3,l.STATIC_DRAW,!1,!0),S=I&&P&&e.modelNormalMatrixCol.map((function(e){return v(e.compileBuffer(Float32Array),4,l.STATIC_DRAW,!0)})),D=h?"points"!==o&&"lines"!==o&&t.uvCompressed&&{buf:v(t.uvCompressed,2,l.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,l.STATIC_DRAW),mat:c};var n=pt.getUVBounds(t),r=pt.compressUVs(t,n.min,n.max);return{buf:v(r.quantized,2,l.STATIC_DRAW),mat:Ae.mat3(r.decodeMatrix)}}();this._buffer=null,co.acquire(),d.push((function(){return co.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"!==o&&"lines"!==o,u,so);var a=n&zi?1:0,A=0;A|=so[0],A|=so[1]<<4,A|=so[2]<<8,A|=so[3]<<12,A|=a<<16,zs[0]=A;var c=s[e],l=c.portionBase,h=c.portionSize;if(i&&!t)O||(O=new Float32Array(m)),Ao(O.subarray(l,l+h),zs);else if(y){var d=co.getTypeArray(Float32Array,h);Ao(d,zs),y.setSubData(d,l)}},L="solid"===o;return{edgesColorOpaqueAllowed:function(){return!0},solid:L,sortId:("points"===o?"Points":"lines"===o?"Lines":"Triangles")+(h?"Instancing":"Batching")+"Layer"+("points"!==o&&"lines"!==o?(L?"-solid":"-surface")+"-autoNormals"+(h?"":(a&&a.colorTexture?"-colorTexture":"")+(a&&a.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=co.getTypeArray(Uint8Array,4*n.portionSize);Ao(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(u.entityOffsetsEnabled){var r=s[e];if(w){Ks.set(t);var i=co.getTypeArray(Float32Array,3*r.portionSize);Ao(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 o=Ys;i?o.set(i,0):o[0]=o[1]=o[2]=0,o[3]=1;var a=n.matrix;Ae.mulMat4v4(a,o,o);for(var c=r.quantizedPositions,u=Js,l=0,h=c.length;l<h;l+=3)u[0]=c[l],u[1]=c[l+1],u[2]=c[l+2],Ae.decompressPosition(u,A),r.matrix&&Ae.transformPoint3(r.matrix,u,u),u[3]=1,Ae.mulMat4v4(a,u,u),Ae.addVec3(o,u,u),t(u)}},readGeometryData:"points"!==o&&"lines"!==o&&function(e){var t=!h&&s[e],r=t?F.getData(t.indicesBaseIndex,t.numIndices).map((function(e){return e-t.portionBase})):F.getData(),o=n.matrix,a=Ae.vec4();a.set(i,0),a[3]=1,Ae.mulMat4v4(o,a,a);var c=I&&Ae.mat4();if(c){var u=I[0].getData(e,1),l=I[1].getData(e,1),d=I[2].getData(e,1);c.set([u[0],l[0],d[0],0,u[1],l[1],d[1],0,u[2],l[2],d[2],0,u[3],l[3],d[3],1])}var f=Ae.mat4();Ae.mulMat4(o,c?Ae.mulMat4(c,A,f):A,f),f[12]+=a[0],f[13]+=a[1],f[14]+=a[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,o,a){var c=s[e].retainedGeometry;if(c){c.matrix&&!c.inverseMatrix&&(c.inverseMatrix=Ae.inverseMat4(c.matrix,Ae.mat4())),a&&c.inverseMatrix&&!c.normalMatrix&&(c.normalMatrix=Ae.transposeMat4(c.inverseMatrix,Ae.mat4()));var u=c.quantizedPositions,l=c.indices,h=c.offset,d=qs,f=$s;d.set(i?Ae.subVec3(t,i,eo):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=to,v=no,g=ro,m=!1,y=0,_=io,b=0,w=l.length;b<w;b+=3){var B=3*l[b],C=3*l[b+1],k=3*l[b+2];if(p[0]=u[B],p[1]=u[B+1],p[2]=u[B+2],v[0]=u[C],v[1]=u[C+1],v[2]=u[C+2],g[0]=u[k],g[1]=u[k+1],g[2]=u[k+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 M=Math.abs(Ae.lenVec3(Ae.subVec3(_,t,[])));(!m||M>y)&&(y=M,o.set(_),a&&Ae.triangleNormal(p,v,g,a),m=!0)}}return m&&a&&(c.normalMatrix&&Ae.transformVec3(c.normalMatrix,a,a),Ae.transformVec3(n.worldNormalMatrix,a,a),Ae.normalizeVec3(a)),m}return!1},layerTextureSet:a,renderers:_s(u,h?"instancing":"batching",o,n.saoEnabled,n.pbrEnabled&&D&&a&&a.colorTexture&&P&&B&&a.metallicRoughnessTexture,n.colorTextureEnabled&&D&&a&&a.colorTexture,!!P,(function(e){return ho(e,h&&{hasModelNormalMat:!!S},u.entityOffsetsEnabled)})),drawCalls:(Q={},R=function(e){return function(t,r,i){var a=0;oo.set(n.rotationMatrix,0),oo.set(i.viewMatrix,a+=16),oo.set(i.projMatrix,a+=16),oo.set(A,a+=16),r.needNormal()&&(oo.set(n.worldNormalMatrix,a+=16),oo.set(i.viewNormalMatrix,a+=16)),r.matrices.setInputValue(oo),r.uvDecodeMatrix.setInputValue&&r.uvDecodeMatrix.setInputValue(D.mat),t in Q||(Q[t]=[null,null,null]);var c,u,f=Q[t],p=e?e.vertices?0:1:2;if(!f[p]){var v=l.createVertexArray();l.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?l.drawArraysInstanced(l.POINTS,0,U.numItems,s.length):l.drawArrays(l.POINTS,0,U.numItems)},u=function(e,t){t.bindIndicesBuffer();var n=t.indicesCount,r=t.indicesType;return function(){h?l.drawElementsInstanced(e,n,r,0,s.length):l.drawElements(e,n,r,0)}},"points"===o?c:"lines"===o?e&&e.vertices?c:u(l.LINES,F):e&&e.vertices?c:e&&k?u(l.LINES,k):u(l.TRIANGLES,F));l.bindVertexArray(null),d.push((function(){return l.deleteVertexArray(v)})),f[p]=function(){l.bindVertexArray(v),_(),l.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}(),lo=function(e){var t={toString:function(){return t.needed=!0,e}};return t},ho=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&&ao(3).map((function(e){return r("vec4","modelMatrixCol"+e)})),modelNormalMatrixCol:t&&t.hasModelNormalMat&&ao(3).map((function(e){return r("vec4","modelNormalMatrixCol"+e)}))},s=lo("aUv"),o=lo("viewNormal"),a=lo("worldNormal"),A=e.createUniform("mat3","uvDecodeMatrix"),c=function(){return o.needed||a.needed},u=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:ao(4).map((function(e){return{toString:function(){return"(int(".concat(i.flags,") >> ").concat(4*e," & 0xF)")}}})),metallicRoughness:i.metallicRoughness,normal:{view:o,world:a},pickColor:i.pickColor,position:{clip:"gl_Position",view:"viewPosition",world:"worldPosition"},uv:s},projMatrix:u.projMatrix,viewMatrix:u.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(u.worldMatrix," * (").concat(u.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(a," = (").concat(u.worldNormalMatrix," * modelNormal).xyz;")),o.needed&&t.push("vec3 ".concat(o," = normalize((").concat(u.viewNormalMatrix," * vec4(").concat(a,", 0.0)).xyz);"))}},layerTypeInputs:{attributes:i,matrices:u,uvDecodeMatrix:A,needNormal:c}}},fo=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}(),po=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}(),vo={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={}}},go=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}(),mo=new go,yo=function(){function e(t){x(this,e),this.manager=void 0!==t?t:mo,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}(),_o={},bo=function(e){m(n,yo);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=vo.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===_o[e]){_o[e]=[],_o[e].push({onLoad:t,onProgress:n,onError:r});var o=new Request(e,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),a=this.mimeType,A=this.responseType;fetch(o).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=_o[e],r=t.body.getReader(),i=t.headers.get("Content-Length"),s=i?parseInt(i):0,o=0!==s,a=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{a+=A.byteLength;for(var c=new ProgressEvent("progress",{lengthComputable:o,loaded:a,total:s}),u=0,l=n.length;u<l;u++){var h=n[u];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,a)}));case"json":return e.json();default:if(void 0===a)return e.text();var t=/charset="?([^;"\s]*)"?/i.exec(a),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){vo.add(e,t);var n=_o[e];delete _o[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=_o[e];if(void 0===n)throw i.manager.itemError(e),t;delete _o[e];for(var r=0,s=n.length;r<s;r++){var o=n[r];o.onError&&o.onError(t)}i.manager.itemError(e)})).finally((function(){i.manager.itemEnd(e)})),this.manager.itemStart(e)}else _o[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}(),wo=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,o=r.transfer;this.workersResolve[e]=i,this.workers[e].postMessage(s,o)}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}(),Bo=0,Co=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 wo,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 bo;n.setPath(this._transcoderPath),n.setWithCredentials(this.withCredentials);var r=n.loadAsync("basis_transcoder.js"),i=new bo;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=M(n,2),i=r[0],s=r[1],o=e.BasisWorker.toString(),a=["/* constants */","let _EngineFormat = "+JSON.stringify(e.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(e.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(e.BasisFormat),"/* basis_transcoder.js */",i,"/* worker */",o.substring(o.indexOf("{")+1,o.lastIndexOf("}"))].join("\n");t._workerSourceURL=URL.createObjectURL(new Blob([a])),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}))})),Bo>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),Bo++}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 o=r;n._init().then((function(){return n._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:o},e)})).then((function(e){var n=e.data,r=n.mipmaps,o=(n.width,n.height,n.format),a=n.type,A=n.error,c=n.dfdTransferFn,u=n.dfdFlags;if("error"===a)return s(A);t.setCompressedData({mipmaps:r,props:{format:o,minFilter:1===r.length?1006:1008,magFilter:1===r.length?1006:1008,encoding:2===c?3001:3e3,premultiplyAlpha:!!(1&u)}}),i()}))}))}},{key:"destroy",value:function(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),Bo--}}]),e}();Co.BasisFormat={ETC1S:0,UASTC_4x4:1},Co.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},Co.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},Co.BasisWorker=function(){var e,t,n,r=_EngineFormat,i=_TranscoderFormat,s=_BasisFormat;self.addEventListener("message",(function(o){var u,l=o.data;switch(l.type){case"init":e=l.config,u=l.transcoderBinary,t=new Promise((function(e){n={wasmBinary:u,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 o=new n.KTX2File(new Uint8Array(t));function u(){o.close(),o.delete()}if(!o.isValid())throw u(),new Error("KTX2TextureTranscoder: Invalid or unsupported .ktx2 file");var l=o.isUASTC()?s.UASTC_4x4:s.ETC1S,h=o.getWidth(),d=o.getHeight(),f=o.getLevels(),p=o.getHasAlpha(),v=o.getDFDTransferFunc(),g=o.getDFDFlags(),m=function(t,n,o,u){for(var l,h,d=t===s.ETC1S?a:A,f=0;f<d.length;f++){var p=d[f];if(e[p.if]&&(p.basisFormat.includes(t)&&!(u&&p.transcoderFormat.length<2)&&(!p.needsPowerOfTwo||c(n)&&c(o))))return{transcoderFormat:l=p.transcoderFormat[u?1:0],engineFormat:h=p.engineFormat[u?1:0]}}return console.warn("KTX2TextureTranscoder: No suitable compressed texture format found. Decoding to RGBA32."),l=i.RGBA32,h=r.RGBAFormat,{transcoderFormat:l,engineFormat:h}}(l,h,d,p),y=m.transcoderFormat,_=m.engineFormat;if(!h||!d||!f)throw u(),new Error("KTX2TextureTranscoder: Invalid texture");if(!o.startTranscoding())throw u(),new Error("KTX2TextureTranscoder: .startTranscoding failed");for(var b=[],w=0;w<f;w++){var B=o.getImageLevelInfo(w,0,0),C=B.origWidth,k=B.origHeight,M=new Uint8Array(o.getImageTranscodedSizeInBytes(w,0,0,y));if(!o.transcodeImage(M,w,0,0,y,0,-1,-1))throw u(),new Error("KTX2TextureTranscoder: .transcodeImage failed.");b.push({data:M,width:C,height:k})}return u(),{width:h,height:d,hasAlpha:p,mipmaps:b,format:_,dfdTransferFn:v,dfdFlags:g}}(l.buffers[0]),o=t.width,u=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:l.id,width:o,height:u,hasAlpha:h,mipmaps:d,format:f,dfdTransferFn:p,dfdFlags:v},g)}catch(e){console.error("[KTX2TextureTranscoder.BasisWorker]: ".concat(e)),self.postMessage({type:"error",id:l.id,error:e.message})}}))}}));var o=[{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}],a=o.sort((function(e,t){return e.priorityETC1S-t.priorityETC1S})),A=o.sort((function(e,t){return e.priorityUASTC-t.priorityUASTC}));function c(e){return e<=2||0==(e&e-1)&&0!==e}};var ko={};function Mo(e){var t=e.scene.id,n=ko[t];return n||(n=new Co({viewer:e}),ko[t]=n,e.scene.on("destroyed",(function(){delete ko[t],n.destroy()}))),n}
|
|
8
8
|
/**
|
|
9
9
|
* @author https://github.com/tmarti, with support from https://tribia.com/
|
|
10
10
|
* @license MIT
|
|
@@ -20,7 +20,7 @@ var e,t,n,r=A().mark(ob),i=A().mark(ab),s=A().mark(jC);function o(e){var t="func
|
|
|
20
20
|
/**
|
|
21
21
|
* @author https://github.com/tmarti, with support from https://tribia.com/
|
|
22
22
|
* @license MIT
|
|
23
|
-
**/var Io=null;function To(e,t){var n,r,i,s,o,a,A=3*e,c=3*t,u=Math.min(n=Io[A],r=Io[A+1],i=Io[A+2]),l=Math.min(s=Io[c],o=Io[c+1],a=Io[c+2]);if(u!==l)return u-l;var h=Math.max(n,r,i),d=Math.max(s,o,a);return h!==d?h-d:0}function Po(e,t){for(var n=new Int32Array(e.length/3),r=0,i=n.length;r<i;r++)n[r]=r;Io=new Int32Array(e.length);for(var s=0,o=e.length;s<o;s++)Io[s]=e[s]>>t;n.sort(To);for(var a=new Int32Array(e.length),A=0,c=n.length;A<c;A++)a[3*A+0]=e[3*n[A]+0],a[3*A+1]=e[3*n[A]+1],a[3*A+2]=e[3*n[A]+2];return a}var So=null;function Do(e,t){var n=So[2*e]-So[2*t];return 0!==n?n:So[2*e+1]-So[2*t+1]}function Qo(e){if(0===(e||[]).length)return[];for(var t=new Int32Array(e.length/2),n=0,r=t.length;n<r;n++)t[n]=n;for(var i=0,s=e.length;i<s;i+=2)if(e[i]>e[i+1]){var o=e[i];e[i]=e[i+1],e[i+1]=o}So=new Int32Array(e),t.sort(Do);for(var a=new Int32Array(e.length),A=0,c=t.length;A<c;A++)a[2*A+0]=e[2*t[A]+0],a[2*A+1]=e[2*t[A]+1];return a}function Ro(e,t){var n={},r={};e.forEach((function(e){for(var t=e.indices,i=e.edgeIndices,s=e.positionsCompressed,o=0,a=t.length;o<a;o+=3){var A=s[3*t[o]]+"_"+s[3*t[o]+1]+"_"+s[3*t[o]+2]+"/"+s[3*t[o+1]]+"_"+s[3*t[o+1]+1]+"_"+s[3*t[o+1]+2]+"/"+s[3*t[o+2]]+"_"+s[3*t[o+2]+1]+"_"+s[3*t[o+2]+2];n[A]=!0}e.edgeIndices.length/2;for(var c=0,u=i.length;c<u;c+=2){var l=s[3*i[c]]+"_"+s[3*i[c]+1]+"_"+s[3*i[c]+2]+"/"+s[3*i[c+1]]+"_"+s[3*i[c+1]+1]+"_"+s[3*i[c+1]+2]+"/";r[l]=!0}}));var i=t.indices;t.edgeIndices;for(var s=t.positionsCompressed,o=0,a=i.length;o<a;o+=3){var A=s[3*i[o]]+"_"+s[3*i[o]+1]+"_"+s[3*i[o]+2]+"/"+s[3*i[o+1]]+"_"+s[3*i[o+1]+1]+"_"+s[3*i[o+1]+2]+"/"+s[3*i[o+2]]+"_"+s[3*i[o+2]+1]+"_"+s[3*i[o+2]+2];if(!(A in n))throw console.log("Not found "+A),"Ohhhh!"}}var Oo=new Float32Array([0,0,0]),Vo=new Uint16Array([0,0,0]);Ae.OBB3();var Lo=function(){function e(t,n,r,i,s,o){x(this,e),this._isObject=n,this.scene=t.scene,this.model=t,this.isSceneModelEntity=!0,this.meshes=i,this._numPrimitives=0,this._capMaterial=null;for(var a=0,A=this.meshes.length;a<A;a++){var c=this.meshes[a];c.parent=this,c.entity=this,this._numPrimitives+=c.numPrimitives}this.id=r,this.originalSystemId=Ae.unglobalizeObjectId(t.id,r),this._flags=s,this._aabb=Ae.AABB3(),this._aabbDirty=!0,this._offset=Ae.vec3(),this._colorizeUpdated=!1,this._opacityUpdated=!1,this._lodCullable=!!o,this._culled=!1,this._culledVFC=!1,this._culledLOD=!1,this._isObject&&t.scene._registerObject(this)}return I(e,[{key:"_transformDirty",value:function(){this._aabbDirty=!0,this.model._transformDirty()}},{key:"_sceneModelDirty",value:function(){this._aabbDirty=!0;for(var e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._sceneModelDirty()}},{key:"aabb",get:function(){if(this._aabbDirty){Ae.collapseAABB3(this._aabb);for(var e=0,t=this.meshes.length;e<t;e++)Ae.expandAABB3(this._aabb,this.meshes[e].aabb);this._aabbDirty=!1}return this._aabb}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return!1}},{key:"isObject",get:function(){return this._isObject}},{key:"numPrimitives",get:function(){return this._numPrimitives}},{key:"numTriangles",get:function(){return this._numPrimitives}},{key:"visible",get:function(){return this._getFlag(Gi)},set:function(e){if(!!(this._flags&Gi)!==e){this._flags=e?this._flags|Gi:this._flags&~Gi;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setVisible(this._flags);this._isObject&&this.model.scene._objectVisibilityUpdated(this),this.model.glRedraw()}}},{key:"highlighted",get:function(){return this._getFlag(Zi)},set:function(e){if(!!(this._flags&Zi)!==e){this._flags=e?this._flags|Zi:this._flags&~Zi;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setHighlighted(this._flags);this._isObject&&this.model.scene._objectHighlightedUpdated(this),this.model.glRedraw()}}},{key:"xrayed",get:function(){return this._getFlag(Ki)},set:function(e){if(!!(this._flags&Ki)!==e){this._flags=e?this._flags|Ki:this._flags&~Ki;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setXRayed(this._flags);this._isObject&&this.model.scene._objectXRayedUpdated(this),this.model.glRedraw()}}},{key:"selected",get:function(){return this._getFlag(Ji)},set:function(e){if(!!(this._flags&Ji)!==e){this._flags=e?this._flags|Ji:this._flags&~Ji;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setSelected(this._flags);this._isObject&&this.model.scene._objectSelectedUpdated(this),this.model.glRedraw()}}},{key:"edges",get:function(){return this._getFlag(Yi)},set:function(e){if(!!(this._flags&Yi)!==e){this._flags=e?this._flags|Yi:this._flags&~Yi;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setEdges(this._flags);this.model.glRedraw()}}},{key:"culledVFC",get:function(){return!!this._culledVFC},set:function(e){this._culledVFC=e,this._setCulled()}},{key:"culledLOD",get:function(){return!!this._culledLOD},set:function(e){this._culledLOD=e,this._setCulled()}},{key:"culled",get:function(){return!!this._culled},set:function(e){this._culled=e,this._setCulled()}},{key:"_setCulled",value:function(){var e=!!this._culled||!(!this._culledLOD||!this._lodCullable)||!!this._culledVFC;if(!!(this._flags&ji)!==e){this._flags=e?this._flags|ji:this._flags&~ji;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setCulled(this._flags);this.model.glRedraw()}}},{key:"clippable",get:function(){return this._getFlag(zi)},set:function(e){if(!!(this._flags&zi)!==e){this._flags=e?this._flags|zi:this._flags&~zi;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setClippable(this._flags);this.model.glRedraw()}}},{key:"collidable",get:function(){return this._getFlag(Xi)},set:function(e){if(!!(this._flags&Xi)!==e){this._flags=e?this._flags|Xi:this._flags&~Xi;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setCollidable(this._flags)}}},{key:"pickable",get:function(){return this._getFlag(Wi)},set:function(e){if(!!(this._flags&Wi)!==e){this._flags=e?this._flags|Wi:this._flags&~Wi;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setPickable(this._flags)}}},{key:"colorize",get:function(){if(0===this.meshes.length)return null;var e=this.meshes[0]._colorize;return Oo[0]=e[0]/255,Oo[1]=e[1]/255,Oo[2]=e[2]/255,Oo},set:function(e){if(e){Vo[0]=Math.floor(255*e[0]),Vo[1]=Math.floor(255*e[1]),Vo[2]=Math.floor(255*e[2]);for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setColorize(Vo)}else for(var r=0,i=this.meshes.length;r<i;r++)this.meshes[r]._setColorize(null);if(this._isObject){var s=!!e;this.scene._objectColorizeUpdated(this,s),this._colorizeUpdated=s}this.model.glRedraw()}},{key:"opacity",get:function(){return this.meshes.length>0?this.meshes[0]._colorize[3]/255:1},set:function(e){if(0!==this.meshes.length){var t=null!=e,n=this.meshes[0]._colorize[3],r=255;if(t){if(e<0?e=0:e>1&&(e=1),n===(r=Math.floor(255*e)))return}else if(n===(r=255))return;for(var i=0,s=this.meshes.length;i<s;i++)this.meshes[i]._setOpacity(r,this._flags);this._isObject&&(this.scene._objectOpacityUpdated(this,t),this._opacityUpdated=t),this.model.glRedraw()}}},{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.meshes.length;t<n;t++)this.meshes[t]._setOffset(this._offset);this._aabbDirty=!0,this.model._aabbDirty=!0,this.scene._aabbDirty=!0,this.scene._objectOffsetUpdated(this,e),this.model.glRedraw()}},{key:"saoEnabled",get:function(){return this.model.saoEnabled}},{key:"capMaterial",get:function(){return this._capMaterial},set:function(e){this.scene.readableGeometryEnabled&&(this._capMaterial=e instanceof zr?e:null,this.scene._capMaterialUpdated(this.id,this.model.id))}},{key:"getEachVertex",value:function(e){for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t].getEachVertex(e)}},{key:"getEachIndex",value:function(e){for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t].getEachIndex(e)}},{key:"getGeometryData",value:function(){for(var e=0,t=[],n=[],r=0,i=this.meshes.length;r<i;r++){var s=this.meshes[r];if(s.layer.readGeometryData){for(var o=s.layer.readGeometryData(s.portionId),a=0,A=o.indices.length;a<A;a++)n.push(o.indices[a]+e);for(var c=0,u=o.positions.length;c<u;c++)t.push(o.positions[c]);e+=o.positions.length/3}}return{indices:n,positions:t}}},{key:"volume",get:function(){for(var e=0,t=0,n=this.meshes.length;t<n;t++){var r=this.meshes[t].volume;if(r<0)return-1;e+=r}return e}},{key:"surfaceArea",get:function(){for(var e=0,t=0,n=this.meshes.length;t<n;t++){var r=this.meshes[t].surfaceArea;r>=0&&(e+=r)}return e>0?e:-1}},{key:"_getFlag",value:function(e){return!!(this._flags&e)}},{key:"_finalize",value:function(){var e=this.model.scene;this._isObject&&(this.visible&&e._objectVisibilityUpdated(this),this.highlighted&&e._objectHighlightedUpdated(this),this.xrayed&&e._objectXRayedUpdated(this),this.selected&&e._objectSelectedUpdated(this));for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._finalize(this._flags)}},{key:"_finalize2",value:function(){for(var e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._finalize2()}},{key:"_destroy",value:function(){var e=this.model.scene;this._isObject&&(e._deregisterObject(this),this.visible&&e._deRegisterVisibleObject(this),this.xrayed&&e._deRegisterXRayedObject(this),this.selected&&e._deRegisterSelectedObject(this),this.highlighted&&e._deRegisterHighlightedObject(this),this._colorizeUpdated&&this.scene._deRegisterColorizedObject(this),this._opacityUpdated&&this.scene._deRegisterOpacityObject(this),!this._offset||0===this._offset[0]&&0===this._offset[1]&&0===this._offset[2]||this.scene._deRegisterOffsetObject(this));for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._destroy();e._aabbDirty=!0}}]),e}(),Ho=Ae.vec4(4),No=Ae.vec4(),Go=Ae.vec4(),jo=Ae.vec3([1,0,0]),Wo=Ae.vec3([0,1,0]),zo=Ae.vec3([0,0,1]);Ae.vec3(3),Ae.vec3(3);var Xo=Ae.identityMat4(),Ko=function(){function e(t){x(this,e),this._model=t.model,this.id=t.id,this._parentTransform=t.parent,this._childTransforms=[],this._meshes=[],this._scale=new Float32Array([1,1,1]),this._quaternion=Ae.identityQuaternion(new Float32Array(4)),this._rotation=new Float32Array(3),this._position=new Float32Array(3),this._localMatrix=Ae.identityMat4(new Float32Array(16)),this._worldMatrix=Ae.identityMat4(new Float32Array(16)),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,t.matrix?this.matrix=t.matrix:(this.scale=t.scale,this.position=t.position,t.quaternion||(this.rotation=t.rotation)),t.parent&&t.parent._addChildTransform(this)}return I(e,[{key:"_addChildTransform",value:function(e){this._childTransforms.push(e),e._parentTransform=this,e._transformDirty(),e._setSubtreeAABBsDirty(this)}},{key:"_addMesh",value:function(e){this._meshes.push(e),e.transform=this}},{key:"parentTransform",get:function(){return this._parentTransform}},{key:"meshes",get:function(){return this._meshes}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._model.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._model.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._model.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._model.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||Xo),Ae.decomposeMat4(this._localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._transformDirty(),this._model.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"rotate",value:function(e,t){return Ho[0]=e[0],Ho[1]=e[1],Ho[2]=e[2],Ho[3]=t*Ae.DEGTORAD,Ae.angleAxisToQuaternion(Ho,No),Ae.mulQuaternions(this.quaternion,No,Go),this.quaternion=Go,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"rotateOnWorldAxis",value:function(e,t){return Ho[0]=e[0],Ho[1]=e[1],Ho[2]=e[2],Ho[3]=t*Ae.DEGTORAD,Ae.angleAxisToQuaternion(Ho,No),Ae.mulQuaternions(No,this.quaternion,No),this}},{key:"rotateX",value:function(e){return this.rotate(jo,e)}},{key:"rotateY",value:function(e){return this.rotate(Wo,e)}},{key:"rotateZ",value:function(e){return this.rotate(zo,e)}},{key:"translate",value:function(e){return this._position[0]+=e[0],this._position[1]+=e[1],this._position[2]+=e[2],this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateX",value:function(e){return this._position[0]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateY",value:function(e){return this._position[1]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateZ",value:function(e){return this._position[2]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._transformDirty()}},{key:"_transformDirty",value:function(){this._worldMatrixDirty=!0;for(var e=0,t=this._childTransforms.length;e<t;e++){var n=this._childTransforms[e];if(n._transformDirty(),n._meshes&&n._meshes.length>0)for(var r=n._meshes,i=0,s=r.length;i<s;i++)r[i]._transformDirty()}if(this._meshes&&this._meshes.length>0)for(var o=this._meshes,a=0,A=o.length;a<A;a++)o[a]._transformDirty()}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentTransform)Ae.mulMat4(this._parentTransform.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._childTransforms)for(var t=0,n=e._childTransforms.length;t<n;t++)this._setSubtreeAABBsDirty(e._childTransforms[t])}}]),e}(),Zo=Ae.vec3(),Jo=Ae.OBB3(),Yo=Ae.vec4(),qo=Ae.vec3([1,1,1]),$o=Ae.vec3([0,0,0]);Ae.vec3([0,0,0]);var ea=Ae.identityQuaternion(),ta=Ae.identityMat4(),na=new Uint8Array([255,255,255]),ra=function(e){m(n,Ie);var t=_(n);function n(e){var r,i,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,n),(i=t.call(this,e,s)).renderOrder=s.renderOrder||0,i._dtxEnabled=i.scene.dtxEnabled&&!1!==s.dtxEnabled,i._enableVertexWelding=!1,i._enableIndexBucketing=!1,i._textureTranscoder=s.textureTranscoder||Mo(i.scene.viewer),i._maxGeometryBatchSize=null!==(r=s.maxGeometryBatchSize)&&void 0!==r?r:5e6,i._aabb=Ae.collapseAABB3(),i._aabbDirty=!0,i._quantizationRanges={},i._vboLayers={},i._dtxLayers={},i._meshList=[],i.layerList=[],i._layersToFinalize=[],i._entityList=[],i._entitiesToFinalize=[],i._geometries={},i._dtxBuckets={},i._textures={},i._textureSets={},i._transforms={},i._meshes={},i._unusedMeshes={},i._entities={},i.renderFlags=new Ur,i.numGeometries=0,i.numPortions=0,i.numVisibleLayerPortions=0,i.numTransparentLayerPortions=0,i.numXRayedLayerPortions=0,i.numHighlightedLayerPortions=0,i.numSelectedLayerPortions=0,i.numEdgesLayerPortions=0,i.numPickableLayerPortions=0,i.numClippableLayerPortions=0,i.numCulledLayerPortions=0,i.numEntities=0,i._numTriangles=0,i._numLines=0,i._numPoints=0,i._layersFinalized=!1,i._edgeThreshold=s.edgeThreshold||10,i._origin=Ae.vec3(s.origin||[0,0,0]),i._position=Ae.vec3(s.position||[0,0,0]),i._rotation=Ae.vec3(s.rotation||[0,0,0]),i._quaternion=Ae.vec4(s.quaternion||[0,0,0,1]),i._conjugateQuaternion=Ae.vec4(s.quaternion||[0,0,0,1]),s.rotation&&Ae.eulerToQuaternion(i._rotation,"XYZ",i._quaternion),i._scale=Ae.vec3(s.scale||[1,1,1]),i._worldRotationMatrix=Ae.mat4(),i._worldRotationMatrixConjugate=Ae.mat4(),i._matrix=Ae.mat4(),i._matrixDirty=!0,i._rebuildMatrices(),i._worldNormalMatrix=Ae.mat4(),Ae.inverseMat4(i._matrix,i._worldNormalMatrix),Ae.transposeMat4(i._worldNormalMatrix),(s.matrix||s.position||s.rotation||s.scale||s.quaternion)&&(i._viewMatrix=Ae.mat4(),i._viewNormalMatrix=Ae.mat4(),i._viewMatrixDirty=!0,i._matrixNonIdentity=!0),i._opacity=1,i._colorize=[1,1,1],i._saoEnabled=!1!==s.saoEnabled,i._pbrEnabled=!1!==s.pbrEnabled,i._colorTextureEnabled=!1!==s.colorTextureEnabled,i._isModel=s.isModel,i._isModel&&i.scene._registerModel(w(i)),i._onCameraViewMatrix=i.scene.camera.on("matrix",(function(){i._viewMatrixDirty=!0})),i._meshesWithDirtyMatrices=[],i._numMeshesWithDirtyMatrices=0,i._onTick=i.scene.on("tick",(function(){for(;i._numMeshesWithDirtyMatrices>0;)i._meshesWithDirtyMatrices[--i._numMeshesWithDirtyMatrices]._updateMatrix()}));var o=function(e,t){return i._textures[e]=new po({id:e,texture:new $r({gl:i.scene.canvas.gl,preloadColor:t})})};return i._textureSets.defaultTextureSet=new fo({id:"defaultTextureSet",colorTexture:o("defaultColorTexture",[1,1,1,1]),metallicRoughnessTexture:o("defaultMetalRoughTexture",[0,1,1,1]),normalsTexture:o("defaultNormalsTexture",[0,0,0,0]),emissiveTexture:o("defaultEmissiveTexture",[0,0,0,1]),occlusionTexture:o("defaultOcclusionTexture",[1,1,1,1])}),i.visible=s.visible,i.culled=s.culled,i.pickable=s.pickable,i.clippable=s.clippable,i.collidable=s.collidable,i.castsShadow=s.castsShadow,i.receivesShadow=s.receivesShadow,i.xrayed=s.xrayed,i.highlighted=s.highlighted,i.selected=s.selected,i.edges=s.edges,i.colorize=s.colorize,i.opacity=s.opacity,i.backfaces=s.backfaces,i}return I(n,[{key:"_meshMatrixDirty",value:function(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}},{key:"isPerformanceModel",get:function(){return!0}},{key:"transforms",get:function(){return this._transforms}},{key:"textures",get:function(){return this._textures}},{key:"textureSets",get:function(){return this._textureSets}},{key:"meshes",get:function(){return this._meshes}},{key:"objects",get:function(){return this._entities}},{key:"origin",get:function(){return this._origin}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),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._setWorldMatrixDirty(),this._sceneModelDirty(),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._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){}},{key:"matrix",get:function(){return this._rebuildMatrices(),this._matrix},set:function(e){this._matrix.set(e||ta),Ae.decomposeMat4(this._matrix,this._position,this._quaternion,this._scale),Ae.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"rotationMatrix",get:function(){return this._rebuildMatrices(),this._worldRotationMatrix}},{key:"_rebuildMatrices",value:function(){this._matrixDirty&&(Ae.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),Ae.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),Ae.quaternionToRotationMat4(this._conjugateQuaternion,this._worldRotationMatrixConjugate),Ae.scaleMat4v(this._scale,this._worldRotationMatrix),Ae.scaleMat4v(this._scale,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),Ae.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._viewMatrixDirty=!0)}},{key:"rotationMatrixConjugate",get:function(){return this._rebuildMatrices(),this._worldRotationMatrixConjugate}},{key:"_setWorldMatrixDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0}},{key:"_transformDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}},{key:"_sceneModelDirty",value:function(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(var e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._sceneModelDirty()}},{key:"worldMatrix",get:function(){return this.matrix}},{key:"worldNormalMatrix",get:function(){return this._worldNormalMatrix}},{key:"_rebuildViewMatrices",value:function(){this._rebuildMatrices(),this._viewMatrixDirty&&(Ae.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),Ae.inverseMat4(this._viewMatrix,this._viewNormalMatrix),Ae.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1)}},{key:"viewMatrix",get:function(){return this._viewMatrix?(this._rebuildViewMatrices(),this._viewMatrix):this.scene.camera.viewMatrix}},{key:"viewNormalMatrix",get:function(){return this._viewNormalMatrix?(this._rebuildViewMatrices(),this._viewNormalMatrix):this.scene.camera.viewNormalMatrix}},{key:"backfaces",get:function(){return this._backfaces},set:function(e){e=!!e,this._backfaces=e,this.glRedraw()}},{key:"entityList",get:function(){return this._entityList}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return!1}},{key:"aabb",get:function(){if(this._aabbDirty){Ae.collapseAABB3(this._aabb);for(var e=0,t=this._entityList.length;e<t;e++)Ae.expandAABB3(this._aabb,this._entityList[e].aabb);this._aabbDirty=!1}return this._aabb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"numLines",get:function(){return this._numLines}},{key:"numPoints",get:function(){return this._numPoints}},{key:"visible",get:function(){return this.numVisibleLayerPortions>0},set:function(e){e=!1!==e,this._visible=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].visible=e;this.glRedraw()}},{key:"xrayed",get:function(){return this.numXRayedLayerPortions>0},set:function(e){e=!!e,this._xrayed=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].xrayed=e;this.glRedraw()}},{key:"highlighted",get:function(){return this.numHighlightedLayerPortions>0},set:function(e){e=!!e,this._highlighted=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].highlighted=e;this.glRedraw()}},{key:"selected",get:function(){return this.numSelectedLayerPortions>0},set:function(e){e=!!e,this._selected=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].selected=e;this.glRedraw()}},{key:"edges",get:function(){return this.numEdgesLayerPortions>0},set:function(e){e=!!e,this._edges=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].edges=e;this.glRedraw()}},{key:"culled",get:function(){return this._culled},set:function(e){e=!!e,this._culled=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].culled=e;this.glRedraw()}},{key:"clippable",get:function(){return this._clippable},set:function(e){e=!1!==e,this._clippable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].clippable=e;this.glRedraw()}},{key:"collidable",get:function(){return this._collidable},set:function(e){e=!1!==e,this._collidable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].collidable=e}},{key:"pickable",get:function(){return this.numPickableLayerPortions>0},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].pickable=e}},{key:"colorize",get:function(){return this._colorize},set:function(e){this._colorize=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].colorize=e}},{key:"opacity",get:function(){return this._opacity},set:function(e){this._opacity=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].opacity=e}},{key:"castsShadow",get:function(){return this._castsShadow},set:function(e){(e=!1!==e)!==this._castsShadow&&(this._castsShadow=e,this.glRedraw())}},{key:"receivesShadow",get:function(){return this._receivesShadow},set:function(e){(e=!1!==e)!==this._receivesShadow&&(this._receivesShadow=e,this.glRedraw())}},{key:"saoEnabled",get:function(){return this._saoEnabled}},{key:"pbrEnabled",get:function(){return this._pbrEnabled}},{key:"colorTextureEnabled",get:function(){return this._colorTextureEnabled}},{key:"isDrawable",get:function(){return!0}},{key:"isStateSortable",get:function(){return!1}},{key:"xrayMaterial",get:function(){return this.scene.xrayMaterial}},{key:"highlightMaterial",get:function(){return this.scene.highlightMaterial}},{key:"selectedMaterial",get:function(){return this.scene.selectedMaterial}},{key:"edgeMaterial",get:function(){return this.scene.edgeMaterial}},{key:"getPickViewMatrix",value:function(e){return this._viewMatrix?this._viewMatrix:e}},{key:"createQuantizationRange",value:function(e){void 0!==e.id&&null!==e.id?e.aabb?this.error("[createQuantizationRange] Config missing: aabb"):this._quantizationRanges[e.id]?this.error("[createQuantizationRange] QuantizationRange already created: "+e.id):this._quantizationRanges[e.id]={id:e.id,aabb:e.aabb,matrix:Hs(e.aabb,Ae.mat4())}:this.error("[createQuantizationRange] Config missing: id")}},{key:"_createDefaultIndices",value:function(e){for(var t=[],n=0;n<e;n++)t.push(n);return t}},{key:"createGeometry",value:function(e){if(void 0!==e.id&&null!==e.id)if(this._geometries[e.id])this.error("[createGeometry] Geometry already created: "+e.id);else if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"===e.primitive||"lines"===e.primitive||"triangles"===e.primitive||"solid"===e.primitive||"surface"===e.primitive){if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("[createGeometry] Param expected: `positions`, `positionsCompressed' or 'buckets"),null;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("[createGeometry] Param expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.positionsDecodeMatrix&&e.positionsDecodeBoundary)return this.error("[createGeometry] Only one of these params expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("[createGeometry] Param expected: `uvDecodeMatrix` (required for `uvCompressed')"),null;if(e.buckets||e.indices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.indices=this._createDefaultIndices((e.positions||e.positionsCompressed).length/3)),!e.buckets&&!e.indices&&"points"!==e.primitive)return this.error("[createGeometry] Param expected: indices (required for '".concat(e.primitive,"' primitive type)")),null;if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Hs(e.positionsDecodeBoundary,Ae.mat4())),e.positions){var t=Ae.collapseAABB3();e.positionsDecodeMatrix=Ae.mat4(),Ae.expandAABB3Points3(t,e.positions),e.positionsCompressed=Ls(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){var n=Ae.collapseAABB3();e.positionsDecodeMatrix=new Float64Array(e.positionsDecodeMatrix),e.positionsCompressed=new Uint16Array(e.positionsCompressed),Ae.expandAABB3Points3(n,e.positionsCompressed),pt.decompressAABB(n,e.positionsDecodeMatrix),e.aabb=n}else if(e.buckets){var r=Ae.collapseAABB3();this._dtxBuckets[e.id]=e.buckets;for(var i=0,s=e.buckets.length;i<s;i++){var o=e.buckets[i];o.positions?Ae.expandAABB3Points3(r,o.positions):o.positionsCompressed&&Ae.expandAABB3Points3(r,o.positionsCompressed)}e.positionsDecodeMatrix&&pt.decompressAABB(r,e.positionsDecodeMatrix),e.aabb=r}if(e.colorsCompressed&&e.colorsCompressed.length>0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var a=e.colors,A=new Uint8Array(a.length),c=0,u=a.length;c<u;c++)A[c]=255*a[c];e.colorsCompressed=A}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=ot(e.positions,e.indices,null,5):e.edgeIndices=ot(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.uv){var l=pt.getUVBounds(e.uv),h=pt.compressUVs(e.uv,l.min,l.max);e.uvCompressed=h.quantized,e.uvDecodeMatrix=h.decodeMatrix}else e.uvCompressed&&(e.uvCompressed=new Uint16Array(e.uvCompressed),e.uvDecodeMatrix=new Float64Array(e.uvDecodeMatrix));e.normals&&(e.normals=null),this._geometries[e.id]=e,this._numTriangles+=e.indices?Math.round(e.indices.length/3):0,this.numGeometries++}else this.error("[createGeometry] Unsupported value for 'primitive': '".concat(e.primitive,"' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'."));else this.error("[createGeometry] Config missing: id")}},{key:"createTexture",value:function(e){var t=this,n=e.id;if(null!=n)if(this._textures[n])this.error("[createTexture] Texture already created: "+n);else{if(!e.src&&!e.image&&!e.buffers)return this.error("[createTexture] Param expected: `src`, `image' or 'buffers'"),null;var r=e.minFilter||1008;1006!==r&&1007!==r&&1008!==r&&1005!==r&&1004!==r&&(this.error("[createTexture] Unsupported value for 'minFilter' - \n supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, \n NearestMipMapLinearFilter and LinearMipmapLinearFilter. Defaulting to LinearMipmapLinearFilter."),r=1008);var i=e.magFilter||1006;1006!==i&&1003!==i&&(this.error("[createTexture] Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),i=1006);var s=e.wrapS||1e3;1001!==s&&1002!==s&&1e3!==s&&(this.error("[createTexture] Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),s=1e3);var o=e.wrapT||1e3;1001!==o&&1002!==o&&1e3!==o&&(this.error("[createTexture] Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),o=1e3);var a=e.wrapR||1e3;1001!==a&&1002!==a&&1e3!==a&&(this.error("[createTexture] Unsupported value for 'wrapR' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),a=1e3);var A=e.encoding||3e3;3e3!==A&&3001!==A&&(this.error("[createTexture] Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),A=3e3);var c=new $r({gl:this.scene.canvas.gl,minFilter:r,magFilter:i,wrapS:s,wrapT:o,wrapR:a,encoding:A});if(e.preloadColor&&c.setPreloadColor(e.preloadColor),e.image){var u=e.image;if(u.crossOrigin="Anonymous",u.compressed){var l=u.data;c.setCompressedData({mipmaps:l,props:{format:l[0].format,minFilter:r,magFilter:i}})}else c.setImage(u,{minFilter:r,magFilter:i,wrapS:s,wrapT:o,wrapR:a,flipY:e.flipY,encoding:A})}else if(e.src){var h=e.src.split(".").pop();switch(h){case"jpeg":case"jpg":case"png":case"gif":var d=new Image;d.onload=function(){c.setImage(d,{minFilter:r,magFilter:i,wrapS:s,wrapT:o,wrapR:a,flipY:e.flipY,encoding:A}),t.glRedraw()},d.src=e.src;break;default:this._textureTranscoder?ge.loadArraybuffer(e.src,(function(e){e.byteLength?t._textureTranscoder.transcode([e],c).then((function(){t.glRedraw()})):t.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error("[createTexture] Can't create texture from 'src': ".concat(e))})):this.error("[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('".concat(h,"')"))}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,c).then((function(){t.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[n]=new po({id:n,texture:c})}else this.error("[createTexture] Config missing: id")}},{key:"createTextureSet",value:function(e){var t=this,n=e.id;if(null==n)return this.error("[createTextureSet] Config missing: id"),!1;if(this._textureSets[n])return this.error("[createTextureSet] Texture set already created: ".concat(n)),!1;var r=function(e,n){var r=null!=e?e:n;if(r in t._textures)return t._textures[r];throw e};try{var i=new fo({id:n,model:this,alphaCutoff:e.alphaCutoff,colorTexture:r(e.colorTextureId,"defaultColorTexture"),metallicRoughnessTexture:r(e.metallicRoughnessTextureId,"defaultMetalRoughTexture"),normalsTexture:r(e.normalsTextureId,"defaultNormalsTexture"),emissiveTexture:r(e.emissiveTextureId,"defaultEmissiveTexture"),occlusionTexture:r(e.occlusionTextureId,"defaultOcclusionTexture")});return this._textureSets[n]=i,i}catch(e){return this.error("[createTextureSet] Texture not found: ".concat(e," - ensure that you create it first with createTexture()")),!1}}},{key:"createTransform",value:function(e){if(void 0!==e.id&&null!==e.id)if(this._transforms[e.id])this.error("[createTransform] SceneModel already has a transform with this ID: ".concat(e.id));else{var t;if(!e.parentTransformId||(t=this._transforms[e.parentTransformId])){var n=new Ko({id:e.id,model:this,parent:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[n.id]=n,n}this.error("[createTransform] SceneModel.createTransform() config missing: id")}else this.error("[createTransform] SceneModel.createTransform() config missing: id")}},{key:"createMesh",value:function(e){var t;if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._meshes[e.id])return this.error("[createMesh] SceneModel already has a mesh with this ID: ".concat(e.id)),!1;var n=e.geometryId,r=void 0!==n;if(r){if(e.positions||e.positionsCompressed||e.indices||e.edgeIndices||e.normals||e.normalsCompressed||e.uv||e.uvCompressed||e.positionsDecodeMatrix)return this.error("Mesh geometry parameters not expected when instancing a geometry (not expected: positions, positionsCompressed, indices, edgeIndices, normals, normalsCompressed, uv, uvCompressed, positionsDecodeMatrix)"),!1;if(e.geometry=this._geometries[n],!e.geometry)return this.error("[createMesh] Geometry not found: ".concat(n," - ensure that you create it first with createGeometry()")),!1}else{var i;null!==(i=e.primitive)&&void 0!==i||(e.primitive="triangles")}var s,o,a=r?e.geometry.primitive:e.primitive,A="triangles"===a||"solid"===a||"surface"===a,c=e.textureSetId,u=this._dtxEnabled&&A&&!c;if(e.origin=e.origin?Ae.addVec3(this._origin,e.origin,Ae.vec3()):this._origin,r){e.positionsDecodeMatrix=e.geometry.positionsDecodeMatrix,e.aabb=Ae.AABB3(e.geometry.aabb);var l=e.transformId;if(l){if(e.transform=this._transforms[l],!e.transform)return this.error("[createMesh] Transform not found: ".concat(l," - ensure that you create it first with createTransform()")),!1}else if(e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position||e.quaternion){var h=e.scale||qo,d=e.position||$o,f=e.rotation?Ae.eulerToQuaternion(e.rotation,"XYZ",Yo):e.quaternion||ea;e.meshMatrix=Ae.composeMat4(d,f,h,Ae.mat4())}}else{if("points"!==a&&"lines"!==a&&"triangles"!==a&&"solid"!==a&&"surface"!==a)return this.error("Unsupported value for 'primitive': '".concat(a,"' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.")),!1;if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),!1;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),!1;if(!e.buckets&&!e.indices)if(A)e.indices=this._createDefaultIndices((e.positions||e.positionsCompressed).length/3);else if("lines"===a)return this.error("Param expected: indices (required for '".concat(a,"' primitive type)")),!1;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),!1;if(e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position||e.quaternion){var p=e.scale||qo,v=e.position||$o,g=e.rotation?Ae.eulerToQuaternion(e.rotation,"XYZ",Yo):e.quaternion||ea;e.meshMatrix=Ae.composeMat4(v,g,p,Ae.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Hs(e.positionsDecodeBoundary,Ae.mat4())),e.positions){var m=[];Yt(e.positions,m,Zo)&&(e.positions=m,e.origin=Ae.addVec3(e.origin,Zo,Ae.vec3()));var y=Ae.collapseAABB3();u?(e.positionsDecodeMatrix=Ae.mat4(),Ae.expandAABB3Points3(y,e.positions),e.positionsCompressed=Ls(e.positions,y,e.positionsDecodeMatrix)):(e.meshMatrix&&(Ae.transformPositions3(e.meshMatrix,e.positions,e.positions),e.meshMatrix=null),Ae.expandAABB3Points3(y,e.positions)),e.aabb=y}else if(e.positionsCompressed){var _=Ae.collapseAABB3();Ae.expandAABB3Points3(_,e.positionsCompressed),pt.decompressAABB(_,e.positionsDecodeMatrix),e.aabb=_}if(u&&e.buckets){var b=Ae.collapseAABB3();e.buckets.forEach((function(e){var t=e.positions||e.positionsCompressed;t&&Ae.expandAABB3Points3(b,t)})),e.positionsDecodeMatrix&&pt.decompressAABB(b,e.positionsDecodeMatrix),e.aabb=b}A&&!e.buckets&&(e.edgeIndices||(e.edgeIndices=ot(e.positions||e.positionsCompressed,e.indices,e.positions?null:e.positionsDecodeMatrix,2)))}if(e.meshMatrix&&(Ae.AABB3ToOBB3(e.aabb,Jo),Ae.transformOBB3(e.meshMatrix,Jo,Jo),Ae.OBB3ToAABB3(Jo,e.aabb)),e.color=e.color?new Uint8Array(e.color.slice(0,3).map((function(e){return Math.floor(255*e)}))):na,e.opacity=Math.floor(255*(null!==(t=e.opacity)&&void 0!==t?t:1)),u)e.type=2,r&&(e.buckets=this._dtxBuckets[n]),e.buckets||(e.buckets=function(e,t,n){var r,i,s,o;if(t||n){var a=M(Uo({positionsCompressed:e.positionsCompressed,indices:e.indices,edgeIndices:e.edgeIndices}),3);r=a[0],i=a[1],s=a[2]}else r=e.positionsCompressed,i=e.indices,s=e.edgeIndices;if(n){o=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=e.positionsCompressed||[],i=Po(e.indices||[],t),s=Qo(e.edgeIndices||[]);function o(e,t){if(e>t){var n=e;e=t,t=n}function r(n,r){return n!==e?e-n:r!==t?t-r:0}for(var i=0,o=(s.length>>1)-1;i<=o;){var a=o+i>>1,A=r(s[2*a],s[2*a+1]);if(A>0)i=a+1;else{if(!(A<0))return a;o=a-1}}return-i-1}var a=new Int32Array(s.length/2);a.fill(0);var A=r.length/3;if(A>8*(1<<t))return[e];var c=new Int32Array(A);c.fill(-1);var u=[];function l(){c.fill(-1);var e={positionsCompressed:[],indices:[],edgeIndices:[],maxNumPositions:(1<<t)-t,numPositions:0,bucketNumber:u.length};return u.push(e),e}for(var h=l(),d=0,f=i.length;d<f;d+=3){var p=0,v=i[d],g=i[d+1],m=i[d+2];if(-1===c[v]&&p++,-1===c[g]&&p++,-1===c[m]&&p++,p+h.numPositions>h.maxNumPositions&&(h=l()),h.bucketNumber>8)return[e];-1===c[v]&&(c[v]=h.numPositions++,h.positionsCompressed.push(r[3*v]),h.positionsCompressed.push(r[3*v+1]),h.positionsCompressed.push(r[3*v+2])),-1===c[g]&&(c[g]=h.numPositions++,h.positionsCompressed.push(r[3*g]),h.positionsCompressed.push(r[3*g+1]),h.positionsCompressed.push(r[3*g+2])),-1===c[m]&&(c[m]=h.numPositions++,h.positionsCompressed.push(r[3*m]),h.positionsCompressed.push(r[3*m+1]),h.positionsCompressed.push(r[3*m+2])),h.indices.push(c[v]),h.indices.push(c[g]),h.indices.push(c[m]);var y=void 0;(y=o(v,g))>=0&&0===a[y]&&(a[y]=1,h.edgeIndices.push(c[s[2*y]]),h.edgeIndices.push(c[s[2*y+1]])),(y=o(v,m))>=0&&0===a[y]&&(a[y]=1,h.edgeIndices.push(c[s[2*y]]),h.edgeIndices.push(c[s[2*y+1]])),(y=o(g,m))>=0&&0===a[y]&&(a[y]=1,h.edgeIndices.push(c[s[2*y]]),h.edgeIndices.push(c[s[2*y+1]]))}var _=t/8*2,b=t/8,w=2*r.length+(i.length+s.length)*_,B=0;return r.length,u.forEach((function(e){B+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*b,e.positionsCompressed.length})),B>w?[e]:(n&&Ro(u,e),u)}({positionsCompressed:r,indices:i,edgeIndices:s},r.length/3>65536?16:8)}else o=[{positionsCompressed:r,indices:i,edgeIndices:s}];return o}(r?e.geometry:e,this._enableVertexWelding,this._enableIndexBucketing),r&&(this._dtxBuckets[n]=e.buckets));else if(e.type=r?0:1,e.metallic=Math.floor(255*(null!==(s=e.metallic)&&void 0!==s?s:0)),e.roughness=Math.floor(255*(null!==(o=e.roughness)&&void 0!==o?o:1)),c&&(e.textureSet=this._textureSets[c],!r&&!e.textureSet))return this.error("[createMesh] Texture set not found: ".concat(c," - ensure that you create it first with createTextureSet()")),!1;e.numPrimitives=this._getNumPrimitives(e);var w=new Ni(this,e.id,e.color,e.opacity,e.transform,e.textureSet),B=this.scene._renderer.getPickID(w);return w.pickId=B,w.origin=Ae.vec3(e.origin),w.layer=2===e.type?this._getDTXLayer(e):this._getVBOLayer(0===e.type,e),w.aabb=e.aabb,e.pickColor=new Uint8Array([255&B,B>>8&255,B>>16&255,B>>24&255]),e.solid="solid"===e.primitive,e.meshMatrix=e.transform?e.transform.worldMatrix:e.meshMatrix,w.portionId=w.layer.createPortion(w,e),w.numPrimitives=e.numPrimitives,this._meshes[e.id]=w,this._unusedMeshes[e.id]=w,this._meshList.push(w),w}},{key:"_getNumPrimitives",value:function(e){var t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(var n=0,r=e.buckets.length;n<r;n++)t+=e.buckets[n].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/3);case"points":switch(e.type){case 2:for(var i=0,s=e.buckets.length;i<s;i++)t+=e.buckets[i].positionsCompressed.length;break;case 1:t+=e.positions?e.positions.length:e.positionsCompressed.length;break;case 0:var o=e.geometry;t+=o.positions?o.positions.length:o.positionsCompressed.length}return Math.round(t);case"lines":case"line-strip":switch(e.type){case 2:for(var a=0,A=e.buckets.length;a<A;a++)t+=e.buckets[a].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/2)}return 0}},{key:"_getDTXLayer",value:function(e){var t=e.origin,n=e.geometry?e.geometry.primitive:e.primitive,r=".".concat(n,".").concat(Math.round(t[0]),".").concat(Math.round(t[1]),".").concat(Math.round(t[2])),i=this._dtxLayers[r];if(i){if(i.canCreatePortion(e))return i;delete this._dtxLayers[r],i=null}switch(n){case"triangles":case"solid":case"surface":i=new Ds(this,n,t);break;default:return}return this._dtxLayers[r]=i,this.layerList.push(i),this._layersToFinalize.push(i),i}},{key:"_getVBOLayer",value:function(e,t){var n=e&&t.geometry,r=e?n.primitive:t.primitive,i=t.origin,s=!e&&(t.positionsDecodeMatrix||t.positionsDecodeBoundary),o=s?(JSON.stringify(s).split("").reduce((function(e,t){return(e<<5)-e+t.charCodeAt(0)|0}),0)>>>0).toString(16):"-",a=t.textureSetId||"-",A=e?t.geometryId:"-",c=(e?"instancing":"batching")+".".concat(Math.round(i[0]),".").concat(Math.round(i[1]),".").concat(Math.round(i[2]),".").concat(r,".").concat(o,".").concat(a,".").concat(A);if(!e&&c in this._vboLayers){var u=this._vboLayers[c],l=t.positionsCompressed?t.positionsCompressed.length:t.positions.length;u.canCreatePortion(l,"points"===r?0:t.indices.length)||(u.finalize(),delete this._vboLayers[c])}if(!(c in this._vboLayers)){var h=new uo(this,r,i,d({textureSet:t.textureSet},e?{geometry:n}:{maxGeometryBatchSize:this._maxGeometryBatchSize,positionsDecodeMatrix:t.positionsDecodeMatrix,uvDecodeMatrix:t.uvDecodeMatrix}));this.layerList.push(h),this._layersToFinalize.push(h),this._vboLayers[c]=h}return this._vboLayers[c]}},{key:"createEntity",value:function(e){if(void 0===e.id?e.id=Ae.createUUID():this.scene.components[e.id]&&(this.error("Scene already has a Component with this ID: ".concat(e.id," - will assign random ID")),e.id=Ae.createUUID()),void 0===e.meshIds)return this.error("Config missing: meshIds"),null;var t=function(e){return!1!==e},n=0;n|=this._visible&&t(e.visible)&&Gi,n|=this._pickable&&t(e.pickable)&&Wi,n|=this._culled&&t(e.culled)&&ji,n|=this._clippable&&t(e.clippable)&&zi,n|=this._collidable&&t(e.collidable)&&Xi,n|=this._xrayed&&t(e.xrayed)&&Ki,n|=this._highlighted&&t(e.highlighted)&&Zi,n|=this._selected&&t(e.selected)&&Ji,n|=this._edges&&t(e.edges)&&Yi,e.flags=n;for(var r=[],i=0,s=e.meshIds.length;i<s;i++){var o=e.meshIds[i],a=this._meshes[o];a?a.parent?this.error('Mesh with ID "'.concat(o,'" already belongs to object with ID "').concat(a.parent.id,'" - ignoring this mesh')):(r.push(a),delete this._unusedMeshes[o]):this.error('Mesh with this ID not found: "'.concat(o,'" - ignoring this mesh'))}var A=new Lo(this,e.isObject,e.id,r,e.flags,!0);return this._entityList.push(A),this._entities[e.id]=A,this._entitiesToFinalize.push(A),this.numEntities++,A}},{key:"preFinalize",value:function(){if(this.destroyed)return!1;if(0===this._layersToFinalize.length)return!1;this._createDummyEntityForUnusedMeshes();for(var e=0,t=this._layersToFinalize.length;e<t;e++){this._layersToFinalize[e].finalize()}this._vboLayers={},this._dtxLayers={},this._layersToFinalize=[];for(var n=0,r=this._entitiesToFinalize.length;n<r;n++){this._entitiesToFinalize[n]._finalize()}for(var i=0,s=this._entitiesToFinalize.length;i<s;i++){this._entitiesToFinalize[i]._finalize2()}this._entitiesToFinalize=[],this.scene._aabbDirty=!0,this._viewMatrixDirty=!0,this._matrixDirty=!0,this._aabbDirty=!0,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.position=this._position,this.layerList.sort((function(e,t){return e.sortId<t.sortId?-1:e.sortId>t.sortId?1:0}));for(var o=0,a=this.layerList.length;o<a;o++){this.layerList[o].layerIndex=o}this.glRedraw(),this._layersFinalized=!0}},{key:"finalize",value:function(){this.destroyed||(this.preFinalize(),this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={})}},{key:"stateSortCompare",value:function(e,t){}},{key:"rebuildRenderFlags",value:function(){this.renderFlags.reset(),this._updateRenderFlagsVisibleLayers(),this.renderFlags.numLayers>0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}},{key:"_updateRenderFlagsVisibleLayers",value:function(){var e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(var t=0,n=this.layerList.length;t<n;t++){var r=this.layerList[t];this._getActiveSectionPlanesForLayer(r)&&(e.visibleLayers[e.numVisibleLayers++]=t)}}},{key:"_createDummyEntityForUnusedMeshes",value:function(){var e=Object.keys(this._unusedMeshes);if(e.length>0){var t="".concat(this.id,"-").concat(Ae.createUUID());this.warn('Creating dummy SceneModelEntity "'.concat(t,'" for unused SceneMeshes: [').concat(e.join(","),"]")),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}},{key:"_getActiveSectionPlanesForLayer",value:function(e){var t=this.renderFlags,n=this.scene._sectionPlanesState.sectionPlanes,r=n.length,i=e.layerIndex*r;if(r>0)for(var s=0;s<r;s++){n[s].active?(t.sectionPlanesActivePerLayer[i+s]=!0,t.sectioned=!0):t.sectionPlanesActivePerLayer[i+s]=!1}return!0}},{key:"_updateRenderFlags",value:function(){if(0!==this.numVisibleLayerPortions&&this.numCulledLayerPortions!==this.numPortions){var e=this.renderFlags;if(e.colorOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){var t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0)this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(e.edgesTransparent=!0));if(this.numSelectedLayerPortions>0){var n=this.scene.selectedMaterial._state;n.fill&&(n.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),n.edges&&(n.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){var r=this.scene.highlightMaterial._state;r.fill&&(r.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),r.edges&&(r.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}},{key:"_withEachVisibleLayer",value:function(e,t){if(!e||0!==this.numVisibleLayerPortions)for(var n=this.renderFlags,r=0,i=n.visibleLayers.length;r<i;r++){var s=n.visibleLayers[r];t(this.layerList[s])}}},{key:"drawColorOpaque",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawColorOpaque(t.renderFlags,e)}))}},{key:"drawColorTransparent",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawColorTransparent(t.renderFlags,e)}))}},{key:"drawDepth",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawDepth(t.renderFlags,e)}))}},{key:"drawSilhouetteXRayed",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawSilhouetteXRayed(t.renderFlags,e)}))}},{key:"drawSilhouetteHighlighted",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawSilhouetteHighlighted(t.renderFlags,e)}))}},{key:"drawSilhouetteSelected",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawSilhouetteSelected(t.renderFlags,e)}))}},{key:"drawEdgesColorOpaque",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawEdgesColorOpaque(t.renderFlags,e)}))}},{key:"drawEdgesColorTransparent",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawEdgesColorTransparent(t.renderFlags,e)}))}},{key:"drawEdgesXRayed",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawEdgesXRayed(t.renderFlags,e)}))}},{key:"drawEdgesHighlighted",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawEdgesHighlighted(t.renderFlags,e)}))}},{key:"drawEdgesSelected",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawEdgesSelected(t.renderFlags,e)}))}},{key:"drawOcclusion",value:function(e){var t=this;this._withEachVisibleLayer(!0,(function(n){return n.drawOcclusion(t.renderFlags,e)}))}},{key:"drawShadow",value:function(e){var t=this;this._withEachVisibleLayer(!0,(function(n){return n.drawShadow(t.renderFlags,e)}))}},{key:"drawPickMesh",value:function(e){var t=this;this._withEachVisibleLayer(!0,(function(n){return n.drawPickMesh(t.renderFlags,e)}))}},{key:"drawPickDepths",value:function(e){var t=this;this._withEachVisibleLayer(!0,(function(n){return n.drawPickDepths(t.renderFlags,e)}))}},{key:"drawPickNormals",value:function(e){var t=this;this._withEachVisibleLayer(!0,(function(n){return n.drawPickNormals(t.renderFlags,e)}))}},{key:"_drawSnap",value:function(e,t){var n=this;this._withEachVisibleLayer(!0,(function(r){return r.drawSnap(n.renderFlags,e,t)}))}},{key:"drawSnapInit",value:function(e){this._drawSnap(e,!0)}},{key:"drawSnap",value:function(e){this._drawSnap(e,!1)}},{key:"destroy",value:function(){Object.values(this._vboLayers).forEach((function(e){return e.destroy()})),this._vboLayers={},this.scene.camera.off(this._onCameraViewMatrix),this.scene.off(this._onTick);for(var e=0,t=this.layerList.length;e<t;e++)this.layerList[e].destroy();this.layerList=[];for(var r=0,i=this._entityList.length;r<i;r++)this._entityList[r]._destroy();this._layersToFinalize=[],this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._meshes={},this._entities={},this.scene._aabbDirty=!0,this._isModel&&this.scene._deregisterModel(this),v(C(n.prototype),"destroy",this).call(this)}}]),n}();var ia=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))._positions=i.positions||[],i.indices)r._indices=i.indices;else{r._indices=[];for(var s=0,o=r._positions.length/3-1;s<o;s+=2)r._indices.push(s),r._indices.push(s+1)}return r._color=i.color||[1,1,1],r._opacity=i.opacity||1,r._sceneModel=new ra(w(r),{isModel:!1}),r._sceneModel.createMesh({id:"linesMesh",primitive:"lines",positions:r._positions,indices:r._indices,color:r._color,opacity:r._opacity}),r._sceneModel.createEntity({meshIds:["linesMesh"],visible:i.visible,clippable:i.clippable,collidable:i.collidable}),r._sceneModel.finalize(),r.scene._lineSetCreated(w(r)),r}return I(n,[{key:"visible",get:function(){return this._sceneModel.visible},set:function(e){this._sceneModel.visible=e}},{key:"positions",get:function(){return this._positions}},{key:"indices",get:function(){return this._indices}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this.scene._lineSetDestroyed(this)}}]),n}(),sa=function(e){m(n,Ie);var t=_(n);function n(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),t.call(this,e,r)}return I(n,[{key:"type",get:function(){return"Light"}},{key:"isLight",get:function(){return!0}}]),n}(),oa=function(e){m(n,sa);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={type:"ambient",color:Ae.vec3([.7,.7,.7]),intensity:1},r.color=i.color,r.intensity=i.intensity,r.scene._lightCreated(w(r)),r}return I(n,[{key:"type",get:function(){return"AmbientLight"}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){this._state.intensity=void 0!==e?e:1,this.glRedraw()}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this.scene._lightDestroyed(this)}}]),n}(),aa=function(){function e(t,n,r){x(this,e),this.gl=t,this.allocated=!1,this.buffer=null,this.bound=!1,this._colorFormats=n,this._hasDepthTexture=r}return I(e,[{key:"setSize",value:function(e){this.size=e}},{key:"bind",value:function(){var e=this.size[0],t=this.size[1];if(!this.buffer||this.buffer.width===e&&this.buffer.height===t||(this.buffer.cleanup(),this.buffer=null),this.buffer||(this._allocateBuffer(e,t),this.bound=!1),!this.bound){var n=this.gl;n.bindFramebuffer(n.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}}},{key:"_allocateBuffer",value:function(e,t){var n=this._colorFormats||[],r=this.gl,i=function(){var e=r.createTexture();return r.bindTexture(r.TEXTURE_2D,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),e},s=(n.length>0?n:[null]).map((function(n){var s=i();return n?r.texStorage2D(r.TEXTURE_2D,1,n,e,t):r.texImage2D(r.TEXTURE_2D,0,r.RGBA,e,t,0,r.RGBA,r.UNSIGNED_BYTE,null),s})),o=r.createRenderbuffer();r.bindRenderbuffer(r.RENDERBUFFER,o),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_COMPONENT32F,e,t);var a=r.createFramebuffer();r.bindFramebuffer(r.FRAMEBUFFER,a);for(var A=0;A<s.length;A++)r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+A,r.TEXTURE_2D,s[A],0);n.length>0&&r.drawBuffers(s.map((function(e,t){return r.COLOR_ATTACHMENT0+t})));var c=this._hasDepthTexture&&i();if(c?(r.texImage2D(r.TEXTURE_2D,0,r.DEPTH_COMPONENT32F,e,t,0,r.DEPTH_COMPONENT,r.FLOAT,null),r.framebufferTexture2D(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.TEXTURE_2D,c,0)):r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.RENDERBUFFER,o),r.bindTexture(r.TEXTURE_2D,null),r.bindRenderbuffer(r.RENDERBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,a),!r.isFramebuffer(a))throw"Invalid framebuffer";r.bindFramebuffer(r.FRAMEBUFFER,null);var u=r.checkFramebufferStatus(r.FRAMEBUFFER);switch(u){case r.FRAMEBUFFER_COMPLETE:break;case r.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case r.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+u}this.buffer={cleanup:function(){s.forEach((function(e){return r.deleteTexture(e)})),c&&r.deleteTexture(c),r.deleteFramebuffer(a),r.deleteRenderbuffer(o)},framebuf:a,width:e,height:t},this.colorTextures=s.map((function(e){return{bind:function(t){return r.activeTexture(r["TEXTURE"+t]),r.bindTexture(r.TEXTURE_2D,e),!0}}})),this.depthTexture=c&&{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,c),!0}}}},{key:"read",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Uint8Array,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:4,o=arguments.length>6&&void 0!==arguments[6]?arguments[6]:0,a=new i(s),A=this.gl;return A.readBuffer(A.COLOR_ATTACHMENT0+o),A.readPixels(e,this.buffer.height-t-1,1,1,n||A.RGBA,r||A.UNSIGNED_BYTE,a,0),a}},{key:"unbind",value:function(){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),this.bound=!1}},{key:"destroy",value:function(){this.allocated&&(this.buffer.cleanup(),this.allocated=!1,this.buffer=null,this.bound=!1),this.colorTextures=null,this.depthTexture=null}}]),e}(),Aa=function(e){m(n,sa);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))._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var s=r.scene.camera,o=r.scene.canvas;return r._onCameraViewMatrix=s.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=s.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=o.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new it({type:"dir",dir:Ae.vec3([1,1,1]),color:Ae.vec3([.7,.7,.8]),intensity:1,space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(r._shadowViewMatrixDirty){r._shadowViewMatrix||(r._shadowViewMatrix=Ae.identityMat4());var e=r.scene.camera,t=r._state.dir,n=e.look,i=[n[0]-t[0],n[1]-t[1],n[2]-t[2]];Ae.lookAtMat4v(i,n,[0,1,0],r._shadowViewMatrix),r._shadowViewMatrixDirty=!1}return r._shadowViewMatrix},getShadowProjMatrix:function(){return r._shadowProjMatrixDirty&&(r._shadowProjMatrix||(r._shadowProjMatrix=Ae.identityMat4()),Ae.orthoMat4c(-40,40,-40,40,-40,80,r._shadowProjMatrix),r._shadowProjMatrixDirty=!1),r._shadowProjMatrix},getShadowRenderBuf:function(){return r._shadowRenderBuf||(r._shadowRenderBuf=new aa(r.scene.canvas.gl),r._shadowRenderBuf.setSize([1024,1024])),r._shadowRenderBuf}}),r.dir=i.dir,r.color=i.color,r.intensity=i.intensity,r.castsShadow=i.castsShadow,r.scene._lightCreated(w(r)),r}return I(n,[{key:"type",get:function(){return"DirLight"}},{key:"dir",get:function(){return this._state.dir},set:function(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),v(C(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}(),ca=function(e){m(n,sa);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,n);var s=w(r=t.call(this,e,i));r._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var o=r.scene.camera,a=r.scene.canvas;return r._onCameraViewMatrix=o.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=o.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=a.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new it({type:"point",pos:Ae.vec3([1,1,1]),color:Ae.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(s._shadowViewMatrixDirty){s._shadowViewMatrix||(s._shadowViewMatrix=Ae.identityMat4());var e=s._state.pos,t=o.look,n=o.up;Ae.lookAtMat4v(e,t,n,s._shadowViewMatrix),s._shadowViewMatrixDirty=!1}return s._shadowViewMatrix},getShadowProjMatrix:function(){if(s._shadowProjMatrixDirty){s._shadowProjMatrix||(s._shadowProjMatrix=Ae.identityMat4());var e=s.scene.canvas.canvas;Ae.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,s._shadowProjMatrix),s._shadowProjMatrixDirty=!1}return s._shadowProjMatrix},getShadowRenderBuf:function(){return s._shadowRenderBuf||(s._shadowRenderBuf=new aa(s.scene.canvas.gl),s._shadowRenderBuf.setSize([1024,1024])),s._shadowRenderBuf}}),r.pos=i.pos,r.color=i.color,r.intensity=i.intensity,r.constantAttenuation=i.constantAttenuation,r.linearAttenuation=i.linearAttenuation,r.quadraticAttenuation=i.quadraticAttenuation,r.castsShadow=i.castsShadow,r.scene._lightCreated(w(r)),r}return I(n,[{key:"type",get:function(){return"PointLight"}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"constantAttenuation",get:function(){return this._state.attenuation[0]},set:function(e){this._state.attenuation[0]=e||0,this.glRedraw()}},{key:"linearAttenuation",get:function(){return this._state.attenuation[1]},set:function(e){this._state.attenuation[1]=e||0,this.glRedraw()}},{key:"quadraticAttenuation",get:function(){return this._state.attenuation[2]},set:function(e){this._state.attenuation[2]=e||0,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),v(C(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}();function ua(e){return 0==(e&e-1)}function la(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var ha=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);var s=(r=t.call(this,e,i)).scene.canvas.gl;return r._state=new it({texture:new $r({gl:s,target:s.TEXTURE_CUBE_MAP}),flipY:r._checkFlipY(i.minFilter),encoding:r._checkEncoding(i.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),r._src=i.src,r._images=[],r._loadSrc(i.src),he.memory.textures++,r}return I(n,[{key:"type",get:function(){return"CubeTexture"}},{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:"_loadSrc",value:function(e){var t=this,n=this.scene.canvas.gl;this._images=[];for(var r=!1,i=0,s=function(s){var o,a,A=new Image;A.onload=(o=A,a=s,function(){if(!r&&(o=function(e){if(!ua(e.width)||!ua(e.height)){var t=document.createElement("canvas");t.width=la(e.width),t.height=la(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}(o),t._images[a]=o,6==++i)){var e=t._state.texture;e||(e=new $r({gl:n,target:n.TEXTURE_CUBE_MAP}),t._state.texture=e),e.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}),A.onerror=function(){r=!0},A.src=e[s]},o=0;o<e.length;o++)s(o)}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.texture&&this._state.texture.destroy(),he.memory.textures--,this._state.destroy()}}]),n}(),da=function(e){m(n,ha);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)).scene._lightsState.addReflectionMap(r._state),r.scene._reflectionMapCreated(w(r)),r}return I(n,[{key:"type",get:function(){return"ReflectionMap"}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this.scene._reflectionMapDestroyed(this)}}]),n}(),fa=function(e){m(n,ha);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)).scene._lightMapCreated(w(r)),r}return I(n,[{key:"type",get:function(){return"LightMap"}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this.scene._lightMapDestroyed(this)}}]),n}(),pa=Ae.vec4(),va=Ae.vec4(),ga=function(e){m(n,Ie);var t=_(n);function n(e,r){var i;return x(this,n),(i=t.call(this,e,r))._entity=null,i._visible=null,i._worldPos=Ae.vec3(),i._origin=Ae.vec3(),i._rtcPos=Ae.vec3(),i._viewPos=Ae.vec3(),i._canvasPos=Ae.vec2(),i._occludable=!1,i._onCameraViewMatrix=i.scene.camera.on("matrix",(function(){i._viewPosDirty=!0,i._needUpdate()})),i._onCameraProjMatrix=i.scene.camera.on("projMatrix",(function(){i._canvasPosDirty=!0,i._needUpdate()})),i._onEntityDestroyed=null,i._onEntityModelDestroyed=null,i._renderer.addMarker(w(i)),i.entity=r.entity,i.worldPos=r.worldPos,i.occludable=r.occludable,i}return I(n,[{key:"_update",value:function(){if(this._viewPosDirty&&(Ae.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){pa.set(this._viewPos),pa[3]=1,Ae.transformPoint4(this.scene.camera.projMatrix,pa,va);var e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+va[0]/va[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-va[1]/va[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}},{key:"_setVisible",value:function(e){this._visible,this._visible=e,this.fire("visible",this._visible)}},{key:"entity",get:function(){return this._entity},set:function(e){var t=this;this._entity!==e&&(this._cleanupDestroyedHandlers(),this._entity=e,this._entity&&(this._entity.isSceneModelEntity?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(function(){t._entity=null,t._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(function(){t._entity=null,t._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0))}},{key:"occludable",get:function(){return this._occludable},set:function(e){(e=!!e)!==this._occludable&&(this._occludable=e,this._occludable&&this._renderer.markerWorldPosUpdated(this))}},{key:"worldPos",get:function(){return this._worldPos},set:function(e){this._worldPos.set(e||[0,0,0]),Jt(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}},{key:"origin",get:function(){return this._origin}},{key:"rtcPos",get:function(){return this._rtcPos}},{key:"viewPos",get:function(){return this._update(),this._viewPos}},{key:"canvasPos",get:function(){return this._update(),this._canvasPos}},{key:"visible",get:function(){return!!this._visible}},{key:"destroy",value:function(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._cleanupDestroyedHandlers(),this._renderer.removeMarker(this),v(C(n.prototype),"destroy",this).call(this)}},{key:"_cleanupDestroyedHandlers",value:function(){this._entity&&(null!==this._onEntityDestroyed&&(this._entity.model?this._entity.model.off(this._onEntityDestroyed):this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model&&this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null))}}]),n}(),ma=function(e){m(n,ga);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,{entity:i.entity,occludable:i.occludable,worldPos:i.worldPos}))._occluded=!1,r._visible=!0,r._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),{src:i.src}),r._geometry=new mt(w(r),{primitive:"triangles",positions:[3,3,0,-3,3,0,-3,-3,0,3,-3,0],normals:[-1,0,0,-1,0,0,-1,0,0,-1,0,0],uv:[1,-1,0,-1,0,0,1,0],indices:[0,1,2,0,2,3]}),r._mesh=new Gr(w(r),{geometry:r._geometry,material:new Zr(w(r),{ambient:[.9,.3,.9],shininess:30,diffuseMap:r._texture,backfaces:!0}),scale:[1,1,1],position:i.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),r.visible=!0,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,r.size=i.size,i.image?r.image=i.image:r.src=i.src,r}return I(n,[{key:"_setVisible",value:function(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,v(C(n.prototype),"_setVisible",this).call(this,e)}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=null==e||e,this._mesh.visible=this._visible&&!this._occluded}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.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:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"collidable",get:function(){return this._mesh.collidable},set:function(e){this._mesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._mesh.clippable},set:function(e){this._mesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._mesh.pickable},set:function(e){this._mesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._mesh.opacity},set:function(e){this._mesh.opacity=e}},{key:"_updatePlaneSizeFromImage",value:function(){var e=.5*this._size,t=this._imageSize[0],n=this._imageSize[1],r=n/t;this._geometry.positions=t>n?[e,e*r,0,-e,e*r,0,-e,-e*r,0,e,-e*r,0]:[e/r,e,0,-e/r,e,0,-e/r,-e,0,e/r,-e,0]}}]),n}(),ya=function(){function e(t){x(this,e),this._eye=Ae.vec3(),this._look=Ae.vec3(),this._up=Ae.vec3(),this._projection={},t&&this.saveCamera(t)}return I(e,[{key:"saveCamera",value:function(e){var t=e.camera,n=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:n.fov,fovAxis:n.fovAxis,near:n.near,far:n.far};break;case"ortho":this._projection={projection:"ortho",scale:n.scale,near:n.near,far:n.far};break;case"frustum":this._projection={projection:"frustum",left:n.left,right:n.right,top:n.top,bottom:n.bottom,near:n.near,far:n.far};break;case"custom":this._projection={projection:"custom",matrix:n.matrix.slice()}}}},{key:"restoreCamera",value:function(e,t){var n=e.camera,r=this._projection;function i(){switch(r.type){case"perspective":n.perspective.fov=r.fov,n.perspective.fovAxis=r.fovAxis,n.perspective.near=r.near,n.perspective.far=r.far;break;case"ortho":n.ortho.scale=r.scale,n.ortho.near=r.near,n.ortho.far=r.far;break;case"frustum":n.frustum.left=r.left,n.frustum.right=r.right,n.frustum.top=r.top,n.frustum.bottom=r.bottom,n.frustum.near=r.near,n.frustum.far=r.far;break;case"custom":n.customProjection.matrix=r.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:r.scale,projection:r.projection},(function(){i(),t()})):(n.eye=this._eye,n.look=this._look,n.up=this._up,i(),n.projection=r.projection)}}]),e}(),_a=Ae.vec3(),ba=function(){function e(t){if(x(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,t){var n=t.metaScene.scene;this.saveObjects(n,t)}}return I(e,[{key:"saveObjects",value:function(e,t,n){this.numObjects=0,this._mask=n?ge.apply(n,{}):null;for(var r=!n||n.visible,i=!n||n.edges,s=!n||n.xrayed,o=!n||n.highlighted,a=!n||n.selected,A=!n||n.clippable,c=!n||n.pickable,u=!n||n.colorize,l=!n||n.opacity,h=t.metaObjects,d=e.objects,f=0,p=h.length;f<p;f++){var v=d[h[f].id];if(v){if(r&&(this.objectsVisible[f]=v.visible),i&&(this.objectsEdges[f]=v.edges),s&&(this.objectsXrayed[f]=v.xrayed),o&&(this.objectsHighlighted[f]=v.highlighted),a&&(this.objectsSelected[f]=v.selected),A&&(this.objectsClippable[f]=v.clippable),c&&(this.objectsPickable[f]=v.pickable),u){var g=v.colorize;this.objectsColorize[3*f+0]=g[0],this.objectsColorize[3*f+1]=g[1],this.objectsColorize[3*f+2]=g[2]}l&&(this.objectsOpacity[f]=v.opacity),this.numObjects++}}}},{key:"restoreObjects",value:function(e,t){for(var n=this._mask,r=!n||n.visible,i=!n||n.edges,s=!n||n.xrayed,o=!n||n.highlighted,a=!n||n.selected,A=!n||n.clippable,c=!n||n.pickable,u=!n||n.colorize,l=!n||n.opacity,h=t.metaObjects,d=e.objects,f=0,p=h.length;f<p;f++){var v=d[h[f].id];v&&(r&&(v.visible=this.objectsVisible[f]),i&&(v.edges=this.objectsEdges[f]),s&&(v.xrayed=this.objectsXrayed[f]),o&&(v.highlighted=this.objectsHighlighted[f]),a&&(v.selected=this.objectsSelected[f]),A&&(v.clippable=this.objectsClippable[f]),c&&(v.pickable=this.objectsPickable[f]),u&&(_a[0]=this.objectsColorize[3*f+0],_a[1]=this.objectsColorize[3*f+1],_a[2]=this.objectsColorize[3*f+2],v.colorize=_a),l&&(v.opacity=this.objectsOpacity[f]))}}}]),e}(),wa=Ae.vec3(),Ba=function(){function e(){x(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}return I(e,[{key:"saveObjects",value:function(e,t){this.numObjects=0,this._mask=t?ge.apply(t,{}):null;var n=e.objects,r=!t||t.visible,i=!t||t.edges,s=!t||t.xrayed,o=!t||t.highlighted,a=!t||t.selected,A=!t||t.clippable,c=!t||t.pickable,u=!t||t.colorize,l=!t||t.opacity;for(var h in n)if(n.hasOwnProperty(h)){var d=n[h],f=this.numObjects;if(r&&(this.objectsVisible[f]=d.visible),i&&(this.objectsEdges[f]=d.edges),s&&(this.objectsXrayed[f]=d.xrayed),o&&(this.objectsHighlighted[f]=d.highlighted),a&&(this.objectsSelected[f]=d.selected),A&&(this.objectsClippable[f]=d.clippable),c&&(this.objectsPickable[f]=d.pickable),u){var p=d.colorize;p?(this.objectsColorize[3*f+0]=p[0],this.objectsColorize[3*f+1]=p[1],this.objectsColorize[3*f+2]=p[2],this.objectsHasColorize[f]=!0):this.objectsHasColorize[f]=!1}l&&(this.objectsOpacity[f]=d.opacity),this.numObjects++}}},{key:"restoreObjects",value:function(e){var t=this._mask,n=!t||t.visible,r=!t||t.edges,i=!t||t.xrayed,s=!t||t.highlighted,o=!t||t.selected,a=!t||t.clippable,A=!t||t.pickable,c=!t||t.colorize,u=!t||t.opacity,l=0,h=e.objects;for(var d in h)if(h.hasOwnProperty(d)){var f=h[d];n&&(f.visible=this.objectsVisible[l]),r&&(f.edges=this.objectsEdges[l]),i&&(f.xrayed=this.objectsXrayed[l]),s&&(f.highlighted=this.objectsHighlighted[l]),o&&(f.selected=this.objectsSelected[l]),a&&(f.clippable=this.objectsClippable[l]),A&&(f.pickable=this.objectsPickable[l]),c&&(this.objectsHasColorize[l]?(wa[0]=this.objectsColorize[3*l+0],wa[1]=this.objectsColorize[3*l+1],wa[2]=this.objectsColorize[3*l+2],f.colorize=wa):f.colorize=null),u&&(f.opacity=this.objectsOpacity[l]),l++}}}]),e}(),Ca=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)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.v3=i.v3,r.t=i.t,r}return I(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||Ae.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||Ae.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||Ae.vec3([0,0,0])}},{key:"v3",get:function(){return this._v3},set:function(e){this.fire("v3",this._v3=e||Ae.vec3([0,0,0]))}},{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=Ae.vec3();return t[0]=Ae.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=Ae.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=Ae.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}]),n}(),ka=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))._cachedLengths=[],r._dirty=!0,r._curves=[],r._t=0,r._dirtySubs=[],r._destroyedSubs=[],r.curves=i.curves||[],r.t=i.t,r}return I(n,[{key:"addCurve",value:function(e){this._curves.push(e),this._dirty=!0}},{key:"curves",get:function(){return this._curves},set:function(e){var t,n,r;for(e=e||[],n=0,r=this._curves.length;n<r;n++)(t=this._curves[n]).off(this._dirtySubs[n]),t.off(this._destroyedSubs[n]);this._curves=[],this._dirtySubs=[],this._destroyedSubs=[];var i=this;function s(){i._dirty=!0}function o(){var e=this.id;for(n=0,r=i._curves.length;n<r;n++)if(i._curves[n].id===e)return i._curves=i._curves.slice(n,n+1),i._dirtySubs=i._dirtySubs.slice(n,n+1),i._destroyedSubs=i._destroyedSubs.slice(n,n+1),void(i._dirty=!0)}for(n=0,r=e.length;n<r;n++){if(t=e[n],ge.isNumeric(t)||ge.isString(t)){var a=t;if(!(t=this.scene.components[a])){this.error("Component not found: "+_inQuotes(a));continue}}var A=t.type;"xeokit.SplineCurve"===A||"xeokit.Path"===A||"xeokit.CubicBezierCurve"===A||"xeokit.QuadraticBezierCurve"===A?(this._curves.push(t),this._dirtySubs.push(t.on("dirty",s)),this._destroyedSubs.push(t.once("destroyed",o))):this.error("Component "+_inQuotes(t.id)+" is not a xeokit.SplineCurve, xeokit.Path or xeokit.QuadraticBezierCurve")}this._dirty=!0}},{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:"length",get:function(){var e=this._getCurveLengths();return e[e.length-1]}},{key:"getPoint",value:function(e){for(var t,n=e*this.length,r=this._getCurveLengths(),i=0;i<r.length;){if(r[i]>=n){var s=1-(r[i]-n)/(t=this._curves[i]).length;return t.getPointAt(s)}i++}return null}},{key:"_getCurveLengths",value:function(){if(!this._dirty)return this._cachedLengths;var e,t=[],n=0,r=this._curves.length;for(e=0;e<r;e++)n+=this._curves[e].length,t.push(n);return this._cachedLengths=t,this._dirty=!1,t}},{key:"_getJSON",value:function(){for(var e=[],t=0,n=this._curves.length;t<n;t++)e.push(this._curves[t].id);return{curves:e,t:this._t}}},{key:"destroy",value:function(){var e,t,r;for(v(C(n.prototype),"destroy",this).call(this),e=0,t=this._curves.length;e<t;e++)(r=this._curves[e]).off(this._dirtySubs[e]),r.off(this._destroyedSubs[e])}}]),n}(),Ma=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)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.t=i.t,r}return I(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||Ae.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||Ae.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||Ae.vec3([0,0,0])}},{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=Ae.vec3();return t[0]=Ae.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=Ae.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=Ae.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}]),n}(),Ea=function(e){m(n,ra);var t=_(n);function n(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),t.call(this,e,r)}return I(n)}(),Fa=Ae.vec3(),xa=Ae.vec3(),Ua=Ae.vec4(),Ia=Ae.vec3([0,0,-1]),Ta=Ae.vec3([0,0,1]),Pa=Ae.vec3([0,1,0]),Sa=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({active:!0,pos:Ae.vec3(),quaternion:Ae.vec4(),roll:0,dir:Ae.vec3(),dist:0}),r.active=i.active,r.pos=i.pos,r.dir=i.dir,r.scene._sectionPlaneCreated(w(r)),r}return I(n,[{key:"type",get:function(){return"SectionPlane"}},{key:"active",get:function(){return this._state.active},set:function(e){this._state.active=!1!==e,this.glRedraw(),this.fire("active",this._state.active),this.scene.fire("sectionPlaneUpdated",this)}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[0,0,0]),this._state.dist=-Ae.dotVec3(this._state.pos,this._state.dir),this.fire("pos",this._state.pos),this.scene.fire("sectionPlaneUpdated",this)}},{key:"quaternion",get:function(){return this._state.quaternion},set:function(e){this._state.quaternion.set(e||[0,0,0,-1]),Ae.vec3ApplyQuaternion(this._state.quaternion,Ta,this._state.dir);var t=Ae.vec3ApplyQuaternion(this._state.quaternion,Pa,Fa),n=Ae.vec3PairToQuaternion(Ta,this._state.dir,Ua),r=Ae.vec3ApplyQuaternion(n,Pa,xa),i=Math.acos(Math.min(1,Ae.dotVec3(t,r))),s=Math.sign(Ae.dotVec3(this._state.dir,Ae.cross3Vec3(t,r,xa)));this._state.roll=s*i,this._onDirUpdated()}},{key:"roll",get:function(){return this._state.roll},set:function(e){this._state.roll=e||0,this._onDirRollUpdated()}},{key:"dir",get:function(){return this._state.dir},set:function(e){this._state.dir.set(e||Ia),this._onDirRollUpdated()}},{key:"_onDirRollUpdated",value:function(){Ae.vec3PairToQuaternion(Ta,this._state.dir,this._state.quaternion),Ua[0]=0,Ua[1]=0,Ua[2]=-1,Ua[3]=this._state.roll,Ae.angleAxisToQuaternion(Ua,Ua),Ae.mulQuaternions(this._state.quaternion,Ua,this._state.quaternion),this._onDirUpdated()}},{key:"_onDirUpdated",value:function(){this._state.dist=-Ae.dotVec3(this._state.pos,this._state.dir),this.glRedraw(),this.fire("dir",this._state.dir),this.scene.fire("sectionPlaneUpdated",this)}},{key:"dist",get:function(){return this._state.dist}},{key:"flipDir",value:function(){Ae.mulVec3Scalar(this._state.dir,-1,this._state.dir),this.dir=this._state.dir}},{key:"destroy",value:function(){this._state.destroy(),this.scene._sectionPlaneDestroyed(this),v(C(n.prototype),"destroy",this).call(this)}}]),n}(),Da=function(){function e(){x(this,e)}return I(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),Qa=function(){function e(){x(this,e),this.entity=null,this.primitive=null,this.primIndex=-1,this.pickSurfacePrecision=!1,this.touchInput=!1,this.snappedToEdge=!1,this.snappedToVertex=!1,this._origin=new Float64Array([0,0,0]),this._direction=new Float64Array([0,0,0]),this._indices=new Int32Array(3),this._localPos=new Float64Array([0,0,0]),this._worldPos=new Float64Array([0,0,0]),this._viewPos=new Float64Array([0,0,0]),this._canvasPos=new Int16Array([0,0]),this._snappedCanvasPos=new Int16Array([0,0]),this._bary=new Float64Array([0,0,0]),this._worldNormal=new Float64Array([0,0,0]),this._uv=new Float64Array([0,0]),this.reset()}return I(e,[{key:"canvasPos",get:function(){return this._gotCanvasPos?this._canvasPos:null},set:function(e){e?(this._canvasPos[0]=e[0],this._canvasPos[1]=e[1],this._gotCanvasPos=!0):this._gotCanvasPos=!1}},{key:"origin",get:function(){return this._gotOrigin?this._origin:null},set:function(e){e?(this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this._gotOrigin=!0):this._gotOrigin=!1}},{key:"direction",get:function(){return this._gotDirection?this._direction:null},set:function(e){e?(this._direction[0]=e[0],this._direction[1]=e[1],this._direction[2]=e[2],this._gotDirection=!0):this._gotDirection=!1}},{key:"indices",get:function(){return this.entity&&this._gotIndices?this._indices:null},set:function(e){e?(this._indices[0]=e[0],this._indices[1]=e[1],this._indices[2]=e[2],this._gotIndices=!0):this._gotIndices=!1}},{key:"localPos",get:function(){return this.entity&&this._gotLocalPos?this._localPos:null},set:function(e){e?(this._localPos[0]=e[0],this._localPos[1]=e[1],this._localPos[2]=e[2],this._gotLocalPos=!0):this._gotLocalPos=!1}},{key:"snappedCanvasPos",get:function(){return this._gotSnappedCanvasPos?this._snappedCanvasPos:null},set:function(e){e?(this._snappedCanvasPos[0]=e[0],this._snappedCanvasPos[1]=e[1],this._gotSnappedCanvasPos=!0):this._gotSnappedCanvasPos=!1}},{key:"worldPos",get:function(){return this._gotWorldPos?this._worldPos:null},set:function(e){e?(this._worldPos[0]=e[0],this._worldPos[1]=e[1],this._worldPos[2]=e[2],this._gotWorldPos=!0):this._gotWorldPos=!1}},{key:"viewPos",get:function(){return this.entity&&this._gotViewPos?this._viewPos:null},set:function(e){e?(this._viewPos[0]=e[0],this._viewPos[1]=e[1],this._viewPos[2]=e[2],this._gotViewPos=!0):this._gotViewPos=!1}},{key:"bary",get:function(){return this.entity&&this._gotBary?this._bary:null},set:function(e){e?(this._bary[0]=e[0],this._bary[1]=e[1],this._bary[2]=e[2],this._gotBary=!0):this._gotBary=!1}},{key:"worldNormal",get:function(){return this.entity&&this._gotWorldNormal?this._worldNormal:null},set:function(e){e?(this._worldNormal[0]=e[0],this._worldNormal[1]=e[1],this._worldNormal[2]=e[2],this._gotWorldNormal=!0):this._gotWorldNormal=!1}},{key:"uv",get:function(){return this.entity&&this._gotUV?this._uv:null},set:function(e){e?(this._uv[0]=e[0],this._uv[1]=e[1],this._gotUV=!0):this._gotUV=!1}},{key:"snapped",get:function(){return this.snappedToEdge||this.snappedToVertex}},{key:"reset",value:function(){this.entity=null,this.primIndex=-1,this.primitive=null,this.pickSurfacePrecision=!1,this._gotCanvasPos=!1,this._gotSnappedCanvasPos=!1,this._gotOrigin=!1,this._gotDirection=!1,this._gotIndices=!1,this._gotLocalPos=!1,this._gotWorldPos=!1,this._gotViewPos=!1,this._gotBary=!1,this._gotWorldNormal=!1,this._gotUV=!1,this.touchInput=!1,this.snappedToEdge=!1,this.snappedToVertex=!1}}]),e}(),Ra={isIphoneSafari:function(){var e=window.navigator.userAgent,t=/iPhone/i.test(e),n=/Safari/i.test(e)&&!/Chrome/i.test(e);return t&&n},isIphoneOrIpadSafari:function(){var e=window.navigator.userAgent,t=/iPhone|iPad/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints&&navigator.maxTouchPoints>2,n=/Safari/i.test(e)&&!/Chrome/i.test(e);return t&&n},isTouchDevice:function(){return"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.mxMaxTouchPoints>0}},Oa=function(){function e(t,n,r){x(this,e),this.id=r&&r.id?r.id:t,this.viewer=n,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,n.addPlugin(this)}return I(e,[{key:"scheduleTask",value:function(e){Fe.scheduleTask(e,null)}},{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){console.log("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"warn",value:function(e){console.warn("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"error",value:function(e){console.error("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"send",value:function(e,t){}},{key:"destroy",value:function(){this.viewer.removePlugin(this)}}]),e}(),Va=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))._canvas=i.canvas,r._element=null,r._isCustom=!1,i.elementId&&(r._element=document.getElementById(i.elementId),r._element?r._adjustPosition():r.error("Can't find given Spinner HTML element: '"+i.elementId+"' - will automatically create default element")),r._element||r._createDefaultSpinner(),r.processes=0,r}return I(n,[{key:"type",get:function(){return"Spinner"}},{key:"_createDefaultSpinner",value:function(){this._injectDefaultCSS();var e=document.createElement("div"),t=e.style;t["z-index"]="9000",t.position="absolute",e.innerHTML='<div class="sk-fading-circle"> <div class="sk-circle1 sk-circle"></div> <div class="sk-circle2 sk-circle"></div> <div class="sk-circle3 sk-circle"></div> <div class="sk-circle4 sk-circle"></div> <div class="sk-circle5 sk-circle"></div> <div class="sk-circle6 sk-circle"></div> <div class="sk-circle7 sk-circle"></div> <div class="sk-circle8 sk-circle"></div> <div class="sk-circle9 sk-circle"></div> <div class="sk-circle10 sk-circle"></div> <div class="sk-circle11 sk-circle"></div> <div class="sk-circle12 sk-circle"></div> </div>',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}},{key:"_injectDefaultCSS",value:function(){var e="xeokit-spinner-css";if(!document.getElementById(e)){var t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}}},{key:"_adjustPosition",value:function(){if(!this._isCustom){var e=this._canvas,t=this._element,n=t.style;n.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",n.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}}},{key:"processes",get:function(){return this._processes},set:function(e){if(e=e||0,this._processes!==e&&!(e<0)){var t=this._processes;this._processes=e;var n=this._element;n&&(n.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}}},{key:"_destroy",value:function(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);var e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}]),n}(),La=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"],Ha=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))._backgroundColor=Ae.vec3([i.backgroundColor?i.backgroundColor[0]:1,i.backgroundColor?i.backgroundColor[1]:1,i.backgroundColor?i.backgroundColor[2]:1]),r._backgroundColorFromAmbientLight=!!i.backgroundColorFromAmbientLight,r.canvas=i.canvas,r.gl=null,r.webgl2=!1,r.transparent=!!i.transparent,r.contextAttr=i.contextAttr||{},r.contextAttr.alpha=r.transparent,r.contextAttr.preserveDrawingBuffer=!!r.contextAttr.preserveDrawingBuffer,r.contextAttr.stencil=!1,r.contextAttr.premultipliedAlpha=!!r.contextAttr.premultipliedAlpha,r.contextAttr.antialias=!1!==r.contextAttr.antialias,r.resolutionScale=i.resolutionScale,r.canvas.width=Math.round(r.canvas.clientWidth*r._resolutionScale),r.canvas.height=Math.round(r.canvas.clientHeight*r._resolutionScale),r.boundary=[r.canvas.offsetLeft,r.canvas.offsetTop,r.canvas.clientWidth,r.canvas.clientHeight],r._initWebGL(i);var s=w(r),o=!0,a=new ResizeObserver((function(e){var t,n=l(e);try{for(n.s();!(t=n.n()).done;){t.value.contentBoxSize&&(o=!0)}}catch(e){n.e(e)}finally{n.f()}}));return a.observe(r.canvas),r._tick=r.scene.on("tick",(function(){o&&(o=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),r._spinner=new Va(r.scene,{canvas:r.canvas,elementId:i.spinnerElementId}),r}return I(n,[{key:"type",get:function(){return"Canvas"}},{key:"backgroundColorFromAmbientLight",get:function(){return this._backgroundColorFromAmbientLight},set:function(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}},{key:"backgroundColor",get:function(){return this._backgroundColor},set:function(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}},{key:"resolutionScale",get:function(){return this._resolutionScale},set:function(e){if((e=e||1)!==this._resolutionScale){this._resolutionScale=e;var t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}}},{key:"spinner",get:function(){return this._spinner}},{key:"_createCanvas",value:function(){var e="xeokit-canvas-"+Ae.createUUID(),t=document.getElementsByTagName("body")[0],n=document.createElement("div"),r=n.style;r.height="100%",r.width="100%",r.padding="0",r.margin="0",r.background="rgba(0,0,0,0);",r.float="left",r.left="0",r.top="0",r.position="absolute",r.opacity="1.0",r["z-index"]="-10000",n.innerHTML+='<canvas id="'+e+'" style="width: 100%; height: 100%; float: left; margin: 0; padding: 0;"></canvas>',t.appendChild(n),this.canvas=document.getElementById(e)}},{key:"_getElementXY",value:function(e){for(var t=0,n=0;e;)t+=e.offsetLeft-e.scrollLeft,n+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:n}}},{key:"_initWebGL",value:function(){if(!this.gl)for(var e=0;!this.gl&&e<La.length;e++)try{this.gl=this.canvas.getContext(La[e],this.contextAttr)}catch(e){}this.gl||(this.error("Failed to get a WebGL context"),this.fire("webglContextFailed",!0,!0));var t=this.gl,n="__",r=t.activeTexture;t.activeTexture=function(e){n!==e&&(n=e,r.call(this,e))};var i={},s=t.bindTexture;t.bindTexture=function(e,t){i[n]!==t&&(i[n]=t,s.call(this,e,t))},this.gl&&this.webgl2&&(this.gl.hint(this.gl.FRAGMENT_SHADER_DERIVATIVE_HINT,this.gl.FASTEST),this.gl,WebGL2RenderingContext)}},{key:"getSnapshot",value:function(e){throw"Canvas#getSnapshot() has been replaced by Viewer#getSnapshot() - use that method instead."}},{key:"readPixels",value:function(e,t,n){return this.scene._renderer.snapshot.readPixels(e,t,n)}},{key:"loseWebGLContext",value:function(){this.canvas.loseContext&&this.canvas.loseContext()}},{key:"destroy",value:function(){this.scene.off(this._tick),this._spinner._destroy(),this.gl=null,v(C(n.prototype),"destroy",this).call(this)}}]),n}(),Na=function(){function e(t){x(this,e),this._matPool=[],this.reset()}return I(e,[{key:"reset",value:function(){this._matPoolNextFreeIndex=0,this._rtcViewMats={},this.lastProgramId=null,this.pbrEnabled=!1,this.colorTextureEnabled=!1,this.withSAO=!1,this.backfaces=!1,this.frontface=!0,this.textureUnit=0,this.drawElements=0,this.drawArrays=0,this.useProgram=0,this.bindTexture=0,this.bindArray=0,this.pass=0,this.viewParams={},this.viewParams.viewMatrix=null,this.viewParams.projMatrix=null,this.viewParams.near=.01,this.viewParams.far=5e3,this.pickInvisible=!1,this.lineWidth=1,this.snapPickLayerParams=[],this.snapPickCoordinateScale=Ae.vec3(),this.snapPickOrigin=Ae.vec3()}},{key:"getRTCViewMatrix",value:function(e,t){var n=this._rtcViewMats[e];return n||(n=this._getNewMat(),Zt(this.viewParams.viewMatrix,t,n),this._rtcViewMats[e]=n),n}},{key:"_getNewMat",value:function(){var e=this._matPool[this._matPoolNextFreeIndex];return e||(e=Ae.mat4(),this._matPool[this._matPoolNextFreeIndex]=e),this._matPoolNextFreeIndex++,e}}]),e}(),Ga={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},ja=document.createElement("canvas");if(ja){var Wa=ja.getContext("webgl",{antialias:!0})||ja.getContext("experimental-webgl",{antialias:!0});Ga.WEBGL=!!Wa,Ga.WEBGL&&(Ga.ANTIALIAS=Wa.getContextAttributes().antialias,Wa.getShaderPrecisionFormat?Wa.getShaderPrecisionFormat(Wa.FRAGMENT_SHADER,Wa.HIGH_FLOAT).precision>0?Ga.FS_MAX_FLOAT_PRECISION="highp":Wa.getShaderPrecisionFormat(Wa.FRAGMENT_SHADER,Wa.MEDIUM_FLOAT).precision>0?Ga.FS_MAX_FLOAT_PRECISION="mediump":Ga.FS_MAX_FLOAT_PRECISION="lowp":Ga.FS_MAX_FLOAT_PRECISION="mediump",Ga.DEPTH_BUFFER_BITS=Wa.getParameter(Wa.DEPTH_BITS),Ga.MAX_TEXTURE_SIZE=Wa.getParameter(Wa.MAX_TEXTURE_SIZE),Ga.MAX_CUBE_MAP_SIZE=Wa.getParameter(Wa.MAX_CUBE_MAP_TEXTURE_SIZE),Ga.MAX_RENDERBUFFER_SIZE=Wa.getParameter(Wa.MAX_RENDERBUFFER_SIZE),Ga.MAX_TEXTURE_UNITS=Wa.getParameter(Wa.MAX_COMBINED_TEXTURE_IMAGE_UNITS),Ga.MAX_TEXTURE_IMAGE_UNITS=Wa.getParameter(Wa.MAX_TEXTURE_IMAGE_UNITS),Ga.MAX_VERTEX_ATTRIBS=Wa.getParameter(Wa.MAX_VERTEX_ATTRIBS),Ga.MAX_VERTEX_UNIFORM_VECTORS=Wa.getParameter(Wa.MAX_VERTEX_UNIFORM_VECTORS),Ga.MAX_FRAGMENT_UNIFORM_VECTORS=Wa.getParameter(Wa.MAX_FRAGMENT_UNIFORM_VECTORS),Ga.MAX_VARYING_VECTORS=Wa.getParameter(Wa.MAX_VARYING_VECTORS),Wa.getSupportedExtensions().forEach((function(e){Ga.SUPPORTED_EXTENSIONS[e]=!0})))}var za=function(){function e(t){x(this,e),this.aabb=Ae.AABB3(),this.origin=Ae.vec3(t),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}return I(e,[{key:"addMarker",value:function(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}},{key:"markerWorldPosUpdated",value:function(e){if(this.markers[e.id]){var t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}}},{key:"removeMarker",value:function(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}},{key:"update",value:function(e,t){if(this.markerListDirty){for(var n in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(n)&&(this.markerList[this.numMarkers]=this.markers[n],this.markerIndices[n]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0}if(this.positionsDirty){for(var r=0,i=0;i<this.numMarkers;i++)if(this.markerList[i]){var s=this.markerList[i].rtcPos;this.positions[r++]=s[0],this.positions[r++]=s[1],this.positions[r++]=s[2],this.indices[i]=i}this.positions.length=3*this.numMarkers,this.indices.length=this.numMarkers,this.positionsDirty=!1;var o=this.aabb;Ae.collapseAABB3(o),Ae.expandAABB3Points3(o,this.positions);var a=this.origin;o[0]+=a[0],o[1]+=a[1],o[2]+=a[2],o[3]+=a[0],o[4]+=a[1],o[5]+=a[2],this.positionsBuf&&this.lenPositionsBuf!==this.positions.length&&(this.positionsBuf.destroy(),this.positionsBuf=null,this.indicesBuf.destroy(),this.indicesBuf=null);var A=new Float32Array(this.positions);this.positionsBuf?this.positionsBuf.setData(A):(this.positionsBuf=new st(e,e.ARRAY_BUFFER,A,A.length,3,e.STATIC_DRAW),this.indicesBuf=new st(e,e.ELEMENT_ARRAY_BUFFER,new Uint16Array(this.indices),this.indices.length,1,e.STATIC_DRAW),this.lenPositionsBuf=this.positions.length)}if(this.occlusionTestListDirty){var c=0;this.lenOcclusionTestList=0;for(var u=0;u<this.numMarkers;u++){var l=this.markerList[u];l.entity&&!l.entity.visible||!t(l)?l._setVisible(!1):l.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=l,this.pixels[c++]=l.canvasPos[0],this.pixels[c++]=l.canvasPos[1]):l._setVisible(!0)}}}},{key:"destroy",value:function(){this.markers={},this.markerList.length=0,this.positionsBuf&&this.positionsBuf.destroy(),this.indicesBuf&&this.indicesBuf.destroy()}}]),e}(),Xa=Ae.vec3([255,0,0]);Ae.vec3();var Ka=function(){function e(t){var n=this;x(this,e),this._scene=t,this._occlusionLayers={},this._occlusionLayersList=[],this._occlusionLayersListDirty=!1,this._drawable=null,this._markersToOcclusionLayersMap={};var r=t.camera,i=function(){n._occlusionTestListDirty=!0};this._onCameraViewMatrix=r.on("viewMatrix",i),this._onCameraProjMatrix=r.on("projMatrix",i),this._onCanvasBoundary=t.canvas.on("boundary",i)}return I(e,[{key:"_addMarker",value:function(e,t){this._occlusionLayers[t]||(this._occlusionLayers[t]=new za(e.origin),this._occlusionLayersListDirty=!0);var n=this._occlusionLayers[t];n.addMarker(e),this._markersToOcclusionLayersMap[e.id]=n}},{key:"_removeMarker",value:function(e,t){1===e.numMarkers?(e.destroy(),delete this._occlusionLayers[e.originHash],this._occlusionLayersListDirty=!0):e.removeMarker(t),delete this._markersToOcclusionLayersMap[t.id]}},{key:"addMarker",value:function(e){var t=e.origin.join();this._addMarker(e,t),this._occlusionTestListDirty=!0}},{key:"markerWorldPosUpdated",value:function(e){var t=this._markersToOcclusionLayersMap[e.id];if(t){var n=e.origin.join();n!==t.originHash?(this._removeMarker(t,e),this._addMarker(e,n)):t.markerWorldPosUpdated(e)}}},{key:"removeMarker",value:function(e){var t=e.origin.join(),n=this._occlusionLayers[t];n&&this._removeMarker(n,e)}},{key:"needOcclusionTest",get:function(){return this._occlusionTestListDirty}},{key:"drawMarkers",value:function(){var e=this,t=this._scene,n=t.canvas,r=n.gl,i=t._sectionPlanesState,s=[n.canvas.id,i.getHash()].join(";");if(!this._drawable||s!==this._drawable.shaderSourceHash){this._drawable&&this._drawable.destroy();var o=gr(),a=o.programVariables,A=a.createUniform("mat4","viewMatrix"),c=a.createUniform("mat4","projMatrix"),u=a.createAttribute("vec3","position"),l=a.createOutput("vec4","outColor"),h="clipPos",d=M(o.buildProgram(r,"OcclusionTester",{sectionPlanesState:i,getLogDepth:t.logarithmicDepthBufferEnabled&&function(e){return e},clippableTest:function(){return"true"},getVertexData:function(){var e=[];return e.push("vec4 worldPosition = vec4(".concat(u,", 1.0);")),e.push("vec4 ".concat(h," = ").concat(c," * ").concat(A," * worldPosition;")),!t.logarithmicDepthBufferEnabled&&t.markerZOffset<0&&e.push("".concat(h,".z += ").concat(t.markerZOffset,";")),e},worldPositionAttribute:"worldPosition",getPointSize:function(){return"20.0"},clipPos:h,appendFragmentOutputs:function(e){return e.push("".concat(l," = vec4(1.0, 0.0, 0.0, 1.0);"))}}),2),f=d[0],p=d[1];if(p)throw console.error(p.join("\n")),p.join("\n");this._occlusionTestListDirty=!0,this._drawable={shaderSourceHash:s,destroy:function(){return f.destroy()},drawCall:function(){var s=t.camera,o=s.project;f.bind(),c.setInputValue(o.matrix);var a=n.boundary,l=a[2],h=a[3],d=s.perspective.near,p=function(e){var t=e.viewPos,n=e.canvasPos,r=n[0],i=n[1];return t[2]<=-d&&r>=-10&&i>=-10&&r<=l+10&&i<=h+10};e._occlusionLayersList.forEach((function(e){e.update(r,p);var t=i.sectionPlanes.some((function(t,n){var r=t.active?Ae.planeAABB3Intersect(t.dir,t.dist,e.aabb):1,i=-1===r;return e.sectionPlanesActive[n]=0===r,i}));if(!t){var n=e.origin;A.setInputValue(Zt(s.viewMatrix,n)),f.inputSetters.setUniforms(null,{view:{far:o.far},mesh:{origin:n,renderFlags:{sectionPlanesActivePerLayer:e.sectionPlanesActive}}}),u.setInputValue(e.positionsBuf);var a=e.indicesBuf;a.bind(),r.drawElements(r.POINTS,a.numItems,a.itemType,0)}}))}}}if(this._occlusionLayersListDirty){var v=0;for(var g in this._occlusionLayers)this._occlusionLayers.hasOwnProperty(g)&&(this._occlusionLayersList[v++]=this._occlusionLayers[g]);this._occlusionLayersList.length=v,this._occlusionLayersListDirty=!1}if(this._occlusionTestListDirty){for(var m=0,y=this._occlusionLayersList.length;m<y;m++){this._occlusionLayersList[m].occlusionTestListDirty=!0}this._occlusionTestListDirty=!1}this._drawable.drawCall()}},{key:"doOcclusionTest",value:function(e){this._occlusionLayersList.forEach((function(t){for(var n=0;n<t.lenOcclusionTestList;n++){var r=2*n,i=e(t.pixels[r],t.pixels[r+1]);t.occlusionTestList[n]._setVisible(Ae.compareVec3(Xa,i))}}))}},{key:"destroy",value:function(){this.destroyed||(this._occlusionLayersList.forEach((function(e){return e.destroy()})),this._drawable&&this._drawable.destroy(),this._scene.camera.off(this._onCameraViewMatrix),this._scene.camera.off(this._onCameraProjMatrix),this._scene.canvas.off(this._onCanvasBoundary),this.destroyed=!0)}}]),e}(),Za=Ae.vec3([0,0,0]),Ja=Ae.vec4([1/4294967296,1/16777216,1/65536,1/256]),Ya=function(e){return e[0]+(e[1]<<8)+(e[2]<<16)+(e[3]<<24)},qa=function(e){return Ae.normalizeVec3(Ae.divVec3Scalar(e,Ae.MAX_INT,Ae.vec3()))},$a=function(e,t,n){return Ae.vec3([e[0]*n[0]+t[0],e[1]*n[1]+t[1],e[2]*n[2]+t[2]])},eA=function(e,t){var n=this;t=t||{};var r,i,s,o,a,A,c,u,l,h,d,f,p,v,g,m,y=new Na,_=e.canvas.canvas,b=e.canvas.gl,w=!!t.transparent,B=t.alphaDepthMask,C=new Z({}),k={},E={},F=[],x=[],U=[],I=!0,T=!0,P=!0,S=!0,D=!0,Q=!0,R=!0,O=!0,V=(r={},i={},{getRenderBuffer:function(t,n,s){var o=1===e.canvas.resolutionScale?r:i;return o[t]||(o[t]=new aa(b,n,s)),o[t]},destroy:function(){Object.values(r).forEach((function(e){return e.destroy()})),Object.values(i).forEach((function(e){return e.destroy()}))}}),L=function(e,t,n,r){var i=n.programVariables,s=i.createUniform("vec2","uViewportInv"),o=i.createUniform("float","uCameraNear"),a=i.createUniform("float","uCameraFar"),A=i.createUniform("sampler2D","uDepthTexture"),c=i.createAttribute("vec2","uv"),u=i.createVarying("vec2","vUV",(function(){return c})),l=i.createOutput("vec4","outColor"),h=i.createFragmentDefinition("getOutColor",(function(e,t){var n="getDepth";t.push("\n float ".concat(n,"(const in vec2 uv) {\n return texture(").concat(A,", uv).r;\n }\n ")),t.push(r(e,u,s,o,a,n))})),d=M(n.buildProgram(e,t,{clipPos:"vec4(2.0 * ".concat(c," - 1.0, 0.0, 1.0)"),appendFragmentOutputs:function(e){return e.push("".concat(l," = ").concat(h,"();"))}}),2),f=d[0],p=d[1];if(p)throw console.error(p.join("\n")),p;var v=new Float32Array([1,1,0,1,0,0,1,0]),g=new st(e,e.ARRAY_BUFFER,v,v.length,2,e.STATIC_DRAW),m=new Uint32Array([0,1,2,0,2,3]),y=new st(e,e.ELEMENT_ARRAY_BUFFER,m,m.length,1,e.STATIC_DRAW);return{destroy:f.destroy,bind:function(e,t,n){f.bind(),s.setInputValue([1/e[0],1/e[1]]),o.setInputValue(t.near),a.setInputValue(t.far),A.setInputValue(n),c.setInputValue(g)},draw:function(){y.bind(),e.drawElements(e.TRIANGLES,y.numItems,y.itemType,0)}}},H=(s=null,o=null,{destroy:function(){return s&&s.destroy()},render:function(e,t,n,r){var i=Math.floor(n.numSamples);if(o!==i){s&&s.destroy();var a=gr(),A=a.programVariables,c=A.createUniform("mat4","uProjectMatrix"),u=A.createUniform("mat4","uInvProjMatrix"),l=A.createUniform("bool","uPerspective"),h=A.createUniform("float","uScale"),d=A.createUniform("float","uIntensity"),f=A.createUniform("float","uBias"),p=A.createUniform("float","uKernelRadius"),v=A.createUniform("float","uMinResolution"),g=A.createUniform("float","uRandomSeed"),m=L(b,"SAOOcclusionRenderer",a,(function(e,t,n,r,s,o){return"\n #define EPSILON 1e-6\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define NUM_SAMPLES ".concat(i,"\n #define NUM_RINGS 4\n\n const vec3 packFactors = vec3(256. * 256. * 256., 256. * 256., 256.);\n\n vec4 packFloatToRGBA(const in float v) {\n vec4 r = vec4(fract(v * packFactors), v);\n r.yzw -= r.xyz / 256.;\n return r * 256. / 255.;\n }\n\n highp float rand(const in vec2 uv) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n return fract(sin(mod(dot(uv, vec2(a, b)), PI)) * c);\n }\n\n vec3 getViewPos(const in vec2 screenPos, const in float depth) {\n float near = ").concat(r,";\n float far = ").concat(s,";\n float viewZ = (").concat(l,"\n ? ((near * far) / ((far - near) * depth - far))\n : (depth * (near - far) - near));\n float clipW = ").concat(c,"[2][3] * viewZ + ").concat(c,"[3][3];\n return (").concat(u," * (clipW * vec4((vec3(screenPos, depth) - 0.5) * 2.0, 1.0))).xyz;\n }\n\n vec4 ").concat(e,"() {\n float centerDepth = ").concat(o,"(").concat(t,");\n if (centerDepth >= (1.0 - EPSILON)) {\n discard;\n }\n\n vec3 centerViewPosition = getViewPos(").concat(t,", centerDepth);\n float scaleDividedByCameraFar = ").concat(h," / ").concat(s,";\n float minResolutionMultipliedByCameraFar = ").concat(v," * ").concat(s,";\n vec3 centerViewNormal = normalize(cross(dFdx(centerViewPosition), dFdy(centerViewPosition)));\n\n vec2 radiusStep = ").concat(p," * ").concat(n," / float(NUM_SAMPLES);\n vec2 radius = radiusStep;\n const float angleStep = PI2 * float(NUM_RINGS) / float(NUM_SAMPLES);\n float angle = PI2 * rand(").concat(t," + ").concat(g,");\n\n float occlusionSum = 0.0;\n float weightSum = 0.0;\n\n for (int i = 0; i < NUM_SAMPLES; i++) {\n vec2 sampleUv = ").concat(t," + vec2(cos(angle), sin(angle)) * radius;\n radius += radiusStep;\n angle += angleStep;\n\n float sampleDepth = ").concat(o,"(sampleUv);\n if (sampleDepth >= (1.0 - EPSILON)) {\n continue;\n }\n\n vec3 sampleViewPosition = getViewPos(sampleUv, sampleDepth);\n vec3 viewDelta = sampleViewPosition - centerViewPosition;\n float scaledScreenDistance = scaleDividedByCameraFar * length(viewDelta);\n occlusionSum += max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - ").concat(f,") / (1.0 + scaledScreenDistance * scaledScreenDistance );\n weightSum += 1.0;\n }\n\n return packFloatToRGBA(1.0 - occlusionSum * ").concat(d," / weightSum);\n }")}));s={destroy:m.destroy,render:function(e,t,n,r){m.bind(e,t,r),c.setInputValue(t.matrix),u.setInputValue(t.inverseMatrix),l.setInputValue("Perspective"===t.type),h.setInputValue(n.scale*t.far/5),d.setInputValue(n.intensity),f.setInputValue(n.bias),p.setInputValue(n.kernelRadius),v.setInputValue(n.minResolution),g.setInputValue(Math.random()),m.draw()}},o=i}s.render(e,t,n,r)}}),N=(A=(a=function(e){for(var t=[],n=0;n<=17;n++)t.push(e[0]*n),t.push(e[1]*n);return new Float32Array(t)})([0,1]),c=a([1,0]),u=new Float32Array(function(e){for(var t=[],n=0;n<e;++n)t.push(n);return t}(17).map((function(e){return function(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}(e,4)}))),l=gr(),h=l.programVariables,d=h.createUniform("float","uDepthCutoff"),f=h.createUniformArray("vec2","uSampleOffsets",17),p=h.createUniformArray("float","uSampleWeights",17),v=h.createUniform("sampler2D","uOcclusionTex"),g=L(b,"SAODepthLimitedBlurRenderer",l,(function(e,t,n,r,i,s){return"\n #define EPSILON 1e-6\n\n const vec3 packFactors = vec3(256. * 256. * 256., 256. * 256., 256.);\n\n vec4 packFloatToRGBA(const in float v) {\n vec4 r = vec4(fract(v * packFactors), v);\n r.yzw -= r.xyz / 256.;\n return r * 256. / 255.;\n }\n\n float getOcclusion(const in vec2 uv) {\n vec4 v = texture(".concat(v,", uv);\n return dot(floor(v * 255.0 + 0.5) / 255.0, 255. / 256. / vec4(packFactors, 1.)); // unpackRGBAToFloat\n }\n\n float getViewZ(const in float depth) {\n return (").concat(r," * ").concat(i,") / ((").concat(i," - ").concat(r,") * depth - ").concat(i,");\n }\n\n vec4 ").concat(e,"() {\n float centerDepth = ").concat(s,"(").concat(t,");\n if (centerDepth >= (1.0 - EPSILON)) {\n discard;\n }\n\n float centerViewZ = getViewZ(centerDepth);\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = ").concat(p,"[0];\n float occlusionSum = getOcclusion(").concat(t,") * weightSum;\n\n for (int i = 1; i <= ").concat(16,"; i++) {\n float sampleWeight = ").concat(p,"[i];\n vec2 sampleUVOffset = ").concat(f,"[i] * ").concat(n,";\n\n if (! rBreak) {\n vec2 rSampleUV = ").concat(t," + sampleUVOffset;\n if (abs(centerViewZ - getViewZ(").concat(s,"(rSampleUV))) > ").concat(d,") {\n rBreak = true;\n } else {\n occlusionSum += getOcclusion(rSampleUV) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n if (! lBreak) {\n vec2 lSampleUV = ").concat(t," - sampleUVOffset;\n if (abs(centerViewZ - getViewZ(").concat(s,"(lSampleUV))) > ").concat(d,") {\n lBreak = true;\n } else {\n occlusionSum += getOcclusion(lSampleUV) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n }\n\n return packFloatToRGBA(occlusionSum / weightSum);\n }")})),{destroy:g.destroy,render:function(e,t,n,r,i){g.bind(e,t,r),d.setInputValue(.01),f.setInputValue(0===n?c:A),p.setInputValue(u),v.setInputValue(i),g.draw()}}),G=(m=null,function(){if(!m){var t=e.camera;m={get eye(){return t.eye},get far(){return t.project.far},get projMatrix(){return t.projMatrix},get viewMatrix(){return t.viewMatrix},get viewNormalMatrix(){return t.viewNormalMatrix}}}return m}),j=function(e,t){return"ortho"===e.projection?1:t/(2*Math.tan(.5*e.perspective.fov*Math.PI/180))};function W(){if(I&&(Object.values(k).forEach((function(e){var t=e.drawableListPreCull,n=0;Object.values(e.drawableMap).forEach((function(e){t[n++]=e})),t.length=n})),I=!1,T=!0),T){var e=0;Object.values(k).forEach((function(t){t.drawableListPreCull.forEach((function(t){F[e++]=t}))})),F.length=e,F.sort((function(e,t){return e.renderOrder-t.renderOrder})),T=!1,P=!0}if(P){var t=0,n=0;F.forEach((function(e){e.rebuildRenderFlags(),e.renderFlags.culled||(e.isUI?U[n++]=e:x[t++]=e)})),x.length=t,U.length=n}}this.scene=e,this._occlusionTester=null,this.capabilities={astcSupported:!!Jr(b,"WEBGL_compressed_texture_astc"),etc1Supported:!0,etc2Supported:!!Jr(b,"WEBGL_compressed_texture_etc"),dxtSupported:!!Jr(b,"WEBGL_compressed_texture_s3tc"),bptcSupported:!!Jr(b,"EXT_texture_compression_bptc"),pvrtcSupported:!(!Jr(b,"WEBGL_compressed_texture_pvrtc")&&!Jr(b,"WEBKIT_WEBGL_compressed_texture_pvrtc"))},this.setTransparentEnabled=function(e){S=e,P=!0},this.setEdgesEnabled=function(e){D=e,P=!0},this.setSAOEnabled=function(e){Q=e,P=!0},this.setPBREnabled=function(e){R=e,P=!0},this.setColorTextureEnabled=function(e){O=e,P=!0},this.needStateSort=function(){T=!0},this.shadowsDirty=function(){},this.imageDirty=function(){P=!0},this.addDrawable=function(e,t){var n=t.type;if(n){var r=k[n];r||(r={type:t.type,count:0,isStateSortable:t.isStateSortable,stateSortCompare:t.stateSortCompare,drawableMap:{},drawableListPreCull:[],drawableList:[]},k[n]=r),r.count++,r.drawableMap[e]=t,E[e]=t,I=!0}else console.error("Renderer#addDrawable() : drawable with ID "+e+" has no 'type' - ignoring")},this.removeDrawable=function(e){var t=E[e];if(t){var n=t.type,r=k[n];--r.count<=0?delete k[n]:delete r.drawableMap[e],delete E[e],I=!0}else console.error("Renderer#removeDrawable() : drawable not found with ID "+e+" - ignoring")},this.getPickID=function(e){return C.addItem(e)},this.putPickID=function(e){C.removeItem(e)},this.clear=function(t){if(b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),w)b.clearColor(1,1,1,1);else{var n=e.canvas.backgroundColorFromAmbientLight?this.lights.getAmbientColorAndIntensity():e.canvas.backgroundColor;b.clearColor(n[0],n[1],n[2],1)}b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT)},this.needsRender=function(){return P||I||T},this.render=function(t,n){W(),P&&(!function(t,n){var r=e.sao,i=Q&&r.possible&&r.numSamples>=1&&function(t){var n=e.sao,r=[b.drawingBufferWidth,b.drawingBufferHeight],i=V.getRenderBuffer("saoDepth",[],!0);i.setSize(r),i.bind(),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),y.reset(),y.pass=t,y.viewParams=G(),y.nearPlaneHeight=j(e.camera,b.drawingBufferHeight),b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),b.clearColor(0,0,0,0),b.enable(b.DEPTH_TEST),b.frontFace(b.CCW),b.enable(b.CULL_FACE),b.depthMask(!0),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),x.forEach((function(e){!e.culled&&e.visible&&e.drawDepth&&e.saoEnabled&&e.renderFlags.colorOpaque&&e.drawDepth(y)})),i.unbind();var s=i.depthTexture,o=V.getRenderBuffer("saoOcclusion");if(o.setSize(r),o.bind(),b.viewport(0,0,r[0],r[1]),b.clearColor(0,0,0,1),b.disable(b.DEPTH_TEST),b.disable(b.BLEND),b.frontFace(b.CCW),b.clear(b.COLOR_BUFFER_BIT),H.render(r,e.camera.project,n,s),o.unbind(),n.blur){var a=V.getRenderBuffer("saoOcclusion2");a.setSize(r);var A=function(t,n,i){n.bind(),b.viewport(0,0,r[0],r[1]),b.clearColor(0,0,0,1),b.enable(b.DEPTH_TEST),b.disable(b.BLEND),b.frontFace(b.CCW),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);var o=e.camera.project;N.render(r,o,i,s,t.colorTextures[0]),n.unbind()};A(o,a,0),A(a,o,1)}return o.colorTextures[0]}(t);e._lightsState.lights.forEach((function(t){if(t.castsShadow){var n=t.getShadowRenderBuf();n.bind(),y.reset(),y.backfaces=!0,y.frontface=!0,y.viewParams.viewMatrix=t.getShadowViewMatrix(),y.viewParams.projMatrix=t.getShadowProjMatrix(),y.nearPlaneHeight=j(e.camera,b.drawingBufferHeight),b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),b.clearColor(0,0,0,1),b.enable(b.DEPTH_TEST),b.disable(b.BLEND),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),Object.values(k).forEach((function(e){e.drawableList.forEach((function(e){!1!==e.visible&&e.castsShadow&&e.drawShadow&&e.renderFlags.colorOpaque&&e.drawShadow(y)}))})),n.unbind()}})),function(t,n,r){var i,s,o=[],a=[],A=[],c=[],u=[],l=[],h=[],d=[],f=[],p=[],v=[],g=[],m=[],_=[],C=[],k=[],M=e._lightsState.getAmbientColorAndIntensity();if(y.reset(),y.pass=t,y.withSAO=!1,y.pbrEnabled=R&&!!e.pbrEnabled,y.colorTextureEnabled=O&&!!e.colorTextureEnabled,y.viewParams=G(),y.nearPlaneHeight=j(e.camera,b.drawingBufferHeight),b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),w)b.clearColor(0,0,0,0);else{var E=e.canvas.backgroundColorFromAmbientLight?M:e.canvas.backgroundColor;b.clearColor(E[0],E[1],E[2],1)}b.enable(b.DEPTH_TEST),b.frontFace(b.CCW),b.enable(b.CULL_FACE),b.depthMask(!0),b.lineWidth(1),y.lineWidth=1,e.sao,y.saoParams=[b.drawingBufferWidth,b.drawingBufferHeight,e.sao.blendCutoff,e.sao.blendFactor],y.occlusionTexture=r;var F=Date.now();n&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);var I=function(t){for(var n=0,M=0,E=0,F=0,x=0,U=0,I=0,T=0,P=0,Q=0,R=0,O=0,V=0,L=0,H=0,N=0,G=0,j=t.length;G<j;G++)if(!0!==(s=t[G]).culled&&!1!==s.visible){var W=s.renderFlags;W.colorOpaque&&(s.saoEnabled&&r?o[n++]=s:s.drawColorOpaque(y)),S&&W.colorTransparent&&(A[E++]=s),W.xrayedSilhouetteTransparent&&(h[I++]=s),W.xrayedSilhouetteOpaque&&(u[x++]=s),W.highlightedSilhouetteTransparent&&(v[R++]=s),W.highlightedSilhouetteOpaque&&(f[P++]=s),W.selectedSilhouetteTransparent&&(C[H++]=s),W.selectedSilhouetteOpaque&&(m[V++]=s),s.edges&&D&&(W.edgesOpaque&&(a[M++]=s),W.edgesTransparent&&(c[F++]=s),W.selectedEdgesTransparent&&(k[N++]=s),W.selectedEdgesOpaque&&(_[L++]=s),W.xrayedEdgesTransparent&&(d[T++]=s),W.xrayedEdgesOpaque&&(l[U++]=s),W.highlightedEdgesTransparent&&(g[O++]=s),W.highlightedEdgesOpaque&&(p[Q++]=s))}if(n>0)for(y.withSAO=!0,i=0;i<n;i++)o[i].drawColorOpaque(y);if(M>0)for(i=0;i<M;i++)a[i].drawEdgesColorOpaque(y);if(x>0)for(i=0;i<x;i++)u[i].drawSilhouetteXRayed(y);if(U>0)for(i=0;i<U;i++)l[i].drawEdgesXRayed(y);if(I>0||T>0||E>0||F>0){if(b.enable(b.CULL_FACE),b.enable(b.BLEND),w?(b.blendEquation(b.FUNC_ADD),b.blendFuncSeparate(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA,b.ONE,b.ONE_MINUS_SRC_ALPHA)):(b.blendEquation(b.FUNC_ADD),b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA)),y.backfaces=!1,B||b.depthMask(!1),(E>0||F>0)&&b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA),F>0)for(i=0;i<F;i++)(s=c[i]).drawEdgesColorTransparent(y);if(E>0){var z=y.viewParams.eye,X=A.map((function(e){return{drawable:e,distSq:Ae.distVec3(e.origin||Za,z)}}));for(X.sort((function(e,t){return t.distSq-e.distSq})),i=0;i<E;i++)X[i].drawable.drawColorTransparent(y)}if(T>0)for(i=0;i<T;i++)d[i].drawEdgesXRayed(y);if(I>0)for(i=0;i<I;i++)h[i].drawSilhouetteXRayed(y);b.disable(b.BLEND),B||b.depthMask(!0)}if(P>0||Q>0){if(y.lastProgramId=null,e.highlightMaterial.glowThrough&&b.clear(b.DEPTH_BUFFER_BIT),Q>0)for(i=0;i<Q;i++)p[i].drawEdgesHighlighted(y);if(P>0)for(i=0;i<P;i++)f[i].drawSilhouetteHighlighted(y)}if(R>0||O>0||P>0){if(y.lastProgramId=null,e.selectedMaterial.glowThrough&&b.clear(b.DEPTH_BUFFER_BIT),b.enable(b.BLEND),w?(b.blendEquation(b.FUNC_ADD),b.blendFuncSeparate(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA,b.ONE,b.ONE_MINUS_SRC_ALPHA)):b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA),b.enable(b.CULL_FACE),O>0)for(i=0;i<O;i++)g[i].drawEdgesHighlighted(y);if(R>0)for(i=0;i<R;i++)v[i].drawSilhouetteHighlighted(y);b.disable(b.BLEND)}if(V>0||L>0){if(y.lastProgramId=null,e.selectedMaterial.glowThrough&&b.clear(b.DEPTH_BUFFER_BIT),L>0)for(i=0;i<L;i++)_[i].drawEdgesSelected(y);if(V>0)for(i=0;i<V;i++)m[i].drawSilhouetteSelected(y)}if(H>0||N>0){if(y.lastProgramId=null,e.selectedMaterial.glowThrough&&b.clear(b.DEPTH_BUFFER_BIT),b.enable(b.CULL_FACE),b.enable(b.BLEND),w?(b.blendEquation(b.FUNC_ADD),b.blendFuncSeparate(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA,b.ONE,b.ONE_MINUS_SRC_ALPHA)):b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA),N>0)for(i=0;i<N;i++)k[i].drawEdgesSelected(y);if(H>0)for(i=0;i<H;i++)C[i].drawSilhouetteSelected(y);b.disable(b.BLEND)}};I(x),U.length>0&&(b.clear(b.DEPTH_BUFFER_BIT),I(U));var T=Date.now(),P=he.frame;P.renderTime=(T-F)/1e3,P.drawElements=y.drawElements,P.drawArrays=y.drawArrays,P.useProgram=y.useProgram,P.bindTexture=y.bindTexture,P.bindArray=y.bindArray;for(var Q=Ga.MAX_TEXTURE_IMAGE_UNITS,V=0;V<Q;V++)b.activeTexture(b.TEXTURE0+V);b.bindTexture(b.TEXTURE_CUBE_MAP,null),b.bindTexture(b.TEXTURE_2D,null);for(var L=Ga.MAX_VERTEX_ATTRIBS,H=0;H<L;H++)b.disableVertexAttribArray(H)}(t,n,i)}(t,n),he.frame.frameCount++,P=!1)};var z,X,K,J,Y,q=function(t,n,r,i,s,o,a){a.reset(),a.backfaces=!0,a.frontface=!0,a.viewParams.eye=i,a.viewParams.projMatrix=s,a.viewParams.viewMatrix=o,a.nearPlaneHeight=j(r,b.drawingBufferHeight);var A=e.canvas.resolutionScale;a.pickClipPos=[t?2*t[0]*A/b.drawingBufferWidth-1:0,t?1-2*t[1]*A/b.drawingBufferHeight:0],a.pickClipPosInv=[b.drawingBufferWidth/n,b.drawingBufferHeight/n]};this.pick=function(){var t=Ae.vec3(),n=Ae.vec3(),r=Ae.vec4(),i=Ae.vec4(),s=Ae.vec4(),o=Ae.vec4(),a=Ae.vec4(),A=Ae.mat4(),c=Ae.mat4(),u=Ae.mat4(),l=Ae.mat4(),h=Ae.vec3([0,1,0]),d=new Qa,f=Ae.vec2(),p=Ae.vec3(),v=Ae.vec3(),g=Ae.vec3();Ae.vec3(),Ae.vec3();var m=new aa(b);m.setSize([1,1]);var w=new aa(b,[b.RGBA32I]);return w.setSize([3,3]),function(B){var k=arguments.length>1&&void 0!==arguments[1]?arguments[1]:d;k.reset(),W();var M=null,E=null,F=null,I=e.camera;if(k.pickSurface=B.pickSurface,B.canvasPos)p[0]=B.canvasPos[0],p[1]=B.canvasPos[1],M=I.viewMatrix,E=I.projMatrix,F=I.projection,f[0]=I.project.near,f[1]=I.project.far,k.canvasPos=B.canvasPos;else{if(B.matrix)M=B.matrix,E=I.projMatrix,F=I.projection,f[0]=I.project.near,f[1]=I.project.far;else{v.set(B.origin||[0,0,0]),g.set(B.direction||[0,0,1]);var T=Ae.addVec3(v,g,t),P=n;Math.abs(Ae.dotVec3(g,h))>.999999?(P[0]=0,P[1]=0,P[2]=Math.sign(g[1])):(Ae.cross3Vec3(g,h,P),Ae.cross3Vec3(P,g,P),Ae.normalizeVec3(P,P)),M=Ae.lookAtMat4v(v,T,P,c),E=I.ortho.matrix,F="ortho",f[0]=I.ortho.near,f[1]=I.ortho.far,k.origin=v,k.direction=g}p[0]=.5*_.clientWidth,p[1]=.5*_.clientHeight}m.bind();var S=function(e){return q(p,e,I,k.origin||I.eye,E||I.projMatrix,M||I.viewMatrix,y)};S(1),y.pickInvisible=!!B.pickInvisible,b.viewport(0,0,1,1),b.depthMask(!0),b.enable(b.DEPTH_TEST),b.disable(b.CULL_FACE),b.disable(b.BLEND),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);var D=B.includeEntityIds,Q=B.excludeEntityIds,R=function(e){e.forEach((function(e){e.culled||!e.visible||!e.pickable||!e.drawPickMesh||D&&!D[e.id]||Q&&Q[e.id]||e.drawPickMesh(y)}))};R(x),U.length>0&&(b.clear(b.DEPTH_BUFFER_BIT),R(U));var O=Ya(m.read(0,0)),V=O>=0&&C.items[O];if(!V)return m.unbind(),null;var L=V.delegatePickedEntity?V.delegatePickedEntity():V;if(!L)return m.unbind(),null;if(B.pickSurface)if(V.canPickTriangle&&V.canPickTriangle())V.drawPickTriangles&&(S(1),b.viewport(0,0,1,1),b.clearColor(0,0,0,0),b.enable(b.DEPTH_TEST),b.disable(b.CULL_FACE),b.disable(b.BLEND),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),V.drawPickTriangles(y),k.primIndex=3*Ya(m.read(0,0))),V.pickTriangleSurface(M,E,F,k),k.pickSurfacePrecision=!1;else if(V.canPickWorldPos&&V.canPickWorldPos()){S(1),y.viewParams.near=f[0],y.viewParams.far=f[1],b.viewport(0,0,1,1),b.clearColor(0,0,0,0),b.depthMask(!0),b.enable(b.DEPTH_TEST),b.disable(b.CULL_FACE),b.disable(b.BLEND),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),V.drawPickDepths(y);var H=Ae.dotVec4(m.read(0,0),Ja),N=(p[0]-_.clientWidth/2)/(_.clientWidth/2),G=-(p[1]-_.clientHeight/2)/(_.clientHeight/2),j=V.origin,z=Ae.inverseMat4(Ae.mulMat4(E,j?Zt(M,j,A):M,u),l),X=function(e,t){return t[0]=N,t[1]=G,t[2]=e,t[3]=1,Ae.transformVec4(z,t,t),Ae.mulVec4Scalar(t,1/t[3])},K=X(-1,r),Z=X(1,i),J=Ae.subVec3(Z,K,s),Y=Ae.addVec3(K,Ae.mulVec4Scalar(J,H,o),a);if(j&&Ae.addVec3(Y,j),k.worldPos=Y,!1!==B.pickSurfaceNormal){S(3),w.bind(),b.viewport(0,0,w.size[0],w.size[1]),b.enable(b.DEPTH_TEST),b.disable(b.CULL_FACE),b.disable(b.BLEND),b.clear(b.DEPTH_BUFFER_BIT),b.clearBufferiv(b.COLOR,0,new Int32Array([0,0,0,0])),V.drawPickNormals(y);var $=w.read(1,1,b.RGBA_INTEGER,b.INT,Int32Array,4);w.unbind(),k.worldNormal=qa($)}k.pickSurfacePrecision=!1}return m.unbind(),k.entity=L,k}}(),this.snapPick=(z=new Qa,X=function(){var e={};return function(t){if(!(t in e)){var n=new aa(b,[b.RGBA32I,b.RGBA32I,b.RGBA8UI],!0);n.setSize([2*t+1,2*t+1]),e[t]=n}return e[t]}}(),function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:z,r=t.canvasPos,i=t.origin,s=t.direction,o=t.snapRadius,a=t.snapToVertex,A=t.snapToEdge;if(!a&&!A)return this.pick({canvasPos:r,pickSurface:!0});var c=e.camera,u=o||30,l=r?c.viewMatrix:Ae.lookAtMat4v(i,Ae.addVec3(i,s,Ae.vec3()),Ae.vec3([0,1,0]),Ae.mat4());q(r,2*u,c,c.eye,c.projMatrix,l,y);var h=X(u);h.bind(),b.viewport(0,0,h.size[0],h.size[1]),b.enable(b.DEPTH_TEST),b.frontFace(b.CCW),b.disable(b.CULL_FACE),b.depthMask(!0),b.disable(b.BLEND),b.depthFunc(b.LEQUAL),b.clear(b.DEPTH_BUFFER_BIT),b.clearBufferiv(b.COLOR,0,new Int32Array([0,0,0,0])),b.clearBufferiv(b.COLOR,1,new Int32Array([0,0,0,0])),b.clearBufferuiv(b.COLOR,2,new Uint32Array([0,0,0,0])),b.drawBuffers([b.COLOR_ATTACHMENT0,b.COLOR_ATTACHMENT1,b.COLOR_ATTACHMENT2]),y.snapPickLayerParams=[],y.snapPickLayerParams.push(null),x.forEach((function(e){!e.culled&&e.visible&&e.pickable&&e.drawSnapInit&&e.drawSnapInit(y)}));var d=y.snapPickLayerParams;y.snapPickLayerParams=[],b.depthMask(!1),b.drawBuffers([b.COLOR_ATTACHMENT0]);var f=function(e){y.snapMode=e,y.snapPickLayerParams.push(null),x.forEach((function(e){!e.culled&&e.visible&&e.pickable&&e.drawSnap&&e.drawSnap(y)}))};A&&f("edge"),a&&f("vertex"),b.depthMask(!0);var p=y.snapPickLayerParams,v=function(e,t,n){var r=h.buffer.width,i=h.buffer.height,s=new t(4*r*i);return b.readBuffer(e),b.readPixels(0,0,r,i,b.RGBA_INTEGER,n,s,0),s},g=v(b.COLOR_ATTACHMENT0,Int32Array,b.INT),m=v(b.COLOR_ATTACHMENT1,Int32Array,b.INT),_=v(b.COLOR_ATTACHMENT2,Uint32Array,b.UNSIGNED_INT);h.unbind();var w=null,B=null,k=null,M=u,E=u,F=4*M+E*h.size[0]*4,U=g.slice(F,F+4),I=m.slice(F,F+4),T=_.slice(F,F+4);if(0!==U[3]){var P=d[Math.abs(U[3])%d.length];w=$a(U,P.origin,P.coordinateScale),B=qa(I),k=C.items[Ya(T)]}for(var S=[],D=0;D<g.length;D+=4){var Q=g[D+3];if(Q>0){var R=Math.floor(D/4),O=h.size[0],V=R%O-Math.floor(O/2),L=Math.floor(R/O)-Math.floor(O/2);S.push({dist:Ae.lenVec2([V,L]),isVertex:a&&A?Q>p.length/2:a,result:g.subarray(D,D+4),normal:m.subarray(D,D+4),id:_.subarray(D,D+4)})}}var H=function(e){return e&&e.delegatePickedEntity?e.delegatePickedEntity():e};if(S.length>0){var N=S.reduce((function(e,t){return(e.isVertex-t.isVertex||t.dist-e.dist)>0?e:t})),G=N.result,j=p[G[3]],W=$a(G,j.origin,j.coordinateScale),K=c.projectWorldPos(W);return n.reset(),n.snappedToEdge=!N.isVertex,n.snappedToVertex=N.isVertex,n.worldPos=W,n.worldNormal=qa(N.normal),n.entity=H(C.items[Ya(N.id)]),n.canvasPos=r||w&&c.projectWorldPos(w)||K,n.snappedCanvasPos=K,n}return w?(n.reset(),n.snappedToEdge=!1,n.snappedToVertex=!1,n.worldPos=w,n.worldNormal=B,n.entity=H(k),n.canvasPos=r||c.projectWorldPos(w),n.snappedCanvasPos=r,n):null}),this.addMarker=function(t){this._occlusionTester=this._occlusionTester||new Ka(e),this._occlusionTester.addMarker(t),e.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){W();var t=V.getRenderBuffer("occlusionReadPix");if(t&&(t.setSize([b.drawingBufferWidth,b.drawingBufferHeight]),t.bind()),y.reset(),y.backfaces=!0,y.frontface=!0,y.viewParams=G(),y.nearPlaneHeight=j(e.camera,b.drawingBufferHeight),b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),b.clearColor(0,0,0,0),b.enable(b.DEPTH_TEST),b.disable(b.CULL_FACE),b.disable(b.BLEND),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),x.forEach((function(e){!e.culled&&e.visible&&e.pickable&&e.drawOcclusion&&e.drawOcclusion(y)})),this._occlusionTester.drawMarkers(),t){var n=e.canvas.resolutionScale;this._occlusionTester.doOcclusionTest((function(e,r){return t.read(Math.round(n*e),Math.round(n*r))})),t.unbind()}}},this.snapshot=(K=!1,J=new aa(b),Y=null,{readPixels:function(e,t,r){J.bind(),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),P=!0,n.render();for(var i=0;i<r;i++){var s=2*i,o=4*i,a=J.read(e[s],e[s+1]);t[o]=a[0],t[o+1]=a[1],t[o+2]=a[2],t[o+3]=a[3]}J.unbind(),P=!0},beginSnapshot:function(){J.setSize([b.drawingBufferWidth,b.drawingBufferHeight]),J.bind(),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),K=!0},renderSnapshotToCanvas:function(){var e=J.buffer.width,t=J.buffer.height;return Y&&Y.width===e&&Y.height===t||(Y=function(){var n=document.createElement("canvas"),r=n.getContext("2d");n.width=e,n.height=t;var i=new Uint8Array(e*t*4),s=r.createImageData(e,t);return{width:e,height:t,getUpdatedCanvas:function(){b.readPixels(0,0,e,t,b.RGBA,b.UNSIGNED_BYTE,i);for(var o=Math.floor(t/2),a=4*e,A=new Uint8Array(a),c=0;c<o;++c){var u=c*a,l=(t-c-1)*a;A.set(i.subarray(u,u+a)),i.copyWithin(u,l,l+a),i.set(A,l)}return s.data.set(i),r.resetTransform(),r.putImageData(s,0,0),n}}}()),K&&(b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),P=!0,n.render(),P=!0),Y.getUpdatedCanvas()},endSnapshot:function(){K&&(J.unbind(),K=!1),P=!0,n.render()}}),this.destroy=function(){k={},E={},V.destroy(),H.destroy(),N.destroy(),this._occlusionTester&&this._occlusionTester.destroy()}},tA=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)).KEY_BACKSPACE=8,r.KEY_TAB=9,r.KEY_ENTER=13,r.KEY_SHIFT=16,r.KEY_CTRL=17,r.KEY_ALT=18,r.KEY_PAUSE_BREAK=19,r.KEY_CAPS_LOCK=20,r.KEY_ESCAPE=27,r.KEY_PAGE_UP=33,r.KEY_PAGE_DOWN=34,r.KEY_END=35,r.KEY_HOME=36,r.KEY_LEFT_ARROW=37,r.KEY_UP_ARROW=38,r.KEY_RIGHT_ARROW=39,r.KEY_DOWN_ARROW=40,r.KEY_INSERT=45,r.KEY_DELETE=46,r.KEY_NUM_0=48,r.KEY_NUM_1=49,r.KEY_NUM_2=50,r.KEY_NUM_3=51,r.KEY_NUM_4=52,r.KEY_NUM_5=53,r.KEY_NUM_6=54,r.KEY_NUM_7=55,r.KEY_NUM_8=56,r.KEY_NUM_9=57,r.KEY_A=65,r.KEY_B=66,r.KEY_C=67,r.KEY_D=68,r.KEY_E=69,r.KEY_F=70,r.KEY_G=71,r.KEY_H=72,r.KEY_I=73,r.KEY_J=74,r.KEY_K=75,r.KEY_L=76,r.KEY_M=77,r.KEY_N=78,r.KEY_O=79,r.KEY_P=80,r.KEY_Q=81,r.KEY_R=82,r.KEY_S=83,r.KEY_T=84,r.KEY_U=85,r.KEY_V=86,r.KEY_W=87,r.KEY_X=88,r.KEY_Y=89,r.KEY_Z=90,r.KEY_LEFT_WINDOW=91,r.KEY_RIGHT_WINDOW=92,r.KEY_SELECT_KEY=93,r.KEY_NUMPAD_0=96,r.KEY_NUMPAD_1=97,r.KEY_NUMPAD_2=98,r.KEY_NUMPAD_3=99,r.KEY_NUMPAD_4=100,r.KEY_NUMPAD_5=101,r.KEY_NUMPAD_6=102,r.KEY_NUMPAD_7=103,r.KEY_NUMPAD_8=104,r.KEY_NUMPAD_9=105,r.KEY_MULTIPLY=106,r.KEY_ADD=107,r.KEY_SUBTRACT=109,r.KEY_DECIMAL_POINT=110,r.KEY_DIVIDE=111,r.KEY_F1=112,r.KEY_F2=113,r.KEY_F3=114,r.KEY_F4=115,r.KEY_F5=116,r.KEY_F6=117,r.KEY_F7=118,r.KEY_F8=119,r.KEY_F9=120,r.KEY_F10=121,r.KEY_F11=122,r.KEY_F12=123,r.KEY_NUM_LOCK=144,r.KEY_SCROLL_LOCK=145,r.KEY_SEMI_COLON=186,r.KEY_EQUAL_SIGN=187,r.KEY_COMMA=188,r.KEY_DASH=189,r.KEY_PERIOD=190,r.KEY_FORWARD_SLASH=191,r.KEY_GRAVE_ACCENT=192,r.KEY_OPEN_BRACKET=219,r.KEY_BACK_SLASH=220,r.KEY_CLOSE_BRACKET=221,r.KEY_SINGLE_QUOTE=222,r.KEY_SPACE=32,r.MOUSE_LEFT_BUTTON=260,r.MOUSE_MIDDLE_BUTTON=261,r.MOUSE_RIGHT_BUTTON=262,r.element=i.element,r.altDown=!1,r.ctrlDown=!1,r.mouseDownLeft=!1,r.mouseDownMiddle=!1,r.mouseDownRight=!1,r.keyDown=[],r.enabled=!0,r.keyboardEnabled=!0,r.mouseover=!1,r.mouseCanvasPos=Ae.vec2(),r._keyboardEventsElement=i.keyboardEventsElement||document,r._bindEvents(),r}return I(n,[{key:"_bindEvents",value:function(){var e=this;if(!this._eventsBound){this._keyboardEventsElement.addEventListener("keydown",this._keyDownListener=function(t){e.enabled&&e.keyboardEnabled&&"INPUT"!==t.target.tagName&&"TEXTAREA"!==t.target.tagName&&(t.keyCode===e.KEY_CTRL?e.ctrlDown=!0:t.keyCode===e.KEY_ALT?e.altDown=!0:t.keyCode===e.KEY_SHIFT&&(e.shiftDown=!0),e.keyDown[t.keyCode]=!0,e.fire("keydown",t.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=function(t){e.enabled&&e.keyboardEnabled&&"INPUT"!==t.target.tagName&&"TEXTAREA"!==t.target.tagName&&(t.keyCode===e.KEY_CTRL?e.ctrlDown=!1:t.keyCode===e.KEY_ALT?e.altDown=!1:t.keyCode===e.KEY_SHIFT&&(e.shiftDown=!1),e.keyDown[t.keyCode]=!1,e.fire("keyup",t.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=function(t){e.enabled&&(e.mouseover=!0,e._getMouseCanvasPos(t),e.fire("mouseenter",e.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=function(t){e.enabled&&(e.mouseover=!1,e._getMouseCanvasPos(t),e.fire("mouseleave",e.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=function(t){if(e.enabled){switch(t.which){case 1:e.mouseDownLeft=!0;break;case 2:e.mouseDownMiddle=!0;break;case 3:e.mouseDownRight=!0}e._getMouseCanvasPos(t),e.element.focus(),e.fire("mousedown",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=function(t){if(e.enabled){switch(t.which){case 1:e.mouseDownLeft=!1;break;case 2:e.mouseDownMiddle=!1;break;case 3:e.mouseDownRight=!1}e.fire("mouseup",e.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=function(t){if(e.enabled){switch(t.which){case 1:case 3:e.mouseDownLeft=!1,e.mouseDownRight=!1;break;case 2:e.mouseDownMiddle=!1}e._getMouseCanvasPos(t),e.fire("click",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=function(t){if(e.enabled){switch(t.which){case 1:case 3:e.mouseDownLeft=!1,e.mouseDownRight=!1;break;case 2:e.mouseDownMiddle=!1}e._getMouseCanvasPos(t),e.fire("dblclick",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}});var t=this.scene.tickify((function(){return e.fire("mousemove",e.mouseCanvasPos,!0)}));this.element.addEventListener("mousemove",this._mouseMoveListener=function(n){e.enabled&&(e._getMouseCanvasPos(n),t(),e.mouseover&&n.preventDefault())}),this.element.addEventListener("contextmenu",this._contextmenuListener=function(t){e.enabled&&(e._getMouseCanvasPos(t),e.fire("contextmenu",e.mouseCanvasPos,!0))});var n=this.scene.tickify((function(t){e.fire("mousewheel",t,!0)}));this.element.addEventListener("wheel",this._mouseWheelListener=function(t,r){if(e.enabled){var i=Math.max(-1,Math.min(1,40*-t.deltaY));n(i)}},{passive:!0});var r,i;this.on("mousedown",(function(e){r=e[0],i=e[1]})),this.on("mouseup",(function(t){r>=t[0]-2&&r<=t[0]+2&&i>=t[1]-2&&i<=t[1]+2&&e.fire("mouseclicked",t,!0)})),this.element.addEventListener("touchstart",this._touchstartListener=function(t){e.enabled&&p(t.changedTouches).forEach((function(t){e.fire("touchstart",[t.identifier,e._getTouchCanvasPos(t)],!0)}))}),this.element.addEventListener("touchend",this._touchendListener=function(t){e.enabled&&p(t.changedTouches).forEach((function(t){e.fire("touchend",[t.identifier,e._getTouchCanvasPos(t)],!0)}))}),this._eventsBound=!0}}},{key:"_unbindEvents",value:function(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("contextmenu",this._contextmenuListener),this.element.removeEventListener("wheel",this._mouseWheelListener),this.element.removeEventListener("touchstart",this._touchstartListener),this.element.removeEventListener("touchend",this._touchendListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}},{key:"_getTouchCanvasPos",value:function(e){for(var t=e.target,n=0,r=0;t.offsetParent;)n+=t.offsetLeft,r+=t.offsetTop,t=t.offsetParent;return[e.pageX-n,e.pageY-r]}},{key:"_getMouseCanvasPos",value:function(e){if(e){var t=e.target.getBoundingClientRect();this.mouseCanvasPos[0]=e.clientX-t.left,this.mouseCanvasPos[1]=e.clientY-t.top}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}},{key:"setEnabled",value:function(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}},{key:"getEnabled",value:function(){return this.enabled}},{key:"setKeyboardEnabled",value:function(e){this.keyboardEnabled=e}},{key:"getKeyboardEnabled",value:function(){return this.keyboardEnabled}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._unbindEvents()}}]),n}(),nA=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({boundary:[0,0,100,100]}),r.boundary=i.boundary,r.autoBoundary=i.autoBoundary,r}return I(n,[{key:"type",get:function(){return"Viewport"}},{key:"boundary",get:function(){return this._state.boundary},set:function(e){if(!this._autoBoundary){if(!e){var t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}},{key:"autoBoundary",get:function(){return this._autoBoundary},set:function(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){var t=e[2],n=e[3];this._state.boundary=[0,0,t,n],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),rA=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)).camera=e,r._state=new it({matrix:Ae.mat4(),inverseMatrix:Ae.mat4(),transposedMatrix:Ae.mat4(),near:.1,far:1e4}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r._fov=60,r._canvasResized=r.scene.canvas.on("boundary",r._needUpdate,w(r)),r.fov=i.fov,r.fovAxis=i.fovAxis,r.near=i.near,r.far=i.far,r}return I(n,[{key:"type",get:function(){return"Perspective"}},{key:"_update",value:function(){var e=this.scene.canvas.boundary,t=e[2]/e[3],n=this._fovAxis,r=this._fov;("x"===n||"min"===n&&t<1||"max"===n&&t>1)&&(r/=t),r=Math.min(r,120),Ae.perspectiveMat4(r*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}},{key:"fov",get:function(){return this._fov},set:function(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}},{key:"fovAxis",get:function(){return this._fovAxis},set:function(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}},{key:"near",get:function(){return this._state.near},set:function(e){var t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}},{key:"far",get:function(){return this._state.far},set:function(e){var t=null!=e?e:1e4;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Ae.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Ae.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var s=this.scene.canvas.canvas,o=s.offsetWidth/2,a=s.offsetHeight/2;return n[0]=(e[0]-o)/o,n[1]=(e[1]-a)/a,n[2]=t,n[3]=1,Ae.mulMat4v4(this.inverseMatrix,n,r),Ae.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Ae.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}]),n}(),iA=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)).camera=e,r._state=new it({matrix:Ae.mat4(),inverseMatrix:Ae.mat4(),transposedMatrix:Ae.mat4(),near:.1,far:1e4}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r.scale=i.scale,r.near=i.near,r.far=i.far,r._onCanvasBoundary=r.scene.canvas.on("boundary",r._needUpdate,w(r)),r}return I(n,[{key:"type",get:function(){return"Ortho"}},{key:"_update",value:function(){var e,t,n,r,i=this.scene,s=.5*this._scale,o=i.canvas.boundary,a=o[2],A=o[3],c=a/A;a>A?(e=-s,t=s,n=s/c,r=-s/c):(e=-s*c,t=s*c,n=s,r=-s),Ae.orthoMat4c(e,t,r,n,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"scale",get:function(){return this._scale},set:function(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}},{key:"near",get:function(){return this._state.near},set:function(e){var t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}},{key:"far",get:function(){return this._state.far},set:function(e){var t=null!=e?e:1e4;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Ae.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Ae.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var s=this.scene.canvas.canvas,o=s.offsetWidth/2,a=s.offsetHeight/2;return n[0]=(e[0]-o)/o,n[1]=(e[1]-a)/a,n[2]=t,n[3]=1,Ae.mulMat4v4(this.inverseMatrix,n,r),Ae.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Ae.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}]),n}(),sA=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)).camera=e,r._state=new it({matrix:Ae.mat4(),inverseMatrix:Ae.mat4(),transposedMatrix:Ae.mat4(),near:.1,far:1e4}),r._left=-1,r._right=1,r._bottom=-1,r._top=1,r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r.left=i.left,r.right=i.right,r.bottom=i.bottom,r.top=i.top,r.near=i.near,r.far=i.far,r}return I(n,[{key:"type",get:function(){return"Frustum"}},{key:"_update",value:function(){Ae.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"left",get:function(){return this._left},set:function(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}},{key:"right",get:function(){return this._right},set:function(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}},{key:"top",get:function(){return this._top},set:function(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}},{key:"bottom",get:function(){return this._bottom},set:function(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}},{key:"near",get:function(){return this._state.near},set:function(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}},{key:"far",get:function(){return this._state.far},set:function(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Ae.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Ae.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var s=this.scene.canvas.canvas,o=s.offsetWidth/2,a=s.offsetHeight/2;return n[0]=(e[0]-o)/o,n[1]=(e[1]-a)/a,n[2]=t,n[3]=1,Ae.mulMat4v4(this.inverseMatrix,n,r),Ae.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Ae.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy(),v(C(n.prototype),"destroy",this).call(this)}}]),n}(),oA=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)).camera=e,r._state=new it({matrix:Ae.mat4(),inverseMatrix:Ae.mat4(),transposedMatrix:Ae.mat4()}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!1,r.matrix=i.matrix,r}return I(n,[{key:"type",get:function(){return"CustomProjection"}},{key:"matrix",get:function(){return this._state.matrix},set:function(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Ae.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Ae.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var s=this.scene.canvas.canvas,o=s.offsetWidth/2,a=s.offsetHeight/2;return n[0]=(e[0]-o)/o,n[1]=(e[1]-a)/a,n[2]=t,n[3]=1,Ae.mulMat4v4(this.inverseMatrix,n,r),Ae.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Ae.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),aA=Ae.vec3(),AA=Ae.vec3(),cA=Ae.vec3(),uA=Ae.vec3(),lA=Ae.vec3(),hA=Ae.vec3(),dA=Ae.vec4(),fA=Ae.vec4(),pA=Ae.vec4(),vA=Ae.mat4(),gA=Ae.mat4(),mA=Ae.vec3(),yA=Ae.vec3(),_A=Ae.vec3(),bA=Ae.vec3(),wA=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({offsetEyeFromLook:!0,deviceMatrix:Ae.mat4(),hasDeviceMatrix:!1,matrix:Ae.mat4(),normalMatrix:Ae.mat4(),inverseMatrix:Ae.mat4()}),r._perspective=new rA(w(r)),r._ortho=new iA(w(r)),r._frustum=new sA(w(r)),r._customProjection=new oA(w(r)),r._project=r._perspective,r._eye=Ae.vec3([0,0,10]),r._look=Ae.vec3([0,0,0]),r._up=Ae.vec3([0,1,0]),r._worldUp=Ae.vec3([0,1,0]),r._worldRight=Ae.vec3([1,0,0]),r._worldForward=Ae.vec3([0,0,-1]),r.deviceMatrix=i.deviceMatrix,r.eye=i.eye,r.look=i.look,r.up=i.up,r.worldAxis=i.worldAxis,r.gimbalLock=i.gimbalLock,r.constrainPitch=i.constrainPitch,r.projection=i.projection,r._perspective.on("matrix",(function(){"perspective"===r._projectionType&&r.fire("projMatrix",r._perspective.matrix)})),r._ortho.on("matrix",(function(){"ortho"===r._projectionType&&r.fire("projMatrix",r._ortho.matrix)})),r._frustum.on("matrix",(function(){"frustum"===r._projectionType&&r.fire("projMatrix",r._frustum.matrix)})),r._customProjection.on("matrix",(function(){"customProjection"===r._projectionType&&r.fire("projMatrix",r._customProjection.matrix)})),r}return I(n,[{key:"type",get:function(){return"Camera"}},{key:"_update",value:function(){var e,t=this._state;"ortho"===this.projection&&this._state.offsetEyeFromLook?(Ae.subVec3(this._eye,this._look,mA),Ae.normalizeVec3(mA,yA),Ae.mulVec3Scalar(yA,1e3,_A),Ae.addVec3(this._look,_A,bA),e=bA):e=this._eye,t.hasDeviceMatrix?(Ae.lookAtMat4v(e,this._look,this._up,gA),Ae.mulMat4(t.deviceMatrix,gA,t.matrix)):Ae.lookAtMat4v(e,this._look,this._up,t.matrix),Ae.inverseMat4(this._state.matrix,this._state.inverseMatrix),Ae.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}},{key:"orbitYaw",value:function(e){var t=Ae.subVec3(this._eye,this._look,aA);Ae.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,vA),t=Ae.transformPoint3(vA,t,AA),this.eye=Ae.addVec3(this._look,t,cA),this.up=Ae.transformPoint3(vA,this._up,uA)}},{key:"orbitPitch",value:function(e){if(!(this._constrainPitch&&(e=Ae.dotVec3(this._up,this._worldUp)/Ae.DEGTORAD)<1)){var t=Ae.subVec3(this._eye,this._look,aA),n=Ae.cross3Vec3(Ae.normalizeVec3(t,AA),Ae.normalizeVec3(this._up,cA));Ae.rotationMat4v(.0174532925*e,n,vA),t=Ae.transformPoint3(vA,t,uA),this.up=Ae.transformPoint3(vA,this._up,lA),this.eye=Ae.addVec3(t,this._look,hA)}}},{key:"yaw",value:function(e){var t=Ae.subVec3(this._look,this._eye,aA);Ae.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,vA),t=Ae.transformPoint3(vA,t,AA),this.look=Ae.addVec3(t,this._eye,cA),this._gimbalLock&&(this.up=Ae.transformPoint3(vA,this._up,uA))}},{key:"pitch",value:function(e){if(!(this._constrainPitch&&(e=Ae.dotVec3(this._up,this._worldUp)/Ae.DEGTORAD)<1)){var t=Ae.subVec3(this._look,this._eye,aA),n=Ae.cross3Vec3(Ae.normalizeVec3(t,AA),Ae.normalizeVec3(this._up,cA));Ae.rotationMat4v(.0174532925*e,n,vA),this.up=Ae.transformPoint3(vA,this._up,hA),t=Ae.transformPoint3(vA,t,uA),this.look=Ae.addVec3(t,this._eye,lA)}}},{key:"pan",value:function(e){var t,n=Ae.subVec3(this._eye,this._look,aA),r=[0,0,0];if(0!==e[0]){var i=Ae.cross3Vec3(Ae.normalizeVec3(n,[]),Ae.normalizeVec3(this._up,AA));t=Ae.mulVec3Scalar(i,e[0]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]}0!==e[1]&&(t=Ae.mulVec3Scalar(Ae.normalizeVec3(this._up,cA),e[1]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]),0!==e[2]&&(t=Ae.mulVec3Scalar(Ae.normalizeVec3(n,uA),e[2]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]),this.eye=Ae.addVec3(this._eye,r,lA),this.look=Ae.addVec3(this._look,r,hA)}},{key:"zoom",value:function(e){var t=Ae.subVec3(this._eye,this._look,aA),n=Math.abs(Ae.lenVec3(t,AA)),r=Math.abs(n+e);if(!(r<.5)){var i=Ae.normalizeVec3(t,cA);this.eye=Ae.addVec3(this._look,Ae.mulVec3Scalar(i,r),uA)}}},{key:"eye",get:function(){return this._eye},set:function(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}},{key:"look",get:function(){return this._look},set:function(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}},{key:"up",get:function(){return this._up},set:function(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}},{key:"deviceMatrix",get:function(){return this._state.deviceMatrix},set:function(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}},{key:"worldAxis",get:function(){return this._worldAxis},set:function(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=Ae.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}},{key:"worldUp",get:function(){return this._worldUp}},{key:"xUp",get:function(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}},{key:"yUp",get:function(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}},{key:"zUp",get:function(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}},{key:"worldRight",get:function(){return this._worldRight}},{key:"worldForward",get:function(){return this._worldForward}},{key:"gimbalLock",get:function(){return this._gimbalLock},set:function(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}},{key:"constrainPitch",set:function(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}},{key:"eyeLookDist",get:function(){return Ae.lenVec3(Ae.subVec3(this._look,this._eye,aA))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"viewMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"normalMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}},{key:"viewNormalMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}},{key:"inverseViewMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}},{key:"projMatrix",get:function(){return this[this.projection].matrix}},{key:"perspective",get:function(){return this._perspective}},{key:"ortho",get:function(){return this._ortho}},{key:"frustum",get:function(){return this._frustum}},{key:"customProjection",get:function(){return this._customProjection}},{key:"projection",get:function(){return this._projectionType},set:function(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}},{key:"project",get:function(){return this._project}},{key:"offsetEyeFromLook",get:function(){return this._state.offsetEyeFromLook},set:function(e){this._state.offsetEyeFromLook=e,this._needUpdate(0)}},{key:"projectWorldPos",value:function(e){var t=dA,n=fA,r=pA;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,Ae.mulMat4v4(this.viewMatrix,t,n),Ae.mulMat4v4(this.projMatrix,n,r),Ae.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1;var i=this.scene.canvas.canvas,s=i.offsetWidth/2,o=i.offsetHeight/2;return[r[0]*s+s,r[1]*o+o]}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),BA={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}},CA=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))._units="meters",r._scale=1,r._origin=Ae.vec3([0,0,0]),r.units=i.units,r.scale=i.scale,r.origin=i.origin,r}return I(n,[{key:"unitsInfo",get:function(){return BA}},{key:"units",get:function(){return this._units},set:function(e){e||(e="meters"),BA[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}},{key:"scale",get:function(){return this._scale},set:function(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}},{key:"origin",get:function(){return this._origin},set:function(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}},{key:"worldToRealPos",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.vec3(3);t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}},{key:"realToWorldPos",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.vec3(3);return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}]),n}(),kA=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))._supported=Ga.SUPPORTED_EXTENSIONS.OES_standard_derivatives,r.enabled=i.enabled,r.kernelRadius=i.kernelRadius,r.intensity=i.intensity,r.bias=i.bias,r.scale=i.scale,r.minResolution=i.minResolution,r.numSamples=i.numSamples,r.blur=i.blur,r.blendCutoff=i.blendCutoff,r.blendFactor=i.blendFactor,r}return I(n,[{key:"supported",get:function(){return this._supported}},{key:"enabled",get:function(){return this._enabled},set:function(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}},{key:"possible",get:function(){if(!this._supported)return!1;if(!this._enabled)return!1;var e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}},{key:"active",get:function(){return this._active}},{key:"kernelRadius",get:function(){return this._kernelRadius},set:function(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}},{key:"intensity",get:function(){return this._intensity},set:function(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}},{key:"bias",get:function(){return this._bias},set:function(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}},{key:"scale",get:function(){return this._scale},set:function(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}},{key:"minResolution",get:function(){return this._minResolution},set:function(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}},{key:"numSamples",get:function(){return this._numSamples},set:function(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}},{key:"blur",get:function(){return this._blur},set:function(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}},{key:"blendCutoff",get:function(){return this._blendCutoff},set:function(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}},{key:"blendFactor",get:function(){return this._blendFactor},set:function(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this)}}]),n}(),MA=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)).sliceColor=i.sliceColor,r.sliceThickness=i.sliceThickness,r}return I(n,[{key:"sliceThickness",get:function(){return this._sliceThickness},set:function(e){null==e&&(e=0),this._sliceThickness!==e&&(this._sliceThickness=e,this.glRedraw())}},{key:"sliceColor",get:function(){return this._sliceColor},set:function(e){null==e&&(e=[0,0,0,1]),this._sliceColor!==e&&(this._sliceColor=e,this.glRedraw())}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this)}}]),n}(),EA={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}},FA=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:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),i.preset?(r.preset=i.preset,void 0!==i.pointSize&&(r.pointSize=i.pointSize),void 0!==i.roundPoints&&(r.roundPoints=i.roundPoints),void 0!==i.perspectivePoints&&(r.perspectivePoints=i.perspectivePoints),void 0!==i.minPerspectivePointSize&&(r.minPerspectivePointSize=i.minPerspectivePointSize),void 0!==i.maxPerspectivePointSize&&(r.maxPerspectivePointSize=i.minPerspectivePointSize)):(r._preset="default",r.pointSize=i.pointSize,r.roundPoints=i.roundPoints,r.perspectivePoints=i.perspectivePoints,r.minPerspectivePointSize=i.minPerspectivePointSize,r.maxPerspectivePointSize=i.maxPerspectivePointSize),r.filterIntensity=i.filterIntensity,r.minIntensity=i.minIntensity,r.maxIntensity=i.maxIntensity,r}return I(n,[{key:"type",get:function(){return"PointsMaterial"}},{key:"presets",get:function(){return EA}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||2,this.glRedraw()}},{key:"roundPoints",get:function(){return this._state.roundPoints},set:function(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"perspectivePoints",get:function(){return this._state.perspectivePoints},set:function(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"minPerspectivePointSize",get:function(){return this._state.minPerspectivePointSize},set:function(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}},{key:"maxPerspectivePointSize",get:function(){return this._state.maxPerspectivePointSize},set:function(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}},{key:"filterIntensity",get:function(){return this._state.filterIntensity},set:function(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"minIntensity",get:function(){return this._state.minIntensity},set:function(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}},{key:"maxIntensity",get:function(){return this._state.maxIntensity},set:function(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=EA[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(EA).join(", "))}}},{key:"hash",get:function(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),xA={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}},UA=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:"LinesMaterial",lineWidth:null}),i.preset?(r.preset=i.preset,void 0!==i.lineWidth&&(r.lineWidth=i.lineWidth)):(r._preset="default",r.lineWidth=i.lineWidth),r}return I(n,[{key:"type",get:function(){return"LinesMaterial"}},{key:"presets",get:function(){return xA}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=xA[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(xA).join(", "))}}},{key:"hash",get:function(){return[""+this.lineWidth].join(";")}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}();function IA(e,t){var n,r,i,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2,o=t&&t.length,a=o?t[0]*s:e.length,A=TA(e,0,a,s,!0),c=[];if(!A||A.next===A.prev)return c;if(o&&(A=VA(e,t,A,s)),e.length>80*s){n=1/0,r=1/0;for(var u=-1/0,l=-1/0,h=s;h<a;h+=s){var d=e[h],f=e[h+1];d<n&&(n=d),f<r&&(r=f),d>u&&(u=d),f>l&&(l=f)}i=0!==(i=Math.max(u-n,l-r))?32767/i:0}return SA(A,c,s,n,r,i,0),c}function TA(e,t,n,r,i){var s;if(i===function(e,t,n,r){for(var i=0,s=t,o=n-r;s<n;s+=r)i+=(e[o]-e[s])*(e[s+1]+e[o+1]),o=s;return i}(e,t,n,r)>0)for(var o=t;o<n;o+=r)s=tc(o/r|0,e[o],e[o+1],s);else for(var a=n-r;a>=t;a-=r)s=tc(a/r|0,e[a],e[a+1],s);return s&&ZA(s,s.next)&&(nc(s),s=s.next),s}function PA(e,t){if(!e)return e;t||(t=e);var n,r=e;do{if(n=!1,r.steiner||!ZA(r,r.next)&&0!==KA(r.prev,r,r.next))r=r.next;else{if(nc(r),(r=t=r.prev)===r.next)break;n=!0}}while(n||r!==t);return t}function SA(e,t,n,r,i,s,o){if(e){!o&&s&&function(e,t,n,r){var i=e;do{0===i.z&&(i.z=GA(i.x,i.y,t,n,r)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next}while(i!==e);i.prevZ.nextZ=null,i.prevZ=null,function(e){var t,n=1;do{var r=e,i=void 0;e=null;var s=null;for(t=0;r;){t++;for(var o=r,a=0,A=0;A<n&&(a++,o=o.nextZ);A++);for(var c=n;a>0||c>0&&o;)0!==a&&(0===c||!o||r.z<=o.z)?(i=r,r=r.nextZ,a--):(i=o,o=o.nextZ,c--),s?s.nextZ=i:e=i,i.prevZ=s,s=i;r=o}s.nextZ=null,n*=2}while(t>1)}(i)}(e,r,i,s);for(var a=e;e.prev!==e.next;){var A=e.prev,c=e.next;if(s?QA(e,r,i,s):DA(e))t.push(A.i,e.i,c.i),nc(e),e=c.next,a=c.next;else if((e=c)===a){o?1===o?SA(e=RA(PA(e),t),t,n,r,i,s,2):2===o&&OA(e,t,n,r,i,s):SA(PA(e),t,n,r,i,s,1);break}}}}function DA(e){var t=e.prev,n=e,r=e.next;if(KA(t,n,r)>=0)return!1;for(var i=t.x,s=n.x,o=r.x,a=t.y,A=n.y,c=r.y,u=Math.min(i,s,o),l=Math.min(a,A,c),h=Math.max(i,s,o),d=Math.max(a,A,c),f=r.next;f!==t;){if(f.x>=u&&f.x<=h&&f.y>=l&&f.y<=d&&zA(i,a,s,A,o,c,f.x,f.y)&&KA(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function QA(e,t,n,r){var i=e.prev,s=e,o=e.next;if(KA(i,s,o)>=0)return!1;for(var a=i.x,A=s.x,c=o.x,u=i.y,l=s.y,h=o.y,d=Math.min(a,A,c),f=Math.min(u,l,h),p=Math.max(a,A,c),v=Math.max(u,l,h),g=GA(d,f,t,n,r),m=GA(p,v,t,n,r),y=e.prevZ,_=e.nextZ;y&&y.z>=g&&_&&_.z<=m;){if(y.x>=d&&y.x<=p&&y.y>=f&&y.y<=v&&y!==i&&y!==o&&zA(a,u,A,l,c,h,y.x,y.y)&&KA(y.prev,y,y.next)>=0)return!1;if(y=y.prevZ,_.x>=d&&_.x<=p&&_.y>=f&&_.y<=v&&_!==i&&_!==o&&zA(a,u,A,l,c,h,_.x,_.y)&&KA(_.prev,_,_.next)>=0)return!1;_=_.nextZ}for(;y&&y.z>=g;){if(y.x>=d&&y.x<=p&&y.y>=f&&y.y<=v&&y!==i&&y!==o&&zA(a,u,A,l,c,h,y.x,y.y)&&KA(y.prev,y,y.next)>=0)return!1;y=y.prevZ}for(;_&&_.z<=m;){if(_.x>=d&&_.x<=p&&_.y>=f&&_.y<=v&&_!==i&&_!==o&&zA(a,u,A,l,c,h,_.x,_.y)&&KA(_.prev,_,_.next)>=0)return!1;_=_.nextZ}return!0}function RA(e,t){var n=e;do{var r=n.prev,i=n.next.next;!ZA(r,i)&&JA(r,n,n.next,i)&&$A(r,i)&&$A(i,r)&&(t.push(r.i,n.i,i.i),nc(n),nc(n.next),n=e=i),n=n.next}while(n!==e);return PA(n)}function OA(e,t,n,r,i,s){var o=e;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&XA(o,a)){var A=ec(o,a);return o=PA(o,o.next),A=PA(A,A.next),SA(o,t,n,r,i,s,0),void SA(A,t,n,r,i,s,0)}a=a.next}o=o.next}while(o!==e)}function VA(e,t,n,r){for(var i=[],s=0,o=t.length;s<o;s++){var a=TA(e,t[s]*r,s<o-1?t[s+1]*r:e.length,r,!1);a===a.next&&(a.steiner=!0),i.push(jA(a))}i.sort(LA);for(var A=0;A<i.length;A++)n=HA(i[A],n);return n}function LA(e,t){var n=e.x-t.x;0===n&&(0===(n=e.y-t.y)&&(n=(e.next.y-e.y)/(e.next.x-e.x)-(t.next.y-t.y)/(t.next.x-t.x)));return n}function HA(e,t){var n=function(e,t){var n,r=t,i=e.x,s=e.y,o=-1/0;if(ZA(e,r))return r;do{if(ZA(e,r.next))return r.next;if(s<=r.y&&s>=r.next.y&&r.next.y!==r.y){var a=r.x+(s-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(a<=i&&a>o&&(o=a,n=r.x<r.next.x?r:r.next,a===i))return n}r=r.next}while(r!==t);if(!n)return null;var A=n,c=n.x,u=n.y,l=1/0;r=n;do{if(i>=r.x&&r.x>=c&&i!==r.x&&WA(s<u?i:o,s,c,u,s<u?o:i,s,r.x,r.y)){var h=Math.abs(s-r.y)/(i-r.x);$A(r,e)&&(h<l||h===l&&(r.x>n.x||r.x===n.x&&NA(n,r)))&&(n=r,l=h)}r=r.next}while(r!==A);return n}(e,t);if(!n)return t;var r=ec(n,e);return PA(r,r.next),PA(n,n.next)}function NA(e,t){return KA(e.prev,e,t.prev)<0&&KA(t.next,e,e.next)<0}function GA(e,t,n,r,i){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-n)*i|0)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*i|0)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function jA(e){var t=e,n=e;do{(t.x<n.x||t.x===n.x&&t.y<n.y)&&(n=t),t=t.next}while(t!==e);return n}function WA(e,t,n,r,i,s,o,a){return(i-o)*(t-a)>=(e-o)*(s-a)&&(e-o)*(r-a)>=(n-o)*(t-a)&&(n-o)*(s-a)>=(i-o)*(r-a)}function zA(e,t,n,r,i,s,o,a){return!(e===o&&t===a)&&WA(e,t,n,r,i,s,o,a)}function XA(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){var n=e;do{if(n.i!==e.i&&n.next.i!==e.i&&n.i!==t.i&&n.next.i!==t.i&&JA(n,n.next,e,t))return!0;n=n.next}while(n!==e);return!1}(e,t)&&($A(e,t)&&$A(t,e)&&function(e,t){var n=e,r=!1,i=(e.x+t.x)/2,s=(e.y+t.y)/2;do{n.y>s!=n.next.y>s&&n.next.y!==n.y&&i<(n.next.x-n.x)*(s-n.y)/(n.next.y-n.y)+n.x&&(r=!r),n=n.next}while(n!==e);return r}(e,t)&&(KA(e.prev,e,t.prev)||KA(e,t.prev,t))||ZA(e,t)&&KA(e.prev,e,e.next)>0&&KA(t.prev,t,t.next)>0)}function KA(e,t,n){return(t.y-e.y)*(n.x-t.x)-(t.x-e.x)*(n.y-t.y)}function ZA(e,t){return e.x===t.x&&e.y===t.y}function JA(e,t,n,r){var i=qA(KA(e,t,n)),s=qA(KA(e,t,r)),o=qA(KA(n,r,e)),a=qA(KA(n,r,t));return i!==s&&o!==a||(!(0!==i||!YA(e,n,t))||(!(0!==s||!YA(e,r,t))||(!(0!==o||!YA(n,e,r))||!(0!==a||!YA(n,t,r)))))}function YA(e,t,n){return t.x<=Math.max(e.x,n.x)&&t.x>=Math.min(e.x,n.x)&&t.y<=Math.max(e.y,n.y)&&t.y>=Math.min(e.y,n.y)}function qA(e){return e>0?1:e<0?-1:0}function $A(e,t){return KA(e.prev,e,e.next)<0?KA(e,t,e.next)>=0&&KA(e,e.prev,t)>=0:KA(e,t,e.prev)<0||KA(e,e.next,t)<0}function ec(e,t){var n=rc(e.i,e.x,e.y),r=rc(t.i,t.x,t.y),i=e.next,s=t.prev;return e.next=t,t.prev=e,n.next=i,i.prev=n,r.next=n,n.prev=r,s.next=r,r.prev=s,r}function tc(e,t,n,r){var i=rc(e,t,n);return r?(i.next=r.next,i.prev=r,r.next.prev=i,r.next=i):(i.prev=i,i.next=i),i}function nc(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function rc(e,t,n){return{i:e,x:t,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}var ic=[0,1,0],sc=[1,0,0],oc=Ae.vec3(),ac=Ae.vec3(),Ac=Ae.vec3(),cc=Ae.vec3(),uc=Ae.vec3();function lc(e,t){return Math.abs(e[0]-t[0])<1e-6&&Math.abs(e[1]-t[1])<1e-6&&Math.abs(e[2]-t[2])<1e-6}var hc=function(){function e(t){x(this,e),this.scene=t,this._resourcesAllocated=!1}return I(e,[{key:"_onCapMaterialUpdated",value:function(e,t){var n=this;if(!this._resourcesAllocated){this._resourcesAllocated=!0,this._sectionPlanes=[],this._sceneModelsData={},this._dirtyMap={},this._prevIntersectionModelsMap={},this._sectionPlaneTimeout=null,this._updateTimeout=null;var r=function(e){var t=function(){n._setAllDirty(!0),n._update()};n._sectionPlanes.push(e),e.on("pos",t),e.on("dir",t),e.on("active",t),e.once("destroyed",function(){var t=e.id;t&&(n._sectionPlanes=n._sectionPlanes.filter((function(e){return e.id!==t})),n._update())}.bind(n))};for(var i in this.scene.sectionPlanes)r(this.scene.sectionPlanes[i]);this._onSectionPlaneCreated=this.scene.on("sectionPlaneCreated",r),this._onTick=this.scene.on("tick",(function(){var e=!1;for(var t in n._sceneModelsData)n.scene.models[t]?n._sceneModelsData[t].visible!==!!n.scene.models[t].visible&&(n._sceneModelsData[t].visible=!!n.scene.models[t].visible,e=!0):(delete n._sceneModelsData[t],e=!0);e&&n._update()}))}this._dirtyMap[t]||(this._dirtyMap[t]=new Map),this._dirtyMap[t].set(e,!0),this._update()}},{key:"_update",value:function(){var e=this;clearTimeout(this._updateTimeout),this._deletePreviousModels(),this._updateTimeout=setTimeout((function(){clearTimeout(e._updateTimeout);var t=Object.values(e.scene.models).filter((function(e){return e.visible}));e._addHatches(t,e._sectionPlanes.filter((function(e){return e.active}))),e._setAllDirty(!1)}),100)}},{key:"_setAllDirty",value:function(e){var t=this,n=function(n){t._dirtyMap[n].forEach((function(r,i){return t._dirtyMap[n].set(i,e)}))};for(var r in this._dirty)n(r)}},{key:"_addHatches",value:function(e,t){var n=this;t.forEach((function(t){e.forEach((function(e){if(n._doesPlaneIntersectBoundingBox(e.aabb,t)&&n._dirtyMap[e.id]){var r=new Map,i=e.objects,s=[Ae.vec3(),Ae.vec3(),Ae.vec3()];n._dirtyMap[e.id].forEach((function(o,a){if(o){var A=i[a];if(n._doesPlaneIntersectBoundingBox(A.aabb,t)){if(!n._sceneModelsData[e.id]){var c=e.aabb;n._sceneModelsData[e.id]={verticesMap:new Map,indicesMap:new Map,modelOrigin:Ae.vec3([(c[0]+c[3])/2,(c[1]+c[4])/2,(c[2]+c[5])/2])}}var u=n._sceneModelsData[e.id],l=u.modelOrigin;if(!u.verticesMap.has(a)){var h=A.meshes[0].isSolid(),d=[],f=[];h&&A.capMaterial&&(A.getEachVertex((function(e){return d.push(e[0]-l[0],e[1]-l[1],e[2]-l[2])})),A.getEachIndex((function(e){return f.push(e)}))),u.verticesMap.set(a,d),u.indicesMap.set(a,f)}for(var p=u.verticesMap.get(a),v=u.indicesMap.get(a),g=-Ae.dotVec3(Ae.subVec3(t.pos,l,oc),t.dir),m=[],y=v.length,_=0;_<y;_+=3){for(var b=0;b<3;b++){var w=3*v[_+b];s[b][0]=p[w],s[b][1]=p[w+1],s[b][2]=p[w+2]}if(s[0][0]||s[0][1]||s[0][2]){for(var B=[],C=0;C<3;C++){var k=s[C],M=s[(C+1)%3],E=g+Ae.dotVec3(t.dir,k),F=g+Ae.dotVec3(t.dir,M);if(!(E*F>0)){var x=-E/(F-E);B.push(Ae.lerpVec3(x,0,1,k,M,Ae.vec3()))}}2===B.length&&m.push(B)}}m.length>0&&r.set(a,m)}}}));var o=new Map;r.forEach((function(e,t){o.set(t,[[e[0]]]),e.splice(0,1);for(var n=0;e.length>0;){for(var i=o.get(t)[n][o.get(t)[n].length-1][1],s=!1,a=0;a<e.length;a++){var A=M(e[a],2),c=A[0],u=A[1];if(lc(i,c)){o.get(t)[n].push(e[a]),e.splice(a,1),s=!0;break}if(lc(i,u)){o.get(t)[n].push([u,c]),e.splice(a,1),s=!0;break}}if(!s&&lc(i,o.get(t)[n][0][0])&&e.length>1)o.get(t).push([r.get(t)[0]]),e.splice(0,1),n++;else if(!s)break}}));var a=new Map;o.forEach((function(e,r){for(var i=[],s=function(r){i.push([]),e[r].forEach((function(e){i[r].push([n._projectTo2D(e[0],t.dir),n._projectTo2D(e[1],t.dir)])}))},o=0;o<e.length;o++)s(o);a.set(r,i)}));var A,c=new Map;a.forEach((function(r,i){var s=n._sceneModelsData[e.id].modelOrigin;A=[];for(var o=r,a=[],u=new Set,l=0;l<o.length;l++)if(!u.has(l)){var h=[o[l]];u.add(l);for(var d=l+1;d<o.length;d++)u.has(d)||(n._isLoopInside(o[l],o[d])||n._isLoopInside(o[d],o[l]))&&(h.push(o[d]),u.add(d));a.push(h)}a.forEach((function(e){var r=[],i=[],o=0,a=e.map((function(e){for(var t=0,n=0;n<e.length;n++){var r=(n+1)%e.length;t+=e[n][0][0]*e[r][0][1],t-=e[r][0][0]*e[n][0][1]}return Math.abs(t)/2})),c=a.indexOf(Math.max.apply(Math,p(a)));e[c].forEach((function(e){r.push(e[0][0],e[0][1]),o+=2}));for(var u=0;u<e.length;u++)u!==c&&(i.push(o/2),e[u].forEach((function(e){r.push(e[0][0],e[0][1]),o+=2})));for(var l=IA(r,i),h=[],d=0;d<l.length;d+=3){for(var f=[],v=0;v<3;v++){var g=2*l[d+v],m=[r[g],r[g+1]],y=n._convertTo3D(m,t,s);f.push(y)}h.push(f)}A.push(h)})),c.set(i,A)}));var u=new Map;c.forEach((function(e,t){A=[],e.forEach((function(e){var t=new Map,n=[],r=[],i=0;e.forEach((function(e){var s=[];e.forEach((function(e){var r="".concat(e[0].toFixed(6),",").concat(e[1].toFixed(6),",").concat(e[2].toFixed(6));t.has(r)?s.push(t.get(r)):(n.push(e[0],e[1],e[2]),t.set(r,i),s.push(i),i++)})),r.push.apply(r,s)})),A.push({positions:n,indices:r})})),u.set(t,A)})),n._prevIntersectionModelsMap[e.id]||(n._prevIntersectionModelsMap[e.id]=new Map),Ae.mulVec3Scalar(t.dir,.001,uc),u.forEach((function(r,i){var s,o=n._sceneModelsData[e.id].modelOrigin,a=new Array(r.size),A=0;(r.forEach((function(r,s){var c=r.positions,u=r.indices;c.length;var l=Ae.buildNormals(c,u),h=n._createUVs(c,t,o);a[A++]=new Gr(n.scene,{id:"".concat(t.id,"-").concat(i,"-").concat(s),geometry:new mt(n.scene,{primitive:"triangles",positions:c,indices:u,normals:l,uv:h}),origin:Ae.addVec3(o,uc,oc),position:[0,0,0],rotation:[0,0,0],material:e.objects[i].capMaterial})})),n._prevIntersectionModelsMap[e.id].has(i))?(s=n._prevIntersectionModelsMap[e.id].get(i)).push.apply(s,a):n._prevIntersectionModelsMap[e.id].set(i,a)}))}}))}))}},{key:"_doesPlaneIntersectBoundingBox",value:function(e,t){for(var n=[e[0],e[1],e[2]],r=[e[3],e[4],e[5]],i=!1,s=!1,o=0,a=[[n[0],n[1],n[2]],[r[0],n[1],n[2]],[n[0],r[1],n[2]],[r[0],r[1],n[2]],[n[0],n[1],r[2]],[r[0],n[1],r[2]],[n[0],r[1],r[2]],[r[0],r[1],r[2]]];o<a.length;o++){var A=a[o],c=t.dist+Ae.dotVec3(t.dir,A);if(c>0&&(i=!0),c<0&&(s=!0),i&&s)return!0}return!1}},{key:"_buildLines",value:function(e){var t=this;for(var n in e)for(var r=0;r<e[n].length;r++){var i=e[n][r];i.length<=0||i.forEach((function(e,n){new Gr(t.scene,{clippable:!1,geometry:new mt(t.scene,Rt({startPoint:e[0],endPoint:e[1]})),material:new Zr(t.scene,{emissive:[1,0,0]})})}))}}},{key:"_projectTo2D",value:function(e,t){var n;n=Math.abs(t[0])>Math.abs(t[1])?[-t[2],0,t[0]]:[0,t[2],-t[1]],n=Ae.normalizeVec3(n);var r=Ae.vec3(t),i=Ae.cross3Vec3(r,n),s=Ae.normalizeVec3(i);return[Ae.dotVec3(e,n),Ae.dotVec3(e,s)]}},{key:"_isLoopInside",value:function(e,t){for(var n=e[0][0],r=!1,i=0,s=t.length-1;i<t.length;s=i++){var o=t[i][0][0],a=t[i][0][1],A=t[s][0][0],c=t[s][0][1];a>n[1]!=c>n[1]&&n[0]<(A-o)*(n[1]-a)/(c-a)+o&&(r=!r)}return r}},{key:"_convertTo3D",value:function(e,t,n){var r,i=t.dir,s=t.pos;r=Math.abs(i[0])>Math.abs(i[1])?[-i[2],0,i[0]]:[0,i[2],-i[1]],r=Ae.normalizeVec3(r);var o=Ae.vec3(i),a=Ae.cross3Vec3(o,r),A=Ae.normalizeVec3(a),c=e[0],u=e[1],l=[r[0]*c+A[0]*u,r[1]*c+A[1]*u,r[2]*c+A[2]*u],h=Ae.dotVec3(i,[s[0]-l[0]-n[0],s[1]-l[1]-n[1],s[2]-l[2]-n[2]]);return[l[0]+i[0]*h,l[1]+i[1]*h,l[2]+i[2]*h]}},{key:"_deletePreviousModels",value:function(){var e=this,t=function(t){e._prevIntersectionModelsMap[t].forEach((function(n,r){e._dirtyMap[t].get(r)&&(n.forEach((function(e){e.destroy()})),e._prevIntersectionModelsMap[t].delete(r))})),e._prevIntersectionModelsMap[t].size<=0&&delete e._prevIntersectionModelsMap[t]};for(var n in this._prevIntersectionModelsMap)t(n)}},{key:"_createUVs",value:function(e,t,n){var r=t.pos,i=oc;i.set(t.dir),Ae.normalizeVec3(i);for(var s=ac,o=[],a=0;a<e.length;a+=3){s[0]=e[a]+n[0],s[1]=e[a+1]+n[1],s[2]=e[a+2]+n[2];var A=Ae.subVec3(s,r,Ac),c=Ae.dotVec3(A,i);Ae.subVec3(s,Ae.mulVec3Scalar(i,c,Ac),s);var u=Math.abs(Ae.dotVec3(i,ic))<.999?Ae.cross3Vec3(i,ic,Ac):sc,l=Ae.cross3Vec3(i,u,Ac);Ae.normalizeVec3(l,l);var h=Ae.subVec3(s,r,s);o.push(Ae.dotVec3(h,Ae.normalizeVec3(Ae.cross3Vec3(l,i,cc))),Ae.dotVec3(h,l))}return o}},{key:"destroy",value:function(){this._deletePreviousModels(),this._resourcesAllocated&&(this.scene.off(this._onModelLoaded),this.scene.off(this._onModelUnloaded),this.scene.off(this._onSectionPlaneCreated),this.scene.off(this._onTick))}}]),e}();function dc(e,t){for(var n,r,i={},s=0,o=t.length;s<o;s++)n=t[s],(r=e.components[n])?r.isEntity?i[n]=!0:e.warn("pick(): Component is not an Entity: "+n):e.warn("pick(): Component not found: "+n);return i}var fc=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,null,i);var s=i.canvasElement||document.querySelector("#".concat(i.canvasId));if(!(s instanceof HTMLCanvasElement))throw"Mandatory config expected: valid canvasId or canvasElement";r._tickifiedFunctions={};var o=!!i.transparent,a=!!i.alphaDepthMask;r._aabbDirty=!0,r._readableGeometry=!!i.readableGeometryEnabled,r.viewer=e,r.occlusionTestCountdown=0,r.loading=0,r.startTime=(new Date).getTime(),r.models={},r.objects={},r._numObjects=0,r.visibleObjects={},r._numVisibleObjects=0,r.xrayedObjects={},r._numXRayedObjects=0,r.highlightedObjects={},r._numHighlightedObjects=0,r.selectedObjects={},r._numSelectedObjects=0,r.colorizedObjects={},r._numColorizedObjects=0,r.opacityObjects={},r._numOpacityObjects=0,r.offsetObjects={},r._numOffsetObjects=0,r._modelIds=null,r._objectIds=null,r._visibleObjectIds=null,r._xrayedObjectIds=null,r._highlightedObjectIds=null,r._selectedObjectIds=null,r._colorizedObjectIds=null,r._opacityObjectIds=null,r._offsetObjectIds=null,r._collidables={},r._compilables={},r._needRecompile=!1,r.types={},r.components={},r.sectionPlanes={},r.lights={},r.lightMaps={},r.reflectionMaps={},r.bitmaps={},r.lineSets={},r.realWorldOffset=i.realWorldOffset||new Float64Array([0,0,0]),r.canvas=new Ha(w(r),{dontClear:!0,canvas:s,spinnerElementId:i.spinnerElementId,transparent:o,webgl2:!1!==i.webgl2,contextAttr:i.contextAttr||{},backgroundColor:i.backgroundColor,backgroundColorFromAmbientLight:i.backgroundColorFromAmbientLight,premultipliedAlpha:i.premultipliedAlpha});var A=function(e){return r.viewer.destroy()};return s.addEventListener("webglcontextlost",A,!1),r._removeWebglcontextlostListener=function(){return s.removeEventListener("webglcontextlost",A,!1)},r.canvas.on("boundary",(function(){r.glRedraw()})),r.canvas.on("webglContextFailed",(function(){alert("xeokit failed to find WebGL!")})),r._renderer=new eA(w(r),{transparent:o,alphaDepthMask:a}),r._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1,this._numCachedSectionPlanes=0;var e=null;this.getHash=function(){if(e)return e;var t=this.getNumAllocatedSectionPlanes();if(this.sectionPlanes,0===t)return this.hash=";";for(var n=[],r=0,i=t;r<i;r++)n.push("cp");return n.push(";"),e=n.join("")},this.addSectionPlane=function(t){this.sectionPlanes.push(t),e=null},this.removeSectionPlane=function(t){for(var n=0,r=this.sectionPlanes.length;n<r;n++)if(this.sectionPlanes[n].id===t.id)return this.sectionPlanes.splice(n,1),void(e=null)},this.setNumCachedSectionPlanes=function(t){this._numCachedSectionPlanes=t,e=null},this.getNumCachedSectionPlanes=function(){return this._numCachedSectionPlanes},this.getNumAllocatedSectionPlanes=function(){var e=this.sectionPlanes.length;return e>this._numCachedSectionPlanes?e:this._numCachedSectionPlanes}},r._sectionPlanesState.setNumCachedSectionPlanes(i.numCachedSectionPlanes||0),r._lightsState=new function(){var e=Ae.vec4([0,0,0,0]),t=Ae.vec4();this.lights=[],this.reflectionMaps=[],this.lightMaps=[];var n=null,r=null;this.getHash=function(){if(n)return n;for(var e,t=[],r=this.lights,i=0,s=r.length;i<s;i++)e=r[i],t.push("/"),t.push(e.type),t.push("world"===e.space?"w":"v"),e.castsShadow&&t.push("sh");return this.lightMaps.length>0&&t.push("/lm"),this.reflectionMaps.length>0&&t.push("/rm"),t.push(";"),n=t.join("")},this.addLight=function(e){this.lights.push(e),r=null,n=null},this.removeLight=function(e){for(var t=0,i=this.lights.length;t<i;t++){if(this.lights[t].id===e.id)return this.lights.splice(t,1),r&&r.id===e.id&&(r=null),void(n=null)}},this.addReflectionMap=function(e){this.reflectionMaps.push(e),n=null},this.removeReflectionMap=function(e){for(var t=0,r=this.reflectionMaps.length;t<r;t++)if(this.reflectionMaps[t].id===e.id)return this.reflectionMaps.splice(t,1),void(n=null)},this.addLightMap=function(e){this.lightMaps.push(e),n=null},this.removeLightMap=function(e){for(var t=0,r=this.lightMaps.length;t<r;t++)if(this.lightMaps[t].id===e.id)return this.lightMaps.splice(t,1),void(n=null)},this.getAmbientColorAndIntensity=function(){if(!r)for(var n=0,i=this.lights.length;n<i;n++){var s=this.lights[n];if("ambient"===s.type){r=s;break}}if(r){var o=r.color,a=r.intensity;return t[0]=o[0],t[1]=o[1],t[2]=o[2],t[3]=a,t}return e}},r.input=new tA(w(r),{dontClear:!0,element:r.canvas.canvas,keyboardEventsElement:i.keyboardEventsElement}),r.metrics=new CA(w(r),{units:i.units,scale:i.scale,origin:i.origin}),r.sao=new kA(w(r),{enabled:i.saoEnabled}),r.crossSections=new MA(w(r),{}),r.ticksPerRender=i.ticksPerRender,r.ticksPerOcclusionTest=i.ticksPerOcclusionTest,r.passes=i.passes,r.clearEachPass=i.clearEachPass,r.gammaInput=i.gammaInput,r.gammaOutput=i.gammaOutput,r.gammaFactor=i.gammaFactor,r._entityOffsetsEnabled=!!i.entityOffsetsEnabled,r._logarithmicDepthBufferEnabled=!!i.logarithmicDepthBufferEnabled,r._dtxEnabled=!1!==i.dtxEnabled,r._pbrEnabled=!!i.pbrEnabled,r._colorTextureEnabled=!1!==i.colorTextureEnabled,r._dtxEnabled=!!i.dtxEnabled,r._markerZOffset=i.markerZOffset,Fe._addScene(w(r)),r._initDefaults(),r._viewport=new nA(w(r),{id:"default.viewport",autoBoundary:!0,dontClear:!0}),r._camera=new wA(w(r),{id:"default.camera",dontClear:!0}),r._sectionCaps=new hc(w(r)),new oa(w(r),{color:[1,1,1],intensity:.7}),new Aa(w(r),{dir:[.8,-.5,-.5],color:[.67,.67,1],intensity:.7,space:"world"}),new Aa(w(r),{dir:[-.8,-1,.5],color:[1,1,.9],intensity:.9,space:"world"}),r._camera.on("dirty",(function(){r._renderer.imageDirty()})),r}return I(n,[{key:"type",get:function(){return"Scene"}},{key:"_initDefaults",value:function(){}},{key:"_addComponent",value:function(e){if(e.id&&this.components[e.id]&&(this.error("Component "+ge.inQuotes(e.id)+" already exists in Scene - ignoring ID, will randomly-generate instead"),e.id=null),!e.id)for(void 0===window.nextID&&(window.nextID=0),e.id="__"+window.nextID++;this.components[e.id];)e.id=Ae.createUUID();this.components[e.id]=e;var t=e.type,n=this.types[e.type];n||(n=this.types[t]={}),n[e.id]=e,e.compile&&(this._compilables[e.id]=e),e.isDrawable&&(this._renderer.addDrawable(e.id,e),this._collidables[e.id]=e)}},{key:"_removeComponent",value:function(e){var t=e.id,n=e.type;delete this.components[t];var r=this.types[n];r&&(delete r[t],ge.isEmptyObject(r)&&delete this.types[n]),e.compile&&delete this._compilables[e.id],e.isDrawable&&(this._renderer.removeDrawable(e.id),delete this._collidables[e.id])}},{key:"_capMaterialUpdated",value:function(e,t){this._sectionCaps._onCapMaterialUpdated(e,t)}},{key:"_sectionPlaneCreated",value:function(e){this.sectionPlanes[e.id]=e,this.scene._sectionPlanesState.addSectionPlane(e._state),this.scene.fire("sectionPlaneCreated",e,!0),this._needRecompile=!0}},{key:"_bitmapCreated",value:function(e){this.bitmaps[e.id]=e,this.scene.fire("bitmapCreated",e,!0)}},{key:"_lineSetCreated",value:function(e){this.lineSets[e.id]=e,this.scene.fire("lineSetCreated",e,!0)}},{key:"_lightCreated",value:function(e){this.lights[e.id]=e,this.scene._lightsState.addLight(e._state),this._needRecompile=!0}},{key:"_lightMapCreated",value:function(e){this.lightMaps[e.id]=e,this.scene._lightsState.addLightMap(e._state),this._needRecompile=!0}},{key:"_reflectionMapCreated",value:function(e){this.reflectionMaps[e.id]=e,this.scene._lightsState.addReflectionMap(e._state),this._needRecompile=!0}},{key:"_sectionPlaneDestroyed",value:function(e){delete this.sectionPlanes[e.id],this.scene._sectionPlanesState.removeSectionPlane(e._state),this.scene.fire("sectionPlaneDestroyed",e,!0),this._needRecompile=!0}},{key:"_bitmapDestroyed",value:function(e){delete this.bitmaps[e.id],this.scene.fire("bitmapDestroyed",e,!0)}},{key:"_lineSetDestroyed",value:function(e){delete this.lineSets[e.id],this.scene.fire("lineSetDestroyed",e,!0)}},{key:"_lightDestroyed",value:function(e){delete this.lights[e.id],this.scene._lightsState.removeLight(e._state),this._needRecompile=!0}},{key:"_lightMapDestroyed",value:function(e){delete this.lightMaps[e.id],this.scene._lightsState.removeLightMap(e._state),this._needRecompile=!0}},{key:"_reflectionMapDestroyed",value:function(e){delete this.reflectionMaps[e.id],this.scene._lightsState.removeReflectionMap(e._state),this._needRecompile=!0}},{key:"_registerModel",value:function(e){this.models[e.id]=e,this._modelIds=null}},{key:"_deregisterModel",value:function(e){var t=e.id;delete this.models[t],this._modelIds=null,this.fire("modelUnloaded",t)}},{key:"_registerObject",value:function(e){this.objects[e.id]=e,this._numObjects++,this._objectIds=null}},{key:"_deregisterObject",value:function(e){delete this.objects[e.id],this._numObjects--,this._objectIds=null}},{key:"_objectVisibilityUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}},{key:"_deRegisterVisibleObject",value:function(e){delete this.visibleObjects[e.id],this._numVisibleObjects--,this._visibleObjectIds=null}},{key:"_objectXRayedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}},{key:"_deRegisterXRayedObject",value:function(e){delete this.xrayedObjects[e.id],this._numXRayedObjects--,this._xrayedObjectIds=null}},{key:"_objectHighlightedUpdated",value:function(e){e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null}},{key:"_deRegisterHighlightedObject",value:function(e){delete this.highlightedObjects[e.id],this._numHighlightedObjects--,this._highlightedObjectIds=null}},{key:"_objectSelectedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}},{key:"_deRegisterSelectedObject",value:function(e){delete this.selectedObjects[e.id],this._numSelectedObjects--,this._selectedObjectIds=null}},{key:"_objectColorizeUpdated",value:function(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}},{key:"_deRegisterColorizedObject",value:function(e){delete this.colorizedObjects[e.id],this._numColorizedObjects--,this._colorizedObjectIds=null}},{key:"_objectOpacityUpdated",value:function(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}},{key:"_deRegisterOpacityObject",value:function(e){delete this.opacityObjects[e.id],this._numOpacityObjects--,this._opacityObjectIds=null}},{key:"_objectOffsetUpdated",value:function(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}},{key:"_deRegisterOffsetObject",value:function(e){delete this.offsetObjects[e.id],this._numOffsetObjects--,this._offsetObjectIds=null}},{key:"capabilities",get:function(){return this._renderer.capabilities}},{key:"entityOffsetsEnabled",get:function(){return this._entityOffsetsEnabled}},{key:"readableGeometryEnabled",get:function(){return this._readableGeometry}},{key:"pickSurfacePrecisionEnabled",get:function(){return this._readableGeometry}},{key:"logarithmicDepthBufferEnabled",get:function(){return this._logarithmicDepthBufferEnabled}},{key:"numCachedSectionPlanes",get:function(){return this._sectionPlanesState.getNumCachedSectionPlanes()},set:function(e){e=e||0,this._sectionPlanesState.getNumCachedSectionPlanes()!==e&&(this._sectionPlanesState.setNumCachedSectionPlanes(e),this._needRecompile=!0,this.glRedraw())}},{key:"pbrEnabled",get:function(){return this._pbrEnabled},set:function(e){this._pbrEnabled=!!e,this.glRedraw()}},{key:"dtxEnabled",get:function(){return this._dtxEnabled},set:function(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}},{key:"colorTextureEnabled",get:function(){return this._colorTextureEnabled},set:function(e){this._colorTextureEnabled=!!e,this.glRedraw()}},{key:"markerZOffset",get:function(){return null==this._markerZOffset?-.001:this._markerZOffset}},{key:"doOcclusionTest",value:function(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}},{key:"render",value:function(e){e&&Fe.runTasks();var t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),e||this._renderer.needsRender()){t.sceneId=this.id;for(var n=0;n<this._passes;n++)t.pass=n,this.fire("rendering",t,!0),e&&this._renderer.imageDirty(),this._renderer.render(n,this._clearEachPass||0===n),this.fire("rendered",t,!0);this._saveAmbientColor()}}},{key:"compile",value:function(){this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1)}},{key:"_recompile",value:function(){for(var e in this._compilables)this._compilables.hasOwnProperty(e)&&this._compilables[e].compile();this._renderer.shadowsDirty(),this.fire("compile",this,!0)}},{key:"_saveAmbientColor",value:function(){var e=this.canvas;if(e.transparent||e.backgroundImage||e.backgroundColor)this._lastAmbientColor=null;else{var t=this._lightsState.getAmbientColorAndIntensity();this._lastAmbientColor&&this._lastAmbientColor[0]===t[0]&&this._lastAmbientColor[1]===t[1]&&this._lastAmbientColor[2]===t[2]&&this._lastAmbientColor[3]===t[3]||(e.backgroundColor=t,this._lastAmbientColor||(this._lastAmbientColor=Ae.vec4([0,0,0,1])),this._lastAmbientColor.set(t))}}},{key:"modelIds",get:function(){return this._modelIds||(this._modelIds=Object.keys(this.models)),this._modelIds}},{key:"numObjects",get:function(){return this._numObjects}},{key:"objectIds",get:function(){return this._objectIds||(this._objectIds=Object.keys(this.objects)),this._objectIds}},{key:"numVisibleObjects",get:function(){return this._numVisibleObjects}},{key:"visibleObjectIds",get:function(){return this._visibleObjectIds||(this._visibleObjectIds=Object.keys(this.visibleObjects)),this._visibleObjectIds}},{key:"numXRayedObjects",get:function(){return this._numXRayedObjects}},{key:"xrayedObjectIds",get:function(){return this._xrayedObjectIds||(this._xrayedObjectIds=Object.keys(this.xrayedObjects)),this._xrayedObjectIds}},{key:"numHighlightedObjects",get:function(){return this._numHighlightedObjects}},{key:"highlightedObjectIds",get:function(){return this._highlightedObjectIds||(this._highlightedObjectIds=Object.keys(this.highlightedObjects)),this._highlightedObjectIds}},{key:"numSelectedObjects",get:function(){return this._numSelectedObjects}},{key:"selectedObjectIds",get:function(){return this._selectedObjectIds||(this._selectedObjectIds=Object.keys(this.selectedObjects)),this._selectedObjectIds}},{key:"numColorizedObjects",get:function(){return this._numColorizedObjects}},{key:"colorizedObjectIds",get:function(){return this._colorizedObjectIds||(this._colorizedObjectIds=Object.keys(this.colorizedObjects)),this._colorizedObjectIds}},{key:"opacityObjectIds",get:function(){return this._opacityObjectIds||(this._opacityObjectIds=Object.keys(this.opacityObjects)),this._opacityObjectIds}},{key:"offsetObjectIds",get:function(){return this._offsetObjectIds||(this._offsetObjectIds=Object.keys(this.offsetObjects)),this._offsetObjectIds}},{key:"ticksPerRender",get:function(){return this._ticksPerRender},set:function(e){null==e?e=1:(!ge.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'ticksPerRender': '"+e+"' - should be an integer greater than zero."),e=1),e!==this._ticksPerRender&&(this._ticksPerRender=e)}},{key:"ticksPerOcclusionTest",get:function(){return this._ticksPerOcclusionTest},set:function(e){null==e?e=20:(!ge.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'ticksPerOcclusionTest': '"+e+"' - should be an integer greater than zero."),e=20),e!==this._ticksPerOcclusionTest&&(this._ticksPerOcclusionTest=e)}},{key:"passes",get:function(){return this._passes},set:function(e){null==e?e=1:(!ge.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'passes': '"+e+"' - should be an integer greater than zero."),e=1),e!==this._passes&&(this._passes=e,this.glRedraw())}},{key:"clearEachPass",get:function(){return this._clearEachPass},set:function(e){(e=!!e)!==this._clearEachPass&&(this._clearEachPass=e,this.glRedraw())}},{key:"gammaInput",get:function(){return this._renderer.gammaInput},set:function(e){(e=!1!==e)!==this._renderer.gammaInput&&(this._renderer.gammaInput=e,this._needRecompile=!0,this.glRedraw())}},{key:"gammaOutput",get:function(){return this._renderer.gammaOutput},set:function(e){(e=!!e)!==this._renderer.gammaOutput&&(this._renderer.gammaOutput=e,this._needRecompile=!0,this.glRedraw())}},{key:"gammaFactor",get:function(){return this._renderer.gammaFactor},set:function(e){(e=null==e?2.2:e)!==this._renderer.gammaFactor&&(this._renderer.gammaFactor=e,this.glRedraw())}},{key:"geometry",get:function(){return this.components["default.geometry"]||kt(mt)}},{key:"material",get:function(){return this.components["default.material"]||new Zr(this,{id:"default.material",emissive:[.4,.4,.4],dontClear:!0})}},{key:"xrayMaterial",get:function(){return this.components["default.xrayMaterial"]||new _i(this,{id:"default.xrayMaterial",fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1,dontClear:!0})}},{key:"highlightMaterial",get:function(){return this.components["default.highlightMaterial"]||new _i(this,{id:"default.highlightMaterial",fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1,dontClear:!0})}},{key:"selectedMaterial",get:function(){return this.components["default.selectedMaterial"]||new _i(this,{id:"default.selectedMaterial",fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1,dontClear:!0})}},{key:"edgeMaterial",get:function(){return this.components["default.edgeMaterial"]||new wi(this,{id:"default.edgeMaterial",fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1,dontClear:!0})}},{key:"pointsMaterial",get:function(){return this.components["default.pointsMaterial"]||new FA(this,{id:"default.pointsMaterial",fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1,dontClear:!0})}},{key:"linesMaterial",get:function(){return this.components["default.linesMaterial"]||new UA(this,{id:"default.linesMaterial",fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1,dontClear:!0})}},{key:"viewport",get:function(){return this._viewport}},{key:"camera",get:function(){return this._camera}},{key:"center",get:function(){if(this._aabbDirty||!this._center){var e=this.aabb;this._center||(this._center=Ae.vec3()),this._center[0]=(e[0]+e[3])/2,this._center[1]=(e[1]+e[4])/2,this._center[2]=(e[2]+e[5])/2}return this._center}},{key:"aabb",get:function(){if(this._aabbDirty){this._aabb||(this._aabb=Ae.AABB3());var e,t,n=Ae.MAX_DOUBLE,r=Ae.MAX_DOUBLE,i=Ae.MAX_DOUBLE,s=Ae.MIN_DOUBLE,o=Ae.MIN_DOUBLE,a=Ae.MIN_DOUBLE,A=this._collidables,c=!1;for(var u in A)if(A.hasOwnProperty(u)){if(!1===(t=A[u]).collidable)continue;(e=t.aabb)[0]<n&&(n=e[0]),e[1]<r&&(r=e[1]),e[2]<i&&(i=e[2]),e[3]>s&&(s=e[3]),e[4]>o&&(o=e[4]),e[5]>a&&(a=e[5]),c=!0}c||(n=-100,r=-100,i=-100,s=100,o=100,a=100),this._aabb[0]=n,this._aabb[1]=r,this._aabb[2]=i,this._aabb[3]=s,this._aabb[4]=o,this._aabb[5]=a,this._aabbDirty=!1,this._center=null}return this._aabb}},{key:"_setAABBDirty",value:function(){this._aabbDirty=!0,this.fire("boundary")}},{key:"pick",value:function(e,t){if(!this.canvas)return this.error("Picking not allowed on a destroyed Scene"),null;if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");var n=e.includeEntities||e.include;n&&(e.includeEntityIds=dc(this,n));var r=e.excludeEntities||e.exclude;return r&&(e.excludeEntityIds=dc(this,r)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=e.snapToEdge||e.snapToVertex?this._renderer.snapPick(e,t):this._renderer.pick(e,t))&&t.entity&&t.entity.fire&&t.entity.fire("picked",t),t}},{key:"snapPick",value:function(e){return this.canvas?(void 0===this._warnSnapPickDeprecated&&(this._warnSnapPickDeprecated=!0,this.warn("Scene.snapPick() is deprecated since v2.4.2 - use Scene.pick() instead")),e.canvasPos?this._renderer.snapPick(e):void this.error("Scene.snapPick() canvasPos parameter expected")):(this.error("Picking not allowed on a destroyed Scene"),null)}},{key:"clear",value:function(){var e;for(var t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}},{key:"clearLights",value:function(){for(var e=Object.keys(this.lights),t=0,n=e.length;t<n;t++)this.lights[e[t]].destroy()}},{key:"clearSectionPlanes",value:function(){for(var e=Object.keys(this.sectionPlanes),t=0,n=e.length;t<n;t++)this.sectionPlanes[e[t]].destroy()}},{key:"clearBitmaps",value:function(){for(var e=Object.keys(this.bitmaps),t=0,n=e.length;t<n;t++)this.bitmaps[e[t]].destroy()}},{key:"clearLines",value:function(){for(var e=Object.keys(this.lineSets),t=0,n=e.length;t<n;t++)this.lineSets[e[t]].destroy()}},{key:"getAABB",value:function(e){if(void 0===e)return this.aabb;if(ge.isString(e)){var t=this.objects[e];if(t&&t.aabb)return t.aabb;e=[e]}if(0===e.length)return this.aabb;var n,r=Ae.MAX_DOUBLE,i=Ae.MAX_DOUBLE,s=Ae.MAX_DOUBLE,o=Ae.MIN_DOUBLE,a=Ae.MIN_DOUBLE,A=Ae.MIN_DOUBLE;if(this.withObjects(e,(function(e){if(e.collidable){var t=e.aabb;t[0]<r&&(r=t[0]),t[1]<i&&(i=t[1]),t[2]<s&&(s=t[2]),t[3]>o&&(o=t[3]),t[4]>a&&(a=t[4]),t[5]>A&&(A=t[5]),n=!0}})),n){var c=Ae.AABB3();return c[0]=r,c[1]=i,c[2]=s,c[3]=o,c[4]=a,c[5]=A,c}return this.aabb}},{key:"setObjectsVisible",value:function(e,t){return this.withObjects(e,(function(e){var n=e.visible!==t;return e.visible=t,n}))}},{key:"setObjectsCollidable",value:function(e,t){return this.withObjects(e,(function(e){var n=e.collidable!==t;return e.collidable=t,n}))}},{key:"setObjectsCulled",value:function(e,t){return this.withObjects(e,(function(e){var n=e.culled!==t;return e.culled=t,n}))}},{key:"setObjectsSelected",value:function(e,t){return this.withObjects(e,(function(e){var n=e.selected!==t;return e.selected=t,n}))}},{key:"setObjectsHighlighted",value:function(e,t){return this.withObjects(e,(function(e){var n=e.highlighted!==t;return e.highlighted=t,n}))}},{key:"setObjectsXRayed",value:function(e,t){return this.withObjects(e,(function(e){var n=e.xrayed!==t;return e.xrayed=t,n}))}},{key:"setObjectsEdges",value:function(e,t){return this.withObjects(e,(function(e){var n=e.edges!==t;return e.edges=t,n}))}},{key:"setObjectsColorized",value:function(e,t){return this.withObjects(e,(function(e){e.colorize=t}))}},{key:"setObjectsOpacity",value:function(e,t){return this.withObjects(e,(function(e){var n=e.opacity!==t;return e.opacity=t,n}))}},{key:"setObjectsPickable",value:function(e,t){return this.withObjects(e,(function(e){var n=e.pickable!==t;return e.pickable=t,n}))}},{key:"setObjectsOffset",value:function(e,t){this.withObjects(e,(function(e){e.offset=t}))}},{key:"withObjects",value:function(e,t){ge.isString(e)&&(e=[e]);for(var n=!1,r=0,i=e.length;r<i;r++){var s=e[r],o=this.objects[s];if(o)n=t(o)||n;else for(var a=this.modelIds,A=0,c=a.length;A<c;A++){var u=a[A],l=Ae.globalizeObjectId(u,s);(o=this.objects[l])&&(n=t(o)||n)}}return n}},{key:"tickify",value:function(e){var t=e.toString();if(t in this._tickifiedFunctions)return this._tickifiedFunctions[t].wrapperFunc;var n,r=0,i=0,s=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];n=t,i++},o=this.on("tick",(function(){i>r&&(r=i,e.apply(void 0,p(n)))}));return this._tickifiedFunctions[t]={tickSubId:o,wrapperFunc:s},s}},{key:"destroy",value:function(){for(var e in v(C(n.prototype),"destroy",this).call(this),this._removeWebglcontextlostListener(),this.components)this.components.hasOwnProperty(e)&&this.components[e].destroy();this._sectionCaps.destroy(),this.canvas.gl=null,this.components=null,this.models=null,this.objects=null,this.visibleObjects=null,this.xrayedObjects=null,this.highlightedObjects=null,this.selectedObjects=null,this.colorizedObjects=null,this.opacityObjects=null,this.sectionPlanes=null,this.lights=null,this.lightMaps=null,this.reflectionMaps=null,this._objectIds=null,this._visibleObjectIds=null,this._xrayedObjectIds=null,this._highlightedObjectIds=null,this._selectedObjectIds=null,this._colorizedObjectIds=null,this._sectionCaps=null,this.types=null,this.components=null,this.canvas=null,this._renderer=null,this.input=null,this._viewport=null,this._camera=null}}]),n}(),pc=Ae.vec4(),vc=Ae.vec4(),gc=Ae.vec3(),mc=Ae.vec3(),yc=Ae.vec3(),_c=Ae.vec4(),bc=Ae.vec4(),wc=Ae.vec4(),Bc=function(){function e(t){x(this,e),this._scene=t}return I(e,[{key:"dollyToCanvasPos",value:function(e,t,n){var r=!1,i=this._scene.camera;if(e){var s=Ae.subVec3(e,i.eye,gc);r=Ae.lenVec3(s)<n}if("perspective"===i.projection){i.ortho.scale=i.ortho.scale-n;var o=this._unproject(t,_c),a=Ae.subVec3(o,i.eye,wc),A=Ae.mulVec3Scalar(Ae.normalizeVec3(a),-n,[]);if(i.eye=[i.eye[0]-A[0],i.eye[1]-A[1],i.eye[2]-A[2]],i.look=[i.look[0]-A[0],i.look[1]-A[1],i.look[2]-A[2]],e){var c=Ae.subVec3(e,i.eye,gc),u=Ae.lenVec3(c),l=Ae.mulVec3Scalar(Ae.normalizeVec3(Ae.subVec3(i.look,i.eye,mc)),u);i.look=[i.eye[0]+l[0],i.eye[1]+l[1],i.eye[2]+l[2]]}}else if("ortho"===i.projection){var h=this._unproject(t,_c);i.ortho.scale=i.ortho.scale-n,i.ortho._update();var d=this._unproject(t,bc),f=Ae.subVec3(d,h,wc),p=Ae.mulVec3Scalar(Ae.normalizeVec3(Ae.subVec3(i.look,i.eye,gc)),-n,mc),v=Ae.addVec3(f,p,yc);i.eye=[i.eye[0]-v[0],i.eye[1]-v[1],i.eye[2]-v[2]],i.look=[i.look[0]-v[0],i.look[1]-v[1],i.look[2]-v[2]]}return r}},{key:"_unproject",value:function(e,t){var n=this._scene.camera,r=n.project.transposedMatrix,i=r.subarray(8,12),s=r.subarray(12),o=[0,0,-1,1],a=Ae.dotVec4(o,i)/Ae.dotVec4(o,s);return n.project.unproject(e,a,pc,vc,t),t}},{key:"destroy",value:function(){}}]),e}(),Cc=Ae.vec3(),kc=Ae.vec3(),Mc=Ae.vec3(),Ec=Ae.vec4(),Fc=Ae.vec4(),xc=Ae.vec4(),Uc=Math.PI-.001,Ic=function(){function e(t,n){var r=this;x(this,e),this._scene=t,this._configs=n,this._pivotWorldPos=Ae.vec3(),this._cameraOffset=Ae.vec3(),this._azimuth=0,this._polar=0,this._radius=0,this._pivotPosSet=!1,this._pivoting=!1,this._shown=!1,this._pivotSphereEnabled=!1,this._pivotSphere=null,this._pivotSphereSize=1,this._pivotSphereGeometry=null,this._pivotSphereMaterial=null,this._rtcCenter=Ae.vec3(),this._rtcPos=Ae.vec3(),this._pivotViewPos=Ae.vec4(),this._pivotProjPos=Ae.vec4(),this._pivotCanvasPos=Ae.vec2(),this._cameraDirty=!0,this._onViewMatrix=this._scene.camera.on("viewMatrix",(function(){r._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(function(){r._cameraDirty=!0})),this._onTick=this._scene.on("tick",(function(){r.updatePivotElement(),r.updatePivotSphere()}))}return I(e,[{key:"createPivotSphere",value:function(){var e=this.getPivotPos(),t=Ae.vec3();Ae.decomposeMat4(Ae.inverseMat4(this._scene.viewer.camera.viewMatrix,Ae.mat4()),t,Ae.vec4(),Ae.vec3());var n=Ae.distVec3(t,e),r=Math.tan(Math.PI/500)*n*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(r/=this._scene.camera.ortho.scale/2),Jt(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new bt(this._scene,It({radius:r})),this._pivotSphere=new Gr(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}},{key:"destroyPivotSphere",value:function(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}},{key:"updatePivotElement",value:function(){var e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){Ae.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,Ae.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);var n=t.boundary,r=n[2],i=n[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*r/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);var s=t._lastBoundingClientRect;if(!s||t._canvasSizeChanged){var o=t.canvas;s=t._lastBoundingClientRect=o.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(s.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(s.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}},{key:"updatePivotSphere",value:function(){this._pivoting&&this._pivotSphere&&(Jt(this.getPivotPos(),this._rtcCenter,this._rtcPos),Ae.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}},{key:"setPivotElement",value:function(e){this._pivotElement=e}},{key:"enablePivotSphere",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);var t=e.color||[1,0,0];this._pivotSphereMaterial=new Zr(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}},{key:"disablePivotSphere",value:function(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}},{key:"startPivot",value:function(){var e=this._scene.camera,t=Ae.lookAtMat4v(e.eye,e.look,e.up);Ae.transformPoint3(t,this.getPivotPos(),this._cameraOffset);var n=this.getPivotPos();this._cameraOffset[2]+=Ae.distVec3(e.eye,n),t=Ae.inverseMat4(t);var r=Ae.transformVec3(t,this._cameraOffset),i=Ae.vec3();if(Ae.subVec3(e.eye,n,i),Ae.addVec3(i,r),e.zUp){var s=i[1];i[1]=i[2],i[2]=s}this._radius=Ae.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}},{key:"_cameraLookingDownwards",value:function(){var e=this._scene.camera,t=Ae.normalizeVec3(Ae.subVec3(e.look,e.eye,Cc)),n=Ae.cross3Vec3(t,e.worldUp,kc);return Ae.sqLenVec3(n)<=1e-4}},{key:"getPivoting",value:function(){return this._pivoting}},{key:"setPivotPos",value:function(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}},{key:"setCanvasPivotPos",value:function(e){var t=this._scene.camera,n=Math.abs(Ae.distVec3(this._scene.center,t.eye)),r=t.project.transposedMatrix,i=r.subarray(8,12),s=r.subarray(12),o=[0,0,-1,1],a=Ae.dotVec4(o,i)/Ae.dotVec4(o,s),A=Ec;t.project.unproject(e,a,Fc,xc,A);var c=Ae.normalizeVec3(Ae.subVec3(A,t.eye,Cc)),u=Ae.addVec3(t.eye,Ae.mulVec3Scalar(c,n,kc),Mc);this.setPivotPos(u)}},{key:"getPivotPos",value:function(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}},{key:"continuePivot",value:function(e,t){if(this._pivoting&&(0!==e||0!==t)){var n=this._scene.camera,r=-e,i=-t;1===n.worldUp[2]&&(r=-r),this._azimuth+=.01*-r;var s=i<0,o=i>0,a=Math.abs(this._polar-.001)<.005,A=Math.abs(this._polar-Uc)<.005,c=this._polar+.01*i;c=a&&s?.001:A&&o?Uc:Ae.clamp(c,.001,Uc),this._polar=c;var u=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===n.worldUp[2]){var l=u[1];u[1]=u[2],u[2]=l}var h=Ae.lenVec3(Ae.subVec3(n.look,n.eye,Ae.vec3())),d=this.getPivotPos();Ae.addVec3(u,d);var f=Ae.lookAtMat4v(u,d,n.worldUp);f=Ae.inverseMat4(f);var p=Ae.transformVec3(f,this._cameraOffset);f[12]-=p[0],f[13]-=p[1],f[14]-=p[2];var v=[f[8],f[9],f[10]];n.eye=[f[12],f[13],f[14]],Ae.subVec3(n.eye,Ae.mulVec3Scalar(v,h),n.look),n.up=[f[4],f[5],f[6]],this.showPivot()}}},{key:"showPivot",value:function(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}},{key:"hidePivot",value:function(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}},{key:"endPivot",value:function(){this._pivoting=!1}},{key:"destroy",value:function(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}]),e}(),Tc=function(){function e(t,n){x(this,e),this._scene=t.scene,this._cameraControl=t,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=n,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=Ae.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}return I(e,[{key:"update",value:function(){if(this._configs.pointerEnabled&&(this.schedulePickEntity||this.schedulePickSurface)){var e="".concat(~~this.pickCursorPos[0],"-").concat(~~this.pickCursorPos[1],"-").concat(this.scheduleSnapOrPick,"-").concat(this.schedulePickSurface,"-").concat(this.schedulePickEntity);if(this._lastHash!==e){this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;var t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var n=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});n&&(n.snappedToEdge||n.snappedToVertex)?(this.snapPickResult=n,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var r=this.pickResult.canvasPos;if(r[0]===this.pickCursorPos[0]&&r[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){var i=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(i[0]===this.pickCursorPos[0]&&i[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}}}},{key:"fireEvents",value:function(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){var e=new Qa;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){var t=this.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=t)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}]),e}(),Pc=Ae.vec2(),Sc=function(){function e(t,n,r,i,s){x(this,e),this._scene=t;var o,a,A,c=n.pickController,u=n.cameraControl,l=0,h=0,d=0,f=0,p=!1,v=Ae.vec3(),g=!0,m=this._scene.canvas.canvas,y=[];function _(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];b(),e&&w()}function b(){l=i.pointerCanvasPos[0],h=i.pointerCanvasPos[1],d=i.pointerCanvasPos[0],f=i.pointerCanvasPos[1]}function w(){c.pickCursorPos=i.pointerCanvasPos,c.schedulePickSurface=!0,c.update(),c.picked&&c.pickedSurface&&c.pickResult&&c.pickResult.worldPos?(p=!0,v.set(c.pickResult.worldPos)):p=!1}document.addEventListener("keydown",this._documentKeyDownHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!0}}),document.addEventListener("keyup",this._documentKeyUpHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!1}}),document.addEventListener("visibilitychange",this._onVisibilityChange=function(){y.splice(0)}),window.addEventListener("blur",this._onBlur=function(){y.splice(0)}),m.addEventListener("mousedown",this._mouseDownHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:y[t.input.KEY_SHIFT]||r.planView?(o=!0,y[t.input.MOUSE_LEFT_BUTTON]=!0,_()):(o=!0,y[t.input.MOUSE_LEFT_BUTTON]=!0,_(!1));break;case 2:a=!0,y[t.input.MOUSE_MIDDLE_BUTTON]=!0,_();break;case 3:A=!0,y[t.input.MOUSE_RIGHT_BUTTON]=!0,r.panRightClick&&_()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&(o||a||A)){var n=t.canvas.boundary,c=n[2],d=n[3],f=i.pointerCanvasPos[0],g=i.pointerCanvasPos[1],m=r.planView||u._isKeyDownForAction(u.MOUSE_PAN,y),_=u._isKeyDownForAction(u.MOUSE_ROTATE,y),b=document.pointerLockElement?e.movementX:f-l,w=document.pointerLockElement?e.movementY:g-h;if(m){var B=t.camera;if("perspective"===B.projection){var C=Math.abs(p?Ae.lenVec3(Ae.subVec3(v,t.camera.eye,[])):t.camera.eyeLookDist)*Math.tan(B.perspective.fov/2*Math.PI/180);s.panDeltaX+=1.5*b*C/d,s.panDeltaY+=1.5*w*C/d}else s.panDeltaX+=.5*B.ortho.scale*(b/d),s.panDeltaY+=.5*B.ortho.scale*(w/d)}else _&&(r.planView||(r.firstPerson?(s.rotateDeltaY-=b/c*r.dragRotationRate/2,s.rotateDeltaX+=w/d*(r.dragRotationRate/4)):(s.rotateDeltaY-=b/c*(1.5*r.dragRotationRate),s.rotateDeltaX+=w/d*(1.5*r.dragRotationRate))));l=f,h=g}}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){r.active&&r.pointerEnabled&&i.mouseover&&(g=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:case 2:case 3:o=!1,a=!1,A=!1,y[t.input.MOUSE_LEFT_BUTTON]=!1,y[t.input.MOUSE_MIDDLE_BUTTON]=!1,y[t.input.MOUSE_RIGHT_BUTTON]=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=function(e){if(r.active&&r.pointerEnabled){if(3===e.which){!function(e,t){if(e){for(var n=e.target,r=0,i=0,s=0,o=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,s+=n.scrollLeft,o+=n.scrollTop,n=n.offsetParent;t[0]=e.pageX+s-r,t[1]=e.pageY+o-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Pc);var t=Pc[0],i=Pc[1];Math.abs(t-d)<3&&Math.abs(i-f)<3&&n.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Pc,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=function(){r.active&&r.pointerEnabled});var B=1/60,C=null;m.addEventListener("wheel",this._mouseWheelHandler=function(e){if(r.active&&r.pointerEnabled&&r.zoomOnMouseWheel&&u._isKeyDownForAction(u.MOUSE_DOLLY,y)){var t=performance.now()/1e3,n=null!==C?t-C:0;C=t,n>.05&&(n=.05),n<B&&(n=B);var o=Math.max(-1,Math.min(1,40*-e.deltaY));if(0!==o){var a=o/Math.abs(o);s.dollyDelta+=-a*n*r.mouseWheelDollyRate,g&&(i.followPointerDirty=!0,g=!1)}}},{passive:!0})}return I(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;document.removeEventListener("keydown",this._documentKeyDownHandler),document.removeEventListener("keyup",this._documentKeyUpHandler),document.removeEventListener("visibilitychange",this._onVisibilityChange),window.removeEventListener("blur",this._onBlur),e.removeEventListener("mousedown",this._mouseDownHandler),document.removeEventListener("mousemove",this._documentMouseMoveHandler),e.removeEventListener("mousemove",this._canvasMouseMoveHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._mouseUpHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("wheel",this._mouseWheelHandler)}}]),e}(),Dc=Ae.vec3(),Qc=Ae.vec3(),Rc=Ae.vec3(),Oc=Ae.vec3(),Vc=Ae.vec3(),Lc={eye:Ae.vec3(),look:Ae.vec3(),up:Ae.vec3()},Hc=function(){function e(t,n,r,i){x(this,e),this._scene=t;var s=n.cameraControl,o=t.camera;this._onSceneKeyDown=t.input.on("keydown",(function(){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(!r.keyboardEnabledOnlyIfMouseover||i.mouseover)){var e=s._isKeyDownForAction(s.AXIS_VIEW_RIGHT),a=s._isKeyDownForAction(s.AXIS_VIEW_BACK),A=s._isKeyDownForAction(s.AXIS_VIEW_LEFT),c=s._isKeyDownForAction(s.AXIS_VIEW_FRONT),u=s._isKeyDownForAction(s.AXIS_VIEW_TOP),l=s._isKeyDownForAction(s.AXIS_VIEW_BOTTOM);if(e||a||A||c||u||l){var h=t.aabb,d=Ae.getAABB3Diag(h);Ae.getAABB3Center(h,Dc);var f=Math.abs(d/Math.tan(n.cameraFlight.fitFOV*Ae.DEGTORAD)),p=1.1*d;Lc.orthoScale=p,e?(Lc.eye.set(Ae.addVec3(Dc,Ae.mulVec3Scalar(o.worldRight,f,Qc),Vc)),Lc.look.set(Dc),Lc.up.set(o.worldUp)):a?(Lc.eye.set(Ae.addVec3(Dc,Ae.mulVec3Scalar(o.worldForward,f,Qc),Vc)),Lc.look.set(Dc),Lc.up.set(o.worldUp)):A?(Lc.eye.set(Ae.addVec3(Dc,Ae.mulVec3Scalar(o.worldRight,-f,Qc),Vc)),Lc.look.set(Dc),Lc.up.set(o.worldUp)):c?(Lc.eye.set(Ae.addVec3(Dc,Ae.mulVec3Scalar(o.worldForward,-f,Qc),Vc)),Lc.look.set(Dc),Lc.up.set(o.worldUp)):u?(Lc.eye.set(Ae.addVec3(Dc,Ae.mulVec3Scalar(o.worldUp,f,Qc),Vc)),Lc.look.set(Dc),Lc.up.set(Ae.normalizeVec3(Ae.mulVec3Scalar(o.worldForward,1,Rc),Oc))):l&&(Lc.eye.set(Ae.addVec3(Dc,Ae.mulVec3Scalar(o.worldUp,-f,Qc),Vc)),Lc.look.set(Dc),Lc.up.set(Ae.normalizeVec3(Ae.mulVec3Scalar(o.worldForward,-1,Rc)))),!r.firstPerson&&r.followPointer&&n.pivotController.setPivotPos(Dc),n.cameraFlight.duration>0?n.cameraFlight.flyTo(Lc,(function(){n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot()})):(n.cameraFlight.jumpTo(Lc),n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot())}}}))}return I(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.input.off(this._onSceneKeyDown)}}]),e}(),Nc=function(){function e(t,n,r,i,s){var o=this;x(this,e),this._scene=t;var a=n.pickController,A=n.pivotController,c=n.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null,this._lastClickedWorldPos=null;var u=!1,l=!1,h=this._scene.canvas.canvas,d=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var i=e&&e.entity?e.entity.aabb:t.aabb;if(r){var s=t.camera;Ae.subVec3(s.eye,s.look,[]),n.cameraFlight.flyTo({aabb:i})}else n.cameraFlight.flyTo({aabb:i})},f=t.tickify(this._canvasMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&!u&&!l){if(c.hasSubs("rayMove")){var n=Ae.vec3(),s=Ae.vec3();Ae.canvasPosToWorldRay(t.canvas.canvas,t.camera.viewMatrix,t.camera.projMatrix,t.camera.projection,i.pointerCanvasPos,n,s),c.fire("rayMove",{canvasPos:i.pointerCanvasPos,ray:{origin:n,direction:s,canvasPos:i.pointerCanvasPos}},!0)}var A=c.hasSubs("hover"),h=c.hasSubs("hoverEnter"),d=c.hasSubs("hoverOut"),f=c.hasSubs("hoverOff"),p=c.hasSubs("hoverSurface"),v=c.hasSubs("hoverSnapOrSurface");if(A||h||d||f||p||v)if(a.pickCursorPos=i.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=p,a.scheduleSnapOrPick=v,a.update(),a.pickResult){if(a.pickResult.entity){var g=a.pickResult.entity.id;o._lastPickedEntityId!==g&&(void 0!==o._lastPickedEntityId&&c.fire("hoverOut",{entity:t.objects[o._lastPickedEntityId]},!0),c.fire("hoverEnter",a.pickResult,!0),o._lastPickedEntityId=g)}c.fire("hover",a.pickResult,!0),(a.pickResult.worldPos||a.pickResult.snappedWorldPos)&&c.fire("hoverSurface",a.pickResult,!0)}else void 0!==o._lastPickedEntityId&&(c.fire("hoverOut",{entity:t.objects[o._lastPickedEntityId]},!0),o._lastPickedEntityId=void 0),c.fire("hoverOff",{canvasPos:a.pickCursorPos},!0)}});h.addEventListener("mousemove",f),h.addEventListener("mousedown",this._canvasMouseDownHandler=function(e){if(1===e.which&&(u=!0),3===e.which&&(l=!0),1===e.which&&r.active&&r.pointerEnabled&&(i.mouseDownClientX=e.clientX,i.mouseDownClientY=e.clientY,i.mouseDownCursorX=i.pointerCanvasPos[0],i.mouseDownCursorY=i.pointerCanvasPos[1],!r.firstPerson&&r.followPointer&&(a.pickCursorPos=i.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),1===e.which))){var n=a.pickResult;n&&n.worldPos?(A.setPivotPos(n.worldPos),A.startPivot(),o._lastClickedWorldPos=n.worldPos.slice()):(r.smartPivot?A.setCanvasPivotPos(i.pointerCanvasPos):o._lastClickedWorldPos?A.setPivotPos(o._lastClickedWorldPos):A.setPivotPos(t.camera.look),A.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){1===e.which&&(u=!1),3===e.which&&(l=!1),A.getPivoting()&&A.endPivot()}),h.addEventListener("mouseup",this._canvasMouseUpHandler=function(e){if(r.active&&r.pointerEnabled&&(1===e.which&&(A.hidePivot(),!(Math.abs(e.clientX-i.mouseDownClientX)>3||Math.abs(e.clientY-i.mouseDownClientY)>3)))){var s=c.hasSubs("picked"),u=c.hasSubs("pickedNothing"),l=c.hasSubs("pickedSurface"),h=c.hasSubs("doublePicked"),f=c.hasSubs("doublePickedSurface"),p=c.hasSubs("doublePickedNothing");if(!(r.doublePickFlyTo||h||f||p))return(s||u||l)&&(a.pickCursorPos=i.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=l,a.update(),a.pickResult?(c.fire("picked",a.pickResult,!0),a.pickedSurface&&c.fire("pickedSurface",a.pickResult,!0)):c.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0)),void(o._clicks=0);if(o._clicks++,1===o._clicks){a.pickCursorPos=i.pointerCanvasPos,a.schedulePickEntity=r.doublePickFlyTo,a.schedulePickSurface=l,a.update();var v=a.pickResult,g=a.pickedSurface;o._timeout=setTimeout((function(){v?(c.fire("picked",v,!0),g&&(c.fire("pickedSurface",v,!0),!r.firstPerson&&r.followPointer&&(n.pivotController.setPivotPos(v.worldPos),n.pivotController.startPivot()&&n.pivotController.showPivot()))):c.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0),o._clicks=0}),r.doubleClickTimeFrame)}else{if(null!==o._timeout&&(window.clearTimeout(o._timeout),o._timeout=null),a.pickCursorPos=i.pointerCanvasPos,a.schedulePickEntity=r.doublePickFlyTo||h||f,a.schedulePickSurface=a.schedulePickEntity&&f,a.update(),a.pickResult){if(c.fire("doublePicked",a.pickResult,!0),a.pickedSurface&&c.fire("doublePickedSurface",a.pickResult,!0),r.doublePickFlyTo&&(d(a.pickResult),!r.firstPerson&&r.followPointer)){var m=a.pickResult.entity.aabb,y=Ae.getAABB3Center(m);n.pivotController.setPivotPos(y),n.pivotController.startPivot()&&n.pivotController.showPivot()}}else if(c.fire("doublePickedNothing",{canvasPos:i.pointerCanvasPos},!0),r.doublePickFlyTo&&(d(),!r.firstPerson&&r.followPointer)){var _=t.aabb,b=Ae.getAABB3Center(_);n.pivotController.setPivotPos(b),n.pivotController.startPivot()&&n.pivotController.showPivot()}o._clicks=0}}},!1)}return I(e,[{key:"reset",value:function(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}]),e}(),Gc=function(){function e(t,n,r,i,s){x(this,e),this._scene=t;var o=t.input,a=[];t.canvas.canvas;var A=!0;this._onSceneMouseMove=o.on("mousemove",(function(){A=!0})),this._onSceneKeyDown=o.on("keydown",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(r.keyboardEnabledOnlyIfMouseover&&!i.mouseover||(a[e]=!0))})),this._onSceneKeyUp=o.on("keyup",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(a[e]=!1,n.pivotController.getPivoting()&&n.pivotController.endPivot())})),document.addEventListener("visibilitychange",this._onVisibilityChange=function(){a.splice(0)}),window.addEventListener("blur",this._onBlur=function(){a.splice(0)}),this._onTick=t.on("tick",(function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(!r.keyboardEnabledOnlyIfMouseover||i.mouseover)){var c=n.cameraControl,u=e.deltaTime/1e3;if(!r.planView){var l=c._isKeyDownForAction(c.ROTATE_Y_POS,a),h=c._isKeyDownForAction(c.ROTATE_Y_NEG,a),d=c._isKeyDownForAction(c.ROTATE_X_POS,a),f=c._isKeyDownForAction(c.ROTATE_X_NEG,a),p=u*r.keyboardRotationRate;(l||h||d||f)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),l?s.rotateDeltaY+=p:h&&(s.rotateDeltaY-=p),d?s.rotateDeltaX+=p:f&&(s.rotateDeltaX-=p),!r.firstPerson&&r.followPointer&&n.pivotController.startPivot())}if(!a[o.KEY_CTRL]&&!a[o.KEY_ALT]){var v=c._isKeyDownForAction(c.DOLLY_BACKWARDS,a),g=c._isKeyDownForAction(c.DOLLY_FORWARDS,a);if(v||g){var m=u*r.keyboardDollyRate;!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),g?s.dollyDelta-=m:v&&(s.dollyDelta+=m),A&&(i.followPointerDirty=!0,A=!1)}}var y=c._isKeyDownForAction(c.PAN_FORWARDS,a),_=c._isKeyDownForAction(c.PAN_BACKWARDS,a),b=c._isKeyDownForAction(c.PAN_LEFT,a),w=c._isKeyDownForAction(c.PAN_RIGHT,a),B=c._isKeyDownForAction(c.PAN_UP,a),C=c._isKeyDownForAction(c.PAN_DOWN,a),k=(a[o.KEY_ALT]?.3:1)*u*r.keyboardPanRate;(y||_||b||w||B||C)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),C?s.panDeltaY+=k:B&&(s.panDeltaY+=-k),w?s.panDeltaX+=-k:b&&(s.panDeltaX+=k),_?s.panDeltaZ+=k:y&&(s.panDeltaZ+=-k))}}))}return I(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),document.removeEventListener("visibilitychange",this._onVisibilityChange),window.removeEventListener("blur",this._onBlur),this._scene.input.off(this._onSceneKeyUp)}}]),e}(),jc=Ae.vec3(),Wc=function(){function e(t,n,r,i,s){x(this,e),this._scene=t;var o=t.camera,a=n.pickController,A=n.pivotController,c=n.panController,u=n.cameraControl,l=1,h=1,d=null;this._onTick=t.on("tick",(function(){if(r.active&&r.pointerEnabled){var e="default";if(Math.abs(s.dollyDelta)<.001&&(s.dollyDelta=0),Math.abs(s.rotateDeltaX)<.001&&(s.rotateDeltaX=0),Math.abs(s.rotateDeltaY)<.001&&(s.rotateDeltaY=0),0===s.rotateDeltaX&&0===s.rotateDeltaY||(s.dollyDelta=0),r.followPointer){if(--l<=0&&(l=1,0!==s.dollyDelta)){if(0===s.rotateDeltaY&&0===s.rotateDeltaX&&r.followPointer&&i.followPointerDirty&&(a.pickCursorPos=i.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.pickResult&&a.pickResult.worldPos?d=a.pickResult.worldPos:(h=1,d=null),i.followPointerDirty=!1),d){var n=Math.abs(Ae.lenVec3(Ae.subVec3(d,t.camera.eye,jc)));h=n/r.dollyProximityThreshold}h<r.dollyMinSpeed&&(h=r.dollyMinSpeed)}}else h=1,d=null;var f=s.dollyDelta*h;if(0===s.rotateDeltaY&&0===s.rotateDeltaX||(!r.firstPerson&&r.followPointer&&A.getPivoting()?(A.continuePivot(s.rotateDeltaY,s.rotateDeltaX),A.showPivot()):(0!==s.rotateDeltaX&&(r.firstPerson?o.pitch(-s.rotateDeltaX):o.orbitPitch(s.rotateDeltaX)),0!==s.rotateDeltaY&&(r.firstPerson?o.yaw(s.rotateDeltaY):o.orbitYaw(s.rotateDeltaY))),s.rotateDeltaX*=r.rotationInertia,s.rotateDeltaY*=r.rotationInertia,e=u._cursors.rotate),Math.abs(s.panDeltaX)<.001&&(s.panDeltaX=0),Math.abs(s.panDeltaY)<.001&&(s.panDeltaY=0),Math.abs(s.panDeltaZ)<.001&&(s.panDeltaZ=0),0!==s.panDeltaX||0!==s.panDeltaY||0!==s.panDeltaZ){var p,v,g=Ae.vec3();if(g[0]=s.panDeltaX,g[1]=s.panDeltaY,g[2]=s.panDeltaZ,r.constrainVertical){o.xUp?(p=o.eye[0],v=o.look[0]):o.yUp?(p=o.eye[1],v=o.look[1]):o.zUp&&(p=o.eye[2],v=o.look[2]),o.pan(g);var m=o.eye,y=o.look;o.xUp?(m[0]=p,y[0]=v):o.yUp?(m[1]=p,y[1]=v):o.zUp&&(m[2]=p,y[2]=v),o.eye=m,o.look=y}else o.pan(g);e=u._cursors.pan}if(s.panDeltaX*=r.panInertia,s.panDeltaY*=r.panInertia,s.panDeltaZ*=r.panInertia,0!==f){if(e=f<0?u._cursors.dollyForward:u._cursors.dollyBackward,r.firstPerson){var _,b;if(r.constrainVertical&&(o.xUp?(_=o.eye[0],b=o.look[0]):o.yUp?(_=o.eye[1],b=o.look[1]):o.zUp&&(_=o.eye[2],b=o.look[2])),r.followPointer)c.dollyToCanvasPos(d,i.pointerCanvasPos,-f)&&(i.followPointerDirty=!0);else o.pan([0,0,f]),o.ortho.scale=o.ortho.scale-f;if(r.constrainVertical){var w=o.eye,B=o.look;o.xUp?(w[0]=_,B[0]=b):o.yUp?(w[1]=_,B[1]=b):o.zUp&&(w[2]=_,B[2]=b),o.eye=w,o.look=B}}else if(r.planView){if(r.followPointer)c.dollyToCanvasPos(d,i.pointerCanvasPos,-f)&&(i.followPointerDirty=!0);else o.ortho.scale=o.ortho.scale+f,o.zoom(f)}else{if(r.followPointer)c.dollyToCanvasPos(d,i.pointerCanvasPos,-f)&&(i.followPointerDirty=!0);else o.ortho.scale=o.ortho.scale+f,o.zoom(f)}s.dollyDelta*=r.dollyInertia}a.fireEvents(),document.body.style.cursor=e}}))}return I(e,[{key:"destroy",value:function(){this._scene.off(this._onTick)}}]),e}(),zc=function(){function e(t,n,r,i,s){x(this,e),this._scene=t;var o=this._scene.canvas.canvas;o.addEventListener("mouseenter",this._mouseEnterHandler=function(){i.mouseover=!0}),o.addEventListener("mouseleave",this._mouseLeaveHandler=function(){i.mouseover=!1,o.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=function(e){Xc(e,o,i.pointerCanvasPos)}),o.addEventListener("mousedown",this._mouseDownHandler=function(e){r.active&&r.pointerEnabled&&(Xc(e,o,i.pointerCanvasPos),i.mouseover=!0)}),o.addEventListener("mouseup",this._mouseUpHandler=function(e){r.active&&r.pointerEnabled})}return I(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}]),e}();function Xc(e,t,n){if(e){var r=t.getBoundingClientRect(),i=r.left,s=r.top;n[0]=e.clientX-i,n[1]=e.clientY-s}else e=window.event,n[0]=e.x,n[1]=e.y;return n}var Kc=function(e,t){if(e){for(var n=e.target,r=0,i=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,n=n.offsetParent;t[0]=e.pageX-r,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t},Zc=function(){function e(t,n,r,i,s){x(this,e),this._scene=t;var o=n.pickController,a=n.pivotController,A=Ae.vec2(),c=Ae.vec2(),u=Ae.vec2(),l=Ae.vec2(),h=[],d=this._scene.canvas.canvas,f=0,p=!1;this._onTick=t.on("tick",(function(){p=!1})),d.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){if(r.active&&r.pointerEnabled){e.preventDefault();var n=e.touches,s=e.changedTouches;for(i.touchStartTime=Date.now(),1===n.length&&1===s.length&&(Kc(n[0],A),r.followPointer&&(o.pickCursorPos=A,o.schedulePickSurface=!0,o.update(),r.planView||(o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(a.setPivotPos(o.pickResult.worldPos),!r.firstPerson&&a.startPivot()&&a.showPivot()):(r.smartPivot?a.setCanvasPivotPos(i.pointerCanvasPos):a.setPivotPos(t.camera.look),!r.firstPerson&&a.startPivot()&&a.showPivot()))));h.length<n.length;)h.push(Ae.vec2());for(var c=0,u=n.length;c<u;++c)Kc(n[c],h[c]);f=n.length}}),d.addEventListener("touchend",this._canvasTouchEndHandler=function(){a.getPivoting()&&(a.endPivot(),a.hidePivot())}),d.addEventListener("touchmove",this._canvasTouchMoveHandler=function(e){if(r.active&&r.pointerEnabled&&(e.stopPropagation(),e.preventDefault(),!p)){p=!0;var n=t.canvas.boundary,a=n[2],A=n[3],d=e.touches;if(e.touches.length===f){if(1===f){Kc(d[0],c),Ae.subVec2(c,h[0],l);var v=l[0],g=l[1];if(null!==i.longTouchTimeout&&(Math.abs(v)>r.longTapRadius||Math.abs(g)>r.longTapRadius)&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),r.planView){var m=t.camera;if("perspective"===m.projection){var y=Math.abs(t.camera.eyeLookDist)*Math.tan(m.perspective.fov/2*Math.PI/180);s.panDeltaX+=v*y/A*r.touchPanRate,s.panDeltaY+=g*y/A*r.touchPanRate}else s.panDeltaX+=.5*m.ortho.scale*(v/A)*r.touchPanRate,s.panDeltaY+=.5*m.ortho.scale*(g/A)*r.touchPanRate}else s.rotateDeltaY-=v/a*(1*r.dragRotationRate),s.rotateDeltaX+=g/A*(1.5*r.dragRotationRate)}else if(2===f){var _=d[0],b=d[1];Kc(_,c),Kc(b,u);var w=Ae.geometricMeanVec2(h[0],h[1]),B=Ae.geometricMeanVec2(c,u),C=Ae.vec2();Ae.subVec2(w,B,C);var k=C[0],M=C[1],E=t.camera,F=Ae.distVec2([_.pageX,_.pageY],[b.pageX,b.pageY]),x=(Ae.distVec2(h[0],h[1])-F)*r.touchDollyRate;if(s.dollyDelta=x,Math.abs(x)<1)if("perspective"===E.projection){var U=o.pickResult?o.pickResult.worldPos:t.center,I=Math.abs(Ae.lenVec3(Ae.subVec3(U,t.camera.eye,[])))*Math.tan(E.perspective.fov/2*Math.PI/180);s.panDeltaX-=k*I/A*r.touchPanRate,s.panDeltaY-=M*I/A*r.touchPanRate}else s.panDeltaX-=.5*E.ortho.scale*(k/A)*r.touchPanRate,s.panDeltaY-=.5*E.ortho.scale*(M/A)*r.touchPanRate;i.pointerCanvasPos=B}for(var T=0;T<f;++T)Kc(d[T],h[T])}}})}return I(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler),e.removeEventListener("touchmove",this._canvasTouchMoveHandler),this._scene.off(this._onTick)}}]),e}(),Jc=function(e,t){if(e){for(var n=e.target,r=0,i=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,n=n.offsetParent;t[0]=e.pageX-r,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t},Yc=function(){function e(t,n,r,i,s){x(this,e),this._scene=t;var o,a=n.pickController,A=n.cameraControl,c=[],u=new Float32Array(2),l=-1,h=-1,d=this._scene.canvas.canvas,f=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var i=e?e.entity.aabb:t.aabb;if(r){var s=t.camera;Ae.subVec3(s.eye,s.look,[]),n.cameraFlight.flyTo({aabb:i})}else n.cameraFlight.flyTo({aabb:i})};d.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){if(r.active&&r.pointerEnabled){null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null);var t=e.touches,s=e.changedTouches;if(o=Date.now(),1===t.length&&1===s.length){l=o,Jc(t[0],u);var a=u[0],A=u[1],h=t[0].pageX,d=t[0].pageY;i.longTouchTimeout=setTimeout((function(){r.active&&r.pointerEnabled&&n.cameraControl.fire("rightClick",{pagePos:[Math.round(h),Math.round(d)],canvasPos:[Math.round(a),Math.round(A)],event:e},!0),i.longTouchTimeout=null}),r.longTapTimeout)}else l=-1;for(;c.length<t.length;)c.push(new Float32Array(2));for(var f=0,p=t.length;f<p;++f)Jc(t[f],c[f]);c.length=t.length}},{passive:!0}),d.addEventListener("touchend",this._canvasTouchEndHandler=function(e){if(r.active&&r.pointerEnabled){var t=Date.now(),n=e.touches,s=e.changedTouches,o=A.hasSubs("pickedSurface");null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),0===n.length&&1===s.length&&l>-1&&t-l<150&&(h>-1&&l-h<325?(Jc(s[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=o,a.update(),a.pickResult?(a.pickResult.touchInput=!0,A.fire("doublePicked",a.pickResult),a.pickedSurface&&A.fire("doublePickedSurface",a.pickResult),r.doublePickFlyTo&&f(a.pickResult)):(A.fire("doublePickedNothing"),r.doublePickFlyTo&&f()),h=-1):Ae.distVec2(c[0],u)<4&&(Jc(s[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=o,a.update(),a.pickResult?(a.pickResult.touchInput=!0,A.fire("picked",a.pickResult),a.pickedSurface&&A.fire("pickedSurface",a.pickResult)):A.fire("pickedNothing"),h=t),l=-1),c.length=n.length;for(var d=0,p=n.length;d<p;++d)c[d][0]=n[d].pageX,c[d][1]=n[d].pageY}},{passive:!0})}return I(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler)}}]),e}(),qc=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)).PAN_LEFT=0,r.PAN_RIGHT=1,r.PAN_UP=2,r.PAN_DOWN=3,r.PAN_FORWARDS=4,r.PAN_BACKWARDS=5,r.ROTATE_X_POS=6,r.ROTATE_X_NEG=7,r.ROTATE_Y_POS=8,r.ROTATE_Y_NEG=9,r.DOLLY_FORWARDS=10,r.DOLLY_BACKWARDS=11,r.AXIS_VIEW_RIGHT=12,r.AXIS_VIEW_BACK=13,r.AXIS_VIEW_LEFT=14,r.AXIS_VIEW_FRONT=15,r.AXIS_VIEW_TOP=16,r.AXIS_VIEW_BOTTOM=17,r.MOUSE_PAN=18,r.MOUSE_ROTATE=19,r.MOUSE_DOLLY=20,r._keyMap={},r.scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},r._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,zoomOnMouseWheel:!0,snapToVertex:true,snapToEdge:true,snapRadius:30,keyboardEnabledOnlyIfMouseover:!0,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},r._states={pointerCanvasPos:Ae.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:Ae.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},r._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};var s=r.scene;return r._controllers={cameraControl:w(r),pickController:new Tc(w(r),r._configs),pivotController:new Ic(s,r._configs),panController:new Bc(s),cameraFlight:new et(w(r),{duration:.5})},r._handlers=[new zc(r.scene,r._controllers,r._configs,r._states,r._updates),new Zc(r.scene,r._controllers,r._configs,r._states,r._updates),new Sc(r.scene,r._controllers,r._configs,r._states,r._updates),new Hc(r.scene,r._controllers,r._configs,r._states,r._updates),new Nc(r.scene,r._controllers,r._configs,r._states,r._updates),new Yc(r.scene,r._controllers,r._configs,r._states,r._updates),new Gc(r.scene,r._controllers,r._configs,r._states,r._updates)],r._cursors={dollyForward:"zoom-in",dollyBackward:"zoom-out",rotate:"grabbing",pan:"move"},r._cameraUpdater=new Wc(r.scene,r._controllers,r._configs,r._states,r._updates),r.navMode=i.navMode,i.planView&&(r.planView=i.planView),r.constrainVertical=i.constrainVertical,i.keyboardLayout?r.keyboardLayout=i.keyboardLayout:r.keyMap=i.keyMap,r.doublePickFlyTo=i.doublePickFlyTo,r.panRightClick=i.panRightClick,r.active=i.active,r.followPointer=i.followPointer,r.rotationInertia=i.rotationInertia,r.keyboardPanRate=i.keyboardPanRate,r.touchPanRate=i.touchPanRate,r.keyboardRotationRate=i.keyboardRotationRate,r.dragRotationRate=i.dragRotationRate,r.touchDollyRate=i.touchDollyRate,r.dollyInertia=i.dollyInertia,r.dollyProximityThreshold=i.dollyProximityThreshold,r.dollyMinSpeed=i.dollyMinSpeed,r.panInertia=i.panInertia,r.pointerEnabled=!0,r.keyboardDollyRate=i.keyboardDollyRate,r.mouseWheelDollyRate=i.mouseWheelDollyRate,r}return I(n,[{key:"keyMap",get:function(){return this._keyMap},set:function(e){if(e=e||"qwerty",ge.isString(e)){var t=this.scene.input,n={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":n[this.PAN_LEFT]=[t.KEY_A],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_Z],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6],n[this.MOUSE_PAN]=[[t.MOUSE_LEFT_BUTTON,t.KEY_SHIFT],this._configs.panRightClick?t.MOUSE_RIGHT_BUTTON:t.MOUSE_MIDDLE_BUTTON],n[this.MOUSE_ROTATE]=[t.MOUSE_LEFT_BUTTON],n[this.MOUSE_DOLLY]=[];break;case"azerty":n[this.PAN_LEFT]=[t.KEY_Q],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_W],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6],n[this.MOUSE_PAN]=[[t.MOUSE_LEFT_BUTTON,t.KEY_SHIFT],this._configs.panRightClick?t.MOUSE_RIGHT_BUTTON:t.MOUSE_MIDDLE_BUTTON],n[this.MOUSE_ROTATE]=[t.MOUSE_LEFT_BUTTON],n[this.MOUSE_DOLLY]=[]}this._keyMap=n}else{var r=e;this._keyMap=r}}},{key:"_areAllKeysDown",value:function(e,t){if(!t||t.length<=0)return!0;if(!e)return!1;for(var n=0,r=t.length;n<r;n++){if(!e[t[n]])return!1}return!0}},{key:"_isAnyOtherKeyDown",value:function(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n])if(Array.isArray(t)){if(t.indexOf(n)<0)return!0}else if(n!==t)return!0;return!1}},{key:"_isMouseAction",value:function(e){switch(e){case this.MOUSE_ROTATE:case this.MOUSE_DOLLY:case this.MOUSE_PAN:return!0;default:return!1}}},{key:"_isKeyDownForAction",value:function(e,t){var n=this._keyMap[e];if(!n)return!1;if(0===n.length&&this._isMouseAction(e))return!0;t||(t=this.scene.input.keyDown);for(var r=0,i=n.length;r<i;r++){var s=n[r];if(Array.isArray(s)){if(this._areAllKeysDown(t,s)&&!this._isAnyOtherKeyDown(t,s))return!0}else if(t[s]&&!this._isAnyOtherKeyDown(t,s))return!0}return!1}},{key:"pivotElement",set:function(e){this._controllers.pivotController.setPivotElement(e)}},{key:"active",get:function(){return this._configs.active},set:function(e){e=!1!==e,this._configs.active=e,this._handlers[1]._active=e,this._handlers[5]._active=e}},{key:"snapToVertex",get:function(){return this._configs.snapToVertex},set:function(e){this._configs.snapToVertex=!!e}},{key:"snapToEdge",get:function(){return this._configs.snapToEdge},set:function(e){this._configs.snapToEdge=!!e}},{key:"snapRadius",get:function(){return this._configs.snapRadius},set:function(e){e=e||30,this._configs.snapRadius=e}},{key:"keyboardEnabledOnlyIfMouseover",get:function(){return this._configs.keyboardEnabledOnlyIfMouseover},set:function(e){this._configs.keyboardEnabledOnlyIfMouseover=!!e}},{key:"navMode",get:function(){return this._configs.navMode},set:function(e){"firstPerson"!==(e=e||"orbit")&&"orbit"!==e&&"planView"!==e&&(this.error("Unsupported value for navMode: "+e+" - supported values are 'orbit', 'firstPerson' and 'planView' - defaulting to 'orbit'"),e="orbit"),this._configs.firstPerson="firstPerson"===e,this._configs.planView="planView"===e,(this._configs.firstPerson||this._configs.planView)&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this._configs.navMode=e}},{key:"pointerEnabled",get:function(){return this._configs.pointerEnabled},set:function(e){this._reset(),this._configs.pointerEnabled=!!e}},{key:"setCursorStyle",value:function(e,t){Object.prototype.hasOwnProperty.call(this._cursors,e)?this._cursors=d(d({},this._cursors),{},f({},e,t)):console.warn("Action '".concat(e,"' is not valid for cursor styles."))}},{key:"getCursorStyle",value:function(e){return this._cursors[e]||null}},{key:"_reset",value:function(){for(var e=0,t=this._handlers.length;e<t;e++){var n=this._handlers[e];n.reset&&n.reset()}this._updates.panDeltaX=0,this._updates.panDeltaY=0,this._updates.rotateDeltaX=0,this._updates.rotateDeltaY=0,this._updates.dolyDelta=0}},{key:"followPointer",get:function(){return this._configs.followPointer},set:function(e){this._configs.followPointer=!1!==e}},{key:"pivotPos",get:function(){return this._controllers.pivotController.getPivotPos()},set:function(e){this._controllers.pivotController.setPivotPos(e)}},{key:"dollyToPointer",get:function(){return this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer},set:function(e){this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer=e}},{key:"panToPointer",get:function(){return this.warn("panToPointer property is deprecated - replaced with followPointer"),!1},set:function(e){this.warn("panToPointer property is deprecated - replaced with followPointer")}},{key:"planView",get:function(){return this.warn("planView property is deprecated - replaced with navMode"),this._configs.planView},set:function(e){this._configs.planView=!!e,this._configs.firstPerson=!1,this._configs.planView&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this.warn("planView property is deprecated - replaced with navMode")}},{key:"firstPerson",get:function(){return this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson},set:function(e){this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson=!!e,this._configs.planView=!1,this._configs.firstPerson&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot())}},{key:"constrainVertical",get:function(){return this._configs.constrainVertical},set:function(e){this._configs.constrainVertical=!!e}},{key:"doublePickFlyTo",get:function(){return this._configs.doublePickFlyTo},set:function(e){this._configs.doublePickFlyTo=!1!==e}},{key:"panRightClick",get:function(){return this._configs.panRightClick},set:function(e){this._configs.panRightClick=!1!==e;var t=this._keyMap[this.MOUSE_PAN];if(t&&t.length>0)for(var n=this.scene.input,r=0,i=t.length;r<i;r++)this._configs.panRightClick&&t[r]===n.MOUSE_MIDDLE_BUTTON?this._keyMap[this.MOUSE_PAN][r]=n.MOUSE_RIGHT_BUTTON:this._configs.panRightClick||t[r]!==n.MOUSE_RIGHT_BUTTON||(this._keyMap[this.MOUSE_PAN][r]=n.MOUSE_MIDDLE_BUTTON)}},{key:"rotationInertia",get:function(){return this._configs.rotationInertia},set:function(e){this._configs.rotationInertia=null!=e?e:0}},{key:"keyboardPanRate",get:function(){return this._configs.keyboardPanRate},set:function(e){this._configs.keyboardPanRate=null!=e?e:5}},{key:"touchPanRate",get:function(){return this._configs.touchPanRate},set:function(e){this._configs.touchPanRate=null!=e?e:1}},{key:"keyboardRotationRate",get:function(){return this._configs.keyboardRotationRate},set:function(e){this._configs.keyboardRotationRate=null!=e?e:90}},{key:"dragRotationRate",get:function(){return this._configs.dragRotationRate},set:function(e){this._configs.dragRotationRate=null!=e?e:360}},{key:"keyboardDollyRate",get:function(){return this._configs.keyboardDollyRate},set:function(e){this._configs.keyboardDollyRate=null!=e?e:15}},{key:"touchDollyRate",get:function(){return this._configs.touchDollyRate},set:function(e){this._configs.touchDollyRate=null!=e?e:.2}},{key:"mouseWheelDollyRate",get:function(){return this._configs.mouseWheelDollyRate},set:function(e){this._configs.mouseWheelDollyRate=null!=e?e:100}},{key:"dollyInertia",get:function(){return this._configs.dollyInertia},set:function(e){this._configs.dollyInertia=null!=e?e:0}},{key:"dollyProximityThreshold",get:function(){return this._configs.dollyProximityThreshold},set:function(e){this._configs.dollyProximityThreshold=null!=e?e:35}},{key:"dollyMinSpeed",get:function(){return this._configs.dollyMinSpeed},set:function(e){this._configs.dollyMinSpeed=null!=e?e:.04}},{key:"panInertia",get:function(){return this._configs.panInertia},set:function(e){this._configs.panInertia=null!=e?e:.5}},{key:"keyboardLayout",get:function(){return this._configs.keyboardLayout},set:function(e){"qwerty"!==(e=e||"qwerty")&&"azerty"!==e&&(this.error("Unsupported value for keyboardLayout - defaulting to 'qwerty'"),e="qwerty"),this._configs.keyboardLayout=e,this.keyMap=this._configs.keyboardLayout}},{key:"enablePivotSphere",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._controllers.pivotController.enablePivotSphere(e)}},{key:"disablePivotSphere",value:function(){this._controllers.pivotController.disablePivotSphere()}},{key:"smartPivot",get:function(){return this._configs.smartPivot},set:function(e){this._configs.smartPivot=!1!==e}},{key:"doubleClickTimeFrame",get:function(){return this._configs.doubleClickTimeFrame},set:function(e){this._configs.doubleClickTimeFrame=null!=e?e:250}},{key:"zoomOnMouseWheel",get:function(){return this._configs.zoomOnMouseWheel},set:function(e){this._configs.zoomOnMouseWheel=!!e}},{key:"destroy",value:function(){this._destroyHandlers(),this._destroyControllers(),this._cameraUpdater.destroy(),v(C(n.prototype),"destroy",this).call(this)}},{key:"_destroyHandlers",value:function(){for(var e=0,t=this._handlers.length;e<t;e++){var n=this._handlers[e];n.destroy&&n.destroy()}}},{key:"_destroyControllers",value:function(){for(var e=0,t=this._controllers.length;e<t;e++){var n=this._controllers[e];n.destroy&&n.destroy()}}}]),n}(),$c=I((function e(t,n,r,i,s){x(this,e),this.name=t,this.type=r,this.value=n,this.valueType=i,this.description=s})),eu=I((function e(t){if(x(this,e),this.id=t.id,this.originalSystemId=t.originalSystemId,this.metaModels=[],this.name=t.name,this.type=t.type,this.properties=[],t.properties)for(var n=t.properties,r=0,i=n.length;r<i;r++){var s=n[r];Number.isInteger(s)?this.properties.push(s):this.properties.push(new $c(s.name,s.value,s.type,s.valueType,s.description))}})),tu=function(){function e(t){x(this,e),this.metaModels=[],this.id=t.id,this.parentId=t.parentId,this.parent=null,this.originalSystemId=t.originalSystemId,this.name=t.name,this.type=t.type,this.propertySetIds=t.propertySetIds,this.propertySets=[],this.attributes=t.attributes||{},void 0!==t.external&&null!==t.external&&(this.external=t.external)}return I(e,[{key:"metaModel",get:function(){return 1==this.metaModels.length?this.metaModels[0]:null}},{key:"getObjectIDsInSubtree",value:function(){var e=[];return function t(n){if(n){e.push(n.id);var r=n.children;if(r)for(var i=0,s=r.length;i<s;i++)t(r[i])}}(this),e}},{key:"withMetaObjectsInSubtree",value:function(e){!function t(n){if(n){e(n);var r=n.children;if(r)for(var i=0,s=r.length;i<s;i++)t(r[i])}}(this)}},{key:"getObjectIDsInSubtreeByType",value:function(e){for(var t={},n=0,r=e.length;n<r;n++)t[e[n]]=e[n];var i=[];return function e(n){if(n){t[n.type]&&i.push(n.id);var r=n.children;if(r)for(var s=0,o=r.length;s<o;s++)e(r[s])}}(this),i}},{key:"getJSON",value:function(){var e={id:this.id,type:this.type,name:this.name};return this.parent&&(e.parent=this.parent.id),e}}]),e}(),nu=function(){function e(t){x(this,e),this.id=t.id,this.projectId=t.projectId,this.revisionId=t.revisionId,this.author=t.author,this.createdAt=t.createdAt,this.creatingApplication=t.creatingApplication,this.schema=t.schema,this.metaScene=t.metaScene,this.propertySets=[],this.rootMetaObjects=[],this.metaObjects={},this.graph=t.graph||{},this.metaScene.metaModels[this.id]=this,this._propertyLookup=[],this.finalized=!1}return I(e,[{key:"rootMetaObject",get:function(){return 1===this.rootMetaObjects.length?this.rootMetaObjects[0]:null}},{key:"loadData",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.finalized)throw"MetaScene already finalized - can't add more data";this._globalizeIDs(e,t);var n=this.metaScene,r=e.properties;if(r)for(var i=0,s=r.length;i<s;i++)this._propertyLookup.push(r[i]);if(e.propertySets)for(var o=0,a=e.propertySets.length;o<a;o++){var A=e.propertySets[o];A.properties||(A.properties=[]);var c=n.propertySets[A.id];c||(c=new eu({id:A.id,originalSystemId:A.originalSystemId||A.id,type:A.type,name:A.name,properties:A.properties}),n.propertySets[c.id]=c),c.metaModels.push(this),this.propertySets.push(c)}if(e.metaObjects)for(var u=0,l=e.metaObjects.length;u<l;u++){var h=e.metaObjects[u],d=h.id,f=n.metaObjects[d];if(!f){var p=h.type,v=h.originalSystemId,g=h.propertySets||h.propertySetIds;f=new tu({id:d,originalSystemId:v,parentId:h.parent,type:p,name:h.name,attributes:h.attributes,propertySetIds:g,external:h.external}),this.metaScene.metaObjects[d]=f,f.metaModels=[]}this.metaObjects[d]=f,h.parent||(this.rootMetaObjects.push(f),n.rootMetaObjects[d]=f),f.metaModels.push(this)}}},{key:"_decompressProperties",value:function(e,t){for(var n=[],r=0,i=t.length;r<i;r++){var s=t[r];if(Number.isInteger(s)){var o=e[s];o?t[r]=o:n.push(s)}}n.length>0&&console.error("[MetaModel._decompressProperties] Properties not found: ".concat(n))}},{key:"finalize",value:function(){if(this.finalized)throw"MetaScene already finalized - can't re-finalize";var e=this.metaScene;for(var t in e.metaObjects){var n=e.metaObjects[t];if(n.children&&(n.children=[]),n.propertySets&&(n.propertySets=[]),n.propertySetIds)for(var r=0,i=n.propertySetIds.length;r<i;r++){var s=n.propertySetIds[r],o=e.propertySets[s];n.propertySets.push(o)}}for(var a in e.metaObjects){var A=e.metaObjects[a];if(A.parentId){var c=e.metaObjects[A.parentId];c&&(A.parent=c,(c.children||(c.children=[])).push(A))}}for(var u in e.metaObjects){e.metaObjects[u].metaModels=[]}for(var l in e.metaModels){var h=e.metaModels[l];for(var d in h.metaObjects){h.metaObjects[d].metaModels.push(h)}}for(var f in e.metaObjectsByType={},e.metaObjects){var p=e.metaObjects[f],v=p.type;(e.metaObjectsByType[v]||(e.metaObjectsByType[v]={}))[f]=p}if(this.propertySets)for(var g=0,m=this.propertySets.length;g<m;g++){var y=this.propertySets[g];this._decompressProperties(this._propertyLookup,y.properties)}this._propertyLookup=[],this.finalized=!0,this.metaScene.fire("metaModelCreated",this.id)}},{key:"getJSON",value:function(){for(var e={id:this.id,projectId:this.projectId,author:this.author,createdAt:this.createdAt,schema:this.schema,creatingApplication:this.creatingApplication,metaObjects:[],propertySets:[]},t=Object.values(this.metaObjects),n=0,r=t.length;n<r;n++){var i=t[n],s={id:i.id,originalSystemId:i.originalSystemId,extId:i.extId,type:i.type,name:i.name};i.parent&&(s.parent=i.parent.id),i.attributes&&(s.attributes=i.attributes),i.propertySetIds&&(s.propertySetIds=i.propertySetIds),e.metaObjects.push(s)}for(var o=0,a=this.propertySets.length;o<a;o++){for(var A=this.propertySets[o],c={id:A.id,originalSystemId:A.originalSystemId,extId:A.extId,type:A.type,name:A.name,propertyies:[]},u=0,l=A.properties.length;u<l;u++){var h=A.properties[u],d={id:h.id,description:h.description,type:h.type,name:h.name,value:h.value,valueType:h.valueType};c.properties.push(d)}e.propertySets.push(c)}return e}},{key:"_globalizeIDs",value:function(e,t){var n=!!t.globalizeObjectIds;if(e.metaObjects)for(var r=0,i=e.metaObjects.length;r<i;r++){var s=e.metaObjects[r];if(s.originalSystemId=s.id,s.parent&&(s.originalParentSystemId=s.parent),n&&(s.id=Ae.globalizeObjectId(this.id,s.id),s.parent&&(s.parent=Ae.globalizeObjectId(this.id,s.parent))),n){var o=s.propertySetIds;if(o){for(var a=[],A=0,c=o.length;A<c;A++)a.push(Ae.globalizeObjectId(this.id,o[A]));s.propertySetIds=a,s.originalSystemPropertySetIds=o}}else s.originalSystemPropertySetIds=s.propertySetIds}if(e.propertySets)for(var u=0,l=e.propertySets.length;u<l;u++){var h=e.propertySets[u];h.originalSystemId=h.id,n&&(h.id=Ae.globalizeObjectId(this.id,h.id))}}}]),e}(),ru=function(){function e(t,n){x(this,e),this.viewer=t,this.scene=n,this.metaModels={},this.propertySets={},this.metaObjects={},this.metaObjectsByType={},this.rootMetaObjects={},this._eventSubs={}}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:"off",value:function(e){}},{key:"createMetaModel",value:function(e,t){var n=new nu({metaScene:this,id:e,projectId:t.projectId||"none",revisionId:t.revisionId||"none",author:t.author||"none",createdAt:t.createdAt||"none",creatingApplication:t.creatingApplication||"none",schema:t.schema||"none",propertySets:[]});return n.loadData(t),n.finalize(),n}},{key:"destroyMetaModel",value:function(e){var t=this.metaModels[e];if(t){if(t.propertySets)for(var n=0,r=t.propertySets.length;n<r;n++){var i=t.propertySets[n];if(1===i.metaModels.length&&i.metaModels[0].id===e)delete this.propertySets[i.id];else{for(var s=[],o=0,a=i.metaModels.length;o<a;o++)i.metaModels[o].id!==e&&s.push(i.metaModels[o]);i.metaModels=s}}if(t.metaObjects)for(var A in t.metaObjects){var c=t.metaObjects[A];1===c.metaModels.length&&c.metaModels[0].id===e?(delete this.metaObjects[A],c.parent||delete this.rootMetaObjects[A]):c.metaModels=c.metaModels.filter((function(t){return t.id!==e}))}for(var u in this.metaObjects){var l=this.metaObjects[u];if(l.children&&(l.children=[]),l.propertySets&&(l.propertySets=[]),l.propertySetIds)for(var h=0,d=l.propertySetIds.length;h<d;h++){var f=l.propertySetIds[h],p=this.propertySets[f];l.propertySets.push(p)}}for(var v in this.metaObjectsByType={},this.metaObjects){var g=this.metaObjects[v],m=g.type;g.children&&(g.children=null),(this.metaObjectsByType[m]||(this.metaObjectsByType[m]={}))[v]=g}for(var y in this.metaObjects){var _=this.metaObjects[y];if(_.parentId){var b=this.metaObjects[_.parentId];b&&(_.parent=b,(b.children||(b.children=[])).push(_))}}for(var w in delete this.metaModels[e],this.metaObjects){this.metaObjects[w].metaModels=[]}for(var B in this.metaModels){var C=this.metaModels[B];for(var k in C.metaObjects){C.metaObjects[k].metaModels.push(C)}}this.fire("metaModelDestroyed",e)}}},{key:"getObjectIDsByType",value:function(e){var t=this.metaObjectsByType[e];return t?Object.keys(t):[]}},{key:"getObjectIDsInSubtree",value:function(e,t,n){var r=[],i=this.metaObjects[e],s=t&&t.length>0?iu(t):null,o=n&&n.length>0?iu(n):null;return function e(t){if(t){var n=!0;(o&&o[t.type]||s&&!s[t.type])&&(n=!1),n&&r.push(t.id);var i=t.children;if(i)for(var a=0,A=i.length;a<A;a++)e(i[a])}}(i),r}},{key:"withMetaObjectsInSubtree",value:function(e,t){var n=this.metaObjects[e];n&&n.withMetaObjectsInSubtree(t)}}]),e}();function iu(e){for(var t={},n=0,r=e.length;n<r;n++)t[e[n]]=!0;return t}
|
|
23
|
+
**/var Io=null;function To(e,t){var n,r,i,s,o,a,A=3*e,c=3*t,u=Math.min(n=Io[A],r=Io[A+1],i=Io[A+2]),l=Math.min(s=Io[c],o=Io[c+1],a=Io[c+2]);if(u!==l)return u-l;var h=Math.max(n,r,i),d=Math.max(s,o,a);return h!==d?h-d:0}function Po(e,t){for(var n=new Int32Array(e.length/3),r=0,i=n.length;r<i;r++)n[r]=r;Io=new Int32Array(e.length);for(var s=0,o=e.length;s<o;s++)Io[s]=e[s]>>t;n.sort(To);for(var a=new Int32Array(e.length),A=0,c=n.length;A<c;A++)a[3*A+0]=e[3*n[A]+0],a[3*A+1]=e[3*n[A]+1],a[3*A+2]=e[3*n[A]+2];return a}var So=null;function Do(e,t){var n=So[2*e]-So[2*t];return 0!==n?n:So[2*e+1]-So[2*t+1]}function Qo(e){if(0===(e||[]).length)return[];for(var t=new Int32Array(e.length/2),n=0,r=t.length;n<r;n++)t[n]=n;for(var i=0,s=e.length;i<s;i+=2)if(e[i]>e[i+1]){var o=e[i];e[i]=e[i+1],e[i+1]=o}So=new Int32Array(e),t.sort(Do);for(var a=new Int32Array(e.length),A=0,c=t.length;A<c;A++)a[2*A+0]=e[2*t[A]+0],a[2*A+1]=e[2*t[A]+1];return a}function Ro(e,t){var n={},r={};e.forEach((function(e){for(var t=e.indices,i=e.edgeIndices,s=e.positionsCompressed,o=0,a=t.length;o<a;o+=3){var A=s[3*t[o]]+"_"+s[3*t[o]+1]+"_"+s[3*t[o]+2]+"/"+s[3*t[o+1]]+"_"+s[3*t[o+1]+1]+"_"+s[3*t[o+1]+2]+"/"+s[3*t[o+2]]+"_"+s[3*t[o+2]+1]+"_"+s[3*t[o+2]+2];n[A]=!0}e.edgeIndices.length/2;for(var c=0,u=i.length;c<u;c+=2){var l=s[3*i[c]]+"_"+s[3*i[c]+1]+"_"+s[3*i[c]+2]+"/"+s[3*i[c+1]]+"_"+s[3*i[c+1]+1]+"_"+s[3*i[c+1]+2]+"/";r[l]=!0}}));var i=t.indices;t.edgeIndices;for(var s=t.positionsCompressed,o=0,a=i.length;o<a;o+=3){var A=s[3*i[o]]+"_"+s[3*i[o]+1]+"_"+s[3*i[o]+2]+"/"+s[3*i[o+1]]+"_"+s[3*i[o+1]+1]+"_"+s[3*i[o+1]+2]+"/"+s[3*i[o+2]]+"_"+s[3*i[o+2]+1]+"_"+s[3*i[o+2]+2];if(!(A in n))throw console.log("Not found "+A),"Ohhhh!"}}var Oo=new Float32Array([0,0,0]),Vo=new Uint16Array([0,0,0]);Ae.OBB3();var Lo=function(){function e(t,n,r,i,s,o){x(this,e),this._isObject=n,this.scene=t.scene,this.model=t,this.isSceneModelEntity=!0,this.meshes=i,this._numPrimitives=0,this._capMaterial=null;for(var a=0,A=this.meshes.length;a<A;a++){var c=this.meshes[a];c.parent=this,c.entity=this,this._numPrimitives+=c.numPrimitives}this.id=r,this.originalSystemId=Ae.unglobalizeObjectId(t.id,r),this._flags=s,this._aabb=Ae.AABB3(),this._aabbDirty=!0,this._offset=Ae.vec3(),this._colorizeUpdated=!1,this._opacityUpdated=!1,this._lodCullable=!!o,this._culled=!1,this._culledVFC=!1,this._culledLOD=!1,this._isObject&&t.scene._registerObject(this)}return I(e,[{key:"_transformDirty",value:function(){this._aabbDirty=!0,this.model._transformDirty()}},{key:"_sceneModelDirty",value:function(){this._aabbDirty=!0;for(var e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._sceneModelDirty()}},{key:"aabb",get:function(){if(this._aabbDirty){Ae.collapseAABB3(this._aabb);for(var e=0,t=this.meshes.length;e<t;e++)Ae.expandAABB3(this._aabb,this.meshes[e].aabb);this._aabbDirty=!1}return this._aabb}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return!1}},{key:"isObject",get:function(){return this._isObject}},{key:"numPrimitives",get:function(){return this._numPrimitives}},{key:"numTriangles",get:function(){return this._numPrimitives}},{key:"visible",get:function(){return this._getFlag(Gi)},set:function(e){if(!!(this._flags&Gi)!==e){this._flags=e?this._flags|Gi:this._flags&~Gi;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setVisible(this._flags);this._isObject&&this.model.scene._objectVisibilityUpdated(this),this.model.glRedraw()}}},{key:"highlighted",get:function(){return this._getFlag(Zi)},set:function(e){if(!!(this._flags&Zi)!==e){this._flags=e?this._flags|Zi:this._flags&~Zi;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setHighlighted(this._flags);this._isObject&&this.model.scene._objectHighlightedUpdated(this),this.model.glRedraw()}}},{key:"xrayed",get:function(){return this._getFlag(Ki)},set:function(e){if(!!(this._flags&Ki)!==e){this._flags=e?this._flags|Ki:this._flags&~Ki;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setXRayed(this._flags);this._isObject&&this.model.scene._objectXRayedUpdated(this),this.model.glRedraw()}}},{key:"selected",get:function(){return this._getFlag(Ji)},set:function(e){if(!!(this._flags&Ji)!==e){this._flags=e?this._flags|Ji:this._flags&~Ji;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setSelected(this._flags);this._isObject&&this.model.scene._objectSelectedUpdated(this),this.model.glRedraw()}}},{key:"edges",get:function(){return this._getFlag(Yi)},set:function(e){if(!!(this._flags&Yi)!==e){this._flags=e?this._flags|Yi:this._flags&~Yi;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setEdges(this._flags);this.model.glRedraw()}}},{key:"culledVFC",get:function(){return!!this._culledVFC},set:function(e){this._culledVFC=e,this._setCulled()}},{key:"culledLOD",get:function(){return!!this._culledLOD},set:function(e){this._culledLOD=e,this._setCulled()}},{key:"culled",get:function(){return!!this._culled},set:function(e){this._culled=e,this._setCulled()}},{key:"_setCulled",value:function(){var e=!!this._culled||!(!this._culledLOD||!this._lodCullable)||!!this._culledVFC;if(!!(this._flags&ji)!==e){this._flags=e?this._flags|ji:this._flags&~ji;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setCulled(this._flags);this.model.glRedraw()}}},{key:"clippable",get:function(){return this._getFlag(zi)},set:function(e){if(!!(this._flags&zi)!==e){this._flags=e?this._flags|zi:this._flags&~zi;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setClippable(this._flags);this.model.glRedraw()}}},{key:"collidable",get:function(){return this._getFlag(Xi)},set:function(e){if(!!(this._flags&Xi)!==e){this._flags=e?this._flags|Xi:this._flags&~Xi;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setCollidable(this._flags)}}},{key:"pickable",get:function(){return this._getFlag(Wi)},set:function(e){if(!!(this._flags&Wi)!==e){this._flags=e?this._flags|Wi:this._flags&~Wi;for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setPickable(this._flags)}}},{key:"colorize",get:function(){if(0===this.meshes.length)return null;var e=this.meshes[0]._colorize;return Oo[0]=e[0]/255,Oo[1]=e[1]/255,Oo[2]=e[2]/255,Oo},set:function(e){if(e){Vo[0]=Math.floor(255*e[0]),Vo[1]=Math.floor(255*e[1]),Vo[2]=Math.floor(255*e[2]);for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._setColorize(Vo)}else for(var r=0,i=this.meshes.length;r<i;r++)this.meshes[r]._setColorize(null);if(this._isObject){var s=!!e;this.scene._objectColorizeUpdated(this,s),this._colorizeUpdated=s}this.model.glRedraw()}},{key:"opacity",get:function(){return this.meshes.length>0?this.meshes[0]._colorize[3]/255:1},set:function(e){if(0!==this.meshes.length){var t=null!=e,n=this.meshes[0]._colorize[3],r=255;if(t){if(e<0?e=0:e>1&&(e=1),n===(r=Math.floor(255*e)))return}else if(n===(r=255))return;for(var i=0,s=this.meshes.length;i<s;i++)this.meshes[i]._setOpacity(r,this._flags);this._isObject&&(this.scene._objectOpacityUpdated(this,t),this._opacityUpdated=t),this.model.glRedraw()}}},{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.meshes.length;t<n;t++)this.meshes[t]._setOffset(this._offset);this._aabbDirty=!0,this.model._aabbDirty=!0,this.scene._aabbDirty=!0,this.scene._objectOffsetUpdated(this,e),this.model.glRedraw()}},{key:"saoEnabled",get:function(){return this.model.saoEnabled}},{key:"capMaterial",get:function(){return this._capMaterial},set:function(e){this.scene.readableGeometryEnabled&&(this._capMaterial=e instanceof zr?e:null,this.scene._capMaterialUpdated(this.id,this.model.id))}},{key:"getEachVertex",value:function(e){for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t].getEachVertex(e)}},{key:"getEachIndex",value:function(e){for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t].getEachIndex(e)}},{key:"getGeometryData",value:function(){for(var e=0,t=[],n=[],r=0,i=this.meshes.length;r<i;r++){var s=this.meshes[r];if(s.layer.readGeometryData){for(var o=s.layer.readGeometryData(s.portionId),a=0,A=o.indices.length;a<A;a++)n.push(o.indices[a]+e);for(var c=0,u=o.positions.length;c<u;c++)t.push(o.positions[c]);e+=o.positions.length/3}}return{indices:n,positions:t}}},{key:"volume",get:function(){for(var e=0,t=0,n=this.meshes.length;t<n;t++){var r=this.meshes[t].volume;if(r<0)return-1;e+=r}return e}},{key:"surfaceArea",get:function(){for(var e=0,t=0,n=this.meshes.length;t<n;t++){var r=this.meshes[t].surfaceArea;r>=0&&(e+=r)}return e>0?e:-1}},{key:"_getFlag",value:function(e){return!!(this._flags&e)}},{key:"_finalize",value:function(){var e=this.model.scene;this._isObject&&(this.visible&&e._objectVisibilityUpdated(this),this.highlighted&&e._objectHighlightedUpdated(this),this.xrayed&&e._objectXRayedUpdated(this),this.selected&&e._objectSelectedUpdated(this));for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._finalize(this._flags)}},{key:"_finalize2",value:function(){for(var e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._finalize2()}},{key:"_destroy",value:function(){var e=this.model.scene;this._isObject&&(e._deregisterObject(this),this.visible&&e._deRegisterVisibleObject(this),this.xrayed&&e._deRegisterXRayedObject(this),this.selected&&e._deRegisterSelectedObject(this),this.highlighted&&e._deRegisterHighlightedObject(this),this._colorizeUpdated&&this.scene._deRegisterColorizedObject(this),this._opacityUpdated&&this.scene._deRegisterOpacityObject(this),!this._offset||0===this._offset[0]&&0===this._offset[1]&&0===this._offset[2]||this.scene._deRegisterOffsetObject(this));for(var t=0,n=this.meshes.length;t<n;t++)this.meshes[t]._destroy();e._aabbDirty=!0}}]),e}(),Ho=Ae.vec4(4),No=Ae.vec4(),Go=Ae.vec4(),jo=Ae.vec3([1,0,0]),Wo=Ae.vec3([0,1,0]),zo=Ae.vec3([0,0,1]);Ae.vec3(3),Ae.vec3(3);var Xo=Ae.identityMat4(),Ko=function(){function e(t){x(this,e),this._model=t.model,this.id=t.id,this._parentTransform=t.parent,this._childTransforms=[],this._meshes=[],this._scale=new Float32Array([1,1,1]),this._quaternion=Ae.identityQuaternion(new Float32Array(4)),this._rotation=new Float32Array(3),this._position=new Float32Array(3),this._localMatrix=Ae.identityMat4(new Float32Array(16)),this._worldMatrix=Ae.identityMat4(new Float32Array(16)),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,t.matrix?this.matrix=t.matrix:(this.scale=t.scale,this.position=t.position,t.quaternion||(this.rotation=t.rotation)),t.parent&&t.parent._addChildTransform(this)}return I(e,[{key:"_addChildTransform",value:function(e){this._childTransforms.push(e),e._parentTransform=this,e._transformDirty(),e._setSubtreeAABBsDirty(this)}},{key:"_addMesh",value:function(e){this._meshes.push(e),e.transform=this}},{key:"parentTransform",get:function(){return this._parentTransform}},{key:"meshes",get:function(){return this._meshes}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._model.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._model.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._model.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._model.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||Xo),Ae.decomposeMat4(this._localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._transformDirty(),this._model.glRedraw()}},{key:"worldMatrix",get:function(){return this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldMatrix}},{key:"rotate",value:function(e,t){return Ho[0]=e[0],Ho[1]=e[1],Ho[2]=e[2],Ho[3]=t*Ae.DEGTORAD,Ae.angleAxisToQuaternion(Ho,No),Ae.mulQuaternions(this.quaternion,No,Go),this.quaternion=Go,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"rotateOnWorldAxis",value:function(e,t){return Ho[0]=e[0],Ho[1]=e[1],Ho[2]=e[2],Ho[3]=t*Ae.DEGTORAD,Ae.angleAxisToQuaternion(Ho,No),Ae.mulQuaternions(No,this.quaternion,No),this}},{key:"rotateX",value:function(e){return this.rotate(jo,e)}},{key:"rotateY",value:function(e){return this.rotate(Wo,e)}},{key:"rotateZ",value:function(e){return this.rotate(zo,e)}},{key:"translate",value:function(e){return this._position[0]+=e[0],this._position[1]+=e[1],this._position[2]+=e[2],this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateX",value:function(e){return this._position[0]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateY",value:function(e){return this._position[1]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"translateZ",value:function(e){return this._position[2]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}},{key:"_setLocalMatrixDirty",value:function(){this._localMatrixDirty=!0,this._transformDirty()}},{key:"_transformDirty",value:function(){this._worldMatrixDirty=!0;for(var e=0,t=this._childTransforms.length;e<t;e++){var n=this._childTransforms[e];if(n._transformDirty(),n._meshes&&n._meshes.length>0)for(var r=n._meshes,i=0,s=r.length;i<s;i++)r[i]._transformDirty()}if(this._meshes&&this._meshes.length>0)for(var o=this._meshes,a=0,A=o.length;a<A;a++)o[a]._transformDirty()}},{key:"_buildWorldMatrix",value:function(){var e=this.matrix;if(this._parentTransform)Ae.mulMat4(this._parentTransform.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._childTransforms)for(var t=0,n=e._childTransforms.length;t<n;t++)this._setSubtreeAABBsDirty(e._childTransforms[t])}}]),e}(),Zo=Ae.vec3(),Jo=Ae.OBB3(),Yo=Ae.vec4(),qo=Ae.vec3([1,1,1]),$o=Ae.vec3([0,0,0]);Ae.vec3([0,0,0]);var ea=Ae.identityQuaternion(),ta=Ae.identityMat4(),na=new Uint8Array([255,255,255]),ra=function(e){m(n,Ie);var t=_(n);function n(e){var r,i,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,n),(i=t.call(this,e,s)).renderOrder=s.renderOrder||0,i._dtxEnabled=i.scene.dtxEnabled&&!1!==s.dtxEnabled,i._enableVertexWelding=!1,i._enableIndexBucketing=!1,i._textureTranscoder=s.textureTranscoder||Mo(i.scene.viewer),i._maxGeometryBatchSize=null!==(r=s.maxGeometryBatchSize)&&void 0!==r?r:5e6,i._aabb=Ae.collapseAABB3(),i._aabbDirty=!0,i._quantizationRanges={},i._vboLayers={},i._dtxLayers={},i._meshList=[],i.layerList=[],i._layersToFinalize=[],i._entityList=[],i._entitiesToFinalize=[],i._geometries={},i._dtxBuckets={},i._textures={},i._textureSets={},i._transforms={},i._meshes={},i._unusedMeshes={},i._entities={},i.renderFlags=new Ur,i.numGeometries=0,i.numPortions=0,i.numVisibleLayerPortions=0,i.numTransparentLayerPortions=0,i.numXRayedLayerPortions=0,i.numHighlightedLayerPortions=0,i.numSelectedLayerPortions=0,i.numEdgesLayerPortions=0,i.numPickableLayerPortions=0,i.numClippableLayerPortions=0,i.numCulledLayerPortions=0,i.numEntities=0,i._numTriangles=0,i._numLines=0,i._numPoints=0,i._layersFinalized=!1,i._edgeThreshold=s.edgeThreshold||10,i._origin=Ae.vec3(s.origin||[0,0,0]),i._position=Ae.vec3(s.position||[0,0,0]),i._rotation=Ae.vec3(s.rotation||[0,0,0]),i._quaternion=Ae.vec4(s.quaternion||[0,0,0,1]),i._conjugateQuaternion=Ae.vec4(s.quaternion||[0,0,0,1]),s.rotation&&Ae.eulerToQuaternion(i._rotation,"XYZ",i._quaternion),i._scale=Ae.vec3(s.scale||[1,1,1]),i._worldRotationMatrix=Ae.mat4(),i._worldRotationMatrixConjugate=Ae.mat4(),i._matrix=Ae.mat4(),i._matrixDirty=!0,i._rebuildMatrices(),i._worldNormalMatrix=Ae.mat4(),Ae.inverseMat4(i._matrix,i._worldNormalMatrix),Ae.transposeMat4(i._worldNormalMatrix),(s.matrix||s.position||s.rotation||s.scale||s.quaternion)&&(i._viewMatrix=Ae.mat4(),i._viewNormalMatrix=Ae.mat4(),i._viewMatrixDirty=!0,i._matrixNonIdentity=!0),i._opacity=1,i._colorize=[1,1,1],i._saoEnabled=!1!==s.saoEnabled,i._pbrEnabled=!1!==s.pbrEnabled,i._colorTextureEnabled=!1!==s.colorTextureEnabled,i._isModel=s.isModel,i._isModel&&i.scene._registerModel(w(i)),i._onCameraViewMatrix=i.scene.camera.on("matrix",(function(){i._viewMatrixDirty=!0})),i._meshesWithDirtyMatrices=[],i._numMeshesWithDirtyMatrices=0,i._onTick=i.scene.on("tick",(function(){for(;i._numMeshesWithDirtyMatrices>0;)i._meshesWithDirtyMatrices[--i._numMeshesWithDirtyMatrices]._updateMatrix()}));var o=function(e,t){return i._textures[e]=new po({id:e,texture:new $r({gl:i.scene.canvas.gl,preloadColor:t})})};return i._textureSets.defaultTextureSet=new fo({id:"defaultTextureSet",colorTexture:o("defaultColorTexture",[1,1,1,1]),metallicRoughnessTexture:o("defaultMetalRoughTexture",[0,1,1,1]),normalsTexture:o("defaultNormalsTexture",[0,0,0,0]),emissiveTexture:o("defaultEmissiveTexture",[0,0,0,1]),occlusionTexture:o("defaultOcclusionTexture",[1,1,1,1])}),i.visible=s.visible,i.culled=s.culled,i.pickable=s.pickable,i.clippable=s.clippable,i.collidable=s.collidable,i.castsShadow=s.castsShadow,i.receivesShadow=s.receivesShadow,i.xrayed=s.xrayed,i.highlighted=s.highlighted,i.selected=s.selected,i.edges=s.edges,i.colorize=s.colorize,i.opacity=s.opacity,i.backfaces=s.backfaces,i}return I(n,[{key:"_meshMatrixDirty",value:function(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}},{key:"isPerformanceModel",get:function(){return!0}},{key:"transforms",get:function(){return this._transforms}},{key:"textures",get:function(){return this._textures}},{key:"textureSets",get:function(){return this._textureSets}},{key:"meshes",get:function(){return this._meshes}},{key:"objects",get:function(){return this._entities}},{key:"origin",get:function(){return this._origin}},{key:"position",get:function(){return this._position},set:function(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),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._setWorldMatrixDirty(),this._sceneModelDirty(),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._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"scale",get:function(){return this._scale},set:function(e){}},{key:"matrix",get:function(){return this._rebuildMatrices(),this._matrix},set:function(e){this._matrix.set(e||ta),Ae.decomposeMat4(this._matrix,this._position,this._quaternion,this._scale),Ae.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}},{key:"rotationMatrix",get:function(){return this._rebuildMatrices(),this._worldRotationMatrix}},{key:"_rebuildMatrices",value:function(){this._matrixDirty&&(Ae.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),Ae.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),Ae.quaternionToRotationMat4(this._conjugateQuaternion,this._worldRotationMatrixConjugate),Ae.scaleMat4v(this._scale,this._worldRotationMatrix),Ae.scaleMat4v(this._scale,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),Ae.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._viewMatrixDirty=!0)}},{key:"rotationMatrixConjugate",get:function(){return this._rebuildMatrices(),this._worldRotationMatrixConjugate}},{key:"_setWorldMatrixDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0}},{key:"_transformDirty",value:function(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}},{key:"_sceneModelDirty",value:function(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(var e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._sceneModelDirty()}},{key:"worldMatrix",get:function(){return this.matrix}},{key:"worldNormalMatrix",get:function(){return this._worldNormalMatrix}},{key:"_rebuildViewMatrices",value:function(){this._rebuildMatrices(),this._viewMatrixDirty&&(Ae.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),Ae.inverseMat4(this._viewMatrix,this._viewNormalMatrix),Ae.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1)}},{key:"viewMatrix",get:function(){return this._viewMatrix?(this._rebuildViewMatrices(),this._viewMatrix):this.scene.camera.viewMatrix}},{key:"viewNormalMatrix",get:function(){return this._viewNormalMatrix?(this._rebuildViewMatrices(),this._viewNormalMatrix):this.scene.camera.viewNormalMatrix}},{key:"backfaces",get:function(){return this._backfaces},set:function(e){e=!!e,this._backfaces=e,this.glRedraw()}},{key:"entityList",get:function(){return this._entityList}},{key:"isEntity",get:function(){return!0}},{key:"isModel",get:function(){return this._isModel}},{key:"isObject",get:function(){return!1}},{key:"aabb",get:function(){if(this._aabbDirty){Ae.collapseAABB3(this._aabb);for(var e=0,t=this._entityList.length;e<t;e++)Ae.expandAABB3(this._aabb,this._entityList[e].aabb);this._aabbDirty=!1}return this._aabb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"numLines",get:function(){return this._numLines}},{key:"numPoints",get:function(){return this._numPoints}},{key:"visible",get:function(){return this.numVisibleLayerPortions>0},set:function(e){e=!1!==e,this._visible=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].visible=e;this.glRedraw()}},{key:"xrayed",get:function(){return this.numXRayedLayerPortions>0},set:function(e){e=!!e,this._xrayed=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].xrayed=e;this.glRedraw()}},{key:"highlighted",get:function(){return this.numHighlightedLayerPortions>0},set:function(e){e=!!e,this._highlighted=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].highlighted=e;this.glRedraw()}},{key:"selected",get:function(){return this.numSelectedLayerPortions>0},set:function(e){e=!!e,this._selected=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].selected=e;this.glRedraw()}},{key:"edges",get:function(){return this.numEdgesLayerPortions>0},set:function(e){e=!!e,this._edges=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].edges=e;this.glRedraw()}},{key:"culled",get:function(){return this._culled},set:function(e){e=!!e,this._culled=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].culled=e;this.glRedraw()}},{key:"clippable",get:function(){return this._clippable},set:function(e){e=!1!==e,this._clippable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].clippable=e;this.glRedraw()}},{key:"collidable",get:function(){return this._collidable},set:function(e){e=!1!==e,this._collidable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].collidable=e}},{key:"pickable",get:function(){return this.numPickableLayerPortions>0},set:function(e){e=!1!==e,this._pickable=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].pickable=e}},{key:"colorize",get:function(){return this._colorize},set:function(e){this._colorize=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].colorize=e}},{key:"opacity",get:function(){return this._opacity},set:function(e){this._opacity=e;for(var t=0,n=this._entityList.length;t<n;t++)this._entityList[t].opacity=e}},{key:"castsShadow",get:function(){return this._castsShadow},set:function(e){(e=!1!==e)!==this._castsShadow&&(this._castsShadow=e,this.glRedraw())}},{key:"receivesShadow",get:function(){return this._receivesShadow},set:function(e){(e=!1!==e)!==this._receivesShadow&&(this._receivesShadow=e,this.glRedraw())}},{key:"saoEnabled",get:function(){return this._saoEnabled}},{key:"pbrEnabled",get:function(){return this._pbrEnabled}},{key:"colorTextureEnabled",get:function(){return this._colorTextureEnabled}},{key:"isDrawable",get:function(){return!0}},{key:"isStateSortable",get:function(){return!1}},{key:"xrayMaterial",get:function(){return this.scene.xrayMaterial}},{key:"highlightMaterial",get:function(){return this.scene.highlightMaterial}},{key:"selectedMaterial",get:function(){return this.scene.selectedMaterial}},{key:"edgeMaterial",get:function(){return this.scene.edgeMaterial}},{key:"getPickViewMatrix",value:function(e){return this._viewMatrix?this._viewMatrix:e}},{key:"createQuantizationRange",value:function(e){void 0!==e.id&&null!==e.id?e.aabb?this.error("[createQuantizationRange] Config missing: aabb"):this._quantizationRanges[e.id]?this.error("[createQuantizationRange] QuantizationRange already created: "+e.id):this._quantizationRanges[e.id]={id:e.id,aabb:e.aabb,matrix:Hs(e.aabb,Ae.mat4())}:this.error("[createQuantizationRange] Config missing: id")}},{key:"_createDefaultIndices",value:function(e){for(var t=[],n=0;n<e;n++)t.push(n);return t}},{key:"createGeometry",value:function(e){if(void 0!==e.id&&null!==e.id)if(this._geometries[e.id])this.error("[createGeometry] Geometry already created: "+e.id);else if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"===e.primitive||"lines"===e.primitive||"triangles"===e.primitive||"solid"===e.primitive||"surface"===e.primitive){if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("[createGeometry] Param expected: `positions`, `positionsCompressed' or 'buckets"),null;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("[createGeometry] Param expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.positionsDecodeMatrix&&e.positionsDecodeBoundary)return this.error("[createGeometry] Only one of these params expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("[createGeometry] Param expected: `uvDecodeMatrix` (required for `uvCompressed')"),null;if(e.buckets||e.indices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.indices=this._createDefaultIndices((e.positions||e.positionsCompressed).length/3)),!e.buckets&&!e.indices&&"points"!==e.primitive)return this.error("[createGeometry] Param expected: indices (required for '".concat(e.primitive,"' primitive type)")),null;if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Hs(e.positionsDecodeBoundary,Ae.mat4())),e.positions){var t=Ae.collapseAABB3();e.positionsDecodeMatrix=Ae.mat4(),Ae.expandAABB3Points3(t,e.positions),e.positionsCompressed=Ls(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){var n=Ae.collapseAABB3();e.positionsDecodeMatrix=new Float64Array(e.positionsDecodeMatrix),e.positionsCompressed=new Uint16Array(e.positionsCompressed),Ae.expandAABB3Points3(n,e.positionsCompressed),pt.decompressAABB(n,e.positionsDecodeMatrix),e.aabb=n}else if(e.buckets){var r=Ae.collapseAABB3();this._dtxBuckets[e.id]=e.buckets;for(var i=0,s=e.buckets.length;i<s;i++){var o=e.buckets[i];o.positions?Ae.expandAABB3Points3(r,o.positions):o.positionsCompressed&&Ae.expandAABB3Points3(r,o.positionsCompressed)}e.positionsDecodeMatrix&&pt.decompressAABB(r,e.positionsDecodeMatrix),e.aabb=r}if(e.colorsCompressed&&e.colorsCompressed.length>0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){for(var a=e.colors,A=new Uint8Array(a.length),c=0,u=a.length;c<u;c++)A[c]=255*a[c];e.colorsCompressed=A}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=ot(e.positions,e.indices,null,5):e.edgeIndices=ot(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.uv){var l=pt.getUVBounds(e.uv),h=pt.compressUVs(e.uv,l.min,l.max);e.uvCompressed=h.quantized,e.uvDecodeMatrix=h.decodeMatrix}else e.uvCompressed&&(e.uvCompressed=new Uint16Array(e.uvCompressed),e.uvDecodeMatrix=new Float64Array(e.uvDecodeMatrix));e.normals&&(e.normals=null),this._geometries[e.id]=e,this._numTriangles+=e.indices?Math.round(e.indices.length/3):0,this.numGeometries++}else this.error("[createGeometry] Unsupported value for 'primitive': '".concat(e.primitive,"' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'."));else this.error("[createGeometry] Config missing: id")}},{key:"createTexture",value:function(e){var t=this,n=e.id;if(null!=n)if(this._textures[n])this.error("[createTexture] Texture already created: "+n);else{if(!e.src&&!e.image&&!e.buffers)return this.error("[createTexture] Param expected: `src`, `image' or 'buffers'"),null;var r=e.minFilter||1008;1006!==r&&1007!==r&&1008!==r&&1005!==r&&1004!==r&&(this.error("[createTexture] Unsupported value for 'minFilter' - \n supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, \n NearestMipMapLinearFilter and LinearMipmapLinearFilter. Defaulting to LinearMipmapLinearFilter."),r=1008);var i=e.magFilter||1006;1006!==i&&1003!==i&&(this.error("[createTexture] Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),i=1006);var s=e.wrapS||1e3;1001!==s&&1002!==s&&1e3!==s&&(this.error("[createTexture] Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),s=1e3);var o=e.wrapT||1e3;1001!==o&&1002!==o&&1e3!==o&&(this.error("[createTexture] Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),o=1e3);var a=e.wrapR||1e3;1001!==a&&1002!==a&&1e3!==a&&(this.error("[createTexture] Unsupported value for 'wrapR' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),a=1e3);var A=e.encoding||3e3;3e3!==A&&3001!==A&&(this.error("[createTexture] Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),A=3e3);var c=new $r({gl:this.scene.canvas.gl,minFilter:r,magFilter:i,wrapS:s,wrapT:o,wrapR:a,encoding:A});if(e.preloadColor&&c.setPreloadColor(e.preloadColor),e.image){var u=e.image;if(u.crossOrigin="Anonymous",u.compressed){var l=u.data;c.setCompressedData({mipmaps:l,props:{format:l[0].format,minFilter:r,magFilter:i}})}else c.setImage(u,{minFilter:r,magFilter:i,wrapS:s,wrapT:o,wrapR:a,flipY:e.flipY,encoding:A})}else if(e.src){var h=e.src.split(".").pop();switch(h){case"jpeg":case"jpg":case"png":case"gif":var d=new Image;d.onload=function(){c.setImage(d,{minFilter:r,magFilter:i,wrapS:s,wrapT:o,wrapR:a,flipY:e.flipY,encoding:A}),t.glRedraw()},d.src=e.src;break;default:this._textureTranscoder?ge.loadArraybuffer(e.src,(function(e){e.byteLength?t._textureTranscoder.transcode([e],c).then((function(){t.glRedraw()})):t.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error("[createTexture] Can't create texture from 'src': ".concat(e))})):this.error("[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('".concat(h,"')"))}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,c).then((function(){t.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[n]=new po({id:n,texture:c})}else this.error("[createTexture] Config missing: id")}},{key:"createTextureSet",value:function(e){var t=this,n=e.id;if(null==n)return this.error("[createTextureSet] Config missing: id"),!1;if(this._textureSets[n])return this.error("[createTextureSet] Texture set already created: ".concat(n)),!1;var r=function(e,n){var r=null!=e?e:n;if(r in t._textures)return t._textures[r];throw e};try{var i=new fo({id:n,model:this,alphaCutoff:e.alphaCutoff,colorTexture:r(e.colorTextureId,"defaultColorTexture"),metallicRoughnessTexture:r(e.metallicRoughnessTextureId,"defaultMetalRoughTexture"),normalsTexture:r(e.normalsTextureId,"defaultNormalsTexture"),emissiveTexture:r(e.emissiveTextureId,"defaultEmissiveTexture"),occlusionTexture:r(e.occlusionTextureId,"defaultOcclusionTexture")});return this._textureSets[n]=i,i}catch(e){return this.error("[createTextureSet] Texture not found: ".concat(e," - ensure that you create it first with createTexture()")),!1}}},{key:"createTransform",value:function(e){if(void 0!==e.id&&null!==e.id)if(this._transforms[e.id])this.error("[createTransform] SceneModel already has a transform with this ID: ".concat(e.id));else{var t;if(!e.parentTransformId||(t=this._transforms[e.parentTransformId])){var n=new Ko({id:e.id,model:this,parent:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[n.id]=n,n}this.error("[createTransform] SceneModel.createTransform() config missing: id")}else this.error("[createTransform] SceneModel.createTransform() config missing: id")}},{key:"createMesh",value:function(e){var t;if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._meshes[e.id])return this.error("[createMesh] SceneModel already has a mesh with this ID: ".concat(e.id)),!1;var n=e.geometryId,r=void 0!==n;if(r){if(e.positions||e.positionsCompressed||e.indices||e.edgeIndices||e.normals||e.normalsCompressed||e.uv||e.uvCompressed||e.positionsDecodeMatrix)return this.error("Mesh geometry parameters not expected when instancing a geometry (not expected: positions, positionsCompressed, indices, edgeIndices, normals, normalsCompressed, uv, uvCompressed, positionsDecodeMatrix)"),!1;if(e.geometry=this._geometries[n],!e.geometry)return this.error("[createMesh] Geometry not found: ".concat(n," - ensure that you create it first with createGeometry()")),!1}else{var i;null!==(i=e.primitive)&&void 0!==i||(e.primitive="triangles")}var s,o,a=r?e.geometry.primitive:e.primitive,A="triangles"===a||"solid"===a||"surface"===a,c=e.textureSetId,u=this._dtxEnabled&&A&&!c;if(e.origin=e.origin?Ae.addVec3(this._origin,e.origin,Ae.vec3()):this._origin,r){e.positionsDecodeMatrix=e.geometry.positionsDecodeMatrix,e.aabb=Ae.AABB3(e.geometry.aabb);var l=e.transformId;if(l){if(e.transform=this._transforms[l],!e.transform)return this.error("[createMesh] Transform not found: ".concat(l," - ensure that you create it first with createTransform()")),!1}else if(e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position||e.quaternion){var h=e.scale||qo,d=e.position||$o,f=e.rotation?Ae.eulerToQuaternion(e.rotation,"XYZ",Yo):e.quaternion||ea;e.meshMatrix=Ae.composeMat4(d,f,h,Ae.mat4())}}else{if("points"!==a&&"lines"!==a&&"triangles"!==a&&"solid"!==a&&"surface"!==a)return this.error("Unsupported value for 'primitive': '".concat(a,"' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.")),!1;if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),!1;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),!1;if(!e.buckets&&!e.indices)if(A)e.indices=this._createDefaultIndices((e.positions||e.positionsCompressed).length/3);else if("lines"===a)return this.error("Param expected: indices (required for '".concat(a,"' primitive type)")),!1;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),!1;if(e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position||e.quaternion){var p=e.scale||qo,v=e.position||$o,g=e.rotation?Ae.eulerToQuaternion(e.rotation,"XYZ",Yo):e.quaternion||ea;e.meshMatrix=Ae.composeMat4(v,g,p,Ae.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Hs(e.positionsDecodeBoundary,Ae.mat4())),e.positions){var m=[];Yt(e.positions,m,Zo)&&(e.positions=m,e.origin=Ae.addVec3(e.origin,Zo,Ae.vec3()));var y=Ae.collapseAABB3();u?(e.positionsDecodeMatrix=Ae.mat4(),Ae.expandAABB3Points3(y,e.positions),e.positionsCompressed=Ls(e.positions,y,e.positionsDecodeMatrix)):(e.meshMatrix&&(Ae.transformPositions3(e.meshMatrix,e.positions,e.positions),e.meshMatrix=null),Ae.expandAABB3Points3(y,e.positions)),e.aabb=y}else if(e.positionsCompressed){var _=Ae.collapseAABB3();Ae.expandAABB3Points3(_,e.positionsCompressed),pt.decompressAABB(_,e.positionsDecodeMatrix),e.aabb=_}if(u&&e.buckets){var b=Ae.collapseAABB3();e.buckets.forEach((function(e){var t=e.positions||e.positionsCompressed;t&&Ae.expandAABB3Points3(b,t)})),e.positionsDecodeMatrix&&pt.decompressAABB(b,e.positionsDecodeMatrix),e.aabb=b}A&&!e.buckets&&(e.edgeIndices||(e.edgeIndices=ot(e.positions||e.positionsCompressed,e.indices,e.positions?null:e.positionsDecodeMatrix,2)))}if(e.meshMatrix&&(Ae.AABB3ToOBB3(e.aabb,Jo),Ae.transformOBB3(e.meshMatrix,Jo,Jo),Ae.OBB3ToAABB3(Jo,e.aabb)),e.color=e.color?new Uint8Array(e.color.slice(0,3).map((function(e){return Math.floor(255*e)}))):na,e.opacity=Math.floor(255*(null!==(t=e.opacity)&&void 0!==t?t:1)),u)e.type=2,r&&(e.buckets=this._dtxBuckets[n]),e.buckets||(e.buckets=function(e,t,n){var r,i,s,o;if(t||n){var a=M(Uo({positionsCompressed:e.positionsCompressed,indices:e.indices,edgeIndices:e.edgeIndices}),3);r=a[0],i=a[1],s=a[2]}else r=e.positionsCompressed,i=e.indices,s=e.edgeIndices;if(n){o=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=e.positionsCompressed||[],i=Po(e.indices||[],t),s=Qo(e.edgeIndices||[]);function o(e,t){if(e>t){var n=e;e=t,t=n}function r(n,r){return n!==e?e-n:r!==t?t-r:0}for(var i=0,o=(s.length>>1)-1;i<=o;){var a=o+i>>1,A=r(s[2*a],s[2*a+1]);if(A>0)i=a+1;else{if(!(A<0))return a;o=a-1}}return-i-1}var a=new Int32Array(s.length/2);a.fill(0);var A=r.length/3;if(A>8*(1<<t))return[e];var c=new Int32Array(A);c.fill(-1);var u=[];function l(){c.fill(-1);var e={positionsCompressed:[],indices:[],edgeIndices:[],maxNumPositions:(1<<t)-t,numPositions:0,bucketNumber:u.length};return u.push(e),e}for(var h=l(),d=0,f=i.length;d<f;d+=3){var p=0,v=i[d],g=i[d+1],m=i[d+2];if(-1===c[v]&&p++,-1===c[g]&&p++,-1===c[m]&&p++,p+h.numPositions>h.maxNumPositions&&(h=l()),h.bucketNumber>8)return[e];-1===c[v]&&(c[v]=h.numPositions++,h.positionsCompressed.push(r[3*v]),h.positionsCompressed.push(r[3*v+1]),h.positionsCompressed.push(r[3*v+2])),-1===c[g]&&(c[g]=h.numPositions++,h.positionsCompressed.push(r[3*g]),h.positionsCompressed.push(r[3*g+1]),h.positionsCompressed.push(r[3*g+2])),-1===c[m]&&(c[m]=h.numPositions++,h.positionsCompressed.push(r[3*m]),h.positionsCompressed.push(r[3*m+1]),h.positionsCompressed.push(r[3*m+2])),h.indices.push(c[v]),h.indices.push(c[g]),h.indices.push(c[m]);var y=void 0;(y=o(v,g))>=0&&0===a[y]&&(a[y]=1,h.edgeIndices.push(c[s[2*y]]),h.edgeIndices.push(c[s[2*y+1]])),(y=o(v,m))>=0&&0===a[y]&&(a[y]=1,h.edgeIndices.push(c[s[2*y]]),h.edgeIndices.push(c[s[2*y+1]])),(y=o(g,m))>=0&&0===a[y]&&(a[y]=1,h.edgeIndices.push(c[s[2*y]]),h.edgeIndices.push(c[s[2*y+1]]))}var _=t/8*2,b=t/8,w=2*r.length+(i.length+s.length)*_,B=0;return r.length,u.forEach((function(e){B+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*b,e.positionsCompressed.length})),B>w?[e]:(n&&Ro(u,e),u)}({positionsCompressed:r,indices:i,edgeIndices:s},r.length/3>65536?16:8)}else o=[{positionsCompressed:r,indices:i,edgeIndices:s}];return o}(r?e.geometry:e,this._enableVertexWelding,this._enableIndexBucketing),r&&(this._dtxBuckets[n]=e.buckets));else if(e.type=r?0:1,e.metallic=Math.floor(255*(null!==(s=e.metallic)&&void 0!==s?s:0)),e.roughness=Math.floor(255*(null!==(o=e.roughness)&&void 0!==o?o:1)),c&&(e.textureSet=this._textureSets[c],!r&&!e.textureSet))return this.error("[createMesh] Texture set not found: ".concat(c," - ensure that you create it first with createTextureSet()")),!1;e.numPrimitives=this._getNumPrimitives(e);var w=new Ni(this,e.id,e.color,e.opacity,e.transform,e.textureSet),B=this.scene._renderer.getPickID(w);return w.pickId=B,w.origin=Ae.vec3(e.origin),w.layer=2===e.type?this._getDTXLayer(e):this._getVBOLayer(0===e.type,e),w.aabb=e.aabb,e.pickColor=new Uint8Array([255&B,B>>8&255,B>>16&255,B>>24&255]),e.solid="solid"===e.primitive,e.meshMatrix=e.transform?e.transform.worldMatrix:e.meshMatrix,w.portionId=w.layer.createPortion(w,e),w.numPrimitives=e.numPrimitives,this._meshes[e.id]=w,this._unusedMeshes[e.id]=w,this._meshList.push(w),w}},{key:"_getNumPrimitives",value:function(e){var t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(var n=0,r=e.buckets.length;n<r;n++)t+=e.buckets[n].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/3);case"points":switch(e.type){case 2:for(var i=0,s=e.buckets.length;i<s;i++)t+=e.buckets[i].positionsCompressed.length;break;case 1:t+=e.positions?e.positions.length:e.positionsCompressed.length;break;case 0:var o=e.geometry;t+=o.positions?o.positions.length:o.positionsCompressed.length}return Math.round(t);case"lines":case"line-strip":switch(e.type){case 2:for(var a=0,A=e.buckets.length;a<A;a++)t+=e.buckets[a].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/2)}return 0}},{key:"_getDTXLayer",value:function(e){var t=e.origin,n=e.geometry?e.geometry.primitive:e.primitive,r=".".concat(n,".").concat(Math.round(t[0]),".").concat(Math.round(t[1]),".").concat(Math.round(t[2])),i=this._dtxLayers[r];if(i){if(i.canCreatePortion(e))return i;delete this._dtxLayers[r],i=null}switch(n){case"triangles":case"solid":case"surface":i=new Ds(this,n,t);break;default:return}return this._dtxLayers[r]=i,this.layerList.push(i),this._layersToFinalize.push(i),i}},{key:"_getVBOLayer",value:function(e,t){var n=e&&t.geometry,r=e?n.primitive:t.primitive,i=t.origin,s=!e&&(t.positionsDecodeMatrix||t.positionsDecodeBoundary),o=s?this._createHashStringFromMatrix(s):"-",a=t.textureSetId||"-",A=e?t.geometryId:"-",c=(e?"instancing":"batching")+".".concat(Math.round(i[0]),".").concat(Math.round(i[1]),".").concat(Math.round(i[2]),".").concat(r,".").concat(o,".").concat(a,".").concat(A);if(!e&&c in this._vboLayers){var u=this._vboLayers[c],l=t.positionsCompressed?t.positionsCompressed.length:t.positions.length;u.canCreatePortion(l,"points"===r?0:t.indices.length)||(u.finalize(),delete this._vboLayers[c])}if(!(c in this._vboLayers)){var h=new uo(this,r,i,d({textureSet:t.textureSet},e?{geometry:n}:{maxGeometryBatchSize:this._maxGeometryBatchSize,positionsDecodeMatrix:t.positionsDecodeMatrix,uvDecodeMatrix:t.uvDecodeMatrix}));this.layerList.push(h),this._layersToFinalize.push(h),this._vboLayers[c]=h}return this._vboLayers[c]}},{key:"_createHashStringFromMatrix",value:function(e){for(var t=e.join(";"),n=0,r=0;r<t.length;r++){n=(n<<5)-n+t.charCodeAt(r),n|=0}return(n>>>0).toString(16)}},{key:"createEntity",value:function(e){if(void 0===e.id?e.id=Ae.createUUID():this.scene.components[e.id]&&(this.error("Scene already has a Component with this ID: ".concat(e.id," - will assign random ID")),e.id=Ae.createUUID()),void 0===e.meshIds)return this.error("Config missing: meshIds"),null;var t=function(e){return!1!==e},n=0;n|=this._visible&&t(e.visible)&&Gi,n|=this._pickable&&t(e.pickable)&&Wi,n|=this._culled&&t(e.culled)&&ji,n|=this._clippable&&t(e.clippable)&&zi,n|=this._collidable&&t(e.collidable)&&Xi,n|=this._xrayed&&t(e.xrayed)&&Ki,n|=this._highlighted&&t(e.highlighted)&&Zi,n|=this._selected&&t(e.selected)&&Ji,n|=this._edges&&t(e.edges)&&Yi,e.flags=n;for(var r=[],i=0,s=e.meshIds.length;i<s;i++){var o=e.meshIds[i],a=this._meshes[o];a?a.parent?this.error('Mesh with ID "'.concat(o,'" already belongs to object with ID "').concat(a.parent.id,'" - ignoring this mesh')):(r.push(a),delete this._unusedMeshes[o]):this.error('Mesh with this ID not found: "'.concat(o,'" - ignoring this mesh'))}var A=new Lo(this,e.isObject,e.id,r,e.flags,!0);return this._entityList.push(A),this._entities[e.id]=A,this._entitiesToFinalize.push(A),this.numEntities++,A}},{key:"preFinalize",value:function(){if(this.destroyed)return!1;if(0===this._layersToFinalize.length)return!1;this._createDummyEntityForUnusedMeshes();for(var e=0,t=this._layersToFinalize.length;e<t;e++){this._layersToFinalize[e].finalize()}this._vboLayers={},this._dtxLayers={},this._layersToFinalize=[];for(var n=0,r=this._entitiesToFinalize.length;n<r;n++){this._entitiesToFinalize[n]._finalize()}for(var i=0,s=this._entitiesToFinalize.length;i<s;i++){this._entitiesToFinalize[i]._finalize2()}this._entitiesToFinalize=[],this.scene._aabbDirty=!0,this._viewMatrixDirty=!0,this._matrixDirty=!0,this._aabbDirty=!0,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.position=this._position,this.layerList.sort((function(e,t){return e.sortId<t.sortId?-1:e.sortId>t.sortId?1:0}));for(var o=0,a=this.layerList.length;o<a;o++){this.layerList[o].layerIndex=o}this.glRedraw(),this._layersFinalized=!0}},{key:"finalize",value:function(){this.destroyed||(this.preFinalize(),this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={})}},{key:"stateSortCompare",value:function(e,t){}},{key:"rebuildRenderFlags",value:function(){this.renderFlags.reset(),this._updateRenderFlagsVisibleLayers(),this.renderFlags.numLayers>0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}},{key:"_updateRenderFlagsVisibleLayers",value:function(){var e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(var t=0,n=this.layerList.length;t<n;t++){var r=this.layerList[t];this._getActiveSectionPlanesForLayer(r)&&(e.visibleLayers[e.numVisibleLayers++]=t)}}},{key:"_createDummyEntityForUnusedMeshes",value:function(){var e=Object.keys(this._unusedMeshes);if(e.length>0){var t="".concat(this.id,"-").concat(Ae.createUUID());this.warn('Creating dummy SceneModelEntity "'.concat(t,'" for unused SceneMeshes: [').concat(e.join(","),"]")),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}},{key:"_getActiveSectionPlanesForLayer",value:function(e){var t=this.renderFlags,n=this.scene._sectionPlanesState.sectionPlanes,r=n.length,i=e.layerIndex*r;if(r>0)for(var s=0;s<r;s++){n[s].active?(t.sectionPlanesActivePerLayer[i+s]=!0,t.sectioned=!0):t.sectionPlanesActivePerLayer[i+s]=!1}return!0}},{key:"_updateRenderFlags",value:function(){if(0!==this.numVisibleLayerPortions&&this.numCulledLayerPortions!==this.numPortions){var e=this.renderFlags;if(e.colorOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){var t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0)this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(e.edgesTransparent=!0));if(this.numSelectedLayerPortions>0){var n=this.scene.selectedMaterial._state;n.fill&&(n.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),n.edges&&(n.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){var r=this.scene.highlightMaterial._state;r.fill&&(r.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),r.edges&&(r.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}}},{key:"_withEachVisibleLayer",value:function(e,t){if(!e||0!==this.numVisibleLayerPortions)for(var n=this.renderFlags,r=0,i=n.visibleLayers.length;r<i;r++){var s=n.visibleLayers[r];t(this.layerList[s])}}},{key:"drawColorOpaque",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawColorOpaque(t.renderFlags,e)}))}},{key:"drawColorTransparent",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawColorTransparent(t.renderFlags,e)}))}},{key:"drawDepth",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawDepth(t.renderFlags,e)}))}},{key:"drawSilhouetteXRayed",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawSilhouetteXRayed(t.renderFlags,e)}))}},{key:"drawSilhouetteHighlighted",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawSilhouetteHighlighted(t.renderFlags,e)}))}},{key:"drawSilhouetteSelected",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawSilhouetteSelected(t.renderFlags,e)}))}},{key:"drawEdgesColorOpaque",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawEdgesColorOpaque(t.renderFlags,e)}))}},{key:"drawEdgesColorTransparent",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawEdgesColorTransparent(t.renderFlags,e)}))}},{key:"drawEdgesXRayed",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawEdgesXRayed(t.renderFlags,e)}))}},{key:"drawEdgesHighlighted",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawEdgesHighlighted(t.renderFlags,e)}))}},{key:"drawEdgesSelected",value:function(e){var t=this;this._withEachVisibleLayer(!1,(function(n){return n.drawEdgesSelected(t.renderFlags,e)}))}},{key:"drawOcclusion",value:function(e){var t=this;this._withEachVisibleLayer(!0,(function(n){return n.drawOcclusion(t.renderFlags,e)}))}},{key:"drawShadow",value:function(e){var t=this;this._withEachVisibleLayer(!0,(function(n){return n.drawShadow(t.renderFlags,e)}))}},{key:"drawPickMesh",value:function(e){var t=this;this._withEachVisibleLayer(!0,(function(n){return n.drawPickMesh(t.renderFlags,e)}))}},{key:"drawPickDepths",value:function(e){var t=this;this._withEachVisibleLayer(!0,(function(n){return n.drawPickDepths(t.renderFlags,e)}))}},{key:"drawPickNormals",value:function(e){var t=this;this._withEachVisibleLayer(!0,(function(n){return n.drawPickNormals(t.renderFlags,e)}))}},{key:"_drawSnap",value:function(e,t){var n=this;this._withEachVisibleLayer(!0,(function(r){return r.drawSnap(n.renderFlags,e,t)}))}},{key:"drawSnapInit",value:function(e){this._drawSnap(e,!0)}},{key:"drawSnap",value:function(e){this._drawSnap(e,!1)}},{key:"destroy",value:function(){Object.values(this._vboLayers).forEach((function(e){return e.destroy()})),this._vboLayers={},this.scene.camera.off(this._onCameraViewMatrix),this.scene.off(this._onTick);for(var e=0,t=this.layerList.length;e<t;e++)this.layerList[e].destroy();this.layerList=[];for(var r=0,i=this._entityList.length;r<i;r++)this._entityList[r]._destroy();this._layersToFinalize=[],this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._meshes={},this._entities={},this.scene._aabbDirty=!0,this._isModel&&this.scene._deregisterModel(this),v(C(n.prototype),"destroy",this).call(this)}}]),n}();var ia=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))._positions=i.positions||[],i.indices)r._indices=i.indices;else{r._indices=[];for(var s=0,o=r._positions.length/3-1;s<o;s+=2)r._indices.push(s),r._indices.push(s+1)}return r._color=i.color||[1,1,1],r._opacity=i.opacity||1,r._sceneModel=new ra(w(r),{isModel:!1}),r._sceneModel.createMesh({id:"linesMesh",primitive:"lines",positions:r._positions,indices:r._indices,color:r._color,opacity:r._opacity}),r._sceneModel.createEntity({meshIds:["linesMesh"],visible:i.visible,clippable:i.clippable,collidable:i.collidable}),r._sceneModel.finalize(),r.scene._lineSetCreated(w(r)),r}return I(n,[{key:"visible",get:function(){return this._sceneModel.visible},set:function(e){this._sceneModel.visible=e}},{key:"positions",get:function(){return this._positions}},{key:"indices",get:function(){return this._indices}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this.scene._lineSetDestroyed(this)}}]),n}(),sa=function(e){m(n,Ie);var t=_(n);function n(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),t.call(this,e,r)}return I(n,[{key:"type",get:function(){return"Light"}},{key:"isLight",get:function(){return!0}}]),n}(),oa=function(e){m(n,sa);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={type:"ambient",color:Ae.vec3([.7,.7,.7]),intensity:1},r.color=i.color,r.intensity=i.intensity,r.scene._lightCreated(w(r)),r}return I(n,[{key:"type",get:function(){return"AmbientLight"}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){this._state.intensity=void 0!==e?e:1,this.glRedraw()}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this.scene._lightDestroyed(this)}}]),n}(),aa=function(){function e(t,n,r){x(this,e),this.gl=t,this.allocated=!1,this.buffer=null,this.bound=!1,this._colorFormats=n,this._hasDepthTexture=r}return I(e,[{key:"setSize",value:function(e){this.size=e}},{key:"bind",value:function(){var e=this.size[0],t=this.size[1];if(!this.buffer||this.buffer.width===e&&this.buffer.height===t||(this.buffer.cleanup(),this.buffer=null),this.buffer||(this._allocateBuffer(e,t),this.bound=!1),!this.bound){var n=this.gl;n.bindFramebuffer(n.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}}},{key:"_allocateBuffer",value:function(e,t){var n=this._colorFormats||[],r=this.gl,i=function(){var e=r.createTexture();return r.bindTexture(r.TEXTURE_2D,e),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),e},s=(n.length>0?n:[null]).map((function(n){var s=i();return n?r.texStorage2D(r.TEXTURE_2D,1,n,e,t):r.texImage2D(r.TEXTURE_2D,0,r.RGBA,e,t,0,r.RGBA,r.UNSIGNED_BYTE,null),s})),o=r.createRenderbuffer();r.bindRenderbuffer(r.RENDERBUFFER,o),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_COMPONENT32F,e,t);var a=r.createFramebuffer();r.bindFramebuffer(r.FRAMEBUFFER,a);for(var A=0;A<s.length;A++)r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+A,r.TEXTURE_2D,s[A],0);n.length>0&&r.drawBuffers(s.map((function(e,t){return r.COLOR_ATTACHMENT0+t})));var c=this._hasDepthTexture&&i();if(c?(r.texImage2D(r.TEXTURE_2D,0,r.DEPTH_COMPONENT32F,e,t,0,r.DEPTH_COMPONENT,r.FLOAT,null),r.framebufferTexture2D(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.TEXTURE_2D,c,0)):r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.RENDERBUFFER,o),r.bindTexture(r.TEXTURE_2D,null),r.bindRenderbuffer(r.RENDERBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,a),!r.isFramebuffer(a))throw"Invalid framebuffer";r.bindFramebuffer(r.FRAMEBUFFER,null);var u=r.checkFramebufferStatus(r.FRAMEBUFFER);switch(u){case r.FRAMEBUFFER_COMPLETE:break;case r.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case r.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+u}this.buffer={cleanup:function(){s.forEach((function(e){return r.deleteTexture(e)})),c&&r.deleteTexture(c),r.deleteFramebuffer(a),r.deleteRenderbuffer(o)},framebuf:a,width:e,height:t},this.colorTextures=s.map((function(e){return{bind:function(t){return r.activeTexture(r["TEXTURE"+t]),r.bindTexture(r.TEXTURE_2D,e),!0}}})),this.depthTexture=c&&{bind:function(e){return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(r.TEXTURE_2D,c),!0}}}},{key:"read",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Uint8Array,s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:4,o=arguments.length>6&&void 0!==arguments[6]?arguments[6]:0,a=new i(s),A=this.gl;return A.readBuffer(A.COLOR_ATTACHMENT0+o),A.readPixels(e,this.buffer.height-t-1,1,1,n||A.RGBA,r||A.UNSIGNED_BYTE,a,0),a}},{key:"unbind",value:function(){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),this.bound=!1}},{key:"destroy",value:function(){this.allocated&&(this.buffer.cleanup(),this.allocated=!1,this.buffer=null,this.bound=!1),this.colorTextures=null,this.depthTexture=null}}]),e}(),Aa=function(e){m(n,sa);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))._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var s=r.scene.camera,o=r.scene.canvas;return r._onCameraViewMatrix=s.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=s.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=o.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new it({type:"dir",dir:Ae.vec3([1,1,1]),color:Ae.vec3([.7,.7,.8]),intensity:1,space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(r._shadowViewMatrixDirty){r._shadowViewMatrix||(r._shadowViewMatrix=Ae.identityMat4());var e=r.scene.camera,t=r._state.dir,n=e.look,i=[n[0]-t[0],n[1]-t[1],n[2]-t[2]];Ae.lookAtMat4v(i,n,[0,1,0],r._shadowViewMatrix),r._shadowViewMatrixDirty=!1}return r._shadowViewMatrix},getShadowProjMatrix:function(){return r._shadowProjMatrixDirty&&(r._shadowProjMatrix||(r._shadowProjMatrix=Ae.identityMat4()),Ae.orthoMat4c(-40,40,-40,40,-40,80,r._shadowProjMatrix),r._shadowProjMatrixDirty=!1),r._shadowProjMatrix},getShadowRenderBuf:function(){return r._shadowRenderBuf||(r._shadowRenderBuf=new aa(r.scene.canvas.gl),r._shadowRenderBuf.setSize([1024,1024])),r._shadowRenderBuf}}),r.dir=i.dir,r.color=i.color,r.intensity=i.intensity,r.castsShadow=i.castsShadow,r.scene._lightCreated(w(r)),r}return I(n,[{key:"type",get:function(){return"DirLight"}},{key:"dir",get:function(){return this._state.dir},set:function(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),v(C(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}(),ca=function(e){m(n,sa);var t=_(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(this,n);var s=w(r=t.call(this,e,i));r._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var o=r.scene.camera,a=r.scene.canvas;return r._onCameraViewMatrix=o.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=o.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=a.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new it({type:"point",pos:Ae.vec3([1,1,1]),color:Ae.vec3([.7,.7,.8]),intensity:1,attenuation:[0,0,0],space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(s._shadowViewMatrixDirty){s._shadowViewMatrix||(s._shadowViewMatrix=Ae.identityMat4());var e=s._state.pos,t=o.look,n=o.up;Ae.lookAtMat4v(e,t,n,s._shadowViewMatrix),s._shadowViewMatrixDirty=!1}return s._shadowViewMatrix},getShadowProjMatrix:function(){if(s._shadowProjMatrixDirty){s._shadowProjMatrix||(s._shadowProjMatrix=Ae.identityMat4());var e=s.scene.canvas.canvas;Ae.perspectiveMat4(Math.PI/180*70,e.clientWidth/e.clientHeight,.1,500,s._shadowProjMatrix),s._shadowProjMatrixDirty=!1}return s._shadowProjMatrix},getShadowRenderBuf:function(){return s._shadowRenderBuf||(s._shadowRenderBuf=new aa(s.scene.canvas.gl),s._shadowRenderBuf.setSize([1024,1024])),s._shadowRenderBuf}}),r.pos=i.pos,r.color=i.color,r.intensity=i.intensity,r.constantAttenuation=i.constantAttenuation,r.linearAttenuation=i.linearAttenuation,r.quadraticAttenuation=i.quadraticAttenuation,r.castsShadow=i.castsShadow,r.scene._lightCreated(w(r)),r}return I(n,[{key:"type",get:function(){return"PointLight"}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"constantAttenuation",get:function(){return this._state.attenuation[0]},set:function(e){this._state.attenuation[0]=e||0,this.glRedraw()}},{key:"linearAttenuation",get:function(){return this._state.attenuation[1]},set:function(e){this._state.attenuation[1]=e||0,this.glRedraw()}},{key:"quadraticAttenuation",get:function(){return this._state.attenuation[2]},set:function(e){this._state.attenuation[2]=e||0,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),v(C(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}();function ua(e){return 0==(e&e-1)}function la(e){--e;for(var t=1;t<32;t<<=1)e|=e>>t;return e+1}var ha=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);var s=(r=t.call(this,e,i)).scene.canvas.gl;return r._state=new it({texture:new $r({gl:s,target:s.TEXTURE_CUBE_MAP}),flipY:r._checkFlipY(i.minFilter),encoding:r._checkEncoding(i.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),r._src=i.src,r._images=[],r._loadSrc(i.src),he.memory.textures++,r}return I(n,[{key:"type",get:function(){return"CubeTexture"}},{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:"_loadSrc",value:function(e){var t=this,n=this.scene.canvas.gl;this._images=[];for(var r=!1,i=0,s=function(s){var o,a,A=new Image;A.onload=(o=A,a=s,function(){if(!r&&(o=function(e){if(!ua(e.width)||!ua(e.height)){var t=document.createElement("canvas");t.width=la(e.width),t.height=la(e.height),t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}(o),t._images[a]=o,6==++i)){var e=t._state.texture;e||(e=new $r({gl:n,target:n.TEXTURE_CUBE_MAP}),t._state.texture=e),e.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}),A.onerror=function(){r=!0},A.src=e[s]},o=0;o<e.length;o++)s(o)}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.texture&&this._state.texture.destroy(),he.memory.textures--,this._state.destroy()}}]),n}(),da=function(e){m(n,ha);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)).scene._lightsState.addReflectionMap(r._state),r.scene._reflectionMapCreated(w(r)),r}return I(n,[{key:"type",get:function(){return"ReflectionMap"}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this.scene._reflectionMapDestroyed(this)}}]),n}(),fa=function(e){m(n,ha);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)).scene._lightMapCreated(w(r)),r}return I(n,[{key:"type",get:function(){return"LightMap"}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this.scene._lightMapDestroyed(this)}}]),n}(),pa=Ae.vec4(),va=Ae.vec4(),ga=function(e){m(n,Ie);var t=_(n);function n(e,r){var i;return x(this,n),(i=t.call(this,e,r))._entity=null,i._visible=null,i._worldPos=Ae.vec3(),i._origin=Ae.vec3(),i._rtcPos=Ae.vec3(),i._viewPos=Ae.vec3(),i._canvasPos=Ae.vec2(),i._occludable=!1,i._onCameraViewMatrix=i.scene.camera.on("matrix",(function(){i._viewPosDirty=!0,i._needUpdate()})),i._onCameraProjMatrix=i.scene.camera.on("projMatrix",(function(){i._canvasPosDirty=!0,i._needUpdate()})),i._onEntityDestroyed=null,i._onEntityModelDestroyed=null,i._renderer.addMarker(w(i)),i.entity=r.entity,i.worldPos=r.worldPos,i.occludable=r.occludable,i}return I(n,[{key:"_update",value:function(){if(this._viewPosDirty&&(Ae.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){pa.set(this._viewPos),pa[3]=1,Ae.transformPoint4(this.scene.camera.projMatrix,pa,va);var e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+va[0]/va[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-va[1]/va[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}},{key:"_setVisible",value:function(e){this._visible,this._visible=e,this.fire("visible",this._visible)}},{key:"entity",get:function(){return this._entity},set:function(e){var t=this;this._entity!==e&&(this._cleanupDestroyedHandlers(),this._entity=e,this._entity&&(this._entity.isSceneModelEntity?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(function(){t._entity=null,t._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(function(){t._entity=null,t._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0))}},{key:"occludable",get:function(){return this._occludable},set:function(e){(e=!!e)!==this._occludable&&(this._occludable=e,this._occludable&&this._renderer.markerWorldPosUpdated(this))}},{key:"worldPos",get:function(){return this._worldPos},set:function(e){this._worldPos.set(e||[0,0,0]),Jt(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}},{key:"origin",get:function(){return this._origin}},{key:"rtcPos",get:function(){return this._rtcPos}},{key:"viewPos",get:function(){return this._update(),this._viewPos}},{key:"canvasPos",get:function(){return this._update(),this._canvasPos}},{key:"visible",get:function(){return!!this._visible}},{key:"destroy",value:function(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._cleanupDestroyedHandlers(),this._renderer.removeMarker(this),v(C(n.prototype),"destroy",this).call(this)}},{key:"_cleanupDestroyedHandlers",value:function(){this._entity&&(null!==this._onEntityDestroyed&&(this._entity.model?this._entity.model.off(this._onEntityDestroyed):this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model&&this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null))}}]),n}(),ma=function(e){m(n,ga);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,{entity:i.entity,occludable:i.occludable,worldPos:i.worldPos}))._occluded=!1,r._visible=!0,r._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),{src:i.src}),r._geometry=new mt(w(r),{primitive:"triangles",positions:[3,3,0,-3,3,0,-3,-3,0,3,-3,0],normals:[-1,0,0,-1,0,0,-1,0,0,-1,0,0],uv:[1,-1,0,-1,0,0,1,0],indices:[0,1,2,0,2,3]}),r._mesh=new Gr(w(r),{geometry:r._geometry,material:new Zr(w(r),{ambient:[.9,.3,.9],shininess:30,diffuseMap:r._texture,backfaces:!0}),scale:[1,1,1],position:i.worldPos,rotation:[90,0,0],billboard:"spherical",occluder:!1}),r.visible=!0,r.collidable=i.collidable,r.clippable=i.clippable,r.pickable=i.pickable,r.opacity=i.opacity,r.size=i.size,i.image?r.image=i.image:r.src=i.src,r}return I(n,[{key:"_setVisible",value:function(e){this._occluded=!e,this._mesh.visible=this._visible&&!this._occluded,v(C(n.prototype),"_setVisible",this).call(this,e)}},{key:"visible",get:function(){return this._visible},set:function(e){this._visible=null==e||e,this._mesh.visible=this._visible&&!this._occluded}},{key:"image",get:function(){return this._image},set:function(e){this._image=e,this._image&&(this._imageSize[0]=this._image.width,this._imageSize[1]=this._image.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:"size",get:function(){return this._size},set:function(e){this._size=null==e?1:e,this._image&&this._updatePlaneSizeFromImage()}},{key:"collidable",get:function(){return this._mesh.collidable},set:function(e){this._mesh.collidable=!1!==e}},{key:"clippable",get:function(){return this._mesh.clippable},set:function(e){this._mesh.clippable=!1!==e}},{key:"pickable",get:function(){return this._mesh.pickable},set:function(e){this._mesh.pickable=!1!==e}},{key:"opacity",get:function(){return this._mesh.opacity},set:function(e){this._mesh.opacity=e}},{key:"_updatePlaneSizeFromImage",value:function(){var e=.5*this._size,t=this._imageSize[0],n=this._imageSize[1],r=n/t;this._geometry.positions=t>n?[e,e*r,0,-e,e*r,0,-e,-e*r,0,e,-e*r,0]:[e/r,e,0,-e/r,e,0,-e/r,-e,0,e/r,-e,0]}}]),n}(),ya=function(){function e(t){x(this,e),this._eye=Ae.vec3(),this._look=Ae.vec3(),this._up=Ae.vec3(),this._projection={},t&&this.saveCamera(t)}return I(e,[{key:"saveCamera",value:function(e){var t=e.camera,n=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:n.fov,fovAxis:n.fovAxis,near:n.near,far:n.far};break;case"ortho":this._projection={projection:"ortho",scale:n.scale,near:n.near,far:n.far};break;case"frustum":this._projection={projection:"frustum",left:n.left,right:n.right,top:n.top,bottom:n.bottom,near:n.near,far:n.far};break;case"custom":this._projection={projection:"custom",matrix:n.matrix.slice()}}}},{key:"restoreCamera",value:function(e,t){var n=e.camera,r=this._projection;function i(){switch(r.type){case"perspective":n.perspective.fov=r.fov,n.perspective.fovAxis=r.fovAxis,n.perspective.near=r.near,n.perspective.far=r.far;break;case"ortho":n.ortho.scale=r.scale,n.ortho.near=r.near,n.ortho.far=r.far;break;case"frustum":n.frustum.left=r.left,n.frustum.right=r.right,n.frustum.top=r.top,n.frustum.bottom=r.bottom,n.frustum.near=r.near,n.frustum.far=r.far;break;case"custom":n.customProjection.matrix=r.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:r.scale,projection:r.projection},(function(){i(),t()})):(n.eye=this._eye,n.look=this._look,n.up=this._up,i(),n.projection=r.projection)}}]),e}(),_a=Ae.vec3(),ba=function(){function e(t){if(x(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsOpacity=[],this.numObjects=0,t){var n=t.metaScene.scene;this.saveObjects(n,t)}}return I(e,[{key:"saveObjects",value:function(e,t,n){this.numObjects=0,this._mask=n?ge.apply(n,{}):null;for(var r=!n||n.visible,i=!n||n.edges,s=!n||n.xrayed,o=!n||n.highlighted,a=!n||n.selected,A=!n||n.clippable,c=!n||n.pickable,u=!n||n.colorize,l=!n||n.opacity,h=t.metaObjects,d=e.objects,f=0,p=h.length;f<p;f++){var v=d[h[f].id];if(v){if(r&&(this.objectsVisible[f]=v.visible),i&&(this.objectsEdges[f]=v.edges),s&&(this.objectsXrayed[f]=v.xrayed),o&&(this.objectsHighlighted[f]=v.highlighted),a&&(this.objectsSelected[f]=v.selected),A&&(this.objectsClippable[f]=v.clippable),c&&(this.objectsPickable[f]=v.pickable),u){var g=v.colorize;this.objectsColorize[3*f+0]=g[0],this.objectsColorize[3*f+1]=g[1],this.objectsColorize[3*f+2]=g[2]}l&&(this.objectsOpacity[f]=v.opacity),this.numObjects++}}}},{key:"restoreObjects",value:function(e,t){for(var n=this._mask,r=!n||n.visible,i=!n||n.edges,s=!n||n.xrayed,o=!n||n.highlighted,a=!n||n.selected,A=!n||n.clippable,c=!n||n.pickable,u=!n||n.colorize,l=!n||n.opacity,h=t.metaObjects,d=e.objects,f=0,p=h.length;f<p;f++){var v=d[h[f].id];v&&(r&&(v.visible=this.objectsVisible[f]),i&&(v.edges=this.objectsEdges[f]),s&&(v.xrayed=this.objectsXrayed[f]),o&&(v.highlighted=this.objectsHighlighted[f]),a&&(v.selected=this.objectsSelected[f]),A&&(v.clippable=this.objectsClippable[f]),c&&(v.pickable=this.objectsPickable[f]),u&&(_a[0]=this.objectsColorize[3*f+0],_a[1]=this.objectsColorize[3*f+1],_a[2]=this.objectsColorize[3*f+2],v.colorize=_a),l&&(v.opacity=this.objectsOpacity[f]))}}}]),e}(),wa=Ae.vec3(),Ba=function(){function e(){x(this,e),this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}return I(e,[{key:"saveObjects",value:function(e,t){this.numObjects=0,this._mask=t?ge.apply(t,{}):null;var n=e.objects,r=!t||t.visible,i=!t||t.edges,s=!t||t.xrayed,o=!t||t.highlighted,a=!t||t.selected,A=!t||t.clippable,c=!t||t.pickable,u=!t||t.colorize,l=!t||t.opacity;for(var h in n)if(n.hasOwnProperty(h)){var d=n[h],f=this.numObjects;if(r&&(this.objectsVisible[f]=d.visible),i&&(this.objectsEdges[f]=d.edges),s&&(this.objectsXrayed[f]=d.xrayed),o&&(this.objectsHighlighted[f]=d.highlighted),a&&(this.objectsSelected[f]=d.selected),A&&(this.objectsClippable[f]=d.clippable),c&&(this.objectsPickable[f]=d.pickable),u){var p=d.colorize;p?(this.objectsColorize[3*f+0]=p[0],this.objectsColorize[3*f+1]=p[1],this.objectsColorize[3*f+2]=p[2],this.objectsHasColorize[f]=!0):this.objectsHasColorize[f]=!1}l&&(this.objectsOpacity[f]=d.opacity),this.numObjects++}}},{key:"restoreObjects",value:function(e){var t=this._mask,n=!t||t.visible,r=!t||t.edges,i=!t||t.xrayed,s=!t||t.highlighted,o=!t||t.selected,a=!t||t.clippable,A=!t||t.pickable,c=!t||t.colorize,u=!t||t.opacity,l=0,h=e.objects;for(var d in h)if(h.hasOwnProperty(d)){var f=h[d];n&&(f.visible=this.objectsVisible[l]),r&&(f.edges=this.objectsEdges[l]),i&&(f.xrayed=this.objectsXrayed[l]),s&&(f.highlighted=this.objectsHighlighted[l]),o&&(f.selected=this.objectsSelected[l]),a&&(f.clippable=this.objectsClippable[l]),A&&(f.pickable=this.objectsPickable[l]),c&&(this.objectsHasColorize[l]?(wa[0]=this.objectsColorize[3*l+0],wa[1]=this.objectsColorize[3*l+1],wa[2]=this.objectsColorize[3*l+2],f.colorize=wa):f.colorize=null),u&&(f.opacity=this.objectsOpacity[l]),l++}}}]),e}(),Ca=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)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.v3=i.v3,r.t=i.t,r}return I(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||Ae.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||Ae.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||Ae.vec3([0,0,0])}},{key:"v3",get:function(){return this._v3},set:function(e){this.fire("v3",this._v3=e||Ae.vec3([0,0,0]))}},{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=Ae.vec3();return t[0]=Ae.b3(e,this._v0[0],this._v1[0],this._v2[0],this._v3[0]),t[1]=Ae.b3(e,this._v0[1],this._v1[1],this._v2[1],this._v3[1]),t[2]=Ae.b3(e,this._v0[2],this._v1[2],this._v2[2],this._v3[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,v3:this._v3,t:this._t}}}]),n}(),ka=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))._cachedLengths=[],r._dirty=!0,r._curves=[],r._t=0,r._dirtySubs=[],r._destroyedSubs=[],r.curves=i.curves||[],r.t=i.t,r}return I(n,[{key:"addCurve",value:function(e){this._curves.push(e),this._dirty=!0}},{key:"curves",get:function(){return this._curves},set:function(e){var t,n,r;for(e=e||[],n=0,r=this._curves.length;n<r;n++)(t=this._curves[n]).off(this._dirtySubs[n]),t.off(this._destroyedSubs[n]);this._curves=[],this._dirtySubs=[],this._destroyedSubs=[];var i=this;function s(){i._dirty=!0}function o(){var e=this.id;for(n=0,r=i._curves.length;n<r;n++)if(i._curves[n].id===e)return i._curves=i._curves.slice(n,n+1),i._dirtySubs=i._dirtySubs.slice(n,n+1),i._destroyedSubs=i._destroyedSubs.slice(n,n+1),void(i._dirty=!0)}for(n=0,r=e.length;n<r;n++){if(t=e[n],ge.isNumeric(t)||ge.isString(t)){var a=t;if(!(t=this.scene.components[a])){this.error("Component not found: "+_inQuotes(a));continue}}var A=t.type;"xeokit.SplineCurve"===A||"xeokit.Path"===A||"xeokit.CubicBezierCurve"===A||"xeokit.QuadraticBezierCurve"===A?(this._curves.push(t),this._dirtySubs.push(t.on("dirty",s)),this._destroyedSubs.push(t.once("destroyed",o))):this.error("Component "+_inQuotes(t.id)+" is not a xeokit.SplineCurve, xeokit.Path or xeokit.QuadraticBezierCurve")}this._dirty=!0}},{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:"length",get:function(){var e=this._getCurveLengths();return e[e.length-1]}},{key:"getPoint",value:function(e){for(var t,n=e*this.length,r=this._getCurveLengths(),i=0;i<r.length;){if(r[i]>=n){var s=1-(r[i]-n)/(t=this._curves[i]).length;return t.getPointAt(s)}i++}return null}},{key:"_getCurveLengths",value:function(){if(!this._dirty)return this._cachedLengths;var e,t=[],n=0,r=this._curves.length;for(e=0;e<r;e++)n+=this._curves[e].length,t.push(n);return this._cachedLengths=t,this._dirty=!1,t}},{key:"_getJSON",value:function(){for(var e=[],t=0,n=this._curves.length;t<n;t++)e.push(this._curves[t].id);return{curves:e,t:this._t}}},{key:"destroy",value:function(){var e,t,r;for(v(C(n.prototype),"destroy",this).call(this),e=0,t=this._curves.length;e<t;e++)(r=this._curves[e]).off(this._dirtySubs[e]),r.off(this._destroyedSubs[e])}}]),n}(),Ma=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)).v0=i.v0,r.v1=i.v1,r.v2=i.v2,r.t=i.t,r}return I(n,[{key:"v0",get:function(){return this._v0},set:function(e){this._v0=e||Ae.vec3([0,0,0])}},{key:"v1",get:function(){return this._v1},set:function(e){this._v1=e||Ae.vec3([0,0,0])}},{key:"v2",get:function(){return this._v2},set:function(e){this._v2=e||Ae.vec3([0,0,0])}},{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=Ae.vec3();return t[0]=Ae.b2(e,this._v0[0],this._v1[0],this._v2[0]),t[1]=Ae.b2(e,this._v0[1],this._v1[1],this._v2[1]),t[2]=Ae.b2(e,this._v0[2],this._v1[2],this._v2[2]),t}},{key:"getJSON",value:function(){return{v0:this._v0,v1:this._v1,v2:this._v2,t:this._t}}}]),n}(),Ea=function(e){m(n,ra);var t=_(n);function n(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return x(this,n),t.call(this,e,r)}return I(n)}(),Fa=Ae.vec3(),xa=Ae.vec3(),Ua=Ae.vec4(),Ia=Ae.vec3([0,0,-1]),Ta=Ae.vec3([0,0,1]),Pa=Ae.vec3([0,1,0]),Sa=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({active:!0,pos:Ae.vec3(),quaternion:Ae.vec4(),roll:0,dir:Ae.vec3(),dist:0}),r.active=i.active,r.pos=i.pos,r.dir=i.dir,r.scene._sectionPlaneCreated(w(r)),r}return I(n,[{key:"type",get:function(){return"SectionPlane"}},{key:"active",get:function(){return this._state.active},set:function(e){this._state.active=!1!==e,this.glRedraw(),this.fire("active",this._state.active),this.scene.fire("sectionPlaneUpdated",this)}},{key:"pos",get:function(){return this._state.pos},set:function(e){this._state.pos.set(e||[0,0,0]),this._state.dist=-Ae.dotVec3(this._state.pos,this._state.dir),this.fire("pos",this._state.pos),this.scene.fire("sectionPlaneUpdated",this)}},{key:"quaternion",get:function(){return this._state.quaternion},set:function(e){this._state.quaternion.set(e||[0,0,0,-1]),Ae.vec3ApplyQuaternion(this._state.quaternion,Ta,this._state.dir);var t=Ae.vec3ApplyQuaternion(this._state.quaternion,Pa,Fa),n=Ae.vec3PairToQuaternion(Ta,this._state.dir,Ua),r=Ae.vec3ApplyQuaternion(n,Pa,xa),i=Math.acos(Math.min(1,Ae.dotVec3(t,r))),s=Math.sign(Ae.dotVec3(this._state.dir,Ae.cross3Vec3(t,r,xa)));this._state.roll=s*i,this._onDirUpdated()}},{key:"roll",get:function(){return this._state.roll},set:function(e){this._state.roll=e||0,this._onDirRollUpdated()}},{key:"dir",get:function(){return this._state.dir},set:function(e){this._state.dir.set(e||Ia),this._onDirRollUpdated()}},{key:"_onDirRollUpdated",value:function(){Ae.vec3PairToQuaternion(Ta,this._state.dir,this._state.quaternion),Ua[0]=0,Ua[1]=0,Ua[2]=-1,Ua[3]=this._state.roll,Ae.angleAxisToQuaternion(Ua,Ua),Ae.mulQuaternions(this._state.quaternion,Ua,this._state.quaternion),this._onDirUpdated()}},{key:"_onDirUpdated",value:function(){this._state.dist=-Ae.dotVec3(this._state.pos,this._state.dir),this.glRedraw(),this.fire("dir",this._state.dir),this.scene.fire("sectionPlaneUpdated",this)}},{key:"dist",get:function(){return this._state.dist}},{key:"flipDir",value:function(){Ae.mulVec3Scalar(this._state.dir,-1,this._state.dir),this.dir=this._state.dir}},{key:"destroy",value:function(){this._state.destroy(),this.scene._sectionPlaneDestroyed(this),v(C(n.prototype),"destroy",this).call(this)}}]),n}(),Da=function(){function e(){x(this,e)}return I(e,[{key:"transcode",value:function(e,t){}},{key:"destroy",value:function(){}}]),e}(),Qa=function(){function e(){x(this,e),this.entity=null,this.primitive=null,this.primIndex=-1,this.pickSurfacePrecision=!1,this.touchInput=!1,this.snappedToEdge=!1,this.snappedToVertex=!1,this._origin=new Float64Array([0,0,0]),this._direction=new Float64Array([0,0,0]),this._indices=new Int32Array(3),this._localPos=new Float64Array([0,0,0]),this._worldPos=new Float64Array([0,0,0]),this._viewPos=new Float64Array([0,0,0]),this._canvasPos=new Int16Array([0,0]),this._snappedCanvasPos=new Int16Array([0,0]),this._bary=new Float64Array([0,0,0]),this._worldNormal=new Float64Array([0,0,0]),this._uv=new Float64Array([0,0]),this.reset()}return I(e,[{key:"canvasPos",get:function(){return this._gotCanvasPos?this._canvasPos:null},set:function(e){e?(this._canvasPos[0]=e[0],this._canvasPos[1]=e[1],this._gotCanvasPos=!0):this._gotCanvasPos=!1}},{key:"origin",get:function(){return this._gotOrigin?this._origin:null},set:function(e){e?(this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this._gotOrigin=!0):this._gotOrigin=!1}},{key:"direction",get:function(){return this._gotDirection?this._direction:null},set:function(e){e?(this._direction[0]=e[0],this._direction[1]=e[1],this._direction[2]=e[2],this._gotDirection=!0):this._gotDirection=!1}},{key:"indices",get:function(){return this.entity&&this._gotIndices?this._indices:null},set:function(e){e?(this._indices[0]=e[0],this._indices[1]=e[1],this._indices[2]=e[2],this._gotIndices=!0):this._gotIndices=!1}},{key:"localPos",get:function(){return this.entity&&this._gotLocalPos?this._localPos:null},set:function(e){e?(this._localPos[0]=e[0],this._localPos[1]=e[1],this._localPos[2]=e[2],this._gotLocalPos=!0):this._gotLocalPos=!1}},{key:"snappedCanvasPos",get:function(){return this._gotSnappedCanvasPos?this._snappedCanvasPos:null},set:function(e){e?(this._snappedCanvasPos[0]=e[0],this._snappedCanvasPos[1]=e[1],this._gotSnappedCanvasPos=!0):this._gotSnappedCanvasPos=!1}},{key:"worldPos",get:function(){return this._gotWorldPos?this._worldPos:null},set:function(e){e?(this._worldPos[0]=e[0],this._worldPos[1]=e[1],this._worldPos[2]=e[2],this._gotWorldPos=!0):this._gotWorldPos=!1}},{key:"viewPos",get:function(){return this.entity&&this._gotViewPos?this._viewPos:null},set:function(e){e?(this._viewPos[0]=e[0],this._viewPos[1]=e[1],this._viewPos[2]=e[2],this._gotViewPos=!0):this._gotViewPos=!1}},{key:"bary",get:function(){return this.entity&&this._gotBary?this._bary:null},set:function(e){e?(this._bary[0]=e[0],this._bary[1]=e[1],this._bary[2]=e[2],this._gotBary=!0):this._gotBary=!1}},{key:"worldNormal",get:function(){return this.entity&&this._gotWorldNormal?this._worldNormal:null},set:function(e){e?(this._worldNormal[0]=e[0],this._worldNormal[1]=e[1],this._worldNormal[2]=e[2],this._gotWorldNormal=!0):this._gotWorldNormal=!1}},{key:"uv",get:function(){return this.entity&&this._gotUV?this._uv:null},set:function(e){e?(this._uv[0]=e[0],this._uv[1]=e[1],this._gotUV=!0):this._gotUV=!1}},{key:"snapped",get:function(){return this.snappedToEdge||this.snappedToVertex}},{key:"reset",value:function(){this.entity=null,this.primIndex=-1,this.primitive=null,this.pickSurfacePrecision=!1,this._gotCanvasPos=!1,this._gotSnappedCanvasPos=!1,this._gotOrigin=!1,this._gotDirection=!1,this._gotIndices=!1,this._gotLocalPos=!1,this._gotWorldPos=!1,this._gotViewPos=!1,this._gotBary=!1,this._gotWorldNormal=!1,this._gotUV=!1,this.touchInput=!1,this.snappedToEdge=!1,this.snappedToVertex=!1}}]),e}(),Ra={isIphoneSafari:function(){var e=window.navigator.userAgent,t=/iPhone/i.test(e),n=/Safari/i.test(e)&&!/Chrome/i.test(e);return t&&n},isIphoneOrIpadSafari:function(){var e=window.navigator.userAgent,t=/iPhone|iPad/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints&&navigator.maxTouchPoints>2,n=/Safari/i.test(e)&&!/Chrome/i.test(e);return t&&n},isTouchDevice:function(){return"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.mxMaxTouchPoints>0}},Oa=function(){function e(t,n,r){x(this,e),this.id=r&&r.id?r.id:t,this.viewer=n,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,n.addPlugin(this)}return I(e,[{key:"scheduleTask",value:function(e){Fe.scheduleTask(e,null)}},{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){console.log("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"warn",value:function(e){console.warn("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"error",value:function(e){console.error("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"send",value:function(e,t){}},{key:"destroy",value:function(){this.viewer.removePlugin(this)}}]),e}(),Va=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))._canvas=i.canvas,r._element=null,r._isCustom=!1,i.elementId&&(r._element=document.getElementById(i.elementId),r._element?r._adjustPosition():r.error("Can't find given Spinner HTML element: '"+i.elementId+"' - will automatically create default element")),r._element||r._createDefaultSpinner(),r.processes=0,r}return I(n,[{key:"type",get:function(){return"Spinner"}},{key:"_createDefaultSpinner",value:function(){this._injectDefaultCSS();var e=document.createElement("div"),t=e.style;t["z-index"]="9000",t.position="absolute",e.innerHTML='<div class="sk-fading-circle"> <div class="sk-circle1 sk-circle"></div> <div class="sk-circle2 sk-circle"></div> <div class="sk-circle3 sk-circle"></div> <div class="sk-circle4 sk-circle"></div> <div class="sk-circle5 sk-circle"></div> <div class="sk-circle6 sk-circle"></div> <div class="sk-circle7 sk-circle"></div> <div class="sk-circle8 sk-circle"></div> <div class="sk-circle9 sk-circle"></div> <div class="sk-circle10 sk-circle"></div> <div class="sk-circle11 sk-circle"></div> <div class="sk-circle12 sk-circle"></div> </div>',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}},{key:"_injectDefaultCSS",value:function(){var e="xeokit-spinner-css";if(!document.getElementById(e)){var t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}}},{key:"_adjustPosition",value:function(){if(!this._isCustom){var e=this._canvas,t=this._element,n=t.style;n.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",n.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}}},{key:"processes",get:function(){return this._processes},set:function(e){if(e=e||0,this._processes!==e&&!(e<0)){var t=this._processes;this._processes=e;var n=this._element;n&&(n.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}}},{key:"_destroy",value:function(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);var e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}]),n}(),La=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"],Ha=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))._backgroundColor=Ae.vec3([i.backgroundColor?i.backgroundColor[0]:1,i.backgroundColor?i.backgroundColor[1]:1,i.backgroundColor?i.backgroundColor[2]:1]),r._backgroundColorFromAmbientLight=!!i.backgroundColorFromAmbientLight,r.canvas=i.canvas,r.gl=null,r.webgl2=!1,r.transparent=!!i.transparent,r.contextAttr=i.contextAttr||{},r.contextAttr.alpha=r.transparent,r.contextAttr.preserveDrawingBuffer=!!r.contextAttr.preserveDrawingBuffer,r.contextAttr.stencil=!1,r.contextAttr.premultipliedAlpha=!!r.contextAttr.premultipliedAlpha,r.contextAttr.antialias=!1!==r.contextAttr.antialias,r.resolutionScale=i.resolutionScale,r.canvas.width=Math.round(r.canvas.clientWidth*r._resolutionScale),r.canvas.height=Math.round(r.canvas.clientHeight*r._resolutionScale),r.boundary=[r.canvas.offsetLeft,r.canvas.offsetTop,r.canvas.clientWidth,r.canvas.clientHeight],r._initWebGL(i);var s=w(r),o=!0,a=new ResizeObserver((function(e){var t,n=l(e);try{for(n.s();!(t=n.n()).done;){t.value.contentBoxSize&&(o=!0)}}catch(e){n.e(e)}finally{n.f()}}));return a.observe(r.canvas),r._tick=r.scene.on("tick",(function(){o&&(o=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),r._spinner=new Va(r.scene,{canvas:r.canvas,elementId:i.spinnerElementId}),r}return I(n,[{key:"type",get:function(){return"Canvas"}},{key:"backgroundColorFromAmbientLight",get:function(){return this._backgroundColorFromAmbientLight},set:function(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}},{key:"backgroundColor",get:function(){return this._backgroundColor},set:function(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}},{key:"resolutionScale",get:function(){return this._resolutionScale},set:function(e){if((e=e||1)!==this._resolutionScale){this._resolutionScale=e;var t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}}},{key:"spinner",get:function(){return this._spinner}},{key:"_createCanvas",value:function(){var e="xeokit-canvas-"+Ae.createUUID(),t=document.getElementsByTagName("body")[0],n=document.createElement("div"),r=n.style;r.height="100%",r.width="100%",r.padding="0",r.margin="0",r.background="rgba(0,0,0,0);",r.float="left",r.left="0",r.top="0",r.position="absolute",r.opacity="1.0",r["z-index"]="-10000",n.innerHTML+='<canvas id="'+e+'" style="width: 100%; height: 100%; float: left; margin: 0; padding: 0;"></canvas>',t.appendChild(n),this.canvas=document.getElementById(e)}},{key:"_getElementXY",value:function(e){for(var t=0,n=0;e;)t+=e.offsetLeft-e.scrollLeft,n+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:n}}},{key:"_initWebGL",value:function(){if(!this.gl)for(var e=0;!this.gl&&e<La.length;e++)try{this.gl=this.canvas.getContext(La[e],this.contextAttr)}catch(e){}this.gl||(this.error("Failed to get a WebGL context"),this.fire("webglContextFailed",!0,!0));var t=this.gl,n="__",r=t.activeTexture;t.activeTexture=function(e){n!==e&&(n=e,r.call(this,e))};var i={},s=t.bindTexture;t.bindTexture=function(e,t){i[n]!==t&&(i[n]=t,s.call(this,e,t))},this.gl&&this.webgl2&&(this.gl.hint(this.gl.FRAGMENT_SHADER_DERIVATIVE_HINT,this.gl.FASTEST),this.gl,WebGL2RenderingContext)}},{key:"getSnapshot",value:function(e){throw"Canvas#getSnapshot() has been replaced by Viewer#getSnapshot() - use that method instead."}},{key:"readPixels",value:function(e,t,n){return this.scene._renderer.snapshot.readPixels(e,t,n)}},{key:"loseWebGLContext",value:function(){this.canvas.loseContext&&this.canvas.loseContext()}},{key:"destroy",value:function(){this.scene.off(this._tick),this._spinner._destroy(),this.gl=null,v(C(n.prototype),"destroy",this).call(this)}}]),n}(),Na=function(){function e(t){x(this,e),this._matPool=[],this.reset()}return I(e,[{key:"reset",value:function(){this._matPoolNextFreeIndex=0,this._rtcViewMats={},this.lastProgramId=null,this.pbrEnabled=!1,this.colorTextureEnabled=!1,this.withSAO=!1,this.backfaces=!1,this.frontface=!0,this.textureUnit=0,this.drawElements=0,this.drawArrays=0,this.useProgram=0,this.bindTexture=0,this.bindArray=0,this.pass=0,this.viewParams={},this.viewParams.viewMatrix=null,this.viewParams.projMatrix=null,this.viewParams.near=.01,this.viewParams.far=5e3,this.pickInvisible=!1,this.lineWidth=1,this.snapPickLayerParams=[],this.snapPickCoordinateScale=Ae.vec3(),this.snapPickOrigin=Ae.vec3()}},{key:"getRTCViewMatrix",value:function(e,t){var n=this._rtcViewMats[e];return n||(n=this._getNewMat(),Zt(this.viewParams.viewMatrix,t,n),this._rtcViewMats[e]=n),n}},{key:"_getNewMat",value:function(){var e=this._matPool[this._matPoolNextFreeIndex];return e||(e=Ae.mat4(),this._matPool[this._matPoolNextFreeIndex]=e),this._matPoolNextFreeIndex++,e}}]),e}(),Ga={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},ja=document.createElement("canvas");if(ja){var Wa=ja.getContext("webgl",{antialias:!0})||ja.getContext("experimental-webgl",{antialias:!0});Ga.WEBGL=!!Wa,Ga.WEBGL&&(Ga.ANTIALIAS=Wa.getContextAttributes().antialias,Wa.getShaderPrecisionFormat?Wa.getShaderPrecisionFormat(Wa.FRAGMENT_SHADER,Wa.HIGH_FLOAT).precision>0?Ga.FS_MAX_FLOAT_PRECISION="highp":Wa.getShaderPrecisionFormat(Wa.FRAGMENT_SHADER,Wa.MEDIUM_FLOAT).precision>0?Ga.FS_MAX_FLOAT_PRECISION="mediump":Ga.FS_MAX_FLOAT_PRECISION="lowp":Ga.FS_MAX_FLOAT_PRECISION="mediump",Ga.DEPTH_BUFFER_BITS=Wa.getParameter(Wa.DEPTH_BITS),Ga.MAX_TEXTURE_SIZE=Wa.getParameter(Wa.MAX_TEXTURE_SIZE),Ga.MAX_CUBE_MAP_SIZE=Wa.getParameter(Wa.MAX_CUBE_MAP_TEXTURE_SIZE),Ga.MAX_RENDERBUFFER_SIZE=Wa.getParameter(Wa.MAX_RENDERBUFFER_SIZE),Ga.MAX_TEXTURE_UNITS=Wa.getParameter(Wa.MAX_COMBINED_TEXTURE_IMAGE_UNITS),Ga.MAX_TEXTURE_IMAGE_UNITS=Wa.getParameter(Wa.MAX_TEXTURE_IMAGE_UNITS),Ga.MAX_VERTEX_ATTRIBS=Wa.getParameter(Wa.MAX_VERTEX_ATTRIBS),Ga.MAX_VERTEX_UNIFORM_VECTORS=Wa.getParameter(Wa.MAX_VERTEX_UNIFORM_VECTORS),Ga.MAX_FRAGMENT_UNIFORM_VECTORS=Wa.getParameter(Wa.MAX_FRAGMENT_UNIFORM_VECTORS),Ga.MAX_VARYING_VECTORS=Wa.getParameter(Wa.MAX_VARYING_VECTORS),Wa.getSupportedExtensions().forEach((function(e){Ga.SUPPORTED_EXTENSIONS[e]=!0})))}var za=function(){function e(t){x(this,e),this.aabb=Ae.AABB3(),this.origin=Ae.vec3(t),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}return I(e,[{key:"addMarker",value:function(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}},{key:"markerWorldPosUpdated",value:function(e){if(this.markers[e.id]){var t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}}},{key:"removeMarker",value:function(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}},{key:"update",value:function(e,t){if(this.markerListDirty){for(var n in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(n)&&(this.markerList[this.numMarkers]=this.markers[n],this.markerIndices[n]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0}if(this.positionsDirty){for(var r=0,i=0;i<this.numMarkers;i++)if(this.markerList[i]){var s=this.markerList[i].rtcPos;this.positions[r++]=s[0],this.positions[r++]=s[1],this.positions[r++]=s[2],this.indices[i]=i}this.positions.length=3*this.numMarkers,this.indices.length=this.numMarkers,this.positionsDirty=!1;var o=this.aabb;Ae.collapseAABB3(o),Ae.expandAABB3Points3(o,this.positions);var a=this.origin;o[0]+=a[0],o[1]+=a[1],o[2]+=a[2],o[3]+=a[0],o[4]+=a[1],o[5]+=a[2],this.positionsBuf&&this.lenPositionsBuf!==this.positions.length&&(this.positionsBuf.destroy(),this.positionsBuf=null,this.indicesBuf.destroy(),this.indicesBuf=null);var A=new Float32Array(this.positions);this.positionsBuf?this.positionsBuf.setData(A):(this.positionsBuf=new st(e,e.ARRAY_BUFFER,A,A.length,3,e.STATIC_DRAW),this.indicesBuf=new st(e,e.ELEMENT_ARRAY_BUFFER,new Uint16Array(this.indices),this.indices.length,1,e.STATIC_DRAW),this.lenPositionsBuf=this.positions.length)}if(this.occlusionTestListDirty){var c=0;this.lenOcclusionTestList=0;for(var u=0;u<this.numMarkers;u++){var l=this.markerList[u];l.entity&&!l.entity.visible||!t(l)?l._setVisible(!1):l.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=l,this.pixels[c++]=l.canvasPos[0],this.pixels[c++]=l.canvasPos[1]):l._setVisible(!0)}}}},{key:"destroy",value:function(){this.markers={},this.markerList.length=0,this.positionsBuf&&this.positionsBuf.destroy(),this.indicesBuf&&this.indicesBuf.destroy()}}]),e}(),Xa=Ae.vec3([255,0,0]);Ae.vec3();var Ka=function(){function e(t){var n=this;x(this,e),this._scene=t,this._occlusionLayers={},this._occlusionLayersList=[],this._occlusionLayersListDirty=!1,this._drawable=null,this._markersToOcclusionLayersMap={};var r=t.camera,i=function(){n._occlusionTestListDirty=!0};this._onCameraViewMatrix=r.on("viewMatrix",i),this._onCameraProjMatrix=r.on("projMatrix",i),this._onCanvasBoundary=t.canvas.on("boundary",i)}return I(e,[{key:"_addMarker",value:function(e,t){this._occlusionLayers[t]||(this._occlusionLayers[t]=new za(e.origin),this._occlusionLayersListDirty=!0);var n=this._occlusionLayers[t];n.addMarker(e),this._markersToOcclusionLayersMap[e.id]=n}},{key:"_removeMarker",value:function(e,t){1===e.numMarkers?(e.destroy(),delete this._occlusionLayers[e.originHash],this._occlusionLayersListDirty=!0):e.removeMarker(t),delete this._markersToOcclusionLayersMap[t.id]}},{key:"addMarker",value:function(e){var t=e.origin.join();this._addMarker(e,t),this._occlusionTestListDirty=!0}},{key:"markerWorldPosUpdated",value:function(e){var t=this._markersToOcclusionLayersMap[e.id];if(t){var n=e.origin.join();n!==t.originHash?(this._removeMarker(t,e),this._addMarker(e,n)):t.markerWorldPosUpdated(e)}}},{key:"removeMarker",value:function(e){var t=e.origin.join(),n=this._occlusionLayers[t];n&&this._removeMarker(n,e)}},{key:"needOcclusionTest",get:function(){return this._occlusionTestListDirty}},{key:"drawMarkers",value:function(){var e=this,t=this._scene,n=t.canvas,r=n.gl,i=t._sectionPlanesState,s=[n.canvas.id,i.getHash()].join(";");if(!this._drawable||s!==this._drawable.shaderSourceHash){this._drawable&&this._drawable.destroy();var o=gr(),a=o.programVariables,A=a.createUniform("mat4","viewMatrix"),c=a.createUniform("mat4","projMatrix"),u=a.createAttribute("vec3","position"),l=a.createOutput("vec4","outColor"),h="clipPos",d=M(o.buildProgram(r,"OcclusionTester",{sectionPlanesState:i,getLogDepth:t.logarithmicDepthBufferEnabled&&function(e){return e},clippableTest:function(){return"true"},getVertexData:function(){var e=[];return e.push("vec4 worldPosition = vec4(".concat(u,", 1.0);")),e.push("vec4 ".concat(h," = ").concat(c," * ").concat(A," * worldPosition;")),!t.logarithmicDepthBufferEnabled&&t.markerZOffset<0&&e.push("".concat(h,".z += ").concat(t.markerZOffset,";")),e},worldPositionAttribute:"worldPosition",getPointSize:function(){return"20.0"},clipPos:h,appendFragmentOutputs:function(e){return e.push("".concat(l," = vec4(1.0, 0.0, 0.0, 1.0);"))}}),2),f=d[0],p=d[1];if(p)throw console.error(p.join("\n")),p.join("\n");this._occlusionTestListDirty=!0,this._drawable={shaderSourceHash:s,destroy:function(){return f.destroy()},drawCall:function(){var s=t.camera,o=s.project;f.bind(),c.setInputValue(o.matrix);var a=n.boundary,l=a[2],h=a[3],d=s.perspective.near,p=function(e){var t=e.viewPos,n=e.canvasPos,r=n[0],i=n[1];return t[2]<=-d&&r>=-10&&i>=-10&&r<=l+10&&i<=h+10};e._occlusionLayersList.forEach((function(e){e.update(r,p);var t=i.sectionPlanes.some((function(t,n){var r=t.active?Ae.planeAABB3Intersect(t.dir,t.dist,e.aabb):1,i=-1===r;return e.sectionPlanesActive[n]=0===r,i}));if(!t){var n=e.origin;A.setInputValue(Zt(s.viewMatrix,n)),f.inputSetters.setUniforms(null,{view:{far:o.far},mesh:{origin:n,renderFlags:{sectionPlanesActivePerLayer:e.sectionPlanesActive}}}),u.setInputValue(e.positionsBuf);var a=e.indicesBuf;a.bind(),r.drawElements(r.POINTS,a.numItems,a.itemType,0)}}))}}}if(this._occlusionLayersListDirty){var v=0;for(var g in this._occlusionLayers)this._occlusionLayers.hasOwnProperty(g)&&(this._occlusionLayersList[v++]=this._occlusionLayers[g]);this._occlusionLayersList.length=v,this._occlusionLayersListDirty=!1}if(this._occlusionTestListDirty){for(var m=0,y=this._occlusionLayersList.length;m<y;m++){this._occlusionLayersList[m].occlusionTestListDirty=!0}this._occlusionTestListDirty=!1}this._drawable.drawCall()}},{key:"doOcclusionTest",value:function(e){this._occlusionLayersList.forEach((function(t){for(var n=0;n<t.lenOcclusionTestList;n++){var r=2*n,i=e(t.pixels[r],t.pixels[r+1]);t.occlusionTestList[n]._setVisible(Ae.compareVec3(Xa,i))}}))}},{key:"destroy",value:function(){this.destroyed||(this._occlusionLayersList.forEach((function(e){return e.destroy()})),this._drawable&&this._drawable.destroy(),this._scene.camera.off(this._onCameraViewMatrix),this._scene.camera.off(this._onCameraProjMatrix),this._scene.canvas.off(this._onCanvasBoundary),this.destroyed=!0)}}]),e}(),Za=Ae.vec3([0,0,0]),Ja=Ae.vec4([1/4294967296,1/16777216,1/65536,1/256]),Ya=function(e){return e[0]+(e[1]<<8)+(e[2]<<16)+(e[3]<<24)},qa=function(e){return Ae.normalizeVec3(Ae.divVec3Scalar(e,Ae.MAX_INT,Ae.vec3()))},$a=function(e,t,n){return Ae.vec3([e[0]*n[0]+t[0],e[1]*n[1]+t[1],e[2]*n[2]+t[2]])},eA=function(e,t){var n=this;t=t||{};var r,i,s,o,a,A,c,u,l,h,d,f,p,v,g,m,y=new Na,_=e.canvas.canvas,b=e.canvas.gl,w=!!t.transparent,B=t.alphaDepthMask,C=new Z({}),k={},E={},F=[],x=[],U=[],I=!0,T=!0,P=!0,S=!0,D=!0,Q=!0,R=!0,O=!0,V=(r={},i={},{getRenderBuffer:function(t,n,s){var o=1===e.canvas.resolutionScale?r:i;return o[t]||(o[t]=new aa(b,n,s)),o[t]},destroy:function(){Object.values(r).forEach((function(e){return e.destroy()})),Object.values(i).forEach((function(e){return e.destroy()}))}}),L=function(e,t,n,r){var i=n.programVariables,s=i.createUniform("vec2","uViewportInv"),o=i.createUniform("float","uCameraNear"),a=i.createUniform("float","uCameraFar"),A=i.createUniform("sampler2D","uDepthTexture"),c=i.createAttribute("vec2","uv"),u=i.createVarying("vec2","vUV",(function(){return c})),l=i.createOutput("vec4","outColor"),h=i.createFragmentDefinition("getOutColor",(function(e,t){var n="getDepth";t.push("\n float ".concat(n,"(const in vec2 uv) {\n return texture(").concat(A,", uv).r;\n }\n ")),t.push(r(e,u,s,o,a,n))})),d=M(n.buildProgram(e,t,{clipPos:"vec4(2.0 * ".concat(c," - 1.0, 0.0, 1.0)"),appendFragmentOutputs:function(e){return e.push("".concat(l," = ").concat(h,"();"))}}),2),f=d[0],p=d[1];if(p)throw console.error(p.join("\n")),p;var v=new Float32Array([1,1,0,1,0,0,1,0]),g=new st(e,e.ARRAY_BUFFER,v,v.length,2,e.STATIC_DRAW),m=new Uint32Array([0,1,2,0,2,3]),y=new st(e,e.ELEMENT_ARRAY_BUFFER,m,m.length,1,e.STATIC_DRAW);return{destroy:f.destroy,bind:function(e,t,n){f.bind(),s.setInputValue([1/e[0],1/e[1]]),o.setInputValue(t.near),a.setInputValue(t.far),A.setInputValue(n),c.setInputValue(g)},draw:function(){y.bind(),e.drawElements(e.TRIANGLES,y.numItems,y.itemType,0)}}},H=(s=null,o=null,{destroy:function(){return s&&s.destroy()},render:function(e,t,n,r){var i=Math.floor(n.numSamples);if(o!==i){s&&s.destroy();var a=gr(),A=a.programVariables,c=A.createUniform("mat4","uProjectMatrix"),u=A.createUniform("mat4","uInvProjMatrix"),l=A.createUniform("bool","uPerspective"),h=A.createUniform("float","uScale"),d=A.createUniform("float","uIntensity"),f=A.createUniform("float","uBias"),p=A.createUniform("float","uKernelRadius"),v=A.createUniform("float","uMinResolution"),g=A.createUniform("float","uRandomSeed"),m=L(b,"SAOOcclusionRenderer",a,(function(e,t,n,r,s,o){return"\n #define EPSILON 1e-6\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define NUM_SAMPLES ".concat(i,"\n #define NUM_RINGS 4\n\n const vec3 packFactors = vec3(256. * 256. * 256., 256. * 256., 256.);\n\n vec4 packFloatToRGBA(const in float v) {\n vec4 r = vec4(fract(v * packFactors), v);\n r.yzw -= r.xyz / 256.;\n return r * 256. / 255.;\n }\n\n highp float rand(const in vec2 uv) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n return fract(sin(mod(dot(uv, vec2(a, b)), PI)) * c);\n }\n\n vec3 getViewPos(const in vec2 screenPos, const in float depth) {\n float near = ").concat(r,";\n float far = ").concat(s,";\n float viewZ = (").concat(l,"\n ? ((near * far) / ((far - near) * depth - far))\n : (depth * (near - far) - near));\n float clipW = ").concat(c,"[2][3] * viewZ + ").concat(c,"[3][3];\n return (").concat(u," * (clipW * vec4((vec3(screenPos, depth) - 0.5) * 2.0, 1.0))).xyz;\n }\n\n vec4 ").concat(e,"() {\n float centerDepth = ").concat(o,"(").concat(t,");\n if (centerDepth >= (1.0 - EPSILON)) {\n discard;\n }\n\n vec3 centerViewPosition = getViewPos(").concat(t,", centerDepth);\n float scaleDividedByCameraFar = ").concat(h," / ").concat(s,";\n float minResolutionMultipliedByCameraFar = ").concat(v," * ").concat(s,";\n vec3 centerViewNormal = normalize(cross(dFdx(centerViewPosition), dFdy(centerViewPosition)));\n\n vec2 radiusStep = ").concat(p," * ").concat(n," / float(NUM_SAMPLES);\n vec2 radius = radiusStep;\n const float angleStep = PI2 * float(NUM_RINGS) / float(NUM_SAMPLES);\n float angle = PI2 * rand(").concat(t," + ").concat(g,");\n\n float occlusionSum = 0.0;\n float weightSum = 0.0;\n\n for (int i = 0; i < NUM_SAMPLES; i++) {\n vec2 sampleUv = ").concat(t," + vec2(cos(angle), sin(angle)) * radius;\n radius += radiusStep;\n angle += angleStep;\n\n float sampleDepth = ").concat(o,"(sampleUv);\n if (sampleDepth >= (1.0 - EPSILON)) {\n continue;\n }\n\n vec3 sampleViewPosition = getViewPos(sampleUv, sampleDepth);\n vec3 viewDelta = sampleViewPosition - centerViewPosition;\n float scaledScreenDistance = scaleDividedByCameraFar * length(viewDelta);\n occlusionSum += max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - ").concat(f,") / (1.0 + scaledScreenDistance * scaledScreenDistance );\n weightSum += 1.0;\n }\n\n return packFloatToRGBA(1.0 - occlusionSum * ").concat(d," / weightSum);\n }")}));s={destroy:m.destroy,render:function(e,t,n,r){m.bind(e,t,r),c.setInputValue(t.matrix),u.setInputValue(t.inverseMatrix),l.setInputValue("Perspective"===t.type),h.setInputValue(n.scale*t.far/5),d.setInputValue(n.intensity),f.setInputValue(n.bias),p.setInputValue(n.kernelRadius),v.setInputValue(n.minResolution),g.setInputValue(Math.random()),m.draw()}},o=i}s.render(e,t,n,r)}}),N=(A=(a=function(e){for(var t=[],n=0;n<=17;n++)t.push(e[0]*n),t.push(e[1]*n);return new Float32Array(t)})([0,1]),c=a([1,0]),u=new Float32Array(function(e){for(var t=[],n=0;n<e;++n)t.push(n);return t}(17).map((function(e){return function(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}(e,4)}))),l=gr(),h=l.programVariables,d=h.createUniform("float","uDepthCutoff"),f=h.createUniformArray("vec2","uSampleOffsets",17),p=h.createUniformArray("float","uSampleWeights",17),v=h.createUniform("sampler2D","uOcclusionTex"),g=L(b,"SAODepthLimitedBlurRenderer",l,(function(e,t,n,r,i,s){return"\n #define EPSILON 1e-6\n\n const vec3 packFactors = vec3(256. * 256. * 256., 256. * 256., 256.);\n\n vec4 packFloatToRGBA(const in float v) {\n vec4 r = vec4(fract(v * packFactors), v);\n r.yzw -= r.xyz / 256.;\n return r * 256. / 255.;\n }\n\n float getOcclusion(const in vec2 uv) {\n vec4 v = texture(".concat(v,", uv);\n return dot(floor(v * 255.0 + 0.5) / 255.0, 255. / 256. / vec4(packFactors, 1.)); // unpackRGBAToFloat\n }\n\n float getViewZ(const in float depth) {\n return (").concat(r," * ").concat(i,") / ((").concat(i," - ").concat(r,") * depth - ").concat(i,");\n }\n\n vec4 ").concat(e,"() {\n float centerDepth = ").concat(s,"(").concat(t,");\n if (centerDepth >= (1.0 - EPSILON)) {\n discard;\n }\n\n float centerViewZ = getViewZ(centerDepth);\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = ").concat(p,"[0];\n float occlusionSum = getOcclusion(").concat(t,") * weightSum;\n\n for (int i = 1; i <= ").concat(16,"; i++) {\n float sampleWeight = ").concat(p,"[i];\n vec2 sampleUVOffset = ").concat(f,"[i] * ").concat(n,";\n\n if (! rBreak) {\n vec2 rSampleUV = ").concat(t," + sampleUVOffset;\n if (abs(centerViewZ - getViewZ(").concat(s,"(rSampleUV))) > ").concat(d,") {\n rBreak = true;\n } else {\n occlusionSum += getOcclusion(rSampleUV) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n if (! lBreak) {\n vec2 lSampleUV = ").concat(t," - sampleUVOffset;\n if (abs(centerViewZ - getViewZ(").concat(s,"(lSampleUV))) > ").concat(d,") {\n lBreak = true;\n } else {\n occlusionSum += getOcclusion(lSampleUV) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n }\n\n return packFloatToRGBA(occlusionSum / weightSum);\n }")})),{destroy:g.destroy,render:function(e,t,n,r,i){g.bind(e,t,r),d.setInputValue(.01),f.setInputValue(0===n?c:A),p.setInputValue(u),v.setInputValue(i),g.draw()}}),G=(m=null,function(){if(!m){var t=e.camera;m={get eye(){return t.eye},get far(){return t.project.far},get projMatrix(){return t.projMatrix},get viewMatrix(){return t.viewMatrix},get viewNormalMatrix(){return t.viewNormalMatrix}}}return m}),j=function(e,t){return"ortho"===e.projection?1:t/(2*Math.tan(.5*e.perspective.fov*Math.PI/180))};function W(){if(I&&(Object.values(k).forEach((function(e){var t=e.drawableListPreCull,n=0;Object.values(e.drawableMap).forEach((function(e){t[n++]=e})),t.length=n})),I=!1,T=!0),T){var e=0;Object.values(k).forEach((function(t){t.drawableListPreCull.forEach((function(t){F[e++]=t}))})),F.length=e,F.sort((function(e,t){return e.renderOrder-t.renderOrder})),T=!1,P=!0}if(P){var t=0,n=0;F.forEach((function(e){e.rebuildRenderFlags(),e.renderFlags.culled||(e.isUI?U[n++]=e:x[t++]=e)})),x.length=t,U.length=n}}this.scene=e,this._occlusionTester=null,this.capabilities={astcSupported:!!Jr(b,"WEBGL_compressed_texture_astc"),etc1Supported:!0,etc2Supported:!!Jr(b,"WEBGL_compressed_texture_etc"),dxtSupported:!!Jr(b,"WEBGL_compressed_texture_s3tc"),bptcSupported:!!Jr(b,"EXT_texture_compression_bptc"),pvrtcSupported:!(!Jr(b,"WEBGL_compressed_texture_pvrtc")&&!Jr(b,"WEBKIT_WEBGL_compressed_texture_pvrtc"))},this.setTransparentEnabled=function(e){S=e,P=!0},this.setEdgesEnabled=function(e){D=e,P=!0},this.setSAOEnabled=function(e){Q=e,P=!0},this.setPBREnabled=function(e){R=e,P=!0},this.setColorTextureEnabled=function(e){O=e,P=!0},this.needStateSort=function(){T=!0},this.shadowsDirty=function(){},this.imageDirty=function(){P=!0},this.addDrawable=function(e,t){var n=t.type;if(n){var r=k[n];r||(r={type:t.type,count:0,isStateSortable:t.isStateSortable,stateSortCompare:t.stateSortCompare,drawableMap:{},drawableListPreCull:[],drawableList:[]},k[n]=r),r.count++,r.drawableMap[e]=t,E[e]=t,I=!0}else console.error("Renderer#addDrawable() : drawable with ID "+e+" has no 'type' - ignoring")},this.removeDrawable=function(e){var t=E[e];if(t){var n=t.type,r=k[n];--r.count<=0?delete k[n]:delete r.drawableMap[e],delete E[e],I=!0}else console.error("Renderer#removeDrawable() : drawable not found with ID "+e+" - ignoring")},this.getPickID=function(e){return C.addItem(e)},this.putPickID=function(e){C.removeItem(e)},this.clear=function(t){if(b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),w)b.clearColor(1,1,1,1);else{var n=e.canvas.backgroundColorFromAmbientLight?this.lights.getAmbientColorAndIntensity():e.canvas.backgroundColor;b.clearColor(n[0],n[1],n[2],1)}b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT)},this.needsRender=function(){return P||I||T},this.render=function(t,n){W(),P&&(!function(t,n){var r=e.sao,i=Q&&r.possible&&r.numSamples>=1&&function(t){var n=e.sao,r=[b.drawingBufferWidth,b.drawingBufferHeight],i=V.getRenderBuffer("saoDepth",[],!0);i.setSize(r),i.bind(),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),y.reset(),y.pass=t,y.viewParams=G(),y.nearPlaneHeight=j(e.camera,b.drawingBufferHeight),b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),b.clearColor(0,0,0,0),b.enable(b.DEPTH_TEST),b.frontFace(b.CCW),b.enable(b.CULL_FACE),b.depthMask(!0),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),x.forEach((function(e){!e.culled&&e.visible&&e.drawDepth&&e.saoEnabled&&e.renderFlags.colorOpaque&&e.drawDepth(y)})),i.unbind();var s=i.depthTexture,o=V.getRenderBuffer("saoOcclusion");if(o.setSize(r),o.bind(),b.viewport(0,0,r[0],r[1]),b.clearColor(0,0,0,1),b.disable(b.DEPTH_TEST),b.disable(b.BLEND),b.frontFace(b.CCW),b.clear(b.COLOR_BUFFER_BIT),H.render(r,e.camera.project,n,s),o.unbind(),n.blur){var a=V.getRenderBuffer("saoOcclusion2");a.setSize(r);var A=function(t,n,i){n.bind(),b.viewport(0,0,r[0],r[1]),b.clearColor(0,0,0,1),b.enable(b.DEPTH_TEST),b.disable(b.BLEND),b.frontFace(b.CCW),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);var o=e.camera.project;N.render(r,o,i,s,t.colorTextures[0]),n.unbind()};A(o,a,0),A(a,o,1)}return o.colorTextures[0]}(t);e._lightsState.lights.forEach((function(t){if(t.castsShadow){var n=t.getShadowRenderBuf();n.bind(),y.reset(),y.backfaces=!0,y.frontface=!0,y.viewParams.viewMatrix=t.getShadowViewMatrix(),y.viewParams.projMatrix=t.getShadowProjMatrix(),y.nearPlaneHeight=j(e.camera,b.drawingBufferHeight),b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),b.clearColor(0,0,0,1),b.enable(b.DEPTH_TEST),b.disable(b.BLEND),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),Object.values(k).forEach((function(e){e.drawableList.forEach((function(e){!1!==e.visible&&e.castsShadow&&e.drawShadow&&e.renderFlags.colorOpaque&&e.drawShadow(y)}))})),n.unbind()}})),function(t,n,r){var i,s,o=[],a=[],A=[],c=[],u=[],l=[],h=[],d=[],f=[],p=[],v=[],g=[],m=[],_=[],C=[],k=[],M=e._lightsState.getAmbientColorAndIntensity();if(y.reset(),y.pass=t,y.withSAO=!1,y.pbrEnabled=R&&!!e.pbrEnabled,y.colorTextureEnabled=O&&!!e.colorTextureEnabled,y.viewParams=G(),y.nearPlaneHeight=j(e.camera,b.drawingBufferHeight),b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),w)b.clearColor(0,0,0,0);else{var E=e.canvas.backgroundColorFromAmbientLight?M:e.canvas.backgroundColor;b.clearColor(E[0],E[1],E[2],1)}b.enable(b.DEPTH_TEST),b.frontFace(b.CCW),b.enable(b.CULL_FACE),b.depthMask(!0),b.lineWidth(1),y.lineWidth=1,e.sao,y.saoParams=[b.drawingBufferWidth,b.drawingBufferHeight,e.sao.blendCutoff,e.sao.blendFactor],y.occlusionTexture=r;var F=Date.now();n&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);var I=function(t){for(var n=0,M=0,E=0,F=0,x=0,U=0,I=0,T=0,P=0,Q=0,R=0,O=0,V=0,L=0,H=0,N=0,G=0,j=t.length;G<j;G++)if(!0!==(s=t[G]).culled&&!1!==s.visible){var W=s.renderFlags;W.colorOpaque&&(s.saoEnabled&&r?o[n++]=s:s.drawColorOpaque(y)),S&&W.colorTransparent&&(A[E++]=s),W.xrayedSilhouetteTransparent&&(h[I++]=s),W.xrayedSilhouetteOpaque&&(u[x++]=s),W.highlightedSilhouetteTransparent&&(v[R++]=s),W.highlightedSilhouetteOpaque&&(f[P++]=s),W.selectedSilhouetteTransparent&&(C[H++]=s),W.selectedSilhouetteOpaque&&(m[V++]=s),s.edges&&D&&(W.edgesOpaque&&(a[M++]=s),W.edgesTransparent&&(c[F++]=s),W.selectedEdgesTransparent&&(k[N++]=s),W.selectedEdgesOpaque&&(_[L++]=s),W.xrayedEdgesTransparent&&(d[T++]=s),W.xrayedEdgesOpaque&&(l[U++]=s),W.highlightedEdgesTransparent&&(g[O++]=s),W.highlightedEdgesOpaque&&(p[Q++]=s))}if(n>0)for(y.withSAO=!0,i=0;i<n;i++)o[i].drawColorOpaque(y);if(M>0)for(i=0;i<M;i++)a[i].drawEdgesColorOpaque(y);if(x>0)for(i=0;i<x;i++)u[i].drawSilhouetteXRayed(y);if(U>0)for(i=0;i<U;i++)l[i].drawEdgesXRayed(y);if(I>0||T>0||E>0||F>0){if(b.enable(b.CULL_FACE),b.enable(b.BLEND),w?(b.blendEquation(b.FUNC_ADD),b.blendFuncSeparate(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA,b.ONE,b.ONE_MINUS_SRC_ALPHA)):(b.blendEquation(b.FUNC_ADD),b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA)),y.backfaces=!1,B||b.depthMask(!1),(E>0||F>0)&&b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA),F>0)for(i=0;i<F;i++)(s=c[i]).drawEdgesColorTransparent(y);if(E>0){var z=y.viewParams.eye,X=A.map((function(e){return{drawable:e,distSq:Ae.distVec3(e.origin||Za,z)}}));for(X.sort((function(e,t){return t.distSq-e.distSq})),i=0;i<E;i++)X[i].drawable.drawColorTransparent(y)}if(T>0)for(i=0;i<T;i++)d[i].drawEdgesXRayed(y);if(I>0)for(i=0;i<I;i++)h[i].drawSilhouetteXRayed(y);b.disable(b.BLEND),B||b.depthMask(!0)}if(P>0||Q>0){if(y.lastProgramId=null,e.highlightMaterial.glowThrough&&b.clear(b.DEPTH_BUFFER_BIT),Q>0)for(i=0;i<Q;i++)p[i].drawEdgesHighlighted(y);if(P>0)for(i=0;i<P;i++)f[i].drawSilhouetteHighlighted(y)}if(R>0||O>0||P>0){if(y.lastProgramId=null,e.selectedMaterial.glowThrough&&b.clear(b.DEPTH_BUFFER_BIT),b.enable(b.BLEND),w?(b.blendEquation(b.FUNC_ADD),b.blendFuncSeparate(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA,b.ONE,b.ONE_MINUS_SRC_ALPHA)):b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA),b.enable(b.CULL_FACE),O>0)for(i=0;i<O;i++)g[i].drawEdgesHighlighted(y);if(R>0)for(i=0;i<R;i++)v[i].drawSilhouetteHighlighted(y);b.disable(b.BLEND)}if(V>0||L>0){if(y.lastProgramId=null,e.selectedMaterial.glowThrough&&b.clear(b.DEPTH_BUFFER_BIT),L>0)for(i=0;i<L;i++)_[i].drawEdgesSelected(y);if(V>0)for(i=0;i<V;i++)m[i].drawSilhouetteSelected(y)}if(H>0||N>0){if(y.lastProgramId=null,e.selectedMaterial.glowThrough&&b.clear(b.DEPTH_BUFFER_BIT),b.enable(b.CULL_FACE),b.enable(b.BLEND),w?(b.blendEquation(b.FUNC_ADD),b.blendFuncSeparate(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA,b.ONE,b.ONE_MINUS_SRC_ALPHA)):b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA),N>0)for(i=0;i<N;i++)k[i].drawEdgesSelected(y);if(H>0)for(i=0;i<H;i++)C[i].drawSilhouetteSelected(y);b.disable(b.BLEND)}};I(x),U.length>0&&(b.clear(b.DEPTH_BUFFER_BIT),I(U));var T=Date.now(),P=he.frame;P.renderTime=(T-F)/1e3,P.drawElements=y.drawElements,P.drawArrays=y.drawArrays,P.useProgram=y.useProgram,P.bindTexture=y.bindTexture,P.bindArray=y.bindArray;for(var Q=Ga.MAX_TEXTURE_IMAGE_UNITS,V=0;V<Q;V++)b.activeTexture(b.TEXTURE0+V);b.bindTexture(b.TEXTURE_CUBE_MAP,null),b.bindTexture(b.TEXTURE_2D,null);for(var L=Ga.MAX_VERTEX_ATTRIBS,H=0;H<L;H++)b.disableVertexAttribArray(H)}(t,n,i)}(t,n),he.frame.frameCount++,P=!1)};var z,X,K,J,Y,q=function(t,n,r,i,s,o,a){a.reset(),a.backfaces=!0,a.frontface=!0,a.viewParams.eye=i,a.viewParams.projMatrix=s,a.viewParams.viewMatrix=o,a.nearPlaneHeight=j(r,b.drawingBufferHeight);var A=e.canvas.resolutionScale;a.pickClipPos=[t?2*t[0]*A/b.drawingBufferWidth-1:0,t?1-2*t[1]*A/b.drawingBufferHeight:0],a.pickClipPosInv=[b.drawingBufferWidth/n,b.drawingBufferHeight/n]};this.pick=function(){var t=Ae.vec3(),n=Ae.vec3(),r=Ae.vec4(),i=Ae.vec4(),s=Ae.vec4(),o=Ae.vec4(),a=Ae.vec4(),A=Ae.mat4(),c=Ae.mat4(),u=Ae.mat4(),l=Ae.mat4(),h=Ae.vec3([0,1,0]),d=new Qa,f=Ae.vec2(),p=Ae.vec3(),v=Ae.vec3(),g=Ae.vec3();Ae.vec3(),Ae.vec3();var m=new aa(b);m.setSize([1,1]);var w=new aa(b,[b.RGBA32I]);return w.setSize([3,3]),function(B){var k=arguments.length>1&&void 0!==arguments[1]?arguments[1]:d;k.reset(),W();var M=null,E=null,F=null,I=e.camera;if(k.pickSurface=B.pickSurface,B.canvasPos)p[0]=B.canvasPos[0],p[1]=B.canvasPos[1],M=I.viewMatrix,E=I.projMatrix,F=I.projection,f[0]=I.project.near,f[1]=I.project.far,k.canvasPos=B.canvasPos;else{if(B.matrix)M=B.matrix,E=I.projMatrix,F=I.projection,f[0]=I.project.near,f[1]=I.project.far;else{v.set(B.origin||[0,0,0]),g.set(B.direction||[0,0,1]);var T=Ae.addVec3(v,g,t),P=n;Math.abs(Ae.dotVec3(g,h))>.999999?(P[0]=0,P[1]=0,P[2]=Math.sign(g[1])):(Ae.cross3Vec3(g,h,P),Ae.cross3Vec3(P,g,P),Ae.normalizeVec3(P,P)),M=Ae.lookAtMat4v(v,T,P,c),E=I.ortho.matrix,F="ortho",f[0]=I.ortho.near,f[1]=I.ortho.far,k.origin=v,k.direction=g}p[0]=.5*_.clientWidth,p[1]=.5*_.clientHeight}m.bind();var S=function(e){return q(p,e,I,k.origin||I.eye,E||I.projMatrix,M||I.viewMatrix,y)};S(1),y.pickInvisible=!!B.pickInvisible,b.viewport(0,0,1,1),b.depthMask(!0),b.enable(b.DEPTH_TEST),b.disable(b.CULL_FACE),b.disable(b.BLEND),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);var D=B.includeEntityIds,Q=B.excludeEntityIds,R=function(e){e.forEach((function(e){e.culled||!e.visible||!e.pickable||!e.drawPickMesh||D&&!D[e.id]||Q&&Q[e.id]||e.drawPickMesh(y)}))};R(x),U.length>0&&(b.clear(b.DEPTH_BUFFER_BIT),R(U));var O=Ya(m.read(0,0)),V=O>=0&&C.items[O];if(!V)return m.unbind(),null;var L=V.delegatePickedEntity?V.delegatePickedEntity():V;if(!L)return m.unbind(),null;if(B.pickSurface)if(V.canPickTriangle&&V.canPickTriangle())V.drawPickTriangles&&(S(1),b.viewport(0,0,1,1),b.clearColor(0,0,0,0),b.enable(b.DEPTH_TEST),b.disable(b.CULL_FACE),b.disable(b.BLEND),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),V.drawPickTriangles(y),k.primIndex=3*Ya(m.read(0,0))),V.pickTriangleSurface(M,E,F,k),k.pickSurfacePrecision=!1;else if(V.canPickWorldPos&&V.canPickWorldPos()){S(1),y.viewParams.near=f[0],y.viewParams.far=f[1],b.viewport(0,0,1,1),b.clearColor(0,0,0,0),b.depthMask(!0),b.enable(b.DEPTH_TEST),b.disable(b.CULL_FACE),b.disable(b.BLEND),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),V.drawPickDepths(y);var H=Ae.dotVec4(m.read(0,0),Ja),N=(p[0]-_.clientWidth/2)/(_.clientWidth/2),G=-(p[1]-_.clientHeight/2)/(_.clientHeight/2),j=V.origin,z=Ae.inverseMat4(Ae.mulMat4(E,j?Zt(M,j,A):M,u),l),X=function(e,t){return t[0]=N,t[1]=G,t[2]=e,t[3]=1,Ae.transformVec4(z,t,t),Ae.mulVec4Scalar(t,1/t[3])},K=X(-1,r),Z=X(1,i),J=Ae.subVec3(Z,K,s),Y=Ae.addVec3(K,Ae.mulVec4Scalar(J,H,o),a);if(j&&Ae.addVec3(Y,j),k.worldPos=Y,!1!==B.pickSurfaceNormal){S(3),w.bind(),b.viewport(0,0,w.size[0],w.size[1]),b.enable(b.DEPTH_TEST),b.disable(b.CULL_FACE),b.disable(b.BLEND),b.clear(b.DEPTH_BUFFER_BIT),b.clearBufferiv(b.COLOR,0,new Int32Array([0,0,0,0])),V.drawPickNormals(y);var $=w.read(1,1,b.RGBA_INTEGER,b.INT,Int32Array,4);w.unbind(),k.worldNormal=qa($)}k.pickSurfacePrecision=!1}return m.unbind(),k.entity=L,k}}(),this.snapPick=(z=new Qa,X=function(){var e={};return function(t){if(!(t in e)){var n=new aa(b,[b.RGBA32I,b.RGBA32I,b.RGBA8UI],!0);n.setSize([2*t+1,2*t+1]),e[t]=n}return e[t]}}(),function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:z,r=t.canvasPos,i=t.origin,s=t.direction,o=t.snapRadius,a=t.snapToVertex,A=t.snapToEdge;if(!a&&!A)return this.pick({canvasPos:r,pickSurface:!0});var c=e.camera,u=o||30,l=r?c.viewMatrix:Ae.lookAtMat4v(i,Ae.addVec3(i,s,Ae.vec3()),Ae.vec3([0,1,0]),Ae.mat4());q(r,2*u,c,c.eye,c.projMatrix,l,y);var h=X(u);h.bind(),b.viewport(0,0,h.size[0],h.size[1]),b.enable(b.DEPTH_TEST),b.frontFace(b.CCW),b.disable(b.CULL_FACE),b.depthMask(!0),b.disable(b.BLEND),b.depthFunc(b.LEQUAL),b.clear(b.DEPTH_BUFFER_BIT),b.clearBufferiv(b.COLOR,0,new Int32Array([0,0,0,0])),b.clearBufferiv(b.COLOR,1,new Int32Array([0,0,0,0])),b.clearBufferuiv(b.COLOR,2,new Uint32Array([0,0,0,0])),b.drawBuffers([b.COLOR_ATTACHMENT0,b.COLOR_ATTACHMENT1,b.COLOR_ATTACHMENT2]),y.snapPickLayerParams=[],y.snapPickLayerParams.push(null),x.forEach((function(e){!e.culled&&e.visible&&e.pickable&&e.drawSnapInit&&e.drawSnapInit(y)}));var d=y.snapPickLayerParams;y.snapPickLayerParams=[],b.depthMask(!1),b.drawBuffers([b.COLOR_ATTACHMENT0]);var f=function(e){y.snapMode=e,y.snapPickLayerParams.push(null),x.forEach((function(e){!e.culled&&e.visible&&e.pickable&&e.drawSnap&&e.drawSnap(y)}))};A&&f("edge"),a&&f("vertex"),b.depthMask(!0);var p=y.snapPickLayerParams,v=function(e,t,n){var r=h.buffer.width,i=h.buffer.height,s=new t(4*r*i);return b.readBuffer(e),b.readPixels(0,0,r,i,b.RGBA_INTEGER,n,s,0),s},g=v(b.COLOR_ATTACHMENT0,Int32Array,b.INT),m=v(b.COLOR_ATTACHMENT1,Int32Array,b.INT),_=v(b.COLOR_ATTACHMENT2,Uint32Array,b.UNSIGNED_INT);h.unbind();var w=null,B=null,k=null,M=u,E=u,F=4*M+E*h.size[0]*4,U=g.slice(F,F+4),I=m.slice(F,F+4),T=_.slice(F,F+4);if(0!==U[3]){var P=d[Math.abs(U[3])%d.length];w=$a(U,P.origin,P.coordinateScale),B=qa(I),k=C.items[Ya(T)]}for(var S=[],D=0;D<g.length;D+=4){var Q=g[D+3];if(Q>0){var R=Math.floor(D/4),O=h.size[0],V=R%O-Math.floor(O/2),L=Math.floor(R/O)-Math.floor(O/2);S.push({dist:Ae.lenVec2([V,L]),isVertex:a&&A?Q>p.length/2:a,result:g.subarray(D,D+4),normal:m.subarray(D,D+4),id:_.subarray(D,D+4)})}}var H=function(e){return e&&e.delegatePickedEntity?e.delegatePickedEntity():e};if(S.length>0){var N=S.reduce((function(e,t){return(e.isVertex-t.isVertex||t.dist-e.dist)>0?e:t})),G=N.result,j=p[G[3]],W=$a(G,j.origin,j.coordinateScale),K=c.projectWorldPos(W);return n.reset(),n.snappedToEdge=!N.isVertex,n.snappedToVertex=N.isVertex,n.worldPos=W,n.worldNormal=qa(N.normal),n.entity=H(C.items[Ya(N.id)]),n.canvasPos=r||w&&c.projectWorldPos(w)||K,n.snappedCanvasPos=K,n}return w?(n.reset(),n.snappedToEdge=!1,n.snappedToVertex=!1,n.worldPos=w,n.worldNormal=B,n.entity=H(k),n.canvasPos=r||c.projectWorldPos(w),n.snappedCanvasPos=r,n):null}),this.addMarker=function(t){this._occlusionTester=this._occlusionTester||new Ka(e),this._occlusionTester.addMarker(t),e.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){W();var t=V.getRenderBuffer("occlusionReadPix");if(t&&(t.setSize([b.drawingBufferWidth,b.drawingBufferHeight]),t.bind()),y.reset(),y.backfaces=!0,y.frontface=!0,y.viewParams=G(),y.nearPlaneHeight=j(e.camera,b.drawingBufferHeight),b.viewport(0,0,b.drawingBufferWidth,b.drawingBufferHeight),b.clearColor(0,0,0,0),b.enable(b.DEPTH_TEST),b.disable(b.CULL_FACE),b.disable(b.BLEND),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),x.forEach((function(e){!e.culled&&e.visible&&e.pickable&&e.drawOcclusion&&e.drawOcclusion(y)})),this._occlusionTester.drawMarkers(),t){var n=e.canvas.resolutionScale;this._occlusionTester.doOcclusionTest((function(e,r){return t.read(Math.round(n*e),Math.round(n*r))})),t.unbind()}}},this.snapshot=(K=!1,J=new aa(b),Y=null,{readPixels:function(e,t,r){J.bind(),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),P=!0,n.render();for(var i=0;i<r;i++){var s=2*i,o=4*i,a=J.read(e[s],e[s+1]);t[o]=a[0],t[o+1]=a[1],t[o+2]=a[2],t[o+3]=a[3]}J.unbind(),P=!0},beginSnapshot:function(){J.setSize([b.drawingBufferWidth,b.drawingBufferHeight]),J.bind(),b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),K=!0},renderSnapshotToCanvas:function(){var e=J.buffer.width,t=J.buffer.height;return Y&&Y.width===e&&Y.height===t||(Y=function(){var n=document.createElement("canvas"),r=n.getContext("2d");n.width=e,n.height=t;var i=new Uint8Array(e*t*4),s=r.createImageData(e,t);return{width:e,height:t,getUpdatedCanvas:function(){b.readPixels(0,0,e,t,b.RGBA,b.UNSIGNED_BYTE,i);for(var o=Math.floor(t/2),a=4*e,A=new Uint8Array(a),c=0;c<o;++c){var u=c*a,l=(t-c-1)*a;A.set(i.subarray(u,u+a)),i.copyWithin(u,l,l+a),i.set(A,l)}return s.data.set(i),r.resetTransform(),r.putImageData(s,0,0),n}}}()),K&&(b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),P=!0,n.render(),P=!0),Y.getUpdatedCanvas()},endSnapshot:function(){K&&(J.unbind(),K=!1),P=!0,n.render()}}),this.destroy=function(){k={},E={},V.destroy(),H.destroy(),N.destroy(),this._occlusionTester&&this._occlusionTester.destroy()}},tA=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)).KEY_BACKSPACE=8,r.KEY_TAB=9,r.KEY_ENTER=13,r.KEY_SHIFT=16,r.KEY_CTRL=17,r.KEY_ALT=18,r.KEY_PAUSE_BREAK=19,r.KEY_CAPS_LOCK=20,r.KEY_ESCAPE=27,r.KEY_PAGE_UP=33,r.KEY_PAGE_DOWN=34,r.KEY_END=35,r.KEY_HOME=36,r.KEY_LEFT_ARROW=37,r.KEY_UP_ARROW=38,r.KEY_RIGHT_ARROW=39,r.KEY_DOWN_ARROW=40,r.KEY_INSERT=45,r.KEY_DELETE=46,r.KEY_NUM_0=48,r.KEY_NUM_1=49,r.KEY_NUM_2=50,r.KEY_NUM_3=51,r.KEY_NUM_4=52,r.KEY_NUM_5=53,r.KEY_NUM_6=54,r.KEY_NUM_7=55,r.KEY_NUM_8=56,r.KEY_NUM_9=57,r.KEY_A=65,r.KEY_B=66,r.KEY_C=67,r.KEY_D=68,r.KEY_E=69,r.KEY_F=70,r.KEY_G=71,r.KEY_H=72,r.KEY_I=73,r.KEY_J=74,r.KEY_K=75,r.KEY_L=76,r.KEY_M=77,r.KEY_N=78,r.KEY_O=79,r.KEY_P=80,r.KEY_Q=81,r.KEY_R=82,r.KEY_S=83,r.KEY_T=84,r.KEY_U=85,r.KEY_V=86,r.KEY_W=87,r.KEY_X=88,r.KEY_Y=89,r.KEY_Z=90,r.KEY_LEFT_WINDOW=91,r.KEY_RIGHT_WINDOW=92,r.KEY_SELECT_KEY=93,r.KEY_NUMPAD_0=96,r.KEY_NUMPAD_1=97,r.KEY_NUMPAD_2=98,r.KEY_NUMPAD_3=99,r.KEY_NUMPAD_4=100,r.KEY_NUMPAD_5=101,r.KEY_NUMPAD_6=102,r.KEY_NUMPAD_7=103,r.KEY_NUMPAD_8=104,r.KEY_NUMPAD_9=105,r.KEY_MULTIPLY=106,r.KEY_ADD=107,r.KEY_SUBTRACT=109,r.KEY_DECIMAL_POINT=110,r.KEY_DIVIDE=111,r.KEY_F1=112,r.KEY_F2=113,r.KEY_F3=114,r.KEY_F4=115,r.KEY_F5=116,r.KEY_F6=117,r.KEY_F7=118,r.KEY_F8=119,r.KEY_F9=120,r.KEY_F10=121,r.KEY_F11=122,r.KEY_F12=123,r.KEY_NUM_LOCK=144,r.KEY_SCROLL_LOCK=145,r.KEY_SEMI_COLON=186,r.KEY_EQUAL_SIGN=187,r.KEY_COMMA=188,r.KEY_DASH=189,r.KEY_PERIOD=190,r.KEY_FORWARD_SLASH=191,r.KEY_GRAVE_ACCENT=192,r.KEY_OPEN_BRACKET=219,r.KEY_BACK_SLASH=220,r.KEY_CLOSE_BRACKET=221,r.KEY_SINGLE_QUOTE=222,r.KEY_SPACE=32,r.MOUSE_LEFT_BUTTON=260,r.MOUSE_MIDDLE_BUTTON=261,r.MOUSE_RIGHT_BUTTON=262,r.element=i.element,r.altDown=!1,r.ctrlDown=!1,r.mouseDownLeft=!1,r.mouseDownMiddle=!1,r.mouseDownRight=!1,r.keyDown=[],r.enabled=!0,r.keyboardEnabled=!0,r.mouseover=!1,r.mouseCanvasPos=Ae.vec2(),r._keyboardEventsElement=i.keyboardEventsElement||document,r._bindEvents(),r}return I(n,[{key:"_bindEvents",value:function(){var e=this;if(!this._eventsBound){this._keyboardEventsElement.addEventListener("keydown",this._keyDownListener=function(t){e.enabled&&e.keyboardEnabled&&"INPUT"!==t.target.tagName&&"TEXTAREA"!==t.target.tagName&&(t.keyCode===e.KEY_CTRL?e.ctrlDown=!0:t.keyCode===e.KEY_ALT?e.altDown=!0:t.keyCode===e.KEY_SHIFT&&(e.shiftDown=!0),e.keyDown[t.keyCode]=!0,e.fire("keydown",t.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=function(t){e.enabled&&e.keyboardEnabled&&"INPUT"!==t.target.tagName&&"TEXTAREA"!==t.target.tagName&&(t.keyCode===e.KEY_CTRL?e.ctrlDown=!1:t.keyCode===e.KEY_ALT?e.altDown=!1:t.keyCode===e.KEY_SHIFT&&(e.shiftDown=!1),e.keyDown[t.keyCode]=!1,e.fire("keyup",t.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=function(t){e.enabled&&(e.mouseover=!0,e._getMouseCanvasPos(t),e.fire("mouseenter",e.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=function(t){e.enabled&&(e.mouseover=!1,e._getMouseCanvasPos(t),e.fire("mouseleave",e.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=function(t){if(e.enabled){switch(t.which){case 1:e.mouseDownLeft=!0;break;case 2:e.mouseDownMiddle=!0;break;case 3:e.mouseDownRight=!0}e._getMouseCanvasPos(t),e.element.focus(),e.fire("mousedown",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=function(t){if(e.enabled){switch(t.which){case 1:e.mouseDownLeft=!1;break;case 2:e.mouseDownMiddle=!1;break;case 3:e.mouseDownRight=!1}e.fire("mouseup",e.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=function(t){if(e.enabled){switch(t.which){case 1:case 3:e.mouseDownLeft=!1,e.mouseDownRight=!1;break;case 2:e.mouseDownMiddle=!1}e._getMouseCanvasPos(t),e.fire("click",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=function(t){if(e.enabled){switch(t.which){case 1:case 3:e.mouseDownLeft=!1,e.mouseDownRight=!1;break;case 2:e.mouseDownMiddle=!1}e._getMouseCanvasPos(t),e.fire("dblclick",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}});var t=this.scene.tickify((function(){return e.fire("mousemove",e.mouseCanvasPos,!0)}));this.element.addEventListener("mousemove",this._mouseMoveListener=function(n){e.enabled&&(e._getMouseCanvasPos(n),t(),e.mouseover&&n.preventDefault())}),this.element.addEventListener("contextmenu",this._contextmenuListener=function(t){e.enabled&&(e._getMouseCanvasPos(t),e.fire("contextmenu",e.mouseCanvasPos,!0))});var n=this.scene.tickify((function(t){e.fire("mousewheel",t,!0)}));this.element.addEventListener("wheel",this._mouseWheelListener=function(t,r){if(e.enabled){var i=Math.max(-1,Math.min(1,40*-t.deltaY));n(i)}},{passive:!0});var r,i;this.on("mousedown",(function(e){r=e[0],i=e[1]})),this.on("mouseup",(function(t){r>=t[0]-2&&r<=t[0]+2&&i>=t[1]-2&&i<=t[1]+2&&e.fire("mouseclicked",t,!0)})),this.element.addEventListener("touchstart",this._touchstartListener=function(t){e.enabled&&p(t.changedTouches).forEach((function(t){e.fire("touchstart",[t.identifier,e._getTouchCanvasPos(t)],!0)}))}),this.element.addEventListener("touchend",this._touchendListener=function(t){e.enabled&&p(t.changedTouches).forEach((function(t){e.fire("touchend",[t.identifier,e._getTouchCanvasPos(t)],!0)}))}),this._eventsBound=!0}}},{key:"_unbindEvents",value:function(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("contextmenu",this._contextmenuListener),this.element.removeEventListener("wheel",this._mouseWheelListener),this.element.removeEventListener("touchstart",this._touchstartListener),this.element.removeEventListener("touchend",this._touchendListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}},{key:"_getTouchCanvasPos",value:function(e){for(var t=e.target,n=0,r=0;t.offsetParent;)n+=t.offsetLeft,r+=t.offsetTop,t=t.offsetParent;return[e.pageX-n,e.pageY-r]}},{key:"_getMouseCanvasPos",value:function(e){if(e){var t=e.target.getBoundingClientRect();this.mouseCanvasPos[0]=e.clientX-t.left,this.mouseCanvasPos[1]=e.clientY-t.top}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}},{key:"setEnabled",value:function(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}},{key:"getEnabled",value:function(){return this.enabled}},{key:"setKeyboardEnabled",value:function(e){this.keyboardEnabled=e}},{key:"getKeyboardEnabled",value:function(){return this.keyboardEnabled}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._unbindEvents()}}]),n}(),nA=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({boundary:[0,0,100,100]}),r.boundary=i.boundary,r.autoBoundary=i.autoBoundary,r}return I(n,[{key:"type",get:function(){return"Viewport"}},{key:"boundary",get:function(){return this._state.boundary},set:function(e){if(!this._autoBoundary){if(!e){var t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}},{key:"autoBoundary",get:function(){return this._autoBoundary},set:function(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){var t=e[2],n=e[3];this._state.boundary=[0,0,t,n],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),rA=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)).camera=e,r._state=new it({matrix:Ae.mat4(),inverseMatrix:Ae.mat4(),transposedMatrix:Ae.mat4(),near:.1,far:1e4}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r._fov=60,r._canvasResized=r.scene.canvas.on("boundary",r._needUpdate,w(r)),r.fov=i.fov,r.fovAxis=i.fovAxis,r.near=i.near,r.far=i.far,r}return I(n,[{key:"type",get:function(){return"Perspective"}},{key:"_update",value:function(){var e=this.scene.canvas.boundary,t=e[2]/e[3],n=this._fovAxis,r=this._fov;("x"===n||"min"===n&&t<1||"max"===n&&t>1)&&(r/=t),r=Math.min(r,120),Ae.perspectiveMat4(r*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}},{key:"fov",get:function(){return this._fov},set:function(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}},{key:"fovAxis",get:function(){return this._fovAxis},set:function(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}},{key:"near",get:function(){return this._state.near},set:function(e){var t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}},{key:"far",get:function(){return this._state.far},set:function(e){var t=null!=e?e:1e4;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Ae.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Ae.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var s=this.scene.canvas.canvas,o=s.offsetWidth/2,a=s.offsetHeight/2;return n[0]=(e[0]-o)/o,n[1]=(e[1]-a)/a,n[2]=t,n[3]=1,Ae.mulMat4v4(this.inverseMatrix,n,r),Ae.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Ae.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}]),n}(),iA=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)).camera=e,r._state=new it({matrix:Ae.mat4(),inverseMatrix:Ae.mat4(),transposedMatrix:Ae.mat4(),near:.1,far:1e4}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r.scale=i.scale,r.near=i.near,r.far=i.far,r._onCanvasBoundary=r.scene.canvas.on("boundary",r._needUpdate,w(r)),r}return I(n,[{key:"type",get:function(){return"Ortho"}},{key:"_update",value:function(){var e,t,n,r,i=this.scene,s=.5*this._scale,o=i.canvas.boundary,a=o[2],A=o[3],c=a/A;a>A?(e=-s,t=s,n=s/c,r=-s/c):(e=-s*c,t=s*c,n=s,r=-s),Ae.orthoMat4c(e,t,r,n,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"scale",get:function(){return this._scale},set:function(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}},{key:"near",get:function(){return this._state.near},set:function(e){var t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}},{key:"far",get:function(){return this._state.far},set:function(e){var t=null!=e?e:1e4;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Ae.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Ae.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var s=this.scene.canvas.canvas,o=s.offsetWidth/2,a=s.offsetHeight/2;return n[0]=(e[0]-o)/o,n[1]=(e[1]-a)/a,n[2]=t,n[3]=1,Ae.mulMat4v4(this.inverseMatrix,n,r),Ae.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Ae.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}]),n}(),sA=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)).camera=e,r._state=new it({matrix:Ae.mat4(),inverseMatrix:Ae.mat4(),transposedMatrix:Ae.mat4(),near:.1,far:1e4}),r._left=-1,r._right=1,r._bottom=-1,r._top=1,r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r.left=i.left,r.right=i.right,r.bottom=i.bottom,r.top=i.top,r.near=i.near,r.far=i.far,r}return I(n,[{key:"type",get:function(){return"Frustum"}},{key:"_update",value:function(){Ae.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"left",get:function(){return this._left},set:function(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}},{key:"right",get:function(){return this._right},set:function(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}},{key:"top",get:function(){return this._top},set:function(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}},{key:"bottom",get:function(){return this._bottom},set:function(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}},{key:"near",get:function(){return this._state.near},set:function(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}},{key:"far",get:function(){return this._state.far},set:function(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Ae.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Ae.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var s=this.scene.canvas.canvas,o=s.offsetWidth/2,a=s.offsetHeight/2;return n[0]=(e[0]-o)/o,n[1]=(e[1]-a)/a,n[2]=t,n[3]=1,Ae.mulMat4v4(this.inverseMatrix,n,r),Ae.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Ae.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy(),v(C(n.prototype),"destroy",this).call(this)}}]),n}(),oA=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)).camera=e,r._state=new it({matrix:Ae.mat4(),inverseMatrix:Ae.mat4(),transposedMatrix:Ae.mat4()}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!1,r.matrix=i.matrix,r}return I(n,[{key:"type",get:function(){return"CustomProjection"}},{key:"matrix",get:function(){return this._state.matrix},set:function(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Ae.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Ae.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var s=this.scene.canvas.canvas,o=s.offsetWidth/2,a=s.offsetHeight/2;return n[0]=(e[0]-o)/o,n[1]=(e[1]-a)/a,n[2]=t,n[3]=1,Ae.mulMat4v4(this.inverseMatrix,n,r),Ae.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Ae.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),aA=Ae.vec3(),AA=Ae.vec3(),cA=Ae.vec3(),uA=Ae.vec3(),lA=Ae.vec3(),hA=Ae.vec3(),dA=Ae.vec4(),fA=Ae.vec4(),pA=Ae.vec4(),vA=Ae.mat4(),gA=Ae.mat4(),mA=Ae.vec3(),yA=Ae.vec3(),_A=Ae.vec3(),bA=Ae.vec3(),wA=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({offsetEyeFromLook:!0,deviceMatrix:Ae.mat4(),hasDeviceMatrix:!1,matrix:Ae.mat4(),normalMatrix:Ae.mat4(),inverseMatrix:Ae.mat4()}),r._perspective=new rA(w(r)),r._ortho=new iA(w(r)),r._frustum=new sA(w(r)),r._customProjection=new oA(w(r)),r._project=r._perspective,r._eye=Ae.vec3([0,0,10]),r._look=Ae.vec3([0,0,0]),r._up=Ae.vec3([0,1,0]),r._worldUp=Ae.vec3([0,1,0]),r._worldRight=Ae.vec3([1,0,0]),r._worldForward=Ae.vec3([0,0,-1]),r.deviceMatrix=i.deviceMatrix,r.eye=i.eye,r.look=i.look,r.up=i.up,r.worldAxis=i.worldAxis,r.gimbalLock=i.gimbalLock,r.constrainPitch=i.constrainPitch,r.projection=i.projection,r._perspective.on("matrix",(function(){"perspective"===r._projectionType&&r.fire("projMatrix",r._perspective.matrix)})),r._ortho.on("matrix",(function(){"ortho"===r._projectionType&&r.fire("projMatrix",r._ortho.matrix)})),r._frustum.on("matrix",(function(){"frustum"===r._projectionType&&r.fire("projMatrix",r._frustum.matrix)})),r._customProjection.on("matrix",(function(){"customProjection"===r._projectionType&&r.fire("projMatrix",r._customProjection.matrix)})),r}return I(n,[{key:"type",get:function(){return"Camera"}},{key:"_update",value:function(){var e,t=this._state;"ortho"===this.projection&&this._state.offsetEyeFromLook?(Ae.subVec3(this._eye,this._look,mA),Ae.normalizeVec3(mA,yA),Ae.mulVec3Scalar(yA,1e3,_A),Ae.addVec3(this._look,_A,bA),e=bA):e=this._eye,t.hasDeviceMatrix?(Ae.lookAtMat4v(e,this._look,this._up,gA),Ae.mulMat4(t.deviceMatrix,gA,t.matrix)):Ae.lookAtMat4v(e,this._look,this._up,t.matrix),Ae.inverseMat4(this._state.matrix,this._state.inverseMatrix),Ae.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}},{key:"orbitYaw",value:function(e){var t=Ae.subVec3(this._eye,this._look,aA);Ae.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,vA),t=Ae.transformPoint3(vA,t,AA),this.eye=Ae.addVec3(this._look,t,cA),this.up=Ae.transformPoint3(vA,this._up,uA)}},{key:"orbitPitch",value:function(e){if(!(this._constrainPitch&&(e=Ae.dotVec3(this._up,this._worldUp)/Ae.DEGTORAD)<1)){var t=Ae.subVec3(this._eye,this._look,aA),n=Ae.cross3Vec3(Ae.normalizeVec3(t,AA),Ae.normalizeVec3(this._up,cA));Ae.rotationMat4v(.0174532925*e,n,vA),t=Ae.transformPoint3(vA,t,uA),this.up=Ae.transformPoint3(vA,this._up,lA),this.eye=Ae.addVec3(t,this._look,hA)}}},{key:"yaw",value:function(e){var t=Ae.subVec3(this._look,this._eye,aA);Ae.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,vA),t=Ae.transformPoint3(vA,t,AA),this.look=Ae.addVec3(t,this._eye,cA),this._gimbalLock&&(this.up=Ae.transformPoint3(vA,this._up,uA))}},{key:"pitch",value:function(e){if(!(this._constrainPitch&&(e=Ae.dotVec3(this._up,this._worldUp)/Ae.DEGTORAD)<1)){var t=Ae.subVec3(this._look,this._eye,aA),n=Ae.cross3Vec3(Ae.normalizeVec3(t,AA),Ae.normalizeVec3(this._up,cA));Ae.rotationMat4v(.0174532925*e,n,vA),this.up=Ae.transformPoint3(vA,this._up,hA),t=Ae.transformPoint3(vA,t,uA),this.look=Ae.addVec3(t,this._eye,lA)}}},{key:"pan",value:function(e){var t,n=Ae.subVec3(this._eye,this._look,aA),r=[0,0,0];if(0!==e[0]){var i=Ae.cross3Vec3(Ae.normalizeVec3(n,[]),Ae.normalizeVec3(this._up,AA));t=Ae.mulVec3Scalar(i,e[0]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]}0!==e[1]&&(t=Ae.mulVec3Scalar(Ae.normalizeVec3(this._up,cA),e[1]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]),0!==e[2]&&(t=Ae.mulVec3Scalar(Ae.normalizeVec3(n,uA),e[2]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]),this.eye=Ae.addVec3(this._eye,r,lA),this.look=Ae.addVec3(this._look,r,hA)}},{key:"zoom",value:function(e){var t=Ae.subVec3(this._eye,this._look,aA),n=Math.abs(Ae.lenVec3(t,AA)),r=Math.abs(n+e);if(!(r<.5)){var i=Ae.normalizeVec3(t,cA);this.eye=Ae.addVec3(this._look,Ae.mulVec3Scalar(i,r),uA)}}},{key:"eye",get:function(){return this._eye},set:function(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}},{key:"look",get:function(){return this._look},set:function(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}},{key:"up",get:function(){return this._up},set:function(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}},{key:"deviceMatrix",get:function(){return this._state.deviceMatrix},set:function(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}},{key:"worldAxis",get:function(){return this._worldAxis},set:function(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=Ae.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}},{key:"worldUp",get:function(){return this._worldUp}},{key:"xUp",get:function(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}},{key:"yUp",get:function(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}},{key:"zUp",get:function(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}},{key:"worldRight",get:function(){return this._worldRight}},{key:"worldForward",get:function(){return this._worldForward}},{key:"gimbalLock",get:function(){return this._gimbalLock},set:function(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}},{key:"constrainPitch",set:function(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}},{key:"eyeLookDist",get:function(){return Ae.lenVec3(Ae.subVec3(this._look,this._eye,aA))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"viewMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"normalMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}},{key:"viewNormalMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}},{key:"inverseViewMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}},{key:"projMatrix",get:function(){return this[this.projection].matrix}},{key:"perspective",get:function(){return this._perspective}},{key:"ortho",get:function(){return this._ortho}},{key:"frustum",get:function(){return this._frustum}},{key:"customProjection",get:function(){return this._customProjection}},{key:"projection",get:function(){return this._projectionType},set:function(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}},{key:"project",get:function(){return this._project}},{key:"offsetEyeFromLook",get:function(){return this._state.offsetEyeFromLook},set:function(e){this._state.offsetEyeFromLook=e,this._needUpdate(0)}},{key:"projectWorldPos",value:function(e){var t=dA,n=fA,r=pA;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,Ae.mulMat4v4(this.viewMatrix,t,n),Ae.mulMat4v4(this.projMatrix,n,r),Ae.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1;var i=this.scene.canvas.canvas,s=i.offsetWidth/2,o=i.offsetHeight/2;return[r[0]*s+s,r[1]*o+o]}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),BA={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}},CA=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))._units="meters",r._scale=1,r._origin=Ae.vec3([0,0,0]),r.units=i.units,r.scale=i.scale,r.origin=i.origin,r}return I(n,[{key:"unitsInfo",get:function(){return BA}},{key:"units",get:function(){return this._units},set:function(e){e||(e="meters"),BA[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}},{key:"scale",get:function(){return this._scale},set:function(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}},{key:"origin",get:function(){return this._origin},set:function(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}},{key:"worldToRealPos",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.vec3(3);t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}},{key:"realToWorldPos",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ae.vec3(3);return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}]),n}(),kA=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))._supported=Ga.SUPPORTED_EXTENSIONS.OES_standard_derivatives,r.enabled=i.enabled,r.kernelRadius=i.kernelRadius,r.intensity=i.intensity,r.bias=i.bias,r.scale=i.scale,r.minResolution=i.minResolution,r.numSamples=i.numSamples,r.blur=i.blur,r.blendCutoff=i.blendCutoff,r.blendFactor=i.blendFactor,r}return I(n,[{key:"supported",get:function(){return this._supported}},{key:"enabled",get:function(){return this._enabled},set:function(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}},{key:"possible",get:function(){if(!this._supported)return!1;if(!this._enabled)return!1;var e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}},{key:"active",get:function(){return this._active}},{key:"kernelRadius",get:function(){return this._kernelRadius},set:function(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}},{key:"intensity",get:function(){return this._intensity},set:function(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}},{key:"bias",get:function(){return this._bias},set:function(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}},{key:"scale",get:function(){return this._scale},set:function(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}},{key:"minResolution",get:function(){return this._minResolution},set:function(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}},{key:"numSamples",get:function(){return this._numSamples},set:function(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}},{key:"blur",get:function(){return this._blur},set:function(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}},{key:"blendCutoff",get:function(){return this._blendCutoff},set:function(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}},{key:"blendFactor",get:function(){return this._blendFactor},set:function(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this)}}]),n}(),MA=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)).sliceColor=i.sliceColor,r.sliceThickness=i.sliceThickness,r}return I(n,[{key:"sliceThickness",get:function(){return this._sliceThickness},set:function(e){null==e&&(e=0),this._sliceThickness!==e&&(this._sliceThickness=e,this.glRedraw())}},{key:"sliceColor",get:function(){return this._sliceColor},set:function(e){null==e&&(e=[0,0,0,1]),this._sliceColor!==e&&(this._sliceColor=e,this.glRedraw())}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this)}}]),n}(),EA={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}},FA=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:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),i.preset?(r.preset=i.preset,void 0!==i.pointSize&&(r.pointSize=i.pointSize),void 0!==i.roundPoints&&(r.roundPoints=i.roundPoints),void 0!==i.perspectivePoints&&(r.perspectivePoints=i.perspectivePoints),void 0!==i.minPerspectivePointSize&&(r.minPerspectivePointSize=i.minPerspectivePointSize),void 0!==i.maxPerspectivePointSize&&(r.maxPerspectivePointSize=i.minPerspectivePointSize)):(r._preset="default",r.pointSize=i.pointSize,r.roundPoints=i.roundPoints,r.perspectivePoints=i.perspectivePoints,r.minPerspectivePointSize=i.minPerspectivePointSize,r.maxPerspectivePointSize=i.maxPerspectivePointSize),r.filterIntensity=i.filterIntensity,r.minIntensity=i.minIntensity,r.maxIntensity=i.maxIntensity,r}return I(n,[{key:"type",get:function(){return"PointsMaterial"}},{key:"presets",get:function(){return EA}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||2,this.glRedraw()}},{key:"roundPoints",get:function(){return this._state.roundPoints},set:function(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"perspectivePoints",get:function(){return this._state.perspectivePoints},set:function(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"minPerspectivePointSize",get:function(){return this._state.minPerspectivePointSize},set:function(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}},{key:"maxPerspectivePointSize",get:function(){return this._state.maxPerspectivePointSize},set:function(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}},{key:"filterIntensity",get:function(){return this._state.filterIntensity},set:function(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"minIntensity",get:function(){return this._state.minIntensity},set:function(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}},{key:"maxIntensity",get:function(){return this._state.maxIntensity},set:function(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=EA[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(EA).join(", "))}}},{key:"hash",get:function(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),xA={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}},UA=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:"LinesMaterial",lineWidth:null}),i.preset?(r.preset=i.preset,void 0!==i.lineWidth&&(r.lineWidth=i.lineWidth)):(r._preset="default",r.lineWidth=i.lineWidth),r}return I(n,[{key:"type",get:function(){return"LinesMaterial"}},{key:"presets",get:function(){return xA}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=xA[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(xA).join(", "))}}},{key:"hash",get:function(){return[""+this.lineWidth].join(";")}},{key:"destroy",value:function(){v(C(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}();function IA(e,t){var n,r,i,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2,o=t&&t.length,a=o?t[0]*s:e.length,A=TA(e,0,a,s,!0),c=[];if(!A||A.next===A.prev)return c;if(o&&(A=VA(e,t,A,s)),e.length>80*s){n=1/0,r=1/0;for(var u=-1/0,l=-1/0,h=s;h<a;h+=s){var d=e[h],f=e[h+1];d<n&&(n=d),f<r&&(r=f),d>u&&(u=d),f>l&&(l=f)}i=0!==(i=Math.max(u-n,l-r))?32767/i:0}return SA(A,c,s,n,r,i,0),c}function TA(e,t,n,r,i){var s;if(i===function(e,t,n,r){for(var i=0,s=t,o=n-r;s<n;s+=r)i+=(e[o]-e[s])*(e[s+1]+e[o+1]),o=s;return i}(e,t,n,r)>0)for(var o=t;o<n;o+=r)s=tc(o/r|0,e[o],e[o+1],s);else for(var a=n-r;a>=t;a-=r)s=tc(a/r|0,e[a],e[a+1],s);return s&&ZA(s,s.next)&&(nc(s),s=s.next),s}function PA(e,t){if(!e)return e;t||(t=e);var n,r=e;do{if(n=!1,r.steiner||!ZA(r,r.next)&&0!==KA(r.prev,r,r.next))r=r.next;else{if(nc(r),(r=t=r.prev)===r.next)break;n=!0}}while(n||r!==t);return t}function SA(e,t,n,r,i,s,o){if(e){!o&&s&&function(e,t,n,r){var i=e;do{0===i.z&&(i.z=GA(i.x,i.y,t,n,r)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next}while(i!==e);i.prevZ.nextZ=null,i.prevZ=null,function(e){var t,n=1;do{var r=e,i=void 0;e=null;var s=null;for(t=0;r;){t++;for(var o=r,a=0,A=0;A<n&&(a++,o=o.nextZ);A++);for(var c=n;a>0||c>0&&o;)0!==a&&(0===c||!o||r.z<=o.z)?(i=r,r=r.nextZ,a--):(i=o,o=o.nextZ,c--),s?s.nextZ=i:e=i,i.prevZ=s,s=i;r=o}s.nextZ=null,n*=2}while(t>1)}(i)}(e,r,i,s);for(var a=e;e.prev!==e.next;){var A=e.prev,c=e.next;if(s?QA(e,r,i,s):DA(e))t.push(A.i,e.i,c.i),nc(e),e=c.next,a=c.next;else if((e=c)===a){o?1===o?SA(e=RA(PA(e),t),t,n,r,i,s,2):2===o&&OA(e,t,n,r,i,s):SA(PA(e),t,n,r,i,s,1);break}}}}function DA(e){var t=e.prev,n=e,r=e.next;if(KA(t,n,r)>=0)return!1;for(var i=t.x,s=n.x,o=r.x,a=t.y,A=n.y,c=r.y,u=Math.min(i,s,o),l=Math.min(a,A,c),h=Math.max(i,s,o),d=Math.max(a,A,c),f=r.next;f!==t;){if(f.x>=u&&f.x<=h&&f.y>=l&&f.y<=d&&zA(i,a,s,A,o,c,f.x,f.y)&&KA(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function QA(e,t,n,r){var i=e.prev,s=e,o=e.next;if(KA(i,s,o)>=0)return!1;for(var a=i.x,A=s.x,c=o.x,u=i.y,l=s.y,h=o.y,d=Math.min(a,A,c),f=Math.min(u,l,h),p=Math.max(a,A,c),v=Math.max(u,l,h),g=GA(d,f,t,n,r),m=GA(p,v,t,n,r),y=e.prevZ,_=e.nextZ;y&&y.z>=g&&_&&_.z<=m;){if(y.x>=d&&y.x<=p&&y.y>=f&&y.y<=v&&y!==i&&y!==o&&zA(a,u,A,l,c,h,y.x,y.y)&&KA(y.prev,y,y.next)>=0)return!1;if(y=y.prevZ,_.x>=d&&_.x<=p&&_.y>=f&&_.y<=v&&_!==i&&_!==o&&zA(a,u,A,l,c,h,_.x,_.y)&&KA(_.prev,_,_.next)>=0)return!1;_=_.nextZ}for(;y&&y.z>=g;){if(y.x>=d&&y.x<=p&&y.y>=f&&y.y<=v&&y!==i&&y!==o&&zA(a,u,A,l,c,h,y.x,y.y)&&KA(y.prev,y,y.next)>=0)return!1;y=y.prevZ}for(;_&&_.z<=m;){if(_.x>=d&&_.x<=p&&_.y>=f&&_.y<=v&&_!==i&&_!==o&&zA(a,u,A,l,c,h,_.x,_.y)&&KA(_.prev,_,_.next)>=0)return!1;_=_.nextZ}return!0}function RA(e,t){var n=e;do{var r=n.prev,i=n.next.next;!ZA(r,i)&&JA(r,n,n.next,i)&&$A(r,i)&&$A(i,r)&&(t.push(r.i,n.i,i.i),nc(n),nc(n.next),n=e=i),n=n.next}while(n!==e);return PA(n)}function OA(e,t,n,r,i,s){var o=e;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&XA(o,a)){var A=ec(o,a);return o=PA(o,o.next),A=PA(A,A.next),SA(o,t,n,r,i,s,0),void SA(A,t,n,r,i,s,0)}a=a.next}o=o.next}while(o!==e)}function VA(e,t,n,r){for(var i=[],s=0,o=t.length;s<o;s++){var a=TA(e,t[s]*r,s<o-1?t[s+1]*r:e.length,r,!1);a===a.next&&(a.steiner=!0),i.push(jA(a))}i.sort(LA);for(var A=0;A<i.length;A++)n=HA(i[A],n);return n}function LA(e,t){var n=e.x-t.x;0===n&&(0===(n=e.y-t.y)&&(n=(e.next.y-e.y)/(e.next.x-e.x)-(t.next.y-t.y)/(t.next.x-t.x)));return n}function HA(e,t){var n=function(e,t){var n,r=t,i=e.x,s=e.y,o=-1/0;if(ZA(e,r))return r;do{if(ZA(e,r.next))return r.next;if(s<=r.y&&s>=r.next.y&&r.next.y!==r.y){var a=r.x+(s-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(a<=i&&a>o&&(o=a,n=r.x<r.next.x?r:r.next,a===i))return n}r=r.next}while(r!==t);if(!n)return null;var A=n,c=n.x,u=n.y,l=1/0;r=n;do{if(i>=r.x&&r.x>=c&&i!==r.x&&WA(s<u?i:o,s,c,u,s<u?o:i,s,r.x,r.y)){var h=Math.abs(s-r.y)/(i-r.x);$A(r,e)&&(h<l||h===l&&(r.x>n.x||r.x===n.x&&NA(n,r)))&&(n=r,l=h)}r=r.next}while(r!==A);return n}(e,t);if(!n)return t;var r=ec(n,e);return PA(r,r.next),PA(n,n.next)}function NA(e,t){return KA(e.prev,e,t.prev)<0&&KA(t.next,e,e.next)<0}function GA(e,t,n,r,i){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-n)*i|0)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*i|0)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function jA(e){var t=e,n=e;do{(t.x<n.x||t.x===n.x&&t.y<n.y)&&(n=t),t=t.next}while(t!==e);return n}function WA(e,t,n,r,i,s,o,a){return(i-o)*(t-a)>=(e-o)*(s-a)&&(e-o)*(r-a)>=(n-o)*(t-a)&&(n-o)*(s-a)>=(i-o)*(r-a)}function zA(e,t,n,r,i,s,o,a){return!(e===o&&t===a)&&WA(e,t,n,r,i,s,o,a)}function XA(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){var n=e;do{if(n.i!==e.i&&n.next.i!==e.i&&n.i!==t.i&&n.next.i!==t.i&&JA(n,n.next,e,t))return!0;n=n.next}while(n!==e);return!1}(e,t)&&($A(e,t)&&$A(t,e)&&function(e,t){var n=e,r=!1,i=(e.x+t.x)/2,s=(e.y+t.y)/2;do{n.y>s!=n.next.y>s&&n.next.y!==n.y&&i<(n.next.x-n.x)*(s-n.y)/(n.next.y-n.y)+n.x&&(r=!r),n=n.next}while(n!==e);return r}(e,t)&&(KA(e.prev,e,t.prev)||KA(e,t.prev,t))||ZA(e,t)&&KA(e.prev,e,e.next)>0&&KA(t.prev,t,t.next)>0)}function KA(e,t,n){return(t.y-e.y)*(n.x-t.x)-(t.x-e.x)*(n.y-t.y)}function ZA(e,t){return e.x===t.x&&e.y===t.y}function JA(e,t,n,r){var i=qA(KA(e,t,n)),s=qA(KA(e,t,r)),o=qA(KA(n,r,e)),a=qA(KA(n,r,t));return i!==s&&o!==a||(!(0!==i||!YA(e,n,t))||(!(0!==s||!YA(e,r,t))||(!(0!==o||!YA(n,e,r))||!(0!==a||!YA(n,t,r)))))}function YA(e,t,n){return t.x<=Math.max(e.x,n.x)&&t.x>=Math.min(e.x,n.x)&&t.y<=Math.max(e.y,n.y)&&t.y>=Math.min(e.y,n.y)}function qA(e){return e>0?1:e<0?-1:0}function $A(e,t){return KA(e.prev,e,e.next)<0?KA(e,t,e.next)>=0&&KA(e,e.prev,t)>=0:KA(e,t,e.prev)<0||KA(e,e.next,t)<0}function ec(e,t){var n=rc(e.i,e.x,e.y),r=rc(t.i,t.x,t.y),i=e.next,s=t.prev;return e.next=t,t.prev=e,n.next=i,i.prev=n,r.next=n,n.prev=r,s.next=r,r.prev=s,r}function tc(e,t,n,r){var i=rc(e,t,n);return r?(i.next=r.next,i.prev=r,r.next.prev=i,r.next=i):(i.prev=i,i.next=i),i}function nc(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function rc(e,t,n){return{i:e,x:t,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}var ic=[0,1,0],sc=[1,0,0],oc=Ae.vec3(),ac=Ae.vec3(),Ac=Ae.vec3(),cc=Ae.vec3(),uc=Ae.vec3();function lc(e,t){return Math.abs(e[0]-t[0])<1e-6&&Math.abs(e[1]-t[1])<1e-6&&Math.abs(e[2]-t[2])<1e-6}var hc=function(){function e(t){x(this,e),this.scene=t,this._resourcesAllocated=!1}return I(e,[{key:"_onCapMaterialUpdated",value:function(e,t){var n=this;if(!this._resourcesAllocated){this._resourcesAllocated=!0,this._sectionPlanes=[],this._sceneModelsData={},this._dirtyMap={},this._prevIntersectionModelsMap={},this._sectionPlaneTimeout=null,this._updateTimeout=null;var r=function(e){var t=function(){n._setAllDirty(!0),n._update()};n._sectionPlanes.push(e),e.on("pos",t),e.on("dir",t),e.on("active",t),e.once("destroyed",function(){var t=e.id;t&&(n._sectionPlanes=n._sectionPlanes.filter((function(e){return e.id!==t})),n._update())}.bind(n))};for(var i in this.scene.sectionPlanes)r(this.scene.sectionPlanes[i]);this._onSectionPlaneCreated=this.scene.on("sectionPlaneCreated",r),this._onTick=this.scene.on("tick",(function(){var e=!1;for(var t in n._sceneModelsData)n.scene.models[t]?n._sceneModelsData[t].visible!==!!n.scene.models[t].visible&&(n._sceneModelsData[t].visible=!!n.scene.models[t].visible,e=!0):(delete n._sceneModelsData[t],e=!0);e&&n._update()}))}this._dirtyMap[t]||(this._dirtyMap[t]=new Map),this._dirtyMap[t].set(e,!0),this._update()}},{key:"_update",value:function(){var e=this;clearTimeout(this._updateTimeout),this._deletePreviousModels(),this._updateTimeout=setTimeout((function(){clearTimeout(e._updateTimeout);var t=Object.values(e.scene.models).filter((function(e){return e.visible}));e._addHatches(t,e._sectionPlanes.filter((function(e){return e.active}))),e._setAllDirty(!1)}),100)}},{key:"_setAllDirty",value:function(e){var t=this,n=function(n){t._dirtyMap[n].forEach((function(r,i){return t._dirtyMap[n].set(i,e)}))};for(var r in this._dirty)n(r)}},{key:"_addHatches",value:function(e,t){var n=this;t.forEach((function(t){e.forEach((function(e){if(n._doesPlaneIntersectBoundingBox(e.aabb,t)&&n._dirtyMap[e.id]){var r=new Map,i=e.objects,s=[Ae.vec3(),Ae.vec3(),Ae.vec3()];n._dirtyMap[e.id].forEach((function(o,a){if(o){var A=i[a];if(n._doesPlaneIntersectBoundingBox(A.aabb,t)){if(!n._sceneModelsData[e.id]){var c=e.aabb;n._sceneModelsData[e.id]={verticesMap:new Map,indicesMap:new Map,modelOrigin:Ae.vec3([(c[0]+c[3])/2,(c[1]+c[4])/2,(c[2]+c[5])/2])}}var u=n._sceneModelsData[e.id],l=u.modelOrigin;if(!u.verticesMap.has(a)){var h=A.meshes[0].isSolid(),d=[],f=[];h&&A.capMaterial&&(A.getEachVertex((function(e){return d.push(e[0]-l[0],e[1]-l[1],e[2]-l[2])})),A.getEachIndex((function(e){return f.push(e)}))),u.verticesMap.set(a,d),u.indicesMap.set(a,f)}for(var p=u.verticesMap.get(a),v=u.indicesMap.get(a),g=-Ae.dotVec3(Ae.subVec3(t.pos,l,oc),t.dir),m=[],y=v.length,_=0;_<y;_+=3){for(var b=0;b<3;b++){var w=3*v[_+b];s[b][0]=p[w],s[b][1]=p[w+1],s[b][2]=p[w+2]}if(s[0][0]||s[0][1]||s[0][2]){for(var B=[],C=0;C<3;C++){var k=s[C],M=s[(C+1)%3],E=g+Ae.dotVec3(t.dir,k),F=g+Ae.dotVec3(t.dir,M);if(!(E*F>0)){var x=-E/(F-E);B.push(Ae.lerpVec3(x,0,1,k,M,Ae.vec3()))}}2===B.length&&m.push(B)}}m.length>0&&r.set(a,m)}}}));var o=new Map;r.forEach((function(e,t){o.set(t,[[e[0]]]),e.splice(0,1);for(var n=0;e.length>0;){for(var i=o.get(t)[n][o.get(t)[n].length-1][1],s=!1,a=0;a<e.length;a++){var A=M(e[a],2),c=A[0],u=A[1];if(lc(i,c)){o.get(t)[n].push(e[a]),e.splice(a,1),s=!0;break}if(lc(i,u)){o.get(t)[n].push([u,c]),e.splice(a,1),s=!0;break}}if(!s&&lc(i,o.get(t)[n][0][0])&&e.length>1)o.get(t).push([r.get(t)[0]]),e.splice(0,1),n++;else if(!s)break}}));var a=new Map;o.forEach((function(e,r){for(var i=[],s=function(r){i.push([]),e[r].forEach((function(e){i[r].push([n._projectTo2D(e[0],t.dir),n._projectTo2D(e[1],t.dir)])}))},o=0;o<e.length;o++)s(o);a.set(r,i)}));var A,c=new Map;a.forEach((function(r,i){var s=n._sceneModelsData[e.id].modelOrigin;A=[];for(var o=r,a=[],u=new Set,l=0;l<o.length;l++)if(!u.has(l)){var h=[o[l]];u.add(l);for(var d=l+1;d<o.length;d++)u.has(d)||(n._isLoopInside(o[l],o[d])||n._isLoopInside(o[d],o[l]))&&(h.push(o[d]),u.add(d));a.push(h)}a.forEach((function(e){var r=[],i=[],o=0,a=e.map((function(e){for(var t=0,n=0;n<e.length;n++){var r=(n+1)%e.length;t+=e[n][0][0]*e[r][0][1],t-=e[r][0][0]*e[n][0][1]}return Math.abs(t)/2})),c=a.indexOf(Math.max.apply(Math,p(a)));e[c].forEach((function(e){r.push(e[0][0],e[0][1]),o+=2}));for(var u=0;u<e.length;u++)u!==c&&(i.push(o/2),e[u].forEach((function(e){r.push(e[0][0],e[0][1]),o+=2})));for(var l=IA(r,i),h=[],d=0;d<l.length;d+=3){for(var f=[],v=0;v<3;v++){var g=2*l[d+v],m=[r[g],r[g+1]],y=n._convertTo3D(m,t,s);f.push(y)}h.push(f)}A.push(h)})),c.set(i,A)}));var u=new Map;c.forEach((function(e,t){A=[],e.forEach((function(e){var t=new Map,n=[],r=[],i=0;e.forEach((function(e){var s=[];e.forEach((function(e){var r="".concat(e[0].toFixed(6),",").concat(e[1].toFixed(6),",").concat(e[2].toFixed(6));t.has(r)?s.push(t.get(r)):(n.push(e[0],e[1],e[2]),t.set(r,i),s.push(i),i++)})),r.push.apply(r,s)})),A.push({positions:n,indices:r})})),u.set(t,A)})),n._prevIntersectionModelsMap[e.id]||(n._prevIntersectionModelsMap[e.id]=new Map),Ae.mulVec3Scalar(t.dir,.001,uc),u.forEach((function(r,i){var s,o=n._sceneModelsData[e.id].modelOrigin,a=new Array(r.size),A=0;(r.forEach((function(r,s){var c=r.positions,u=r.indices;c.length;var l=Ae.buildNormals(c,u),h=n._createUVs(c,t,o);a[A++]=new Gr(n.scene,{id:"".concat(t.id,"-").concat(i,"-").concat(s),geometry:new mt(n.scene,{primitive:"triangles",positions:c,indices:u,normals:l,uv:h}),origin:Ae.addVec3(o,uc,oc),position:[0,0,0],rotation:[0,0,0],material:e.objects[i].capMaterial})})),n._prevIntersectionModelsMap[e.id].has(i))?(s=n._prevIntersectionModelsMap[e.id].get(i)).push.apply(s,a):n._prevIntersectionModelsMap[e.id].set(i,a)}))}}))}))}},{key:"_doesPlaneIntersectBoundingBox",value:function(e,t){for(var n=[e[0],e[1],e[2]],r=[e[3],e[4],e[5]],i=!1,s=!1,o=0,a=[[n[0],n[1],n[2]],[r[0],n[1],n[2]],[n[0],r[1],n[2]],[r[0],r[1],n[2]],[n[0],n[1],r[2]],[r[0],n[1],r[2]],[n[0],r[1],r[2]],[r[0],r[1],r[2]]];o<a.length;o++){var A=a[o],c=t.dist+Ae.dotVec3(t.dir,A);if(c>0&&(i=!0),c<0&&(s=!0),i&&s)return!0}return!1}},{key:"_buildLines",value:function(e){var t=this;for(var n in e)for(var r=0;r<e[n].length;r++){var i=e[n][r];i.length<=0||i.forEach((function(e,n){new Gr(t.scene,{clippable:!1,geometry:new mt(t.scene,Rt({startPoint:e[0],endPoint:e[1]})),material:new Zr(t.scene,{emissive:[1,0,0]})})}))}}},{key:"_projectTo2D",value:function(e,t){var n;n=Math.abs(t[0])>Math.abs(t[1])?[-t[2],0,t[0]]:[0,t[2],-t[1]],n=Ae.normalizeVec3(n);var r=Ae.vec3(t),i=Ae.cross3Vec3(r,n),s=Ae.normalizeVec3(i);return[Ae.dotVec3(e,n),Ae.dotVec3(e,s)]}},{key:"_isLoopInside",value:function(e,t){for(var n=e[0][0],r=!1,i=0,s=t.length-1;i<t.length;s=i++){var o=t[i][0][0],a=t[i][0][1],A=t[s][0][0],c=t[s][0][1];a>n[1]!=c>n[1]&&n[0]<(A-o)*(n[1]-a)/(c-a)+o&&(r=!r)}return r}},{key:"_convertTo3D",value:function(e,t,n){var r,i=t.dir,s=t.pos;r=Math.abs(i[0])>Math.abs(i[1])?[-i[2],0,i[0]]:[0,i[2],-i[1]],r=Ae.normalizeVec3(r);var o=Ae.vec3(i),a=Ae.cross3Vec3(o,r),A=Ae.normalizeVec3(a),c=e[0],u=e[1],l=[r[0]*c+A[0]*u,r[1]*c+A[1]*u,r[2]*c+A[2]*u],h=Ae.dotVec3(i,[s[0]-l[0]-n[0],s[1]-l[1]-n[1],s[2]-l[2]-n[2]]);return[l[0]+i[0]*h,l[1]+i[1]*h,l[2]+i[2]*h]}},{key:"_deletePreviousModels",value:function(){var e=this,t=function(t){e._prevIntersectionModelsMap[t].forEach((function(n,r){e._dirtyMap[t].get(r)&&(n.forEach((function(e){e.destroy()})),e._prevIntersectionModelsMap[t].delete(r))})),e._prevIntersectionModelsMap[t].size<=0&&delete e._prevIntersectionModelsMap[t]};for(var n in this._prevIntersectionModelsMap)t(n)}},{key:"_createUVs",value:function(e,t,n){var r=t.pos,i=oc;i.set(t.dir),Ae.normalizeVec3(i);for(var s=ac,o=[],a=0;a<e.length;a+=3){s[0]=e[a]+n[0],s[1]=e[a+1]+n[1],s[2]=e[a+2]+n[2];var A=Ae.subVec3(s,r,Ac),c=Ae.dotVec3(A,i);Ae.subVec3(s,Ae.mulVec3Scalar(i,c,Ac),s);var u=Math.abs(Ae.dotVec3(i,ic))<.999?Ae.cross3Vec3(i,ic,Ac):sc,l=Ae.cross3Vec3(i,u,Ac);Ae.normalizeVec3(l,l);var h=Ae.subVec3(s,r,s);o.push(Ae.dotVec3(h,Ae.normalizeVec3(Ae.cross3Vec3(l,i,cc))),Ae.dotVec3(h,l))}return o}},{key:"destroy",value:function(){this._deletePreviousModels(),this._resourcesAllocated&&(this.scene.off(this._onModelLoaded),this.scene.off(this._onModelUnloaded),this.scene.off(this._onSectionPlaneCreated),this.scene.off(this._onTick))}}]),e}();function dc(e,t){for(var n,r,i={},s=0,o=t.length;s<o;s++)n=t[s],(r=e.components[n])?r.isEntity?i[n]=!0:e.warn("pick(): Component is not an Entity: "+n):e.warn("pick(): Component not found: "+n);return i}var fc=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,null,i);var s=i.canvasElement||document.querySelector("#".concat(i.canvasId));if(!(s instanceof HTMLCanvasElement))throw"Mandatory config expected: valid canvasId or canvasElement";r._tickifiedFunctions={};var o=!!i.transparent,a=!!i.alphaDepthMask;r._aabbDirty=!0,r._readableGeometry=!!i.readableGeometryEnabled,r.viewer=e,r.occlusionTestCountdown=0,r.loading=0,r.startTime=(new Date).getTime(),r.models={},r.objects={},r._numObjects=0,r.visibleObjects={},r._numVisibleObjects=0,r.xrayedObjects={},r._numXRayedObjects=0,r.highlightedObjects={},r._numHighlightedObjects=0,r.selectedObjects={},r._numSelectedObjects=0,r.colorizedObjects={},r._numColorizedObjects=0,r.opacityObjects={},r._numOpacityObjects=0,r.offsetObjects={},r._numOffsetObjects=0,r._modelIds=null,r._objectIds=null,r._visibleObjectIds=null,r._xrayedObjectIds=null,r._highlightedObjectIds=null,r._selectedObjectIds=null,r._colorizedObjectIds=null,r._opacityObjectIds=null,r._offsetObjectIds=null,r._collidables={},r._compilables={},r._needRecompile=!1,r.types={},r.components={},r.sectionPlanes={},r.lights={},r.lightMaps={},r.reflectionMaps={},r.bitmaps={},r.lineSets={},r.realWorldOffset=i.realWorldOffset||new Float64Array([0,0,0]),r.canvas=new Ha(w(r),{dontClear:!0,canvas:s,spinnerElementId:i.spinnerElementId,transparent:o,webgl2:!1!==i.webgl2,contextAttr:i.contextAttr||{},backgroundColor:i.backgroundColor,backgroundColorFromAmbientLight:i.backgroundColorFromAmbientLight,premultipliedAlpha:i.premultipliedAlpha});var A=function(e){return r.viewer.destroy()};return s.addEventListener("webglcontextlost",A,!1),r._removeWebglcontextlostListener=function(){return s.removeEventListener("webglcontextlost",A,!1)},r.canvas.on("boundary",(function(){r.glRedraw()})),r.canvas.on("webglContextFailed",(function(){alert("xeokit failed to find WebGL!")})),r._renderer=new eA(w(r),{transparent:o,alphaDepthMask:a}),r._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1,this._numCachedSectionPlanes=0;var e=null;this.getHash=function(){if(e)return e;var t=this.getNumAllocatedSectionPlanes();if(this.sectionPlanes,0===t)return this.hash=";";for(var n=[],r=0,i=t;r<i;r++)n.push("cp");return n.push(";"),e=n.join("")},this.addSectionPlane=function(t){this.sectionPlanes.push(t),e=null},this.removeSectionPlane=function(t){for(var n=0,r=this.sectionPlanes.length;n<r;n++)if(this.sectionPlanes[n].id===t.id)return this.sectionPlanes.splice(n,1),void(e=null)},this.setNumCachedSectionPlanes=function(t){this._numCachedSectionPlanes=t,e=null},this.getNumCachedSectionPlanes=function(){return this._numCachedSectionPlanes},this.getNumAllocatedSectionPlanes=function(){var e=this.sectionPlanes.length;return e>this._numCachedSectionPlanes?e:this._numCachedSectionPlanes}},r._sectionPlanesState.setNumCachedSectionPlanes(i.numCachedSectionPlanes||0),r._lightsState=new function(){var e=Ae.vec4([0,0,0,0]),t=Ae.vec4();this.lights=[],this.reflectionMaps=[],this.lightMaps=[];var n=null,r=null;this.getHash=function(){if(n)return n;for(var e,t=[],r=this.lights,i=0,s=r.length;i<s;i++)e=r[i],t.push("/"),t.push(e.type),t.push("world"===e.space?"w":"v"),e.castsShadow&&t.push("sh");return this.lightMaps.length>0&&t.push("/lm"),this.reflectionMaps.length>0&&t.push("/rm"),t.push(";"),n=t.join("")},this.addLight=function(e){this.lights.push(e),r=null,n=null},this.removeLight=function(e){for(var t=0,i=this.lights.length;t<i;t++){if(this.lights[t].id===e.id)return this.lights.splice(t,1),r&&r.id===e.id&&(r=null),void(n=null)}},this.addReflectionMap=function(e){this.reflectionMaps.push(e),n=null},this.removeReflectionMap=function(e){for(var t=0,r=this.reflectionMaps.length;t<r;t++)if(this.reflectionMaps[t].id===e.id)return this.reflectionMaps.splice(t,1),void(n=null)},this.addLightMap=function(e){this.lightMaps.push(e),n=null},this.removeLightMap=function(e){for(var t=0,r=this.lightMaps.length;t<r;t++)if(this.lightMaps[t].id===e.id)return this.lightMaps.splice(t,1),void(n=null)},this.getAmbientColorAndIntensity=function(){if(!r)for(var n=0,i=this.lights.length;n<i;n++){var s=this.lights[n];if("ambient"===s.type){r=s;break}}if(r){var o=r.color,a=r.intensity;return t[0]=o[0],t[1]=o[1],t[2]=o[2],t[3]=a,t}return e}},r.input=new tA(w(r),{dontClear:!0,element:r.canvas.canvas,keyboardEventsElement:i.keyboardEventsElement}),r.metrics=new CA(w(r),{units:i.units,scale:i.scale,origin:i.origin}),r.sao=new kA(w(r),{enabled:i.saoEnabled}),r.crossSections=new MA(w(r),{}),r.ticksPerRender=i.ticksPerRender,r.ticksPerOcclusionTest=i.ticksPerOcclusionTest,r.passes=i.passes,r.clearEachPass=i.clearEachPass,r.gammaInput=i.gammaInput,r.gammaOutput=i.gammaOutput,r.gammaFactor=i.gammaFactor,r._entityOffsetsEnabled=!!i.entityOffsetsEnabled,r._logarithmicDepthBufferEnabled=!!i.logarithmicDepthBufferEnabled,r._dtxEnabled=!1!==i.dtxEnabled,r._pbrEnabled=!!i.pbrEnabled,r._colorTextureEnabled=!1!==i.colorTextureEnabled,r._dtxEnabled=!!i.dtxEnabled,r._markerZOffset=i.markerZOffset,Fe._addScene(w(r)),r._initDefaults(),r._viewport=new nA(w(r),{id:"default.viewport",autoBoundary:!0,dontClear:!0}),r._camera=new wA(w(r),{id:"default.camera",dontClear:!0}),r._sectionCaps=new hc(w(r)),new oa(w(r),{color:[1,1,1],intensity:.7}),new Aa(w(r),{dir:[.8,-.5,-.5],color:[.67,.67,1],intensity:.7,space:"world"}),new Aa(w(r),{dir:[-.8,-1,.5],color:[1,1,.9],intensity:.9,space:"world"}),r._camera.on("dirty",(function(){r._renderer.imageDirty()})),r}return I(n,[{key:"type",get:function(){return"Scene"}},{key:"_initDefaults",value:function(){}},{key:"_addComponent",value:function(e){if(e.id&&this.components[e.id]&&(this.error("Component "+ge.inQuotes(e.id)+" already exists in Scene - ignoring ID, will randomly-generate instead"),e.id=null),!e.id)for(void 0===window.nextID&&(window.nextID=0),e.id="__"+window.nextID++;this.components[e.id];)e.id=Ae.createUUID();this.components[e.id]=e;var t=e.type,n=this.types[e.type];n||(n=this.types[t]={}),n[e.id]=e,e.compile&&(this._compilables[e.id]=e),e.isDrawable&&(this._renderer.addDrawable(e.id,e),this._collidables[e.id]=e)}},{key:"_removeComponent",value:function(e){var t=e.id,n=e.type;delete this.components[t];var r=this.types[n];r&&(delete r[t],ge.isEmptyObject(r)&&delete this.types[n]),e.compile&&delete this._compilables[e.id],e.isDrawable&&(this._renderer.removeDrawable(e.id),delete this._collidables[e.id])}},{key:"_capMaterialUpdated",value:function(e,t){this._sectionCaps._onCapMaterialUpdated(e,t)}},{key:"_sectionPlaneCreated",value:function(e){this.sectionPlanes[e.id]=e,this.scene._sectionPlanesState.addSectionPlane(e._state),this.scene.fire("sectionPlaneCreated",e,!0),this._needRecompile=!0}},{key:"_bitmapCreated",value:function(e){this.bitmaps[e.id]=e,this.scene.fire("bitmapCreated",e,!0)}},{key:"_lineSetCreated",value:function(e){this.lineSets[e.id]=e,this.scene.fire("lineSetCreated",e,!0)}},{key:"_lightCreated",value:function(e){this.lights[e.id]=e,this.scene._lightsState.addLight(e._state),this._needRecompile=!0}},{key:"_lightMapCreated",value:function(e){this.lightMaps[e.id]=e,this.scene._lightsState.addLightMap(e._state),this._needRecompile=!0}},{key:"_reflectionMapCreated",value:function(e){this.reflectionMaps[e.id]=e,this.scene._lightsState.addReflectionMap(e._state),this._needRecompile=!0}},{key:"_sectionPlaneDestroyed",value:function(e){delete this.sectionPlanes[e.id],this.scene._sectionPlanesState.removeSectionPlane(e._state),this.scene.fire("sectionPlaneDestroyed",e,!0),this._needRecompile=!0}},{key:"_bitmapDestroyed",value:function(e){delete this.bitmaps[e.id],this.scene.fire("bitmapDestroyed",e,!0)}},{key:"_lineSetDestroyed",value:function(e){delete this.lineSets[e.id],this.scene.fire("lineSetDestroyed",e,!0)}},{key:"_lightDestroyed",value:function(e){delete this.lights[e.id],this.scene._lightsState.removeLight(e._state),this._needRecompile=!0}},{key:"_lightMapDestroyed",value:function(e){delete this.lightMaps[e.id],this.scene._lightsState.removeLightMap(e._state),this._needRecompile=!0}},{key:"_reflectionMapDestroyed",value:function(e){delete this.reflectionMaps[e.id],this.scene._lightsState.removeReflectionMap(e._state),this._needRecompile=!0}},{key:"_registerModel",value:function(e){this.models[e.id]=e,this._modelIds=null}},{key:"_deregisterModel",value:function(e){var t=e.id;delete this.models[t],this._modelIds=null,this.fire("modelUnloaded",t)}},{key:"_registerObject",value:function(e){this.objects[e.id]=e,this._numObjects++,this._objectIds=null}},{key:"_deregisterObject",value:function(e){delete this.objects[e.id],this._numObjects--,this._objectIds=null}},{key:"_objectVisibilityUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}},{key:"_deRegisterVisibleObject",value:function(e){delete this.visibleObjects[e.id],this._numVisibleObjects--,this._visibleObjectIds=null}},{key:"_objectXRayedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}},{key:"_deRegisterXRayedObject",value:function(e){delete this.xrayedObjects[e.id],this._numXRayedObjects--,this._xrayedObjectIds=null}},{key:"_objectHighlightedUpdated",value:function(e){e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null}},{key:"_deRegisterHighlightedObject",value:function(e){delete this.highlightedObjects[e.id],this._numHighlightedObjects--,this._highlightedObjectIds=null}},{key:"_objectSelectedUpdated",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}},{key:"_deRegisterSelectedObject",value:function(e){delete this.selectedObjects[e.id],this._numSelectedObjects--,this._selectedObjectIds=null}},{key:"_objectColorizeUpdated",value:function(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}},{key:"_deRegisterColorizedObject",value:function(e){delete this.colorizedObjects[e.id],this._numColorizedObjects--,this._colorizedObjectIds=null}},{key:"_objectOpacityUpdated",value:function(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}},{key:"_deRegisterOpacityObject",value:function(e){delete this.opacityObjects[e.id],this._numOpacityObjects--,this._opacityObjectIds=null}},{key:"_objectOffsetUpdated",value:function(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}},{key:"_deRegisterOffsetObject",value:function(e){delete this.offsetObjects[e.id],this._numOffsetObjects--,this._offsetObjectIds=null}},{key:"capabilities",get:function(){return this._renderer.capabilities}},{key:"entityOffsetsEnabled",get:function(){return this._entityOffsetsEnabled}},{key:"readableGeometryEnabled",get:function(){return this._readableGeometry}},{key:"pickSurfacePrecisionEnabled",get:function(){return this._readableGeometry}},{key:"logarithmicDepthBufferEnabled",get:function(){return this._logarithmicDepthBufferEnabled}},{key:"numCachedSectionPlanes",get:function(){return this._sectionPlanesState.getNumCachedSectionPlanes()},set:function(e){e=e||0,this._sectionPlanesState.getNumCachedSectionPlanes()!==e&&(this._sectionPlanesState.setNumCachedSectionPlanes(e),this._needRecompile=!0,this.glRedraw())}},{key:"pbrEnabled",get:function(){return this._pbrEnabled},set:function(e){this._pbrEnabled=!!e,this.glRedraw()}},{key:"dtxEnabled",get:function(){return this._dtxEnabled},set:function(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}},{key:"colorTextureEnabled",get:function(){return this._colorTextureEnabled},set:function(e){this._colorTextureEnabled=!!e,this.glRedraw()}},{key:"markerZOffset",get:function(){return null==this._markerZOffset?-.001:this._markerZOffset}},{key:"doOcclusionTest",value:function(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}},{key:"render",value:function(e){e&&Fe.runTasks();var t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),e||this._renderer.needsRender()){t.sceneId=this.id;for(var n=0;n<this._passes;n++)t.pass=n,this.fire("rendering",t,!0),e&&this._renderer.imageDirty(),this._renderer.render(n,this._clearEachPass||0===n),this.fire("rendered",t,!0);this._saveAmbientColor()}}},{key:"compile",value:function(){this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1)}},{key:"_recompile",value:function(){for(var e in this._compilables)this._compilables.hasOwnProperty(e)&&this._compilables[e].compile();this._renderer.shadowsDirty(),this.fire("compile",this,!0)}},{key:"_saveAmbientColor",value:function(){var e=this.canvas;if(e.transparent||e.backgroundImage||e.backgroundColor)this._lastAmbientColor=null;else{var t=this._lightsState.getAmbientColorAndIntensity();this._lastAmbientColor&&this._lastAmbientColor[0]===t[0]&&this._lastAmbientColor[1]===t[1]&&this._lastAmbientColor[2]===t[2]&&this._lastAmbientColor[3]===t[3]||(e.backgroundColor=t,this._lastAmbientColor||(this._lastAmbientColor=Ae.vec4([0,0,0,1])),this._lastAmbientColor.set(t))}}},{key:"modelIds",get:function(){return this._modelIds||(this._modelIds=Object.keys(this.models)),this._modelIds}},{key:"numObjects",get:function(){return this._numObjects}},{key:"objectIds",get:function(){return this._objectIds||(this._objectIds=Object.keys(this.objects)),this._objectIds}},{key:"numVisibleObjects",get:function(){return this._numVisibleObjects}},{key:"visibleObjectIds",get:function(){return this._visibleObjectIds||(this._visibleObjectIds=Object.keys(this.visibleObjects)),this._visibleObjectIds}},{key:"numXRayedObjects",get:function(){return this._numXRayedObjects}},{key:"xrayedObjectIds",get:function(){return this._xrayedObjectIds||(this._xrayedObjectIds=Object.keys(this.xrayedObjects)),this._xrayedObjectIds}},{key:"numHighlightedObjects",get:function(){return this._numHighlightedObjects}},{key:"highlightedObjectIds",get:function(){return this._highlightedObjectIds||(this._highlightedObjectIds=Object.keys(this.highlightedObjects)),this._highlightedObjectIds}},{key:"numSelectedObjects",get:function(){return this._numSelectedObjects}},{key:"selectedObjectIds",get:function(){return this._selectedObjectIds||(this._selectedObjectIds=Object.keys(this.selectedObjects)),this._selectedObjectIds}},{key:"numColorizedObjects",get:function(){return this._numColorizedObjects}},{key:"colorizedObjectIds",get:function(){return this._colorizedObjectIds||(this._colorizedObjectIds=Object.keys(this.colorizedObjects)),this._colorizedObjectIds}},{key:"opacityObjectIds",get:function(){return this._opacityObjectIds||(this._opacityObjectIds=Object.keys(this.opacityObjects)),this._opacityObjectIds}},{key:"offsetObjectIds",get:function(){return this._offsetObjectIds||(this._offsetObjectIds=Object.keys(this.offsetObjects)),this._offsetObjectIds}},{key:"ticksPerRender",get:function(){return this._ticksPerRender},set:function(e){null==e?e=1:(!ge.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'ticksPerRender': '"+e+"' - should be an integer greater than zero."),e=1),e!==this._ticksPerRender&&(this._ticksPerRender=e)}},{key:"ticksPerOcclusionTest",get:function(){return this._ticksPerOcclusionTest},set:function(e){null==e?e=20:(!ge.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'ticksPerOcclusionTest': '"+e+"' - should be an integer greater than zero."),e=20),e!==this._ticksPerOcclusionTest&&(this._ticksPerOcclusionTest=e)}},{key:"passes",get:function(){return this._passes},set:function(e){null==e?e=1:(!ge.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'passes': '"+e+"' - should be an integer greater than zero."),e=1),e!==this._passes&&(this._passes=e,this.glRedraw())}},{key:"clearEachPass",get:function(){return this._clearEachPass},set:function(e){(e=!!e)!==this._clearEachPass&&(this._clearEachPass=e,this.glRedraw())}},{key:"gammaInput",get:function(){return this._renderer.gammaInput},set:function(e){(e=!1!==e)!==this._renderer.gammaInput&&(this._renderer.gammaInput=e,this._needRecompile=!0,this.glRedraw())}},{key:"gammaOutput",get:function(){return this._renderer.gammaOutput},set:function(e){(e=!!e)!==this._renderer.gammaOutput&&(this._renderer.gammaOutput=e,this._needRecompile=!0,this.glRedraw())}},{key:"gammaFactor",get:function(){return this._renderer.gammaFactor},set:function(e){(e=null==e?2.2:e)!==this._renderer.gammaFactor&&(this._renderer.gammaFactor=e,this.glRedraw())}},{key:"geometry",get:function(){return this.components["default.geometry"]||kt(mt)}},{key:"material",get:function(){return this.components["default.material"]||new Zr(this,{id:"default.material",emissive:[.4,.4,.4],dontClear:!0})}},{key:"xrayMaterial",get:function(){return this.components["default.xrayMaterial"]||new _i(this,{id:"default.xrayMaterial",fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1,dontClear:!0})}},{key:"highlightMaterial",get:function(){return this.components["default.highlightMaterial"]||new _i(this,{id:"default.highlightMaterial",fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1,dontClear:!0})}},{key:"selectedMaterial",get:function(){return this.components["default.selectedMaterial"]||new _i(this,{id:"default.selectedMaterial",fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1,dontClear:!0})}},{key:"edgeMaterial",get:function(){return this.components["default.edgeMaterial"]||new wi(this,{id:"default.edgeMaterial",fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1,dontClear:!0})}},{key:"pointsMaterial",get:function(){return this.components["default.pointsMaterial"]||new FA(this,{id:"default.pointsMaterial",fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1,dontClear:!0})}},{key:"linesMaterial",get:function(){return this.components["default.linesMaterial"]||new UA(this,{id:"default.linesMaterial",fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1,dontClear:!0})}},{key:"viewport",get:function(){return this._viewport}},{key:"camera",get:function(){return this._camera}},{key:"center",get:function(){if(this._aabbDirty||!this._center){var e=this.aabb;this._center||(this._center=Ae.vec3()),this._center[0]=(e[0]+e[3])/2,this._center[1]=(e[1]+e[4])/2,this._center[2]=(e[2]+e[5])/2}return this._center}},{key:"aabb",get:function(){if(this._aabbDirty){this._aabb||(this._aabb=Ae.AABB3());var e,t,n=Ae.MAX_DOUBLE,r=Ae.MAX_DOUBLE,i=Ae.MAX_DOUBLE,s=Ae.MIN_DOUBLE,o=Ae.MIN_DOUBLE,a=Ae.MIN_DOUBLE,A=this._collidables,c=!1;for(var u in A)if(A.hasOwnProperty(u)){if(!1===(t=A[u]).collidable)continue;(e=t.aabb)[0]<n&&(n=e[0]),e[1]<r&&(r=e[1]),e[2]<i&&(i=e[2]),e[3]>s&&(s=e[3]),e[4]>o&&(o=e[4]),e[5]>a&&(a=e[5]),c=!0}c||(n=-100,r=-100,i=-100,s=100,o=100,a=100),this._aabb[0]=n,this._aabb[1]=r,this._aabb[2]=i,this._aabb[3]=s,this._aabb[4]=o,this._aabb[5]=a,this._aabbDirty=!1,this._center=null}return this._aabb}},{key:"_setAABBDirty",value:function(){this._aabbDirty=!0,this.fire("boundary")}},{key:"pick",value:function(e,t){if(!this.canvas)return this.error("Picking not allowed on a destroyed Scene"),null;if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");var n=e.includeEntities||e.include;n&&(e.includeEntityIds=dc(this,n));var r=e.excludeEntities||e.exclude;return r&&(e.excludeEntityIds=dc(this,r)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=e.snapToEdge||e.snapToVertex?this._renderer.snapPick(e,t):this._renderer.pick(e,t))&&t.entity&&t.entity.fire&&t.entity.fire("picked",t),t}},{key:"snapPick",value:function(e){return this.canvas?(void 0===this._warnSnapPickDeprecated&&(this._warnSnapPickDeprecated=!0,this.warn("Scene.snapPick() is deprecated since v2.4.2 - use Scene.pick() instead")),e.canvasPos?this._renderer.snapPick(e):void this.error("Scene.snapPick() canvasPos parameter expected")):(this.error("Picking not allowed on a destroyed Scene"),null)}},{key:"clear",value:function(){var e;for(var t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}},{key:"clearLights",value:function(){for(var e=Object.keys(this.lights),t=0,n=e.length;t<n;t++)this.lights[e[t]].destroy()}},{key:"clearSectionPlanes",value:function(){for(var e=Object.keys(this.sectionPlanes),t=0,n=e.length;t<n;t++)this.sectionPlanes[e[t]].destroy()}},{key:"clearBitmaps",value:function(){for(var e=Object.keys(this.bitmaps),t=0,n=e.length;t<n;t++)this.bitmaps[e[t]].destroy()}},{key:"clearLines",value:function(){for(var e=Object.keys(this.lineSets),t=0,n=e.length;t<n;t++)this.lineSets[e[t]].destroy()}},{key:"getAABB",value:function(e){if(void 0===e)return this.aabb;if(ge.isString(e)){var t=this.objects[e];if(t&&t.aabb)return t.aabb;e=[e]}if(0===e.length)return this.aabb;var n,r=Ae.MAX_DOUBLE,i=Ae.MAX_DOUBLE,s=Ae.MAX_DOUBLE,o=Ae.MIN_DOUBLE,a=Ae.MIN_DOUBLE,A=Ae.MIN_DOUBLE;if(this.withObjects(e,(function(e){if(e.collidable){var t=e.aabb;t[0]<r&&(r=t[0]),t[1]<i&&(i=t[1]),t[2]<s&&(s=t[2]),t[3]>o&&(o=t[3]),t[4]>a&&(a=t[4]),t[5]>A&&(A=t[5]),n=!0}})),n){var c=Ae.AABB3();return c[0]=r,c[1]=i,c[2]=s,c[3]=o,c[4]=a,c[5]=A,c}return this.aabb}},{key:"setObjectsVisible",value:function(e,t){return this.withObjects(e,(function(e){var n=e.visible!==t;return e.visible=t,n}))}},{key:"setObjectsCollidable",value:function(e,t){return this.withObjects(e,(function(e){var n=e.collidable!==t;return e.collidable=t,n}))}},{key:"setObjectsCulled",value:function(e,t){return this.withObjects(e,(function(e){var n=e.culled!==t;return e.culled=t,n}))}},{key:"setObjectsSelected",value:function(e,t){return this.withObjects(e,(function(e){var n=e.selected!==t;return e.selected=t,n}))}},{key:"setObjectsHighlighted",value:function(e,t){return this.withObjects(e,(function(e){var n=e.highlighted!==t;return e.highlighted=t,n}))}},{key:"setObjectsXRayed",value:function(e,t){return this.withObjects(e,(function(e){var n=e.xrayed!==t;return e.xrayed=t,n}))}},{key:"setObjectsEdges",value:function(e,t){return this.withObjects(e,(function(e){var n=e.edges!==t;return e.edges=t,n}))}},{key:"setObjectsColorized",value:function(e,t){return this.withObjects(e,(function(e){e.colorize=t}))}},{key:"setObjectsOpacity",value:function(e,t){return this.withObjects(e,(function(e){var n=e.opacity!==t;return e.opacity=t,n}))}},{key:"setObjectsPickable",value:function(e,t){return this.withObjects(e,(function(e){var n=e.pickable!==t;return e.pickable=t,n}))}},{key:"setObjectsOffset",value:function(e,t){this.withObjects(e,(function(e){e.offset=t}))}},{key:"withObjects",value:function(e,t){ge.isString(e)&&(e=[e]);for(var n=!1,r=0,i=e.length;r<i;r++){var s=e[r],o=this.objects[s];if(o)n=t(o)||n;else for(var a=this.modelIds,A=0,c=a.length;A<c;A++){var u=a[A],l=Ae.globalizeObjectId(u,s);(o=this.objects[l])&&(n=t(o)||n)}}return n}},{key:"tickify",value:function(e){var t=e.toString();if(t in this._tickifiedFunctions)return this._tickifiedFunctions[t].wrapperFunc;var n,r=0,i=0,s=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];n=t,i++},o=this.on("tick",(function(){i>r&&(r=i,e.apply(void 0,p(n)))}));return this._tickifiedFunctions[t]={tickSubId:o,wrapperFunc:s},s}},{key:"destroy",value:function(){for(var e in v(C(n.prototype),"destroy",this).call(this),this._removeWebglcontextlostListener(),this.components)this.components.hasOwnProperty(e)&&this.components[e].destroy();this._sectionCaps.destroy(),this.canvas.gl=null,this.components=null,this.models=null,this.objects=null,this.visibleObjects=null,this.xrayedObjects=null,this.highlightedObjects=null,this.selectedObjects=null,this.colorizedObjects=null,this.opacityObjects=null,this.sectionPlanes=null,this.lights=null,this.lightMaps=null,this.reflectionMaps=null,this._objectIds=null,this._visibleObjectIds=null,this._xrayedObjectIds=null,this._highlightedObjectIds=null,this._selectedObjectIds=null,this._colorizedObjectIds=null,this._sectionCaps=null,this.types=null,this.components=null,this.canvas=null,this._renderer=null,this.input=null,this._viewport=null,this._camera=null}}]),n}(),pc=Ae.vec4(),vc=Ae.vec4(),gc=Ae.vec3(),mc=Ae.vec3(),yc=Ae.vec3(),_c=Ae.vec4(),bc=Ae.vec4(),wc=Ae.vec4(),Bc=function(){function e(t){x(this,e),this._scene=t}return I(e,[{key:"dollyToCanvasPos",value:function(e,t,n){var r=!1,i=this._scene.camera;if(e){var s=Ae.subVec3(e,i.eye,gc);r=Ae.lenVec3(s)<n}if("perspective"===i.projection){i.ortho.scale=i.ortho.scale-n;var o=this._unproject(t,_c),a=Ae.subVec3(o,i.eye,wc),A=Ae.mulVec3Scalar(Ae.normalizeVec3(a),-n,[]);if(i.eye=[i.eye[0]-A[0],i.eye[1]-A[1],i.eye[2]-A[2]],i.look=[i.look[0]-A[0],i.look[1]-A[1],i.look[2]-A[2]],e){var c=Ae.subVec3(e,i.eye,gc),u=Ae.lenVec3(c),l=Ae.mulVec3Scalar(Ae.normalizeVec3(Ae.subVec3(i.look,i.eye,mc)),u);i.look=[i.eye[0]+l[0],i.eye[1]+l[1],i.eye[2]+l[2]]}}else if("ortho"===i.projection){var h=this._unproject(t,_c);i.ortho.scale=i.ortho.scale-n,i.ortho._update();var d=this._unproject(t,bc),f=Ae.subVec3(d,h,wc),p=Ae.mulVec3Scalar(Ae.normalizeVec3(Ae.subVec3(i.look,i.eye,gc)),-n,mc),v=Ae.addVec3(f,p,yc);i.eye=[i.eye[0]-v[0],i.eye[1]-v[1],i.eye[2]-v[2]],i.look=[i.look[0]-v[0],i.look[1]-v[1],i.look[2]-v[2]]}return r}},{key:"_unproject",value:function(e,t){var n=this._scene.camera,r=n.project.transposedMatrix,i=r.subarray(8,12),s=r.subarray(12),o=[0,0,-1,1],a=Ae.dotVec4(o,i)/Ae.dotVec4(o,s);return n.project.unproject(e,a,pc,vc,t),t}},{key:"destroy",value:function(){}}]),e}(),Cc=Ae.vec3(),kc=Ae.vec3(),Mc=Ae.vec3(),Ec=Ae.vec4(),Fc=Ae.vec4(),xc=Ae.vec4(),Uc=Math.PI-.001,Ic=function(){function e(t,n){var r=this;x(this,e),this._scene=t,this._configs=n,this._pivotWorldPos=Ae.vec3(),this._cameraOffset=Ae.vec3(),this._azimuth=0,this._polar=0,this._radius=0,this._pivotPosSet=!1,this._pivoting=!1,this._shown=!1,this._pivotSphereEnabled=!1,this._pivotSphere=null,this._pivotSphereSize=1,this._pivotSphereGeometry=null,this._pivotSphereMaterial=null,this._rtcCenter=Ae.vec3(),this._rtcPos=Ae.vec3(),this._pivotViewPos=Ae.vec4(),this._pivotProjPos=Ae.vec4(),this._pivotCanvasPos=Ae.vec2(),this._cameraDirty=!0,this._onViewMatrix=this._scene.camera.on("viewMatrix",(function(){r._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(function(){r._cameraDirty=!0})),this._onTick=this._scene.on("tick",(function(){r.updatePivotElement(),r.updatePivotSphere()}))}return I(e,[{key:"createPivotSphere",value:function(){var e=this.getPivotPos(),t=Ae.vec3();Ae.decomposeMat4(Ae.inverseMat4(this._scene.viewer.camera.viewMatrix,Ae.mat4()),t,Ae.vec4(),Ae.vec3());var n=Ae.distVec3(t,e),r=Math.tan(Math.PI/500)*n*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(r/=this._scene.camera.ortho.scale/2),Jt(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new bt(this._scene,It({radius:r})),this._pivotSphere=new Gr(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}},{key:"destroyPivotSphere",value:function(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}},{key:"updatePivotElement",value:function(){var e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){Ae.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,Ae.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);var n=t.boundary,r=n[2],i=n[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*r/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*i/2);var s=t._lastBoundingClientRect;if(!s||t._canvasSizeChanged){var o=t.canvas;s=t._lastBoundingClientRect=o.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(s.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(s.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}},{key:"updatePivotSphere",value:function(){this._pivoting&&this._pivotSphere&&(Jt(this.getPivotPos(),this._rtcCenter,this._rtcPos),Ae.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}},{key:"setPivotElement",value:function(e){this._pivotElement=e}},{key:"enablePivotSphere",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);var t=e.color||[1,0,0];this._pivotSphereMaterial=new Zr(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}},{key:"disablePivotSphere",value:function(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}},{key:"startPivot",value:function(){var e=this._scene.camera,t=Ae.lookAtMat4v(e.eye,e.look,e.up);Ae.transformPoint3(t,this.getPivotPos(),this._cameraOffset);var n=this.getPivotPos();this._cameraOffset[2]+=Ae.distVec3(e.eye,n),t=Ae.inverseMat4(t);var r=Ae.transformVec3(t,this._cameraOffset),i=Ae.vec3();if(Ae.subVec3(e.eye,n,i),Ae.addVec3(i,r),e.zUp){var s=i[1];i[1]=i[2],i[2]=s}this._radius=Ae.lenVec3(i),this._polar=Math.acos(i[1]/this._radius),this._azimuth=Math.atan2(i[0],i[2]),this._pivoting=!0}},{key:"_cameraLookingDownwards",value:function(){var e=this._scene.camera,t=Ae.normalizeVec3(Ae.subVec3(e.look,e.eye,Cc)),n=Ae.cross3Vec3(t,e.worldUp,kc);return Ae.sqLenVec3(n)<=1e-4}},{key:"getPivoting",value:function(){return this._pivoting}},{key:"setPivotPos",value:function(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}},{key:"setCanvasPivotPos",value:function(e){var t=this._scene.camera,n=Math.abs(Ae.distVec3(this._scene.center,t.eye)),r=t.project.transposedMatrix,i=r.subarray(8,12),s=r.subarray(12),o=[0,0,-1,1],a=Ae.dotVec4(o,i)/Ae.dotVec4(o,s),A=Ec;t.project.unproject(e,a,Fc,xc,A);var c=Ae.normalizeVec3(Ae.subVec3(A,t.eye,Cc)),u=Ae.addVec3(t.eye,Ae.mulVec3Scalar(c,n,kc),Mc);this.setPivotPos(u)}},{key:"getPivotPos",value:function(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}},{key:"continuePivot",value:function(e,t){if(this._pivoting&&(0!==e||0!==t)){var n=this._scene.camera,r=-e,i=-t;1===n.worldUp[2]&&(r=-r),this._azimuth+=.01*-r;var s=i<0,o=i>0,a=Math.abs(this._polar-.001)<.005,A=Math.abs(this._polar-Uc)<.005,c=this._polar+.01*i;c=a&&s?.001:A&&o?Uc:Ae.clamp(c,.001,Uc),this._polar=c;var u=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===n.worldUp[2]){var l=u[1];u[1]=u[2],u[2]=l}var h=Ae.lenVec3(Ae.subVec3(n.look,n.eye,Ae.vec3())),d=this.getPivotPos();Ae.addVec3(u,d);var f=Ae.lookAtMat4v(u,d,n.worldUp);f=Ae.inverseMat4(f);var p=Ae.transformVec3(f,this._cameraOffset);f[12]-=p[0],f[13]-=p[1],f[14]-=p[2];var v=[f[8],f[9],f[10]];n.eye=[f[12],f[13],f[14]],Ae.subVec3(n.eye,Ae.mulVec3Scalar(v,h),n.look),n.up=[f[4],f[5],f[6]],this.showPivot()}}},{key:"showPivot",value:function(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}},{key:"hidePivot",value:function(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}},{key:"endPivot",value:function(){this._pivoting=!1}},{key:"destroy",value:function(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}]),e}(),Tc=function(){function e(t,n){x(this,e),this._scene=t.scene,this._cameraControl=t,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=n,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=Ae.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}return I(e,[{key:"update",value:function(){if(this._configs.pointerEnabled&&(this.schedulePickEntity||this.schedulePickSurface)){var e="".concat(~~this.pickCursorPos[0],"-").concat(~~this.pickCursorPos[1],"-").concat(this.scheduleSnapOrPick,"-").concat(this.schedulePickSurface,"-").concat(this.schedulePickEntity);if(this._lastHash!==e){this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;var t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var n=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});n&&(n.snappedToEdge||n.snappedToVertex)?(this.snapPickResult=n,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){var r=this.pickResult.canvasPos;if(r[0]===this.pickCursorPos[0]&&r[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){var i=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(i[0]===this.pickCursorPos[0]&&i[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}}}},{key:"fireEvents",value:function(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){var e=new Qa;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){var t=this.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=t)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}]),e}(),Pc=Ae.vec2(),Sc=function(){function e(t,n,r,i,s){x(this,e),this._scene=t;var o,a,A,c=n.pickController,u=n.cameraControl,l=0,h=0,d=0,f=0,p=!1,v=Ae.vec3(),g=!0,m=this._scene.canvas.canvas,y=[];function _(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];b(),e&&w()}function b(){l=i.pointerCanvasPos[0],h=i.pointerCanvasPos[1],d=i.pointerCanvasPos[0],f=i.pointerCanvasPos[1]}function w(){c.pickCursorPos=i.pointerCanvasPos,c.schedulePickSurface=!0,c.update(),c.picked&&c.pickedSurface&&c.pickResult&&c.pickResult.worldPos?(p=!0,v.set(c.pickResult.worldPos)):p=!1}document.addEventListener("keydown",this._documentKeyDownHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!0}}),document.addEventListener("keyup",this._documentKeyUpHandler=function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled){var n=e.keyCode;y[n]=!1}}),document.addEventListener("visibilitychange",this._onVisibilityChange=function(){y.splice(0)}),window.addEventListener("blur",this._onBlur=function(){y.splice(0)}),m.addEventListener("mousedown",this._mouseDownHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:y[t.input.KEY_SHIFT]||r.planView?(o=!0,y[t.input.MOUSE_LEFT_BUTTON]=!0,_()):(o=!0,y[t.input.MOUSE_LEFT_BUTTON]=!0,_(!1));break;case 2:a=!0,y[t.input.MOUSE_MIDDLE_BUTTON]=!0,_();break;case 3:A=!0,y[t.input.MOUSE_RIGHT_BUTTON]=!0,r.panRightClick&&_()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&(o||a||A)){var n=t.canvas.boundary,c=n[2],d=n[3],f=i.pointerCanvasPos[0],g=i.pointerCanvasPos[1],m=r.planView||u._isKeyDownForAction(u.MOUSE_PAN,y),_=u._isKeyDownForAction(u.MOUSE_ROTATE,y),b=document.pointerLockElement?e.movementX:f-l,w=document.pointerLockElement?e.movementY:g-h;if(m){var B=t.camera;if("perspective"===B.projection){var C=Math.abs(p?Ae.lenVec3(Ae.subVec3(v,t.camera.eye,[])):t.camera.eyeLookDist)*Math.tan(B.perspective.fov/2*Math.PI/180);s.panDeltaX+=1.5*b*C/d,s.panDeltaY+=1.5*w*C/d}else s.panDeltaX+=.5*B.ortho.scale*(b/d),s.panDeltaY+=.5*B.ortho.scale*(w/d)}else _&&(r.planView||(r.firstPerson?(s.rotateDeltaY-=b/c*r.dragRotationRate/2,s.rotateDeltaX+=w/d*(r.dragRotationRate/4)):(s.rotateDeltaY-=b/c*(1.5*r.dragRotationRate),s.rotateDeltaX+=w/d*(1.5*r.dragRotationRate))));l=f,h=g}}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=function(e){r.active&&r.pointerEnabled&&i.mouseover&&(g=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){if(r.active&&r.pointerEnabled)switch(e.which){case 1:case 2:case 3:o=!1,a=!1,A=!1,y[t.input.MOUSE_LEFT_BUTTON]=!1,y[t.input.MOUSE_MIDDLE_BUTTON]=!1,y[t.input.MOUSE_RIGHT_BUTTON]=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=function(e){if(r.active&&r.pointerEnabled){if(3===e.which){!function(e,t){if(e){for(var n=e.target,r=0,i=0,s=0,o=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,s+=n.scrollLeft,o+=n.scrollTop,n=n.offsetParent;t[0]=e.pageX+s-r,t[1]=e.pageY+o-i}else e=window.event,t[0]=e.x,t[1]=e.y}(e,Pc);var t=Pc[0],i=Pc[1];Math.abs(t-d)<3&&Math.abs(i-f)<3&&n.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:Pc,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=function(){r.active&&r.pointerEnabled});var B=1/60,C=null;m.addEventListener("wheel",this._mouseWheelHandler=function(e){if(r.active&&r.pointerEnabled&&r.zoomOnMouseWheel&&u._isKeyDownForAction(u.MOUSE_DOLLY,y)){var t=performance.now()/1e3,n=null!==C?t-C:0;C=t,n>.05&&(n=.05),n<B&&(n=B);var o=Math.max(-1,Math.min(1,40*-e.deltaY));if(0!==o){var a=o/Math.abs(o);s.dollyDelta+=-a*n*r.mouseWheelDollyRate,g&&(i.followPointerDirty=!0,g=!1)}}},{passive:!0})}return I(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;document.removeEventListener("keydown",this._documentKeyDownHandler),document.removeEventListener("keyup",this._documentKeyUpHandler),document.removeEventListener("visibilitychange",this._onVisibilityChange),window.removeEventListener("blur",this._onBlur),e.removeEventListener("mousedown",this._mouseDownHandler),document.removeEventListener("mousemove",this._documentMouseMoveHandler),e.removeEventListener("mousemove",this._canvasMouseMoveHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._mouseUpHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("wheel",this._mouseWheelHandler)}}]),e}(),Dc=Ae.vec3(),Qc=Ae.vec3(),Rc=Ae.vec3(),Oc=Ae.vec3(),Vc=Ae.vec3(),Lc={eye:Ae.vec3(),look:Ae.vec3(),up:Ae.vec3()},Hc=function(){function e(t,n,r,i){x(this,e),this._scene=t;var s=n.cameraControl,o=t.camera;this._onSceneKeyDown=t.input.on("keydown",(function(){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(!r.keyboardEnabledOnlyIfMouseover||i.mouseover)){var e=s._isKeyDownForAction(s.AXIS_VIEW_RIGHT),a=s._isKeyDownForAction(s.AXIS_VIEW_BACK),A=s._isKeyDownForAction(s.AXIS_VIEW_LEFT),c=s._isKeyDownForAction(s.AXIS_VIEW_FRONT),u=s._isKeyDownForAction(s.AXIS_VIEW_TOP),l=s._isKeyDownForAction(s.AXIS_VIEW_BOTTOM);if(e||a||A||c||u||l){var h=t.aabb,d=Ae.getAABB3Diag(h);Ae.getAABB3Center(h,Dc);var f=Math.abs(d/Math.tan(n.cameraFlight.fitFOV*Ae.DEGTORAD)),p=1.1*d;Lc.orthoScale=p,e?(Lc.eye.set(Ae.addVec3(Dc,Ae.mulVec3Scalar(o.worldRight,f,Qc),Vc)),Lc.look.set(Dc),Lc.up.set(o.worldUp)):a?(Lc.eye.set(Ae.addVec3(Dc,Ae.mulVec3Scalar(o.worldForward,f,Qc),Vc)),Lc.look.set(Dc),Lc.up.set(o.worldUp)):A?(Lc.eye.set(Ae.addVec3(Dc,Ae.mulVec3Scalar(o.worldRight,-f,Qc),Vc)),Lc.look.set(Dc),Lc.up.set(o.worldUp)):c?(Lc.eye.set(Ae.addVec3(Dc,Ae.mulVec3Scalar(o.worldForward,-f,Qc),Vc)),Lc.look.set(Dc),Lc.up.set(o.worldUp)):u?(Lc.eye.set(Ae.addVec3(Dc,Ae.mulVec3Scalar(o.worldUp,f,Qc),Vc)),Lc.look.set(Dc),Lc.up.set(Ae.normalizeVec3(Ae.mulVec3Scalar(o.worldForward,1,Rc),Oc))):l&&(Lc.eye.set(Ae.addVec3(Dc,Ae.mulVec3Scalar(o.worldUp,-f,Qc),Vc)),Lc.look.set(Dc),Lc.up.set(Ae.normalizeVec3(Ae.mulVec3Scalar(o.worldForward,-1,Rc)))),!r.firstPerson&&r.followPointer&&n.pivotController.setPivotPos(Dc),n.cameraFlight.duration>0?n.cameraFlight.flyTo(Lc,(function(){n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot()})):(n.cameraFlight.jumpTo(Lc),n.pivotController.getPivoting()&&r.followPointer&&n.pivotController.showPivot())}}}))}return I(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.input.off(this._onSceneKeyDown)}}]),e}(),Nc=function(){function e(t,n,r,i,s){var o=this;x(this,e),this._scene=t;var a=n.pickController,A=n.pivotController,c=n.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null,this._lastClickedWorldPos=null;var u=!1,l=!1,h=this._scene.canvas.canvas,d=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var i=e&&e.entity?e.entity.aabb:t.aabb;if(r){var s=t.camera;Ae.subVec3(s.eye,s.look,[]),n.cameraFlight.flyTo({aabb:i})}else n.cameraFlight.flyTo({aabb:i})},f=t.tickify(this._canvasMouseMoveHandler=function(e){if(r.active&&r.pointerEnabled&&!u&&!l){if(c.hasSubs("rayMove")){var n=Ae.vec3(),s=Ae.vec3();Ae.canvasPosToWorldRay(t.canvas.canvas,t.camera.viewMatrix,t.camera.projMatrix,t.camera.projection,i.pointerCanvasPos,n,s),c.fire("rayMove",{canvasPos:i.pointerCanvasPos,ray:{origin:n,direction:s,canvasPos:i.pointerCanvasPos}},!0)}var A=c.hasSubs("hover"),h=c.hasSubs("hoverEnter"),d=c.hasSubs("hoverOut"),f=c.hasSubs("hoverOff"),p=c.hasSubs("hoverSurface"),v=c.hasSubs("hoverSnapOrSurface");if(A||h||d||f||p||v)if(a.pickCursorPos=i.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=p,a.scheduleSnapOrPick=v,a.update(),a.pickResult){if(a.pickResult.entity){var g=a.pickResult.entity.id;o._lastPickedEntityId!==g&&(void 0!==o._lastPickedEntityId&&c.fire("hoverOut",{entity:t.objects[o._lastPickedEntityId]},!0),c.fire("hoverEnter",a.pickResult,!0),o._lastPickedEntityId=g)}c.fire("hover",a.pickResult,!0),(a.pickResult.worldPos||a.pickResult.snappedWorldPos)&&c.fire("hoverSurface",a.pickResult,!0)}else void 0!==o._lastPickedEntityId&&(c.fire("hoverOut",{entity:t.objects[o._lastPickedEntityId]},!0),o._lastPickedEntityId=void 0),c.fire("hoverOff",{canvasPos:a.pickCursorPos},!0)}});h.addEventListener("mousemove",f),h.addEventListener("mousedown",this._canvasMouseDownHandler=function(e){if(1===e.which&&(u=!0),3===e.which&&(l=!0),1===e.which&&r.active&&r.pointerEnabled&&(i.mouseDownClientX=e.clientX,i.mouseDownClientY=e.clientY,i.mouseDownCursorX=i.pointerCanvasPos[0],i.mouseDownCursorY=i.pointerCanvasPos[1],!r.firstPerson&&r.followPointer&&(a.pickCursorPos=i.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),1===e.which))){var n=a.pickResult;n&&n.worldPos?(A.setPivotPos(n.worldPos),A.startPivot(),o._lastClickedWorldPos=n.worldPos.slice()):(r.smartPivot?A.setCanvasPivotPos(i.pointerCanvasPos):o._lastClickedWorldPos?A.setPivotPos(o._lastClickedWorldPos):A.setPivotPos(t.camera.look),A.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=function(e){1===e.which&&(u=!1),3===e.which&&(l=!1),A.getPivoting()&&A.endPivot()}),h.addEventListener("mouseup",this._canvasMouseUpHandler=function(e){if(r.active&&r.pointerEnabled&&(1===e.which&&(A.hidePivot(),!(Math.abs(e.clientX-i.mouseDownClientX)>3||Math.abs(e.clientY-i.mouseDownClientY)>3)))){var s=c.hasSubs("picked"),u=c.hasSubs("pickedNothing"),l=c.hasSubs("pickedSurface"),h=c.hasSubs("doublePicked"),f=c.hasSubs("doublePickedSurface"),p=c.hasSubs("doublePickedNothing");if(!(r.doublePickFlyTo||h||f||p))return(s||u||l)&&(a.pickCursorPos=i.pointerCanvasPos,a.schedulePickEntity=!0,a.schedulePickSurface=l,a.update(),a.pickResult?(c.fire("picked",a.pickResult,!0),a.pickedSurface&&c.fire("pickedSurface",a.pickResult,!0)):c.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0)),void(o._clicks=0);if(o._clicks++,1===o._clicks){a.pickCursorPos=i.pointerCanvasPos,a.schedulePickEntity=r.doublePickFlyTo,a.schedulePickSurface=l,a.update();var v=a.pickResult,g=a.pickedSurface;o._timeout=setTimeout((function(){v?(c.fire("picked",v,!0),g&&(c.fire("pickedSurface",v,!0),!r.firstPerson&&r.followPointer&&(n.pivotController.setPivotPos(v.worldPos),n.pivotController.startPivot()&&n.pivotController.showPivot()))):c.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0),o._clicks=0}),r.doubleClickTimeFrame)}else{if(null!==o._timeout&&(window.clearTimeout(o._timeout),o._timeout=null),a.pickCursorPos=i.pointerCanvasPos,a.schedulePickEntity=r.doublePickFlyTo||h||f,a.schedulePickSurface=a.schedulePickEntity&&f,a.update(),a.pickResult){if(c.fire("doublePicked",a.pickResult,!0),a.pickedSurface&&c.fire("doublePickedSurface",a.pickResult,!0),r.doublePickFlyTo&&(d(a.pickResult),!r.firstPerson&&r.followPointer)){var m=a.pickResult.entity.aabb,y=Ae.getAABB3Center(m);n.pivotController.setPivotPos(y),n.pivotController.startPivot()&&n.pivotController.showPivot()}}else if(c.fire("doublePickedNothing",{canvasPos:i.pointerCanvasPos},!0),r.doublePickFlyTo&&(d(),!r.firstPerson&&r.followPointer)){var _=t.aabb,b=Ae.getAABB3Center(_);n.pivotController.setPivotPos(b),n.pivotController.startPivot()&&n.pivotController.showPivot()}o._clicks=0}}},!1)}return I(e,[{key:"reset",value:function(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}]),e}(),Gc=function(){function e(t,n,r,i,s){x(this,e),this._scene=t;var o=t.input,a=[];t.canvas.canvas;var A=!0;this._onSceneMouseMove=o.on("mousemove",(function(){A=!0})),this._onSceneKeyDown=o.on("keydown",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(r.keyboardEnabledOnlyIfMouseover&&!i.mouseover||(a[e]=!0))})),this._onSceneKeyUp=o.on("keyup",(function(e){r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(a[e]=!1,n.pivotController.getPivoting()&&n.pivotController.endPivot())})),document.addEventListener("visibilitychange",this._onVisibilityChange=function(){a.splice(0)}),window.addEventListener("blur",this._onBlur=function(){a.splice(0)}),this._onTick=t.on("tick",(function(e){if(r.active&&r.pointerEnabled&&t.input.keyboardEnabled&&(!r.keyboardEnabledOnlyIfMouseover||i.mouseover)){var c=n.cameraControl,u=e.deltaTime/1e3;if(!r.planView){var l=c._isKeyDownForAction(c.ROTATE_Y_POS,a),h=c._isKeyDownForAction(c.ROTATE_Y_NEG,a),d=c._isKeyDownForAction(c.ROTATE_X_POS,a),f=c._isKeyDownForAction(c.ROTATE_X_NEG,a),p=u*r.keyboardRotationRate;(l||h||d||f)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),l?s.rotateDeltaY+=p:h&&(s.rotateDeltaY-=p),d?s.rotateDeltaX+=p:f&&(s.rotateDeltaX-=p),!r.firstPerson&&r.followPointer&&n.pivotController.startPivot())}if(!a[o.KEY_CTRL]&&!a[o.KEY_ALT]){var v=c._isKeyDownForAction(c.DOLLY_BACKWARDS,a),g=c._isKeyDownForAction(c.DOLLY_FORWARDS,a);if(v||g){var m=u*r.keyboardDollyRate;!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),g?s.dollyDelta-=m:v&&(s.dollyDelta+=m),A&&(i.followPointerDirty=!0,A=!1)}}var y=c._isKeyDownForAction(c.PAN_FORWARDS,a),_=c._isKeyDownForAction(c.PAN_BACKWARDS,a),b=c._isKeyDownForAction(c.PAN_LEFT,a),w=c._isKeyDownForAction(c.PAN_RIGHT,a),B=c._isKeyDownForAction(c.PAN_UP,a),C=c._isKeyDownForAction(c.PAN_DOWN,a),k=(a[o.KEY_ALT]?.3:1)*u*r.keyboardPanRate;(y||_||b||w||B||C)&&(!r.firstPerson&&r.followPointer&&n.pivotController.startPivot(),C?s.panDeltaY+=k:B&&(s.panDeltaY+=-k),w?s.panDeltaX+=-k:b&&(s.panDeltaX+=k),_?s.panDeltaZ+=k:y&&(s.panDeltaZ+=-k))}}))}return I(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),document.removeEventListener("visibilitychange",this._onVisibilityChange),window.removeEventListener("blur",this._onBlur),this._scene.input.off(this._onSceneKeyUp)}}]),e}(),jc=Ae.vec3(),Wc=function(){function e(t,n,r,i,s){x(this,e),this._scene=t;var o=t.camera,a=n.pickController,A=n.pivotController,c=n.panController,u=n.cameraControl,l=1,h=1,d=null;this._onTick=t.on("tick",(function(){if(r.active&&r.pointerEnabled){var e="default";if(Math.abs(s.dollyDelta)<.001&&(s.dollyDelta=0),Math.abs(s.rotateDeltaX)<.001&&(s.rotateDeltaX=0),Math.abs(s.rotateDeltaY)<.001&&(s.rotateDeltaY=0),0===s.rotateDeltaX&&0===s.rotateDeltaY||(s.dollyDelta=0),r.followPointer){if(--l<=0&&(l=1,0!==s.dollyDelta)){if(0===s.rotateDeltaY&&0===s.rotateDeltaX&&r.followPointer&&i.followPointerDirty&&(a.pickCursorPos=i.pointerCanvasPos,a.schedulePickSurface=!0,a.update(),a.pickResult&&a.pickResult.worldPos?d=a.pickResult.worldPos:(h=1,d=null),i.followPointerDirty=!1),d){var n=Math.abs(Ae.lenVec3(Ae.subVec3(d,t.camera.eye,jc)));h=n/r.dollyProximityThreshold}h<r.dollyMinSpeed&&(h=r.dollyMinSpeed)}}else h=1,d=null;var f=s.dollyDelta*h;if(0===s.rotateDeltaY&&0===s.rotateDeltaX||(!r.firstPerson&&r.followPointer&&A.getPivoting()?(A.continuePivot(s.rotateDeltaY,s.rotateDeltaX),A.showPivot()):(0!==s.rotateDeltaX&&(r.firstPerson?o.pitch(-s.rotateDeltaX):o.orbitPitch(s.rotateDeltaX)),0!==s.rotateDeltaY&&(r.firstPerson?o.yaw(s.rotateDeltaY):o.orbitYaw(s.rotateDeltaY))),s.rotateDeltaX*=r.rotationInertia,s.rotateDeltaY*=r.rotationInertia,e=u._cursors.rotate),Math.abs(s.panDeltaX)<.001&&(s.panDeltaX=0),Math.abs(s.panDeltaY)<.001&&(s.panDeltaY=0),Math.abs(s.panDeltaZ)<.001&&(s.panDeltaZ=0),0!==s.panDeltaX||0!==s.panDeltaY||0!==s.panDeltaZ){var p,v,g=Ae.vec3();if(g[0]=s.panDeltaX,g[1]=s.panDeltaY,g[2]=s.panDeltaZ,r.constrainVertical){o.xUp?(p=o.eye[0],v=o.look[0]):o.yUp?(p=o.eye[1],v=o.look[1]):o.zUp&&(p=o.eye[2],v=o.look[2]),o.pan(g);var m=o.eye,y=o.look;o.xUp?(m[0]=p,y[0]=v):o.yUp?(m[1]=p,y[1]=v):o.zUp&&(m[2]=p,y[2]=v),o.eye=m,o.look=y}else o.pan(g);e=u._cursors.pan}if(s.panDeltaX*=r.panInertia,s.panDeltaY*=r.panInertia,s.panDeltaZ*=r.panInertia,0!==f){if(e=f<0?u._cursors.dollyForward:u._cursors.dollyBackward,r.firstPerson){var _,b;if(r.constrainVertical&&(o.xUp?(_=o.eye[0],b=o.look[0]):o.yUp?(_=o.eye[1],b=o.look[1]):o.zUp&&(_=o.eye[2],b=o.look[2])),r.followPointer)c.dollyToCanvasPos(d,i.pointerCanvasPos,-f)&&(i.followPointerDirty=!0);else o.pan([0,0,f]),o.ortho.scale=o.ortho.scale-f;if(r.constrainVertical){var w=o.eye,B=o.look;o.xUp?(w[0]=_,B[0]=b):o.yUp?(w[1]=_,B[1]=b):o.zUp&&(w[2]=_,B[2]=b),o.eye=w,o.look=B}}else if(r.planView){if(r.followPointer)c.dollyToCanvasPos(d,i.pointerCanvasPos,-f)&&(i.followPointerDirty=!0);else o.ortho.scale=o.ortho.scale+f,o.zoom(f)}else{if(r.followPointer)c.dollyToCanvasPos(d,i.pointerCanvasPos,-f)&&(i.followPointerDirty=!0);else o.ortho.scale=o.ortho.scale+f,o.zoom(f)}s.dollyDelta*=r.dollyInertia}a.fireEvents(),document.body.style.cursor=e}}))}return I(e,[{key:"destroy",value:function(){this._scene.off(this._onTick)}}]),e}(),zc=function(){function e(t,n,r,i,s){x(this,e),this._scene=t;var o=this._scene.canvas.canvas;o.addEventListener("mouseenter",this._mouseEnterHandler=function(){i.mouseover=!0}),o.addEventListener("mouseleave",this._mouseLeaveHandler=function(){i.mouseover=!1,o.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=function(e){Xc(e,o,i.pointerCanvasPos)}),o.addEventListener("mousedown",this._mouseDownHandler=function(e){r.active&&r.pointerEnabled&&(Xc(e,o,i.pointerCanvasPos),i.mouseover=!0)}),o.addEventListener("mouseup",this._mouseUpHandler=function(e){r.active&&r.pointerEnabled})}return I(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}]),e}();function Xc(e,t,n){if(e){var r=t.getBoundingClientRect(),i=r.left,s=r.top;n[0]=e.clientX-i,n[1]=e.clientY-s}else e=window.event,n[0]=e.x,n[1]=e.y;return n}var Kc=function(e,t){if(e){for(var n=e.target,r=0,i=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,n=n.offsetParent;t[0]=e.pageX-r,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t},Zc=function(){function e(t,n,r,i,s){x(this,e),this._scene=t;var o=n.pickController,a=n.pivotController,A=Ae.vec2(),c=Ae.vec2(),u=Ae.vec2(),l=Ae.vec2(),h=[],d=this._scene.canvas.canvas,f=0,p=!1;this._onTick=t.on("tick",(function(){p=!1})),d.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){if(r.active&&r.pointerEnabled){e.preventDefault();var n=e.touches,s=e.changedTouches;for(i.touchStartTime=Date.now(),1===n.length&&1===s.length&&(Kc(n[0],A),r.followPointer&&(o.pickCursorPos=A,o.schedulePickSurface=!0,o.update(),r.planView||(o.picked&&o.pickedSurface&&o.pickResult&&o.pickResult.worldPos?(a.setPivotPos(o.pickResult.worldPos),!r.firstPerson&&a.startPivot()&&a.showPivot()):(r.smartPivot?a.setCanvasPivotPos(i.pointerCanvasPos):a.setPivotPos(t.camera.look),!r.firstPerson&&a.startPivot()&&a.showPivot()))));h.length<n.length;)h.push(Ae.vec2());for(var c=0,u=n.length;c<u;++c)Kc(n[c],h[c]);f=n.length}}),d.addEventListener("touchend",this._canvasTouchEndHandler=function(){a.getPivoting()&&(a.endPivot(),a.hidePivot())}),d.addEventListener("touchmove",this._canvasTouchMoveHandler=function(e){if(r.active&&r.pointerEnabled&&(e.stopPropagation(),e.preventDefault(),!p)){p=!0;var n=t.canvas.boundary,a=n[2],A=n[3],d=e.touches;if(e.touches.length===f){if(1===f){Kc(d[0],c),Ae.subVec2(c,h[0],l);var v=l[0],g=l[1];if(null!==i.longTouchTimeout&&(Math.abs(v)>r.longTapRadius||Math.abs(g)>r.longTapRadius)&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),r.planView){var m=t.camera;if("perspective"===m.projection){var y=Math.abs(t.camera.eyeLookDist)*Math.tan(m.perspective.fov/2*Math.PI/180);s.panDeltaX+=v*y/A*r.touchPanRate,s.panDeltaY+=g*y/A*r.touchPanRate}else s.panDeltaX+=.5*m.ortho.scale*(v/A)*r.touchPanRate,s.panDeltaY+=.5*m.ortho.scale*(g/A)*r.touchPanRate}else s.rotateDeltaY-=v/a*(1*r.dragRotationRate),s.rotateDeltaX+=g/A*(1.5*r.dragRotationRate)}else if(2===f){var _=d[0],b=d[1];Kc(_,c),Kc(b,u);var w=Ae.geometricMeanVec2(h[0],h[1]),B=Ae.geometricMeanVec2(c,u),C=Ae.vec2();Ae.subVec2(w,B,C);var k=C[0],M=C[1],E=t.camera,F=Ae.distVec2([_.pageX,_.pageY],[b.pageX,b.pageY]),x=(Ae.distVec2(h[0],h[1])-F)*r.touchDollyRate;if(s.dollyDelta=x,Math.abs(x)<1)if("perspective"===E.projection){var U=o.pickResult?o.pickResult.worldPos:t.center,I=Math.abs(Ae.lenVec3(Ae.subVec3(U,t.camera.eye,[])))*Math.tan(E.perspective.fov/2*Math.PI/180);s.panDeltaX-=k*I/A*r.touchPanRate,s.panDeltaY-=M*I/A*r.touchPanRate}else s.panDeltaX-=.5*E.ortho.scale*(k/A)*r.touchPanRate,s.panDeltaY-=.5*E.ortho.scale*(M/A)*r.touchPanRate;i.pointerCanvasPos=B}for(var T=0;T<f;++T)Kc(d[T],h[T])}}})}return I(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler),e.removeEventListener("touchmove",this._canvasTouchMoveHandler),this._scene.off(this._onTick)}}]),e}(),Jc=function(e,t){if(e){for(var n=e.target,r=0,i=0;n.offsetParent;)r+=n.offsetLeft,i+=n.offsetTop,n=n.offsetParent;t[0]=e.pageX-r,t[1]=e.pageY-i}else e=window.event,t[0]=e.x,t[1]=e.y;return t},Yc=function(){function e(t,n,r,i,s){x(this,e),this._scene=t;var o,a=n.pickController,A=n.cameraControl,c=[],u=new Float32Array(2),l=-1,h=-1,d=this._scene.canvas.canvas,f=function(e){var r;e&&e.worldPos&&(r=e.worldPos);var i=e?e.entity.aabb:t.aabb;if(r){var s=t.camera;Ae.subVec3(s.eye,s.look,[]),n.cameraFlight.flyTo({aabb:i})}else n.cameraFlight.flyTo({aabb:i})};d.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){if(r.active&&r.pointerEnabled){null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null);var t=e.touches,s=e.changedTouches;if(o=Date.now(),1===t.length&&1===s.length){l=o,Jc(t[0],u);var a=u[0],A=u[1],h=t[0].pageX,d=t[0].pageY;i.longTouchTimeout=setTimeout((function(){r.active&&r.pointerEnabled&&n.cameraControl.fire("rightClick",{pagePos:[Math.round(h),Math.round(d)],canvasPos:[Math.round(a),Math.round(A)],event:e},!0),i.longTouchTimeout=null}),r.longTapTimeout)}else l=-1;for(;c.length<t.length;)c.push(new Float32Array(2));for(var f=0,p=t.length;f<p;++f)Jc(t[f],c[f]);c.length=t.length}},{passive:!0}),d.addEventListener("touchend",this._canvasTouchEndHandler=function(e){if(r.active&&r.pointerEnabled){var t=Date.now(),n=e.touches,s=e.changedTouches,o=A.hasSubs("pickedSurface");null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),0===n.length&&1===s.length&&l>-1&&t-l<150&&(h>-1&&l-h<325?(Jc(s[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=o,a.update(),a.pickResult?(a.pickResult.touchInput=!0,A.fire("doublePicked",a.pickResult),a.pickedSurface&&A.fire("doublePickedSurface",a.pickResult),r.doublePickFlyTo&&f(a.pickResult)):(A.fire("doublePickedNothing"),r.doublePickFlyTo&&f()),h=-1):Ae.distVec2(c[0],u)<4&&(Jc(s[0],a.pickCursorPos),a.schedulePickEntity=!0,a.schedulePickSurface=o,a.update(),a.pickResult?(a.pickResult.touchInput=!0,A.fire("picked",a.pickResult),a.pickedSurface&&A.fire("pickedSurface",a.pickResult)):A.fire("pickedNothing"),h=t),l=-1),c.length=n.length;for(var d=0,p=n.length;d<p;++d)c[d][0]=n[d].pageX,c[d][1]=n[d].pageY}},{passive:!0})}return I(e,[{key:"reset",value:function(){}},{key:"destroy",value:function(){var e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler)}}]),e}(),qc=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)).PAN_LEFT=0,r.PAN_RIGHT=1,r.PAN_UP=2,r.PAN_DOWN=3,r.PAN_FORWARDS=4,r.PAN_BACKWARDS=5,r.ROTATE_X_POS=6,r.ROTATE_X_NEG=7,r.ROTATE_Y_POS=8,r.ROTATE_Y_NEG=9,r.DOLLY_FORWARDS=10,r.DOLLY_BACKWARDS=11,r.AXIS_VIEW_RIGHT=12,r.AXIS_VIEW_BACK=13,r.AXIS_VIEW_LEFT=14,r.AXIS_VIEW_FRONT=15,r.AXIS_VIEW_TOP=16,r.AXIS_VIEW_BOTTOM=17,r.MOUSE_PAN=18,r.MOUSE_ROTATE=19,r.MOUSE_DOLLY=20,r._keyMap={},r.scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},r._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,zoomOnMouseWheel:!0,snapToVertex:true,snapToEdge:true,snapRadius:30,keyboardEnabledOnlyIfMouseover:!0,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},r._states={pointerCanvasPos:Ae.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:Ae.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},r._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};var s=r.scene;return r._controllers={cameraControl:w(r),pickController:new Tc(w(r),r._configs),pivotController:new Ic(s,r._configs),panController:new Bc(s),cameraFlight:new et(w(r),{duration:.5})},r._handlers=[new zc(r.scene,r._controllers,r._configs,r._states,r._updates),new Zc(r.scene,r._controllers,r._configs,r._states,r._updates),new Sc(r.scene,r._controllers,r._configs,r._states,r._updates),new Hc(r.scene,r._controllers,r._configs,r._states,r._updates),new Nc(r.scene,r._controllers,r._configs,r._states,r._updates),new Yc(r.scene,r._controllers,r._configs,r._states,r._updates),new Gc(r.scene,r._controllers,r._configs,r._states,r._updates)],r._cursors={dollyForward:"zoom-in",dollyBackward:"zoom-out",rotate:"grabbing",pan:"move"},r._cameraUpdater=new Wc(r.scene,r._controllers,r._configs,r._states,r._updates),r.navMode=i.navMode,i.planView&&(r.planView=i.planView),r.constrainVertical=i.constrainVertical,i.keyboardLayout?r.keyboardLayout=i.keyboardLayout:r.keyMap=i.keyMap,r.doublePickFlyTo=i.doublePickFlyTo,r.panRightClick=i.panRightClick,r.active=i.active,r.followPointer=i.followPointer,r.rotationInertia=i.rotationInertia,r.keyboardPanRate=i.keyboardPanRate,r.touchPanRate=i.touchPanRate,r.keyboardRotationRate=i.keyboardRotationRate,r.dragRotationRate=i.dragRotationRate,r.touchDollyRate=i.touchDollyRate,r.dollyInertia=i.dollyInertia,r.dollyProximityThreshold=i.dollyProximityThreshold,r.dollyMinSpeed=i.dollyMinSpeed,r.panInertia=i.panInertia,r.pointerEnabled=!0,r.keyboardDollyRate=i.keyboardDollyRate,r.mouseWheelDollyRate=i.mouseWheelDollyRate,r}return I(n,[{key:"keyMap",get:function(){return this._keyMap},set:function(e){if(e=e||"qwerty",ge.isString(e)){var t=this.scene.input,n={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":n[this.PAN_LEFT]=[t.KEY_A],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_Z],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6],n[this.MOUSE_PAN]=[[t.MOUSE_LEFT_BUTTON,t.KEY_SHIFT],this._configs.panRightClick?t.MOUSE_RIGHT_BUTTON:t.MOUSE_MIDDLE_BUTTON],n[this.MOUSE_ROTATE]=[t.MOUSE_LEFT_BUTTON],n[this.MOUSE_DOLLY]=[];break;case"azerty":n[this.PAN_LEFT]=[t.KEY_Q],n[this.PAN_RIGHT]=[t.KEY_D],n[this.PAN_UP]=[t.KEY_W],n[this.PAN_DOWN]=[t.KEY_X],n[this.PAN_BACKWARDS]=[],n[this.PAN_FORWARDS]=[],n[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],n[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],n[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],n[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],n[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],n[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],n[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],n[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],n[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],n[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],n[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],n[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6],n[this.MOUSE_PAN]=[[t.MOUSE_LEFT_BUTTON,t.KEY_SHIFT],this._configs.panRightClick?t.MOUSE_RIGHT_BUTTON:t.MOUSE_MIDDLE_BUTTON],n[this.MOUSE_ROTATE]=[t.MOUSE_LEFT_BUTTON],n[this.MOUSE_DOLLY]=[]}this._keyMap=n}else{var r=e;this._keyMap=r}}},{key:"_areAllKeysDown",value:function(e,t){if(!t||t.length<=0)return!0;if(!e)return!1;for(var n=0,r=t.length;n<r;n++){if(!e[t[n]])return!1}return!0}},{key:"_isAnyOtherKeyDown",value:function(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n])if(Array.isArray(t)){if(t.indexOf(n)<0)return!0}else if(n!==t)return!0;return!1}},{key:"_isMouseAction",value:function(e){switch(e){case this.MOUSE_ROTATE:case this.MOUSE_DOLLY:case this.MOUSE_PAN:return!0;default:return!1}}},{key:"_isKeyDownForAction",value:function(e,t){var n=this._keyMap[e];if(!n)return!1;if(0===n.length&&this._isMouseAction(e))return!0;t||(t=this.scene.input.keyDown);for(var r=0,i=n.length;r<i;r++){var s=n[r];if(Array.isArray(s)){if(this._areAllKeysDown(t,s)&&!this._isAnyOtherKeyDown(t,s))return!0}else if(t[s]&&!this._isAnyOtherKeyDown(t,s))return!0}return!1}},{key:"pivotElement",set:function(e){this._controllers.pivotController.setPivotElement(e)}},{key:"active",get:function(){return this._configs.active},set:function(e){e=!1!==e,this._configs.active=e,this._handlers[1]._active=e,this._handlers[5]._active=e}},{key:"snapToVertex",get:function(){return this._configs.snapToVertex},set:function(e){this._configs.snapToVertex=!!e}},{key:"snapToEdge",get:function(){return this._configs.snapToEdge},set:function(e){this._configs.snapToEdge=!!e}},{key:"snapRadius",get:function(){return this._configs.snapRadius},set:function(e){e=e||30,this._configs.snapRadius=e}},{key:"keyboardEnabledOnlyIfMouseover",get:function(){return this._configs.keyboardEnabledOnlyIfMouseover},set:function(e){this._configs.keyboardEnabledOnlyIfMouseover=!!e}},{key:"navMode",get:function(){return this._configs.navMode},set:function(e){"firstPerson"!==(e=e||"orbit")&&"orbit"!==e&&"planView"!==e&&(this.error("Unsupported value for navMode: "+e+" - supported values are 'orbit', 'firstPerson' and 'planView' - defaulting to 'orbit'"),e="orbit"),this._configs.firstPerson="firstPerson"===e,this._configs.planView="planView"===e,(this._configs.firstPerson||this._configs.planView)&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this._configs.navMode=e}},{key:"pointerEnabled",get:function(){return this._configs.pointerEnabled},set:function(e){this._reset(),this._configs.pointerEnabled=!!e}},{key:"setCursorStyle",value:function(e,t){Object.prototype.hasOwnProperty.call(this._cursors,e)?this._cursors=d(d({},this._cursors),{},f({},e,t)):console.warn("Action '".concat(e,"' is not valid for cursor styles."))}},{key:"getCursorStyle",value:function(e){return this._cursors[e]||null}},{key:"_reset",value:function(){for(var e=0,t=this._handlers.length;e<t;e++){var n=this._handlers[e];n.reset&&n.reset()}this._updates.panDeltaX=0,this._updates.panDeltaY=0,this._updates.rotateDeltaX=0,this._updates.rotateDeltaY=0,this._updates.dolyDelta=0}},{key:"followPointer",get:function(){return this._configs.followPointer},set:function(e){this._configs.followPointer=!1!==e}},{key:"pivotPos",get:function(){return this._controllers.pivotController.getPivotPos()},set:function(e){this._controllers.pivotController.setPivotPos(e)}},{key:"dollyToPointer",get:function(){return this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer},set:function(e){this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer=e}},{key:"panToPointer",get:function(){return this.warn("panToPointer property is deprecated - replaced with followPointer"),!1},set:function(e){this.warn("panToPointer property is deprecated - replaced with followPointer")}},{key:"planView",get:function(){return this.warn("planView property is deprecated - replaced with navMode"),this._configs.planView},set:function(e){this._configs.planView=!!e,this._configs.firstPerson=!1,this._configs.planView&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this.warn("planView property is deprecated - replaced with navMode")}},{key:"firstPerson",get:function(){return this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson},set:function(e){this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson=!!e,this._configs.planView=!1,this._configs.firstPerson&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot())}},{key:"constrainVertical",get:function(){return this._configs.constrainVertical},set:function(e){this._configs.constrainVertical=!!e}},{key:"doublePickFlyTo",get:function(){return this._configs.doublePickFlyTo},set:function(e){this._configs.doublePickFlyTo=!1!==e}},{key:"panRightClick",get:function(){return this._configs.panRightClick},set:function(e){this._configs.panRightClick=!1!==e;var t=this._keyMap[this.MOUSE_PAN];if(t&&t.length>0)for(var n=this.scene.input,r=0,i=t.length;r<i;r++)this._configs.panRightClick&&t[r]===n.MOUSE_MIDDLE_BUTTON?this._keyMap[this.MOUSE_PAN][r]=n.MOUSE_RIGHT_BUTTON:this._configs.panRightClick||t[r]!==n.MOUSE_RIGHT_BUTTON||(this._keyMap[this.MOUSE_PAN][r]=n.MOUSE_MIDDLE_BUTTON)}},{key:"rotationInertia",get:function(){return this._configs.rotationInertia},set:function(e){this._configs.rotationInertia=null!=e?e:0}},{key:"keyboardPanRate",get:function(){return this._configs.keyboardPanRate},set:function(e){this._configs.keyboardPanRate=null!=e?e:5}},{key:"touchPanRate",get:function(){return this._configs.touchPanRate},set:function(e){this._configs.touchPanRate=null!=e?e:1}},{key:"keyboardRotationRate",get:function(){return this._configs.keyboardRotationRate},set:function(e){this._configs.keyboardRotationRate=null!=e?e:90}},{key:"dragRotationRate",get:function(){return this._configs.dragRotationRate},set:function(e){this._configs.dragRotationRate=null!=e?e:360}},{key:"keyboardDollyRate",get:function(){return this._configs.keyboardDollyRate},set:function(e){this._configs.keyboardDollyRate=null!=e?e:15}},{key:"touchDollyRate",get:function(){return this._configs.touchDollyRate},set:function(e){this._configs.touchDollyRate=null!=e?e:.2}},{key:"mouseWheelDollyRate",get:function(){return this._configs.mouseWheelDollyRate},set:function(e){this._configs.mouseWheelDollyRate=null!=e?e:100}},{key:"dollyInertia",get:function(){return this._configs.dollyInertia},set:function(e){this._configs.dollyInertia=null!=e?e:0}},{key:"dollyProximityThreshold",get:function(){return this._configs.dollyProximityThreshold},set:function(e){this._configs.dollyProximityThreshold=null!=e?e:35}},{key:"dollyMinSpeed",get:function(){return this._configs.dollyMinSpeed},set:function(e){this._configs.dollyMinSpeed=null!=e?e:.04}},{key:"panInertia",get:function(){return this._configs.panInertia},set:function(e){this._configs.panInertia=null!=e?e:.5}},{key:"keyboardLayout",get:function(){return this._configs.keyboardLayout},set:function(e){"qwerty"!==(e=e||"qwerty")&&"azerty"!==e&&(this.error("Unsupported value for keyboardLayout - defaulting to 'qwerty'"),e="qwerty"),this._configs.keyboardLayout=e,this.keyMap=this._configs.keyboardLayout}},{key:"enablePivotSphere",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this._controllers.pivotController.enablePivotSphere(e)}},{key:"disablePivotSphere",value:function(){this._controllers.pivotController.disablePivotSphere()}},{key:"smartPivot",get:function(){return this._configs.smartPivot},set:function(e){this._configs.smartPivot=!1!==e}},{key:"doubleClickTimeFrame",get:function(){return this._configs.doubleClickTimeFrame},set:function(e){this._configs.doubleClickTimeFrame=null!=e?e:250}},{key:"zoomOnMouseWheel",get:function(){return this._configs.zoomOnMouseWheel},set:function(e){this._configs.zoomOnMouseWheel=!!e}},{key:"destroy",value:function(){this._destroyHandlers(),this._destroyControllers(),this._cameraUpdater.destroy(),v(C(n.prototype),"destroy",this).call(this)}},{key:"_destroyHandlers",value:function(){for(var e=0,t=this._handlers.length;e<t;e++){var n=this._handlers[e];n.destroy&&n.destroy()}}},{key:"_destroyControllers",value:function(){for(var e=0,t=this._controllers.length;e<t;e++){var n=this._controllers[e];n.destroy&&n.destroy()}}}]),n}(),$c=I((function e(t,n,r,i,s){x(this,e),this.name=t,this.type=r,this.value=n,this.valueType=i,this.description=s})),eu=I((function e(t){if(x(this,e),this.id=t.id,this.originalSystemId=t.originalSystemId,this.metaModels=[],this.name=t.name,this.type=t.type,this.properties=[],t.properties)for(var n=t.properties,r=0,i=n.length;r<i;r++){var s=n[r];Number.isInteger(s)?this.properties.push(s):this.properties.push(new $c(s.name,s.value,s.type,s.valueType,s.description))}})),tu=function(){function e(t){x(this,e),this.metaModels=[],this.id=t.id,this.parentId=t.parentId,this.parent=null,this.originalSystemId=t.originalSystemId,this.name=t.name,this.type=t.type,this.propertySetIds=t.propertySetIds,this.propertySets=[],this.attributes=t.attributes||{},void 0!==t.external&&null!==t.external&&(this.external=t.external)}return I(e,[{key:"metaModel",get:function(){return 1==this.metaModels.length?this.metaModels[0]:null}},{key:"getObjectIDsInSubtree",value:function(){var e=[];return function t(n){if(n){e.push(n.id);var r=n.children;if(r)for(var i=0,s=r.length;i<s;i++)t(r[i])}}(this),e}},{key:"withMetaObjectsInSubtree",value:function(e){!function t(n){if(n){e(n);var r=n.children;if(r)for(var i=0,s=r.length;i<s;i++)t(r[i])}}(this)}},{key:"getObjectIDsInSubtreeByType",value:function(e){for(var t={},n=0,r=e.length;n<r;n++)t[e[n]]=e[n];var i=[];return function e(n){if(n){t[n.type]&&i.push(n.id);var r=n.children;if(r)for(var s=0,o=r.length;s<o;s++)e(r[s])}}(this),i}},{key:"getJSON",value:function(){var e={id:this.id,type:this.type,name:this.name};return this.parent&&(e.parent=this.parent.id),e}}]),e}(),nu=function(){function e(t){x(this,e),this.id=t.id,this.projectId=t.projectId,this.revisionId=t.revisionId,this.author=t.author,this.createdAt=t.createdAt,this.creatingApplication=t.creatingApplication,this.schema=t.schema,this.metaScene=t.metaScene,this.propertySets=[],this.rootMetaObjects=[],this.metaObjects={},this.graph=t.graph||{},this.metaScene.metaModels[this.id]=this,this._propertyLookup=[],this.finalized=!1}return I(e,[{key:"rootMetaObject",get:function(){return 1===this.rootMetaObjects.length?this.rootMetaObjects[0]:null}},{key:"loadData",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.finalized)throw"MetaScene already finalized - can't add more data";this._globalizeIDs(e,t);var n=this.metaScene,r=e.properties;if(r)for(var i=0,s=r.length;i<s;i++)this._propertyLookup.push(r[i]);if(e.propertySets)for(var o=0,a=e.propertySets.length;o<a;o++){var A=e.propertySets[o];A.properties||(A.properties=[]);var c=n.propertySets[A.id];c||(c=new eu({id:A.id,originalSystemId:A.originalSystemId||A.id,type:A.type,name:A.name,properties:A.properties}),n.propertySets[c.id]=c),c.metaModels.push(this),this.propertySets.push(c)}if(e.metaObjects)for(var u=0,l=e.metaObjects.length;u<l;u++){var h=e.metaObjects[u],d=h.id,f=n.metaObjects[d];if(!f){var p=h.type,v=h.originalSystemId,g=h.propertySets||h.propertySetIds;f=new tu({id:d,originalSystemId:v,parentId:h.parent,type:p,name:h.name,attributes:h.attributes,propertySetIds:g,external:h.external}),this.metaScene.metaObjects[d]=f,f.metaModels=[]}this.metaObjects[d]=f,h.parent||(this.rootMetaObjects.push(f),n.rootMetaObjects[d]=f),f.metaModels.push(this)}}},{key:"_decompressProperties",value:function(e,t){for(var n=[],r=0,i=t.length;r<i;r++){var s=t[r];if(Number.isInteger(s)){var o=e[s];o?t[r]=o:n.push(s)}}n.length>0&&console.error("[MetaModel._decompressProperties] Properties not found: ".concat(n))}},{key:"finalize",value:function(){if(this.finalized)throw"MetaScene already finalized - can't re-finalize";var e=this.metaScene;for(var t in e.metaObjects){var n=e.metaObjects[t];if(n.children&&(n.children=[]),n.propertySets&&(n.propertySets=[]),n.propertySetIds)for(var r=0,i=n.propertySetIds.length;r<i;r++){var s=n.propertySetIds[r],o=e.propertySets[s];n.propertySets.push(o)}}for(var a in e.metaObjects){var A=e.metaObjects[a];if(A.parentId){var c=e.metaObjects[A.parentId];c&&(A.parent=c,(c.children||(c.children=[])).push(A))}}for(var u in e.metaObjects){e.metaObjects[u].metaModels=[]}for(var l in e.metaModels){var h=e.metaModels[l];for(var d in h.metaObjects){h.metaObjects[d].metaModels.push(h)}}for(var f in e.metaObjectsByType={},e.metaObjects){var p=e.metaObjects[f],v=p.type;(e.metaObjectsByType[v]||(e.metaObjectsByType[v]={}))[f]=p}if(this.propertySets)for(var g=0,m=this.propertySets.length;g<m;g++){var y=this.propertySets[g];this._decompressProperties(this._propertyLookup,y.properties)}this._propertyLookup=[],this.finalized=!0,this.metaScene.fire("metaModelCreated",this.id)}},{key:"getJSON",value:function(){for(var e={id:this.id,projectId:this.projectId,author:this.author,createdAt:this.createdAt,schema:this.schema,creatingApplication:this.creatingApplication,metaObjects:[],propertySets:[]},t=Object.values(this.metaObjects),n=0,r=t.length;n<r;n++){var i=t[n],s={id:i.id,originalSystemId:i.originalSystemId,extId:i.extId,type:i.type,name:i.name};i.parent&&(s.parent=i.parent.id),i.attributes&&(s.attributes=i.attributes),i.propertySetIds&&(s.propertySetIds=i.propertySetIds),e.metaObjects.push(s)}for(var o=0,a=this.propertySets.length;o<a;o++){for(var A=this.propertySets[o],c={id:A.id,originalSystemId:A.originalSystemId,extId:A.extId,type:A.type,name:A.name,propertyies:[]},u=0,l=A.properties.length;u<l;u++){var h=A.properties[u],d={id:h.id,description:h.description,type:h.type,name:h.name,value:h.value,valueType:h.valueType};c.properties.push(d)}e.propertySets.push(c)}return e}},{key:"_globalizeIDs",value:function(e,t){var n=!!t.globalizeObjectIds;if(e.metaObjects)for(var r=0,i=e.metaObjects.length;r<i;r++){var s=e.metaObjects[r];if(s.originalSystemId=s.id,s.parent&&(s.originalParentSystemId=s.parent),n&&(s.id=Ae.globalizeObjectId(this.id,s.id),s.parent&&(s.parent=Ae.globalizeObjectId(this.id,s.parent))),n){var o=s.propertySetIds;if(o){for(var a=[],A=0,c=o.length;A<c;A++)a.push(Ae.globalizeObjectId(this.id,o[A]));s.propertySetIds=a,s.originalSystemPropertySetIds=o}}else s.originalSystemPropertySetIds=s.propertySetIds}if(e.propertySets)for(var u=0,l=e.propertySets.length;u<l;u++){var h=e.propertySets[u];h.originalSystemId=h.id,n&&(h.id=Ae.globalizeObjectId(this.id,h.id))}}}]),e}(),ru=function(){function e(t,n){x(this,e),this.viewer=t,this.scene=n,this.metaModels={},this.propertySets={},this.metaObjects={},this.metaObjectsByType={},this.rootMetaObjects={},this._eventSubs={}}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:"off",value:function(e){}},{key:"createMetaModel",value:function(e,t){var n=new nu({metaScene:this,id:e,projectId:t.projectId||"none",revisionId:t.revisionId||"none",author:t.author||"none",createdAt:t.createdAt||"none",creatingApplication:t.creatingApplication||"none",schema:t.schema||"none",propertySets:[]});return n.loadData(t),n.finalize(),n}},{key:"destroyMetaModel",value:function(e){var t=this.metaModels[e];if(t){if(t.propertySets)for(var n=0,r=t.propertySets.length;n<r;n++){var i=t.propertySets[n];if(1===i.metaModels.length&&i.metaModels[0].id===e)delete this.propertySets[i.id];else{for(var s=[],o=0,a=i.metaModels.length;o<a;o++)i.metaModels[o].id!==e&&s.push(i.metaModels[o]);i.metaModels=s}}if(t.metaObjects)for(var A in t.metaObjects){var c=t.metaObjects[A];1===c.metaModels.length&&c.metaModels[0].id===e?(delete this.metaObjects[A],c.parent||delete this.rootMetaObjects[A]):c.metaModels=c.metaModels.filter((function(t){return t.id!==e}))}for(var u in this.metaObjects){var l=this.metaObjects[u];if(l.children&&(l.children=[]),l.propertySets&&(l.propertySets=[]),l.propertySetIds)for(var h=0,d=l.propertySetIds.length;h<d;h++){var f=l.propertySetIds[h],p=this.propertySets[f];l.propertySets.push(p)}}for(var v in this.metaObjectsByType={},this.metaObjects){var g=this.metaObjects[v],m=g.type;g.children&&(g.children=null),(this.metaObjectsByType[m]||(this.metaObjectsByType[m]={}))[v]=g}for(var y in this.metaObjects){var _=this.metaObjects[y];if(_.parentId){var b=this.metaObjects[_.parentId];b&&(_.parent=b,(b.children||(b.children=[])).push(_))}}for(var w in delete this.metaModels[e],this.metaObjects){this.metaObjects[w].metaModels=[]}for(var B in this.metaModels){var C=this.metaModels[B];for(var k in C.metaObjects){C.metaObjects[k].metaModels.push(C)}}this.fire("metaModelDestroyed",e)}}},{key:"getObjectIDsByType",value:function(e){var t=this.metaObjectsByType[e];return t?Object.keys(t):[]}},{key:"getObjectIDsInSubtree",value:function(e,t,n){var r=[],i=this.metaObjects[e],s=t&&t.length>0?iu(t):null,o=n&&n.length>0?iu(n):null;return function e(t){if(t){var n=!0;(o&&o[t.type]||s&&!s[t.type])&&(n=!1),n&&r.push(t.id);var i=t.children;if(i)for(var a=0,A=i.length;a<A;a++)e(i[a])}}(i),r}},{key:"withMetaObjectsInSubtree",value:function(e,t){var n=this.metaObjects[e];n&&n.withMetaObjectsInSubtree(t)}}]),e}();function iu(e){for(var t={},n=0,r=e.length;n<r;n++)t[e[n]]=!0;return t}
|
|
24
24
|
/*!
|
|
25
25
|
* html2canvas 1.4.1 <https://html2canvas.hertzen.com>
|
|
26
26
|
* Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>
|