@woosh/meep-engine 2.118.13 → 2.119.1

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.
Files changed (104) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/package.json +1 -5
  3. package/src/core/bvh2/bvh3/query/BVHQueryAnd.d.ts +12 -0
  4. package/src/core/bvh2/bvh3/query/BVHQueryAnd.d.ts.map +1 -0
  5. package/src/core/bvh2/bvh3/query/BVHQueryAnd.js +29 -0
  6. package/src/core/bvh2/bvh3/query/BVHQueryIntersectsAABB.d.ts +7 -0
  7. package/src/core/bvh2/bvh3/query/BVHQueryIntersectsAABB.d.ts.map +1 -0
  8. package/src/core/bvh2/bvh3/query/BVHQueryIntersectsAABB.js +22 -0
  9. package/src/core/bvh2/bvh3/query/BVHQueryIntersectsRay.js +1 -1
  10. package/src/core/geom/3d/compute_triangle_normal.d.ts +16 -4
  11. package/src/core/geom/3d/compute_triangle_normal.d.ts.map +1 -1
  12. package/src/core/geom/3d/compute_triangle_normal.js +3 -3
  13. package/src/core/geom/3d/mat4/m4_multiply.d.ts +4 -4
  14. package/src/core/geom/3d/mat4/m4_multiply.d.ts.map +1 -1
  15. package/src/core/geom/3d/mat4/m4_multiply.js +3 -3
  16. package/src/core/geom/3d/topology/computeTopoMeshVertexDuplicates.d.ts.map +1 -1
  17. package/src/core/geom/3d/topology/computeTopoMeshVertexDuplicates.js +10 -5
  18. package/src/core/geom/3d/topology/query/query_edge_is_boundary.d.ts +1 -0
  19. package/src/core/geom/3d/topology/query/query_edge_is_boundary.d.ts.map +1 -1
  20. package/src/core/geom/3d/topology/query/query_edge_is_boundary.js +1 -0
  21. package/src/core/geom/3d/topology/{isVertexConnectedToOutline.d.ts → query/query_vertex_is_boundary.d.ts} +2 -2
  22. package/src/core/geom/3d/topology/query/query_vertex_is_boundary.d.ts.map +1 -0
  23. package/src/core/geom/3d/topology/{isVertexConnectedToOutline.js → query/query_vertex_is_boundary.js} +2 -2
  24. package/src/core/geom/3d/topology/samples/prototypeFloodFill.d.ts +2 -0
  25. package/src/core/geom/3d/topology/samples/prototypeFloodFill.d.ts.map +1 -0
  26. package/src/core/geom/3d/topology/samples/{sampleFloodFill.js → prototypeFloodFill.js} +3 -3
  27. package/src/core/geom/3d/topology/simplify/EdgeCollapseCandidate.d.ts.map +1 -1
  28. package/src/core/geom/3d/topology/simplify/EdgeCollapseCandidate.js +2 -32
  29. package/src/core/geom/3d/topology/simplify/computeEdgeCollapseCost.js +3 -3
  30. package/src/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.d.ts.map +1 -1
  31. package/src/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.js +9 -15
  32. package/src/core/geom/3d/topology/simplify/edge_collapse_quadratic.d.ts.map +1 -1
  33. package/src/core/geom/3d/topology/simplify/edge_collapse_quadratic.js +2 -57
  34. package/src/core/geom/3d/topology/simplify/prototypeMeshSimplification.js +2 -2
  35. package/src/core/geom/3d/topology/simplify/quadratic/Quadratic3.d.ts.map +1 -1
  36. package/src/core/geom/3d/topology/simplify/quadratic/Quadratic3.js +18 -18
  37. package/src/core/geom/3d/topology/simplify/simplifyTopoMesh.d.ts.map +1 -1
  38. package/src/core/geom/3d/topology/simplify/simplifyTopoMesh.js +1 -0
  39. package/src/core/geom/3d/topology/simplify/tm_edge_collapse_is_degenerate_flip.d.ts.map +1 -1
  40. package/src/core/geom/3d/topology/simplify/tm_edge_collapse_is_degenerate_flip.js +2 -18
  41. package/src/core/geom/3d/topology/struct/TopoTriangle.d.ts +17 -1
  42. package/src/core/geom/3d/topology/struct/TopoTriangle.d.ts.map +1 -1
  43. package/src/core/geom/3d/topology/struct/TopoTriangle.js +60 -1
  44. package/src/core/geom/3d/topology/struct/TopoVertex.d.ts +8 -0
  45. package/src/core/geom/3d/topology/struct/TopoVertex.d.ts.map +1 -1
  46. package/src/core/geom/3d/topology/struct/TopoVertex.js +22 -1
  47. package/src/core/geom/3d/topology/{three_buffer_geometry_to_topo_mesh.d.ts → three/three_buffer_geometry_to_topo_mesh.d.ts} +1 -1
  48. package/src/core/geom/3d/topology/three/three_buffer_geometry_to_topo_mesh.d.ts.map +1 -0
  49. package/src/core/geom/3d/topology/{three_buffer_geometry_to_topo_mesh.js → three/three_buffer_geometry_to_topo_mesh.js} +1 -1
  50. package/src/core/geom/3d/topology/three/topo_mesh_to_three_buffer_geometry.d.ts.map +1 -0
  51. package/src/core/geom/3d/topology/tm_weld_duplicate_vertices.d.ts +9 -0
  52. package/src/core/geom/3d/topology/tm_weld_duplicate_vertices.d.ts.map +1 -0
  53. package/src/core/geom/3d/topology/{weld_duplicate_vertices.js → tm_weld_duplicate_vertices.js} +4 -5
  54. package/src/core/math/GOLDEN_RATIO.d.ts +1 -0
  55. package/src/core/math/GOLDEN_RATIO.d.ts.map +1 -1
  56. package/src/core/math/GOLDEN_RATIO.js +1 -0
  57. package/src/core/math/matrix/mat4x4_transpose_copy_to_mat4x3.d.ts +9 -0
  58. package/src/core/math/matrix/mat4x4_transpose_copy_to_mat4x3.d.ts.map +1 -0
  59. package/src/core/math/matrix/mat4x4_transpose_copy_to_mat4x3.js +26 -0
  60. package/src/engine/graphics/ecs/light/LightContext.d.ts.map +1 -1
  61. package/src/engine/graphics/ecs/light/LightContext.js +7 -10
  62. package/src/engine/graphics/ecs/light/binding/three/ThreeLightBinding.d.ts.map +1 -1
  63. package/src/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +4 -6
  64. package/src/engine/graphics/ecs/light/shadow/ShadowManager.d.ts.map +1 -1
  65. package/src/engine/graphics/ecs/light/shadow/ShadowManager.js +14 -15
  66. package/src/engine/graphics/geometry/AttributeGroupSpec.d.ts.map +1 -1
  67. package/src/engine/graphics/geometry/AttributeGroupSpec.js +15 -6
  68. package/src/engine/graphics/geometry/skining/computeSkinnedMeshVertices.d.ts.map +1 -1
  69. package/src/engine/graphics/geometry/skining/computeSkinnedMeshVertices.js +23 -109
  70. package/src/engine/graphics/geometry/skining/mesh_apply_skeletal_vertex_skinning.d.ts +15 -0
  71. package/src/engine/graphics/geometry/skining/mesh_apply_skeletal_vertex_skinning.d.ts.map +1 -0
  72. package/src/engine/graphics/geometry/skining/mesh_apply_skeletal_vertex_skinning.js +85 -0
  73. package/src/engine/graphics/trail/x/RibbonXPlugin.d.ts +1 -1
  74. package/src/engine/graphics/trail/x/RibbonXPlugin.d.ts.map +1 -1
  75. package/src/engine/graphics/trail/x/RibbonXPlugin.js +2 -14
  76. package/src/engine/intelligence/blackboard/BlackboardValue.d.ts +2 -2
  77. package/src/engine/intelligence/blackboard/BlackboardValue.d.ts.map +1 -1
  78. package/build/meep.cjs +0 -118569
  79. package/build/meep.min.js +0 -1
  80. package/build/meep.module.js +0 -118534
  81. package/src/__module.d.ts +0 -3
  82. package/src/__module.d.ts.map +0 -1
  83. package/src/__module.js +0 -6
  84. package/src/core/__module.d.ts +0 -21
  85. package/src/core/__module.d.ts.map +0 -1
  86. package/src/core/__module.js +0 -22
  87. package/src/core/geom/3d/topology/isEdgeConnectedToOutline.d.ts +0 -7
  88. package/src/core/geom/3d/topology/isEdgeConnectedToOutline.d.ts.map +0 -1
  89. package/src/core/geom/3d/topology/isEdgeConnectedToOutline.js +0 -13
  90. package/src/core/geom/3d/topology/isVertexConnectedToOutline.d.ts.map +0 -1
  91. package/src/core/geom/3d/topology/samples/sampleFloodFill.d.ts +0 -2
  92. package/src/core/geom/3d/topology/samples/sampleFloodFill.d.ts.map +0 -1
  93. package/src/core/geom/3d/topology/three_buffer_geometry_to_topo_mesh.d.ts.map +0 -1
  94. package/src/core/geom/3d/topology/topo_mesh_to_three_buffer_geometry.d.ts.map +0 -1
  95. package/src/core/geom/3d/topology/weld_duplicate_vertices.d.ts +0 -9
  96. package/src/core/geom/3d/topology/weld_duplicate_vertices.d.ts.map +0 -1
  97. package/src/engine/__module.d.ts +0 -18
  98. package/src/engine/__module.d.ts.map +0 -1
  99. package/src/engine/__module.js +0 -20
  100. package/src/engine/intelligence/__module.d.ts +0 -7
  101. package/src/engine/intelligence/__module.d.ts.map +0 -1
  102. package/src/engine/intelligence/__module.js +0 -6
  103. /package/src/core/geom/3d/topology/{topo_mesh_to_three_buffer_geometry.d.ts → three/topo_mesh_to_three_buffer_geometry.d.ts} +0 -0
  104. /package/src/core/geom/3d/topology/{topo_mesh_to_three_buffer_geometry.js → three/topo_mesh_to_three_buffer_geometry.js} +0 -0
package/build/meep.min.js DELETED
@@ -1 +0,0 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).MEEP={})}(this,(function(t){"use strict";function e(t,e){const i=t.length;if(i!==e.length)return!1;for(let n=0;n<i;n++)if(t[n]!==e[n])return!1;return!0}function i(t){if("object"!=typeof t)return!1;if(null===t)return!1;const e=t.constructor;return e===Uint8Array||e===Uint16Array||e===Uint32Array||e===Int8Array||e===Int16Array||e===Int32Array||e===Float32Array||e===Float64Array||e===BigUint64Array||e===BigInt64Array}class n{appendDescriptionOf(t){throw new Error("Not Implemented")}appendList(t,e,i,n){throw new Error("Not Implemented")}appendText(t){throw new Error("Not Implemented")}appendValue(t){throw new Error("Not Implemented")}appendValueList(t,e,i,n){throw new Error("Not Implemented")}}class s{describeTo(t){throw new Error("Not Implemented")}}class r extends s{value;constructor(t){super(),this.value=t}describeTo(t){t.appendValue(this.value)}}class a{#t;constructor(t){this.#t=t}*[Symbol.iterator](){for(const t of this.#t)yield new r(t)}}class o extends n{appendDescriptionOf(t){return t.describeTo(this),this}#e(t){this.appendText('"'),this.appendText(t),this.appendText('"')}appendValue(t){return null==t?this.appendText("null"):void 0===t?this.appendText("undefined"):"string"==typeof t?this.#e(t):"number"==typeof t?this.appendText(function(t){return String(t)}(t)):Array.isArray(t)?this.appendValueList("[",", ","]",t):(this.appendText("<"),this.appendText(function(t){try{return String(t)}catch(t){return"VALUE@0"}}(t)),this.appendText(">")),this}appendValueList(t,e,i,n){return this.appendList(t,e,i,new a(n)),this}appendList(t,e,i,n){let s=!1;this.appendText(t);const r=n[Symbol.iterator]();for(let t=r.next();!0!==t.done;t=r.next())s&&this.appendText(e),this.appendDescriptionOf(t.value),s=!0;return this.appendText(i),this}}class l extends o{value="";appendText(t){return this.value+=t,this}}function h(t,e){if(!t)throw new Error(e||"AssertionError")}function c(t,e,i,n){const s=i.x,r=i.y,a=i.z,o=i.w,l=s+s,h=r+r,c=a+a,u=s*l,d=s*h,p=s*c,f=r*h,m=r*c,_=a*c,g=o*l,y=o*h,v=o*c,x=n.x,w=n.y,b=n.z;t[0]=(1-(f+_))*x,t[1]=(d+v)*x,t[2]=(p-y)*x,t[3]=0,t[4]=(d-v)*w,t[5]=(1-(u+_))*w,t[6]=(m+g)*w,t[7]=0,t[8]=(p+y)*b,t[9]=(m-g)*b,t[10]=(1-(u+f))*b,t[11]=0,t[12]=e.x,t[13]=e.y,t[14]=e.z,t[15]=1}function u(t,e,i){return Math.sqrt(t*t+e*e+i*i)}h.enum=function(t,e,i="value"){for(let i in e)if(e[i]===t)return;throw new Error(`${i}(=${t}) is not a valid enumerable value, valid values are: [${Object.values(e).join(", ")}]`)},h.notEqual=function(t,e,i){h(t!==e,i)},h.notOk=function(t,e){h(!t,e)},h.equal=function(t,e,i){if(t!==e){const n=`${t} !== ${e}`;throw new Error(void 0!==i&&""!==i?`${i}. ${n}`:n)}},h.logicalyEqual=function(t,e,i){},h.ok=h,h.greaterThan=function(t,e,i){if(!(t>e)){let n="";throw void 0!==i&&(n+=i+". "),n+=`Expected ${t} > ${e}.`,new Error(n)}},h.greaterThanOrEqual=function(t,e,i){if(!(t>=e)){let n="";throw void 0!==i&&(n+=i+". "),n+=`Expected ${t} >= ${e}.`,new Error(n)}},h.lessThan=function(t,e,i){if(!(t<e)){let n="";throw void 0!==i&&(n+=i+". "),n+=`Expected ${t} < ${e}.`,new Error(n)}},h.lessThanOrEqual=function(t,e,i){if(!(t<=e)){let n="";throw void 0!==i&&(n+=i+". "),n+=`Expected ${t} <= ${e}.`,new Error(n)}},h.typeOf=function(t,e,i="value"){const n=typeof t;if(n!==e)throw new Error(`expected ${i} to be ${e}, instead was '${n}'(=${t})`)},h.arrayHas=function(t,e,i="Array does not contain the item"){},h.arrayHasNo=function(t,e,i="Array contains the item"){},h.arrayEqual=function(t,i,n="Arrays are not equal"){if(!e(t,i))throw new Error(n)},h.isInstanceOf=function(t,e,i="value",n=e.name){},h.isNumber=function(t,e="value"){const i=typeof t;if("number"!==i)throw new Error(`expected ${e} to be a number, instead was '${i}'(=${t})`)},h.isString=function(t,e="value"){const i=typeof t;if("string"!==i)throw new Error(`expected ${e} to be a string, instead was '${i}'(=${t})`)},h.isBoolean=function(t,e="value"){const i=typeof t;if("boolean"!==i)throw new Error(`expected ${e} to be a boolean, instead was '${i}'(=${t})`)},h.isFunction=function(t,e="value"){const i=typeof t;if("function"!==i)throw new Error(`expected ${e} to be a function, instead was '${i}'(=${t})`)},h.isObject=function(t,e="value"){const i=typeof t;if("object"!==i)throw new Error(`expected ${e} to be an object, instead was '${i}'(=${t})`)},h.isInteger=function(t,e="value"){if(!Number.isInteger(t))throw new Error(`${e} must be an integer, instead was ${t}`)},h.isNonNegativeInteger=function(t,e="value"){if(t<0)throw new Error(`${e} must be >= 0, instead was ${t}`)},h.isArray=function(t,e="value"){if(!Array.isArray(t))throw new Error(`expected ${e} to be an array, instead was something else (typeof ='${typeof t}')`)},h.isArrayLike=function(t,e="value"){if(!Array.isArray(t)&&!i(t))throw new Error(`expected ${e} to be an array-like structure, instead was something else (typeof ='${typeof t}')`)},h.defined=function(t,e="value"){if(void 0===t)throw new Error(`${e} is undefined`)},h.isNull=function(t,e){if(null!==t)throw new Error(`${e} is NOT null`)},h.notNull=function(t,e="value"){if(null===t)throw new Error(`${e} is null`)},h.notNaN=function(t,e="value"){if(Number.isNaN(t))throw new Error(`${e} must be a valid number, instead was NaN`)},h.isFiniteNumber=function(t,e="value"){if(!Number.isFinite(t))throw new Error(`${e} must be a finite number, instead was ${t}`)},h.that=function(t,e,i){if(i.matches(t))return;const n=new l;throw n.appendText(`Expected ${e} to be `),i.describeTo(n),n.appendText(" instead "),i.describeMismatch(t,n),new Error(n.value)};const d=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);let p=null,f=16;class m{next=null;flags=0;constructor(t,e){this.handle=t,this.context=e}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}}m.prototype.isSignalHandler=!0;class _{handlers=new Map;flags=0;get silent(){return this.getFlag(1)}set silent(t){this.writeFlag(1,t)}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}contains(t,e){const i=this.handlers.get(t);if(void 0===i)return!1;const n=function(t,e,i){let n=t;for(;;){if(n.handle===e&&n.context===i)return n;if(n=n.next,null===n)return null}}(i,t,e);return null!==n}mute(){this.setFlag(1)}unmute(){this.clearFlag(1)}hasHandlers(){return this.handlers.size>0}addOne(t,e){const i=new m(t,e);i.setFlag(1),this.#i(i)}add(t,e){const i=new m(t,e);this.#i(i)}#i(t){const e=t.handle,i=this.handlers.get(e);void 0===i||(t.next=i),this.handlers.set(e,t)}remove(t,e){const i=this.handlers.get(t);if(void 0===i)return!1;if(i.handle===t&&i.context===e)return null===i.next?this.handlers.delete(t):this.handlers.set(t,i.next),!0;let n=i,s=i.next;for(;null!==s;){if(s.handle===t&&s.context===e)return n.next=s.next,!0;n=s,s=s.next}return!1}removeAll(){this.handlers.clear()}#n(t){const e=this.handlers.get(t.handle);if(void 0===e)return!1;if(e===t)return null===e.next?this.handlers.delete(t.handle):this.handlers.set(t.handle,e.next),!0;let i=e,n=e.next;for(;null!==n;){const e=n.next;if(n===t)return i.next=e,!0;i=n,n=e}return!1}dispatch(...t){if(0!=(1&this.flags))return;const e=this.handlers;for(const i of e.values()){let e=i;do{const i=e.next;e.getFlag(1)&&this.#n(e);const n=e.handle;try{n.apply(e.context,t)}catch(t){}e=i}while(null!==e)}}send0(){if(0!=(1&this.flags))return;const t=this.handlers;for(const e of t.values()){let t=e;do{const e=t.next;t.getFlag(1)&&this.#n(t);const i=t.handle;try{i.call(t.context)}catch(t){}t=e}while(null!==t)}}send1(t){if(0!=(1&this.flags))return;const e=this.handlers;for(const i of e.values()){let e=i;do{const i=e.next;e.getFlag(1)&&this.#n(e);const n=e.handle;try{n.call(e.context,t)}catch(t){}e=i}while(null!==e)}}send2(t,e){if(0!=(1&this.flags))return;const i=this.handlers;for(const n of i.values()){let i=n;do{const n=i.next;i.getFlag(1)&&this.#n(i);const s=i.handle;try{s.call(i.context,t,e)}catch(t){}i=n}while(null!==i)}}send3(t,e,i){if(0!=(1&this.flags))return;const n=this.handlers;for(const s of n.values()){let n=s;do{const s=n.next;n.getFlag(1)&&this.#n(n);const r=n.handle;try{r.call(n.context,t,e,i)}catch(t){}n=s}while(null!==n)}}send4(t,e,i,n){if(0!=(1&this.flags))return;const s=this.handlers;for(const r of s.values()){let s=r;do{const r=s.next;s.getFlag(1)&&this.#n(s);const a=s.handle;try{a.call(s.context,t,e,i,n)}catch(t){}s=r}while(null!==s)}}send6(t,e,i,n,s,r){if(0!=(1&this.flags))return;const a=this.handlers;for(const o of a.values()){let a=o;do{const o=a.next;a.getFlag(1)&&this.#n(a);const l=a.handle;try{l.call(a.context,t,e,i,n,s,r)}catch(s){}a=o}while(null!==a)}}send8(t,e,i,n,s,r,a,o){if(0!=(1&this.flags))return;const l=this.handlers;for(const h of l.values()){let l=h;do{const h=l.next;l.getFlag(1)&&this.#n(l);const c=l.handle;try{c.call(l.context,t,e,i,n,s,r,a,o)}catch(s){}l=h}while(null!==l)}}merge(t){const e=new _;function i(){e.dispatch(arguments)}return this.add(i),t.add(i),e}}function g(t,e,i){return t<e?e:t>i?i:t}function y(t){return t<0?0:t>1?1:t}_.prototype.isSignal=!0;const v=1e-6;function x(t,e,i=v){return Math.abs(t-e)<=i}function w(t,e,i){return(e-t)*i+t}const b=4294967295;function S(t){const e=t>>0;return(t-e)*b^e}const M=Math.SQRT1_2/511;function T(t,e,i,n){return t*t+e*e+i*i+n*n}function A(t,e,i,n){return Math.sqrt(T(t,e,i,n))}function C(t,e,i,n,s,r){return t*n+e*s+i*r}function E(t){return t>0?1:t<0?-1:0}function z(t,e,i){return t*t+e*e+i*i}function I(t,e,i,n,s,r,a,o){const l=w(e,s,o),h=w(i,r,o),c=w(n,a,o);t.set(l,h,c)}let L=class t{constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i,this.onChanged=new _}readFromArray(t,e=0){this.set(t[e],t[e+1],t[e+2])}writeToArray(t,e=0){t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z}asArray(){const t=[];return this.writeToArray(t,0),t}set(t,e,i){const n=this.x,s=this.y,r=this.z;return t===n&&e===s&&i===r||(this.x=t,this.y=e,this.z=i,this.onChanged.hasHandlers()&&this.onChanged.send6(t,e,i,n,s,r)),this}setScalar(t){this.set(t,t,t)}setX(t){return this.set(t,this.y,this.z)}setY(t){return this.set(this.x,t,this.z)}setZ(t){return this.set(this.x,this.y,t)}setXY(t,e){return this.set(t,e,this.z)}setXZ(t,e){return this.set(t,this.y,e)}setYZ(t,e){return this.set(this.x,t,e)}addVectors(t,e){const i=t.x+e.x,n=t.y+e.y,s=t.z+e.z;this.set(i,n,s)}add(t){return this._add(t.x,t.y,t.z)}_add(t,e,i){return this.set(this.x+t,this.y+e,this.z+i)}subVectors(t,e){const i=t.x-e.x,n=t.y-e.y,s=t.z-e.z;this.set(i,n,s)}sub(t){return this._sub(t.x,t.y,t.z)}_sub(t,e,i){const n=this.x-t,s=this.y-e,r=this.z-i;return this.set(n,s,r)}_multiply(t,e,i){return this.set(this.x*t,this.y*e,this.z*i)}multiply(t){return this._multiply(t.x,t.y,t.z)}multiplyVectors(t,e){this.set(t.x*e.x,t.y*e.y,t.z*e.z)}subScalar(t){return this.set(this.x-t,this.y-t,this.z-t)}addScalar(t){return this.set(this.x+t,this.y+t,this.z+t)}clone(){return new t(this.x,this.y,this.z)}multiplyScalar(t){return this.set(this.x*t,this.y*t,this.z*t)}isZero(){return 0===this.x&&0===this.y&&0===this.z}cross(t){return this.crossVectors(this,t),this}crossVectors(t,e){const i=t.x,n=t.y,s=t.z,r=e.x,a=e.y,o=e.z;this._crossVectors(i,n,s,r,a,o)}_crossVectors(t,e,i,n,s,r){const a=e*r-i*s,o=i*n-t*r,l=t*s-e*n;this.set(a,o,l)}abs(){return this.set(Math.abs(this.x),Math.abs(this.y),Math.abs(this.z))}dot(e){return t.dot(this,e)}length(){return u(this.x,this.y,this.z)}lengthSqr(){return z(this.x,this.y,this.z)}normalize(){const t=this.length();if(0===t)return;const e=1/t;this.multiplyScalar(e)}isNormalized(t=1e-5){return x(this.lengthSqr(),1,t)}copy(t){return this.set(t.x,t.y,t.z)}negate(){return this.set(-this.x,-this.y,-this.z)}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceSqrTo(t){return z(this.x-t.x,this.y-t.y,this.z-t.z)}_distanceSqrTo(t,e,i){return z(this.x-t,this.y-e,this.z-i)}angleTo(t){return function(t,e,i,n,s,r){const a=function(t,e,i,n,s,r){const a=C(t,e,i,n,s,r),o=u(t,e,i)*u(n,s,r);return 0===o?0:g(a/o,-1,1)}(t,e,i,n,s,r);return Math.acos(a)}(this.x,this.y,this.z,t.x,t.y,t.z)}applyQuaternion(t){const e=this.x,i=this.y,n=this.z,s=t.x,r=t.y,a=t.z,o=t.w,l=o*e+r*n-a*i,h=o*i+a*e-s*n,c=o*n+s*i-r*e,u=-s*e-r*i-a*n,d=l*o+u*-s+h*-a-c*-r,p=h*o+u*-r+c*-s-l*-a,f=c*o+u*-a+l*-r-h*-s;this.set(d,p,f)}sign(){return this.set(E(this.x),E(this.y),E(this.z))}lerp(t,e){const i=w(this.x,t.x,e),n=w(this.y,t.y,e),s=w(this.z,t.z,e);return this.set(i,n,s)}lerpVectors(t,e,i){I(this,t.x,t.y,t.z,e.x,e.y,e.z,i)}slerpVectors(t,e,i){!function(t,e,i,n,s,r,a,o){const l=C(e,i,n,s,r,a);if(l>=1||l<=-1)return void I(t,e,i,n,s,r,a,o);const h=Math.acos(l),c=1/Math.sin(h),u=Math.sin((1-o)*h)*c,d=Math.sin(o*h)*c,p=e*u+s*d,f=i*u+r*d,m=n*u+a*d;t.set(p,f,m)}(this,t.x,t.y,t.z,e.x,e.y,e.z,i)}applyMatrix4_three(t){this.applyMatrix4(t.elements)}applyMatrix4(t){const e=this.x,i=this.y,n=this.z,s=1/(t[3]*e+t[7]*i+t[11]*n+t[15]),r=(t[0]*e+t[4]*i+t[8]*n+t[12])*s,a=(t[1]*e+t[5]*i+t[9]*n+t[13])*s,o=(t[2]*e+t[6]*i+t[10]*n+t[14])*s;this.set(r,a,o)}applyDirectionMatrix4(t){const e=this.x,i=this.y,n=this.z,s=t[0]*e+t[4]*i+t[8]*n,r=t[1]*e+t[5]*i+t[9]*n,a=t[2]*e+t[6]*i+t[10]*n,o=1/u(s,r,a);this.set(s*o,r*o,a*o)}transformDirection_three(t){const e=t.elements;this.applyDirectionMatrix4(e)}applyMatrix3_three(t){return this.applyMatrix3(t.elements),this}applyMatrix3(t){const e=this.x,i=this.y,n=this.z,s=t[0]*e+t[3]*i+t[6]*n,r=t[1]*e+t[4]*i+t[7]*n,a=t[2]*e+t[5]*i+t[8]*n;this.set(s,r,a)}threejs_setFromMatrixPosition(t){this.setFromMatrixPosition(t.elements)}setFromMatrixPosition(t){const e=t[12],i=t[13],n=t[14];this.set(e,i,n)}equals(t){return this._equals(t.x,t.y,t.z)}_equals(t,e,i){return this.x===t&&this.y===e&&this.z===i}roughlyEquals(t,e){return this._roughlyEquals(t.x,t.y,t.z,e)}_roughlyEquals(t,e,i,n=v){return x(this.x,t,n)&&x(this.y,e,n)&&x(this.z,i,n)}floor(){const t=0|this.x,e=0|this.y,i=0|this.z;this.set(t,e,i)}projectOntoVector3(t){const e=this.x,i=this.y,n=this.z,s=t.x,r=t.y,a=t.z;this._projectVectors(e,i,n,s,r,a)}_projectVectors(t,e,i,n,s,r){const a=C(t,e,i,n,s,r)/(n*n+s*s+r*r),o=n*a,l=s*a,h=r*a;this.set(o,l,h)}setFromSphericalCoords(t,e,i){const n=Math.sin(e),s=Math.cos(e),r=t*n*Math.sin(i),a=t*s,o=t*n*Math.cos(i);this.set(r,a,o)}process(t,e){return t.call(e,this.x,this.y,this.z),this.onChanged.add(t,e),this}toJSON(){return{x:this.x,y:this.y,z:this.z}}fromJSON(t){"number"==typeof t?this.setScalar(t):this.copy(t)}toString(){return`Vector3{ x:${this.x}, y:${this.y}, z:${this.z} }`}toBinaryBuffer(t){t.writeFloat64(this.x),t.writeFloat64(this.y),t.writeFloat64(this.z)}fromBinaryBuffer(t){const e=t.readFloat64(),i=t.readFloat64(),n=t.readFloat64();this.set(e,i,n)}toBinaryBufferFloat32(t){t.writeFloat32(this.x),t.writeFloat32(this.y),t.writeFloat32(this.z)}fromBinaryBufferFloat32(t){const e=t.readFloat32(),i=t.readFloat32(),n=t.readFloat32();this.set(e,i,n)}hash(){return S(this.x)^S(this.y)<<1^S(this.z)<<2}get 0(){return this.x}get 1(){return this.y}get 2(){return this.z}set 0(t){this.x=t}set 1(t){this.y=t}set 2(t){this.z=t}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}static dot(t,e){return C(t.x,t.y,t.z,e.x,e.y,e.z)}static distance(t,e){return u(t.x-e.x,t.y-e.y,t.z-e.z)}static fromArray(e,i=0){return new t(e[i],e[i+1],e[i+2])}static fromScalar(e){return new t(e,e,e)}};L.prototype.distanceToSquared=L.prototype.distanceSqrTo,L.prototype.lengthSq=L.prototype.lengthSqr,L.prototype.fromArray=L.prototype.readFromArray,L.prototype.toArray=L.prototype.writeToArray,L.zero=Object.freeze(new L(0,0,0)),L.one=Object.freeze(new L(1,1,1)),L.minus_one=Object.freeze(new L(-1,-1,-1)),L.up=Object.freeze(new L(0,1,0)),L.down=Object.freeze(new L(0,-1,0)),L.left=Object.freeze(new L(-1,0,0)),L.right=Object.freeze(new L(1,0,0)),L.forward=Object.freeze(new L(0,0,1)),L.back=Object.freeze(new L(0,0,-1)),L.prototype.isVector3=!0,L.typeName="Vector3";const N=new L,P=new L,D=new L,F=Math.sin,O=Math.cos;let R=class t{constructor(t=0,e=0,i=0,n=1){this.x=t,this.y=e,this.z=i,this.w=n,this.onChanged=new _}get 0(){return this.x}get 1(){return this.y}get 2(){return this.z}get 3(){return this.w}set 0(t){this.x=t}set 1(t){this.y=t}set 2(t){this.z=t}set 3(t){this.w=t}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}_lookRotation(t,e,i,n,s,r){N.set(t,e,i),N.normalize(),D._crossVectors(n,s,r,N.x,N.y,N.z),0===D.lengthSq()&&(1===Math.abs(r)?N.x+=.001:N.z+=.001,N.normalize(),D._crossVectors(n,s,r,N.x,N.y,N.z)),D.normalize(),P.crossVectors(N,D);const a=D.x,o=D.y,l=D.z,h=P.x,c=P.y,u=P.z,d=N.x,p=N.y,f=N.z;this.__setFromRotationMatrix(a,h,d,o,c,p,l,u,f)}lookRotation(t,e=L.up){this._lookRotation(t.x,t.y,t.z,e.x,e.y,e.z)}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}copyInverse(t){this.copy(t),this.invert()}invert(){const t=this.x,e=this.y,i=this.z,n=this.w,s=t*t+e*e+i*i+n*n;if(0===s)return void this.set(0,0,0,1);const r=1/s,a=-t*r,o=-e*r,l=-i*r,h=n*r;this.set(a,o,l,h)}angleTo(t){const e=this.x,i=this.y,n=this.z,s=this.w,r=g(e*t.x+i*t.y+n*t.z+s*t.w,-1,1),a=Math.abs(r);return 2*Math.acos(a)}fromAxisAngle(t,e){this._fromAxisAngle(t.x,t.y,t.z,e)}_fromAxisAngle(t,e,i,n){const s=.5*n,r=F(s),a=t*r,o=e*r,l=i*r,h=O(s),c=1/Math.sqrt(a*a+o*o+l*l+h*h),u=a*c,d=o*c,p=l*c,f=h*c;this.set(u,d,p,f)}computeSwingAndTwist(t,e,i){const n=this.x,s=this.y,r=this.z,a=this.w,o=C(n,s,r,t.x,t.y,t.z),l=o/(t.x*t.x+t.y*t.y+t.z*t.z),h=t.x*l,c=t.y*l,u=t.z*l;o<0?i.set(-h,-c,-u,-a):i.set(h,c,u,a),i.normalize(),e._multiplyQuaternions(n,s,r,a,-i.x,-i.y,-i.z,i.w)}computeTwistAngle(e){const i=new t,n=new t;return this.computeSwingAndTwist(e,i,n),2*Math.acos(n.w)}toAxisAngle(t){const e=2*Math.acos(this.w),i=F(.5*e);return Math.abs(i)>v?t.set(this.x/i,this.y/i,this.z/i):t.set(1,0,0),e}normalize(){let t=this.length();if(t<v)this.set(0,0,0,1);else{const e=1/t;this.multiplyScalar(e)}}multiplyScalar(t){return this.set(this.x*t,this.y*t,this.z*t,this.w*t)}multiply(t){this.multiplyQuaternions(this,t)}multiplyQuaternions(t,e){const i=t.x,n=t.y,s=t.z,r=t.w,a=e.x,o=e.y,l=e.z,h=e.w;this._multiplyQuaternions(i,n,s,r,a,o,l,h)}_multiplyQuaternions(t,e,i,n,s,r,a,o){const l=t*o+n*s+e*a-i*r,h=e*o+n*r+i*s-t*a,c=i*o+n*a+t*r-e*s,u=n*o-t*s-e*r-i*a;return this.set(l,h,c,u)}length(){return A(this.x,this.y,this.z,this.w)}rotateTowards(e,i){t.rotateTowards(this,this,e,i)}lookAt(t,e,i=L.up){const n=new L;n.subVectors(e,t),n.normalize(),this.lookRotation(n,i)}setRandom(t){this.set(t(),t(),t(),t()),this.normalize()}__setFromEuler(t,e,i,n="XYZ"){if("XYZ"===n)this.fromEulerAnglesXYZ(t,e,i);else if("YXZ"===n)this.fromEulerAnglesYXZ(t,e,i);else if("ZXY"===n)this.fromEulerAnglesZXY(t,e,i);else if("ZYX"===n)this.fromEulerAnglesZYX(t,e,i);else if("YZX"===n)this.fromEulerAnglesYZX(t,e,i);else{if("XZY"!==n)throw new Error(`Invalid order '${n}', bust be 3 capital letters consisting of X,Y and Z`);this.fromEulerAnglesXZY(t,e,i)}return this}toEulerAnglesXYZ(t){const e=this.x,i=this.y,n=this.z,s=this.w,r=s*s,a=e*e,o=i*i,l=n*n,h=2*(e*s-i*n),c=r-a-o+l,u=Math.atan2(h,c),d=2*(e*n+i*s),p=Math.asin(d),f=2*(n*s-e*i),m=r+a-o-l,_=Math.atan2(f,m);t.set(u,p,_)}toEulerAnglesYXZ(t){const e=this.x,i=this.y,n=this.z,s=this.w,r=n*n,a=e*e,o=s*s,l=i*i,h=2*(e*n+s*i),c=o-a-l+r,u=-2*(i*n-s*e),d=2*(e*i+s*n),p=o-a+l-r,f=Math.atan2(d,p),m=Math.asin(u),_=Math.atan2(h,c);t.set(m,_,f)}toEulerAnglesZYX(t){const e=this.x,i=this.y,n=this.z,s=this.w,r=e*e,a=i*i,o=n*n,l=s*s,h=2*(e*i+s*n),c=l+r-a-o,u=-2*(e*n-s*i),d=2*(i*n+s*e),p=l-r-a+o,f=Math.atan2(d,p),m=Math.asin(u),_=Math.atan2(h,c);t.set(f,m,_)}fromEulerAngles(t,e,i){return this.fromEulerAnglesXYZ(t,e,i)}fromEulerAnglesXYZ(t,e,i){const n=.5*t,s=.5*e,r=.5*i,a=F(n),o=F(s),l=F(r),h=O(n),c=O(s),u=O(r),d=a*c*u+h*o*l,p=h*o*u-a*c*l,f=h*c*l+a*o*u,m=h*c*u-a*o*l;this.set(d,p,f,m)}fromEulerAnglesYXZ(t,e,i){const n=.5*t,s=.5*e,r=.5*i,a=F(n),o=F(s),l=F(r),h=O(n),c=O(s),u=O(r),d=a*c*u+h*o*l,p=h*o*u-a*c*l,f=h*c*l-a*o*u,m=h*c*u+a*o*l;this.set(d,p,f,m)}fromEulerAnglesZXY(t,e,i){const n=.5*t,s=.5*e,r=.5*i,a=F(n),o=F(s),l=F(r),h=O(n),c=O(s),u=O(r),d=a*c*u-h*o*l,p=h*o*u+a*c*l,f=h*c*l+a*o*u,m=h*c*u-a*o*l;this.set(d,p,f,m)}fromEulerAnglesZYX(t,e,i){const n=.5*t,s=.5*e,r=.5*i,a=F(n),o=F(s),l=F(r),h=O(n),c=O(s),u=O(r),d=a*c*u-h*o*l,p=h*o*u+a*c*l,f=h*c*l-a*o*u,m=h*c*u+a*o*l;this.set(d,p,f,m)}fromEulerAnglesYZX(t,e,i){const n=.5*t,s=.5*e,r=.5*i,a=F(n),o=F(s),l=F(r),h=O(n),c=O(s),u=O(r),d=a*c*u+h*o*l,p=h*o*u+a*c*l,f=h*c*l-a*o*u,m=h*c*u-a*o*l;this.set(d,p,f,m)}fromEulerAnglesXZY(t,e,i){const n=.5*t,s=.5*e,r=.5*i,a=F(n),o=F(s),l=F(r),h=O(n),c=O(s),u=O(r),d=a*c*u-h*o*l,p=h*o*u-a*c*l,f=h*c*l+a*o*u,m=h*c*u+a*o*l;this.set(d,p,f,m)}fromUnitVectors(t,e){const i=t.x,n=t.y,s=t.z,r=e.x,a=e.y,o=e.z,l=C(i,n,s,r,a,o);if(l<-.9999999)return N.crossVectors(L.left,t),N.lengthSqr()<1e-5&&N.crossVectors(L.up,t),N.normalize(),void this.set(N.x,N.y,N.z,0);const h=Math.sqrt(2+2*l),c=1/h,u=c*(n*o-s*a),d=c*(s*r-i*o),p=c*(i*a-n*r);this.set(u,d,p,.5*h)}setFromRotationMatrix(t){const e=t.elements;this.__setFromRotationMatrix(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10])}__setFromRotationMatrix(t,e,i,n,s,r,a,o,l){const h=t+s+l;let c,u,d,p,f;return h>0?(f=Math.sqrt(h+1),p=.5*f,f=.5/f,c=(o-r)*f,u=(i-a)*f,d=(n-e)*f):t>s&&t>l?(f=Math.sqrt(1+t-s-l),c=.5*f,f=.5/f,p=(o-r)*f,u=(e+n)*f,d=(i+a)*f):s>l?(f=Math.sqrt(1+s-t-l),u=.5*f,f=.5/f,p=(i-a)*f,c=(e+n)*f,d=(r+o)*f):(f=Math.sqrt(1+l-t-s),d=.5*f,f=.5/f,p=(n-e)*f,c=(i+a)*f,u=(r+o)*f),this.set(c,u,d,p)}lerp(t,e){this.lerpQuaternions(this,t,e)}lerpQuaternions(t,e,i){const n=w(t.x,e.x,i),s=w(t.y,e.y,i),r=w(t.z,e.z,i),a=w(t.w,e.w,i);this.set(n,s,r,a)}slerpQuaternions(t,e,i){const n=t.x,s=t.y,r=t.z,a=t.w;let o,l,h,c,u,d=e.x,p=e.y,f=e.z,m=e.w;l=n*d+s*p+r*f+a*m,l<0&&(l=-l,d=-d,p=-p,f=-f,m=-m),1-l>v?(o=Math.acos(l),h=F(o),c=F((1-i)*o)/h,u=F(i*o)/h):(c=1-i,u=i);const _=c*n+u*d,g=c*s+u*p,y=c*r+u*f,x=c*a+u*m;this.set(_,g,y,x)}slerp(t,e){this.slerpQuaternions(this,t,e)}process(t){t(this.x,this.y,this.z,this.w),this.onChanged.add(t)}copy(t){return this.set(t.x,t.y,t.z,t.w)}clone(){const e=new t;return e.copy(this),e}set(t,e,i,n){const s=this.x,r=this.y,a=this.z,o=this.w;return s===t&&r===e&&a===i&&o===n||(this.x=t,this.y=e,this.z=i,this.w=n,this.onChanged.hasHandlers()&&this.onChanged.send8(t,e,i,n,s,r,a,o)),this}conjugate(){return this.set(-this.x,-this.y,-this.z,this.w)}toJSON(){return{x:this.x,y:this.y,z:this.z,w:this.w}}fromJSON(t){this.set(t.x,t.y,t.z,t.w)}toBinaryBuffer(t){t.writeFloat64(this.x),t.writeFloat64(this.y),t.writeFloat64(this.z),t.writeFloat64(this.w)}fromBinaryBuffer(t){const e=t.readFloat64(),i=t.readFloat64(),n=t.readFloat64(),s=t.readFloat64();this.set(e,i,n,s)}toBinaryBufferFloat32(t){t.writeFloat32(this.x),t.writeFloat32(this.y),t.writeFloat32(this.z),t.writeFloat32(this.w)}fromBinaryBufferFloat32(t){const e=t.readFloat32(),i=t.readFloat32(),n=t.readFloat32(),s=t.readFloat32();this.set(e,i,n,s)}decodeFromUint32(t){!function(t,e,i){const n=3&i,s=i>>12&1023,r=i>>22&1023,a=(i>>2&1023)*M-Math.SQRT1_2,o=s*M-Math.SQRT1_2,l=r*M-Math.SQRT1_2,h=1-a*a-o*o-l*l,c=Math.sqrt(h);let u,d,p,f;0===n?(u=c,d=a,p=o,f=l):1===n?(u=a,d=c,p=o,f=l):2===n?(u=a,d=o,p=c,f=l):(u=a,d=o,p=l,f=c),t[0]=u,t[1]=d,t[2]=p,t[3]=f}(this,0,t)}encodeToUint32(){return function(t,e,i,n){const s=Math.abs(t),r=Math.abs(e),a=Math.abs(i),o=Math.abs(n);let l,h,c,u,d;d=r>s?r>a?r>o?1:3:a>o?2:3:s>a?s>o?0:3:a>o?2:3,0===d?(l=e,h=i,c=n,u=t):1===d?(l=t,h=i,c=n,u=e):2===d?(l=t,h=e,c=n,u=i):(l=t,h=e,c=i,u=n),u<0&&(l=-l,h=-h,c=-c);const p=511/(A(l,h,c,u)*Math.SQRT1_2);return 3&d|(1023&Math.round(l*p+511))<<2|(1023&Math.round(h*p+511))<<12|(1023&Math.round(c*p+511))<<22}(this.x,this.y,this.z,this.w)}readFromArray(t,e=0){this.set(t[e],t[e+1],t[e+2],t[e+3])}writeToArray(t,e=0){t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w}asArray(){return[this.x,this.y,this.z,this.w]}equals(t){return this.x===t.x&&this.y===t.y&&this.z===t.z&&this.w===t.w}hash(){return S(this.x)^S(this.y)>>2^S(this.z)>>1^S(this.w)<<2}roughlyEquals(t,e){return this._roughlyEquals(t.x,t.y,t.z,t.w,e)}_roughlyEquals(t,e,i,n,s=v){return x(this.x,t,s)&&x(this.y,e,s)&&x(this.z,i,s)&&x(this.w,n,s)}random(t=Math.random){const e=t(),i=Math.sqrt(1-e),n=Math.sqrt(e),s=2*Math.PI*t(),r=2*Math.PI*t();return this.set(i*O(s),n*F(r),n*O(r),i*F(s))}toString(){return`{ x: ${this.x}, y: ${this.y}, z: ${this.z}, w: ${this.w} }`}static random(e=Math.random){const i=new t;return i.random(e),i}static fromEulerAngles(e,i,n){const s=new t;return s.fromEulerAnglesXYZ(e,i,n),s}static rotateTowards(t,e,i,n){const s=e.angleTo(i);if(0===s)t.copy(i);else{const r=y(n/s);t.slerpQuaternions(e,i,r)}}};R.prototype.fromArray=R.prototype.readFromArray,R.prototype.toArray=R.prototype.writeToArray,R.identity=Object.freeze(new R(0,0,0,1));const k=new Float32Array(16);class B{position=new L(0,0,0);rotation=new R(0,0,0,1);scale=new L(1,1,1);matrix=function(){f>=16&&(p=new ArrayBuffer(1024),f=0);const t=new Float32Array(p,64*f,16);return t.set(d),f++,t}();flags=2;constructor(){this.subscribe(this.#s,this)}get forward(){const t=L.forward.clone();return t.applyDirectionMatrix4(this.matrix),t}get up(){const t=L.up.clone();return t.applyDirectionMatrix4(this.matrix),t}get right(){const t=L.right.clone();return t.applyDirectionMatrix4(this.matrix),t}subscribe(t,e){this.position.onChanged.add(t,e),this.rotation.onChanged.add(t,e),this.scale.onChanged.add(t,e)}unsubscribe(t,e){this.position.onChanged.remove(t,e),this.rotation.onChanged.remove(t,e),this.scale.onChanged.remove(t,e)}#s(){this.getFlag(2)&&this.updateMatrix()}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}updateMatrix(){c(this.matrix,this.position,this.rotation,this.scale)}lookAt(t,e=L.up){const i=this.position,n=t.x-i.x,s=t.y-i.y,r=t.z-i.z;0===n&&0===s&&0===r||this.rotation._lookRotation(n,s,r,e.x,e.y,e.z)}fromJSON(t){const e=t.position;void 0!==e?this.position.fromJSON(e):this.position.copy(L.zero);const i=t.rotation;void 0!==i?this.rotation.fromJSON(i):this.rotation.copy(R.identity);const n=t.scale;void 0!==n?this.scale.fromJSON(n):this.scale.copy(L.one)}toJSON(){return{position:this.position.toJSON(),rotation:this.rotation.toJSON(),scale:this.scale.toJSON()}}copy(t){this.clearFlag(2),this.matrix.set(t.matrix),this.position.copy(t.position),this.rotation.copy(t.rotation),this.scale.copy(t.scale),this.flags=t.flags}clone(){const t=new B;return t.copy(this),t}equals(t){return this.position.equals(t.position)&&this.rotation.equals(t.rotation)&&this.scale.equals(t.scale)}hash(){return this.position.hash()}static fromJSON(t){const e=new B;return e.fromJSON(t),e}static fromMatrix(t){const e=new B;return e.fromMatrix4(t),e}multiplyTransforms(t,e){!function(t,e,i){const n=e[0],s=e[1],r=e[2],a=e[3],o=e[4],l=e[5],h=e[6],c=e[7],u=e[8],d=e[9],p=e[10],f=e[11],m=e[12],_=e[13],g=e[14],y=e[15];let v=i[0],x=i[1],w=i[2],b=i[3];t[0]=v*n+x*o+w*u+b*m,t[1]=v*s+x*l+w*d+b*_,t[2]=v*r+x*h+w*p+b*g,t[3]=v*a+x*c+w*f+b*y,v=i[4],x=i[5],w=i[6],b=i[7],t[4]=v*n+x*o+w*u+b*m,t[5]=v*s+x*l+w*d+b*_,t[6]=v*r+x*h+w*p+b*g,t[7]=v*a+x*c+w*f+b*y,v=i[8],x=i[9],w=i[10],b=i[11],t[8]=v*n+x*o+w*u+b*m,t[9]=v*s+x*l+w*d+b*_,t[10]=v*r+x*h+w*p+b*g,t[11]=v*a+x*c+w*f+b*y,v=i[12],x=i[13],w=i[14],b=i[15],t[12]=v*n+x*o+w*u+b*m,t[13]=v*s+x*l+w*d+b*_,t[14]=v*r+x*h+w*p+b*g,t[15]=v*a+x*c+w*f+b*y}(k,t.matrix,e.matrix),this.fromMatrix4(k)}fromMatrix4(t){const e=this.getFlag(2);this.clearFlag(2),this.matrix.set(t),function(t,e,i,n){const s=t[0],r=t[1],a=t[2],o=u(s,r,a),l=t[4],h=t[5],c=t[6],d=u(l,h,c),p=t[8],f=t[9],m=t[10],_=u(p,f,m),g=0!==o?1/o:1e7,y=0!==d?1/d:1e7,v=0!==_?1/_:1e7,x=s*g,w=r*g,b=a*g,S=l*y,M=h*y,T=c*y,A=p*v,C=f*v,E=m*v;e.set(t[12],t[13],t[14]),n.set(o,d,_),i.__setFromRotationMatrix(x,S,A,w,M,C,b,T,E)}(t,this.position,this.rotation,this.scale),this.writeFlag(2,e)}toMatrix4(t){c(t,this.position,this.rotation,this.scale)}makeIdentity(){this.fromMatrix4(d)}toString(){return`{ position: ${this.position}, rotation: ${this.rotation}, scale: ${this.scale} }`}static adjustRotation(t,e,i=Infinity){const n=new R;n.lookRotation(e),t.rotateTowards(n,i)}}B.typeName="Transform",B.prototype.isTransform=!0;var U,V="undefined"!=typeof Float32Array?Float32Array:Array;function W(){var t=new V(16);return V!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function G(t,e){return 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}function H(t,e){var i=e[0],n=e[1],s=e[2],r=e[3],a=e[4],o=e[5],l=e[6],h=e[7],c=e[8],u=e[9],d=e[10],p=e[11],f=e[12],m=e[13],_=e[14],g=e[15],y=i*o-n*a,v=i*l-s*a,x=i*h-r*a,w=n*l-s*o,b=n*h-r*o,S=s*h-r*l,M=c*m-u*f,T=c*_-d*f,A=c*g-p*f,C=u*_-d*m,E=u*g-p*m,z=d*g-p*_,I=y*z-v*E+x*C+w*A-b*T+S*M;return I?(I=1/I,t[0]=(o*z-l*E+h*C)*I,t[1]=(s*E-n*z-r*C)*I,t[2]=(m*S-_*b+g*w)*I,t[3]=(d*b-u*S-p*w)*I,t[4]=(l*A-a*z-h*T)*I,t[5]=(i*z-s*A+r*T)*I,t[6]=(_*x-f*S-g*v)*I,t[7]=(c*S-d*x+p*v)*I,t[8]=(a*E-o*A+h*M)*I,t[9]=(n*A-i*E-r*M)*I,t[10]=(f*b-m*x+g*y)*I,t[11]=(u*x-c*b-p*y)*I,t[12]=(o*T-a*C-l*M)*I,t[13]=(i*C-n*T+s*M)*I,t[14]=(m*v-f*w-_*y)*I,t[15]=(c*w-u*v+d*y)*I,t):null}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)}),U=new V(3),V!=Float32Array&&(U[0]=0,U[1]=0,U[2]=0);const j="136",q=0,J=1,$=2,Y=1,X=2,Z=3,K=0,Q=1,tt=2,et=0,it=1,nt=2,st=3,rt=4,at=5,ot=100,lt=101,ht=102,ct=103,ut=104,dt=200,pt=201,ft=202,mt=203,_t=204,gt=205,yt=206,vt=207,xt=208,wt=209,bt=210,St=0,Mt=1,Tt=2,At=3,Ct=4,Et=5,zt=6,It=7,Lt=0,Nt=1,Pt=2,Dt=0,Ft=1,Ot=2,Rt=3,kt=4,Bt=5,Ut=301,Vt=302,Wt=303,Gt=304,Ht=306,jt=307,qt=1e3,Jt=1001,$t=1002,Yt=1003,Xt=1004,Zt=1005,Kt=1006,Qt=1007,te=1008,ee=1009,ie=1010,ne=1011,se=1012,re=1013,ae=1014,oe=1015,le=1016,he=1017,ce=1018,ue=1019,de=1020,pe=1021,fe=1022,me=1023,_e=1024,ge=1025,ye=1026,ve=1027,xe=1028,we=1029,be=1030,Se=1031,Me=1032,Te=1033,Ae=33776,Ce=33777,Ee=33778,ze=33779,Ie=35840,Le=35841,Ne=35842,Pe=35843,De=36196,Fe=37492,Oe=37496,Re=37808,ke=37809,Be=37810,Ue=37811,Ve=37812,We=37813,Ge=37814,He=37815,je=37816,qe=37817,Je=37818,$e=37819,Ye=37820,Xe=37821,Ze=36492,Ke=37840,Qe=37841,ti=37842,ei=37843,ii=37844,ni=37845,si=37846,ri=37847,ai=37848,oi=37849,li=37850,hi=37851,ci=37852,ui=37853,di=2300,pi=2301,fi=2302,mi=2400,_i=2401,gi=2402,yi=3e3,vi=3001,xi=3201,wi=0,bi=1,Si=7680,Mi=35044,Ti=35048,Ai="300 es";class Ci{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const i=this._listeners;void 0===i[t]&&(i[t]=[]),-1===i[t].indexOf(e)&&i[t].push(e)}hasEventListener(t,e){if(void 0===this._listeners)return!1;const i=this._listeners;return void 0!==i[t]&&-1!==i[t].indexOf(e)}removeEventListener(t,e){if(void 0===this._listeners)return;const i=this._listeners[t];if(void 0!==i){const t=i.indexOf(e);-1!==t&&i.splice(t,1)}}dispatchEvent(t){if(void 0===this._listeners)return;const e=this._listeners[t.type];if(void 0!==e){t.target=this;const i=e.slice(0);for(let e=0,n=i.length;e<n;e++)i[e].call(this,t);t.target=null}}}const Ei=[];for(let t=0;t<256;t++)Ei[t]=(t<16?"0":"")+t.toString(16);const zi=Math.PI/180,Ii=180/Math.PI;function Li(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,i=4294967295*Math.random()|0,n=4294967295*Math.random()|0;return(Ei[255&t]+Ei[t>>8&255]+Ei[t>>16&255]+Ei[t>>24&255]+"-"+Ei[255&e]+Ei[e>>8&255]+"-"+Ei[e>>16&15|64]+Ei[e>>24&255]+"-"+Ei[63&i|128]+Ei[i>>8&255]+"-"+Ei[i>>16&255]+Ei[i>>24&255]+Ei[255&n]+Ei[n>>8&255]+Ei[n>>16&255]+Ei[n>>24&255]).toUpperCase()}function Ni(t,e,i){return Math.max(e,Math.min(i,t))}function Pi(t,e,i){return(1-i)*t+i*e}function Di(t){return 0==(t&t-1)&&0!==t}function Fi(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}let Oi,Ri=class{constructor(t=0,e=0){this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t,e){return void 0!==e?this.addVectors(t,e):(this.x+=t.x,this.y+=t.y,this)}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t,e){return void 0!==e?this.subVectors(t,e):(this.x-=t.x,this.y-=t.y,this)}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,i=this.y,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6],this.y=n[1]*e+n[4]*i+n[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e,i){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const i=Math.cos(e),n=Math.sin(e),s=this.x-t.x,r=this.y-t.y;return this.x=s*i-r*n+t.x,this.y=s*n+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}};Ri.prototype.isVector2=!0;class ki{constructor(){this.elements=[1,0,0,0,1,0,0,0,1]}set(t,e,i,n,s,r,a,o,l){const h=this.elements;return h[0]=t,h[1]=n,h[2]=a,h[3]=e,h[4]=s,h[5]=o,h[6]=i,h[7]=r,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,n=e.elements,s=this.elements,r=i[0],a=i[3],o=i[6],l=i[1],h=i[4],c=i[7],u=i[2],d=i[5],p=i[8],f=n[0],m=n[3],_=n[6],g=n[1],y=n[4],v=n[7],x=n[2],w=n[5],b=n[8];return s[0]=r*f+a*g+o*x,s[3]=r*m+a*y+o*w,s[6]=r*_+a*v+o*b,s[1]=l*f+h*g+c*x,s[4]=l*m+h*y+c*w,s[7]=l*_+h*v+c*b,s[2]=u*f+d*g+p*x,s[5]=u*m+d*y+p*w,s[8]=u*_+d*v+p*b,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],a=t[5],o=t[6],l=t[7],h=t[8];return e*r*h-e*a*l-i*s*h+i*a*o+n*s*l-n*r*o}invert(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],a=t[5],o=t[6],l=t[7],h=t[8],c=h*r-a*l,u=a*o-h*s,d=l*s-r*o,p=e*c+i*u+n*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const f=1/p;return t[0]=c*f,t[1]=(n*l-h*i)*f,t[2]=(a*i-n*r)*f,t[3]=u*f,t[4]=(h*e-n*o)*f,t[5]=(n*s-a*e)*f,t[6]=d*f,t[7]=(i*o-l*e)*f,t[8]=(r*e-i*s)*f,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return 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],this}setUvTransform(t,e,i,n,s,r,a){const o=Math.cos(s),l=Math.sin(s);return this.set(i*o,i*l,-i*(o*r+l*a)+r+t,-n*l,n*o,-n*(-l*r+o*a)+a+e,0,0,1),this}scale(t,e){const i=this.elements;return i[0]*=t,i[3]*=t,i[6]*=t,i[1]*=e,i[4]*=e,i[7]*=e,this}rotate(t){const e=Math.cos(t),i=Math.sin(t),n=this.elements,s=n[0],r=n[3],a=n[6],o=n[1],l=n[4],h=n[7];return n[0]=e*s+i*o,n[3]=e*r+i*l,n[6]=e*a+i*h,n[1]=-i*s+e*o,n[4]=-i*r+e*l,n[7]=-i*a+e*h,this}translate(t,e){const i=this.elements;return i[0]+=t*i[2],i[3]+=t*i[5],i[6]+=t*i[8],i[1]+=e*i[2],i[4]+=e*i[5],i[7]+=e*i[8],this}equals(t){const e=this.elements,i=t.elements;for(let t=0;t<9;t++)if(e[t]!==i[t])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}function Bi(t){if(0===t.length)return-Infinity;let e=t[0];for(let i=1,n=t.length;i<n;++i)t[i]>e&&(e=t[i]);return e}function Ui(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}ki.prototype.isMatrix3=!0;class Vi{static getDataURL(t){if(/^data:/i.test(t.src))return t.src;if("undefined"==typeof HTMLCanvasElement)return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{void 0===Oi&&(Oi=Ui("canvas")),Oi.width=t.width,Oi.height=t.height;const i=Oi.getContext("2d");t instanceof ImageData?i.putImageData(t,0,0):i.drawImage(t,0,0,t.width,t.height),e=Oi}return e.width>2048||e.height>2048?e.toDataURL("image/jpeg",.6):e.toDataURL("image/png")}}let Wi=0;class Gi extends Ci{constructor(t=Gi.DEFAULT_IMAGE,e=Gi.DEFAULT_MAPPING,i=Jt,n=Jt,s=Kt,r=te,a=me,o=ee,l=1,h=yi){super(),Object.defineProperty(this,"id",{value:Wi++}),this.uuid=Li(),this.name="",this.image=t,this.mipmaps=[],this.mapping=e,this.wrapS=i,this.wrapT=n,this.magFilter=s,this.minFilter=r,this.anisotropy=l,this.format=a,this.internalFormat=null,this.type=o,this.offset=new Ri(0,0),this.repeat=new Ri(1,1),this.center=new Ri(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new ki,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.encoding=h,this.userData={},this.version=0,this.onUpdate=null,this.isRenderTargetTexture=!1}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}clone(){return(new this.constructor).copy(this)}copy(t){return this.name=t.name,this.image=t.image,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.encoding=t.encoding,this.userData=JSON.parse(JSON.stringify(t.userData)),this}toJSON(t){const e=void 0===t||"string"==typeof t;if(!e&&void 0!==t.textures[this.uuid])return t.textures[this.uuid];const i={metadata:{version:4.5,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,mapping:this.mapping,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,type:this.type,encoding:this.encoding,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};if(void 0!==this.image){const n=this.image;if(void 0===n.uuid&&(n.uuid=Li()),!e&&void 0===t.images[n.uuid]){let e;if(Array.isArray(n)){e=[];for(let t=0,i=n.length;t<i;t++)n[t].isDataTexture?e.push(Hi(n[t].image)):e.push(Hi(n[t]))}else e=Hi(n);t.images[n.uuid]={uuid:n.uuid,url:e}}i.image=n.uuid}return"{}"!==JSON.stringify(this.userData)&&(i.userData=this.userData),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(300!==this.mapping)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case qt:t.x=t.x-Math.floor(t.x);break;case Jt:t.x=t.x<0?0:1;break;case $t:1===Math.abs(Math.floor(t.x)%2)?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x)}if(t.y<0||t.y>1)switch(this.wrapT){case qt:t.y=t.y-Math.floor(t.y);break;case Jt:t.y=t.y<0?0:1;break;case $t:1===Math.abs(Math.floor(t.y)%2)?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y)}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){!0===t&&this.version++}}function Hi(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?Vi.getDataURL(t):t.data?{data:Array.prototype.slice.call(t.data),width:t.width,height:t.height,type:t.data.constructor.name}:{}}Gi.DEFAULT_IMAGE=void 0,Gi.DEFAULT_MAPPING=300,Gi.prototype.isTexture=!0;let ji=class{constructor(t=0,e=0,i=0,n=1){this.x=t,this.y=e,this.z=i,this.w=n}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,i,n){return this.x=t,this.y=e,this.z=i,this.w=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=void 0!==t.w?t.w:1,this}add(t,e){return void 0!==e?this.addVectors(t,e):(this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this)}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t,e){return void 0!==e?this.subVectors(t,e):(this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this)}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,i=this.y,n=this.z,s=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*n+r[12]*s,this.y=r[1]*e+r[5]*i+r[9]*n+r[13]*s,this.z=r[2]*e+r[6]*i+r[10]*n+r[14]*s,this.w=r[3]*e+r[7]*i+r[11]*n+r[15]*s,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,i,n,s;const r=.01,a=.1,o=t.elements,l=o[0],h=o[4],c=o[8],u=o[1],d=o[5],p=o[9],f=o[2],m=o[6],_=o[10];if(Math.abs(h-u)<r&&Math.abs(c-f)<r&&Math.abs(p-m)<r){if(Math.abs(h+u)<a&&Math.abs(c+f)<a&&Math.abs(p+m)<a&&Math.abs(l+d+_-3)<a)return this.set(1,0,0,0),this;e=Math.PI;const t=(l+1)/2,o=(d+1)/2,g=(_+1)/2,y=(h+u)/4,v=(c+f)/4,x=(p+m)/4;return t>o&&t>g?t<r?(i=0,n=.707106781,s=.707106781):(i=Math.sqrt(t),n=y/i,s=v/i):o>g?o<r?(i=.707106781,n=0,s=.707106781):(n=Math.sqrt(o),i=y/n,s=x/n):g<r?(i=.707106781,n=.707106781,s=0):(s=Math.sqrt(g),i=v/s,n=x/s),this.set(i,n,s,e),this}let g=Math.sqrt((m-p)*(m-p)+(c-f)*(c-f)+(u-h)*(u-h));return Math.abs(g)<.001&&(g=1),this.x=(m-p)/g,this.y=(c-f)/g,this.z=(u-h)/g,this.w=Math.acos((l+d+_-1)/2),this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this.w=Math.max(t.w,Math.min(e.w,this.w)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this.w=Math.max(t,Math.min(e,this.w)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z),this.w=this.w<0?Math.ceil(this.w):Math.floor(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this.w=t.w+(e.w-t.w)*i,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e,i){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}};ji.prototype.isVector4=!0;class qi extends Ci{constructor(t,e,i={}){super(),this.width=t,this.height=e,this.depth=1,this.scissor=new ji(0,0,t,e),this.scissorTest=!1,this.viewport=new ji(0,0,t,e),this.texture=new Gi(void 0,i.mapping,i.wrapS,i.wrapT,i.magFilter,i.minFilter,i.format,i.type,i.anisotropy,i.encoding),this.texture.isRenderTargetTexture=!0,this.texture.image={width:t,height:e,depth:1},this.texture.generateMipmaps=void 0!==i.generateMipmaps&&i.generateMipmaps,this.texture.internalFormat=void 0!==i.internalFormat?i.internalFormat:null,this.texture.minFilter=void 0!==i.minFilter?i.minFilter:Kt,this.depthBuffer=void 0===i.depthBuffer||i.depthBuffer,this.stencilBuffer=void 0!==i.stencilBuffer&&i.stencilBuffer,this.depthTexture=void 0!==i.depthTexture?i.depthTexture:null}setTexture(t){t.image={width:this.width,height:this.height,depth:this.depth},this.texture=t}setSize(t,e,i=1){this.width===t&&this.height===e&&this.depth===i||(this.width=t,this.height=e,this.depth=i,this.texture.image.width=t,this.texture.image.height=e,this.texture.image.depth=i,this.dispose()),this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e)}clone(){return(new this.constructor).copy(this)}copy(t){return this.width=t.width,this.height=t.height,this.depth=t.depth,this.viewport.copy(t.viewport),this.texture=t.texture.clone(),this.texture.image={...this.texture.image},this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,this.depthTexture=t.depthTexture,this}dispose(){this.dispatchEvent({type:"dispose"})}}qi.prototype.isWebGLRenderTarget=!0,class extends qi{constructor(t,e,i){super(t,e);const n=this.texture;this.texture=[];for(let t=0;t<i;t++)this.texture[t]=n.clone()}setSize(t,e,i=1){if(this.width!==t||this.height!==e||this.depth!==i){this.width=t,this.height=e,this.depth=i;for(let n=0,s=this.texture.length;n<s;n++)this.texture[n].image.width=t,this.texture[n].image.height=e,this.texture[n].image.depth=i;this.dispose()}return this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e),this}copy(t){this.dispose(),this.width=t.width,this.height=t.height,this.depth=t.depth,this.viewport.set(0,0,this.width,this.height),this.scissor.set(0,0,this.width,this.height),this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,this.depthTexture=t.depthTexture,this.texture.length=0;for(let e=0,i=t.texture.length;e<i;e++)this.texture[e]=t.texture[e].clone();return this}}.prototype.isWebGLMultipleRenderTargets=!0;class Ji extends qi{constructor(t,e,i={}){super(t,e,i),this.samples=4,this.ignoreDepthForMultisampleCopy=void 0===i.ignoreDepth||i.ignoreDepth,this.useRenderToTexture=void 0!==i.useRenderToTexture&&i.useRenderToTexture,this.useRenderbuffer=!1===this.useRenderToTexture}copy(t){return super.copy.call(this,t),this.samples=t.samples,this.useRenderToTexture=t.useRenderToTexture,this.useRenderbuffer=t.useRenderbuffer,this}}Ji.prototype.isWebGLMultisampleRenderTarget=!0;class $i{constructor(t=0,e=0,i=0,n=1){this._x=t,this._y=e,this._z=i,this._w=n}static slerp(t,e,i,n){return i.slerpQuaternions(t,e,n)}static slerpFlat(t,e,i,n,s,r,a){let o=i[n+0],l=i[n+1],h=i[n+2],c=i[n+3];const u=s[r+0],d=s[r+1],p=s[r+2],f=s[r+3];if(0===a)return t[e+0]=o,t[e+1]=l,t[e+2]=h,void(t[e+3]=c);if(1===a)return t[e+0]=u,t[e+1]=d,t[e+2]=p,void(t[e+3]=f);if(c!==f||o!==u||l!==d||h!==p){let t=1-a;const e=o*u+l*d+h*p+c*f,i=e>=0?1:-1,n=1-e*e;if(n>Number.EPSILON){const s=Math.sqrt(n),r=Math.atan2(s,e*i);t=Math.sin(t*r)/s,a=Math.sin(a*r)/s}const s=a*i;if(o=o*t+u*s,l=l*t+d*s,h=h*t+p*s,c=c*t+f*s,t===1-a){const t=1/Math.sqrt(o*o+l*l+h*h+c*c);o*=t,l*=t,h*=t,c*=t}}t[e]=o,t[e+1]=l,t[e+2]=h,t[e+3]=c}static multiplyQuaternionsFlat(t,e,i,n,s,r){const a=i[n],o=i[n+1],l=i[n+2],h=i[n+3],c=s[r],u=s[r+1],d=s[r+2],p=s[r+3];return t[e]=a*p+h*c+o*d-l*u,t[e+1]=o*p+h*u+l*c-a*d,t[e+2]=l*p+h*d+a*u-o*c,t[e+3]=h*p-a*c-o*u-l*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,i,n){return this._x=t,this._y=e,this._z=i,this._w=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e){if(!t||!t.isEuler)throw new Error("THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.");const i=t._x,n=t._y,s=t._z,r=t._order,a=Math.cos,o=Math.sin,l=a(i/2),h=a(n/2),c=a(s/2),u=o(i/2),d=o(n/2),p=o(s/2);switch(r){case"XYZ":this._x=u*h*c+l*d*p,this._y=l*d*c-u*h*p,this._z=l*h*p+u*d*c,this._w=l*h*c-u*d*p;break;case"YXZ":this._x=u*h*c+l*d*p,this._y=l*d*c-u*h*p,this._z=l*h*p-u*d*c,this._w=l*h*c+u*d*p;break;case"ZXY":this._x=u*h*c-l*d*p,this._y=l*d*c+u*h*p,this._z=l*h*p+u*d*c,this._w=l*h*c-u*d*p;break;case"ZYX":this._x=u*h*c-l*d*p,this._y=l*d*c+u*h*p,this._z=l*h*p-u*d*c,this._w=l*h*c+u*d*p;break;case"YZX":this._x=u*h*c+l*d*p,this._y=l*d*c+u*h*p,this._z=l*h*p-u*d*c,this._w=l*h*c-u*d*p;break;case"XZY":this._x=u*h*c-l*d*p,this._y=l*d*c-u*h*p,this._z=l*h*p+u*d*c,this._w=l*h*c+u*d*p}return!1!==e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,n=Math.sin(i);return this._x=t.x*n,this._y=t.y*n,this._z=t.z*n,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],n=e[4],s=e[8],r=e[1],a=e[5],o=e[9],l=e[2],h=e[6],c=e[10],u=i+a+c;if(u>0){const t=.5/Math.sqrt(u+1);this._w=.25/t,this._x=(h-o)*t,this._y=(s-l)*t,this._z=(r-n)*t}else if(i>a&&i>c){const t=2*Math.sqrt(1+i-a-c);this._w=(h-o)/t,this._x=.25*t,this._y=(n+r)/t,this._z=(s+l)/t}else if(a>c){const t=2*Math.sqrt(1+a-i-c);this._w=(s-l)/t,this._x=(n+r)/t,this._y=.25*t,this._z=(o+h)/t}else{const t=2*Math.sqrt(1+c-i-a);this._w=(r-n)/t,this._x=(s+l)/t,this._y=(o+h)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<Number.EPSILON?(i=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(Ni(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(0===i)return this;const n=Math.min(1,e/i);return this.slerp(t,n),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t,e){return void 0!==e?this.multiplyQuaternions(t,e):this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const i=t._x,n=t._y,s=t._z,r=t._w,a=e._x,o=e._y,l=e._z,h=e._w;return this._x=i*h+r*a+n*l-s*o,this._y=n*h+r*o+s*a-i*l,this._z=s*h+r*l+i*o-n*a,this._w=r*h-i*a-n*o-s*l,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const i=this._x,n=this._y,s=this._z,r=this._w;let a=r*t._w+i*t._x+n*t._y+s*t._z;if(a<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,a=-a):this.copy(t),a>=1)return this._w=r,this._x=i,this._y=n,this._z=s,this;const o=1-a*a;if(o<=Number.EPSILON){const t=1-e;return this._w=t*r+e*this._w,this._x=t*i+e*this._x,this._y=t*n+e*this._y,this._z=t*s+e*this._z,this.normalize(),this._onChangeCallback(),this}const l=Math.sqrt(o),h=Math.atan2(l,a),c=Math.sin((1-e)*h)/l,u=Math.sin(e*h)/l;return this._w=r*c+this._w*u,this._x=i*c+this._x*u,this._y=n*c+this._y*u,this._z=s*c+this._z*u,this._onChangeCallback(),this}slerpQuaternions(t,e,i){this.copy(t).slerp(e,i)}random(){const t=Math.random(),e=Math.sqrt(1-t),i=Math.sqrt(t),n=2*Math.PI*Math.random(),s=2*Math.PI*Math.random();return this.set(e*Math.cos(n),i*Math.sin(s),i*Math.cos(s),e*Math.sin(n))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}}$i.prototype.isQuaternion=!0;class Yi{constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i}set(t,e,i){return void 0===i&&(i=this.z),this.x=t,this.y=e,this.z=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t,e){return void 0!==e?this.addVectors(t,e):(this.x+=t.x,this.y+=t.y,this.z+=t.z,this)}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t,e){return void 0!==e?this.subVectors(t,e):(this.x-=t.x,this.y-=t.y,this.z-=t.z,this)}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t,e){return void 0!==e?this.multiplyVectors(t,e):(this.x*=t.x,this.y*=t.y,this.z*=t.z,this)}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return!t||t.isEuler,this.applyQuaternion(Zi.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Zi.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,n=this.z,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6]*n,this.y=s[1]*e+s[4]*i+s[7]*n,this.z=s[2]*e+s[5]*i+s[8]*n,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,n=this.z,s=t.elements,r=1/(s[3]*e+s[7]*i+s[11]*n+s[15]);return this.x=(s[0]*e+s[4]*i+s[8]*n+s[12])*r,this.y=(s[1]*e+s[5]*i+s[9]*n+s[13])*r,this.z=(s[2]*e+s[6]*i+s[10]*n+s[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,n=this.z,s=t.x,r=t.y,a=t.z,o=t.w,l=o*e+r*n-a*i,h=o*i+a*e-s*n,c=o*n+s*i-r*e,u=-s*e-r*i-a*n;return this.x=l*o+u*-s+h*-a-c*-r,this.y=h*o+u*-r+c*-s-l*-a,this.z=c*o+u*-a+l*-r-h*-s,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,i=this.y,n=this.z,s=t.elements;return this.x=s[0]*e+s[4]*i+s[8]*n,this.y=s[1]*e+s[5]*i+s[9]*n,this.z=s[2]*e+s[6]*i+s[10]*n,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t,e){return void 0!==e?this.crossVectors(t,e):this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,n=t.y,s=t.z,r=e.x,a=e.y,o=e.z;return this.x=n*o-s*a,this.y=s*r-i*o,this.z=i*a-n*r,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return Xi.copy(this).projectOnVector(t),this.sub(Xi)}reflect(t){return this.sub(Xi.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(Ni(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,n=this.z-t.z;return e*e+i*i+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,i){const n=Math.sin(e)*t;return this.x=n*Math.sin(i),this.y=Math.cos(e)*t,this.z=n*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),i=this.setFromMatrixColumn(t,1).length(),n=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=n,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e,i){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=2*(Math.random()-.5),e=Math.random()*Math.PI*2,i=Math.sqrt(1-t**2);return this.x=i*Math.cos(e),this.y=i*Math.sin(e),this.z=t,this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}Yi.prototype.isVector3=!0;const Xi=new Yi,Zi=new $i;class Ki{constructor(t=new Yi(Infinity,Infinity,Infinity),e=new Yi(-Infinity,-Infinity,-Infinity)){this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){let e=Infinity,i=Infinity,n=Infinity,s=-Infinity,r=-Infinity,a=-Infinity;for(let o=0,l=t.length;o<l;o+=3){const l=t[o],h=t[o+1],c=t[o+2];l<e&&(e=l),h<i&&(i=h),c<n&&(n=c),l>s&&(s=l),h>r&&(r=h),c>a&&(a=c)}return this.min.set(e,i,n),this.max.set(s,r,a),this}setFromBufferAttribute(t){let e=Infinity,i=Infinity,n=Infinity,s=-Infinity,r=-Infinity,a=-Infinity;for(let o=0,l=t.count;o<l;o++){const l=t.getX(o),h=t.getY(o),c=t.getZ(o);l<e&&(e=l),h<i&&(i=h),c<n&&(n=c),l>s&&(s=l),h>r&&(r=h),c>a&&(a=c)}return this.min.set(e,i,n),this.max.set(s,r,a),this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=tn.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),this}setFromObject(t){return this.makeEmpty(),this.expandByObject(t)}clone(){return(new this.constructor).copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=Infinity,this.max.x=this.max.y=this.max.z=-Infinity,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t){t.updateWorldMatrix(!1,!1);const e=t.geometry;void 0!==e&&(null===e.boundingBox&&e.computeBoundingBox(),en.copy(e.boundingBox),en.applyMatrix4(t.matrixWorld),this.union(en));const i=t.children;for(let t=0,e=i.length;t<e;t++)this.expandByObject(i[t]);return this}containsPoint(t){return!(t.x<this.min.x||t.x>this.max.x||t.y<this.min.y||t.y>this.max.y||t.z<this.min.z||t.z>this.max.z)}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return!(t.max.x<this.min.x||t.min.x>this.max.x||t.max.y<this.min.y||t.min.y>this.max.y||t.max.z<this.min.z||t.min.z>this.max.z)}intersectsSphere(t){return this.clampPoint(t.center,tn),tn.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,i;return t.normal.x>0?(e=t.normal.x*this.min.x,i=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,i=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,i+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,i+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,i+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,i+=t.normal.z*this.min.z),e<=-t.constant&&i>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(hn),cn.subVectors(this.max,hn),nn.subVectors(t.a,hn),sn.subVectors(t.b,hn),rn.subVectors(t.c,hn),an.subVectors(sn,nn),on.subVectors(rn,sn),ln.subVectors(nn,rn);let e=[0,-an.z,an.y,0,-on.z,on.y,0,-ln.z,ln.y,an.z,0,-an.x,on.z,0,-on.x,ln.z,0,-ln.x,-an.y,an.x,0,-on.y,on.x,0,-ln.y,ln.x,0];return!!pn(e,nn,sn,rn,cn)&&(e=[1,0,0,0,1,0,0,0,1],!!pn(e,nn,sn,rn,cn)&&(un.crossVectors(an,on),e=[un.x,un.y,un.z],pn(e,nn,sn,rn,cn)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return tn.copy(t).clamp(this.min,this.max).sub(t).length()}getBoundingSphere(t){return this.getCenter(t.center),t.radius=.5*this.getSize(tn).length(),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()||(Qi[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Qi[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Qi[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Qi[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Qi[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Qi[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Qi[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Qi[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Qi)),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}Ki.prototype.isBox3=!0;const Qi=[new Yi,new Yi,new Yi,new Yi,new Yi,new Yi,new Yi,new Yi],tn=new Yi,en=new Ki,nn=new Yi,sn=new Yi,rn=new Yi,an=new Yi,on=new Yi,ln=new Yi,hn=new Yi,cn=new Yi,un=new Yi,dn=new Yi;function pn(t,e,i,n,s){for(let r=0,a=t.length-3;r<=a;r+=3){dn.fromArray(t,r);const a=s.x*Math.abs(dn.x)+s.y*Math.abs(dn.y)+s.z*Math.abs(dn.z),o=e.dot(dn),l=i.dot(dn),h=n.dot(dn);if(Math.max(-Math.max(o,l,h),Math.min(o,l,h))>a)return!1}return!0}const fn=new Ki,mn=new Yi,_n=new Yi,gn=new Yi;class yn{constructor(t=new Yi,e=-1){this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const i=this.center;void 0!==e?i.copy(e):fn.setFromPoints(t).getCenter(i);let n=0;for(let e=0,s=t.length;e<s;e++)n=Math.max(n,i.distanceToSquared(t[e]));return this.radius=Math.sqrt(n),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const i=this.center.distanceToSquared(t);return e.copy(t),i>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){gn.subVectors(t,this.center);const e=gn.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),i=.5*(t-this.radius);this.center.add(gn.multiplyScalar(i/t)),this.radius+=i}return this}union(t){return!0===this.center.equals(t.center)?_n.set(0,0,1).multiplyScalar(t.radius):_n.subVectors(t.center,this.center).normalize().multiplyScalar(t.radius),this.expandByPoint(mn.copy(t.center).add(_n)),this.expandByPoint(mn.copy(t.center).sub(_n)),this}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const vn=new Yi,xn=new Yi,wn=new Yi,bn=new Yi,Sn=new Yi,Mn=new Yi,Tn=new Yi;class An{constructor(t=new Yi,e=new Yi(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.direction).multiplyScalar(t).add(this.origin)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,vn)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const i=e.dot(this.direction);return i<0?e.copy(this.origin):e.copy(this.direction).multiplyScalar(i).add(this.origin)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=vn.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(vn.copy(this.direction).multiplyScalar(e).add(this.origin),vn.distanceToSquared(t))}distanceSqToSegment(t,e,i,n){xn.copy(t).add(e).multiplyScalar(.5),wn.copy(e).sub(t).normalize(),bn.copy(this.origin).sub(xn);const s=.5*t.distanceTo(e),r=-this.direction.dot(wn),a=bn.dot(this.direction),o=-bn.dot(wn),l=bn.lengthSq(),h=Math.abs(1-r*r);let c,u,d,p;if(h>0)if(c=r*o-a,u=r*a-o,p=s*h,c>=0)if(u>=-p)if(u<=p){const t=1/h;c*=t,u*=t,d=c*(c+r*u+2*a)+u*(r*c+u+2*o)+l}else u=s,c=Math.max(0,-(r*u+a)),d=-c*c+u*(u+2*o)+l;else u=-s,c=Math.max(0,-(r*u+a)),d=-c*c+u*(u+2*o)+l;else u<=-p?(c=Math.max(0,-(-r*s+a)),u=c>0?-s:Math.min(Math.max(-s,-o),s),d=-c*c+u*(u+2*o)+l):u<=p?(c=0,u=Math.min(Math.max(-s,-o),s),d=u*(u+2*o)+l):(c=Math.max(0,-(r*s+a)),u=c>0?s:Math.min(Math.max(-s,-o),s),d=-c*c+u*(u+2*o)+l);else u=r>0?-s:s,c=Math.max(0,-(r*u+a)),d=-c*c+u*(u+2*o)+l;return i&&i.copy(this.direction).multiplyScalar(c).add(this.origin),n&&n.copy(wn).multiplyScalar(u).add(xn),d}intersectSphere(t,e){vn.subVectors(t.center,this.origin);const i=vn.dot(this.direction),n=vn.dot(vn)-i*i,s=t.radius*t.radius;if(n>s)return null;const r=Math.sqrt(s-n),a=i-r,o=i+r;return a<0&&o<0?null:a<0?this.at(o,e):this.at(a,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;const i=-(this.origin.dot(t.normal)+t.constant)/e;return i>=0?i:null}intersectPlane(t,e){const i=this.distanceToPlane(t);return null===i?null:this.at(i,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return 0===e||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let i,n,s,r,a,o;const l=1/this.direction.x,h=1/this.direction.y,c=1/this.direction.z,u=this.origin;return l>=0?(i=(t.min.x-u.x)*l,n=(t.max.x-u.x)*l):(i=(t.max.x-u.x)*l,n=(t.min.x-u.x)*l),h>=0?(s=(t.min.y-u.y)*h,r=(t.max.y-u.y)*h):(s=(t.max.y-u.y)*h,r=(t.min.y-u.y)*h),i>r||s>n?null:((s>i||i!=i)&&(i=s),(r<n||n!=n)&&(n=r),c>=0?(a=(t.min.z-u.z)*c,o=(t.max.z-u.z)*c):(a=(t.max.z-u.z)*c,o=(t.min.z-u.z)*c),i>o||a>n?null:((a>i||i!=i)&&(i=a),(o<n||n!=n)&&(n=o),n<0?null:this.at(i>=0?i:n,e)))}intersectsBox(t){return null!==this.intersectBox(t,vn)}intersectTriangle(t,e,i,n,s){Sn.subVectors(e,t),Mn.subVectors(i,t),Tn.crossVectors(Sn,Mn);let r,a=this.direction.dot(Tn);if(a>0){if(n)return null;r=1}else{if(!(a<0))return null;r=-1,a=-a}bn.subVectors(this.origin,t);const o=r*this.direction.dot(Mn.crossVectors(bn,Mn));if(o<0)return null;const l=r*this.direction.dot(Sn.cross(bn));if(l<0)return null;if(o+l>a)return null;const h=-r*bn.dot(Tn);return h<0?null:this.at(h/a,s)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return(new this.constructor).copy(this)}}class Cn{constructor(){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}set(t,e,i,n,s,r,a,o,l,h,c,u,d,p,f,m){const _=this.elements;return _[0]=t,_[4]=e,_[8]=i,_[12]=n,_[1]=s,_[5]=r,_[9]=a,_[13]=o,_[2]=l,_[6]=h,_[10]=c,_[14]=u,_[3]=d,_[7]=p,_[11]=f,_[15]=m,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return(new Cn).fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,i){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,i=t.elements,n=1/En.setFromMatrixColumn(t,0).length(),s=1/En.setFromMatrixColumn(t,1).length(),r=1/En.setFromMatrixColumn(t,2).length();return e[0]=i[0]*n,e[1]=i[1]*n,e[2]=i[2]*n,e[3]=0,e[4]=i[4]*s,e[5]=i[5]*s,e[6]=i[6]*s,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){!t||t.isEuler;const e=this.elements,i=t.x,n=t.y,s=t.z,r=Math.cos(i),a=Math.sin(i),o=Math.cos(n),l=Math.sin(n),h=Math.cos(s),c=Math.sin(s);if("XYZ"===t.order){const t=r*h,i=r*c,n=a*h,s=a*c;e[0]=o*h,e[4]=-o*c,e[8]=l,e[1]=i+n*l,e[5]=t-s*l,e[9]=-a*o,e[2]=s-t*l,e[6]=n+i*l,e[10]=r*o}else if("YXZ"===t.order){const t=o*h,i=o*c,n=l*h,s=l*c;e[0]=t+s*a,e[4]=n*a-i,e[8]=r*l,e[1]=r*c,e[5]=r*h,e[9]=-a,e[2]=i*a-n,e[6]=s+t*a,e[10]=r*o}else if("ZXY"===t.order){const t=o*h,i=o*c,n=l*h,s=l*c;e[0]=t-s*a,e[4]=-r*c,e[8]=n+i*a,e[1]=i+n*a,e[5]=r*h,e[9]=s-t*a,e[2]=-r*l,e[6]=a,e[10]=r*o}else if("ZYX"===t.order){const t=r*h,i=r*c,n=a*h,s=a*c;e[0]=o*h,e[4]=n*l-i,e[8]=t*l+s,e[1]=o*c,e[5]=s*l+t,e[9]=i*l-n,e[2]=-l,e[6]=a*o,e[10]=r*o}else if("YZX"===t.order){const t=r*o,i=r*l,n=a*o,s=a*l;e[0]=o*h,e[4]=s-t*c,e[8]=n*c+i,e[1]=c,e[5]=r*h,e[9]=-a*h,e[2]=-l*h,e[6]=i*c+n,e[10]=t-s*c}else if("XZY"===t.order){const t=r*o,i=r*l,n=a*o,s=a*l;e[0]=o*h,e[4]=-c,e[8]=l*h,e[1]=t*c+s,e[5]=r*h,e[9]=i*c-n,e[2]=n*c-i,e[6]=a*h,e[10]=s*c+t}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(In,t,Ln)}lookAt(t,e,i){const n=this.elements;return Dn.subVectors(t,e),0===Dn.lengthSq()&&(Dn.z=1),Dn.normalize(),Nn.crossVectors(i,Dn),0===Nn.lengthSq()&&(1===Math.abs(i.z)?Dn.x+=1e-4:Dn.z+=1e-4,Dn.normalize(),Nn.crossVectors(i,Dn)),Nn.normalize(),Pn.crossVectors(Dn,Nn),n[0]=Nn.x,n[4]=Pn.x,n[8]=Dn.x,n[1]=Nn.y,n[5]=Pn.y,n[9]=Dn.y,n[2]=Nn.z,n[6]=Pn.z,n[10]=Dn.z,this}multiply(t,e){return void 0!==e?this.multiplyMatrices(t,e):this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,n=e.elements,s=this.elements,r=i[0],a=i[4],o=i[8],l=i[12],h=i[1],c=i[5],u=i[9],d=i[13],p=i[2],f=i[6],m=i[10],_=i[14],g=i[3],y=i[7],v=i[11],x=i[15],w=n[0],b=n[4],S=n[8],M=n[12],T=n[1],A=n[5],C=n[9],E=n[13],z=n[2],I=n[6],L=n[10],N=n[14],P=n[3],D=n[7],F=n[11],O=n[15];return s[0]=r*w+a*T+o*z+l*P,s[4]=r*b+a*A+o*I+l*D,s[8]=r*S+a*C+o*L+l*F,s[12]=r*M+a*E+o*N+l*O,s[1]=h*w+c*T+u*z+d*P,s[5]=h*b+c*A+u*I+d*D,s[9]=h*S+c*C+u*L+d*F,s[13]=h*M+c*E+u*N+d*O,s[2]=p*w+f*T+m*z+_*P,s[6]=p*b+f*A+m*I+_*D,s[10]=p*S+f*C+m*L+_*F,s[14]=p*M+f*E+m*N+_*O,s[3]=g*w+y*T+v*z+x*P,s[7]=g*b+y*A+v*I+x*D,s[11]=g*S+y*C+v*L+x*F,s[15]=g*M+y*E+v*N+x*O,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[4],n=t[8],s=t[12],r=t[1],a=t[5],o=t[9],l=t[13],h=t[2],c=t[6],u=t[10],d=t[14];return t[3]*(+s*o*c-n*l*c-s*a*u+i*l*u+n*a*d-i*o*d)+t[7]*(+e*o*d-e*l*u+s*r*u-n*r*d+n*l*h-s*o*h)+t[11]*(+e*l*c-e*a*d-s*r*c+i*r*d+s*a*h-i*l*h)+t[15]*(-n*a*h-e*o*c+e*a*u+n*r*c-i*r*u+i*o*h)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,i){const n=this.elements;return t.isVector3?(n[12]=t.x,n[13]=t.y,n[14]=t.z):(n[12]=t,n[13]=e,n[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],a=t[5],o=t[6],l=t[7],h=t[8],c=t[9],u=t[10],d=t[11],p=t[12],f=t[13],m=t[14],_=t[15],g=c*m*l-f*u*l+f*o*d-a*m*d-c*o*_+a*u*_,y=p*u*l-h*m*l-p*o*d+r*m*d+h*o*_-r*u*_,v=h*f*l-p*c*l+p*a*d-r*f*d-h*a*_+r*c*_,x=p*c*o-h*f*o-p*a*u+r*f*u+h*a*m-r*c*m,w=e*g+i*y+n*v+s*x;if(0===w)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const b=1/w;return t[0]=g*b,t[1]=(f*u*s-c*m*s-f*n*d+i*m*d+c*n*_-i*u*_)*b,t[2]=(a*m*s-f*o*s+f*n*l-i*m*l-a*n*_+i*o*_)*b,t[3]=(c*o*s-a*u*s-c*n*l+i*u*l+a*n*d-i*o*d)*b,t[4]=y*b,t[5]=(h*m*s-p*u*s+p*n*d-e*m*d-h*n*_+e*u*_)*b,t[6]=(p*o*s-r*m*s-p*n*l+e*m*l+r*n*_-e*o*_)*b,t[7]=(r*u*s-h*o*s+h*n*l-e*u*l-r*n*d+e*o*d)*b,t[8]=v*b,t[9]=(p*c*s-h*f*s-p*i*d+e*f*d+h*i*_-e*c*_)*b,t[10]=(r*f*s-p*a*s+p*i*l-e*f*l-r*i*_+e*a*_)*b,t[11]=(h*a*s-r*c*s-h*i*l+e*c*l+r*i*d-e*a*d)*b,t[12]=x*b,t[13]=(h*f*n-p*c*n+p*i*u-e*f*u-h*i*m+e*c*m)*b,t[14]=(p*a*n-r*f*n-p*i*o+e*f*o+r*i*m-e*a*m)*b,t[15]=(r*c*n-h*a*n+h*i*o-e*c*o-r*i*u+e*a*u)*b,this}scale(t){const e=this.elements,i=t.x,n=t.y,s=t.z;return e[0]*=i,e[4]*=n,e[8]*=s,e[1]*=i,e[5]*=n,e[9]*=s,e[2]*=i,e[6]*=n,e[10]*=s,e[3]*=i,e[7]*=n,e[11]*=s,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],n=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,n))}makeTranslation(t,e,i){return this.set(1,0,0,t,0,1,0,e,0,0,1,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),n=Math.sin(e),s=1-i,r=t.x,a=t.y,o=t.z,l=s*r,h=s*a;return this.set(l*r+i,l*a-n*o,l*o+n*a,0,l*a+n*o,h*a+i,h*o-n*r,0,l*o-n*a,h*o+n*r,s*o*o+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,n,s,r){return this.set(1,i,s,0,t,1,r,0,e,n,1,0,0,0,0,1),this}compose(t,e,i){const n=this.elements,s=e._x,r=e._y,a=e._z,o=e._w,l=s+s,h=r+r,c=a+a,u=s*l,d=s*h,p=s*c,f=r*h,m=r*c,_=a*c,g=o*l,y=o*h,v=o*c,x=i.x,w=i.y,b=i.z;return n[0]=(1-(f+_))*x,n[1]=(d+v)*x,n[2]=(p-y)*x,n[3]=0,n[4]=(d-v)*w,n[5]=(1-(u+_))*w,n[6]=(m+g)*w,n[7]=0,n[8]=(p+y)*b,n[9]=(m-g)*b,n[10]=(1-(u+f))*b,n[11]=0,n[12]=t.x,n[13]=t.y,n[14]=t.z,n[15]=1,this}decompose(t,e,i){const n=this.elements;let s=En.set(n[0],n[1],n[2]).length();const r=En.set(n[4],n[5],n[6]).length(),a=En.set(n[8],n[9],n[10]).length();this.determinant()<0&&(s=-s),t.x=n[12],t.y=n[13],t.z=n[14],zn.copy(this);const o=1/s,l=1/r,h=1/a;return zn.elements[0]*=o,zn.elements[1]*=o,zn.elements[2]*=o,zn.elements[4]*=l,zn.elements[5]*=l,zn.elements[6]*=l,zn.elements[8]*=h,zn.elements[9]*=h,zn.elements[10]*=h,e.setFromRotationMatrix(zn),i.x=s,i.y=r,i.z=a,this}makePerspective(t,e,i,n,s,r){const a=this.elements,o=2*s/(e-t),l=2*s/(i-n),h=(e+t)/(e-t),c=(i+n)/(i-n),u=-(r+s)/(r-s),d=-2*r*s/(r-s);return a[0]=o,a[4]=0,a[8]=h,a[12]=0,a[1]=0,a[5]=l,a[9]=c,a[13]=0,a[2]=0,a[6]=0,a[10]=u,a[14]=d,a[3]=0,a[7]=0,a[11]=-1,a[15]=0,this}makeOrthographic(t,e,i,n,s,r){const a=this.elements,o=1/(e-t),l=1/(i-n),h=1/(r-s),c=(e+t)*o,u=(i+n)*l,d=(r+s)*h;return a[0]=2*o,a[4]=0,a[8]=0,a[12]=-c,a[1]=0,a[5]=2*l,a[9]=0,a[13]=-u,a[2]=0,a[6]=0,a[10]=-2*h,a[14]=-d,a[3]=0,a[7]=0,a[11]=0,a[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let t=0;t<16;t++)if(e[t]!==i[t])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}}Cn.prototype.isMatrix4=!0;const En=new Yi,zn=new Cn,In=new Yi(0,0,0),Ln=new Yi(1,1,1),Nn=new Yi,Pn=new Yi,Dn=new Yi,Fn=new Cn,On=new $i;class Rn{constructor(t=0,e=0,i=0,n=Rn.DefaultOrder){this._x=t,this._y=e,this._z=i,this._order=n}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,i,n=this._order){return this._x=t,this._y=e,this._z=i,this._order=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,i=!0){const n=t.elements,s=n[0],r=n[4],a=n[8],o=n[1],l=n[5],h=n[9],c=n[2],u=n[6],d=n[10];switch(e){case"XYZ":this._y=Math.asin(Ni(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,d),this._z=Math.atan2(-r,s)):(this._x=Math.atan2(u,l),this._z=0);break;case"YXZ":this._x=Math.asin(-Ni(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,l)):(this._y=Math.atan2(-c,s),this._z=0);break;case"ZXY":this._x=Math.asin(Ni(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-c,d),this._z=Math.atan2(-r,l)):(this._y=0,this._z=Math.atan2(o,s));break;case"ZYX":this._y=Math.asin(-Ni(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(u,d),this._z=Math.atan2(o,s)):(this._x=0,this._z=Math.atan2(-r,l));break;case"YZX":this._z=Math.asin(Ni(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-c,s)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-Ni(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(u,l),this._y=Math.atan2(a,s)):(this._x=Math.atan2(-h,d),this._y=0)}return this._order=e,!0===i&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return Fn.makeRotationFromQuaternion(t),this.setFromRotationMatrix(Fn,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return On.setFromEuler(this),this.setFromQuaternion(On,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}toVector3(t){return t?t.set(this._x,this._y,this._z):new Yi(this._x,this._y,this._z)}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}}Rn.prototype.isEuler=!0,Rn.DefaultOrder="XYZ",Rn.RotationOrders=["XYZ","YZX","ZXY","XZY","YXZ","ZYX"];class kn{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return 0!=(this.mask&t.mask)}isEnabled(t){return 0!=(this.mask&(1<<t|0))}}let Bn=0;const Un=new Yi,Vn=new $i,Wn=new Cn,Gn=new Yi,Hn=new Yi,jn=new Yi,qn=new $i,Jn=new Yi(1,0,0),$n=new Yi(0,1,0),Yn=new Yi(0,0,1),Xn={type:"added"},Zn={type:"removed"};class Kn extends Ci{constructor(){super(),Object.defineProperty(this,"id",{value:Bn++}),this.uuid=Li(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Kn.DefaultUp.clone();const t=new Yi,e=new Rn,i=new $i,n=new Yi(1,1,1);e._onChange((function(){i.setFromEuler(e,!1)})),i._onChange((function(){e.setFromQuaternion(i,void 0,!1)})),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:n},modelViewMatrix:{value:new Cn},normalMatrix:{value:new ki}}),this.matrix=new Cn,this.matrixWorld=new Cn,this.matrixAutoUpdate=Kn.DefaultMatrixAutoUpdate,this.matrixWorldNeedsUpdate=!1,this.layers=new kn,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.userData={}}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return Vn.setFromAxisAngle(t,e),this.quaternion.multiply(Vn),this}rotateOnWorldAxis(t,e){return Vn.setFromAxisAngle(t,e),this.quaternion.premultiply(Vn),this}rotateX(t){return this.rotateOnAxis(Jn,t)}rotateY(t){return this.rotateOnAxis($n,t)}rotateZ(t){return this.rotateOnAxis(Yn,t)}translateOnAxis(t,e){return Un.copy(t).applyQuaternion(this.quaternion),this.position.add(Un.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(Jn,t)}translateY(t){return this.translateOnAxis($n,t)}translateZ(t){return this.translateOnAxis(Yn,t)}localToWorld(t){return t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return t.applyMatrix4(Wn.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?Gn.copy(t):Gn.set(t,e,i);const n=this.parent;this.updateWorldMatrix(!0,!1),Hn.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Wn.lookAt(Hn,Gn,this.up):Wn.lookAt(Gn,Hn,this.up),this.quaternion.setFromRotationMatrix(Wn),n&&(Wn.extractRotation(n.matrixWorld),Vn.setFromRotationMatrix(Wn),this.quaternion.premultiply(Vn.invert()))}add(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return t===this||t&&t.isObject3D&&(null!==t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t),t.dispatchEvent(Xn)),this}remove(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.remove(arguments[t]);return this}const e=this.children.indexOf(t);return-1!==e&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(Zn)),this}removeFromParent(){const t=this.parent;return null!==t&&t.remove(this),this}clear(){for(let t=0;t<this.children.length;t++){const e=this.children[t];e.parent=null,e.dispatchEvent(Zn)}return this.children.length=0,this}attach(t){return this.updateWorldMatrix(!0,!1),Wn.copy(this.matrixWorld).invert(),null!==t.parent&&(t.parent.updateWorldMatrix(!0,!1),Wn.multiply(t.parent.matrixWorld)),t.applyMatrix4(Wn),this.add(t),t.updateWorldMatrix(!1,!0),this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let i=0,n=this.children.length;i<n;i++){const n=this.children[i].getObjectByProperty(t,e);if(void 0!==n)return n}}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Hn,t,jn),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Hn,qn,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let i=0,n=e.length;i<n;i++)e[i].traverse(t)}traverseVisible(t){if(!1===this.visible)return;t(this);const e=this.children;for(let i=0,n=e.length;i<n;i++)e[i].traverseVisible(t)}traverseAncestors(t){const e=this.parent;null!==e&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let i=0,n=e.length;i<n;i++)e[i].updateMatrixWorld(t)}updateWorldMatrix(t,e){const i=this.parent;if(!0===t&&null!==i&&i.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix),!0===e){const t=this.children;for(let e=0,i=t.length;e<i;e++)t[e].updateWorldMatrix(!1,!0)}}toJSON(t){const e=void 0===t||"string"==typeof t,i={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{}},i.metadata={version:4.5,type:"Object",generator:"Object3D.toJSON"});const n={};function s(e,i){return void 0===e[i.uuid]&&(e[i.uuid]=i.toJSON(t)),i.uuid}if(n.uuid=this.uuid,n.type=this.type,""!==this.name&&(n.name=this.name),!0===this.castShadow&&(n.castShadow=!0),!0===this.receiveShadow&&(n.receiveShadow=!0),!1===this.visible&&(n.visible=!1),!1===this.frustumCulled&&(n.frustumCulled=!1),0!==this.renderOrder&&(n.renderOrder=this.renderOrder),"{}"!==JSON.stringify(this.userData)&&(n.userData=this.userData),n.layers=this.layers.mask,n.matrix=this.matrix.toArray(),!1===this.matrixAutoUpdate&&(n.matrixAutoUpdate=!1),this.isInstancedMesh&&(n.type="InstancedMesh",n.count=this.count,n.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(n.instanceColor=this.instanceColor.toJSON())),this.isScene)this.background&&(this.background.isColor?n.background=this.background.toJSON():this.background.isTexture&&(n.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&(n.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){n.geometry=s(t.geometries,this.geometry);const e=this.geometry.parameters;if(void 0!==e&&void 0!==e.shapes){const i=e.shapes;if(Array.isArray(i))for(let e=0,n=i.length;e<n;e++){const n=i[e];s(t.shapes,n)}else s(t.shapes,i)}}if(this.isSkinnedMesh&&(n.bindMode=this.bindMode,n.bindMatrix=this.bindMatrix.toArray(),void 0!==this.skeleton&&(s(t.skeletons,this.skeleton),n.skeleton=this.skeleton.uuid)),void 0!==this.material)if(Array.isArray(this.material)){const e=[];for(let i=0,n=this.material.length;i<n;i++)e.push(s(t.materials,this.material[i]));n.material=e}else n.material=s(t.materials,this.material);if(this.children.length>0){n.children=[];for(let e=0;e<this.children.length;e++)n.children.push(this.children[e].toJSON(t).object)}if(this.animations.length>0){n.animations=[];for(let e=0;e<this.animations.length;e++){const i=this.animations[e];n.animations.push(s(t.animations,i))}}if(e){const e=r(t.geometries),n=r(t.materials),s=r(t.textures),a=r(t.images),o=r(t.shapes),l=r(t.skeletons),h=r(t.animations);e.length>0&&(i.geometries=e),n.length>0&&(i.materials=n),s.length>0&&(i.textures=s),a.length>0&&(i.images=a),o.length>0&&(i.shapes=o),l.length>0&&(i.skeletons=l),h.length>0&&(i.animations=h)}return i.object=n,i;function r(t){const e=[];for(const i in t){const n=t[i];delete n.metadata,e.push(n)}return e}}clone(t){return(new this.constructor).copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.userData=JSON.parse(JSON.stringify(t.userData)),!0===e)for(let e=0;e<t.children.length;e++){const i=t.children[e];this.add(i.clone())}return this}}Kn.DefaultUp=new Yi(0,1,0),Kn.DefaultMatrixAutoUpdate=!0,Kn.prototype.isObject3D=!0;const Qn=new Yi,ts=new Yi,es=new Yi,is=new Yi,ns=new Yi,ss=new Yi,rs=new Yi,as=new Yi,os=new Yi,ls=new Yi;class hs{constructor(t=new Yi,e=new Yi,i=new Yi){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,n){n.subVectors(i,e),Qn.subVectors(t,e),n.cross(Qn);const s=n.lengthSq();return s>0?n.multiplyScalar(1/Math.sqrt(s)):n.set(0,0,0)}static getBarycoord(t,e,i,n,s){Qn.subVectors(n,e),ts.subVectors(i,e),es.subVectors(t,e);const r=Qn.dot(Qn),a=Qn.dot(ts),o=Qn.dot(es),l=ts.dot(ts),h=ts.dot(es),c=r*l-a*a;if(0===c)return s.set(-2,-1,-1);const u=1/c,d=(l*o-a*h)*u,p=(r*h-a*o)*u;return s.set(1-d-p,p,d)}static containsPoint(t,e,i,n){return this.getBarycoord(t,e,i,n,is),is.x>=0&&is.y>=0&&is.x+is.y<=1}static getUV(t,e,i,n,s,r,a,o){return this.getBarycoord(t,e,i,n,is),o.set(0,0),o.addScaledVector(s,is.x),o.addScaledVector(r,is.y),o.addScaledVector(a,is.z),o}static isFrontFacing(t,e,i,n){return Qn.subVectors(i,e),ts.subVectors(t,e),Qn.cross(ts).dot(n)<0}set(t,e,i){return this.a.copy(t),this.b.copy(e),this.c.copy(i),this}setFromPointsAndIndices(t,e,i,n){return this.a.copy(t[e]),this.b.copy(t[i]),this.c.copy(t[n]),this}setFromAttributeAndIndices(t,e,i,n){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,n),this}clone(){return(new this.constructor).copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return Qn.subVectors(this.c,this.b),ts.subVectors(this.a,this.b),.5*Qn.cross(ts).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return hs.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return hs.getBarycoord(t,this.a,this.b,this.c,e)}getUV(t,e,i,n,s){return hs.getUV(t,this.a,this.b,this.c,e,i,n,s)}containsPoint(t){return hs.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return hs.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const i=this.a,n=this.b,s=this.c;let r,a;ns.subVectors(n,i),ss.subVectors(s,i),as.subVectors(t,i);const o=ns.dot(as),l=ss.dot(as);if(o<=0&&l<=0)return e.copy(i);os.subVectors(t,n);const h=ns.dot(os),c=ss.dot(os);if(h>=0&&c<=h)return e.copy(n);const u=o*c-h*l;if(u<=0&&o>=0&&h<=0)return r=o/(o-h),e.copy(i).addScaledVector(ns,r);ls.subVectors(t,s);const d=ns.dot(ls),p=ss.dot(ls);if(p>=0&&d<=p)return e.copy(s);const f=d*l-o*p;if(f<=0&&l>=0&&p<=0)return a=l/(l-p),e.copy(i).addScaledVector(ss,a);const m=h*p-d*c;if(m<=0&&c-h>=0&&d-p>=0)return rs.subVectors(s,n),a=(c-h)/(c-h+(d-p)),e.copy(n).addScaledVector(rs,a);const _=1/(m+f+u);return r=f*_,a=u*_,e.copy(i).addScaledVector(ns,r).addScaledVector(ss,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}let cs=0;class us extends Ci{constructor(){super(),Object.defineProperty(this,"id",{value:cs++}),this.uuid=Li(),this.name="",this.type="Material",this.fog=!0,this.blending=it,this.side=K,this.vertexColors=!1,this.opacity=1,this.format=me,this.transparent=!1,this.blendSrc=_t,this.blendDst=gt,this.blendEquation=ot,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.depthFunc=At,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=519,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=Si,this.stencilZFail=Si,this.stencilZPass=Si,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(t){this._alphaTest>0!=t>0&&this.version++,this._alphaTest=t}onBuild(){}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const i=t[e];if(void 0===i)continue;if("shading"===e){this.flatShading=1===i;continue}const n=this[e];void 0!==n&&(n&&n.isColor?n.set(i):n&&n.isVector3&&i&&i.isVector3?n.copy(i):this[e]=i)}}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{}});const i={metadata:{version:4.5,type:"Material",generator:"Material.toJSON"}};function n(t){const e=[];for(const i in t){const n=t[i];delete n.metadata,e.push(n)}return e}if(i.uuid=this.uuid,i.type=this.type,""!==this.name&&(i.name=this.name),this.color&&this.color.isColor&&(i.color=this.color.getHex()),void 0!==this.roughness&&(i.roughness=this.roughness),void 0!==this.metalness&&(i.metalness=this.metalness),void 0!==this.sheen&&(i.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(i.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(i.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(i.emissive=this.emissive.getHex()),this.emissiveIntensity&&1!==this.emissiveIntensity&&(i.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(i.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(i.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(i.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(i.shininess=this.shininess),void 0!==this.clearcoat&&(i.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(i.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(i.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(i.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(i.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,i.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.map&&this.map.isTexture&&(i.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(i.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(i.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(i.lightMap=this.lightMap.toJSON(t).uuid,i.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(i.aoMap=this.aoMap.toJSON(t).uuid,i.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(i.bumpMap=this.bumpMap.toJSON(t).uuid,i.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(i.normalMap=this.normalMap.toJSON(t).uuid,i.normalMapType=this.normalMapType,i.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(i.displacementMap=this.displacementMap.toJSON(t).uuid,i.displacementScale=this.displacementScale,i.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(i.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(i.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(i.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(i.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(i.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(i.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(i.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(i.combine=this.combine)),void 0!==this.envMapIntensity&&(i.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(i.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(i.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(i.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(i.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(i.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(i.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(i.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&(i.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(i.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(i.size=this.size),null!==this.shadowSide&&(i.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(i.sizeAttenuation=this.sizeAttenuation),this.blending!==it&&(i.blending=this.blending),this.side!==K&&(i.side=this.side),this.vertexColors&&(i.vertexColors=!0),this.opacity<1&&(i.opacity=this.opacity),this.format!==me&&(i.format=this.format),!0===this.transparent&&(i.transparent=this.transparent),i.depthFunc=this.depthFunc,i.depthTest=this.depthTest,i.depthWrite=this.depthWrite,i.colorWrite=this.colorWrite,i.stencilWrite=this.stencilWrite,i.stencilWriteMask=this.stencilWriteMask,i.stencilFunc=this.stencilFunc,i.stencilRef=this.stencilRef,i.stencilFuncMask=this.stencilFuncMask,i.stencilFail=this.stencilFail,i.stencilZFail=this.stencilZFail,i.stencilZPass=this.stencilZPass,this.rotation&&0!==this.rotation&&(i.rotation=this.rotation),!0===this.polygonOffset&&(i.polygonOffset=!0),0!==this.polygonOffsetFactor&&(i.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(i.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth&&1!==this.linewidth&&(i.linewidth=this.linewidth),void 0!==this.dashSize&&(i.dashSize=this.dashSize),void 0!==this.gapSize&&(i.gapSize=this.gapSize),void 0!==this.scale&&(i.scale=this.scale),!0===this.dithering&&(i.dithering=!0),this.alphaTest>0&&(i.alphaTest=this.alphaTest),!0===this.alphaToCoverage&&(i.alphaToCoverage=this.alphaToCoverage),!0===this.premultipliedAlpha&&(i.premultipliedAlpha=this.premultipliedAlpha),!0===this.wireframe&&(i.wireframe=this.wireframe),this.wireframeLinewidth>1&&(i.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(i.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(i.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(i.flatShading=this.flatShading),!1===this.visible&&(i.visible=!1),!1===this.toneMapped&&(i.toneMapped=!1),"{}"!==JSON.stringify(this.userData)&&(i.userData=this.userData),e){const e=n(t.textures),s=n(t.images);e.length>0&&(i.textures=e),s.length>0&&(i.images=s)}return i}clone(){return(new this.constructor).copy(this)}copy(t){this.name=t.name,this.fog=t.fog,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.format=t.format,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let i=null;if(null!==e){const t=e.length;i=new Array(t);for(let n=0;n!==t;++n)i[n]=e[n].clone()}return this.clippingPlanes=i,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}}us.prototype.isMaterial=!0;const ds={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},ps={h:0,s:0,l:0},fs={h:0,s:0,l:0};function ms(t,e,i){return i<0&&(i+=1),i>1&&(i-=1),i<1/6?t+6*(e-t)*i:i<.5?e:i<2/3?t+6*(e-t)*(2/3-i):t}function _s(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function gs(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let ys=class{constructor(t,e,i){return void 0===e&&void 0===i?this.set(t):this.setRGB(t,e,i)}set(t){return t&&t.isColor?this.copy(t):"number"==typeof t?this.setHex(t):"string"==typeof t&&this.setStyle(t),this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,this}setRGB(t,e,i){return this.r=t,this.g=e,this.b=i,this}setHSL(t,e,i){if(t=(t%1+1)%1,e=Ni(e,0,1),i=Ni(i,0,1),0===e)this.r=this.g=this.b=i;else{const n=i<=.5?i*(1+e):i+e-i*e,s=2*i-n;this.r=ms(s,n,t+1/3),this.g=ms(s,n,t),this.b=ms(s,n,t-1/3)}return this}setStyle(t){let e;if(e=/^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec(t)){let t;const i=e[1],n=e[2];switch(i){case"rgb":case"rgba":if(t=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))return this.r=Math.min(255,parseInt(t[1],10))/255,this.g=Math.min(255,parseInt(t[2],10))/255,this.b=Math.min(255,parseInt(t[3],10))/255,t[4],this;if(t=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))return this.r=Math.min(100,parseInt(t[1],10))/100,this.g=Math.min(100,parseInt(t[2],10))/100,this.b=Math.min(100,parseInt(t[3],10))/100,t[4],this;break;case"hsl":case"hsla":if(t=/^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n)){const e=parseFloat(t[1])/360,i=parseInt(t[2],10)/100,n=parseInt(t[3],10)/100;return t[4],this.setHSL(e,i,n)}}}else if(e=/^\#([A-Fa-f\d]+)$/.exec(t)){const t=e[1],i=t.length;if(3===i)return this.r=parseInt(t.charAt(0)+t.charAt(0),16)/255,this.g=parseInt(t.charAt(1)+t.charAt(1),16)/255,this.b=parseInt(t.charAt(2)+t.charAt(2),16)/255,this;if(6===i)return this.r=parseInt(t.charAt(0)+t.charAt(1),16)/255,this.g=parseInt(t.charAt(2)+t.charAt(3),16)/255,this.b=parseInt(t.charAt(4)+t.charAt(5),16)/255,this}return t&&t.length>0?this.setColorName(t):this}setColorName(t){const e=ds[t.toLowerCase()];return void 0!==e&&this.setHex(e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=_s(t.r),this.g=_s(t.g),this.b=_s(t.b),this}copyLinearToSRGB(t){return this.r=gs(t.r),this.g=gs(t.g),this.b=gs(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(){return 255*this.r<<16^255*this.g<<8^255*this.b<<0}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}getHSL(t){const e=this.r,i=this.g,n=this.b,s=Math.max(e,i,n),r=Math.min(e,i,n);let a,o;const l=(r+s)/2;if(r===s)a=0,o=0;else{const t=s-r;switch(o=l<=.5?t/(s+r):t/(2-s-r),s){case e:a=(i-n)/t+(i<n?6:0);break;case i:a=(n-e)/t+2;break;case n:a=(e-i)/t+4}a/=6}return t.h=a,t.s=o,t.l=l,t}getStyle(){return"rgb("+(255*this.r|0)+","+(255*this.g|0)+","+(255*this.b|0)+")"}offsetHSL(t,e,i){return this.getHSL(ps),ps.h+=t,ps.s+=e,ps.l+=i,this.setHSL(ps.h,ps.s,ps.l),this}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,i){return this.r=t.r+(e.r-t.r)*i,this.g=t.g+(e.g-t.g)*i,this.b=t.b+(e.b-t.b)*i,this}lerpHSL(t,e){this.getHSL(ps),t.getHSL(fs);const i=Pi(ps.h,fs.h,e),n=Pi(ps.s,fs.s,e),s=Pi(ps.l,fs.l,e);return this.setHSL(i,n,s),this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),!0===t.normalized&&(this.r/=255,this.g/=255,this.b/=255),this}toJSON(){return this.getHex()}};ys.NAMES=ds,ys.prototype.isColor=!0,ys.prototype.r=1,ys.prototype.g=1,ys.prototype.b=1;class vs extends us{constructor(t){super(),this.type="MeshBasicMaterial",this.color=new ys(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=Lt,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this}}vs.prototype.isMeshBasicMaterial=!0;const xs=new Yi,ws=new Ri;class bs{constructor(t,e,i){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.name="",this.array=t,this.itemSize=e,this.count=void 0!==t?t.length/e:0,this.normalized=!0===i,this.usage=Mi,this.updateRange={offset:0,count:-1},this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this}copyAt(t,e,i){t*=this.itemSize,i*=e.itemSize;for(let n=0,s=this.itemSize;n<s;n++)this.array[t+n]=e.array[i+n];return this}copyArray(t){return this.array.set(t),this}copyColorsArray(t){const e=this.array;let i=0;for(let n=0,s=t.length;n<s;n++){let s=t[n];void 0===s&&(s=new ys),e[i++]=s.r,e[i++]=s.g,e[i++]=s.b}return this}copyVector2sArray(t){const e=this.array;let i=0;for(let n=0,s=t.length;n<s;n++){let s=t[n];void 0===s&&(s=new Ri),e[i++]=s.x,e[i++]=s.y}return this}copyVector3sArray(t){const e=this.array;let i=0;for(let n=0,s=t.length;n<s;n++){let s=t[n];void 0===s&&(s=new Yi),e[i++]=s.x,e[i++]=s.y,e[i++]=s.z}return this}copyVector4sArray(t){const e=this.array;let i=0;for(let n=0,s=t.length;n<s;n++){let s=t[n];void 0===s&&(s=new ji),e[i++]=s.x,e[i++]=s.y,e[i++]=s.z,e[i++]=s.w}return this}applyMatrix3(t){if(2===this.itemSize)for(let e=0,i=this.count;e<i;e++)ws.fromBufferAttribute(this,e),ws.applyMatrix3(t),this.setXY(e,ws.x,ws.y);else if(3===this.itemSize)for(let e=0,i=this.count;e<i;e++)xs.fromBufferAttribute(this,e),xs.applyMatrix3(t),this.setXYZ(e,xs.x,xs.y,xs.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)xs.x=this.getX(e),xs.y=this.getY(e),xs.z=this.getZ(e),xs.applyMatrix4(t),this.setXYZ(e,xs.x,xs.y,xs.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)xs.x=this.getX(e),xs.y=this.getY(e),xs.z=this.getZ(e),xs.applyNormalMatrix(t),this.setXYZ(e,xs.x,xs.y,xs.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)xs.x=this.getX(e),xs.y=this.getY(e),xs.z=this.getZ(e),xs.transformDirection(t),this.setXYZ(e,xs.x,xs.y,xs.z);return this}set(t,e=0){return this.array.set(t,e),this}getX(t){return this.array[t*this.itemSize]}setX(t,e){return this.array[t*this.itemSize]=e,this}getY(t){return this.array[t*this.itemSize+1]}setY(t,e){return this.array[t*this.itemSize+1]=e,this}getZ(t){return this.array[t*this.itemSize+2]}setZ(t,e){return this.array[t*this.itemSize+2]=e,this}getW(t){return this.array[t*this.itemSize+3]}setW(t,e){return this.array[t*this.itemSize+3]=e,this}setXY(t,e,i){return t*=this.itemSize,this.array[t+0]=e,this.array[t+1]=i,this}setXYZ(t,e,i,n){return t*=this.itemSize,this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=n,this}setXYZW(t,e,i,n,s){return t*=this.itemSize,this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=n,this.array[t+3]=s,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.prototype.slice.call(this.array),normalized:this.normalized};return""!==this.name&&(t.name=this.name),this.usage!==Mi&&(t.usage=this.usage),0===this.updateRange.offset&&-1===this.updateRange.count||(t.updateRange=this.updateRange),t}}bs.prototype.isBufferAttribute=!0;class Ss extends bs{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class Ms extends bs{constructor(t,e,i){super(new Uint32Array(t),e,i)}}(class extends bs{constructor(t,e,i){super(new Uint16Array(t),e,i)}}).prototype.isFloat16BufferAttribute=!0;class Ts extends bs{constructor(t,e,i){super(new Float32Array(t),e,i)}}let As=0;const Cs=new Cn,Es=new Kn,zs=new Yi,Is=new Ki,Ls=new Ki,Ns=new Yi;class Ps extends Ci{constructor(){super(),Object.defineProperty(this,"id",{value:As++}),this.uuid=Li(),this.name="",this.type="BufferGeometry",this.index=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:Infinity},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(Bi(t)>65535?Ms:Ss)(t,1):this.index=t,this}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return void 0!==this.attributes[t]}addGroup(t,e,i=0){this.groups.push({start:t,count:e,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;void 0!==e&&(e.applyMatrix4(t),e.needsUpdate=!0);const i=this.attributes.normal;if(void 0!==i){const e=(new ki).getNormalMatrix(t);i.applyNormalMatrix(e),i.needsUpdate=!0}const n=this.attributes.tangent;return void 0!==n&&(n.transformDirection(t),n.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}applyQuaternion(t){return Cs.makeRotationFromQuaternion(t),this.applyMatrix4(Cs),this}rotateX(t){return Cs.makeRotationX(t),this.applyMatrix4(Cs),this}rotateY(t){return Cs.makeRotationY(t),this.applyMatrix4(Cs),this}rotateZ(t){return Cs.makeRotationZ(t),this.applyMatrix4(Cs),this}translate(t,e,i){return Cs.makeTranslation(t,e,i),this.applyMatrix4(Cs),this}scale(t,e,i){return Cs.makeScale(t,e,i),this.applyMatrix4(Cs),this}lookAt(t){return Es.lookAt(t),Es.updateMatrix(),this.applyMatrix4(Es.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(zs).negate(),this.translate(zs.x,zs.y,zs.z),this}setFromPoints(t){const e=[];for(let i=0,n=t.length;i<n;i++){const n=t[i];e.push(n.x,n.y,n.z||0)}return this.setAttribute("position",new Ts(e,3)),this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new Ki);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)this.boundingBox.set(new Yi(-Infinity,-Infinity,-Infinity),new Yi(Infinity,Infinity,Infinity));else{if(void 0!==t){if(this.boundingBox.setFromBufferAttribute(t),e)for(let t=0,i=e.length;t<i;t++){const i=e[t];Is.setFromBufferAttribute(i),this.morphTargetsRelative?(Ns.addVectors(this.boundingBox.min,Is.min),this.boundingBox.expandByPoint(Ns),Ns.addVectors(this.boundingBox.max,Is.max),this.boundingBox.expandByPoint(Ns)):(this.boundingBox.expandByPoint(Is.min),this.boundingBox.expandByPoint(Is.max))}}else this.boundingBox.makeEmpty();isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z)}}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new yn);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)this.boundingSphere.set(new Yi,Infinity);else if(t){const i=this.boundingSphere.center;if(Is.setFromBufferAttribute(t),e)for(let t=0,i=e.length;t<i;t++){const i=e[t];Ls.setFromBufferAttribute(i),this.morphTargetsRelative?(Ns.addVectors(Is.min,Ls.min),Is.expandByPoint(Ns),Ns.addVectors(Is.max,Ls.max),Is.expandByPoint(Ns)):(Is.expandByPoint(Ls.min),Is.expandByPoint(Ls.max))}Is.getCenter(i);let n=0;for(let e=0,s=t.count;e<s;e++)Ns.fromBufferAttribute(t,e),n=Math.max(n,i.distanceToSquared(Ns));if(e)for(let s=0,r=e.length;s<r;s++){const r=e[s],a=this.morphTargetsRelative;for(let e=0,s=r.count;e<s;e++)Ns.fromBufferAttribute(r,e),a&&(zs.fromBufferAttribute(t,e),Ns.add(zs)),n=Math.max(n,i.distanceToSquared(Ns))}this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)}}computeTangents(){const t=this.index,e=this.attributes;if(null===t||void 0===e.position||void 0===e.normal||void 0===e.uv)return;const i=t.array,n=e.position.array,s=e.normal.array,r=e.uv.array,a=n.length/3;void 0===e.tangent&&this.setAttribute("tangent",new bs(new Float32Array(4*a),4));const o=e.tangent.array,l=[],h=[];for(let t=0;t<a;t++)l[t]=new Yi,h[t]=new Yi;const c=new Yi,u=new Yi,d=new Yi,p=new Ri,f=new Ri,m=new Ri,_=new Yi,g=new Yi;function y(t,e,i){c.fromArray(n,3*t),u.fromArray(n,3*e),d.fromArray(n,3*i),p.fromArray(r,2*t),f.fromArray(r,2*e),m.fromArray(r,2*i),u.sub(c),d.sub(c),f.sub(p),m.sub(p);const s=1/(f.x*m.y-m.x*f.y);isFinite(s)&&(_.copy(u).multiplyScalar(m.y).addScaledVector(d,-f.y).multiplyScalar(s),g.copy(d).multiplyScalar(f.x).addScaledVector(u,-m.x).multiplyScalar(s),l[t].add(_),l[e].add(_),l[i].add(_),h[t].add(g),h[e].add(g),h[i].add(g))}let v=this.groups;0===v.length&&(v=[{start:0,count:i.length}]);for(let t=0,e=v.length;t<e;++t){const e=v[t],n=e.start;for(let t=n,s=n+e.count;t<s;t+=3)y(i[t+0],i[t+1],i[t+2])}const x=new Yi,w=new Yi,b=new Yi,S=new Yi;function M(t){b.fromArray(s,3*t),S.copy(b);const e=l[t];x.copy(e),x.sub(b.multiplyScalar(b.dot(e))).normalize(),w.crossVectors(S,e);const i=w.dot(h[t])<0?-1:1;o[4*t]=x.x,o[4*t+1]=x.y,o[4*t+2]=x.z,o[4*t+3]=i}for(let t=0,e=v.length;t<e;++t){const e=v[t],n=e.start;for(let t=n,s=n+e.count;t<s;t+=3)M(i[t+0]),M(i[t+1]),M(i[t+2])}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(void 0!==e){let i=this.getAttribute("normal");if(void 0===i)i=new bs(new Float32Array(3*e.count),3),this.setAttribute("normal",i);else for(let t=0,e=i.count;t<e;t++)i.setXYZ(t,0,0,0);const n=new Yi,s=new Yi,r=new Yi,a=new Yi,o=new Yi,l=new Yi,h=new Yi,c=new Yi;if(t)for(let u=0,d=t.count;u<d;u+=3){const d=t.getX(u+0),p=t.getX(u+1),f=t.getX(u+2);n.fromBufferAttribute(e,d),s.fromBufferAttribute(e,p),r.fromBufferAttribute(e,f),h.subVectors(r,s),c.subVectors(n,s),h.cross(c),a.fromBufferAttribute(i,d),o.fromBufferAttribute(i,p),l.fromBufferAttribute(i,f),a.add(h),o.add(h),l.add(h),i.setXYZ(d,a.x,a.y,a.z),i.setXYZ(p,o.x,o.y,o.z),i.setXYZ(f,l.x,l.y,l.z)}else for(let t=0,a=e.count;t<a;t+=3)n.fromBufferAttribute(e,t+0),s.fromBufferAttribute(e,t+1),r.fromBufferAttribute(e,t+2),h.subVectors(r,s),c.subVectors(n,s),h.cross(c),i.setXYZ(t+0,h.x,h.y,h.z),i.setXYZ(t+1,h.x,h.y,h.z),i.setXYZ(t+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}merge(t,e){if(!t||!t.isBufferGeometry)return;void 0===e&&(e=0);const i=this.attributes;for(const n in i){if(void 0===t.attributes[n])continue;const s=i[n].array,r=t.attributes[n],a=r.array,o=r.itemSize*e,l=Math.min(a.length,s.length-o);for(let t=0,e=o;t<l;t++,e++)s[e]=a[t]}return this}normalizeNormals(){const t=this.attributes.normal;for(let e=0,i=t.count;e<i;e++)Ns.fromBufferAttribute(t,e),Ns.normalize(),t.setXYZ(e,Ns.x,Ns.y,Ns.z)}toNonIndexed(){function t(t,e){const i=t.array,n=t.itemSize,s=t.normalized,r=new i.constructor(e.length*n);let a=0,o=0;for(let s=0,l=e.length;s<l;s++){a=t.isInterleavedBufferAttribute?e[s]*t.data.stride+t.offset:e[s]*n;for(let t=0;t<n;t++)r[o++]=i[a++]}return new bs(r,n,s)}if(null===this.index)return this;const e=new Ps,i=this.index.array,n=this.attributes;for(const s in n){const r=t(n[s],i);e.setAttribute(s,r)}const s=this.morphAttributes;for(const n in s){const r=[],a=s[n];for(let e=0,n=a.length;e<n;e++){const n=t(a[e],i);r.push(n)}e.morphAttributes[n]=r}e.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let t=0,i=r.length;t<i;t++){const i=r[t];e.addGroup(i.start,i.count,i.materialIndex)}return e}toJSON(){const t={metadata:{version:4.5,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.type,""!==this.name&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),void 0!==this.parameters){const e=this.parameters;for(const i in e)void 0!==e[i]&&(t[i]=e[i]);return t}t.data={attributes:{}};const e=this.index;null!==e&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const i=this.attributes;for(const e in i){const n=i[e];t.data.attributes[e]=n.toJSON(t.data)}const n={};let s=!1;for(const e in this.morphAttributes){const i=this.morphAttributes[e],r=[];for(let e=0,n=i.length;e<n;e++){const n=i[e];r.push(n.toJSON(t.data))}r.length>0&&(n[e]=r,s=!0)}s&&(t.data.morphAttributes=n,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const a=this.boundingSphere;return null!==a&&(t.data.boundingSphere={center:a.center.toArray(),radius:a.radius}),t}clone(){return(new this.constructor).copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const i=t.index;null!==i&&this.setIndex(i.clone(e));const n=t.attributes;for(const t in n){const i=n[t];this.setAttribute(t,i.clone(e))}const s=t.morphAttributes;for(const t in s){const i=[],n=s[t];for(let t=0,s=n.length;t<s;t++)i.push(n[t].clone(e));this.morphAttributes[t]=i}this.morphTargetsRelative=t.morphTargetsRelative;const r=t.groups;for(let t=0,e=r.length;t<e;t++){const e=r[t];this.addGroup(e.start,e.count,e.materialIndex)}const a=t.boundingBox;null!==a&&(this.boundingBox=a.clone());const o=t.boundingSphere;return null!==o&&(this.boundingSphere=o.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,void 0!==t.parameters&&(this.parameters=Object.assign({},t.parameters)),this}dispose(){this.dispatchEvent({type:"dispose"})}}Ps.prototype.isBufferGeometry=!0;const Ds=new Cn,Fs=new An,Os=new yn,Rs=new Yi,ks=new Yi,Bs=new Yi,Us=new Yi,Vs=new Yi,Ws=new Yi,Gs=new Yi,Hs=new Yi,js=new Yi,qs=new Ri,Js=new Ri,$s=new Ri,Ys=new Yi,Xs=new Yi;class Zs extends Kn{constructor(t=new Ps,e=new vs){super(),this.type="Mesh",this.geometry=t,this.material=e,this.updateMorphTargets()}copy(t){return super.copy(t),void 0!==t.morphTargetInfluences&&(this.morphTargetInfluences=t.morphTargetInfluences.slice()),void 0!==t.morphTargetDictionary&&(this.morphTargetDictionary=Object.assign({},t.morphTargetDictionary)),this.material=t.material,this.geometry=t.geometry,this}updateMorphTargets(){const t=this.geometry;if(t.isBufferGeometry){const e=t.morphAttributes,i=Object.keys(e);if(i.length>0){const t=e[i[0]];if(void 0!==t){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,i=t.length;e<i;e++){const i=t[e].name||String(e);this.morphTargetInfluences.push(0),this.morphTargetDictionary[i]=e}}}}else{const e=t.morphTargets;void 0!==e&&e.length}}raycast(t,e){const i=this.geometry,n=this.material,s=this.matrixWorld;if(void 0===n)return;if(null===i.boundingSphere&&i.computeBoundingSphere(),Os.copy(i.boundingSphere),Os.applyMatrix4(s),!1===t.ray.intersectsSphere(Os))return;if(Ds.copy(s).invert(),Fs.copy(t.ray).applyMatrix4(Ds),null!==i.boundingBox&&!1===Fs.intersectsBox(i.boundingBox))return;let r;if(i.isBufferGeometry){const s=i.index,a=i.attributes.position,o=i.morphAttributes.position,l=i.morphTargetsRelative,h=i.attributes.uv,c=i.attributes.uv2,u=i.groups,d=i.drawRange;if(null!==s)if(Array.isArray(n))for(let i=0,p=u.length;i<p;i++){const p=u[i],f=n[p.materialIndex];for(let i=Math.max(p.start,d.start),n=Math.min(s.count,Math.min(p.start+p.count,d.start+d.count));i<n;i+=3){const n=s.getX(i),u=s.getX(i+1),d=s.getX(i+2);r=Ks(this,f,t,Fs,a,o,l,h,c,n,u,d),r&&(r.faceIndex=Math.floor(i/3),r.face.materialIndex=p.materialIndex,e.push(r))}}else for(let i=Math.max(0,d.start),u=Math.min(s.count,d.start+d.count);i<u;i+=3){const u=s.getX(i),d=s.getX(i+1),p=s.getX(i+2);r=Ks(this,n,t,Fs,a,o,l,h,c,u,d,p),r&&(r.faceIndex=Math.floor(i/3),e.push(r))}else if(void 0!==a)if(Array.isArray(n))for(let i=0,s=u.length;i<s;i++){const s=u[i],p=n[s.materialIndex];for(let i=Math.max(s.start,d.start),n=Math.min(a.count,Math.min(s.start+s.count,d.start+d.count));i<n;i+=3)r=Ks(this,p,t,Fs,a,o,l,h,c,i,i+1,i+2),r&&(r.faceIndex=Math.floor(i/3),r.face.materialIndex=s.materialIndex,e.push(r))}else for(let i=Math.max(0,d.start),s=Math.min(a.count,d.start+d.count);i<s;i+=3)r=Ks(this,n,t,Fs,a,o,l,h,c,i,i+1,i+2),r&&(r.faceIndex=Math.floor(i/3),e.push(r))}else i.isGeometry}}function Ks(t,e,i,n,s,r,a,o,l,h,c,u){Rs.fromBufferAttribute(s,h),ks.fromBufferAttribute(s,c),Bs.fromBufferAttribute(s,u);const d=t.morphTargetInfluences;if(r&&d){Gs.set(0,0,0),Hs.set(0,0,0),js.set(0,0,0);for(let t=0,e=r.length;t<e;t++){const e=d[t],i=r[t];0!==e&&(Us.fromBufferAttribute(i,h),Vs.fromBufferAttribute(i,c),Ws.fromBufferAttribute(i,u),a?(Gs.addScaledVector(Us,e),Hs.addScaledVector(Vs,e),js.addScaledVector(Ws,e)):(Gs.addScaledVector(Us.sub(Rs),e),Hs.addScaledVector(Vs.sub(ks),e),js.addScaledVector(Ws.sub(Bs),e)))}Rs.add(Gs),ks.add(Hs),Bs.add(js)}t.isSkinnedMesh&&(t.boneTransform(h,Rs),t.boneTransform(c,ks),t.boneTransform(u,Bs));const p=function(t,e,i,n,s,r,a,o){let l;if(l=e.side===Q?n.intersectTriangle(a,r,s,!0,o):n.intersectTriangle(s,r,a,e.side!==tt,o),null===l)return null;Xs.copy(o),Xs.applyMatrix4(t.matrixWorld);const h=i.ray.origin.distanceTo(Xs);return h<i.near||h>i.far?null:{distance:h,point:Xs.clone(),object:t}}(t,e,i,n,Rs,ks,Bs,Ys);if(p){o&&(qs.fromBufferAttribute(o,h),Js.fromBufferAttribute(o,c),$s.fromBufferAttribute(o,u),p.uv=hs.getUV(Ys,Rs,ks,Bs,qs,Js,$s,new Ri)),l&&(qs.fromBufferAttribute(l,h),Js.fromBufferAttribute(l,c),$s.fromBufferAttribute(l,u),p.uv2=hs.getUV(Ys,Rs,ks,Bs,qs,Js,$s,new Ri));const t={a:h,b:c,c:u,normal:new Yi,materialIndex:0};hs.getNormal(Rs,ks,Bs,t.normal),p.face=t}return p}Zs.prototype.isMesh=!0;class Qs extends Ps{constructor(t=1,e=1,i=1,n=1,s=1,r=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:i,widthSegments:n,heightSegments:s,depthSegments:r};const a=this;n=Math.floor(n),s=Math.floor(s),r=Math.floor(r);const o=[],l=[],h=[],c=[];let u=0,d=0;function p(t,e,i,n,s,r,p,f,m,_,g){const y=r/m,v=p/_,x=r/2,w=p/2,b=f/2,S=m+1,M=_+1;let T=0,A=0;const C=new Yi;for(let r=0;r<M;r++){const a=r*v-w;for(let o=0;o<S;o++){const u=o*y-x;C[t]=u*n,C[e]=a*s,C[i]=b,l.push(C.x,C.y,C.z),C[t]=0,C[e]=0,C[i]=f>0?1:-1,h.push(C.x,C.y,C.z),c.push(o/m),c.push(1-r/_),T+=1}}for(let t=0;t<_;t++)for(let e=0;e<m;e++){const i=u+e+S*t,n=u+e+S*(t+1),s=u+(e+1)+S*(t+1),r=u+(e+1)+S*t;o.push(i,n,r),o.push(n,s,r),A+=6}a.addGroup(d,A,g),d+=A,u+=T}p("z","y","x",-1,-1,i,e,t,r,s,0),p("z","y","x",1,-1,i,e,-t,r,s,1),p("x","z","y",1,1,t,i,e,n,r,2),p("x","z","y",1,-1,t,i,-e,n,r,3),p("x","y","z",1,-1,t,e,i,n,s,4),p("x","y","z",-1,-1,t,e,-i,n,s,5),this.setIndex(o),this.setAttribute("position",new Ts(l,3)),this.setAttribute("normal",new Ts(h,3)),this.setAttribute("uv",new Ts(c,2))}static fromJSON(t){return new Qs(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}function tr(t){const e={};for(const i in t){e[i]={};for(const n in t[i]){const s=t[i][n];s&&(s.isColor||s.isMatrix3||s.isMatrix4||s.isVector2||s.isVector3||s.isVector4||s.isTexture||s.isQuaternion)?e[i][n]=s.clone():Array.isArray(s)?e[i][n]=s.slice():e[i][n]=s}}return e}function er(t){const e={};for(let i=0;i<t.length;i++){const n=tr(t[i]);for(const t in n)e[t]=n[t]}return e}const ir={clone:tr,merge:er};class nr extends us{constructor(t){super(),this.type="ShaderMaterial",this.defines={},this.uniforms={},this.vertexShader="void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",this.fragmentShader="void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}",this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.extensions={derivatives:!1,fragDepth:!1,drawBuffers:!1,shaderTextureLOD:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv2:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,void 0!==t&&(t.attributes,this.setValues(t))}copy(t){return super.copy(t),this.fragmentShader=t.fragmentShader,this.vertexShader=t.vertexShader,this.uniforms=tr(t.uniforms),this.defines=Object.assign({},t.defines),this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.lights=t.lights,this.clipping=t.clipping,this.extensions=Object.assign({},t.extensions),this.glslVersion=t.glslVersion,this}toJSON(t){const e=super.toJSON(t);e.glslVersion=this.glslVersion,e.uniforms={};for(const i in this.uniforms){const n=this.uniforms[i].value;n&&n.isTexture?e.uniforms[i]={type:"t",value:n.toJSON(t).uuid}:n&&n.isColor?e.uniforms[i]={type:"c",value:n.getHex()}:n&&n.isVector2?e.uniforms[i]={type:"v2",value:n.toArray()}:n&&n.isVector3?e.uniforms[i]={type:"v3",value:n.toArray()}:n&&n.isVector4?e.uniforms[i]={type:"v4",value:n.toArray()}:n&&n.isMatrix3?e.uniforms[i]={type:"m3",value:n.toArray()}:n&&n.isMatrix4?e.uniforms[i]={type:"m4",value:n.toArray()}:e.uniforms[i]={value:n}}Object.keys(this.defines).length>0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader;const i={};for(const t in this.extensions)!0===this.extensions[t]&&(i[t]=!0);return Object.keys(i).length>0&&(e.extensions=i),e}}nr.prototype.isShaderMaterial=!0;let sr=class extends Kn{constructor(){super(),this.type="Camera",this.matrixWorldInverse=new Cn,this.projectionMatrix=new Cn,this.projectionMatrixInverse=new Cn}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(-e[8],-e[9],-e[10]).normalize()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return(new this.constructor).copy(this)}};sr.prototype.isCamera=!0;class rr extends sr{constructor(t=50,e=1,i=.1,n=2e3){super(),this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=i,this.far=n,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=null===t.view?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=2*Ii*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*zi*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*Ii*Math.atan(Math.tan(.5*zi*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}setViewOffset(t,e,i,n,s,r){this.aspect=t/e,null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=i,this.view.offsetY=n,this.view.width=s,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(.5*zi*this.fov)/this.zoom,i=2*e,n=this.aspect*i,s=-.5*n;const r=this.view;if(null!==this.view&&this.view.enabled){const t=r.fullWidth,a=r.fullHeight;s+=r.offsetX*n/t,e-=r.offsetY*i/a,n*=r.width/t,i*=r.height/a}const a=this.filmOffset;0!==a&&(s+=t*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(s,s+n,e,e-i,t,this.far),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,null!==this.view&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}rr.prototype.isPerspectiveCamera=!0;const ar=90;class or extends Kn{constructor(t,e,i){if(super(),this.type="CubeCamera",!0!==i.isWebGLCubeRenderTarget)return;this.renderTarget=i;const n=new rr(ar,1,t,e);n.layers=this.layers,n.up.set(0,-1,0),n.lookAt(new Yi(1,0,0)),this.add(n);const s=new rr(ar,1,t,e);s.layers=this.layers,s.up.set(0,-1,0),s.lookAt(new Yi(-1,0,0)),this.add(s);const r=new rr(ar,1,t,e);r.layers=this.layers,r.up.set(0,0,1),r.lookAt(new Yi(0,1,0)),this.add(r);const a=new rr(ar,1,t,e);a.layers=this.layers,a.up.set(0,0,-1),a.lookAt(new Yi(0,-1,0)),this.add(a);const o=new rr(ar,1,t,e);o.layers=this.layers,o.up.set(0,-1,0),o.lookAt(new Yi(0,0,1)),this.add(o);const l=new rr(ar,1,t,e);l.layers=this.layers,l.up.set(0,-1,0),l.lookAt(new Yi(0,0,-1)),this.add(l)}update(t,e){null===this.parent&&this.updateMatrixWorld();const i=this.renderTarget,[n,s,r,a,o,l]=this.children,h=t.xr.enabled,c=t.getRenderTarget();t.xr.enabled=!1;const u=i.texture.generateMipmaps;i.texture.generateMipmaps=!1,t.setRenderTarget(i,0),t.render(e,n),t.setRenderTarget(i,1),t.render(e,s),t.setRenderTarget(i,2),t.render(e,r),t.setRenderTarget(i,3),t.render(e,a),t.setRenderTarget(i,4),t.render(e,o),i.texture.generateMipmaps=u,t.setRenderTarget(i,5),t.render(e,l),t.setRenderTarget(c),t.xr.enabled=h}}class lr extends Gi{constructor(t,e,i,n,s,r,a,o,l,h){super(t=void 0!==t?t:[],e=void 0!==e?e:Ut,i,n,s,r,a,o,l,h),this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}lr.prototype.isCubeTexture=!0;class hr extends qi{constructor(t,e,i){Number.isInteger(e)&&(e=i),super(t,t,e),e=e||{},this.texture=new lr(void 0,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.encoding),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=void 0!==e.generateMipmaps&&e.generateMipmaps,this.texture.minFilter=void 0!==e.minFilter?e.minFilter:Kt,this.texture._needsFlipEnvMap=!1}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.format=me,this.texture.encoding=e.encoding,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const i=new Qs(5,5,5),n=new nr({name:"CubemapFromEquirect",uniforms:tr({tEquirect:{value:null}}),vertexShader:"\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t\t#include <begin_vertex>\n\t\t\t\t\t#include <project_vertex>\n\n\t\t\t\t}\n\t\t\t",fragmentShader:"\n\n\t\t\t\tuniform sampler2D tEquirect;\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\t#include <common>\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t\t}\n\t\t\t",side:Q,blending:et});n.uniforms.tEquirect.value=e;const s=new Zs(i,n),r=e.minFilter;return e.minFilter===te&&(e.minFilter=Kt),new or(1,10,this).update(t,s),e.minFilter=r,s.geometry.dispose(),s.material.dispose(),this}clear(t,e,i,n){const s=t.getRenderTarget();for(let s=0;s<6;s++)t.setRenderTarget(this,s),t.clear(e,i,n);t.setRenderTarget(s)}}hr.prototype.isWebGLCubeRenderTarget=!0;const cr=new Yi,ur=new Yi,dr=new ki;class pr{constructor(t=new Yi(1,0,0),e=0){this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,i,n){return this.normal.set(t,e,i),this.constant=n,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,i){const n=cr.subVectors(i,e).cross(ur.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(n,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(this.normal).multiplyScalar(-this.distanceToPoint(t)).add(t)}intersectLine(t,e){const i=t.delta(cr),n=this.normal.dot(i);if(0===n)return 0===this.distanceToPoint(t.start)?e.copy(t.start):null;const s=-(t.start.dot(this.normal)+this.constant)/n;return s<0||s>1?null:e.copy(i).multiplyScalar(s).add(t.start)}intersectsLine(t){const e=this.distanceToPoint(t.start),i=this.distanceToPoint(t.end);return e<0&&i>0||i<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const i=e||dr.getNormalMatrix(t),n=this.coplanarPoint(cr).applyMatrix4(t),s=this.normal.applyMatrix3(i).normalize();return this.constant=-n.dot(s),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return(new this.constructor).copy(this)}}pr.prototype.isPlane=!0;const fr=new yn,mr=new Yi;class _r{constructor(t=new pr,e=new pr,i=new pr,n=new pr,s=new pr,r=new pr){this.planes=[t,e,i,n,s,r]}set(t,e,i,n,s,r){const a=this.planes;return a[0].copy(t),a[1].copy(e),a[2].copy(i),a[3].copy(n),a[4].copy(s),a[5].copy(r),this}copy(t){const e=this.planes;for(let i=0;i<6;i++)e[i].copy(t.planes[i]);return this}setFromProjectionMatrix(t){const e=this.planes,i=t.elements,n=i[0],s=i[1],r=i[2],a=i[3],o=i[4],l=i[5],h=i[6],c=i[7],u=i[8],d=i[9],p=i[10],f=i[11],m=i[12],_=i[13],g=i[14],y=i[15];return e[0].setComponents(a-n,c-o,f-u,y-m).normalize(),e[1].setComponents(a+n,c+o,f+u,y+m).normalize(),e[2].setComponents(a+s,c+l,f+d,y+_).normalize(),e[3].setComponents(a-s,c-l,f-d,y-_).normalize(),e[4].setComponents(a-r,c-h,f-p,y-g).normalize(),e[5].setComponents(a+r,c+h,f+p,y+g).normalize(),this}intersectsObject(t){const e=t.geometry;return null===e.boundingSphere&&e.computeBoundingSphere(),fr.copy(e.boundingSphere).applyMatrix4(t.matrixWorld),this.intersectsSphere(fr)}intersectsSprite(t){return fr.center.set(0,0,0),fr.radius=.7071067811865476,fr.applyMatrix4(t.matrixWorld),this.intersectsSphere(fr)}intersectsSphere(t){const e=this.planes,i=t.center,n=-t.radius;for(let t=0;t<6;t++)if(e[t].distanceToPoint(i)<n)return!1;return!0}intersectsBox(t){const e=this.planes;for(let i=0;i<6;i++){const n=e[i];if(mr.x=n.normal.x>0?t.max.x:t.min.x,mr.y=n.normal.y>0?t.max.y:t.min.y,mr.z=n.normal.z>0?t.max.z:t.min.z,n.distanceToPoint(mr)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let i=0;i<6;i++)if(e[i].distanceToPoint(t)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}function gr(){let t=null,e=!1,i=null,n=null;function s(e,r){i(e,r),n=t.requestAnimationFrame(s)}return{start:function(){!0!==e&&null!==i&&(n=t.requestAnimationFrame(s),e=!0)},stop:function(){t.cancelAnimationFrame(n),e=!1},setAnimationLoop:function(t){i=t},setContext:function(e){t=e}}}function yr(t,e){const i=e.isWebGL2,n=new WeakMap;return{get:function(t){return t.isInterleavedBufferAttribute&&(t=t.data),n.get(t)},remove:function(e){e.isInterleavedBufferAttribute&&(e=e.data);const i=n.get(e);i&&(t.deleteBuffer(i.buffer),n.delete(e))},update:function(e,s){if(e.isGLBufferAttribute){const t=n.get(e);return void((!t||t.version<e.version)&&n.set(e,{buffer:e.buffer,type:e.type,bytesPerElement:e.elementSize,version:e.version}))}e.isInterleavedBufferAttribute&&(e=e.data);const r=n.get(e);void 0===r?n.set(e,function(e,n){const s=e.array,r=e.usage,a=t.createBuffer();t.bindBuffer(n,a),t.bufferData(n,s,r),e.onUploadCallback();let o=5126;return s instanceof Float32Array?o=5126:s instanceof Float64Array||(s instanceof Uint16Array?e.isFloat16BufferAttribute?i&&(o=5131):o=5123:s instanceof Int16Array?o=5122:s instanceof Uint32Array?o=5125:s instanceof Int32Array?o=5124:s instanceof Int8Array?o=5120:(s instanceof Uint8Array||s instanceof Uint8ClampedArray)&&(o=5121)),{buffer:a,type:o,bytesPerElement:s.BYTES_PER_ELEMENT,version:e.version}}(e,s)):r.version<e.version&&(function(e,n,s){const r=n.array,a=n.updateRange;t.bindBuffer(s,e),-1===a.count?t.bufferSubData(s,0,r):(i?t.bufferSubData(s,a.offset*r.BYTES_PER_ELEMENT,r,a.offset,a.count):t.bufferSubData(s,a.offset*r.BYTES_PER_ELEMENT,r.subarray(a.offset,a.offset+a.count)),a.count=-1)}(r.buffer,e,s),r.version=e.version)}}}class vr extends Ps{constructor(t=1,e=1,i=1,n=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:i,heightSegments:n};const s=t/2,r=e/2,a=Math.floor(i),o=Math.floor(n),l=a+1,h=o+1,c=t/a,u=e/o,d=[],p=[],f=[],m=[];for(let t=0;t<h;t++){const e=t*u-r;for(let i=0;i<l;i++){const n=i*c-s;p.push(n,-e,0),f.push(0,0,1),m.push(i/a),m.push(1-t/o)}}for(let t=0;t<o;t++)for(let e=0;e<a;e++){const i=e+l*t,n=e+l*(t+1),s=e+1+l*(t+1),r=e+1+l*t;d.push(i,n,r),d.push(n,s,r)}this.setIndex(d),this.setAttribute("position",new Ts(p,3)),this.setAttribute("normal",new Ts(f,3)),this.setAttribute("uv",new Ts(m,2))}static fromJSON(t){return new vr(t.width,t.height,t.widthSegments,t.heightSegments)}}const xr={alphamap_fragment:"#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif",alphamap_pars_fragment:"#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif",alphatest_fragment:"#ifdef USE_ALPHATEST\n\tif ( diffuseColor.a < alphaTest ) discard;\n#endif",alphatest_pars_fragment:"#ifdef USE_ALPHATEST\n\tuniform float alphaTest;\n#endif",aomap_fragment:"#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_ENVMAP ) && defined( STANDARD )\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n\t#endif\n#endif",aomap_pars_fragment:"#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif",begin_vertex:"vec3 transformed = vec3( position );",beginnormal_vertex:"vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif",bsdfs:"vec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 f0, const in float f90, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( f0, f90, dotVH );\n\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( V * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, 1.0, dotVH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie( float roughness, float dotNH ) {\n\tfloat alpha = pow2( roughness );\n\tfloat invAlpha = 1.0 / alpha;\n\tfloat cos2h = dotNH * dotNH;\n\tfloat sin2h = max( 1.0 - cos2h, 0.0078125 );\n\treturn ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n}\nfloat V_Neubelt( float dotNV, float dotNL ) {\n\treturn saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n}\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat D = D_Charlie( sheenRoughness, dotNH );\n\tfloat V = V_Neubelt( dotNV, dotNL );\n\treturn sheenColor * ( D * V );\n}\n#endif",bumpmap_pars_fragment:"#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 ) * faceDirection;\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif",clipping_planes_fragment:"#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#pragma unroll_loop_end\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\tif ( clipped ) discard;\n\t#endif\n#endif",clipping_planes_pars_fragment:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif",clipping_planes_pars_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif",clipping_planes_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif",color_fragment:"#if defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\n#elif defined( USE_COLOR )\n\tdiffuseColor.rgb *= vColor;\n#endif",color_pars_fragment:"#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR )\n\tvarying vec3 vColor;\n#endif",color_pars_vertex:"#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif",color_vertex:"#if defined( USE_COLOR_ALPHA )\n\tvColor = vec4( 1.0 );\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif",common:"#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract( sin( sn ) * c );\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n#ifdef USE_CLEARCOAT\n\tvec3 clearcoatNormal;\n#endif\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}",cube_uv_reflection_fragment:"#ifdef ENVMAP_TYPE_CUBE_UV\n\t#define cubeUV_maxMipLevel 8.0\n\t#define cubeUV_minMipLevel 4.0\n\t#define cubeUV_maxTileSize 256.0\n\t#define cubeUV_minTileSize 16.0\n\tfloat getFace( vec3 direction ) {\n\t\tvec3 absDirection = abs( direction );\n\t\tfloat face = - 1.0;\n\t\tif ( absDirection.x > absDirection.z ) {\n\t\t\tif ( absDirection.x > absDirection.y )\n\t\t\t\tface = direction.x > 0.0 ? 0.0 : 3.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t} else {\n\t\t\tif ( absDirection.z > absDirection.y )\n\t\t\t\tface = direction.z > 0.0 ? 2.0 : 5.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t}\n\t\treturn face;\n\t}\n\tvec2 getUV( vec3 direction, float face ) {\n\t\tvec2 uv;\n\t\tif ( face == 0.0 ) {\n\t\t\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 1.0 ) {\n\t\t\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n\t\t} else if ( face == 2.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\n\t\t} else if ( face == 3.0 ) {\n\t\t\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 4.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\n\t\t} else {\n\t\t\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\n\t\t}\n\t\treturn 0.5 * ( uv + 1.0 );\n\t}\n\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\t\tfloat face = getFace( direction );\n\t\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\t\tmipInt = max( mipInt, cubeUV_minMipLevel );\n\t\tfloat faceSize = exp2( mipInt );\n\t\tfloat texelSize = 1.0 / ( 3.0 * cubeUV_maxTileSize );\n\t\tvec2 uv = getUV( direction, face ) * ( faceSize - 1.0 ) + 0.5;\n\t\tif ( face > 2.0 ) {\n\t\t\tuv.y += faceSize;\n\t\t\tface -= 3.0;\n\t\t}\n\t\tuv.x += face * faceSize;\n\t\tif ( mipInt < cubeUV_maxMipLevel ) {\n\t\t\tuv.y += 2.0 * cubeUV_maxTileSize;\n\t\t}\n\t\tuv.y += filterInt * 2.0 * cubeUV_minTileSize;\n\t\tuv.x += 3.0 * max( 0.0, cubeUV_maxTileSize - 2.0 * faceSize );\n\t\tuv *= texelSize;\n\t\treturn texture2D( envMap, uv ).rgb;\n\t}\n\t#define r0 1.0\n\t#define v0 0.339\n\t#define m0 - 2.0\n\t#define r1 0.8\n\t#define v1 0.276\n\t#define m1 - 1.0\n\t#define r4 0.4\n\t#define v4 0.046\n\t#define m4 2.0\n\t#define r5 0.305\n\t#define v5 0.016\n\t#define m5 3.0\n\t#define r6 0.21\n\t#define v6 0.0038\n\t#define m6 4.0\n\tfloat roughnessToMip( float roughness ) {\n\t\tfloat mip = 0.0;\n\t\tif ( roughness >= r1 ) {\n\t\t\tmip = ( r0 - roughness ) * ( m1 - m0 ) / ( r0 - r1 ) + m0;\n\t\t} else if ( roughness >= r4 ) {\n\t\t\tmip = ( r1 - roughness ) * ( m4 - m1 ) / ( r1 - r4 ) + m1;\n\t\t} else if ( roughness >= r5 ) {\n\t\t\tmip = ( r4 - roughness ) * ( m5 - m4 ) / ( r4 - r5 ) + m4;\n\t\t} else if ( roughness >= r6 ) {\n\t\t\tmip = ( r5 - roughness ) * ( m6 - m5 ) / ( r5 - r6 ) + m5;\n\t\t} else {\n\t\t\tmip = - 2.0 * log2( 1.16 * roughness );\t\t}\n\t\treturn mip;\n\t}\n\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\t\tfloat mip = clamp( roughnessToMip( roughness ), m0, cubeUV_maxMipLevel );\n\t\tfloat mipF = fract( mip );\n\t\tfloat mipInt = floor( mip );\n\t\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\t\tif ( mipF == 0.0 ) {\n\t\t\treturn vec4( color0, 1.0 );\n\t\t} else {\n\t\t\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\t\t\treturn vec4( mix( color0, color1, mipF ), 1.0 );\n\t\t}\n\t}\n#endif",defaultnormal_vertex:"vec3 transformedNormal = objectNormal;\n#ifdef USE_INSTANCING\n\tmat3 m = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );\n\ttransformedNormal = m * transformedNormal;\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif",displacementmap_pars_vertex:"#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif",displacementmap_vertex:"#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif",emissivemap_fragment:"#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif",emissivemap_pars_fragment:"#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif",encodings_fragment:"gl_FragColor = linearToOutputTexel( gl_FragColor );",encodings_pars_fragment:"vec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 sRGBToLinear( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}",envmap_fragment:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t\tenvColor = envMapTexelToLinear( envColor );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif",envmap_common_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\t\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) ||defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif",envmap_physical_pars_fragment:"#if defined( USE_ENVMAP )\n\t#ifdef ENVMAP_MODE_REFRACTION\n\t\tuniform float refractionRatio;\n\t#endif\n\tvec3 getIBLIrradiance( const in vec3 normal ) {\n\t\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );\n\t\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\tvec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec3 reflectVec;\n\t\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\t\treflectVec = reflect( - viewDir, normal );\n\t\t\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t\t#else\n\t\t\t\treflectVec = refract( - viewDir, normal, refractionRatio );\n\t\t\t#endif\n\t\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n\t\t\treturn envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif",fog_vertex:"#ifdef USE_FOG\n\tvFogDepth = - mvPosition.z;\n#endif",fog_pars_vertex:"#ifdef USE_FOG\n\tvarying float vFogDepth;\n#endif",fog_fragment:"#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, vFogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif",fog_pars_fragment:"#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float vFogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif",gradientmap_pars_fragment:"#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn vec3( texture2D( gradientMap, coord ).r );\n\t#else\n\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n\t#endif\n}",lightmap_fragment:"#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel = texture2D( lightMap, vUv2 );\n\tvec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tlightMapIrradiance *= PI;\n\t#endif\n\treflectedLight.indirectDiffuse += lightMapIrradiance;\n#endif",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif",lights_lambert_vertex:"vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\nvIndirectFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n\tvIndirectBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\nvIndirectFront += getAmbientLightIrradiance( ambientLightColor );\nvIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );\n#ifdef DOUBLE_SIDED\n\tvIndirectBack += getAmbientLightIrradiance( ambientLightColor );\n\tvIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry.normal );\n#endif\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointLightInfo( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotLightInfo( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tgetDirectionalLightInfo( directionalLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry.normal );\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif",lights_pars_begin:"uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\nuniform vec3 lightProbe[ 9 ];\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\t#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\t\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\t\tif ( cutoffDistance > 0.0 ) {\n\t\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t\t}\n\t\treturn distanceFalloff;\n\t#else\n\t\tif ( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\t\treturn pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t\t}\n\t\treturn 1.0;\n\t#endif\n}\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n\treturn smoothstep( coneCosine, penumbraCosine, angleCosine );\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalLightInfo( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight light ) {\n\t\tlight.color = directionalLight.color;\n\t\tlight.direction = directionalLight.direction;\n\t\tlight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointLightInfo( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight light ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tlight.color = pointLight.color;\n\t\tlight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotLightInfo( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight light ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat angleCos = dot( light.direction, spotLight.direction );\n\t\tfloat spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\tif ( spotAttenuation > 0.0 ) {\n\t\t\tfloat lightDistance = length( lVector );\n\t\t\tlight.color = spotLight.color * spotAttenuation;\n\t\t\tlight.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t\t} else {\n\t\t\tlight.color = vec3( 0.0 );\n\t\t\tlight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n\t\tfloat dotNL = dot( normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\treturn irradiance;\n\t}\n#endif",lights_toon_fragment:"ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;",lights_toon_pars_fragment:"varying vec3 vViewPosition;\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon\n#define Material_LightProbeLOD( material )\t(0)",lights_phong_fragment:"BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;",lights_phong_pars_fragment:"varying vec3 vViewPosition;\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material )\t(0)",lights_physical_fragment:"PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n\t#ifdef SPECULAR\n\t\tfloat specularIntensityFactor = specularIntensity;\n\t\tvec3 specularColorFactor = specularColor;\n\t\t#ifdef USE_SPECULARINTENSITYMAP\n\t\t\tspecularIntensityFactor *= texture2D( specularIntensityMap, vUv ).a;\n\t\t#endif\n\t\t#ifdef USE_SPECULARCOLORMAP\n\t\t\tspecularColorFactor *= specularColorMapTexelToLinear( texture2D( specularColorMap, vUv ) ).rgb;\n\t\t#endif\n\t\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\t#else\n\t\tfloat specularIntensityFactor = 1.0;\n\t\tvec3 specularColorFactor = vec3( 1.0 );\n\t\tmaterial.specularF90 = 1.0;\n\t#endif\n\tmaterial.specularColor = mix( min( pow2( ( ior - 1.0 ) / ( ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\tmaterial.clearcoatF0 = vec3( 0.04 );\n\tmaterial.clearcoatF90 = 1.0;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheenColor;\n\t#ifdef USE_SHEENCOLORMAP\n\t\tmaterial.sheenColor *= sheenColorMapTexelToLinear( texture2D( sheenColorMap, vUv ) ).rgb;\n\t#endif\n\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\n\t#ifdef USE_SHEENROUGHNESSMAP\n\t\tmaterial.sheenRoughness *= texture2D( sheenRoughnessMap, vUv ).a;\n\t#endif\n#endif",lights_physical_pars_fragment:"struct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat roughness;\n\tvec3 specularColor;\n\tfloat specularF90;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat clearcoat;\n\t\tfloat clearcoatRoughness;\n\t\tvec3 clearcoatF0;\n\t\tfloat clearcoatF90;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tvec3 sheenColor;\n\t\tfloat sheenRoughness;\n\t#endif\n};\nvec3 clearcoatSpecular = vec3( 0.0 );\nvec3 sheenSpecular = vec3( 0.0 );\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat r2 = roughness * roughness;\n\tfloat a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;\n\tfloat b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;\n\tfloat DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );\n\treturn saturate( DG * RECIPROCAL_PI );\n}\nvec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\tvec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;\n\treturn fab;\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\treturn specularColor * fab.x + specularF90 * fab.y;\n}\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\tvec3 FssEss = specularColor * fab.x + specularF90 * fab.y;\n\tfloat Ess = fab.x + fab.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.roughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNLcc = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = dotNLcc * directLight.color;\n\t\tclearcoatSpecular += ccIrradiance * BRDF_GGX( directLight.direction, geometry.viewDir, geometry.clearcoatNormal, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecular += irradiance * BRDF_Sheen( directLight.direction, geometry.viewDir, geometry.normal, material.sheenColor, material.sheenRoughness );\n\t#endif\n\treflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularF90, material.roughness );\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatSpecular += clearcoatRadiance * EnvironmentBRDF( geometry.clearcoatNormal, geometry.viewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecular += irradiance * material.sheenColor * IBLSheenBRDF( geometry.normal, geometry.viewDir, material.sheenRoughness );\n\t#endif\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tcomputeMultiscattering( geometry.normal, geometry.viewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );\n\treflectedLight.indirectSpecular += radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}",lights_fragment_begin:"\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n#ifdef USE_CLEARCOAT\n\tgeometry.clearcoatNormal = clearcoatNormal;\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointLightInfo( pointLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotLightInfo( spotLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\tirradiance += getLightProbeIrradiance( lightProbe, geometry.normal );\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif",lights_fragment_maps:"#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vUv2 );\n\t\tvec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getIBLIrradiance( geometry.normal );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getIBLRadiance( geometry.viewDir, geometry.normal, material.roughness );\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatRadiance += getIBLRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness );\n\t#endif\n#endif",lights_fragment_end:"#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );\n#endif",logdepthbuf_fragment:"#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif",logdepthbuf_pars_fragment:"#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_pars_vertex:"#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t\tvarying float vIsPerspective;\n\t#else\n\t\tuniform float logDepthBufFC;\n\t#endif\n#endif",logdepthbuf_vertex:"#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n\t#else\n\t\tif ( isPerspectiveMatrix( projectionMatrix ) ) {\n\t\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\t\tgl_Position.z *= gl_Position.w;\n\t\t}\n\t#endif\n#endif",map_fragment:"#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif",map_pars_fragment:"#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif",map_particle_fragment:"#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n#endif\n#ifdef USE_MAP\n\tvec4 mapTexel = texture2D( map, uv );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif",map_particle_pars_fragment:"#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tuniform mat3 uvTransform;\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif",metalnessmap_fragment:"float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif",metalnessmap_pars_fragment:"#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif",morphnormal_vertex:"#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t\tif ( morphTargetInfluences[ i ] > 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1, 2 ) * morphTargetInfluences[ i ];\n\t\t}\n\t#else\n\t\tobjectNormal += morphNormal0 * morphTargetInfluences[ 0 ];\n\t\tobjectNormal += morphNormal1 * morphTargetInfluences[ 1 ];\n\t\tobjectNormal += morphNormal2 * morphTargetInfluences[ 2 ];\n\t\tobjectNormal += morphNormal3 * morphTargetInfluences[ 3 ];\n\t#endif\n#endif",morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\n\tuniform float morphTargetBaseInfluence;\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\t\tuniform sampler2DArray morphTargetsTexture;\n\t\tuniform vec2 morphTargetsTextureSize;\n\t\tvec3 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset, const in int stride ) {\n\t\t\tfloat texelIndex = float( vertexIndex * stride + offset );\n\t\t\tfloat y = floor( texelIndex / morphTargetsTextureSize.x );\n\t\t\tfloat x = texelIndex - y * morphTargetsTextureSize.x;\n\t\t\tvec3 morphUV = vec3( ( x + 0.5 ) / morphTargetsTextureSize.x, y / morphTargetsTextureSize.y, morphTargetIndex );\n\t\t\treturn texture( morphTargetsTexture, morphUV ).xyz;\n\t\t}\n\t#else\n\t\t#ifndef USE_MORPHNORMALS\n\t\t\tuniform float morphTargetInfluences[ 8 ];\n\t\t#else\n\t\t\tuniform float morphTargetInfluences[ 4 ];\n\t\t#endif\n\t#endif\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t\t#ifndef USE_MORPHNORMALS\n\t\t\t\tif ( morphTargetInfluences[ i ] > 0.0 ) transformed += getMorph( gl_VertexID, i, 0, 1 ) * morphTargetInfluences[ i ];\n\t\t\t#else\n\t\t\t\tif ( morphTargetInfluences[ i ] > 0.0 ) transformed += getMorph( gl_VertexID, i, 0, 2 ) * morphTargetInfluences[ i ];\n\t\t\t#endif\n\t\t}\n\t#else\n\t\ttransformed += morphTarget0 * morphTargetInfluences[ 0 ];\n\t\ttransformed += morphTarget1 * morphTargetInfluences[ 1 ];\n\t\ttransformed += morphTarget2 * morphTargetInfluences[ 2 ];\n\t\ttransformed += morphTarget3 * morphTargetInfluences[ 3 ];\n\t\t#ifndef USE_MORPHNORMALS\n\t\t\ttransformed += morphTarget4 * morphTargetInfluences[ 4 ];\n\t\t\ttransformed += morphTarget5 * morphTargetInfluences[ 5 ];\n\t\t\ttransformed += morphTarget6 * morphTargetInfluences[ 6 ];\n\t\t\ttransformed += morphTarget7 * morphTargetInfluences[ 7 ];\n\t\t#endif\n\t#endif\n#endif",normal_fragment_begin:"float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * faceDirection;\n\t\t\tbitangent = bitangent * faceDirection;\n\t\t#endif\n\t\t#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t#endif\n\t#endif\n#endif\nvec3 geometryNormal = normal;",normal_fragment_maps:"#ifdef OBJECTSPACE_NORMALMAP\n\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( TANGENTSPACE_NORMALMAP )\n\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\t#ifdef USE_TANGENT\n\t\tnormal = normalize( vTBN * mapN );\n\t#else\n\t\tnormal = perturbNormal2Arb( - vViewPosition, normal, mapN, faceDirection );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif",normal_pars_fragment:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_pars_vertex:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_vertex:"#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif",normalmap_pars_fragment:"#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN, float faceDirection ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tvec3 N = surf_norm;\n\t\tvec3 q1perp = cross( q1, N );\n\t\tvec3 q0perp = cross( N, q0 );\n\t\tvec3 T = q1perp * st0.x + q0perp * st1.x;\n\t\tvec3 B = q1perp * st0.y + q0perp * st1.y;\n\t\tfloat det = max( dot( T, T ), dot( B, B ) );\n\t\tfloat scale = ( det == 0.0 ) ? 0.0 : faceDirection * inversesqrt( det );\n\t\treturn normalize( T * ( mapN.x * scale ) + B * ( mapN.y * scale ) + N * mapN.z );\n\t}\n#endif",clearcoat_normal_fragment_begin:"#ifdef USE_CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif",clearcoat_normal_fragment_maps:"#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\t#ifdef USE_TANGENT\n\t\tclearcoatNormal = normalize( vTBN * clearcoatMapN );\n\t#else\n\t\tclearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN, faceDirection );\n\t#endif\n#endif",clearcoat_pars_fragment:"#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif",output_fragment:"#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= transmissionAlpha + 0.1;\n#endif\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );",packing:"vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nvec4 pack2HalfToRGBA( vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\nvec2 unpackRGBATo2Half( vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n\treturn linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\n}",premultiplied_alpha_fragment:"#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif",project_vertex:"vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;",dithering_fragment:"#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif",dithering_pars_fragment:"#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif",roughnessmap_fragment:"float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif",roughnessmap_pars_fragment:"#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif",shadowmap_pars_fragment:"#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\t\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\n\t}\n\tfloat VSMShadow (sampler2D shadow, vec2 uv, float compare ){\n\t\tfloat occlusion = 1.0;\n\t\tvec2 distribution = texture2DDistribution( shadow, uv );\n\t\tfloat hard_shadow = step( compare , distribution.x );\n\t\tif (hard_shadow != 1.0 ) {\n\t\t\tfloat distance = compare - distribution.x ;\n\t\t\tfloat variance = max( 0.00000, distribution.y * distribution.y );\n\t\t\tfloat softness_probability = variance / (variance + distance * distance );\t\t\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\t\t\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\t\t}\n\t\treturn occlusion;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n\t\tbool inFrustum = all( inFrustumVec );\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\t\tbool frustumTest = all( frustumTestVec );\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx = texelSize.x;\n\t\t\tfloat dy = texelSize.y;\n\t\t\tvec2 uv = shadowCoord.xy;\n\t\t\tvec2 f = fract( uv * shadowMapSize + 0.5 );\n\t\t\tuv -= f * texelSize;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t f.y )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\t\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn shadow;\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\n\t}\n#endif",shadowmap_pars_vertex:"#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif",shadowmap_vertex:"#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0 || NUM_SPOT_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0\n\t\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\tvec4 shadowWorldPosition;\n\t#endif\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n#endif",shadowmask_pars_fragment:"float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}",skinbase_vertex:"#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif",skinning_pars_vertex:"#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform highp sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif",skinning_vertex:"#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif",skinnormal_vertex:"#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif",specularmap_fragment:"float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif",specularmap_pars_fragment:"#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif",tonemapping_fragment:"#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif",tonemapping_pars_fragment:"#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }",transmission_fragment:"#ifdef USE_TRANSMISSION\n\tfloat transmissionAlpha = 1.0;\n\tfloat transmissionFactor = transmission;\n\tfloat thicknessFactor = thickness;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\ttransmissionFactor *= texture2D( transmissionMap, vUv ).r;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tthicknessFactor *= texture2D( thicknessMap, vUv ).g;\n\t#endif\n\tvec3 pos = vWorldPosition;\n\tvec3 v = normalize( cameraPosition - pos );\n\tvec3 n = inverseTransformDirection( normal, viewMatrix );\n\tvec4 transmission = getIBLVolumeRefraction(\n\t\tn, v, roughnessFactor, material.diffuseColor, material.specularColor, material.specularF90,\n\t\tpos, modelMatrix, viewMatrix, projectionMatrix, ior, thicknessFactor,\n\t\tattenuationColor, attenuationDistance );\n\ttotalDiffuse = mix( totalDiffuse, transmission.rgb, transmissionFactor );\n\ttransmissionAlpha = mix( transmissionAlpha, transmission.a, transmissionFactor );\n#endif",transmission_pars_fragment:"#ifdef USE_TRANSMISSION\n\tuniform float transmission;\n\tuniform float thickness;\n\tuniform float attenuationDistance;\n\tuniform vec3 attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tuniform sampler2D transmissionMap;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tuniform sampler2D thicknessMap;\n\t#endif\n\tuniform vec2 transmissionSamplerSize;\n\tuniform sampler2D transmissionSamplerMap;\n\tuniform mat4 modelMatrix;\n\tuniform mat4 projectionMatrix;\n\tvarying vec3 vWorldPosition;\n\tvec3 getVolumeTransmissionRay( vec3 n, vec3 v, float thickness, float ior, mat4 modelMatrix ) {\n\t\tvec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n\t\tvec3 modelScale;\n\t\tmodelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n\t\tmodelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n\t\tmodelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n\t\treturn normalize( refractionVector ) * thickness * modelScale;\n\t}\n\tfloat applyIorToRoughness( float roughness, float ior ) {\n\t\treturn roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n\t}\n\tvec4 getTransmissionSample( vec2 fragCoord, float roughness, float ior ) {\n\t\tfloat framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\treturn texture2DLodEXT( transmissionSamplerMap, fragCoord.xy, framebufferLod );\n\t\t#else\n\t\t\treturn texture2D( transmissionSamplerMap, fragCoord.xy, framebufferLod );\n\t\t#endif\n\t}\n\tvec3 applyVolumeAttenuation( vec3 radiance, float transmissionDistance, vec3 attenuationColor, float attenuationDistance ) {\n\t\tif ( attenuationDistance == 0.0 ) {\n\t\t\treturn radiance;\n\t\t} else {\n\t\t\tvec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n\t\t\tvec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );\t\t\treturn transmittance * radiance;\n\t\t}\n\t}\n\tvec4 getIBLVolumeRefraction( vec3 n, vec3 v, float roughness, vec3 diffuseColor, vec3 specularColor, float specularF90,\n\t\tvec3 position, mat4 modelMatrix, mat4 viewMatrix, mat4 projMatrix, float ior, float thickness,\n\t\tvec3 attenuationColor, float attenuationDistance ) {\n\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\trefractionCoords += 1.0;\n\t\trefractionCoords /= 2.0;\n\t\tvec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\tvec3 attenuatedColor = applyVolumeAttenuation( transmittedLight.rgb, length( transmissionRay ), attenuationColor, attenuationDistance );\n\t\tvec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n\t\treturn vec4( ( 1.0 - F ) * attenuatedColor * diffuseColor, transmittedLight.a );\n\t}\n#endif",uv_pars_fragment:"#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif",uv_pars_vertex:"#ifdef USE_UV\n\t#ifdef UVS_VERTEX_ONLY\n\t\tvec2 vUv;\n\t#else\n\t\tvarying vec2 vUv;\n\t#endif\n\tuniform mat3 uvTransform;\n#endif",uv_vertex:"#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif",uv2_pars_fragment:"#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif",uv2_pars_vertex:"#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n\tuniform mat3 uv2Transform;\n#endif",uv2_vertex:"#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif",worldpos_vertex:"#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION )\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif",background_vert:"varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}",background_frag:"uniform sampler2D t2D;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}",cube_vert:"varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}",cube_frag:"#include <envmap_common_pars_fragment>\nuniform float opacity;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\tvec3 vReflect = vWorldDirection;\n\t#include <envmap_fragment>\n\tgl_FragColor = envColor;\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}",depth_vert:"#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvHighPrecisionZW = gl_Position.zw;\n}",depth_frag:"#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <logdepthbuf_fragment>\n\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#endif\n}",distanceRGBA_vert:"#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}",distanceRGBA_frag:"#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}",equirect_vert:"varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}",equirect_frag:"uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tvec4 texColor = texture2D( tEquirect, sampleUV );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}",linedashed_vert:"uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}",linedashed_frag:"uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}",meshbasic_vert:"#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinbase_vertex>\n\t\t#include <skinnormal_vertex>\n\t\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}",meshbasic_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\treflectedLight.indirectDiffuse += lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshlambert_vert:"#define LAMBERT\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <lights_lambert_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",meshlambert_frag:"uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <emissivemap_fragment>\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;\n\t#else\n\t\treflectedLight.indirectDiffuse += vIndirectFront;\n\t#endif\n\t#include <lightmap_fragment>\n\treflectedLight.indirectDiffuse *= BRDF_Lambert( diffuseColor.rgb );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n\t#else\n\t\treflectedLight.directDiffuse = vLightFront;\n\t#endif\n\treflectedLight.directDiffuse *= BRDF_Lambert( diffuseColor.rgb ) * getShadowMask();\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshmatcap_vert:"#define MATCAP\nvarying vec3 vViewPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}",meshmatcap_frag:"#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <fog_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t\tmatcapColor = matcapTexelToLinear( matcapColor );\n\t#else\n\t\tvec4 matcapColor = vec4( 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshnormal_vert:"#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}",meshnormal_frag:"#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}",meshphong_vert:"#define PHONG\nvarying vec3 vViewPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",meshphong_frag:"#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshphysical_vert:"#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n#ifdef USE_TRANSMISSION\n\tvWorldPosition = worldPosition.xyz;\n#endif\n}",meshphysical_frag:"#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define SPECULAR\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULARINTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n\t#ifdef USE_SPECULARCOLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEENCOLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEENROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_physical_pars_fragment>\n#include <transmission_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include <transmission_fragment>\n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n\t\tfloat sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );\n\t\toutgoingLight = outgoingLight * sheenEnergyComp + sheenSpecular;\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + clearcoatSpecular * material.clearcoat;\n\t#endif\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshtoon_vert:"#define TOON\nvarying vec3 vViewPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",meshtoon_frag:"#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_toon_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",points_vert:"uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}",points_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}",shadow_vert:"#include <common>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",shadow_frag:"uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}",sprite_vert:"uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n\tvec2 scale;\n\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}",sprite_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}"},wr={common:{diffuse:{value:new ys(16777215)},opacity:{value:1},map:{value:null},uvTransform:{value:new ki},uv2Transform:{value:new ki},alphaMap:{value:null},alphaTest:{value:0}},specularmap:{specularMap:{value:null}},envmap:{envMap:{value:null},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1}},emissivemap:{emissiveMap:{value:null}},bumpmap:{bumpMap:{value:null},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalScale:{value:new Ri(1,1)}},displacementmap:{displacementMap:{value:null},displacementScale:{value:1},displacementBias:{value:0}},roughnessmap:{roughnessMap:{value:null}},metalnessmap:{metalnessMap:{value:null}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new ys(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotShadowMap:{value:[]},spotShadowMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new ys(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaTest:{value:0},uvTransform:{value:new ki}},sprite:{diffuse:{value:new ys(16777215)},opacity:{value:1},center:{value:new Ri(.5,.5)},rotation:{value:0},map:{value:null},alphaMap:{value:null},alphaTest:{value:0},uvTransform:{value:new ki}}},br={basic:{uniforms:er([wr.common,wr.specularmap,wr.envmap,wr.aomap,wr.lightmap,wr.fog]),vertexShader:xr.meshbasic_vert,fragmentShader:xr.meshbasic_frag},lambert:{uniforms:er([wr.common,wr.specularmap,wr.envmap,wr.aomap,wr.lightmap,wr.emissivemap,wr.fog,wr.lights,{emissive:{value:new ys(0)}}]),vertexShader:xr.meshlambert_vert,fragmentShader:xr.meshlambert_frag},phong:{uniforms:er([wr.common,wr.specularmap,wr.envmap,wr.aomap,wr.lightmap,wr.emissivemap,wr.bumpmap,wr.normalmap,wr.displacementmap,wr.fog,wr.lights,{emissive:{value:new ys(0)},specular:{value:new ys(1118481)},shininess:{value:30}}]),vertexShader:xr.meshphong_vert,fragmentShader:xr.meshphong_frag},standard:{uniforms:er([wr.common,wr.envmap,wr.aomap,wr.lightmap,wr.emissivemap,wr.bumpmap,wr.normalmap,wr.displacementmap,wr.roughnessmap,wr.metalnessmap,wr.fog,wr.lights,{emissive:{value:new ys(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:xr.meshphysical_vert,fragmentShader:xr.meshphysical_frag},toon:{uniforms:er([wr.common,wr.aomap,wr.lightmap,wr.emissivemap,wr.bumpmap,wr.normalmap,wr.displacementmap,wr.gradientmap,wr.fog,wr.lights,{emissive:{value:new ys(0)}}]),vertexShader:xr.meshtoon_vert,fragmentShader:xr.meshtoon_frag},matcap:{uniforms:er([wr.common,wr.bumpmap,wr.normalmap,wr.displacementmap,wr.fog,{matcap:{value:null}}]),vertexShader:xr.meshmatcap_vert,fragmentShader:xr.meshmatcap_frag},points:{uniforms:er([wr.points,wr.fog]),vertexShader:xr.points_vert,fragmentShader:xr.points_frag},dashed:{uniforms:er([wr.common,wr.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:xr.linedashed_vert,fragmentShader:xr.linedashed_frag},depth:{uniforms:er([wr.common,wr.displacementmap]),vertexShader:xr.depth_vert,fragmentShader:xr.depth_frag},normal:{uniforms:er([wr.common,wr.bumpmap,wr.normalmap,wr.displacementmap,{opacity:{value:1}}]),vertexShader:xr.meshnormal_vert,fragmentShader:xr.meshnormal_frag},sprite:{uniforms:er([wr.sprite,wr.fog]),vertexShader:xr.sprite_vert,fragmentShader:xr.sprite_frag},background:{uniforms:{uvTransform:{value:new ki},t2D:{value:null}},vertexShader:xr.background_vert,fragmentShader:xr.background_frag},cube:{uniforms:er([wr.envmap,{opacity:{value:1}}]),vertexShader:xr.cube_vert,fragmentShader:xr.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:xr.equirect_vert,fragmentShader:xr.equirect_frag},distanceRGBA:{uniforms:er([wr.common,wr.displacementmap,{referencePosition:{value:new Yi},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:xr.distanceRGBA_vert,fragmentShader:xr.distanceRGBA_frag},shadow:{uniforms:er([wr.lights,wr.fog,{color:{value:new ys(0)},opacity:{value:1}}]),vertexShader:xr.shadow_vert,fragmentShader:xr.shadow_frag}};function Sr(t,e,i,n,s){const r=new ys(0);let a,o,l=0,h=null,c=0,u=null;function d(t,e){i.buffers.color.setClear(t.r,t.g,t.b,e,s)}return{getClearColor:function(){return r},setClearColor:function(t,e=1){r.set(t),l=e,d(r,l)},getClearAlpha:function(){return l},setClearAlpha:function(t){l=t,d(r,l)},render:function(i,s){let p=!1,f=!0===s.isScene?s.background:null;f&&f.isTexture&&(f=e.get(f));const m=t.xr,_=m.getSession&&m.getSession();_&&"additive"===_.environmentBlendMode&&(f=null),null===f?d(r,l):f&&f.isColor&&(d(f,1),p=!0),(t.autoClear||p)&&t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil),f&&(f.isCubeTexture||f.mapping===Ht)?(void 0===o&&(o=new Zs(new Qs(1,1,1),new nr({name:"BackgroundCubeMaterial",uniforms:tr(br.cube.uniforms),vertexShader:br.cube.vertexShader,fragmentShader:br.cube.fragmentShader,side:Q,depthTest:!1,depthWrite:!1,fog:!1})),o.geometry.deleteAttribute("normal"),o.geometry.deleteAttribute("uv"),o.onBeforeRender=function(t,e,i){this.matrixWorld.copyPosition(i.matrixWorld)},Object.defineProperty(o.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),n.update(o)),o.material.uniforms.envMap.value=f,o.material.uniforms.flipEnvMap.value=f.isCubeTexture&&!1===f.isRenderTargetTexture?-1:1,h===f&&c===f.version&&u===t.toneMapping||(o.material.needsUpdate=!0,h=f,c=f.version,u=t.toneMapping),i.unshift(o,o.geometry,o.material,0,0,null)):f&&f.isTexture&&(void 0===a&&(a=new Zs(new vr(2,2),new nr({name:"BackgroundMaterial",uniforms:tr(br.background.uniforms),vertexShader:br.background.vertexShader,fragmentShader:br.background.fragmentShader,side:K,depthTest:!1,depthWrite:!1,fog:!1})),a.geometry.deleteAttribute("normal"),Object.defineProperty(a.material,"map",{get:function(){return this.uniforms.t2D.value}}),n.update(a)),a.material.uniforms.t2D.value=f,!0===f.matrixAutoUpdate&&f.updateMatrix(),a.material.uniforms.uvTransform.value.copy(f.matrix),h===f&&c===f.version&&u===t.toneMapping||(a.material.needsUpdate=!0,h=f,c=f.version,u=t.toneMapping),i.unshift(a,a.geometry,a.material,0,0,null))}}}function Mr(t,e,i,n){const s=t.getParameter(34921),r=n.isWebGL2?null:e.get("OES_vertex_array_object"),a=n.isWebGL2||null!==r,o={},l=d(null);let h=l;function c(e){return n.isWebGL2?t.bindVertexArray(e):r.bindVertexArrayOES(e)}function u(e){return n.isWebGL2?t.deleteVertexArray(e):r.deleteVertexArrayOES(e)}function d(t){const e=[],i=[],n=[];for(let t=0;t<s;t++)e[t]=0,i[t]=0,n[t]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:e,enabledAttributes:i,attributeDivisors:n,object:t,attributes:{},index:null}}function p(){const t=h.newAttributes;for(let e=0,i=t.length;e<i;e++)t[e]=0}function f(t){m(t,0)}function m(i,s){const r=h.newAttributes,a=h.enabledAttributes,o=h.attributeDivisors;r[i]=1,0===a[i]&&(t.enableVertexAttribArray(i),a[i]=1),o[i]!==s&&((n.isWebGL2?t:e.get("ANGLE_instanced_arrays"))[n.isWebGL2?"vertexAttribDivisor":"vertexAttribDivisorANGLE"](i,s),o[i]=s)}function _(){const e=h.newAttributes,i=h.enabledAttributes;for(let n=0,s=i.length;n<s;n++)i[n]!==e[n]&&(t.disableVertexAttribArray(n),i[n]=0)}function g(e,i,s,r,a,o){!0!==n.isWebGL2||5124!==s&&5125!==s?t.vertexAttribPointer(e,i,s,r,a,o):t.vertexAttribIPointer(e,i,s,a,o)}function y(){v(),h!==l&&(h=l,c(h.object))}function v(){l.geometry=null,l.program=null,l.wireframe=!1}return{setup:function(s,l,u,y,v){let x=!1;if(a){const e=function(e,i,s){const a=!0===s.wireframe;let l=o[e.id];void 0===l&&(l={},o[e.id]=l);let h=l[i.id];void 0===h&&(h={},l[i.id]=h);let c=h[a];return void 0===c&&(c=d(n.isWebGL2?t.createVertexArray():r.createVertexArrayOES()),h[a]=c),c}(y,u,l);h!==e&&(h=e,c(h.object)),x=function(t,e){const i=h.attributes,n=t.attributes;let s=0;for(const t in n){const e=i[t],r=n[t];if(void 0===e)return!0;if(e.attribute!==r)return!0;if(e.data!==r.data)return!0;s++}return h.attributesNum!==s||h.index!==e}(y,v),x&&function(t,e){const i={},n=t.attributes;let s=0;for(const t in n){const e=n[t],r={};r.attribute=e,e.data&&(r.data=e.data),i[t]=r,s++}h.attributes=i,h.attributesNum=s,h.index=e}(y,v)}else{const t=!0===l.wireframe;h.geometry===y.id&&h.program===u.id&&h.wireframe===t||(h.geometry=y.id,h.program=u.id,h.wireframe=t,x=!0)}!0===s.isInstancedMesh&&(x=!0),null!==v&&i.update(v,34963),x&&(function(s,r,a,o){if(!1===n.isWebGL2&&(s.isInstancedMesh||o.isInstancedBufferGeometry)&&null===e.get("ANGLE_instanced_arrays"))return;p();const l=o.attributes,h=a.getAttributes(),c=r.defaultAttributeValues;for(const e in h){const n=h[e];if(n.location>=0){let r=l[e];if(void 0===r&&("instanceMatrix"===e&&s.instanceMatrix&&(r=s.instanceMatrix),"instanceColor"===e&&s.instanceColor&&(r=s.instanceColor)),void 0!==r){const e=r.normalized,a=r.itemSize,l=i.get(r);if(void 0===l)continue;const h=l.buffer,c=l.type,u=l.bytesPerElement;if(r.isInterleavedBufferAttribute){const i=r.data,l=i.stride,d=r.offset;if(i&&i.isInstancedInterleavedBuffer){for(let t=0;t<n.locationSize;t++)m(n.location+t,i.meshPerAttribute);!0!==s.isInstancedMesh&&void 0===o._maxInstanceCount&&(o._maxInstanceCount=i.meshPerAttribute*i.count)}else for(let t=0;t<n.locationSize;t++)f(n.location+t);t.bindBuffer(34962,h);for(let t=0;t<n.locationSize;t++)g(n.location+t,a/n.locationSize,c,e,l*u,(d+a/n.locationSize*t)*u)}else{if(r.isInstancedBufferAttribute){for(let t=0;t<n.locationSize;t++)m(n.location+t,r.meshPerAttribute);!0!==s.isInstancedMesh&&void 0===o._maxInstanceCount&&(o._maxInstanceCount=r.meshPerAttribute*r.count)}else for(let t=0;t<n.locationSize;t++)f(n.location+t);t.bindBuffer(34962,h);for(let t=0;t<n.locationSize;t++)g(n.location+t,a/n.locationSize,c,e,a*u,a/n.locationSize*t*u)}}else if(void 0!==c){const i=c[e];if(void 0!==i)switch(i.length){case 2:t.vertexAttrib2fv(n.location,i);break;case 3:t.vertexAttrib3fv(n.location,i);break;case 4:t.vertexAttrib4fv(n.location,i);break;default:t.vertexAttrib1fv(n.location,i)}}}}_()}(s,l,u,y),null!==v&&t.bindBuffer(34963,i.get(v).buffer))},reset:y,resetDefaultState:v,dispose:function(){y();for(const t in o){const e=o[t];for(const t in e){const i=e[t];for(const t in i)u(i[t].object),delete i[t];delete e[t]}delete o[t]}},releaseStatesOfGeometry:function(t){if(void 0===o[t.id])return;const e=o[t.id];for(const t in e){const i=e[t];for(const t in i)u(i[t].object),delete i[t];delete e[t]}delete o[t.id]},releaseStatesOfProgram:function(t){for(const e in o){const i=o[e];if(void 0===i[t.id])continue;const n=i[t.id];for(const t in n)u(n[t].object),delete n[t];delete i[t.id]}},initAttributes:p,enableAttribute:f,disableUnusedAttributes:_}}function Tr(t,e,i,n){const s=n.isWebGL2;let r;this.setMode=function(t){r=t},this.render=function(e,n){t.drawArrays(r,e,n),i.update(n,r,1)},this.renderInstances=function(n,a,o){if(0===o)return;let l,h;if(s)l=t,h="drawArraysInstanced";else if(l=e.get("ANGLE_instanced_arrays"),h="drawArraysInstancedANGLE",null===l)return;l[h](r,n,a,o),i.update(a,r,o)}}function Ar(t,e,i){let n;function s(e){if("highp"===e){if(t.getShaderPrecisionFormat(35633,36338).precision>0&&t.getShaderPrecisionFormat(35632,36338).precision>0)return"highp";e="mediump"}return"mediump"===e&&t.getShaderPrecisionFormat(35633,36337).precision>0&&t.getShaderPrecisionFormat(35632,36337).precision>0?"mediump":"lowp"}const r="undefined"!=typeof WebGL2RenderingContext&&t instanceof WebGL2RenderingContext||"undefined"!=typeof WebGL2ComputeRenderingContext&&t instanceof WebGL2ComputeRenderingContext;let a=void 0!==i.precision?i.precision:"highp";const o=s(a);o!==a&&(a=o);const l=r||e.has("WEBGL_draw_buffers"),h=!0===i.logarithmicDepthBuffer,c=t.getParameter(34930),u=t.getParameter(35660),d=t.getParameter(3379),p=t.getParameter(34076),f=t.getParameter(34921),m=t.getParameter(36347),_=t.getParameter(36348),g=t.getParameter(36349),y=u>0,v=r||e.has("OES_texture_float");return{isWebGL2:r,drawBuffers:l,getMaxAnisotropy:function(){if(void 0!==n)return n;if(!0===e.has("EXT_texture_filter_anisotropic")){const i=e.get("EXT_texture_filter_anisotropic");n=t.getParameter(i.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else n=0;return n},getMaxPrecision:s,precision:a,logarithmicDepthBuffer:h,maxTextures:c,maxVertexTextures:u,maxTextureSize:d,maxCubemapSize:p,maxAttributes:f,maxVertexUniforms:m,maxVaryings:_,maxFragmentUniforms:g,vertexTextures:y,floatFragmentTextures:v,floatVertexTextures:y&&v,maxSamples:r?t.getParameter(36183):0}}function Cr(t){const e=this;let i=null,n=0,s=!1,r=!1;const a=new pr,o=new ki,l={value:null,needsUpdate:!1};function h(){l.value!==i&&(l.value=i,l.needsUpdate=n>0),e.numPlanes=n,e.numIntersection=0}function c(t,i,n,s){const r=null!==t?t.length:0;let h=null;if(0!==r){if(h=l.value,!0!==s||null===h){const e=n+4*r,s=i.matrixWorldInverse;o.getNormalMatrix(s),(null===h||h.length<e)&&(h=new Float32Array(e));for(let e=0,i=n;e!==r;++e,i+=4)a.copy(t[e]).applyMatrix4(s,o),a.normal.toArray(h,i),h[i+3]=a.constant}l.value=h,l.needsUpdate=!0}return e.numPlanes=r,e.numIntersection=0,h}this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(t,e,r){const a=0!==t.length||e||0!==n||s;return s=e,i=c(t,r,0),n=t.length,a},this.beginShadows=function(){r=!0,c(null)},this.endShadows=function(){r=!1,h()},this.setState=function(e,a,o){const u=e.clippingPlanes,d=e.clipIntersection,p=e.clipShadows,f=t.get(e);if(!s||null===u||0===u.length||r&&!p)r?c(null):h();else{const t=r?0:n,e=4*t;let s=f.clippingState||null;l.value=s,s=c(u,a,e,o);for(let t=0;t!==e;++t)s[t]=i[t];f.clippingState=s,this.numIntersection=d?this.numPlanes:0,this.numPlanes+=t}}}function Er(t){let e=new WeakMap;function i(t,e){return e===Wt?t.mapping=Ut:e===Gt&&(t.mapping=Vt),t}function n(t){const i=t.target;i.removeEventListener("dispose",n);const s=e.get(i);void 0!==s&&(e.delete(i),s.dispose())}return{get:function(s){if(s&&s.isTexture&&!1===s.isRenderTargetTexture){const r=s.mapping;if(r===Wt||r===Gt){if(e.has(s))return i(e.get(s).texture,s.mapping);{const r=s.image;if(r&&r.height>0){const a=t.getRenderTarget(),o=new hr(r.height/2);return o.fromEquirectangularTexture(t,s),e.set(s,o),t.setRenderTarget(a),s.addEventListener("dispose",n),i(o.texture,s.mapping)}return null}}}return s},dispose:function(){e=new WeakMap}}}br.physical={uniforms:er([br.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatNormalScale:{value:new Ri(1,1)},clearcoatNormalMap:{value:null},sheen:{value:0},sheenColor:{value:new ys(0)},sheenColorMap:{value:null},sheenRoughness:{value:0},sheenRoughnessMap:{value:null},transmission:{value:0},transmissionMap:{value:null},transmissionSamplerSize:{value:new Ri},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},attenuationDistance:{value:0},attenuationColor:{value:new ys(0)},specularIntensity:{value:0},specularIntensityMap:{value:null},specularColor:{value:new ys(1,1,1)},specularColorMap:{value:null}}]),vertexShader:xr.meshphysical_vert,fragmentShader:xr.meshphysical_frag};class zr extends sr{constructor(t=-1,e=1,i=1,n=-1,s=.1,r=2e3){super(),this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=i,this.bottom=n,this.near=s,this.far=r,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom,this.near=t.near,this.far=t.far,this.zoom=t.zoom,this.view=null===t.view?null:Object.assign({},t.view),this}setViewOffset(t,e,i,n,s,r){null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=i,this.view.offsetY=n,this.view.width=s,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=(this.right-this.left)/(2*this.zoom),e=(this.top-this.bottom)/(2*this.zoom),i=(this.right+this.left)/2,n=(this.top+this.bottom)/2;let s=i-t,r=i+t,a=n+e,o=n-e;if(null!==this.view&&this.view.enabled){const t=(this.right-this.left)/this.view.fullWidth/this.zoom,e=(this.top-this.bottom)/this.view.fullHeight/this.zoom;s+=t*this.view.offsetX,r=s+t*this.view.width,a-=e*this.view.offsetY,o=a-e*this.view.height}this.projectionMatrix.makeOrthographic(s,r,a,o,this.near,this.far),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,null!==this.view&&(e.object.view=Object.assign({},this.view)),e}}zr.prototype.isOrthographicCamera=!0;class Ir extends nr{constructor(t){super(t),this.type="RawShaderMaterial"}}Ir.prototype.isRawShaderMaterial=!0;const Lr=Math.pow(2,8),Nr=[.125,.215,.35,.446,.526,.582],Pr=5+Nr.length,Dr={[yi]:0,[vi]:1},Fr=new zr,{_lodPlanes:Or,_sizeLods:Rr,_sigmas:kr}=jr(),Br=new ys;let Ur=null;const Vr=(1+Math.sqrt(5))/2,Wr=1/Vr,Gr=[new Yi(1,1,1),new Yi(-1,1,1),new Yi(1,1,-1),new Yi(-1,1,-1),new Yi(0,Vr,Wr),new Yi(0,Vr,-Wr),new Yi(Wr,0,Vr),new Yi(-Wr,0,Vr),new Yi(Vr,Wr,0),new Yi(-Vr,Wr,0)];class Hr{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._blurMaterial=function(t){const e=new Float32Array(20),i=new Yi(0,1,0);return new Ir({name:"SphericalGaussianBlur",defines:{n:20},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:e},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:i}},vertexShader:"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute vec3 position;\n\t\tattribute vec2 uv;\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t",fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform int samples;\n\t\t\tuniform float weights[ n ];\n\t\t\tuniform bool latitudinal;\n\t\t\tuniform float dTheta;\n\t\t\tuniform float mipInt;\n\t\t\tuniform vec3 poleAxis;\n\n\t\t\t\n\n\t\tuniform int inputEncoding;\n\n\t\t#include <encodings_pars_fragment>\n\n\t\tvec4 inputTexelToLinear( vec4 value ) {\n\n\t\t\tif ( inputEncoding == 0 ) {\n\n\t\t\t\treturn value;\n\n\t\t\t} else {\n\n\t\t\t\treturn sRGBToLinear( value );\n\n\t\t\t}\n\n\t\t}\n\n\t\tvec4 envMapTexelToLinear( vec4 color ) {\n\n\t\t\treturn inputTexelToLinear( color );\n\n\t\t}\n\t\n\n\t\t\t#define ENVMAP_TYPE_CUBE_UV\n\t\t\t#include <cube_uv_reflection_fragment>\n\n\t\t\tvec3 getSample( float theta, vec3 axis ) {\n\n\t\t\t\tfloat cosTheta = cos( theta );\n\t\t\t\t// Rodrigues' axis-angle rotation\n\t\t\t\tvec3 sampleDirection = vOutputDirection * cosTheta\n\t\t\t\t\t+ cross( axis, vOutputDirection ) * sin( theta )\n\t\t\t\t\t+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );\n\n\t\t\t\treturn bilinearCubeUV( envMap, sampleDirection, mipInt );\n\n\t\t\t}\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );\n\n\t\t\t\tif ( all( equal( axis, vec3( 0.0 ) ) ) ) {\n\n\t\t\t\t\taxis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );\n\n\t\t\t\t}\n\n\t\t\t\taxis = normalize( axis );\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t\t\t\tgl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );\n\n\t\t\t\tfor ( int i = 1; i < n; i++ ) {\n\n\t\t\t\t\tif ( i >= samples ) {\n\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t}\n\n\t\t\t\t\tfloat theta = dTheta * float( i );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( theta, axis );\n\n\t\t\t\t}\n\n\t\t\t}\n\t\t",blending:et,depthTest:!1,depthWrite:!1})}(),this._equirectShader=null,this._cubemapShader=null,this._compileMaterial(this._blurMaterial)}fromScene(t,e=0,i=.1,n=100){Ur=this._renderer.getRenderTarget();const s=this._allocateTargets();return this._sceneToCubeUV(t,i,n,s),e>0&&this._blur(s,0,0,e),this._applyPMREM(s),this._cleanup(s),s}fromEquirectangular(t){return this._fromTexture(t)}fromCubemap(t){return this._fromTexture(t)}compileCubemapShader(){null===this._cubemapShader&&(this._cubemapShader=Yr(),this._compileMaterial(this._cubemapShader))}compileEquirectangularShader(){null===this._equirectShader&&(this._equirectShader=$r(),this._compileMaterial(this._equirectShader))}dispose(){this._blurMaterial.dispose(),null!==this._cubemapShader&&this._cubemapShader.dispose(),null!==this._equirectShader&&this._equirectShader.dispose();for(let t=0;t<Or.length;t++)Or[t].dispose()}_cleanup(t){this._pingPongRenderTarget.dispose(),this._renderer.setRenderTarget(Ur),t.scissorTest=!1,Jr(t,0,0,t.width,t.height)}_fromTexture(t){Ur=this._renderer.getRenderTarget();const e=this._allocateTargets(t);return this._textureToCubeUV(t,e),this._applyPMREM(e),this._cleanup(e),e}_allocateTargets(t){const e={magFilter:Kt,minFilter:Kt,generateMipmaps:!1,type:le,format:me,encoding:yi,depthBuffer:!1},i=qr(e);return i.depthBuffer=!t,this._pingPongRenderTarget=qr(e),i}_compileMaterial(t){const e=new Zs(Or[0],t);this._renderer.compile(e,Fr)}_sceneToCubeUV(t,e,i,n){const s=new rr(90,1,e,i),r=[1,-1,1,1,1,1],a=[1,1,1,-1,-1,-1],o=this._renderer,l=o.autoClear,h=o.toneMapping;o.getClearColor(Br),o.toneMapping=Dt,o.autoClear=!1;const c=new vs({name:"PMREM.Background",side:Q,depthWrite:!1,depthTest:!1}),u=new Zs(new Qs,c);let d=!1;const p=t.background;p?p.isColor&&(c.color.copy(p),t.background=null,d=!0):(c.color.copy(Br),d=!0);for(let e=0;e<6;e++){const i=e%3;0==i?(s.up.set(0,r[e],0),s.lookAt(a[e],0,0)):1==i?(s.up.set(0,0,r[e]),s.lookAt(0,a[e],0)):(s.up.set(0,r[e],0),s.lookAt(0,0,a[e])),Jr(n,i*Lr,e>2?Lr:0,Lr,Lr),o.setRenderTarget(n),d&&o.render(u,s),o.render(t,s)}u.geometry.dispose(),u.material.dispose(),o.toneMapping=h,o.autoClear=l,t.background=p}_setEncoding(t,e){!0===this._renderer.capabilities.isWebGL2&&e.format===me&&e.type===ee&&e.encoding===vi?t.value=Dr[yi]:t.value=Dr[e.encoding]}_textureToCubeUV(t,e){const i=this._renderer,n=t.mapping===Ut||t.mapping===Vt;n?null==this._cubemapShader&&(this._cubemapShader=Yr()):null==this._equirectShader&&(this._equirectShader=$r());const s=n?this._cubemapShader:this._equirectShader,r=new Zs(Or[0],s),a=s.uniforms;a.envMap.value=t,n||a.texelSize.value.set(1/t.image.width,1/t.image.height),this._setEncoding(a.inputEncoding,t),Jr(e,0,0,3*Lr,2*Lr),i.setRenderTarget(e),i.render(r,Fr)}_applyPMREM(t){const e=this._renderer,i=e.autoClear;e.autoClear=!1;for(let e=1;e<Pr;e++){const i=Math.sqrt(kr[e]*kr[e]-kr[e-1]*kr[e-1]),n=Gr[(e-1)%Gr.length];this._blur(t,e-1,e,i,n)}e.autoClear=i}_blur(t,e,i,n,s){const r=this._pingPongRenderTarget;this._halfBlur(t,r,e,i,n,"latitudinal",s),this._halfBlur(r,t,i,i,n,"longitudinal",s)}_halfBlur(t,e,i,n,s,r,a){const o=this._renderer,l=this._blurMaterial,h=new Zs(Or[n],l),c=l.uniforms,u=Rr[i]-1,d=isFinite(s)?Math.PI/(2*u):2*Math.PI/39,p=s/d,f=isFinite(s)?1+Math.floor(3*p):20,m=[];let _=0;for(let t=0;t<20;++t){const e=t/p,i=Math.exp(-e*e/2);m.push(i),0==t?_+=i:t<f&&(_+=2*i)}for(let t=0;t<m.length;t++)m[t]=m[t]/_;c.envMap.value=t.texture,c.samples.value=f,c.weights.value=m,c.latitudinal.value="latitudinal"===r,a&&(c.poleAxis.value=a),c.dTheta.value=d,c.mipInt.value=8-i;const g=Rr[n];Jr(e,3*Math.max(0,Lr-2*g),(0===n?0:2*Lr)+2*g*(n>4?n-8+4:0),3*g,2*g),o.setRenderTarget(e),o.render(h,Fr)}}function jr(){const t=[],e=[],i=[];let n=8;for(let s=0;s<Pr;s++){const r=Math.pow(2,n);e.push(r);let a=1/r;s>4?a=Nr[s-8+4-1]:0==s&&(a=0),i.push(a);const o=1/(r-1),l=-o/2,h=1+o/2,c=[l,l,h,l,h,h,l,l,h,h,l,h],u=6,d=6,p=3,f=2,m=1,_=new Float32Array(p*d*u),g=new Float32Array(f*d*u),y=new Float32Array(m*d*u);for(let t=0;t<u;t++){const e=t%3*2/3-1,i=t>2?0:-1,n=[e,i,0,e+2/3,i,0,e+2/3,i+1,0,e,i,0,e+2/3,i+1,0,e,i+1,0];_.set(n,p*d*t),g.set(c,f*d*t);const s=[t,t,t,t,t,t];y.set(s,m*d*t)}const v=new Ps;v.setAttribute("position",new bs(_,p)),v.setAttribute("uv",new bs(g,f)),v.setAttribute("faceIndex",new bs(y,m)),t.push(v),n>4&&n--}return{_lodPlanes:t,_sizeLods:e,_sigmas:i}}function qr(t){const e=new qi(3*Lr,3*Lr,t);return e.texture.mapping=Ht,e.texture.name="PMREM.cubeUv",e.scissorTest=!0,e}function Jr(t,e,i,n,s){t.viewport.set(e,i,n,s),t.scissor.set(e,i,n,s)}function $r(){const t=new Ri(1,1);return new Ir({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null},texelSize:{value:t},inputEncoding:{value:Dr[yi]}},vertexShader:"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute vec3 position;\n\t\tattribute vec2 uv;\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t",fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform vec2 texelSize;\n\n\t\t\t\n\n\t\tuniform int inputEncoding;\n\n\t\t#include <encodings_pars_fragment>\n\n\t\tvec4 inputTexelToLinear( vec4 value ) {\n\n\t\t\tif ( inputEncoding == 0 ) {\n\n\t\t\t\treturn value;\n\n\t\t\t} else {\n\n\t\t\t\treturn sRGBToLinear( value );\n\n\t\t\t}\n\n\t\t}\n\n\t\tvec4 envMapTexelToLinear( vec4 color ) {\n\n\t\t\treturn inputTexelToLinear( color );\n\n\t\t}\n\t\n\n\t\t\t#include <common>\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\n\t\t\t\tvec3 outputDirection = normalize( vOutputDirection );\n\t\t\t\tvec2 uv = equirectUv( outputDirection );\n\n\t\t\t\tvec2 f = fract( uv / texelSize - 0.5 );\n\t\t\t\tuv -= f * texelSize;\n\t\t\t\tvec3 tl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\t\t\t\tuv.x += texelSize.x;\n\t\t\t\tvec3 tr = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\t\t\t\tuv.y += texelSize.y;\n\t\t\t\tvec3 br = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\t\t\t\tuv.x -= texelSize.x;\n\t\t\t\tvec3 bl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\n\t\t\t\tvec3 tm = mix( tl, tr, f.x );\n\t\t\t\tvec3 bm = mix( bl, br, f.x );\n\t\t\t\tgl_FragColor.rgb = mix( tm, bm, f.y );\n\n\t\t\t}\n\t\t",blending:et,depthTest:!1,depthWrite:!1})}function Yr(){return new Ir({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},inputEncoding:{value:Dr[yi]}},vertexShader:"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute vec3 position;\n\t\tattribute vec2 uv;\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t",fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform samplerCube envMap;\n\n\t\t\t\n\n\t\tuniform int inputEncoding;\n\n\t\t#include <encodings_pars_fragment>\n\n\t\tvec4 inputTexelToLinear( vec4 value ) {\n\n\t\t\tif ( inputEncoding == 0 ) {\n\n\t\t\t\treturn value;\n\n\t\t\t} else {\n\n\t\t\t\treturn sRGBToLinear( value );\n\n\t\t\t}\n\n\t\t}\n\n\t\tvec4 envMapTexelToLinear( vec4 color ) {\n\n\t\t\treturn inputTexelToLinear( color );\n\n\t\t}\n\t\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = envMapTexelToLinear( textureCube( envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ) ) );\n\n\t\t\t}\n\t\t",blending:et,depthTest:!1,depthWrite:!1})}function Xr(t){let e=new WeakMap,i=null;function n(t){const i=t.target;i.removeEventListener("dispose",n);const s=e.get(i);void 0!==s&&(e.delete(i),s.dispose())}return{get:function(s){if(s&&s.isTexture&&!1===s.isRenderTargetTexture){const r=s.mapping,a=r===Wt||r===Gt,o=r===Ut||r===Vt;if(a||o){if(e.has(s))return e.get(s).texture;{const r=s.image;if(a&&r&&r.height>0||o&&r&&function(t){let e=0;for(let i=0;i<6;i++)void 0!==t[i]&&e++;return 6===e}(r)){const r=t.getRenderTarget();null===i&&(i=new Hr(t));const o=a?i.fromEquirectangular(s):i.fromCubemap(s);return e.set(s,o),t.setRenderTarget(r),s.addEventListener("dispose",n),o.texture}return null}}}return s},dispose:function(){e=new WeakMap,null!==i&&(i.dispose(),i=null)}}}function Zr(t){const e={};function i(i){if(void 0!==e[i])return e[i];let n;switch(i){case"WEBGL_depth_texture":n=t.getExtension("WEBGL_depth_texture")||t.getExtension("MOZ_WEBGL_depth_texture")||t.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":n=t.getExtension("EXT_texture_filter_anisotropic")||t.getExtension("MOZ_EXT_texture_filter_anisotropic")||t.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":n=t.getExtension("WEBGL_compressed_texture_s3tc")||t.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||t.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":n=t.getExtension("WEBGL_compressed_texture_pvrtc")||t.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:n=t.getExtension(i)}return e[i]=n,n}return{has:function(t){return null!==i(t)},init:function(t){t.isWebGL2?i("EXT_color_buffer_float"):(i("WEBGL_depth_texture"),i("OES_texture_float"),i("OES_texture_half_float"),i("OES_texture_half_float_linear"),i("OES_standard_derivatives"),i("OES_element_index_uint"),i("OES_vertex_array_object"),i("ANGLE_instanced_arrays")),i("OES_texture_float_linear"),i("EXT_color_buffer_half_float"),i("WEBGL_multisampled_render_to_texture")},get:function(t){return i(t)}}}function Kr(t,e,i,n){const s={},r=new WeakMap;function a(t){const o=t.target;null!==o.index&&e.remove(o.index);for(const t in o.attributes)e.remove(o.attributes[t]);o.removeEventListener("dispose",a),delete s[o.id];const l=r.get(o);l&&(e.remove(l),r.delete(o)),n.releaseStatesOfGeometry(o),!0===o.isInstancedBufferGeometry&&delete o._maxInstanceCount,i.memory.geometries--}function o(t){const i=[],n=t.index,s=t.attributes.position;let a=0;if(null!==n){const t=n.array;a=n.version;for(let e=0,n=t.length;e<n;e+=3){const n=t[e+0],s=t[e+1],r=t[e+2];i.push(n,s,s,r,r,n)}}else{const t=s.array;a=s.version;for(let e=0,n=t.length/3-1;e<n;e+=3){const t=e+0,n=e+1,s=e+2;i.push(t,n,n,s,s,t)}}const o=new(Bi(i)>65535?Ms:Ss)(i,1);o.version=a;const l=r.get(t);l&&e.remove(l),r.set(t,o)}return{get:function(t,e){return!0===s[e.id]||(e.addEventListener("dispose",a),s[e.id]=!0,i.memory.geometries++),e},update:function(t){const i=t.attributes;for(const t in i)e.update(i[t],34962);const n=t.morphAttributes;for(const t in n){const i=n[t];for(let t=0,n=i.length;t<n;t++)e.update(i[t],34962)}},getWireframeAttribute:function(t){const e=r.get(t);if(e){const i=t.index;null!==i&&e.version<i.version&&o(t)}else o(t);return r.get(t)}}}function Qr(t,e,i,n){const s=n.isWebGL2;let r,a,o;this.setMode=function(t){r=t},this.setIndex=function(t){a=t.type,o=t.bytesPerElement},this.render=function(e,n){t.drawElements(r,n,a,e*o),i.update(n,r,1)},this.renderInstances=function(n,l,h){if(0===h)return;let c,u;if(s)c=t,u="drawElementsInstanced";else if(c=e.get("ANGLE_instanced_arrays"),u="drawElementsInstancedANGLE",null===c)return;c[u](r,l,a,n*o,h),i.update(l,r,h)}}function ta(t){const e={frame:0,calls:0,triangles:0,points:0,lines:0};return{memory:{geometries:0,textures:0},render:e,programs:null,autoReset:!0,reset:function(){e.frame++,e.calls=0,e.triangles=0,e.points=0,e.lines=0},update:function(t,i,n){switch(e.calls++,i){case 4:e.triangles+=n*(t/3);break;case 1:e.lines+=n*(t/2);break;case 3:e.lines+=n*(t-1);break;case 2:e.lines+=n*t;break;case 0:e.points+=n*t}}}}class ea extends Gi{constructor(t=null,e=1,i=1,n=1){super(null),this.image={data:t,width:e,height:i,depth:n},this.magFilter=Yt,this.minFilter=Yt,this.wrapR=Jt,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}function ia(t,e){return t[0]-e[0]}function na(t,e){return Math.abs(e[1])-Math.abs(t[1])}function sa(t,e){let i=1;const n=e.isInterleavedBufferAttribute?e.data.array:e.array;n instanceof Int8Array?i=127:n instanceof Int16Array?i=32767:n instanceof Int32Array&&(i=2147483647),t.divideScalar(i)}function ra(t,e,i){const n={},s=new Float32Array(8),r=new WeakMap,a=new Yi,o=[];for(let t=0;t<8;t++)o[t]=[t,0];return{update:function(l,h,c,u){const d=l.morphTargetInfluences;if(!0===e.isWebGL2){const n=h.morphAttributes.position.length;let s=r.get(h);if(void 0===s||s.count!==n){void 0!==s&&s.texture.dispose();const t=void 0!==h.morphAttributes.normal,i=h.morphAttributes.position,o=h.morphAttributes.normal||[],l=!0===t?2:1;let c=h.attributes.position.count*l,u=1;c>e.maxTextureSize&&(u=Math.ceil(c/e.maxTextureSize),c=e.maxTextureSize);const d=new Float32Array(c*u*4*n),p=new ea(d,c,u,n);p.format=me,p.type=oe,p.needsUpdate=!0;const f=4*l;for(let e=0;e<n;e++){const n=i[e],s=o[e],r=c*u*4*e;for(let e=0;e<n.count;e++){a.fromBufferAttribute(n,e),!0===n.normalized&&sa(a,n);const i=e*f;d[r+i+0]=a.x,d[r+i+1]=a.y,d[r+i+2]=a.z,d[r+i+3]=0,!0===t&&(a.fromBufferAttribute(s,e),!0===s.normalized&&sa(a,s),d[r+i+4]=a.x,d[r+i+5]=a.y,d[r+i+6]=a.z,d[r+i+7]=0)}}s={count:n,texture:p,size:new Ri(c,u)},r.set(h,s)}let o=0;for(let t=0;t<d.length;t++)o+=d[t];const l=h.morphTargetsRelative?1:1-o;u.getUniforms().setValue(t,"morphTargetBaseInfluence",l),u.getUniforms().setValue(t,"morphTargetInfluences",d),u.getUniforms().setValue(t,"morphTargetsTexture",s.texture,i),u.getUniforms().setValue(t,"morphTargetsTextureSize",s.size)}else{const e=void 0===d?0:d.length;let i=n[h.id];if(void 0===i||i.length!==e){i=[];for(let t=0;t<e;t++)i[t]=[t,0];n[h.id]=i}for(let t=0;t<e;t++){const e=i[t];e[0]=t,e[1]=d[t]}i.sort(na);for(let t=0;t<8;t++)t<e&&i[t][1]?(o[t][0]=i[t][0],o[t][1]=i[t][1]):(o[t][0]=Number.MAX_SAFE_INTEGER,o[t][1]=0);o.sort(ia);const r=h.morphAttributes.position,a=h.morphAttributes.normal;let l=0;for(let t=0;t<8;t++){const e=o[t],i=e[0],n=e[1];i!==Number.MAX_SAFE_INTEGER&&n?(r&&h.getAttribute("morphTarget"+t)!==r[i]&&h.setAttribute("morphTarget"+t,r[i]),a&&h.getAttribute("morphNormal"+t)!==a[i]&&h.setAttribute("morphNormal"+t,a[i]),s[t]=n,l+=n):(r&&!0===h.hasAttribute("morphTarget"+t)&&h.deleteAttribute("morphTarget"+t),a&&!0===h.hasAttribute("morphNormal"+t)&&h.deleteAttribute("morphNormal"+t),s[t]=0)}const c=h.morphTargetsRelative?1:1-l;u.getUniforms().setValue(t,"morphTargetBaseInfluence",c),u.getUniforms().setValue(t,"morphTargetInfluences",s)}}}}function aa(t,e,i,n){let s=new WeakMap;function r(t){const e=t.target;e.removeEventListener("dispose",r),i.remove(e.instanceMatrix),null!==e.instanceColor&&i.remove(e.instanceColor)}return{update:function(t){const a=n.render.frame,o=t.geometry,l=e.get(t,o);return s.get(l)!==a&&(e.update(l),s.set(l,a)),t.isInstancedMesh&&(!1===t.hasEventListener("dispose",r)&&t.addEventListener("dispose",r),i.update(t.instanceMatrix,34962),null!==t.instanceColor&&i.update(t.instanceColor,34962)),l},dispose:function(){s=new WeakMap}}}ea.prototype.isDataTexture2DArray=!0;class oa extends Gi{constructor(t=null,e=1,i=1,n=1){super(null),this.image={data:t,width:e,height:i,depth:n},this.magFilter=Yt,this.minFilter=Yt,this.wrapR=Jt,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}oa.prototype.isDataTexture3D=!0;const la=new Gi,ha=new ea,ca=new oa,ua=new lr,da=[],pa=[],fa=new Float32Array(16),ma=new Float32Array(9),_a=new Float32Array(4);function ga(t,e,i){const n=t[0];if(n<=0||n>0)return t;const s=e*i;let r=da[s];if(void 0===r&&(r=new Float32Array(s),da[s]=r),0!==e){n.toArray(r,0);for(let n=1,s=0;n!==e;++n)s+=i,t[n].toArray(r,s)}return r}function ya(t,e){if(t.length!==e.length)return!1;for(let i=0,n=t.length;i<n;i++)if(t[i]!==e[i])return!1;return!0}function va(t,e){for(let i=0,n=e.length;i<n;i++)t[i]=e[i]}function xa(t,e){let i=pa[e];void 0===i&&(i=new Int32Array(e),pa[e]=i);for(let n=0;n!==e;++n)i[n]=t.allocateTextureUnit();return i}function wa(t,e){const i=this.cache;i[0]!==e&&(t.uniform1f(this.addr,e),i[0]=e)}function ba(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y||(t.uniform2f(this.addr,e.x,e.y),i[0]=e.x,i[1]=e.y);else{if(ya(i,e))return;t.uniform2fv(this.addr,e),va(i,e)}}function Sa(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z||(t.uniform3f(this.addr,e.x,e.y,e.z),i[0]=e.x,i[1]=e.y,i[2]=e.z);else if(void 0!==e.r)i[0]===e.r&&i[1]===e.g&&i[2]===e.b||(t.uniform3f(this.addr,e.r,e.g,e.b),i[0]=e.r,i[1]=e.g,i[2]=e.b);else{if(ya(i,e))return;t.uniform3fv(this.addr,e),va(i,e)}}function Ma(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z&&i[3]===e.w||(t.uniform4f(this.addr,e.x,e.y,e.z,e.w),i[0]=e.x,i[1]=e.y,i[2]=e.z,i[3]=e.w);else{if(ya(i,e))return;t.uniform4fv(this.addr,e),va(i,e)}}function Ta(t,e){const i=this.cache,n=e.elements;if(void 0===n){if(ya(i,e))return;t.uniformMatrix2fv(this.addr,!1,e),va(i,e)}else{if(ya(i,n))return;_a.set(n),t.uniformMatrix2fv(this.addr,!1,_a),va(i,n)}}function Aa(t,e){const i=this.cache,n=e.elements;if(void 0===n){if(ya(i,e))return;t.uniformMatrix3fv(this.addr,!1,e),va(i,e)}else{if(ya(i,n))return;ma.set(n),t.uniformMatrix3fv(this.addr,!1,ma),va(i,n)}}function Ca(t,e){const i=this.cache,n=e.elements;if(void 0===n){if(ya(i,e))return;t.uniformMatrix4fv(this.addr,!1,e),va(i,e)}else{if(ya(i,n))return;fa.set(n),t.uniformMatrix4fv(this.addr,!1,fa),va(i,n)}}function Ea(t,e){const i=this.cache;i[0]!==e&&(t.uniform1i(this.addr,e),i[0]=e)}function za(t,e){const i=this.cache;ya(i,e)||(t.uniform2iv(this.addr,e),va(i,e))}function Ia(t,e){const i=this.cache;ya(i,e)||(t.uniform3iv(this.addr,e),va(i,e))}function La(t,e){const i=this.cache;ya(i,e)||(t.uniform4iv(this.addr,e),va(i,e))}function Na(t,e){const i=this.cache;i[0]!==e&&(t.uniform1ui(this.addr,e),i[0]=e)}function Pa(t,e){const i=this.cache;ya(i,e)||(t.uniform2uiv(this.addr,e),va(i,e))}function Da(t,e){const i=this.cache;ya(i,e)||(t.uniform3uiv(this.addr,e),va(i,e))}function Fa(t,e){const i=this.cache;ya(i,e)||(t.uniform4uiv(this.addr,e),va(i,e))}function Oa(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.safeSetTexture2D(e||la,s)}function Ra(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.setTexture3D(e||ca,s)}function ka(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.safeSetTextureCube(e||ua,s)}function Ba(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.setTexture2DArray(e||ha,s)}function Ua(t,e){t.uniform1fv(this.addr,e)}function Va(t,e){const i=ga(e,this.size,2);t.uniform2fv(this.addr,i)}function Wa(t,e){const i=ga(e,this.size,3);t.uniform3fv(this.addr,i)}function Ga(t,e){const i=ga(e,this.size,4);t.uniform4fv(this.addr,i)}function Ha(t,e){const i=ga(e,this.size,4);t.uniformMatrix2fv(this.addr,!1,i)}function ja(t,e){const i=ga(e,this.size,9);t.uniformMatrix3fv(this.addr,!1,i)}function qa(t,e){const i=ga(e,this.size,16);t.uniformMatrix4fv(this.addr,!1,i)}function Ja(t,e){t.uniform1iv(this.addr,e)}function $a(t,e){t.uniform2iv(this.addr,e)}function Ya(t,e){t.uniform3iv(this.addr,e)}function Xa(t,e){t.uniform4iv(this.addr,e)}function Za(t,e){t.uniform1uiv(this.addr,e)}function Ka(t,e){t.uniform2uiv(this.addr,e)}function Qa(t,e){t.uniform3uiv(this.addr,e)}function to(t,e){t.uniform4uiv(this.addr,e)}function eo(t,e,i){const n=e.length,s=xa(i,n);t.uniform1iv(this.addr,s);for(let t=0;t!==n;++t)i.safeSetTexture2D(e[t]||la,s[t])}function io(t,e,i){const n=e.length,s=xa(i,n);t.uniform1iv(this.addr,s);for(let t=0;t!==n;++t)i.setTexture3D(e[t]||ca,s[t])}function no(t,e,i){const n=e.length,s=xa(i,n);t.uniform1iv(this.addr,s);for(let t=0;t!==n;++t)i.safeSetTextureCube(e[t]||ua,s[t])}function so(t,e,i){const n=e.length,s=xa(i,n);t.uniform1iv(this.addr,s);for(let t=0;t!==n;++t)i.setTexture2DArray(e[t]||ha,s[t])}function ro(t,e,i){this.id=t,this.addr=i,this.cache=[],this.setValue=function(t){switch(t){case 5126:return wa;case 35664:return ba;case 35665:return Sa;case 35666:return Ma;case 35674:return Ta;case 35675:return Aa;case 35676:return Ca;case 5124:case 35670:return Ea;case 35667:case 35671:return za;case 35668:case 35672:return Ia;case 35669:case 35673:return La;case 5125:return Na;case 36294:return Pa;case 36295:return Da;case 36296:return Fa;case 35678:case 36198:case 36298:case 36306:case 35682:return Oa;case 35679:case 36299:case 36307:return Ra;case 35680:case 36300:case 36308:case 36293:return ka;case 36289:case 36303:case 36311:case 36292:return Ba}}(e.type)}function ao(t,e,i){this.id=t,this.addr=i,this.cache=[],this.size=e.size,this.setValue=function(t){switch(t){case 5126:return Ua;case 35664:return Va;case 35665:return Wa;case 35666:return Ga;case 35674:return Ha;case 35675:return ja;case 35676:return qa;case 5124:case 35670:return Ja;case 35667:case 35671:return $a;case 35668:case 35672:return Ya;case 35669:case 35673:return Xa;case 5125:return Za;case 36294:return Ka;case 36295:return Qa;case 36296:return to;case 35678:case 36198:case 36298:case 36306:case 35682:return eo;case 35679:case 36299:case 36307:return io;case 35680:case 36300:case 36308:case 36293:return no;case 36289:case 36303:case 36311:case 36292:return so}}(e.type)}function oo(t){this.id=t,this.seq=[],this.map={}}ao.prototype.updateCache=function(t){const e=this.cache;t instanceof Float32Array&&e.length!==t.length&&(this.cache=new Float32Array(t.length)),va(e,t)},oo.prototype.setValue=function(t,e,i){const n=this.seq;for(let s=0,r=n.length;s!==r;++s){const r=n[s];r.setValue(t,e[r.id],i)}};const lo=/(\w+)(\])?(\[|\.)?/g;function ho(t,e){t.seq.push(e),t.map[e.id]=e}function co(t,e,i){const n=t.name,s=n.length;for(lo.lastIndex=0;;){const r=lo.exec(n),a=lo.lastIndex;let o=r[1];const l="]"===r[2],h=r[3];if(l&&(o|=0),void 0===h||"["===h&&a+2===s){ho(i,void 0===h?new ro(o,t,e):new ao(o,t,e));break}{let t=i.map[o];void 0===t&&(t=new oo(o),ho(i,t)),i=t}}}function uo(t,e){this.seq=[],this.map={};const i=t.getProgramParameter(e,35718);for(let n=0;n<i;++n){const i=t.getActiveUniform(e,n);co(i,t.getUniformLocation(e,i.name),this)}}function po(t,e,i){const n=t.createShader(e);return t.shaderSource(n,i),t.compileShader(n),n}uo.prototype.setValue=function(t,e,i,n){const s=this.map[e];void 0!==s&&s.setValue(t,i,n)},uo.prototype.setOptional=function(t,e,i){const n=e[i];void 0!==n&&this.setValue(t,i,n)},uo.upload=function(t,e,i,n){for(let s=0,r=e.length;s!==r;++s){const r=e[s],a=i[r.id];!1!==a.needsUpdate&&r.setValue(t,a.value,n)}},uo.seqWithValue=function(t,e){const i=[];for(let n=0,s=t.length;n!==s;++n){const s=t[n];s.id in e&&i.push(s)}return i};let fo=0;function mo(t){switch(t){case yi:return["Linear","( value )"];case vi:return["sRGB","( value )"];default:return["Linear","( value )"]}}function _o(t,e,i){const n=t.getShaderParameter(e,35713),s=t.getShaderInfoLog(e).trim();return n&&""===s?"":i.toUpperCase()+"\n\n"+s+"\n\n"+function(t){const e=t.split("\n");for(let t=0;t<e.length;t++)e[t]=t+1+": "+e[t];return e.join("\n")}(t.getShaderSource(e))}function go(t,e){const i=mo(e);return"vec4 "+t+"( vec4 value ) { return "+i[0]+"ToLinear"+i[1]+"; }"}function yo(t,e){const i=mo(e);return"vec4 "+t+"( vec4 value ) { return LinearTo"+i[0]+i[1]+"; }"}function vo(t,e){let i;switch(e){case Ft:i="Linear";break;case Ot:i="Reinhard";break;case Rt:i="OptimizedCineon";break;case kt:i="ACESFilmic";break;case Bt:i="Custom";break;default:i="Linear"}return"vec3 "+t+"( vec3 color ) { return "+i+"ToneMapping( color ); }"}function xo(t){return""!==t}function wo(t,e){return t.replace(/NUM_DIR_LIGHTS/g,e.numDirLights).replace(/NUM_SPOT_LIGHTS/g,e.numSpotLights).replace(/NUM_RECT_AREA_LIGHTS/g,e.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,e.numPointLights).replace(/NUM_HEMI_LIGHTS/g,e.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,e.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS/g,e.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,e.numPointLightShadows)}function bo(t,e){return t.replace(/NUM_CLIPPING_PLANES/g,e.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,e.numClippingPlanes-e.numClipIntersection)}const So=/^[ \t]*#include +<([\w\d./]+)>/gm;function Mo(t){return t.replace(So,To)}function To(t,e){const i=xr[e];if(void 0===i)throw new Error("Can not resolve #include <"+e+">");return Mo(i)}const Ao=/#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g,Co=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function Eo(t){return t.replace(Co,Io).replace(Ao,zo)}function zo(t,e,i,n){return Io(0,e,i,n)}function Io(t,e,i,n){let s="";for(let t=parseInt(e);t<parseInt(i);t++)s+=n.replace(/\[\s*i\s*\]/g,"[ "+t+" ]").replace(/UNROLLED_LOOP_INDEX/g,t);return s}function Lo(t){let e="precision "+t.precision+" float;\nprecision "+t.precision+" int;";return"highp"===t.precision?e+="\n#define HIGH_PRECISION":"mediump"===t.precision?e+="\n#define MEDIUM_PRECISION":"lowp"===t.precision&&(e+="\n#define LOW_PRECISION"),e}function No(t,e,i,n){const s=t.getContext(),r=i.defines;let a=i.vertexShader,o=i.fragmentShader;const l=function(t){let e="SHADOWMAP_TYPE_BASIC";return t.shadowMapType===Y?e="SHADOWMAP_TYPE_PCF":t.shadowMapType===X?e="SHADOWMAP_TYPE_PCF_SOFT":t.shadowMapType===Z&&(e="SHADOWMAP_TYPE_VSM"),e}(i),h=function(t){let e="ENVMAP_TYPE_CUBE";if(t.envMap)switch(t.envMapMode){case Ut:case Vt:e="ENVMAP_TYPE_CUBE";break;case Ht:case jt:e="ENVMAP_TYPE_CUBE_UV"}return e}(i),c=function(t){let e="ENVMAP_MODE_REFLECTION";if(t.envMap)switch(t.envMapMode){case Vt:case jt:e="ENVMAP_MODE_REFRACTION"}return e}(i),u=function(t){let e="ENVMAP_BLENDING_NONE";if(t.envMap)switch(t.combine){case Lt:e="ENVMAP_BLENDING_MULTIPLY";break;case Nt:e="ENVMAP_BLENDING_MIX";break;case Pt:e="ENVMAP_BLENDING_ADD"}return e}(i),d=i.isWebGL2?"":function(t){return[t.extensionDerivatives||t.envMapCubeUV||t.bumpMap||t.tangentSpaceNormalMap||t.clearcoatNormalMap||t.flatShading||"physical"===t.shaderID?"#extension GL_OES_standard_derivatives : enable":"",(t.extensionFragDepth||t.logarithmicDepthBuffer)&&t.rendererExtensionFragDepth?"#extension GL_EXT_frag_depth : enable":"",t.extensionDrawBuffers&&t.rendererExtensionDrawBuffers?"#extension GL_EXT_draw_buffers : require":"",(t.extensionShaderTextureLOD||t.envMap||t.transmission)&&t.rendererExtensionShaderTextureLod?"#extension GL_EXT_shader_texture_lod : enable":""].filter(xo).join("\n")}(i),p=function(t){const e=[];for(const i in t){const n=t[i];!1!==n&&e.push("#define "+i+" "+n)}return e.join("\n")}(r),f=s.createProgram();let m,_,g=i.glslVersion?"#version "+i.glslVersion+"\n":"";i.isRawShaderMaterial?(m=[p].filter(xo).join("\n"),m.length>0&&(m+="\n"),_=[d,p].filter(xo).join("\n"),_.length>0&&(_+="\n")):(m=[Lo(i),"#define SHADER_NAME "+i.shaderName,p,i.instancing?"#define USE_INSTANCING":"",i.instancingColor?"#define USE_INSTANCING_COLOR":"",i.supportsVertexTextures?"#define VERTEX_TEXTURES":"","#define MAX_BONES "+i.maxBones,i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp2?"#define FOG_EXP2":"",i.map?"#define USE_MAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+c:"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.normalMap&&i.objectSpaceNormalMap?"#define OBJECTSPACE_NORMALMAP":"",i.normalMap&&i.tangentSpaceNormalMap?"#define TANGENTSPACE_NORMALMAP":"",i.clearcoatMap?"#define USE_CLEARCOATMAP":"",i.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",i.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",i.displacementMap&&i.supportsVertexTextures?"#define USE_DISPLACEMENTMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.specularIntensityMap?"#define USE_SPECULARINTENSITYMAP":"",i.specularColorMap?"#define USE_SPECULARCOLORMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.transmission?"#define USE_TRANSMISSION":"",i.transmissionMap?"#define USE_TRANSMISSIONMAP":"",i.thicknessMap?"#define USE_THICKNESSMAP":"",i.sheenColorMap?"#define USE_SHEENCOLORMAP":"",i.sheenRoughnessMap?"#define USE_SHEENROUGHNESSMAP":"",i.vertexTangents?"#define USE_TANGENT":"",i.vertexColors?"#define USE_COLOR":"",i.vertexAlphas?"#define USE_COLOR_ALPHA":"",i.vertexUvs?"#define USE_UV":"",i.uvsVertexOnly?"#define UVS_VERTEX_ONLY":"",i.flatShading?"#define FLAT_SHADED":"",i.skinning?"#define USE_SKINNING":"",i.useVertexTexture?"#define BONE_TEXTURE":"",i.morphTargets?"#define USE_MORPHTARGETS":"",i.morphNormals&&!1===i.flatShading?"#define USE_MORPHNORMALS":"",i.morphTargets&&i.isWebGL2?"#define MORPHTARGETS_TEXTURE":"",i.morphTargets&&i.isWebGL2?"#define MORPHTARGETS_COUNT "+i.morphTargetsCount:"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+l:"",i.sizeAttenuation?"#define USE_SIZEATTENUATION":"",i.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",i.logarithmicDepthBuffer&&i.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING","\tattribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR","\tattribute vec3 instanceColor;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_TANGENT","\tattribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )","\tattribute vec4 color;","#elif defined( USE_COLOR )","\tattribute vec3 color;","#endif","#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )","\tattribute vec3 morphTarget0;","\tattribute vec3 morphTarget1;","\tattribute vec3 morphTarget2;","\tattribute vec3 morphTarget3;","\t#ifdef USE_MORPHNORMALS","\t\tattribute vec3 morphNormal0;","\t\tattribute vec3 morphNormal1;","\t\tattribute vec3 morphNormal2;","\t\tattribute vec3 morphNormal3;","\t#else","\t\tattribute vec3 morphTarget4;","\t\tattribute vec3 morphTarget5;","\t\tattribute vec3 morphTarget6;","\t\tattribute vec3 morphTarget7;","\t#endif","#endif","#ifdef USE_SKINNING","\tattribute vec4 skinIndex;","\tattribute vec4 skinWeight;","#endif","\n"].filter(xo).join("\n"),_=[d,Lo(i),"#define SHADER_NAME "+i.shaderName,p,i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp2?"#define FOG_EXP2":"",i.map?"#define USE_MAP":"",i.matcap?"#define USE_MATCAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+h:"",i.envMap?"#define "+c:"",i.envMap?"#define "+u:"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.normalMap&&i.objectSpaceNormalMap?"#define OBJECTSPACE_NORMALMAP":"",i.normalMap&&i.tangentSpaceNormalMap?"#define TANGENTSPACE_NORMALMAP":"",i.clearcoat?"#define USE_CLEARCOAT":"",i.clearcoatMap?"#define USE_CLEARCOATMAP":"",i.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",i.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.specularIntensityMap?"#define USE_SPECULARINTENSITYMAP":"",i.specularColorMap?"#define USE_SPECULARCOLORMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.alphaTest?"#define USE_ALPHATEST":"",i.sheen?"#define USE_SHEEN":"",i.sheenColorMap?"#define USE_SHEENCOLORMAP":"",i.sheenRoughnessMap?"#define USE_SHEENROUGHNESSMAP":"",i.transmission?"#define USE_TRANSMISSION":"",i.transmissionMap?"#define USE_TRANSMISSIONMAP":"",i.thicknessMap?"#define USE_THICKNESSMAP":"",i.vertexTangents?"#define USE_TANGENT":"",i.vertexColors||i.instancingColor?"#define USE_COLOR":"",i.vertexAlphas?"#define USE_COLOR_ALPHA":"",i.vertexUvs?"#define USE_UV":"",i.uvsVertexOnly?"#define UVS_VERTEX_ONLY":"",i.gradientMap?"#define USE_GRADIENTMAP":"",i.flatShading?"#define FLAT_SHADED":"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+l:"",i.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",i.physicallyCorrectLights?"#define PHYSICALLY_CORRECT_LIGHTS":"",i.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",i.logarithmicDepthBuffer&&i.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"",(i.extensionShaderTextureLOD||i.envMap)&&i.rendererExtensionShaderTextureLod?"#define TEXTURE_LOD_EXT":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",i.toneMapping!==Dt?"#define TONE_MAPPING":"",i.toneMapping!==Dt?xr.tonemapping_pars_fragment:"",i.toneMapping!==Dt?vo("toneMapping",i.toneMapping):"",i.dithering?"#define DITHERING":"",i.format===fe?"#define OPAQUE":"",xr.encodings_pars_fragment,i.map?go("mapTexelToLinear",i.mapEncoding):"",i.matcap?go("matcapTexelToLinear",i.matcapEncoding):"",i.envMap?go("envMapTexelToLinear",i.envMapEncoding):"",i.emissiveMap?go("emissiveMapTexelToLinear",i.emissiveMapEncoding):"",i.specularColorMap?go("specularColorMapTexelToLinear",i.specularColorMapEncoding):"",i.sheenColorMap?go("sheenColorMapTexelToLinear",i.sheenColorMapEncoding):"",i.lightMap?go("lightMapTexelToLinear",i.lightMapEncoding):"",yo("linearToOutputTexel",i.outputEncoding),i.depthPacking?"#define DEPTH_PACKING "+i.depthPacking:"","\n"].filter(xo).join("\n")),a=Mo(a),a=wo(a,i),a=bo(a,i),o=Mo(o),o=wo(o,i),o=bo(o,i),a=Eo(a),o=Eo(o),i.isWebGL2&&!0!==i.isRawShaderMaterial&&(g="#version 300 es\n",m=["precision mediump sampler2DArray;","#define attribute in","#define varying out","#define texture2D texture"].join("\n")+"\n"+m,_=["#define varying in",i.glslVersion===Ai?"":"layout(location = 0) out highp vec4 pc_fragColor;",i.glslVersion===Ai?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join("\n")+"\n"+_);const y=g+_+o,v=po(s,35633,g+m+a),x=po(s,35632,y);if(s.attachShader(f,v),s.attachShader(f,x),void 0!==i.index0AttributeName?s.bindAttribLocation(f,0,i.index0AttributeName):!0===i.morphTargets&&s.bindAttribLocation(f,0,"position"),s.linkProgram(f),t.debug.checkShaderErrors){const t=s.getProgramInfoLog(f).trim(),e=s.getShaderInfoLog(v).trim(),i=s.getShaderInfoLog(x).trim();let n=!0,r=!0;!1===s.getProgramParameter(f,35714)?(n=!1,_o(s,v,"vertex"),_o(s,x,"fragment")):""!==t||""!==e&&""!==i||(r=!1),r&&(this.diagnostics={runnable:n,programLog:t,vertexShader:{log:e,prefix:m},fragmentShader:{log:i,prefix:_}})}let w,b;return s.deleteShader(v),s.deleteShader(x),this.getUniforms=function(){return void 0===w&&(w=new uo(s,f)),w},this.getAttributes=function(){return void 0===b&&(b=function(t,e){const i={},n=t.getProgramParameter(e,35721);for(let s=0;s<n;s++){const n=t.getActiveAttrib(e,s),r=n.name;let a=1;35674===n.type&&(a=2),35675===n.type&&(a=3),35676===n.type&&(a=4),i[r]={type:n.type,location:t.getAttribLocation(e,r),locationSize:a}}return i}(s,f)),b},this.destroy=function(){n.releaseStatesOfProgram(this),s.deleteProgram(f),this.program=void 0},this.name=i.shaderName,this.id=fo++,this.cacheKey=e,this.usedTimes=1,this.program=f,this.vertexShader=v,this.fragmentShader=x,this}let Po=0;class Do{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(t){const e=t.vertexShader,i=t.fragmentShader,n=this._getShaderStage(e),s=this._getShaderStage(i),r=this._getShaderCacheForMaterial(t);return!1===r.has(n)&&(r.add(n),n.usedTimes++),!1===r.has(s)&&(r.add(s),s.usedTimes++),this}remove(t){const e=this.materialCache.get(t);for(const t of e)t.usedTimes--,0===t.usedTimes&&this.shaderCache.delete(t);return this.materialCache.delete(t),this}getVertexShaderID(t){return this._getShaderStage(t.vertexShader).id}getFragmentShaderID(t){return this._getShaderStage(t.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(t){const e=this.materialCache;return!1===e.has(t)&&e.set(t,new Set),e.get(t)}_getShaderStage(t){const e=this.shaderCache;if(!1===e.has(t)){const i=new Fo;e.set(t,i)}return e.get(t)}}class Fo{constructor(){this.id=Po++,this.usedTimes=0}}function Oo(t,e,i,n,s,r,a){const o=new kn,l=new Do,h=[],c=s.isWebGL2,u=s.logarithmicDepthBuffer,d=s.floatVertexTextures,p=s.maxVertexUniforms,f=s.vertexTextures;let m=s.precision;const _={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distanceRGBA",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function g(t){let e;return e=t&&t.isTexture?t.encoding:t&&t.isWebGLRenderTarget?t.texture.encoding:yi,c&&t&&t.isTexture&&t.format===me&&t.type===ee&&t.encoding===vi&&(e=yi),e}return{getParameters:function(r,o,h,y,v){const x=y.fog,w=r.isMeshStandardMaterial?y.environment:null,b=(r.isMeshStandardMaterial?i:e).get(r.envMap||w),S=_[r.type],M=v.isSkinnedMesh?function(t){const e=t.skeleton.bones;if(d)return 1024;{const t=p,i=Math.floor((t-20)/4),n=Math.min(i,e.length);return n<e.length?0:n}}(v):0;let T,A,C,E;if(null!==r.precision&&(m=s.getMaxPrecision(r.precision),r.precision),S){const t=br[S];T=t.vertexShader,A=t.fragmentShader}else T=r.vertexShader,A=r.fragmentShader,l.update(r),C=l.getVertexShaderID(r),E=l.getFragmentShaderID(r);const z=t.getRenderTarget(),I=r.alphaTest>0,L=r.clearcoat>0;return{isWebGL2:c,shaderID:S,shaderName:r.type,vertexShader:T,fragmentShader:A,defines:r.defines,customVertexShaderID:C,customFragmentShaderID:E,isRawShaderMaterial:!0===r.isRawShaderMaterial,glslVersion:r.glslVersion,precision:m,instancing:!0===v.isInstancedMesh,instancingColor:!0===v.isInstancedMesh&&null!==v.instanceColor,supportsVertexTextures:f,outputEncoding:null!==z?g(z.texture):t.outputEncoding,map:!!r.map,mapEncoding:g(r.map),matcap:!!r.matcap,matcapEncoding:g(r.matcap),envMap:!!b,envMapMode:b&&b.mapping,envMapEncoding:g(b),envMapCubeUV:!!b&&(b.mapping===Ht||b.mapping===jt),lightMap:!!r.lightMap,lightMapEncoding:g(r.lightMap),aoMap:!!r.aoMap,emissiveMap:!!r.emissiveMap,emissiveMapEncoding:g(r.emissiveMap),bumpMap:!!r.bumpMap,normalMap:!!r.normalMap,objectSpaceNormalMap:r.normalMapType===bi,tangentSpaceNormalMap:r.normalMapType===wi,clearcoat:L,clearcoatMap:L&&!!r.clearcoatMap,clearcoatRoughnessMap:L&&!!r.clearcoatRoughnessMap,clearcoatNormalMap:L&&!!r.clearcoatNormalMap,displacementMap:!!r.displacementMap,roughnessMap:!!r.roughnessMap,metalnessMap:!!r.metalnessMap,specularMap:!!r.specularMap,specularIntensityMap:!!r.specularIntensityMap,specularColorMap:!!r.specularColorMap,specularColorMapEncoding:g(r.specularColorMap),alphaMap:!!r.alphaMap,alphaTest:I,gradientMap:!!r.gradientMap,sheen:r.sheen>0,sheenColorMap:!!r.sheenColorMap,sheenColorMapEncoding:g(r.sheenColorMap),sheenRoughnessMap:!!r.sheenRoughnessMap,transmission:r.transmission>0,transmissionMap:!!r.transmissionMap,thicknessMap:!!r.thicknessMap,combine:r.combine,vertexTangents:!!r.normalMap&&!!v.geometry&&!!v.geometry.attributes.tangent,vertexColors:r.vertexColors,vertexAlphas:!0===r.vertexColors&&!!v.geometry&&!!v.geometry.attributes.color&&4===v.geometry.attributes.color.itemSize,vertexUvs:!!(r.map||r.bumpMap||r.normalMap||r.specularMap||r.alphaMap||r.emissiveMap||r.roughnessMap||r.metalnessMap||r.clearcoatMap||r.clearcoatRoughnessMap||r.clearcoatNormalMap||r.displacementMap||r.transmissionMap||r.thicknessMap||r.specularIntensityMap||r.specularColorMap||r.sheenColorMap||r.sheenRoughnessMap),uvsVertexOnly:!(r.map||r.bumpMap||r.normalMap||r.specularMap||r.alphaMap||r.emissiveMap||r.roughnessMap||r.metalnessMap||r.clearcoatNormalMap||r.transmission>0||r.transmissionMap||r.thicknessMap||r.specularIntensityMap||r.specularColorMap||r.sheen>0||r.sheenColorMap||r.sheenRoughnessMap||!r.displacementMap),fog:!!x,useFog:r.fog,fogExp2:x&&x.isFogExp2,flatShading:!!r.flatShading,sizeAttenuation:r.sizeAttenuation,logarithmicDepthBuffer:u,skinning:!0===v.isSkinnedMesh&&M>0,maxBones:M,useVertexTexture:d,morphTargets:!!v.geometry&&!!v.geometry.morphAttributes.position,morphNormals:!!v.geometry&&!!v.geometry.morphAttributes.normal,morphTargetsCount:v.geometry&&v.geometry.morphAttributes.position?v.geometry.morphAttributes.position.length:0,numDirLights:o.directional.length,numPointLights:o.point.length,numSpotLights:o.spot.length,numRectAreaLights:o.rectArea.length,numHemiLights:o.hemi.length,numDirLightShadows:o.directionalShadowMap.length,numPointLightShadows:o.pointShadowMap.length,numSpotLightShadows:o.spotShadowMap.length,numClippingPlanes:a.numPlanes,numClipIntersection:a.numIntersection,format:r.format,dithering:r.dithering,shadowMapEnabled:t.shadowMap.enabled&&h.length>0,shadowMapType:t.shadowMap.type,toneMapping:r.toneMapped?t.toneMapping:Dt,physicallyCorrectLights:t.physicallyCorrectLights,premultipliedAlpha:r.premultipliedAlpha,doubleSided:r.side===tt,flipSided:r.side===Q,depthPacking:void 0!==r.depthPacking&&r.depthPacking,index0AttributeName:r.index0AttributeName,extensionDerivatives:r.extensions&&r.extensions.derivatives,extensionFragDepth:r.extensions&&r.extensions.fragDepth,extensionDrawBuffers:r.extensions&&r.extensions.drawBuffers,extensionShaderTextureLOD:r.extensions&&r.extensions.shaderTextureLOD,rendererExtensionFragDepth:c||n.has("EXT_frag_depth"),rendererExtensionDrawBuffers:c||n.has("WEBGL_draw_buffers"),rendererExtensionShaderTextureLod:c||n.has("EXT_shader_texture_lod"),customProgramCacheKey:r.customProgramCacheKey()}},getProgramCacheKey:function(e){const i=[];if(e.shaderID?i.push(e.shaderID):(i.push(e.customVertexShaderID),i.push(e.customFragmentShaderID)),void 0!==e.defines)for(const t in e.defines)i.push(t),i.push(e.defines[t]);return!1===e.isRawShaderMaterial&&(function(t,e){t.push(e.precision),t.push(e.outputEncoding),t.push(e.mapEncoding),t.push(e.matcapEncoding),t.push(e.envMapMode),t.push(e.envMapEncoding),t.push(e.lightMapEncoding),t.push(e.emissiveMapEncoding),t.push(e.combine),t.push(e.vertexUvs),t.push(e.fogExp2),t.push(e.sizeAttenuation),t.push(e.maxBones),t.push(e.morphTargetsCount),t.push(e.numDirLights),t.push(e.numPointLights),t.push(e.numSpotLights),t.push(e.numHemiLights),t.push(e.numRectAreaLights),t.push(e.numDirLightShadows),t.push(e.numPointLightShadows),t.push(e.numSpotLightShadows),t.push(e.shadowMapType),t.push(e.toneMapping),t.push(e.numClippingPlanes),t.push(e.numClipIntersection),t.push(e.format),t.push(e.specularColorMapEncoding),t.push(e.sheenColorMapEncoding)}(i,e),function(t,e){o.disableAll(),e.isWebGL2&&o.enable(0),e.supportsVertexTextures&&o.enable(1),e.instancing&&o.enable(2),e.instancingColor&&o.enable(3),e.map&&o.enable(4),e.matcap&&o.enable(5),e.envMap&&o.enable(6),e.envMapCubeUV&&o.enable(7),e.lightMap&&o.enable(8),e.aoMap&&o.enable(9),e.emissiveMap&&o.enable(10),e.bumpMap&&o.enable(11),e.normalMap&&o.enable(12),e.objectSpaceNormalMap&&o.enable(13),e.tangentSpaceNormalMap&&o.enable(14),e.clearcoat&&o.enable(15),e.clearcoatMap&&o.enable(16),e.clearcoatRoughnessMap&&o.enable(17),e.clearcoatNormalMap&&o.enable(18),e.displacementMap&&o.enable(19),e.specularMap&&o.enable(20),e.roughnessMap&&o.enable(21),e.metalnessMap&&o.enable(22),e.gradientMap&&o.enable(23),e.alphaMap&&o.enable(24),e.alphaTest&&o.enable(25),e.vertexColors&&o.enable(26),e.vertexAlphas&&o.enable(27),e.vertexUvs&&o.enable(28),e.vertexTangents&&o.enable(29),e.uvsVertexOnly&&o.enable(30),e.fog&&o.enable(31),t.push(o.mask),o.disableAll(),e.useFog&&o.enable(0),e.flatShading&&o.enable(1),e.logarithmicDepthBuffer&&o.enable(2),e.skinning&&o.enable(3),e.useVertexTexture&&o.enable(4),e.morphTargets&&o.enable(5),e.morphNormals&&o.enable(6),e.premultipliedAlpha&&o.enable(7),e.shadowMapEnabled&&o.enable(8),e.physicallyCorrectLights&&o.enable(9),e.doubleSided&&o.enable(10),e.flipSided&&o.enable(11),e.depthPacking&&o.enable(12),e.dithering&&o.enable(13),e.specularIntensityMap&&o.enable(14),e.specularColorMap&&o.enable(15),e.transmission&&o.enable(16),e.transmissionMap&&o.enable(17),e.thicknessMap&&o.enable(18),e.sheen&&o.enable(19),e.sheenColorMap&&o.enable(20),e.sheenRoughnessMap&&o.enable(21),t.push(o.mask)}(i,e),i.push(t.outputEncoding)),i.push(e.customProgramCacheKey),i.join()},getUniforms:function(t){const e=_[t.type];let i;if(e){const t=br[e];i=ir.clone(t.uniforms)}else i=t.uniforms;return i},acquireProgram:function(e,i){let n;for(let t=0,e=h.length;t<e;t++){const e=h[t];if(e.cacheKey===i){n=e,++n.usedTimes;break}}return void 0===n&&(n=new No(t,i,e,r),h.push(n)),n},releaseProgram:function(t){if(0==--t.usedTimes){const e=h.indexOf(t);h[e]=h[h.length-1],h.pop(),t.destroy()}},releaseShaderCache:function(t){l.remove(t)},programs:h,dispose:function(){l.dispose()}}}function Ro(){let t=new WeakMap;return{get:function(e){let i=t.get(e);return void 0===i&&(i={},t.set(e,i)),i},remove:function(e){t.delete(e)},update:function(e,i,n){t.get(e)[i]=n},dispose:function(){t=new WeakMap}}}function ko(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.material.id!==e.material.id?t.material.id-e.material.id:t.z!==e.z?t.z-e.z:t.id-e.id}function Bo(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.z!==e.z?e.z-t.z:t.id-e.id}function Uo(){const t=[];let e=0;const i=[],n=[],s=[];function r(i,n,s,r,a,o){let l=t[e];return void 0===l?(l={id:i.id,object:i,geometry:n,material:s,groupOrder:r,renderOrder:i.renderOrder,z:a,group:o},t[e]=l):(l.id=i.id,l.object=i,l.geometry=n,l.material=s,l.groupOrder=r,l.renderOrder=i.renderOrder,l.z=a,l.group=o),e++,l}return{opaque:i,transmissive:n,transparent:s,init:function(){e=0,i.length=0,n.length=0,s.length=0},push:function(t,e,a,o,l,h){const c=r(t,e,a,o,l,h);a.transmission>0?n.push(c):!0===a.transparent?s.push(c):i.push(c)},unshift:function(t,e,a,o,l,h){const c=r(t,e,a,o,l,h);a.transmission>0?n.unshift(c):!0===a.transparent?s.unshift(c):i.unshift(c)},finish:function(){for(let i=e,n=t.length;i<n;i++){const e=t[i];if(null===e.id)break;e.id=null,e.object=null,e.geometry=null,e.material=null,e.group=null}},sort:function(t,e){i.length>1&&i.sort(t||ko),n.length>1&&n.sort(e||Bo),s.length>1&&s.sort(e||Bo)}}}function Vo(){let t=new WeakMap;return{get:function(e,i){let n;return!1===t.has(e)?(n=new Uo,t.set(e,[n])):i>=t.get(e).length?(n=new Uo,t.get(e).push(n)):n=t.get(e)[i],n},dispose:function(){t=new WeakMap}}}function Wo(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let i;switch(e.type){case"DirectionalLight":i={direction:new Yi,color:new ys};break;case"SpotLight":i={position:new Yi,direction:new Yi,color:new ys,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":i={position:new Yi,color:new ys,distance:0,decay:0};break;case"HemisphereLight":i={direction:new Yi,skyColor:new ys,groundColor:new ys};break;case"RectAreaLight":i={color:new ys,position:new Yi,halfWidth:new Yi,halfHeight:new Yi}}return t[e.id]=i,i}}}let Go=0;function Ho(t,e){return(e.castShadow?1:0)-(t.castShadow?1:0)}function jo(t,e){const i=new Wo,n=function(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let i;switch(e.type){case"DirectionalLight":case"SpotLight":i={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Ri};break;case"PointLight":i={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Ri,shadowCameraNear:1,shadowCameraFar:1e3}}return t[e.id]=i,i}}}(),s={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotShadow:[],spotShadowMap:[],spotShadowMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[]};for(let t=0;t<9;t++)s.probe.push(new Yi);const r=new Yi,a=new Cn,o=new Cn;return{setup:function(r,a){let o=0,l=0,h=0;for(let t=0;t<9;t++)s.probe[t].set(0,0,0);let c=0,u=0,d=0,p=0,f=0,m=0,_=0,g=0;r.sort(Ho);const y=!0!==a?Math.PI:1;for(let t=0,e=r.length;t<e;t++){const e=r[t],a=e.color,v=e.intensity,x=e.distance,w=e.shadow&&e.shadow.map?e.shadow.map.texture:null;if(e.isAmbientLight)o+=a.r*v*y,l+=a.g*v*y,h+=a.b*v*y;else if(e.isLightProbe)for(let t=0;t<9;t++)s.probe[t].addScaledVector(e.sh.coefficients[t],v);else if(e.isDirectionalLight){const t=i.get(e);if(t.color.copy(e.color).multiplyScalar(e.intensity*y),e.castShadow){const t=e.shadow,i=n.get(e);i.shadowBias=t.bias,i.shadowNormalBias=t.normalBias,i.shadowRadius=t.radius,i.shadowMapSize=t.mapSize,s.directionalShadow[c]=i,s.directionalShadowMap[c]=w,s.directionalShadowMatrix[c]=e.shadow.matrix,m++}s.directional[c]=t,c++}else if(e.isSpotLight){const t=i.get(e);if(t.position.setFromMatrixPosition(e.matrixWorld),t.color.copy(a).multiplyScalar(v*y),t.distance=x,t.coneCos=Math.cos(e.angle),t.penumbraCos=Math.cos(e.angle*(1-e.penumbra)),t.decay=e.decay,e.castShadow){const t=e.shadow,i=n.get(e);i.shadowBias=t.bias,i.shadowNormalBias=t.normalBias,i.shadowRadius=t.radius,i.shadowMapSize=t.mapSize,s.spotShadow[d]=i,s.spotShadowMap[d]=w,s.spotShadowMatrix[d]=e.shadow.matrix,g++}s.spot[d]=t,d++}else if(e.isRectAreaLight){const t=i.get(e);t.color.copy(a).multiplyScalar(v),t.halfWidth.set(.5*e.width,0,0),t.halfHeight.set(0,.5*e.height,0),s.rectArea[p]=t,p++}else if(e.isPointLight){const t=i.get(e);if(t.color.copy(e.color).multiplyScalar(e.intensity*y),t.distance=e.distance,t.decay=e.decay,e.castShadow){const t=e.shadow,i=n.get(e);i.shadowBias=t.bias,i.shadowNormalBias=t.normalBias,i.shadowRadius=t.radius,i.shadowMapSize=t.mapSize,i.shadowCameraNear=t.camera.near,i.shadowCameraFar=t.camera.far,s.pointShadow[u]=i,s.pointShadowMap[u]=w,s.pointShadowMatrix[u]=e.shadow.matrix,_++}s.point[u]=t,u++}else if(e.isHemisphereLight){const t=i.get(e);t.skyColor.copy(e.color).multiplyScalar(v*y),t.groundColor.copy(e.groundColor).multiplyScalar(v*y),s.hemi[f]=t,f++}}p>0&&(e.isWebGL2||!0===t.has("OES_texture_float_linear")?(s.rectAreaLTC1=wr.LTC_FLOAT_1,s.rectAreaLTC2=wr.LTC_FLOAT_2):!0===t.has("OES_texture_half_float_linear")&&(s.rectAreaLTC1=wr.LTC_HALF_1,s.rectAreaLTC2=wr.LTC_HALF_2)),s.ambient[0]=o,s.ambient[1]=l,s.ambient[2]=h;const v=s.hash;v.directionalLength===c&&v.pointLength===u&&v.spotLength===d&&v.rectAreaLength===p&&v.hemiLength===f&&v.numDirectionalShadows===m&&v.numPointShadows===_&&v.numSpotShadows===g||(s.directional.length=c,s.spot.length=d,s.rectArea.length=p,s.point.length=u,s.hemi.length=f,s.directionalShadow.length=m,s.directionalShadowMap.length=m,s.pointShadow.length=_,s.pointShadowMap.length=_,s.spotShadow.length=g,s.spotShadowMap.length=g,s.directionalShadowMatrix.length=m,s.pointShadowMatrix.length=_,s.spotShadowMatrix.length=g,v.directionalLength=c,v.pointLength=u,v.spotLength=d,v.rectAreaLength=p,v.hemiLength=f,v.numDirectionalShadows=m,v.numPointShadows=_,v.numSpotShadows=g,s.version=Go++)},setupView:function(t,e){let i=0,n=0,l=0,h=0,c=0;const u=e.matrixWorldInverse;for(let e=0,d=t.length;e<d;e++){const d=t[e];if(d.isDirectionalLight){const t=s.directional[i];t.direction.setFromMatrixPosition(d.matrixWorld),r.setFromMatrixPosition(d.target.matrixWorld),t.direction.sub(r),t.direction.transformDirection(u),i++}else if(d.isSpotLight){const t=s.spot[l];t.position.setFromMatrixPosition(d.matrixWorld),t.position.applyMatrix4(u),t.direction.setFromMatrixPosition(d.matrixWorld),r.setFromMatrixPosition(d.target.matrixWorld),t.direction.sub(r),t.direction.transformDirection(u),l++}else if(d.isRectAreaLight){const t=s.rectArea[h];t.position.setFromMatrixPosition(d.matrixWorld),t.position.applyMatrix4(u),o.identity(),a.copy(d.matrixWorld),a.premultiply(u),o.extractRotation(a),t.halfWidth.set(.5*d.width,0,0),t.halfHeight.set(0,.5*d.height,0),t.halfWidth.applyMatrix4(o),t.halfHeight.applyMatrix4(o),h++}else if(d.isPointLight){const t=s.point[n];t.position.setFromMatrixPosition(d.matrixWorld),t.position.applyMatrix4(u),n++}else if(d.isHemisphereLight){const t=s.hemi[c];t.direction.setFromMatrixPosition(d.matrixWorld),t.direction.transformDirection(u),t.direction.normalize(),c++}}},state:s}}function qo(t,e){const i=new jo(t,e),n=[],s=[];return{init:function(){n.length=0,s.length=0},state:{lightsArray:n,shadowsArray:s,lights:i},setupLights:function(t){i.setup(n,t)},setupLightsView:function(t){i.setupView(n,t)},pushLight:function(t){n.push(t)},pushShadow:function(t){s.push(t)}}}function Jo(t,e){let i=new WeakMap;return{get:function(n,s=0){let r;return!1===i.has(n)?(r=new qo(t,e),i.set(n,[r])):s>=i.get(n).length?(r=new qo(t,e),i.get(n).push(r)):r=i.get(n)[s],r},dispose:function(){i=new WeakMap}}}class $o extends us{constructor(t){super(),this.type="MeshDepthMaterial",this.depthPacking=3200,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}$o.prototype.isMeshDepthMaterial=!0;class Yo extends us{constructor(t){super(),this.type="MeshDistanceMaterial",this.referencePosition=new Yi,this.nearDistance=1,this.farDistance=1e3,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.fog=!1,this.setValues(t)}copy(t){return super.copy(t),this.referencePosition.copy(t.referencePosition),this.nearDistance=t.nearDistance,this.farDistance=t.farDistance,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}Yo.prototype.isMeshDistanceMaterial=!0;const Xo="void main() {\n\tgl_Position = vec4( position, 1.0 );\n}",Zo="uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tconst float samples = float( VSM_SAMPLES );\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n\tfloat uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n\tfor ( float i = 0.0; i < samples; i ++ ) {\n\t\tfloat uvOffset = uvStart + i * uvStride;\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean / samples;\n\tsquared_mean = squared_mean / samples;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";function Ko(t,e,i){let n=new _r;const s=new Ri,r=new Ri,a=new ji,o=new $o({depthPacking:xi}),l=new Yo,h={},c=i.maxTextureSize,u={0:Q,1:K,2:tt},d=new nr({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new Ri},radius:{value:4}},vertexShader:Xo,fragmentShader:Zo}),p=d.clone();p.defines.HORIZONTAL_PASS=1;const f=new Ps;f.setAttribute("position",new bs(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const m=new Zs(f,d),_=this;function g(i,n){const s=e.update(m);d.defines.VSM_SAMPLES!==i.blurSamples&&(d.defines.VSM_SAMPLES=i.blurSamples,p.defines.VSM_SAMPLES=i.blurSamples,d.needsUpdate=!0,p.needsUpdate=!0),d.uniforms.shadow_pass.value=i.map.texture,d.uniforms.resolution.value=i.mapSize,d.uniforms.radius.value=i.radius,t.setRenderTarget(i.mapPass),t.clear(),t.renderBufferDirect(n,null,s,d,m,null),p.uniforms.shadow_pass.value=i.mapPass.texture,p.uniforms.resolution.value=i.mapSize,p.uniforms.radius.value=i.radius,t.setRenderTarget(i.map),t.clear(),t.renderBufferDirect(n,null,s,p,m,null)}function y(e,i,n,s,r,a,c){let d=null;const p=!0===s.isPointLight?e.customDistanceMaterial:e.customDepthMaterial;if(d=void 0!==p?p:!0===s.isPointLight?l:o,t.localClippingEnabled&&!0===n.clipShadows&&0!==n.clippingPlanes.length||n.displacementMap&&0!==n.displacementScale||n.alphaMap&&n.alphaTest>0){const t=d.uuid,e=n.uuid;let i=h[t];void 0===i&&(i={},h[t]=i);let s=i[e];void 0===s&&(s=d.clone(),i[e]=s),d=s}return d.visible=n.visible,d.wireframe=n.wireframe,d.side=c===Z?null!==n.shadowSide?n.shadowSide:n.side:null!==n.shadowSide?n.shadowSide:u[n.side],d.alphaMap=n.alphaMap,d.alphaTest=n.alphaTest,d.clipShadows=n.clipShadows,d.clippingPlanes=n.clippingPlanes,d.clipIntersection=n.clipIntersection,d.displacementMap=n.displacementMap,d.displacementScale=n.displacementScale,d.displacementBias=n.displacementBias,d.wireframeLinewidth=n.wireframeLinewidth,d.linewidth=n.linewidth,!0===s.isPointLight&&!0===d.isMeshDistanceMaterial&&(d.referencePosition.setFromMatrixPosition(s.matrixWorld),d.nearDistance=r,d.farDistance=a),d}function v(i,s,r,a,o){if(!1===i.visible)return;if(i.layers.test(s.layers)&&(i.isMesh||i.isLine||i.isPoints)&&(i.castShadow||i.receiveShadow&&o===Z)&&(!i.frustumCulled||n.intersectsObject(i))){i.modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,i.matrixWorld);const n=e.update(i),s=i.material;if(Array.isArray(s)){const e=n.groups;for(let l=0,h=e.length;l<h;l++){const h=e[l],c=s[h.materialIndex];if(c&&c.visible){const e=y(i,0,c,a,r.near,r.far,o);t.renderBufferDirect(r,null,n,e,i,h)}}}else if(s.visible){const e=y(i,0,s,a,r.near,r.far,o);t.renderBufferDirect(r,null,n,e,i,null)}}const l=i.children;for(let t=0,e=l.length;t<e;t++)v(l[t],s,r,a,o)}this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=Y,this.render=function(e,i,o){if(!1===_.enabled)return;if(!1===_.autoUpdate&&!1===_.needsUpdate)return;if(0===e.length)return;const l=t.getRenderTarget(),h=t.getActiveCubeFace(),u=t.getActiveMipmapLevel(),d=t.state;d.setBlending(et),d.buffers.color.setClear(1,1,1,1),d.buffers.depth.setTest(!0),d.setScissorTest(!1);for(let l=0,h=e.length;l<h;l++){const h=e[l],u=h.shadow;if(void 0===u)continue;if(!1===u.autoUpdate&&!1===u.needsUpdate)continue;s.copy(u.mapSize);const p=u.getFrameExtents();if(s.multiply(p),r.copy(u.mapSize),(s.x>c||s.y>c)&&(s.x>c&&(r.x=Math.floor(c/p.x),s.x=r.x*p.x,u.mapSize.x=r.x),s.y>c&&(r.y=Math.floor(c/p.y),s.y=r.y*p.y,u.mapSize.y=r.y)),null===u.map&&!u.isPointLightShadow&&this.type===Z){const t={minFilter:Kt,magFilter:Kt,format:me};u.map=new qi(s.x,s.y,t),u.map.texture.name=h.name+".shadowMap",u.mapPass=new qi(s.x,s.y,t),u.camera.updateProjectionMatrix()}if(null===u.map){const t={minFilter:Yt,magFilter:Yt,format:me};u.map=new qi(s.x,s.y,t),u.map.texture.name=h.name+".shadowMap",u.camera.updateProjectionMatrix()}t.setRenderTarget(u.map),t.clear();const f=u.getViewportCount();for(let t=0;t<f;t++){const e=u.getViewport(t);a.set(r.x*e.x,r.y*e.y,r.x*e.z,r.y*e.w),d.viewport(a),u.updateMatrices(h,t),n=u.getFrustum(),v(i,o,u.camera,h,this.type)}u.isPointLightShadow||this.type!==Z||g(u,o),u.needsUpdate=!1}_.needsUpdate=!1,t.setRenderTarget(l,h,u)}}function Qo(t,e,i){const n=i.isWebGL2,s=new function(){let e=!1;const i=new ji;let n=null;const s=new ji(0,0,0,0);return{setMask:function(i){n===i||e||(t.colorMask(i,i,i,i),n=i)},setLocked:function(t){e=t},setClear:function(e,n,r,a,o){!0===o&&(e*=a,n*=a,r*=a),i.set(e,n,r,a),!1===s.equals(i)&&(t.clearColor(e,n,r,a),s.copy(i))},reset:function(){e=!1,n=null,s.set(-1,0,0,0)}}},r=new function(){let e=!1,i=null,n=null,s=null;return{setTest:function(t){t?O(2929):R(2929)},setMask:function(n){i===n||e||(t.depthMask(n),i=n)},setFunc:function(e){if(n!==e){if(e)switch(e){case St:t.depthFunc(512);break;case Mt:t.depthFunc(519);break;case Tt:t.depthFunc(513);break;case At:t.depthFunc(515);break;case Ct:t.depthFunc(514);break;case Et:t.depthFunc(518);break;case zt:t.depthFunc(516);break;case It:t.depthFunc(517);break;default:t.depthFunc(515)}else t.depthFunc(515);n=e}},setLocked:function(t){e=t},setClear:function(e){s!==e&&(t.clearDepth(e),s=e)},reset:function(){e=!1,i=null,n=null,s=null}}},a=new function(){let e=!1,i=null,n=null,s=null,r=null,a=null,o=null,l=null,h=null;return{setTest:function(t){e||(t?O(2960):R(2960))},setMask:function(n){i===n||e||(t.stencilMask(n),i=n)},setFunc:function(e,i,a){n===e&&s===i&&r===a||(t.stencilFunc(e,i,a),n=e,s=i,r=a)},setOp:function(e,i,n){a===e&&o===i&&l===n||(t.stencilOp(e,i,n),a=e,o=i,l=n)},setLocked:function(t){e=t},setClear:function(e){h!==e&&(t.clearStencil(e),h=e)},reset:function(){e=!1,i=null,n=null,s=null,r=null,a=null,o=null,l=null,h=null}}};let o={},l={},h=null,c=!1,u=null,d=null,p=null,f=null,m=null,_=null,g=null,y=!1,v=null,x=null,w=null,b=null,S=null;const M=t.getParameter(35661);let T=!1,A=0;const C=t.getParameter(7938);-1!==C.indexOf("WebGL")?(A=parseFloat(/^WebGL (\d)/.exec(C)[1]),T=A>=1):-1!==C.indexOf("OpenGL ES")&&(A=parseFloat(/^OpenGL ES (\d)/.exec(C)[1]),T=A>=2);let E=null,z={};const I=t.getParameter(3088),L=t.getParameter(2978),N=(new ji).fromArray(I),P=(new ji).fromArray(L);function D(e,i,n){const s=new Uint8Array(4),r=t.createTexture();t.bindTexture(e,r),t.texParameteri(e,10241,9728),t.texParameteri(e,10240,9728);for(let e=0;e<n;e++)t.texImage2D(i+e,0,6408,1,1,0,6408,5121,s);return r}const F={};function O(e){!0!==o[e]&&(t.enable(e),o[e]=!0)}function R(e){!1!==o[e]&&(t.disable(e),o[e]=!1)}F[3553]=D(3553,3553,1),F[34067]=D(34067,34069,6),s.setClear(0,0,0,1),r.setClear(1),a.setClear(0),O(2929),r.setFunc(At),V(!1),W(J),O(2884),U(et);const k={[ot]:32774,[lt]:32778,[ht]:32779};if(n)k[ct]=32775,k[ut]=32776;else{const t=e.get("EXT_blend_minmax");null!==t&&(k[ct]=t.MIN_EXT,k[ut]=t.MAX_EXT)}const B={[dt]:0,[pt]:1,[ft]:768,[_t]:770,[bt]:776,[xt]:774,[yt]:772,[mt]:769,[gt]:771,[wt]:775,[vt]:773};function U(e,i,n,s,r,a,o,l){if(e!==et){if(!1===c&&(O(3042),c=!0),e===at)r=r||i,a=a||n,o=o||s,i===d&&r===m||(t.blendEquationSeparate(k[i],k[r]),d=i,m=r),n===p&&s===f&&a===_&&o===g||(t.blendFuncSeparate(B[n],B[s],B[a],B[o]),p=n,f=s,_=a,g=o),u=e,y=null;else if(e!==u||l!==y){if(d===ot&&m===ot||(t.blendEquation(32774),d=ot,m=ot),l)switch(e){case it:t.blendFuncSeparate(1,771,1,771);break;case nt:t.blendFunc(1,1);break;case st:t.blendFuncSeparate(0,0,769,771);break;case rt:t.blendFuncSeparate(0,768,0,770)}else switch(e){case it:t.blendFuncSeparate(770,771,1,771);break;case nt:t.blendFunc(770,1);break;case st:t.blendFunc(0,769);break;case rt:t.blendFunc(0,768)}p=null,f=null,_=null,g=null,u=e,y=l}}else!0===c&&(R(3042),c=!1)}function V(e){v!==e&&(e?t.frontFace(2304):t.frontFace(2305),v=e)}function W(e){e!==q?(O(2884),e!==x&&(e===J?t.cullFace(1029):e===$?t.cullFace(1028):t.cullFace(1032))):R(2884),x=e}function G(e,i,n){e?(O(32823),b===i&&S===n||(t.polygonOffset(i,n),b=i,S=n)):R(32823)}function H(e){void 0===e&&(e=33984+M-1),E!==e&&(t.activeTexture(e),E=e)}return{buffers:{color:s,depth:r,stencil:a},enable:O,disable:R,bindFramebuffer:function(e,i){return l[e]!==i&&(t.bindFramebuffer(e,i),l[e]=i,n&&(36009===e&&(l[36160]=i),36160===e&&(l[36009]=i)),!0)},useProgram:function(e){return h!==e&&(t.useProgram(e),h=e,!0)},setBlending:U,setMaterial:function(t,e){t.side===tt?R(2884):O(2884);let i=t.side===Q;e&&(i=!i),V(i),t.blending===it&&!1===t.transparent?U(et):U(t.blending,t.blendEquation,t.blendSrc,t.blendDst,t.blendEquationAlpha,t.blendSrcAlpha,t.blendDstAlpha,t.premultipliedAlpha),r.setFunc(t.depthFunc),r.setTest(t.depthTest),r.setMask(t.depthWrite),s.setMask(t.colorWrite);const n=t.stencilWrite;a.setTest(n),n&&(a.setMask(t.stencilWriteMask),a.setFunc(t.stencilFunc,t.stencilRef,t.stencilFuncMask),a.setOp(t.stencilFail,t.stencilZFail,t.stencilZPass)),G(t.polygonOffset,t.polygonOffsetFactor,t.polygonOffsetUnits),!0===t.alphaToCoverage?O(32926):R(32926)},setFlipSided:V,setCullFace:W,setLineWidth:function(e){e!==w&&(T&&t.lineWidth(e),w=e)},setPolygonOffset:G,setScissorTest:function(t){t?O(3089):R(3089)},activeTexture:H,bindTexture:function(e,i){null===E&&H();let n=z[E];void 0===n&&(n={type:void 0,texture:void 0},z[E]=n),n.type===e&&n.texture===i||(t.bindTexture(e,i||F[e]),n.type=e,n.texture=i)},unbindTexture:function(){const e=z[E];void 0!==e&&void 0!==e.type&&(t.bindTexture(e.type,null),e.type=void 0,e.texture=void 0)},compressedTexImage2D:function(){try{t.compressedTexImage2D.apply(t,arguments)}catch(t){}},texImage2D:function(){try{t.texImage2D.apply(t,arguments)}catch(t){}},texImage3D:function(){try{t.texImage3D.apply(t,arguments)}catch(t){}},texStorage2D:function(){try{t.texStorage2D.apply(t,arguments)}catch(t){}},texStorage3D:function(){try{t.texStorage3D.apply(t,arguments)}catch(t){}},texSubImage2D:function(){try{t.texSubImage2D.apply(t,arguments)}catch(t){}},texSubImage3D:function(){try{t.texSubImage3D.apply(t,arguments)}catch(t){}},compressedTexSubImage2D:function(){try{t.compressedTexSubImage2D.apply(t,arguments)}catch(t){}},scissor:function(e){!1===N.equals(e)&&(t.scissor(e.x,e.y,e.z,e.w),N.copy(e))},viewport:function(e){!1===P.equals(e)&&(t.viewport(e.x,e.y,e.z,e.w),P.copy(e))},reset:function(){t.disable(3042),t.disable(2884),t.disable(2929),t.disable(32823),t.disable(3089),t.disable(2960),t.disable(32926),t.blendEquation(32774),t.blendFunc(1,0),t.blendFuncSeparate(1,0,1,0),t.colorMask(!0,!0,!0,!0),t.clearColor(0,0,0,0),t.depthMask(!0),t.depthFunc(513),t.clearDepth(1),t.stencilMask(4294967295),t.stencilFunc(519,0,4294967295),t.stencilOp(7680,7680,7680),t.clearStencil(0),t.cullFace(1029),t.frontFace(2305),t.polygonOffset(0,0),t.activeTexture(33984),t.bindFramebuffer(36160,null),!0===n&&(t.bindFramebuffer(36009,null),t.bindFramebuffer(36008,null)),t.useProgram(null),t.lineWidth(1),t.scissor(0,0,t.canvas.width,t.canvas.height),t.viewport(0,0,t.canvas.width,t.canvas.height),o={},E=null,z={},l={},h=null,c=!1,u=null,d=null,p=null,f=null,m=null,_=null,g=null,y=!1,v=null,x=null,w=null,b=null,S=null,N.set(0,0,t.canvas.width,t.canvas.height),P.set(0,0,t.canvas.width,t.canvas.height),s.reset(),r.reset(),a.reset()}}}function tl(t,e,i,n,s,r,a){const o=s.isWebGL2;s.maxTextures;const l=s.maxCubemapSize,h=s.maxTextureSize,c=s.maxSamples,u=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):void 0,d=new WeakMap;let p,f=!1;try{f="undefined"!=typeof OffscreenCanvas&&null!==new OffscreenCanvas(1,1).getContext("2d")}catch(t){}function m(t,e){return f?new OffscreenCanvas(t,e):Ui("canvas")}function _(t,e,i,n){let s=1;if((t.width>n||t.height>n)&&(s=n/Math.max(t.width,t.height)),s<1||!0===e){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){const n=e?Fi:Math.floor,r=n(s*t.width),a=n(s*t.height);void 0===p&&(p=m(r,a));const o=i?m(r,a):p;return o.width=r,o.height=a,o.getContext("2d").drawImage(t,0,0,r,a),o}return t}return t}function g(t){return Di(t.width)&&Di(t.height)}function y(t,e){return t.generateMipmaps&&e&&t.minFilter!==Yt&&t.minFilter!==Kt}function v(e){t.generateMipmap(e)}function x(i,n,s,r){if(!1===o)return n;if(null!==i&&void 0!==t[i])return t[i];let a=n;return 6403===n&&(5126===s&&(a=33326),5131===s&&(a=33325),5121===s&&(a=33321)),6407===n&&(5126===s&&(a=34837),5131===s&&(a=34843),5121===s&&(a=32849)),6408===n&&(5126===s&&(a=34836),5131===s&&(a=34842),5121===s&&(a=r===vi?35907:32856)),33325!==a&&33326!==a&&34842!==a&&34836!==a||e.get("EXT_color_buffer_float"),a}function w(t,e,i){return!0===y(t,i)||t.isFramebufferTexture&&t.minFilter!==Yt&&t.minFilter!==Kt?Math.log2(Math.max(e.width,e.height))+1:void 0!==t.mipmaps&&t.mipmaps.length>0?t.mipmaps.length:t.isCompressedTexture&&Array.isArray(t.image)?e.mipmaps.length:1}function b(t){return t===Yt||t===Xt||t===Zt?9728:9729}function S(e){const i=e.target;i.removeEventListener("dispose",S),function(e){const i=n.get(e);void 0!==i.__webglInit&&(t.deleteTexture(i.__webglTexture),n.remove(e))}(i),i.isVideoTexture&&d.delete(i),a.memory.textures--}function M(e){const i=e.target;i.removeEventListener("dispose",M),function(e){const i=e.texture,s=n.get(e),r=n.get(i);if(e){if(void 0!==r.__webglTexture&&(t.deleteTexture(r.__webglTexture),a.memory.textures--),e.depthTexture&&e.depthTexture.dispose(),e.isWebGLCubeRenderTarget)for(let e=0;e<6;e++)t.deleteFramebuffer(s.__webglFramebuffer[e]),s.__webglDepthbuffer&&t.deleteRenderbuffer(s.__webglDepthbuffer[e]);else t.deleteFramebuffer(s.__webglFramebuffer),s.__webglDepthbuffer&&t.deleteRenderbuffer(s.__webglDepthbuffer),s.__webglMultisampledFramebuffer&&t.deleteFramebuffer(s.__webglMultisampledFramebuffer),s.__webglColorRenderbuffer&&t.deleteRenderbuffer(s.__webglColorRenderbuffer),s.__webglDepthRenderbuffer&&t.deleteRenderbuffer(s.__webglDepthRenderbuffer);if(e.isWebGLMultipleRenderTargets)for(let e=0,s=i.length;e<s;e++){const s=n.get(i[e]);s.__webglTexture&&(t.deleteTexture(s.__webglTexture),a.memory.textures--),n.remove(i[e])}n.remove(i),n.remove(e)}}(i)}let T=0;function A(t,e){const s=n.get(t);if(t.isVideoTexture&&function(t){const e=a.render.frame;d.get(t)!==e&&(d.set(t,e),t.update())}(t),t.version>0&&s.__version!==t.version){const i=t.image;if(void 0===i);else if(!1!==i.complete)return void N(s,t,e)}i.activeTexture(33984+e),i.bindTexture(3553,s.__webglTexture)}function C(e,s){const a=n.get(e);e.version>0&&a.__version!==e.version?function(e,n,s){if(6!==n.image.length)return;L(e,n),i.activeTexture(33984+s),i.bindTexture(34067,e.__webglTexture),t.pixelStorei(37440,n.flipY),t.pixelStorei(37441,n.premultiplyAlpha),t.pixelStorei(3317,n.unpackAlignment),t.pixelStorei(37443,0);const a=n&&(n.isCompressedTexture||n.image[0].isCompressedTexture),h=n.image[0]&&n.image[0].isDataTexture,c=[];for(let t=0;t<6;t++)c[t]=a||h?h?n.image[t].image:n.image[t]:_(n.image[t],!1,!0,l);const u=c[0],d=g(u)||o,p=r.convert(n.format),f=r.convert(n.type),m=x(n.internalFormat,p,f,n.encoding),b=o&&!0!==n.isVideoTexture,S=void 0===e.__version;let M,T=w(n,u,d);if(I(34067,n,d),a){b&&S&&i.texStorage2D(34067,T,m,u.width,u.height);for(let t=0;t<6;t++){M=c[t].mipmaps;for(let e=0;e<M.length;e++){const s=M[e];n.format!==me&&n.format!==fe?null!==p&&(b?i.compressedTexSubImage2D(34069+t,e,0,0,s.width,s.height,p,s.data):i.compressedTexImage2D(34069+t,e,m,s.width,s.height,0,s.data)):b?i.texSubImage2D(34069+t,e,0,0,s.width,s.height,p,f,s.data):i.texImage2D(34069+t,e,m,s.width,s.height,0,p,f,s.data)}}}else{M=n.mipmaps,b&&S&&(M.length>0&&T++,i.texStorage2D(34067,T,m,c[0].width,c[0].height));for(let t=0;t<6;t++)if(h){b?i.texSubImage2D(34069+t,0,0,0,c[t].width,c[t].height,p,f,c[t].data):i.texImage2D(34069+t,0,m,c[t].width,c[t].height,0,p,f,c[t].data);for(let e=0;e<M.length;e++){const n=M[e].image[t].image;b?i.texSubImage2D(34069+t,e+1,0,0,n.width,n.height,p,f,n.data):i.texImage2D(34069+t,e+1,m,n.width,n.height,0,p,f,n.data)}}else{b?i.texSubImage2D(34069+t,0,0,0,p,f,c[t]):i.texImage2D(34069+t,0,m,p,f,c[t]);for(let e=0;e<M.length;e++){const n=M[e];b?i.texSubImage2D(34069+t,e+1,0,0,p,f,n.image[t]):i.texImage2D(34069+t,e+1,m,p,f,n.image[t])}}}y(n,d)&&v(34067),e.__version=n.version,n.onUpdate&&n.onUpdate(n)}(a,e,s):(i.activeTexture(33984+s),i.bindTexture(34067,a.__webglTexture))}const E={[qt]:10497,[Jt]:33071,[$t]:33648},z={[Yt]:9728,[Xt]:9984,[Zt]:9986,[Kt]:9729,[Qt]:9985,[te]:9987};function I(i,r,a){if(a?(t.texParameteri(i,10242,E[r.wrapS]),t.texParameteri(i,10243,E[r.wrapT]),32879!==i&&35866!==i||t.texParameteri(i,32882,E[r.wrapR]),t.texParameteri(i,10240,z[r.magFilter]),t.texParameteri(i,10241,z[r.minFilter])):(t.texParameteri(i,10242,33071),t.texParameteri(i,10243,33071),32879!==i&&35866!==i||t.texParameteri(i,32882,33071),r.wrapS!==Jt||r.wrapT,t.texParameteri(i,10240,b(r.magFilter)),t.texParameteri(i,10241,b(r.minFilter)),r.minFilter!==Yt&&r.minFilter),!0===e.has("EXT_texture_filter_anisotropic")){const a=e.get("EXT_texture_filter_anisotropic");if(r.type===oe&&!1===e.has("OES_texture_float_linear"))return;if(!1===o&&r.type===le&&!1===e.has("OES_texture_half_float_linear"))return;(r.anisotropy>1||n.get(r).__currentAnisotropy)&&(t.texParameterf(i,a.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(r.anisotropy,s.getMaxAnisotropy())),n.get(r).__currentAnisotropy=r.anisotropy)}}function L(e,i){void 0===e.__webglInit&&(e.__webglInit=!0,i.addEventListener("dispose",S),e.__webglTexture=t.createTexture(),a.memory.textures++)}function N(e,n,s){let a=3553;n.isDataTexture2DArray&&(a=35866),n.isDataTexture3D&&(a=32879),L(e,n),i.activeTexture(33984+s),i.bindTexture(a,e.__webglTexture),t.pixelStorei(37440,n.flipY),t.pixelStorei(37441,n.premultiplyAlpha),t.pixelStorei(3317,n.unpackAlignment),t.pixelStorei(37443,0);const l=function(t){return!o&&(t.wrapS!==Jt||t.wrapT!==Jt||t.minFilter!==Yt&&t.minFilter!==Kt)}(n)&&!1===g(n.image),c=_(n.image,l,!1,h),u=g(c)||o,d=r.convert(n.format);let p,f=r.convert(n.type),m=x(n.internalFormat,d,f,n.encoding);I(a,n,u);const b=n.mipmaps,S=o&&!0!==n.isVideoTexture,M=void 0===e.__version,T=w(n,c,u);if(n.isDepthTexture)m=6402,o?m=n.type===oe?36012:n.type===ae?33190:n.type===de?35056:33189:n.type,n.format===ye&&6402===m&&n.type!==se&&n.type!==ae&&(n.type=se,f=r.convert(n.type)),n.format===ve&&6402===m&&(m=34041,n.type!==de&&(n.type=de,f=r.convert(n.type))),S&&M?i.texStorage2D(3553,1,m,c.width,c.height):i.texImage2D(3553,0,m,c.width,c.height,0,d,f,null);else if(n.isDataTexture)if(b.length>0&&u){S&&M&&i.texStorage2D(3553,T,m,b[0].width,b[0].height);for(let t=0,e=b.length;t<e;t++)p=b[t],S?i.texSubImage2D(3553,0,0,0,p.width,p.height,d,f,p.data):i.texImage2D(3553,t,m,p.width,p.height,0,d,f,p.data);n.generateMipmaps=!1}else S?(M&&i.texStorage2D(3553,T,m,c.width,c.height),i.texSubImage2D(3553,0,0,0,c.width,c.height,d,f,c.data)):i.texImage2D(3553,0,m,c.width,c.height,0,d,f,c.data);else if(n.isCompressedTexture){S&&M&&i.texStorage2D(3553,T,m,b[0].width,b[0].height);for(let t=0,e=b.length;t<e;t++)p=b[t],n.format!==me&&n.format!==fe?null!==d&&(S?i.compressedTexSubImage2D(3553,t,0,0,p.width,p.height,d,p.data):i.compressedTexImage2D(3553,t,m,p.width,p.height,0,p.data)):S?i.texSubImage2D(3553,t,0,0,p.width,p.height,d,f,p.data):i.texImage2D(3553,t,m,p.width,p.height,0,d,f,p.data)}else if(n.isDataTexture2DArray)S?(M&&i.texStorage3D(35866,T,m,c.width,c.height,c.depth),i.texSubImage3D(35866,0,0,0,0,c.width,c.height,c.depth,d,f,c.data)):i.texImage3D(35866,0,m,c.width,c.height,c.depth,0,d,f,c.data);else if(n.isDataTexture3D)S?(M&&i.texStorage3D(32879,T,m,c.width,c.height,c.depth),i.texSubImage3D(32879,0,0,0,0,c.width,c.height,c.depth,d,f,c.data)):i.texImage3D(32879,0,m,c.width,c.height,c.depth,0,d,f,c.data);else if(n.isFramebufferTexture)S&&M?i.texStorage2D(3553,T,m,c.width,c.height):i.texImage2D(3553,0,m,c.width,c.height,0,d,f,null);else if(b.length>0&&u){S&&M&&i.texStorage2D(3553,T,m,b[0].width,b[0].height);for(let t=0,e=b.length;t<e;t++)p=b[t],S?i.texSubImage2D(3553,t,0,0,d,f,p):i.texImage2D(3553,t,m,d,f,p);n.generateMipmaps=!1}else S?(M&&i.texStorage2D(3553,T,m,c.width,c.height),i.texSubImage2D(3553,0,0,0,d,f,c)):i.texImage2D(3553,0,m,d,f,c);y(n,u)&&v(a),e.__version=n.version,n.onUpdate&&n.onUpdate(n)}function P(e,s,a,o,l){const h=r.convert(a.format),c=r.convert(a.type),d=x(a.internalFormat,h,c,a.encoding);n.get(s).__hasExternalTextures||(32879===l||35866===l?i.texImage3D(l,0,d,s.width,s.height,s.depth,0,h,c,null):i.texImage2D(l,0,d,s.width,s.height,0,h,c,null)),i.bindFramebuffer(36160,e),s.useRenderToTexture?u.framebufferTexture2DMultisampleEXT(36160,o,l,n.get(a).__webglTexture,0,O(s)):t.framebufferTexture2D(36160,o,l,n.get(a).__webglTexture,0),i.bindFramebuffer(36160,null)}function D(e,i,n){if(t.bindRenderbuffer(36161,e),i.depthBuffer&&!i.stencilBuffer){let s=33189;if(n||i.useRenderToTexture){const e=i.depthTexture;e&&e.isDepthTexture&&(e.type===oe?s=36012:e.type===ae&&(s=33190));const n=O(i);i.useRenderToTexture?u.renderbufferStorageMultisampleEXT(36161,n,s,i.width,i.height):t.renderbufferStorageMultisample(36161,n,s,i.width,i.height)}else t.renderbufferStorage(36161,s,i.width,i.height);t.framebufferRenderbuffer(36160,36096,36161,e)}else if(i.depthBuffer&&i.stencilBuffer){const s=O(i);n&&i.useRenderbuffer?t.renderbufferStorageMultisample(36161,s,35056,i.width,i.height):i.useRenderToTexture?u.renderbufferStorageMultisampleEXT(36161,s,35056,i.width,i.height):t.renderbufferStorage(36161,34041,i.width,i.height),t.framebufferRenderbuffer(36160,33306,36161,e)}else{const e=!0===i.isWebGLMultipleRenderTargets?i.texture[0]:i.texture,s=r.convert(e.format),a=r.convert(e.type),o=x(e.internalFormat,s,a,e.encoding),l=O(i);n&&i.useRenderbuffer?t.renderbufferStorageMultisample(36161,l,o,i.width,i.height):i.useRenderToTexture?u.renderbufferStorageMultisampleEXT(36161,l,o,i.width,i.height):t.renderbufferStorage(36161,o,i.width,i.height)}t.bindRenderbuffer(36161,null)}function F(e){const s=n.get(e),r=!0===e.isWebGLCubeRenderTarget;if(e.depthTexture&&!s.__autoAllocateDepthBuffer){if(r)throw new Error("target.depthTexture not supported in Cube render targets");!function(e,s){if(s&&s.isWebGLCubeRenderTarget)throw new Error("Depth Texture with cube render targets is not supported");if(i.bindFramebuffer(36160,e),!s.depthTexture||!s.depthTexture.isDepthTexture)throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");n.get(s.depthTexture).__webglTexture&&s.depthTexture.image.width===s.width&&s.depthTexture.image.height===s.height||(s.depthTexture.image.width=s.width,s.depthTexture.image.height=s.height,s.depthTexture.needsUpdate=!0),A(s.depthTexture,0);const r=n.get(s.depthTexture).__webglTexture,a=O(s);if(s.depthTexture.format===ye)s.useRenderToTexture?u.framebufferTexture2DMultisampleEXT(36160,36096,3553,r,0,a):t.framebufferTexture2D(36160,36096,3553,r,0);else{if(s.depthTexture.format!==ve)throw new Error("Unknown depthTexture format");s.useRenderToTexture?u.framebufferTexture2DMultisampleEXT(36160,33306,3553,r,0,a):t.framebufferTexture2D(36160,33306,3553,r,0)}}(s.__webglFramebuffer,e)}else if(r){s.__webglDepthbuffer=[];for(let n=0;n<6;n++)i.bindFramebuffer(36160,s.__webglFramebuffer[n]),s.__webglDepthbuffer[n]=t.createRenderbuffer(),D(s.__webglDepthbuffer[n],e,!1)}else i.bindFramebuffer(36160,s.__webglFramebuffer),s.__webglDepthbuffer=t.createRenderbuffer(),D(s.__webglDepthbuffer,e,!1);i.bindFramebuffer(36160,null)}function O(t){return o&&(t.useRenderbuffer||t.useRenderToTexture)?Math.min(c,t.samples):0}this.allocateTextureUnit=function(){const t=T;return T+=1,t},this.resetTextureUnits=function(){T=0},this.setTexture2D=A,this.setTexture2DArray=function(t,e){const s=n.get(t);t.version>0&&s.__version!==t.version?N(s,t,e):(i.activeTexture(33984+e),i.bindTexture(35866,s.__webglTexture))},this.setTexture3D=function(t,e){const s=n.get(t);t.version>0&&s.__version!==t.version?N(s,t,e):(i.activeTexture(33984+e),i.bindTexture(32879,s.__webglTexture))},this.setTextureCube=C,this.rebindTextures=function(t,e,i){const s=n.get(t);void 0!==e&&P(s.__webglFramebuffer,t,t.texture,36064,3553),void 0!==i&&F(t)},this.setupRenderTarget=function(e){const l=e.texture,h=n.get(e),c=n.get(l);e.addEventListener("dispose",M),!0!==e.isWebGLMultipleRenderTargets&&(void 0===c.__webglTexture&&(c.__webglTexture=t.createTexture()),c.__version=l.version,a.memory.textures++);const u=!0===e.isWebGLCubeRenderTarget,d=!0===e.isWebGLMultipleRenderTargets,p=l.isDataTexture3D||l.isDataTexture2DArray,f=g(e)||o;if(!o||l.format!==fe||l.type!==oe&&l.type!==le||(l.format=me),u){h.__webglFramebuffer=[];for(let e=0;e<6;e++)h.__webglFramebuffer[e]=t.createFramebuffer()}else if(h.__webglFramebuffer=t.createFramebuffer(),d){if(s.drawBuffers){const i=e.texture;for(let e=0,s=i.length;e<s;e++){const s=n.get(i[e]);void 0===s.__webglTexture&&(s.__webglTexture=t.createTexture(),a.memory.textures++)}}}else if(e.useRenderbuffer&&o){h.__webglMultisampledFramebuffer=t.createFramebuffer(),h.__webglColorRenderbuffer=t.createRenderbuffer(),t.bindRenderbuffer(36161,h.__webglColorRenderbuffer);const n=r.convert(l.format),s=r.convert(l.type),a=x(l.internalFormat,n,s,l.encoding),o=O(e);t.renderbufferStorageMultisample(36161,o,a,e.width,e.height),i.bindFramebuffer(36160,h.__webglMultisampledFramebuffer),t.framebufferRenderbuffer(36160,36064,36161,h.__webglColorRenderbuffer),t.bindRenderbuffer(36161,null),e.depthBuffer&&(h.__webglDepthRenderbuffer=t.createRenderbuffer(),D(h.__webglDepthRenderbuffer,e,!0)),i.bindFramebuffer(36160,null)}if(u){i.bindTexture(34067,c.__webglTexture),I(34067,l,f);for(let t=0;t<6;t++)P(h.__webglFramebuffer[t],e,l,36064,34069+t);y(l,f)&&v(34067),i.unbindTexture()}else if(d){const t=e.texture;for(let s=0,r=t.length;s<r;s++){const r=t[s],a=n.get(r);i.bindTexture(3553,a.__webglTexture),I(3553,r,f),P(h.__webglFramebuffer,e,r,36064+s,3553),y(r,f)&&v(3553)}i.unbindTexture()}else{let t=3553;p&&o&&(t=l.isDataTexture3D?32879:35866),i.bindTexture(t,c.__webglTexture),I(t,l,f),P(h.__webglFramebuffer,e,l,36064,t),y(l,f)&&v(t),i.unbindTexture()}e.depthBuffer&&F(e)},this.updateRenderTargetMipmap=function(t){const e=g(t)||o,s=!0===t.isWebGLMultipleRenderTargets?t.texture:[t.texture];for(let r=0,a=s.length;r<a;r++){const a=s[r];if(y(a,e)){const e=t.isWebGLCubeRenderTarget?34067:3553,s=n.get(a).__webglTexture;i.bindTexture(e,s),v(e),i.unbindTexture()}}},this.updateMultisampleRenderTarget=function(e){if(e.useRenderbuffer&&o){const s=e.width,r=e.height;let a=16384;const o=[36064],l=e.stencilBuffer?33306:36096;e.depthBuffer&&o.push(l),e.ignoreDepthForMultisampleCopy||(e.depthBuffer&&(a|=256),e.stencilBuffer&&(a|=1024));const h=n.get(e);i.bindFramebuffer(36008,h.__webglMultisampledFramebuffer),i.bindFramebuffer(36009,h.__webglFramebuffer),e.ignoreDepthForMultisampleCopy&&(t.invalidateFramebuffer(36008,[l]),t.invalidateFramebuffer(36009,[l])),t.blitFramebuffer(0,0,s,r,0,0,s,r,a,9728),t.invalidateFramebuffer(36008,o),i.bindFramebuffer(36008,null),i.bindFramebuffer(36009,h.__webglMultisampledFramebuffer)}},this.setupDepthRenderbuffer=F,this.setupFrameBufferTexture=P,this.safeSetTexture2D=function(t,e){t&&t.isWebGLRenderTarget&&(t=t.texture),A(t,e)},this.safeSetTextureCube=function(t,e){t&&t.isWebGLCubeRenderTarget&&(t=t.texture),C(t,e)}}function el(t,e,i){const n=i.isWebGL2;return{convert:function(t){let i;if(t===ee)return 5121;if(t===he)return 32819;if(t===ce)return 32820;if(t===ue)return 33635;if(t===ie)return 5120;if(t===ne)return 5122;if(t===se)return 5123;if(t===re)return 5124;if(t===ae)return 5125;if(t===oe)return 5126;if(t===le)return n?5131:(i=e.get("OES_texture_half_float"),null!==i?i.HALF_FLOAT_OES:null);if(t===pe)return 6406;if(t===fe)return 6407;if(t===me)return 6408;if(t===_e)return 6409;if(t===ge)return 6410;if(t===ye)return 6402;if(t===ve)return 34041;if(t===xe)return 6403;if(t===we)return 36244;if(t===be)return 33319;if(t===Se)return 33320;if(t===Me)return 36248;if(t===Te)return 36249;if(t===Ae||t===Ce||t===Ee||t===ze){if(i=e.get("WEBGL_compressed_texture_s3tc"),null===i)return null;if(t===Ae)return i.COMPRESSED_RGB_S3TC_DXT1_EXT;if(t===Ce)return i.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(t===Ee)return i.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(t===ze)return i.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(t===Ie||t===Le||t===Ne||t===Pe){if(i=e.get("WEBGL_compressed_texture_pvrtc"),null===i)return null;if(t===Ie)return i.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(t===Le)return i.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(t===Ne)return i.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(t===Pe)return i.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(t===De)return i=e.get("WEBGL_compressed_texture_etc1"),null!==i?i.COMPRESSED_RGB_ETC1_WEBGL:null;if((t===Fe||t===Oe)&&(i=e.get("WEBGL_compressed_texture_etc"),null!==i)){if(t===Fe)return i.COMPRESSED_RGB8_ETC2;if(t===Oe)return i.COMPRESSED_RGBA8_ETC2_EAC}return t===Re||t===ke||t===Be||t===Ue||t===Ve||t===We||t===Ge||t===He||t===je||t===qe||t===Je||t===$e||t===Ye||t===Xe||t===Ke||t===Qe||t===ti||t===ei||t===ii||t===ni||t===si||t===ri||t===ai||t===oi||t===li||t===hi||t===ci||t===ui?(i=e.get("WEBGL_compressed_texture_astc"),null!==i?t:null):t===Ze?(i=e.get("EXT_texture_compression_bptc"),null!==i?t:null):t===de?n?34042:(i=e.get("WEBGL_depth_texture"),null!==i?i.UNSIGNED_INT_24_8_WEBGL:null):void 0}}}class il extends rr{constructor(t=[]){super(),this.cameras=t}}il.prototype.isArrayCamera=!0;class nl extends Kn{constructor(){super(),this.type="Group"}}nl.prototype.isGroup=!0;const sl={type:"move"};class rl{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return null===this._hand&&(this._hand=new nl,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return null===this._targetRay&&(this._targetRay=new nl,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new Yi,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new Yi),this._targetRay}getGripSpace(){return null===this._grip&&(this._grip=new nl,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new Yi,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new Yi),this._grip}dispatchEvent(t){return null!==this._targetRay&&this._targetRay.dispatchEvent(t),null!==this._grip&&this._grip.dispatchEvent(t),null!==this._hand&&this._hand.dispatchEvent(t),this}disconnect(t){return this.dispatchEvent({type:"disconnected",data:t}),null!==this._targetRay&&(this._targetRay.visible=!1),null!==this._grip&&(this._grip.visible=!1),null!==this._hand&&(this._hand.visible=!1),this}update(t,e,i){let n=null,s=null,r=null;const a=this._targetRay,o=this._grip,l=this._hand;if(t&&"visible-blurred"!==e.session.visibilityState)if(null!==a&&(n=e.getPose(t.targetRaySpace,i),null!==n&&(a.matrix.fromArray(n.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),n.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(n.linearVelocity)):a.hasLinearVelocity=!1,n.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(n.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(sl))),l&&t.hand){r=!0;for(const n of t.hand.values()){const t=e.getJointPose(n,i);if(void 0===l.joints[n.jointName]){const t=new nl;t.matrixAutoUpdate=!1,t.visible=!1,l.joints[n.jointName]=t,l.add(t)}const s=l.joints[n.jointName];null!==t&&(s.matrix.fromArray(t.transform.matrix),s.matrix.decompose(s.position,s.rotation,s.scale),s.jointRadius=t.radius),s.visible=null!==t}const n=l.joints["index-finger-tip"],s=l.joints["thumb-tip"],a=n.position.distanceTo(s.position),o=.02,h=.005;l.inputState.pinching&&a>o+h?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:t.handedness,target:this})):!l.inputState.pinching&&a<=o-h&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:t.handedness,target:this}))}else null!==o&&t.gripSpace&&(s=e.getPose(t.gripSpace,i),null!==s&&(o.matrix.fromArray(s.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),s.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(s.linearVelocity)):o.hasLinearVelocity=!1,s.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(s.angularVelocity)):o.hasAngularVelocity=!1));return null!==a&&(a.visible=null!==n),null!==o&&(o.visible=null!==s),null!==l&&(l.visible=null!==r),this}}class al extends Gi{constructor(t,e,i,n,s,r,a,o,l,h){if((h=void 0!==h?h:ye)!==ye&&h!==ve)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===i&&h===ye&&(i=se),void 0===i&&h===ve&&(i=de),super(null,n,s,r,a,o,h,i,l),this.image={width:t,height:e},this.magFilter=void 0!==a?a:Yt,this.minFilter=void 0!==o?o:Yt,this.flipY=!1,this.generateMipmaps=!1}}al.prototype.isDepthTexture=!0;class ol extends Ci{constructor(t,e){super();const i=this;let n=null,s=1,r=null,a="local-floor";const o=t.extensions.has("WEBGL_multisampled_render_to_texture");let l=null,h=null,c=null,u=null,d=!1,p=null;const f=e.getContextAttributes();let m=null,_=null;const g=[],y=new Map,v=new rr;v.layers.enable(1),v.viewport=new ji;const x=new rr;x.layers.enable(2),x.viewport=new ji;const w=[v,x],b=new il;b.layers.enable(1),b.layers.enable(2);let S=null,M=null;function T(t){const e=y.get(t.inputSource);e&&e.dispatchEvent({type:t.type,data:t.inputSource})}function A(){y.forEach((function(t,e){t.disconnect(e)})),y.clear(),S=null,M=null,t.setRenderTarget(m),u=null,c=null,h=null,n=null,_=null,N.stop(),i.isPresenting=!1,i.dispatchEvent({type:"sessionend"})}function C(t){const e=n.inputSources;for(let t=0;t<g.length;t++)y.set(e[t],g[t]);for(let e=0;e<t.removed.length;e++){const i=t.removed[e],n=y.get(i);n&&(n.dispatchEvent({type:"disconnected",data:i}),y.delete(i))}for(let e=0;e<t.added.length;e++){const i=t.added[e],n=y.get(i);n&&n.dispatchEvent({type:"connected",data:i})}}this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(t){let e=g[t];return void 0===e&&(e=new rl,g[t]=e),e.getTargetRaySpace()},this.getControllerGrip=function(t){let e=g[t];return void 0===e&&(e=new rl,g[t]=e),e.getGripSpace()},this.getHand=function(t){let e=g[t];return void 0===e&&(e=new rl,g[t]=e),e.getHandSpace()},this.setFramebufferScaleFactor=function(t){s=t,i.isPresenting},this.setReferenceSpaceType=function(t){a=t,i.isPresenting},this.getReferenceSpace=function(){return r},this.getBaseLayer=function(){return null!==c?c:u},this.getBinding=function(){return h},this.getFrame=function(){return p},this.getSession=function(){return n},this.setSession=async function(l){if(n=l,null!==n){if(m=t.getRenderTarget(),n.addEventListener("select",T),n.addEventListener("selectstart",T),n.addEventListener("selectend",T),n.addEventListener("squeeze",T),n.addEventListener("squeezestart",T),n.addEventListener("squeezeend",T),n.addEventListener("end",A),n.addEventListener("inputsourceschange",C),!0!==f.xrCompatible&&await e.makeXRCompatible(),void 0===n.renderState.layers||!1===t.capabilities.isWebGL2){const i={antialias:void 0!==n.renderState.layers||f.antialias,alpha:f.alpha,depth:f.depth,stencil:f.stencil,framebufferScaleFactor:s};u=new XRWebGLLayer(n,e,i),n.updateRenderState({baseLayer:u}),_=new qi(u.framebufferWidth,u.framebufferHeight,{format:me,type:ee,encoding:t.outputEncoding})}else{d=f.antialias;let i=null,r=null,a=null;f.depth&&(a=f.stencil?35056:33190,i=f.stencil?ve:ye,r=f.stencil?de:se);const l={colorFormat:f.alpha||d?32856:32849,depthFormat:a,scaleFactor:s};h=new XRWebGLBinding(n,e),c=h.createProjectionLayer(l),n.updateRenderState({layers:[c]}),_=d?new Ji(c.textureWidth,c.textureHeight,{format:me,type:ee,depthTexture:new al(c.textureWidth,c.textureHeight,r,void 0,void 0,void 0,void 0,void 0,void 0,i),stencilBuffer:f.stencil,ignoreDepth:c.ignoreDepthValues,useRenderToTexture:o,encoding:t.outputEncoding}):new qi(c.textureWidth,c.textureHeight,{format:f.alpha?me:fe,type:ee,depthTexture:new al(c.textureWidth,c.textureHeight,r,void 0,void 0,void 0,void 0,void 0,void 0,i),stencilBuffer:f.stencil,ignoreDepth:c.ignoreDepthValues,encoding:t.outputEncoding})}this.setFoveation(1),r=await n.requestReferenceSpace(a),N.setContext(n),N.start(),i.isPresenting=!0,i.dispatchEvent({type:"sessionstart"})}};const E=new Yi,z=new Yi;function I(t,e){null===e?t.matrixWorld.copy(t.matrix):t.matrixWorld.multiplyMatrices(e.matrixWorld,t.matrix),t.matrixWorldInverse.copy(t.matrixWorld).invert()}this.updateCamera=function(t){if(null===n)return;b.near=x.near=v.near=t.near,b.far=x.far=v.far=t.far,S===b.near&&M===b.far||(n.updateRenderState({depthNear:b.near,depthFar:b.far}),S=b.near,M=b.far);const e=t.parent,i=b.cameras;I(b,e);for(let t=0;t<i.length;t++)I(i[t],e);b.matrixWorld.decompose(b.position,b.quaternion,b.scale),t.position.copy(b.position),t.quaternion.copy(b.quaternion),t.scale.copy(b.scale),t.matrix.copy(b.matrix),t.matrixWorld.copy(b.matrixWorld);const s=t.children;for(let t=0,e=s.length;t<e;t++)s[t].updateMatrixWorld(!0);2===i.length?function(t,e,i){E.setFromMatrixPosition(e.matrixWorld),z.setFromMatrixPosition(i.matrixWorld);const n=E.distanceTo(z),s=e.projectionMatrix.elements,r=i.projectionMatrix.elements,a=s[14]/(s[10]-1),o=s[14]/(s[10]+1),l=(s[9]+1)/s[5],h=(s[9]-1)/s[5],c=(s[8]-1)/s[0],u=(r[8]+1)/r[0],d=a*c,p=a*u,f=n/(-c+u),m=f*-c;e.matrixWorld.decompose(t.position,t.quaternion,t.scale),t.translateX(m),t.translateZ(f),t.matrixWorld.compose(t.position,t.quaternion,t.scale),t.matrixWorldInverse.copy(t.matrixWorld).invert();const _=a+f,g=o+f,y=d-m,v=p+(n-m),x=l*o/g*_,w=h*o/g*_;t.projectionMatrix.makePerspective(y,v,x,w,_,g)}(b,v,x):b.projectionMatrix.copy(v.projectionMatrix)},this.getCamera=function(){return b},this.getFoveation=function(){return null!==c?c.fixedFoveation:null!==u?u.fixedFoveation:void 0},this.setFoveation=function(t){null!==c&&(c.fixedFoveation=t),null!==u&&void 0!==u.fixedFoveation&&(u.fixedFoveation=t)};let L=null;const N=new gr;N.setAnimationLoop((function(e,i){if(l=i.getViewerPose(r),p=i,null!==l){const e=l.views;null!==u&&(t.setRenderTargetFramebuffer(_,u.framebuffer),t.setRenderTarget(_));let i=!1;e.length!==b.cameras.length&&(b.cameras.length=0,i=!0);for(let n=0;n<e.length;n++){const s=e[n];let r=null;if(null!==u)r=u.getViewport(s);else{const e=h.getViewSubImage(c,s);r=e.viewport,0===n&&(t.setRenderTargetTextures(_,e.colorTexture,c.ignoreDepthValues?void 0:e.depthStencilTexture),t.setRenderTarget(_))}const a=w[n];a.matrix.fromArray(s.transform.matrix),a.projectionMatrix.fromArray(s.projectionMatrix),a.viewport.set(r.x,r.y,r.width,r.height),0===n&&b.matrix.copy(a.matrix),!0===i&&b.cameras.push(a)}}const s=n.inputSources;for(let t=0;t<g.length;t++){const e=g[t],n=s[t];e.update(n,i,r)}L&&L(e,i),p=null})),this.setAnimationLoop=function(t){L=t},this.dispose=function(){}}}function ll(t){function e(e,i){e.opacity.value=i.opacity,i.color&&e.diffuse.value.copy(i.color),i.emissive&&e.emissive.value.copy(i.emissive).multiplyScalar(i.emissiveIntensity),i.map&&(e.map.value=i.map),i.alphaMap&&(e.alphaMap.value=i.alphaMap),i.specularMap&&(e.specularMap.value=i.specularMap),i.alphaTest>0&&(e.alphaTest.value=i.alphaTest);const n=t.get(i).envMap;let s,r;n&&(e.envMap.value=n,e.flipEnvMap.value=n.isCubeTexture&&!1===n.isRenderTargetTexture?-1:1,e.reflectivity.value=i.reflectivity,e.ior.value=i.ior,e.refractionRatio.value=i.refractionRatio),i.lightMap&&(e.lightMap.value=i.lightMap,e.lightMapIntensity.value=i.lightMapIntensity),i.aoMap&&(e.aoMap.value=i.aoMap,e.aoMapIntensity.value=i.aoMapIntensity),i.map?s=i.map:i.specularMap?s=i.specularMap:i.displacementMap?s=i.displacementMap:i.normalMap?s=i.normalMap:i.bumpMap?s=i.bumpMap:i.roughnessMap?s=i.roughnessMap:i.metalnessMap?s=i.metalnessMap:i.alphaMap?s=i.alphaMap:i.emissiveMap?s=i.emissiveMap:i.clearcoatMap?s=i.clearcoatMap:i.clearcoatNormalMap?s=i.clearcoatNormalMap:i.clearcoatRoughnessMap?s=i.clearcoatRoughnessMap:i.specularIntensityMap?s=i.specularIntensityMap:i.specularColorMap?s=i.specularColorMap:i.transmissionMap?s=i.transmissionMap:i.thicknessMap?s=i.thicknessMap:i.sheenColorMap?s=i.sheenColorMap:i.sheenRoughnessMap&&(s=i.sheenRoughnessMap),void 0!==s&&(s.isWebGLRenderTarget&&(s=s.texture),!0===s.matrixAutoUpdate&&s.updateMatrix(),e.uvTransform.value.copy(s.matrix)),i.aoMap?r=i.aoMap:i.lightMap&&(r=i.lightMap),void 0!==r&&(r.isWebGLRenderTarget&&(r=r.texture),!0===r.matrixAutoUpdate&&r.updateMatrix(),e.uv2Transform.value.copy(r.matrix))}function i(e,i){e.roughness.value=i.roughness,e.metalness.value=i.metalness,i.roughnessMap&&(e.roughnessMap.value=i.roughnessMap),i.metalnessMap&&(e.metalnessMap.value=i.metalnessMap),i.emissiveMap&&(e.emissiveMap.value=i.emissiveMap),i.bumpMap&&(e.bumpMap.value=i.bumpMap,e.bumpScale.value=i.bumpScale,i.side===Q&&(e.bumpScale.value*=-1)),i.normalMap&&(e.normalMap.value=i.normalMap,e.normalScale.value.copy(i.normalScale),i.side===Q&&e.normalScale.value.negate()),i.displacementMap&&(e.displacementMap.value=i.displacementMap,e.displacementScale.value=i.displacementScale,e.displacementBias.value=i.displacementBias),t.get(i).envMap&&(e.envMapIntensity.value=i.envMapIntensity)}return{refreshFogUniforms:function(t,e){t.fogColor.value.copy(e.color),e.isFog?(t.fogNear.value=e.near,t.fogFar.value=e.far):e.isFogExp2&&(t.fogDensity.value=e.density)},refreshMaterialUniforms:function(t,n,s,r,a){n.isMeshBasicMaterial?e(t,n):n.isMeshLambertMaterial?(e(t,n),function(t,e){e.emissiveMap&&(t.emissiveMap.value=e.emissiveMap)}(t,n)):n.isMeshToonMaterial?(e(t,n),function(t,e){e.gradientMap&&(t.gradientMap.value=e.gradientMap),e.emissiveMap&&(t.emissiveMap.value=e.emissiveMap),e.bumpMap&&(t.bumpMap.value=e.bumpMap,t.bumpScale.value=e.bumpScale,e.side===Q&&(t.bumpScale.value*=-1)),e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale),e.side===Q&&t.normalScale.value.negate()),e.displacementMap&&(t.displacementMap.value=e.displacementMap,t.displacementScale.value=e.displacementScale,t.displacementBias.value=e.displacementBias)}(t,n)):n.isMeshPhongMaterial?(e(t,n),function(t,e){t.specular.value.copy(e.specular),t.shininess.value=Math.max(e.shininess,1e-4),e.emissiveMap&&(t.emissiveMap.value=e.emissiveMap),e.bumpMap&&(t.bumpMap.value=e.bumpMap,t.bumpScale.value=e.bumpScale,e.side===Q&&(t.bumpScale.value*=-1)),e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale),e.side===Q&&t.normalScale.value.negate()),e.displacementMap&&(t.displacementMap.value=e.displacementMap,t.displacementScale.value=e.displacementScale,t.displacementBias.value=e.displacementBias)}(t,n)):n.isMeshStandardMaterial?(e(t,n),n.isMeshPhysicalMaterial?function(t,e,n){i(t,e),t.ior.value=e.ior,e.sheen>0&&(t.sheenColor.value.copy(e.sheenColor).multiplyScalar(e.sheen),t.sheenRoughness.value=e.sheenRoughness,e.sheenColorMap&&(t.sheenColorMap.value=e.sheenColorMap),e.sheenRoughnessMap&&(t.sheenRoughnessMap.value=e.sheenRoughnessMap)),e.clearcoat>0&&(t.clearcoat.value=e.clearcoat,t.clearcoatRoughness.value=e.clearcoatRoughness,e.clearcoatMap&&(t.clearcoatMap.value=e.clearcoatMap),e.clearcoatRoughnessMap&&(t.clearcoatRoughnessMap.value=e.clearcoatRoughnessMap),e.clearcoatNormalMap&&(t.clearcoatNormalScale.value.copy(e.clearcoatNormalScale),t.clearcoatNormalMap.value=e.clearcoatNormalMap,e.side===Q&&t.clearcoatNormalScale.value.negate())),e.transmission>0&&(t.transmission.value=e.transmission,t.transmissionSamplerMap.value=n.texture,t.transmissionSamplerSize.value.set(n.width,n.height),e.transmissionMap&&(t.transmissionMap.value=e.transmissionMap),t.thickness.value=e.thickness,e.thicknessMap&&(t.thicknessMap.value=e.thicknessMap),t.attenuationDistance.value=e.attenuationDistance,t.attenuationColor.value.copy(e.attenuationColor)),t.specularIntensity.value=e.specularIntensity,t.specularColor.value.copy(e.specularColor),e.specularIntensityMap&&(t.specularIntensityMap.value=e.specularIntensityMap),e.specularColorMap&&(t.specularColorMap.value=e.specularColorMap)}(t,n,a):i(t,n)):n.isMeshMatcapMaterial?(e(t,n),function(t,e){e.matcap&&(t.matcap.value=e.matcap),e.bumpMap&&(t.bumpMap.value=e.bumpMap,t.bumpScale.value=e.bumpScale,e.side===Q&&(t.bumpScale.value*=-1)),e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale),e.side===Q&&t.normalScale.value.negate()),e.displacementMap&&(t.displacementMap.value=e.displacementMap,t.displacementScale.value=e.displacementScale,t.displacementBias.value=e.displacementBias)}(t,n)):n.isMeshDepthMaterial?(e(t,n),function(t,e){e.displacementMap&&(t.displacementMap.value=e.displacementMap,t.displacementScale.value=e.displacementScale,t.displacementBias.value=e.displacementBias)}(t,n)):n.isMeshDistanceMaterial?(e(t,n),function(t,e){e.displacementMap&&(t.displacementMap.value=e.displacementMap,t.displacementScale.value=e.displacementScale,t.displacementBias.value=e.displacementBias),t.referencePosition.value.copy(e.referencePosition),t.nearDistance.value=e.nearDistance,t.farDistance.value=e.farDistance}(t,n)):n.isMeshNormalMaterial?(e(t,n),function(t,e){e.bumpMap&&(t.bumpMap.value=e.bumpMap,t.bumpScale.value=e.bumpScale,e.side===Q&&(t.bumpScale.value*=-1)),e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale),e.side===Q&&t.normalScale.value.negate()),e.displacementMap&&(t.displacementMap.value=e.displacementMap,t.displacementScale.value=e.displacementScale,t.displacementBias.value=e.displacementBias)}(t,n)):n.isLineBasicMaterial?(function(t,e){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity}(t,n),n.isLineDashedMaterial&&function(t,e){t.dashSize.value=e.dashSize,t.totalSize.value=e.dashSize+e.gapSize,t.scale.value=e.scale}(t,n)):n.isPointsMaterial?function(t,e,i,n){let s;t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.size.value=e.size*i,t.scale.value=.5*n,e.map&&(t.map.value=e.map),e.alphaMap&&(t.alphaMap.value=e.alphaMap),e.alphaTest>0&&(t.alphaTest.value=e.alphaTest),e.map?s=e.map:e.alphaMap&&(s=e.alphaMap),void 0!==s&&(!0===s.matrixAutoUpdate&&s.updateMatrix(),t.uvTransform.value.copy(s.matrix))}(t,n,s,r):n.isSpriteMaterial?function(t,e){let i;t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.rotation.value=e.rotation,e.map&&(t.map.value=e.map),e.alphaMap&&(t.alphaMap.value=e.alphaMap),e.alphaTest>0&&(t.alphaTest.value=e.alphaTest),e.map?i=e.map:e.alphaMap&&(i=e.alphaMap),void 0!==i&&(!0===i.matrixAutoUpdate&&i.updateMatrix(),t.uvTransform.value.copy(i.matrix))}(t,n):n.isShadowMaterial?(t.color.value.copy(n.color),t.opacity.value=n.opacity):n.isShaderMaterial&&(n.uniformsNeedUpdate=!1)}}}function hl(t={}){const e=void 0!==t.canvas?t.canvas:function(){const t=Ui("canvas");return t.style.display="block",t}(),i=void 0!==t.context?t.context:null,n=void 0!==t.alpha&&t.alpha,s=void 0===t.depth||t.depth,r=void 0===t.stencil||t.stencil,a=void 0!==t.antialias&&t.antialias,o=void 0===t.premultipliedAlpha||t.premultipliedAlpha,l=void 0!==t.preserveDrawingBuffer&&t.preserveDrawingBuffer,h=void 0!==t.powerPreference?t.powerPreference:"default",c=void 0!==t.failIfMajorPerformanceCaveat&&t.failIfMajorPerformanceCaveat;let u=null,d=null;const p=[],f=[];this.domElement=e,this.debug={checkShaderErrors:!0},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.outputEncoding=yi,this.physicallyCorrectLights=!1,this.toneMapping=Dt,this.toneMappingExposure=1;const m=this;let _=!1,g=0,y=0,v=null,x=-1,w=null;const b=new ji,S=new ji;let M=null,T=e.width,A=e.height,C=1,E=null,z=null;const I=new ji(0,0,T,A),L=new ji(0,0,T,A);let N=!1;const P=[],D=new _r;let F=!1,O=!1,R=null;const k=new Cn,B=new Yi,U={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};function V(){return null===v?C:1}let W,G,H,q,J,$,Y,X,Z,et,it,nt,st,rt,at,ot,lt,ht,ct,ut,dt,pt,ft,mt=i;function _t(t,i){for(let n=0;n<t.length;n++){const s=t[n],r=e.getContext(s,i);if(null!==r)return r}return null}try{const t={alpha:n,depth:s,stencil:r,antialias:a,premultipliedAlpha:o,preserveDrawingBuffer:l,powerPreference:h,failIfMajorPerformanceCaveat:c};if("setAttribute"in e&&e.setAttribute("data-engine",`three.js r${j}`),e.addEventListener("webglcontextlost",vt,!1),e.addEventListener("webglcontextrestored",xt,!1),null===mt){const e=["webgl2","webgl","experimental-webgl"];if(!0===m.isWebGL1Renderer&&e.shift(),mt=_t(e,t),null===mt)throw _t(e)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}void 0===mt.getShaderPrecisionFormat&&(mt.getShaderPrecisionFormat=function(){return{rangeMin:1,rangeMax:1,precision:1}})}catch(t){throw t}function gt(){W=new Zr(mt),G=new Ar(mt,W,t),W.init(G),pt=new el(mt,W,G),H=new Qo(mt,W,G),P[0]=1029,q=new ta,J=new Ro,$=new tl(mt,W,H,J,G,pt,q),Y=new Er(m),X=new Xr(m),Z=new yr(mt,G),ft=new Mr(mt,W,Z,G),et=new Kr(mt,Z,q,ft),it=new aa(mt,et,Z,q),ct=new ra(mt,G,$),ot=new Cr(J),nt=new Oo(m,Y,X,W,G,ft,ot),st=new ll(J),rt=new Vo,at=new Jo(W,G),ht=new Sr(m,Y,H,it,o),lt=new Ko(m,it,G),ut=new Tr(mt,W,q,G),dt=new Qr(mt,W,q,G),q.programs=nt.programs,m.capabilities=G,m.extensions=W,m.properties=J,m.renderLists=rt,m.shadowMap=lt,m.state=H,m.info=q}gt();const yt=new ol(m,mt);function vt(t){t.preventDefault(),_=!0}function xt(){_=!1;const t=q.autoReset,e=lt.enabled,i=lt.autoUpdate,n=lt.needsUpdate,s=lt.type;gt(),q.autoReset=t,lt.enabled=e,lt.autoUpdate=i,lt.needsUpdate=n,lt.type=s}function wt(t){const e=t.target;e.removeEventListener("dispose",wt),function(t){(function(t){const e=J.get(t).programs;void 0!==e&&(e.forEach((function(t){nt.releaseProgram(t)})),t.isShaderMaterial&&nt.releaseShaderCache(t))})(t),J.remove(t)}(e)}this.xr=yt,this.getContext=function(){return mt},this.getContextAttributes=function(){return mt.getContextAttributes()},this.forceContextLoss=function(){const t=W.get("WEBGL_lose_context");t&&t.loseContext()},this.forceContextRestore=function(){const t=W.get("WEBGL_lose_context");t&&t.restoreContext()},this.getPixelRatio=function(){return C},this.setPixelRatio=function(t){void 0!==t&&(C=t,this.setSize(T,A,!1))},this.getSize=function(t){return t.set(T,A)},this.setSize=function(t,i,n){yt.isPresenting||(T=t,A=i,e.width=Math.floor(t*C),e.height=Math.floor(i*C),!1!==n&&(e.style.width=t+"px",e.style.height=i+"px"),this.setViewport(0,0,t,i))},this.getDrawingBufferSize=function(t){return t.set(T*C,A*C).floor()},this.setDrawingBufferSize=function(t,i,n){T=t,A=i,C=n,e.width=Math.floor(t*n),e.height=Math.floor(i*n),this.setViewport(0,0,t,i)},this.getCurrentViewport=function(t){return t.copy(b)},this.getViewport=function(t){return t.copy(I)},this.setViewport=function(t,e,i,n){t.isVector4?I.set(t.x,t.y,t.z,t.w):I.set(t,e,i,n),H.viewport(b.copy(I).multiplyScalar(C).floor())},this.getScissor=function(t){return t.copy(L)},this.setScissor=function(t,e,i,n){t.isVector4?L.set(t.x,t.y,t.z,t.w):L.set(t,e,i,n),H.scissor(S.copy(L).multiplyScalar(C).floor())},this.getScissorTest=function(){return N},this.setScissorTest=function(t){H.setScissorTest(N=t)},this.setOpaqueSort=function(t){E=t},this.setTransparentSort=function(t){z=t},this.getClearColor=function(t){return t.copy(ht.getClearColor())},this.setClearColor=function(){ht.setClearColor.apply(ht,arguments)},this.getClearAlpha=function(){return ht.getClearAlpha()},this.setClearAlpha=function(){ht.setClearAlpha.apply(ht,arguments)},this.clear=function(t,e,i){let n=0;(void 0===t||t)&&(n|=16384),(void 0===e||e)&&(n|=256),(void 0===i||i)&&(n|=1024),mt.clear(n)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.dispose=function(){e.removeEventListener("webglcontextlost",vt,!1),e.removeEventListener("webglcontextrestored",xt,!1),rt.dispose(),at.dispose(),J.dispose(),Y.dispose(),X.dispose(),it.dispose(),ft.dispose(),nt.dispose(),yt.dispose(),yt.removeEventListener("sessionstart",St),yt.removeEventListener("sessionend",Mt),R&&(R.dispose(),R=null),Tt.stop()},this.renderBufferDirect=function(t,e,i,n,s,r){null===e&&(e=U);const a=s.isMesh&&s.matrixWorld.determinant()<0,o=function(t,e,i,n,s){!0!==e.isScene&&(e=U),$.resetTextureUnits();const r=e.fog,a=n.isMeshStandardMaterial?e.environment:null,o=null===v?m.outputEncoding:v.texture.encoding,l=(n.isMeshStandardMaterial?X:Y).get(n.envMap||a),h=!0===n.vertexColors&&!!i.attributes.color&&4===i.attributes.color.itemSize,c=!!n.normalMap&&!!i.attributes.tangent,u=!!i.morphAttributes.position,p=!!i.morphAttributes.normal,f=i.morphAttributes.position?i.morphAttributes.position.length:0,_=n.toneMapped?m.toneMapping:Dt,g=J.get(n),y=d.state.lights;if(!0===F&&(!0===O||t!==w)){const e=t===w&&n.id===x;ot.setState(n,t,e)}let b=!1;n.version===g.__version?g.needsLights&&g.lightsStateVersion!==y.state.version||g.outputEncoding!==o||s.isInstancedMesh&&!1===g.instancing?b=!0:s.isInstancedMesh||!0!==g.instancing?s.isSkinnedMesh&&!1===g.skinning?b=!0:s.isSkinnedMesh||!0!==g.skinning?g.envMap!==l||n.fog&&g.fog!==r?b=!0:void 0===g.numClippingPlanes||g.numClippingPlanes===ot.numPlanes&&g.numIntersection===ot.numIntersection?(g.vertexAlphas!==h||g.vertexTangents!==c||g.morphTargets!==u||g.morphNormals!==p||g.toneMapping!==_||!0===G.isWebGL2&&g.morphTargetsCount!==f)&&(b=!0):b=!0:b=!0:b=!0:(b=!0,g.__version=n.version);let S=g.currentProgram;!0===b&&(S=It(n,e,s));let M=!1,T=!1,E=!1;const z=S.getUniforms(),I=g.uniforms;if(H.useProgram(S.program)&&(M=!0,T=!0,E=!0),n.id!==x&&(x=n.id,T=!0),M||w!==t){if(z.setValue(mt,"projectionMatrix",t.projectionMatrix),G.logarithmicDepthBuffer&&z.setValue(mt,"logDepthBufFC",2/(Math.log(t.far+1)/Math.LN2)),w!==t&&(w=t,T=!0,E=!0),n.isShaderMaterial||n.isMeshPhongMaterial||n.isMeshToonMaterial||n.isMeshStandardMaterial||n.envMap){const e=z.map.cameraPosition;void 0!==e&&e.setValue(mt,B.setFromMatrixPosition(t.matrixWorld))}(n.isMeshPhongMaterial||n.isMeshToonMaterial||n.isMeshLambertMaterial||n.isMeshBasicMaterial||n.isMeshStandardMaterial||n.isShaderMaterial)&&z.setValue(mt,"isOrthographic",!0===t.isOrthographicCamera),(n.isMeshPhongMaterial||n.isMeshToonMaterial||n.isMeshLambertMaterial||n.isMeshBasicMaterial||n.isMeshStandardMaterial||n.isShaderMaterial||n.isShadowMaterial||s.isSkinnedMesh)&&z.setValue(mt,"viewMatrix",t.matrixWorldInverse)}if(s.isSkinnedMesh){z.setOptional(mt,s,"bindMatrix"),z.setOptional(mt,s,"bindMatrixInverse");const t=s.skeleton;t&&(G.floatVertexTextures?(null===t.boneTexture&&t.computeBoneTexture(),z.setValue(mt,"boneTexture",t.boneTexture,$),z.setValue(mt,"boneTextureSize",t.boneTextureSize)):z.setOptional(mt,t,"boneMatrices"))}return!i||void 0===i.morphAttributes.position&&void 0===i.morphAttributes.normal||ct.update(s,i,n,S),(T||g.receiveShadow!==s.receiveShadow)&&(g.receiveShadow=s.receiveShadow,z.setValue(mt,"receiveShadow",s.receiveShadow)),T&&(z.setValue(mt,"toneMappingExposure",m.toneMappingExposure),g.needsLights&&function(t,e){t.ambientLightColor.needsUpdate=e,t.lightProbe.needsUpdate=e,t.directionalLights.needsUpdate=e,t.directionalLightShadows.needsUpdate=e,t.pointLights.needsUpdate=e,t.pointLightShadows.needsUpdate=e,t.spotLights.needsUpdate=e,t.spotLightShadows.needsUpdate=e,t.rectAreaLights.needsUpdate=e,t.hemisphereLights.needsUpdate=e}(I,E),r&&n.fog&&st.refreshFogUniforms(I,r),st.refreshMaterialUniforms(I,n,C,A,R),uo.upload(mt,g.uniformsList,I,$)),n.isShaderMaterial&&!0===n.uniformsNeedUpdate&&(uo.upload(mt,g.uniformsList,I,$),n.uniformsNeedUpdate=!1),n.isSpriteMaterial&&z.setValue(mt,"center",s.center),z.setValue(mt,"modelViewMatrix",s.modelViewMatrix),z.setValue(mt,"normalMatrix",s.normalMatrix),z.setValue(mt,"modelMatrix",s.matrixWorld),S}(t,e,i,n,s);H.setMaterial(n,a);let l=i.index;const h=i.attributes.position;if(null===l){if(void 0===h||0===h.count)return}else if(0===l.count)return;let c,u=1;!0===n.wireframe&&(l=et.getWireframeAttribute(i),u=2),ft.setup(s,n,o,i,l);let p=ut;null!==l&&(c=Z.get(l),p=dt,p.setIndex(c));const f=null!==l?l.count:h.count,_=i.drawRange.start*u,g=i.drawRange.count*u,y=null!==r?r.start*u:0,b=null!==r?r.count*u:Infinity,S=Math.max(_,y),M=Math.min(f,_+g,y+b)-1,T=Math.max(0,M-S+1);if(0!==T){if(s.isMesh)!0===n.wireframe?(H.setLineWidth(n.wireframeLinewidth*V()),p.setMode(1)):p.setMode(4);else if(s.isLine){let t=n.linewidth;void 0===t&&(t=1),H.setLineWidth(t*V()),s.isLineSegments?p.setMode(1):s.isLineLoop?p.setMode(2):p.setMode(3)}else s.isPoints?p.setMode(0):s.isSprite&&p.setMode(4);if(s.isInstancedMesh)p.renderInstances(S,T,s.count);else if(i.isInstancedBufferGeometry){const t=Math.min(i.instanceCount,i._maxInstanceCount);p.renderInstances(S,T,t)}else p.render(S,T)}},this.compile=function(t,e){d=at.get(t),d.init(),f.push(d),t.traverseVisible((function(t){t.isLight&&t.layers.test(e.layers)&&(d.pushLight(t),t.castShadow&&d.pushShadow(t))})),d.setupLights(m.physicallyCorrectLights),t.traverse((function(e){const i=e.material;if(i)if(Array.isArray(i))for(let n=0;n<i.length;n++)It(i[n],t,e);else It(i,t,e)})),f.pop(),d=null};let bt=null;function St(){Tt.stop()}function Mt(){Tt.start()}const Tt=new gr;function At(t,e,i,n){if(!1===t.visible)return;if(t.layers.test(e.layers))if(t.isGroup)i=t.renderOrder;else if(t.isLOD)!0===t.autoUpdate&&t.update(e);else if(t.isLight)d.pushLight(t),t.castShadow&&d.pushShadow(t);else if(t.isSprite){if(!t.frustumCulled||D.intersectsSprite(t)){n&&B.setFromMatrixPosition(t.matrixWorld).applyMatrix4(k);const e=it.update(t),s=t.material;s.visible&&u.push(t,e,s,i,B.z,null)}}else if((t.isMesh||t.isLine||t.isPoints)&&(t.isSkinnedMesh&&t.skeleton.frame!==q.render.frame&&(t.skeleton.update(),t.skeleton.frame=q.render.frame),!t.frustumCulled||D.intersectsObject(t))){n&&B.setFromMatrixPosition(t.matrixWorld).applyMatrix4(k);const e=it.update(t),s=t.material;if(Array.isArray(s)){const n=e.groups;for(let r=0,a=n.length;r<a;r++){const a=n[r],o=s[a.materialIndex];o&&o.visible&&u.push(t,e,o,i,B.z,a)}}else s.visible&&u.push(t,e,s,i,B.z,null)}const s=t.children;for(let t=0,r=s.length;t<r;t++)At(s[t],e,i,n)}function Ct(t,e,i,n){const s=t.opaque,r=t.transmissive,o=t.transparent;d.setupLightsView(i),r.length>0&&function(t,e,i){if(null===R){const t=!0===a&&!0===G.isWebGL2;R=new(t?Ji:qi)(1024,1024,{generateMipmaps:!0,type:null!==pt.convert(le)?le:ee,minFilter:te,magFilter:Yt,wrapS:Jt,wrapT:Jt,useRenderToTexture:W.has("WEBGL_multisampled_render_to_texture")})}const n=m.getRenderTarget();m.setRenderTarget(R),m.clear();const s=m.toneMapping;m.toneMapping=Dt,Et(t,e,i),m.toneMapping=s,$.updateMultisampleRenderTarget(R),$.updateRenderTargetMipmap(R),m.setRenderTarget(n)}(s,e,i),n&&H.viewport(b.copy(n)),s.length>0&&Et(s,e,i),r.length>0&&Et(r,e,i),o.length>0&&Et(o,e,i)}function Et(t,e,i){const n=!0===e.isScene?e.overrideMaterial:null;for(let s=0,r=t.length;s<r;s++){const r=t[s],a=r.object,o=r.geometry,l=null===n?r.material:n,h=r.group;a.layers.test(i.layers)&&zt(a,e,i,o,l,h)}}function zt(t,e,i,n,s,r){t.onBeforeRender(m,e,i,n,s,r),t.modelViewMatrix.multiplyMatrices(i.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix),s.onBeforeRender(m,e,i,n,t,r),!0===s.transparent&&s.side===tt?(s.side=Q,s.needsUpdate=!0,m.renderBufferDirect(i,e,n,s,t,r),s.side=K,s.needsUpdate=!0,m.renderBufferDirect(i,e,n,s,t,r),s.side=tt):m.renderBufferDirect(i,e,n,s,t,r),t.onAfterRender(m,e,i,n,s,r)}function It(t,e,i){!0!==e.isScene&&(e=U);const n=J.get(t),s=d.state.lights,r=d.state.shadowsArray,a=s.state.version,o=nt.getParameters(t,s.state,r,e,i),l=nt.getProgramCacheKey(o);let h=n.programs;n.environment=t.isMeshStandardMaterial?e.environment:null,n.fog=e.fog,n.envMap=(t.isMeshStandardMaterial?X:Y).get(t.envMap||n.environment),void 0===h&&(t.addEventListener("dispose",wt),h=new Map,n.programs=h);let c=h.get(l);if(void 0!==c){if(n.currentProgram===c&&n.lightsStateVersion===a)return Lt(t,o),c}else o.uniforms=nt.getUniforms(t),t.onBuild(i,o,m),t.onBeforeCompile(o,m),c=nt.acquireProgram(o,l),h.set(l,c),n.uniforms=o.uniforms;const u=n.uniforms;(t.isShaderMaterial||t.isRawShaderMaterial)&&!0!==t.clipping||(u.clippingPlanes=ot.uniform),Lt(t,o),n.needsLights=function(t){return t.isMeshLambertMaterial||t.isMeshToonMaterial||t.isMeshPhongMaterial||t.isMeshStandardMaterial||t.isShadowMaterial||t.isShaderMaterial&&!0===t.lights}(t),n.lightsStateVersion=a,n.needsLights&&(u.ambientLightColor.value=s.state.ambient,u.lightProbe.value=s.state.probe,u.directionalLights.value=s.state.directional,u.directionalLightShadows.value=s.state.directionalShadow,u.spotLights.value=s.state.spot,u.spotLightShadows.value=s.state.spotShadow,u.rectAreaLights.value=s.state.rectArea,u.ltc_1.value=s.state.rectAreaLTC1,u.ltc_2.value=s.state.rectAreaLTC2,u.pointLights.value=s.state.point,u.pointLightShadows.value=s.state.pointShadow,u.hemisphereLights.value=s.state.hemi,u.directionalShadowMap.value=s.state.directionalShadowMap,u.directionalShadowMatrix.value=s.state.directionalShadowMatrix,u.spotShadowMap.value=s.state.spotShadowMap,u.spotShadowMatrix.value=s.state.spotShadowMatrix,u.pointShadowMap.value=s.state.pointShadowMap,u.pointShadowMatrix.value=s.state.pointShadowMatrix);const p=c.getUniforms(),f=uo.seqWithValue(p.seq,u);return n.currentProgram=c,n.uniformsList=f,c}function Lt(t,e){const i=J.get(t);i.outputEncoding=e.outputEncoding,i.instancing=e.instancing,i.skinning=e.skinning,i.morphTargets=e.morphTargets,i.morphNormals=e.morphNormals,i.morphTargetsCount=e.morphTargetsCount,i.numClippingPlanes=e.numClippingPlanes,i.numIntersection=e.numClipIntersection,i.vertexAlphas=e.vertexAlphas,i.vertexTangents=e.vertexTangents,i.toneMapping=e.toneMapping}Tt.setAnimationLoop((function(t){bt&&bt(t)})),"undefined"!=typeof window&&Tt.setContext(window),this.setAnimationLoop=function(t){bt=t,yt.setAnimationLoop(t),null===t?Tt.stop():Tt.start()},yt.addEventListener("sessionstart",St),yt.addEventListener("sessionend",Mt),this.render=function(t,e){if(void 0!==e&&!0!==e.isCamera)return;if(!0===_)return;!0===t.autoUpdate&&t.updateMatrixWorld(),null===e.parent&&e.updateMatrixWorld(),!0===yt.enabled&&!0===yt.isPresenting&&(!0===yt.cameraAutoUpdate&&yt.updateCamera(e),e=yt.getCamera()),!0===t.isScene&&t.onBeforeRender(m,t,e,v),d=at.get(t,f.length),d.init(),f.push(d),k.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),D.setFromProjectionMatrix(k),O=this.localClippingEnabled,F=ot.init(this.clippingPlanes,O,e),u=rt.get(t,p.length),u.init(),p.push(u),At(t,e,0,m.sortObjects),u.finish(),!0===m.sortObjects&&u.sort(E,z),!0===F&&ot.beginShadows();const i=d.state.shadowsArray;if(lt.render(i,t,e),!0===F&&ot.endShadows(),!0===this.info.autoReset&&this.info.reset(),ht.render(u,t),d.setupLights(m.physicallyCorrectLights),e.isArrayCamera){const i=e.cameras;for(let e=0,n=i.length;e<n;e++){const n=i[e];Ct(u,t,n,n.viewport)}}else Ct(u,t,e);null!==v&&($.updateMultisampleRenderTarget(v),$.updateRenderTargetMipmap(v)),!0===t.isScene&&t.onAfterRender(m,t,e),H.buffers.depth.setTest(!0),H.buffers.depth.setMask(!0),H.buffers.color.setMask(!0),H.setPolygonOffset(!1),ft.resetDefaultState(),x=-1,w=null,f.pop(),d=f.length>0?f[f.length-1]:null,p.pop(),u=p.length>0?p[p.length-1]:null},this.getActiveCubeFace=function(){return g},this.getActiveMipmapLevel=function(){return y},this.getRenderTarget=function(){return v},this.setRenderTargetTextures=function(t,e,i){J.get(t.texture).__webglTexture=e,J.get(t.depthTexture).__webglTexture=i;const n=J.get(t);n.__hasExternalTextures=!0,n.__hasExternalTextures&&(n.__autoAllocateDepthBuffer=void 0===i,n.__autoAllocateDepthBuffer||t.useRenderToTexture&&(t.useRenderToTexture=!1,t.useRenderbuffer=!0))},this.setRenderTargetFramebuffer=function(t,e){const i=J.get(t);i.__webglFramebuffer=e,i.__useDefaultFramebuffer=void 0===e},this.setRenderTarget=function(t,e=0,i=0){v=t,g=e,y=i;let n=!0;if(t){const e=J.get(t);void 0!==e.__useDefaultFramebuffer?(H.bindFramebuffer(36160,null),n=!1):void 0===e.__webglFramebuffer?$.setupRenderTarget(t):e.__hasExternalTextures&&$.rebindTextures(t,J.get(t.texture).__webglTexture,J.get(t.depthTexture).__webglTexture)}let s=null,r=!1,a=!1;if(t){const i=t.texture;(i.isDataTexture3D||i.isDataTexture2DArray)&&(a=!0);const n=J.get(t).__webglFramebuffer;t.isWebGLCubeRenderTarget?(s=n[e],r=!0):s=t.useRenderbuffer?J.get(t).__webglMultisampledFramebuffer:n,b.copy(t.viewport),S.copy(t.scissor),M=t.scissorTest}else b.copy(I).multiplyScalar(C).floor(),S.copy(L).multiplyScalar(C).floor(),M=N;if(H.bindFramebuffer(36160,s)&&G.drawBuffers&&n){let e=!1;if(t)if(t.isWebGLMultipleRenderTargets){const i=t.texture;if(P.length!==i.length||36064!==P[0]){for(let t=0,e=i.length;t<e;t++)P[t]=36064+t;P.length=i.length,e=!0}}else 1===P.length&&36064===P[0]||(P[0]=36064,P.length=1,e=!0);else 1===P.length&&1029===P[0]||(P[0]=1029,P.length=1,e=!0);e&&(G.isWebGL2?mt.drawBuffers(P):W.get("WEBGL_draw_buffers").drawBuffersWEBGL(P))}if(H.viewport(b),H.scissor(S),H.setScissorTest(M),r){const n=J.get(t.texture);mt.framebufferTexture2D(36160,36064,34069+e,n.__webglTexture,i)}else if(a){const n=J.get(t.texture),s=e||0;mt.framebufferTextureLayer(36160,36064,n.__webglTexture,i||0,s)}x=-1},this.readRenderTargetPixels=function(t,e,i,n,s,r,a){if(!t||!t.isWebGLRenderTarget)return;let o=J.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&void 0!==a&&(o=o[a]),o){H.bindFramebuffer(36160,o);try{const a=t.texture,o=a.format,l=a.type;if(o!==me&&pt.convert(o)!==mt.getParameter(35739))return;const h=l===le&&(W.has("EXT_color_buffer_half_float")||G.isWebGL2&&W.has("EXT_color_buffer_float"));if(!(l===ee||pt.convert(l)===mt.getParameter(35738)||l===oe&&(G.isWebGL2||W.has("OES_texture_float")||W.has("WEBGL_color_buffer_float"))||h))return;36053===mt.checkFramebufferStatus(36160)&&e>=0&&e<=t.width-n&&i>=0&&i<=t.height-s&&mt.readPixels(e,i,n,s,pt.convert(o),pt.convert(l),r)}finally{const t=null!==v?J.get(v).__webglFramebuffer:null;H.bindFramebuffer(36160,t)}}},this.copyFramebufferToTexture=function(t,e,i=0){if(!0!==e.isFramebufferTexture)return;const n=Math.pow(2,-i),s=Math.floor(e.image.width*n),r=Math.floor(e.image.height*n);$.setTexture2D(e,0),mt.copyTexSubImage2D(3553,i,0,0,t.x,t.y,s,r),H.unbindTexture()},this.copyTextureToTexture=function(t,e,i,n=0){const s=e.image.width,r=e.image.height,a=pt.convert(i.format),o=pt.convert(i.type);$.setTexture2D(i,0),mt.pixelStorei(37440,i.flipY),mt.pixelStorei(37441,i.premultiplyAlpha),mt.pixelStorei(3317,i.unpackAlignment),e.isDataTexture?mt.texSubImage2D(3553,n,t.x,t.y,s,r,a,o,e.image.data):e.isCompressedTexture?mt.compressedTexSubImage2D(3553,n,t.x,t.y,e.mipmaps[0].width,e.mipmaps[0].height,a,e.mipmaps[0].data):mt.texSubImage2D(3553,n,t.x,t.y,a,o,e.image),0===n&&i.generateMipmaps&&mt.generateMipmap(3553),H.unbindTexture()},this.copyTextureToTexture3D=function(t,e,i,n,s=0){if(m.isWebGL1Renderer)return;const r=t.max.x-t.min.x+1,a=t.max.y-t.min.y+1,o=t.max.z-t.min.z+1,l=pt.convert(n.format),h=pt.convert(n.type);let c;if(n.isDataTexture3D)$.setTexture3D(n,0),c=32879;else{if(!n.isDataTexture2DArray)return;$.setTexture2DArray(n,0),c=35866}mt.pixelStorei(37440,n.flipY),mt.pixelStorei(37441,n.premultiplyAlpha),mt.pixelStorei(3317,n.unpackAlignment);const u=mt.getParameter(3314),d=mt.getParameter(32878),p=mt.getParameter(3316),f=mt.getParameter(3315),_=mt.getParameter(32877),g=i.isCompressedTexture?i.mipmaps[0]:i.image;mt.pixelStorei(3314,g.width),mt.pixelStorei(32878,g.height),mt.pixelStorei(3316,t.min.x),mt.pixelStorei(3315,t.min.y),mt.pixelStorei(32877,t.min.z),i.isDataTexture||i.isDataTexture3D?mt.texSubImage3D(c,s,e.x,e.y,e.z,r,a,o,l,h,g.data):i.isCompressedTexture?mt.compressedTexSubImage3D(c,s,e.x,e.y,e.z,r,a,o,l,g.data):mt.texSubImage3D(c,s,e.x,e.y,e.z,r,a,o,l,h,g),mt.pixelStorei(3314,u),mt.pixelStorei(32878,d),mt.pixelStorei(3316,p),mt.pixelStorei(3315,f),mt.pixelStorei(32877,_),0===s&&n.generateMipmaps&&mt.generateMipmap(c),H.unbindTexture()},this.initTexture=function(t){$.setTexture2D(t,0),H.unbindTexture()},this.resetState=function(){g=0,y=0,v=null,H.reset(),ft.reset()},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}hl.prototype.isWebGLRenderer=!0,class extends hl{}.prototype.isWebGL1Renderer=!0;let cl=class extends Kn{constructor(){super(),this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.overrideMaterial=null,this.autoUpdate=!0,"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),null!==t.background&&(this.background=t.background.clone()),null!==t.environment&&(this.environment=t.environment.clone()),null!==t.fog&&(this.fog=t.fog.clone()),null!==t.overrideMaterial&&(this.overrideMaterial=t.overrideMaterial.clone()),this.autoUpdate=t.autoUpdate,this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return null!==this.fog&&(e.object.fog=this.fog.toJSON()),e}};cl.prototype.isScene=!0;class ul{constructor(t,e){this.array=t,this.stride=e,this.count=void 0!==t?t.length/e:0,this.usage=Mi,this.updateRange={offset:0,count:-1},this.version=0,this.uuid=Li()}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,i){t*=this.stride,i*=e.stride;for(let n=0,s=this.stride;n<s;n++)this.array[t+n]=e.array[i+n];return this}set(t,e=0){return this.array.set(t,e),this}clone(t){void 0===t.arrayBuffers&&(t.arrayBuffers={}),void 0===this.array.buffer._uuid&&(this.array.buffer._uuid=Li()),void 0===t.arrayBuffers[this.array.buffer._uuid]&&(t.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const e=new this.array.constructor(t.arrayBuffers[this.array.buffer._uuid]),i=new this.constructor(e,this.stride);return i.setUsage(this.usage),i}onUpload(t){return this.onUploadCallback=t,this}toJSON(t){return void 0===t.arrayBuffers&&(t.arrayBuffers={}),void 0===this.array.buffer._uuid&&(this.array.buffer._uuid=Li()),void 0===t.arrayBuffers[this.array.buffer._uuid]&&(t.arrayBuffers[this.array.buffer._uuid]=Array.prototype.slice.call(new Uint32Array(this.array.buffer))),{uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride}}}ul.prototype.isInterleavedBuffer=!0;const dl=new Yi;class pl{constructor(t,e,i,n=!1){this.name="",this.data=t,this.itemSize=e,this.offset=i,this.normalized=!0===n}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(t){this.data.needsUpdate=t}applyMatrix4(t){for(let e=0,i=this.data.count;e<i;e++)dl.x=this.getX(e),dl.y=this.getY(e),dl.z=this.getZ(e),dl.applyMatrix4(t),this.setXYZ(e,dl.x,dl.y,dl.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)dl.x=this.getX(e),dl.y=this.getY(e),dl.z=this.getZ(e),dl.applyNormalMatrix(t),this.setXYZ(e,dl.x,dl.y,dl.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)dl.x=this.getX(e),dl.y=this.getY(e),dl.z=this.getZ(e),dl.transformDirection(t),this.setXYZ(e,dl.x,dl.y,dl.z);return this}setX(t,e){return this.data.array[t*this.data.stride+this.offset]=e,this}setY(t,e){return this.data.array[t*this.data.stride+this.offset+1]=e,this}setZ(t,e){return this.data.array[t*this.data.stride+this.offset+2]=e,this}setW(t,e){return this.data.array[t*this.data.stride+this.offset+3]=e,this}getX(t){return this.data.array[t*this.data.stride+this.offset]}getY(t){return this.data.array[t*this.data.stride+this.offset+1]}getZ(t){return this.data.array[t*this.data.stride+this.offset+2]}getW(t){return this.data.array[t*this.data.stride+this.offset+3]}setXY(t,e,i){return t=t*this.data.stride+this.offset,this.data.array[t+0]=e,this.data.array[t+1]=i,this}setXYZ(t,e,i,n){return t=t*this.data.stride+this.offset,this.data.array[t+0]=e,this.data.array[t+1]=i,this.data.array[t+2]=n,this}setXYZW(t,e,i,n,s){return t=t*this.data.stride+this.offset,this.data.array[t+0]=e,this.data.array[t+1]=i,this.data.array[t+2]=n,this.data.array[t+3]=s,this}clone(t){if(void 0===t){const t=[];for(let e=0;e<this.count;e++){const i=e*this.data.stride+this.offset;for(let e=0;e<this.itemSize;e++)t.push(this.data.array[i+e])}return new bs(new this.array.constructor(t),this.itemSize,this.normalized)}return void 0===t.interleavedBuffers&&(t.interleavedBuffers={}),void 0===t.interleavedBuffers[this.data.uuid]&&(t.interleavedBuffers[this.data.uuid]=this.data.clone(t)),new pl(t.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(t){if(void 0===t){const t=[];for(let e=0;e<this.count;e++){const i=e*this.data.stride+this.offset;for(let e=0;e<this.itemSize;e++)t.push(this.data.array[i+e])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:t,normalized:this.normalized}}return void 0===t.interleavedBuffers&&(t.interleavedBuffers={}),void 0===t.interleavedBuffers[this.data.uuid]&&(t.interleavedBuffers[this.data.uuid]=this.data.toJSON(t)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}pl.prototype.isInterleavedBufferAttribute=!0;class fl extends us{constructor(t){super(),this.type="SpriteMaterial",this.color=new ys(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.rotation=t.rotation,this.sizeAttenuation=t.sizeAttenuation,this}}let ml;fl.prototype.isSpriteMaterial=!0;const _l=new Yi,gl=new Yi,yl=new Yi,vl=new Ri,xl=new Ri,wl=new Cn,bl=new Yi,Sl=new Yi,Ml=new Yi,Tl=new Ri,Al=new Ri,Cl=new Ri;function El(t,e,i,n,s,r){vl.subVectors(t,i).addScalar(.5).multiply(n),void 0!==s?(xl.x=r*vl.x-s*vl.y,xl.y=s*vl.x+r*vl.y):xl.copy(vl),t.copy(e),t.x+=xl.x,t.y+=xl.y,t.applyMatrix4(wl)}(class extends Kn{constructor(t){if(super(),this.type="Sprite",void 0===ml){ml=new Ps;const t=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),e=new ul(t,5);ml.setIndex([0,1,2,0,2,3]),ml.setAttribute("position",new pl(e,3,0,!1)),ml.setAttribute("uv",new pl(e,2,3,!1))}this.geometry=ml,this.material=void 0!==t?t:new fl,this.center=new Ri(.5,.5)}raycast(t,e){t.camera,gl.setFromMatrixScale(this.matrixWorld),wl.copy(t.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(t.camera.matrixWorldInverse,this.matrixWorld),yl.setFromMatrixPosition(this.modelViewMatrix),t.camera.isPerspectiveCamera&&!1===this.material.sizeAttenuation&&gl.multiplyScalar(-yl.z);const i=this.material.rotation;let n,s;0!==i&&(s=Math.cos(i),n=Math.sin(i));const r=this.center;El(bl.set(-.5,-.5,0),yl,r,gl,n,s),El(Sl.set(.5,-.5,0),yl,r,gl,n,s),El(Ml.set(.5,.5,0),yl,r,gl,n,s),Tl.set(0,0),Al.set(1,0),Cl.set(1,1);let a=t.ray.intersectTriangle(bl,Sl,Ml,!1,_l);if(null===a&&(El(Sl.set(-.5,.5,0),yl,r,gl,n,s),Al.set(0,1),a=t.ray.intersectTriangle(bl,Ml,Sl,!1,_l),null===a))return;const o=t.ray.origin.distanceTo(_l);o<t.near||o>t.far||e.push({distance:o,point:_l.clone(),uv:hs.getUV(_l,bl,Sl,Ml,Tl,Al,Cl,new Ri),face:null,object:this})}copy(t){return super.copy(t),void 0!==t.center&&this.center.copy(t.center),this.material=t.material,this}}).prototype.isSprite=!0;const zl=new Yi,Il=new ji,Ll=new ji,Nl=new Yi,Pl=new Cn;class Dl extends Zs{constructor(t,e){super(t,e),this.type="SkinnedMesh",this.bindMode="attached",this.bindMatrix=new Cn,this.bindMatrixInverse=new Cn}copy(t){return super.copy(t),this.bindMode=t.bindMode,this.bindMatrix.copy(t.bindMatrix),this.bindMatrixInverse.copy(t.bindMatrixInverse),this.skeleton=t.skeleton,this}bind(t,e){this.skeleton=t,void 0===e&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),e=this.matrixWorld),this.bindMatrix.copy(e),this.bindMatrixInverse.copy(e).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(){const t=new ji,e=this.geometry.attributes.skinWeight;for(let i=0,n=e.count;i<n;i++){t.x=e.getX(i),t.y=e.getY(i),t.z=e.getZ(i),t.w=e.getW(i);const n=1/t.manhattanLength();Infinity!==n?t.multiplyScalar(n):t.set(1,0,0,0),e.setXYZW(i,t.x,t.y,t.z,t.w)}}updateMatrixWorld(t){super.updateMatrixWorld(t),"attached"===this.bindMode?this.bindMatrixInverse.copy(this.matrixWorld).invert():"detached"===this.bindMode&&this.bindMatrixInverse.copy(this.bindMatrix).invert()}boneTransform(t,e){const i=this.skeleton,n=this.geometry;Il.fromBufferAttribute(n.attributes.skinIndex,t),Ll.fromBufferAttribute(n.attributes.skinWeight,t),zl.copy(e).applyMatrix4(this.bindMatrix),e.set(0,0,0);for(let t=0;t<4;t++){const n=Ll.getComponent(t);if(0!==n){const s=Il.getComponent(t);Pl.multiplyMatrices(i.bones[s].matrixWorld,i.boneInverses[s]),e.addScaledVector(Nl.copy(zl).applyMatrix4(Pl),n)}}return e.applyMatrix4(this.bindMatrixInverse)}}Dl.prototype.isSkinnedMesh=!0,class extends Kn{constructor(){super(),this.type="Bone"}}.prototype.isBone=!0;class Fl extends Gi{constructor(t=null,e=1,i=1,n,s,r,a,o,l=Yt,h=Yt,c,u){super(null,r,a,o,l,h,n,s,c,u),this.image={data:t,width:e,height:i},this.magFilter=l,this.minFilter=h,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}Fl.prototype.isDataTexture=!0;class Ol extends bs{constructor(t,e,i,n=1){"number"==typeof i&&(n=i,i=!1),super(t,e,i),this.meshPerAttribute=n}copy(t){return super.copy(t),this.meshPerAttribute=t.meshPerAttribute,this}toJSON(){const t=super.toJSON();return t.meshPerAttribute=this.meshPerAttribute,t.isInstancedBufferAttribute=!0,t}}Ol.prototype.isInstancedBufferAttribute=!0;const Rl=new Cn,kl=new Cn,Bl=[],Ul=new Zs;(class extends Zs{constructor(t,e,i){super(t,e),this.instanceMatrix=new Ol(new Float32Array(16*i),16),this.instanceColor=null,this.count=i,this.frustumCulled=!1}copy(t){return super.copy(t),this.instanceMatrix.copy(t.instanceMatrix),null!==t.instanceColor&&(this.instanceColor=t.instanceColor.clone()),this.count=t.count,this}getColorAt(t,e){e.fromArray(this.instanceColor.array,3*t)}getMatrixAt(t,e){e.fromArray(this.instanceMatrix.array,16*t)}raycast(t,e){const i=this.matrixWorld,n=this.count;if(Ul.geometry=this.geometry,Ul.material=this.material,void 0!==Ul.material)for(let s=0;s<n;s++){this.getMatrixAt(s,Rl),kl.multiplyMatrices(i,Rl),Ul.matrixWorld=kl,Ul.raycast(t,Bl);for(let t=0,i=Bl.length;t<i;t++){const i=Bl[t];i.instanceId=s,i.object=this,e.push(i)}Bl.length=0}}setColorAt(t,e){null===this.instanceColor&&(this.instanceColor=new Ol(new Float32Array(3*this.instanceMatrix.count),3)),e.toArray(this.instanceColor.array,3*t)}setMatrixAt(t,e){e.toArray(this.instanceMatrix.array,16*t)}updateMorphTargets(){}dispose(){this.dispatchEvent({type:"dispose"})}}).prototype.isInstancedMesh=!0;class Vl extends us{constructor(t){super(),this.type="LineBasicMaterial",this.color=new ys(16777215),this.linewidth=1,this.linecap="round",this.linejoin="round",this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.linewidth=t.linewidth,this.linecap=t.linecap,this.linejoin=t.linejoin,this}}Vl.prototype.isLineBasicMaterial=!0;const Wl=new Yi,Gl=new Yi,Hl=new Cn,jl=new An,ql=new yn;let Jl=class extends Kn{constructor(t=new Ps,e=new Vl){super(),this.type="Line",this.geometry=t,this.material=e,this.updateMorphTargets()}copy(t){return super.copy(t),this.material=t.material,this.geometry=t.geometry,this}computeLineDistances(){const t=this.geometry;if(t.isBufferGeometry){if(null===t.index){const e=t.attributes.position,i=[0];for(let t=1,n=e.count;t<n;t++)Wl.fromBufferAttribute(e,t-1),Gl.fromBufferAttribute(e,t),i[t]=i[t-1],i[t]+=Wl.distanceTo(Gl);t.setAttribute("lineDistance",new Ts(i,1))}}else t.isGeometry;return this}raycast(t,e){const i=this.geometry,n=this.matrixWorld,s=t.params.Line.threshold,r=i.drawRange;if(null===i.boundingSphere&&i.computeBoundingSphere(),ql.copy(i.boundingSphere),ql.applyMatrix4(n),ql.radius+=s,!1===t.ray.intersectsSphere(ql))return;Hl.copy(n).invert(),jl.copy(t.ray).applyMatrix4(Hl);const a=s/((this.scale.x+this.scale.y+this.scale.z)/3),o=a*a,l=new Yi,h=new Yi,c=new Yi,u=new Yi,d=this.isLineSegments?2:1;if(i.isBufferGeometry){const n=i.index,s=i.attributes.position;if(null!==n)for(let i=Math.max(0,r.start),a=Math.min(n.count,r.start+r.count)-1;i<a;i+=d){const r=n.getX(i),a=n.getX(i+1);if(l.fromBufferAttribute(s,r),h.fromBufferAttribute(s,a),jl.distanceSqToSegment(l,h,u,c)>o)continue;u.applyMatrix4(this.matrixWorld);const d=t.ray.origin.distanceTo(u);d<t.near||d>t.far||e.push({distance:d,point:c.clone().applyMatrix4(this.matrixWorld),index:i,face:null,faceIndex:null,object:this})}else for(let i=Math.max(0,r.start),n=Math.min(s.count,r.start+r.count)-1;i<n;i+=d){if(l.fromBufferAttribute(s,i),h.fromBufferAttribute(s,i+1),jl.distanceSqToSegment(l,h,u,c)>o)continue;u.applyMatrix4(this.matrixWorld);const n=t.ray.origin.distanceTo(u);n<t.near||n>t.far||e.push({distance:n,point:c.clone().applyMatrix4(this.matrixWorld),index:i,face:null,faceIndex:null,object:this})}}else i.isGeometry}updateMorphTargets(){const t=this.geometry;if(t.isBufferGeometry){const e=t.morphAttributes,i=Object.keys(e);if(i.length>0){const t=e[i[0]];if(void 0!==t){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,i=t.length;e<i;e++){const i=t[e].name||String(e);this.morphTargetInfluences.push(0),this.morphTargetDictionary[i]=e}}}}else{const e=t.morphTargets;void 0!==e&&e.length}}};Jl.prototype.isLine=!0;const $l=new Yi,Yl=new Yi;class Xl extends Jl{constructor(t,e){super(t,e),this.type="LineSegments"}computeLineDistances(){const t=this.geometry;if(t.isBufferGeometry){if(null===t.index){const e=t.attributes.position,i=[];for(let t=0,n=e.count;t<n;t+=2)$l.fromBufferAttribute(e,t),Yl.fromBufferAttribute(e,t+1),i[t]=0===t?0:i[t-1],i[t+1]=i[t]+$l.distanceTo(Yl);t.setAttribute("lineDistance",new Ts(i,1))}}else t.isGeometry;return this}}Xl.prototype.isLineSegments=!0,class extends Jl{constructor(t,e){super(t,e),this.type="LineLoop"}}.prototype.isLineLoop=!0;class Zl extends us{constructor(t){super(),this.type="PointsMaterial",this.color=new ys(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.size=t.size,this.sizeAttenuation=t.sizeAttenuation,this}}Zl.prototype.isPointsMaterial=!0;const Kl=new Cn,Ql=new An,th=new yn,eh=new Yi;class ih extends Kn{constructor(t=new Ps,e=new Zl){super(),this.type="Points",this.geometry=t,this.material=e,this.updateMorphTargets()}copy(t){return super.copy(t),this.material=t.material,this.geometry=t.geometry,this}raycast(t,e){const i=this.geometry,n=this.matrixWorld,s=t.params.Points.threshold,r=i.drawRange;if(null===i.boundingSphere&&i.computeBoundingSphere(),th.copy(i.boundingSphere),th.applyMatrix4(n),th.radius+=s,!1===t.ray.intersectsSphere(th))return;Kl.copy(n).invert(),Ql.copy(t.ray).applyMatrix4(Kl);const a=s/((this.scale.x+this.scale.y+this.scale.z)/3),o=a*a;if(i.isBufferGeometry){const s=i.index,a=i.attributes.position;if(null!==s)for(let i=Math.max(0,r.start),l=Math.min(s.count,r.start+r.count);i<l;i++){const r=s.getX(i);eh.fromBufferAttribute(a,r),nh(eh,r,o,n,t,e,this)}else for(let i=Math.max(0,r.start),s=Math.min(a.count,r.start+r.count);i<s;i++)eh.fromBufferAttribute(a,i),nh(eh,i,o,n,t,e,this)}}updateMorphTargets(){const t=this.geometry;if(t.isBufferGeometry){const e=t.morphAttributes,i=Object.keys(e);if(i.length>0){const t=e[i[0]];if(void 0!==t){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,i=t.length;e<i;e++){const i=t[e].name||String(e);this.morphTargetInfluences.push(0),this.morphTargetDictionary[i]=e}}}}else{const e=t.morphTargets;void 0!==e&&e.length}}}function nh(t,e,i,n,s,r,a){const o=Ql.distanceSqToPoint(t);if(o<i){const i=new Yi;Ql.closestPointToPoint(t,i),i.applyMatrix4(n);const l=s.ray.origin.distanceTo(i);if(l<s.near||l>s.far)return;r.push({distance:l,distanceToRay:Math.sqrt(o),point:i,index:e,face:null,object:a})}}ih.prototype.isPoints=!0,class extends Gi{constructor(t,e,i,n,s,r,a,o,l){super(t,e,i,n,s,r,a,o,l),this.format=void 0!==a?a:fe,this.minFilter=void 0!==r?r:Kt,this.magFilter=void 0!==s?s:Kt,this.generateMipmaps=!1;const h=this;"requestVideoFrameCallback"in t&&t.requestVideoFrameCallback((function e(){h.needsUpdate=!0,t.requestVideoFrameCallback(e)}))}clone(){return new this.constructor(this.image).copy(this)}update(){const t=this.image;0=="requestVideoFrameCallback"in t&&t.readyState>=t.HAVE_CURRENT_DATA&&(this.needsUpdate=!0)}}.prototype.isVideoTexture=!0,class extends Gi{constructor(t,e,i){super({width:t,height:e}),this.format=i,this.magFilter=Yt,this.minFilter=Yt,this.generateMipmaps=!1,this.needsUpdate=!0}}.prototype.isFramebufferTexture=!0;class sh extends Gi{constructor(t,e,i,n,s,r,a,o,l,h,c,u){super(null,r,a,o,l,h,n,s,c,u),this.image={width:e,height:i},this.mipmaps=t,this.flipY=!1,this.generateMipmaps=!1}}sh.prototype.isCompressedTexture=!0,class extends Gi{constructor(t,e,i,n,s,r,a,o,l){super(t,e,i,n,s,r,a,o,l),this.needsUpdate=!0}}.prototype.isCanvasTexture=!0;class rh{constructor(){this.type="Curve",this.arcLengthDivisions=200}getPoint(){return null}getPointAt(t,e){const i=this.getUtoTmapping(t);return this.getPoint(i,e)}getPoints(t=5){const e=[];for(let i=0;i<=t;i++)e.push(this.getPoint(i/t));return e}getSpacedPoints(t=5){const e=[];for(let i=0;i<=t;i++)e.push(this.getPointAt(i/t));return e}getLength(){const t=this.getLengths();return t[t.length-1]}getLengths(t=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const e=[];let i,n=this.getPoint(0),s=0;e.push(0);for(let r=1;r<=t;r++)i=this.getPoint(r/t),s+=i.distanceTo(n),e.push(s),n=i;return this.cacheArcLengths=e,e}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(t,e){const i=this.getLengths();let n=0;const s=i.length;let r;r=e||t*i[s-1];let a,o=0,l=s-1;for(;o<=l;)if(n=Math.floor(o+(l-o)/2),a=i[n]-r,a<0)o=n+1;else{if(!(a>0)){l=n;break}l=n-1}if(n=l,i[n]===r)return n/(s-1);const h=i[n];return(n+(r-h)/(i[n+1]-h))/(s-1)}getTangent(t,e){const i=1e-4;let n=t-i,s=t+i;n<0&&(n=0),s>1&&(s=1);const r=this.getPoint(n),a=this.getPoint(s),o=e||(r.isVector2?new Ri:new Yi);return o.copy(a).sub(r).normalize(),o}getTangentAt(t,e){const i=this.getUtoTmapping(t);return this.getTangent(i,e)}computeFrenetFrames(t,e){const i=new Yi,n=[],s=[],r=[],a=new Yi,o=new Cn;for(let e=0;e<=t;e++){const i=e/t;n[e]=this.getTangentAt(i,new Yi)}s[0]=new Yi,r[0]=new Yi;let l=Number.MAX_VALUE;const h=Math.abs(n[0].x),c=Math.abs(n[0].y),u=Math.abs(n[0].z);h<=l&&(l=h,i.set(1,0,0)),c<=l&&(l=c,i.set(0,1,0)),u<=l&&i.set(0,0,1),a.crossVectors(n[0],i).normalize(),s[0].crossVectors(n[0],a),r[0].crossVectors(n[0],s[0]);for(let e=1;e<=t;e++){if(s[e]=s[e-1].clone(),r[e]=r[e-1].clone(),a.crossVectors(n[e-1],n[e]),a.length()>Number.EPSILON){a.normalize();const t=Math.acos(Ni(n[e-1].dot(n[e]),-1,1));s[e].applyMatrix4(o.makeRotationAxis(a,t))}r[e].crossVectors(n[e],s[e])}if(!0===e){let e=Math.acos(Ni(s[0].dot(s[t]),-1,1));e/=t,n[0].dot(a.crossVectors(s[0],s[t]))>0&&(e=-e);for(let i=1;i<=t;i++)s[i].applyMatrix4(o.makeRotationAxis(n[i],e*i)),r[i].crossVectors(n[i],s[i])}return{tangents:n,normals:s,binormals:r}}clone(){return(new this.constructor).copy(this)}copy(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}toJSON(){const t={metadata:{version:4.5,type:"Curve",generator:"Curve.toJSON"}};return t.arcLengthDivisions=this.arcLengthDivisions,t.type=this.type,t}fromJSON(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}}class ah extends rh{constructor(t=0,e=0,i=1,n=1,s=0,r=2*Math.PI,a=!1,o=0){super(),this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=i,this.yRadius=n,this.aStartAngle=s,this.aEndAngle=r,this.aClockwise=a,this.aRotation=o}getPoint(t,e){const i=e||new Ri,n=2*Math.PI;let s=this.aEndAngle-this.aStartAngle;const r=Math.abs(s)<Number.EPSILON;for(;s<0;)s+=n;for(;s>n;)s-=n;s<Number.EPSILON&&(s=r?0:n),!0!==this.aClockwise||r||(s===n?s=-n:s-=n);const a=this.aStartAngle+t*s;let o=this.aX+this.xRadius*Math.cos(a),l=this.aY+this.yRadius*Math.sin(a);if(0!==this.aRotation){const t=Math.cos(this.aRotation),e=Math.sin(this.aRotation),i=o-this.aX,n=l-this.aY;o=i*t-n*e+this.aX,l=i*e+n*t+this.aY}return i.set(o,l)}copy(t){return super.copy(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}toJSON(){const t=super.toJSON();return t.aX=this.aX,t.aY=this.aY,t.xRadius=this.xRadius,t.yRadius=this.yRadius,t.aStartAngle=this.aStartAngle,t.aEndAngle=this.aEndAngle,t.aClockwise=this.aClockwise,t.aRotation=this.aRotation,t}fromJSON(t){return super.fromJSON(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}}ah.prototype.isEllipseCurve=!0;class oh extends ah{constructor(t,e,i,n,s,r){super(t,e,i,i,n,s,r),this.type="ArcCurve"}}function lh(){let t=0,e=0,i=0,n=0;function s(s,r,a,o){t=s,e=a,i=-3*s+3*r-2*a-o,n=2*s-2*r+a+o}return{initCatmullRom:function(t,e,i,n,r){s(e,i,r*(i-t),r*(n-e))},initNonuniformCatmullRom:function(t,e,i,n,r,a,o){let l=(e-t)/r-(i-t)/(r+a)+(i-e)/a,h=(i-e)/a-(n-e)/(a+o)+(n-i)/o;l*=a,h*=a,s(e,i,l,h)},calc:function(s){const r=s*s;return t+e*s+i*r+n*(r*s)}}}oh.prototype.isArcCurve=!0;const hh=new Yi,ch=new lh,uh=new lh,dh=new lh;class ph extends rh{constructor(t=[],e=!1,i="centripetal",n=.5){super(),this.type="CatmullRomCurve3",this.points=t,this.closed=e,this.curveType=i,this.tension=n}getPoint(t,e=new Yi){const i=e,n=this.points,s=n.length,r=(s-(this.closed?0:1))*t;let a,o,l=Math.floor(r),h=r-l;this.closed?l+=l>0?0:(Math.floor(Math.abs(l)/s)+1)*s:0===h&&l===s-1&&(l=s-2,h=1),this.closed||l>0?a=n[(l-1)%s]:(hh.subVectors(n[0],n[1]).add(n[0]),a=hh);const c=n[l%s],u=n[(l+1)%s];if(this.closed||l+2<s?o=n[(l+2)%s]:(hh.subVectors(n[s-1],n[s-2]).add(n[s-1]),o=hh),"centripetal"===this.curveType||"chordal"===this.curveType){const t="chordal"===this.curveType?.5:.25;let e=Math.pow(a.distanceToSquared(c),t),i=Math.pow(c.distanceToSquared(u),t),n=Math.pow(u.distanceToSquared(o),t);i<1e-4&&(i=1),e<1e-4&&(e=i),n<1e-4&&(n=i),ch.initNonuniformCatmullRom(a.x,c.x,u.x,o.x,e,i,n),uh.initNonuniformCatmullRom(a.y,c.y,u.y,o.y,e,i,n),dh.initNonuniformCatmullRom(a.z,c.z,u.z,o.z,e,i,n)}else"catmullrom"===this.curveType&&(ch.initCatmullRom(a.x,c.x,u.x,o.x,this.tension),uh.initCatmullRom(a.y,c.y,u.y,o.y,this.tension),dh.initCatmullRom(a.z,c.z,u.z,o.z,this.tension));return i.set(ch.calc(h),uh.calc(h),dh.calc(h)),i}copy(t){super.copy(t),this.points=[];for(let e=0,i=t.points.length;e<i;e++){const i=t.points[e];this.points.push(i.clone())}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,i=this.points.length;e<i;e++){const i=this.points[e];t.points.push(i.toArray())}return t.closed=this.closed,t.curveType=this.curveType,t.tension=this.tension,t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,i=t.points.length;e<i;e++){const i=t.points[e];this.points.push((new Yi).fromArray(i))}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}}function fh(t,e,i,n,s){const r=.5*(n-e),a=.5*(s-i),o=t*t;return(2*i-2*n+r+a)*(t*o)+(-3*i+3*n-2*r-a)*o+r*t+i}function mh(t,e,i,n){return function(t,e){const i=1-t;return i*i*e}(t,e)+function(t,e){return 2*(1-t)*t*e}(t,i)+function(t,e){return t*t*e}(t,n)}function _h(t,e,i,n,s){return function(t,e){const i=1-t;return i*i*i*e}(t,e)+function(t,e){const i=1-t;return 3*i*i*t*e}(t,i)+function(t,e){return 3*(1-t)*t*t*e}(t,n)+function(t,e){return t*t*t*e}(t,s)}ph.prototype.isCatmullRomCurve3=!0;class gh extends rh{constructor(t=new Ri,e=new Ri,i=new Ri,n=new Ri){super(),this.type="CubicBezierCurve",this.v0=t,this.v1=e,this.v2=i,this.v3=n}getPoint(t,e=new Ri){const i=e,n=this.v0,s=this.v1,r=this.v2,a=this.v3;return i.set(_h(t,n.x,s.x,r.x,a.x),_h(t,n.y,s.y,r.y,a.y)),i}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}gh.prototype.isCubicBezierCurve=!0;class yh extends rh{constructor(t=new Yi,e=new Yi,i=new Yi,n=new Yi){super(),this.type="CubicBezierCurve3",this.v0=t,this.v1=e,this.v2=i,this.v3=n}getPoint(t,e=new Yi){const i=e,n=this.v0,s=this.v1,r=this.v2,a=this.v3;return i.set(_h(t,n.x,s.x,r.x,a.x),_h(t,n.y,s.y,r.y,a.y),_h(t,n.z,s.z,r.z,a.z)),i}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}yh.prototype.isCubicBezierCurve3=!0;class vh extends rh{constructor(t=new Ri,e=new Ri){super(),this.type="LineCurve",this.v1=t,this.v2=e}getPoint(t,e=new Ri){const i=e;return 1===t?i.copy(this.v2):(i.copy(this.v2).sub(this.v1),i.multiplyScalar(t).add(this.v1)),i}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e){const i=e||new Ri;return i.copy(this.v2).sub(this.v1).normalize(),i}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}vh.prototype.isLineCurve=!0;class xh extends rh{constructor(t=new Ri,e=new Ri,i=new Ri){super(),this.type="QuadraticBezierCurve",this.v0=t,this.v1=e,this.v2=i}getPoint(t,e=new Ri){const i=e,n=this.v0,s=this.v1,r=this.v2;return i.set(mh(t,n.x,s.x,r.x),mh(t,n.y,s.y,r.y)),i}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}xh.prototype.isQuadraticBezierCurve=!0;class wh extends rh{constructor(t=new Yi,e=new Yi,i=new Yi){super(),this.type="QuadraticBezierCurve3",this.v0=t,this.v1=e,this.v2=i}getPoint(t,e=new Yi){const i=e,n=this.v0,s=this.v1,r=this.v2;return i.set(mh(t,n.x,s.x,r.x),mh(t,n.y,s.y,r.y),mh(t,n.z,s.z,r.z)),i}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}wh.prototype.isQuadraticBezierCurve3=!0;class bh extends rh{constructor(t=[]){super(),this.type="SplineCurve",this.points=t}getPoint(t,e=new Ri){const i=e,n=this.points,s=(n.length-1)*t,r=Math.floor(s),a=s-r,o=n[0===r?r:r-1],l=n[r],h=n[r>n.length-2?n.length-1:r+1],c=n[r>n.length-3?n.length-1:r+2];return i.set(fh(a,o.x,l.x,h.x,c.x),fh(a,o.y,l.y,h.y,c.y)),i}copy(t){super.copy(t),this.points=[];for(let e=0,i=t.points.length;e<i;e++){const i=t.points[e];this.points.push(i.clone())}return this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,i=this.points.length;e<i;e++){const i=this.points[e];t.points.push(i.toArray())}return t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,i=t.points.length;e<i;e++){const i=t.points[e];this.points.push((new Ri).fromArray(i))}return this}}bh.prototype.isSplineCurve=!0;var Sh=Object.freeze({__proto__:null,ArcCurve:oh,CatmullRomCurve3:ph,CubicBezierCurve:gh,CubicBezierCurve3:yh,EllipseCurve:ah,LineCurve:vh,LineCurve3:class extends rh{constructor(t=new Yi,e=new Yi){super(),this.type="LineCurve3",this.isLineCurve3=!0,this.v1=t,this.v2=e}getPoint(t,e=new Yi){const i=e;return 1===t?i.copy(this.v2):(i.copy(this.v2).sub(this.v1),i.multiplyScalar(t).add(this.v1)),i}getPointAt(t,e){return this.getPoint(t,e)}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}},QuadraticBezierCurve:xh,QuadraticBezierCurve3:wh,SplineCurve:bh});class Mh extends rh{constructor(){super(),this.type="CurvePath",this.curves=[],this.autoClose=!1}add(t){this.curves.push(t)}closePath(){const t=this.curves[0].getPoint(0),e=this.curves[this.curves.length-1].getPoint(1);t.equals(e)||this.curves.push(new vh(e,t))}getPoint(t,e){const i=t*this.getLength(),n=this.getCurveLengths();let s=0;for(;s<n.length;){if(n[s]>=i){const t=n[s]-i,r=this.curves[s],a=r.getLength(),o=0===a?0:1-t/a;return r.getPointAt(o,e)}s++}return null}getLength(){const t=this.getCurveLengths();return t[t.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;const t=[];let e=0;for(let i=0,n=this.curves.length;i<n;i++)e+=this.curves[i].getLength(),t.push(e);return this.cacheLengths=t,t}getSpacedPoints(t=40){const e=[];for(let i=0;i<=t;i++)e.push(this.getPoint(i/t));return this.autoClose&&e.push(e[0]),e}getPoints(t=12){const e=[];let i;for(let n=0,s=this.curves;n<s.length;n++){const r=s[n],a=r&&r.isEllipseCurve?2*t:r&&(r.isLineCurve||r.isLineCurve3)?1:r&&r.isSplineCurve?t*r.points.length:t,o=r.getPoints(a);for(let t=0;t<o.length;t++){const n=o[t];i&&i.equals(n)||(e.push(n),i=n)}}return this.autoClose&&e.length>1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}copy(t){super.copy(t),this.curves=[];for(let e=0,i=t.curves.length;e<i;e++){const i=t.curves[e];this.curves.push(i.clone())}return this.autoClose=t.autoClose,this}toJSON(){const t=super.toJSON();t.autoClose=this.autoClose,t.curves=[];for(let e=0,i=this.curves.length;e<i;e++){const i=this.curves[e];t.curves.push(i.toJSON())}return t}fromJSON(t){super.fromJSON(t),this.autoClose=t.autoClose,this.curves=[];for(let e=0,i=t.curves.length;e<i;e++){const i=t.curves[e];this.curves.push((new Sh[i.type]).fromJSON(i))}return this}}class Th extends Mh{constructor(t){super(),this.type="Path",this.currentPoint=new Ri,t&&this.setFromPoints(t)}setFromPoints(t){this.moveTo(t[0].x,t[0].y);for(let e=1,i=t.length;e<i;e++)this.lineTo(t[e].x,t[e].y);return this}moveTo(t,e){return this.currentPoint.set(t,e),this}lineTo(t,e){const i=new vh(this.currentPoint.clone(),new Ri(t,e));return this.curves.push(i),this.currentPoint.set(t,e),this}quadraticCurveTo(t,e,i,n){const s=new xh(this.currentPoint.clone(),new Ri(t,e),new Ri(i,n));return this.curves.push(s),this.currentPoint.set(i,n),this}bezierCurveTo(t,e,i,n,s,r){const a=new gh(this.currentPoint.clone(),new Ri(t,e),new Ri(i,n),new Ri(s,r));return this.curves.push(a),this.currentPoint.set(s,r),this}splineThru(t){const e=[this.currentPoint.clone()].concat(t),i=new bh(e);return this.curves.push(i),this.currentPoint.copy(t[t.length-1]),this}arc(t,e,i,n,s,r){const a=this.currentPoint.x,o=this.currentPoint.y;return this.absarc(t+a,e+o,i,n,s,r),this}absarc(t,e,i,n,s,r){return this.absellipse(t,e,i,i,n,s,r),this}ellipse(t,e,i,n,s,r,a,o){const l=this.currentPoint.x,h=this.currentPoint.y;return this.absellipse(t+l,e+h,i,n,s,r,a,o),this}absellipse(t,e,i,n,s,r,a,o){const l=new ah(t,e,i,n,s,r,a,o);if(this.curves.length>0){const t=l.getPoint(0);t.equals(this.currentPoint)||this.lineTo(t.x,t.y)}this.curves.push(l);const h=l.getPoint(1);return this.currentPoint.copy(h),this}copy(t){return super.copy(t),this.currentPoint.copy(t.currentPoint),this}toJSON(){const t=super.toJSON();return t.currentPoint=this.currentPoint.toArray(),t}fromJSON(t){return super.fromJSON(t),this.currentPoint.fromArray(t.currentPoint),this}}class Ah extends Th{constructor(t){super(t),this.uuid=Li(),this.type="Shape",this.holes=[]}getPointsHoles(t){const e=[];for(let i=0,n=this.holes.length;i<n;i++)e[i]=this.holes[i].getPoints(t);return e}extractPoints(t){return{shape:this.getPoints(t),holes:this.getPointsHoles(t)}}copy(t){super.copy(t),this.holes=[];for(let e=0,i=t.holes.length;e<i;e++){const i=t.holes[e];this.holes.push(i.clone())}return this}toJSON(){const t=super.toJSON();t.uuid=this.uuid,t.holes=[];for(let e=0,i=this.holes.length;e<i;e++){const i=this.holes[e];t.holes.push(i.toJSON())}return t}fromJSON(t){super.fromJSON(t),this.uuid=t.uuid,this.holes=[];for(let e=0,i=t.holes.length;e<i;e++){const i=t.holes[e];this.holes.push((new Th).fromJSON(i))}return this}}function Ch(t,e,i,n,s){let r,a;if(s===function(t,e,i,n){let s=0;for(let r=e,a=i-n;r<i;r+=n)s+=(t[a]-t[r])*(t[r+1]+t[a+1]),a=r;return s}(t,e,i,n)>0)for(r=e;r<i;r+=n)a=$h(r,t[r],t[r+1],a);else for(r=i-n;r>=e;r-=n)a=$h(r,t[r],t[r+1],a);return a&&Wh(a,a.next)&&(Yh(a),a=a.next),a}function Eh(t,e){if(!t)return t;e||(e=t);let i,n=t;do{if(i=!1,n.steiner||!Wh(n,n.next)&&0!==Vh(n.prev,n,n.next))n=n.next;else{if(Yh(n),n=e=n.prev,n===n.next)break;i=!0}}while(i||n!==e);return e}function zh(t,e,i,n,s,r,a){if(!t)return;!a&&r&&function(t,e,i,n){let s=t;do{null===s.z&&(s.z=Rh(s.x,s.y,e,i,n)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next}while(s!==t);s.prevZ.nextZ=null,s.prevZ=null,function(t){let e,i,n,s,r,a,o,l,h=1;do{for(i=t,t=null,r=null,a=0;i;){for(a++,n=i,o=0,e=0;e<h&&(o++,n=n.nextZ,n);e++);for(l=h;o>0||l>0&&n;)0!==o&&(0===l||!n||i.z<=n.z)?(s=i,i=i.nextZ,o--):(s=n,n=n.nextZ,l--),r?r.nextZ=s:t=s,s.prevZ=r,r=s;i=n}r.nextZ=null,h*=2}while(a>1)}(s)}(t,n,s,r);let o,l,h=t;for(;t.prev!==t.next;)if(o=t.prev,l=t.next,r?Lh(t,n,s,r):Ih(t))e.push(o.i/i),e.push(t.i/i),e.push(l.i/i),Yh(t),t=l.next,h=l.next;else if((t=l)===h){a?1===a?zh(t=Nh(Eh(t),e,i),e,i,n,s,r,2):2===a&&Ph(t,e,i,n,s,r):zh(Eh(t),e,i,n,s,r,1);break}}function Ih(t){const e=t.prev,i=t,n=t.next;if(Vh(e,i,n)>=0)return!1;let s=t.next.next;for(;s!==t.prev;){if(Bh(e.x,e.y,i.x,i.y,n.x,n.y,s.x,s.y)&&Vh(s.prev,s,s.next)>=0)return!1;s=s.next}return!0}function Lh(t,e,i,n){const s=t.prev,r=t,a=t.next;if(Vh(s,r,a)>=0)return!1;const o=s.x<r.x?s.x<a.x?s.x:a.x:r.x<a.x?r.x:a.x,l=s.y<r.y?s.y<a.y?s.y:a.y:r.y<a.y?r.y:a.y,h=s.x>r.x?s.x>a.x?s.x:a.x:r.x>a.x?r.x:a.x,c=s.y>r.y?s.y>a.y?s.y:a.y:r.y>a.y?r.y:a.y,u=Rh(o,l,e,i,n),d=Rh(h,c,e,i,n);let p=t.prevZ,f=t.nextZ;for(;p&&p.z>=u&&f&&f.z<=d;){if(p!==t.prev&&p!==t.next&&Bh(s.x,s.y,r.x,r.y,a.x,a.y,p.x,p.y)&&Vh(p.prev,p,p.next)>=0)return!1;if(p=p.prevZ,f!==t.prev&&f!==t.next&&Bh(s.x,s.y,r.x,r.y,a.x,a.y,f.x,f.y)&&Vh(f.prev,f,f.next)>=0)return!1;f=f.nextZ}for(;p&&p.z>=u;){if(p!==t.prev&&p!==t.next&&Bh(s.x,s.y,r.x,r.y,a.x,a.y,p.x,p.y)&&Vh(p.prev,p,p.next)>=0)return!1;p=p.prevZ}for(;f&&f.z<=d;){if(f!==t.prev&&f!==t.next&&Bh(s.x,s.y,r.x,r.y,a.x,a.y,f.x,f.y)&&Vh(f.prev,f,f.next)>=0)return!1;f=f.nextZ}return!0}function Nh(t,e,i){let n=t;do{const s=n.prev,r=n.next.next;!Wh(s,r)&&Gh(s,n,n.next,r)&&qh(s,r)&&qh(r,s)&&(e.push(s.i/i),e.push(n.i/i),e.push(r.i/i),Yh(n),Yh(n.next),n=t=r),n=n.next}while(n!==t);return Eh(n)}function Ph(t,e,i,n,s,r){let a=t;do{let t=a.next.next;for(;t!==a.prev;){if(a.i!==t.i&&Uh(a,t)){let o=Jh(a,t);return a=Eh(a,a.next),o=Eh(o,o.next),zh(a,e,i,n,s,r),void zh(o,e,i,n,s,r)}t=t.next}a=a.next}while(a!==t)}function Dh(t,e){return t.x-e.x}function Fh(t,e){if(e=function(t,e){let i=e;const n=t.x,s=t.y;let r,a=-Infinity;do{if(s<=i.y&&s>=i.next.y&&i.next.y!==i.y){const t=i.x+(s-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(t<=n&&t>a){if(a=t,t===n){if(s===i.y)return i;if(s===i.next.y)return i.next}r=i.x<i.next.x?i:i.next}}i=i.next}while(i!==e);if(!r)return null;if(n===a)return r;const o=r,l=r.x,h=r.y;let c,u=Infinity;i=r;do{n>=i.x&&i.x>=l&&n!==i.x&&Bh(s<h?n:a,s,l,h,s<h?a:n,s,i.x,i.y)&&(c=Math.abs(s-i.y)/(n-i.x),qh(i,t)&&(c<u||c===u&&(i.x>r.x||i.x===r.x&&Oh(r,i)))&&(r=i,u=c)),i=i.next}while(i!==o);return r}(t,e),e){const i=Jh(e,t);Eh(e,e.next),Eh(i,i.next)}}function Oh(t,e){return Vh(t.prev,t,e.prev)<0&&Vh(e.next,t,t.next)<0}function Rh(t,e,i,n,s){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-i)*s)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-n)*s)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function kh(t){let e=t,i=t;do{(e.x<i.x||e.x===i.x&&e.y<i.y)&&(i=e),e=e.next}while(e!==t);return i}function Bh(t,e,i,n,s,r,a,o){return(s-a)*(e-o)-(t-a)*(r-o)>=0&&(t-a)*(n-o)-(i-a)*(e-o)>=0&&(i-a)*(r-o)-(s-a)*(n-o)>=0}function Uh(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let i=t;do{if(i.i!==t.i&&i.next.i!==t.i&&i.i!==e.i&&i.next.i!==e.i&&Gh(i,i.next,t,e))return!0;i=i.next}while(i!==t);return!1}(t,e)&&(qh(t,e)&&qh(e,t)&&function(t,e){let i=t,n=!1;const s=(t.x+e.x)/2,r=(t.y+e.y)/2;do{i.y>r!=i.next.y>r&&i.next.y!==i.y&&s<(i.next.x-i.x)*(r-i.y)/(i.next.y-i.y)+i.x&&(n=!n),i=i.next}while(i!==t);return n}(t,e)&&(Vh(t.prev,t,e.prev)||Vh(t,e.prev,e))||Wh(t,e)&&Vh(t.prev,t,t.next)>0&&Vh(e.prev,e,e.next)>0)}function Vh(t,e,i){return(e.y-t.y)*(i.x-e.x)-(e.x-t.x)*(i.y-e.y)}function Wh(t,e){return t.x===e.x&&t.y===e.y}function Gh(t,e,i,n){const s=jh(Vh(t,e,i)),r=jh(Vh(t,e,n)),a=jh(Vh(i,n,t)),o=jh(Vh(i,n,e));return s!==r&&a!==o||!(0!==s||!Hh(t,i,e))||!(0!==r||!Hh(t,n,e))||!(0!==a||!Hh(i,t,n))||!(0!==o||!Hh(i,e,n))}function Hh(t,e,i){return e.x<=Math.max(t.x,i.x)&&e.x>=Math.min(t.x,i.x)&&e.y<=Math.max(t.y,i.y)&&e.y>=Math.min(t.y,i.y)}function jh(t){return t>0?1:t<0?-1:0}function qh(t,e){return Vh(t.prev,t,t.next)<0?Vh(t,e,t.next)>=0&&Vh(t,t.prev,e)>=0:Vh(t,e,t.prev)<0||Vh(t,t.next,e)<0}function Jh(t,e){const i=new Xh(t.i,t.x,t.y),n=new Xh(e.i,e.x,e.y),s=t.next,r=e.prev;return t.next=e,e.prev=t,i.next=s,s.prev=i,n.next=i,i.prev=n,r.next=n,n.prev=r,n}function $h(t,e,i,n){const s=new Xh(t,e,i);return n?(s.next=n.next,s.prev=n,n.next.prev=s,n.next=s):(s.prev=s,s.next=s),s}function Yh(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function Xh(t,e,i){this.i=t,this.x=e,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}class Zh{static area(t){const e=t.length;let i=0;for(let n=e-1,s=0;s<e;n=s++)i+=t[n].x*t[s].y-t[s].x*t[n].y;return.5*i}static isClockWise(t){return Zh.area(t)<0}static triangulateShape(t,e){const i=[],n=[],s=[];Kh(t),Qh(i,t);let r=t.length;e.forEach(Kh);for(let t=0;t<e.length;t++)n.push(r),r+=e[t].length,Qh(i,e[t]);const a=function(t,e,i=2){const n=e&&e.length,s=n?e[0]*i:t.length;let r=Ch(t,0,s,i,!0);const a=[];if(!r||r.next===r.prev)return a;let o,l,h,c,u,d,p;if(n&&(r=function(t,e,i,n){const s=[];let r,a,o,l,h;for(r=0,a=e.length;r<a;r++)o=e[r]*n,l=r<a-1?e[r+1]*n:t.length,h=Ch(t,o,l,n,!1),h===h.next&&(h.steiner=!0),s.push(kh(h));for(s.sort(Dh),r=0;r<s.length;r++)Fh(s[r],i),i=Eh(i,i.next);return i}(t,e,r,i)),t.length>80*i){o=h=t[0],l=c=t[1];for(let e=i;e<s;e+=i)u=t[e],d=t[e+1],u<o&&(o=u),d<l&&(l=d),u>h&&(h=u),d>c&&(c=d);p=Math.max(h-o,c-l),p=0!==p?1/p:0}return zh(r,a,i,o,l,p),a}(i,n);for(let t=0;t<a.length;t+=3)s.push(a.slice(t,t+3));return s}}function Kh(t){const e=t.length;e>2&&t[e-1].equals(t[0])&&t.pop()}function Qh(t,e){for(let i=0;i<e.length;i++)t.push(e[i].x),t.push(e[i].y)}class tc extends Ps{constructor(t=new Ah([new Ri(.5,.5),new Ri(-.5,.5),new Ri(-.5,-.5),new Ri(.5,-.5)]),e={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:t,options:e},t=Array.isArray(t)?t:[t];const i=this,n=[],s=[];for(let e=0,i=t.length;e<i;e++)r(t[e]);function r(t){const r=[],a=void 0!==e.curveSegments?e.curveSegments:12,o=void 0!==e.steps?e.steps:1;let l=void 0!==e.depth?e.depth:1,h=void 0===e.bevelEnabled||e.bevelEnabled,c=void 0!==e.bevelThickness?e.bevelThickness:.2,u=void 0!==e.bevelSize?e.bevelSize:c-.1,d=void 0!==e.bevelOffset?e.bevelOffset:0,p=void 0!==e.bevelSegments?e.bevelSegments:3;const f=e.extrudePath,m=void 0!==e.UVGenerator?e.UVGenerator:ec;void 0!==e.amount&&(l=e.amount);let _,g,y,v,x,w=!1;f&&(_=f.getSpacedPoints(o),w=!0,h=!1,g=f.computeFrenetFrames(o,!1),y=new Yi,v=new Yi,x=new Yi),h||(p=0,c=0,u=0,d=0);const b=t.extractPoints(a);let S=b.shape;const M=b.holes;if(!Zh.isClockWise(S)){S=S.reverse();for(let t=0,e=M.length;t<e;t++){const e=M[t];Zh.isClockWise(e)&&(M[t]=e.reverse())}}const T=Zh.triangulateShape(S,M),A=S;for(let t=0,e=M.length;t<e;t++){const e=M[t];S=S.concat(e)}function C(t,e,i){return e.clone().multiplyScalar(i).add(t)}const E=S.length,z=T.length;function I(t,e,i){let n,s,r;const a=t.x-e.x,o=t.y-e.y,l=i.x-t.x,h=i.y-t.y,c=a*a+o*o,u=a*h-o*l;if(Math.abs(u)>Number.EPSILON){const u=Math.sqrt(c),d=Math.sqrt(l*l+h*h),p=e.x-o/u,f=e.y+a/u,m=((i.x-h/d-p)*h-(i.y+l/d-f)*l)/(a*h-o*l);n=p+a*m-t.x,s=f+o*m-t.y;const _=n*n+s*s;if(_<=2)return new Ri(n,s);r=Math.sqrt(_/2)}else{let t=!1;a>Number.EPSILON?l>Number.EPSILON&&(t=!0):a<-Number.EPSILON?l<-Number.EPSILON&&(t=!0):Math.sign(o)===Math.sign(h)&&(t=!0),t?(n=-o,s=a,r=Math.sqrt(c)):(n=a,s=o,r=Math.sqrt(c/2))}return new Ri(n/r,s/r)}const L=[];for(let t=0,e=A.length,i=e-1,n=t+1;t<e;t++,i++,n++)i===e&&(i=0),n===e&&(n=0),L[t]=I(A[t],A[i],A[n]);const N=[];let P,D=L.concat();for(let t=0,e=M.length;t<e;t++){const e=M[t];P=[];for(let t=0,i=e.length,n=i-1,s=t+1;t<i;t++,n++,s++)n===i&&(n=0),s===i&&(s=0),P[t]=I(e[t],e[n],e[s]);N.push(P),D=D.concat(P)}for(let t=0;t<p;t++){const e=t/p,i=c*Math.cos(e*Math.PI/2),n=u*Math.sin(e*Math.PI/2)+d;for(let t=0,e=A.length;t<e;t++){const e=C(A[t],L[t],n);R(e.x,e.y,-i)}for(let t=0,e=M.length;t<e;t++){const e=M[t];P=N[t];for(let t=0,s=e.length;t<s;t++){const s=C(e[t],P[t],n);R(s.x,s.y,-i)}}}const F=u+d;for(let t=0;t<E;t++){const e=h?C(S[t],D[t],F):S[t];w?(v.copy(g.normals[0]).multiplyScalar(e.x),y.copy(g.binormals[0]).multiplyScalar(e.y),x.copy(_[0]).add(v).add(y),R(x.x,x.y,x.z)):R(e.x,e.y,0)}for(let t=1;t<=o;t++)for(let e=0;e<E;e++){const i=h?C(S[e],D[e],F):S[e];w?(v.copy(g.normals[t]).multiplyScalar(i.x),y.copy(g.binormals[t]).multiplyScalar(i.y),x.copy(_[t]).add(v).add(y),R(x.x,x.y,x.z)):R(i.x,i.y,l/o*t)}for(let t=p-1;t>=0;t--){const e=t/p,i=c*Math.cos(e*Math.PI/2),n=u*Math.sin(e*Math.PI/2)+d;for(let t=0,e=A.length;t<e;t++){const e=C(A[t],L[t],n);R(e.x,e.y,l+i)}for(let t=0,e=M.length;t<e;t++){const e=M[t];P=N[t];for(let t=0,s=e.length;t<s;t++){const s=C(e[t],P[t],n);w?R(s.x,s.y+_[o-1].y,_[o-1].x+i):R(s.x,s.y,l+i)}}}function O(t,e){let i=t.length;for(;--i>=0;){const n=i;let s=i-1;s<0&&(s=t.length-1);for(let t=0,i=o+2*p;t<i;t++){const i=E*t,r=E*(t+1);B(e+n+i,e+s+i,e+s+r,e+n+r)}}}function R(t,e,i){r.push(t),r.push(e),r.push(i)}function k(t,e,s){U(t),U(e),U(s);const r=n.length/3,a=m.generateTopUV(i,n,r-3,r-2,r-1);V(a[0]),V(a[1]),V(a[2])}function B(t,e,s,r){U(t),U(e),U(r),U(e),U(s),U(r);const a=n.length/3,o=m.generateSideWallUV(i,n,a-6,a-3,a-2,a-1);V(o[0]),V(o[1]),V(o[3]),V(o[1]),V(o[2]),V(o[3])}function U(t){n.push(r[3*t+0]),n.push(r[3*t+1]),n.push(r[3*t+2])}function V(t){s.push(t.x),s.push(t.y)}!function(){const t=n.length/3;if(h){let t=0,e=E*t;for(let t=0;t<z;t++){const i=T[t];k(i[2]+e,i[1]+e,i[0]+e)}t=o+2*p,e=E*t;for(let t=0;t<z;t++){const i=T[t];k(i[0]+e,i[1]+e,i[2]+e)}}else{for(let t=0;t<z;t++){const e=T[t];k(e[2],e[1],e[0])}for(let t=0;t<z;t++){const e=T[t];k(e[0]+E*o,e[1]+E*o,e[2]+E*o)}}i.addGroup(t,n.length/3-t,0)}(),function(){const t=n.length/3;let e=0;O(A,e),e+=A.length;for(let t=0,i=M.length;t<i;t++){const i=M[t];O(i,e),e+=i.length}i.addGroup(t,n.length/3-t,1)}()}this.setAttribute("position",new Ts(n,3)),this.setAttribute("uv",new Ts(s,2)),this.computeVertexNormals()}toJSON(){const t=super.toJSON();return function(t,e,i){if(i.shapes=[],Array.isArray(t))for(let e=0,n=t.length;e<n;e++){const n=t[e];i.shapes.push(n.uuid)}else i.shapes.push(t.uuid);return void 0!==e.extrudePath&&(i.options.extrudePath=e.extrudePath.toJSON()),i}(this.parameters.shapes,this.parameters.options,t)}static fromJSON(t,e){const i=[];for(let n=0,s=t.shapes.length;n<s;n++){const s=e[t.shapes[n]];i.push(s)}const n=t.options.extrudePath;return void 0!==n&&(t.options.extrudePath=(new Sh[n.type]).fromJSON(n)),new tc(i,t.options)}}const ec={generateTopUV:function(t,e,i,n,s){const r=e[3*i],a=e[3*i+1],o=e[3*n],l=e[3*n+1],h=e[3*s],c=e[3*s+1];return[new Ri(r,a),new Ri(o,l),new Ri(h,c)]},generateSideWallUV:function(t,e,i,n,s,r){const a=e[3*i],o=e[3*i+1],l=e[3*i+2],h=e[3*n],c=e[3*n+1],u=e[3*n+2],d=e[3*s],p=e[3*s+1],f=e[3*s+2],m=e[3*r],_=e[3*r+1],g=e[3*r+2];return Math.abs(o-c)<Math.abs(a-h)?[new Ri(a,1-l),new Ri(h,1-u),new Ri(d,1-f),new Ri(m,1-g)]:[new Ri(o,1-l),new Ri(c,1-u),new Ri(p,1-f),new Ri(_,1-g)]}};class ic extends Ps{constructor(t=new Ah([new Ri(0,.5),new Ri(-.5,-.5),new Ri(.5,-.5)]),e=12){super(),this.type="ShapeGeometry",this.parameters={shapes:t,curveSegments:e};const i=[],n=[],s=[],r=[];let a=0,o=0;if(!1===Array.isArray(t))l(t);else for(let e=0;e<t.length;e++)l(t[e]),this.addGroup(a,o,e),a+=o,o=0;function l(t){const a=n.length/3,l=t.extractPoints(e);let h=l.shape;const c=l.holes;!1===Zh.isClockWise(h)&&(h=h.reverse());for(let t=0,e=c.length;t<e;t++){const e=c[t];!0===Zh.isClockWise(e)&&(c[t]=e.reverse())}const u=Zh.triangulateShape(h,c);for(let t=0,e=c.length;t<e;t++){const e=c[t];h=h.concat(e)}for(let t=0,e=h.length;t<e;t++){const e=h[t];n.push(e.x,e.y,0),s.push(0,0,1),r.push(e.x,e.y)}for(let t=0,e=u.length;t<e;t++){const e=u[t],n=e[0]+a,s=e[1]+a,r=e[2]+a;i.push(n,s,r),o+=3}}this.setIndex(i),this.setAttribute("position",new Ts(n,3)),this.setAttribute("normal",new Ts(s,3)),this.setAttribute("uv",new Ts(r,2))}toJSON(){const t=super.toJSON();return function(t,e){if(e.shapes=[],Array.isArray(t))for(let i=0,n=t.length;i<n;i++){const n=t[i];e.shapes.push(n.uuid)}else e.shapes.push(t.uuid);return e}(this.parameters.shapes,t)}static fromJSON(t,e){const i=[];for(let n=0,s=t.shapes.length;n<s;n++){const s=e[t.shapes[n]];i.push(s)}return new ic(i,t.curveSegments)}}(class extends us{constructor(t){super(),this.type="ShadowMaterial",this.color=new ys(0),this.transparent=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this}}).prototype.isShadowMaterial=!0;class nc extends us{constructor(t){super(),this.defines={STANDARD:""},this.type="MeshStandardMaterial",this.color=new ys(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ys(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=wi,this.normalScale=new Ri(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.defines={STANDARD:""},this.color.copy(t.color),this.roughness=t.roughness,this.metalness=t.metalness,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.roughnessMap=t.roughnessMap,this.metalnessMap=t.metalnessMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapIntensity=t.envMapIntensity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this}}nc.prototype.isMeshStandardMaterial=!0,class extends nc{constructor(t){super(),this.defines={STANDARD:"",PHYSICAL:""},this.type="MeshPhysicalMaterial",this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new Ri(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return Ni(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(t){this.ior=(1+.4*t)/(1-.4*t)}}),this.sheenColor=new ys(0),this.sheenColorMap=null,this.sheenRoughness=1,this.sheenRoughnessMap=null,this.transmissionMap=null,this.thickness=0,this.thicknessMap=null,this.attenuationDistance=0,this.attenuationColor=new ys(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new ys(1,1,1),this.specularColorMap=null,this._sheen=0,this._clearcoat=0,this._transmission=0,this.setValues(t)}get sheen(){return this._sheen}set sheen(t){this._sheen>0!=t>0&&this.version++,this._sheen=t}get clearcoat(){return this._clearcoat}set clearcoat(t){this._clearcoat>0!=t>0&&this.version++,this._clearcoat=t}get transmission(){return this._transmission}set transmission(t){this._transmission>0!=t>0&&this.version++,this._transmission=t}copy(t){return super.copy(t),this.defines={STANDARD:"",PHYSICAL:""},this.clearcoat=t.clearcoat,this.clearcoatMap=t.clearcoatMap,this.clearcoatRoughness=t.clearcoatRoughness,this.clearcoatRoughnessMap=t.clearcoatRoughnessMap,this.clearcoatNormalMap=t.clearcoatNormalMap,this.clearcoatNormalScale.copy(t.clearcoatNormalScale),this.ior=t.ior,this.sheen=t.sheen,this.sheenColor.copy(t.sheenColor),this.sheenColorMap=t.sheenColorMap,this.sheenRoughness=t.sheenRoughness,this.sheenRoughnessMap=t.sheenRoughnessMap,this.transmission=t.transmission,this.transmissionMap=t.transmissionMap,this.thickness=t.thickness,this.thicknessMap=t.thicknessMap,this.attenuationDistance=t.attenuationDistance,this.attenuationColor.copy(t.attenuationColor),this.specularIntensity=t.specularIntensity,this.specularIntensityMap=t.specularIntensityMap,this.specularColor.copy(t.specularColor),this.specularColorMap=t.specularColorMap,this}}.prototype.isMeshPhysicalMaterial=!0;class sc extends us{constructor(t){super(),this.type="MeshPhongMaterial",this.color=new ys(16777215),this.specular=new ys(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ys(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=wi,this.normalScale=new Ri(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=Lt,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.specular.copy(t.specular),this.shininess=t.shininess,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this}}sc.prototype.isMeshPhongMaterial=!0,class extends us{constructor(t){super(),this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new ys(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ys(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=wi,this.normalScale=new Ri(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.gradientMap=t.gradientMap,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this}}.prototype.isMeshToonMaterial=!0;class rc extends us{constructor(t){super(),this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=wi,this.normalScale=new Ri(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.flatShading=t.flatShading,this}}rc.prototype.isMeshNormalMaterial=!0,class extends us{constructor(t){super(),this.type="MeshLambertMaterial",this.color=new ys(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ys(0),this.emissiveIntensity=1,this.emissiveMap=null,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=Lt,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this}}.prototype.isMeshLambertMaterial=!0,class extends us{constructor(t){super(),this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new ys(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=wi,this.normalScale=new Ri(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.defines={MATCAP:""},this.color.copy(t.color),this.matcap=t.matcap,this.map=t.map,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.flatShading=t.flatShading,this}}.prototype.isMeshMatcapMaterial=!0,class extends Vl{constructor(t){super(),this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(t)}copy(t){return super.copy(t),this.scale=t.scale,this.dashSize=t.dashSize,this.gapSize=t.gapSize,this}}.prototype.isLineDashedMaterial=!0;const ac={arraySlice:function(t,e,i){return ac.isTypedArray(t)?new t.constructor(t.subarray(e,void 0!==i?i:t.length)):t.slice(e,i)},convertArray:function(t,e,i){return!t||!i&&t.constructor===e?t:"number"==typeof e.BYTES_PER_ELEMENT?new e(t):Array.prototype.slice.call(t)},isTypedArray:function(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)},getKeyframeOrder:function(t){const e=t.length,i=new Array(e);for(let t=0;t!==e;++t)i[t]=t;return i.sort((function(e,i){return t[e]-t[i]})),i},sortedArray:function(t,e,i){const n=t.length,s=new t.constructor(n);for(let r=0,a=0;a!==n;++r){const n=i[r]*e;for(let i=0;i!==e;++i)s[a++]=t[n+i]}return s},flattenJSON:function(t,e,i,n){let s=1,r=t[0];for(;void 0!==r&&void 0===r[n];)r=t[s++];if(void 0===r)return;let a=r[n];if(void 0!==a)if(Array.isArray(a))do{a=r[n],void 0!==a&&(e.push(r.time),i.push.apply(i,a)),r=t[s++]}while(void 0!==r);else if(void 0!==a.toArray)do{a=r[n],void 0!==a&&(e.push(r.time),a.toArray(i,i.length)),r=t[s++]}while(void 0!==r);else do{a=r[n],void 0!==a&&(e.push(r.time),i.push(a)),r=t[s++]}while(void 0!==r)},subclip:function(t,e,i,n,s=30){const r=t.clone();r.name=e;const a=[];for(let t=0;t<r.tracks.length;++t){const e=r.tracks[t],o=e.getValueSize(),l=[],h=[];for(let t=0;t<e.times.length;++t){const r=e.times[t]*s;if(!(r<i||r>=n)){l.push(e.times[t]);for(let i=0;i<o;++i)h.push(e.values[t*o+i])}}0!==l.length&&(e.times=ac.convertArray(l,e.times.constructor),e.values=ac.convertArray(h,e.values.constructor),a.push(e))}r.tracks=a;let o=Infinity;for(let t=0;t<r.tracks.length;++t)o>r.tracks[t].times[0]&&(o=r.tracks[t].times[0]);for(let t=0;t<r.tracks.length;++t)r.tracks[t].shift(-1*o);return r.resetDuration(),r},makeClipAdditive:function(t,e=0,i=t,n=30){n<=0&&(n=30);const s=i.tracks.length,r=e/n;for(let e=0;e<s;++e){const n=i.tracks[e],s=n.ValueTypeName;if("bool"===s||"string"===s)continue;const a=t.tracks.find((function(t){return t.name===n.name&&t.ValueTypeName===s}));if(void 0===a)continue;let o=0;const l=n.getValueSize();n.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(o=l/3);let h=0;const c=a.getValueSize();a.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(h=c/3);const u=n.times.length-1;let d;if(r<=n.times[0]){const t=o,e=l-o;d=ac.arraySlice(n.values,t,e)}else if(r>=n.times[u]){const t=u*l+o,e=t+l-o;d=ac.arraySlice(n.values,t,e)}else{const t=n.createInterpolant(),e=o,i=l-o;t.evaluate(r),d=ac.arraySlice(t.resultBuffer,e,i)}"quaternion"===s&&(new $i).fromArray(d).normalize().conjugate().toArray(d);const p=a.times.length;for(let t=0;t<p;++t){const e=t*c+h;if("quaternion"===s)$i.multiplyQuaternionsFlat(a.values,e,d,0,a.values,e);else{const t=c-2*h;for(let i=0;i<t;++i)a.values[e+i]-=d[i]}}}return t.blendMode=2501,t}};class oc{constructor(t,e,i,n){this.parameterPositions=t,this._cachedIndex=0,this.resultBuffer=void 0!==n?n:new e.constructor(i),this.sampleValues=e,this.valueSize=i,this.settings=null,this.DefaultSettings_={}}evaluate(t){const e=this.parameterPositions;let i=this._cachedIndex,n=e[i],s=e[i-1];t:{e:{let r;i:{n:if(!(t<n)){for(let r=i+2;;){if(void 0===n){if(t<s)break n;return i=e.length,this._cachedIndex=i,this.afterEnd_(i-1,t,s)}if(i===r)break;if(s=n,n=e[++i],t<n)break e}r=e.length;break i}if(t>=s)break t;{const a=e[1];t<a&&(i=2,s=a);for(let r=i-2;;){if(void 0===s)return this._cachedIndex=0,this.beforeStart_(0,t,n);if(i===r)break;if(n=s,s=e[--i-1],t>=s)break e}r=i,i=0}}for(;i<r;){const n=i+r>>>1;t<e[n]?r=n:i=n+1}if(n=e[i],s=e[i-1],void 0===s)return this._cachedIndex=0,this.beforeStart_(0,t,n);if(void 0===n)return i=e.length,this._cachedIndex=i,this.afterEnd_(i-1,s,t)}this._cachedIndex=i,this.intervalChanged_(i,s,n)}return this.interpolate_(i,s,t,n)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(t){const e=this.resultBuffer,i=this.sampleValues,n=this.valueSize,s=t*n;for(let t=0;t!==n;++t)e[t]=i[s+t];return e}interpolate_(){throw new Error("call to abstract method")}intervalChanged_(){}}oc.prototype.beforeStart_=oc.prototype.copySampleValue_,oc.prototype.afterEnd_=oc.prototype.copySampleValue_;class lc extends oc{constructor(t,e,i,n){super(t,e,i,n),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:mi,endingEnd:mi}}intervalChanged_(t,e,i){const n=this.parameterPositions;let s=t-2,r=t+1,a=n[s],o=n[r];if(void 0===a)switch(this.getSettings_().endingStart){case _i:s=t,a=2*e-i;break;case gi:s=n.length-2,a=e+n[s]-n[s+1];break;default:s=t,a=i}if(void 0===o)switch(this.getSettings_().endingEnd){case _i:r=t,o=2*i-e;break;case gi:r=1,o=i+n[1]-n[0];break;default:r=t-1,o=e}const l=.5*(i-e),h=this.valueSize;this._weightPrev=l/(e-a),this._weightNext=l/(o-i),this._offsetPrev=s*h,this._offsetNext=r*h}interpolate_(t,e,i,n){const s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,o=t*a,l=o-a,h=this._offsetPrev,c=this._offsetNext,u=this._weightPrev,d=this._weightNext,p=(i-e)/(n-e),f=p*p,m=f*p,_=-u*m+2*u*f-u*p,g=(1+u)*m+(-1.5-2*u)*f+(-.5+u)*p+1,y=(-1-d)*m+(1.5+d)*f+.5*p,v=d*m-d*f;for(let t=0;t!==a;++t)s[t]=_*r[h+t]+g*r[l+t]+y*r[o+t]+v*r[c+t];return s}}class hc extends oc{constructor(t,e,i,n){super(t,e,i,n)}interpolate_(t,e,i,n){const s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,o=t*a,l=o-a,h=(i-e)/(n-e),c=1-h;for(let t=0;t!==a;++t)s[t]=r[l+t]*c+r[o+t]*h;return s}}class cc extends oc{constructor(t,e,i,n){super(t,e,i,n)}interpolate_(t){return this.copySampleValue_(t-1)}}class uc{constructor(t,e,i,n){if(void 0===t)throw new Error("THREE.KeyframeTrack: track name is undefined");if(void 0===e||0===e.length)throw new Error("THREE.KeyframeTrack: no keyframes in track named "+t);this.name=t,this.times=ac.convertArray(e,this.TimeBufferType),this.values=ac.convertArray(i,this.ValueBufferType),this.setInterpolation(n||this.DefaultInterpolation)}static toJSON(t){const e=t.constructor;let i;if(e.toJSON!==this.toJSON)i=e.toJSON(t);else{i={name:t.name,times:ac.convertArray(t.times,Array),values:ac.convertArray(t.values,Array)};const e=t.getInterpolation();e!==t.DefaultInterpolation&&(i.interpolation=e)}return i.type=t.ValueTypeName,i}InterpolantFactoryMethodDiscrete(t){return new cc(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodLinear(t){return new hc(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodSmooth(t){return new lc(this.times,this.values,this.getValueSize(),t)}setInterpolation(t){let e;switch(t){case di:e=this.InterpolantFactoryMethodDiscrete;break;case pi:e=this.InterpolantFactoryMethodLinear;break;case fi:e=this.InterpolantFactoryMethodSmooth}if(void 0===e){const e="unsupported interpolation for "+this.ValueTypeName+" keyframe track named "+this.name;if(void 0===this.createInterpolant){if(t===this.DefaultInterpolation)throw new Error(e);this.setInterpolation(this.DefaultInterpolation)}return this}return this.createInterpolant=e,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return di;case this.InterpolantFactoryMethodLinear:return pi;case this.InterpolantFactoryMethodSmooth:return fi}}getValueSize(){return this.values.length/this.times.length}shift(t){if(0!==t){const e=this.times;for(let i=0,n=e.length;i!==n;++i)e[i]+=t}return this}scale(t){if(1!==t){const e=this.times;for(let i=0,n=e.length;i!==n;++i)e[i]*=t}return this}trim(t,e){const i=this.times,n=i.length;let s=0,r=n-1;for(;s!==n&&i[s]<t;)++s;for(;-1!==r&&i[r]>e;)--r;if(++r,0!==s||r!==n){s>=r&&(r=Math.max(r,1),s=r-1);const t=this.getValueSize();this.times=ac.arraySlice(i,s,r),this.values=ac.arraySlice(this.values,s*t,r*t)}return this}validate(){let t=!0;const e=this.getValueSize();e-Math.floor(e)!=0&&(t=!1);const i=this.times,n=this.values,s=i.length;0===s&&(t=!1);let r=null;for(let e=0;e!==s;e++){const n=i[e];if("number"==typeof n&&isNaN(n)){t=!1;break}if(null!==r&&r>n){t=!1;break}r=n}if(void 0!==n&&ac.isTypedArray(n))for(let e=0,i=n.length;e!==i;++e){const i=n[e];if(isNaN(i)){t=!1;break}}return t}optimize(){const t=ac.arraySlice(this.times),e=ac.arraySlice(this.values),i=this.getValueSize(),n=this.getInterpolation()===fi,s=t.length-1;let r=1;for(let a=1;a<s;++a){let s=!1;const o=t[a];if(o!==t[a+1]&&(1!==a||o!==t[0]))if(n)s=!0;else{const t=a*i,n=t-i,r=t+i;for(let a=0;a!==i;++a){const i=e[t+a];if(i!==e[n+a]||i!==e[r+a]){s=!0;break}}}if(s){if(a!==r){t[r]=t[a];const n=a*i,s=r*i;for(let t=0;t!==i;++t)e[s+t]=e[n+t]}++r}}if(s>0){t[r]=t[s];for(let t=s*i,n=r*i,a=0;a!==i;++a)e[n+a]=e[t+a];++r}return r!==t.length?(this.times=ac.arraySlice(t,0,r),this.values=ac.arraySlice(e,0,r*i)):(this.times=t,this.values=e),this}clone(){const t=ac.arraySlice(this.times,0),e=ac.arraySlice(this.values,0),i=new(0,this.constructor)(this.name,t,e);return i.createInterpolant=this.createInterpolant,i}}uc.prototype.TimeBufferType=Float32Array,uc.prototype.ValueBufferType=Float32Array,uc.prototype.DefaultInterpolation=pi;class dc extends uc{}dc.prototype.ValueTypeName="bool",dc.prototype.ValueBufferType=Array,dc.prototype.DefaultInterpolation=di,dc.prototype.InterpolantFactoryMethodLinear=void 0,dc.prototype.InterpolantFactoryMethodSmooth=void 0;class pc extends uc{}pc.prototype.ValueTypeName="color";class fc extends uc{}fc.prototype.ValueTypeName="number";class mc extends oc{constructor(t,e,i,n){super(t,e,i,n)}interpolate_(t,e,i,n){const s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,o=(i-e)/(n-e);let l=t*a;for(let t=l+a;l!==t;l+=4)$i.slerpFlat(s,0,r,l-a,r,l,o);return s}}class _c extends uc{InterpolantFactoryMethodLinear(t){return new mc(this.times,this.values,this.getValueSize(),t)}}_c.prototype.ValueTypeName="quaternion",_c.prototype.DefaultInterpolation=pi,_c.prototype.InterpolantFactoryMethodSmooth=void 0;class gc extends uc{}gc.prototype.ValueTypeName="string",gc.prototype.ValueBufferType=Array,gc.prototype.DefaultInterpolation=di,gc.prototype.InterpolantFactoryMethodLinear=void 0,gc.prototype.InterpolantFactoryMethodSmooth=void 0;class yc extends uc{}yc.prototype.ValueTypeName="vector";class vc{constructor(t,e=-1,i,n=2500){this.name=t,this.tracks=i,this.duration=e,this.blendMode=n,this.uuid=Li(),this.duration<0&&this.resetDuration()}static parse(t){const e=[],i=t.tracks,n=1/(t.fps||1);for(let t=0,s=i.length;t!==s;++t)e.push(xc(i[t]).scale(n));const s=new this(t.name,t.duration,e,t.blendMode);return s.uuid=t.uuid,s}static toJSON(t){const e=[],i=t.tracks,n={name:t.name,duration:t.duration,tracks:e,uuid:t.uuid,blendMode:t.blendMode};for(let t=0,n=i.length;t!==n;++t)e.push(uc.toJSON(i[t]));return n}static CreateFromMorphTargetSequence(t,e,i,n){const s=e.length,r=[];for(let t=0;t<s;t++){let a=[],o=[];a.push((t+s-1)%s,t,(t+1)%s),o.push(0,1,0);const l=ac.getKeyframeOrder(a);a=ac.sortedArray(a,1,l),o=ac.sortedArray(o,1,l),n||0!==a[0]||(a.push(s),o.push(o[0])),r.push(new fc(".morphTargetInfluences["+e[t].name+"]",a,o).scale(1/i))}return new this(t,-1,r)}static findByName(t,e){let i=t;if(!Array.isArray(t)){const e=t;i=e.geometry&&e.geometry.animations||e.animations}for(let t=0;t<i.length;t++)if(i[t].name===e)return i[t];return null}static CreateClipsFromMorphTargetSequences(t,e,i){const n={},s=/^([\w-]*?)([\d]+)$/;for(let e=0,i=t.length;e<i;e++){const i=t[e],r=i.name.match(s);if(r&&r.length>1){const t=r[1];let e=n[t];e||(n[t]=e=[]),e.push(i)}}const r=[];for(const t in n)r.push(this.CreateFromMorphTargetSequence(t,n[t],e,i));return r}static parseAnimation(t,e){if(!t)return null;const i=function(t,e,i,n,s){if(0!==i.length){const r=[],a=[];ac.flattenJSON(i,r,a,n),0!==r.length&&s.push(new t(e,r,a))}},n=[],s=t.name||"default",r=t.fps||30,a=t.blendMode;let o=t.length||-1;const l=t.hierarchy||[];for(let t=0;t<l.length;t++){const s=l[t].keys;if(s&&0!==s.length)if(s[0].morphTargets){const t={};let e;for(e=0;e<s.length;e++)if(s[e].morphTargets)for(let i=0;i<s[e].morphTargets.length;i++)t[s[e].morphTargets[i]]=-1;for(const i in t){const t=[],r=[];for(let n=0;n!==s[e].morphTargets.length;++n){const n=s[e];t.push(n.time),r.push(n.morphTarget===i?1:0)}n.push(new fc(".morphTargetInfluence["+i+"]",t,r))}o=t.length*(r||1)}else{const r=".bones["+e[t].name+"]";i(yc,r+".position",s,"pos",n),i(_c,r+".quaternion",s,"rot",n),i(yc,r+".scale",s,"scl",n)}}return 0===n.length?null:new this(s,o,n,a)}resetDuration(){let t=0;for(let e=0,i=this.tracks.length;e!==i;++e){const i=this.tracks[e];t=Math.max(t,i.times[i.times.length-1])}return this.duration=t,this}trim(){for(let t=0;t<this.tracks.length;t++)this.tracks[t].trim(0,this.duration);return this}validate(){let t=!0;for(let e=0;e<this.tracks.length;e++)t=t&&this.tracks[e].validate();return t}optimize(){for(let t=0;t<this.tracks.length;t++)this.tracks[t].optimize();return this}clone(){const t=[];for(let e=0;e<this.tracks.length;e++)t.push(this.tracks[e].clone());return new this.constructor(this.name,this.duration,t,this.blendMode)}toJSON(){return this.constructor.toJSON(this)}}function xc(t){if(void 0===t.type)throw new Error("THREE.KeyframeTrack: track type undefined, can not parse");const e=function(t){switch(t.toLowerCase()){case"scalar":case"double":case"float":case"number":case"integer":return fc;case"vector":case"vector2":case"vector3":case"vector4":return yc;case"color":return pc;case"quaternion":return _c;case"bool":case"boolean":return dc;case"string":return gc}throw new Error("THREE.KeyframeTrack: Unsupported typeName: "+t)}(t.type);if(void 0===t.times){const e=[],i=[];ac.flattenJSON(t.keys,e,i,"value"),t.times=e,t.values=i}return void 0!==e.parse?e.parse(t):new e(t.name,t.times,t.values,t.interpolation)}const wc={enabled:!1,files:{},add:function(t,e){!1!==this.enabled&&(this.files[t]=e)},get:function(t){if(!1!==this.enabled)return this.files[t]},remove:function(t){delete this.files[t]},clear:function(){this.files={}}},bc=new class{constructor(t,e,i){const n=this;let s,r=!1,a=0,o=0;const l=[];this.onStart=void 0,this.onLoad=t,this.onProgress=e,this.onError=i,this.itemStart=function(t){o++,!1===r&&void 0!==n.onStart&&n.onStart(t,a,o),r=!0},this.itemEnd=function(t){a++,void 0!==n.onProgress&&n.onProgress(t,a,o),a===o&&(r=!1,void 0!==n.onLoad&&n.onLoad())},this.itemError=function(t){void 0!==n.onError&&n.onError(t)},this.resolveURL=function(t){return s?s(t):t},this.setURLModifier=function(t){return s=t,this},this.addHandler=function(t,e){return l.push(t,e),this},this.removeHandler=function(t){const e=l.indexOf(t);return-1!==e&&l.splice(e,2),this},this.getHandler=function(t){for(let e=0,i=l.length;e<i;e+=2){const i=l[e],n=l[e+1];if(i.global&&(i.lastIndex=0),i.test(t))return n}return null}}};class Sc{constructor(t){this.manager=void 0!==t?t:bc,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={}}load(){}loadAsync(t,e){const i=this;return new Promise((function(n,s){i.load(t,n,e,s)}))}parse(){}setCrossOrigin(t){return this.crossOrigin=t,this}setWithCredentials(t){return this.withCredentials=t,this}setPath(t){return this.path=t,this}setResourcePath(t){return this.resourcePath=t,this}setRequestHeader(t){return this.requestHeader=t,this}}const Mc={};class Tc extends Sc{constructor(t){super(t)}load(t,e,i,n){void 0===t&&(t=""),void 0!==this.path&&(t=this.path+t),t=this.manager.resolveURL(t);const s=wc.get(t);if(void 0!==s)return this.manager.itemStart(t),setTimeout((()=>{e&&e(s),this.manager.itemEnd(t)}),0),s;if(void 0!==Mc[t])return void Mc[t].push({onLoad:e,onProgress:i,onError:n});Mc[t]=[],Mc[t].push({onLoad:e,onProgress:i,onError:n});const r=new Request(t,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"});fetch(r).then((e=>{if(200===e.status||0===e.status){if(e.status,"undefined"==typeof ReadableStream||void 0===e.body.getReader)return e;const i=Mc[t],n=e.body.getReader(),s=e.headers.get("Content-Length"),r=s?parseInt(s):0,a=0!==r;let o=0;const l=new ReadableStream({start(t){!function e(){n.read().then((({done:n,value:s})=>{if(n)t.close();else{o+=s.byteLength;const n=new ProgressEvent("progress",{lengthComputable:a,loaded:o,total:r});for(let t=0,e=i.length;t<e;t++){const e=i[t];e.onProgress&&e.onProgress(n)}t.enqueue(s),e()}}))}()}});return new Response(l)}throw Error(`fetch for "${e.url}" responded with ${e.status}: ${e.statusText}`)})).then((t=>{switch(this.responseType){case"arraybuffer":return t.arrayBuffer();case"blob":return t.blob();case"document":return t.text().then((t=>(new DOMParser).parseFromString(t,this.mimeType)));case"json":return t.json();default:return t.text()}})).then((e=>{wc.add(t,e);const i=Mc[t];delete Mc[t];for(let t=0,n=i.length;t<n;t++){const n=i[t];n.onLoad&&n.onLoad(e)}})).catch((e=>{const i=Mc[t];if(void 0===i)throw this.manager.itemError(t),e;delete Mc[t];for(let t=0,n=i.length;t<n;t++){const n=i[t];n.onError&&n.onError(e)}this.manager.itemError(t)})).finally((()=>{this.manager.itemEnd(t)})),this.manager.itemStart(t)}setResponseType(t){return this.responseType=t,this}setMimeType(t){return this.mimeType=t,this}}class Ac extends Sc{constructor(t){super(t)}load(t,e,i,n){const s=this,r=[],a=new sh,o=new Tc(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(s.withCredentials);let l=0;function h(h){o.load(t[h],(function(t){const i=s.parse(t,!0);r[h]={width:i.width,height:i.height,format:i.format,mipmaps:i.mipmaps},l+=1,6===l&&(1===i.mipmapCount&&(a.minFilter=Kt),a.image=r,a.format=i.format,a.needsUpdate=!0,e&&e(a))}),i,n)}if(Array.isArray(t))for(let e=0,i=t.length;e<i;++e)h(e);else o.load(t,(function(t){const i=s.parse(t,!0);if(i.isCubemap){const t=i.mipmaps.length/i.mipmapCount;for(let e=0;e<t;e++){r[e]={mipmaps:[]};for(let t=0;t<i.mipmapCount;t++)r[e].mipmaps.push(i.mipmaps[e*i.mipmapCount+t]),r[e].format=i.format,r[e].width=i.width,r[e].height=i.height}a.image=r}else a.image.width=i.width,a.image.height=i.height,a.mipmaps=i.mipmaps;1===i.mipmapCount&&(a.minFilter=Kt),a.format=i.format,a.needsUpdate=!0,e&&e(a)}),i,n);return a}}class Cc extends Sc{constructor(t){super(t)}load(t,e,i,n){void 0!==this.path&&(t=this.path+t),t=this.manager.resolveURL(t);const s=this,r=wc.get(t);if(void 0!==r)return s.manager.itemStart(t),setTimeout((function(){e&&e(r),s.manager.itemEnd(t)}),0),r;const a=Ui("img");function o(){h(),wc.add(t,this),e&&e(this),s.manager.itemEnd(t)}function l(e){h(),n&&n(e),s.manager.itemError(t),s.manager.itemEnd(t)}function h(){a.removeEventListener("load",o,!1),a.removeEventListener("error",l,!1)}return a.addEventListener("load",o,!1),a.addEventListener("error",l,!1),"data:"!==t.substr(0,5)&&void 0!==this.crossOrigin&&(a.crossOrigin=this.crossOrigin),s.manager.itemStart(t),a.src=t,a}}class Ec extends Sc{constructor(t){super(t)}load(t,e,i,n){const s=new lr,r=new Cc(this.manager);r.setCrossOrigin(this.crossOrigin),r.setPath(this.path);let a=0;function o(i){r.load(t[i],(function(t){s.images[i]=t,a++,6===a&&(s.needsUpdate=!0,e&&e(s))}),void 0,n)}for(let e=0;e<t.length;++e)o(e);return s}}class zc extends Sc{constructor(t){super(t)}load(t,e,i,n){const s=new Gi,r=new Cc(this.manager);return r.setCrossOrigin(this.crossOrigin),r.setPath(this.path),r.load(t,(function(t){s.image=t,s.needsUpdate=!0,void 0!==e&&e(s)}),i,n),s}}let Ic=class extends Kn{constructor(t,e=1){super(),this.type="Light",this.color=new ys(t),this.intensity=e}dispose(){}copy(t){return super.copy(t),this.color.copy(t.color),this.intensity=t.intensity,this}toJSON(t){const e=super.toJSON(t);return e.object.color=this.color.getHex(),e.object.intensity=this.intensity,void 0!==this.groundColor&&(e.object.groundColor=this.groundColor.getHex()),void 0!==this.distance&&(e.object.distance=this.distance),void 0!==this.angle&&(e.object.angle=this.angle),void 0!==this.decay&&(e.object.decay=this.decay),void 0!==this.penumbra&&(e.object.penumbra=this.penumbra),void 0!==this.shadow&&(e.object.shadow=this.shadow.toJSON()),e}};Ic.prototype.isLight=!0,class extends Ic{constructor(t,e,i){super(t,i),this.type="HemisphereLight",this.position.copy(Kn.DefaultUp),this.updateMatrix(),this.groundColor=new ys(e)}copy(t){return Ic.prototype.copy.call(this,t),this.groundColor.copy(t.groundColor),this}}.prototype.isHemisphereLight=!0;const Lc=new Cn,Nc=new Yi,Pc=new Yi;class Dc{constructor(t){this.camera=t,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new Ri(512,512),this.map=null,this.mapPass=null,this.matrix=new Cn,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new _r,this._frameExtents=new Ri(1,1),this._viewportCount=1,this._viewports=[new ji(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,i=this.matrix;Nc.setFromMatrixPosition(t.matrixWorld),e.position.copy(Nc),Pc.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(Pc),e.updateMatrixWorld(),Lc.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Lc),i.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),i.multiply(e.projectionMatrix),i.multiply(e.matrixWorldInverse)}getViewport(t){return this._viewports[t]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(t){return this.camera=t.camera.clone(),this.bias=t.bias,this.radius=t.radius,this.mapSize.copy(t.mapSize),this}clone(){return(new this.constructor).copy(this)}toJSON(){const t={};return 0!==this.bias&&(t.bias=this.bias),0!==this.normalBias&&(t.normalBias=this.normalBias),1!==this.radius&&(t.radius=this.radius),512===this.mapSize.x&&512===this.mapSize.y||(t.mapSize=this.mapSize.toArray()),t.camera=this.camera.toJSON(!1).object,delete t.camera.matrix,t}}class Fc extends Dc{constructor(){super(new rr(50,1,.5,500)),this.focus=1}updateMatrices(t){const e=this.camera,i=2*Ii*t.angle*this.focus,n=this.mapSize.width/this.mapSize.height,s=t.distance||e.far;i===e.fov&&n===e.aspect&&s===e.far||(e.fov=i,e.aspect=n,e.far=s,e.updateProjectionMatrix()),super.updateMatrices(t)}copy(t){return super.copy(t),this.focus=t.focus,this}}Fc.prototype.isSpotLightShadow=!0;class Oc extends Ic{constructor(t,e,i=0,n=Math.PI/3,s=0,r=1){super(t,e),this.type="SpotLight",this.position.copy(Kn.DefaultUp),this.updateMatrix(),this.target=new Kn,this.distance=i,this.angle=n,this.penumbra=s,this.decay=r,this.shadow=new Fc}get power(){return this.intensity*Math.PI}set power(t){this.intensity=t/Math.PI}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.distance=t.distance,this.angle=t.angle,this.penumbra=t.penumbra,this.decay=t.decay,this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}Oc.prototype.isSpotLight=!0;const Rc=new Cn,kc=new Yi,Bc=new Yi;class Uc extends Dc{constructor(){super(new rr(90,1,.5,500)),this._frameExtents=new Ri(4,2),this._viewportCount=6,this._viewports=[new ji(2,1,1,1),new ji(0,1,1,1),new ji(3,1,1,1),new ji(1,1,1,1),new ji(3,0,1,1),new ji(1,0,1,1)],this._cubeDirections=[new Yi(1,0,0),new Yi(-1,0,0),new Yi(0,0,1),new Yi(0,0,-1),new Yi(0,1,0),new Yi(0,-1,0)],this._cubeUps=[new Yi(0,1,0),new Yi(0,1,0),new Yi(0,1,0),new Yi(0,1,0),new Yi(0,0,1),new Yi(0,0,-1)]}updateMatrices(t,e=0){const i=this.camera,n=this.matrix,s=t.distance||i.far;s!==i.far&&(i.far=s,i.updateProjectionMatrix()),kc.setFromMatrixPosition(t.matrixWorld),i.position.copy(kc),Bc.copy(i.position),Bc.add(this._cubeDirections[e]),i.up.copy(this._cubeUps[e]),i.lookAt(Bc),i.updateMatrixWorld(),n.makeTranslation(-kc.x,-kc.y,-kc.z),Rc.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Rc)}}Uc.prototype.isPointLightShadow=!0;let Vc,Wc=class extends Ic{constructor(t,e,i=0,n=1){super(t,e),this.type="PointLight",this.distance=i,this.decay=n,this.shadow=new Uc}get power(){return 4*this.intensity*Math.PI}set power(t){this.intensity=t/(4*Math.PI)}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.distance=t.distance,this.decay=t.decay,this.shadow=t.shadow.clone(),this}};Wc.prototype.isPointLight=!0;class Gc extends Dc{constructor(){super(new zr(-5,5,5,-5,.5,500))}}Gc.prototype.isDirectionalLightShadow=!0;class Hc extends Ic{constructor(t,e){super(t,e),this.type="DirectionalLight",this.position.copy(Kn.DefaultUp),this.updateMatrix(),this.target=new Kn,this.shadow=new Gc}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}Hc.prototype.isDirectionalLight=!0;class jc extends Ic{constructor(t,e){super(t,e),this.type="AmbientLight"}}jc.prototype.isAmbientLight=!0,class extends Ic{constructor(t,e,i=10,n=10){super(t,e),this.type="RectAreaLight",this.width=i,this.height=n}get power(){return this.intensity*this.width*this.height*Math.PI}set power(t){this.intensity=t/(this.width*this.height*Math.PI)}copy(t){return super.copy(t),this.width=t.width,this.height=t.height,this}toJSON(t){const e=super.toJSON(t);return e.object.width=this.width,e.object.height=this.height,e}}.prototype.isRectAreaLight=!0;class qc{constructor(){this.coefficients=[];for(let t=0;t<9;t++)this.coefficients.push(new Yi)}set(t){for(let e=0;e<9;e++)this.coefficients[e].copy(t[e]);return this}zero(){for(let t=0;t<9;t++)this.coefficients[t].set(0,0,0);return this}getAt(t,e){const i=t.x,n=t.y,s=t.z,r=this.coefficients;return e.copy(r[0]).multiplyScalar(.282095),e.addScaledVector(r[1],.488603*n),e.addScaledVector(r[2],.488603*s),e.addScaledVector(r[3],.488603*i),e.addScaledVector(r[4],i*n*1.092548),e.addScaledVector(r[5],n*s*1.092548),e.addScaledVector(r[6],.315392*(3*s*s-1)),e.addScaledVector(r[7],i*s*1.092548),e.addScaledVector(r[8],.546274*(i*i-n*n)),e}getIrradianceAt(t,e){const i=t.x,n=t.y,s=t.z,r=this.coefficients;return e.copy(r[0]).multiplyScalar(.886227),e.addScaledVector(r[1],1.023328*n),e.addScaledVector(r[2],1.023328*s),e.addScaledVector(r[3],1.023328*i),e.addScaledVector(r[4],.858086*i*n),e.addScaledVector(r[5],.858086*n*s),e.addScaledVector(r[6],.743125*s*s-.247708),e.addScaledVector(r[7],.858086*i*s),e.addScaledVector(r[8],.429043*(i*i-n*n)),e}add(t){for(let e=0;e<9;e++)this.coefficients[e].add(t.coefficients[e]);return this}addScaledSH(t,e){for(let i=0;i<9;i++)this.coefficients[i].addScaledVector(t.coefficients[i],e);return this}scale(t){for(let e=0;e<9;e++)this.coefficients[e].multiplyScalar(t);return this}lerp(t,e){for(let i=0;i<9;i++)this.coefficients[i].lerp(t.coefficients[i],e);return this}equals(t){for(let e=0;e<9;e++)if(!this.coefficients[e].equals(t.coefficients[e]))return!1;return!0}copy(t){return this.set(t.coefficients)}clone(){return(new this.constructor).copy(this)}fromArray(t,e=0){const i=this.coefficients;for(let n=0;n<9;n++)i[n].fromArray(t,e+3*n);return this}toArray(t=[],e=0){const i=this.coefficients;for(let n=0;n<9;n++)i[n].toArray(t,e+3*n);return t}static getBasisAt(t,e){const i=t.x,n=t.y,s=t.z;e[0]=.282095,e[1]=.488603*n,e[2]=.488603*s,e[3]=.488603*i,e[4]=1.092548*i*n,e[5]=1.092548*n*s,e[6]=.315392*(3*s*s-1),e[7]=1.092548*i*s,e[8]=.546274*(i*i-n*n)}}qc.prototype.isSphericalHarmonics3=!0;class Jc extends Ic{constructor(t=new qc,e=1){super(void 0,e),this.sh=t}copy(t){return super.copy(t),this.sh.copy(t.sh),this}fromJSON(t){return this.intensity=t.intensity,this.sh.fromArray(t.sh),this}toJSON(t){const e=super.toJSON(t);return e.object.sh=this.sh.toArray(),e}}Jc.prototype.isLightProbe=!0;class $c{static decodeText(t){if("undefined"!=typeof TextDecoder)return(new TextDecoder).decode(t);let e="";for(let i=0,n=t.length;i<n;i++)e+=String.fromCharCode(t[i]);try{return decodeURIComponent(escape(e))}catch(t){return e}}static extractUrlBase(t){const e=t.lastIndexOf("/");return-1===e?"./":t.substr(0,e+1)}static resolveURL(t,e){return"string"!=typeof t||""===t?"":(/^https?:\/\//i.test(e)&&/^\//.test(t)&&(e=e.replace(/(^https?:\/\/[^\/]+).*/i,"$1")),/^(https?:)?\/\//i.test(t)||/^data:.*,.*$/i.test(t)||/^blob:.*$/i.test(t)?t:e+t)}}class Yc extends Ps{constructor(){super(),this.type="InstancedBufferGeometry",this.instanceCount=Infinity}copy(t){return super.copy(t),this.instanceCount=t.instanceCount,this}clone(){return(new this.constructor).copy(this)}toJSON(){const t=super.toJSON(this);return t.instanceCount=this.instanceCount,t.isInstancedBufferGeometry=!0,t}}Yc.prototype.isInstancedBufferGeometry=!0,class extends Sc{constructor(t){super(t),this.options={premultiplyAlpha:"none"}}setOptions(t){return this.options=t,this}load(t,e,i,n){void 0===t&&(t=""),void 0!==this.path&&(t=this.path+t),t=this.manager.resolveURL(t);const s=this,r=wc.get(t);if(void 0!==r)return s.manager.itemStart(t),setTimeout((function(){e&&e(r),s.manager.itemEnd(t)}),0),r;const a={};a.credentials="anonymous"===this.crossOrigin?"same-origin":"include",a.headers=this.requestHeader,fetch(t,a).then((function(t){return t.blob()})).then((function(t){return createImageBitmap(t,Object.assign(s.options,{colorSpaceConversion:"none"}))})).then((function(i){wc.add(t,i),e&&e(i),s.manager.itemEnd(t)})).catch((function(e){n&&n(e),s.manager.itemError(t),s.manager.itemEnd(t)})),s.manager.itemStart(t)}}.prototype.isImageBitmapLoader=!0;class Xc extends Sc{constructor(t){super(t)}load(t,e,i,n){const s=this,r=new Tc(this.manager);r.setResponseType("arraybuffer"),r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,(function(i){try{const t=i.slice(0);(void 0===Vc&&(Vc=new(window.AudioContext||window.webkitAudioContext)),Vc).decodeAudioData(t,(function(t){e(t)}))}catch(e){n&&n(e),s.manager.itemError(t)}}),i,n)}}(class extends Jc{constructor(t,e,i=1){super(void 0,i);const n=(new ys).set(t),s=(new ys).set(e),r=new Yi(n.r,n.g,n.b),a=new Yi(s.r,s.g,s.b),o=Math.sqrt(Math.PI),l=o*Math.sqrt(.75);this.sh.coefficients[0].copy(r).add(a).multiplyScalar(o),this.sh.coefficients[1].copy(r).sub(a).multiplyScalar(l)}}).prototype.isHemisphereLightProbe=!0,class extends Jc{constructor(t,e=1){super(void 0,e);const i=(new ys).set(t);this.sh.coefficients[0].set(i.r,i.g,i.b).multiplyScalar(2*Math.sqrt(Math.PI))}}.prototype.isAmbientLightProbe=!0;class Zc{constructor(t,e,i){let n,s,r;switch(this.binding=t,this.valueSize=i,e){case"quaternion":n=this._slerp,s=this._slerpAdditive,r=this._setAdditiveIdentityQuaternion,this.buffer=new Float64Array(6*i),this._workIndex=5;break;case"string":case"bool":n=this._select,s=this._select,r=this._setAdditiveIdentityOther,this.buffer=new Array(5*i);break;default:n=this._lerp,s=this._lerpAdditive,r=this._setAdditiveIdentityNumeric,this.buffer=new Float64Array(5*i)}this._mixBufferRegion=n,this._mixBufferRegionAdditive=s,this._setIdentity=r,this._origIndex=3,this._addIndex=4,this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,this.useCount=0,this.referenceCount=0}accumulate(t,e){const i=this.buffer,n=this.valueSize,s=t*n+n;let r=this.cumulativeWeight;if(0===r){for(let t=0;t!==n;++t)i[s+t]=i[t];r=e}else{r+=e;const t=e/r;this._mixBufferRegion(i,s,0,t,n)}this.cumulativeWeight=r}accumulateAdditive(t){const e=this.buffer,i=this.valueSize,n=i*this._addIndex;0===this.cumulativeWeightAdditive&&this._setIdentity(),this._mixBufferRegionAdditive(e,n,0,t,i),this.cumulativeWeightAdditive+=t}apply(t){const e=this.valueSize,i=this.buffer,n=t*e+e,s=this.cumulativeWeight,r=this.cumulativeWeightAdditive,a=this.binding;if(this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,s<1){const t=e*this._origIndex;this._mixBufferRegion(i,n,t,1-s,e)}r>0&&this._mixBufferRegionAdditive(i,n,this._addIndex*e,1,e);for(let t=e,s=e+e;t!==s;++t)if(i[t]!==i[t+e]){a.setValue(i,n);break}}saveOriginalState(){const t=this.binding,e=this.buffer,i=this.valueSize,n=i*this._origIndex;t.getValue(e,n);for(let t=i,s=n;t!==s;++t)e[t]=e[n+t%i];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const t=3*this.valueSize;this.binding.setValue(this.buffer,t)}_setAdditiveIdentityNumeric(){const t=this._addIndex*this.valueSize,e=t+this.valueSize;for(let i=t;i<e;i++)this.buffer[i]=0}_setAdditiveIdentityQuaternion(){this._setAdditiveIdentityNumeric(),this.buffer[this._addIndex*this.valueSize+3]=1}_setAdditiveIdentityOther(){const t=this._origIndex*this.valueSize,e=this._addIndex*this.valueSize;for(let i=0;i<this.valueSize;i++)this.buffer[e+i]=this.buffer[t+i]}_select(t,e,i,n,s){if(n>=.5)for(let n=0;n!==s;++n)t[e+n]=t[i+n]}_slerp(t,e,i,n){$i.slerpFlat(t,e,t,e,t,i,n)}_slerpAdditive(t,e,i,n,s){const r=this._workIndex*s;$i.multiplyQuaternionsFlat(t,r,t,e,t,i),$i.slerpFlat(t,e,t,e,t,r,n)}_lerp(t,e,i,n,s){const r=1-n;for(let a=0;a!==s;++a){const s=e+a;t[s]=t[s]*r+t[i+a]*n}}_lerpAdditive(t,e,i,n,s){for(let r=0;r!==s;++r){const s=e+r;t[s]=t[s]+t[i+r]*n}}}const Kc="\\[\\]\\.:\\/",Qc=new RegExp("["+Kc+"]","g"),tu="[^"+Kc+"]",eu="[^"+Kc.replace("\\.","")+"]",iu=/((?:WC+[\/:])*)/.source.replace("WC",tu),nu=/(WCOD+)?/.source.replace("WCOD",eu),su=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",tu),ru=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",tu),au=new RegExp("^"+iu+nu+su+ru+"$"),ou=["material","materials","bones"];class lu{constructor(t,e,i){this.path=e,this.parsedPath=i||lu.parseTrackName(e),this.node=lu.findNode(t,this.parsedPath.nodeName)||t,this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,i){return t&&t.isAnimationObjectGroup?new lu.Composite(t,e,i):new lu(t,e,i)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(Qc,"")}static parseTrackName(t){const e=au.exec(t);if(!e)throw new Error("PropertyBinding: Cannot parse trackName: "+t);const i={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},n=i.nodeName&&i.nodeName.lastIndexOf(".");if(void 0!==n&&-1!==n){const t=i.nodeName.substring(n+1);-1!==ou.indexOf(t)&&(i.nodeName=i.nodeName.substring(0,n),i.objectName=t)}if(null===i.propertyName||0===i.propertyName.length)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+t);return i}static findNode(t,e){if(!e||""===e||"."===e||-1===e||e===t.name||e===t.uuid)return t;if(t.skeleton){const i=t.skeleton.getBoneByName(e);if(void 0!==i)return i}if(t.children){const i=function(t){for(let n=0;n<t.length;n++){const s=t[n];if(s.name===e||s.uuid===e)return s;const r=i(s.children);if(r)return r}return null},n=i(t.children);if(n)return n}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(t,e){t[e]=this.targetObject[this.propertyName]}_getValue_array(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)t[e++]=i[n]}_getValue_arrayElement(t,e){t[e]=this.resolvedProperty[this.propertyIndex]}_getValue_toArray(t,e){this.resolvedProperty.toArray(t,e)}_setValue_direct(t,e){this.targetObject[this.propertyName]=t[e]}_setValue_direct_setNeedsUpdate(t,e){this.targetObject[this.propertyName]=t[e],this.targetObject.needsUpdate=!0}_setValue_direct_setMatrixWorldNeedsUpdate(t,e){this.targetObject[this.propertyName]=t[e],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_array(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=t[e++]}_setValue_array_setNeedsUpdate(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=t[e++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=t[e++];this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_arrayElement(t,e){this.resolvedProperty[this.propertyIndex]=t[e]}_setValue_arrayElement_setNeedsUpdate(t,e){this.resolvedProperty[this.propertyIndex]=t[e],this.targetObject.needsUpdate=!0}_setValue_arrayElement_setMatrixWorldNeedsUpdate(t,e){this.resolvedProperty[this.propertyIndex]=t[e],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_fromArray(t,e){this.resolvedProperty.fromArray(t,e)}_setValue_fromArray_setNeedsUpdate(t,e){this.resolvedProperty.fromArray(t,e),this.targetObject.needsUpdate=!0}_setValue_fromArray_setMatrixWorldNeedsUpdate(t,e){this.resolvedProperty.fromArray(t,e),this.targetObject.matrixWorldNeedsUpdate=!0}_getValue_unbound(t,e){this.bind(),this.getValue(t,e)}_setValue_unbound(t,e){this.bind(),this.setValue(t,e)}bind(){let t=this.node;const e=this.parsedPath,i=e.objectName,n=e.propertyName;let s=e.propertyIndex;if(t||(t=lu.findNode(this.rootNode,e.nodeName)||this.rootNode,this.node=t),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!t)return;if(i){let n=e.objectIndex;switch(i){case"materials":if(!t.material)return;if(!t.material.materials)return;t=t.material.materials;break;case"bones":if(!t.skeleton)return;t=t.skeleton.bones;for(let e=0;e<t.length;e++)if(t[e].name===n){n=e;break}break;default:if(void 0===t[i])return;t=t[i]}if(void 0!==n){if(void 0===t[n])return;t=t[n]}}const r=t[n];if(void 0===r)return void e.nodeName;let a=this.Versioning.None;this.targetObject=t,void 0!==t.needsUpdate?a=this.Versioning.NeedsUpdate:void 0!==t.matrixWorldNeedsUpdate&&(a=this.Versioning.MatrixWorldNeedsUpdate);let o=this.BindingType.Direct;if(void 0!==s){if("morphTargetInfluences"===n){if(!t.geometry)return;if(!t.geometry.isBufferGeometry)return;if(!t.geometry.morphAttributes)return;void 0!==t.morphTargetDictionary[s]&&(s=t.morphTargetDictionary[s])}o=this.BindingType.ArrayElement,this.resolvedProperty=r,this.propertyIndex=s}else void 0!==r.fromArray&&void 0!==r.toArray?(o=this.BindingType.HasFromToArray,this.resolvedProperty=r):Array.isArray(r)?(o=this.BindingType.EntireArray,this.resolvedProperty=r):this.propertyName=n;this.getValue=this.GetterByBindingType[o],this.setValue=this.SetterByBindingTypeAndVersioning[o][a]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}}lu.Composite=class{constructor(t,e,i){const n=i||lu.parseTrackName(e);this._targetGroup=t,this._bindings=t.subscribe_(e,n)}getValue(t,e){this.bind();const i=this._targetGroup.nCachedObjects_,n=this._bindings[i];void 0!==n&&n.getValue(t,e)}setValue(t,e){const i=this._bindings;for(let n=this._targetGroup.nCachedObjects_,s=i.length;n!==s;++n)i[n].setValue(t,e)}bind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,i=t.length;e!==i;++e)t[e].bind()}unbind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,i=t.length;e!==i;++e)t[e].unbind()}},lu.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3},lu.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2},lu.prototype.GetterByBindingType=[lu.prototype._getValue_direct,lu.prototype._getValue_array,lu.prototype._getValue_arrayElement,lu.prototype._getValue_toArray],lu.prototype.SetterByBindingTypeAndVersioning=[[lu.prototype._setValue_direct,lu.prototype._setValue_direct_setNeedsUpdate,lu.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[lu.prototype._setValue_array,lu.prototype._setValue_array_setNeedsUpdate,lu.prototype._setValue_array_setMatrixWorldNeedsUpdate],[lu.prototype._setValue_arrayElement,lu.prototype._setValue_arrayElement_setNeedsUpdate,lu.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[lu.prototype._setValue_fromArray,lu.prototype._setValue_fromArray_setNeedsUpdate,lu.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];class hu{constructor(t,e,i=null,n=e.blendMode){this._mixer=t,this._clip=e,this._localRoot=i,this.blendMode=n;const s=e.tracks,r=s.length,a=new Array(r),o={endingStart:mi,endingEnd:mi};for(let t=0;t!==r;++t){const e=s[t].createInterpolant(null);a[t]=e,e.settings=o}this._interpolantSettings=o,this._interpolants=a,this._propertyBindings=new Array(r),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._weightInterpolant=null,this.loop=2201,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=Infinity,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}play(){return this._mixer._activateAction(this),this}stop(){return this._mixer._deactivateAction(this),this.reset()}reset(){return this.paused=!1,this.enabled=!0,this.time=0,this._loopCount=-1,this._startTime=null,this.stopFading().stopWarping()}isRunning(){return this.enabled&&!this.paused&&0!==this.timeScale&&null===this._startTime&&this._mixer._isActiveAction(this)}isScheduled(){return this._mixer._isActiveAction(this)}startAt(t){return this._startTime=t,this}setLoop(t,e){return this.loop=t,this.repetitions=e,this}setEffectiveWeight(t){return this.weight=t,this._effectiveWeight=this.enabled?t:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(t){return this._scheduleFading(t,0,1)}fadeOut(t){return this._scheduleFading(t,1,0)}crossFadeFrom(t,e,i){if(t.fadeOut(e),this.fadeIn(e),i){const i=this._clip.duration,n=t._clip.duration,s=n/i,r=i/n;t.warp(1,s,e),this.warp(r,1,e)}return this}crossFadeTo(t,e,i){return t.crossFadeFrom(this,e,i)}stopFading(){const t=this._weightInterpolant;return null!==t&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}setEffectiveTimeScale(t){return this.timeScale=t,this._effectiveTimeScale=this.paused?0:t,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(t){return this.timeScale=this._clip.duration/t,this.stopWarping()}syncWith(t){return this.time=t.time,this.timeScale=t.timeScale,this.stopWarping()}halt(t){return this.warp(this._effectiveTimeScale,0,t)}warp(t,e,i){const n=this._mixer,s=n.time,r=this.timeScale;let a=this._timeScaleInterpolant;null===a&&(a=n._lendControlInterpolant(),this._timeScaleInterpolant=a);const o=a.parameterPositions,l=a.sampleValues;return o[0]=s,o[1]=s+i,l[0]=t/r,l[1]=e/r,this}stopWarping(){const t=this._timeScaleInterpolant;return null!==t&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(t,e,i,n){if(!this.enabled)return void this._updateWeight(t);const s=this._startTime;if(null!==s){const n=(t-s)*i;if(n<0||0===i)return;this._startTime=null,e=i*n}e*=this._updateTimeScale(t);const r=this._updateTime(e),a=this._updateWeight(t);if(a>0){const t=this._interpolants,e=this._propertyBindings;if(2501===this.blendMode)for(let i=0,n=t.length;i!==n;++i)t[i].evaluate(r),e[i].accumulateAdditive(a);else for(let i=0,s=t.length;i!==s;++i)t[i].evaluate(r),e[i].accumulate(n,a)}}_updateWeight(t){let e=0;if(this.enabled){e=this.weight;const i=this._weightInterpolant;if(null!==i){const n=i.evaluate(t)[0];e*=n,t>i.parameterPositions[1]&&(this.stopFading(),0===n&&(this.enabled=!1))}}return this._effectiveWeight=e,e}_updateTimeScale(t){let e=0;if(!this.paused){e=this.timeScale;const i=this._timeScaleInterpolant;null!==i&&(e*=i.evaluate(t)[0],t>i.parameterPositions[1]&&(this.stopWarping(),0===e?this.paused=!0:this.timeScale=e))}return this._effectiveTimeScale=e,e}_updateTime(t){const e=this._clip.duration,i=this.loop;let n=this.time+t,s=this._loopCount;const r=2202===i;if(0===t)return-1===s?n:r&&1==(1&s)?e-n:n;if(2200===i){-1===s&&(this._loopCount=0,this._setEndings(!0,!0,!1));t:{if(n>=e)n=e;else{if(!(n<0)){this.time=n;break t}n=0}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=n,this._mixer.dispatchEvent({type:"finished",action:this,direction:t<0?-1:1})}}else{if(-1===s&&(t>=0?(s=0,this._setEndings(!0,0===this.repetitions,r)):this._setEndings(0===this.repetitions,!0,r)),n>=e||n<0){const i=Math.floor(n/e);n-=e*i,s+=Math.abs(i);const a=this.repetitions-s;if(a<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,n=t>0?e:0,this.time=n,this._mixer.dispatchEvent({type:"finished",action:this,direction:t>0?1:-1});else{if(1===a){const e=t<0;this._setEndings(e,!e,r)}else this._setEndings(!1,!1,r);this._loopCount=s,this.time=n,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:i})}}else this.time=n;if(r&&1==(1&s))return e-n}return n}_setEndings(t,e,i){const n=this._interpolantSettings;i?(n.endingStart=_i,n.endingEnd=_i):(n.endingStart=t?this.zeroSlopeAtStart?_i:mi:gi,n.endingEnd=e?this.zeroSlopeAtEnd?_i:mi:gi)}_scheduleFading(t,e,i){const n=this._mixer,s=n.time;let r=this._weightInterpolant;null===r&&(r=n._lendControlInterpolant(),this._weightInterpolant=r);const a=r.parameterPositions,o=r.sampleValues;return a[0]=s,o[0]=e,a[1]=s+t,o[1]=i,this}}(class extends Ci{constructor(t){super(),this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}_bindAction(t,e){const i=t._localRoot||this._root,n=t._clip.tracks,s=n.length,r=t._propertyBindings,a=t._interpolants,o=i.uuid,l=this._bindingsByRootAndName;let h=l[o];void 0===h&&(h={},l[o]=h);for(let t=0;t!==s;++t){const s=n[t],l=s.name;let c=h[l];if(void 0!==c)r[t]=c;else{if(c=r[t],void 0!==c){null===c._cacheIndex&&(++c.referenceCount,this._addInactiveBinding(c,o,l));continue}const n=e&&e._propertyBindings[t].binding.parsedPath;c=new Zc(lu.create(i,l,n),s.ValueTypeName,s.getValueSize()),++c.referenceCount,this._addInactiveBinding(c,o,l),r[t]=c}a[t].resultBuffer=c.buffer}}_activateAction(t){if(!this._isActiveAction(t)){if(null===t._cacheIndex){const e=(t._localRoot||this._root).uuid,i=t._clip.uuid,n=this._actionsByClip[i];this._bindAction(t,n&&n.knownActions[0]),this._addInactiveAction(t,i,e)}const e=t._propertyBindings;for(let t=0,i=e.length;t!==i;++t){const i=e[t];0==i.useCount++&&(this._lendBinding(i),i.saveOriginalState())}this._lendAction(t)}}_deactivateAction(t){if(this._isActiveAction(t)){const e=t._propertyBindings;for(let t=0,i=e.length;t!==i;++t){const i=e[t];0==--i.useCount&&(i.restoreOriginalState(),this._takeBackBinding(i))}this._takeBackAction(t)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;const t=this;this.stats={actions:{get total(){return t._actions.length},get inUse(){return t._nActiveActions}},bindings:{get total(){return t._bindings.length},get inUse(){return t._nActiveBindings}},controlInterpolants:{get total(){return t._controlInterpolants.length},get inUse(){return t._nActiveControlInterpolants}}}}_isActiveAction(t){const e=t._cacheIndex;return null!==e&&e<this._nActiveActions}_addInactiveAction(t,e,i){const n=this._actions,s=this._actionsByClip;let r=s[e];if(void 0===r)r={knownActions:[t],actionByRoot:{}},t._byClipCacheIndex=0,s[e]=r;else{const e=r.knownActions;t._byClipCacheIndex=e.length,e.push(t)}t._cacheIndex=n.length,n.push(t),r.actionByRoot[i]=t}_removeInactiveAction(t){const e=this._actions,i=e[e.length-1],n=t._cacheIndex;i._cacheIndex=n,e[n]=i,e.pop(),t._cacheIndex=null;const s=t._clip.uuid,r=this._actionsByClip,a=r[s],o=a.knownActions,l=o[o.length-1],h=t._byClipCacheIndex;l._byClipCacheIndex=h,o[h]=l,o.pop(),t._byClipCacheIndex=null,delete a.actionByRoot[(t._localRoot||this._root).uuid],0===o.length&&delete r[s],this._removeInactiveBindingsForAction(t)}_removeInactiveBindingsForAction(t){const e=t._propertyBindings;for(let t=0,i=e.length;t!==i;++t){const i=e[t];0==--i.referenceCount&&this._removeInactiveBinding(i)}}_lendAction(t){const e=this._actions,i=t._cacheIndex,n=this._nActiveActions++,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_takeBackAction(t){const e=this._actions,i=t._cacheIndex,n=--this._nActiveActions,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_addInactiveBinding(t,e,i){const n=this._bindingsByRootAndName,s=this._bindings;let r=n[e];void 0===r&&(r={},n[e]=r),r[i]=t,t._cacheIndex=s.length,s.push(t)}_removeInactiveBinding(t){const e=this._bindings,i=t.binding,n=i.rootNode.uuid,s=i.path,r=this._bindingsByRootAndName,a=r[n],o=e[e.length-1],l=t._cacheIndex;o._cacheIndex=l,e[l]=o,e.pop(),delete a[s],0===Object.keys(a).length&&delete r[n]}_lendBinding(t){const e=this._bindings,i=t._cacheIndex,n=this._nActiveBindings++,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_takeBackBinding(t){const e=this._bindings,i=t._cacheIndex,n=--this._nActiveBindings,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_lendControlInterpolant(){const t=this._controlInterpolants,e=this._nActiveControlInterpolants++;let i=t[e];return void 0===i&&(i=new hc(new Float32Array(2),new Float32Array(2),1,this._controlInterpolantsResultBuffer),i.__cacheIndex=e,t[e]=i),i}_takeBackControlInterpolant(t){const e=this._controlInterpolants,i=t.__cacheIndex,n=--this._nActiveControlInterpolants,s=e[n];t.__cacheIndex=n,e[n]=t,s.__cacheIndex=i,e[i]=s}clipAction(t,e,i){const n=e||this._root,s=n.uuid;let r="string"==typeof t?vc.findByName(n,t):t;const a=null!==r?r.uuid:t,o=this._actionsByClip[a];let l=null;if(void 0===i&&(i=null!==r?r.blendMode:2500),void 0!==o){const t=o.actionByRoot[s];if(void 0!==t&&t.blendMode===i)return t;l=o.knownActions[0],null===r&&(r=l._clip)}if(null===r)return null;const h=new hu(this,r,e,i);return this._bindAction(h,l),this._addInactiveAction(h,a,s),h}existingAction(t,e){const i=e||this._root,n=i.uuid,s="string"==typeof t?vc.findByName(i,t):t,r=s?s.uuid:t,a=this._actionsByClip[r];return void 0!==a&&a.actionByRoot[n]||null}stopAllAction(){const t=this._actions;for(let e=this._nActiveActions-1;e>=0;--e)t[e].stop();return this}update(t){t*=this.timeScale;const e=this._actions,i=this._nActiveActions,n=this.time+=t,s=Math.sign(t),r=this._accuIndex^=1;for(let a=0;a!==i;++a)e[a]._update(n,t,s,r);const a=this._bindings,o=this._nActiveBindings;for(let t=0;t!==o;++t)a[t].apply(r);return this}setTime(t){this.time=0;for(let t=0;t<this._actions.length;t++)this._actions[t].time=0;return this.update(t)}getRoot(){return this._root}uncacheClip(t){const e=this._actions,i=t.uuid,n=this._actionsByClip,s=n[i];if(void 0!==s){const t=s.knownActions;for(let i=0,n=t.length;i!==n;++i){const n=t[i];this._deactivateAction(n);const s=n._cacheIndex,r=e[e.length-1];n._cacheIndex=null,n._byClipCacheIndex=null,r._cacheIndex=s,e[s]=r,e.pop(),this._removeInactiveBindingsForAction(n)}delete n[i]}}uncacheRoot(t){const e=t.uuid,i=this._actionsByClip;for(const t in i){const n=i[t].actionByRoot[e];void 0!==n&&(this._deactivateAction(n),this._removeInactiveAction(n))}const n=this._bindingsByRootAndName[e];if(void 0!==n)for(const t in n){const e=n[t];e.restoreOriginalState(),this._removeInactiveBinding(e)}}uncacheAction(t,e){const i=this.existingAction(t,e);null!==i&&(this._deactivateAction(i),this._removeInactiveAction(i))}}).prototype._controlInterpolantsResultBuffer=new Float32Array(1),class extends ul{constructor(t,e,i=1){super(t,e),this.meshPerAttribute=i}copy(t){return super.copy(t),this.meshPerAttribute=t.meshPerAttribute,this}clone(t){const e=super.clone(t);return e.meshPerAttribute=this.meshPerAttribute,e}toJSON(t){const e=super.toJSON(t);return e.isInstancedInterleavedBuffer=!0,e.meshPerAttribute=this.meshPerAttribute,e}}.prototype.isInstancedInterleavedBuffer=!0;class cu{constructor(t,e,i=0,n=Infinity){this.ray=new An(t,e),this.near=i,this.far=n,this.camera=null,this.layers=new kn,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(t,e){this.ray.set(t,e)}setFromCamera(t,e){e&&e.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(e.matrixWorld),this.ray.direction.set(t.x,t.y,.5).unproject(e).sub(this.ray.origin).normalize(),this.camera=e):e&&e.isOrthographicCamera&&(this.ray.origin.set(t.x,t.y,(e.near+e.far)/(e.near-e.far)).unproject(e),this.ray.direction.set(0,0,-1).transformDirection(e.matrixWorld),this.camera=e)}intersectObject(t,e=!0,i=[]){return du(t,this,i,e),i.sort(uu),i}intersectObjects(t,e=!0,i=[]){for(let n=0,s=t.length;n<s;n++)du(t[n],this,i,e);return i.sort(uu),i}}function uu(t,e){return t.distance-e.distance}function du(t,e,i,n){if(t.layers.test(e.layers)&&t.raycast(e,i),!0===n){const n=t.children;for(let t=0,s=n.length;t<s;t++)du(n[t],e,i,!0)}}const pu=new Yi,fu=new Cn,mu=new Cn;function _u(t){const e=[];t&&t.isBone&&e.push(t);for(let i=0;i<t.children.length;i++)e.push.apply(e,_u(t.children[i]));return e}const gu=new Float32Array(1);function yu(t,e,i,n,s,r,a,o){t[e]=i,t[e+1]=n,t[e+2]=s,t[e+3]=r,t[e+4]=a,t[e+5]=o}new Int32Array(gu.buffer),rh.create=function(t,e){return t.prototype=Object.create(rh.prototype),t.prototype.constructor=t,t.prototype.getPoint=e,t},Th.prototype.fromPoints=function(t){return this.setFromPoints(t)},class extends Xl{constructor(t=10,e=10,i=4473924,n=8947848){i=new ys(i),n=new ys(n);const s=e/2,r=t/e,a=t/2,o=[],l=[];for(let t=0,h=0,c=-a;t<=e;t++,c+=r){o.push(-a,0,c,a,0,c),o.push(c,0,-a,c,0,a);const e=t===s?i:n;e.toArray(l,h),h+=3,e.toArray(l,h),h+=3,e.toArray(l,h),h+=3,e.toArray(l,h),h+=3}const h=new Ps;h.setAttribute("position",new Ts(o,3)),h.setAttribute("color",new Ts(l,3)),super(h,new Vl({vertexColors:!0,toneMapped:!1})),this.type="GridHelper"}}.prototype.setColors=function(){},class extends Xl{constructor(t){const e=_u(t),i=new Ps,n=[],s=[],r=new ys(0,0,1),a=new ys(0,1,0);for(let t=0;t<e.length;t++){const i=e[t];i.parent&&i.parent.isBone&&(n.push(0,0,0),n.push(0,0,0),s.push(r.r,r.g,r.b),s.push(a.r,a.g,a.b))}i.setAttribute("position",new Ts(n,3)),i.setAttribute("color",new Ts(s,3)),super(i,new Vl({vertexColors:!0,depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0})),this.type="SkeletonHelper",this.isSkeletonHelper=!0,this.root=t,this.bones=e,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1}updateMatrixWorld(t){const e=this.bones,i=this.geometry,n=i.getAttribute("position");mu.copy(this.root.matrixWorld).invert();for(let t=0,i=0;t<e.length;t++){const s=e[t];s.parent&&s.parent.isBone&&(fu.multiplyMatrices(mu,s.matrixWorld),pu.setFromMatrixPosition(fu),n.setXYZ(i,pu.x,pu.y,pu.z),fu.multiplyMatrices(mu,s.parent.matrixWorld),pu.setFromMatrixPosition(fu),n.setXYZ(i+1,pu.x,pu.y,pu.z),i+=2)}i.getAttribute("position").needsUpdate=!0,super.updateMatrixWorld(t)}}.prototype.update=function(){},Sc.prototype.extractUrlBase=function(t){return $c.extractUrlBase(t)},Sc.Handlers={add:function(){},get:function(){}},Ki.prototype.center=function(t){return this.getCenter(t)},Ki.prototype.empty=function(){return this.isEmpty()},Ki.prototype.isIntersectionBox=function(t){return this.intersectsBox(t)},Ki.prototype.isIntersectionSphere=function(t){return this.intersectsSphere(t)},Ki.prototype.size=function(t){return this.getSize(t)},yn.prototype.empty=function(){return this.isEmpty()},_r.prototype.setFromMatrix=function(t){return this.setFromProjectionMatrix(t)},ki.prototype.flattenToArrayOffset=function(t,e){return this.toArray(t,e)},ki.prototype.multiplyVector3=function(t){return t.applyMatrix3(this)},ki.prototype.multiplyVector3Array=function(){},ki.prototype.applyToBufferAttribute=function(t){return t.applyMatrix3(this)},ki.prototype.applyToVector3Array=function(){},ki.prototype.getInverse=function(t){return this.copy(t).invert()},Cn.prototype.extractPosition=function(t){return this.copyPosition(t)},Cn.prototype.flattenToArrayOffset=function(t,e){return this.toArray(t,e)},Cn.prototype.getPosition=function(){return(new Yi).setFromMatrixColumn(this,3)},Cn.prototype.setRotationFromQuaternion=function(t){return this.makeRotationFromQuaternion(t)},Cn.prototype.multiplyToArray=function(){},Cn.prototype.multiplyVector3=function(t){return t.applyMatrix4(this)},Cn.prototype.multiplyVector4=function(t){return t.applyMatrix4(this)},Cn.prototype.multiplyVector3Array=function(){},Cn.prototype.rotateAxis=function(t){t.transformDirection(this)},Cn.prototype.crossVector=function(t){return t.applyMatrix4(this)},Cn.prototype.translate=function(){},Cn.prototype.rotateX=function(){},Cn.prototype.rotateY=function(){},Cn.prototype.rotateZ=function(){},Cn.prototype.rotateByAxis=function(){},Cn.prototype.applyToBufferAttribute=function(t){return t.applyMatrix4(this)},Cn.prototype.applyToVector3Array=function(){},Cn.prototype.makeFrustum=function(t,e,i,n,s,r){return this.makePerspective(t,e,n,i,s,r)},Cn.prototype.getInverse=function(t){return this.copy(t).invert()},pr.prototype.isIntersectionLine=function(t){return this.intersectsLine(t)},$i.prototype.multiplyVector3=function(t){return t.applyQuaternion(this)},$i.prototype.inverse=function(){return this.invert()},An.prototype.isIntersectionBox=function(t){return this.intersectsBox(t)},An.prototype.isIntersectionPlane=function(t){return this.intersectsPlane(t)},An.prototype.isIntersectionSphere=function(t){return this.intersectsSphere(t)},hs.prototype.area=function(){return this.getArea()},hs.prototype.barycoordFromPoint=function(t,e){return this.getBarycoord(t,e)},hs.prototype.midpoint=function(t){return this.getMidpoint(t)},hs.prototypenormal=function(t){return this.getNormal(t)},hs.prototype.plane=function(t){return this.getPlane(t)},hs.barycoordFromPoint=function(t,e,i,n,s){return hs.getBarycoord(t,e,i,n,s)},hs.normal=function(t,e,i,n){return hs.getNormal(t,e,i,n)},Ah.prototype.extractAllPoints=function(t){return this.extractPoints(t)},Ah.prototype.extrude=function(t){return new tc(this,t)},Ah.prototype.makeGeometry=function(t){return new ic(this,t)},Ri.prototype.fromAttribute=function(t,e,i){return this.fromBufferAttribute(t,e,i)},Ri.prototype.distanceToManhattan=function(t){return this.manhattanDistanceTo(t)},Ri.prototype.lengthManhattan=function(){return this.manhattanLength()},Yi.prototype.setEulerFromRotationMatrix=function(){},Yi.prototype.setEulerFromQuaternion=function(){},Yi.prototype.getPositionFromMatrix=function(t){return this.setFromMatrixPosition(t)},Yi.prototype.getScaleFromMatrix=function(t){return this.setFromMatrixScale(t)},Yi.prototype.getColumnFromMatrix=function(t,e){return this.setFromMatrixColumn(e,t)},Yi.prototype.applyProjection=function(t){return this.applyMatrix4(t)},Yi.prototype.fromAttribute=function(t,e,i){return this.fromBufferAttribute(t,e,i)},Yi.prototype.distanceToManhattan=function(t){return this.manhattanDistanceTo(t)},Yi.prototype.lengthManhattan=function(){return this.manhattanLength()},ji.prototype.fromAttribute=function(t,e,i){return this.fromBufferAttribute(t,e,i)},ji.prototype.lengthManhattan=function(){return this.manhattanLength()},Kn.prototype.getChildByName=function(t){return this.getObjectByName(t)},Kn.prototype.renderDepth=function(){},Kn.prototype.translate=function(t,e){return this.translateOnAxis(e,t)},Kn.prototype.getWorldRotation=function(){},Kn.prototype.applyMatrix=function(t){return this.applyMatrix4(t)},Object.defineProperties(Kn.prototype,{eulerOrder:{get:function(){return this.rotation.order},set:function(t){this.rotation.order=t}},useQuaternion:{get:function(){},set:function(){}}}),Zs.prototype.setDrawMode=function(){},Object.defineProperties(Zs.prototype,{drawMode:{get:function(){return 0},set:function(){}}}),Dl.prototype.initBones=function(){},rr.prototype.setLens=function(t,e){void 0!==e&&(this.filmGauge=e),this.setFocalLength(t)},Object.defineProperties(Ic.prototype,{onlyShadow:{set:function(){}},shadowCameraFov:{set:function(t){this.shadow.camera.fov=t}},shadowCameraLeft:{set:function(t){this.shadow.camera.left=t}},shadowCameraRight:{set:function(t){this.shadow.camera.right=t}},shadowCameraTop:{set:function(t){this.shadow.camera.top=t}},shadowCameraBottom:{set:function(t){this.shadow.camera.bottom=t}},shadowCameraNear:{set:function(t){this.shadow.camera.near=t}},shadowCameraFar:{set:function(t){this.shadow.camera.far=t}},shadowCameraVisible:{set:function(){}},shadowBias:{set:function(t){this.shadow.bias=t}},shadowDarkness:{set:function(){}},shadowMapWidth:{set:function(t){this.shadow.mapSize.width=t}},shadowMapHeight:{set:function(t){this.shadow.mapSize.height=t}}}),Object.defineProperties(bs.prototype,{length:{get:function(){return this.array.length}},dynamic:{get:function(){return this.usage===Ti},set:function(){this.setUsage(Ti)}}}),bs.prototype.setDynamic=function(t){return this.setUsage(!0===t?Ti:Mi),this},bs.prototype.copyIndicesArray=function(){},bs.prototype.setArray=function(){},Ps.prototype.addIndex=function(t){this.setIndex(t)},Ps.prototype.addAttribute=function(t,e){return e&&e.isBufferAttribute||e&&e.isInterleavedBufferAttribute?"index"===t?(this.setIndex(e),this):this.setAttribute(t,e):this.setAttribute(t,new bs(arguments[1],arguments[2]))},Ps.prototype.addDrawCall=function(t,e,i){this.addGroup(t,e)},Ps.prototype.clearDrawCalls=function(){this.clearGroups()},Ps.prototype.computeOffsets=function(){},Ps.prototype.removeAttribute=function(t){return this.deleteAttribute(t)},Ps.prototype.applyMatrix=function(t){return this.applyMatrix4(t)},Object.defineProperties(Ps.prototype,{drawcalls:{get:function(){return this.groups}},offsets:{get:function(){return this.groups}}}),ul.prototype.setDynamic=function(t){return this.setUsage(!0===t?Ti:Mi),this},ul.prototype.setArray=function(){},tc.prototype.getArrays=function(){},tc.prototype.addShapeList=function(){},tc.prototype.addShape=function(){},cl.prototype.dispose=function(){},Object.defineProperties(us.prototype,{wrapAround:{get:function(){},set:function(){}},overdraw:{get:function(){},set:function(){}},wrapRGB:{get:function(){return new ys}},shading:{get:function(){},set:function(t){this.flatShading=1===t}},stencilMask:{get:function(){return this.stencilFuncMask},set:function(t){this.stencilFuncMask=t}},vertexTangents:{get:function(){},set:function(){}}}),Object.defineProperties(nr.prototype,{derivatives:{get:function(){return this.extensions.derivatives},set:function(t){this.extensions.derivatives=t}}}),hl.prototype.clearTarget=function(t,e,i,n){this.setRenderTarget(t),this.clear(e,i,n)},hl.prototype.animate=function(t){this.setAnimationLoop(t)},hl.prototype.getCurrentRenderTarget=function(){return this.getRenderTarget()},hl.prototype.getMaxAnisotropy=function(){return this.capabilities.getMaxAnisotropy()},hl.prototype.getPrecision=function(){return this.capabilities.precision},hl.prototype.resetGLState=function(){return this.state.reset()},hl.prototype.supportsFloatTextures=function(){return this.extensions.get("OES_texture_float")},hl.prototype.supportsHalfFloatTextures=function(){return this.extensions.get("OES_texture_half_float")},hl.prototype.supportsStandardDerivatives=function(){return this.extensions.get("OES_standard_derivatives")},hl.prototype.supportsCompressedTextureS3TC=function(){return this.extensions.get("WEBGL_compressed_texture_s3tc")},hl.prototype.supportsCompressedTexturePVRTC=function(){return this.extensions.get("WEBGL_compressed_texture_pvrtc")},hl.prototype.supportsBlendMinMax=function(){return this.extensions.get("EXT_blend_minmax")},hl.prototype.supportsVertexTextures=function(){return this.capabilities.vertexTextures},hl.prototype.supportsInstancedArrays=function(){return this.extensions.get("ANGLE_instanced_arrays")},hl.prototype.enableScissorTest=function(t){this.setScissorTest(t)},hl.prototype.initMaterial=function(){},hl.prototype.addPrePlugin=function(){},hl.prototype.addPostPlugin=function(){},hl.prototype.updateShadowMap=function(){},hl.prototype.setFaceCulling=function(){},hl.prototype.allocTextureUnit=function(){},hl.prototype.setTexture=function(){},hl.prototype.setTexture2D=function(){},hl.prototype.setTextureCube=function(){},hl.prototype.getActiveMipMapLevel=function(){return this.getActiveMipmapLevel()},Object.defineProperties(hl.prototype,{shadowMapEnabled:{get:function(){return this.shadowMap.enabled},set:function(t){this.shadowMap.enabled=t}},shadowMapType:{get:function(){return this.shadowMap.type},set:function(t){this.shadowMap.type=t}},shadowMapCullFace:{get:function(){},set:function(){}},context:{get:function(){return this.getContext()}},vr:{get:function(){return this.xr}},gammaInput:{get:function(){return!1},set:function(){}},gammaOutput:{get:function(){return!1},set:function(t){this.outputEncoding=!0===t?vi:yi}},toneMappingWhitePoint:{get:function(){return 1},set:function(){}},gammaFactor:{get:function(){return 2},set:function(){}}}),Object.defineProperties(Ko.prototype,{cullFace:{get:function(){},set:function(){}},renderReverseSided:{get:function(){},set:function(){}},renderSingleSided:{get:function(){},set:function(){}}}),Object.defineProperties(qi.prototype,{wrapS:{get:function(){return this.texture.wrapS},set:function(t){this.texture.wrapS=t}},wrapT:{get:function(){return this.texture.wrapT},set:function(t){this.texture.wrapT=t}},magFilter:{get:function(){return this.texture.magFilter},set:function(t){this.texture.magFilter=t}},minFilter:{get:function(){return this.texture.minFilter},set:function(t){this.texture.minFilter=t}},anisotropy:{get:function(){return this.texture.anisotropy},set:function(t){this.texture.anisotropy=t}},offset:{get:function(){return this.texture.offset},set:function(t){this.texture.offset=t}},repeat:{get:function(){return this.texture.repeat},set:function(t){this.texture.repeat=t}},format:{get:function(){return this.texture.format},set:function(t){this.texture.format=t}},type:{get:function(){return this.texture.type},set:function(t){this.texture.type=t}},generateMipmaps:{get:function(){return this.texture.generateMipmaps},set:function(t){this.texture.generateMipmaps=t}}}),class extends Kn{constructor(t){super(),this.type="Audio",this.listener=t,this.context=t.context,this.gain=this.context.createGain(),this.gain.connect(t.getInput()),this.autoplay=!1,this.buffer=null,this.detune=0,this.loop=!1,this.loopStart=0,this.loopEnd=0,this.offset=0,this.duration=void 0,this.playbackRate=1,this.isPlaying=!1,this.hasPlaybackControl=!0,this.source=null,this.sourceType="empty",this._startedAt=0,this._progress=0,this._connected=!1,this.filters=[]}getOutput(){return this.gain}setNodeSource(t){return this.hasPlaybackControl=!1,this.sourceType="audioNode",this.source=t,this.connect(),this}setMediaElementSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaNode",this.source=this.context.createMediaElementSource(t),this.connect(),this}setMediaStreamSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaStreamNode",this.source=this.context.createMediaStreamSource(t),this.connect(),this}setBuffer(t){return this.buffer=t,this.sourceType="buffer",this.autoplay&&this.play(),this}play(t=0){if(!0===this.isPlaying)return;if(!1===this.hasPlaybackControl)return;this._startedAt=this.context.currentTime+t;const e=this.context.createBufferSource();return e.buffer=this.buffer,e.loop=this.loop,e.loopStart=this.loopStart,e.loopEnd=this.loopEnd,e.onended=this.onEnded.bind(this),e.start(this._startedAt,this._progress+this.offset,this.duration),this.isPlaying=!0,this.source=e,this.setDetune(this.detune),this.setPlaybackRate(this.playbackRate),this.connect()}pause(){if(!1!==this.hasPlaybackControl)return!0===this.isPlaying&&(this._progress+=Math.max(this.context.currentTime-this._startedAt,0)*this.playbackRate,!0===this.loop&&(this._progress=this._progress%(this.duration||this.buffer.duration)),this.source.stop(),this.source.onended=null,this.isPlaying=!1),this}stop(){if(!1!==this.hasPlaybackControl)return this._progress=0,this.source.stop(),this.source.onended=null,this.isPlaying=!1,this}connect(){if(this.filters.length>0){this.source.connect(this.filters[0]);for(let t=1,e=this.filters.length;t<e;t++)this.filters[t-1].connect(this.filters[t]);this.filters[this.filters.length-1].connect(this.getOutput())}else this.source.connect(this.getOutput());return this._connected=!0,this}disconnect(){if(this.filters.length>0){this.source.disconnect(this.filters[0]);for(let t=1,e=this.filters.length;t<e;t++)this.filters[t-1].disconnect(this.filters[t]);this.filters[this.filters.length-1].disconnect(this.getOutput())}else this.source.disconnect(this.getOutput());return this._connected=!1,this}getFilters(){return this.filters}setFilters(t){return t||(t=[]),!0===this._connected?(this.disconnect(),this.filters=t.slice(),this.connect()):this.filters=t.slice(),this}setDetune(t){if(this.detune=t,void 0!==this.source.detune)return!0===this.isPlaying&&this.source.detune.setTargetAtTime(this.detune,this.context.currentTime,.01),this}getDetune(){return this.detune}getFilter(){return this.getFilters()[0]}setFilter(t){return this.setFilters(t?[t]:[])}setPlaybackRate(t){if(!1!==this.hasPlaybackControl)return this.playbackRate=t,!0===this.isPlaying&&this.source.playbackRate.setTargetAtTime(this.playbackRate,this.context.currentTime,.01),this}getPlaybackRate(){return this.playbackRate}onEnded(){this.isPlaying=!1}getLoop(){return!1!==this.hasPlaybackControl&&this.loop}setLoop(t){if(!1!==this.hasPlaybackControl)return this.loop=t,!0===this.isPlaying&&(this.source.loop=this.loop),this}setLoopStart(t){return this.loopStart=t,this}setLoopEnd(t){return this.loopEnd=t,this}getVolume(){return this.gain.gain.value}setVolume(t){return this.gain.gain.setTargetAtTime(t,this.context.currentTime,.01),this}}.prototype.load=function(t){const e=this;return(new Xc).load(t,(function(t){e.setBuffer(t)})),this},or.prototype.updateCubeMap=function(t,e){return this.update(t,e)},or.prototype.clear=function(t,e,i,n){return this.renderTarget.clear(t,e,i,n)},Vi.crossOrigin=void 0,Vi.loadTexture=function(t,e,i,n){const s=new zc;s.setCrossOrigin(this.crossOrigin);const r=s.load(t,i,void 0,n);return e&&(r.mapping=e),r},Vi.loadTextureCube=function(t,e,i,n){const s=new Ec;s.setCrossOrigin(this.crossOrigin);const r=s.load(t,i,void 0,n);return e&&(r.mapping=e),r},Vi.loadCompressedTexture=function(){},Vi.loadCompressedTextureCube=function(){},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:j}})),"undefined"!=typeof window&&(window.__THREE__||(window.__THREE__=j));class vu{#r=null;#a=-1;bounds=new Float32Array(6);get is_linked(){return-1!==this.#a}link(t,e){this.#r=t;const i=t.allocate_node();this.#a=i,t.node_set_aabb(i,this.bounds),t.node_set_user_data(i,e),t.insert_leaf(i)}unlink(){const t=this.#a;this.#r.remove_leaf(t),this.#r.release_node(t),this.#a=-1,this.#r=null}write_bounds(){null!==this.#r&&this.#r.node_move_aabb(this.#a,this.bounds)}resize(t,e,i,n,s,r){yu(this.bounds,0,t,e,i,n,s,r),this.write_bounds()}}class xu extends Error{constructor(t){super(t)}}class wu{normal=new L(0,1,0);position=new L(0,0,0);index=-1;get 0(){return this.position.x}get 1(){return this.position.y}get 2(){return this.position.z}get 3(){return this.normal.x}get 4(){return this.normal.y}get 5(){return this.normal.z}applyMatrix4(t){this.position.applyMatrix4(t),this.normal.applyDirectionMatrix4(t)}applyMatrix4_three(t){this.applyMatrix4(t.elements)}fromArray(t,e=0){this.position.readFromArray(t,e),this.normal.readFromArray(t,e+3)}toArray(t,e=0){this.position.writeToArray(t,e),this.normal.writeToArray(t,e+3)}equals(t){return this.index===t.index&&this.position.equals(t.position)&&this.normal.equals(t.normal)}copy(t){this.position.copy(t.position),this.normal.copy(t.normal),this.index=t.index}clone(){const t=new wu;return t.copy(this),t}}function bu(t,e){return t<e?e:t}function Su(t,e){return t<e?t:e}function Mu(t,e){return t*t+e*e}function Tu(t,e){return Math.sqrt(Mu(t,e))}function Au(t,e,i,n){return Tu(i-t,n-e)}function Cu(t,e,i,n){return t*i+e*n}class Eu{constructor(t=0,e=0){this.x=t,this.y=e,this.onChanged=new _}fromArray(t,e=0){this.set(t[e],t[e+1])}toArray(t,e=0){t[e]=this.x,t[e+1]=this.y}asArray(){const t=[];return this.writeToArray(t,0),t}set(t,e){const i=this.x,n=this.y;return i===t&&n===e||(this.x=t,this.y=e,this.onChanged.hasHandlers()&&this.onChanged.send4(t,e,i,n)),this}setSilent(t,e){this.x=t,this.y=e}setX(t){return this.set(t,this.y)}setY(t){return this.set(this.x,t)}_sub(t,e){return this.set(this.x-t,this.y-e)}sub(t){return this._sub(t.x,t.y)}subVectors(t,e){this.set(t.x-e.x,t.y-e.y)}floor(){return this.set(Math.floor(this.x),Math.floor(this.y))}ceil(){return this.set(Math.ceil(this.x),Math.ceil(this.y))}round(){const t=Math.round(this.x),e=Math.round(this.y);this.set(t,e)}abs(){return this.set(Math.abs(this.x),Math.abs(this.y))}_mod(t,e){return this.set(this.x%t,this.y%e)}mod(t){return this._mod(t.x,t.y)}divide(t){return this.set(this.x/t.x,this.y/t.y)}multiply(t){return this._multiply(t.x,t.y)}_multiply(t,e){return this.set(this.x*t,this.y*e)}max(t){const e=bu(this.x,t.x),i=bu(this.y,t.y);return this.set(e,i)}dot(t){return Cu(this.x,this.y,t.x,t.y)}copy(t){return this.set(t.x,t.y)}clone(){return new Eu(this.x,this.y)}negate(){return this.set(-this.x,-this.y)}_add(t,e){return this.set(this.x+t,this.y+e)}add(t){return this._add(t.x,t.y)}addScalar(t){return this._add(t,t)}setScalar(t){this.set(t,t)}divideScalar(t){this.multiplyScalar(1/t)}multiplyScalar(t){return this.set(this.x*t,this.y*t)}toJSON(){return{x:this.x,y:this.y}}fromJSON(t){if("number"==typeof t)this.set(t,t);else{const{x:e=0,y:i=0}=t;this.set(e,i)}}toBinaryBuffer(t){t.writeFloat64(this.x),t.writeFloat64(this.y)}fromBinaryBuffer(t){const e=t.readFloat64(),i=t.readFloat64();this.set(e,i)}toBinaryBufferFloat32(t){t.writeFloat32(this.x),t.writeFloat32(this.y)}fromBinaryBufferFloat32(t){const e=t.readFloat32(),i=t.readFloat32();this.set(e,i)}isZero(){return 0===this.x&&0===this.y}clamp(t,e,i,n){const s=g(this.x,t,i),r=g(this.y,e,n);return this.set(s,r)}clampLow(t,e){const i=bu(this.x,t),n=bu(this.y,e);return this.set(i,n)}clampHigh(t,e){const i=Su(this.x,t),n=Su(this.y,e);return this.set(i,n)}distanceSqrTo(t){return this._distanceSqrTo(t.x,t.y)}lerpVectors(t,e,i){const n=w(t.x,e.x,i),s=w(t.y,e.y,i);this.set(n,s)}applyMatrix3(t){const e=this.x,i=this.y,n=t[0]*e+t[3]*i+t[6],s=t[1]*e+t[4]*i+t[7];this.set(n,s)}distanceTo(t){return this._distanceTo(t.x,t.y)}_distanceSqrTo(t,e){return Mu(this.x-t,this.y-e)}_distanceTo(t,e){return Math.sqrt(this._distanceSqrTo(t,e))}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}length(){return Tu(this.x,this.y)}normalize(){const t=this.length();if(0===t)return;const e=1/t;this.multiplyScalar(e)}hash(){const t=S(this.x);return(t<<5)-t+S(this.y)}rotate(t){const e=Math.sin(t),i=Math.cos(t),n=this.x,s=this.y,r=n*i-s*e,a=n*e+s*i;this.set(r,a)}process(t,e){return t.call(e,this.x,this.y),this.onChanged.add(t,e),this}toString(){return`Vector2{ x:${this.x}, y:${this.y} }`}equals(t){return this.x===t.x&&this.y===t.y}roughlyEquals(t,e){return this._roughlyEquals(t.x,t.y,e)}_roughlyEquals(t,e,i=v){return x(this.x,t,i)&&x(this.y,e,i)}get 0(){return this.x}get 1(){return this.y}set 0(t){this.x=t}set 1(t){this.y=t}*[Symbol.iterator](){yield this.x,yield this.y}}Eu.up=Object.freeze(new Eu(0,1)),Eu.down=Object.freeze(new Eu(0,-1)),Eu.left=Object.freeze(new Eu(-1,0)),Eu.right=Object.freeze(new Eu(1,0)),Eu.zero=Object.freeze(new Eu(0,0)),Eu.one=Object.freeze(new Eu(1,1)),Eu.prototype.isVector2=!0,Eu._distance=Au,Eu.prototype.writeToArray=Eu.prototype.toArray,Eu.prototype.readFromArray=Eu.prototype.fromArray;const zu="texture",Iu="json",Lu="image",Nu=["float rand(float v){"," return fract(sin(v) * 43758.5453);","}"].join("\n"),Pu=["#ifdef SHADOWMAP_CLOUDS"," uniform float f_CloudsTime;"," uniform vec2 v_CloudsSpeed_0;"," uniform vec2 v_CloudsSpeed_1;"," uniform vec2 v_CloudsSpeed_2;"," uniform vec2 v_CloudsSize_0;"," uniform vec2 v_CloudsSize_1;"," uniform vec2 v_CloudsSize_2;"," varying vec2 v_Clouds_0_offset;"," varying vec2 v_Clouds_1_offset;"," varying vec2 v_Clouds_2_offset;","#endif"].join("\n"),Du=["#ifdef SHADOWMAP_CLOUDS"," vec2 cloudsUV = worldPosition.xz;"," v_Clouds_0_offset = (v_CloudsSpeed_0 * f_CloudsTime + cloudsUV) / v_CloudsSize_0;"," v_Clouds_1_offset = (v_CloudsSpeed_1 * f_CloudsTime + cloudsUV) / v_CloudsSize_1;"," v_Clouds_2_offset = (v_CloudsSpeed_2 * f_CloudsTime + cloudsUV) / v_CloudsSize_2;","#endif"].join("\n"),Fu=["#ifdef SHADOWMAP_CLOUDS"," varying vec2 v_Clouds_0_offset;"," varying vec2 v_Clouds_1_offset;"," varying vec2 v_Clouds_2_offset;"," uniform sampler2D t_Clouds_0;"," uniform sampler2D t_Clouds_1;"," uniform sampler2D t_Clouds_2;"," uniform float f_CloudsAmount;"," uniform float f_CloudsIntensity;","#endif"].join("\n"),Ou=["#ifdef SHADOWMAP_CLOUDS"," vec4 shadowmapCloudsColor = texture2D(t_Clouds_0, v_Clouds_0_offset) * texture2D(t_Clouds_1, v_Clouds_1_offset) * texture2D(t_Clouds_2, v_Clouds_2_offset);"," float shadowmapCloudsIntensity = min( max(shadowmapCloudsColor.r-(1.0-f_CloudsAmount),0.0)*(1.0/f_CloudsAmount), 0.05 ) * 20.0;"," reflectedLight.directDiffuse *= mix(1.0, 1.0-f_CloudsIntensity, shadowmapCloudsIntensity);","#endif"].join("\n");["#ifdef USE_MAP"," vec4 texelColor = texture2D( map, vUv );"," texelColor = GammaToLinear( texelColor, float( GAMMA_FACTOR ) );"," \tdiffuseColor *= texelColor;","#endif"].join("\n");const Ru={vertexShader:`\n #define PHYSICAL\n #define STANDARD\n \n uniform vec2 gridResolution;\n \n uniform vec4 uGridTransform;\n \n varying vec3 vViewPosition;\n varying vec2 vGridPosition;\n \n #ifndef FLAT_SHADED\n varying vec3 vNormal;\n #endif\n \n varying vec2 vUv;\n varying vec2 vUvGrid;\n uniform vec4 offsetRepeat;\n \n #include <common>\n #include <uv_pars_vertex>\n #include <uv2_pars_vertex>\n #include <color_pars_vertex>\n #include <fog_pars_vertex>\n #include <morphtarget_pars_vertex>\n #include <skinning_pars_vertex>\n #include <shadowmap_pars_vertex>\n #include <logdepthbuf_pars_vertex>\n #include <clipping_planes_pars_vertex>\n \n ${Pu}\n \n void main() {\n \n vUv = uv;\n #if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = uv;\n #endif\n \n vGridPosition = (position.xz - uGridTransform.zw) / uGridTransform.xy;\n vUvGrid = vGridPosition / gridResolution;\n \n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n \n #ifndef FLAT_SHADED // Normal computed with derivatives when FLAT_SHADED\n vNormal = normalize( transformedNormal );\n #endif\n \n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n\t \n\t vViewPosition = - mvPosition.xyz;\n \n #if defined( SHADOWMAP_CLOUDS ) && !(defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ))\n vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n #endif\n \n #include <worldpos_vertex>\n \n \n #include <shadowmap_vertex>\n #include <fog_vertex>\n \n ${Du}\n \n }\n `,fragmentShader:`\n #define PHYSICAL\n #define STANDARD\n \n #ifdef PHYSICAL\n //#define IOR\n //#define SPECULAR\n #endif\n \n #ifdef IOR\n uniform float ior;\n #endif\n precision highp sampler2DArray;\n \n uniform sampler2DArray splatWeightMap;\n uniform int splatLayerCount;\n \n uniform vec2 splatResolution;\n \n uniform sampler2D materialScalesMap;\n \n uniform sampler2DArray diffuseMaps;\n\n uniform sampler2D diffuseGridOverlaySprite;\n uniform sampler2D diffuseGridOverlayMap;\n \n uniform vec2 gridResolution;\n uniform float gridBorderWidth;\n uniform vec4 offsetRepeat;\n\n uniform vec3 diffuse;\n uniform vec3 emissive;\n uniform float opacity;\n \n varying vec3 vViewPosition;\n \n\n #include <common>\n #include <packing>\n #include <dithering_pars_fragment>\n #include <color_pars_fragment>\n \n varying vec2 vUv;\n varying vec2 vUvGrid;\n varying vec2 vGridPosition;\n \n #include <uv2_pars_fragment>\n #include <alphamap_pars_fragment>\n #include <alphatest_pars_fragment>\n #include <aomap_pars_fragment>\n #include <lightmap_pars_fragment>\n #include <emissivemap_pars_fragment>\n #include <bsdfs>\n #include <cube_uv_reflection_fragment>\n #include <envmap_common_pars_fragment>\n #include <envmap_physical_pars_fragment>\n #include <fog_pars_fragment>\n #include <lights_pars_begin>\n \n #ifndef FLAT_SHADED\n varying vec3 vNormal;\n \n #ifdef USE_TANGENT\n varying vec3 vTangent;\n varying vec3 vBitangent;\n #endif\n \n #endif\n \n #include <lights_physical_pars_fragment>\n #include <transmission_pars_fragment>\n #include <shadowmap_pars_fragment>\n #include <bumpmap_pars_fragment>\n #include <clearcoat_pars_fragment>\n #include <roughnessmap_pars_fragment>\n #include <metalnessmap_pars_fragment>\n #include <logdepthbuf_pars_fragment>\n #include <clipping_planes_pars_fragment>\n \n ${Nu}\n \n vec4 blendSplatTextures(const in vec4 tex0, const in vec4 tex1, const in vec4 tex2, const in vec4 tex3, const in vec4 splat){\n \n float b0 = splat[0];\n \n float b1 = splat[1];\n \n float b2 = splat[2];\n \n float b3 = splat[3];\n \n return (tex0*b0 + tex1*b1 + tex2*b2 + tex3*b3) / (b0 + b1 + b2 + b3);\n }\n \n void randomBlend(in vec2 uv, inout vec3 v, float level){\n vec3 noise = vec3( rand(uv.x*12.9898 + uv.y*78.233), rand(uv.x*10.9898 + uv.y*73.233) , rand(uv.x*6.9898 + uv.y*71.233));\n v = v*(1.0 - level) + noise*level;\n }\n \n vec3 AdjustContrastCurve(vec3 color, float contrast) {\n float p = 1.0 / max(contrast, 0.0001);\n vec3 v = abs(color * 2.0 - 1.0);\n return pow(v, vec3(p)) * sign(color - 0.5) + 0.5;\n }\n \n vec3 AdjustSaturation(vec3 rgb, float adjustment){\n const vec3 W = vec3(0.2125, 0.7154, 0.0721);\n vec3 intensity = vec3(dot(rgb, W));\n return mix(intensity, rgb, adjustment);\n }\n \n vec4 blendAlpha(in vec4 source, in vec4 target){\n return source*(1.0 - target.a) + vec4(target.rgb*target.a , target.a);\n }\n \n vec4 blendAdd(in vec4 source, in vec4 target){\n return source + target;\n } \n \n vec4 blendAddAlpha(in vec4 source, in vec4 target){\n \n vec4 a = blendAlpha(source, target);\n vec4 b = blendAdd(source, target);\n \n return mix(a, b, target.a);\n }\n \n vec3 rgb2hsv(vec3 c){\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n \n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n }\n \n vec3 hsv2rgb(vec3 c){\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n }\n \n const mat3 rgb2yiq = mat3(0.299, 0.587, 0.114, 0.595716, -0.274453, -0.321263, 0.211456, -0.522591, 0.311135);\n const mat3 yiq2rgb = mat3(1.0, 0.9563, 0.6210, 1.0, -0.2721, -0.6474, 1.0, -1.1070, 1.7046);\n\n vec3 brighten(const in vec3 color, in float factor){\n //vec3 yiq = rgb2yiq*color;\n \n //yiq.x *= factor;\n \n //return yiq2rgb * yiq;\n \n vec3 hsv = rgb2hsv(color);\n \n hsv.z *= factor;\n \n return hsv2rgb(hsv);\n }\n \n vec3 brighten2(const in vec3 color, in float factor, float p){\n vec3 yiq = rgb2yiq*color;\n \n yiq.x *= p;\n yiq.x = pow(yiq.x,factor);\n \n return yiq2rgb * yiq;\n }\n \n vec4 computeGridOverlayTexel(const in vec2 grid_uv, const in vec2 grid_resolution){\n vec2 grid_texel = vGridPosition + 0.5;\n \n vec2 uv = grid_texel / grid_resolution;\n \n vec4 tile_data = texture2D(diffuseGridOverlayMap, uv);\n \n if(tile_data.a == 0.0){\n return vec4(0.0);\n }\n \n vec2 tile_uv = mod(grid_texel , 1.0);\n \n vec4 tile_color = texture2D(diffuseGridOverlaySprite, tile_uv);\n \n if(tile_color.a <= 0.01){\n return vec4(0.0);\n }\n \n return tile_color * tile_data;\n }\n \n vec4 computeSplatMix(vec2 uv){\n \n float weightSum = 0.0;\n vec4 colorSum = vec4(0.0);\n \n for( int i = 0; i < splatLayerCount; i++){\n \n vec2 scale = texelFetch(materialScalesMap, ivec2(i, 0), 0 ).xy;\n \n vec2 layerUv = vUv * scale;\n \n vec4 diffuseData = texture(diffuseMaps, vec3(layerUv, i) );\n \n float weight = texture(splatWeightMap, vec3(uv, i)).x;\n \n weightSum += weight;\n colorSum += diffuseData*weight;\n }\n \n return colorSum / weightSum; \n }\n \n ${Fu}\n \n out highp vec4 pc_fragColor;\n \n void main() { \n vec4 splatDiffuseColor = computeSplatMix(vUv);\n \n //decode the texture\n splatDiffuseColor = sRGBToLinear( splatDiffuseColor );\n \n //ensure it is fully opaque\n splatDiffuseColor.a = 1.0;\n \n #ifdef DIFFUSE_GRAIN\n randomBlend(vUv, splatDiffuseColor.rgb, 0.03);\n #endif\n \n vec4 gridOverlayColor = computeGridOverlayTexel(vUvGrid, gridResolution);\n \n #include <clipping_planes_fragment>\n \n vec4 diffuseColor = blendAlpha( splatDiffuseColor, gridOverlayColor );\n \n #ifdef USE_AOMAP\n \n vec4 aoShadowMapTexel = texture2D( aoMap, vUv2 );\n \n diffuseColor *= aoShadowMapTexel.r;\n \n #endif\n \n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n \n #include <logdepthbuf_fragment>\n \n // make surface completely diffuse\n float roughnessFactor = 1.0;\n float metalnessFactor = 0.0;\n \n #include <normal_fragment_begin>\n #include <emissivemap_fragment>\n \n vec3 rawDiffuseColor = diffuseColor.rgb;\n \n // accumulation\n #include <lights_physical_fragment>\n #include <lights_fragment_begin>\n #include <lights_fragment_maps>\n #include <lights_fragment_end>\n \n ${Ou}\n \n // modulation\n #include <aomap_fragment>\n \n \n vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n \n vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n \n pc_fragColor = vec4( outgoingLight, diffuseColor.a );\n \n #if defined( TONE_MAPPING )\n pc_fragColor.rgb = toneMapping( pc_fragColor.rgb );\n #endif\n \n //encode fragment\n pc_fragColor = linearToOutputTexel( pc_fragColor );\n #ifdef USE_FOG\n #ifdef FOG_EXP2\n float fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth );\n #else\n float fogFactor = smoothstep( fogNear, fogFar, fogDepth );\n #endif\n pc_fragColor.rgb = mix( pc_fragColor.rgb, fogColor, fogFactor );\n #endif\n \n #ifdef PREMULTIPLIED_ALPHA\n // Get get normal blending with premultipled, use with CustomBlending, OneFactor, OneMinusSrcAlphaFactor, AddEquation.\n pc_fragColor.rgb *= pc_fragColor.a;\n #endif\n \n #ifdef DITHERING\n pc_fragColor.rgb = dithering( pc_fragColor.rgb );\n #endif\n }\n `};function ku({gridResolution:t,splatMap:e,diffuseMaps:i,lightMap:n}){const s=ir.merge([wr.common,wr.specularmap,wr.envmap,wr.aomap,wr.lightmap,wr.emissivemap,wr.fog,wr.lights,{splatWeightMap:{type:"t",value:null},splatLayerCount:{type:"f",value:4},splatResolution:{type:"v2",value:new Ri(1,1)},gridResolution:{type:"v2",value:new Ri(1,1)},uGridTransform:{type:"v4",value:new ji},gridBorderWidth:{type:"f",value:.1},materialScalesMap:{type:"t",value:null},diffuseMaps:{type:"t",value:null},diffuseGridOverlayMap:{type:"t",value:null},diffuseGridOverlaySprite:{type:"t",value:function(t,e){const i=new Fl(new Uint8Array([255,255,255,255]),1,1);return i.generateMipmaps=!1,i.needsUpdate=!0,i.type=ee,i}()}},{emissive:{type:"c",value:new ys(0)},specular:{type:"c",value:new ys(16777215)},shininess:{type:"f",value:0},envMapIntensity:{value:1}},{f_CloudsTime:{type:"f",value:0},f_CloudsAmount:{type:"f",value:.9},f_CloudsIntensity:{type:"f",value:.3},v_CloudsSpeed_0:{type:"v2",value:new Ri(.03,-.03)},v_CloudsSpeed_1:{type:"v2",value:new Ri(.011,-.011)},v_CloudsSpeed_2:{type:"v2",value:new Ri(.023,-.023)},v_CloudsSize_0:{type:"v2",value:new Ri(40,40)},v_CloudsSize_1:{type:"v2",value:new Ri(20,20)},v_CloudsSize_2:{type:"v2",value:new Ri(10,10)},t_Clouds_0:{type:"t",value:null},t_Clouds_1:{type:"t",value:null},t_Clouds_2:{type:"t",value:null}}]);void 0!==t&&s.gridResolution.value.set(t.x,t.y);const r=new nr({uniforms:s,vertexShader:Ru.vertexShader,fragmentShader:Ru.fragmentShader,side:K,blending:it,depthTest:!0,depthWrite:!0,transparent:!1,lights:!0,defines:{SHADOWMAP_CLOUDS:!1,DIFFUSE_GRAIN:!1},glslVersion:Ai});return r.depthWrite=!0,r.transparent=!1,s.diffuse.value=new ys(16777215),void 0!==e&&(e.wrapS=e.wrapT=Jt,e.minFilter=Kt,e.magFilter=Kt,s.splatMap.value=e),void 0!==i&&(s.diffuseMaps.value=i),void 0!==n&&(r.aoMap=!0,s.aoMap.value=n,s.aoMapIntensity.value=.7),r.extensions.derivatives=!0,r.needsUpdate=!0,r.isSplatMaterial=!0,r}const Bu=[],Uu=[],Vu="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let t=0,e=64;t<e;++t)Bu[t]=Vu[t],Uu[Vu.charCodeAt(t)]=t;function Wu(t,e,i){const n=[];for(let r=e;r<i;r+=3){const e=(t[r]<<16&16711680)+(t[r+1]<<8&65280)+(255&t[r+2]);n.push(Bu[(s=e)>>18&63]+Bu[s>>12&63]+Bu[s>>6&63]+Bu[63&s])}var s;return n.join("")}Uu["-".charCodeAt(0)]=62,Uu["_".charCodeAt(0)]=63;const Gu=16383;class Hu{static encode(t){return function(t){const e=t.length,i=e%3,n=[],s=e-i;for(let e=0;e<s;e+=Gu){const i=Wu(t,e,e+Gu>s?s:e+Gu);n.push(i)}if(1===i){const i=t[e-1];n.push(Bu[i>>2]+Bu[i<<4&63]+"==")}else if(2===i){const i=(t[e-2]<<8)+t[e-1];n.push(Bu[i>>10]+Bu[i>>4&63]+Bu[i<<2&63]+"=")}return n.join("")}(new Uint8Array(t))}static decode(t){return function(t){let e;const i=function(t){const e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");let i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}(t),n=i[0],s=i[1],r=new Uint8Array(function(t,e){return 3*(t+e)/4-e}(n,s));let a=0;const o=s>0?n-4:n;let l=0;for(;l<o;l+=4){const i=t.charCodeAt(l),n=t.charCodeAt(l+1),s=t.charCodeAt(l+2),o=t.charCodeAt(l+3);e=Uu[i]<<18|Uu[n]<<12|Uu[s]<<6|Uu[o],r[a++]=e>>16&255,r[a++]=e>>8&255,r[a++]=255&e}if(2===s){const i=t.charCodeAt(l),n=t.charCodeAt(l+1);e=Uu[i]<<2|Uu[n]>>4,r[a++]=255&e}if(1===s){const i=t.charCodeAt(l),n=t.charCodeAt(l+1),s=t.charCodeAt(l+2);e=Uu[i]<<10|Uu[n]<<4|Uu[s]>>2,r[a++]=e>>8&255,r[a++]=255&e}return r}(t).buffer}}const ju={Uint8:"uint8",Uint16:"uint16",Uint32:"uint32",Uint64:"uint64",Int8:"int8",Int16:"int16",Int32:"int32",Int64:"int64",Float16:"float16",Float32:"float32",Float64:"float64"},qu={[ju.Uint8]:Uint8Array,[ju.Uint16]:Uint16Array,[ju.Uint32]:Uint32Array,[ju.Int8]:Int8Array,[ju.Int16]:Int16Array,[ju.Int32]:Int32Array,[ju.Float16]:Uint16Array,[ju.Float32]:Float32Array,[ju.Float64]:Float64Array};function Ju(t){const e=Object.getPrototypeOf(t).constructor;switch(e){case Uint8Array:case Uint8ClampedArray:return ju.Uint8;case Uint16Array:return ju.Uint16;case Uint32Array:return ju.Uint32;case Int8Array:return ju.Int8;case Int16Array:return ju.Int16;case Int32Array:return ju.Int32;case Float32Array:return ju.Float32;case Float64Array:return ju.Float64;default:throw new Error(`unsupported constructor type ${e.name}`)}}function $u(t,e,i){const n=t|e|i;return 0==(3&n)?4:0==(1&n)?2:1}function Yu(t,i){if(t===i)return!0;const n=t.length;if(n!==i.length)return!1;const s=t.constructor;if(s!==i.constructor)return!1;if(0===n)return!0;if(n<128)return e(t,i);const r=t.byteLength;if(r!==i.byteLength)return!1;const a=t.buffer,o=i.buffer,l=t.byteOffset,h=i.byteOffset;if(a===o&&l===h)return!0;let c=t,u=i;const d=s.BYTES_PER_ELEMENT,p=$u(l,h,r);return d<4&&4===p?(c=new Uint32Array(a,l,r>>>2),u=new Uint32Array(o,h,r>>>2)):d<2&&2===p&&(c=new Uint16Array(a,l,r>>>1),u=new Uint16Array(o,h,r>>>1)),e(c,u)}function Xu(t,e,i,n,s){return.5*(n-e+(2*e-5*i+4*n-s+(3*(i-n)+s-e)*t)*t)*t+i}class Zu{constructor(t=[],e=1,i=0,n=0){if(!Number.isInteger(e)||e<0)throw new Error(`itemSize must be a non-negative integer, instead was ${e}`);if(!Number.isInteger(i)||i<0)throw new Error(`width must be a non-negative integer, instead was ${i}`);if(!Number.isInteger(n)||i<0)throw new Error(`height must be a non-negative integer, instead was ${n}`);if(void 0===t)throw new Error("data was undefined");if(t.length<i*n*e)throw new Error(`Buffer underflow, data.length(=${t.length}) is too small. Expected at least ${i*n*e}`);this.width=i,this.height=n,this.itemSize=e,this.data=t,this.version=0}sampleCatmullRomUV(t,e,i){const n=this.itemSize;for(let s=0;s<n;s++)i[s]=this.sampleChannelCatmullRomUV(t,e,s)}sampleChannelCatmullRomUV(t,e,i){const n=t*this.width-.5,s=e*this.height-.5;return this.sampleChannelCatmullRom(n,s,i)}sampleChannelCatmullRom(t,e,i){const n=Math.floor(t),s=Math.floor(e),r=t-n,a=e-s,o=r*(r*(1-.5*r)-.5),l=a*(a*(1-.5*a)-.5),h=r*(.5+r*(2-1.5*r)),c=a*(.5+a*(2-1.5*a)),u=r*r*(.5*r-.5),d=a*a*(.5*a-.5),p=1+r*r*(1.5*r-2.5)+h,f=1+a*a*(1.5*a-2.5)+c,m=n-1,_=s-1,g=n+2,y=s+2,v=n+h/p,x=s+c/f;let w=0;return w+=this.sampleChannelBilinear(m,_,i)*o*l,w+=this.sampleChannelBilinear(v,_,i)*p*l,w+=this.sampleChannelBilinear(g,_,i)*u*l,w+=this.sampleChannelBilinear(m,x,i)*o*f,w+=this.sampleChannelBilinear(v,x,i)*p*f,w+=this.sampleChannelBilinear(g,x,i)*u*f,w+=this.sampleChannelBilinear(m,y,i)*o*d,w+=this.sampleChannelBilinear(v,y,i)*p*d,w+=this.sampleChannelBilinear(g,y,i)*u*d,w}sampleBicubicUV(t,e,i){const n=this.itemSize;for(let s=0;s<n;s++)i[s]=this.sampleChannelBicubicUV(t,e,s)}sampleBicubic(t,e,i,n){const s=this.itemSize;for(let r=0;r<s;r++)i[r+n]=this.sampleChannelBicubic(t,e,r)}sampleChannelBicubicUV(t,e,i){const n=t*this.width,s=e*this.height;return this.sampleChannelBicubic(n-.5,s-.5,i)}sampleChannelBicubic(t,e,i){const n=this.itemSize,s=this.width,r=this.height,a=this.data,o=s*n,l=s-1,h=r-1,c=g(t,0,l),u=g(e,0,h),d=0|c,p=0|u,f=c-d,m=u-p,_=bu(0,d-1),y=bu(0,p-1),v=Su(l,d+1),x=Su(h,p+1),w=Su(l,v+1),b=y*o+i,S=p*o+i,M=x*o+i,T=Su(h,x+1)*o+i,A=_*n,C=d*n,E=v*n,z=w*n,I=a[b+A],L=a[b+C],N=a[b+E],P=a[b+z],D=a[S+A],F=a[S+C],O=a[S+E],R=a[S+z],k=a[M+A],B=a[M+C],U=a[M+E],V=a[M+z],W=a[T+A],G=a[T+C],H=a[T+E],j=a[T+z],q=Xu(f,I,L,N,P),J=Xu(f,D,F,O,R),$=Xu(f,k,B,U,V),Y=Xu(f,W,G,H,j);return Xu(m,q,J,$,Y)}sampleBilinearUV(t,e,i,n=0){const s=this.itemSize;for(let r=0;r<s;r++)i[r+n]=this.sampleChannelBilinearUV(t,e,r)}sampleBilinear(t,e,i,n=0){const s=this.itemSize;for(let r=0;r<s;r++)i[r+n]=this.sampleChannelBilinear(t,e,r)}sampleChannelBilinearUV(t,e,i){const n=t*this.width-.5,s=e*this.height-.5;return this.sampleChannelBilinear(n,s,i)}sampleChannelBilinear(t,e,i){const n=this.itemSize,s=this.width,r=s*n,a=this.height-1,o=g(t,0,s-1),l=g(e,0,a),h=o>>>0,c=l>>>0,u=c*r,d=h*n+i,p=u+d;let f,m;f=o===h?h:h+1,m=l===c?c:c+1;const _=this.data,y=_[p];if(h===f&&c===m)return y;const v=o-h,x=l-c,b=f*n+i,S=m*r,M=S+d,T=S+b,A=_[u+b],C=_[M],E=_[T],z=w(y,A,v),I=w(C,E,v);return w(z,I,x)}sampleNearestUV(t,e,i){const n=this.width,s=this.height,r=Math.round(t*n-.5),a=Math.round(e*s-.5);this.read(g(r,0,n-1),g(a,0,s-1),i)}readChannel(t,e,i){const n=(e*this.width+t)*this.itemSize+i;return this.data[n]}read(t,e,i){const n=this.width,s=this.itemSize,r=(e*n+t)*s;for(let t=0;t<s;t++)i[t]=this.data[r+t]}write(t,e,i){const n=this.width,s=this.itemSize,r=(e*n+t)*s;for(let t=0;t<s;t++)this.data[r+t]=i[t]}point2index(t,e){return t+e*this.width}index2point(t,e){const i=this.width,n=t%i,s=t/i|0;e.set(n,s)}copy(t,e,i,n,s,r,a){const o=Math.min(r,t.width-e,this.width-n),l=Math.min(a,t.height-i,this.height-s),h=this.itemSize,c=t.itemSize,u=Math.min(h,c),d=h*this.width,p=c*t.width,f=t.data,m=this.data;let _,g,y;for(g=0;g<l;g++){const t=(g+s)*d,r=(g+i)*p;for(_=0;_<o;_++){const i=t+(_+n)*h,s=r+(_+e)*c;for(y=0;y<u;y++)m[i+y]=f[s+y]}}this.version++}zeroFill(t,e,i,n){const s=g(t,0,this.width),r=g(e,0,this.height),a=g(t+i,0,this.width),o=g(e+n,0,this.height),l=this.data,h=this.itemSize,c=h*this.width,u=s*h,d=a*h;let p;for(p=r;p<o;p++){const t=p*c;l.fill(0,t+u,t+d)}this.version++}channelFill(t,e){const i=this.itemSize,n=this.data,s=n.length;for(let r=t;r<s;r+=i)n[r]=e;this.version++}fill(t,e,i,n,s){const r=this.width,a=this.height,o=g(t,0,r),l=g(e,0,a),h=g(t+i,0,r),c=g(e+n,0,a),u=this.data,d=this.itemSize,p=d*r;let f,m,_;for(f=l;f<c;f++){const t=f*p;for(m=o;m<h;m++){const e=t+m*d;for(_=0;_<d;_++)u[e+_]=s[_]}}this.version++}writeChannel(t,e,i,n){const s=(e*this.width+t)*this.itemSize+i;this.data[s]=n,this.version++}set(t,e,i){const n=this.data,s=this.itemSize,r=s*this.width*e+t*s;for(let t=0;t<s;t++)n[r+t]=i[t];this.version++}traverseCircle(t,e,i,n){let s,r;const a=0|t,o=0|e,l=i*i,h=Math.ceil(i);for(r=-h;r<=h;r++){const t=r*r;for(s=-h;s<=h;s++)s*s+t<=l&&n(a+s,o+r,this)}}resize(t,e,i=!0){const n=this.width,s=this.height;if(n===t&&s===e)return;const r=this.itemSize,a=t*e*r,o=this.data,l=new(function(t){if(t instanceof Int8Array)return Int8Array;if(t instanceof Int16Array)return Int16Array;if(t instanceof Int32Array)return Int32Array;if(t instanceof Uint8Array)return Uint8Array;if(t instanceof Uint8ClampedArray)return Uint8ClampedArray;if(t instanceof Uint16Array)return Uint16Array;if(t instanceof Uint32Array)return Uint32Array;if(t instanceof Float32Array)return Float32Array;if(t instanceof Float64Array)return Float64Array;if(Array.isArray(t))return Array;throw new TypeError("Unsupported array type")}(o))(a);if(i)if(t===n)l.set(o.subarray(0,Math.min(o.length,a)));else{const i=Su(e,s),a=Su(t,n);for(let e=0;e<i;e++)for(let i=0;i<a;i++){const s=(e*t+i)*r,a=(e*n+i)*r;for(let t=0;t<r;t++)l[s+t]=o[a+t]}}this.width=t,this.height=e,this.data=l,this.version++}computeByteSize(){let t;const e=this.data;return t=Array.isArray(e)?8*e.length:e.buffer.byteLength,t+280}equals(t){return this===t||this.width===t.width&&this.height===t.height&&this.itemSize===t.itemSize&&Yu(this.data,t.data)}hash(){let t=((65535&this.width)<<16|65535&this.height)^this.itemSize;const e=this.data.length;return t^=function(t,e,i,n=31){const s=Su(i,1024);return function(t,e,i,n,s,r){let a=i;for(let e=0;e<i;e+=n)a=(a<<5)-a+s.call(void 0,t[e]);return a>>>0}(t,0,s,Math.max(1,Math.ceil(s/n)),S)}(this.data,0,e,509),t}clone(){let t;return t=Array.isArray(this.data)?this.data.slice():new(0,this.data.constructor)(this.data),new Zu(t,this.itemSize,this.width,this.height)}toJSON(){const t=Hu.encode(this.data.buffer);return{height:this.height,width:this.width,itemSize:this.itemSize,type:Ju(this.data),data:t}}fromJSON({height:t,width:e,itemSize:i,type:n,data:s}){const r=function(t){const e=qu[t];if(void 0===e)throw new Error(`Unsupported data type '${t}'`);return e}(n);if("string"==typeof s){const t=Hu.decode(s);this.data=new r(t)}else{if(!Array.isArray(s))throw new Error("Unsupported data format");this.data=new r(s)}this.height=t,this.width=e,this.itemSize=i}static uint8clamped(t,e,i){const n=new Uint8ClampedArray(e*i*t);return new Zu(n,t,e,i)}static uint8(t,e,i){const n=new Uint8Array(e*i*t);return new Zu(n,t,e,i)}static uint16(t,e,i){const n=new Uint16Array(e*i*t);return new Zu(n,t,e,i)}static uint32(t,e,i){const n=new Uint32Array(e*i*t);return new Zu(n,t,e,i)}static int8(t,e,i){const n=new Int8Array(e*i*t);return new Zu(n,t,e,i)}static int16(t,e,i){const n=new Int16Array(e*i*t);return new Zu(n,t,e,i)}static int32(t,e,i){const n=new Int32Array(e*i*t);return new Zu(n,t,e,i)}static float32(t,e,i){const n=new Float32Array(e*i*t);return new Zu(n,t,e,i)}static float64(t,e,i){const n=new Float64Array(e*i*t);return new Zu(n,t,e,i)}}Zu.prototype.isSampler2D=!0,Zu.typeName="Sampler2D";const Ku="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAA1JREFUGFdj+P///38ACfsD/QVDRcoAAAAASUVORK5CYII=";function Qu(t){return Math.round(255*t)}function td(t){return t/255}function ed(t,e,i,n,s){let r,a,o;for(o=0;o<s;o++)r=e+o,a=n+o,i[a]=t[r]}class id extends Number{constructor(t=0){super(),this.x=t,this.onChanged=new _}valueOf(){return this.x}toString(){return String(this.x)}getValue(){return this.x}compareTo(t){return this.x-t.x}set(t){const e=this.x;return e!==t&&(this.x=t,this.onChanged.hasHandlers()&&this.onChanged.send2(t,e)),this}setSilent(t){this.x=t}isZero(){return 0===this.x}increment(){this._add(1)}decrement(){this._add(-1)}_add(t){return this.set(this.x+t)}add(t){return this._add(t.x)}_sub(t){return this._add(-t)}sub(t){return this._sub(t.x)}multiply(t){return this.set(this.x*t.x)}multiplyScalar(t){this.set(this.x*t)}clamp(t,e){return this.set(g(this.x,t,e))}negate(){this.set(-this.x)}copy(t){this.set(t.x)}clone(){return new id(this.x)}equals(t){return this.x===t.x}hash(){return S(this.x)}process(t){t(this.x,this.x),this.onChanged.add(t)}toJSON(){return this.x}fromJSON(t){this.set(t)}readFromArray(t,e=0){this.set(t[e])}writeToArray(t,e=0){t[e]=this.x}asArray(){return[this.x]}toBinaryBuffer(t){t.writeFloat64(this.x)}fromBinaryBuffer(t){const e=t.readFloat64();this.set(e)}static compare(t,e){return t.x-e.x}get 0(){return this.x}set 0(t){this.x=t}*[Symbol.iterator](){yield this.x}}function nd(...t){return function(t,e,i,n){let s=i;for(let e=0;e<i;e+=1)s=(s<<5)-s+(t[e]>>>0);return s>>>0}(t,0,t.length)}id.prototype.isVector1=!0,id.typeName="Vector1",id.zero=Object.freeze(new id(0)),id.one=Object.freeze(new id(1));class sd{constructor(t=0,e=0,i=0,n=0){this.x=t,this.y=e,this.z=i,this.w=n,this.onChanged=new _}get 0(){return this.x}get 1(){return this.y}get 2(){return this.z}get 3(){return this.w}readFromArray(t,e=0){this.set(t[e],t[e+1],t[e+2],t[e+3])}writeToArray(t,e=0){t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w}set(t,e,i,n){const s=this.x,r=this.y,a=this.z,o=this.w;return s===t&&r===e&&a===i&&o===n||(this.x=t,this.y=e,this.z=i,this.w=n,this.onChanged.hasHandlers()&&this.onChanged.send8(t,e,i,n,s,r,a,o)),this}multiplyVector3(t){const e=this.x*t.x,i=this.y*t.y,n=this.z*t.z;this.set(e,i,n,this.w)}multiplyScalar(t){return this.set(this.x*t,this.y*t,this.z*t,this.w*t)}_applyMatrix4(t,e,i,n,s,r,a,o,l,h,c,u,d,p,f,m){const _=this.x,g=this.y,y=this.z,v=this.w,x=t*_+s*g+l*y+d*v,w=e*_+r*g+h*y+p*v,b=i*_+a*g+c*y+f*v,S=n*_+o*g+u*y+m*v;return this.set(x,w,b,S)}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}add3(t){return this.set(this.x+t.x,this.y+t.y,this.z+t.z,this.w)}threeApplyMatrix4(t){const e=t.elements;return this._applyMatrix4(e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8],e[9],e[10],e[11],e[12],e[13],e[14],e[15])}copy(t){return this.set(t.x,t.y,t.z,t.w)}clone(){const t=new sd;return t.copy(this),t}applyQuaternion(t){const e=this.x,i=this.y,n=this.z,s=this.w,r=t.x,a=t.y,o=t.z,l=t.w,h=l*e+a*n-o*i,c=l*i+o*e-r*n,u=l*n+r*i-a*e,d=-r*e-a*i-o*n,p=h*l+d*-r+c*-o-u*-a,f=c*l+d*-a+u*-r-h*-o,m=u*l+d*-o+h*-a-c*-r;this.set(p,f,m,s)}equals(t){return this.x===t.x&&this.y===t.y&&this.z===t.z&&this.w===t.w}hash(){return nd(S(this.x),S(this.y),S(this.z),S(this.w))}lerpVectors(t,e,i){sd.lerp(t,e,i,this)}toArray(t){t[0]=this.x,t[1]=this.y,t[2]=this.z,t[3]=this.w}asArray(){const t=[];return this.toArray(t),t}setFromArray(t,e){this.set(t[e],t[e+1],t[e+2],t[e+3])}toJSON(){return{x:this.x,y:this.y,z:this.z,w:this.w}}fromJSON(t){this.copy(t)}toBinaryBuffer(t){t.writeFloat64(this.x),t.writeFloat64(this.y),t.writeFloat64(this.z),t.writeFloat64(this.w)}fromBinaryBuffer(t){const e=t.readFloat64(),i=t.readFloat64(),n=t.readFloat64(),s=t.readFloat64();this.set(e,i,n,s)}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}static lerp(t,e,i,n){const s=w(t.x,e.x,i),r=w(t.y,e.y,i),a=w(t.z,e.z,i),o=w(t.w,e.w,i);n.set(s,r,a,o)}}function rd(t,e,i){if(null===t)return 0;if(void 0===t)return 1;let n=e??0,s=i??t.length-n,r=s;const a=n+s;for(let e=n;e<a;e++)r=(r<<5)-r+t.charCodeAt(e);return r>>>0}class ad extends String{constructor(t=""){super(),this.__value=t,this.onChanged=new _}valueOf(){return this.__value}toString(){return this.__value}set(t){const e=this.__value;return e!==t&&(this.__value=t,this.onChanged.send2(t,e)),this}copy(t){this.set(t.getValue())}equals(t){return this.__value===t.__value}getValue(){return this.__value}process(t){t(this.getValue()),this.onChanged.add(t)}toJSON(){return this.__value}fromJSON(t){this.set(t)}toBinaryBuffer(t){t.writeUTF8String(this.__value)}fromBinaryBuffer(t){const e=t.readUTF8String();this.set(e)}hash(){return rd(this.__value)}}ad.prototype.isObservedString=!0;const od=new WeakMap;function ld(t){const e=t.width,i=t.height,n=function(t){let e=od.get(t);return void 0===e&&(e=t.getContext("2d"),od.set(t,e)),e}(t),s=n.getImageData(0,0,e,i).data;return new Zu(s,4,e,i)}function hd(t,e){const i=e.width,n=e.height,s=t.width/i,r=t.height/n,a=bu(1,Math.ceil(s)),o=bu(1,Math.ceil(r)),l=1/(a*o),h=t.itemSize,c=new Float32Array(h);let u,d,p,f,m;for(u=0;u<n;u++){const n=u*r;for(d=0;d<i;d++){const r=d*s,_=(u*i+d)*h;for(p=0;p<o;p++)for(f=0;f<a;f++)for(m=0;m<h;m++)c[m]+=t.sampleChannelBilinear(r+f,n+p,m);for(m=0;m<h;m++)e.data[_+m]=c[m]*l,c[m]=0}}}function cd(t,e){e.itemSize;const i=e.width,n=e.height,s=t.width,r=t.height;s===i&&r===n?e.data.set(t.data):s>i&&r>n?Number.isInteger(s/i)&&Number.isInteger(r/n)?function(t,e){const i=t.width,n=t.height,s=e.width,r=e.height,a=i/s,o=n/r,l=t.itemSize,h=new Float64Array(l),c=1/(a*o),u=t.data,d=e.data;for(let t=0;t<r;t++){const e=t*o,n=t*s*l;for(let t=0;t<s;t++){const s=n+t*l,r=t*a;for(let t=0;t<o;t++){let n=((e+t)*i+r)*l;for(let t=a;t>0;t--){for(let t=0;t<l;t++)h[t]+=u[t+n];n+=l}}for(let t=0;t<l;t++)d[s+t]=h[t]*c,h[t]=0}}}(t,e):hd(t,e):s<i&&r<n?function(t,e){const i=e.itemSize,n=e.width,s=e.height,r=t.width,a=t.height,o=e.data;if(r===n&&a===s)return void o.set(t.data);const l=i*n,h=r/n,c=a/s;for(let e=0;e<s;e++){const s=e*c,r=e*l;for(let e=0;e<n;e++){const n=r+e*i;t.sampleBilinear(e*h,s,o,n)}}}(t,e):hd(t,e)}function ud(t,e,i){const n=t[3]/255,s=e[3]/255;i[0]=t[0]*n+e[0]*(1-n),i[1]=t[1]*n+e[1]*(1-n),i[2]=t[2]*n+e[2]*(1-n),i[3]=255*(n+s*(1-n))}let dd=class{constructor(t,e,i){this.sampler=t,this.borderWidth=e,this.tileImage=i}};const pd=[0,0,0,0];class fd{constructor(t){this.borderWidth=new id(.1),this.size=new Eu(t.x,t.y),this.tileImage=new ad(Ku),this.sampler=Zu.uint8(4,t.x,t.y);const e=this.texture=new Fl(this.sampler.data);e.wrapS=Jt,e.wrapT=Jt,e.magFilter=Yt,e.minFilter=Yt,e.anisotropy=0,e.flipY=!1,e.repeat.set(1,1),e.needsUpdate=!0,e.generateMipmaps=!1,this.stack=[],this.size.onChanged.add(((t,e)=>{this.sampler.resize(t,e),this.texture.dispose(),this.texture.image.data=this.sampler.data,this.texture.image.width=t,this.texture.image.height=e}))}get baseTileImage(){return 0===this.stack.length?this.tileImage.getValue():this.stack[0].tileImage}set baseTileImage(t){0===this.stack.length?this.tileImage.set(t):this.stack[0].tileImage=t}get canvas(){throw new Error("Deprecated, used .sampler instead")}push(){const t=this.sampler.clone(),e=new dd(t,this.borderWidth.getValue(),this.tileImage.getValue());this.stack.push(e),this.clear()}pop(){if(0===this.stack.length)return;const t=this.stack.pop(),e=t.sampler;this.size.set(e.width,e.height),this.sampler.copy(e,0,0,0,0,e.width,e.height),this.borderWidth.set(t.borderWidth),this.tileImage.set(t.tileImage),this.update()}clear(){const t=this.size;this.sampler.zeroFill(0,0,t.x,t.y),this.update()}update(){this.texture.needsUpdate=!0}readPoint(t,e,i){for(let n=0;n<4;n++){const s=this.sampler.readChannel(t,e,n);i[n]=td(s)}}paintPointAlphaBlend(t,e,i){const n=new sd;this.readPoint(t,e,n);const s=1-i.w;n.set(i.x*i.w+n.x*s,i.y*i.w+n.y*s,i.z*i.w+n.z*s,i.w+n.w*s),this.clearPoint(t,e),this.paintPoint(t,e,n)}clearPoint(t,e){this.sampler.set(t,e,pd)}paintPoint(t,e,i){for(let n=0;n<4;n++)this.sampler.writeChannel(t,e,n,Qu(i[n]));this.texture.needsUpdate=!0}writeData(t){const e=this.size;0!==e.x&&0!==e.y&&(i(this.sampler.data)?this.sampler.data.set(t):ed(t,0,this.sampler.data,0,t.length),this.sampler.version++,this.texture.needsUpdate=!0)}paintImage(t,e,i,n,s){const r=ld(t);this.paintSampler(r,e,i,n,s)}paintSampler(t,e,i,n,s){const r=Zu.uint8(4,n,s);cd(t,r),function(t,e,i,n,s,r,a,o,l=0){let h;if(0!==l)throw new Error(`Unsupported blendType(=${l})`);h=ud;const c=Math.min(a,e.width-i,t.width-s),u=Math.min(o,e.height-n,t.height-r),d=Math.max(0,-s),p=[0,0,0,255],f=[0,0,0,255],m=[];let _,g;for(g=Math.max(0,-r);g<u;g++)for(_=d;_<c;_++){const i=Math.round(_+s),a=Math.round(g+r);t.read(i,a,p);const o=Math.round(_+n),l=Math.round(g+n);e.read(o,l,f),h(f,p,m),t.set(i,a,m)}}(this,r,0,0,e,i,n,s),this.texture.needsUpdate=!0}}const md=new Map;function _d(t){const e=md.get(t);if(void 0!==e)return e;const i=(new zc).load(t);return i.wrapS=qt,i.wrapT=qt,i.repeat.set(1,1),md.set(t,i),i}class gd{__enabled=!1;materials=[];time=0;__speed0=new Eu;__speed1=new Eu;__speed2=new Eu;variability=.37;constructor(){this.setSpeed(.5,-.5)}set enabled(t){t!==this.__enabled&&(this.__enabled=t,this.materials.forEach(this.writeOneEnabled.bind(this)))}get enabled(){return this.__enabled}setSpeed(t,e){const i=this.variability;this.__speed0.set(t,e),this.__speed1.set(t*(1-i),e*(1+i)),this.__speed2.set(t*(1+i),e*(1-i))}writeOneCloudSpeed(t){const e=t.uniforms;e.v_CloudsSpeed_0.value.copy(this.__speed0),e.v_CloudsSpeed_1.value.copy(this.__speed1),e.v_CloudsSpeed_2.value.copy(this.__speed2)}writeOneEnabled(t){t.defines.SHADOWMAP_CLOUDS=this.__enabled,t.needsUpdate=!0}writeOneTime(t){t.uniforms.f_CloudsTime.value=this.time}writeAllTime(){const t=this.materials,e=t.length;for(let i=0;i<e;i++){const e=t[i];this.writeOneTime(e)}}update(t){this.time+=t,this.writeAllTime()}writeOneCloudTextures(t){const e=t.uniforms;e.t_Clouds_0.value=_d("data/textures/noise/tile_256.png"),e.t_Clouds_1.value=_d("data/textures/noise/tile_256.png"),e.t_Clouds_2.value=_d("data/textures/noise/tile_256.png")}writeOneCloudUniforms(t){const e=t.uniforms;e.v_CloudsSize_0.value.set(161,161),e.v_CloudsSize_1.value.set(83,83),e.v_CloudsSize_2.value.set(23,23),e.f_CloudsAmount.value=.8,e.f_CloudsIntensity.value=.2,this.writeOneCloudSpeed(t)}removeMaterial(t){const e=this.materials.indexOf(t);return-1!==e&&(this.materials.splice(e,1),!0)}addMaterial(t){"object"==typeof t.defines&&t.defines.hasOwnProperty("SHADOWMAP_CLOUDS")&&(this.writeOneTime(t),this.writeOneEnabled(t),this.writeOneCloudTextures(t),this.writeOneCloudUniforms(t),this.materials.push(t))}}class yd{url="";offset=new Eu(0,0);scale=new Eu(1,1);copy(t){this.url=t.url,this.scale.copy(t.scale),this.offset.copy(t.offset)}toJSON(){return{url:this.url,offset:this.offset.toJSON(),scale:this.scale.toJSON()}}fromJSON(t){this.url=t.url,this.offset.fromJSON(t.offset),this.scale.fromJSON(t.scale)}toBinaryBuffer(t){t.writeUTF8String(this.url),this.offset.toBinaryBuffer(t),this.scale.toBinaryBuffer(t)}fromBinaryBuffer(t){this.url=t.readUTF8String(),this.offset.fromBinaryBuffer(t),this.scale.fromBinaryBuffer(t)}}function vd(t,e,i,n,s){let r,a;const o=$u(e,n,s);4===o?(r=new Uint32Array(t,e,s>>>2),a=new Uint32Array(i,n,s>>>2)):2===o?(r=new Uint16Array(t,e,s>>>1),a=new Uint16Array(i,n,s>>>1)):(r=new Uint8Array(t,e,s),a=new Uint8Array(i,n,s)),a.set(r)}function xd(t,e,i,n,s,r){const a=n-t,o=r-i;return 2*((s-e)*(a+o)+o*a)}const wd=b,bd=10,Sd=Math.floor(b/40);class Md{__data_buffer=new ArrayBuffer(5120);get data_buffer(){return this.__data_buffer}__data_float32=new Float32Array(this.__data_buffer);__data_uint32=new Uint32Array(this.__data_buffer);__capacity=128;__size=0;__free=[];__free_pointer=0;__root=wd;get root(){return this.__root}set root(t){this.__root=t}get node_capacity(){return this.__capacity}set node_capacity(t){if(this.__size>t)throw new Error(`Can't shrink capacity to ${t}, because it's below occupancy(${this.__size}).`);this.__set_capacity(t)}__grow_capacity(){if(this.__capacity>=Sd)throw new Error("Can not grow capacity, already at maximum platform limit");let t=Math.ceil(bu(1.2*this.__capacity,this.__capacity+64));t>Sd&&(t=Sd),this.__set_capacity(t)}__set_capacity(t){if(this.__capacity===t)return;const e=this.__data_uint32,i=new ArrayBuffer(40*t);this.__data_buffer=i,this.__data_float32=new Float32Array(i),this.__data_uint32=new Uint32Array(i),this.__size>0&&vd(e.buffer,e.byteOffset,i,0,Math.min(40*this.__size,i.byteLength)),this.__capacity=t}trim(){this.__capacity>this.__size&&this.__set_capacity(this.__size)}allocate_node(){let t;const e=this.__free_pointer;if(e>0){const i=e-1;t=this.__free[i],this.__free_pointer=i}else t=this.__size,t>=this.__capacity&&this.__grow_capacity(),this.__size++;const i=bd*t,n=this.__data_float32;n[i]=Number.POSITIVE_INFINITY,n[i+1]=Number.POSITIVE_INFINITY,n[i+2]=Number.POSITIVE_INFINITY,n[i+3]=Number.NEGATIVE_INFINITY,n[i+4]=Number.NEGATIVE_INFINITY,n[i+5]=Number.NEGATIVE_INFINITY;const s=this.__data_uint32;return s[i+6]=wd,s[i+7]=wd,s[i+8]=wd,s[i+9]=0,t}release_node(t){this.__free[this.__free_pointer++]=t}node_is_leaf(t){return this.__data_uint32[bd*t+7]===wd}node_get_user_data(t){return this.__data_uint32[bd*t+8]}node_set_user_data(t,e){this.__data_uint32[bd*t+8]=e}node_get_child1(t){return this.__data_uint32[bd*t+7]}node_set_child1(t,e){this.__data_uint32[bd*t+7]=e}node_get_child2(t){return this.__data_uint32[bd*t+8]}node_set_child2(t,e){this.__data_uint32[bd*t+8]=e}node_get_parent(t){return this.__data_uint32[bd*t+6]}node_set_parent(t,e){this.__data_uint32[bd*t+6]=e}node_get_height(t){return this.__data_uint32[bd*t+9]}node_set_height(t,e){this.__data_uint32[bd*t+9]=e}node_get_aabb(t,e){const i=bd*t,n=this.__data_float32;e[0]=n[i],e[1]=n[i+1],e[2]=n[i+2],e[3]=n[i+3],e[4]=n[i+4],e[5]=n[i+5]}node_set_aabb(t,e){const i=bd*t,n=this.__data_float32;n[i]=e[0],n[i+1]=e[1],n[i+2]=e[2],n[i+3]=e[3],n[i+4]=e[4],n[i+5]=e[5]}node_move_aabb(t,e){this.node_set_aabb(t,e);const i=this.__data_uint32[bd*t+6];i!==wd&&this.bubble_up_refit(i)}node_set_aabb_primitive(t,e,i,n,s,r,a){const o=bd*t,l=this.__data_float32;l[o]=e,l[o+1]=i,l[o+2]=n,l[o+3]=s,l[o+4]=r,l[o+5]=a}node_get_surface_area(t){const e=bd*t,i=this.__data_float32;return xd(i[e],i[e+1],i[e+2],i[e+3],i[e+4],i[e+5])}node_get_combined_surface_area(t,e){const i=bd*t,n=bd*e,s=this.__data_float32;return xd(Su(s[i],s[n]),Su(s[i+1],s[n+1]),Su(s[i+2],s[n+2]),bu(s[i+3],s[n+3]),bu(s[i+4],s[n+4]),bu(s[i+5],s[n+5]))}node_set_combined_aabb(t,e,i){const n=bd*e,s=bd*i,r=bd*t,a=this.__data_float32,o=a[n],l=a[n+1],h=a[n+2],c=a[n+3],u=a[n+4],d=a[n+5],p=a[s],f=a[s+1],m=a[s+2],_=a[s+3],g=a[s+4],y=a[s+5],v=Su(o,p),x=Su(l,f),w=Su(h,m),b=bu(c,_),S=bu(u,g),M=bu(d,y);a[r]=v,a[r+1]=x,a[r+2]=w,a[r+3]=b,a[r+4]=S,a[r+5]=M}insert_leaf(t){let e=this.__data_uint32;if(this.__root===wd)return this.__root=t,void(e[t*bd+6]=wd);let i=this.__root;for(;!1===this.node_is_leaf(i);){const n=i*bd,s=e[n+7],r=e[n+8],a=this.node_get_surface_area(i),o=this.node_get_combined_surface_area(i,t),l=2*o,h=2*(o-a);let c,u;if(this.node_is_leaf(s))c=this.node_get_combined_surface_area(t,s)+h;else{const e=this.node_get_surface_area(s);c=this.node_get_combined_surface_area(t,s)-e+h}if(this.node_is_leaf(r))u=this.node_get_combined_surface_area(t,r)+h;else{const e=this.node_get_surface_area(r);u=this.node_get_combined_surface_area(t,r)-e+h}if(l<c&&l<u)break;i=c<u?s:r}const n=i,s=e[n*bd+6],r=this.allocate_node();e=this.__data_uint32,e[r*bd+6]=s,this.node_set_combined_aabb(r,t,n),e[r*bd+9]=e[n*bd+9]+1,s!==wd?e[s*bd+7]===n?e[s*bd+7]=r:e[s*bd+8]=r:this.__root=r,e[r*bd+7]=n,e[r*bd+8]=t,e[n*bd+6]=r,e[t*bd+6]=r,this.bubble_up_update(r)}bubble_up_refit(t){let e=t;const i=this.__data_uint32;do{const t=e*bd,n=i[t+7],s=i[t+8];this.node_set_combined_aabb(e,n,s),e=i[t+6]}while(e!==wd)}bubble_up_update(t){let e=t;const i=this.__data_uint32;for(;e!==wd;){e=this.balance(e);const t=e*bd,n=i[t+7],s=i[t+8];i[t+9]=1+bu(i[n*bd+9],i[s*bd+9]),this.node_set_combined_aabb(e,n,s),e=i[t+6]}}remove_leaf(t){if(t===this.__root)return void(this.__root=wd);const e=this.__data_uint32,i=e[t*bd+6],n=e[i*bd+6];let s;const r=e[i*bd+7];s=r===t?e[i*bd+8]:r,n!==wd?(e[n*bd+7]===i?e[n*bd+7]=s:e[n*bd+8]=s,e[s*bd+6]=n,this.release_node(i),this.bubble_up_update(n)):(this.__root=s,e[s*bd+6]=wd,this.release_node(i))}balance(t){const e=this.__data_uint32;if(this.node_is_leaf(t)||e[t*bd+9]<2)return t;const i=e[t*bd+7],n=e[t*bd+8],s=e[n*bd+9]-e[i*bd+9];if(s>1){const s=e[n*bd+7],r=e[n*bd+8];e[n*bd+7]=t;const a=e[t*bd+6];return e[n*bd+6]=a,e[t*bd+6]=n,a!==wd?e[a*bd+7]===t?e[a*bd+7]=n:e[a*bd+8]=n:this.__root=n,e[s*bd+9]>e[r*bd+9]?(e[n*bd+8]=s,e[t*bd+8]=r,e[r*bd+6]=t,this.node_set_combined_aabb(t,i,r),this.node_set_combined_aabb(n,t,s),e[t*bd+9]=1+bu(e[i*bd+9],e[r*bd+9]),e[n*bd+9]=1+bu(e[t*bd+9],e[s*bd+9])):(e[n*bd+8]=r,e[t*bd+8]=s,e[s*bd+6]=t,this.node_set_combined_aabb(t,i,s),this.node_set_combined_aabb(n,t,r),e[t*bd+9]=1+bu(e[i*bd+9],e[s*bd+9]),e[n*bd+9]=1+bu(e[t*bd+9],e[r*bd+9])),n}if(s<-1){const s=e[i*bd+7],r=e[i*bd+8];e[i*bd+7]=t;const a=e[t*bd+6];return e[i*bd+6]=a,e[t*bd+6]=i,a!==wd?e[a*bd+7]===t?e[a*bd+7]=i:e[a*bd+8]=i:this.__root=i,e[s*bd+9]>e[r*bd+9]?(e[i*bd+8]=s,e[t*bd+7]=r,e[r*bd+6]=t,this.node_set_combined_aabb(t,n,r),this.node_set_combined_aabb(i,t,s),e[t*bd+9]=1+bu(e[n*bd+9],e[r*bd+9]),e[i*bd+9]=1+bu(e[t*bd+9],e[s*bd+9])):(e[i*bd+8]=r,e[t*bd+7]=s,e[s*bd+6]=t,this.node_set_combined_aabb(t,n,s),this.node_set_combined_aabb(i,t,r),e[t*bd+9]=1+bu(e[n*bd+9],e[s*bd+9]),e[i*bd+9]=1+bu(e[t*bd+9],e[r*bd+9])),i}return t}release_all(){this.__root=wd,this.__size=0,this.__free_pointer=0}traverse(t,e){let i=0;const n=[],s=this.__root;s!==wd&&(n[i++]=s);const r=this.__data_uint32;for(;i>0;){i--;const s=n[i];t.call(e,s,this);const a=s*bd,o=r[a+7],l=r[a+8];o!==wd&&(n[i++]=l,n[i++]=o)}}collect_nodes_all(t,e){let i=e;return this.traverse((e=>{t[i++]=e})),i-e}__move_node_links(t,e){const i=this.__data_uint32,n=t*bd,s=i[n+7],r=i[n+8];s!==wd&&(i[s*bd+6]=e,i[r*bd+6]=e);const a=i[n+6];a!==wd&&(i[a*bd+7]===t?i[a*bd+7]=e:i[a*bd+8]=e)}swap_nodes(t,e){const i=this.__data_uint32,n=t*bd,s=e*bd;return i[n+6]!==e&&i[s+6]!==t&&(this.__move_node_links(t,e),this.__move_node_links(e,t),ed(i,n,this.__free,this.__free_pointer,bd),ed(i,s,i,n,bd),ed(this.__free,this.__free_pointer,i,s,bd),this.__root===t?this.__root=e:this.__root===e&&(this.__root=t),!0)}}const Td=new Uint32Array(781250);Td.pointer=0;const Ad=Math.abs;function Cd(t,e,i,n,s,r,a,o,l,h,c,u){const d=.5*(n-t),p=a-(t+d);if(p*h>=0&&Ad(p)>d)return!1;const f=.5*(s-e),m=o-(e+f);if(m*c>=0&&Ad(m)>f)return!1;const _=.5*(r-i),g=l-(i+_);if(g*u>=0&&Ad(g)>_)return!1;const y=Ad(c),v=Ad(u);if(Ad(c*g-u*m)>f*v+_*y)return!1;const x=Ad(h);return!(Ad(u*p-h*g)>d*v+_*x)&&Ad(h*m-c*p)<=d*y+f*x}const Ed=Td;function zd(t,e,i){let n=t;return n>e&&(n=e),n>i&&(n=i),n}function Id(t){const e=Math.round(t).toString(16);return 1===e.length?"0"+e:e}function Ld(t){return parseInt(t,16)}const Nd=/rgb\(\s*([0-9]+),\s*([0-9]+),\s*([0-9]+)\s*\)/,Pd=/rgba\(\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?)\s*\)/,Dd=/hsv\(([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?)\)/;function Fd(t,e,i){const n=Qu(t),s=Qu(e);return 255&Qu(i)|(255&s)<<8|(255&n)<<16}function Od(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.4166666666666667)-.055}function Rd(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}class kd{constructor(t=0,e=0,i=0,n=1){this.r=t,this.g=e,this.b=i,this.a=n,this.onChanged=new _}get 0(){return this.r}set 0(t){this.r=t}get 1(){return this.g}set 1(t){this.g=t}get 2(){return this.b}set 2(t){this.b=t}get 3(){return this.a}set 3(t){this.a=t}get length(){return 4}setRGB(t,e,i){this.set(t,e,i,this.a)}setRGBUint8(t,e,i){this.setRGB(td(t),td(e),td(i))}setA(t){this.set(this.r,this.g,this.b,t)}set(t,e,i,n){const s=this.r,r=this.g,a=this.b,o=this.a;s===t&&r===e&&a===i&&o===n||(this.r=t,this.g=e,this.b=i,this.a=n,this.onChanged.send8(t,e,i,n,s,r,a,o))}setHSL(t,e,i){let n=t%1;n<0&&(n+=Math.ceil(Math.abs(n)));const s=12*n%12,r=(8+12*n)%12,a=(4+12*n)%12,o=e*Su(i,1-i),l=i-o*bu(-1,zd(s-3,9-s,1)),h=i-o*bu(-1,zd(r-3,9-r,1)),c=i-o*bu(-1,zd(a-3,9-a,1));this.setRGB(l,h,c)}setHCL(t,e,i){let n=t%1;n<0&&(n+=Math.ceil(Math.abs(n)));const s=6*n,r=e*(1-Math.abs(s%2-1));let a,o,l;switch(Math.floor(s)){case 0:a=e,o=r,l=0;break;case 1:a=r,o=e,l=0;break;case 2:a=0,o=e,l=r;break;case 3:a=0,o=r,l=e;break;case 4:a=r,o=0,l=e;break;case 5:a=e,o=0,l=r}const h=i-(.3*a+.59*o+.11*l);this.setRGB(a+h,o+h,l+h)}setHSI(t,e,i){let n=t%1;n<0&&(n+=Math.ceil(Math.abs(n)));const s=6*n,r=1-Math.abs(s%2-1),a=3*i*e/(1+r),o=a*r;let l,h,c;switch(Math.floor(s)){case 0:l=a,h=o,c=0;break;case 1:l=o,h=a,c=0;break;case 2:l=0,h=a,c=o;break;case 3:l=0,h=o,c=a;break;case 4:l=o,h=0,c=a;break;case 5:l=a,h=0,c=o}const u=i*(1-e);this.setRGB(l+u,h+u,c+u)}setHSV(t,e,i){let n=t;n<0&&(n+=Math.ceil(Math.abs(n))),n%=1;const s=y(e),r=y(i);let a,o,l;const h=Math.floor(6*n),c=6*n-h,u=r*(1-s),d=r*(1-c*s),p=r*(1-(1-c)*s);switch(h%6){case 0:a=r,o=p,l=u;break;case 1:a=d,o=r,l=u;break;case 2:a=u,o=r,l=p;break;case 3:a=u,o=d,l=r;break;case 4:a=p,o=u,l=r;break;case 5:a=r,o=u,l=d}this.setRGB(a,o,l)}computeLuminance(){return.299*this.r+.587*this.g+.114*this.b}getHSV(){return function(t,e,i){const n=Math.max(t,e,i),s=Math.min(t,e,i);let r,a,o=n;const l=n-s;if(a=0===n?0:l/n,n===s)r=0;else{switch(n){case t:r=(e-i)/l+(e<i?6:0);break;case e:r=(i-t)/l+2;break;case i:r=(t-e)/l+4}r/=6}return{h:r,s:a,v:o}}(this.r,this.g,this.b)}toUint(){return Fd(this.r,this.g,this.b)}toUint32(){return t=this.r,e=this.g,i=this.b,n=this.a,Fd(t,i,e)<<8|255&Qu(n);var t,e,i,n}fromUint(t){const e=t>>16,i=t>>8&255,n=255&t;this.setRGBUint8(e,i,n)}toHex(){return"#"+(t=Qu(this.r),e=Qu(this.g),i=Qu(this.b),Id(t)+Id(e)+Id(i));var t,e,i}toCssRGBAString(){return`rgba(${Qu(this.r)},${Qu(this.g)},${Qu(this.b)},${this.a})`}equals(t){return this.r===t.r&&this.g===t.g&&this.b===t.b&&this.a===t.a}copy(t){this.a=t.a,this.setRGB(t.r,t.g,t.b)}clone(){const t=new kd;return t.copy(this),t}hash(){return this.toUint()}fromJSON({r:t,g:e,b:i,a:n=1}){this.set(t,e,i,n)}toJSON(){return{r:this.r,g:this.g,b:this.b,a:this.a}}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b,yield this.a}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t[e+3]=this.a,t}fromArray(t,e=0){const i=t[e+0],n=t[e+1],s=t[e+2],r=t[e+3];this.set(i,n,s,r)}toBinaryBuffer(t){t.writeFloat32(this.r),t.writeFloat32(this.g),t.writeFloat32(this.b),t.writeFloat32(this.a)}fromBinaryBuffer(t){const e=t.readFloat32(),i=t.readFloat32(),n=t.readFloat32(),s=t.readFloat32();this.set(e,i,n,s)}parse(t){const e=function(t){const e=[],i=typeof t;let n,s,r,a=1;if("string"===i){const e=t.toLowerCase();let i;if(null!==(i=e.match(Nd)))n=parseInt(i[1]),s=parseInt(i[2]),r=parseInt(i[3]);else if(null!==(i=e.match(Pd)))n=parseFloat(i[1]),s=parseFloat(i[2]),r=parseFloat(i[3]),a=parseFloat(i[4]);else if(null!==(i=e.match(Dd))){const t=function(t,e,i){let n=t;n<0&&(n+=Math.ceil(Math.abs(n))),n%=1;const s=y(e),r=y(i);let a,o,l,h,c,u,d,p;switch(h=Math.floor(6*n),c=6*n-h,u=r*(1-s),d=r*(1-c*s),p=r*(1-(1-c)*s),h%6){case 0:a=r,o=p,l=u;break;case 1:a=d,o=r,l=u;break;case 2:a=u,o=r,l=p;break;case 3:a=u,o=d,l=r;break;case 4:a=p,o=u,l=r;break;case 5:a=r,o=u,l=d}return{r:Qu(a),g:Qu(o),b:Qu(l)}}(parseFloat(i[1]),parseFloat(i[2]),parseFloat(i[3]));n=t.r,s=t.g,r=t.b}else{if(!e.startsWith("#"))throw new Error(`Failed to decode color string '${t}' `);{const t=function(t){const e={r:Ld(t.slice(1,3)),g:Ld(t.slice(3,5)),b:Ld(t.slice(5,7))};return t.length>7?e.a=Ld(t.slice(7,9)):e.a=1,e}(e);n=t.r,s=t.g,r=t.b,a=t.a}}}else{if("number"!==i)throw new Error(`Failed to decode color '${t}'`);n=t>>16,s=t>>8&255,r=255&t}return e[0]=n,e[1]=s,e[2]=r,e[3]=a,e}(t);"number"==typeof e[3]?this.a=e[3]:this.a=1,this.setRGB(e[0]/255,e[1]/255,e[2]/255)}lerpColors(t,e,i){this.r=w(t.r,e.r,i),this.g=w(t.g,e.g,i),this.b=w(t.b,e.b,i),this.a=w(t.a,e.a,i)}static fromRGB(t,e,i){return new kd(t,e,i)}static fromHSV(t,e,i){const n=new kd;return n.setHSV(t,e,i),n}static parse(t){const e=new kd;return e.parse(t),e}static from_linear_to_sRGB(t,e=new kd){return function(t,e,i,n){const s=i[0],r=i[1],a=i[2];t[0]=Od(s),t[1]=Od(r),t[2]=Od(a)}(e,0,t),e}static from_sRGB_to_linear(t,e=new kd){return function(t,e,i,n){const s=i[0],r=i[1],a=i[2];t[0]=Rd(s),t[1]=Rd(r),t[2]=Rd(a)}(e,0,t),e}}function Bd(t,e,i,n){return e>i&&n>t}function Ud(t,e,i,n,s,r,a,o){return Bd(t,i,s,a)&&Bd(e,n,r,o)}function Vd(t,e,i){const n=e-t;return 0===n?0:(i-t)/n}kd.prototype.writeToArray=kd.prototype.toArray,kd.red=Object.freeze(new kd(1,0,0)),kd.green=Object.freeze(new kd(0,1,0)),kd.blue=Object.freeze(new kd(0,0,1)),kd.yellow=Object.freeze(new kd(1,1,0)),kd.cyan=Object.freeze(new kd(0,1,1)),kd.magenta=Object.freeze(new kd(1,0,1)),kd.white=Object.freeze(new kd(1,1,1)),kd.black=Object.freeze(new kd(0,0,0)),kd.transparent=Object.freeze(new kd(0,0,0,0));class Wd{constructor(t=Number.NEGATIVE_INFINITY,e=Number.POSITIVE_INFINITY){this.min=t,this.max=e,this.onChanged=new _}set(t,e){const i=this.min,n=this.max;t===i&&e===n||(this.min=t,this.max=e,this.onChanged.hasHandlers()&&this.onChanged.send4(t,e,i,n))}multiplyScalar(t){const e=this.min*t,i=this.max*t;e>i?this.set(i,e):this.set(e,i)}normalizeValue(t){return Vd(this.min,this.max,t)}isZero(){return 0===this.min&&0===this.max}isExact(){return this.min===this.max}computeAverage(){return.5*(this.min+this.max)}sampleRandom(t){return this.min+t()*(this.max-this.min)}fromJSON(t){this.set(t.min,t.max)}toJSON(){return{min:this.min,max:this.max}}toString(){return`NumericInterval{ min=${this.min}, max=${this.max} }`}toBinaryBuffer(t){t.writeFloat64(this.min),t.writeFloat64(this.max)}fromBinaryBuffer(t){this.min=t.readFloat64(),this.max=t.readFloat64()}copy(t){this.set(t.min,t.max)}equals(t){return this.min===t.min&&this.max===t.max}hash(){let t=S(this.min);return t=(t<<5)-t+S(this.max),t}get span(){return this.max-this.min}}Wd.prototype.isNumericInterval=!0,Wd.zero_zero=Object.freeze(new Wd(0,0)),Wd.zero_one=Object.freeze(new Wd(0,1)),Wd.one_one=Object.freeze(new Wd(1,1));class Gd extends Number{onChanged=new _;constructor(t=0){super(),this.__value=t}valueOf(){return this.getValue()}toString(){return this.getValue().toString()}set(t){const e=this.__value;return e!==t&&(this.__value=t,this.onChanged.send2(t,e)),this}setSilent(t){this.__value=t}isZero(){return 0===this.getValue()}subtract(t){this._add(-t.getValue())}_subtract(t){this.set(this.getValue()-t)}add(t){this._add(t.getValue())}_add(t){this.set(this.getValue()+t)}increment(){this.set(this.getValue()+1)}decrement(){this.set(this.getValue()-1)}getValue(){return this.__value}copy(t){this.set(t.__value)}equals(t){return this.__value===t.__value}hash(){return this.__value}toJSON(){return this.__value}fromJSON(t){this.set(t)}toBinaryBuffer(t){const e=this.__value;Infinity===e?t.writeInt32(2147483647):-Infinity===e?t.writeInt32(-2147483648):t.writeInt32(e)}fromBinaryBuffer(t){const e=t.readInt32();2147483647===e?this.set(Infinity):-2147483648===e?this.set(-Infinity):this.set(e)}}Gd.prototype.isObservedInteger=!0;class Hd{constructor(t){this.onChanged=new _,this.__value=t,this.getValue=Hd.prototype.get}set(t){if(this.__value!==t){const e=this.__value;this.__value=t,this.onChanged.send2(t,e)}}setSilent(t){this.__value=t}get(){return this.__value}copy(t){this.set(t.__value)}equals(t){return"object"==typeof t&&this.__value===t.__value}clone(){return new Hd(this.__value)}process(t){return t(this.__value),this.onChanged.add(t),this}toString(){return JSON.stringify({value:this.__value})}toJSON(){return this.get()}fromJSON(t){this.set(t)}}function jd(t){let e=t-1;return e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e++,e}function qd(t,e,i,n,s,r){const a=i[n+0],o=i[n+1],l=i[n+2],h=i[n+3],c=i[n+4],u=i[n+5],d=s[r+0],p=s[r+1],f=s[r+2],m=s[r+3],_=s[r+4],g=s[r+5],y=Su(a,d),v=Su(o,p),x=Su(l,f),w=bu(h,m),b=bu(c,_),S=bu(u,g);t[e+0]=y,t[e+1]=v,t[e+2]=x,t[e+3]=w,t[e+4]=b,t[e+5]=S}function Jd(t,e,i,n,s,r){const a=n-t,o=r-i;return(s-e)*(a+o)+o*a}function $d(t){let e=t;return e=50331903&(e|e<<16),e=50393103&(e|e<<8),e=51130563&(e|e<<4),e=153391689&(e|e<<2),e}function Yd(t,e,i){return $d(t)|$d(e)<<1|$d(i)<<2}function Xd(t,e,i){const n=t[i],s=t[i+1],r=t[i+2];yu(t,e,n,s,r,n,s,r)}function Zd(t,e,i){const n=t[e],s=t[e+1],r=t[e+2];return function(t,e,i,n){const s=n[0],r=n[1],a=n[2],o=1023*(t-s)/(n[3]-s),l=1023*(e-r)/(n[4]-r),h=1023*(i-a)/(n[5]-a);return Yd(Math.round(o),Math.round(l),Math.round(h))}(.5*(n+t[e+3]),.5*(s+t[e+4]),.5*(r+t[e+5]),i)}const Kd=Td;class Qd{__data_buffer;__data_float32;__data_uint32;__node_count_binary=0;__node_count_leaf=0;constructor(){this.data=new ArrayBuffer(320)}estimateByteSize(){return this.data.byteLength+248}getTotalBoxCount(){return this.__node_count_binary+this.__node_count_leaf}get binary_node_count(){return this.__node_count_binary}get leaf_node_count(){return this.__node_count_leaf}getLeafBlockAddress(){return 6*this.__node_count_binary}get float32(){return this.__data_float32}get uint32(){return this.__data_uint32}set data(t){this.__data_buffer=t,this.__data_float32=new Float32Array(this.__data_buffer),this.__data_uint32=new Uint32Array(this.__data_buffer)}get data(){return this.__data_buffer}getNodeAddress(t){const e=this.__node_count_binary,i=t-e;return i<0?6*t:6*e+7*i}initialize_structure(){const t=4*(6*this.__node_count_binary+7*this.__node_count_leaf);this.__data_buffer.byteLength<t&&(this.data=new ArrayBuffer(t))}setLeafCount(t){this.__node_count_leaf=t;const e=jd(t);this.__node_count_binary=t<=1?e:e-1}getLeafAddress(t){return 7*t+6*this.__node_count_binary}setLeafData(t,e,i,n,s,r,a,o){const l=this.getLeafAddress(t);yu(this.__data_float32,l,i,n,s,r,a,o),this.__data_uint32[l+6]=e}readBounds(t,e,i){ed(this.__data_float32,t,e,i,6)}readLeafPayload(t){const e=this.getLeafBlockAddress()+7*t+6;return this.__data_uint32[e]}compute_total_surface_area(){let t=0;const e=new Float32Array(6);for(let i=0;i<this.getTotalBoxCount();i++){let n;n=i<this.__node_count_binary?6*i:7*(i-this.__node_count_binary)+this.getLeafBlockAddress(),this.readBounds(n,e,0),t+=Jd(e[0],e[1],e[2],e[3],e[4],e[5])}return t}sort_morton(t){const e=6*this.__node_count_binary;if(this.__node_count_leaf<2)return;const i=Kd.pointer;let n,s,r=i;Kd[r++]=0,Kd[r++]=this.__node_count_leaf-1;const a=this.__data_float32;for(;r>i;){r-=2;const i=Kd[r+1],o=Kd[r];n=o,s=i;const l=Zd(a,7*(o+i>>1)+e,t);for(;n<=s;){for(;Zd(a,7*n+e,t)<l;)n++;for(;Zd(a,7*s+e,t)>l;)s--;n<=s&&(n!==s&&this.__swap_leaves(n,s),n++,s--)}o<s&&(Kd[r++]=o,Kd[r++]=s),n<i&&(Kd[r++]=n,Kd[r++]=i)}}__swap_leaves(t,e){const i=this.getLeafBlockAddress(),n=7*t+i,s=7*e+i;!function(t,e,i,n,s){for(let s=0;s<7;s++){const r=e+s,a=n+s,o=i[a];i[a]=t[r],t[r]=o}}(this.__data_float32,n,this.__data_float32,s)}build(){const t=this.__node_count_binary,e=6*t;let i,n,s,r,a=Math.floor(Math.log(t)/Math.log(2));s=Math.pow(2,a),n=6*(s-1);const o=this.__node_count_leaf,l=this.__data_float32;for(i=0;i<s;i++){const t=i<<1,s=t+1,r=e+7*t;s<o?qd(l,n,l,r,l,e+7*s):t<o?ed(l,r,l,n,6):Xd(this.__data_float32,n,n-6),n+=6}for(a--;a>=0;a--)for(s=1<<a,r=s-1,i=0;i<s;i++){const t=6*(1+(r<<1));qd(l,6*r,l,t,l,t+6),r++}}}function tp(t,e,i,n,s,r,a,o){t[e]=i,t[e+1]=n,t[e+2]=s,t[e+3]=r,t[e+4]=n,t[e+5]=s,t[e+6]=i,t[e+7]=a,t[e+8]=s,t[e+9]=r,t[e+10]=a,t[e+11]=s,t[e+12]=i,t[e+13]=n,t[e+14]=o,t[e+15]=r,t[e+16]=n,t[e+17]=o,t[e+18]=i,t[e+19]=a,t[e+20]=o,t[e+21]=r,t[e+22]=a,t[e+23]=o}function ep(t,e,i,n,s,r,a,o,l,h){return n+t*(t>0?o:s)+e*(e>0?l:r)+i*(i>0?h:a)}function ip(t,e,i,n,s,r,a,o,l,h){let c,u,d,p,f,m;t>0?(c=s,p=o):(c=o,p=s),e>0?(u=r,f=l):(u=l,f=r),i>0?(d=a,m=h):(d=h,m=a);const _=-n;return C(p,f,m,t,e,i)<_?-2:C(t,e,i,c,u,d)>=_?2:0}function np(t,e,i,n,s,r,a,o,l){const h=4*l;for(let l=0;l<h;l+=4){const h=o+l;if(ep(a[h],a[h+1],a[h+2],a[h+3],t,e,i,n,s,r)<0)return!1}return!0}function sp(t,e,i,n,s,r,a){let o=2;for(let l=0;l<24;l+=4){const h=ip(a[l],a[l+1],a[l+2],a[l+3],t,e,i,n,s,r);if(h<0)return 0;0===h&&(o=1)}return o}function rp(t){return t>=0?t:-t}function ap(t,e,i){t[0]=t[3]=i[12],t[1]=t[4]=i[13],t[2]=t[5]=i[14];for(let n=0;n<3;n++)for(let s=0;s<3;s++){const r=i[n+4*s],a=r*e[s],o=r*e[s+3];a<o?(t[n]+=a,t[n+3]+=o):(t[n]+=o,t[n+3]+=a)}}class op{constructor(t=0,e=0,i=0,n=0,s=0,r=0){this.setBounds(t,e,i,n,s,r)}*[Symbol.iterator](){yield this.x0,yield this.y0,yield this.z0,yield this.x1,yield this.y1,yield this.z1}get 0(){return this.x0}get 1(){return this.y0}get 2(){return this.z0}get 3(){return this.x1}get 4(){return this.y1}get 5(){return this.z1}set 0(t){this.x0=t}set 1(t){this.y0=t}set 2(t){this.z0=t}set 3(t){this.x1=t}set 4(t){this.y1=t}set 5(t){this.z1=t}containsPoint(t,e,i){return function(t,e,i,n){return e>=t[0]&&e<=t[3]&&i>=t[1]&&i<=t[4]&&n>=t[2]&&n<=t[5]}(this,t,e,i)}containsPointWithTolerance(t,e,i,n){return!(t+n<this.x0||t-n>this.x1||e+n<this.y0||e-n>this.y1||i+n<this.z0||i-n>this.z1)}computeSurfaceArea(){return xd(this.x0,this.y0,this.z0,this.x1,this.y1,this.z1)}getSurfaceArea(){return this.computeSurfaceArea()}computeVolume(){return this.getExtentsX()*this.getExtentsY()*this.getExtentsZ()}copy(t){this.setBounds(t.x0,t.y0,t.z0,t.x1,t.y1,t.z1)}setBounds(t,e,i,n,s,r){this.x0=t,this.y0=e,this.z0=i,this.x1=n,this.y1=s,this.z1=r}equals(t){return this._equals(t.x0,t.y0,t.z0,t.x1,t.y1,t.z1)}_equals(t,e,i,n,s,r){return this.x0===t&&this.y0===e&&this.z0===i&&this.x1===n&&this.y1===s&&this.z1===r}setBoundsUnordered(t,e,i,n,s,r){let a,o,l,h,c,u;t<n?(a=t,h=n):(a=n,h=t),e<s?(o=e,c=s):(o=s,c=e),i<r?(l=i,u=r):(l=r,u=i),this.setBounds(a,o,l,h,c,u)}setNegativelyInfiniteBounds(){this.setBounds(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY)}setInfiniteBounds(){this.setBounds(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}_translate(t,e,i){this.setBounds(this.x0+t,this.y0+e,this.z0+i,this.x1+t,this.y1+e,this.z1+i)}distanceToPoint2(t,e,i){return function(t,e,i,n,s,r,a,o,l){const h=e-o,c=o-s,u=i-l,d=l-r;let p=bu(t-a,a-n),f=bu(h,c),m=bu(u,d);return p>0||f>0||m>0?(p=bu(p,0),f=bu(f,0),m=bu(m,0),p*p+f*f+m*m):-(p*p+f*f+m*m)}(this.x0,this.y0,this.z0,this.x1,this.y1,this.z1,t,e,i)}distanceToBox(t){return this._distanceToBox(t.x0,t.y0,t.z0,t.x1,t.y1,t.z1)}_distanceToBox(t,e,i,n,s,r){return function(t,e,i,n,s,r,a,o,l,h,c,u){const d=a-n,p=t-h,f=o-s,m=e-c,_=l-r,g=i-u,y=Math.max(d,p),v=Math.max(f,m),x=Math.max(_,g);let w=Math.sqrt(y*y+v*v+x*x);return y<0&&v<0&&x<0?-w:w}(this.x0,this.y0,this.z0,this.x1,this.y1,this.z1,t,e,i,n,s,r)}costForInclusion(t){return this._costForInclusion(t.x0,t.y0,t.z0,t.x1,t.y1,t.z1)}_costForInclusion(t,e,i,n,s,r){let a=0,o=0,l=0;const h=this.x0,c=this.y0,u=this.z0,d=this.x1,p=this.y1,f=this.z1;h>t&&(a+=h-t),d<n&&(a+=n-d),c>e&&(o+=c-e),p<s&&(o+=s-p),u>i&&(l+=u-i),f<r&&(l+=r-f);const m=d-h,_=p-c,g=f-u;return a*(_+g)+o*(m+g)+l*(m+_)}_expandToFitPoint(t,e,i){let n=!1;return t<this.x0&&(this.x0=t,n=!0),e<this.y0&&(this.y0=e,n=!0),i<this.z0&&(this.z0=i,n=!0),t>this.x1&&(this.x1=t,n=!0),e>this.y1&&(this.y1=e,n=!0),i>this.z1&&(this.z1=i,n=!0),n}expandToFit(t){return this._expandToFit(t.x0,t.y0,t.z0,t.x1,t.y1,t.z1)}_expandToFit(t,e,i,n,s,r){let a=!1;return t<this.x0&&(this.x0=t,a=!0),e<this.y0&&(this.y0=e,a=!0),i<this.z0&&(this.z0=i,a=!0),n>this.x1&&(this.x1=n,a=!0),s>this.y1&&(this.y1=s,a=!0),r>this.z1&&(this.z1=r,a=!0),a}_containsBox(t,e,i,n,s,r){return t>=this.x0&&e>=this.y0&&i>=this.z0&&n<=this.x1&&s<=this.y1&&r<=this.z1}containsBox(t){return this._containsBox(t.x0,t.y0,t.z0,t.x1,t.y1,t.z1)}getExtentsX(){return this.x1-this.x0}get width(){return this.getExtentsX()}getExtentsY(){return this.y1-this.y0}get height(){return this.getExtentsY()}getExtentsZ(){return this.z1-this.z0}get depth(){return this.getExtentsZ()}getHalfExtentsX(){return this.getExtentsX()/2}getHalfExtentsY(){return this.getExtentsY()/2}getHalfExtentsZ(){return this.getExtentsZ()/2}getExtents(t){const e=this.x1-this.x0,i=this.y1-this.y0,n=this.z1-this.z0;t.set(e,i,n)}getCenterX(){return.5*(this.x0+this.x1)}get centerX(){return this.getCenterX()}getCenterY(){return.5*(this.y0+this.y1)}get centerY(){return this.getCenterY()}getCenterZ(){return.5*(this.z0+this.z1)}get centerZ(){return this.getCenterZ()}getCenter(t=new L){const e=this.getCenterX(),i=this.getCenterY(),n=this.getCenterZ();return t.set(e,i,n),t}intersectRay(t,e,i,n,s,r){return Cd(this.x0,this.y0,this.z0,this.x1,this.y1,this.z1,t,e,i,n,s,r)}intersectSegment(t,e,i,n,s,r){return function(t,e,i,n,s,r,a,o,l,h,c,u){let d,p,f,m,_,g,y,v,x,w,b,S,M,T,A,C;return y=.5*(h-a),d=(n-t)/2,w=t+d,m=.5*(h+a)-w,M=rp(y),!(rp(m)>d+M||(v=.5*(c-o),p=(s-e)/2,b=e+p,_=.5*(c+o)-b,T=rp(v),rp(_)>p+T||(x=.5*(u-l),f=(r-i)/2,S=i+f,g=.5*(u+l)-S,A=rp(x),rp(g)>f+A||(C=v*g-x*_,rp(C)>p*A+f*T||(C=x*m-y*g,rp(C)>d*A+f*M||(C=y*_-v*m,rp(C)>d*T+p*M))))))}(this.x0,this.y0,this.z0,this.x1,this.y1,this.z1,t,e,i,n,s,r)}threeContainsBox(t){const e=t.min,i=t.max;return this._containsBox(e.x,e.y,e.z,i.x,i.y,i.z)}traverseCorners(t,e){const i=this.x0,n=this.y0,s=this.z0,r=this.x1,a=this.y1,o=this.z1;t.call(e,i,n,s),t.call(e,i,n,o),t.call(e,i,a,s),t.call(e,i,a,o),t.call(e,r,n,s),t.call(e,r,n,o),t.call(e,r,a,s),t.call(e,r,a,o)}getCorners(t){tp(t,0,this.x0,this.y0,this.z0,this.x1,this.y1,this.z1)}writeToArray(t,e=0){t[e]=this.x0,t[e+1]=this.y0,t[e+2]=this.z0,t[e+3]=this.x1,t[e+4]=this.y1,t[e+5]=this.z1}readFromArray(t,e=0){const i=t[e],n=t[e+1],s=t[e+2],r=t[e+3],a=t[e+4],o=t[e+5];this.setBounds(i,n,s,r,a,o)}computePlaneSide(t){const e=t.normal;return ip(e.x,e.y,e.z,t.constant,this.x0,this.y0,this.z0,this.x1,this.y1,this.z1)}computeDistanceAbovePlane(t,e,i,n){return ep(t,e,i,n,this.x0,this.y0,this.z0,this.x1,this.y1,this.z1)}_isBelowPlane(t,e,i,n){return this.computeDistanceAbovePlane(t,e,i,n)<0}isBelowPlane(t){const e=t.normal;return this._isBelowPlane(e.x,e.y,e.z,t.constant)}intersectSpace(t){let e=0;const i=t.length;for(;e<i;e++){const i=t[e];if(this.isBelowPlane(i))return!1}return!0}intersectFrustumDegree(t){const e=t.planes;let i=0,n=2;for(;i<6;i++){const t=e[i],s=this.computePlaneSide(t);if(s<0)return 0;0===s&&(n=1)}return n}intersectFrustumDegree_array(t){return sp(this.x0,this.y0,this.z0,this.x1,this.y1,this.z1,t)}intersectFrustum(t){const e=t.planes;for(let t=0;t<6;t++){const i=e[t];if(this.isBelowPlane(i))return!1}return!0}intersectFrustum_array(t){return np(this.x0,this.y0,this.z0,this.x1,this.y1,this.z1,t,0,6)}applyMatrix4(t){const e=[],i=[];this.writeToArray(e,0),ap(i,e,t),this.readFromArray(i,0)}grow(t){this.x0-=t,this.y0-=t,this.z0-=t,this.x1+=t,this.y1+=t,this.z1+=t}clone(){const t=new op;return t.copy(this),t}fromJSON({x0:t,y0:e,z0:i,x1:n,y1:s,z1:r}){this.setBounds(t,e,i,n,s,r)}}function lp(t,e,i,n,s){const r=i[n+0],a=i[n+1],o=i[n+2],l=i[n+3],h=i[n+4],c=i[n+5],d=s[3]*r+s[7]*a+s[11]*o+s[15];if(0===d)return!1;const p=1/d,f=(s[0]*r+s[4]*a+s[8]*o+s[12])*p,m=(s[1]*r+s[5]*a+s[9]*o+s[13])*p,_=(s[2]*r+s[6]*a+s[10]*o+s[14])*p,g=s[0]*l+s[4]*h+s[8]*c,y=s[1]*l+s[5]*h+s[9]*c,v=s[2]*l+s[6]*h+s[10]*c,x=u(g,y,v);if(0===x)return!1;const w=1/x,b=g*w,S=y*w,M=v*w;return t[e+0]=f,t[e+1]=m,t[e+2]=_,t[e+3]=b,t[e+4]=S,t[e+5]=M,!0}function hp(t,e,i,n,s,r,a){t[0]=e,t[1]=i,t[2]=n,t[3]=s,t[4]=r,t[5]=a}function cp(t,e,i,n,s,r,a,o){return Cd(t[e],t[e+1],t[e+2],t[e+3],t[e+4],t[e+5],i,n,s,r,a,o)}op.prototype.isAABB3=!0,op.prototype.length=6;const up=Td;function dp(t,e,i,n,s,r,a,o,l,h,c,u,d,p,f,m){const _=c-o,g=u-l,y=d-h,v=p-o,x=f-l,w=m-h,b=g*w-y*x,S=y*v-_*w,M=_*x-g*v;let T=C(s,r,a,b,S,M),A=1;if(0===T)return!1;T<0&&(A=-1,T=-T);const E=e-o,z=i-l,I=n-h,L=A*C(s,r,a,z*w-I*x,I*v-E*w,E*x-z*v);if(L<0)return!1;const N=A*C(s,r,a,g*I-y*z,y*E-_*I,_*z-g*E);if(N<0)return!1;if(L+N>T)return!1;const P=-A*C(E,z,I,b,S,M);if(P<0)return!1;const D=P/T;return t.normal.set(b,S,M),t.position.set(s*D+e,r*D+i,a*D+n),!0}const pp=[],fp=new wu;function mp(t,e,i,n,s,r,a,o,l,h,c,u){let d=!1;const p=function(t,e,i,n,s,r,a,o,l){let h=0;const c=i.binary_node_count;if(c<=0)return 0;const u=up.pointer++;up[u]=0;const d=c+i.leaf_node_count,p=i.float32,f=i.uint32;do{up.pointer--;const e=up[up.pointer],u=i.getNodeAddress(e);if(cp(p,u,n,s,r,a,o,l))if(e<c){const t=1+(e<<1),i=t+1;i<d?(up[up.pointer++]=i,up[up.pointer++]=t):t<d&&(up[up.pointer++]=t)}else t[0+h]=f[u+6],h++}while(up.pointer>u);return h}(pp,0,e,a,o,l,h,c,u);let f,m,_,g=Infinity;for(let e=0;e<p;e++){const p=3*pp[e];void 0!==r?(f=r[p],m=r[p+1],_=r[p+2]):(f=p,m=p+1,_=p+2);const y=f*s+n,v=m*s+n,x=_*s+n,w=i[y],b=i[y+1],S=i[y+2],M=i[v],T=i[v+1],A=i[v+2],C=i[x],E=i[x+1],z=i[x+2];if(!dp(fp,a,o,l,h,c,u,w,b,S,M,T,A,C,E,z))continue;d=!0;const I=fp.position._distanceSqrTo(a,o,l);I<g&&(g=I,t.copy(fp))}return d}var _p=function(t,e){const i=new Zs(t,e);return(n=i).matrixAutoUpdate=!1,n.frustumCulled=!1,i;var n};const gp=new Ps,yp=new vs,vp=[],xp=[];class wp{gridPosition=new Eu;scale=new Eu(1,1);size=new Eu(1,1);position=new Eu;resolution=new Gd(1);material=null;mesh=_p(gp,yp);geometry=null;enableBVH=!0;external_bvh=new vu;bvh=null;isBuilt=!1;isBuildInProgress=!1;referenceCount=0;onBuilt=new _;onDestroyed=new _;stitching={top:!1,bottom:!1,left:!1,right:!1,topLeft:!1,topRight:!1,bottomLeft:!1,bottomRight:!1};__initial_height_range=new Wd(Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY);version=0;constructor(){this.mesh.name="TerrainTile",this.mesh.matrixWorldNeedsUpdate=!1}get transform(){return this.mesh.matrixWorld.elements}set transform(t){ed(t,0,this.mesh.matrixWorld.elements,0,16),this.computeBoundingBox()}raycastFirstSync(t,e,i,n,s,r,a){const o=this.transform;H(xp,o),hp(vp,e,i,n,s,r,a),lp(vp,0,vp,0,xp);const l=vp[0],h=vp[1],c=vp[2],u=vp[3],d=vp[4],p=vp[5],f=this.geometry,m=f.getIndex().array,_=f.getAttribute("position").array;let g=mp(t,this.bvh,_,0,3,m,l,h,c,u,d,p);return g&&(t.applyMatrix4(o),t.normal.normalize()),g}getVertexNormal(t,e){const i=this.geometry.attributes.normal.array,n=3*t;e.set(i[n],i[n+1],i[n+2])}setVertexNormal(t,e){const i=this.geometry.attributes.normal.array,n=3*t;i[n]=e.x,i[n+1]=e.y,i[n+2]=e.z}stitchNormals(t,e,i,n,s,r,a,o){const l=new L,h=new L,c=new L,u=new L,d=this;function p(t){return void 0!==t&&t.isBuilt}function f(t){t.geometry.attributes.normal.needsUpdate=!0}function m(t,e){if(p(t)&&p(e)){let i;const n=e.resolution.getValue(),s=t.resolution.getValue(),r=t.size.x*s*(t.size.y*s-1),a=e.size.x*n-1;if(t.stitching.bottom){for(i=1;i<a;i++)t.getVertexNormal(r+i,l),e.setVertexNormal(i,l);f(e),e.stitching.top=!0}else if(e.stitching.top){for(i=1;i<a;i++)e.getVertexNormal(i,l),t.setVertexNormal(r+i,l);f(t),t.stitching.bottom=!0}else{for(i=1;i<a;i++)e.getVertexNormal(i,l),t.getVertexNormal(r+i,h),l.add(h),l.normalize(),e.setVertexNormal(i,l),t.setVertexNormal(r+i,l);f(t),f(e),t.stitching.bottom=!0,e.stitching.top=!0}}}function _(t,e){if(p(t)&&p(e)){let i;const n=e.resolution.getValue(),s=t.resolution.getValue(),r=e.size.y*n-1,a=t.size.x*s-1,o=t.size.x*s,c=e.size.x*n;let u,d;if(t.stitching.right){for(i=0;i<r;i++)u=i*c,d=a+i*o,t.getVertexNormal(d,l),e.setVertexNormal(u,l);f(e),e.stitching.left=!0}else if(e.stitching.left){for(i=0;i<r;i++)u=i*c,d=a+i*o,e.getVertexNormal(u,l),t.setVertexNormal(d,l);f(t),t.stitching.right=!0}else{for(i=0;i<r;i++)u=i*c,d=a+i*o,e.getVertexNormal(u,l),t.getVertexNormal(d,h),l.add(h),l.normalize(),e.setVertexNormal(u,l),t.setVertexNormal(d,l);f(t),f(e),t.stitching.right=!0,e.stitching.left=!0}}}function g(t,e,i,n){if(p(t)&&p(e)&&p(i)&&p(n)){const s=t.size.x*t.resolution.getValue()*(t.size.y*t.resolution.getValue())-1,r=0,a=e.size.x*e.resolution.getValue()*(e.size.y*e.resolution.getValue()-1),o=i.size.x*i.resolution.getValue()-1;t.getVertexNormal(s,l),n.getVertexNormal(r,h),e.getVertexNormal(a,c),i.getVertexNormal(o,u),l.add(h),l.add(c),l.add(u),l.normalize(),t.setVertexNormal(s,l),n.setVertexNormal(r,l),e.setVertexNormal(a,l),i.setVertexNormal(o,l),f(t),f(e),f(i),f(n),t.stitching.bottomRight=!0,e.stitching.bottomLeft=!0,i.stitching.topRight=!0,n.stitching.topLeft=!0}}g(s,t,i,d),g(t,r,d,n),g(i,d,a,e),g(d,n,e,o),m(t,d),m(d,e),_(i,d),_(d,n)}computeBoundingBox(){let t;const e=this.geometry;if(null===e){const e=this.position,i=this.scale,n=this.size,s=this.__initial_height_range,r=new Yi(e.x*i.x,s.min,e.y*i.y),a=new Yi(r.x+n.x*i.x,s.max,r.z+n.y*i.y);t=new Ki(r,a)}else{const i=this.bvh;if(null!==i){const t=i.float32,n=t[0],s=t[1],r=t[2],a=t[3],o=t[4],l=t[5];e.boundingBox=new Ki(new Yi(n,s,r),new Yi(a,o,l));const h=a-n,c=o-s,u=l-r,d=Math.sqrt(h*h+c*c+u*u)/2,p=new Yi(n+h/2,s+c/2,r+u/2);e.boundingSphere=new yn(p,d)}t=e.boundingBox,null===t&&(e.computeBoundingBox(),t=e.boundingBox)}const i=t.min.x,n=t.min.y,s=t.min.z,r=t.max.x,a=t.max.y,o=t.max.z,l=new op(i,n,s,r,a,o);l.applyMatrix4(this.transform),this.external_bvh.resize(l.x0,l.y0,l.z0,l.x1,l.y1,l.z1)}setInitialHeightBounds(t,e){this.__initial_height_range.set(t,e)}dispose(){this.isBuilt&&(null!==this.geometry&&(this.geometry.dispose(),this.geometry=null),this.isBuilt=!1,this.onDestroyed.send1(this))}build(t){this.isBuilt=!0;const e=t.geometry,i=new Ps;if(i.setIndex(new bs(e.indices,1)),i.setAttribute("position",new bs(e.vertices,3)),i.setAttribute("normal",new bs(e.normals,3)),i.setAttribute("uv",new bs(e.uvs,2)),this.geometry=i,this.enableBVH){const e=this.bvh=new Qd,i=t.bvh;e.setLeafCount(i.leaf_count),e.data=i.data}const n=this.mesh;return n.geometry=i,n.receiveShadow=!0,n.castShadow=!0,this.computeBoundingBox(),this.version++,n}}const bp=[],Sp=new wu;class Mp{tiles=[];on={tileBuilt:new _,tileDestroyed:new _};tileSize=new Eu(10,10);totalSize=new Eu(1,1);resolution=new Gd(4);scale=new Eu(1,1);__transform=new Float32Array(16);bvh=new Md;heightRange=new Wd(0,0);debugTileMaterialRandom=!1;constructor({material:t,buildWorker:e}){if(void 0===t){const e=function(t){const e=(new zc).load("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wIZFDQQxd+nEAAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAAH0lEQVQI12NkQAL///+Hs5kYcADSJRiRzWVkZKSFHQBYfwYMUOT4KAAAAABJRU5ErkJggg==");return e.magFilter=Yt,void 0!==t&&(e.wrapS=qt,e.wrapT=qt,e.repeat.copy(t)),e}(this.totalSize.clone()._sub(1,1).multiplyScalar(.5));t=new sc({map:e})}this.material=new Hd(t),this.buildWorker=e,this.material.onChanged.add((()=>{this.traverse(this.assignTileMaterial,this)}))}set transform(t){e(t,this.__transform)||(G(this.__transform,t),this.traverse((e=>{e.transform=t})))}get transform(){return this.__transform}setHeightRange(t,e){this.heightRange.set(t,e);const i=this.tiles,n=i.length;for(let s=0;s<n;s++){const n=i[s];if(!n.isBuilt&&!n.isBuildInProgress){const i=n.external_bvh;i.bounds[1]=t,i.bounds[4]=e,i.write_bounds()}}}initialize(){this.destroyTiles(),this.initializeTiles()}assignTileMaterial(t){let e=this.material.getValue();if(this.debugTileMaterialRandom){const t=new kd;t.setHSV(Math.random(),.6*(0,Math.random)()+.4,1),e=new sc({color:t.toUint()})}t.material=e,null!==t.mesh&&(t.mesh.material=e)}traverse(t,e){const i=this.tiles;let n,s=0;const r=i.length;for(;s<r;s++)n=i[s],t.call(e,n)}destroyTiles(){const t=this.tiles,e=t.length;for(let i=0;i<e;i++){const e=t[i];e.external_bvh.unlink(),e.dispose()}t.splice(0,e),this.bvh.release_all()}rebuild(){this.destroyTiles(),this.initializeTiles()}rebuildTilesByUV(t,e,i,n){const s=this.totalSize,r=t*s.x,a=i*s.x,o=e*s.y,l=n*s.y,h=this.getRawTilesOverlappingRectangle(r-1,o-1,a+1,l+1),c=h.length;for(let t=0;t<c;t++)h[t].isBuilt=!1}getRawTilesOverlappingRectangle(t,e,i,n){const s=[],r=this.tiles,a=r.length;for(let o=0;o<a;o++){const a=r[o],l=a.position.x,h=a.position.y;Ud(t,e,i,n,l,h,l+a.size.x,h+a.size.y)&&s.push(a)}return s}initializeTiles(){const t=this.totalSize,e=t.clone(),i=this.tileSize;e.divide(i),e.ceil();const n=this.tiles;if(n.length>0)throw new Error(`There are already ${n.length} initialized tiles, those must be destroyed before initialization can happen`);const s=e.y,r=e.x;for(let e=0;e<s;e++){const a=e<s-1?i.y:t.y-i.y*e;for(let s=0;s<r;s++){const o=s<r-1?i.x:t.x-i.x*s,l=new wp,h=e*r+s;n[h]=l,this.assignTileMaterial(l),l.gridPosition.set(s,e),l.size.set(o,a),l.position.set(i.x*s,i.y*e),l.scale.copy(this.scale),l.resolution.copy(this.resolution),l.setInitialHeightBounds(this.heightRange.min,this.heightRange.max),l.computeBoundingBox(),l.external_bvh.link(this.bvh,h)}}}computeTileIndex(t,e){return e*Math.ceil(this.totalSize.x/this.tileSize.x)+t}getRaw(t,e){if(t<0||t>=Math.ceil(this.totalSize.x/this.tileSize.x)||e<0)return;const i=this.computeTileIndex(t,e);return this.tiles[i]}getRawTileByPosition(t,e){const i=Math.floor(t/this.tileSize.x),n=Math.floor(e/this.tileSize.y);return this.getRaw(i,n)}getTileByWorldPosition2D(t,e){const i=function(t,e,i){var n=new V(3);return n[0]=t,n[1]=0,n[2]=i,n}(t,0,e),n=W();return H(n,this.transform),function(t,e,i){var n=e[0],s=e[1],r=e[2],a=i[3]*n+i[7]*s+i[11]*r+i[15];a=a||1,t[0]=(i[0]*n+i[4]*s+i[8]*r+i[12])/a,t[1]=(i[1]*n+i[5]*s+i[9]*r+i[13])/a,t[2]=(i[2]*n+i[6]*s+i[10]*r+i[14])/a}(i,i,n),this.getRawTileByPosition(i[0],i[1])}obtainTileAtWorldPosition2D(t,e){const i=this.getTileByWorldPosition2D(t,e);return this.obtain(i.gridPosition.x,i.gridPosition.y)}obtain(t,e){const i=this.getRaw(t,e);if(void 0===i)throw new Error(`No tile found at x=${t},y=${e}`);return i.referenceCount++,i.isBuilt?Promise.resolve(i):i.isBuildInProgress?new Promise(((t,e)=>{i.onBuilt.addOne(t),i.onDestroyed.addOne(e)})):new Promise(((i,n)=>this.build(t,e,i,n)))}release(t){t.referenceCount,t.referenceCount--,t.referenceCount<=0&&t.dispose()}dispose(){const t=this.tiles,e=t.length;for(let i=0;i<e;i++)t[i].dispose()}stitchTile(t,e,i){const n=this.totalSize.clone();n.divide(this.tileSize),n.floor();const s=this;let r,a,o,l,h,c,u,d;e>0&&(r=s.getRaw(t,e-1),t>0&&(h=s.getRaw(t-1,e-1)),t<n.x-1&&(c=s.getRaw(t+1,e-1))),e<n.y-1&&(a=s.getRaw(t,e+1),t>0&&(u=s.getRaw(t-1,e+1)),t<n.x-1&&(d=s.getRaw(t+1,e+1))),t>0&&(o=s.getRaw(t-1,e)),t<n.x-1&&(l=s.getRaw(t+1,e)),i.stitchNormals(r,a,o,l,h,c,u,d)}raycastFirstSync(t,e,i,n,s,r,a){const o=function(t,e,i,n,s,r,a,o,l,h){if(e===wd)return 0;const c=Ed.pointer++;Ed[c]=e;let u=0;const d=t.__data_float32,p=t.__data_uint32;do{Ed.pointer--;const t=Ed[Ed.pointer],e=t*bd;if(!Cd(d[e],d[e+1],d[e+2],d[e+3],d[e+4],d[e+5],s,r,a,o,l,h))continue;const n=p[e+7];n!==wd?(Ed[Ed.pointer++]=p[e+8],Ed[Ed.pointer++]=n):i[u++]=t}while(Ed.pointer>c);return u-0}(this.bvh,this.bvh.root,bp,0,e,i,n,s,r,a);let l=Number.POSITIVE_INFINITY,h=!1;for(let c=0;c<o;c++){const o=bp[c],u=this.bvh.node_get_user_data(o),d=this.tiles[u];if(!d.isBuilt)continue;if(!d.raycastFirstSync(Sp,e,i,n,s,r,a))continue;h=!0;const p=Sp.position._distanceSqrTo(e,i,n);p<l&&(l=p,t.copy(Sp))}return h}raycastVerticalFirstSync(t,e,i){return this.raycastFirstSync(t,e,-1e4,i,0,1,0)}build(t,e,i,n){const s=this.computeTileIndex(t,e),r=this.tiles[s];if(r.isBuildInProgress)throw new Error("Tile is already in process of being built");const a=r.version;r.isBuilt=!1,r.isBuildInProgress=!0;const o=r.resolution.getValue();this.buildWorker.buildTile(r.position.toJSON(),r.size.toJSON(),r.scale.toJSON(),this.totalSize.toJSON(),o).then((o=>{if(this.tiles[s]===r)if(r.version===a){if(!r.isBuildInProgress)return r.isBuilt?void i(r):void n("Build request has been cancelled");r.build(o),this.stitchTile(t,e,r),r.external_bvh.write_bounds(),r.isBuilt=!0,r.isBuildInProgress=!1,r.onBuilt.send1(r),this.on.tileBuilt.send1(r),i(r)}else n(`Tile version changed, likely due to concurrent build request. Expected version ${a}, actual version ${r.version}`);else n("Original tile was destroyed during build process")}),(t=>{r.isBuilt=!1,r.isBuildInProgress=!1,n(t)}))}}class Tp{used=new Set;get(){const t=document.createElement("canvas"),e=new hl({alpha:!0,context:t.getContext("webgl2",{antialias:!0}),canvas:t});return this.used.add(e),e}release(t){return!!this.used.has(t)&&(this.used.delete(t),t.forceContextLoss(),t.dispose(),t.domElement=null,!0)}use(t,e){const i=this.get();try{return t.call(e,i)}finally{this.release(i)}}async useAsync(t,e){const i=this.get();try{await t.call(e,i)}finally{this.release(i)}}static global=new Tp}function Ap(t,e){if(1===t.itemSize){if(e.format!==xe&&e.format!==_e)throw new Error("itemSize is 1 and texture.format is not RedFormat")}else if(2===t.itemSize){if(e.format!==be)throw new Error("itemSize is 2 and texture.format is not RGFormat")}else if(3===t.itemSize){if(e.format!==fe)throw new Error("itemSize is 3 and texture.format is not RGBFormat")}else{if(4!==t.itemSize)throw new Error("Unsupported itemSize");if(e.format!==me)throw new Error("itemSize is 4 and texture.format is not RGBAFormat")}e.image.data!==t.data&&e.dispose(),e.image.data=t.data,e.image.width=t.width,e.image.height=t.height,e.needsUpdate=!0}const Cp=" \n varying vec2 vUv;\n\n void main() {\n\n vUv = uv;\n \n gl_Position = vec4( (uv - 0.5)*2.0, 0.0, 1.0 );\n \n }",Ep=new Ps;function zp(t,e,i,n,s){void 0===s&&(s=new Uint8ClampedArray(e*i*4)),t.setSize(e,i);const r=new zr(-1,1,1,-1,0,1),a=new cl;a.add(r);const o=new nr(Object.assign({vertexShader:Cp},n));o.lights=!1,o.fog=!1,o.uniformsNeedUpdate=!0,o.needsUpdate=!0,o.side=tt;const l=new Zs(Ep,o);a.add(l);const h=new qi(e,i,{generateMipmaps:!1,minFilter:Kt,stencilBuffer:!1,depthBuffer:!1}),c=t.getRenderTarget();t.setRenderTarget(h),t.render(a,r);const u=t.getContext();return u.readPixels(0,0,e,i,u.RGBA,u.UNSIGNED_BYTE,s),t.setRenderTarget(c),h.dispose(),o.dispose(),{array:s,graphics:t}}Ep.setAttribute("position",new bs(new Float32Array([-1,-1,0,3,-1,0,-1,3,0]),3)),Ep.setAttribute("uv",new bs(new Float32Array([0,0,2,0,0,2]),2));const Ip=function(){return{uniforms:{heightMap:{type:"t",value:null},resolution:{type:"v2",value:new Ri(512,512)}},vertexShader:["varying vec2 vUv;","void main() {","vUv = uv;","gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","}"].join("\n"),fragmentShader:["uniform vec2 resolution;","uniform sampler2D heightMap;","#define sqrt2 1.41421356237;","varying vec2 vUv;","void main() {"," float uStep = 1.0/resolution.x;"," float vStep = 1.0/resolution.y;"," float top = texture2D( heightMap, vUv + vec2(0, -vStep)).x;"," float bottom = texture2D( heightMap, vUv + vec2(0, +vStep)).x;"," float left = texture2D( heightMap, vUv + vec2(-uStep, 0)).x;"," float right = texture2D( heightMap, vUv + vec2(+uStep, 0)).x;"," float dX = (right ) - ( left);"," float dY = ( bottom ) - ( top);"," float dZ = 2.0;"," vec3 n = normalize(vec3(dX, dY, dZ));"," gl_FragColor = vec4( n*0.5+0.5, 1.0 );","}"].join("\n")}};function Lp(t){switch(t){case 1:return xe;case 2:return be;case 3:return fe;case 4:return me;default:throw new Error(`Unsupported channel count '${t}'`)}}function Np(t,e){let i="";switch(t){case ju.Uint8:i="8UI";break;case ju.Uint16:i="16UI";break;case ju.Uint32:i="32UI";break;case ju.Int8:i="8I";break;case ju.Int16:i="16I";break;case ju.Int32:i="32I";break;case ju.Float16:i="16F";break;case ju.Float32:i="32F";break;case ju.Float64:i="64F";break;default:throw new Error(`Unsupported data type '${t}'`)}let n="";switch(e){case 1:n="R";break;case 2:n="RG";break;case 3:n="RGB";break;case 4:n="RGBA";break;default:throw new Error(`Unsupported channel count '${e}'`)}return n+i}function Pp(t){const e=t.width,i=t.height,n=new Fl(t.data,e,i);return n.wrapS=Jt,n.wrapT=Jt,n.generateMipmaps=!1,n.minFilter=Kt,n.magFilter=Yt,n.flipY=!1,n.type=oe,n.format=Lp(t.itemSize),n.internalFormat=Np(ju.Float32,t.itemSize),n.needsUpdate=!0,n}function Dp(t){return t/255-.5}const Fp=function(){return{uniforms:{normalMap:{type:"t",value:null},heightMap:{type:"t",value:null},world_size:{type:"v2",value:new Ri(512,512)},rayLength:{type:"f",value:17}},defines:{NUM_SAMPLES:64,NUM_RINGS:7},vertexShader:["varying vec2 vUv;","void main() {","vUv = uv;","gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","}"].join("\n"),fragmentShader:["\n uniform sampler2D normalMap;\n uniform sampler2D heightMap;\n uniform float rayLength;\n uniform vec2 world_size;\n\n varying vec2 vUv;\n\n vec3 get(float x, float y){\n vec2 _uv = vUv.xy + vec2(x,y) / world_size;\n float h = texture2D(heightMap, _uv).x;\n return vec3( _uv.x * world_size.x, h, _uv.y * world_size.y );\n }\n \n float hash1( float n )\n {\n return fract( n*17.0*fract( n*0.3183099 ) );\n }\n \n float hash1( vec2 p )\n {\n p = 50.0*fract( p*0.3183099 );\n return fract( p.x*p.y*(p.x+p.y) );\n }\n \n // Non-sin based hash function, fast and has good randomness\n float hash12(vec2 p){\n vec3 p3 = fract(vec3(p.xyx) * .1031);\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n }\n \n const float bias = 0.001;\n \n float pow2(float x){\n return x*x;\n }\n \n float getOcclusion(vec3 origin, vec3 normal, vec3 hit_position){\n vec3 viewDelta = hit_position - origin;\n \n float viewDistance = length( viewDelta );\n \n float vn = dot( normal, viewDelta );\n float a2 = (vn) / viewDistance - bias;\n float a1 = (1.0 + pow2( viewDistance ) );\n \n return max(0.0, a2) / a1;\n }\n \n const float PI2 = 6.28318530717958;\n const float kernelRadius = 100.0;\n \n const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n \n float getAmbientOcclusion(vec3 world_position, vec3 world_normal){\n // jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/\n float angle = hash12( vUv ) * PI2;\n vec2 radius = vec2( rayLength * INV_NUM_SAMPLES );\n \n float occlusionSum = 0.0;\n float weightSum = 0.0;\n \n for( int i = 0; i < NUM_SAMPLES; i ++ ) {\n vec2 sampleUv = vec2( cos( angle ), sin( angle ) ) * radius * float(i+1);\n \n angle += ANGLE_STEP;\n \n vec3 sample_pos = get(sampleUv.x, sampleUv.y);\n \n occlusionSum += getOcclusion(world_position, world_normal, sample_pos);\n weightSum += 1.0;\n }\n \n return occlusionSum/weightSum;\n }\n \n void main() {\n vec3 pos = get(0.0, 0.0);\n \n vec3 normal = texture2D( normalMap, vUv ).xzy;\n \n float occlusion = getAmbientOcclusion(pos, normal);\n \n float incident = 1.0 - occlusion;\n \n gl_FragColor = vec4(pow(incident,10.0), 0.0, 0.0, 1.0);\n }\n "].join("\n")}};function Op(t,e){return.39894*function(t,e){const i=e*e,n=t*t;return Math.exp(-i/(2*n))}(e,t)/e}const Rp=15,kp=`\n// bilateral filter, based on https://www.shadertoy.com/view/4dfGDH# and\n// http://people.csail.mit.edu/sparis/bf_course/course_notes.pdf\n// A bilateral filter is a non-linear, edge-preserving, and noise-reducing smoothing filter for images.\n// It replaces the intensity of each pixel with a weighted average of intensity values from nearby pixels.\n// This weight can be based on a Gaussian distribution. Crucially, the weights depend not only on\n// Euclidean distance of pixels, but also on the radiometric differences (e.g., range differences, such\n// as color intensity, depth distance, etc.). This preserves sharp edges.\n\nfloat normpdf3(in vec3 v, in float sigma) {\n return 0.39894 * exp(-0.5 * dot(v, v) / (sigma * sigma)) / sigma;\n}\n\n// filter size\n#define MSIZE ${Rp}\nvarying vec2 vUv;\nuniform sampler2D source;\nuniform vec2 pixelOffset;\nuniform vec2 sigmas;\nuniform float bZnorm;\nuniform float kernel[MSIZE];\n\nvoid main(void) {\n\n // range sigma - controls blurriness based on a pixel distance\n float sigma = sigmas.x;\n \n // domain sigma - controls blurriness based on a pixel similarity (to preserve edges)\n float bSigma = sigmas.y;\n vec4 pixel = texture2D(source, vUv);\n vec4 accumulatedColor = vec4(0.0);\n float accumulatedFactor = 0.0;\n \n // read out the texels\n const int kSize = (MSIZE-1)/2;\n \n for (int i = -kSize; i <= kSize; ++i) {\n for (int j = -kSize; j <= kSize; ++j) {\n\n // sample the pixel with offset\n vec2 coord = vUv + vec2(float(i), float(j)) * pixelOffset;\n vec4 rgba = texture2D(source, coord);\n \n // bilateral factors\n float factor = kernel[kSize + j] * kernel[kSize + i];\n factor *= normpdf3(rgba.rgb - pixel.rgb, bSigma) * bZnorm;\n \n // accumulate\n accumulatedColor += factor * rgba;\n accumulatedFactor += factor;\n }\n }\n \n gl_FragColor = accumulatedColor / accumulatedFactor;\n}\n`;function Bp(t=10,e=.2){const i=1/Op(0,e),n=new Float32Array(Rp),s=Math.floor((Rp-1)/2);for(let e=0;e<=s;e++){const i=Op(e,t);n[s+e]=i,n[s-e]=i}return{uniforms:{source:{type:"t",value:null},pixelOffset:{type:"v2",value:new Ri(1,1)},sigmas:{type:"v2",value:new Ri(t,t)},bZnorm:{type:"f",value:i},kernel:{type:"f",value:n}},fragmentShader:kp}}function Up(t,e){return t.equals(e)}function Vp(t){return t.hash()}function Wp(t,e){return(t<<2)+t+1&e}class Gp{constructor(t,e,i){this.key=t,this.value=e,this.hash=i}}const Hp=4294967295,jp=new Uint32Array(0);class qp{__bins=jp;__entries=new Array(0);__entries_bound=0;__entries_start=0;__size=0;__bin_count=0;__entries_allocated_count=0;__bin_count_power_of_two=0;__entries_count_power_of_two=0;__bin_count_mask=0;__load_factor=.75;__version=0;constructor({keyHashFunction:t=Vp,keyEqualityFunction:e=Up,capacity:i=16,loadFactor:n=.75}={}){this.keyHashFunction=t,this.keyEqualityFunction=e,this.__load_factor=n,this.#o(jd(i))}get size(){return this.__size}getCurrentLoad(){return this.__size/this.__bin_count}#o(t){if(t<this.__size)throw new Error(`count must be at least equal to must of records in the map (=${this.__size}), instead was ${t}`);this.__entries_count_power_of_two=function(t){let e=t,i=0;return 0==(65535&e)&&(e>>=16,i+=16),0==(255&e)&&(e>>=8,i+=8),0==(15&e)&&(e>>=4,i+=4),0==(3&e)&&(e>>=2,i+=2),0==(1&e)&&(e>>=1,i+=1),0===e&&(i+=1),i}(t),this.__bin_count_power_of_two=this.__entries_count_power_of_two+1,this.__bin_count=2**this.__bin_count_power_of_two,this.__bin_count_mask=this.__bin_count-1;const e=this.__entries_allocated_count;this.__entries_allocated_count=2**this.__entries_count_power_of_two;const i=function(t){if(t<=256)return Uint8Array;if(t<=65536)return Uint16Array;if(t<=4294967295)return Uint32Array;throw new Error(`Unsupported size ${t}`)}(this.__entries_allocated_count+2);this.__bins=new i(this.__bin_count);const n=new Array(this.__entries_allocated_count),s=this.__entries;this.__entries=n,ed(s,0,n,0,Su(e,this.__entries_allocated_count)),this.__size>0&&this.rebuild()}compute_bin_index(t){return(t>>>16^t)>>>0&this.__bin_count_mask}#l(t){const e=this.keyHashFunction(t);return e===Hp?0:e}#h(t,e,i){return t.hash===e&&(t.key===i||this.keyEqualityFunction(t.key,i))}#c(t,e,i){const n=this.__entries_bound;this.__entries_bound++;const s=this.__entries[n];return void 0!==s?(s.hash=i,s.key=t,s.value=e):this.__entries[n]=new Gp(t,e,i),n}#u(t){t.key=null,t.value=null,t.hash=Hp}#d(){this.__entries_bound===this.__entries_allocated_count&&(this.__size===this.__entries_allocated_count?this.#p():this.rebuild())}set(t,e){this.#d();const i=this.#l(t);let n=this.compute_bin_index(i),s=-1;for(;;){const r=this.__bins[n];if(r>1){const n=this.__entries[r-2];if(this.#h(n,i,t))return void(n.value=e)}else{if(0===r){-1!==s&&(n=s);const r=this.#c(t,e,i)+2;this.__bins[n]=r;break}-1===s&&(s=n)}n=Wp(n,this.__bin_count_mask)}const r=this.__size+1;this.__size=r,r/this.__bin_count>this.__load_factor&&this.#p()}get(t){const e=this.#l(t);let i=this.compute_bin_index(e);for(;;){const n=this.__bins[i];if(n>1){const i=this.__entries[n-2];if(this.#h(i,e,t))return i.value}else if(0===n)return;i=Wp(i,this.__bin_count_mask)}}getOrCompute(t,e,i){const n=this.get(t);if(void 0!==n)return n;const s=e.call(i,t);return this.set(t,s),s}getOrSet(t,e){const i=this.get(t);return void 0!==i?i:(this.set(t,e),e)}#f(t){if(this.__entries_start!==t)return;let e=t+1,i=this.__entries_bound;const n=this.__entries;for(;e<i&&n[e].hash===Hp;)e++;this.__entries_start=e}delete(t){const e=this.#l(t);let i=this.compute_bin_index(e);const n=this.__bins,s=this.__entries;for(;;){const r=n[i];if(r>1){const a=r-2,o=s[a];if(this.#h(o,e,t))return this.#u(o),n[i]=1,this.__size--,this.#f(a),!0}else if(0===r)return!1;i=Wp(i,this.__bin_count_mask)}}verifyHashes(t,e){let i=!0;const n=this.__bin_count;for(let s=0;s<n;s++){const n=this.__bins[s];if(n<=1)continue;const r=this.__entries[n-2],a=this.#l(r.key);r.hash!==a&&(t.call(e,`Hash stored on the entry(=${r.hash}) is different from the computed key hash(=${a}).`,r.key,r.value),i=!1)}return i}#p(){this.#o(2*this.__entries_allocated_count)}rebuild(){const t=this.__entries_bound,e=this.__entries,i=this.__bins;i.fill(0);let n=0;for(let s=this.__entries_start;s<t;s++){const t=e[s].hash;if(t===Hp)continue;const r=n;if(n++,r!==s){const t=e[r];e[r]=e[s],e[s]=t}let a=this.compute_bin_index(t);for(;;){if(0===i[a]){i[a]=r+2;break}a=Wp(a,this.__bin_count_mask)}}this.__entries_start=0,this.__entries_bound=this.__size,this.__version++}#m(){let t=0;for(let e=this.__entries_start;e<this.__entries_bound;e++)this.__entries[e].hash!==Hp&&t++;return t}forEach(t,e){const i=this.__bin_count,n=this.__entries,s=this.__bins;this.__version;for(let r=0;r<i;r++){const i=s[r];if(i<=1)continue;const a=n[i-2];t.call(e,a.value,a.key,this)}}has(t){return void 0!==this.get(t)}clear(){const t=this.__bins,e=this.__bin_count;for(let i=0;i<e;i++){const e=t[i];if(0!==e){if(1!==e){const t=e-2;this.#u(this.__entries[t])}t[i]=0}}this.__size=0,this.__entries_start=0,this.__entries_bound=0}*[Symbol.iterator](){const t=this.__bin_count,e=this.__bins,i=this.__entries;this.__version;for(let n=0;n<t;n++){const t=e[n];if(t<=1)continue;const s=i[t-2];yield[s.key,s.value]}}*values(){for(const[t,e]of this)yield e}*keys(){for(const[t,e]of this)yield t}}function Jp(){return 1}function $p(){return 0}function Yp(t,e){return t===e}class Xp{constructor(){this.key=null,this.value=null,this.weight=0,this.next=null,this.previous=null}unlink(){const t=this.next,e=this.previous;null!==e&&(e.next=t),null!==t&&(t.previous=e)}toString(){return`CacheElement{ hasNext:${null!==this.next}, hasPrevious:${null!==this.previous}, weight:${this.weight}, key:${this.key}, value:${this.value} }`}}class Zp{#_=Number.POSITIVE_INFINITY;#g=0;constructor({maxWeight:t=Number.POSITIVE_INFINITY,keyWeigher:e=$p,valueWeigher:i=Jp,keyHashFunction:n=$p,keyEqualityFunction:s=Yp,capacity:r}={}){this.#_=t,this.keyWeigher=e,this.valueWeigher=i,this.__first=null,this.__last=null,this.data=new qp({keyHashFunction:n,keyEqualityFunction:s,capacity:r}),this.onEvicted=new _,this.onRemoved=new _,this.onSet=new _}__promote(t){t!==this.__first&&(t===this.__last&&(this.__last=t.previous),t.unlink(),t.previous=null,null!==this.__first?(t.next=this.__first,this.__first.previous=t):t.next=null,this.__first=t)}size(){return this.data.size}setMaxWeight(t){this.maxWeight=t}get weight(){return this.#g}set maxWeight(t){if("number"!=typeof t||t<0)throw new Error(`Weight must be a non-negative number, instead was '${t}'`);this.#_=t,this.evictUntilWeight(this.#_)}get maxWeight(){return this.#_}recomputeWeight(){let t=0;for(let[e,i]of this.data){const n=this.computeElementWeight(e,i.value);i.weight=n,t+=n}this.#g=t,this.evictUntilWeight(this.#_)}updateElementWeight(t){const e=this.data.get(t);if(void 0===e)return!1;const i=e.weight,n=this.computeElementWeight(t,e.value);if(n===i)return!0;e.weight=n;const s=n-i;return this.#g+=s,this.#g>this.#_&&n<=this.#_&&this.evictUntilWeight(this.#_),!0}computeElementWeight(t,e){return this.keyWeigher(t)+this.valueWeigher(e)}findEvictionVictim(){return this.__last}evictOne(){const t=this.findEvictionVictim();return null!==t&&(this.remove(t.key),this.onEvicted.send2(t.key,t.value),!0)}evictUntilWeight(t){const e=Math.max(t,0);for(;this.#g>e;)this.evictOne()}put(t,e){let i=this.data.get(t);if(void 0===i){const n=this.computeElementWeight(t,e),s=this.#_-n;if(s<0)return;i=new Xp,i.key=t,i.value=e,i.next=this.__first,null!==this.__first&&(this.__first.previous=i),this.__first=i,null===this.__last&&(this.__last=i),i.weight=n,this.evictUntilWeight(s),this.data.set(t,i),this.#g+=n}else{if(e===i.value);else{this.#g-=i.weight;const n=this.computeElementWeight(t,e);this.#g+=n,i.weight=n,i.value=e}this.__promote(i)}this.onSet.send2(t,e)}contains(t){return this.data.has(t)}get(t){const e=this.data.get(t);return void 0===e?null:(this.__promote(e),e.value)}getOrCompute(t,e,i){const n=this.get(t);if(null!==n)return n;const s=e.call(i,t);return this.set(t,s),s}__removeElement(t){t.value,t===this.__first&&(this.__first=t.next),t===this.__last&&(this.__last=t.previous),t.unlink();const e=t.key;this.data.delete(e),this.#g-=t.weight}remove(t){const e=this.data.get(t);return void 0!==e&&(this.__removeElement(e),this.onRemoved.send2(t,e.value),!0)}silentRemove(t){const e=this.data.get(t);return void 0!==e&&(this.__removeElement(e),!0)}clear(){const t=[];!function(t,e){for(let i=e.next();!i.done;i=e.next())t.push(i.value)}(t,this.data.keys());const e=t.length;for(let i=0;i<e;i++){const e=t[i];this.remove(e)}}drop(){this.data.clear(),this.__first=null,this.__last=null,this.#g=0}validate(t,e){return this.data.verifyHashes(((i,n,s)=>{t.call(e,i,n,s.value)}))}}function Kp(t,e){const i=e.length;i>=t.length?e.set(t,0):t.constructor===e.constructor?vd(t.buffer,t.byteOffset,e.buffer,e.byteOffset,Math.min(t.byteLength,e.byteLength)):ed(t,0,e,0,i)}function Qp(t,e){return t===e||"object"==typeof t&&"function"==typeof t.equals&&t.equals(e)}function tf(t,e,i){const n=t.length;for(let s=0;s<n;s++)if(i(e,t[s]))return s;return-1}function ef(t,e,i=Yp){const n=t.slice(),s=e.slice(),r=[];let a=n.length;for(let t=0;t<a;t++){const e=n[t],o=tf(s,e,i);-1!==o&&(r.push(e),n.splice(t,1),s.splice(o,1),t--,a--)}return{uniqueA:n,uniqueB:s,common:r}}Zp.prototype.set=Zp.prototype.put,Zp.prototype.delete=Zp.prototype.remove,Zp.prototype.has=Zp.prototype.contains;class nf{on={added:new _,removed:new _};data=[];constructor(t){void 0!==t&&(this.data=t.slice()),this.length=this.data.length}get(t){return this.data[t]}set(t,e){const i=this.data[t];void 0!==i?this.on.removed.send2(i,t):t>=this.length&&(this.length=t+1,this.length),this.data[t]=e,this.on.added.send2(e,t)}add(t){this.data.push(t);const e=this.length;return this.length=e+1,this.on.added.send2(t,e),this}addUnique(t){return!this.contains(t)&&(this.add(t),!0)}insert(t,e){return t>this.length?(this.length=t,this.data[t]=e):this.data.splice(t,0,e),this.length++,this.on.added.send2(e,t),this}crop(t,e){const i=this.data,n=i.splice(e,this.length-e),s=i.splice(0,t);this.length=e-t;const r=s.length,a=n.length,o=this.on.removed;if(o.hasHandlers()){let t;for(t=0;t<r;t++)o.send2(s[t],t);for(t=0;t<a;t++)o.send2(n[t],e+t)}return r+a}patch(t){const e=ef(this.data,t,Qp),i=e.uniqueA,n=i.length;for(let t=0;t<n;t++){const e=i[t];this.removeOneOf(e)}const s=e.uniqueB;s.sort(((e,i)=>{const n=t.indexOf(e);return t.indexOf(i)-n}));const r=s.length;for(let e=0;e<r;e++){const i=s[e];let n=0;for(let e=t.indexOf(i)-1;e>=0;e--){const i=t[e],s=this.indexOf(i);if(-1!==s){n=s+1;break}}this.insert(n,i)}}addAll(t){const e=t.length,i=this.on.added;if(i.hasHandlers())for(let n=0;n<e;n++){const e=t[n];this.data.push(e),i.send2(e,this.length++)}else Array.prototype.push.apply(this.data,t),this.length+=e}addAllUnique(t){const e=t.length;for(let i=0;i<e;i++)this.addUnique(t[i])}removeMany(t,e){const i=this.data.splice(t,e),n=i.length;this.length-=n;const s=this.on.removed;if(s.hasHandlers())for(let e=0;e<n;e++){const n=i[e];s.send2(n,t+e)}return i}remove(t){const e=this.data.splice(t,1);this.length--;const i=e[0];return this.on.removed.send2(i,t),i}removeAll(t){let e,i,n,s;i=t.length,s=this.length;let r=0;const a=this.data;t:for(e=0;e<i;e++){const i=t[e];for(n=s-1;n>=0;n--)if(Qp(a[n],i)){this.remove(n),s--;continue t}r++}return 0===r}removeOneOf(t){return"object"==typeof t&&"function"==typeof t.equals?this.removeOneIf(sf,t):this.removeOneIf(rf,t)}sort(t){return Array.prototype.sort.call(this.data,t),this}clone(){return new nf(this.data)}slice(t,e){return this.data.slice(t,e)}some(t){const e=this.length,i=this.data;for(let n=0;n<e;n++)if(t(i[n]))return!0;return!1}removeIf(t,e){let i=this.length;const n=this.data;for(let s=0;s<i;s++){const r=n[s];t.call(e,r)&&(this.remove(s),s--,i--)}}removeOneIf(t,e){const i=this.length,n=this.data;for(let s=0;s<i;s++){const i=n[s];if(t.call(e,i))return this.remove(s),!0}return!1}forEach(t,e){const i=this.length,n=this.data;for(let s=0;s<i;s++)t.call(e,n[s],s)}reduce(t,e){let i=e;return this.forEach((function(e){i=t(i,e)})),i}filter(t){return this.data.filter(t)}find(t){const e=this.data;let i=0;const n=this.length;for(;i<n;i++){const n=e[i];if(t(n))return n}}findIndex(t){const e=this.data;let i=0;const n=this.length;for(;i<n;i++)if(t(e[i]))return i;return-1}visitFirstMatch(t,e){const i=this.findIndex(t);if(-1===i)return!1;const n=this.data[i];return!!t(n)&&(e(n,i),!0)}contains(t){return-1!==this.data.indexOf(t)}containsAny(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];if(this.contains(e))return!0}return!1}isEmpty(){return this.length<=0}indexOf(t){return this.data.indexOf(t)}map(t,e){const i=[],n=this.data,s=this.length;for(let r=0;r<s;r++){const s=n[r];void 0!==s&&(i[r]=t.call(e,s,r))}return i}resetViaCallback(t,e){const i=this.length,n=this.on.removed,s=this.data;for(let r=i-1;r>=0;r--){const i=s[r];s.length=r,this.length=r,n.send2(i,r),t.call(e,i,r)}}reset(){const t=this.length;if(t>0){const e=this.on.removed;if(e.hasHandlers()){const i=this.data;for(let n=t-1;n>=0;n--){const t=i[n];this.data.length=n,this.length=n,e.send2(t,n)}}else this.data=[],this.length=0}}deepCopy(t,e,i){const n=[],s=t.asArray(),r=s.length,a=this.data;let o=this.length;for(let t=0;t<o;t++){const r=a[t],o=tf(s,r,Up);-1!==o?n[o]=r:"function"==typeof e&&e.call(i,r)}for(let t=0;t<r;t++)if(void 0===n[t]){const e=s[t];n[t]=e.clone()}this.reset(),this.addAll(n)}copy(t){this!==t&&(this.reset(),t.length>0&&(t instanceof nf?this.addAll(t.data):this.addAll(t)))}asArray(){return this.data}toJSON(){return JSON.parse(JSON.stringify(this.data))}fromJSON(t,e){this.reset(),"function"==typeof e?this.addAll(t.map((function(t){const i=new e;return i.fromJSON(t),i}))):this.addAll(t)}toBinaryBuffer(t){const e=this.length;t.writeUint32(e);for(let i=0;i<e;i++){const e=this.data[i];if("function"!=typeof e.toBinaryBuffer)throw new Error("item.toBinaryBuffer is not a function");e.toBinaryBuffer(t)}}fromBinaryBuffer(t,e){this.fromBinaryBufferViaFactory(t,(function(t){const i=new e;if("function"!=typeof i.fromBinaryBuffer)throw new Error("item.fromBinaryBuffer is not a function");return i.fromBinaryBuffer(t),i}))}fromBinaryBufferViaFactory(t,e){this.reset(),this.addFromBinaryBufferViaFactory(t,e)}addFromBinaryBufferViaFactory(t,e){const i=t.readUint32();for(let n=0;n<i;n++){const i=e(t);this.add(i)}}addFromJSONViaFactory(t,e){const i=t.length;for(let n=0;n<i;n++){const i=e(t[n]);this.add(i)}}hash(){let t=0;const e=this.length;for(let i=0;i<e;i++)t=(t<<5)-t+this.data[i].hash(),t|=0;return t}first(){return this.get(0)}last(){return this.get(this.length-1)}equals(t){const e=this.length;if(e!==t.length)return!1;let i;for(i=0;i<e;i++){const e=this.get(i),n=t.get(i);if(e!==n&&("object"!=typeof e||"object"!=typeof n||"function"!=typeof e.equals||!e.equals(n)))return!1}return!0}compare(t){const e=this.length,i=t.length;if(e!==i)return e-i;for(let i=0;i<e;i++){const e=this.get(i),n=t.get(i),s=e.compare(n);if(0!==s)return s}return 0}}function sf(t){return this===t||this.equals(t)}function rf(t){return this===t}function af(t){const e=t.length;let i=0;for(let n=0;n<e;n++){let e=t.charCodeAt(n);for(;e>255;)i++,e>>=8;i++}return i}const of=new Zp({maxWeight:304857600,keyHashFunction:rd,keyWeigher:af,valueWeigher:t=>t.computeByteSize()});class lf{textureDiffuseURL="";diffuse=Zu.uint8(3,1,1);size=new Eu(1,1);extra={};onChanged=new _;toJSON(){return{textureDiffuseURL:this.textureDiffuseURL,size:this.size.toJSON(),extra:this.extra}}fromJSON({textureDiffuseURL:t,size:e,extra:i={}}){this.textureDiffuseURL=t,this.size.fromJSON(e),this.extra=i}static from(t,e,i){const n=new lf;return n.textureDiffuseURL=t,n.size.set(e,i),n}static fromDescription(t){return lf.from(t.diffuse,t.size.x,t.size.y)}loadTextureData(t){const e=this.textureDiffuseURL,i=of.get(e);return null!==i?(this.diffuse.resize(i.width,i.height,!1),this.diffuse.data.set(i.data),this.onChanged.send0(),Promise.resolve()):t.promise(e,Lu).then((t=>{const i=void 0,n=i.itemSize,s=i.data;null!==this.diffuse&&this.diffuse.width===i.width&&this.diffuse.height===i.height||(this.diffuse=Zu.uint8(3,i.width,i.height)),function(t,e){if(t.width!==e.width||t.height!==e.height)throw new Error("Source and destination dimensions do not match");const i=t.itemSize,n=e.itemSize,s=t.width*t.height,r=e.data,a=t.data;let o=0,l=0;if(i===n)r.set(a);else if(i>n)for(o=0;o<s;o++){const t=o*i,e=o*n;for(l=0;l<n;l++)r[e+l]=a[t+l]}else if(3===i&&4===n){const t=function(t){switch(t){case Uint8Array:return 255;case Uint16Array:return 65535;case Uint32Array:return 4294967295;case Int8Array:return 127;case Int16Array:return 32767;case Int32Array:return 2147483647;case Float32Array:case Float64Array:default:return 1}}(r.constructor);for(o=0;o<s;o++){const e=3*o,i=4*o;r[i]=a[e],r[i+1]=a[e+1],r[i+2]=a[e+2],r[i+3]=t}}else{if(2!==i||4!==n)throw new Error("Unsupported channel layout combination");for(o=0;o<s;o++){const t=2*o,e=4*o,i=a[t];r[e]=i,r[e+1]=i,r[e+2]=i,r[e+3]=a[t+1]}}e.version++}(new Zu(s,n,i.width,i.height),this.diffuse),this.onChanged.send0();const r=Zu.uint8(3,i.width,i.height);r.data.set(this.diffuse.data),of.put(e,r)}))}}lf.prototype.isTerrainLayer=!0;class hf{uri="";size=new Eu;static from(t,e){const i=new hf;return i.uri=t,i.size.copy(e),i}hash(){return rd(this.uri)^this.size.hash()}equals(t){return this.uri===t.uri&&this.size.equals(t.size)}}const cf=new Zp({maxWeight:104857600,keyEqualityFunction:Up,keyHashFunction:Vp,valueWeigher:t=>t.computeByteSize()});class uf{constructor(){this.layers=new nf,this.resolution=new Eu(512,512),this.texture=new ea(new Uint8Array(3),1,1,1),this.texture.format=fe,this.texture.type=ee,this.texture.wrapS=qt,this.texture.wrapT=qt,this.texture.anisotropy=8,this.texture.magFilter=Kt,this.texture.minFilter=1008,this.texture.generateMipmaps=!0,this.texture.encoding=yi,this.texture.internalFormat="RGB8",this.scalesTexture=new Fl(new Float32Array(64),32,1,be,oe),this.scalesTexture.wrapS=Jt,this.scalesTexture.wrapT=Jt,this.scalesTexture.minFilter=Kt,this.scalesTexture.magFilter=Yt,this.scalesTexture.internalFormat="RG32F",this.scalesTexture.generateMipmaps=!1}toJSON(){return{resolution:this.resolution.toJSON(),layers:this.layers.toJSON()}}fromJSON({resolution:t=512,layers:e=[]}={}){this.resolution.fromJSON(t),this.layers.fromJSON(e,lf)}updateLayerScales(t,e){const i=this.layers,n=i.length,s=this.scalesTexture,r=s.image,a=2*n;r.data.length<a&&(s.dispose(),r.data=new Float32Array(a),r.height=1,r.width=n);const o=r.data;for(let s=0;s<n;s++){const n=i.get(s),r=2*s,a=t/n.size.x,l=e/n.size.y;o[r]=a,o[r+1]=l}s.needsUpdate=!0}loadTextureData(t){const e=this.layers.length,i=[];for(let n=0;n<e;n++){const e=this.layers.get(n).loadTextureData(t),s=n;e.then((()=>{this.writeLayerDataIntoTexture(s)}),(t=>{})),i.push(e)}return Promise.all(i)}writeAllLayersDataIntoTexture(){for(let t=0;t<this.layers.length;t++)this.writeLayerDataIntoTexture(t)}get(t){return this.layers.get(t)}findIndexByDescription(t){const e=this.layers,i=e.length;for(let n=0;n<i;n++){const i=e.get(n);if(i.size.equals(t.size)&&i.textureDiffuseURL===t.diffuse)return n}return-1}findIndexByDiffuseTextureURL(t){return this.layers.findIndex((e=>e.textureDiffuseURL===t))}count(){return this.layers.length}addLayer(t){const e=this.layers.length;return this.layers.add(t),e}removeLayer(t){return this.layers.removeOneOf(t)}__obtain_layer_data_at_resolution(t,e){const i=t.diffuse,n=e.x,s=e.y;if(i.width===n&&i.height===s)return t.diffuse;{const r=hf.from(t.textureDiffuseURL,e),a=cf.get(r);if(null!==a)return a;const o=Zu.uint8(3,n,s);return cd(i,o),cf.put(r,o),o}}writeLayerDataIntoTexture(t){const e=this.get(t),i=this.texture.image.data,n=this.resolution,s=n.x*n.y*3;if(i.length<s*t)throw new Error("Texture data is too small, make sure you rebuild texture data before attempting to write");const r=s*t,a=this.__obtain_layer_data_at_resolution(e,n);i.set(a.data,r),this.texture.needsUpdate=!0}dispose(){this.texture.dispose(),this.scalesTexture.dispose()}clear(){this.layers.reset()}buildTexture(){const t=this.texture,e=t.image,i=this.resolution.x,n=this.resolution.y,s=this.layers.length;if(e.width===i&&e.height===n&&e.depth===s)return;t.dispose();const r=new Uint8Array(i*n*3*s);e.width===i&&e.height===n&&Kp(e.data,r),e.data=r,e.width=i,e.height=n,e.depth=s,t.needsUpdate=!0}}const df=/[a-zA-Z0-9_\-]+\:\/\//,pf="object"==typeof window,ff="object"==typeof process&&!pf,mf="function"==typeof importScripts;class _f{constructor(t,e){this.text=t,this.indentation=e}toString(){return`Line{ indentation=${this.indentation}, text="${this.text}" }`}}class gf{#y=[];#v=0;indentSpaces=4;get count(){return this.#y.length}containsSubstring(t){const e=this.#y,i=e.length;for(let n=0;n<i;n++)if(-1!==e[n].text.indexOf(t))return!0;return!1}indent(){return this.#v++,this}dedent(){return this.#v--,this}add(t){const e=new _f(t,this.#v);return this.#y.push(e),this}addLines(t){const e=t.#y,i=e.length;for(let t=0;t<i;t++){const i=e[t],n=new _f(i.text,i.indentation+this.#v);this.#y.push(n)}}clear(){this.#y=[],this.#v=0}build(){const t=[];let e,i,n;const s=this.#y;for(e=0,n=s.length;e<n;e++){const n=s[e];let r="";for(i=0;i<n.indentation*this.indentSpaces;i++)r+=" ";t.push(r+n.text)}return t.join("\n")}static fromText(t,e="\n"){const i=new gf,n=t.split(e),s=n.length;for(let t=0;t<s;t++){const e=n[t];i.add(e)}return i}toString(){return this.build()}}function yf(t,e){try{return t.postMessage(e),!0}catch(t){return!1}}class vf{__pending={};__isRunning=!1;__worker=null;__id_counter=0;constructor(t,e){this.url=t,this.methods=e,this.__generateAPI()}$submitRequest(t,e){const i=this.__pending[t],n=e.length,s=new Array(n);for(let t=0;t<n;t++){const i=e[t];null!==(r=i)&&"object"==typeof r&&r.hasOwnProperty("toJSON")&&"function"===r.toJSON?s[t]=i.toJSON():s[t]=i}var r;const a=this.__id_counter++;return new Promise(((e,n)=>{const r={parameters:s,id:a,resolve:e,reject:n};if(i.push(r),this.isRunning()){const e={methodName:t,id:r.id,parameters:s};if(!yf(this.__worker,e)){const t=i.indexOf(r);i.splice(t,1)}}}))}__makeMethod(t){if(this.__pending.hasOwnProperty(t))throw new Error(`Method '${t}' already defined`);this.__pending[t]=[];const e=this;this[t]=function(){return e.$submitRequest(t,arguments)}}__generateAPI(){for(let t in this.methods)this.methods.hasOwnProperty(t)&&this.__makeMethod(t)}__handleMessage=t=>{const e=this.__pending,i=t.data,n=i.id,s=i.methodName,r=e[s];if(void 0===r)throw new Error("Unexpected method '"+s+"'");{const t=r.length;for(let e=0;e<t;e++){const t=r[e];if(t.id===n)return r.splice(e,1),void(i.hasOwnProperty("error")?t.reject(i.error):t.resolve(i.result))}throw new Error(`Request ${n} not found in the request queue`)}};isRunning(){return this.__isRunning}stop(){this.__isRunning&&(this.__worker.terminate(),this.__isRunning=!1)}cancelRequest(t,e){const i=this.__pending[e];if(void 0===i)throw new Error(`No request queue for method name '${e}'`);const n=i.length;for(let e=0;e<n;e++)if(i[e].id===t){if(this.__isRunning)throw new Error("Ability to cancel pending requests while worker is running is not implemented yet");return i.splice(e,1),!0}}sendPendingRequests(){for(let t in this.__pending)if(this.__pending.hasOwnProperty(t)){const e=this.__pending[t],i=e.length;for(let n=0;n<i;n++){const i=e[n],s={methodName:t,id:i.id,parameters:i.parameters};yf(this.__worker,s)}}}start(){this.__isRunning||(this.__worker=new Worker(this.url),this.__worker.onmessage=this.__handleMessage,this.__worker.onerror=t=>{},this.__isRunning=!0,this.sendPendingRequests())}}const xf=/(function\s*)([a-zA-Z0-9_]+)?(\s*\([^\]]*\)\s*\{.*)/g;class wf{imports=[];methods={};functions=[];preamble=new gf;addCode(t){this.preamble.add(t)}addMethod(t,e){this.methods[t]=e}importFunction(t,e){this.functions.push({f:e,name:t})}importScript(t){const e=function(t){const e=function(t){return 0===t.search(df)}(t);let i=t;return e||(i=function(t){let e;if(pf)e=window;else if(mf)e=self;else{if(!ff)throw new Error("Unknown environment");{let t=`${process.cwd()}/`.replace(/\\/g,"/");t=t.replace(/\/+/g,"/"),"/"!==t[0]&&(t=`/${t}`),e={location:{pathname:t,host:"",protocol:"file:"}}}}const i=e.location,n=i.pathname;let s;if(n.endsWith("/"))s=n.substring(0,n.length-1);else{const t=n.lastIndexOf("/");s=-1===t?"":n.substring(0,t)}return i.protocol+"//"+i.host+s+"/"+t}(t)),i}(t);this.imports.push(e)}build(){const t=[];t.push("var globalScope = globalThis;"),this.imports.forEach((function(e){t.push("globalScope.importScripts('"+e+"');")})),t.push(this.preamble.build()),this.functions.forEach((function(e){const i=e.f.toString().replace(xf,`$1${e.name}$3`);t.push(i)})),t.push("var api = {};");for(let e in this.methods)if(this.methods.hasOwnProperty(e)){const i=this.methods[e],n=typeof i;let s;if("function"===n)s=i.toString();else{if("string"!==n)throw new Error(`Unsupported method type '${n}'`);s=i}t.push("api['"+e+"'] = "+s+";")}Array.prototype.push.apply(t,['function extractTransferables(obj, result) {\n if (typeof obj !== "object") {\n return; //not an object, skip\n } else if (obj instanceof ArrayBuffer) {\n result.push(obj);\n } else if (obj.buffer instanceof ArrayBuffer) {\n result.push(obj.buffer);\n } else if (typeof ImageBitmap !== "undefined" && obj instanceof ImageBitmap) {\n result.push(obj);\n } else {\n for (var i in obj) {\n if (obj.hasOwnProperty(i)) {\n extractTransferables(obj[i], result);\n }\n }\n }\n }',"globalScope.onmessage = function(event){"," var eventData = event.data;"," var requestId = eventData.id"," var methodName = eventData.methodName;"," var parameters = eventData.parameters;"," var method = api[methodName];"," function sendResult(result){"," var transferables = [];"," extractTransferables(result, transferables);"," globalScope.postMessage({methodName: methodName, id: requestId, result: result}, transferables);"," }"," function sendError(error){",' let stack = "";',' try{stack = error.stack.split("\\n")}catch(e){}'," globalScope.postMessage({methodName: methodName, id: requestId, error: {message: error.message, stack: stack }});"," }"," if(method === undefined){",' sendError(new Error("API named \'"+methodName+"\' was not found."));'," }else{"," try{"," method.apply(null,parameters).then(sendResult, sendError);"," }catch(e){"," sendError(e);"," }"," }","};"]);const e=function(t,e="application/javascript"){const i=function(t,e="application/javascript"){let i;if(void 0!==globalThis.Blob)i=new Blob([t],{type:e});else{const e=globalThis.BlobBuilder||globalThis.BlobBuilder||globalThis.WebKitBlobBuilder||globalThis.MozBlobBuilder;if(void 0===e)throw new Error("No BlobBuilder interface supported in current context");i=new e,i.append(t),i=i.getBlob()}return i}(t,e);return void 0!==i&&void 0!==URL.createObjectURL?URL.createObjectURL(i):`data:${e},${encodeURIComponent(t)}`}(t.join("\n"));return new vf(e,this.methods)}}class bf{offset_x=0;offset_y=0;scale_x=1;scale_y=1}function Sf(t,e){return-1===t.indexOf(e)&&(t.push(e),!0)}function Mf(){}const Tf={INITIAL:0,READY:1,RUNNING:2,FAILED:3,SUCCEEDED:4,CANCELLED:5};let Af=0;class Cf{id=Af++;on={started:new _,completed:new _,failed:new _};state=new Gd(Tf.INITIAL);__executedCpuTime=0;__executedCycleCount=0;constructor({name:t="Unnamed",initializer:e=Mf,cycleFunction:i,computeProgress:n,dependencies:s=[],estimatedDuration:r=1}){this.dependencies=s,this.estimatedDuration=r,this.name=t,this.cycle=i,this.initialize=e,void 0!==n&&(this.computeProgress=n)}computeProgress(){const t=this.__executedCycleCount;return 0===t?0:1-1/t}getExecutedCpuTime(){return this.__executedCpuTime}getEstimatedDuration(){return this.estimatedDuration}addDependency(t){if(t.isTaskGroup)this.addDependencies(t.children);else{if(!t.isTask)throw new Error("Expected a Task or a TaskGroup, got something else");Sf(this.dependencies,t)}return this}addDependencies(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];this.addDependency(e)}}toString(){return`Task{name:'${this.name}'}`}join(t,e){Cf.join(this,t,e)}executeSync(){this.initialize(this,null),this.on.started.send0();let t=this.cycle();for(;0!==t&&1!==t;t=this.cycle());return 0===t?this.on.completed.send0():1===t&&this.on.failed.send0(),t}promise(){return Cf.promise(this)}static promiseAll(t){const e=t.map(Cf.promise);return Promise.all(e)}static promise(t){return new Promise(((e,i)=>Cf.join(t,e,i)))}static join(t,e,i){const n=t.state.getValue();n===Tf.SUCCEEDED?e():n===Tf.FAILED?void 0!==i&&i():(t.on.completed.addOne(e),void 0!==i&&t.on.failed.addOne(i))}static joinAll(t,e,i){let n=t.length;if(0===n)return void e();let s=!1;function r(){n--,n<=0&&!s&&e()}function a(){s||(s=!0,i(arguments))}for(let e=0;e<t.length;e++)t[e].join(r,a)}}Cf.prototype.isTask=!0;class Ef{constructor(){this.size=new Eu(1,1),this.depth=1;const t=this.size,e=t.x,i=t.y;this.weightTexture=new ea(new Uint8Array(e*i),e,i,1),this.weightTexture.generateMipmaps=!1,this.weightTexture.format=xe,this.weightTexture.type=ee,this.weightTexture.magFilter=Kt,this.weightTexture.minFilter=Yt,this.materialTexture=new Fl(new Uint8Array(e*i*4),e,i)}toJSON(){const t=Hu.encode(this.weightData.buffer);return{size:this.size.toJSON(),depth:this.depth,data:t}}fromJSON({size:t={x:1,y:1},depth:e=0,data:i}={}){let n;if(this.resize(t.x,t.y,e),"string"==typeof i){const t=Hu.decode(i);n=new Uint8Array(t)}else{if(!Array.isArray(i))throw new Error("Unsupported data format");n=i}ed(n,0,this.weightData,0,i.length),this.weightTexture.needsUpdate=!0}writeLayerFromSampler(t,e,i=0){const n=this.weightData,s=this.size.x,r=this.size.y,a=e*s*r,o=t.width,l=t.height-1,h=o-1;for(let e=0;e<r;e++){const o=e/r;for(let r=0;r<s;r++){const c=r/s,u=a+(e*s+r),d=t.sampleChannelBilinear(c*h,o*l,i);n[u]=d}}}readLayerToSampler(t,e,i=0){const n=this.weightData,s=this.size.x,r=this.size.y,a=e*s*r;for(let e=0;e<r;e++)for(let r=0;r<s;r++){const o=n[a+(e*s+r)];t.writeChannel(r,e,i,o)}}writeWeightData(t,e,i,n,s){const r=this.depth,a=n*s,o=this.size.x,l=this.size.y,h=o*l,c=bu(0,Su(o-e,n)),u=bu(0,Su(l-i,s)),d=this.weightData;for(let s=0;s<r;s++){const r=h*s,l=a*s;for(let s=0;s<u;s++){const a=(s+i)*o+r,h=s*n+l;for(let i=0;i<c;i++){const n=h+i;d[a+(i+e)]=t[n]}}}}readWeightData(t,e,i,n,s){const r=this.depth,a=this.size.x,o=this.size.y,l=a*o,h=n*s,c=bu(0,Su(a-e,n)),u=bu(0,Su(o-i,s)),d=this.weightData;for(let s=0;s<r;s++){const r=h*s,o=l*s;for(let s=0;s<u;s++){const l=s*n+r,h=(s+i)*a+o;for(let i=0;i<c;i++){const n=h+i+e;t[l+i]=d[n]}}}}sampleWeight(t,e,i){return this.getLayerWeightSampler(i).sampleChannelBilinearUV(t,e,0)}getLayerWeightSampler(t){const e=this.size.x,i=this.size.y,n=e*i,s=n*t,r=s+n;return new Zu(this.weightData.subarray(s,r),1,e,i)}get weightData(){return this.weightTexture.image.data}get materialData(){return this.materialTexture.image.data}get materialSampler(){return new Zu(this.materialData,4,this.size.x,this.size.y)}optimize(){return[]}computeWeightRankingMap(t){const e=this.size.x,i=this.size.y,n=this.depth,s=this.weightData,r=[],a=[];function o(t,e){const i=r[t];return r[e]-i}const l=e*i;return function(e,i,h){let c=0,u=0,d=c;const p=typeof i;return new Cf({name:"count (from 0 to "+("number"===p?i:"variable")+")",initializer(){c=0,"number"===p?u=i:"function"===p&&(u=i()),d=c},cycleFunction:function(){return d>=u?0:((e=>{for(let t=0;t<n;t++){const i=e+t*l;a[t]=t,r[t]=s[i]}a.sort(o);for(let i=0;i<n;i++){const n=a[i];t[e+n*l]=i}})(d),d++,2)},computeProgress:function(){const t=u-c;return 0===t?0:(d-c)/t}})}(0,e*i)}dispose(){this.weightTexture.dispose(),this.materialTexture.dispose()}removeWeightLayer(t){if(t>=this.depth)return!1;this.depth--;const e=this.size.x*this.size.y,i=t*e,n=(t+1)*e,s=this.weightTexture;s.dispose();const r=s.image,a=r.data;a.copyWithin(i,n);const o=new Uint8Array(this.depth*e);return o.set(a.subarray(0,o.length)),r.data=o,r.depth=this.depth,s.needsUpdate=!0,!0}fillLayerWeights(t,e){const i=this.size.x*this.size.y,n=i*t,s=n+i,r=this.weightData;for(let t=n;t<s;t++)r[t]=e}addWeightLayer(){this.weightTexture.dispose();const t=this.size.x*this.size.y;this.depth++;const e=this.depth,i=new Uint8Array(t*e);i.set(this.weightData),this.weightTexture.image.data=i,this.weightTexture.image.depth=e,this.weightTexture.needsUpdate=!0}resize(t,e,i,n=!0){const s=this.size.x,r=this.size.y,a=this.depth;this.depth=i,t===s&&e===r&&i===a||this.size.set(t,e);const o=this.weightTexture,l=o.image;if(l.width!==t||l.height!==e||l.depth!==i){o.dispose();const h=l.data,c=s*r,u=t*e;if(l.width=t,l.height=e,l.depth=i,l.data=new Uint8Array(u*i),n)if(s===t&&r===e)Kp(h,l.data);else for(let n=0;n<Su(i,a);n++)cd(new Zu(h.subarray(n*c,(n+1)*c),1,s,r),new Zu(l.data.subarray(n*u,(n+1)*u),1,t,e));o.needsUpdate=!0}}}let zf=0;class If{id=zf++;flags=0;gridScale=1;gridTransform=new bf;gridTransformKind=1;resolution=4;size=new Eu(0,0);preview=new yd;splat=new Ef;layers=new uf;__buildWorker=function(){const t=new wf;return t.importScript("bundle-worker-terrain.js"),t.addCode("\n function useSampler(callback) {\n if (globalScope.samplerHeight !== undefined) {\n callback(globalScope.samplerHeight);\n } else {\n if (globalScope.useSampleCallbacks === undefined) {\n globalScope.useSampleCallbacks = [callback];\n } else {\n globalScope.useSampleCallbacks.push(callback);\n }\n }\n }\n "),t.addMethod("computeHeightRange",(function(){return new Promise((function(t,e){useSampler((function(e){const i=Lib.sampler2d_channel_compute_min(e),n=Lib.sampler2d_channel_compute_max(e);t({min:i.value,max:n.value})}))}))})),t.addMethod("setHeightSampler",(function(t,e,i,n){return new Promise((function(s,r){globalScope.samplerHeight=new Lib.Sampler2D(t,e,i,n),void 0!==globalScope.useSampleCallbacks&&globalScope.useSampleCallbacks.forEach((function(t){t(globalScope.samplerHeight)})),s()}))})),t.addMethod("buildTile",(function(t,e,i,n,s){return new Promise((function(r,a){useSampler((function(o){try{const a=Lib.BufferedGeometryArraysBuilder.build(o,t,e,i,n,s);Lib.tensionOptimizeUV(a.vertices,a.uvs,a.indices,21);const l=Lib.build_bvh(a.vertices,a.indices);r({geometry:a,bvh:{leaf_count:l.leaf_node_count,data:l.data}})}catch(t){a(t)}}))}))})),t.build()}();bvh=new vu;constructor(){this.clouds=new gd,this.clouds.enabled=!0,this.heightRange=0,this.samplerHeight=Zu.float32(1,1,1),this.heightTexture=new Fl(this.samplerHeight.data,this.samplerHeight.width,this.samplerHeight,xe,oe),this.heightTexture.wrapS=Jt,this.heightTexture.wrapT=Jt,this.heightTexture.generateMipmaps=!1,this.heightTexture.minFilter=Kt,this.heightTexture.magFilter=Yt,this.heightTexture.flipY=!1,this.heightTexture.internalFormat="R32F",this.material=new ku({}),this.frustumCulled=!0,this.__transform_matrix=W(),this.overlay=new fd(this.size),this.__tiles=new Mp({material:this.material,buildWorker:this.__buildWorker}),this.__tiles.tileSize.set(Lf,Lf),this.__tiles.material.set(this.material),this.__assetManager=null,this.__legacyMaterialSpec=null,this.__legacyHeightSamplerURL=null,this.lightMapURL=null,this.__material_reference=null,this.initialize()}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}link(t){if(this.getFlag(2))return;this.startBuildService();const e=t.getMaterialManager().obtain(this.material);this.__material_reference=e;const i=e.getValue();this.clouds.addMaterial(i),this.__tiles.material.set(i),this.updateMaterial(),i.uniforms.diffuseMaps.value=this.layers.texture,this.setFlag(2)}unlink(){if(!this.getFlag(2))return;this.stopBuildService();const t=this.__material_reference.getValue();this.clouds.removeMaterial(t),this.__material_reference.release(),this.__tiles.dispose(),this.splat.dispose(),this.layers.dispose(),this.heightTexture.dispose(),this.bvh.unlink(),this.clearFlag(2)}dispose(){if(this.getFlag(2))throw new xu("component is linked, must be unlinked first")}initialize(){const t=this.overlay,e=this.material.uniforms;e.diffuseGridOverlayMap.value=t.texture,e.gridBorderWidth.value=t.borderWidth.getValue();const i=this.size;t.size.onChanged.add(((t,n)=>{e.gridResolution.value.set(i.x,i.y)})),t.borderWidth.onChanged.add((t=>{e.gridBorderWidth.value=t})),t.tileImage.onChanged.add(this.updateTileImage,this)}async updateTileImage(){const t=this.overlay.tileImage.getValue(),e=this.__assetManager;if(null===e)return;const i=await e.promise(t,zu);if(t!==this.overlay.tileImage.getValue())return;const n=i.create();n.minFilter=Kt,n.magFilter=Kt,n.generateMipmaps=!1,this.material.uniforms.diffuseGridOverlaySprite.value=n}update(t){this.clouds.update(t)}sampleHeight(t,e,i,n,s){const r=new wu;this.raycastVerticalFirstSync(r,t,e)?i(r.position.y):n()}raycastFirstSync(t,e,i,n,s,r,a){return this.__tiles.raycastFirstSync(t,e,i,n,s,r,a)}raycast(t,e,i,n){throw new Error("Deprecated, use raycastFirstSync instead")}raycastVertical(t,e,i,n,s){throw new Error("Deprecated, use raycastVerticalFirstSync instead")}raycastVerticalFirstSync(t,e,i){return this.__tiles.raycastVerticalFirstSync(t,e,i)}projectPointsVertical(t,e,i){const n=this;let s=0;const r=t.length,a=[];function o(){++s>=r&&(function(t,e){const i=t.length-1,n=e.length;for(let s=0;s<n;s++){const n=e[s];let r=0,a=0;n>0&&(r+=t[n-1].y,a++),n<i&&(r+=t[n+1].y,a++),a>0&&(t[n].y=r/a)}}(t,a),e(t))}function l(e){const s=t[e];n.sampleHeight(s.x,s.z,(function(t){s.y=t,o()}),(function(){a.push(e),o()}),i)}if(0===r)e(t);else for(let t=0;t<r;t++)l(t)}mapGridPoints(t,e,i,n){const s=this,r=t.length;for(let i=0;i<r;i++){const n=t[i],r=e[i];s.mapPointGrid2World(n.x,n.y,r)}this.projectPointsVertical(e,i,n)}mapPointGrid2World(t,e,i){const n=this.gridTransform,s=t*n.scale_x+n.offset_x,r=e*n.scale_y+n.offset_y;i.set(s,i.y,r)}mapPointWorld2Grid(t,e){const i=this.gridTransform,n=(t.x-i.offset_x)/i.scale_x,s=(t.z-i.offset_y)/i.scale_y;e.set(n,s)}promiseAllTiles(){const t=this.__tiles,e=[];return t.traverse((function(i){const n=i.gridPosition,s=n.x,r=n.y,a=t.obtain(s,r);e.push(a)})),Promise.all(e)}updateMaterial(){let t=this.material;null!==this.__material_reference&&null!==this.__material_reference.getValue()&&(t=this.__material_reference.getValue());const e=t.uniforms;e.diffuseMaps.value=this.layers.texture,e.splatWeightMap.value=this.splat.weightTexture,e.splatLayerCount.value=this.layers.count(),e.materialScalesMap.value=this.layers.scalesTexture,e.splatResolution.value.set(this.splat.size.x,this.splat.size.y),e.gridResolution.value.set(this.size.x,this.size.y),e.uGridTransform.value.set(this.gridTransform.scale_x,this.gridTransform.scale_y,this.gridTransform.offset_x,this.gridTransform.offset_y),this.layers.updateLayerScales(this.size.x*this.gridScale,this.size.y*this.gridScale),t.uniformsNeedUpdate=!0}set transform(t){G(this.__transform_matrix,t),this.__tiles.transform=t}get transform(){return this.__transform_matrix}addLayer(t){const e=this.layers,i=e.addLayer(t);return this.splat.addWeightLayer(),this.getFlag(1)&&(e.buildTexture(),t.loadTextureData(this.__assetManager).then((()=>{e.get(i)===t&&e.writeLayerDataIntoTexture(i)})),this.updateMaterial()),i}async updateHeights(){this.updateHeightTexture(),await this.updateWorkerHeights()}updateHeightTexture(){const t=this.samplerHeight,e=this.heightTexture,i=e.image;i.data!==t.data&&(e.dispose(),i.data=t.data),i.width=t.width,i.height=t.height,e.needsUpdate=!0}buildFromLegacy(t){throw new Error("Deprecated, no longer supported")}startBuildService(){this.__buildWorker.start(),this.updateWorkerHeights()}async updateWorkerHeights(){const t=this.samplerHeight,e=this.__buildWorker;return await e.setHeightSampler(t.data,t.itemSize,t.width,t.height),await e.computeHeightRange().then((({min:t,max:e})=>{this.__tiles.setHeightRange(t,e)}))}stopBuildService(){this.__buildWorker.stop()}buildGridTransform(){0===this.gridTransformKind?(this.gridTransform.scale_x=this.size.x/(this.size.x-1)*this.gridScale,this.gridTransform.scale_y=this.size.y/(this.size.y-1)*this.gridScale,this.gridTransform.offset_x=0,this.gridTransform.offset_y=0):1===this.gridTransformKind&&(this.gridTransform.scale_x=this.gridScale,this.gridTransform.scale_y=this.gridScale,this.gridTransform.offset_x=this.gridScale/2,this.gridTransform.offset_y=this.gridScale/2)}buildNonVisual(){this.buildGridTransform(),this.bvh.resize(0,0,0,0,0,0),this.overlay.size.copy(this.size),this.__tiles.totalSize.copy(this.size),this.__tiles.scale.set(this.gridScale,this.gridScale),this.__tiles.resolution.set(this.resolution),this.updateHeightTexture(),this.updateWorkerHeights()}build(t){this.getFlag(1)||(this.__assetManager=t,this.buildNonVisual(),this.layers.buildTexture(),this.layers.loadTextureData(t),null!==this.lightMapURL&&(this.material.aoMap=!0,this.material.needsUpdate=!0,t.promise(this.lightMapURL,zu).then((t=>{this.material.uniforms.aoMap.value=t.create(),this.material.uniforms.aoMapIntensity.value=.7}))),this.pMaterial=Promise.resolve(this.material),this.pTiles=Promise.resolve(this.__tiles),this.__tiles.initialize(),this.updateMaterial(),this.updateTileImage(),this.setFlag(1))}get tiles(){return this.__tiles}get aoMap(){const t=this.__material_reference;if(null===t)return null;const e=t.getValue();return null===e?null:e.uniforms.aoMap.value}buildLightMap(t=4){const e=this.size.x,i=this.size.y,n=g(e,16,2048),s=g(i,16,2048),r=new Uint8Array(n*s),a=new Fl(r,n,s,xe,ee);return a.wrapT=Jt,a.wrapS=Jt,a.minFilter=Yt,a.magFilter=Kt,a.flipY=!1,a.anisotropy=4,function({texture:t,heightSampler:e,resolution:i=new Eu(t.image.width,t.image.height),rayLength:n=11,worldSize:s=i}){return Tp.global.useAsync((async r=>{const a=function(t,e){const i=function(t,e){const i=e.width,n=e.height,s=Pp(e),r=new Ip;r.uniforms.heightMap.value=s,r.uniforms.resolution.value.set(i,n);const a=function(t){const e=t.length,i=Math.floor(e/4),n=new Float32Array(3*i);let s;for(let e=0;e<i;e++){const i=4*e,r=3*e;let a=Dp(t[i]),o=Dp(t[i+1]),l=Dp(t[i+2]);s=Math.sqrt(a*a+o*o+l*l),a/=s,o/=s,l/=s,n[r]=a,n[r+1]=o,n[r+2]=l}return n}(zp(t,i,n,r).array);return new Zu(a,3,i,n)}(t,e);return Promise.resolve(i)}(r,e),o=await function({renderer:t,pSamplerNormal:e,samplerHeight:i,resolution:n,wordSize:s=n,rayLength:r}){return new Promise((function(a,o){Promise.all([e]).then((function(e){const o=e[0],l=function(t,e,i,n,s=new Ri(e.width,e.width),r=17){const a=n.x,o=n.y,l=Pp(i),h=Pp(e),c=new Fp;c.uniforms.heightMap.value=h,c.uniforms.normalMap.value=l,c.uniforms.world_size.value.set(s.x,s.y),c.uniforms.rayLength.value=r;const u=zp(t,a,o,c),d=new Bp(2);d.uniforms.source.value=function(t,e,i){const n=new Fl;return n.format=me,n.type=ee,n.flipY=!1,n.image={data:t,width:e,height:i},n.wrapS=Jt,n.wrapT=Jt,n.repeat.set(1,1),n.needsUpdate=!0,n.anisotropy=4,n}(u.array,a,o),d.uniforms.pixelOffset.value.set(1/a,1/o);const p=zp(t,a,o,d),f=new Zu(new Uint8ClampedArray(a*o),1,a,o),m=a*o;for(let t=0;t<m;t++)f.data[t]=p.array[4*t];return f}(t,i,o,s,n,r);a(l)}),o)}))}({renderer:r,pSamplerNormal:a,samplerHeight:e,resolution:i,rayLength:n,worldSize:s});Ap(o,t)}))}({texture:a,heightSampler:this.samplerHeight,worldSize:new Eu(e*this.gridScale,i*this.gridScale),resolution:new Eu(e*t,i*t)}).then((()=>{const t=this.__material_reference;let e=this.material;return null!==t&&null!==t.getValue()&&(e=t.getValue()),e.aoMap=!0,e.needsUpdate=!0,e.uniforms.aoMap.value=a,e.uniforms.aoMapIntensity.value=.7,a}))}fromJSON({resolution:t=4,preview:e,size:i=1,scale:n=1,material:s,heights:r,layers:a,splat:o,overlayTileImage:l}={},h){this.clearFlag(1),void 0!==e&&this.preview.fromJSON(e),this.resolution=t,this.size.fromJSON(i),this.gridScale=n,this.materialDesc=s,void 0!==r?this.samplerHeight.fromJSON(r):(this.samplerHeight.data=new Float32Array(1),this.samplerHeight.width=1,this.samplerHeight.height=1,this.samplerHeight.itemSize=1,this.samplerHeight.version++),this.layers.fromJSON(a),this.splat.fromJSON(o),this.overlay.baseTileImage=void 0!==l?l:Ku,this.build(h.assetManager)}toJSON(){return{size:this.size.toJSON(),scale:this.gridScale,resolution:this.resolution,material:this.materialDesc,preview:this.preview.toJSON(),heights:this.samplerHeight.toJSON(),layers:this.layers.toJSON(),splat:this.splat.toJSON(),overlayTileImage:this.overlay.baseTileImage}}}If.typeName="Terrain";const Lf=7;function Nf(t,e){const i=t.length;for(let n=0;n<i;n++){const i=t[n],s=4*n,r=i.normal;e[s]=r.x,e[s+1]=r.y,e[s+2]=r.z,e[s+3]=i.constant}}function Pf(t,e,i){let n=t;return n<e&&(n=e),n<i&&(n=i),n}function Df(t,e,i,n,s,r){const a=t.getLeafAddress(e);!function(t,e,i,n,s,r){const a=3*n,o=3*s,l=3*r,h=i[a],c=i[a+1],u=i[a+2],d=i[o],p=i[o+1],f=i[o+2],m=i[l],_=i[l+1],g=i[l+2];t[e]=zd(h,d,m),t[e+1]=zd(c,p,_),t[e+2]=zd(u,f,g),t[e+3]=Pf(h,d,m),t[e+4]=Pf(c,p,_),t[e+5]=Pf(u,f,g)}(t.__data_float32,a,i,n,s,r),t.__data_uint32[a+6]=e}function Ff(t){if(!0!==t.isInterleavedBufferAttribute&&t.isBufferAttribute)return t;const e=t.data,i=e.array,n=e.stride,s=t.count,r=t.itemSize,a=s*r,o=t.offset,l=new i.constructor(a),h=new bs(l,r);h.normalized=t.normalized,h.name=t.name;let c=0,u=0;for(;c<s;c++)for(u=0;u<r;u++)l[c*r+u]=i[c*n+o+u];return h}function Of(t,e,i,n,s){return np(t[e+0],t[e+1],t[e+2],t[e+3],t[e+4],t[e+5],i,n,s)}const Rf=Td;function kf(t,e,i,n,s,r,a,o,l,h,c,u,d){let p=0;return p+=C(t,e,i,s,r,a)>=n?1:-1,p+=C(t,e,i,o,l,h)>=n?1:-1,p+=C(t,e,i,c,u,d)>=n?1:-1,p}function Bf(t,e,i,n,s,r,a,o,l,h,c,u){for(let d=0;d<i;d++){const i=e+4*d;if(-3===kf(t[i],t[i+1],t[i+2],t[i+3],n,s,r,a,o,l,h,c,u))return!1}return!0}const Uf=[],Vf=[];class Wf{constructor(t=104857600){this.cache=new Zp({maxWeight:t,keyHashFunction:t=>t.id,keyEqualityFunction:(t,e)=>t.id===e.id&&t.uuid===e.uuid,valueWeigher:t=>t.estimateByteSize()})}set cache_size(t){this.cache.maxWeight=t}get cache_size(){return this.cache.maxWeight}queryContainmentViaClippingPlanes(t,e){const i=this.acquire_bvh(t);Nf(e,Vf);const n=t.getIndex()?.array,s=t.getAttribute("position");let r,a=3,o=0;return s.isInterleavedBufferAttribute?(r=s.data.array,a=s.data.stride,o=s.offset):(r=s.array,a=3,o=0),function(t,e,i,n,s,r,a,o){const l=function(t,e,i,n,s,r){let a=0;const o=i.binary_node_count;if(o<=0)return 0;const l=Rf.pointer++;Rf[l]=0;const h=o+i.leaf_node_count,c=i.float32,u=i.uint32;do{Rf.pointer--;const e=Rf[Rf.pointer],s=i.getNodeAddress(e);if(Of(c,s,n,0,r))if(e<o){const t=1+(e<<1),i=t+1;i<h?(Rf[Rf.pointer++]=i,Rf[Rf.pointer++]=t):t<h&&(Rf[Rf.pointer++]=t)}else t[0+a]=u[s+6],a++}while(Rf.pointer>l);return a}(Uf,0,t,r,0,o);let h,c,u;for(let t=0;t<l;t++){const a=3*Uf[t];void 0!==s?(h=s[a],c=s[a+1],u=s[a+2]):(h=a,c=a+1,u=a+2);const l=h*n+i,d=c*n+i,p=u*n+i;if(Bf(r,0,o,e[l],e[l+1],e[l+2],e[d],e[d+1],e[d+2],e[p],e[p+1],e[p+2]))return!0}return!1}(i,r,o,a,n,Vf,0,e.length)}queryRaycastNearest_array(t,e,i){return this.queryRaycastNearest_primitive(t,e,i[0],i[1],i[2],i[3],i[4],i[5])}queryRaycastNearest_primitive(t,e,i,n,s,r,a,o){let l;try{l=this.acquire_bvh(e)}catch(t){return!1}const h=e.getIndex()?.array,c=e.getAttribute("position");let u,d=3,p=0;return c.isInterleavedBufferAttribute?(u=c.data.array,d=c.data.stride,p=c.offset):(u=c.array,d=3,p=0),mp(t,l,u,p,d,h,i,n,s,r,a,o)}queryRaycastNearest(t,e,i,n){return this.queryRaycastNearest_primitive(t,e,i.x,i.y,i.z,n.x,n.y,n.z)}cache_remove_geometry(t){return this.cache.remove(t)}acquire_bvh(t){const e=this.cache.get(t);if(null!==e)return e;const i=this.__build_bvh(t);return this.cache.put(t,i),i}__build_bvh(t){const e=new Qd,i=t.getAttribute("position"),n=t.getIndex(),s=Ff(i).array;return null==n?function(t,e){const i=e.length/9;t.setLeafCount(i),t.initialize_structure();for(let n=0;n<i;n++){const i=3*n;Df(t,n,e,i,i+1,i+2)}t.build()}(e,s):function(t,e,i){const n=i.length/3;t.setLeafCount(n),t.initialize_structure();for(let s=0;s<n;s++){const n=3*s;Df(t,s,e,i[n],i[n+1],i[n+2])}t.build()}(e,s,Ff(n).array),e}}Wf.INSTANCE=new Wf;const Gf=new Float32Array(6),Hf=new Float32Array(16),jf=new Float32Array(6);class qf{constructor(){this.geometry=null,this.material=null,this.depth_material=null,this.__bvh_leaf=new vu,this.__entity=-1,this.__c_transform=null,this.mode=0,this.draw_method=0,this.flags=22}get __cached_object(){throw new Error("Deprecated")}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}hash(){return this.geometry.id^this.material.id^30&this.flags^this.draw_method<<16^this.mode<<12}equals(t){return this.geometry.id===t.geometry.id&&this.material.id===t.material.id&&this.draw_method===t.draw_method&&this.mode===t.mode&&(30&this.flags)==(30&t.flags)&&this.depth_material===t.depth_material}copy(t){this.geometry=t.geometry,this.material=t.material,this.depth_material=t.depth_material,this.draw_method=t.draw_method,this.mode=t.mode,this.flags=t.flags}clone(){const t=new qf;return t.copy(this),t}get entity(){return this.__entity}get transform(){return this.__c_transform.matrix}get bvh(){throw new Error("Deprecated, use #getBoundingBox method instead")}getBoundingBox(t){const e=this.__bvh_leaf.bounds;t.readFromArray(e)}from(t,e,i=0){this.geometry=t,this.material=e,this.mode=i,null===t.boundingBox&&t.computeBoundingBox()}static from(t,e,i){const n=new qf;return n.from(t,e,i),n}updateTransform(){this.update_bounds(),this.__bvh_leaf.write_bounds()}update_bounds(){!function(t,e){const i=e.boundingBox;!function(t,e,i){e.x,e.y,e.z,i.x,i.y,i.z,t[0]=e.x,t[1]=e.y,t[2]=e.z,t[3]=i.x,t[4]=i.y,t[5]=i.z}(t,i.min,i.max)}(Gf,this.geometry),ap(this.__bvh_leaf.bounds,Gf,this.transform)}query_raycast_nearest(t,e,i){return H(Hf,i),!!lp(jf,0,e,0,Hf)&&!!Wf.INSTANCE.queryRaycastNearest_array(t,this.geometry,jf)&&(t.applyMatrix4(i),!0)}}qf.typeName="ShadedGeometry",qf.serializable=!1;const Jf=new op;function $f(t,e){const i=e.entity.getComponent(qf);null!==i&&(i.getBoundingBox(Jf),t.expandToFit(Jf));const n=e.children,s=n.length;for(let e=0;e<s;e++)$f(t,n[e])}function Yf(t,e){t.setNegativelyInfiniteBounds(),$f(t,e)}class Xf{#x=null;flags=3;__url=null;__node=null;__initial_bounds=new op;get node(){return this.__node}equals(t){return null!=t&&this.__url===t.__url&&this.flags===t.flags&&this.materialOverride===t.materialOverride}hash(){return rd(this.__url)}copy(t){this.__url=t.__url,this.__node=null,this.__initial_bounds.copy(t.__initial_bounds),this.#x=t.#x}clone(){const t=new Xf;return t.copy(this),t}set materialOverride(t){if(t!==this.#x){if(null===t)throw new Error("Once material override is set it can not be cleared, create a new SGMesh instance if you would like to clear override");this.#x=t,this.applyMaterialOverride()}}get materialOverride(){return this.#x}applyMaterialOverride(){null!==this.__node&&this.__node.traverse((t=>{const e=t.entity.getComponent(qf);null!==e&&(e.material=this.#x)}))}get url(){return this.__url}set url(t){t!==this.__url&&(this.__url=t)}getBoundingBox(t){return null!==this.__node&&(Yf(t,this.__node),!0)}getUntransformedBoundingBox(t){t.copy(this.__initial_bounds)}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}get castShadow(){return this.getFlag(1)}set castShadow(t){this.writeFlag(1,t)}get receiveShadow(){return this.getFlag(2)}set receiveShadow(t){this.writeFlag(2,t)}static fromURL(t){const e=new Xf;return e.url=t,e.castShadow=!0,e.receiveShadow=!0,e}toJSON(){return{url:this.__url,receiveShadow:this.receiveShadow,castShadow:this.castShadow}}fromJSON({url:t,receiveShadow:e=!0,castShadow:i=!0}){this.clearFlag(4),this.__url=t,this.receiveShadow=e,this.castShadow=i}}function Zf(t,e,i){return sp(t[e],t[e+1],t[e+2],t[e+3],t[e+4],t[e+5],i)}Xf.typeName="SGMesh";const Kf=Td;function Qf(t,e,i,n){if(n===wd)return 0;const s=Kf.pointer++;Kf[s]=n;let r=e;for(;Kf.pointer>s;){Kf.pointer--;const e=Kf[Kf.pointer];if(i.node_is_leaf(e))t[r++]=i.node_get_user_data(e);else{const t=i.node_get_child1(e),n=i.node_get_child2(e);Kf[Kf.pointer++]=t,Kf[Kf.pointer++]=n}}return r-e}const tm=Td,em=new Float32Array(6);function im(t,e,i,n){const s=i.root;if(s===wd)return 0;const r=tm.pointer++;tm[r]=s;let a=e;for(;tm.pointer>r;){tm.pointer--;const e=tm[tm.pointer];i.node_get_aabb(e,em);const s=Zf(em,0,n);if(0!==s)if(i.node_is_leaf(e))t[a++]=i.node_get_user_data(e);else if(2===s)a+=Qf(t,a,i,e);else{const t=i.node_get_child1(e),n=i.node_get_child2(e);tm[tm.pointer++]=t,tm[tm.pointer++]=n}}return a-e}function nm(t){const e=typeof t;if("string"!==e)throw new Error(`path must be a string, instead was '${e}'`);const i=function(t){if("string"!=typeof t)throw new Error("path is not a string");const e=t.lastIndexOf("/");return-1!==e?t.substring(e+1):t}(t),n=i.lastIndexOf(".");return-1!==n?i.substring(n+1):null}const sm={uniforms:{tDiffuse:{type:"t",value:null},opacity:{type:"f",value:1}},vertexShader:["varying vec2 vUv;","void main() {","vUv = uv;","gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","}"].join("\n"),fragmentShader:["uniform float opacity;","uniform sampler2D tDiffuse;","varying vec2 vUv;","void main() {","vec4 texel = texture2D( tDiffuse, vUv );","gl_FragColor = opacity * texel;","}"].join("\n")};function rm(t,e,i,n,s,r){const a=e.width,o=e.height,l=t.width,h=t.height;if(a!==l||o!==h)throw new Error("Dimensions of input and output are incompatible");const c=e.itemSize,u=t.itemSize,d=e.data,p=t.data,f=a*o;if(function(t){const e=t.constructor;return e===Uint8ClampedArray||e===Uint8Array||e===Uint16Array||e===Uint32Array||e===Int8Array||e===Int16Array||e===Int32Array}(p))for(let t=0;t<f;t++){const e=t*u+i,a=d[t*c+n];p[e]=Math.round(a*s+r)}else for(let t=0;t<f;t++){const e=t*u+i,a=d[t*c+n];p[e]=a*s+r}}class am{constructor(t,e=0){this.factory=t,this.byteSize=e,this.dependencies=[],this.description=null}equals(t){return this===t||this.description===t.description||this.description.equals(t.description)}hash(){return this.description.hash()}create(){return this.factory()}}am.prototype.byteSize=0;class om{kind="anonymous"}const lm=new om;om.default=Object.freeze(lm);class hm{assetManager=null;context=null;async link(t,e){this.assetManager=t,this.context=e}async unlink(){}load(t,e,i,n,s){n("Not Implemented")}}class cm extends hm{constructor({fetch_priority:t="auto"}={}){super(),this.__fetch_priority=t}async load(t,e,i,n=console.error,s=Mf){const r=null!==this.assetManager?this.assetManager.crossOriginConfig:om.default,a=new Headers,o=new Request(e,{credentials:"use-credentials"===r.kind?"include":"same-origin",headers:a});void 0!==o.priority&&(o.priority=this.__fetch_priority);let l=await fetch(o);const h=l.status;if(200!==h&&0!==h)throw Error(`fetch for "${l.url}" responded with ${h}: ${l.statusText}`);try{l=function(t,e){let i=t;if("undefined"==typeof ReadableStream||void 0===i.body||void 0===i.body.getReader)return i;const n=i.headers.get("Content-Length")||i.headers.get("X-File-Size"),s=n?parseInt(n):0;let r=0;const a={type:"bytes",start(t){const n=i.body.getReader();!function i(){n.read().then((({done:n,value:a})=>{n?t.close():(r+=a.byteLength,e(r,s),t.enqueue(a),i())}))}()}};let o;try{o=new ReadableStream(a),i=new Response(o)}catch(t){}return i}(l,s)}catch(t){}const c=await l.arrayBuffer(),u=new am((function(){return c}),c.byteSize);return i(u),u}}class um{async decode(t){throw new Error("Unsupported Operation")}async test(t){return!0}}class dm extends um{constructor(...t){if(super(),this.children=t.slice(),this.children.length<1)throw new Error("At least one codec must be provided")}async test(t){const e=this.children,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(await i.test(t))return!0}return!1}async decode(t){const e=this.children,i=e.length,n=[];let s;for(let r=0;r<i;r++){const i=e[r];if(await i.test(t)){try{s=await i.decode(t)}catch(t){n.push({index:r,error:t});continue}return s}n.push({index:r,error:"Codec doesn't support this data"})}throw new Error(`All codecs failed, errors: ${n.map((t=>JSON.stringify(t))).join("\n")}`)}}class pm extends um{async decode(t){const e=new Image,i=new Blob([t]),n=URL.createObjectURL(i);e.src=n,await e.decode();const s=function(t){const e=t.width,i=t.height,n=document.createElement("canvas");n.width=e,n.height=i;const s=n.getContext("2d");return s.drawImage(t,0,0,e,i),s.getImageData(0,0,e,i).data}(e),r=e.width,a=e.height;return URL.revokeObjectURL(n),{data:s,width:r,height:a,itemSize:4,bitDepth:8}}}class fm{__request_count=0;__timeout=1e3;__pending_termination=-1;constructor(t){this.worker=t}setTimeout(t){this.__timeout=t}terminate=()=>{this.cancelScheduledTermination(),this.worker.stop()};cancelScheduledTermination(){this.__pending_termination>=0&&(clearInterval(this.__pending_termination),this.__pending_termination=-1)}scheduleTermination(t){this.cancelScheduledTermination(),this.__pending_termination=setTimeout(this.terminate,t)}decrement=()=>{this.__request_count--,this.__request_count<=0&&this.worker.isRunning()&&this.scheduleTermination(this.__timeout)};increment(){this.__request_count++,this.worker.isRunning()?this.__pending_termination>=0&&(clearInterval(this.__pending_termination),this.__pending_termination=-1):this.worker.start()}request(t,e){this.increment();const i=this.worker.$submitRequest(t,e);return i.finally(this.decrement),i}}const mm=[137,80,78,71,13,10,26,10];class _m extends um{constructor(){super();const t=new wf;t.importScript("bundle-worker-image-decoder.js"),t.addMethod("decode",(function(t,e){return Lib.decode(t,e)})),this.worker=new fm(t.build()),this.worker.setTimeout(1200)}async test(t){for(let e=0;e<mm.length;e++)if(t[e]!==mm[e])return!1;return!0}decode(t){return this.worker.request("decode",[t.buffer])}}class gm extends am{constructor(t,e,i,n=4){super(),this.data=t,this.width=e,this.height=i,this.itemSize=n,this.byteSize=t.length}create(){return new Zu(this.data,this.itemSize,this.width,this.height)}}const ym="arraybuffer";class vm extends hm{constructor(){super(),this.decoder=new dm(new _m,new pm)}async link(t,e){void 0===t.getLoaderByType(ym)&&await t.registerLoader(ym,new cm),await super.link(t,e)}async __decode_via_worker(t,e){const i=(await this.assetManager.promise(t,ym,{scope:e})).create();return await this.decoder.decode(new Uint8Array(i))}async __standard(t,e){const i=await this.__decode_via_worker(t,e);let n;const s=i.bitDepth;switch(s){case 8:n=new Uint8Array(i.data);break;case 16:n=new Uint16Array(i.data);break;default:throw new Error(`Unsupported bit depth '${s}'. path='${t}'`)}return new gm(n,i.width,i.height,i.itemSize)}load(t,e,i,n,s){"dds"===nm(e)?this.assetManager.get({path:e,scope:t,type:zu,callback:t=>{const e=t.create(),n=function(t,e,i,n=!0){let s=void 0,r=void 0;const a=function(t){switch(t){case xe:case we:return 1;case be:return 2;case 1022:case Ae:return 3;case me:case Ce:case Ee:case ze:return 4;default:throw new Error(`Unsupported format '${t}'`)}}(t.format);if(void 0===r||void 0===s){const e=t.image;null!=e?(void 0===r&&(r="number"==typeof e.width?e.width:512),void 0===s&&(s="number"==typeof e.height?e.height:512)):(void 0===r&&(r=512),void 0===s&&(s=512))}let o;if(!0===t.isDataTexture)o=function(t,e,i,n){let s=function(t){if(4===t.itemSize&&(t.data.constructor===Uint8Array||t.data.constructor===Uint8ClampedArray))return t;const e=Zu.uint8(4,t.width,t.height);return function(t,e){if(e.width!==t.width||e.height!==t.height)throw new Error("Dimensions of source and destination are incompatible");if(4!==t.itemSize)throw new Error(`Destination must have 4 channels exactly, instead got '${t.itemSize}'`);const{gradient:i,intercept:n}=function(t){let e=1,i=0;switch(t){case Uint16Array:e=.0038910505836575876;break;case Uint32Array:e=5.937181414556033e-8;break;case Int8Array:e=1,i=127;break;case Int16Array:e=.0038910505836575876,i=127;break;case Int32Array:e=5.937181414556033e-8,i=127;break;case Float32Array:case Float64Array:e=255}return{gradient:e,intercept:i}}(e.data.constructor),s=e.itemSize;0!==n||1!==i||4!==s?1===s?(rm(t,e,0,0,i,n),rm(t,e,1,0,i,n),rm(t,e,2,0,i,n),t.channelFill(3,255)):2===s?(rm(t,e,0,0,i,n),rm(t,e,1,0,i,n),rm(t,e,2,0,i,n),rm(t,e,3,1,i,n)):3===s?(rm(t,e,0,0,i,n),rm(t,e,1,1,i,n),rm(t,e,2,2,i,n),t.channelFill(3,255)):4===s&&(rm(t,e,0,0,i,n),rm(t,e,1,1,i,n),rm(t,e,2,2,i,n),rm(t,e,3,3,i,n)):t.data.set(e.data)}(e,t),e}(new Zu(t.image.data,e,t.image.width,t.image.height));if(s.width!==i||s.height!==n){const t=Zu.uint8(4,i,n);cd(s,t),s=t}return s}(t,a,r,s).data;else if(t.image instanceof Image){const e=function(t,e,i,n){const s=t.image,r=document.createElement("canvas");r.width=i,r.height=n;const a=r.getContext("2d");a.drawImage(s,0,0,s.width,s.height,0,0,i,n);const o=Zu.uint8(4,i,n);return function(t,e){const i=t.width,n=t.height,s=e.getImageData(0,0,i,n).data;t.data=s}(o,a),o}(t,0,r,s);o=e.data}else o=Tp.global.use((e=>(e.getContext().getExtension("WEBGL_compressed_texture_s3tc"),zp(e,r,s,{vertexShader:sm.vertexShader,fragmentShader:sm.fragmentShader,uniforms:{tDiffuse:{value:t,type:"t"},opacity:{value:1}}})))).array;return n&&function(t,e,i,n=4){const s=e*n;let r,a,o,l=0;const h=i>>1;for(;l<h;l++){const e=(i-l-1)*s,n=l*s;for(let i=0;i<s;i++)a=n+i,o=e+i,r=t[a],t[a]=t[o],t[o]=r}}(o,r,s),new Zu(o,4,r,s)}(e);e.dispose();const s=new gm(n.data,n.width,n.height,n.itemSize);i(s)},failure:n,progress:s}):this.__standard(e,t).then(i,n)}}class xm extends Ac{constructor(t){super(t)}parse(t,e){const i={mipmaps:[],width:0,height:0,format:null,mipmapCount:1};function n(t){return t.charCodeAt(0)+(t.charCodeAt(1)<<8)+(t.charCodeAt(2)<<16)+(t.charCodeAt(3)<<24)}function s(t,e,i,n){const s=i*n*4,r=new Uint8Array(t,e,s),a=new Uint8Array(s);let o=0,l=0;for(let t=0;t<n;t++)for(let t=0;t<i;t++){const t=r[l];l++;const e=r[l];l++;const i=r[l];l++;const n=r[l];l++,a[o]=i,o++,a[o]=e,o++,a[o]=t,o++,a[o]=n,o++}return a}const r=n("DXT1"),a=n("DXT3"),o=n("DXT5"),l=n("ETC1"),h=new Int32Array(t,0,31);if(542327876!==h[0])return i;if(4&!h[20])return i;let c,u=!1;switch(h[21]){case r:c=8,i.format=Ae;break;case a:c=16,i.format=Ee;break;case o:c=16,i.format=ze;break;case l:c=8,i.format=De;break;default:if(!(32===h[22]&&16711680&h[23]&&65280&h[24]&&255&h[25]&&4278190080&h[26]))return i;u=!0,c=64,i.format=me}i.mipmapCount=1,131072&h[2]&&!1!==e&&(i.mipmapCount=Math.max(1,h[7]));const d=h[28];if(i.isCubemap=!!(512&d),i.isCubemap&&(!(1024&d)||!(2048&d)||!(4096&d)||!(8192&d)||!(16384&d)||!(32768&d)))return i;i.width=h[4],i.height=h[3];let p=h[1]+4;const f=i.isCubemap?6:1;for(let e=0;e<f;e++){let e=i.width,n=i.height;for(let r=0;r<i.mipmapCount;r++){let r,a;u?(r=s(t,p,e,n),a=r.length):(a=Math.max(4,e)/4*Math.max(4,n)/4*c,r=new Uint8Array(t,p,a));const o={data:r,width:e,height:n};i.mipmaps.push(o),p+=a,e=Math.max(e>>1,1),n=Math.max(n>>1,1)}}return i}}function wm(t){const e=t.clone();return e.needsUpdate=!0,e}const bm=new zc;class Sm extends hm{load(t,e,i,n,s){let r=nm(e);if(null===r){const t=e.match(/^data\:image\/([a-zA-Z0-9]+)\;/);if(null===t)throw new Error(`no file extension on path '${e}'`);r=t[1]}const a=r.toLowerCase();switch(a){case"dds":!function(t,e,i,n){(new xm).load(t,(function(t){const i=function(t){let e=0;const i=t.image;for(let t=0;t<i.length;t++){const n=i[t].mipmaps;for(let t=0;t<n.length;t++)e+=n[t].data.length}return e}(t),n=new am((function(){return wm(t)}),i);e(n)}),n,i)}(e,i,n,s);break;case"png":case"jpg":!function(t,e,i,n){bm.load(t,(function(t){t.flipY=!1;const i=function(t){const e=t.image;return e instanceof ImageData?e.array.length:1}(t),n=new am((function(){return wm(t)}),i);e(n)}),n,i)}(e,i,n,s);break;default:throw new Error(`Unsupported texture file format: '${a}'`)}}}class Mm{#w=!1;get linked(){return this.#w}constructor(t,e,i){if("function"!=typeof e)throw new TypeError(`handler must be a function, instead was '${typeof e}'`);if("object"!=typeof t)throw new TypeError(`signal must be of an object, instead was '${typeof t}'`);if("function"!=typeof t.add)throw new TypeError(`signal.add must be a function, instead was '${typeof t.add}'`);this.signal=t,this.handler=e,this.context=i}link(){this.#w||(this.#w=!0,this.signal.add(this.handler,this.context))}unlink(){this.#w&&(this.#w=!1,this.signal.remove(this.handler,this.context))}static bind(t,e,i){const n=new Mm(t,e,i);return n.link(),n}}class Tm{access=3;resource=null;static from(t,e=3){const i=new Tm;return i.access=e,i.resource=t,i}}function Am(t,e,i,n,s){let r=n,a=0;for(;a<s;a++){const n=t[e+a],s=i.indexOf(n);(-1===s||s>=r)&&(i[r]=n,r++)}return r-n}Tm.prototype.isResourceAccessSpecification=!0;class Cm{entityManager=null;state=new Hd(Em.INITIAL);dependencies=[];components_used=[];get referenced_components(){const t=[];Am(this.dependencies,0,t,t.length,this.dependencies.length);const e=this.components_used,i=e.length;for(let n=0;n<i;n++)Sf(t,e[n].resource);return t}getAccessForComponent(t){let e=0;const i=this.components_used,n=i.length;for(let s=0;s<n;s++){const n=i[s];if(n.resource===t){e|=n.access;break}}const s=this.dependencies,r=s.length;for(let i=0;i<r;i++)if(s[i]===t){e|=1;break}return e}startup(t,e,i){this.entityManager=t,e()}shutdown(t,e,i){e()}link(t,e){}unlink(t,e){}}Cm.prototype.isSystem=!0,Cm.prototype.fixedUpdate=Mf,Cm.prototype.update=Mf,Object.defineProperties(Cm.prototype,{componentClass:{configurable:!0,get:()=>null}});const Em={INITIAL:0,STARTING:1,RUNNING:2,STOPPING:3,STOPPED:4};function zm(t){return t.constructor.name}function Im(t){t.updateMatrix();const e=t.children;for(let t=0,i=e.length;t<i;t++)Im(e[t])}function Lm(t){Im(t),t.updateMatrixWorld(!1)}Cm.State=Em;const Nm={Perspective:"perspective",Orthographic:"orthographic"};function Pm(t){let e;switch(t.projectionType.getValue()){default:case Nm.Perspective:e=new rr(t.fov.getValue(),1,1,50);break;case Nm.Orthographic:e=new zr(-10,10,20,-20,1,1)}return e.far=t.clip_far,e.near=t.clip_near,e}class Dm extends Boolean{constructor(t){super(),this.__value=t,this.onChanged=new _}valueOf(){return this.__value}toString(){return this.__value.toString()}set(t){const e=this.__value;return e!==t&&(this.__value=t,this.onChanged.send2(t,e)),this}setTrue(){this.set(!0)}setFalse(){this.set(!1)}copy(t){this.set(t.getValue())}equals(t){return this.__value===t.__value}hashCode(){return this.__value?1:0}process(t){t(this.__value),this.onChanged.add(t)}getValue(){return this.__value}invert(){this.set(!this.__value)}toJSON(){return this.__value}fromJSON(t){this.set(t)}toBinaryBuffer(t){t.writeUint8(this.__value?1:0)}fromBinaryBuffer(t){const e=0!==t.readUint8();this.set(e)}}Dm.FALSE=Object.freeze(new Dm(!1)),Dm.TRUE=Object.freeze(new Dm(!0)),Dm.prototype.isObservedBoolean=!0;class Fm{constructor(t,e){this.__value=t,this.__validSet=e,this.onChanged=new _}getValidValueSet(){return this.__validSet}set(t){const e=this.__value;return e!==t&&(this.__value=t,this.onChanged.dispatch(t,e)),this}equals(t){return this.__value===t.__value}copy(t){this.set(t.getValue())}getValue(){return this.__value}invert(){this.set(!this.__value)}process(t){this.onChanged.add(t),t(this.__value,this.__value)}toJSON(){return this.__value}fromJSON(t){this.set(t)}}const Om=new Cn;function Rm(t,e,i=!0){i&&t.updateProjectionMatrix(),Om.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),e.setFromProjectionMatrix(Om)}const km=new L,Bm=new L;function Um(t,e){const i=km,n=Bm;i.copy(L.forward),n.copy(L.up),i.applyQuaternion(e),n.applyQuaternion(e),i.negate(),t.lookRotation(i,n)}class Vm{constructor(){this.autoClip=!1,this.autoClipHysteresis=.33,this.object=null,this.fov=new id(45),this.projectionType=new Fm(Nm.Perspective,Nm),this.active=new Dm(!0),this.__clip_far=100,this.__clip_near=.1}getReciprocalRotation(t,e){Um(t,e)}get clip_far(){return this.__clip_far}set clip_far(t){this.__clip_far=t,null!==this.object&&(this.object.far=t)}get clip_near(){return this.__clip_near}set clip_near(t){this.__clip_near=t,null!==this.object&&(this.object.near=t)}updateMatrices(){const t=this.object;null!==t&&(t.updateProjectionMatrix(),t.updateMatrixWorld(!0),t.matrixWorldInverse.copy(t.matrixWorld),t.matrixWorldInverse.invert())}projectRay(t,e,i,n){Vm.projectRay(this.object,t,e,i,n)}copy(t){this.active.copy(t.active),this.projectionType.copy(t.projectionType),this.autoClip=t.autoClip}clone(){const t=new Vm;return t.copy(this),t}toJSON(){return{autoClip:this.autoClip,active:this.active.toJSON()}}fromJSON(t){this.autoClip=t.autoClip,"boolean"==typeof t.active?this.active.fromJSON(t.active):this.active.set(!1)}static projectRay(t,e,i,n,s){if(!t.isPerspectiveCamera&&!t.isOrthographicCamera)throw new Error("Unsupported camera type");{const h=t.matrixWorld.elements,c=t.projectionMatrixInverse.elements;Gm.setFromMatrixPosition(h),Wm.set(e,i,.5),a=Wm,o=c,l=h,(r=Wm).copy(a),r.applyMatrix4(o),r.applyMatrix4(l),Wm.sub(Gm),Wm.normalize(),n.copy(Gm),s.copy(Wm)}var r,a,o,l}computeProjectionMatrix(t){const e=this.object;return null!==e&&(t.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),!0)}rayPlaneIntersection(t,e,i,n,s,r,a,o){Rm(this.object,Hm);const l=Hm.planes[o];!function(t,e,i,n,s,r,a,o,l,h,c){const u=C(s,r,a,o,l,h),d=C(o,l,h,e,i,n)+c;if(0!==u){const o=-d/u;return!(o<0||(t.set(s*o+e,r*o+i,a*o+n),0))}0===d&&t.set(e,i,n)}(t,e,i,n,s,r,a,l.normal.x,l.normal.y,l.normal.z,l.constant)}projectWorldPointOntoNearPlane(t,e,i,n){Rm(this.object,Hm);const s=Hm.planes[0];Wm.set(t,e,i);const r=s.normal,a=function(t,e,i,n,s,r,a){return C(n,s,r,t,e,i)+a}(t,e,i,r.x,r.y,r.z,s.constant),o=-a;n.set(r.x*o+t,r.y*o+e,r.z*o+i)}}Vm.typeName="Camera",Vm.ProjectionType=Nm;const Wm=new L,Gm=new L,Hm=new _r;function jm(t,e,i){const n=t.object;if(null===n)return;const s=e/i;switch(t.projectionType.getValue()){case Vm.ProjectionType.Perspective:n.aspect=s;break;case Vm.ProjectionType.Orthographic:const t=n.right-n.left,e=n.bottom-n.top,i=s-t/e;if(i>0){const t=e*i;n.left-=t/2,n.right+=t/2}else if(i<0){const t=-e*i;n.top+=t/2,n.bottom-=t/2}}n.updateProjectionMatrix()}const qm=new R;class Jm extends Cm{constructor(t){super(),this.scene=t.scene,this.dependencies=[Vm,B],this.components_used=[Tm.from(Vm,2)],this.entityManager=null,this.graphics=t,this.entityData=[];const e=this;this.__handleViewportResize=function(t,i){const n=e.entityManager;if(null===n)return;const s=n.dataset;null!==s&&s.traverseComponents(Vm,(function(e){jm(e,t,i)}))},this.signalBindings=[]}link(t,e,i){null===t.object&&(t.object=Pm(t));const n=this.graphics,s=n.viewport.size;function r(e,i,n){t.object.position.set(e,i,n),function(t){const e=t.object;null!==e&&(e.updateProjectionMatrix(),Lm(e))}(t)}function a(){const i=e.rotation;!function(t,e){Um(qm,e),t.quaternion.set(qm.x,qm.y,qm.z,qm.w),t.rotation.setFromQuaternion(t.quaternion),t.updateProjectionMatrix(),Lm(t)}(t.object,i)}function o(){t.object=Pm(t),jm(t,s.x,s.y);const i=e.position;r(i.x,i.y,i.z),a(),l(t.active.getValue())}function l(e){e&&(n.camera=t.object)}jm(t,s.x,s.y),this.scene.add(t.object);const h=e.position,c=e.rotation,u=[new Mm(h.onChanged,r),new Mm(c.onChanged,a),new Mm(t.projectionType.onChanged,o),new Mm(t.active.onChanged,l),new Mm(t.fov.onChanged,o)];u.forEach((t=>t.link())),this.entityData[i]=u,r(h.x,h.y,h.z),a(c.x,c.y,c.z,c.w),l(t.active.getValue())}unlink(t,e,i){const n=this.entityData;if(n.hasOwnProperty(i)){const t=n[i];void 0!==t&&t.forEach((t=>t.unlink())),delete n[i]}this.scene.remove(t.object)}startup(t,e,i){this.entityManager=t;const n=this.graphics;n.viewport.size.onChanged.add(this.__handleViewportResize);const s=new Mm(n.on.visibilityConstructionStarted,(function(){const e=t;n.layers;const i=e.dataset;null!==i&&i.traverseComponents(Vm,(function(t){null!==t.object&&t.active.getValue()&&(void 0!==t.object.updateProjectionMatrix&&(t.object.updateProjectionMatrix(),t.object.updateMatrix(),t.object.updateMatrixWorld(!0)),!0===t.autoClip?function(t,e){t.object.far=t.clip_far,t.object.near=t.clip_near}(t):(t.object.far=t.clip_far,t.object.near=t.clip_near))}))}));s.link(),this.signalBindings.push(s),e()}shutdown(t,e,i){this.graphics.viewport.size.onChanged.remove(this.__handleViewportResize),this.signalBindings.forEach((t=>t.unlink())),this.signalBindings.splice(0,this.signalBindings.length),e()}static traverseActiveCameras(t,e){t.traverseComponents(Vm,(function(t,i){t.active.getValue()&&e(t,i)}))}static getFirstActiveCamera(t){const e={entity:-1,component:void 0};return this.traverseActiveCameras(t,((t,i)=>{e.entity=i,e.component=t})),e}static getActiveFrustums(t,e){const i=[];null!==t&&t.traverseComponents(Vm,(function(t){if(t.active.getValue()){const e=t.object;if(null!==e){const t=new _r;Rm(e,t),i.push(t)}}})),e(i)}}function $m(t,e){if(!t.isBuilt&&!t.isBuildInProgress){const i=t.gridPosition;e.build(i.x,i.y,Mf,Mf)}}class Ym extends Cm{dependencies=[If];gridScaleX=1;gridScaleY=1;__time_delta=0;renderLayer=null;bvh=new Md;constructor(t,e){if(super(),void 0===t)throw new Error("No GraphicsEngine supplied");if(void 0===e)throw new Error("No AssetManager supplied");this.graphics=t,this.assetManager=e}mapPointGrid2World(t,e,i){const n=t*this.gridScaleX,s=i.y,r=e*this.gridScaleY;i.set(n,s,r)}async startup(t,e,i){this.entityManager=t,this.renderLayer=this.graphics.layers.create("terrain-system"),this.renderLayer.buildVisibleSet=(t,e,i)=>{const n=this.entityManager;if(null===n)return 0;const s=n.dataset;if(null===s)return 0;const r=[];let a=0;return s.traverseComponents(If,((n,s)=>{const o=n.tiles,l=im(r,0,o.bvh,i.frustum);for(let i=0;i<l;i++){const n=r[i],s=o.tiles[n];s.isBuilt&&(t[e+a]=s.mesh,a++)}})),a};const n=this.assetManager;await n.tryRegisterLoader("image",new vm),await n.tryRegisterLoader("texture",new Sm),e()}shutdown(t,e,i){this.graphics.layers.remove(this.renderLayer),e()}link(t,e){t.getFlag(1)||t.build(this.assetManager);const i=t.size,n=t.gridScale,s=i.x,r=i.y;this.gridScaleX=s*n/(s-1),this.gridScaleY=r*n/(r-1),t.link(this.graphics),t.bvh.link(this.bvh,e)}unlink(t,e){t.unlink()}update(t){const e=this.entityManager.dataset;this.__time_delta=t,null!==e&&e.traverseComponents(If,this.__visitTerrainComponent,this)}__visitTerrainComponent(t,e){const i=this.entityManager.dataset,n=i.getComponent(e,B);t.transform=void 0!==n?n.matrix:d,t.update(this.__time_delta),t.frustumCulled&&Ym.traverseVisibleTiles(i,t,$m)}static traverseVisibleTiles(t,e,i){const n=e.__tiles,s=[],r=new Set,a=new Float32Array(24);void 0!==n&&Jm.getActiveFrustums(t,(function(t){let e=0;for(let i=0;i<t.length;i++)Nf(t[i].planes,a),e+=im(s,0,n.bvh,a);for(let t=0;t<e;t++){const e=s[t];if(!r.has(e)){const t=n.tiles[e];i(t,n)}r.add(e)}}))}}const Xm=new Zp({maxWeight:134217728,keyEqualityFunction:Up,keyHashFunction:Vp,keyWeigher:t=>t.byteSize+64,valueWeigher:t=>1});function Zm(t,e,i=0,n=t.length){const s=i+n;for(let n=i;n<s;n++)if(t[n]===e)return t.splice(n,1),!0;return!1}function Km(t){return void 0!==t}const Qm=new Uint8Array([0,1,28,2,29,14,24,3,30,22,20,15,25,17,4,8,31,27,13,23,21,19,16,7,26,12,18,6,11,5,10,9]);function t_(t){return Qm[125613361*(t&-t)>>>27]}class e_{constructor(t=64){this.__length=0,this.__capacity=t+31>>>5<<5,this.__data_uint32=new Uint32Array(this.__capacity>>5),this.__shrinkFactor=.5}preventShrink(){this.__shrinkFactor=0}setShrinkFactor(t){this.__shrinkFactor=t}setCapacity(t){if(this.__length>t)throw new Error(`Current length(=${this.__length}) is greater than requested size(=${t})`);this.__resize(t)}size(){return this.__length}capacity(){return this.__capacity}__resize(t){const e=Math.ceil(t/32),i=this.__data_uint32,n=new Uint32Array(e);i.length<e?n.set(i):n.set(i.subarray(0,e)),this.__data_uint32=n,this.__capacity=32*e}__updateLength(){const t=this.previousSetBit(this.__length)+1;t<this.__length&&this.__setLength(t)}__setLength(t){this.__length=t;const e=this.__capacity;if(t>e){const i=Math.ceil(Pf(t,e+128,1.3*e));this.__resize(i)}else t<e-128&&t<e*this.__shrinkFactor&&this.__resize(t)}previousSetBit(t){const e=Su(t,this.__length-1);let i=e>>5,n=31&e;const s=this.__data_uint32;let r=s[i];for(;n>=0;n--)if(0!=(r&1<<n))return 32*i+n;for(i--;i>=0;i--)for(r=s[i],n=31;n>=0;n--)if(0!=(r&1<<n))return 32*i+n;return-1}nextSetBit(t){const e=this.__length;if(t>=e)return-1;const i=this.__data_uint32;let n,s,r=t>>5,a=31&t;if(0!==a){const t=~((1<<a)-1),e=i[r]&t;if(0!==e)return a=t_(e),(r<<5)+a;r++}const o=e+31>>5;for(;r<o;r++)if(n=i[r],0!==n)return a=t_(n),s=(r<<5)+a,s;return-1}nextClearBit(t){let e,i=t>>5,n=31&t;const s=this.__data_uint32;if(0!==n){e=s[i];const t=(e|(1<<n)-1)>>>0;if(4294967295!==t)return n=t_(~t),n+32*i;i++}const r=this.__length,a=r+31>>5;for(;i<a;i++)if(e=s[i],4294967295!==e)return n=t_(~e),n+32*i;return r}set(t,e){const i=t>>5,n=1<<(31&t);if(e){const e=t+1;e>this.__length&&this.__setLength(e),this.__data_uint32[i]|=n}else t<this.__length&&(this.__data_uint32[i]&=~n,this.__updateLength())}clear(t){this.set(t,!1)}setRange(t,e){for(let i=t;i<=e;i++)this.set(i,!0)}clearRange(t,e){for(let i=t;i<e;i++)this.set(i,!1)}get(t){if(t>=this.__length)return!1;const e=t>>5,i=31&t;return 0!=(this.__data_uint32[e]&1<<i)}getAndSet(t){const e=this.get(t);return e||this.set(t,!0),e}getAndClear(t){const e=this.get(t);return e&&this.set(t,!1),e}shift_right(t,e,i){for(let n=i;n>=e;n--){const e=this.get(n);this.set(n+t,e)}}shift_left(t,e,i){for(let n=e;n<=i;n++){const e=this.get(n);this.set(n-t,e)}}shift(t,e,i){t>0?this.shift_right(t,e,i):this.shift_right(-t,e,i)}reset(){const t=this.__length;t<=0||(t<=32?this.__data_uint32[0]=0:this.__data_uint32.fill(0,0,Math.ceil(t/32)),this.__length=0)}copy(t){const e=t.__length,i=e>>5,n=this.__length;n!==e&&(n<e?this.__resize(e):this.__data_uint32.fill(0,i),this.__length=e);for(let e=0;e<i;e++)this.__data_uint32[e]=t.__data_uint32[e];const s=i<<5,r=e-s;for(let e=0;e<r;e++){const i=s+e;this.set(i,t.get(i))}}static fixedSize(t){const e=new e_(t);return e.__shrinkFactor=0,e}}class i_{componentMask=new e_;componentIndexMapping=[];dataset=null;constructor(t,e,i,n){const s=t.length;if(s<1)throw new Error(`Observer has to have at least 1 component types to watch, instead was given ${s}`);this.componentTypeCount=s,this.callbackComplete=e,this.callbackBroken=i,this.componentTypes=t,this.thisArg=n}build(t){let e;for(this.componentIndexMapping=[],this.componentMask.reset(),e=0;e<this.componentTypeCount;e++){const i=this.componentTypes[e],n=t.indexOf(i);if(-1===n)throw new Error(`Component type[${e}] was not found in the supplied map. Observer is not compatible.`);this.componentMask.set(n,!0),this.componentIndexMapping[n]=e}}connect(t){t.addObserver(this,!0)}disconnect(){this.dataset.removeObserver(this)}}function n_(t,e){for(let i in t)if(t[i]===e)return i}const s_={Undirected:3,Forward:1,Backward:2};class r_{constructor(t,e){this.first=t,this.second=e,this.direction=s_.Undirected}contains(t){return this.first===t||this.second===t}validateTransition(t,e){const i=this.first,n=this.second;return i===t&&n===e&&this.traversableForward()||n===t&&i===e&&this.traversableBackward()}other(t){return t===this.first?this.second:this.first}traversableForward(){return 0!=(this.direction&s_.Forward)}traversableBackward(){return 0!=(this.direction&s_.Backward)}isDirectedTowards(t){return this.first===t&&this.direction===s_.Backward||this.second===t&&this.direction===s_.Forward}isDirectedAwayFrom(t){return this.first===t&&this.direction===s_.Forward||this.second===t&&this.direction===s_.Backward}get nodes(){return[this.first,this.second]}toString(){return`Edge{ first=${this.first}, second=${this.second}, direction=${n_(s_,this.direction)} }`}}r_.prototype.isEdge=!0;class a_{node=null;__edges=[];__neighbors=new Map;get neighbours(){return Array.from(this.__neighbors.keys())}getEdgeCount(){return this.__edges.length}getEdges(){return this.__edges}get inNodes(){return this.inEdges.map((t=>t.other(this.node)))}get outNodes(){return this.outEdges.map((t=>t.other(this.node)))}get outEdges(){const t=[];return this.getOutgoingEdges(t),t}get inEdges(){const t=[];return this.getIncomingEdges(t),t}getIncomingEdges(t){const e=this.__edges,i=e.length;let n=0;for(let s=0;s<i;s++){const i=e[s];i.isDirectedTowards(this.node)&&(t.push(i),n++)}return n}getOutgoingEdges(t){const e=this.__edges,i=e.length;let n=0;for(let s=0;s<i;s++){const i=e[s];i.isDirectedAwayFrom(this.node)&&(t.push(i),n++)}return n}getIncomingEdgeCount(){let t=0;const e=this.__edges,i=e.length,n=this.node;for(let s=0;s<i;s++){const i=e[s];(i.first===n&&i.direction===s_.Forward||i.second===n&&i.direction===s_.Backward)&&t++}return t}edgeWithNodeExists(t){return this.__neighbors.has(t)}traverseEdges(t,e){let i=0;const n=this.__edges,s=n.length;for(;i<s;i++){const s=n[i];t.call(e,s)}return i}getAnyEdgeWith(t){if(!this.edgeWithNodeExists(t))return;const e=this.__edges,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i.contains(t))return i}}getAnyDirectionEdgeTo(t){const e=this.__edges,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i.second===t&&i.direction===s_.Forward||i.first===t&&i.direction===s_.Backward)return i}}addEdge(t){if(this.__edges.includes(t))return!1;const e=t.other(this.node);this.__edges.push(t);let i=this.__neighbors.get(e);return void 0===i&&(i=0),this.__neighbors.set(e,i+1),!0}removeEdge(t){const e=this.__edges,i=e.indexOf(t);if(-1===i)return!1;e.splice(i,1);const n=t.other(this.node),s=this.__neighbors.get(n);return s<=1?this.__neighbors.delete(n):this.__neighbors.set(n,s-1),!0}}function o_(t,e){const i=[];let n=t;do{i.unshift(n.node),n=e.get(n)}while(void 0!==n);return i}class l_{__nodes=new Map;__edges=new Set;on={nodeAdded:new _,nodeRemoved:new _,edgeAdded:new _,edgeRemoved:new _};hasNode(t){return this.__nodes.has(t)}addNode(t){if(this.hasNode(t))return!1;const e=new a_;return e.node=t,this.__nodes.set(t,e),this.on.nodeAdded.send2(t,this),!0}removeNode(t){const e=this.__nodes.get(t);return void 0!==e&&(e.traverseEdges(this.removeEdge,this),this.__nodes.delete(t),this.on.nodeRemoved.send2(t,this),!0)}traverseNodes(t,e){for(const[i,n]of this.__nodes)t.call(e,i)}get nodeCount(){return this.__nodes.size}getNodeCount(){return this.__nodes.size}findNode(t,e){const i=this.__nodes;for(const[n,s]of i)if(t.call(e,n))return n}getNodeContainer(t){return this.__nodes.get(t)}getNodeDegree(t){const e=this.__nodes.get(t);return void 0===e?0:e.getEdgeCount()}get nodes(){return Array.from(this.getNodes())}getNodes(){return this.__nodes.keys()}getEdges(){return this.__edges}createEdge(t,e,i=s_.Undirected){const n=new r_(t,e);return n.direction=i,this.addEdge(n),n}addEdge(t){if(this.hasEdge(t))return!1;const e=this.__nodes.get(t.first),i=this.__nodes.get(t.second);if(void 0===e)throw new Error(`First node(=${t.first}) of the edge is not part of the graph`);if(void 0===i)throw new Error(`Second node(=${t.second}) of the edge is not part of the graph`);return e.addEdge(t),i.addEdge(t),this.__edges.add(t),this.on.edgeAdded.send2(t,this),!0}removeEdge(t){if(!this.hasEdge(t))return!1;const e=this.__nodes.get(t.first),i=this.__nodes.get(t.second);if(void 0===e||void 0===i)throw new Error("One or both nodes of the edge are not present on the graph. This is a critical error");return e.removeEdge(t),i.removeEdge(t),this.__edges.delete(t),this.on.edgeRemoved.send2(t,this),!0}hasEdge(t){return this.__edges.has(t)}traverseEdges(t,e){for(const i of this.__edges)t.call(e,i)}get edgeCount(){return this.__edges.size}edgeExistsBetween(t,e){const i=this.__nodes.get(t);return void 0!==i&&i.edgeWithNodeExists(e)}getAnyEdgeBetween(t,e){const i=this.__nodes.get(t);if(void 0!==i&&this.hasNode(e))return i.getAnyEdgeWith(e)}getAnyDirectedEdge(t,e){const i=this.__nodes.get(t);if(void 0!==i)return i.getAnyDirectionEdgeTo(e)}getAttachedEdges(t,e){const i=this.__nodes.get(e);if(void 0===i)return 0;const n=i.getEdges(),s=n.length;for(let e=0;e<s;e++)t[e]=n[e];return s}getNeighbours(t){const e=this.__nodes.get(t);return void 0===e?[]:e.neighbours}nodeHasEdges(t){const e=this.__nodes.get(t);return void 0!==e&&e.getEdgeCount()>0}findPath(t,e){const i=this.__nodes.get(t);if(void 0===i)throw new Error(`Start node not found in the graph '${t}'`);const n=this.__nodes.get(e);if(void 0===n)throw new Error(`Goal node not found in the graph '${e}'`);const s=new Set;s.add(i);const r=new Set,a=new Map;for(;s.size>0;){const t=s.values().next().value;if(t===n)return o_(n,a);s.delete(t),r.add(t);const e=t.getEdges(),i=t.node,o=e.length;for(let n=0;n<o;n++){const o=e[n],l=o.first,h=o.second;let c=null;if(l!==i||o.direction!==s_.Forward&&o.direction!==s_.Undirected){if(h!==i||o.direction!==s_.Backward&&o.direction!==s_.Undirected)continue;c=l}else c=h;const u=this.__nodes.get(c);r.has(u)||s.has(u)||(s.add(u),a.set(u,t))}}return null}clear(){this.__nodes.clear(),this.__edges.clear()}copy(t){this.clear(),t.traverseNodes(this.addNode,this),t.traverseEdges(this.addEdge,this)}clone(){const t=new l_;return t.copy(this),t}}const h_="entityRemoved",c_="componentAdded";class u_{systems=[];systemsExecutionOrder=[];systemObservers=[];on={systemStarted:new _,systemStopped:new _,systemAdded:new _,systemRemoved:new _};state=0;systemAccumulatedFixedStepTime=new Map;fixedUpdateStepSize=.015;fixedUpdatePerSystemExecutionTimeLimit=15;dataset=null;__execution_order_needs_update=!0;updateExecutionOrder(){const t=this.systemsExecutionOrder;t.splice(0,t.length);const e=this.systems,i=e.length;let n=0;for(let s=0;s<i;s++){const i=e[s];i.update===Mf&&i.fixedUpdate===Mf||(t[n++]=i)}const s=function(t,e){const i=new l_;for(let n=0;n<t;n++){const t=e[n],s=t.referenced_components,r=s.length;for(let t=0;t<r;t++){const e=s[t];i.addNode(e)}for(let e=0;e<r;e++){const n=s[e];if(0!=(6&t.getAccessForComponent(n)))for(let a=0;a<r;a++){if(e===a)continue;const r=s[a];0!=(1&t.getAccessForComponent(r))&&void 0===i.getAnyDirectedEdge(n,r)&&i.createEdge(n,r,s_.Forward)}}}return i}(n,t);function r(t){let e=0;const i=t.referenced_components,n=i.length;for(let r=0;r<n;r++){const n=i[r];e+=1e-4;const a=s.getNodeContainer(n).getIncomingEdgeCount(),o=t.getAccessForComponent(n);e+=0!=(4&o)?4*a:0!=(2&o)?2*a:a}return e}const a=new Map;for(let e=0;e<n;e++){const i=t[e];a.set(i,r(i))}t.sort(((t,e)=>a.get(e)-a.get(t))),this.__execution_order_needs_update=!1}detachDataSet(){const t=this.dataset;null!==t&&(this.systemObservers.forEach((function(e){t.removeObserver(e,!0)})),this.dataset=null)}getComponentTypeMap(){const t=[],e=this.systems,i=e.length;for(let n=0;n<i;n++){const i=e[n].referenced_components;Am(i,0,t,t.length,i.length)}return t}attachDataSet(t){if(null!==this.dataset){if(this.dataset===t)return;throw new Error("Illegal status, another dataset is currently attached")}const e=this.getComponentTypeMap();t.registerManyComponentTypes(e),this.dataset=t,this.systemObservers.forEach((function(e){t.addObserver(e,!0)}))}hasSystem(t){return null!==this.getSystem(t)}getSystem(t){const e=this.systems,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i instanceof t)return i}return null}getComponentClassByName(t){const e=this.getComponentTypeMap();let i=0;const n=e.length;for(;i<n;i++){const n=e[i];if(n.typeName===t)return n}return null}simulate(t){this.__execution_order_needs_update&&this.updateExecutionOrder();const e=this.systems,i=e.length,n=this.fixedUpdateStepSize,s=this.systemAccumulatedFixedStepTime;for(let r=0;r<i;r++){const i=e[r];if(i.fixedUpdate!==Mf){let e=s.get(i)+t;const r=performance.now();for(;e>=n;){try{i.fixedUpdate(n)}catch(t){}if(e-=n,performance.now()-r>this.fixedUpdatePerSystemExecutionTimeLimit)break}s.set(i,e)}if(i.update!==Mf)try{i.update(t)}catch(t){}}}addSystem(t){const e=this.getSystem(Object.getPrototypeOf(t).constructor);if(null!==e){if(e===t)return Promise.resolve();throw new xu(`Another instance of system '${zm(t)}' is already registered`)}try{!function(t){if(void 0===t)throw new Error("System is undefined");if(null===t)throw new Error("System is null");if(!(t instanceof Cm))throw new TypeError('System does not inherit from "System" class');if("function"==typeof t.add)throw new Error("uses deprecated 'add' method, should use 'link' instead");if("function"==typeof t.remove)throw new Error("uses deprecated 'remove' method, should use 'unlink' instead");const e=t.components_used,i=e.length;for(let t=0;t<i;t++){const i=e[t];if(null==i||!0!==i.isResourceAccessSpecification)throw new Error(`Invalid access specification[${t}], expected an instance of ResourceAccessSpecification, but got something else`);if(null===i.resource)throw new Error(`No component specified for element [${t}]`);if(0===i.access)throw new Error("No access modifiers specified, must have at least one (such as Read, Write, Create)");for(let n=0;n<t-1;n++)if(e[n].resource===i.resource)throw new Error(`Duplicate specification of component [${n}] and [${t}]`)}const n=t.dependencies,s=n.length;if(s<1)throw new Error("A system must declare at least one dependency");if(s>1)for(let t=0;t<s;t++){const e=n[t];for(let i=t+1;i<s;i++)if(e===n[i])throw new Error(`Detected duplicate dependency: ${e.constructor.typeName}`)}const r=s+1;if(t.link!==Cm.prototype.link&&t.link.length!==r&&!0!==t.__validation_ignore_link_argument_count)throw new Error(`'link' method declares ${t.link.length} instead of expected ${r} based on it's ${s} dependencies`);if(t.unlink!==Cm.prototype.unlink&&t.unlink.length!==r&&!0!==t.__validation_ignore_link_argument_count)throw new Error(`'unlink' method declares ${t.unlink.length} instead of expected ${r} based on it's ${s} dependencies`)}(t)}catch(t){}const i=t.state.getValue(),n=[Em.INITIAL,Em.STOPPED];if(-1===n.indexOf(i))throw new xu(`System must be in one of these states: [${n.join(",")}], instead was ${i}`);const s=this.systems,r=s.length;s[r]=t,this.__execution_order_needs_update=!0;const a=new i_(t.dependencies,t.link,t.unlink,t);let o;if(this.systemObservers[r]=a,o=2===this.state?new Promise(((e,i)=>{this.startSystem(t,e,i)})):Promise.resolve(),null===t.entityManager)t.entityManager=this;else if(t.entityManager!==this)throw new Error("System is bound to another EntityManager");return null!==this.dataset&&(this.dataset.registerManyComponentTypes(t.referenced_components),this.dataset.addObserver(a)),this.systemAccumulatedFixedStepTime.set(t,0),this.on.systemAdded.send1(t),o}async removeSystem(t){const e=this.systems.indexOf(t);if(-1===e)return!1;const i=this.systemObservers[e];return this.systemObservers.splice(e,1),this.systems.splice(e,1),this.__execution_order_needs_update=!0,null!==this.dataset&&this.dataset.removeObserver(i),await new Promise(((e,i)=>{this.stopSystem(t,e,(e=>{i(`system ${zm(t)} shutdown failed: ${e}`)}))})),this.systemAccumulatedFixedStepTime.delete(t),this.on.systemRemoved.send1(t),!0}stopSystem(t,e,i){const n=this;try{t.state.set(Em.STOPPING)}catch(t){return void i(t)}try{t.shutdown(n,(function(){t.state.set(Em.STOPPED),n.on.systemStopped.send1(t),e(t)}),(function(t){i(t)}))}catch(t){i(t)}}startSystem(t,e,i){if(t.state.getValue()===Em.RUNNING)return void e(t);const n=this;try{t.state.set(Em.STARTING)}catch(t){return void i(t)}function s(t){i(t)}try{t.startup(n,(function(){t.state.set(Em.RUNNING),n.on.systemStarted.dispatch(t),e(t)}),s)}catch(t){s(t)}}startup(t,e){if(1===this.state)throw new xu("System is currently in starting state");if(2===this.state)return void t();this.state=1;const i=this,n=this.systems;let s=0;const r=n.length;function a(){i.state=2;try{t()}catch(t){}}function o(){s++,s===r&&a()}let l=!0;function h(t,n){l&&(l=!1,i.state=3,e(n))}0!==r?n.forEach((function(t){const e=o.bind(null,t),n=h.bind(null,t);i.startSystem(t,e,n)})):a()}promiseSystem(t){const e=this;return new Promise((function(i,n){const s=e.getSystem(t);null!==s?i(s):e.on.systemAdded.add((function n(s){s instanceof t&&(e.on.systemAdded.remove(n),i(s))}))}))}promiseSystemInState(t,e){const i=this;return new Promise((function(n,s){i.promiseSystem(t).then((function(t){!function i(){t.state.get()!==e?t.state.onChanged.addOne(i):n(t)}()}),s)}))}shutdown(t,e){this.state=4,null!==this.dataset&&this.detachDataSet();const i=this,n=this.systems;let s=0;const r=n.length;function a(){i.state=5;try{t()}catch(t){}}function o(t){s++,t.state.set(Em.STOPPED),i.on.systemStopped.send1(t),s===r&&a()}let l=!0;function h(t){l&&(l=!1,i.state=3,e())}0===r&&a(),n.forEach((function(t){t.state.set(Em.STOPPING);const e=o.bind(null,t),n=h.bind(null,t);try{t.shutdown(i,e,n)}catch(t){n(t)}}))}}class d_{id=-1;generation=-1;components=[];#b=[];dataset=null;flags=6;properties={};on={built:new _};#S(){this.clearFlag(1)}setFlag(t){this.flags|=t}getFlag(t){return 0!=(this.flags&t)}clearFlag(t){this.flags&=~t}get isBuilt(){return this.getFlag(1)}removeAllComponents(){const t=this.components;for(let e=t.length-1;e>=0;e--){const i=t[e];this.removeComponent(Object.getPrototypeOf(i).constructor)}}get count(){return this.components.length}add(t){if(null==t)throw new Error(`Can not add ${t} to Entity`);return this.components.push(t),this.getFlag(1)&&this.dataset.addComponentToEntity(this.id,t),this}hasComponent(t){return null!==this.getComponent(t)}getComponent(t){const e=this.components,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i instanceof t)return i}return null}getComponentSafe(t){const e=this.getComponent(t);if(null===e)throw new Error(`Component of given class '${computeComponentClassName(t)}' not found`);return e}removeComponent(t){const e=this.components,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i instanceof t)return e.splice(n,1),this.getFlag(1)&&this.dataset.removeComponentFromEntity(this.id,t),i}return null}sendEvent(t,e){this.getFlag(1)&&this.dataset.sendEvent(this.id,t,e)}promiseEvent(t){return new Promise(((e,i)=>{const n=()=>{this.removeEventListener(t,n),this.removeEventListener(h_,i),e()};this.addEventListener(t,n),this.removeEventListener(h_,i)}))}addEventListener(t,e,i){return this.getFlag(1)?this.dataset.addEntityEventListener(this.id,t,e,i):this.#b.push({name:t,listener:e,context:i}),this}removeEventListener(t,e,i){if(this.getFlag(1))this.dataset.removeEntityEventListener(this.id,t,e,i);else{const n=this.#b;for(let s=0,r=n.length;s<r;s++){const a=n[s];a.name===t&&a.listener===e&&a.context===i&&(n.splice(s,1),s--,r--)}}return this}destroy(){if(this.getFlag(1)){const t=this.dataset,e=this.id;return t.removeEntityEventListener(e,h_,this.#S,this),t.removeEntity(e),this.id=-1,this.generation=-1,this.clearFlag(1),!0}return!1}build(t){if(this.getFlag(1)&&function(t,e,i){if(!i.entityExists(t))return!1;const n=e.length;for(let s=0;s<n;s++){const n=e[s];if(i.getComponent(t,n.constructor)!==n)return!1}return!0}(this.id,this.components,t))return this.id;const e=this.id=t.createEntity();let i;this.generation=t.getEntityGeneration(e),this.dataset=t;const n=this.#b,s=n.length;for(i=0;i<s;i++){const s=n[i];t.addEntityEventListener(e,s.name,s.listener,s.context)}this.#b.splice(0,s);const r=this.components,a=r.length;if(this.getFlag(2))for(i=0;i<a;i++){const e=r[i];t.registerComponentType(e.constructor)}for(i=0;i<a;i++){const n=r[i];t.addComponentToEntity(e,n)}return this.setFlag(1),this.getFlag(4)&&t.addEntityEventListener(e,h_,this.#S,this),this.on.built.send2(e,t),e}static readFromDataset(t,e){const i=new d_;return e.getAllComponents(t).filter(Km).forEach(i.add,i),i.setFlag(1),i.id=t,i.dataset=e,i.generation=e.getEntityGeneration(t),i}}d_.prototype.isEntity=!0;class p_{transform=new B;parent=-1;flags=1;toString(){return JSON.stringify(this.toJSON())}toJSON(){return{transform:this.transform.toJSON(),parent:this.parent,flags:this.flags}}fromJSON({transform:t,parent:e=-1,flags:i=1}){this.transform.fromJSON(t),this.parent=e,this.flags=i}get immediate(){return this.getFlag(1)}set immediate(t){this.writeFlag(1,t)}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}}p_.typeName="TransformAttachment";class f_{constructor(){this.entity=-1}static from(t){const e=new f_;return e.entity=t,e}toJSON(){return{entity:this.entity}}fromJSON({entity:t}){this.entity=t}}f_.typeName="ParentEntity",f_.serializable=!1;class m_{__parent=null;__children=[];__transform=new B;on={built:new _,destroyed:new _};flags=1;constructor(t=new d_){this.__entity=t}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}traverse(t,e){t.call(e,this);const i=this.__children,n=i.length;for(let s=0;s<n;s++)i[s].traverse(t,e)}traverseChildren(t,e){this.__children.forEach(t,e)}get children(){return this.__children}__transform_sync_down(){const t=this.__transform;if(null===this.__parent){const e=this.__entity.getComponent(B);null!==e&&e.copy(t)}else this.__safe_get_attachment().transform.copy(t)}static fromComponents(...t){const e=new m_;for(let i=0;i<t.length;i++){const n=t[i];e.entity.add(n)}return e}__safe_get_attachment(){const t=this.__entity;let e=t.getComponent(p_);return null===e&&(e=new p_,e.setFlag(1),t.add(e)),e}get transform(){return this.__transform}get parent(){return this.__parent}set parent(t){this.__parent=t;const e=this.__entity;if(!e.isBuilt)return;let i=e.removeComponent(f_),n=e.removeComponent(p_);if(null!==t){null===i&&(i=new f_);const s=t.entity;if(!s.isBuilt)throw new Error("Parent entity is not built");const r=s.id;i.entity=r,e.add(i),null===n&&(n=this.__safe_get_attachment()),n.parent=r}}get entity(){return this.__entity}addChild(t){return!!Sf(this.__children,t)&&(null!==t.parent&&t.parent.removeChild(t),t.parent=this,this.__entity.isBuilt&&t.build(this.__entity.dataset),!0)}removeChild(t){return!!Zm(this.__children,t)&&(t.parent=null,!0)}get isBuilt(){return this.__entity.isBuilt}attachListeners(){this.getFlag(2)||(this.__transform.position.onChanged.add(this.__transform_sync_down,this),this.__transform.scale.onChanged.add(this.__transform_sync_down,this),this.__transform.rotation.onChanged.add(this.__transform_sync_down,this),this.setFlag(2))}detachListeners(){this.__transform.position.onChanged.remove(this.__transform_sync_down,this),this.__transform.scale.onChanged.remove(this.__transform_sync_down,this),this.__transform.rotation.onChanged.remove(this.__transform_sync_down,this),this.clearFlag(2)}build(t){const e=this.__parent;if(null!==e){let t=this.__entity.getComponent(f_);null===t&&(t=new f_,this.__entity.add(t));const i=e.__entity;if(!i.isBuilt)throw new Error("Parent entity is not built");const n=i.id;t.entity=n,this.__safe_get_attachment().parent=n}this.__transform_sync_down(),this.getFlag(1)&&this.attachListeners(),this.__entity.build(t);const i=this.__children,n=i.length;for(let e=0;e<n;e++)i[e].build(t);this.on.built.send0()}destroy(){if(!this.__entity.isBuilt)return;this.getFlag(2)&&this.detachListeners();const t=this.__children;for(let e=t.length-1;e>=0;e--)t[e].destroy();this.__entity.destroy(),this.on.destroyed.send0()}}m_.prototype.isEntityNode=!0;class __{constructor(){this.attachment=null,this.transform=null,this.entity=-1,this.parent_transform=null,this.ecd=null}toString(){return`UpdateContext{ attachment:${this.attachment}, entity:${this.entity} }`}update(){this.transform.multiplyTransforms(this.parent_transform,this.attachment.transform)}bind_parent(){const t=this.ecd.getComponent(this.attachment.parent,B);return void 0!==t&&(this.parent_transform=t,!0)}link(){this.parent_transform.subscribe(this.update,this),this.attachment.transform.subscribe(this.update,this)}unlink(){this.parent_transform.unsubscribe(this.update,this),this.attachment.transform.unsubscribe(this.update,this)}}class g_ extends Cm{__contexts=[];__queue=[];__queue_size=0;__queue_cursor=0;constructor(){super(),this.dependencies=[p_,B],this.components_used=[Tm.from(p_,1),Tm.from(B,3)]}__finalize_link(t){t.link(),this.__contexts[t.entity]=t,0!=(1&t.attachment.flags)&&t.update()}__enqueue(t){this.__queue[this.__queue_size++]=t}__dequeue_entity(t){for(let e=0;e<this.__queue_size;e++)if(this.__queue[e].entity===t)return this.__queue.splice(e,1),this.__queue_size--,!0;return!1}link(t,e,i){const n=new __;n.attachment=t,n.transform=e,n.entity=i,n.ecd=this.entityManager.dataset,n.bind_parent()?this.__finalize_link(n):this.__enqueue(n)}unlink(t,e,i){const n=this.__contexts[i];void 0!==n?(delete this.__contexts[i],n.unlink()):this.__dequeue_entity(i)}update(t){const e=Su(this.__queue_size,32);for(let t=0;t<e;t++){const t=this.__queue_cursor%this.__queue_size,e=this.__queue[t];e.bind_parent()?(this.__finalize_link(e),this.__queue.splice(t,1),this.__queue_size--):this.__queue_cursor++}}}class y_ extends ad{constructor(t=""){super(t)}getLocalizationKey(){return`component.name.${this.getValue()}`}getLocalizedValue(t){return t.getString(this.getLocalizationKey())}clone(){const t=new y_;return t.copy(this),t}}function v_(t){const e=new m_;!function(t,e){t.position.copy(e.position),t.scale.copy(e.scale),t.rotation.copy(e.quaternion),t.matrix.set(e.matrix.elements)}(e.transform,t);const i=e.entity,n=new B;if(n.fromMatrix4(t.matrixWorld.elements),i.add(n),i.add(new y_(t.name)),t.isMesh){t.isSkinnedMesh;const e=qf.from(t.geometry,t.material);i.add(e)}const s=t.children,r=s.length;for(let t=0;t<r;t++){const i=v_(s[t]);e.addChild(i)}return e}y_.typeName="Name";const x_=Td;function w_(t,e,i,n,s){if(n===wd)return 0;const r=x_.pointer++;x_[r]=n;let a=e;for(;x_.pointer>r;){x_.pointer--;const e=x_[x_.pointer];if(s.evaluate(e,i))if(i.node_is_leaf(e))t[a++]=e;else{const t=i.node_get_child1(e),n=i.node_get_child2(e);x_[x_.pointer++]=n,x_[x_.pointer++]=t}}return a-e}class b_{evaluate(t,e){throw new Error("Not Implemented")}}const S_=[];class M_ extends b_{ray=[];static from(t){const e=new M_;return e.ray=t,e}evaluate(t,e){return e.node_get_aabb(t,S_),function(t,e){return Cd(t[0],t[1],t[2],t[3],t[4],t[5],e[0],e[1],e[2],e[3],e[4],e[5])}(S_,this.ray)}}function T_(){return!0}function A_(t,e,i,n,s,r){const a=t-n,o=e-s,l=i-r;return a*a+o*o+l*l}class C_ extends n{appendText(t){return this}appendList(t,e,i,n){return this}appendValueList(t,e,i,n){return this}appendValue(t){return this}appendDescriptionOf(t){return this}}C_.INSTANCE=new C_,class extends s{matches(t,e=C_.INSTANCE){throw new Error("Not Implemented")}describeMismatch(t,e){throw new Error("Not Implemented")}}.prototype.isMatcher=!0;class E_{constructor(){this.__system=null,this.__entity_iterator=null}step(){const t=this.__system;if(null===t)return!1;const e=t.entityManager.dataset;if(null===e)return!1;if(!e.isComponentTypeRegistered(qf))return!1;null===this.__entity_iterator&&(this.__entity_iterator=e.createEntityIterator());const i=this.__entity_iterator.next();if(i.done)return this.__entity_iterator=e.createEntityIterator(),!1;const n=i.value;if(!e.entityExists(n))return this.__entity_iterator=null,!1;const s=e.getComponent(n,qf);if(void 0===s)return!1;if(s.getFlag(8))return!1;const r=t.getGeometryUsageCounters().get(s.geometry.id),a=t.__view_contexts.values().next().value;if(void 0===a)return!1;const o=a.adapters,l=o.length;let h=Number.NEGATIVE_INFINITY,c=-1;for(let t=0;t<l;t++){const e=o[t].score(s.geometry,s.material,r);e>h&&(h=e,c=t)}return-1!==c&&s.draw_method!==c&&!!o[c].intend_draw(s)&&(s.draw_method=c,!0)}}const z_=[];function I_(t,e){const i=t.material,n=e.material;return i===n?0:void 0===i?1:void 0===n?-1:i.id-n.id}class L_{constructor(){this.__object_count=0,this.__objects=[]}sort_by_material(){!function(t,e,i,n,s){if(0>=s)return;let r,a,o=2;for(z_[0]=0,z_[1]=s;o>0;){o-=2;const i=z_[o+1],n=z_[o];r=n,a=i;const s=t[n+i>>1];for(;r<=a;){for(;e.call(null,t[r],s)<0;)r++;for(;e.call(null,t[a],s)>0;)a--;if(r<=a){if(r!==a){const e=t[r];t[r]=t[a],t[a]=e}r++,a--}}n<a&&(z_[o++]=n,z_[o++]=a),r<i&&(z_[o++]=r,z_[o++]=i)}}(this.__objects,I_,0,0,this.__object_count-1)}score(t,e,i){return 0}intend_draw(t){return!0}add(t){throw new Error("Not Implemented")}build_start(t,e){}build_end(){}clear(){this.__object_count=0}*maintain(){}get objects(){return this.__objects}get object_count(){return this.__object_count}dispose(){}}L_.prototype.isShadedGeometryRenderAdapter=!0;class N_{object=null;key=null}class P_{constructor(){this.__object_cache=new WeakMap}get(t){const e=this.__object_cache.get(t);if(void 0!==e){const i=e.object;if(e.key.equals(t))return i}const i=t.clone(),n=function(t){let e;const i=t.mode,n=t.material,s=t.geometry;if(0===i)e=new Zs(s,n);else if(2===i)e=new Jl(s,n);else if(3===i)e=new Xl(s,n);else{if(4!==i)throw new Error(`Unsupported draw mode '${i}'`);e=new ih(s,n)}return e.matrixAutoUpdate=!1,e.frustumCulled=!1,e.matrixWorldNeedsUpdate=!1,e.castShadow=t.getFlag(2),e.receiveShadow=t.getFlag(4),null!==t.depth_material&&(e.customDepthMaterial=t.depth_material),e}(i),s=new N_;return s.key=i,s.object=n,this.__object_cache.set(t,s),n}}P_.INSTANCE=new P_;class D_ extends L_{constructor(){super(),this.__cache=P_.INSTANCE}build_start(t,e){this.clear()}add(t){const e=this.__cache.get(t),i=t.transform,n=e.matrixWorld.elements;for(let t=0;t<16;t++)n[t]=i[t];this.__objects[this.__object_count++]=e}}function F_(t,e,i){const n=t.length;let s=n;for(let r=0;r<n;r++){const n=t[r];s=(s<<5)-s+e.call(i,n),s|=0}return s}function O_(t){return t.getHex()}function R_(t){return Yd(t.normal.x,t.normal.y,t.normal.z)^t.constant}function k_(t){return null==t?0:t.id}function B_(t){let e=nd(S(t.alphaTest),t.blendDst,null===t.blendDstAlpha?0:S(t.blendDstAlpha),t.blendEquation,null===t.blendEquationAlpha?0:S(t.blendEquationAlpha),t.blending,t.blendSrc,null===t.blendSrcAlpha?0:S(t.blendSrcAlpha),t.clipIntersection?0:1,null===t.clippingPlanes?0:F_(t.clippingPlanes,R_),t.clipShadows?0:1,t.colorWrite?0:1,t.depthFunc,t.depthTest?0:1,t.depthWrite?0:1,t.fog?0:1,S(t.opacity),t.polygonOffset?0:1,S(t.polygonOffsetFactor),S(t.polygonOffsetUnits),rd(t.precision),t.premultipliedAlpha?0:1,t.dithering?0:1,t.flatShading?0:1,t.side,t.transparent?0:1,rd(t.type),t.vertexColors?0:1,t.visible?0:1);return t.isMeshStandardMaterial?e=nd(e,O_(t.color),S(t.roughness),S(t.metalness),k_(t.map),k_(t.lightMap),S(t.lightMapIntensity),k_(t.aoMap),S(t.aoMapIntensity),O_(t.emissive),S(t.emissiveIntensity),k_(t.emissiveMap),S(t.envMapIntensity),k_(t.bumpMap),k_(t.normalMap)):t.isShaderMaterial&&(e^=t.lights?0:1),e}class U_{constructor({read:t,write:e,name:i,uv_index:n=0}){this.name=i,this.read=t,this.write=e,this.uv_index=n}}const V_=new U_({name:"diffuse",uv_index:0,read:t=>t.map,write(t,e){t.map=e}}),W_=new U_({name:"alpha",uv_index:0,read:t=>t.alphaMap,write(t,e){t.alphaMap=e}}),G_=new U_({name:"displacement",uv_index:0,read:t=>t.displacementMap,write(t,e){t.displacementMap=e}}),H_={MeshDepthMaterial:[V_,G_,W_],MeshBasicMaterial:[V_],MeshStandardMaterial:[V_,W_,new U_({name:"light",uv_index:1,read:t=>t.lightMap,write(t,e){t.lightMap=e}}),new U_({name:"ao",uv_index:1,read:t=>t.aoMap,write(t,e){t.aoMap=e}}),new U_({name:"emissive",uv_index:0,read:t=>t.emissiveMap,write(t,e){t.emissiveMap=e}}),new U_({name:"bump",uv_index:0,read:t=>t.bumpMap,write(t,e){t.bumpMap=e}}),new U_({name:"normal",uv_index:0,read:t=>t.normalMap,write(t,e){t.normalMap=e}}),G_,new U_({name:"roughness",uv_index:0,read:t=>t.roughnessMap,write(t,e){t.roughnessMap=e}}),new U_({name:"metalness",uv_index:0,read:t=>t.metalnessMap,write(t,e){t.metalnessMap=e}}),new U_({name:"environment",uv_index:0,read:t=>t.envMap,write(t,e){t.envMap=e}})]};function j_(t,e){let i,n=e,s=0;const r=t.length;for(;s<r;)i=t[s],++s,i=3432918353*(65535&i)+((3432918353*(i>>>16)&65535)<<16),i=i<<15|i>>>17,i=461845907*(65535&i)+((461845907*(i>>>16)&65535)<<16),n^=i,n=n<<13|n>>>19,n=5*(65535&n)+((5*(n>>>16)&65535)<<16),n=27492+(65535&n)+((58964+(n>>>16)&65535)<<16);return n^=r,n^=n>>>16,n=2246822507*(65535&n)+((2246822507*(n>>>16)&65535)<<16),n^=n>>>13,n=3266489909*(65535&n)+((3266489909*(n>>>16)&65535)<<16),n^=n>>>16,n>>>0}function q_(t){return"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap}function J_(t,i){return Array.isArray(t)||Array.isArray(i)?e(t,i):Yu(t,i)}H_.MeshPhysicalMaterial=H_.MeshStandardMaterial;const $_=new WeakMap;function Y_(t,e){const i=$_.get(t);if(void 0!==i)return i;const n=t.width,s=t.height,r=Zu.uint8(4,n,s);return function(t,e,i){t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,i),t.drawBuffers([t.COLOR_ATTACHMENT0]);const n=e.width,s=e.height;if(4!==e.itemSize)throw new Error(`Expected sampler.itemSize to be 4, instead was '${e.itemSize}'`);const r=e.data;t.readPixels(0,0,n,s,t.RGBA,t.UNSIGNED_BYTE,r)}(e,r,t),$_.set(t,r),r}let X_=null;function Z_(t,e){let i;if(null===X_||void 0===(i=X_.deref())){i=document.createElement("canvas").getContext("webgl2"),i.activeTexture(i.TEXTURE0);const t=i.createTexture();i.bindTexture(i.TEXTURE_2D,t);const e=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,e),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,t,0),X_=new WeakRef(i)}return i}function K_(t){const e=S(t.x);return(e<<5)-e+S(t.y)}const Q_=new WeakMap;function tg(t){if(null===t)return 0;if(void 0===t)return 0;const e=function(t){let e,i=0;null!==t.image&&void 0!==t.image&&(i=function(t){const e=Q_.get(t);if(void 0!==e)return e;let i=0;q_(t)?i=function(t){const e=Su(t.width,8),i=Su(t.height,8),n=function(t){return Y_(t,Z_(t.width,t.height))}(t),s=n.data,r=n.itemSize;let a=0;for(let t=0;t<i;t++){const i=t*n.width;for(let t=0;t<e;t++){const e=(t+i)*r;for(let t=0;t<r;t++)a=(a<<5)-a+s[e]}}return a}(t):t instanceof HTMLImageElement?i=rd(t.src):t instanceof HTMLCanvasElement&&(i=ld(t).hash());let n=0,s=0;return"number"==typeof t.width&&(n=t.width),"number"==typeof t.height&&(s=t.height),i^=(65535&n)<<16|65535&s,Q_.set(t,i),i}(t.image));const n=t.mipmaps;if(Array.isArray(n)){const t=n.length;for(e=0;e<t;e++){const t=n[e].data;if(!(t.length>1024)){i=(i<<5)-i+j_(t,1337);break}}}return i}(t);return nd(t.mapping,t.wrapS,t.wrapT,t.magFilter,t.minFilter,t.anisotropy,t.format,t.type,K_(t.offset),K_(t.repeat),K_(t.center),S(t.rotation),t.generateMipmaps?1:0,t.premultiplyAlpha?1:0,t.flipY?1:0,t.unpackAlignment,e)}function eg(t,e){return t===e||null!==t&&null!==e&&void 0!==t&&void 0!==e&&!!(t.mapping===e.mapping&&t.wrapS===e.wrapS&&t.wrapT===e.wrapT&&t.magFilter===e.magFilter&&t.minFilter===e.minFilter&&t.anisotropy===e.anisotropy&&t.format===e.format&&t.type===e.type&&t.offset.equals(e.offset)&&t.repeat.equals(e.repeat)&&t.center.equals(e.center)&&t.rotation===e.rotation&&t.generateMipmaps===e.generateMipmaps&&t.premultiplyAlpha===e.premultiplyAlpha&&t.flipY===e.flipY&&t.unpackAlignment===e.unpackAlignment&&t.encoding===e.encoding&&function(t,e){if(t===e)return!0;if(t instanceof Image&&e instanceof Image)return t.src===e.src;if("number"==typeof t.width&&t.width!==e.width||"number"==typeof t.height&&t.height!==e.height)return!1;if(q_(t)&&q_(e))return function(t,e){if(t===e)return!0;if(t.width!==e.width||t.height!==e.height)return!1;const i=Z_(t.width,t.height),n=Y_(t,i),s=Y_(e,i);return J_(n.data,s.data)}(t,e);if(t instanceof HTMLCanvasElement&&e instanceof HTMLCanvasElement)return function(t,e){if(t===e)return!0;if(t.width!==e.width||t.height!==e.height)return!1;const i=ld(t),n=ld(e);return!!i.equals(n)}(t,e);if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++){const n=t[i],s=e[i];if(n.format!==s.format)return!1;if(!ig(n.mipmaps,s.mipmaps))return!1}return!0}return!(!i(t.data)||!i(e.data))&&ng(t,e)}(t.image,e.image))&&!(t.isCompressedTexture&&e.isCompressedTexture&&!ig(t.mipmaps,e.mipmaps))}function ig(t,e){if(void 0===t)return void 0===e;if(void 0===e)return!1;const i=t.length;if(i!==e.length)return!1;for(let n=i-1;n>=0;n--)if(!ng(t[n],e[n]))return!1;return!0}function ng(t,e){if(t.width!==e.width)return!1;if(t.height!==e.width)return!1;const i=t.data,n=e.data;return i===n||J_(i,n)}function sg(t,e){return t.equals(e)}function rg(t,e,i,n){if(t===e)return!0;if(null===t||null===e||void 0===t||void 0===e)return!1;const s=t.length;if(s!==e.length)return!1;for(let r=0;r<s;r++){const s=t[r],a=e[r];if(!i.call(n,s,a))return!1}return!0}function ag(t,e){return t===e||null!==t&&null!==e&&void 0!==t&&void 0!==e&&t.id===e.id}function og(t,e){if(t===e)return!0;if(t.type!==e.type)return!1;if(t.alphaTest!==e.alphaTest||t.blendDst!==e.blendDst||t.blendDstAlpha!==e.blendDstAlpha||t.blendEquation!==e.blendEquation||t.blendEquationAlpha!==e.blendEquationAlpha||t.blending!==e.blending||t.blendSrc!==e.blendSrc||t.blendSrcAlpha!==e.blendSrcAlpha||t.clipIntersection!==e.clipIntersection||!rg(t.clippingPlanes,e.clippingPlanes,sg)||t.clipShadows!==e.clipShadows||t.colorWrite!==e.colorWrite||t.depthFunc!==e.depthFunc||t.depthTest!==e.depthTest||t.depthWrite!==e.depthWrite||t.fog!==e.fog||t.lights!==e.lights||t.opacity!==e.opacity||t.polygonOffset!==e.polygonOffset||t.polygonOffsetFactor!==e.polygonOffsetFactor||t.polygonOffsetUnits!==e.polygonOffsetUnits||t.precision!==e.precision||t.premultipliedAlpha!==e.premultipliedAlpha||t.dithering!==e.dithering||t.flatShading!==e.flatShading||t.side!==e.side||t.transparent!==e.transparent||t.vertexColors!==e.vertexColors||t.visible!==e.visible)return!1;if(t.onBeforeCompile!==e.onBeforeCompile)return!1;if(t.isMeshStandardMaterial){if(!(t.color.equals(e.color)&&t.roughness===e.roughness&&t.metalness===e.metalness&&t.lightMapIntensity===e.lightMapIntensity&&t.aoMapIntensity===e.aoMapIntensity&&t.emissive.equals(e.emissive)&&t.emissiveIntensity===e.emissiveIntensity&&t.bumpScale===e.bumpScale&&t.normalMapType===e.normalMapType&&t.normalScale.equals(e.normalScale)&&t.displacementScale===e.displacementScale&&t.displacementBias===e.displacementBias&&t.envMapIntensity===e.envMapIntensity&&t.refractionRatio===e.refractionRatio&&t.wireframe===e.wireframe&&t.wireframeLinewidth===e.wireframeLinewidth&&t.morphTargets===e.morphTargets&&t.morphNormals===e.morphNormals&&ag(t.roughnessMap,e.roughnessMap)&&ag(t.metalnessMap,e.metalnessMap)&&ag(t.alphaMap,e.alphaMap)&&ag(t.envMap,e.envMap)&&ag(t.displacementMap,e.displacementMap)&&ag(t.normalMap,e.normalMap)&&ag(t.emissiveMap,e.emissiveMap)&&ag(t.bumpMap,e.bumpMap)&&ag(t.aoMap,e.aoMap)&&ag(t.map,e.map)&&ag(t.lightMap,e.lightMap)))return!1}else if(t.isMeshDepthMaterial){if(!ag(t.alphaMap,e.alphaMap)||t.depthPacking!==e.depthPacking||!ag(t.displacementMap,e.displacementMap)||t.displacementScale!==e.displacementScale||t.displacementBias!==e.displacementBias||!ag(t.map,e.map)||t.morphTargets!==e.morphTargets||t.wireframe!==e.wireframe||t.wireframeLinewidth!==e.wireframeLinewidth)return!1}else{if(!t.isMeshMatcapMaterial)return!1;if(!(t.color.equals(e.color)&&ag(t.matcap,e.matcap)&&ag(t.map,e.map)&&ag(t.bumpMap,e.bumpMap)&&ag(t.normalMap,e.normalMap)&&t.normalScale.equals(e.normalScale)&&ag(t.displacementMap,e.displacementMap)&&t.displacementScale===e.displacementScale&&t.displacementBias===e.displacementBias&&ag(t.alphaMap,e.alphaMap)&&t.morphTargets===e.morphTargets&&t.morphNormals===e.morphNormals&&t.flatShading===e.flatShading))return!1}return!0}class lg{constructor(){this.materialCache=new Zp({maxWeight:1e3,keyHashFunction:B_,keyEqualityFunction:og}),this.textureCache=new Zp({maxWeight:1e3,keyHashFunction:tg,keyEqualityFunction:eg})}acquire(t){const e=this.materialCache.get(t);if(null!==e)return e;const i=this.textureCache,n=t.type,s=H_[n];if(void 0!==s){const e=s.length;for(let n=0;n<e;n++){const e=s[n],r=e.read(t);if(null==r)continue;const a=i.get(r);null!==a?e.write(t,a):i.put(r,r)}}return this.materialCache.put(t,t),t}validate(t,e){const i=this.materialCache.validate(((i,n,s)=>{t.call(e,`Material error: ${i}. Material ${n}`)})),n=this.textureCache.validate(((i,n,s)=>{t.call(e,`Texture error: ${i}. Texture ${n}`)}));return i&&n}}lg.Global=new lg;const hg=new WeakMap;let cg=0;function ug(t,e){let i=hg.get(t);void 0===i&&(i=new WeakMap,hg.set(t,i));let n=i.get(e);return void 0===n&&(n=new Function("previous, next",`return function f${cg++}(a,b,c,d){ previous(a,b,c,d); next(a,b,c,d); };`)(t,e),i.set(e,n)),n}function dg(t){const e="\n #define USE_COLOR_ALPHA\n #define USE_INSTANCING_COLOR \n \n attribute mat4 instanceMatrix;\n attribute vec4 instanceColor;\n \n"+t.vertexShader.replace("#include <begin_vertex>","\n vec3 transformed = ( instanceMatrix * vec4(position,1.0) ).xyz;\n ").replace("#include <beginnormal_vertex>","\n vec3 objectNormal = vec3( normal );\n {\n // this is in lieu of a per-instance normal-matrix\n // shear transforms in the instance matrix are not supported\n\n mat3 m = mat3( instanceMatrix );\n \n objectNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );\n objectNormal = m * objectNormal;\n \n }\n \n #ifdef USE_TANGENT\n vec3 objectTangent = vec3( tangent.xyz );\n #endif\n ").replace("#include <color_vertex>","\n #if defined( USE_COLOR_ALPHA )\n vColor = instanceColor;\n #else\n vColor = instanceColor.xyz;\n #endif\n ");t.vertexShader=e,t.fragmentShader="\n #define USE_COLOR_ALPHA\n #define USE_INSTANCING_COLOR \n "+t.fragmentShader}const pg=new Zp({maxWeight:1024,keyHashFunction:B_});class fg{constructor(){this.__threeGeometry=null,this.__threeInstanceGeometry=null,this.count=0,this.capacity=0,this.growFactor=1.2,this.growConstant=16,this.shrinkFactor=.5,this.shrinkConstant=64,this.__attributeTransform=null,this.__attributeTransformArray=null,this.__attributeColor=null,this.__attributeColorArray=null,this.__instanceUsage=Ti,this.__material=null,this.indices=[],this.references=[],this.__draw_mode=0,this.mesh=_p(),this.use_color=!0}__build_mesh(){let t;switch(this.__draw_mode){case 0:t=new Zs(this.mesh.geometry,this.mesh.material);break;case 2:t=new Jl(this.mesh.geometry,this.mesh.material);break;case 3:t=new Xl(this.mesh.geometry,this.mesh.material);break;default:throw new Error(`Unsupported DrawMode '${this.__draw_mode}'`)}t.matrixAutoUpdate=!1,t.frustumCulled=!1,t.matrixWorldNeedsUpdate=!1,null!==this.mesh&&(t.castShadow=this.mesh.castShadow,t.receiveShadow=this.mesh.receiveShadow,t.customDepthMaterial=this.mesh.customDepthMaterial),this.mesh=t}set draw_mode(t){t!==this.__draw_mode&&(this.__draw_mode=t,this.__build_mesh())}set instance_usage(t){this.__instanceUsage!==t&&(this.__instanceUsage=t,null!==this.__attributeTransform&&this.__attributeTransform.setUsage(t),null!==this.__attributeColor&&this.__attributeColor.setUsage(t))}get instance_usage(){return this.__instanceUsage}dispose(){null!==this.__threeGeometry&&this.__threeGeometry.dispose()}setGeometry(t){if(!0!==t.isBufferGeometry)throw new Error("Expected THREE.BufferedGeometry, got something else instead.");this.__threeInstanceGeometry=t,this.build()}#M(t){const e=t.clone();if(e.isShaderMaterial)for(const i in e.uniforms)e.uniforms[i]=t.uniforms[i];e.onBeforeCompile=ug(t.onBeforeCompile,dg);const i=new $o({depthPacking:xi});return 0!==e.alphaTest&&(i.alphaTest=e.alphaTest,i.map=e.map),i.onBeforeCompile=dg,{color:lg.Global.acquire(e),depth:lg.Global.acquire(i)}}setMaterial(t){const e=pg.getOrCompute(t,this.#M,this);this.__material=e.color,this.mesh.material=e.color,this.mesh.customDepthMaterial=e.depth}setCapacity(t){this.capacity!==t&&(this.capacity=t,this.build())}ensureCapacity(t){const e=this.capacity;if(e<t){const i=Pf(t,e*this.growFactor,e+this.growConstant),n=Math.ceil(i);this.setCapacity(n)}else Su(e*this.shrinkFactor,e-this.shrinkConstant)>t&&this.setCapacity(t)}setTransformAt(t,e){ed(e,0,this.__attributeTransformArray,16*t,16)}setColorAt(t,e){ed(e,0,this.__attributeColorArray,4*t,4)}setColorByComponentAt(t,e,i,n,s){const r=this.__attributeColorArray,a=4*t;r[a]=e,r[a+1]=i,r[a+2]=n,r[a+3]=s}requestAttributeUpdate(){this.__attributeTransform.needsUpdate=!0,null!==this.__attributeColor&&(this.__attributeColor.needsUpdate=!0)}swap(t,e){throw new Error("Not Implemented Yet")}setCount(t){this.ensureCapacity(t),this.count=t,this.__threeGeometry.instanceCount=t}getCount(){return this.count}add(t){const e=this.count;return this.setCount(e+1),this.indices[t]=e,this.references[e]=t,e}traverseReferences(t,e){const i=this.indices,n=i.length;for(let s=0;s<n;s++){const n=i[s];void 0!==n&&t.call(e,n,s)}}remove(t){const e=this.indices[t];if(void 0===e)throw new Error(`Reference '${t}' was not found`);delete this.indices[t];const i=this.count-1,n=this.references;if(e===i)delete n[e];else{const t=this.__attributeTransform;t.array.copyWithin(16*e,16*i,16*i+16),t.needsUpdate=!0;const s=this.__attributeColor;null!==s&&(s.array.copyWithin(4*e,4*i,4*i+4),s.needsUpdate=!0);const r=n[i];if(void 0===r)throw new Error("Moved reference was not found");delete n[i],n[e]=r,this.indices[r]=e}this.setCount(this.count-1)}build(){null!==this.__threeGeometry&&this.__threeGeometry.dispose(),this.__threeGeometry=new Yc;const t=this.__threeInstanceGeometry,e=this.__threeGeometry;e.instanceCount=this.count,e.dynamic=!0,function(t,e){t.index=e.index;for(let i in e.attributes)e.attributes.hasOwnProperty(i)&&(t.attributes[i]=e.attributes[i])}(e,t);const i=new Float32Array(16*this.capacity);if(null!==this.__attributeTransform){const t=this.__attributeTransform.array;Kp(t,i),i.length>t.length&&i.fill(0,t.length)}if(this.__attributeTransformArray=i,this.__attributeTransform=new Ol(i,16),this.__attributeTransform.setUsage(this.__instanceUsage),e.setAttribute("instanceMatrix",this.__attributeTransform),this.use_color){const t=new Uint8Array(4*this.capacity);if(null!==this.__attributeColor){const e=this.__attributeColor.array;Kp(e,t),t.length>e.length&&t.fill(255,e.length)}this.__attributeColorArray=t,this.__attributeColor=new Ol(t,4),this.__attributeColor.normalized=!0,this.__attributeColor.setUsage(this.__instanceUsage),e.setAttribute("instanceColor",this.__attributeColor)}else this.__attributeColorArray=null,this.__attributeColor=null;this.mesh.geometry=e}static from(t,e){const i=new fg;return i.setGeometry(t),i.setMaterial(e),i}}class mg{geometry=-1;material=-1;mode=0;flags=0;hash(){return this.geometry^this.material}equals(t){return this.geometry===t.geometry&&this.material===t.material&&this.mode===t.mode&&this.flags===t.flags}copy(t){this.geometry=t.geometry,this.material=t.material,this.mode=t.mode,this.flags=t.flags}clone(){const t=new mg;return t.copy(this),t}fromSG(t){this.geometry=t.geometry.id,this.material=t.material.id,this.mode=t.mode,this.flags=t.flags}}const _g=new mg;class gg extends L_{__instanced_meshes=new qp;__active_meshes=new Set;score(t,e,i){return i>16?1:i<4?-1:0}__get_instanced_mesh(t){_g.fromSG(t),_g.flags&=6;let e=this.__instanced_meshes.get(_g);return void 0!==e||(e=new fg,e.instance_usage=35040,e.shrinkFactor=0,e.draw_mode=t.mode,e.setMaterial(t.material),e.setGeometry(t.geometry),e.mesh.castShadow=t.getFlag(2),e.mesh.receiveShadow=t.getFlag(4),this.__instanced_meshes.set(_g.clone(),e)),e}add(t){const e=this.__get_instanced_mesh(t),i=e.count,n=i+1;n>e.capacity&&e.ensureCapacity(n),e.setTransformAt(i,t.transform),e.count=n,this.__active_meshes.add(e)}build_start(t,e){this.clear()}build_end(){const t=this.__objects;for(const e of this.__active_meshes)e.setCount(e.getCount()),e.requestAttributeUpdate(),t[this.__object_count++]=e.mesh}clear(){super.clear();const t=this.__active_meshes;for(const e of t)e.setCount(0);t.clear()}dispose(){this.clear(),this.__instanced_meshes.forEach(((t,e)=>{t.dispose()})),this.__instanced_meshes.clear()}}const yg=[];class vg{constructor(){this.adapters=[new D_,new gg]}*maintain(){const t=this.adapters;for(let e=0;e<t.length;e++){const i=t[e];void 0!==i&&(yield*i.maintain())}}setAdapter(t,e){const i=this.adapters[t];void 0!==i&&i.dispose(),this.adapters[t]=e}removeAdapter(t){const e=this.adapters[t];return void 0!==e&&(delete this.adapters[t],e.dispose(),!0)}collect(t,e,i,n,s,r){const a=this.adapters,o=a.length;let l=0,h=0;for(;l<o;l++)a[l].build_start(i,n);const c=im(yg,0,s,n.frustum),u=r.computeComponentTypeIndex(qf);for(l=0;l<c;l++){const t=yg[l],e=r.getComponentByIndex(t,u);0!=(16&e.flags)&&e.material.visible&&a[e.draw_method].add(e)}let d=0;for(l=0;l<o;l++){const i=a[l];i.build_end();const n=i.object_count;for(h=0;h<n;h++){const n=i.objects[h];t[e+d]=n,d++}}return d}dispose(){for(const t of this.adapters)void 0!==t&&t.dispose()}}const xg=new wu,wg=new Float32Array(6),bg={New:"new",Initializing:"initializing",Initialized:"initialized",Finalizing:"finalizing",Finalized:"finalized",Starting:"starting",Running:"running",Stopping:"stopping",Stopped:"stopped"};class Sg{id="";__state=new Fm(bg.New,bg);getState(){return this.__state}initialize(){const t=this.__state.getValue();if(t!==bg.New&&t!==bg.Finalized)throw new xu(`Expected New or Finalized state, instead got ${n_(bg,t)}`);this.__state.set(bg.Initialized)}finalize(){const t=this.__state;if(t.getValue()===bg.Running&&this.shutdown(),t.getValue()!==bg.Stopped&&t.getValue()!==bg.Initialized)throw new xu(`Expected Initialized or Stopped state, instead got ${n_(bg,t.getValue())}`);t.set(bg.Finalized)}startup(){const t=this.__state.getValue();if(t!==bg.Initialized&&t!==bg.Stopped)throw new xu(`Expected Initial state, instead got ${n_(bg,t)}`);this.__state.set(bg.Running)}shutdown(){this.__state.set(bg.Stopped)}}class Mg extends Sg{__dependencies=[];engine=null;attach(){this.id="",this.engine=null}get dependencies(){return this.__dependencies}initialize(t){this.engine=t,super.initialize()}finalize(){super.finalize()}async startup(){return super.startup(),Promise.resolve()}async shutdown(){return super.shutdown(),Promise.resolve()}}const Tg={defines:{NUM_SAMPLES:7,NUM_RINGS:4,NORMAL_TEXTURE:0,DIFFUSE_TEXTURE:0,DEPTH_PACKING:1,PERSPECTIVE_CAMERA:1},uniforms:{tDepth:{value:null},tNormal:{value:null},size:{value:new Ri(512,512)},cameraNear:{value:1},cameraFar:{value:100},cameraProjectionMatrix:{value:new Cn},cameraInverseProjectionMatrix:{value:new Cn},intensity:{value:.1},bias:{value:.5},minResolution:{value:0},kernelRadius:{value:100},randomSeed:{value:0}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\t\t}",fragmentShader:"\n\n\t\t#include <common>\n\n\t\tvarying vec2 vUv;\n\n\t\tuniform sampler2D tDepth;\n\n\t\t#if NORMAL_TEXTURE == 1\n\t\tuniform sampler2D tNormal;\n\t\t#endif\n\n\t\tuniform float cameraNear;\n\t\tuniform float cameraFar;\n\t\tuniform mat4 cameraProjectionMatrix;\n\t\tuniform mat4 cameraInverseProjectionMatrix;\n\n\t\tuniform float intensity;\n\t\tuniform float bias;\n\t\tuniform float kernelRadius;\n\t\tuniform float minResolution;\n\t\tuniform vec2 size;\n\t\tuniform float randomSeed;\n\n\t\t// RGBA depth\n\n\t\t#include <packing>\n\t\t\n\t\tout float out_occlusion;\n\n\t\tfloat getDepth( const in vec2 screenPosition ) {\n\t\t\t#if DEPTH_PACKING == 1\n\t\t\treturn unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );\n\t\t\t#else\n\t\t\treturn texture2D( tDepth, screenPosition ).x;\n\t\t\t#endif\n\t\t}\n\n\t\tfloat getViewZ( const in float depth ) {\n\t\t\t#if PERSPECTIVE_CAMERA == 1\n\t\t\treturn perspectiveDepthToViewZ( depth, cameraNear, cameraFar );\n\t\t\t#else\n\t\t\treturn orthographicDepthToViewZ( depth, cameraNear, cameraFar );\n\t\t\t#endif\n\t\t}\n\n\t\tvec3 getViewPosition( const in vec2 screenPosition, const in float depth, const in float viewZ ) {\n\t\t\tfloat clipW = cameraProjectionMatrix[2][3] * viewZ + cameraProjectionMatrix[3][3];\n\t\t\tvec4 clipPosition = vec4( ( vec3( screenPosition, depth ) - 0.5 ) * 2.0, 1.0 );\n\t\t\tclipPosition *= clipW; // unprojection.\n\n\t\t\treturn ( cameraInverseProjectionMatrix * clipPosition ).xyz;\n\t\t}\n\n\t\tvec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPosition ) {\n\t\t\t#if NORMAL_TEXTURE == 1\n\t\t\treturn unpackRGBToNormal( texture2D( tNormal, screenPosition ).xyz );\n\t\t\t#else\n\t\t\treturn normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );\n\t\t\t#endif\n\t\t}\n\t\t\n\t\t// Non-sin based hash function, fast and has good randomness\n float hash12(vec2 p){\n vec3 p3 = fract(vec3(p.xyx) * .1031);\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n }\n \n\t\tfloat minResolutionMultipliedByCameraFar;\n\n\t\tfloat getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {\n\t\t\tvec3 viewDelta = sampleViewPosition - centerViewPosition;\n\t\t\t\n\t\t\tfloat viewDistance = length( viewDelta );\n\t\t\t\n float vn = dot( centerViewNormal, viewDelta );\n float a2 = (vn - minResolutionMultipliedByCameraFar) / viewDistance - bias;\n float a1 = (1.0 + pow2( viewDistance ) );\n \n\t\t\treturn max(0.0, a2) / a1;\n\t\t}\n\n\t\t// moving costly divides into consts\n\t\tconst float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n\t\tconst float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n\t\tfloat getAmbientOcclusion( const in vec3 centerViewPosition ) {\n\t\t\t// precompute some variables require in getOcclusion.\n\t\t\tminResolutionMultipliedByCameraFar = minResolution * cameraFar;\n\t\t\tvec3 centerViewNormal = getViewNormal( centerViewPosition, vUv );\n\n\t\t\t// jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/\n\t\t\tfloat angle = hash12( vUv + randomSeed ) * PI2;\n\t\t\tvec2 radius = vec2( kernelRadius * INV_NUM_SAMPLES ) / size;\n\n\t\t\tfloat occlusionSum = 0.0;\n\t\t\tfloat weightSum = 0.0;\n\n\t\t\tfor( int i = 0; i < NUM_SAMPLES; i ++ ) {\n\t\t\t\tvec2 sampleUv = vUv + vec2( cos( angle ), sin( angle ) ) * radius * float(i+1);\n\t\t\t\t\n\t\t\t\tangle += ANGLE_STEP;\n\n\t\t\t\tfloat sampleDepth = getDepth( sampleUv );\n\t\t\t\t\n\t\t\t\tif( sampleDepth >= ( 1.0 - EPSILON ) ) {\n\t\t\t\t // skip, too far\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tfloat sampleViewZ = getViewZ( sampleDepth );\n\t\t\t\t\n\t\t\t\tvec3 sampleViewPosition = getViewPosition( sampleUv, sampleDepth, sampleViewZ );\n\t\t\t\t\n\t\t\t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n\t\t\t\t\n\t\t\t\tweightSum += 1.0;\n\t\t\t}\n\n\t\t\tif( weightSum == 0.0 ) discard;\n\n\t\t\treturn occlusionSum * ( intensity / weightSum );\n\t\t}\n\n\t\tvoid main() {\n\t\t\tfloat centerDepth = getDepth( vUv );\n\t\t\tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n\t\t\t\tdiscard;\n\t\t\t}\n\n\t\t\tfloat centerViewZ = getViewZ( centerDepth );\n\t\t\tvec3 viewPosition = getViewPosition( vUv, centerDepth, centerViewZ );\n\n\t\t\tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n\t\t\t\n\t\t\tfloat invOcclusion = 1.0 - ambientOcclusion;\n\t\t\t\n\t\t\tout_occlusion = invOcclusion;\n\t\t}"},Ag=function(t=["r","g","b","a"]){return`\n uniform sampler2D tTexture;\n varying vec2 vUv;\n \n void main(){\n vec4 texel = texture2D( tTexture, vUv );\n gl_FragColor = ${function(t,e){const i=[],n=e.length;for(let t=0;t<n;t++){const n=e[t];if("string"==typeof n)i[t]=`texel.${n}`;else{if("number"!=typeof n)throw new Error(`Unsupported swizzle token '${n}'`);i[t]=Number(n).toFixed(4)}}const s=i.join(", "),r=[void 0,"float","vec2","vec3","vec4"][e.length];if(void 0===r)throw new Error(`No constructor for input length ${e.length}`);return`${r}(${s})`}(0,t)};\n }\n `};function Cg(t,e){if(4===e)t.blending=at,t.blendEquation=ot,t.blendSrc=pt,t.blendDst=gt;else{const i=function(t){let e;if(5===t)e=et;else if(0===t)e=it;else if(1===t)e=nt;else if(2===t)e=st;else{if(3!==t)throw new TypeError(`Unsupported blending type ${t}`);e=rt}return e}(e);t.blending=i}}class Eg{constructor({renderTarget:t,blending:e,renderTargetScale:i=1}){this.name="",this.__blending=e,this.renderTarget=t,this.renderTargetScale=i,this.object=new Zs(Ep,this.buildMaterial()),this.stage=0,this.size=new Eu,this.__enabled=!0,this.__order=0,this.on={preRender:new _}}get blending(){return this.__blending}set blending(t){t!==this.__blending&&(this.__blending=t,Cg(this.object.material,t))}set order(t){this.__order=t,this.object.renderOrder=t}get order(){return this.__order}set enabled(t){!this.__enabled&&t?this.enable():this.__enabled&&!t&&this.disable()}get enabled(){return this.__enabled}enable(){this.__enabled||(this.__enabled=!0,this.object.visible=!0)}disable(){this.__enabled&&(this.__enabled=!1,this.object.visible=!1)}setSize(t,e){this.size.set(t,e),this.updateRenderTargetSize()}updateRenderTargetSize(){if(null!==this.renderTarget){const t=this.renderTargetScale,e=this.size,i=e.x*t,n=e.y*t;this.renderTarget.setSize(i,n)}}setRenderTargetScale(t){this.renderTargetScale=t,this.updateRenderTargetSize()}setCustomMaterial(t){Cg(t,this.blending),this.object.material=t}buildMaterial(){const t={tTexture:{type:"t",value:this.renderTarget.texture}};let e;const i=this.renderTarget.texture.format;if(i===xe)e=["r","r","r",1];else{if(i!==me)throw new Error("Unsupported format");e=["r","g","b","a"]}const n=new nr({uniforms:t,vertexShader:"\n varying vec2 vUv;\n \n void main() {\n \n vUv = uv;\n gl_Position = vec4( (uv - 0.5)*2.0, 0.0, 1.0 );\n \n }\n ",fragmentShader:Ag(e),lights:!1,fog:!1,depthTest:!1,depthWrite:!1,transparent:!0,vertexColors:!1});return Cg(n,this.blending),n}}const zg={defines:{KERNEL_RADIUS:4,DEPTH_PACKING:1,PERSPECTIVE_CAMERA:1},uniforms:{tDiffuse:{value:null},size:{value:new Ri(512,512)},sampleUvOffsets:{value:[new Ri(0,0)]},sampleWeights:{value:[1]},tDepth:{value:null},cameraNear:{value:10},cameraFar:{value:1e3},depthCutoff:{value:10}},vertexShader:"\n\n\t\t#include <common>\n\n\t\tuniform vec2 size;\n\n\t\tvarying vec2 vUv;\n\t\tvarying vec2 vInvSize;\n\n\t\tvoid main() {\n\t\t\tvUv = uv;\n\t\t\tvInvSize = 1.0 / size;\n\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\t\t}",fragmentShader:"\n\n\t\t#include <common>\n\t\t#include <packing>\n\n\t\tuniform sampler2D tDiffuse;\n\t\tuniform sampler2D tDepth;\n\n\t\tuniform float cameraNear;\n\t\tuniform float cameraFar;\n\t\tuniform float depthCutoff;\n\n\t\tuniform vec2 sampleUvOffsets[ KERNEL_RADIUS + 1 ];\n\t\tuniform float sampleWeights[ KERNEL_RADIUS + 1 ];\n\n\t\tvarying vec2 vUv;\n\t\tvarying vec2 vInvSize;\n\n\t\tfloat getDepth( const in vec2 screenPosition ) {\n\t\t\t#if DEPTH_PACKING == 1\n\t\t\treturn unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );\n\t\t\t#else\n\t\t\treturn texture2D( tDepth, screenPosition ).x;\n\t\t\t#endif\n\t\t}\n\n\t\tfloat getViewZ( const in float depth ) {\n\t\t\t#if PERSPECTIVE_CAMERA == 1\n\t\t\treturn perspectiveDepthToViewZ( depth, cameraNear, cameraFar );\n\t\t\t#else\n\t\t\treturn orthographicDepthToViewZ( depth, cameraNear, cameraFar );\n\t\t\t#endif\n\t\t}\n\n\t\tvoid main() {\n\t\t\tfloat depth = getDepth( vUv );\n\t\t\tif( depth >= ( 1.0 - EPSILON ) ) {\n\t\t\t\tdiscard;\n\t\t\t}\n\n\t\t\tfloat centerViewZ = -getViewZ( depth );\n\t\t\tbool rBreak = false, lBreak = false;\n\n\t\t\tfloat weightSum = sampleWeights[0];\n\t\t\tvec4 diffuseSum = texture2D( tDiffuse, vUv ) * weightSum;\n\n\t\t\tfor( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n\t\t\t\tfloat sampleWeight = sampleWeights[i];\n\t\t\t\tvec2 sampleUvOffset = sampleUvOffsets[i] * vInvSize;\n\n\t\t\t\tvec2 sampleUv = vUv + sampleUvOffset;\n\t\t\t\tfloat viewZ = -getViewZ( getDepth( sampleUv ) );\n\n\t\t\t\tif( abs( viewZ - centerViewZ ) > depthCutoff ) rBreak = true;\n\n\t\t\t\tif( ! rBreak ) {\n\t\t\t\t\tdiffuseSum += texture2D( tDiffuse, sampleUv ) * sampleWeight;\n\t\t\t\t\tweightSum += sampleWeight;\n\t\t\t\t}\n\n\t\t\t\tsampleUv = vUv - sampleUvOffset;\n\t\t\t\tviewZ = -getViewZ( getDepth( sampleUv ) );\n\n\t\t\t\tif( abs( viewZ - centerViewZ ) > depthCutoff ) lBreak = true;\n\n\t\t\t\tif( ! lBreak ) {\n\t\t\t\t\tdiffuseSum += texture2D( tDiffuse, sampleUv ) * sampleWeight;\n\t\t\t\t\tweightSum += sampleWeight;\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tgl_FragColor = diffuseSum / weightSum;\n\t\t}"},Ig={createSampleWeights:function(t,e){const i=[];for(let n=0;n<=t;n++)i.push(Lg(n,e));return i},createSampleOffsets:function(t,e){const i=[];for(let n=0;n<=t;n++)i.push(e.clone().multiplyScalar(n));return i},configure:function(t,e,i,n){t.defines.KERNEL_RADIUS=e,t.uniforms.sampleUvOffsets.value=Ig.createSampleOffsets(e,n),t.uniforms.sampleWeights.value=Ig.createSampleWeights(e,i),t.needsUpdate=!0}};function Lg(t,e){return Math.exp(-t*t/(e*e*2))/(Math.sqrt(2*Math.PI)*e)}const Ng=new Zs(Ep,null);Ng.frustumCulled=!1,Ng.matrixAutoUpdate=!1,Ng.matrixWorldNeedsUpdate=!1;const Pg=new zr(-1,1,1,-1,0,1),Dg=new cl;function Fg(t,e){Ng.material=e,t.render(Dg,Pg),Ng.material=null}Dg.autoUpdate=!1,Dg.matrixAutoUpdate=!1,Dg.matrixWorldNeedsUpdate=!1,Dg.add(Ng);const Og=new ys;class Rg{constructor({format:t=me,radius:e=8,clear_color:i=0,clear_alpha:n=1}){this.__rt_input=null,this.__rt_output=null,this.__intermediate=new Ji({format:t}),this.__material_blur_x=new nr({uniforms:ir.clone(zg.uniforms),defines:Object.assign({},zg.defines),vertexShader:zg.vertexShader,fragmentShader:zg.fragmentShader,blending:et}),this.__material_blur_y=new nr({uniforms:ir.clone(zg.uniforms),defines:Object.assign({},zg.defines),vertexShader:zg.vertexShader,fragmentShader:zg.fragmentShader,blending:et}),this.__depth_cutoff=.01,this.__blur_radius=e,this.__blur_std_dev=4,this.__clear_color=new ys(i),this.__clear_alpha=n}configureMaterials(){const t=this.__material_blur_x,e=this.__material_blur_y;t.defines.DEPTH_PACKING=e.defines.DEPTH_PACKING=0,t.defines.PERSPECTIVE_CAMERA=e.defines.PERSPECTIVE_CAMERA=1,t.blending=e.blending=et,Ig.configure(t,this.__blur_radius,this.__blur_std_dev,new Ri(1,0)),Ig.configure(e,this.__blur_radius,this.__blur_std_dev,new Ri(0,1)),this.__material_blur_y.uniforms.tDiffuse.value=this.__intermediate.texture}setRenderCamera(t){const e=this.__material_blur_x,i=this.__material_blur_y;!0===t.isPerspectiveCamera&&1!==e.defines.PERSPECTIVE_CAMERA?(e.defines.PERSPECTIVE_CAMERA=1,i.defines.PERSPECTIVE_CAMERA=1,e.needsUpdate=!0,i.needsUpdate=!0):!0!==t.isPerspectiveCamera&&0!==e.defines.PERSPECTIVE_CAMERA&&(e.defines.PERSPECTIVE_CAMERA=0,i.defines.PERSPECTIVE_CAMERA=0,e.needsUpdate=!0,i.needsUpdate=!0);const n=this.__depth_cutoff*(t.far-t.near);e.uniforms.depthCutoff.value=n,i.uniforms.depthCutoff.value=n,e.uniforms.cameraNear.value=i.uniforms.cameraNear.value=t.near,e.uniforms.cameraFar.value=i.uniforms.cameraFar.value=t.far}execute(t){this.__intermediate.width===this.__rt_output.width&&this.__intermediate.height===this.__rt_output.height||this.__intermediate.setSize(this.__rt_output.width,this.__rt_output.height);const e=this.__material_blur_x,i=this.__material_blur_y;e.uniforms.size.value.set(this.__rt_output.width,this.__rt_output.height),i.uniforms.size.value.set(this.__rt_output.width,this.__rt_output.height);const n=t.getRenderTarget(),s=Og;t.getClearColor(s);const r=t.getClearAlpha(),a=t.autoClear;t.autoClear=!1,t.setClearColor(this.__clear_color),t.setRenderTarget(this.__intermediate),t.clearColor(),Fg(t,e),t.setRenderTarget(this.__rt_output),t.clearColor(),Fg(t,i),t.setRenderTarget(n),t.setClearColor(s,r),t.autoClear=a}setDepthBuffer(t){const e=this.__material_blur_x,i=this.__material_blur_y;e.uniforms.tDepth.value=i.uniforms.tDepth.value=t}setInput(t){this.__rt_input=t,this.__material_blur_x.uniforms.tDiffuse.value=t.texture}setOutput(t){this.__rt_output=t}dispose(){this.__intermediate.dispose()}}const kg="color-and-depth",Bg="normal";var Ug=function(){var t=0,e=document.createElement("div");function i(t){return e.appendChild(t.dom),t}function n(i){for(var n=0;n<e.children.length;n++)e.children[n].style.display=n===i?"block":"none";t=i}e.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000",e.addEventListener("click",(function(i){i.preventDefault(),n(++t%e.children.length)}),!1);var s=(performance||Date).now(),r=s,a=0,o=i(new Ug.Panel("FPS","#0ff","#002")),l=i(new Ug.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var h=i(new Ug.Panel("MB","#f08","#201"));return n(0),{REVISION:16,dom:e,addPanel:i,showPanel:n,begin:function(){s=(performance||Date).now()},end:function(){a++;var t=(performance||Date).now();if(l.update(t-s,200),t>=r+1e3&&(o.update(1e3*a/(t-r),100),r=t,a=0,h)){var e=performance.memory;h.update(e.usedJSHeapSize/1048576,e.jsHeapSizeLimit/1048576)}return t},update:function(){s=this.end()},domElement:e,setMode:n}};Ug.Panel=function(t,e,i){var n=Infinity,s=0,r=Math.round,a=r(window.devicePixelRatio||1),o=80*a,l=48*a,h=3*a,c=2*a,u=3*a,d=15*a,p=74*a,f=30*a,m=document.createElement("canvas");m.width=o,m.height=l,m.style.cssText="width:80px;height:48px";var _=m.getContext("2d");return _.font="bold "+9*a+"px Helvetica,Arial,sans-serif",_.textBaseline="top",_.fillStyle=i,_.fillRect(0,0,o,l),_.fillStyle=e,_.fillText(t,h,c),_.fillRect(u,d,p,f),_.fillStyle=i,_.globalAlpha=.9,_.fillRect(u,d,p,f),{dom:m,update:function(l,g){n=Math.min(n,l),s=Math.max(s,l),_.fillStyle=i,_.globalAlpha=1,_.fillRect(0,0,o,d),_.fillStyle=e,_.fillText(r(l)+" "+t+" ("+r(n)+"-"+r(s)+")",h,c),_.drawImage(m,u+a,d,p-a,f,u,d,p-a,f),_.fillRect(u+p-a,d,a,f),_.fillStyle=i,_.globalAlpha=.9,_.fillRect(u+p-a,d,a,r((1-l/g)*f))}}};const Vg=new Float32Array(2);function Wg(t,e,i,n,s,r,a,o,l){const h=function(t,e,i,n,s,r,a,o,l,h){const c=s-i,u=r-n,d=l-a,p=h-o,f=n-o,m=i-a,_=1/(-d*u+c*p),g=(-u*m+c*f)*_,y=(d*f-p*m)*_;if(g>=0&&g<=1&&y>=0&&y<=1){const e=i+y*c,s=n+y*u;return t[0]=e,t[1]=s,!0}return!1}(Vg,0,t,e,i,n,s,r,a,o);return h&&l.readFromArray(Vg),h}class Gg{constructor(t=0,e=0,i=0,n=0){this.x0=t,this.y0=e,this.x1=i,this.y1=n}growWidth(t){this.x0-=t,this.x1+=t}growHeight(t){this.y0-=t,this.y1+=t}grow(t){this.growWidth(t),this.growHeight(t)}shrink(t){this.grow(-t)}applyMatrix3(t){const e=t[0],i=t[1],n=t[3],s=t[4],r=t[6],a=t[7],o=this.x0,l=this.y0,h=this.x1,c=this.y1,u=e*o+n*l+r,d=i*o+s*l+a,p=e*h+n*c+r,f=i*h+s*c+a;let m=Su(u,p),_=bu(u,p),g=Su(d,f),y=bu(d,f);this.set(m,g,_,y)}multiplyScalar(t){this.set(this.x0*t,this.y0*t,this.x1*t,this.y1*t)}computeOverlap(t,e){return function(t,e,i,n,s,r,a,o,l){const h=bu(t,s),c=Su(i,a);if(h>=c)return!1;const u=bu(e,r),d=Su(n,o);return!(u>=d||(l.set(h,u,c,d),0))}(this.x0,this.y0,this.x1,this.y1,t.x0,t.y0,t.x1,t.y1,e)}overlapExists(t){return Ud(this.x0,this.y0,this.x1,this.y1,t.x0,t.y0,t.x1,t.y1)}_expandToFit(t,e,i,n){this.x0=Su(this.x0,t),this.y0=Su(this.y0,e),this.x1=bu(this.x1,i),this.y1=bu(this.y1,n)}_expandToFitPoint(t,e){this._expandToFit(t,e,t,e)}lineIntersectionPoint(t,e,i){const n=this.x0,s=this.y0,r=this.x1,a=this.y1;return!!(Wg(t.x,t.y,e.x,e.y,n,s,r,s,i)||Wg(t.x,t.y,e.x,e.y,n,a,r,a,i)||Wg(t.x,t.y,e.x,e.y,n,s,n,a,i)||Wg(t.x,t.y,e.x,e.y,r,s,r,a,i))}computeNearestPointToPoint(t,e){let i,n;const s=this.x0,r=this.y0,a=this.x1,o=this.y1,l=t.x,h=t.y;i=g(l,s,a),n=g(h,r,o),e.set(i,n)}costForInclusion(t){return this._costForInclusion(t.x0,t.y0,t.x1,t.y1)}_costForInclusion(t,e,i,n){let s=0,r=0;const a=this.x0,o=this.y0,l=this.x1,h=this.y1;return a>t&&(s+=a-t),l<i&&(s+=i-l),o>e&&(r+=o-e),h<n&&(r+=n-h),s*(h-o)+r*(l-a)}computeArea(){return t=this.x0,e=this.y0,(this.x1-t)*(this.y1-e);var t,e}computeSurfaceArea(){const t=this.x0,e=this.y0;return 2*(this.x1-t+(this.y1-e))}containsPoint(t,e){return t>=this.x0&&t<=this.x1&&e>=this.y0&&e<=this.y1}expandToFit(t){this._expandToFit(t.x0,t.y0,t.x1,t.y1)}getCenter(t=new Eu){return t.set(this.centerX,this.centerY),t}midX(){return this.centerX}midY(){return this.centerY}get centerX(){return.5*(this.x0+this.x1)}get centerY(){return.5*(this.y0+this.y1)}getWidth(){return this.x1-this.x0}get width(){return this.getWidth()}getHeight(){return this.y1-this.y0}get height(){return this.getHeight()}set(t,e,i,n){return this.x0=t,this.y0=e,this.x1=i,this.y1=n,this}setPosition(t,e){const i=this.getWidth(),n=this.getHeight();this.set(t,e,t+i,e+n)}move(t,e){this.set(this.x0+t,this.y0+e,this.x1+t,this.y1+e)}clone(){return new Gg(this.x0,this.y0,this.x1,this.y1)}copy(t){return this.set(t.x0,t.y0,t.x1,t.y1)}equals(t){return this.x0===t.x0&&this.y0===t.y0&&this.x1===t.x1&&this.y1===t.y1}clamp(t,e,i,n){this.x0=g(this.x0,t,i),this.y0=g(this.y0,e,n),this.x1=g(this.x1,t,i),this.y1=g(this.y1,e,n)}setBoundsUnordered(t,e,i,n){let s,r,a,o;t<i?(s=t,a=i):(s=i,a=t),e<n?(r=e,o=n):(r=n,o=e),this.set(s,r,a,o)}setNegativelyInfiniteBounds(){return this.set(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY)}toString(){return`AABB2{x0:${this.x0}, y0:${this.y0}, x1:${this.x1}, y1:${this.y1}}`}toJSON(){return{x0:this.x0,y0:this.y0,x1:this.x1,y1:this.y1}}fromJSON(t){this.set(t.x0,t.y0,t.x1,t.y1)}toArray(t=[],e=0){return t[e]=this.x0,t[e+1]=this.y0,t[e+2]=this.x1,t[e+3]=this.y1,t}}Gg.computeLineBetweenTwoBoxes=function(t,e,i,n){const s=new Eu(t.centerX,t.centerY),r=new Eu(e.centerX,e.centerY);return!!t.lineIntersectionPoint(s,r,i)&&!!e.lineIntersectionPoint(s,r,n)},Gg.zero=Object.freeze(new Gg(0,0,0,0)),Gg.unit=Object.freeze(new Gg(0,0,1,1));class Hg{bindings=[];flags=4;position=new Eu(0,0);rotation=new id(0);scale=new Eu(1,1);size=new Eu(0,0);transformOrigin=new Eu(.5,.5);on={linked:new _,unlinked:new _};children=[];parent=null;#T=new Float32Array(9);#A=new Float32Array(9);constructor(){this.el=null,this.position.onChanged.add(this.__updateTransform,this),this.scale.onChanged.add(this.__updateTransform,this),this.rotation.onChanged.add(this.__updateTransform,this),this.size.onChanged.add(this.__setDimensions,this),this.transformOrigin.onChanged.add(this.__setTransformOrigin,this)}get isLinked(){return this.getFlag(1)}get isDestroyed(){return this.getFlag(2)}set visible(t){t!==this.getFlag(4)&&(this.writeFlag(4,t),function(t,e){const i=t.style;e?i.removeProperty("display"):i.display="none"}(this.el,t))}get visible(){return this.getFlag(4)}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}__setTransformOrigin(t,e){this.el.style.transformOrigin=`${100*t}% ${100*e}%`}__setDimensions(t,e){const i=this.el.style;i.width=t+"px",i.height=e+"px"}__updateTransform(){const t=this.position,e=this.scale,i=this.rotation.getValue();!function(t,e,i,n,s,r,a,o){const l=-o,h=Math.sin(l),c=Math.cos(l);t[0]=n*c,t[1]=n*h,t[2]=-n*(0*c+0*h)+0+e,t[3]=-s*h,t[4]=s*c,t[5]=-s*(0*-h+0*c)+0+i,t[6]=0,t[7]=0,t[8]=1}(this.#A,t.x,t.y,e.x,e.y,0,0,i),this.#C()}#C(){const t=this.#A,e=this.#T;for(let i=0;i<9;i++)if(!x(t[i],e[i],1.192092896e-7))return this.#E(),!0;return!1}#E(){!function(t,e){const i="matrix("+t[0]+","+t[3]+","+t[1]+","+t[4]+","+t[2]+","+t[5]+")";e.style.transform=i}(this.#A,this.el),this.#T.set(this.#A)}link(){if(this.isLinked)return;this.setFlag(1);const t=this.bindings,e=t.length;let i;for(i=0;i<e;i++)t[i].link();const n=this.children,s=n.length;for(i=0;i<s;i++)n[i].link();this.on.linked.send0()}unlink(){if(!this.isLinked)return;this.clearFlag(1);const t=this.bindings,e=t.length;let i;for(i=0;i<e;i++)t[i].unlink();const n=this.children,s=n.length;for(i=0;i<s;i++)n[i].unlink();this.on.unlinked.send0()}addChildren(t){for(let e=0;e<t.length;e++)this.addChild(t[e])}addChild(t){return t.parent=this,this.isLinked&&!t.isLinked&&t.link(),this.children.push(t),this.el.appendChild(t.el),this}computePlacement(t,e,i,n,s,r){const a=new Eu(e,i);a.multiply(this.size),a.add(this.position),a._sub(t.x*n,t.y*s),r.copy(a)}addChildAt(t,e,i,n,s){this.computePlacement(t.size,e,i,n,s,t.position),this.addChild(t),this.resizeToFitChildren()}removeChild(t){const e=this.children,i=e.indexOf(t);return-1!==i&&(e.splice(i,1),this.el.removeChild(t.el),t.unlink(),t.parent=null,!0)}hasChild(t){return-1!==this.children.indexOf(t)}removeAllChildren(){const t=this.children,e=t.length;for(let i=0;i<e;i++){const e=t.pop();this.el.removeChild(e.el),e.unlink(),e.parent=null}}expandToFit(t,e,i){const n=this.position.x+e,s=this.position.y+i;t._expandToFit(n,s,n+this.size.x,s+this.size.y);const r=this.children;let a=0;const o=r.length;for(;a<o;a++)r[a].expandToFit(t,n,s)}computeBoundingBox(t){return void 0===t&&(t=new Gg).setNegativelyInfiniteBounds(),this.expandToFit(t,0,0),t}resizeToFitChildren(){const t=new Gg(0,0,this.size.x,this.size.y),e=this.children;let i=0;const n=e.length;for(;i<n;i++)e[i].expandToFit(t,0,0);this.size.set(t.x1,t.y1)}positionLocalToGlobal(t,e){e.copy(t);let i=this;for(;null!==i;)e.add(i.position),i=i.parent;return e}positionGlobalToLocal(t,e){e.copy(t);let i=this;for(;null!==i;)e.sub(i.position),i=i.parent;return e}computeGlobalScale(t){let e=this,i=1,n=1;for(;null!==e;)i*=e.scale.x,n*=e.scale.y,e=e.parent;t.set(i,n)}destroy(){const t=this.children,e=t.length;for(let i=0;i<e;i++)t[i].destroy();this.setFlag(2)}bindSignal(t,e,i){const n=new Mm(t,e,i);return this.bindings.push(n),this.isLinked&&n.link(),this}unbindSignal(t,e,i){const n=this.bindings,s=n.length;for(let r=0;r<s;r++){const s=n[r];if(s.signal===t&&s.handler===e&&(void 0===i||s.context===i))return n.splice(r,1),s.unlink(),!0}return!1}addClass(t){this.el.classList.add(t)}addClasses(t){const e=this.el.classList,i=t.length;for(let n=0;n<i;n++){const i=t[n];e.add(i)}}removeClass(t){this.el.classList.remove(t)}removeClassesByPattern(t){const e=this.el.classList,i=[],n=e.length;for(let s=0;s<n;s++){const n=e[s];-1!==n.search(t)&&i.push(n)}const s=i.length;for(let t=0;t<s;t++){const n=i[t];e.remove(n)}return i}setClass(t,e){return this.el.classList.toggle(t,e),this}css(t){for(let e in t)t.hasOwnProperty(e)&&(this.el.style[e]=t[e])}attr(t){for(let e in t)t.hasOwnProperty(e)&&this.el.setAttribute(e,t[e])}followSize({size:t,padding:e=Eu.zero}){const i=()=>{this.size.set(t.x-2*e.x,t.y-2*e.y)};this.on.linked.add((()=>{i(),t.onChanged.add(i)})),this.on.unlinked.add((()=>{t.onChanged.remove(i)})),i()}}Hg.prototype.isView=!0;class jg extends Hg{constructor({classList:t=[],el:e,tag:i="div",tagNamespace:n,css:s,attr:r}={}){super(),this.el=void 0!==e?e:void 0!==n?document.createElementNS(n,i):document.createElement(i),this.addClasses(t),void 0!==s&&this.css(s),void 0!==r&&this.attr(r)}static group(t,e={}){const i=new jg(e);return t.forEach(i.addChild,i),i}static create(){return new jg}}class qg extends hm{load(t,e,i,n,s){!function(t,e,i){const n=new XMLHttpRequest;n.open("GET",t,!0),n.onreadystatechange=function(){n.readyState===XMLHttpRequest.DONE&&(200===n.status?e&&e(n.response):i&&i(n))},n.send()}(e,(function(t){let e;try{e=JSON.parse(t)}catch(t){return void n(t)}i({create:function(){return e}})}),n)}}class Jg{flags=0;setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}toJSON(){return{flags:this.flags}}fromJSON({flags:t=0}){this.flags=t}}const $g=new Jg;$g.setFlag(1),Jg.Transient=Object.freeze($g),Jg.typeName="SerializationMetadata";class Yg{values=[];get count(){return this.values.length}get(t){return this.values[t]}clear(){this.values.splice(0,this.values.length)}add(t){return!this.contains(t)&&(this.values.push(t),!0)}addAll(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];this.add(e)}}getFirst(){return this.values[0]}contains(t){return-1!==this.values.indexOf(t)}containsAll(t){const e=t.length,i=this.values,n=i.length;let s=0,r=0;t:for(;s<e;s++){const e=t[s];for(r=0;r<n;r++)if(i[r]===e)continue t;return!1}return!0}containsOneOf(t){const e=this.values,i=t,n=e.length,s=i.length;for(let t=0;t<n;t++){const n=e[t];for(let t=0;t<s;t++)if(n===i[t])return!0}return!1}getValues(){return this.values}traverse(t,e){this.values.forEach(t,e)}hash(){let t=0;const e=this.values,i=e.length;for(let n=0;n<i;n++)t=(t<<5)-t+rd(e[n]),t|=0;return t}equals(t){return e(this.values,t.values)}toJSON(){return this.values}fromJSON(t){if(this.clear(),"string"==typeof t)this.add(t);else{const e=t.length;for(let i=0;i<e;i++)this.add(t[i])}}static find(t,e){const i=[];return e.traverseComponents(Yg,((e,n)=>{e.containsAll(t)&&i.push(n)})),i}static fromOne(t){const e=new Yg;return e.add(t),e}static fromJSON(t){const e=new Yg;return e.fromJSON(t),e}}Yg.typeName="Tag";class Xg{constructor(t,e,i,n,s){this.value=t,this.start=e,this.end=i,this.name=n,this.type=s}equals(t){return this.value===t.value&&this.start===t.start&&this.end===t.end&&this.name===t.name&&this.type===t.type}hash(){return this.start^this.end<<16}}const Zg={Text:0,Reference:1,StyleStart:2,StyleEnd:3,ReferenceValue:4};class Kg extends Error{constructor(t,e,i){super(),this.position=t,this.message=e,this.input=i}getDetails(){const t=this.input,e=this.position,i=bu(0,e-10),n=Su(t.length,e+10),s=t.slice(i,n),r=function(t,e){if(e<=0)return"";let i=" ";for(let t=1;t<e;t++)i+=" ";return i}(0,e-i)+"^";return s+"\n"+r}toString(){return`[ParseError] ${this.message}. Error at position ${this.position} near:\n${this.getDetails()}`}}function Qg(t,e,i){let n=e;const s=t.charAt(e);if("["!==s)throw new Kg(e,`expected style start: '[', got '${s}' instead`,t);n++;const r=t.charAt(n);let a;if("$"===r)a=Zg.StyleStart,n++;else if("/"===r){n++;const e=t.charAt(n);if(n++,"$"!==e)throw new Kg(n,`expected style end sequence '[/$', instead got '[/${e}'`,t);a=Zg.StyleEnd}const o=n;for(;n<i;){if("]"===t.charAt(n)){const i=t.substring(o,n);return n++,new Xg(i,e,n,"style",a)}n++}throw new Kg(e,"input underflow, missing terminal of style sequence ']'",t)}class ty{constructor(t,e){this.key=t,this.value=e}equals(t){return this.key===t.key&&this.value===t.value}}const ey={String:"string",Number:"number",Boolean:"boolean",Array:"array",Any:"any"},iy={LiteralString:"literal-string",LiteralNumber:"literal-number",LiteralBoolean:"literal-boolean",Identifier:"identifier",Reference:"reference"};function ny(t,e,i){let n=e,s=0;t:for(;n<i;){const i=t.charAt(n);let r;switch(i){case"0":r=0;break;case"1":r=1;break;case"2":r=2;break;case"3":r=3;break;case"4":r=4;break;case"5":r=5;break;case"6":r=6;break;case"7":r=7;break;case"8":r=8;break;case"9":r=9;break;default:if(n===e)throw new Kg(n,`Expected a digit [0,1,2,3,4,5,6,7,8,9] but got '${i}' instead`,t);break t}n++,s=10*s+r}return new Xg(s,e,n,"uint",ey.Number)}function sy(t,e,i){let n,s=e;for(;s<i&&(n=t.charAt(s)," "===n||"\n"===n||"\t"===n);)s++;return s}function ry(t,e,i){const n=t.charAt(e);switch(n){case"t":case"f":return function(t,e,i){const n=t.charAt(e);let s,r=e;if("t"===n&&i-e>=4){if("rue"!==t.substring(e+1,e+4))throw new Kg(e,`expected 'true', instead got '${t.substring(e,e+4)}'`,t);s=!0,r=e+4}else{if(!("f"===n&&i-e>=5))throw new Kg(e,`expected 't' or 'f', instead got '${n}'`,t);if("alse"!==t.substring(e+1,e+5))throw new Kg(e,`expected 'false', instead got '${t.substring(e,e+5)}'`,t);s=!1,r=e+5}return new Xg(s,e,r,iy.LiteralBoolean,ey.Boolean)}(t,e,i);case'"':case"'":return function(t,e,i){let n=e;const s=function(t,e){const i=t.charAt(e);if('"'!==i&&"'"!==i)throw new Kg(e,'Expected ", found '+i+" instead",t);return i}(t,n);let r;n++;let a="";const o=i-1;for(;n<o;n++)if(r=t.charAt(n),"\\"===r)switch(n++,r=t.charAt(n),r){case"n":a+="\n";break;case"t":a+="\t";break;case"r":a+="\r";break;case"b":a+="\b";break;case"f":a+="\f";break;case"v":a+="\v";break;case"0":a+="\0";break;default:a+=r}else{if(r===s)break;a+=r}if(r=t.charAt(n),r!==s)throw new Kg(e,"Expected string terminator : "+s+", but found '"+r+"' instead",t);return n++,new Xg(a,e,n,iy.LiteralString,ey.String)}(t,e,i);case"-":case"+":case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":return function(t,e,i){let n=e;const s=function(t){let e=1;const s=t.charAt(n);if("-"===s)e=-1;else{if("+"!==s)return 1;e=1}return n=sy(t,n+1,i),e}(t);let r;if("0"!==t.charAt(n)||"x"!==t.charAt(n+1)&&"X"!==t.charAt(n+1)){const e=ny(t,n,i);if(n=e.end,r=e.value,n<i&&"."===t.charAt(n)){n++;const e=ny(t,n,i),s=e.end-e.start;r+=e.value/Math.pow(10,s),n=e.end}}else{const e=function(t,e,i){const n=t.charAt(e),s=t.charAt(e+1);if("0"!==n||"x"!==s&&"X"!==s)throw new Kg(e,"Expected hex prefix 0x",t);let r=e+2,a=0;t:for(;r<i;){const i=t.charAt(r);let n;switch(i){case"0":n=0;break;case"1":n=1;break;case"2":n=2;break;case"3":n=3;break;case"4":n=4;break;case"5":n=5;break;case"6":n=6;break;case"7":n=7;break;case"8":n=8;break;case"9":n=9;break;case"a":case"A":n=10;break;case"b":case"B":n=11;break;case"c":case"C":n=12;break;case"d":case"D":n=13;break;case"e":case"E":n=14;break;case"f":case"F":n=15;break;default:if(r===e)throw new Kg(r,`Expected a digit [0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F] but got '${i}' instead`,t);break t}r++,a=16*a+n}return new Xg(a,e,r,"uint",ey.Number)}(t,n,i);n=e.end,r=e.value}return r*=s,new Xg(r,e,n,iy.LiteralNumber,ey.Number)}(t,e,i);case"[":return function(t,e,i){let n=e;const s=t.charAt(n);if("["!==s)throw new Kg(e,`expected array start: '[', got '${s}' instead`,t);n++;const r=[];for(;n<i;){n=sy(t,n,i);const e=ry(t,n,i);if(n=e.end,r.push(e),n=sy(t,n,i),!(n<i))throw new Kg(n,"Unterminated array literal",t);{const e=t.charAt(n);if(","!==e){if("]"===e){n++;break}throw new Kg(n,`Unexpected input '${e}', expected either separator ',' or end of sequence ']'`,t)}n++}}return new Xg(r,e,n,"array",ey.Array)}(t,e,i);default:throw new Kg(e,"Expected literal start, but found '"+n+"'",t)}}function ay(t,e,i){let n,s,r;for(s=e;;){if(s>=i)throw new Kg(s,"Input underflow while reading reference key",t);if(n=t.charAt(s),s++,"="===n){r=t.substring(e,s-1).trim();break}}const a=s;if(s>=i)throw new Kg(s,`Input underflow while reading reference value, value so far='${t.substring(a,i)}'`,t);const o=ry(t,s,i);s=o.end;const l=new ty(r,o.value);return new Xg(l,e,s,"reference-value",Zg.ReferenceValue)}class oy{constructor(t,e){this.type=t,this.values=e}}function ly(t,e,i){let n,s=e;const r=t.charAt(e);if("["!==r)throw new Kg(e,`expected reference start: '[', got '${r}' instead`,t);s++;const a=s;let o;for(;;){if(s>=i)throw new Kg(e,"input underflow, expected reference separator ':' is missing",t);if(":"===t.charAt(s)){o=t.substring(a,s),s++;break}s++}s=sy(t,s,i),n=t.charAt(s);let l={};if("]"!==n){for(;;){s=sy(t,s,i);const e=ay(t,s,i);s=e.end,s=sy(t,s,i);const r=e.value;if(l[r.key]=r.value,n=t.charAt(s),","!==n)break;s++}s=sy(t,s,i),n=t.charAt(s)}if("]"===n){s++;const t=new oy(o,l);return new Xg(t,e,s,"reference",Zg.Reference)}throw new Kg(s,"input underflow, expected reference end ']' is missing",t)}function hy(t,e,i){let n=e;for(;n<i&&"["!==t.charAt(n);)n++;const s=t.substring(e,n);return new Xg(s,e,n,"text",Zg.Text)}function cy(t){let e=0,i=t.length;const n=[];for(;e<i;){let s;if("["===t.charAt(e)){const n=t.charAt(e+1);s="$"===n||"/"===n?Qg(t,e,i):ly(t,e,i)}else s=hy(t,e,i);if(void 0===s)break;n.push(s),e=s.end}return n}const uy=/\$\{([a-zA-Z0-9_]+)\}/gi,dy=function(t,e){const i=t.length,n=e.length;if(0===i&&0===n)return 1;const s=function(t,e,i,n){const s=e_.fixedSize(i),r=e_.fixedSize(n),a=function(t,e,i,n){const s=t.length,r=e.length,a=bu(0,Math.floor(.5*bu(s,r))-1);let o=0;for(let l=0;l<s;l++){const s=bu(0,l-a),h=Su(l+a+1,r);for(let r=s;r<h;r++)if(!n.get(r)&&t.charAt(l)===e.charAt(r)){i.set(l,!0),n.set(r,!0),++o;break}}return o}(t,e,s,r);if(a<=0)return 0;const o=function(t,e,i,n){let s=0;const r=t.length,a=e.length;for(let o=0,l=0;o<r;o++)if(!1!==i.get(o)){for(;l<a&&!1===n.get(l);)l++;t.charAt(o)!==e.charAt(l)&&s++,l++}return Math.floor(.5*s)}(t,e,s,r);return(a/i+a/n+(a-o)/a)/3}(t,e,i,n);if(0===s)return 0;const r=function(t,e,i){let n=0;for(;n<i;n++)if(t.charAt(n)!==e.charAt(n))return n;return++n}(t,e,zd(i,n,4));return s+.1*r*(1-s)};class py{reading_speed=10;fallback_languages=[];locale="";fromJSON({reading_speed:t=10,fallback_languages:e=[]}){this.reading_speed=t,this.fallback_languages=e}static fromJSON(t){const e=new py;return e.fromJSON(t),e}}const fy=Object.freeze({}),my=Object.freeze(new py);class _y{constructor(){this.assetManager=null,this.json={},this.language_metadata=my,this.locale=new ad(""),this.debug=!0,this.__failure_cache=new Zp({maxWeight:1024,keyHashFunction:t=>F_(t,rd)})}get reading_speed(){return this.language_metadata.reading_speed}estimateReadingTime(t){return t.length/this.reading_speed}setAssetManager(t){this.assetManager=t}validate(t){let e=!0;for(let i in this.json){const n=this.json[i],s=n.replace(uy,(function(t,e){return"0"}));try{cy(s)}catch(s){e=!1,t(i,s,n)}}return e}loadLocale(t,e="data/database/text"){const i=this.assetManager;if(null===i)throw new Error("AssetManager is not set");let n=e.trim();for(;n.endsWith("/")||n.endsWith("\\");)n.slice(0,n.length-1);const s=i.promise(`${n}/${t}.json`,"json").then((e=>{const i=e.create();this.json=i,this.locale.set(t)}),(t=>{this.json={}})),r=i.promise(`${n}/languages.json`,"json").then((e=>{const i=e.create();this.language_metadata=py.fromJSON(i[t])}),(t=>{this.language_metadata=my}));return Promise.all([s,r])}formatIntegerByThousands(t){return new Intl.NumberFormat(this.locale.getValue(),{useGrouping:!0}).format(t)}__debugMissingKey(t,e){const i=this.locale.getValue(),n=JSON.stringify(e);this.__failure_cache.getOrCompute([i,t,n],(()=>{const e=Object.keys(this.json).map((function(e){return{key:e,distance:dy(e,t)}}));e.sort((function(t,e){return t.distance-e.distance}));const i=e.slice(0,3).map((t=>t.key));return`No localization value for id='${t}', seed=${n}, approximate matches: ${i.join(", ")}`}))}getString(t,e=fy){const i=this.json[t];return void 0===i?(this.debug&&this.__debugMissingKey(t,e),`@${t}`):function(t,e){return t.replace(uy,(function(t,i){return e[i]}))}(i,e)}hasString(t){return void 0!==this.json[t]}}class gy{#z=new Map;#I=new Map;proxy=new Proxy(this,{get(t,e,i){const n=t.get(e);if(void 0===n)throw new Error(`Module '${e}' not found in the registry`);return n}});traverse(t){this.#z.forEach(((e,i)=>t(i,e)))}get(t){return this.#z.get(t)}has(t){return this.#z.has(t)}add(t,e){if(this.has(t))return this.get(t),!1;this.#z.set(t,e);let i=this.#I.get(e);return void 0===i&&(i=[],this.#I.set(e,i)),i.push(t),!0}findNamesByModule(t){const e=this.#I.get(t);if(void 0===e)throw new Error("Module not found");return e}initialize(){}}function yy(t){return t.children instanceof Array}class vy{#L=0;#N=-1;constructor(t=1,e=15){this.quietTime=t,this.workTime=e,this.queueUnresolved=[],this.queueReady=[],this.on={task_started:new _,task_completed:new _,completed:new _},this.busy=!1,this.policy=xy.ROUND_ROBIN}runGroup(t){const e=t.state.getValue();if(e!==Tf.INITIAL)throw new xu(`Expected task state INITIAL, instead got ${n_(Tf,e)}`);const i=this,n=t.children,s=n.length;let r=s,a=!1;function o(){a||(a=!0,t.state.set(Tf.SUCCEEDED),t.on.completed.send0(),i.prod())}function l(){r--,r<=0&&o()}function h(e){!function(e){a||(a=!0,t.state.set(Tf.FAILED),t.on.failed.send1(e),i.prod())}(e)}if(s>0){t.state.set(Tf.RUNNING);let e=0;for(;e<s;e++){const t=n[e];t.on.completed.add(l),t.on.failed.add(h),yy(t)?this.runGroup(t):this.run(t)}}else o()}removeGroup(t){const e=t.children,i=e.length;for(let t=0;t<i;t++){const i=e[t];yy(i)?this.removeGroup(i):this.removeTask(i)}}removeTask(t){const e=this.queueReady.indexOf(t);if(-1!==e)return this.queueReady.splice(e,1),!0;const i=this.queueUnresolved.indexOf(t);return-1!==i&&(this.queueUnresolved.splice(i,1),!0)}run(t){this.queueUnresolved.push(t),this.prod()}runMany(t){Array.prototype.push.apply(this.queueUnresolved,t),this.prod()}startTask(t){const e=performance.now();try{t.initialize(t,this)}catch(e){return t.state.set(Tf.FAILED),t.on.failed.dispatch(e),!1}finally{const i=performance.now()-e;t.__executedCpuTime+=i}return t.state.set(Tf.RUNNING),t.on.started.send1(this),this.queueReady.push(t),this.on.task_started.send1(t),!0}resolveTasks(){const t=this.queueUnresolved;let e=0,i=t.length;for(;e<i;e++){const n=t[e];switch(by(n)){case wy.READY:t.splice(e,1),n.state.set(Tf.READY),this.startTask(n),e=0,i=t.length;break;case wy.FAILED:t.splice(e,1),i--,e--}}}contains(t){return-1!==this.queueUnresolved.indexOf(t)||-1!==this.queueReady.indexOf(t)}#P(){const t=this.queueReady;switch(this.policy){case vy.POLICY.ROUND_ROBIN:return t[this.#L%t.length];default:case vy.POLICY.SEQUENTIAL:return t[0]}}#D(t){const e=this.queueReady,i=e.indexOf(t);-1!==i&&e.splice(i,1),t.state.set(Tf.SUCCEEDED),t.on.completed.send1(this),this.resolveTasks(),this.on.task_completed.send1(t)}#F(t,e){const i=this.queueReady,n=i.indexOf(t);-1!==n&&i.splice(n,1),t.state.set(Tf.FAILED),t.on.failed.send1(e),t.on.failed.hasHandlers(),this.resolveTasks(),this.on.task_completed.send1(t)}#O(t,e){let i=0;const n=t.cycle,s=performance.now(),r=s+e;let a,o=s+1e-6;for(;o<r;)if(i++,a=n(),o=performance.now(),2!==a){if(3===a)break;if(0===a)break;if(1===a)break;throw new Error(`Task '${t.name}' produced unknown signal: `+a)}const l=o-s;return t.__executedCpuTime+=l,t.__executedCycleCount+=i,0===a?this.#D(t):1===a&&this.#F(t,"Task signalled failure"),l}#R=this.#k.bind(this);#k(){let t=this.workTime,e=0;const i=this.queueReady;for(;i.length>0;){const i=this.#P();if(void 0===i)break;try{e=this.#O(i,t)}catch(t){const e=new Error("Task threw an exception");e.cause=t,this.#F(i,e)}if(this.#L++,t-=Math.max(e,1),t<=0)break}0===this.queueReady.length?(this.busy=!1,this.on.completed.send0()):this.#N=setTimeout(this.#R,this.quietTime)}prod(){this.resolveTasks(),!this.busy&&this.queueReady.length>0&&(this.busy=!0,this.#k())}join(t){0===this.queueReady.length&&0===this.queueUnresolved.length?t():this.on.completed.addOne(t)}}const xy={ROUND_ROBIN:0,SEQUENTIAL:1,TIME_SLICE:2};vy.POLICY=xy;const wy={READY:0,FAILED:1,UNRESOLVED:2};function by(t){const e=t.dependencies;let i=0;const n=e.length;for(;i<n;i++)switch(e[i].state.getValue()){case Tf.INITIAL:case Tf.RUNNING:case Tf.READY:return wy.UNRESOLVED;case Tf.SUCCEEDED:break;default:return wy.FAILED}return wy.READY}const Sy=function(t,e){let i;return i="string"==typeof t?void 0===e?document.createElement(t):document.createElementNS(e,t):"object"==typeof t?t:document.createElement("div"),this.el=i,this};function My(t){let e;return e=t instanceof Sy?t.el:t,e}function Ty(t,e){return new Sy(t,e)}Sy.prototype.createChild=function(t){const e=new Sy(t);return this.append(e),e},Sy.prototype.append=function(t){const e=My(t);return this.el.appendChild(e),this},Sy.prototype.remove=function(t){const e=My(t);return this.el.removeChild(e),this},Sy.prototype.text=function(t){return this.el.innerText=t,this},Sy.prototype.select=function(t){const e=this.el.querySelector(t);return null===e?null:Ty(e)},Sy.prototype.addClass=function(t){return this.el.classList.add(t),this},Sy.prototype.removeClass=function(t){return this.el.classList.remove(t),this},Sy.prototype.setClass=function(t,e){return this.el.classList.toggle(t,e),this},Sy.prototype.css=function(t){for(let e in t)t.hasOwnProperty(e)&&(this.el.style[e]=t[e]);return this},Sy.prototype.attr=function(t){const e=this.el;for(let i in t)t.hasOwnProperty(i)&&e.setAttribute(i,t[i]);return this},Sy.prototype.clone=function(){return new Sy(this.el.cloneNode(!0))},Sy.prototype.clear=function(){const t=this.el;for(;t.children.length>0;)t.removeChild(t.children[0]);return this},Sy.prototype.on=function(t,e){return this.el.addEventListener(t,e),this},Sy.prototype.off=function(t,e){return this.el.removeEventListener(t,e),this};class Ay{constructor(t,e){this.view=t,this.name=e}}class Cy extends Hg{constructor(){super();const t=Ty("div").css({position:"absolute",left:0,top:0,pointerEvents:"none"}).el;t.setAttribute("tabindex",0),this.el=t,this.addClass("view-stack"),this.__stack=[],this.__activeFrame=null,this.bindSignal(this.size.onChanged,this.updateActiveFrameSize.bind(this))}updateActiveFrameSize(){const t=this.__activeFrame;null!==t&&t.view.size.copy(this.size)}link(){super.link(),this.updateActiveFrameSize()}setActiveFrame(t){const e=this.__stack;if(t>=e.length)throw new Error("Index is too high, stack overflow");if(null!==this.__activeFrame&&this.removeChild(this.__activeFrame.view),t>=0){const i=e[t];this.__activeFrame=i;const n=i.view;this.addChild(n),n.size.copy(this.size),n.position.set(0,0)}else this.__activeFrame=null}push(t,e=""){const i=this.__stack,n=new Ay(t,e);i.push(n);const s=i.length-1;this.setActiveFrame(s)}unwind(t){const e=this.__stack,i=e.length,n=e.splice(t,i-t);return this.setActiveFrame(t-1),n}pop(){return this.unwind(this.__stack.length-1)[0]}}class Ey{data=[];length=0;constructor(t){this.scoreFunction=t}bubbleUp(t){const e=this.data;let i,n=t,s=e[n],r=this.scoreFunction(s);for(;n>0;){i=n-1>>1;const t=e[i];if(!(r<this.scoreFunction(t)))break;e[i]=s,e[n]=t,n=i}}bubbleDown(t){const e=this.data,i=this.length;let n=t,s=n;for(;;){const t=1+(n<<1);if(t>=i)break;const r=t+1;let a=e[s];const o=this.scoreFunction(a),l=e[t],h=this.scoreFunction(l);if(r>=i){if(h>=o)break;s=t,a=l}else{const i=e[r],n=this.scoreFunction(i);if(h<=n){if(h>=o)break;s=t,a=l}else{if(n>=o)break;s=r,a=i}}e[s]=e[n],e[n]=a,n=s}}pop(){this.length--;const t=this.length,e=this.data.pop();if(0===t)return e;const i=this.data[0];return this.data[0]=e,this.bubbleDown(0),i}peek(){return this.data[0]}delete(t){const e=this.data.indexOf(t);return-1!==e&&(this.deleteByIndex(e),!0)}deleteByIndex(t){this.data.splice(t,1),this.length--}clear(){this.data=[],this.length=0}contains(t){return-1!==this.data.indexOf(t)}isEmpty(){return 0===this.length}size(){return this.length}updateElementScore(t){const e=this.data.indexOf(t);return-1!==e&&(this.bubbleDown(e),!0)}push(t){this.data.push(t);const e=this.length;this.length=e+1,this.bubbleUp(e)}}Ey.prototype.isBinaryHeap=!0;class zy{on={set:new _,deleted:new _};constructor(t=new Map){this.data=t}get(t){return this.data.get(t)}set(t,e){return this.data.set(t,e),this.on.set.send2(t,e),this}delete(t){const e=this.data.delete(t);return e&&this.on.deleted.send1(t),e}forEach(t,e){this.data.forEach(t,e)}get size(){return this.data.size}}const Iy=new Array(0);class Ly{#B=Iy;#U=0;#V=0;#W=1;constructor(t=16){const e=jd(bu(1,t));this.#B=new Array(e)}#G(t){const e=this.#U,i=this.#V;this.#W=e===i?t?0:1:2}#H(t){const e=t+1;return e>=this.#B.length?0:e}#j(t){const e=t-1;return e<0?this.#B.length-1:e}#q(){if(0!==this.#W)return;const t=this.#B.length;if(b===t)throw new Error("Maximum array size exceeded");let e=2*t;e>b&&(e=b);const i=new Array(e),n=this.#U;ed(this.#B,n,i,0,t-n),ed(this.#B,0,i,t-n,n),this.#U=0,this.#V=t,this.#W=2,this.#B=i}isEmpty(){return 1===this.#W}clear(){if(1!==this.#W){let t=this.#U;const e=this.#V;do{this.#B[t]=void 0,t=this.#H(t)}while(t!==e);this.#W=1}this.#U=0,this.#V=0}size(){const t=this.#B;if(0===this.#W)return t.length;const e=this.#U,i=this.#V;return e<=i?i-e:i+t.length-e}#J(t){let e=t;const i=this.#V;for(;e!==i;){const t=this.#H(e);this.#B[e]=this.#B[t],e=t}this.#V=this.#j(i),this.#B[e]=void 0,this.#G(!1)}remove(t){const e=this.#$(t);return-1!==e&&(this.#J(e),!0)}#$(t){const e=this.size(),i=this.#B,n=i.length,s=this.#U;for(let r=0;r<e;r++)if(i[(s+r)%n]===t)return r;return-1}has(t){return-1!==this.#$(t)}addFirst(t){this.#q(),this.#U=this.#j(this.#U),this.#B[this.#U]=t,this.#G(!0)}removeFirst(){const t=this.#B[this.#U];return this.#B[this.#U]=void 0,this.#U=this.#H(this.#U),this.#G(!1),t}getFirst(){return this.#B[this.#U]}addLast(t){this.#q(),this.#B[this.#V]=t,this.#V=this.#H(this.#V),this.#G(!0)}removeLast(){const t=this.#j(this.#V),e=this.#B[t];return this.#B[t]=void 0,this.#V=t,this.#G(!1),e}getLast(){const t=this.#j(this.#V);return this.#B[t]}getElementByIndex(t){if(t>=this.size())return;const e=this.#B;return e[(this.#U+t)%e.length]}toArray(t=[],e=0){const i=this.size();for(let e=0;e<i;e++)t[e]=this.getElementByIndex(e);return t}*[Symbol.iterator](){const t=this.size();for(let e=0;e<t;e++)yield this.getElementByIndex(e)}}Ly.prototype.peek=Ly.prototype.getFirst,Ly.prototype.push=Ly.prototype.addFirst,Ly.prototype.pop=Ly.prototype.removeFirst,Ly.prototype.add=Ly.prototype.addLast;class Ny{constructor({keyHashFunction:t=Vp,keyEqualityFunction:e=Up,capacity:i}={}){this.__map=new qp({keyHashFunction:t,keyEqualityFunction:e,capacity:i})}get size(){return this.__map.size}add(t){return this.__map.set(t,t),this}clear(){this.__map.clear()}delete(t){return this.__map.delete(t)}has(t){return this.__map.has(t)}*[Symbol.iterator](){for(const t of this.__map.keys())yield t}keys(){return this.__map.keys()}values(){return this.__map.keys()}entries(){throw new Error("Not implemented")}get(t){return this.__map.get(t)}forEach(t,e){for(const i of this.values())t.call(e,i,i,this)}ensure(t){const e=this.get(t);return void 0!==e?e:(this.add(t),t)}}class Py{constructor(t,e){this.path=t,this.type=e}equals(t){return this.path===t.path&&this.type===t.type}hash(){return nd(rd(this.path),rd(this.type))}toString(){return`{ type: '${this.type}', path: '${this.path}' }`}}Py.prototype.isAssetDescription=!0;class Dy{constructor(t,e,i){this.successCallback=t,this.failureCallback=e,this.pogressCallback=i,this.priority=1,this.scope=null,this.flags=0}get scoped_priority(){const t=this.priority,e=this.scope;return null===e?t:t*e.final_priority}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}}let Fy=0;class Oy{id=Fy++;priority=1;sources=[];get final_priority(){const t=this.sources,e=t.length;if(0===e)return this.priority;let i=t[0].final_priority;for(let n=0;n<e;n++){const e=t[n].final_priority;e>i&&(i=e)}return this.priority*i}static from(t){const e=new Oy;return e.sources=t,e}toString(){const t=this.sources.length>0?`[ ${this.sources.join(", ")} ]`:"none";return`Scope{ id:${this.id}, sources:${t} }`}}Oy.GLOBAL=Object.freeze(new Oy);class Ry{constructor(t,e,i){this.__value=void 0!==t?t:0,this.__limitUpper=void 0!==e?e:0,this.__limitLower=void 0!==i?i:0,this.onChanged=new _,this.onOverflow=new _,this.onFilled=new _,this.on={changed:this.onChanged,overflow:this.onOverflow}}setUpperLimit(t){const e=this.__limitUpper;t!==e&&(this.__limitUpper=t,this.onChanged.send4(this.__value,this.__limitUpper,this.__value,e))}getUpperLimit(){return this.__limitUpper}getLowerLimit(){return this.__limitLower}setLowerLimit(t){t!==this.__limitLower&&(this.__limitLower=t,this.onChanged.dispatch())}setValue(t){const e=this.__value;if(e===t)return;const i=t-this.__limitUpper;this.__value=t,this.onChanged.send4(this.__value,this.__limitUpper,e,this.__limitUpper),i>0&&this.onOverflow.send1(i),i>=0&&this.onFilled.send0()}getValue(){return this.__value}getFraction(){return Vd(this.__limitLower,this.__limitUpper,this.__value)}setValueToLimit(){this.setValue(this.__limitUpper)}isValueAtLimit(){return this.__value===this.__limitUpper}addValue(t){this.setValue(this.__value+t)}copy(t){return this.setUpperLimit(t.getUpperLimit()),this.setValue(t.getValue()),this}equals(t){return this.__value===t.__value&&this.__limitLower===t.__limitLower&&this.__limitUpper===t.__limitUpper}hash(){const t=S(this.__value),e=(t<<5)-t+S(this.__limitLower);return(e<<5)-e+S(this.__limitUpper)}toJSON(){return{value:this.__value,limit:this.__limitUpper}}fromJSON(t){this.setUpperLimit(t.limit),this.setValue(t.value)}toBinaryBuffer(t){t.writeFloat64(this.__value),t.writeFloat64(this.__limitUpper)}fromBinaryBuffer(t){const e=t.readFloat64(),i=t.readFloat64();this.setUpperLimit(i),this.setValue(e)}}class ky{constructor(t){this.description=t,this.requests=[],this.progress=new Ry(0,0),this.state=0}get priority(){const t=this.requests,e=t.length;if(0===e)return 0;let i=t[0].priority;for(let n=1;n<e;n++){const e=t[n];e.scoped_priority>i&&(i=e)}return i}}let By=class{constructor(t,e){this.asset=t,this.request=e}};function Uy(t){return-t.priority}class Vy{assets=new qp({capacity:1024});request_map=new zy(new qp);#Y=new Ey(Uy);#X=new Set;load_concurrency=Infinity;#Z={};#K={};#Q=new Map;rootPath="";crossOriginConfig=new om;#tt=new Ny;#et=new Ly;#it=new Cf({name:"Asset Manager Response processor",cycleFunction:()=>{if(this.#et.isEmpty())return 3;const t=this.#et.removeFirst();return this.#nt(t),2}});#st=!1;#rt=null;#at=null;constructor({context:t,executor:e=new vy}={}){this.#rt=t,this.#at=e}startup(){this.#st||(this.#at.run(this.#it),this.#st=!0)}async shutdown(t=!1){this.#st&&(t||await Promise.allSettled([Cf.promise(this.#it)]),this.#at.removeTask(this.#it),this.#st=!1)}remove(t,e){const i=new Py(t,e);return this.assets.delete(i)}clear(){this.assets.clear()}dumpLoadedAssetList(){return JSON.stringify(function(t){const e={"texture-deferred":3,[zu]:3,"image/svg":3,[Lu]:3,[Iu]:1,arraybuffer:1,"three.js":2,"model/gltf+json":2,"model/gltf":2},i=[];return t.assets.forEach((function(t,n){const s=n.type,r=function(t){const i=e[t];return void 0===i?3:i}(s),a=n.path;i.push({uri:a,type:s,level:r})})),i}(this),3,3)}promise(t,e,{scope:i,skip_queue:n=!1}={}){return new Promise(((n,s)=>{this.get({path:t,type:e,callback:n,failure:s,scope:i})}))}get({path:t,type:e,callback:i=Mf,failure:n=console.error,progress:s=Mf,skip_queue:r=!1,scope:a=null}){if("string"!=typeof t)throw new TypeError(`Path must be string. instead was '${typeof t}'`);if("string"!=typeof e)throw new TypeError(`type must be a string, instead was '${typeof e}'`);const o=new Py(t,e),l=this.assets.get(o);if(void 0!==l)i(l);else{const t=new Dy(i,n,s);t.scope=a,t.writeFlag(1,r),this.submitRequest(o,t)}}insert(t,e,i){const n=new Py(t,e);this.assets.get(n),this.assets.set(n,i)}#nt(t){try{t.request.successCallback(t.asset)}catch(t){}}#ot(t,e){this.#et.add(new By(t,e))}#lt(t){this.#X.size<this.load_concurrency?this.#ht(t):this.#Y.push(t)}#ct(t){this.#X.has(t)||(this.#Y.delete(t),this.#ht(t))}#ut(t){const e=this.#X;this.request_map.delete(t.description),e.delete(t);const i=this.#Y;for(;!i.isEmpty()&&e.size<this.load_concurrency;){const t=i.pop();this.#ht(t)}}#ht(t){const e=t.requests,i=t.description,n=i.type,s=i.path,r=this.#Z[n];if(void 0===r){for(let t=0;t<e.length;t++){const i=e[t];"function"==typeof i.failureCallback&&i.failureCallback(`no loader exists for asset type '${n}', valid types are: ${Object.keys(this.#Z).join(", ")}`)}return void this.#ut(t)}this.#X.add(t);const a=this.assets,o=this.#tt,l=async s=>{if(3===t.state)return;t.state,t.state=3;let r=s;const o=this.#K[n];if(void 0!==o){const t=o.length;for(let e=0;e<t;e++){const t=o[e],n=await t.transform(r,i);"object"!=typeof n||(r=n)}}r.description=i,a.set(i,r),this.#ut(t);for(let t=0;t<e.length;t++){const i=e[t];this.#ot(r,i)}},h=n=>{if(4!==t.state){t.state,t.state=4;for(let t=0;t<e.length;t++){const i=e[t];try{i.failureCallback(n)}catch(t){}}this.#ut(t),o.add(i)}},c=[];for(let t=0;t<e.length;t++){const i=e[t].scope;null!==i&&Sf(c,i)}let u;u=c.length>0?Oy.from(c):Oy.GLOBAL;const d=this.rootPath+s;try{const i=r.load(u,d,l,h,(function(i,n){e.forEach((function(t){if("function"==typeof t.pogressCallback)try{t.pogressCallback(i,n)}catch(t){}})),t.progress.setValue(i),t.progress.setUpperLimit(n)}));i instanceof Promise&&i.catch(h)}catch(t){h(t)}}submitRequest(t,e){const i=this.request_map;let n=!1,s=i.get(t);void 0===s&&(s=new ky(t),i.set(t,s),n=!0),s.requests.push(e),n?this.#lt(s):this.#Y.updateElementScore(s),e.getFlag(1)&&this.#ct(s)}hasLoaderForType(t){return void 0!==this.getLoaderByType(t)}getLoaderByType(t){return this.#Z[t]}#dt(t){return Array.from(this.assets.keys()).filter((e=>e.type===t))}registerTransformer(t,e){let i=this.#K[t];void 0===i&&(i=[],this.#K[t]=i),i.push(e),this.#dt(t).length}unregisterTransformer(t,e){const i=this.#K[t];return void 0!==i&&!!Zm(i,e)&&(this.#dt(t).length,!0)}async tryRegisterLoader(t,e){return!this.hasLoaderForType(t)&&(await this.registerLoader(t,e),!0)}async registerLoader(t,e){const i=this.getLoaderByType(t);if(void 0!==i){if(i===e)return i;if(Object.getPrototypeOf(i)===Object.getPrototypeOf(e))return i;throw new Error(`Loader for type '${t}' is already registered`)}let n=e;return"function"==typeof n?(n=new hm,n.load=e):await n.link(this,this.#rt),this.#Z[t]=n,n}async unregisterLoader(t){const e=this.getLoaderByType(t);void 0!==e&&(delete this.#Z[t],await e.unlink())}tryGet(t,e){const i=new Py(t,e),n=this.assets.get(i);return void 0!==n?n:null}isFailed(t,e){const i=new Py(t,e);return this.#tt.has(i)}promiseByAlias(t){const e=this.#Q.get(t);return void 0===e?new Promise.reject(`Alias '${t}' not found`):this.promise(e.path,e.path)}resolveAlias(t){return this.#Q.get(t)}assignAlias(t,e,i){const n=new Py(e,i);this.#Q.set(t,n)}}Vy.prototype.isAssetManager=!0;const Wy={CRITICAL:0,HIGH:1,NORMAL:2,OPTIONAL:3};class Gy{constructor(){this.uri=null,this.type=null,this.level=Wy.OPTIONAL,this.priotity=0}fromJSON({uri:t,type:e,level:i=Wy.OPTIONAL,priority:n=0}){this.uri=t,this.type=e,this.level=i,this.priotity=n}static fromJSON(t){const e=new Gy;return e.fromJSON(t),e}}const Hy=function(){this.totalAssetCount=0;const t=this.assets=[];for(let e in Wy)Wy.hasOwnProperty(e)&&(t[Wy[e]]=[]);this.on={added:new _,progress:new _,levelFinished:new _,error:new _,loadStart:new _,completed:new _}};Hy.prototype.add=function(t,e,i,n){void 0===i&&(i=Wy.OPTIONAL);const s=this.assets,r=Gy.fromJSON({uri:t,type:e,priority:n});return s.hasOwnProperty(i)||(i=Wy.OPTIONAL),s[i].push(r),this.totalAssetCount++,this.on.added.send2(r,i),this},Hy.prototype.addAll=function(t){const e=this;t.forEach((function(t){e.add(t.uri,t.type,t.level)}))},Hy.prototype.load=function(t){const e=this.on,i=this.assets,n=i.map((function(t,e){return{level:e,count:t.length}}));e.loadStart.send1(n);const s=this.totalAssetCount;let r=0;const a=[];for(let t in i)i.hasOwnProperty(t)&&a.push(t);let o=0;return function n(){if(o<a.length){const a=o;o++,e.levelFinished.addOne(n),function(n){const a=i[n],o=a.length;if(0===o)return void e.levelFinished.dispatch(n);let l=0;function h(t){l++,r++,e.progress.dispatch({level:{id:n,value:l,max:o},global:{value:r,max:s}}),l>=o&&e.levelFinished.dispatch(n)}function c(t){e.error.dispatch(t)}a.sort(((t,e)=>e.priotity-t.priority)),a.forEach((function(e){t.get({path:e.uri,type:e.type,callback:h,failure:c})}))}(a)}else e.completed.send0()}(),this};class jy{constructor(t){this.size=t,this.head=0,this.tail=0,this.count=0,this.data=new Array(t)}resize(t){if(t===this.size)return;const e=new Array(t);this.data=e,this.size=t,this.count=Su(t,this.count),this.clear()}getHead(){return this.data[this.head-1]}getFromHead(t){let e=this.head-(t+1);for(;e<0;)e+=this.size;return this.data[e]}clear(){this.head=0,this.tail=0,this.count=0}push(t){const e=this.head;this.data[e]=t;const i=this.size,n=(e+1)%i;this.head=n,this.count===i?this.tail=(this.tail+1)%i:this.count++}shift(){if(0===this.count)return;const t=this.data[this.tail];return this.count--,this.tail=(this.tail+1)%this.size,t}removeElementByIndex(t){if(t>=this.count)return;const e=this.size,i=this.tail,n=this.count;for(let s=t;s<n;s++){const t=i+s,n=t%e,r=(t+1)%e;this.data[n]=this.data[r]}this.head--,this.count--}removeIf(t,e){const i=this.count,n=this.size,s=this.tail,r=this.data;for(let a=0;a<i;a++){const i=(s+a)%n,o=r[i];if(t.call(e,o))return this.removeElementByIndex(i),o}}forEach(t,e){const i=this.count,n=this.size,s=this.tail,r=this.data;for(let a=0;a<i;a++){const i=r[(s+a)%n];t.call(e,i)}}contains(t){return-1!==this.data.indexOf(t)}}function qy(t,e){return t-e}class Jy{record(t){throw new Error("Not implemented")}getLastRecord(){throw new Error("Not implemented")}computeStats(t){throw new Error("Not implemented")}clear(){throw new Error("Not implemented")}}class $y extends Jy{constructor(t=100){super(),this.__data=new jy(t)}resize(t){this.__data.resize(t)}getLastRecord(){return this.__data.getHead()}record(t){this.__data.push(t)}computeStats(t){const e=this.__data,i=e.data,n=e.count;return 0===n?(t.mean=0,t.median=0,t.min=0,t.max=0,!1):(t.mean=function(t,e=0,i=t.length){let n=0;const s=i-e;for(let e=0;e<i;e++)n+=t[e];return n/s}(i,0,n),t.median=function(t,e,i){const n=t.slice();return n.sort(qy),n[0+(i-0>>1)]}(i,0,n-1),t.max=function(t,e=0,i=t.length){let n=Number.NEGATIVE_INFINITY;for(let s=e;s<i;s++){const e=t[s];e>n&&(n=e)}return n}(i,0,n),t.min=function(t,e=0,i=t.length){let n=Number.POSITIVE_INFINITY;for(let s=e;s<i;s++){const e=t[s];e<n&&(n=e)}return n}(i,0,n),!0)}clear(){this.__data.clear()}}class Yy{constructor(){this.data=new Map}clear(){this.data.forEach(((t,e)=>{t.clear()}))}list(){return Array.from(this.data.keys())}create({name:t,buffer_size:e=1e3}){const i=new $y(e);return this.add(t,i),i}add(t,e){this.data.set(t,e)}get(t){return this.data.get(t)}}class Xy{mean=0;median=0;max=0;min=0;toString(){return`{min:${this.min}, max:${this.max}, mean:${this.mean}, median:${this.median}`}}class Zy{constructor(t=15,e,i){this.__timeout=t,this.__handle=-1,this.__method=()=>{e.call(i)}}start(){-1!==this.__handle&&this.stop(),this.__handle=setInterval(this.__method,1e3*this.__timeout)}stop(){-1!==this.__handle&&(clearInterval(this.__handle),this.__handle=-1)}}class Ky{upgraders=new Map;serializers=new Map;registerAdapters(t){t.forEach((t=>{this.registerAdapter(t)}))}registerAdapter(t,e){let i=e;if(void 0===i){const e=t.getClass();if("string"!=typeof e.typeName)throw new Error("className not specified, could not infer class name from the class itself");i=e.typeName}return!this.serializers.has(i)&&(this.serializers.set(i,t),!0)}removeAdapter(t){const e=this.serializers.get(t);return void 0!==e&&this.serializers.delete(t),e}getAdapter(t){return this.serializers.get(t)}registerUpgrader(t,e){if(e.getStartVersion()===e.getTargetVersion())throw new Error(`Upgrader for '${t}' start(=${e.getStartVersion()}) and target(=${e.getTargetVersion()}) versions are the same, must be different`);e.getStartVersion(),e.getTargetVersion();let i=this.upgraders.get(t);return void 0===i&&(i=new l_,this.upgraders.set(t,i)),!i.hasNode(e)&&(i.addNode(e),i.traverseNodes((t=>{t!==e&&(t.getStartVersion()===e.getTargetVersion()?i.createEdge(t,e):t.getTargetVersion()===e.getStartVersion()&&i.createEdge(e,t))})),!0)}getUpgradersChain(t,e,i){if(e===i)return[];const n=this.upgraders.get(t);if(void 0===n)throw new Error(`No upgraders available for class '${t}', upgrade is required from from version ${e} to ${i}`);const s=[],r=[];n.traverseNodes((t=>{t.getStartVersion()===e&&s.push(t),t.getTargetVersion()===i&&r.push(t)}));let a=null,o=Number.POSITIVE_INFINITY;for(let t=0,e=s.length;t<e;t++){const e=s[t];for(let t=0,i=r.length;t<i;t++){const i=r[t],s=n.findPath(e,i);if(null!==s){const t=s.length;o>t&&(a=s,o=t)}}}return a}}Ky.prototype.isBinarySerializationRegistry=!0;class Qy{constructor(){}record(t,e){}}class tv extends Qy{record(t,e){}}tv.INSTANCE=new tv;const ev=new class extends Qy{constructor(){super(),this.target=tv.INSTANCE}setTarget(t){this.target=t}record(t,e){this.target.record(t,e)}};class iv{constructor(){this.layerTargets=[],this.camera=new zr(-1,1,1,-1,0,1),this.scene=new cl,this.size=new Eu(0,0),this.__pixelRatio=1}remove(t){const e=this.layerTargets.indexOf(t);return-1!==e&&(this.layerTargets.splice(e,1),t.renderTarget.dispose(),!0)}createLayer(t,e=0){let i;if(t instanceof qi||t instanceof Ji)i=t;else{const e={minFilter:Kt,magFilter:Kt,format:me,depthBuffer:!1,stencilBuffer:!1,generateMipmaps:!1};for(let i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);i=new Ji(1,1,e)}const n=new Eg({renderTarget:i,blending:e});return this.addLayer(n),n}addLayer(t){return!this.layerTargets.includes(t)&&(t.setSize(this.size.x,this.size.y),this.layerTargets.push(t),!0)}hasActiveLayers(){const t=this.layerTargets,e=t.length;for(let i=0;i<e;i++)if(t[i].enabled)return!0;return!1}__prepare_scene_for_stage(t){const e=this.layerTargets,i=e.length,n=this.scene;let s=0;for(let r=0;r<i;r++){const i=e[r];i.stage===t&&(n.children[s++]=i.object,i.on.preRender.send0())}n.children.length=s}composite(t,e){if(!this.hasActiveLayers())return;this.__prepare_scene_for_stage(e);const i=this.camera,n=this.scene;t.autoClear=!1,t.render(n,i)}setPixelRatio(t){this.__pixelRatio!==t&&(this.__pixelRatio=t,this.__updateResolution())}getPixelRatio(){return this.__pixelRatio}__updateResolution(){const t=this.size.x,e=this.size.y*this.__pixelRatio,i=t*this.__pixelRatio,n=this.layerTargets;for(let t=0;t<n.length;t++)n[t].setSize(i,e)}setSize(t,e){this.size.set(t,e),this.__updateResolution(t,e)}}class nv{#pt=new _;#ft=null;#mt=!1;get bound(){return this.#mt}get onReleased(){return this.#pt}bind(t){if(t!==this.#ft){if(this.#mt)throw new Error("Reference is already bound, must release before binding to a new value");this.#ft=t,this.#mt=!0}}getValue(){return this.#ft}release(){if(!this.#mt)return;const t=this.#ft;this.#ft=null,this.#mt=!1,this.#pt.send2(this,t)}}nv.NULL=Object.freeze(new nv);class sv{constructor(t){this.__source=null,this.__material=t,this.__ref_count=0,this.onLastReleased=new _}getSource(){return this.__source}setSource(t){this.__source=t}getMaterial(){return this.__material}__release_reference(){this.__ref_count--,0===this.__ref_count&&this.onLastReleased.send1(this)}getRef(){const t=new nv;return t.bind(this.__material),t.onReleased.add(this.__release_reference,this),this.__ref_count++,t}}class rv{constructor(){this.__library=new qp({keyHashFunction:B_,keyEqualityFunction:og,capacity:1024}),this.__cache=new Zp({keyHashFunction:B_,keyEqualityFunction:og,maxWeight:100}),this.__reverse_library=new qp({keyHashFunction:B_,keyEqualityFunction:og,capacity:1024}),this.__cache.onEvicted.add(this.__dispose_material,this),this.__transform_chain=[]}__dispose_material(t,e){e.getMaterial().dispose()}__handle_last_reference_removed(t){const e=t.getMaterial(),i=t.getSource();this.__library.delete(i),this.__reverse_library.delete(e),this.__cache.put(i,t)}addCompileStep(t){this.__transform_chain.push(t)}removeCompileStep(t){const e=this.__transform_chain.indexOf(t);return-1!==e&&(this.__transform_chain.splice(e,1),!0)}__compile(t){let e=t;const i=this.__transform_chain,n=i.length;for(let t=0;t<n;t++)e=i[t].transform(e);return e}obtain(t){let e=this.__reverse_library.get(t);if(void 0!==e)return e.getRef();if(e=this.__library.get(t),void 0===e){if(e=this.__cache.get(t),null!==e)this.__cache.remove(t);else{const i=this.__compile(t);e=new sv(i),e.setSource(t)}e.onLastReleased.addOne(this.__handle_last_reference_removed,this),this.__library.set(t,e),this.__reverse_library.set(e.getMaterial(),e)}return e.getRef()}}class av{renderTarget=null;referenceCount=0;dependencies=[];size=new Eu(0,0);constructor(t){this.id=t}getRenderTarget(){return this.renderTarget}initialize(t){}finalize(t){}render(t,e,i,n){const s=t.getRenderTarget();t.setRenderTarget(this.renderTarget),t.clear(),t.render(i,e),t.setRenderTarget(s)}setSize(t,e){const i=this.size;t===i.x&&e===i.y||(this.renderTarget.setSize(t,e),i.set(t,e))}}class ov extends av{initialize(t){if(e=t.getContext(),!(void 0!==WebGL2RenderingContext&&e instanceof WebGL2RenderingContext||t.extensions.get("WEBGL_depth_texture")))throw new Error("renderer does not support required 'WEBGL_depth_texture' extension");var e;const i=new Ri;t.getSize(i);const n=new Ji(i.x,i.y,{ignoreDepth:!1});n.texture.format=fe,n.texture.minFilter=Yt,n.texture.magFilter=Yt,n.texture.generateMipmaps=!1,n.texture.encoding=vi,n.stencilBuffer=!1,n.depthBuffer=!0,n.depthTexture=new al,n.depthTexture.format=ye,n.depthTexture.type=oe,n.depthTexture.generateMipmaps=!1,n.depthTexture.internalFormat="DEPTH_COMPONENT32F",this.renderTarget=n}}const lv=[];class hv{constructor(){this.__object_map=new WeakMap}__get_object_twin(t){const e=this.__object_map.get(t);if(void 0!==e)return e;let i;const n=t.geometry;return i=t.isSkinnedMesh?new Dl(n,null):new Zs(n,null),i.matrixAutoUpdate=!1,i.matrixWorldNeedsUpdate=!1,i.frustumCulled=!1,this.__object_map.set(t,i),i}build_scene({scene:t,input:e,input_size:i,input_filter:n=T_,object_filter:s,material_extractor:r,material_extractor_context:a}){const o=t.children;o.length=0;let l=0,h=0,c=0;for(;c<i;c++){const t=e[c];n(t)&&(lv[l++]=t)}for(;l>0;){const e=lv[--l];if(s(e)&&e.isMesh){const i=e.geometry;if(null!==i){const n=this.__get_object_twin(e),s=r.call(a,e);n.geometry=i,n.material=s,e.isSkinnedMesh&&(n.bindMatrix.copy(e.bindMatrix),n.bindMatrixInverse.copy(e.bindMatrixInverse),n.skeleton=e.skeleton),n.matrix.copy(e.matrix),n.matrixWorld.copy(e.matrixWorld),n.normalMatrix.copy(e.normalMatrix),o[h++]=n,n.parent=t}}const i=e.children,n=i.length;for(c=0;c<n;c++){const t=i[c];lv[l++]=t}}o.length=h}}hv.INSTANCE=new hv;class cv extends av{constructor(t){super(t),this.dependencies.push(kg)}initialize(t){super.initialize(t),t.extensions.get("EXT_color_buffer_float");const e=new Ri;t.getSize(e);const i=new Ji(e.x,e.y,{minFilter:Yt,magFilter:Yt,format:me,type:le,depthBuffer:!0,stencilBuffer:!1,generateMipmaps:!1});i.texture.internalFormat="RGBA16F",this.renderTarget=i,this.__material_static=new rc({depthWrite:!0}),this.__material_skinned=new rc({depthWrite:!0}),this.__material_static.side=tt,this.__material_skinned.side=tt;const n=new cl;this.__scene=n,n.autoUpdate=!1,n.matrixAutoUpdate=!1,n.matrixWorldNeedsUpdate=!1}__bindMaterial(t){let e;if(void 0!==t.customNormalMaterial)e=t.customNormalMaterial;else{const i=t.material;e=t.isSkinnedMesh?this.__material_skinned:this.__material_static,void 0!==i&&(i.alphaTest>0?e.map=i.map:e.map=null,e.normalMap=i.normalMap)}return e}render(t,e,i,n){this.__renderer=t;const s=t.getRenderTarget();t.setRenderTarget(this.renderTarget),t.clear(!0,!0,!1),hv.INSTANCE.build_scene({scene:this.__scene,input:i.children,input_size:i.children.length,object_filter:t=>t.visible,material_extractor:this.__bindMaterial,material_extractor_context:this}),t.render(this.__scene,e),t.setRenderTarget(s)}}const uv=[];class dv{constructor(){this.buffers=[],this.needsRebuild=!1,this.orderedBuffers=[],this.pixelRatio=1}initialize(t){for(const e of this.buffers){if(e.initialize(t),"object"!=typeof e.renderTarget)throw new Error(`renderTarget was expected to be of type 'object', instead was '${typeof e.renderTarget}'`);if(!0!==e.renderTarget.isWebGLRenderTarget)throw new Error(`renderTarget.isWebGLRenderTarget must be true, instead was '${e.renderTarget.isWebGLRenderTarget}'`)}}build(){this.orderedBuffers=this.computeRenderOrder(),this.needsRebuild=!1}computeRenderOrder(){const t=this.buffers.slice(),e={},i=[];function n(t){const i=t.dependencies;for(let t=0;t<i.length;t++){const n=i[t];if(void 0===e[n])return!1}return!0}let s=t.length;for(;s>0;){const r=s;for(let r=0;r<s;r++){const a=t[r];n(a)&&(i.push(a),t.splice(r,1),e[a.id]=a,r--,s--)}if(r===s)throw new Error(`dependencies could not be satisfied for ${s} buffers`)}return i}getById(t){return this.buffers.find((function(e){return e.id===t}))}add(t){if(void 0!==this.getById(t.id))throw new Error(`Failed to add buffer. Another buffer with id='${t.id}' already exists`);this.buffers.push(t),this.needsRebuild=!0}update(){this.needsRebuild&&this.build()}__populate_dependencies(t,e){const i=e.dependencies,n=i.length;for(let e=0;e<n;e++){const n=i[e],s=this.getById(n);t[e]=s}}render(t,e,i){this.update();const n=this.orderedBuffers,s=n.length;for(let r=0;r<s;r++){const s=n[r];s.referenceCount>0&&(this.__populate_dependencies(uv,s),s.render(t,e,i,uv))}}setPixelRatio(t){this.pixelRatio=t}setSize(t,e){const i=this.buffers,n=i.length,s=this.pixelRatio;for(let r=0;r<n;r++)i[r].setSize(t*s,e*s)}}function pv(t){return t}function fv(t,e){return t.id-e.id}function mv(t,e){const i=t.length-e;i>0&&t.splice(e,i)}class _v{constructor(t){this.__elements=[],this.__elements_cursor=0,this.__swap_elements=[],this.__swap_elements_count=0,this.__compare=t,this.version=0,this.size=0,this.onUpdateFinished=new _,this.onAdded=new _,this.onRemoved=new _,this.state=0}get elements(){return this.__elements}forEach(t,e){const i=this.size,n=this.__elements;for(let s=0;s<i;s++){const i=n[s];t.call(e,i)}}sort(t,e){throw new Error("Deprecated, the set is always sorted")}contains(t){return-1!==this.__indexOf(t)}__indexOf(t){const e=this.__indexExpected(t);return this.__elements[e]===t?e:-1}__indexExpected(t){return function(t,e,i,n=0,s=t.length-1){let r=n,a=s;for(;r<=a;){const n=r+a>>1,s=i(e,t[n]);if(s<0)a=n-1;else{if(!(s>0))return n;r=n+1}}return r}(this.__elements,t,this.__compare,0,this.size-1)}forceRemove(t){if(1===this.state)throw new xu("Cannot remove during build");const e=this.__indexOf(t);return-1!==e&&(this.__elements.splice(e,1),this.size--,this.version++,!0)}clear(){0!==this.size&&(this.size=0,this.state=0,this.version++)}includeAll(){throw new Error("deprecated #includeAll")}initializeUpdate(){const t=this.__elements;this.__elements=this.__swap_elements,this.__swap_elements=t;const e=this.size;this.size=this.__swap_elements_count,this.__swap_elements_count=e,this.__elements_cursor=0,this.state=1,this.version++}finalizeUpdate(){const t=this.__elements_cursor,e=this.__swap_elements_count;this.size=t;const i=this.__elements,n=this.__swap_elements,s=this.__compare,r=this.onAdded,a=this.onRemoved;mv(i,t),i.sort(s);let o=0,l=0;for(;o<t&&l<e;){const t=i[o],e=n[l],h=s(t,e);0===h?(o++,l++):h<0?(o++,r.send1(t)):(l++,a.send1(e))}for(;o<t;o++)r.send1(i[o]);for(;l<e;l++)a.send1(n[l]);this.state=2,this.onUpdateFinished.send0()}push(t){this.__elements[this.__elements_cursor++]=t}pushOther(t){const e=t.__elements,i=t.size;for(let t=0;t<i;t++){const i=e[t];this.push(i)}}}_v.prototype.isIncrementalDeltaSet=!0;class gv{constructor(){this.visible=!0}copy(t){this.visible=t.visible}clone(){const t=new gv;return t.copy(this),t}}class yv{state=new gv;name=null;managed=!1;extractRenderable=pv;visibleSet=new _v(fv);get visible(){return this.state.visible}set visible(t){this.state.visible=t}computeNearFarClippingPlanes(t,e,i,n,s){throw new Error("deprecated")}buildVisibleSet(t,e,i){throw new Error("deprecated")}}class vv{data=[];on={removed:new _,added:new _};asArray(){return this.data.slice()}isEmpty(){return this.data.length<=0}remove(t){const e=this.data.indexOf(t);return-1!==e&&(this.data.splice(e,1),this.on.removed.send1(t),!0)}push(t){this.data.push(t),this.on.added.send1(t)}pop(){if(this.isEmpty())return;const t=this.data.pop();return this.on.removed.send1(t),t}peek(){return this.data[this.data.length-1]}clear(){if(this.on.removed.hasHandlers())for(;!this.isEmpty();)this.pop();else this.data.splice(0,this.data.length)}}class xv{constructor(){this.layers=new Map}write(t){for(const[e,i]of this.layers)t.getLayerByName(e).state.copy(i)}read(t){this.layers.clear();const e=t.layers,i=e.length;for(let t=0;t<i;t++){const i=e.get(t),n=i.state.clone();this.layers.set(i.name,n)}}}class wv{constructor(){this.__stateStack=new vv,this.layers=new nf}getLayerCount(){return this.layers.length}getLayerByIndex(t){const e=this.layers.get(t);if(void 0===e)throw new Error(`Layer with index ${t} not found`);return e}hideAll(){const t=this.layers,e=t.length;for(let i=0;i<e;i++)t.get(i).state.visible=!1}pushState(){const t=new xv;return t.read(this),this.__stateStack.push(t),t}popState(){this.__stateStack.isEmpty()||this.__stateStack.pop().write(this)}create(t){const e=new yv;return e.name=t,this.add(e),e}add(t){const e=t.name;if(void 0!==this.getLayerByName(e))throw new Error(`RenderLayer named '${e}' already exists`);this.layers.add(t)}remove(t){return this.layers.removeOneOf(t)}getLayerByName(t){return this.layers.find((function(e){return e.name===t}))}traverse(t,e){this.layers.forEach(t,e)}map(t){return this.layers.map(t)}}const bv={tTexture:{type:"t",value:null}},Sv=new nr({uniforms:bv,vertexShader:"\n varying vec2 vUv;\n \n void main() {\n \n vUv = uv;\n gl_Position = vec4( (uv - 0.5)*2.0, 0.0, 1.0 );\n \n }\n ",fragmentShader:Ag(),blending:it,lights:!1,fog:!1,depthTest:!1,depthWrite:!1,transparent:!0,vertexColors:!1}),Mv=new _r,Tv=new Float32Array(16);class Av{constructor(){this.name="",this.__camera=null,this.frustum=new Float32Array(24),this.projection_matrix=new Float32Array(16),this.bounding_box=new op,this.visible_objects=new _v(fv),this.flags=7,this.on={preVisibilityBuild:new _,postVisibilityBuild:new _,preRender:new _},this.projection_modifiers=[]}addProjectionModifier(t){this.projection_modifiers.push(t)}removeProjectionModifier(t){return Zm(this.projection_modifiers,t)}set_from_camera(t){this.__camera=t,Rm(t,Mv,!1),Nf(Mv.planes,this.frustum),ed(t.projectionMatrix.elements,0,this.projection_matrix,0,16);let e=this.projection_matrix,i=Tv;for(let t=0;t<this.projection_modifiers.length;t++){const n=this.projection_modifiers[t];n.transform.call(n.context,e,i);const s=e;e=i,i=s}e!==this.projection_matrix&&ed(e,0,this.projection_matrix,0,16),ed(this.projection_matrix,0,this.__camera.projectionMatrix.elements,0,16)}get camera(){return this.__camera}build_visibility(t,e){this.on.preVisibilityBuild.send0(),this.visible_objects.initializeUpdate(),e.output=this.visible_objects,e.view=this,e.build(t),this.visible_objects.finalizeUpdate(),this.on.postVisibilityBuild.send0()}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}}const Cv=[];class Ev{constructor(){this.__view=null,this.__activeLayer=null,this.__output=null}get filters(){throw new Error("Method is deprecated")}set filters(t){throw new Error("Method is deprecated")}addFilter(t){throw new Error("Method is deprecated")}removeFilter(t){throw new Error("Method is deprecated")}set view(t){this.__view=t}__processLayer(t){if(!t.state.visible)return;if(this.__activeLayer=t,t.managed)return void this.__output.pushOther(t.visibleSet);const e=t.buildVisibleSet(Cv,0,this.__view);for(let t=0;t<e;t++){const e=Cv[t];this.__output.push(e),this.__activeLayer.visibleSet.push(e)}}set output(t){this.__output=t}build(t){t.traverse(this.__processLayer,this)}}class zv{constructor(){this.__data=new nf,this.__visibility_computer=new Ev,this.on={preViewBuild:new _,postViewBuild:new _}}get elements(){return this.__data}create(){const t=new Av;return this.__data.add(t),t}add(t){return!this.__data.contains(t)&&(this.__data.add(t),!0)}remove(t){return this.__data.removeOneOf(t)}build_visibility(t){t.traverse((t=>{t.managed||t.visibleSet.initializeUpdate()}));const e=this.__data,i=e.length;for(let n=0;n<i;n++){const i=e.get(n);i.getFlag(1)?(this.on.preViewBuild.send1(i),i.build_visibility(t,this.__visibility_computer),this.on.postViewBuild.send1(i)):i.visible_objects.clear()}t.traverse((t=>{t.managed||t.visibleSet.finalizeUpdate()}))}}const Iv=new nr({uniforms:{shadow_pass:{value:null},resolution:{value:new Ri},radius:{value:4},samples:{value:8}},defines:{VSM_SAMPLES:8},vertexShader:"\nvoid main() {\n\tgl_Position = vec4( position, 1.0 );\n}\n",fragmentShader:"\nuniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tconst float samples = float( VSM_SAMPLES );\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\t// This seems totally useless but it's a crazy work around for a Adreno compiler bug\n\t// float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n\tfloat uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n\tfloat uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n\tfor ( float i = 0.0; i < samples; i ++ ) {\n\t\tfloat uvOffset = uvStart + i * uvStride;\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean / samples;\n\tsquared_mean = squared_mean / samples;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}\n"}),Lv=Iv.clone();Lv.defines.HORIZONTAL_PASS=1;const Nv=new ys;class Pv{constructor(){this.__renderer=null,this.onBeforeRender=new _}update(t,e,i,n){const s=e.camera;this.__renderer=t,this.__ensure_map(e,t);const r=t.getRenderTarget(),a=t.getActiveCubeFace(),o=t.getActiveMipmapLevel(),l=t.getScissorTest();t.getClearColor(Nv);const h=t.getClearAlpha(),c=t.autoClearColor,u=t.autoClearDepth,d=t.autoClearStencil,p=t.sortObjects,f=e.map;t.setRenderTarget(f),t.setClearColor(16777215,1),t.setScissorTest(!1),t.autoClearColor=!1,t.autoClearDepth=!1,t.autoClearStencil=!1,t.sortObjects=!1,t.clear(!0,!0,!1),e.updateMatrices(n,0),this.onBeforeRender.send3(t,s,i),f.width<=0||f.height<=0||(t.render(i,s),t.shadowMap.type===Z&&this.__do_vsm_pass(e)),t.setRenderTarget(r,a,o),t.setScissorTest(l),t.setClearColor(Nv,h),t.autoClearColor=c,t.autoClearDepth=u,t.autoClearStencil=d,t.sortObjects=p,t.info.render.frame++}__do_vsm_pass(t){const e=this.__renderer;Iv.defines.VSM_SAMPLES!==t.blurSamples&&(Iv.defines.VSM_SAMPLES=t.blurSamples,Lv.defines.VSM_SAMPLES=t.blurSamples,Iv.needsUpdate=!0,Lv.needsUpdate=!0);const i=Iv.uniforms;i.shadow_pass.value=t.map.texture,i.resolution.value=t.mapSize,i.radius.value=t.radius,i.samples.value=t.blurSamples,e.setRenderTarget(t.mapPass),e.clear(),Fg(e,Iv);const n=Lv.uniforms;n.shadow_pass.value=t.mapPass.texture,n.resolution.value=t.mapSize,n.radius.value=t.radius,n.samples.value=t.blurSamples,e.setRenderTarget(t.map),e.clear(),Fg(e,Lv)}__ensure_map(t,e){const i=t.mapSize;if(null===t.map){const n={format:me,scissorTest:!1,stencilBuffer:!1};t.isPointLightShadow||e.shadowMap.type!==Z?(n.minFilter=Yt,n.magFilter=Yt):(n.minFilter=Kt,n.magFilter=Kt,t.mapPass=new qi(i.x,i.y,Object.assign({depthBuffer:!1},n))),t.map=new qi(i.x,i.y,n),t.map.texture.name=".shadowMap",t.camera.updateProjectionMatrix()}}}class Dv{#_t=!1;get isGraphicsEngine(){return!0}constructor({camera:t,debug:e=!1}){this.#_t=e;const i=this;this.__material_manager=new rv,this.on={preRender:new _,postRender:new _,preOpaquePass:new _,postOpaquePass:new _,preComposite:new _,postComposite:new _,buffersRendered:new _,visibilityConstructionStarted:new _,visibilityConstructionEnded:new _},this.pixelRatio=new id(1),this.layers=new wv;const n=new cl;n.autoUpdate=!1,n.matrixAutoUpdate=!1,this.scene=n,this.visibleGroup=new nl,this.visibleGroup.matrixAutoUpdate=!1,this.scene.add(this.visibleGroup),this.camera=t,this.renderer=null,this.layerComposer=new iv,Object.defineProperties(this,{info:{get:function(){return i.renderer.info}}}),this.viewport=new jg,this.viewport.size.onChanged.add(this.updateSize,this),this.pixelRatio.onChanged.add(this.updateSize,this),this.frameBuffers=new dv,this.shadowmap_renderer=new Pv,this.views=new zv,this.main_view=this.views.create(),this.main_view.name="Main Camera",this.needDraw=!0,this.autoDraw=!0,this.frameIndex=0,this.intersectObjectUnderViewportPoint=function(){const t=new Yi,e=new cu,i=new Yi;return function(n,s,r,a){return this.viewportProjectionRay(n,s,i,t),e.set(i,t),e.intersectObject(r,a)}}()}getMaterialManager(){return this.__material_manager}getRenderer(){return this.renderer}updateSize(){const t=this.viewport.size,e=this.renderer,i=this.pixelRatio.getValue(),n=bu(0,t.x*i),s=bu(0,t.y*i);e.setSize(n,s);const r=window.devicePixelRatio;e.setPixelRatio(r),e.domElement.style.width=t.x+"px",e.domElement.style.height=t.y+"px",this.frameBuffers.setPixelRatio(r),this.layerComposer.setPixelRatio(r),this.layerComposer.setSize(n,s),this.frameBuffers.setSize(n,s)}getResolution(t){const e=this.computeTotalPixelRatio();t.set(this.viewport.size.x*e,this.viewport.size.y*e)}computeTotalPixelRatio(){return this.pixelRatio.getValue()*window.devicePixelRatio}initializeFrameBuffers(){const t=new ov(kg);t.referenceCount+=1,this.frameBuffers.add(t);const e=new cv(Bg);this.frameBuffers.add(e),this.frameBuffers.initialize(this.renderer)}start(){const t=document.createElement("canvas"),e=t.getContext("webgl2",{antialias:!1}),i={antialias:!0,logarithmicDepthBuffer:!1,canvas:t,context:e,powerPreference:"high-performance"},n=this.renderer=new hl(i),s=this.getGPUName();ev.record("gpu-type",{category:"system",label:s}),n.domElement.addEventListener("webglcontextrestored",(function(t){}),!1),n.domElement.addEventListener("webglcontextlost",(function(t){t.preventDefault()}),!1);const r=this.domElement=n.domElement,a=r.style;r.classList.add("graphics-engine-render-canvas"),a.userSelect=a.webkitUserSelect=a.mozUserSelect="none",a.touchAction="none",function(t){t.autoClear=!1,t.setClearColor(12303359,0),t.outputEncoding=yi,t.toneMapping=Dt,t.toneMappingExposure=1,t.state.setFlipSided(!1),t.shadowMap.enabled=!0,t.shadowMap.type=Z,t.sortObjects=!0,t.info.autoReset=!1}(n),n.debug.checkShaderErrors=this.#_t,this.enableExtensions(),this.initializeFrameBuffers();const o=this.viewport,l=o.size;n.setSize(l.x,l.y),this.frameBuffers.setSize(l.x,l.y),o.el=n.domElement}getGPUName(){const t=this.renderer.getContext(),e=t.getExtension("WEBGL_debug_renderer_info");return null===e?"Unknown":t.getParameter(e.UNMASKED_RENDERER_WEBGL)}stop(){const t=this.renderer;void 0!==t&&(t.forceContextLoss(),t.context=null,t.domElement=null,this.renderer=null)}enableExtensions(){const t=this.renderer.getContext();t.getExtension("OES_standard_derivatives"),t.getExtension("WEBGL_depth_texture"),t.getExtension("WEBGL_compressed_texture_s3tc")}viewportProjectionRay(t,e,i,n){Vm.projectRay(this.camera,t,e,i,n)}normalizeViewportPoint(t,e){const i=this.viewport.size,n=t.x+.5,s=t.y+.5;e.x=n/i.x*2-1,e.y=-s/i.y*2+1}constructVisibleScene(t,e,i){this.on.visibilityConstructionStarted.send3(t,e,i),this.main_view.set_from_camera(e),this.views.build_visibility(this.layers),this.on.visibilityConstructionEnded.send3(t,e,i)}clearVisibleGroup(){this.visibleGroup.children.length=0}prepareRenderPass(t){this.clearVisibleGroup();const e=this.visibleGroup;let i=0;const n=this.main_view.visible_objects,s=n.size,r=n.elements;for(let n=0;n<s;n++){const s=r[n];Fv(s)===t&&(s.parent=e,e.children[i++]=s)}e.length=i}renderOpaque(){this.on.preOpaquePass.send0(),this.prepareRenderPass(1);const t=this.renderer,e=this.frameBuffers;e.render(t,this.camera,this.scene);const i=e.getById(kg);if(void 0===i)throw new Error("No color-depth frame buffer");!function(t,e){bv.tTexture.value=t,Fg(e,Sv)}(i.renderTarget.texture,t),this.on.postOpaquePass.send0()}renderTransparent(){const t=this.scene,e=t.background;t.background=null,this.prepareRenderPass(2),this.renderer.render(t,this.camera),t.background=e}render(){this.needDraw&&!this.autoDraw&&(this.needDraw=!1),this.frameIndex++;const t=this.renderer;t.info.reset(),t.autoClear=!1,t.clearAlpha=0;const e=this.scene,i=this.camera;e.children.indexOf(i)<0&&e.add(i),this.constructVisibleScene(t,i,e),this.on.preRender.send3(t,i,e),this.main_view.on.preRender.send1(this.main_view),this.renderOpaque(),this.layerComposer.composite(t,1),this.on.buffersRendered.send3(t,i,e),this.renderTransparent(),this.layerComposer.composite(t,0),this.on.postRender.send3(t,i,e)}}function Fv(t){if(t.isMesh||t.isPoints){const e=t.material;if(!1===e.depthWrite&&!1===e.depthTest)return 2}return 1}const Ov="keyup",Rv="keydown";class kv{down=new _;up=new _;is_down=!1;press(){this.is_down||(this.is_down=!0,this.down.send0())}release(){this.is_down&&(this.is_down=!1,this.up.send0())}}function Bv(t,e){return null!=e&&"object"==typeof e&&t instanceof e}const Uv={backspace:8,tab:9,enter:13,shift:16,ctrl:17,alt:18,pause_break:19,caps_lock:20,escape:27,space:32,page_up:33,page_down:34,end:35,home:36,left_arrow:37,up_arrow:38,right_arrow:39,down_arrow:40,insert:45,delete:46,0:48,1:49,2:50,3:51,4:52,5:53,6:54,7:55,8:56,9:57,a:65,b:66,c:67,d:68,e:69,f:70,g:71,h:72,i:73,j:74,k:75,l:76,m:77,n:78,o:79,p:80,q:81,r:82,s:83,t:84,u:85,v:86,w:87,x:88,y:89,z:90,"left_window key":91,"right_window key":92,select_key:93,numpad_0:96,numpad_1:97,numpad_2:98,numpad_3:99,numpad_4:100,numpad_5:101,numpad_6:102,numpad_7:103,numpad_8:104,numpad_9:105,multiply:106,add:107,subtract:109,decimal_point:110,divide:111,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123,num_lock:144,scroll_lock:145,semi_colon:186,equal_sign:187,comma:188,dash:189,period:190,forward_slash:191,grave_accent:192,open_bracket:219,backslash:220,close_bracket:221,single_quote:222,back_quote:223},Vv=[];class Wv{on={down:new _,up:new _};keys={};constructor(t){var e;Bv(e=t,HTMLInputElement)||Bv(e,HTMLSelectElement)||Bv(e,HTMLTextAreaElement)||Bv(e,HTMLAnchorElement)||Bv(e,HTMLButtonElement)||Bv(e,HTMLAreaElement)||t.getAttribute("tabindex"),this.domElement=t;for(let t in Uv)Vv[Uv[t]]=t,this.keys[t]=new kv}#gt=t=>{if(t.repeat)return;this.on.down.send1(t);const e=t.keyCode,i=Vv[e];void 0!==i&&this.keys[i].press()};#yt=t=>{this.on.up.send1(t);const e=t.keyCode,i=Vv[e];void 0!==i&&this.keys[i].release()};start(){this.domElement.addEventListener(Rv,this.#gt),this.domElement.addEventListener(Ov,this.#yt)}stop(){this.domElement.removeEventListener(Rv,this.#gt),this.domElement.removeEventListener(Ov,this.#yt)}}const Gv="undefined"==typeof performance?Date:performance;function Hv(){return.001*Gv.now()}const jv="mousedown",qv="mouseenter",Jv="mouseleave",$v="wheel",Yv="pointerup",Xv="pointerdown",Zv="pointermove";class Kv{timestamp=Hv();position=new Eu;static from(t){const e=new Kv;return e.position.copy(t),e}}function Qv(t){return t.preventDefault(),t.stopPropagation(),!1}class tx{position=new Eu;#vt=new _;on={down:new _,up:new _,move:new _,tap:new _,drag:new _,dragStart:new _,dragEnd:new _,wheel:new _,pinch:new _,pinchStart:new _,pinchEnd:new _};#xt=null;#wt=null;isRunning=!1;buttons=new Array(32);get mouseButtonLeft(){return this.buttons[0]}get mouseButtonRight(){return this.buttons[2]}get mouseButtonMiddle(){return this.buttons[1]}constructor(t){for(let t=0;t<this.buttons.length;t++)this.buttons[t]=new kv;this.#wt=t,function({up:t,down:e,move:i=new _,maxDistance:n=10,maxDelay:s=1,signal:r}){const a=new Map;function o(e){a.delete(e)&&(t.remove(l),i.remove(h))}function l(t,e){const i=e.pointerId,n=a.get(i);void 0!==n&&(o(i),Hv()-n.timestamp>s||r.send2(t,e))}function h(t,e){const i=e.pointerId,s=a.get(i);void 0!==s?s.position.distanceTo(t)>n&&o(i):o(i)}e.add((function(e,n){const s=n.pointerId;o(s),a.set(s,Kv.from(e)),t.addOne(l),i.add(h)}))}({up:this.on.up,down:this.on.down,move:this.on.move,maxDistance:10,signal:this.on.tap}),function(t,e,i,n,s,r){const a=new Eu;function o(e){t.remove(o),i.remove(h)}function l(e){t.remove(l),i.remove(u),s.send1(e)}function h(e,s){i.remove(h),i.add(u),t.remove(o),t.add(l),c.copy(a),n.send2(a,s),u(e,s)}const c=new Eu;function u(t,e){r.send4(t,a,c,e),c.copy(t)}e.add((function(e){a.copy(e),t.add(o),i.add(h)}))}(this.#vt,this.on.down,this.on.move,this.on.dragStart,this.on.dragEnd,this.on.drag)}#bt=t=>{this.readPointerPositionFromEvent(this.position,t),this.on.down.send2(this.position,t);const e=t.button,i=this.buttons[e];i?.press()};#St=t=>{this.readPointerPositionFromEvent(this.position,t),this.on.up.send2(this.position,t)};#Mt=t=>{this.readPointerPositionFromEvent(this.position,t),this.#vt.send2(this.position,t);const e=t.button,i=this.buttons[e];i?.release()};#Tt=t=>{t.preventDefault();const e=E(t.deltaX),i=E(t.deltaY),n=E(t.deltaZ),s=new L(e,i,n);this.readPointerPositionFromEvent(this.position,t),this.on.wheel.send3(s,this.position,t)};#At=t=>{t.preventDefault(),this.#xt=t.target,this.readPointerPositionFromEvent(this.position,t),this.on.move.send3(this.position,t,new Eu(t.movementX,t.movementY))};getTargetElement(){return this.#xt}set domElement(t){if(this.#wt===t)return;let e=this.isRunning;e&&this.stop(),this.#wt=t,e&&this.start()}get domElement(){return this.#wt}readPointerPositionFromEvent(t,e){!function(t,e,i=e.target){let n=e.clientX,s=e.clientY;if("function"==typeof i.getBoundingClientRect){const t=i.getBoundingClientRect();s-=t.top,n-=t.left}t.set(n,s)}(t,e,this.domElement)}start(){if(this.isRunning)return;this.isRunning=!0;const t=this.#wt;t.addEventListener(Zv,this.#At),t.addEventListener(Yv,this.#St),t.addEventListener(Xv,this.#bt),window.addEventListener(Yv,this.#Mt),t.addEventListener($v,this.#Tt,{passive:!1}),t.addEventListener("contextmenu",Qv)}stop(){if(!this.isRunning)return;this.isRunning=!1;const t=this.domElement;t.removeEventListener(Zv,this.#At),t.removeEventListener(Yv,this.#St),t.removeEventListener(Xv,this.#bt),window.removeEventListener(Yv,this.#Mt),t.removeEventListener($v,this.#Tt),t.removeEventListener("contextmenu",Qv)}}class ex{constructor(t,e="Unnamed"){this.name=e,this.children=t,this.on={started:new _,completed:new _,failed:new _},this.state=new Gd(Tf.INITIAL),this.isTaskGroup=!0}getExecutedCpuTime(){let t=0;const e=this.children,i=e.length;for(let n=0;n<i;n++)t+=e[n].getExecutedCpuTime();return t}addChild(t){return Sf(this.children,t)}addChildren(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];this.addChild(e)}}addDependency(t){if(t.isTaskGroup)this.addDependencies(t.children);else{const e=this.children,i=e.length;for(let n=0;n<i;n++)e[n].addDependency(t)}}addDependencies(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];this.addDependency(e)}}getEstimatedDuration(){let t=0;const e=this.children,i=e.length;for(let n=0;n<i;n++){const i=e[n].getEstimatedDuration();isNaN(i)||i<0||(t+=i)}return t}getVerboseStatusMessage(){const t=new gf;return function e(i){if(i.isTaskGroup){t.add(`group ['${i.name}']`),t.indent();for(let t=0;t<i.children.length;t++)e(i.children[t]);t.dedent()}else t.add(`task ['${i.name}'] ${n_(Tf,i.state.getValue())}`)}(this),t.build()}computeProgress(){const t=this.children,e=t.length;let i=0,n=0;for(let s=0;s<e;s++){const e=t[s],r=e.getEstimatedDuration();isNaN(r)||(i+=ix(e)*r,n+=r)}return 0===n?0:i/n}join(t,e){Cf.join(this,t,e)}promise(){return new Promise(((t,e)=>this.join(t,e)))}}function ix(t){if(t.isTask){const e=t.state.getValue();if(e===Tf.INITIAL||e===Tf.READY)return 0}return t.computeProgress()}class nx{constructor(){this.table=null,this.id=null,this.source=null}static from(t,e,i){const n=new nx;return n.id=t,n.source=e,n.table=i,n}}const sx={Initial:0,Loading:1,Loaded:2,Failed:3};class rx{__state=new Fm(sx.Initial,sx);__specs=[];#Ct=!1;set validation_enabled(t){this.#Ct=t}reset(){this.__state.set(sx.Initial);const t=this.__specs,e=t.length;for(let i=0;i<e;i++)t[i].table.reset()}add(t,e,i){const n=this.__state.getValue();if(n!==sx.Initial)throw new xu(`Adding new tables is only allowed in Initial state, current state is ${n_(sx,n)}`);const s=this.getDescriptorById(t);if(void 0!==s){if(s.id===t&&s.source===e&&Object.getPrototypeOf(s.table)===Object.getPrototypeOf(i))return;throw new Error(`Table '${t}' already exists`)}const r=nx.from(t,e,i);this.__specs.push(r),this[t]=i}getDescriptorById(t){const e=this.__specs,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i.id===t)return i}}getTable(t){const e=this.getDescriptorById(t);if(void 0!==e)return e.table}promise(){const t=this.__state;return new Promise((function(e,i){t.process((function(t){return t===sx.Loaded?e():t===sx.Failed?i("Failed to load Static Knowledge"):void 0}))}))}validate(t){const e=this.__specs.map((t=>t.table.validate(this,console.error))),i=new ex(e,"Database Validation"),n=Cf.promise(i);return t.runGroup(i),n}async __link_table(t,e,i){const n=t.table;await n.link(this,e,i)}link(t,e){const i=this.__specs.map((i=>{this.__link_table(i,t,e).catch((t=>{i.table}))}));return Promise.all([i])}async __load_table(t,e,i){const n=t.source,s=t.table;if(!0!==s.isStaticKnowledgeDataTable)throw new Error("Illegal argument, table.isStaticKnowledgeDataTable !== true");const r=(await e.promise(n,Iu)).create();return await s.load(r,i),s}async __hot_load(t,e,i){await this.__load_table(t,e,i),await this.__link_table(t,e,i)}load(t,e){if(this.__state.getValue()!==sx.Initial)throw new Error("Illegal state");this.__state.set(sx.Loading);const i=this,n=[],s=this.__specs.length;for(let i=0;i<s;i++){const s=this.__specs[i],r=this.__load_table(s,t,e);n.push(r)}return Promise.all(n).then((()=>{let i=this.link(t,e);return this.#Ct&&(i=i.then((()=>this.validate(e)))),i})).then((function(){i.__state.set(sx.Loaded)}),(function(t){i.__state.set(sx.Failed)}))}}rx.prototype.isStaticKnowledgeDatabase=!0;const ax=new class{backends=[];addBackend(t){return!this.backends.includes(t)&&(this.backends.push(t),!0)}removeBackend(t){const e=this.backends.indexOf(t);return-1!==e&&(this.backends.splice(e,1),!0)}log(t,e){const i=this.backends,n=i.length;for(let s=0;s<n;s++){const n=i[s];t>n.getLevel()||n.log(t,e)}}info(t){this.log(3,t)}warn(t){this.log(2,t)}error(t){this.log(1,t)}};class ox{parent=null;constructor(t){this.id=t}computePath(){const t=[];let e=this;for(;null!==e;)t.unshift(e.id),e=e.parent;return t}}class lx extends ox{on={written:new _,writeFailed:new _,settingsUpdated:new _};constructor(t,e,i=Mf,n={transient:!1}){super(t);const s=this;this.read=e,this.write=function(t){let e,n=!1;try{e=i(t)}catch(e){n=!0,s.on.writeFailed.send2(t,e)}return n||(void 0!==e&&"function"==typeof e.then?e.then((()=>s.on.written.send1(t)),(e=>s.on.writeFailed.send2(t,e))):s.on.written.send1(t)),e},this.settings=n,this.isTransient=!0===n.transient}setSetting(t,e){this.settings[t]=e,this.on.settingsUpdated.send2(t,e)}toJSON(){let t=this.read();switch(typeof t){case"number":case"boolean":case"string":return t;default:return null}}fromJSON(t){this.write(t)}}class hx extends ox{children=[];resolve(t){let e=this;for(let i=0;i<t.length;i++){const n=t[i],s=e;if(e=s.children.find((t=>t.id===n)),void 0===e)throw new Error(`Failed to resolve path at '${n}'[${i}], in path: [${t.join(", ")}], available options:[${s.children.map((t=>t.id)).join(", ")}]`)}return e}addChild(t){return void 0===this.getChildById(t.id)&&(this.children.push(t),t.parent=this,!0)}getChildById(t){return this.children.find((e=>e.id===t))}add(t,e,i,n){let s=new lx(t,e,i,n);return this.addChild(s),this}addGroup(t){let e=new hx(t);return this.addChild(e),e}toJSON(){const t={};return this.children.forEach((e=>{e.isTransient||(t[e.id]=e.toJSON())})),t}fromJSON(t){this.children.forEach((e=>{t.hasOwnProperty(e.id)&&e.fromJSON(t[e.id])}))}traverseOptions(t,e){this.children.forEach((function(i){!function(t){return"function"==typeof t.read}(i)?i.traverseOptions(t,e):t.call(e,i)}))}attachToStorage(t,e){const n=this,s=t;function r(){const t=function(t){let e="";try{!function(t,e){function n(t,i){e('"'+t+'":'),s(i)}function s(t){const r=typeof t;switch(r){case"object":null===t?e("null"):t instanceof Array||i(t)?function(t){e("[");const i=t.length;if(i>0){s(t[0]);for(let n=1;n<i;n++)e(","),s(t[n])}e("]")}(t):function(t){e("{");let i=0;for(let s in t)i++>0&&e(","),n(s,t[s]);e("}")}(t);break;case"number":case"boolean":case"string":e(JSON.stringify(t));break;case"undefined":s("null");break;default:throw new Error("Can not process object of type "+r)}}s(t)}(t,(function(t){e+=t}))}catch(t){throw t}return e}(n.toJSON());e.store(s,t,Mf,console.error,Mf)}return new Promise((function(t,i){e.load(s,t,i)})).then((t=>{void 0!==t&&"string"==typeof t&&n.fromJSON(JSON.parse(t))})).finally((()=>{n.traverseOptions((t=>t.on.written.add(r)))}))}}hx.prototype.isOptionGroup=!0;const cx=[bg.Finalizing,bg.Initializing,bg.Starting,bg.Stopping];function ux(t,e){const i=t.getState().getValue();return i===bg.Initialized||i===bg.Stopped?Promise.resolve():i===bg.New||i===bg.Finalized?(t.initialize(e),Promise.resolve()):i===bg.Running?t.shutdown():Promise.reject(`Unsupported initial state '${i}'`)}class dx{constructor(t,e){this.__klass=e,this.__instance=t,this.__references=new nf,this.dependency_references=new nf,this.on={lastReleased:new _},this.__transition=Promise.resolve()}synchronize(){return this.__transition}transition(t,e){if(cx.includes(t))return Promise.reject(`Requested state '${t}' is transient. Only steady states are allowed`);const i=this.__instance,n=this.__transition.then((()=>new Promise(((n,s)=>i.getState().getValue()===t?n():t===bg.Initialized?ux(i,e).then(n,s):t===bg.Running?function(t,e){const i=t.getState().getValue();return i===bg.Running?Promise.resolve():i===bg.Initialized||i===bg.Stopped?t.startup():i===bg.New||i===bg.Finalized?ux(t,e).then((()=>t.startup())):Promise.reject(`Unsupported initial state '${i}'`)}(i,e).then(n,s):t===bg.Finalized?function(t,e){const i=t.getState().getValue();return i===bg.New||i===bg.Finalized?Promise.resolve():i===bg.Running?ux(t,e).then((()=>t.finalize())):i===bg.Stopped||i===bg.Initialized?(t.finalize(),Promise.resolve()):Promise.reject(`Unsupported initial state '${i}'`)}(i,e).then(n,s):void s(`Unsupported target state '${t}'`)))));return this.__transition=n,n}async dispose(){const t=this.__instance,e=t.getState();e.getValue()===bg.Running&&await t.shutdown(),e.getValue()!==bg.Stopped&&e.getValue()!==bg.Initialized||await t.finalize(),this.dependency_references.forEach((t=>t.release()))}__handle_reference_released(t){this.__references.removeOneOf(t)&&this.__references.isEmpty()&&this.on.lastReleased.send2(this,t)}getKlass(){return this.__klass}getReference(){const t=new nv;return t.onReleased.add(this.__handle_reference_released,this),t.bind(this.__instance),this.__references.add(t),t}get referenceCount(){return this.__references.length}get instance(){return this.__instance}}class px extends Sg{__plugins=new Map;engine=null;__version=0;__getActivePluginInstances(){const t=[];for(const[e,i]of this.__plugins)i.referenceCount<=0||t.push(i.instance);return t}__getActivePluginContexts(){const t=[];for(const[e,i]of this.__plugins)i.referenceCount<=0||t.push(i);return t}async __transition_plugin_to_state(t,e){const i=t.instance;if(e===bg.Initialized||e===bg.Running){const t=i.dependencies;for(let i=0;i<t.length;i++){const n=t[i],s=this.__plugins.get(n),r=s.instance.getState().getValue();r!==bg.Running&&(e===bg.Running||r!==bg.Initialized)&&await s.transition(e,this.engine)}}await t.transition(e,this.engine)}async __transition_active_plugins_to(t){let e;do{e=this.__version;const i=this.__getActivePluginContexts(),n=i.length,s=[];for(let e=0;e<n;e++){const n=i[e],r=this.__transition_plugin_to_state(n,t);s.push(r)}await Promise.all(s)}while(e!==this.__version)}__handle_last_plugin_reference_release(t){this.__version++;const e=t.getKlass();this.__plugins.delete(e)&&t.dispose()}initialize(t){this.engine=t,super.initialize();const e=this.__getActivePluginInstances(),i=e.length;for(let n=0;n<i;n++)e[n].initialize(t)}finalize(){super.finalize();const t=this.__getActivePluginInstances(),e=t.length;for(let i=0;i<e;i++)t[i].finalize()}async startup(){return super.startup(),this.__transition_active_plugins_to(bg.Running)}async shutdown(){return super.shutdown(),this.__transition_active_plugins_to(bg.Finalized)}async acquire(t){if(!function(t,e){let i=t;for(;void 0!==i;){if(i===e||i instanceof e)return!0;i=i.prototype}return!1}(t,Mg))throw new Error("PluginClass is not a subclass of EnginePlugin");let e,i=this.__plugins.get(t);if(void 0===i){this.__version++;const n=new t;i=new dx(n,t),i.on.lastReleased.add(this.__handle_last_plugin_reference_release,this),this.__plugins.set(t,i),e=i.getReference();const s=await this.acquireMany(n.dependencies);i.dependency_references.addAll(s);const r=this.getState().getValue(),a=this.engine;await i.transition(r,a)}else e=i.getReference(),await i.synchronize();return e}async acquireMany(t){const e=t.map(this.acquire,this);return await Promise.all(e)}getPlugin(t){const e=this.__getActivePluginInstances(),i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i.constructor===t)return i}}getById(t){const e=this.__getActivePluginInstances(),i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i.id===t)return i}}}function fx(t,e,i){const n=t.length;for(let s=0;s<n;s++){const n=t[s];if(n.handle===e){if(void 0!==i&&i!==n.context)continue;return s}}return-1}function mx(t,e,i){const n=t.length;for(let s=0;s<n;s++){const n=t[s];if(n.handle===e&&n.context===i)return s}return-1}function _x(t,e,i,n){const s=e*i;for(let e=n.nextSetBit(0);-1!==e;e=n.nextSetBit(e+1))if(!t.get(e+s))return!1;return!0}function gx(t,e,i,n,s){for(let r=e.nextSetBit(0);-1!==r;r=e.nextSetBit(r+1)){const e=n[r][t];s[i[r]]=e}}const yx=[],vx=[];class xx{entityOccupancy=new e_;entityGeneration=new Uint32Array(0);componentOccupancy=new e_;componentTypeMap=[];__type_to_index_map=new Map;componentTypeCount=0;components=[];entityCount=0;generation=0;onEntityCreated=new _;onEntityRemoved=new _;__entityEventListeners=[];__entityAnyEventListeners=[];observers=[];promiseComponent(t,e){const i=this;return new Promise((function(n,s){const r=i.getComponent(t,e);void 0===r?(i.addEntityEventListener(t,c_,(function t(s,r){if(s.klass===e){const e=s.instance;i.removeEntityEventListener(r,c_,t),n(e)}})),i.addEntityEventListener(t,h_,(function(){s(`Entity ${t} has been removed`)}))):n(r)}))}addObserver(t,e){if(t.dataset===this)return!1;let i;t.dataset=this,t.build(this.componentTypeMap);const n=t.componentMask;for(i=n.nextSetBit(0);-1!==i;i=n.nextSetBit(i+1))this.observers[i].push(t);if(!0===e){const e=this.componentTypeCount,s=this.componentOccupancy,r=this.entityOccupancy,a=this.components,o=t.componentIndexMapping,l=[];for(i=r.nextSetBit(0);-1!==i;i=r.nextSetBit(i+1))_x(s,i,e,n)&&(gx(i,n,o,a,l),l[t.componentTypeCount]=i,t.callbackComplete.apply(t.thisArg,l))}return!0}removeObserver(t,e){let i,n=!1;const s=t.componentMask;for(i=s.nextSetBit(0);-1!==i;i=s.nextSetBit(i+1)){const e=this.observers[i],s=e.indexOf(t);-1!==s&&(n=!0,e.splice(s,1))}if(n&&!0===e){const e=this.componentTypeCount,n=this.componentOccupancy,r=this.entityOccupancy,a=this.components,o=t.componentIndexMapping,l=[];for(i=r.nextSetBit(0);-1!==i;i=r.nextSetBit(i+1))_x(n,i,e,s)&&(gx(i,s,o,a,l),l[t.componentTypeCount]=i,t.callbackBroken.apply(t.thisArg,l))}return t.dataset=null,n}getEntityCount(){return this.entityCount}getComponentTypeCount(){return this.componentTypeCount}getComponents(t,e){const i=e.length,n=new Array(i),s=this.componentTypeCount,r=s*t,a=r+s;for(let i=this.componentOccupancy.nextSetBit(r);i<a&&-1!==i;i=this.componentOccupancy.nextSetBit(i+1)){const r=i%s,a=this.componentTypeMap[r],o=e.indexOf(a);-1!==o&&(n[o]=this.components[r][t])}return n}getAllComponents(t){const e=[],i=this.componentTypeCount,n=i*t,s=n+i;for(let r=this.componentOccupancy.nextSetBit(n);r<s&&-1!==r;r=this.componentOccupancy.nextSetBit(r+1)){const n=r%i;e[n]=this.components[n][t]}return e}setComponentTypeMap(t){const e=t.length,i=ef(t,this.componentTypeMap),n=i.uniqueA,s=i.uniqueB,r=i.common,a=this;!function(){const t=[];for(let e=0;e<s.length;e++){const i=s[e];a.traverseComponents(i,(function(){return t.push(i),!1}))}if(t.length>0){const e=t.map((t=>t.typeName)).join(", ");throw new Error(`Component types can not be unmapped due to presence of live components: ${e}`)}}();const o=function(){const e=[];let i,n;for(i=0,n=r.length;i<n;i++){const n=r[i],s=a.componentTypeMap.indexOf(n),o=t.indexOf(n);e[s]=o}return e}();!function(t){const i=new e_;let n;const s=a.componentTypeCount;for(n=a.componentOccupancy.nextSetBit(0);-1!==n;n=a.componentOccupancy.nextSetBit(n+1)){const r=t[n%s];if(void 0!==r){const t=Math.floor(n/s);i.set(t*e+r,!0)}}a.componentOccupancy=i}(o),function(e){let i,s;const r=[];for(i=0,s=n.length;i<s;i++){const e=n[i];r[t.indexOf(e)]=[]}for(i=0,s=e.length;i<s;i++){const t=e[i];void 0!==t&&(r[t]=a.components[i])}a.components=r}(o),function(e){let i,s;const r=[];for(i=0,s=n.length;i<s;i++){const e=n[i];r[t.indexOf(e)]=[]}for(i=0,s=e.length;i<s;i++){const n=e[i];if(void 0===n)continue;const s=a.observers[i];s.forEach((function(e){e.build(t)})),r[n]=s}a.observers=r}(o),this.componentTypeMap=t,this.__type_to_index_map.clear();for(let i=0;i<e;i++)this.__type_to_index_map.set(t[i],i);this.componentTypeCount=e}areComponentTypesRegistered(t){for(let e=0;e<t.length;e++){const i=t[e];if(!this.isComponentTypeRegistered(i))return!1}return!0}isComponentTypeRegistered(t){return-1!==this.getComponentTypeMap().indexOf(t)}getComponentTypeMap(){return this.componentTypeMap}registerManyComponentTypes(t){const e=ef(t,this.componentTypeMap);if(0===e.uniqueA.length)return!1;const i=this.componentTypeMap.concat(e.uniqueA);return this.setComponentTypeMap(i),!0}registerComponentType(t){if(this.isComponentTypeRegistered(t))return!1;const e=this.componentTypeMap.concat([t]);return this.setComponentTypeMap(e),!0}unregisterComponentType(t){if(this.isComponentTypeRegistered(t))return!1;const e=this.componentTypeMap.slice(),i=e.indexOf(t);return e.splice(i,1),this.setComponentTypeMap(e),!0}enlargeGenerationTable(t){const e=this.entityGeneration.length,i=Pf(t,Math.ceil(1.2*e),e+16),n=new Uint32Array(i);n.set(this.entityGeneration),this.entityGeneration=n}getEntityGeneration(t){return this.entityGeneration[t]}createEntityUnsafe(t){this.entityOccupancy.set(t,!0),this.entityGeneration.length<=t&&this.enlargeGenerationTable(t+1);const e=this.generation;this.generation=e+1,this.entityGeneration[t]=e,this.entityCount++,this.onEntityCreated.send1(t)}createEntity(){const t=this.entityOccupancy.nextClearBit(0);return this.createEntityUnsafe(t),t}createEntitySpecific(t){if(this.entityExists(t))throw new Error(`EntityId ${t} is already in use`);this.createEntityUnsafe(t)}entityExists(t){return this.entityOccupancy.get(t)}componentIndexExists(t){return t>=0&&t<this.componentTypeCount}removeEntity(t){if(!this.entityExists(t))return;const e=this.componentOccupancy,i=this.componentTypeCount,n=t*i,s=n+i;for(let r=e.nextSetBit(n);r<s&&-1!==r;r=e.nextSetBit(r+1)){const e=r%i;this.removeComponentFromEntityByIndex_Unchecked(t,e,r)}this.sendEvent(t,h_,t),delete this.__entityEventListeners[t],delete this.__entityAnyEventListeners[t],this.entityOccupancy.set(t,!1),this.entityCount--,this.onEntityRemoved.send1(t)}removeEntities(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];this.removeEntity(e)}}removeComponentFromEntity(t,e){const i=this.componentTypeMap.indexOf(e);if(-1===i)throw new Error("Component class not found in this dataset");this.removeComponentFromEntityByIndex(t,i)}removeComponentFromEntityByIndex(t,e){const i=t*this.componentTypeCount+e;this.componentOccupancy.get(i)&&this.removeComponentFromEntityByIndex_Unchecked(t,e,i)}removeComponentFromEntityByIndex_Unchecked(t,e,i){this.processObservers_ComponentRemoved(t,e);const n=this.components[e][t];delete this.components[e][t],this.componentOccupancy.clear(i);const s=this.componentTypeMap[e];this.sendEvent(t,"componentRemoved",{klass:s,instance:n})}computeComponentTypeIndex(t){const e=this.__type_to_index_map.get(t);return void 0===e?-1:e}computeComponentCount(t){let e=0;return this.traverseComponents(t,(function(){e++})),e}getAnyComponent(t){let e=-1,i=null;return this.traverseComponents(t,((t,n)=>(e=n,i=t,!1))),{entity:e,component:i}}addComponentToEntity(t,e){const i=e.constructor,n=this.__type_to_index_map.get(i);if("number"!=typeof n)throw new Error(`Component class not found in this dataset for componentInstance ${s=e,"object"==typeof s?s.constructor.toString():s}`);var s;this.addComponentToEntityByIndex(t,n,e)}addComponentToEntityByIndex(t,e,i){const n=t*this.componentTypeCount+e;this.componentOccupancy.set(n,!0),this.components[e][t]=i,this.processObservers_ComponentAdded(t,e);const s=this.componentTypeMap[e];this.sendEvent(t,c_,{klass:s,instance:i})}getComponentByIndex(t,e){return this.components[e][t]}hasComponent(t,e){return void 0!==this.getComponent(t,e)}getComponent(t,e){const i=this.computeComponentTypeIndex(e);if(-1!==i)return this.getComponentByIndex(t,i)}getComponentSafe(t,e){const i=this.getComponent(t,e);if(void 0===i)throw new Error("Component not found");return i}getComponentAsync(t,e,i,n){const s=this.getComponent(t,e),r=s=>{s.klass===e&&(this.removeEntityEventListener(t,c_,r),i.call(n,s.instance))};void 0===s?this.addEntityEventListener(t,c_,r):i.call(n,s)}traverseEntities(t,e,i){let n,s;const r=yx,a=t.length;for(s=0;s<a;s++){const e=t[s],i=this.computeComponentTypeIndex(e);if(-1===i)return;r[s]=i}const o=vx;mv(vx,a+1);const l=this.entityOccupancy,h=this.componentTypeCount,c=this.componentOccupancy,u=this.components;t:for(n=l.nextSetBit(0);-1!==n;n=l.nextSetBit(n+1)){const t=n*h;for(s=0;s<a;s++){const e=r[s];if(!c.get(t+e))continue t;o[s]=u[e][n]}if(o[a]=n,!1===e.apply(i,o))return}}traverseEntitiesExact(t,e,i){let n,s;const r=[],a=t.length;for(s=0;s<a;s++){const e=t[s],i=this.computeComponentTypeIndex(e);r[s]=i}const o=[];t:for(n=this.entityOccupancy.nextSetBit(0);-1!==n;n=this.entityOccupancy.nextSetBit(n+1)){const t=n*this.componentTypeCount,l=t+this.componentTypeCount;let h=0;for(s=this.componentOccupancy.nextSetBit(t);s<l&&-1!==s;s=this.componentOccupancy.nextSetBit(s+1)){const e=s-t,i=r.indexOf(e);if(-1===i)continue t;h++,o[i]=this.components[e][n]}if(h===a&&(o[a]=n,!1===e.apply(i,o)))return}}*createEntityIterator(){const t=this.entityOccupancy;for(let e=t.nextSetBit(0);-1!==e;e=t.nextSetBit(e+1))yield e}traverseComponents(t,e,i){const n=this.computeComponentTypeIndex(t);-1!==n&&this.traverseComponentsByIndex(n,e,i)}traverseComponentsByIndex(t,e,i){this.__traverseComponentsByIndex_via_property(t,e,i)}__traverseComponentsByIndex_via_bitset(t,e,i){const n=this.components[t],s=this.componentTypeCount,r=this.entityOccupancy,a=this.componentOccupancy;for(let o=r.nextSetBit(0);-1!==o;o=r.nextSetBit(o+1)){const r=o*s+t;if(a.get(r)){const t=n[o];if(!1===e.call(i,t,o))break}}}__traverseComponentsByIndex_via_property(t,e,i){const n=this.components[t];for(const t in n){const s=Number.parseInt(t),r=n[s];if(void 0!==r&&!1===e.call(i,r,s))break}}processObservers_ComponentAdded(t,e){const i=this.observers[e],n=i.length;if(0===n)return;let s=0;const r=[];for(;s<n;s++){const e=i[s];_x(this.componentOccupancy,t,this.componentTypeCount,e.componentMask)&&(gx(t,e.componentMask,e.componentIndexMapping,this.components,r),r[e.componentTypeCount]=t,e.callbackComplete.apply(e.thisArg,r))}}processObservers_ComponentRemoved(t,e){const i=this.observers[e],n=i.length;let s;const r=[];for(s=0;s<n;s++){const e=i[s];_x(this.componentOccupancy,t,this.componentTypeCount,e.componentMask)&&(gx(t,e.componentMask,e.componentIndexMapping,this.components,r),r[e.componentTypeCount]=t,e.callbackBroken.apply(e.thisArg,r))}}addEntityAnyEventListener(t,e,i){if(!this.entityExists(t))throw new Error(`Entity '${t}' does not exist`);const n=this.__entityAnyEventListeners;let s=n[t];void 0===s&&(s=[],n[t]=s);const r=new m(e,i);s.push(r)}removeAnyEventListener(t,e,i){let n,s=this.__entityAnyEventListeners[t];return void 0!==s&&(n=void 0===i?fx(s,e):mx(s,e,i),!(n<0||(s.splice(n,1),0)))}addEntityEventListener(t,e,i,n){if(!this.entityExists(t))throw new Error(`Entity '${t}' does not exist`);const s=this.__entityEventListeners;let r=s[t];void 0===r&&(r={},s[t]=r);let a=r[e];void 0===a&&(a=[],r[e]=a);const o=new m(i,n);a.push(o)}removeEntityEventListener(t,e,i,n){const s=this.__entityEventListeners[t];if(void 0===s)return!1;const r=s[e];if(void 0===r)return!1;let a;return a=void 0===n?fx(r,i):mx(r,i,n),!(a<0||(r.splice(a,1),0))}sendEvent(t,e,i){!function(t,e,i,n){const s=t[e];void 0!==s&&function(t,e,i,n){const s=t[i];if(void 0===s)return;const r=s.length;if(0===r)return;const a=bx;let o;for(bx+=r,o=0;o<r;o++){const t=s[o];wx[o+a]=t}for(let t=0;t<r;t++){const i=wx[t+a];i.handle.call(i.context,n,e)}bx=a}(s,e,i,n)}(this.__entityEventListeners,t,e,i);const n=this.__entityAnyEventListeners[t];void 0!==n&&function(t,e,i,n){const s=t.length;if(0===s)return;const r=bx;let a;for(bx+=s,a=0;a<s;a++){const e=t[a];wx[a+r]=e}for(let t=0;t<s;t++){const s=wx[t+r];s.handle.call(s.context,i,n,e)}bx=r}(n,t,e,i)}entityHasComponents(t){const e=this.getAllComponents(t),i=e.length;for(let t=0;t<i;t++)if(void 0!==e[t])return!0;return!1}clear(){const t=this.entityOccupancy;for(let e=t.nextSetBit(0);-1!==e;e=t.nextSetBit(e+1))this.removeEntity(e)}dropData(){for(let t=0;t<this.componentTypeCount;t++)this.components[t]=[];this.componentOccupancy.reset(),this.entityOccupancy.reset(),this.entityCount=0,this.__entityEventListeners=[]}getComponentClassByName(t){let e=0;for(;e<this.componentTypeCount;e++){const i=this.componentTypeMap[e];if(i.typeName===t)return i}return null}maskedCopy(t,e){let i;const n=e.length,s=[],r=[];for(i=0;i<n;i++){const n=e[i],a=t.computeComponentTypeIndex(n);if(-1===a)continue;const o=this.computeComponentTypeIndex(n);if(-1===o)throw new Error("This dataset does not have component class registered");s.push(a),r.push(o)}const a=s.length,o=t.entityOccupancy,l=t.componentOccupancy,h=t.componentTypeCount;let c;for(c=o.nextSetBit(0);-1!==c;c=o.nextSetBit(c+1))for(this.createEntitySpecific(c),i=0;i<a;i++){const e=s[i];if(l.get(h*c+e)){const n=r[i],s=t.getComponentByIndex(c,e);this.addComponentToEntityByIndex(c,n,s)}}}traverseEntitiesCompactedFiltered(t,e){const i=t.length,n=new Array(i);let s,r;for(s=0;s<i;s++){const e=t[s],i=this.computeComponentTypeIndex(e);n[s]=i}n.sort();const a=this.entityOccupancy,o=this.componentOccupancy,l=this.componentTypeCount,h=[];let c;for(s=a.nextSetBit(0);-1!==s;s=a.nextSetBit(s+1)){const t=s*l;for(c=0,r=0;r<i;r++){const e=n[r];if(o.get(t+e)){const t=this.components[e][s];h[c]=t,c++}}e(s,h,c)}}isEmpty(){return 0===this.entityCount}traverseEntityIndices(t){let e;const i=this.entityOccupancy;for(e=i.nextSetBit(0);-1!==e;e=i.nextSetBit(e+1))t(e)}}xx.prototype.isEntityComponentDataset=!0;const wx=[];let bx=0;class Sx{constructor(t="Unnamed"){this.name=t,this.dataset=new xx,this.active=new Dm(!1),this.destroyed=!1,this.speedModifiers=new nf}handlePreActivation(){}handlePostActivation(){}handlePreDeactivation(){}handlePostDeactivation(){}setup(t,e,i,n){return function(t,e){let i=!1,n=!1,s=null;return t.then((function(){i=!0}),(function(t){n=!0,s=t})),new Cf({name:e,cycleFunction:function(){if(i)return 0;if(n)throw s;return 3},computeProgress:function(){return i?1:0}})}(new Promise((function(t,e){i(),t()})),`${name} scene setup`)}teardown(t,e,i){}clear(){this.dataset.clear()}}class Mx{#Et=null;get current_scene(){return this.#Et}#zt=null;get entity_manager(){return this.#zt}constructor(t,e){this.scenes=new nf,this.#zt=t,this.clock=e,this.stack=[]}create(t){const e=new Sx(t);return this.add(e),e}add(t){if(this.exists(t.name))throw new Error(`Scene named '${t.name}' already exists`);this.scenes.add(t)}indexByName(t){const e=this.scenes.length;for(let i=0;i<e;i++)if(this.scenes.get(i).name===t)return i;return-1}getByName(t){return this.scenes.find((function(e){return e.name===t}))}remove(t){const e=this.indexByName(t);if(-1===e)return!1;const i=this.scenes.get(e);return this.#Et===i&&(this.deactivateCurrentScene(),this.#Et=null),this.scenes.remove(e),!0}clear(){return null!==this.#Et&&(this.#Et.active.set(!1),this.#zt.detachDataSet(),this.#Et=null),this}exists(t){return void 0!==this.getByName(t)}deactivateScene(t){if(t.active.getValue()){try{t.handlePreDeactivation()}catch(t){}t.active.set(!1),this.#zt.dataset===t.dataset&&this.#zt.detachDataSet(),t.speedModifiers.forEach((t=>this.clock.speed.removeModifier(t))),t.speedModifiers.on.added.remove(this.__handleSpeedModifierAdded,this),t.speedModifiers.on.removed.remove(this.__handleSpeedModifierRemoved,this);try{t.handlePostDeactivation()}catch(t){}}}activateScene(t){try{t.handlePreActivation()}catch(t){}this.#zt.attachDataSet(t.dataset),t.active.set(!0),t.speedModifiers.forEach((t=>this.clock.speed.addModifier(t))),t.speedModifiers.on.added.add(this.__handleSpeedModifierAdded,this),t.speedModifiers.on.removed.add(this.__handleSpeedModifierRemoved,this);try{t.handlePostActivation()}catch(t){}this.#Et=t}deactivateCurrentScene(){const t=this.#Et;null!==t&&this.deactivateScene(t)}__handleSpeedModifierAdded(t){this.clock.speed.addModifier(t)}__handleSpeedModifierRemoved(t){this.clock.speed.removeModifier(t)}set(t){const e=this.getByName(t);if(void 0===e)throw new Error(`Scene named '${t}' doesn't exist, valid options are: [${this.scenes.map((t=>t.name)).join(", ")}]`);if(this.#Et===e)return;const i=this.#zt;e.dataset.registerManyComponentTypes(i.getComponentTypeMap()),this.deactivateCurrentScene(),this.activateScene(e)}stackPush(t){this.stack.push(this.#Et.name),this.set(t)}stackPop(){const t=this.stack.pop();return this.set(t),t}stackDrop(){this.stack.splice(0,this.stack.length)}update(t){}}class Tx{constructor(t=1,e=0){this.a=t,this.b=e,this.source=0,this.transient=!1}copy(t){this.a=t.a,this.b=t.b,this.source=t.source,this.transient=t.transient}clone(){const t=new Tx;return t.copy(this),t}add(t){this.a+=t.a-1,this.b+=t.b}equals(t){return this.a===t.a&&this.b===t.b&&this.source===t.source&&this.transient===t.transient}hash(){return S(this.a)^S(this.b)^this.source^(this.transient?0:1)}toString(){return`LinearModifier{ a:${this.a}, b:${this.b} }`}toJSON(){return{a:this.a,b:this.b,source:this.source,transient:this.transient}}fromJSON({a:t=1,b:e=0,source:i=0,transient:n=!1}){this.a=t,this.b=e,this.source=i,this.transient=n}}Tx.CONSTANT_ONE=Object.freeze(new Tx(0,1)),Tx.CONSTANT_ZERO=Object.freeze(new Tx(0,0));class Ax extends Number{constructor(t){super(),this.id=0,this.base=new id(t),this.__modifiers=new nf,this.value=new id(t),this.base.onChanged.add(this.updateValue,this),this.postprocess=Ax.Process.NONE}get onModifierAdded(){return this.__modifiers.on.added}get onModifierRemoved(){return this.__modifiers.on.removed}resetModifiers(){this.__modifiers.reset()}valueOf(){return this.getValue()}toString(){return String(this.getValue())}getValue(){return this.value.x}updateValue(){const t=this.base.x,e=this.__modifiers,i=Ax.applyModifiers(t,e),n=this.postprocess(i);this.value.set(n)}getBaseValue(){return this.base.getValue()}setBaseValue(t){this.base.set(t)}getModifiers(){return this.__modifiers.data}addModifier(t){this.__modifiers.add(t),this.updateValue()}hasModifier(t){return this.__modifiers.contains(t)}removeModifier(t){const e=this.__modifiers.removeOneOf(t);return this.updateValue(),e}equals(t){return x(this.getValue(),t.getValue(),v)}copy(t){this.base.copy(t.base),this.__modifiers.copy(t.__modifiers),this.updateValue()}copyBase(t){this.base.copy(t.base)}setBaseFromParametricFunction(t,e){const i=t(e);this.base.set(i)}addNonTransientModifiersFromStat(t){const e=t.__modifiers.data,i=e.length;for(let t=0;t<i;t++){const i=e[t];if(i.transient)continue;const n=i.clone();this.addModifier(n)}}toJSON(){return{base:this.base.toJSON(),modifiers:this.__modifiers.toJSON()}}fromJSON(t){this.base.fromJSON(t.base),this.__modifiers.fromJSON(t.modifiers,Tx),this.updateValue()}get onChanged(){return this.value.onChanged}static applyModifiers(t,e){let i,n=1,s=0;const r=e.length,a=e.data;for(i=0;i<r;i++){const t=a[i];n+=t.a-1,s+=t.b}return t*n+s}}function Cx(t){const e=Hv(),i=(e-t.__lastMeasurement)*t.speed;t.__lastMeasurement=e,t.elapsedTime+=i}Ax.Process={ROUND_DOWN:function(t){return 0|t},NONE:function(t){return t},clampMin:function(t){return function(e){return bu(t,e)}},chain:function(...t){const e=t.length;return function(i){let n=i;for(let i=0;i<e;i++)n=(0,t[i])(n);return n}}},Ax.prototype.isStat=!0;class Ex{__lastMeasurement=0;elapsedTime=0;timeAtDelta=0;__isRunning=!1;speed=new Ax(1);constructor(){this.speed.postprocess=Ax.Process.clampMin(0)}set multiplier(t){this.speed.base.set(t)}get multiplier(){return this.speed.base.getValue()}start(){this.__lastMeasurement=Hv(),this.timeAtDelta=this.updateElapsedTime(),this.__isRunning=!0}stop(){this.__isRunning=!1}pause(){this.__isRunning=!1,Cx(this)}getDelta(){const t=this.updateElapsedTime(),e=t-this.timeAtDelta;return this.timeAtDelta=t,e}updateElapsedTime(){return this.__isRunning&&Cx(this),this.elapsedTime}getElapsedTime(){return this.elapsedTime}reset(){this.elapsedTime=0,this.timeAtDelta=0}}class zx{clock=new Ex;#It=!1;#Lt=-1;#Nt=-1;onTick=new _;get callbacks(){throw new Error("deprecated, use onTick signal instead")}constructor(){this.clock.pause()}subscribe(t,e){this.onTick.add(t,e)}unsubscribe(t,e){this.onTick.remove(t,e)}#Pt(){return-1!==this.#Nt&&-1!==this.#Lt}start({maxTimeout:t=100}={}){if(this.#Pt())throw new Error("Already running");this.#It=!0;const e=()=>{if(!this.#It)return;const t=this.clock.getDelta();this.onTick.send1(t)},i=()=>{cancelAnimationFrame(this.#Lt),s()},n=()=>{clearTimeout(this.#Nt),this.#Nt=setTimeout(s,0)},s=()=>{this.#Lt=requestAnimationFrame(n),e(),this.#Nt=setTimeout(i,t)};this.clock.getDelta(),this.clock.start(),requestAnimationFrame(n)}pause(){if(!this.#Pt())throw new Error("Not currently running");this.#It=!1}resume(){if(!this.#Pt())throw new Error("Not currently running");this.#It=!0}stop(){clearTimeout(this.#Nt),cancelAnimationFrame(this.#Lt),this.#It=!1,this.#Nt=-1,this.#Lt=-1}}class Ix{constructor(){let t=window.AudioContext||null;if(!t)throw new Error("AudioContext not supported!");const e=this.context=new t({latencyHint:"interactive"});e.suspend();const i=e.createGain(),n=e.createDynamicsCompressor();this.destination=i,i.connect(n),n.connect(e.destination),Object.defineProperties(this,{volume:{get:function(){return i.gain.value},set:function(t){i.gain.setValueAtTime(t,e.currentTime,0)}}})}getCurrentTime(){return this.context.currentTime}resumeContext(){return this.context.resume()}start(){return new Promise(((t,e)=>{this.resumeContext(),t()}))}}const Lx=[];let Nx=0;function Px(t,e,i){try{t.apply(e,i)}catch(t){}}function Dx(t,e){const i=t.length,n=Nx,s=n+i;let r,a;for(Nx=s,r=0;r<i;r++)Lx[n+r]=t[i-(r+1)];for(r=s-1;r>=n;r--){if(a=Lx[r],a.getFlag(1)){const e=t.indexOf(a);t.splice(e,1)}Px(a.handle,a.context,e)}Nx=n}class Fx{__state=-1;__eventHandlersStateEntry=[];__eventHandlersStateExit=[];constructor(t){this.description=t}addEventHandlerStateEntry(t,e,i){const n=this.__eventHandlersStateEntry[t],s=new m(e,i);void 0===n?this.__eventHandlersStateEntry[t]=[s]:n.push(s)}removeEventHandlerStateEntry(t,e,i){const n=this.__eventHandlersStateEntry[t];if(void 0!==n){const t=fx(n,e,i);if(-1!==t)return n.splice(t,1),!0}return!1}addEventHandlerStateExit(t,e,i){const n=this.__eventHandlersStateExit[t],s=new m(e,i);void 0===n?this.__eventHandlersStateExit[t]=[s]:n.push(s)}removeEventHandlerStateExit(t,e,i){const n=this.__eventHandlersStateExit[t];if(void 0!==n){const t=fx(n,e,i);if(-1!==t)return n.splice(t,1),!0}return!1}setState(t){const e=this.__state,i=this.__eventHandlersStateExit[e];void 0!==i&&Dx(i,[e,t]),this.__state=t;const n=this.__eventHandlersStateEntry[t];void 0!==n&&Dx(n,[t,e])}getState(){return this.__state}navigateTo(t){const e=this.getState();if(e===t)return;const i=this.description.findPath(e,t);if(null===i)throw new Error(`No path exists from current state '${e}' to target state '${t}'`);const n=i.length;for(let t=1;t<n;t++){const e=i[t];this.setState(e)}}advance(t,e=Mf){const i=this.description,n=i.__actions[this.__state];let s;if(void 0===n){const t=i.getOutgoingStates(this.__state);if(1!==t.length)return!1;s=t[0]}else s=n(t);return e(s,t),this.setState(s),!0}}const Ox=new class{constructor(){this.__states=new e_,this.__edges=[],this.__actions=[]}traverseStates(t,e){const i=this.__states;for(let n=i.nextSetBit(0);-1!==n;n=i.nextSetBit(n+1))t.call(e,n)}stateExists(t){return this.__states.get(t)}edgeExists(t,e){const i=this.__edges[t];return void 0!==i&&-1!==i.indexOf(e)}createState(t=this.__states.nextClearBit(0)){return this.__states.set(t,!0),t}createEdge(t,e){const i=this.__edges,n=i[t];void 0===n?i[t]=[e]:n.push(e)}setAction(t,e){this.__actions[t]=e}getOutgoingStates(t){const e=this.__edges[t];return void 0===e?[]:e}getIncomingStates(t){const e=[];for(let i in this.__edges){const n=parseInt(i);-1!==this.__edges[n].indexOf(t)&&e.push(n)}return e}findPath(t,e){const i=new Set;i.add(t);const n=new Set,s=new Map;function r(){const t=[];let i=e;do{t.unshift(i),i=s.get(i)}while(void 0!==i);return t}const a=this;function o(t){const e=a.getOutgoingStates(t),r=e.length;for(let a=0;a<r;a++){const r=e[a];n.has(r)||i.has(r)||(i.add(r),s.set(r,t))}}for(;i.size>0;){const t=i.values().next().value;if(t===e)return r();i.delete(t),n.add(t),o(t)}return null}};Ox.createState(0),Ox.createState(1),Ox.createState(2),Ox.createState(3),Ox.createEdge(0,1),Ox.createEdge(1,2),Ox.createEdge(2,1),Ox.createEdge(1,3),Ox.setAction(0,(()=>1)),Ox.setAction(1,(t=>t)),Ox.setAction(2,(()=>1));class Rx{constructor({priority:t=0}={}){this.sm=new Fx(Ox),this.sm.setState(0),this.priority=t}get state(){return this.sm.getState()}makeReady(){const t=this.sm.getState();if(1!==t){if(0!==t&&2!==t)throw new xu(`expected Initial(=0) or Active(=2) state, got ${t}`);this.sm.advance()}}makeActive(){const t=this.sm.getState();2!==t&&(1!==t&&this.makeReady(),this.sm.advance(2))}makeDestroyed(){const t=this.sm.getState();3!==t&&(1!==t&&this.makeReady(),this.sm.advance(3))}}function kx(t){const e=t%1;return e*Math.pow(10,2)>0&&Math.abs(t)<100?function(t,e){let i=t.length;for(;"0"===t.substring(i-1,i);)i-=1;return t.substring(0,i)}(t.toFixed(2)):function(t,e=","){return t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,e)}(t-e,",")}function Bx(t){return function(e){return e instanceof t}}function Ux(t){return function(e){return typeof e===t}}function Vx(t,e){let i=!1;function n(){i=!1,t.call(e)}return function(){i||(i=!0,requestAnimationFrame(n))}}function Wx(t){return"number"==typeof t?kx(t):t}function Gx(t){return kx(t)}function Hx(t){return Wx(t[0])+" / "+Wx(t[1])}function jx(t){return t.getValue()}function qx(t){return Yx.find((function(e){return e.matcher(t)}))}class Jx{constructor(t,e,i){this.matcher=t,this.extractor=e,this.formatter=i}}function $x(t,e,i){return new Jx(t,e,i)}const Yx=[$x(Bx(Dm),jx,Wx),$x(Bx(Hd),jx,Wx),$x(Bx(ad),jx,Wx),$x(Bx(Ry),(function(t){return[t.getValue(),t.getUpperLimit()]}),Hx),$x(Bx(Ax),jx,Gx),$x(Bx(id),jx,Gx),$x(Bx(Gd),jx,Gx),$x((Xx=i,Zx=Array.isArray,function(t){return Xx(t)||Zx(t)}),(function(t){return t.map((function(t){return(0,qx(t).extractor)(t)}))}),Hx),$x(Ux("number"),pv,Gx),$x(Ux("string"),pv,pv),$x(Ux("boolean"),pv,pv),$x(Ux("function"),(function(t){return t()}),Wx),$x(Ux("undefined"),pv,pv)];var Xx,Zx;class Kx extends Hg{constructor(t,{classList:e=[],transform:i=pv,format:n=Mf,tag:s="div",size:r,css:a}={}){super(),this.model=t;const o=qx(t),l=o.extractor,h=n!==Mf?n:o.formatter;this.__extractor=l,this.__formatter=h,this.__transform=i,this.el=document.createElement(s),this.el.classList.add("label");for(const t of e)this.el.classList.add(t);if(this.size.onChanged.add(this.updateSize,this),"object"==typeof this.model&&void 0!==this.model.onChanged){const t=Vx(this.updateTransform,this);this.bindSignal(this.model.onChanged,t)}void 0!==a&&this.css(a),void 0!==r&&this.size.fromJSON(r)}updateSize(t,e){this.el.style.lineHeight=e+"px"}updateText(t){this.el.textContent=t}updateTransform(){const t=this.model,e=this.__extractor(t),i=this.__transform(e),n=this.__formatter(i);this.updateText(n)}link(){super.link(),this.updateTransform()}}class Qx{pool=[];maxSize=256;constructor(t,e=Mf,i=Mf){this.creator=t,this.destroyer=e,this.resetter=i}get(){const t=this.pool;if(t.length>0){const e=t.pop();return this.resetter(e),e}return this.creator()}release(t){const e=this.pool;return e.length>=this.maxSize?(this.destroyer!==Mf&&this.destroyer(t),!1):(e.push(t),!0)}}function tw(t,e){const i=t.length;if(i!==e.length)return!1;let n=0;for(;n<i;n++){const i=t[n],s=e[n];if(i!==s){if(null==i||null==s)return!1;if("object"!=typeof i||"function"!=typeof i.equals)return!1;if(!i.equals(s))return!1}}return!0}function ew(t){return nd(rd(t.key),rd(t.value))}function iw(t,e){const i=t.key,n=e.key;if(i===n)return 0;const s=typeof i,r=typeof n,a=s.localeCompare(r);return 0!==a?a:"string"!==s?0:i.localeCompare(n)}Qx.prototype.create=Qx.prototype.get;class nw{constructor(){this.attributes=[],this.style=[],this.tag="",this.__hash=-1}setAttribute(t,e){const i=this.#Dt(t);if(void 0!==i){if(i.value===e)return;i.value=e}else this.attributes.push(new ty(t,e));this.update()}getAttribute(t){const e=this.#Dt(t);return void 0===e?null:e.value}#Dt(t){const e=this.attributes,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i.key===t)return i}}#Ft(){this.attributes.sort(iw),this.style.sort(iw)}update(){this.#Ft(),this.#Ot()}toJSON(){const t={},e=this.attributes.length;for(let i=0;i<e;i++){const e=this.attributes[i];t[e.key]=e.value}const i={},n=this.style.length;for(let t=0;t<n;t++){const e=this.style[t];i[e.key]=e.value}return{attributes:t,styles:i}}initializeFromElement(t){this.tag=t.tagName.toLowerCase();const e=t.classList.length;for(let i=0;i<e;i++)t.classList[i];let i=0;const n=t.style,s=n.length;for(let t=0;t<s;t++){const e=n.item(t),i=new ty(e,n.getPropertyValue(e));this.style[t]=i}this.style.splice(i,this.style.length-i);const r=t.getAttributeNames(),a=r.length;for(i=0;i<a;i++){const e=r[i],n=t.getAttribute(e),s=new ty(e,n);this.attributes[i]=s}this.attributes.splice(i,this.attributes.length-i),this.update()}#Ot(){const t=F_(this.style,ew),e=F_(this.attributes,ew),i=rd(this.tag);this.__hash=nd(t,e,i)}hash(){return this.__hash}equals(t){return this.tag===t.tag&&tw(this.style,t.style)&&tw(this.attributes,t.attributes)}reset(){const t=this.attributes;t.splice(0,t.length);const e=this.style;e.splice(0,e.length)}static fromElement(t){const e=new nw;return e.initializeFromElement(t),e}createElement(){const t=document.createElement(this.tag),e=this.style,i=e.length,n=t.style;for(let t=0;t<i;t++){const i=e[t];n.setProperty(i.key,i.value)}const s=this.attributes,r=s.length;for(let e=0;e<r;e++){const i=s[e];t.setAttribute(i.key,i.value)}return t}}const sw=new Qx((()=>new nw),Mf,(t=>{t.reset()})),rw=new class{onRemoved=new _;data=new qp;__first=null;__last=null;constructor({capacity:t=100,perKeyCapacity:e=10}={}){this.capacity=t,this.perKeyCapacity=e,this.size=0}get(t){const e=this.data.get(t);if(void 0===e)return;let i;return e.length>1?i=e.pop():(i=e[0],this.data.delete(t)),i.unlink(),this.size--,i.value}clear(){for(;null!==this.__first;)this.__removeElement(this.__first)}__removeElement(t){t===this.__first&&(this.__first=t.next),t===this.__last&&(this.__last=t.previous),t.unlink();const e=t.key,i=this.data.get(e),n=i.indexOf(t);i.splice(n,1),0===i.length&&this.data.delete(e),this.size--,this.onRemoved.send2(e,t.value)}add(t,e){let i=this.data.get(t);if(void 0===i)i=[],this.data.set(t,i);else if(i.length>=this.perKeyCapacity)return!1;this.size>=this.capacity&&this.__removeElement(this.__first);const n=new Xp;return n.value=e,n.key=t,n.previous=this.__last,null!==this.__last&&(this.__last.next=n),this.__last=n,null===this.__first&&(this.__first=n),i.push(n),this.size++,!0}}({capacity:500,perKeyCapacity:100});class aw extends Hg{constructor(t,{classList:e=[],attributes:i={}}={}){let n;super(),null==t?n="":"string"==typeof t?n=t:"object"==typeof t&&"function"==typeof t.getValue&&(n=t.getValue(),void 0!==t.onChanged&&this.bindSignal(t.onChanged,this.__setSource,this));const s=sw.create();s.tag="img",s.attributes=[new ty("src",n),new ty("class",e.join(" "))];for(const t in i){const e=String(i[t]),n=new ty(t,e);s.attributes.push(n)}s.update(),this.el=function(t){let e=rw.get(t);return void 0===e&&(e=t.createElement()),e}(s),sw.release(s);const r=e.length;for(let t=0;t<r;t++){const i=e[t];this.addClass(i)}this.size.onChanged.add(this.__setSize,this)}destroy(){super.destroy();const t=sw.create();t.initializeFromElement(this.el),rw.add(t,this.el)||sw.release(t)}__setSize(t,e){this.el.setAttribute("width",t),this.el.setAttribute("height",e)}__setSource(t){this.el.setAttribute("src",t)}}class ow extends Hg{constructor({tag:t="div",action:e,name:i,icon:n,classList:s=[],css:r}){if(super(),"function"!=typeof e)throw new Error("Action must be a function");const a=Ty(t);this.el=a.el;const o=Ty();o.addClass("foreground");const l=Ty();if(l.addClass("background"),a.append(o),a.append(l),a.addClass("ui-button-view"),void 0!==r&&this.css(r),this.addClasses(s),this.el.addEventListener("click",(t=>{if(this.__enabled){const i=e(t);i instanceof Promise&&(this.enabled=!1,i.finally((()=>{this.enabled=!0})))}})),void 0!==i){const t=new Kx(i);this.addChild(t),this.size.onChanged.add((function(e,i){t.size.set(e,i)}))}if(null!=n){const t=new aw(n);this.addChild(t)}this.__enabled=!0}set enabled(t){this.__enabled!==t&&(this.__enabled=t,this.setClass("enabled",t),this.setClass("disabled",!t))}get enabled(){return this.__enabled}}class lw extends Hg{constructor(t,e){super();const i=Ty("div").addClass("ui-confirmation-dialog-view");this.el=i.el;const n=new jg({classList:["content-container"]});n.addChild(t),this.addChild(n);const s=new jg({classList:["button-area"]}),r=e.length;for(let t=0;t<r;t++){const i=e[t],n="button-"+i.name.replace(" ","-"),r=i.displayName,a=new ow({name:r,action:function(t){t.stopPropagation(),i.callback(t)},classList:[n,"ui-confirmation-dialog-button","ui-button-rectangular"]}),o=i.enabled;if(void 0!==o){const t=()=>a.enabled=o.getValue();a.on.linked.add(t),a.bindSignal(o.onChanged,t)}a.size.set(115,36),s.addChild(a)}this.addChild(s)}}class hw{constructor({el:t,dragStart:e=Mf,drag:i=Mf,dragEnd:n=Mf,stopPropagation:s=!0}){this.pointerLocal=new tx(t);const r=this.pointerGlobal=new tx(window),a=new Eu,o=new Eu;s&&this.pointerLocal.on.down.add(((t,e)=>{e.stopPropagation()})),this.pointerLocal.on.dragStart.add((t=>{a.copy(t),o.copy(t),r.start(),e(t),r.on.up.add((function t(e){r.on.up.remove(t),r.stop(),n(e,a)}))})),this.pointerGlobal.on.move.add(((t,e,n)=>{i(t,a,n)}))}getPointer(){return this.pointerLocal}start(){this.pointerLocal.start()}stop(){this.pointerLocal.stop(),this.pointerGlobal.stop()}}class cw extends Hg{constructor(t,e){super(t,e);const i=Ty("div").addClass("ui-element-window");this.el=i.el,t.addClass("content"),this.addChild(t);const n=e.closeAction;!1!==e.closeable&&"function"==typeof n&&function(t,e){const i=document.createElement("div");i.classList.add("button-close"),t.el.appendChild(i);const n=document.createElement("div");n.classList.add("icon"),i.appendChild(n),i.addEventListener("click",e)}(this,n),this.title=new Hd(e.title);const s=new Kx(this.title,{classList:["title"]});this.addChild(s),e.draggable&&function(t,e){let i=null;new hw({el:e,drag(e,n){const s=e.clone().sub(n);t.position.copy(i.clone().add(s))},dragStart(){i=t.position.clone()}}).start()}(this,s.el),e.resizable&&function(t){const e=new tx(window),i=new tx(t.el);i.start();let n=null;e.on.move.add((function(e){const i=e.clone().sub(n);t.size.add(i)})),e.on.up.add((function(){e.stop()})),i.on.down.add((function(i){const s=t.size.clone().sub(i.clone().sub(t.position));s.x<10&&s.x>0&&s.y<10&&s.y>0&&(n=i.clone(),e.start())}))}(this),this.content=t}}function uw(t,e,i,n){return e>=i&&n>=t}class dw{constructor(t=0,e=0,i=0,n=0){this.position=new Eu(t,e),this.size=new Eu(i,n)}get x0(){return this.position.x}get x1(){return this.position.x+this.size.x}get y0(){return this.position.y}get y1(){return this.position.y+this.size.y}set(t,e,i,n){this.size.set(i,n),this.position.set(t,e)}clone(){const t=this.position,e=this.size;return new dw(t.x,t.y,e.x,e.y)}copy(t){this.position.copy(t.position),this.size.copy(t.size)}_intersects(t,e,i,n){const s=this.position,r=this.size,a=s.x,o=s.y;return uw(t,i,a,r.x+a)&&uw(e,n,o,o+r.y)}intersects(t){const e=t.position.x,i=t.position.y,n=t.size.y+i,s=t.size.x+e;return this._intersects(e,i,s,n)}_overlaps(t,e,i,n){const s=this.position,r=this.size,a=s.x,o=s.y;return Ud(a,o,r.x+a,o+r.y,t,e,i,n)}overlaps(t){const e=t.position.x,i=t.position.y,n=t.size.y+i,s=t.size.x+e;return this._overlaps(e,i,s,n)}_resizeToFit(t,e,i,n){const s=this.size,r=this.position.x,a=this.position.y;let o=s.y+a,l=s.x+r;Number.isNaN(l)&&(l=-Infinity),Number.isNaN(o)&&(o=-Infinity);const h=Su(t,r),c=Su(e,a),u=bu(i,l),d=bu(n,o);this.position.set(h,c),s.set(u-h,d-c)}resizeToFit(t){const e=t.position.x,i=t.position.y,n=t.size.y+i,s=t.size.x+e;return this._resizeToFit(e,i,s,n)}_contains(t,e,i,n){const s=this.size,r=this.position,a=r.x,o=r.y,l=s.y+o;return function(t,e,i,n,s,r,a,o){return s>=t&&a<=i&&r>=e&&o<=n}(a,o,s.x+a,l,t,e,i,n)}contains(t){const e=t.position.x,i=t.position.y,n=t.size.y+i,s=t.size.x+e;return this._contains(e,i,s,n)}computeCenter(t){const e=this.position,i=this.size,n=e.x+i.x/2,s=e.y+i.y/2;t.set(n,s)}computeArea(){return this.size.x*this.size.y}toArray(t,e=0){t[e]=this.position.x,t[e+1]=this.position.y,t[e+2]=this.size.x,t[e+3]=this.size.y}toJSON(){return{position:this.position.toJSON(),size:this.size.toJSON()}}fromJSON(t){this.position.fromJSON(t.position),this.size.fromJSON(t.size)}}dw.prototype.isRectangle=!0;class pw{constructor(t,e,i,n=[]){this.target=t,this.factory=e,this.factoryContext=i,this.obstracles=n,this.view=null}}function fw(t,e,i){const n=t.getBoundingClientRect();if(n.left<i.x0&&(i.x0=n.left),n.right>i.x1&&(i.x1=n.right),n.top<i.y0&&(i.y0=n.top),n.bottom>i.y1&&(i.y1=n.bottom),e>0){const n=t.children;for(let t=0,s=n.length;t<s;t++)fw(n[t],e-1,i)}}const mw=new Gg;class _w{constructor({depth:t=0}={}){this.dimensions=new dw,this.__depth=t,this.element=null,this.running=!1,this.__dom_resize_observer=new ResizeObserver(this.__dom_resize_observer_callback.bind(this))}__dom_resize_observer_callback(t,e){const i=t[0].contentRect;mw.setNegativelyInfiniteBounds(),fw(this.element,this.__depth,mw);const n=this.dimensions;n.position.set(mw.x0,mw.y0),n.size.set(i.width,i.height)}synchronize(){mw.setNegativelyInfiniteBounds(),fw(this.element,this.__depth,mw);const t=this.dimensions;t.position.set(mw.x0,mw.y0),t.size.set(mw.getWidth(),mw.getHeight())}start(){this.running||(this.running=!0,this.synchronize(),null!==this.element&&this.__dom_resize_observer.observe(this.element))}attach(t){this.element=t,this.running&&this.__dom_resize_observer.unobserve(this.element)}stop(){this.running&&(this.running=!1,null!==this.element&&this.__dom_resize_observer.unobserve(this.element))}watchView(t){this.attach(t.el),t.on.linked.add(this.start,this),t.on.unlinked.add(this.stop,this)}unwatchView(t){t.on.linked.remove(this.start,this),t.on.unlinked.remove(this.stop,this)}}class gw{constructor(t,e,i){this.view=t,this.factory=e;const n=new dw;this.tipTargetRectangle=n,this.tip=new pw(n,e,i),this.on={entered:new _,exited:new _};const s=this.isEntered=new Dm(!1),r=new _w;this.sizeObserver=r,this.bindings=[new Mm(t.position.onChanged,this.__copyDimensions,this),new Mm(t.size.onChanged,this.__copyDimensions,this),new Mm(r.dimensions.position.onChanged,this.__copyDimensionsFromBoundingRect,this),new Mm(r.dimensions.size.onChanged,this.__copyDimensionsFromBoundingRect,this)],this.handleMouseEnter=()=>{s.set(!0),this.on.entered.send0(),r.attach(t.el),r.start()},this.handleMouseLeave=()=>{s.set(!1),r.stop(),this.on.exited.send0()}}__copyDimensionsFromBoundingRect(){const t=this.sizeObserver.dimensions;this.tipTargetRectangle.copy(t)}__copyDimensions(){const t=this.view,e=t.position,i=t.scale,n=t.size,s=this.tipTargetRectangle;s.position.set(e.x,e.y),s.size.set(n.x*i.x,n.y*i.y)}__handleViewLinked(){const t=this.view.el;t.style.pointerEvents="auto",t.addEventListener(qv,this.handleMouseEnter),t.addEventListener(Jv,this.handleMouseLeave);const e=this.bindings,i=e.length;for(let t=0;t<i;t++)e[t].link();this.__copyDimensions()}__handleViewUnlinked(){const t=this.view.el;t.removeEventListener(qv,this.handleMouseEnter),t.removeEventListener(Jv,this.handleMouseLeave);const e=this.bindings,i=e.length;for(let t=0;t<i;t++)e[t].unlink();this.isEntered.getValue()&&this.handleMouseLeave()}link(){const t=this.view;t.isLinked&&this.__handleViewLinked(),t.on.linked.add(this.__handleViewLinked,this),t.on.unlinked.add(this.__handleViewUnlinked,this)}unlink(){const t=this.view;t.isLinked&&this.__handleViewUnlinked(),t.on.linked.remove(this.__handleViewLinked,this),t.on.unlinked.remove(this.__handleViewUnlinked,this)}}class yw{constructor(t){this.tipManager=t,this.live=new WeakMap,this.__showDelay=128,this.__showDelayTimeout=-1}getTipManager(){return this.tipManager}show(t){const e=t.tip;this.tipManager.add(e)}hide(t){const e=t.tip;this.tipManager.remove(e)}updatePositions(){const t=this.tipManager;t.tips.forEach((e=>{t.positionTip(e.view)}))}updateTip(t){const e=this.live.get(t);if(void 0===e)return!1;e.isEntered.getValue()&&(this.hide(e),this.show(e))}manage(t,e,i){t.on.linked.add((()=>{this.add(t,e,i)})),t.on.unlinked.add((()=>{this.remove(t)}))}requestShow(t){this.cancelShowRequest(),this.__showDelayTimeout=setTimeout((()=>{this.show(t)}),this.__showDelay)}cancelShowRequest(){-1!==this.__showDelayTimeout&&(clearTimeout(this.__showDelayTimeout),this.__showDelayTimeout=-1)}initializeHide(t){this.cancelShowRequest(),this.hide(t)}add(t,e,i){const n=new gw(t,e,i);this.live.set(t,n),n.on.entered.add((()=>{this.requestShow(n)})),n.on.exited.add((()=>{this.initializeHide(n)})),n.link()}remove(t){const e=this.live.get(t);void 0!==e&&(this.hide(e),this.live.delete(t),e.unlink())}}class vw{#Rt=new Zp({maxWeight:1048576,keyWeigher:af,valueWeigher:t=>256*t.length,keyHashFunction:rd,keyEqualityFunction:Yp});parse(t){return this.#Rt.getOrCompute(t,cy)}}class xw{constructor(){this.enableTooltips=!0}}class ww{constructor(){this.database=null,this.localization=null,this.tooltips=null,this.__recursionCount=0,this.__recursionReferencePath=[],this.__contextStack=[],this.__tooltipsEnabled=!0,this.__reference_compilers_visual=new Map,this.__reference_compilers_text=new Map,this.__parser=new vw}addReferenceCompilerVisual(t,e){return!this.__reference_compilers_visual.has(t)&&(this.__reference_compilers_visual.set(t,e),!0)}removeReferenceCompilerVisual(t){return!!this.__reference_compilers_visual.has(t)&&(this.__reference_compilers_visual.delete(t),!0)}addReferenceCompilerText(t,e){return!this.__reference_compilers_text.has(t)&&(this.__reference_compilers_text.set(t,e),!0)}removeReferenceCompilerText(t){return!!this.__reference_compilers_text.has(t)&&(this.__reference_compilers_text.delete(t),!0)}getTooltipsEnabled(){return this.__tooltipsEnabled}setTooltipsEnabled(t){this.__tooltipsEnabled=t}initialize(t,e){this.database=t,this.localization=e}startup(){const t=this;return new Promise((function(e,i){if(null===t.database)throw new Error("Database not set; probably not initialized");t.database.promise().then(e,i)}))}getReferenceDepth(t){let e=0;const i=this.__recursionReferencePath,n=i.length;for(let s=0;s<n;s++)i[s].type===t&&e++;return e}compileTokensToText(t){const e=this.database,i=this.localization,n=this.tooltips,s=this;return t.map((t=>{let r;const a=t.type;if(a===Zg.Reference)r=function(t){const r=t.value,a=r.type.toLocaleLowerCase(),o=s.__reference_compilers_text.get(a);if(void 0===o)return;let l;s.__recursionReferencePath.push(r);try{l=o.compile(r.values,e,i,s,n)}catch(t){l="ERROR"}return s.__recursionReferencePath.pop(),l}(t);else if(a===Zg.Text)r=t.value;else if(a===Zg.StyleStart);else if(a!==Zg.StyleEnd)throw new TypeError(`Unsupported token type '${a}'`);return r})).filter((t=>void 0!==t)).join("")}compileTokensToVisual(t,e=new jg({tag:"span"})){const i=this.database,n=this.localization,s=this.tooltips,r=this;function a(t,e){const i=t.value,n=new Kx(i,{tag:"span"});e.push(n)}function o(t,e){const a=t.value,o=a.type.toLocaleLowerCase(),l=r.__reference_compilers_visual.get(o);if(void 0===l)return;let h;r.__recursionReferencePath.push(a);try{h=l.compile(a.values,i,n,r,s)}catch(t){h=new Kx("ERROR")}r.__recursionReferencePath.pop(),h.addClass("reference-type-"+o),e.push(h)}const l=[];let h=e;function c(){const t=new jg({tag:"span"});return l.forEach((e=>t.addClass(e))),t}function u(t){l.push(t);const i=c();e.addChild(i),h=i}function d(t){const i=l.indexOf(t);if(-1!==i)if(l.splice(i,1),0===l.length)h=e;else{const t=c();e.addChild(t),h=t}}const p=t.length;for(let e=0;e<p;e++){let i=t[e];const n=[],s=i.type;if(s===Zg.Reference)o(i,n);else if(s===Zg.Text)a(i,n);else if(s===Zg.StyleStart)u(i.value);else{if(s!==Zg.StyleEnd)throw new TypeError(`Unsupported token type '${s}'`);d(i.value)}const r=n.length;for(let t=0;t<r;t++){const e=n[t];h.addChild(e)}}return e}pushState(){const t=new xw;t.enableTooltips=this.__tooltipsEnabled,this.__contextStack.push(t)}popState(){const t=this.__contextStack.pop();this.__tooltipsEnabled=t.enableTooltips}compileAsText(t){if(this.__recursionCount>=50)return"";this.__recursionCount++,this.pushState();try{const e=this.__parser.parse(t);return this.compileTokensToText(e)}finally{this.popState(),this.__recursionCount--}}compile(t,e){if(this.__recursionCount>=50)return new jg;this.__recursionCount++,this.pushState();try{const i=this.__parser.parse(t);return this.compileTokensToVisual(i,e)}finally{this.popState(),this.__recursionCount--}}compile_localized(t,e,i){const n=this.localization.getString(t,i);return this.compile(n,e)}}function bw(t,e,i,n){let s=0;if(n-i>=e-t)t<i?s=i-t:e>n&&(s=n-e);else{const r=t-i,a=n-e;r>0&&r<a?s=-r:a>0&&(s=a)}return s}function Sw(t,e){const i=bw(e.x0,e.x1,t.x0,t.x1),n=bw(e.y0,e.y1,t.y0,t.y1);e.move(i,n)}function Mw(t,e){const i=e.length;for(let e=0;e<i;e++)t[e].set(0,0);let n=0;for(let s=0;s<i-1;s++){const r=e[s],a=r.x1,o=r.y1;for(let l=s+1;l<i;l++){const i=e[l],h=a-i.x0;if(h<0)continue;const c=i.x1-r.x0;if(c<0)continue;const u=o-i.y0;if(u<0)continue;const d=i.y1-r.y0;if(d<0)continue;let p=h<c?-h:c,f=u<d?-u:d;Math.abs(p)<Math.abs(f)?f=0:p=0;const m=new Eu(p,f),_=m.multiplyScalar(.5),g=t[s],y=t[l];!0===r.locked&&!0===i.locked||(!0===r.locked?y.sub(m):!0===i.locked?g.add(m):(g.add(_),y.sub(_)),n++)}}for(let n=0;n<i;n++){const i=e[n],s=t[n],r=s.x,a=s.y;i.move(r,a)}return n}var Tw=function(t){return document.createElementNS("http://www.w3.org/2000/svg",t)};class Aw extends Hg{constructor(){super();const t=Tw("svg"),e=Tw("defs"),i=Tw("linearGradient");i.setAttribute("id","gradient"),e.appendChild(i);const n=Tw("stop"),s=Tw("stop");n.setAttribute("offset","50%"),s.setAttribute("offset","100%"),n.classList.add("color-stop-0"),s.classList.add("color-stop-1"),i.appendChild(n),i.appendChild(s),t.appendChild(e),t.classList.add("compass"),t.setAttribute("width",28),t.setAttribute("height",24);const r=Tw("polygon");r.setAttribute("points","28,12 0,24 0,0"),r.classList.add("compass-triangle"),t.appendChild(r);const a=12*Math.SQRT2;t.style.transformOrigin=`${a}px 12px`,t.style.top="-12px",t.style.left=`-${a}px`,this.el=t}rotateFromDirectionVector(t,e){const i=Math.atan2(e,t);this.rotation.set(i)}}class Cw extends Hg{constructor(t,e){super(),this.model=t,this.el=document.createElement("div"),this.addClass("tooltip-view");const i=new jg({classList:["contents"]});this.addChild(i),i.addChild(e),this.contentView=i;const n=new Aw;this.addChild(n),this.compass=n}layout(t){const e=function(t){const e=t.getBoundingClientRect();let i=e.left,n=e.top,s=e.right,r=e.bottom;return Number.isNaN(s)&&(s=i),Number.isNaN(r)&&(r=n),new Gg(i,n,s,r)}(this.contentView.el);e.grow(16);const i=function(t){const e=t.position,i=e.x,n=e.y,s=t.size;let r=i,a=n;return s.x>0&&(r+=s.x),s.y>0&&(a+=s.y),new Gg(i,n,r,a)}(this.model.target),n=function(t,e,i){const n=t.clone(),s=e.clone(),r=(i.height+n.height)/2,a=(i.width+n.width)/2;n.set(a,r,a+n.width,r+n.height),new Eu(s.centerX,s.centerY),s.locked=!0;const o=function(t,e,i){const n=[Eu.up,Eu.right,Eu.down,Eu.left],s=e.getCenter(),r=e.getHeight(),a=e.getWidth(),o=Math.sqrt(r*r+a*a),l=t.getWidth(),h=t.getHeight(),c=l/2,u=h/2,d=new Eu,p=n.map((function(t){const i=t.clone()._multiply(1,-1),n=i.clone();n.multiplyScalar(o+1),n.add(s),e.lineIntersectionPoint(s,n,d);const r=new Eu(c,u);return r.multiply(i),r._sub(c,u),r.add(d),r})),f=p.map((function(t){const n=new Gg,s=t.x,r=s+l,a=t.y,o=a+h;r<=e.x0?n.set(i.x0,i.y0,e.x0,i.y1):s>=e.x1?n.set(e.x1,i.y0,i.x1,i.y1):o<=e.y0?n.set(i.x0,i.y0,i.x1,e.y0):a>=e.y1&&n.set(i.x0,e.y1,i.x1,i.y1);let c=0;const u=n.getWidth();return n.getHeight()-h<0&&c--,u-l<0&&c--,c}));let m=0,_=f[0];for(let t=1;t<f.length;t++){const e=f[t];e>_+v&&(_=e,m=t)}return p[m]}(n,s,i);n.set(o.x,o.y,o.x+n.width,o.y+n.height);for(let t=0;t<5;t++)!function(t,e,i,n){const s=.1*(e-t.centerX),r=.1*(i-t.centerY);t.move(s,r)}(n,o.x+n.width/2,o.y+n.height/2),function(t,e=3){const i=[],n=t.length;for(let t=0;t<n;t++)i.push(new Eu(0,0));let s=-1,r=e;for(;r>0&&0!==s;)r--,s=Mw(i,t)}([n,s],10),function(t,e){for(let i=0,n=e.length;i<n;i++){const n=e[i];!0!==n.locked&&Sw(t,n)}}(i,[n]);return t.copy(n),t}(e,i,t);n.shrink(16);const s=this.compass;!function(){const t=i.getCenter(),e=new Eu;n.computeNearestPointToPoint(t,e),s.rotateFromDirectionVector(t.x-e.x,t.y-e.y),s.position.copy(e)._add(-n.x0,-n.y0)}(),this.position.set(n.x0,n.y0)}}class Ew{constructor(){this.gml=null,this.contextView=new jg,this.contextView.addClass("ui-tooltip-manager-context"),this.pointer=null;const t=this;this.updateTask=new Cf({name:"Update Tooltip Cursor",cycleFunction:function(){const e=t.pointer.position;return t.update(e.x,e.y),3}}),this.executor=new vy(500,1e-5),this.tips=new nf}getGML(){return this.gml}initialize(t,e){this.gml=t,this.pointer=e,this.signalBindings=[]}startup(){const t=this;return new Promise((function(e,i){if(null===t.database)throw new Error("Database not set; probably not initialized");if(null===t.contextView)throw new Error("ContextView not set; probably not initialized");t.signalBindings.forEach((t=>t.link())),t.executor.run(t.updateTask),t.gml.startup().then(e,i)}))}shutdown(){const t=this;return new Promise((function(e,i){t.signalBindings.forEach((t=>t.unlink())),t.executor.removeTask(t.updateTask),e()}))}update(){}buildTipView(t){const e=this.getGML();e.pushState(),e.setTooltipsEnabled(!1);const i=t.factory.call(t.factoryContext);let n;if(e.popState(),"object"==typeof i)n=i;else{const t=i.toString();n=this.gml.compile(t)}const s=new Cw(t,n);t.view=s;const r=Vx((()=>{this.positionTip(s)}));return s.bindSignal(t.target.position.onChanged,r),s.bindSignal(t.target.size.onChanged,r),s}add(t){const e=this.contextView,i=this.buildTipView(t);i.css({opacity:0}),requestAnimationFrame((()=>{this.positionTip(i),i.css({opacity:1})})),e.addChild(i),this.tips.add(t)}contains(t){return this.tips.contains(t)}remove(t){this.tips.removeOneOf(t)&&(this.contextView.removeChild(t.view),t.view=null)}positionTip(t){if(null===t)return;const e=this.contextView,i=new Gg(0,0,e.size.x,e.size.y);t.layout(i)}}class zw{constructor(t){this.properties=t,this.propertyCount=t.length,this.keyValues=[],this.keyTimes=[],this.timeStart=Number.POSITIVE_INFINITY,this.timeEnd=Number.NEGATIVE_INFINITY,this.transitionKeys=[],this.transitionFunctions=[]}optimize(){const t=this.keyValues.length,e=this.keyTimes.length,i=new ArrayBuffer(4*e+8*t),n=new Float32Array(i,0,e),s=new Float64Array(i,4*e,t);s.set(this.keyValues,0),this.keyValues=s,n.set(this.keyTimes,0),this.keyTimes=n}addKey(t,e){if(e.length!==this.propertyCount)throw new Error("Number of supplied values("+e.length+") does not match number of track properties("+this.propertyCount+")");if(0===this.keyTimes.length)this.timeStart=t;else{if(t<this.timeEnd)throw new Error("Attempted to insert key in the past. Keys must be sequential");if(t===this.timeEnd)throw new Error("Attempted to insert key at the same time as already existing key")}this.timeEnd=t,Array.prototype.push.apply(this.keyValues,e),this.keyTimes.push(t)}addTransition(t,e){this.transitionKeys.push(t),this.transitionFunctions.push(e)}keyLowerBoundIndexAt(t){const e=this.keyTimes,i=e.length;for(let n=0,s=i;n<s;n++)if(e[n]>t)return n-1;return i-1}transitionIndexAt(t){const e=this.transitionKeys,i=e.length,n=this.keyTimes;for(let s=0,r=i;s<r;s++){const i=e[s];if(!(n[i+1]<t))return n[i]<=t?s:-1}return-1}readKeyValues(t,e){const i=this.propertyCount,n=i*t,s=this.keyValues;for(let t=0;t<i;t++)e[t]=s[t+n]}}class Iw{constructor(t,e,i){this.track=t,this.position=t.timeStart,this.updateCallback=e,this.updateTraget=i,this.__lastKeyIndex=0,this.__lastTransitionIndex=0,this.__nextKeyIndex=0,this.__nextKeyTime=0,this.__loop=!1,this.__valueBuffer=new Float64Array(t.propertyCount),this.on={ended:new _},this.setPosition(0)}promiseEnded(){return this.position>=this.track.timeEnd?Promise.resolve():new Promise(((t,e)=>{this.on.ended.add(t)}))}setLoop(t){this.__loop=t}reset(){this.setPosition(this.track.timeStart)}setPosition(t){this.position=t;const e=this.track,i=e.transitionIndexAt(t);this.__lastTransitionIndex=i,this.__lastKeyIndex=-1!==i?e.transitionKeys[i]:e.keyLowerBoundIndexAt(t);const n=e.keyTimes.length;this.__nextKeyIndex=n>1?Su(this.__lastKeyIndex+1,n-1):this.__lastKeyIndex,this.__nextKeyTime=e.keyTimes[this.__nextKeyIndex]}advanceKey(){const t=this.track,e=t.keyTimes.length;if(this.__lastKeyIndex===e-1){if(!this.__loop)return this.__lastTransitionIndex=-1,this.on.ended.dispatch(),!1;this.__lastKeyIndex=-1}this.__lastKeyIndex=this.__lastKeyIndex+1,this.__nextKeyTime=t.keyTimes[Math.min(this.__lastKeyIndex+1,e-1)];const i=t.transitionKeys,n=i.length;for(let t=this.__lastTransitionIndex+1;t<n;t++){const e=i[t];if(e===this.__lastKeyIndex){this.__lastTransitionIndex=t;break}if(e>this.__lastKeyIndex){this.__lastTransitionIndex=-1;break}}return!0}advance(t){let e=this.position+t;t<0?this.setPosition(e):e>this.__nextKeyTime?(e>=this.track.timeEnd&&(this.__loop?e%=this.track.timeEnd:this.on.ended.dispatch()),this.setPosition(e)):this.position=e,this.update()}update(){this.readCurrentValues(this.__valueBuffer),this.updateCallback.apply(this.updateTraget,this.__valueBuffer)}readCurrentValues(t){const e=this.track,i=this.__lastKeyIndex;if(-1!==this.__lastTransitionIndex){const n=this.__nextKeyTime,s=e.keyTimes[i],r=n-s,a=(this.position-s)/r,o=(0,e.transitionFunctions[this.__lastTransitionIndex])(a),l=e.propertyCount,h=e.keyValues,c=i*l,u=c+l;for(let e=0;e<l;e++){const i=h[e+c],n=o*(h[e+u]-i)+i;t[e]=n}}else e.readKeyValues(i,t)}}const Lw={Initial:0,Running:1,Succeeded:2,Failed:3,Suspended:4,Invalid:5};class Nw{context=null;onInitialized=new _;onFinalized=new _;tick(t){throw new Error("Abstract method, needs to be overridden")}initialize(t){this.context=t,this.onInitialized.send2(this,t)}finalize(){this.onFinalized.send1(this)}}Nw.prototype.isBehavior=!0,Nw.typeName="Behavior";class Pw extends Nw{constructor(){super(),this.__source=null}getSource(){return this.__source}setSource(t){this.__source=t}initialize(t){this.__source.initialize(t),super.initialize(t)}finalize(){this.__source.finalize(),super.finalize()}}Pw.prototype.isDecoratorBehavior=!0;class Dw extends Pw{constructor(t,e=Infinity){super(),this.limit=e,this.__iterator=0,this.setSource(t)}setCount(t){this.limit=t}getCount(){return this.limit}static from(t,e=Infinity){return new Dw(t,e)}initialize(t){this.__iterator=0,super.initialize(t)}tick(t){const e=this.__source,i=e.tick(t);return i!==Lw.Succeeded&&i!==Lw.Failed?i:(this.__iterator++,this.__iterator>=this.limit?Lw.Succeeded:(e.initialize(this.context),Lw.Running))}}Dw.typeName="RepeatBehavior";class Fw extends Nw{constructor(t,e){super(),this.__action=t,this.__context=void 0===e?this:e}tick(t){try{return this.__action.call(this.__context,t,this.context),Lw.Succeeded}catch(t){return Lw.Failed}}}class Ow extends Nw{constructor(){super(),this.__children=[]}addChild(t){this.__children.push(t)}addChildren(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];this.addChild(e)}}getChildren(){return this.__children}removeChild(t){const e=this.__children.indexOf(t);return-1!==e&&(this.__children.splice(e,1),!0)}clearChildren(){this.__children=[]}}Ow.prototype.isCompositeBehavior=!0;class Rw extends Ow{constructor(){super(),this.__currentBehaviourIndex=-1,this.__currentBehaviourState=Lw.Initial,this.__currentBehaviour=void 0}initialize(t){this.__currentBehaviourIndex=0,this.__currentBehaviour=this.__children[0],this.__currentBehaviour.initialize(t),this.__currentBehaviourState=Lw.Running,super.initialize(t)}tick(t){const e=this.__currentBehaviour,i=e.tick(t);return this.__currentBehaviourState=i,i!==Lw.Succeeded?i:(e.finalize(),this.__currentBehaviourState=Lw.Initial,this.__currentBehaviourIndex++,this.__currentBehaviourIndex<this.__children.length?(this.__currentBehaviour=this.__children[this.__currentBehaviourIndex],this.__currentBehaviour.initialize(this.context),this.__currentBehaviourState=Lw.Running,Lw.Running):Lw.Succeeded)}finalize(){const t=this.__children.length;this.__currentBehaviourIndex!==t&&void 0!==this.__currentBehaviour&&this.__currentBehaviourState!==Lw.Initial&&this.__currentBehaviour.finalize(),this.__currentBehaviour=void 0,this.__currentBehaviourIndex=t,super.finalize()}static from(t){const e=new Rw;return e.addChildren(t),e}}Rw.prototype.isSequenceBehavior=!0,Rw.typeName="SequenceBehavior";class kw{constructor(){this.clock=0,this.flags=0,this.__behavior=null}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}get behavior(){return this.__behavior}set behavior(t){this.__behavior=t}get list(){return null!==this.__behavior?[this.__behavior]:[]}set list(t){t.length>1?this.__behavior=Rw.from(t):1===t.length?this.__behavior=t[0]:this.__behavior=null}static looping_function(t,e){return kw.fromOne(Dw.from(new Fw(t,e)))}static fromOne(t){const e=new kw;return e.__behavior=t,e}}kw.serializable=!0,kw.typeName="BehaviorComponent";class Bw extends Nw{constructor(t){super(),this.animation=t}tick(t){return this.animation.advance(t),this.animation.position>=this.animation.track.timeEnd&&!this.animation.loop?Lw.Succeeded:Lw.Running}initialize(){this.animation.setPosition(this.animation.track.timeStart)}}const Uw=function(t){return t},Vw=function(t){return t*t},Ww=function(t){return-t*(t-2)};function Gw(t,i,n=Gw,s=null){if(t===i)return!0;const r=typeof t;if(r!==typeof i)return!1;if("object"!==r)return!1;if(null===t||null===i)return!1;if(Array.isArray(t))return!!Array.isArray(i)&&rg(t,i,n,s);if("function"==typeof t.equals&&"function"==typeof i.equals)return t.equals(i);const a=Object.keys(t),o=Object.keys(i);if(a.sort(),o.sort(),!e(a,o))return!1;const l=a.length;for(let e=0;e<l;e++){const r=a[e],o=t[r],l=i[r];if(!n.call(s,o,l))return!1}return!0}class Hw{view=null;klass=null;parameters={};anchor=new Eu(0,0);group=null;flags=1;visible=new Dm(!0);setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}equals(t){return!(this.flags!==t.flags||this.klass!==t.klass||!this.getFlag(1)&&this.view!==t.view||!this.anchor.equals(t.anchor)||this.group!==t.group||!this.visible.equals(t.visible)||!Gw(this.parameters,t.parameters))}hash(){return nd(this.flags,rd(this.klass),this.anchor.hash(),rd(this.group),this.visible.hashCode())}static fromView(t){const e=new Hw;return e.clearFlag(1),e.view=t,e}static fromJSON(t){const e=new Hw;return e.fromJSON(t),e}fromJSON({klass:t,parameters:e={},anchor:i=Eu.zero,group:n=null,visible:s=!0}){if(null!==n&&"string"!=typeof n)throw new Error(`Expected group to be null or string, instead was '${typeof n}'`);this.klass=t,this.parameters=e,this.anchor.fromJSON(i),this.group=n,this.visible.set(s)}toJSON(){return{klass:this.klass,parameters:this.parameters,anchor:this.anchor.toJSON(),group:this.group,visible:this.visible.toJSON()}}}Hw.typeName="GUIElement",Hw.serializable=!0;class jw{position=new Eu;offset=new Eu;anchor=new Eu(0,0);resolveGuiCollisions=!1;screenEdgeWidth=10;stickToScreenEdge=!1;enabled=new Dm(!0);equals(t){return this.position.equals(t.position)&&this.offset.equals(t.offset)&&this.anchor.equals(t.anchor)&&this.resolveGuiCollisions===t.resolveGuiCollisions&&this.screenEdgeWidth===t.screenEdgeWidth&&this.stickToScreenEdge===t.stickToScreenEdge&&this.enabled.equals(t.enabled)}hash(){return nd(this.position.hash(),this.offset.hash(),this.anchor.hash(),this.resolveGuiCollisions?1:0,S(this.screenEdgeWidth),this.stickToScreenEdge?1:0,this.enabled.hashCode())}fromJSON({position:t=Eu.zero,offset:e=Eu.zero,anchor:i=Eu.zero,screenEdgeWidth:n=0,stickToScreenEdge:s=!1,enabled:r=!0}){this.position.fromJSON(t),this.offset.fromJSON(e),this.anchor.fromJSON(i),this.screenEdgeWidth=n,this.stickToScreenEdge=s,this.enabled.fromJSON(r)}toJSON(){return{position:this.position.toJSON(),offset:this.offset.toJSON(),anchor:this.anchor.toJSON(),screenEdgeWidth:this.screenEdgeWidth,stickToScreenEdge:this.stickToScreenEdge,enabled:this.enabled.toJSON()}}static fromJSON(t){const e=new jw;return e.fromJSON(t),e}}jw.typeName="ViewportPosition",jw.serializable=!0;class qw{constructor(){this.elements=[],this.__active=null,this.observers=new Map,this.on={added:new _,lastRemoved:new _,firstAdded:new _}}hasActive(){return null!==this.__active}update(){if(!this.hasActive()&&this.elements.length>0){const t=this.elements[0];this.activate(t)}}activate(t){this.__active=t,t.makeActive()}add(t){t.sm.addEventHandlerStateEntry(3,(()=>{this.remove(t),this.update()})),this.elements.push(t),this.elements.sort(((t,e)=>e.priority-t.priority)),this.hasActive()&&this.__active!==this.elements[0]&&(this.__active.makeReady(),this.__active=null),this.update(),this.on.added.send1(t),1===this.elements.length&&this.on.firstAdded.send0()}remove(t){const e=this.elements.indexOf(t);return-1!==e&&(t===this.__active&&(this.__active=null),this.elements.splice(e,1),this.update(),0===this.elements.length&&this.on.lastRemoved.send0(),!0)}}class Jw{constructor({title:t="",description:e="",image:i="",classList:n=[]}){this.title=t,this.description=e,this.image=new Hd(i),this.classList=n}}Jw.prototype.isNotification=!0;class $w{elements=new nf;maxLength=1e3;add(t){const e=new Jw(t);return this.addNotification(e),e}addNotification(t){const e=this.elements.length,i=this.maxLength-1;e>i&&this.elements.crop(e-i,e),this.elements.add(t)}}class Yw{constructor({log:t,initializer:e,updateFunction:i=Mf}){this.needsUpdate=i!==Mf,this.__update_function=i,this.log=t,this.initializer=e,this.timeScale=1}update(t){const e=this.timeScale*t;this.__update_function(e)}initialize(){this.initializer(this.log)}}class Xw{constructor(){this.channels=new Map,this.displays=new nf,this.defaultArea=void 0,this.ecd=null}createChannel(t){if(this.channels.has(t))throw new Error(`channel '${t}' already exists`);this.channels.set(t,new $w),void 0===this.defaultArea&&(this.defaultArea=t)}getChannel(t){return this.channels.get(t)}getDisplays(t){const e=this.getChannel(t);return this.displays.filter((t=>t.log===e))}addDisplay(t,e,i){const n=this.channels.get(t);if(void 0===n)throw new Error(`channel '${t}' doesn't exist`);const s=new Yw({log:n,initializer:e,updateFunction:i});this.displays.add(s),s.initialize()}addEmitterDisplay(t,e,i=null){const n=new Map,s=this,r=`managed-notification-channel-${t}`;function a(t){for(const[e,i]of n)if(i.id===t){n.delete(e);break}}this.addDisplay(t,(function(t){e.objectEmitter.objectFinalizer=function(t){const e=n.get(t);void 0!==e&&(e.removeEventListener(h_,a),e.destroy(),n.delete(t))},t.elements.on.added.add((function(t){e.spawn(t)})),e.on.spanwed.add((function(t){t.addClass(r);const e=new d_;e.add(Jg.Transient);const o=s.ecd;if(null!==o){const s=Hw.fromView(t);s.group=i,e.addEventListener(h_,a),e.add(s).build(o),n.set(t,e)}}))}),(function(t){e.tick(t)}))}addNotification(t,e=this.defaultArea){const i=this.channels.get(e);if(void 0===i)throw new Error(`Area '${e}' doesn't exist`);i.addNotification(t)}tick(t){const e=this.displays,i=e.length;for(let n=0;n<i;n++){const i=e.get(n);i.needsUpdate&&i.update(t)}}}class Zw{constructor(t){this.object=t,this.playback=null}}class Kw{constructor(){this.animation=null,this.animationUpdater=null,this.objectFactory=null,this.objectInitializer=Mf,this.objectFinalizer=Mf,this.elements=[],this.rushThreshold=Number.POSITIVE_INFINITY,this.spawnDelay=0,this.__spawnTimeBudget=0,this.__spawnBuffer=[],this.on={spanwed:new _,removed:new _},this.liveCount=0}setAnimation(t,e){this.animation=t,this.animationUpdater=e}setInitializer(t){this.objectInitializer=t}setFinalizer(t){this.objectFinalizer=t}spawn(t){this.liveCount++,this.__spawnTimeBudget<this.spawnDelay?this.__spawnBuffer.push(t):(this.spawnImmediate(t),this.__spawnTimeBudget=0)}spawnImmediate(t){const e=this.objectFactory(t),i=new Iw(this.animation,this.animationUpdater,e);i.reset(),i.update(),this.objectInitializer(e);const n=this;i.on.ended.add((function(){n.remove(e)}));const s=new Zw(e);return s.playback=i,this.elements.push(s),this.on.spanwed.dispatch(e),s}trySpawnDeferred(){const t=this.__spawnBuffer;let e=t.length;if(0===e)return;const i=this.__spawnTimeBudget;let n=0;const s=Su(Math.floor(i/this.spawnDelay),e),r=t.splice(0,s);for(n=0;n<s;n++){const t=r[n];this.spawnImmediate(t).playback.advance((s-(n+1))*this.spawnDelay)}this.__spawnTimeBudget%=this.spawnDelay}remove(t){const e=this.elements;for(let i=0,n=e.length;i<n;i++)if(e[i].object===t)return e.splice(i,1),this.liveCount--,this.objectFinalizer(t),this.on.removed.send1(t),!0;return!1}tick(t){const e=this.elements,i=e.length;for(let n=i-1;n>=0;n--){const s=e[n].playback,r=bu(1,(i-n)/this.rushThreshold)*t;s.advance(r)}this.__spawnTimeBudget+=t,this.trySpawnDeferred()}}class Qw{constructor(){this.source=new Eu,this.objectEmitter=new Kw,this.objectEmitter.objectInitializer=function(t){t.visible=!0};const t=this;this.objectEmitter.objectFactory=function(e){const i=t.viewFactory(e);return i.position.copy(t.source),i},this.viewFactory=null,this.timeScale=1,this.on=this.objectEmitter.on}setAnimation(t,e){this.objectEmitter.setAnimation(t,e)}setRushThreshold(t){this.objectEmitter.rushThreshold=t}setSpawnDelay(t){this.objectEmitter.spawnDelay=t}tick(t){const e=t*this.timeScale;this.objectEmitter.tick(e)}spawn(t){return this.objectEmitter.spawn(t)}remove(t){return this.objectEmitter.remove(t)}}class tb extends Hg{constructor(t){super(),this.model=t;const e=Ty("div").addClass("ui-notification-view");this.el=e.el,this.addClasses(t.classList),this.vImage=new aw(t.image,{classList:["image"]}),this.addChild(this.vImage),this.dTitle=e.createChild("div").addClass("title"),this.dDescription=e.createChild("div").addClass("description"),this.bindSignal(t.image.onChanged,this.updateImage,this)}link(){super.link();const t=this.model;this.dTitle.text(t.title),this.dDescription.text(t.description),this.updateImage()}updateImage(){const t=this.model.image.getValue();this.vImage.visible=void 0!==t&&""!==t}}const eb="primary",ib="secondary",nb="toast";class sb{constructor(){this.scene=null,this.modals=new qw,this.notifications=new Xw,this.clockModifierZero=new Tx(0,0)}initialize(t){var e;this.scene=t,(e=this.notifications).createChannel(eb),e.createChannel(ib),e.createChannel(nb),e.addEmitterDisplay(eb,function(){const t=new Qw;t.setRushThreshold(1),t.setSpawnDelay(2);const e=new zw(["alpha","scale"]);return e.addKey(0,[0,1.3]),e.addKey(.6,[1,1]),e.addKey(2.9,[1,1]),e.addKey(3.4,[0,1]),e.addTransition(0,Vw),e.addTransition(2,Ww),t.setAnimation(e,(function(t,e){this.el.style.opacity=t,this.scale.set(e,e)})),t.viewFactory=function(t){return new tb(t)},t}()),e.addEmitterDisplay(ib,function(){const t=new Qw;t.setRushThreshold(1),t.setSpawnDelay(.7);const e=new zw(["alpha","position.y","scale"]);return e.addKey(0,[.2,0,1.1]),e.addKey(.17,[1,0,1]),e.addKey(3.2,[1,-60,1]),e.addKey(3.7,[0,-70,1]),e.addTransition(0,Vw),e.addTransition(1,Uw),e.addTransition(2,Ww),t.setAnimation(e,(function(t,e,i){const n=this;n.el.style.opacity=t,n.position.setY(e),n.scale.set(i,i)})),t.viewFactory=function(t){return new tb(t)},t}()),e.addEmitterDisplay(nb,function(){const t=new Qw;t.setRushThreshold(5),t.setSpawnDelay(.1);const e=new zw(["alpha","position.x"]);return e.addKey(0,[.2,100]),e.addKey(.17,[1,0]),e.addKey(7.5,[1,0]),e.addKey(8,[0,0]),e.addTransition(0,Vw),e.addTransition(1,Uw),e.addTransition(2,Ww),t.setAnimation(e,(function(t,e){this.el.style.opacity=t,this.position.setX(e)})),t.viewFactory=function(t){return new tb(t)},t}(),"managed-toast-notifications"),this.notifications.ecd=t.dataset}tick(t){this.notifications.tick(t)}stopTime(){this.scene.speedModifiers.add(this.clockModifierZero)}resumeTime(){this.scene.speedModifiers.removeOneOf(this.clockModifierZero)}startup(){this.modals.on.firstAdded.add(this.stopTime,this),this.modals.on.lastRemoved.add(this.resumeTime,this)}shutdown(){this.modals.on.firstAdded.remove(this.stopTime,this),this.modals.on.lastRemoved.remove(this.resumeTime,this)}}class rb{windows=new nf;entityManager=null;engine=null;sceneContexts=new WeakMap;tooltips=new Ew;viewTooltips=new yw(this.tooltips);ticker=new zx;view=new jg({classList:["gui-engine-root"],css:{position:"absolute",left:"0",top:"0"}});gml=new ww;cursor=new ad("normal");localization=null;constructor(){this.ticker.onTick.add((t=>{let e=null;try{e=this.getActiveSceneContext()}catch(t){}null!==e&&e.tick(t)}))}openWindow({closeable:t,content:e,title:i,wrapper:n}){const s=new d_,r=new cw(e,{closeAction:function(){s.destroy()},title:i,closeable:t});let a;s.add(new jw),void 0!==n?(a=n,n.addChild(r)):a=r;const o=Hw.fromView(a);s.add(o).add(Jg.Transient);const l=this.entityManager.dataset;return function(t,e){const i=new zw(["alpha","scale"]);i.addKey(0,[0,.95]),i.addKey(.2,[1,1]),i.addTransition(0,Uw);const n=new Iw(i,(function(t,e){this.el.style.opacity=t,this.scale.set(e,e)}),t);n.update(),function(t,e){const i=new d_,n=kw.fromOne(new Bw(t));n.clock=1,i.add(n),i.add(Jg.Transient),t.update(),i.build(e),t.on.ended.add((function(){i.destroy()}))}(n,e)}(r,l),s.build(l),s}createModal({content:t,title:e,priority:i=0}){const n=this.entityManager,s=this;let r=null,a=null;const o=new Rx({priority:i});return o.sm.addEventHandlerStateEntry(2,(function(){a=function(){const t=new Hg;t.el=document.createElement("div"),t.el.classList.add("ui-modal-overlay"),t.el.addEventListener("click",(function(t){t.stopPropagation(),o.makeDestroyed()}));const e=new d_;return e.add(Jg.Transient),e.add(Hw.fromView(t)),e}(),a.build(n.dataset);const i=t,l=new jg({classList:["ui-modal-window-container"]});r=s.openWindow({title:e,content:i,closeable:!1,wrapper:l}),r.getComponent(Hw).anchor.set(.5,.5),r.removeComponent(jw)})),o.sm.addEventHandlerStateExit(2,(function(){r.destroy(),a.destroy()})),this.getActiveSceneContext().modals.add(o),o}createModalConfirmation({title:t,content:e,confirmationEnabled:i}){const n=this;let s=null;return new Promise((function(r,a){let o=!1;function l(){s.makeDestroyed()}const h=new lw(e,[{name:"yes",displayName:n.localization.getString("system_confirmation_confirm"),callback:function(){o=!0,l(),r()},enabled:i},{name:"no",displayName:n.localization.getString("system_confirmation_cancel"),callback:function(){o=!0,l(),a()}}]);s=n.createModal({content:h,title:t}),s.sm.addEventHandlerStateEntry(3,(function(){o||a()}))}))}confirmTextDialog({text:t,title:e}){const i=ab(t);return this.createModalConfirmation({title:e,content:i})}createTextAlert({text:t,title:e}){const i=ab(t);return this.createAlert({content:i,title:e})}createAlert({content:t,title:e,marks:i=[],priority:n=0,lifecycleHook:s=Mf}){let r=null;const a=this.localization,o=new lw(t,[{name:"ok",displayName:a.getString("system_confirmation_continue"),callback:function(){r.makeDestroyed()}}]);if(i.length>0){const t=new jg({classList:["marks"]});i.forEach(t.addChild,t),o.addChild(t)}r=this.createModal({content:o,title:e,priority:n});const l=new Promise((function(t,e){r.sm.addEventHandlerStateEntry(3,t)}));return s(r),l}obtainSceneContext(t){let e=this.sceneContexts.get(t);return void 0===e&&(e=new sb,e.initialize(t),e.startup(),this.sceneContexts.set(t,e)),e}getActiveSceneContext(){const t=this.engine;if(null===t)throw new Error("Engine is not set");const e=t.sceneManager.current_scene;return null===e?null:this.obtainSceneContext(e)}__update_localization(){this.view.removeClassesByPattern(/locale-/),this.view.addClass(`locale-${this.localization.locale.getValue()}`)}startup(t){this.engine=t,this.entityManager=t.entityManager;const e=this,i=t.localization;return this.gml.initialize(t.staticKnowledge,i),this.tooltips.initialize(this.gml,t.devices.pointer),this.gml.tooltips=this.viewTooltips,this.view.addChild(this.tooltips.contextView),t.gameView.addChild(this.view),t.gameView.size.process((function(t,i){e.view.size.set(t,i),e.tooltips.contextView.size.set(t,i)})),this.ticker.start(),this.localization=i,this.cursor.process((function(e,i){function n(t){return`cursor-${t}`}const s=t.graphics.domElement.classList;"string"==typeof i&&s.remove(n(i)),"string"==typeof e&&s.add(n(e))})),this.localization.locale.onChanged.add(this.__update_localization,this),this.__update_localization(),Promise.all([this.tooltips.startup()])}shutdown(){this.windows.reset(),this.entityManager=null;const t=this.tooltips.shutdown();return this.localization.locale.onChanged.remove(this.__update_localization,this),Promise.all([t])}}function ab(t){const e=new Hg;return e.el=document.createElement("div"),e.el.classList.add("text"),e.el.innerText=t,e.size.set(300,100),e}class ob{graphics_control_viewport_size=new Dm(!0);simulation_speed=new id(1);input_mouse_sensitivity=new id(5)}const lb="frame_delay",hb="render_time",cb="simulation_time";class ub{#kt=0;viewStack=new Cy;constructor(t,{entityManager:e,enableGraphics:i=!0,enableAudio:n=!0,debug:s=!0}={}){this.platform=t,this.staticKnowledge=new rx,this.staticKnowledge.validation_enabled=s,this.plugins=new px,this.performance=new Yy,this.executor=new vy(1,10),this.__using_external_entity_manager=void 0!==e,this.__using_external_entity_manager?this.entityManager=e:this.entityManager=new u_,this.ticker=new zx,this.assetManager=new Vy({context:this,executor:this.executor}),this.__performacne_monitor=new Zy(15,(()=>{const t=this.performance,e=new Xy,i=t.get(hb);i.computeStats(e);const n=(1e3*e.mean).toFixed(2),s=t.get(cb);s.computeStats(e);const r=(1e3*e.mean).toFixed(2),a=t.get(lb);a.computeStats(e);const o=(1/e.mean).toFixed(2);return i.clear(),s.clear(),a.clear(),`FPS: ${o}, RENDER: ${n}ms, SIMULATION: ${r}ms`})),this.__using_external_entity_manager||this.ticker.onTick.add((t=>{const e=performance.now();this.entityManager.simulate(t);const i=(performance.now()-e)/1e3;this.performance.get(cb).record(i)})),this.performance.create({name:hb}),this.performance.create({name:cb}),this.performance.create({name:lb}),this.options=new hx("options"),this.moduleRegistry=new gy,this.binarySerializationRegistry=new Ky,this.settings=new ob,this.services={},this.storage=this.platform.getStorage(),this.localization=new _y,this.localization.setAssetManager(this.assetManager);const r=window.innerWidth/3,a=window.innerHeight/3;if(this.camera=new rr(45,r/a,1,50),!1!==i){const t=new Dv({camera:this.camera,debug:s});this.graphics=t;try{t.start()}catch(t){ax.error(`Failed to start GraphicEngine: ${t}`)}}else ax.info("enableGraphics option is not set, no graphics engine will be created");if(!1!==n){const t=new Ix;t.volume=1,this.sound=t}else ax.info("enableAudio option is not set, no audio engine will be created");this.gui=new rb,this.sceneManager=new Mx(this.entityManager,this.ticker.clock),this.initializeViews(),this.devices={pointer:new tx(this.viewStack.el),keyboard:new Wv(this.viewStack.el)},this.devices.pointer.start(),this.devices.keyboard.start(),this.initializeSettings(),ax.info("engine initialized"),this.renderingEnabled=!0,this.plugins.initialize(this)}get inputEngine(){throw new Error("Deprecated, use .devices instead")}get grid(){throw new Error("Deprecated, use systems/components to achieve the same functionality as before")}initializeViews(){const t=new jg;if(t.addClass("game-view"),t.css({left:0,top:0,position:"absolute",pointerEvents:"none"}),this.gameView=t,this.viewStack.push(t,"game-view"),void 0!==this.graphics){const e=this.graphics.viewport;e.css({pointerEvents:"auto"}),t.addChild(e),e.bindSignal(t.size.onChanged,e.size.set.bind(e.size)),t.on.linked.add((function(){e.size.copy(t.size)}))}}initializeSettings(){ax.info("Initializing engine settings...");const t=this;function e(){let e=t.viewStack.el.parentElement;for(;null!==e&&void 0===e.innerWidth;)e=e.parentElement;null==e&&(e=window),t.viewStack.size.set(e.innerWidth,e.innerHeight)}this.settings.graphics_control_viewport_size.process((function(t){t?(e(),window.addEventListener("resize",e,!1)):window.removeEventListener("resize",e)})),ax.info("Engine settings initilized.")}benchmark(){let t=0;const e=Date.now();let i;for(;this.entityManager.simulate(1e-10),i=Date.now(),!(i-e>2e3);)t++;return t/((i-e)/1e3)}loadAssetList(t){const e=new Hy,i=this.assetManager;return i.get({path:t,type:"json",callback:function(t){e.addAll(t.create()),e.load(i)}}),e}render(){const t=this.graphics;if(t.autoDraw&&(t.needDraw=!0),t&&this.renderingEnabled&&t.needDraw){const e=this.performance,i=performance.now();t.render();const n=(performance.now()-i)/1e3;e.get(hb).record(n)}}start(){return this.assetManager.startup(),this.__performacne_monitor.start(),Promise.all([this.sound.start().then((()=>new Promise(((t,e)=>{this.entityManager.startup(t,e)})))),this.staticKnowledge.load(this.assetManager,this.executor),this.gui.startup(this),this.plugins.startup()]).then((async()=>{this.#kt=performance.now(),requestAnimationFrame(this.#Bt),this.ticker.start({maxTimeout:200}),await this.options.attachToStorage("lazykitty.komrade.options",this.storage),ax.info("engine started")}),(function(t){ax.error(`Engine Failed to start: ${t}`)}))}#Bt=()=>{const t=this.#kt,e=performance.now();requestAnimationFrame(this.#Bt),this.render();const i=(e-t)/1e3;this.#kt=e,this.performance.get(lb).record(i)};async stop(){this.__performacne_monitor.stop(),this.ticker.pause(),this.__using_external_entity_manager||await new Promise(((t,e)=>this.entityManager.shutdown(t,e))),await this.plugins.shutdown(),await this.gui.shutdown(),await this.assetManager.shutdown()}exit(){window.close()}requestExit(){return this.gui.confirmTextDialog({title:this.localization.getString("system_confirm_exit_to_system.title"),text:this.localization.getString("system_confirm_exit_to_system.text")}).then((()=>{this.exit()}))}}ub.prototype.isEngine=!0;class db{systems=[];plugins=[];knowledge=[];loaders=new Map;hasLoader(t){return this.loaders.has(t)}addLoader(t,e){return!this.loaders.has(t)&&(this.loaders.set(t,e),!0)}removeLoader(t){const e=this.loaders.get(t);return void 0!==e&&this.loaders.delete(t),e}addPlugin(t){return this.plugins.push(t),!0}addSystem(t){return this.systems.push(t),!0}addManySystems(...t){t.forEach((t=>this.addSystem(t)))}addDataTable(t){return this.knowledge.push(t),!0}async apply(t){const e=[];this.loaders.forEach(((i,n)=>{e.push(t.assetManager.registerLoader(n,i))})),await Promise.all(e);const i=this.knowledge.length;for(let e=0;e<i;e++){const i=this.knowledge[e];t.staticKnowledge.add(i.id,i.source,i.table)}const n=t.plugins,s=this.plugins,r=s.length;for(let t=0;t<r;t++){const e=s[t];await n.acquire(e)}const a=t.entityManager,o=this.systems.length;for(let e=0;e<o;e++){const i=this.systems[e];t.entityManager.hasSystem(i.constructor)||await a.addSystem(i)}}}class pb{constructor({path:t,listener:e,exclusive:i=!1}){this.path=t,this.listener=e,this.exclusive=i}}class fb{constructor(t=[]){this.mapping=new nf;const e=t.map((t=>new pb(t)));this.mapping.addAll(e),this.on={unlinked:new _}}bind(t,e){const i=new pb({path:t,listener:e});return this.mapping.add(i),i}static from(t){const e=new fb,i=t.length;for(let n=0;n<i;n++){const i=t[n],s=new pb(i);e.mapping.add(s)}return e}}function mb(t,e,i){return t[e+4*i]}fb.typeName="InputController",fb.serializable=!1;const _b=Math.sin,gb=Math.cos,yb=Math.atan2,vb=2*Math.PI;function xb(t){let e=t%vb;return e=(e+vb)%vb,e>Math.PI&&(e-=vb),e}const wb=new Cn,bb=[],Sb=new L;function Mb(t,e,i,n){const s=xb(i.pitch),r=xb(i.yaw),a=xb(i.roll),o=(a>=Math.PI/2-1e-4||a<=-(Math.PI/2-1e-4)?-1:1)*(s>Math.PI||s<0?-1:1)*t;n.yaw=r+o,n.pitch=s-e}const Tb=Math.PI/360;class Ab{constructor(t){this.target=new L,this.pitch=0,this.yaw=0,this.roll=0,this.distance=0,this.distanceMin=1,this.distanceMax=200,void 0!==t&&this.fromJSON(t)}setFromEyeAndTarget(t,e,i=L.up){wb.lookAt(e,t,i),function(t,e,i,n,s){{t[0]=yb(mb(e,1,0),mb(e,0,0));const i=Tu(mb(e,2,2),mb(e,2,1));t[0]<0||t[0]>0?(t[0]>0?t[0]-=Math.PI:t[0]+=Math.PI,t[1]=yb(-mb(e,2,0),-i)):t[1]=yb(-mb(e,2,0),i);const n=_b(t[0]),s=gb(t[0]);t[2]=yb(n*mb(e,0,2)-s*mb(e,1,2),s*mb(e,1,1)-n*mb(e,0,1))}}(bb,wb.elements),this.pitch=bb[2],this.yaw=bb[1],this.roll=bb[0],this.distance=t.distanceTo(e),this.distanceMax=bu(this.distance,this.distanceMax),this.target.copy(e)}equals(t){return this.target.equals(t.target)&&this.pitch===t.pitch&&this.yaw===t.yaw&&this.roll===t.roll&&this.distance===t.distance&&this.distanceMin===t.distanceMin&&this.distanceMax===t.distanceMax}copy(t){this.target.copy(t.target),this.pitch=t.pitch,this.yaw=t.yaw,this.roll=t.roll,this.distance=t.distance,this.distanceMax=t.distanceMax,this.distanceMin=t.distanceMin}clone(){const t=new Ab;return t.copy(this),t}lerp(t,e,i){this.target.lerpVectors(t.target,e.target,i),this.pitch=w(t.pitch,e.pitch,i),this.yaw=w(t.yaw,e.yaw,i),this.roll=w(t.roll,e.roll,i),this.distance=w(t.distance,e.distance,i),this.distanceMin=w(t.distanceMin,e.distanceMin,i),this.distanceMax=w(t.distanceMax,e.distanceMax,i)}toJSON(){return{target:this.target.toJSON(),pitch:this.pitch,yaw:this.yaw,roll:this.roll,distance:this.distance,distanceMin:this.distanceMin,distanceMax:this.distanceMax}}fromJSON({distance:t=0,distanceMin:e=0,distanceMax:i=0,pitch:n=0,yaw:s=0,roll:r=0,target:a=L.zero}){this.distance=t,this.distanceMin=e,this.distanceMax=i,this.pitch=n,this.roll=r,this.yaw=s,this.target.fromJSON(a)}static fromJSON(t){const e=new Ab;return e.fromJSON(t),e}}Ab.typeName="TopDownCameraController",Ab.pan=function(t,e,i,n,s,r,a=L.one){const o=n*Math.tan(s*Tb)*2/i.clientHeight;!function(t,e,i,n){const s=e.matrix.elements;Sb.set(s[0],s[1],s[2]),Sb.multiplyScalar(-t),i._sub(Sb.x*n.x,Sb.y*n.y,Sb.z*n.z)}(t.x*o,e,r,a),function(t,e,i,n){const s=e.matrix.elements;Sb.set(s[4],s[5],s[6]),Sb.multiplyScalar(t),i._sub(Sb.x*n.x,Sb.y*n.y,Sb.z*n.z)}(t.y*o,e,r,a)},Ab.rotate=Mb;const Cb=new L;class Eb extends Cm{constructor(){super(),this.enabled=new Hd(!0),this.dependencies=[Ab],this.components_used=[Tm.from(B,2)]}__visit_camera_entity(t,e){const i=this.entityManager.dataset.getComponent(e,B);void 0!==i&&function(t,e){const i=e.rotation,n=g(t.distance,t.distanceMin,t.distanceMax),s=t.target,r=t.yaw,a=t.pitch,o=t.roll;i.__setFromEuler(a,r,o,"ZYX"),Cb.copy(L.forward),Cb.applyQuaternion(i),Cb.multiplyScalar(-n),Cb.add(s),e.position.copy(Cb)}(t,i)}update(t){const e=this.entityManager.dataset;this.enabled.get()&&null!==e&&e.traverseComponents(Ab,this.__visit_camera_entity,this)}}const zb={DIRECTION:0,SPOT:1,POINT:2,AMBIENT:3};class Ib{constructor(){this.type=new Fm(zb.DIRECTION,zb),this.color=new kd(1,1,1),this.intensity=new id(1),this.angle=new id(Math.PI/4),this.penumbra=new id(.4),this.distance=new id(1),this.castShadow=new Dm(!1),this.__threeObject=null,this.__fp_light=null}static fromJSON(t){const e=new Ib;return e.fromJSON(t),e}fromJSON(t){void 0!==t.type&&this.type.fromJSON(t.type),void 0!==t.color?"string"==typeof t.color?this.color.parse(t.color):this.color.fromUint(t.color):this.color.setRGB(1,1,1),void 0!==t.intensity?this.intensity.fromJSON(t.intensity):this.intensity.set(1),void 0!==t.castShadow?this.castShadow.fromJSON(t.castShadow):this.castShadow.set(!1);const e=this.type.getValue();e===zb.SPOT&&(void 0!==t.angle&&this.angle.fromJSON(t.angle),void 0!==t.penumbra&&this.penumbra.fromJSON(t.penumbra)),e!==zb.SPOT&&e!==zb.POINT||(void 0!==t.distance?this.distance.fromJSON(t.distance):this.distance.set(1)),this.__threeObject=null}toJSON(){const t={type:this.type.toJSON(),color:this.color.toUint(),intensity:this.intensity.toJSON(),castShadow:this.castShadow.toJSON()},e=this.type.getValue();return e===zb.SPOT&&(t.angle=this.angle.toJSON(),t.penumbra=this.penumbra.toJSON()),e!==zb.SPOT&&e!==zb.POINT||(t.distance=this.distance.toJSON()),t}}Ib.typeName="Light",Ib.Type=zb;class Lb extends Cm{constructor(t){super(),this.__ContextClass=t,this.__context_pool=new Qx((()=>new t),(t=>{}),(t=>{})),this.__live_contexts=[],this.__validation_ignore_link_argument_count=!0}__getEntityContext(t){return this.__live_contexts[t]}link(){const t=arguments.length-1,e=arguments[t],i=this.__context_pool.create();i.system=this,i.entity=e;for(let e=0;e<t;e++)i.components[e]=arguments[e];i.link(),this.__live_contexts[e]=i}unlink(){const t=arguments[arguments.length-1],e=this.__live_contexts[t];void 0!==e&&(delete this.__live_contexts[t],e.unlink(),this.__context_pool.release(e))}}function Nb(t,e){if(0===t){if(e<=8)return ju.Uint8;if(e<=16)return ju.Uint16;if(e<=32)return ju.Uint32}else if(1===t){if(e<=8)return ju.Int8;if(e<=16)return ju.Int16;if(e<=32)return ju.Int32}else if(2===t){if(e<=32)return ju.Float32;if(e<=64)return ju.Float64}throw new Error(`Unsupported numeric type(=${t}) and precision(=${e}) combination`)}function Pb(t,e,i){const n=t[e];t[e]=t[i],t[i]=n}const Db=[];function Fb(t,e,i,n){const s=3*e;i[n]=t[s],i[n+1]=t[s+1],i[n+2]=t[s+2]}function Ob(t,e,i,n,s,r,a){Fb(a,e*i+n*s+r,t,0);const o=r+1;Fb(a,e*i+n*s+o,t,12);const l=n+1;Fb(a,e*i+l*s+r,t,6),Fb(a,e*i+l*s+o,t,18);const h=e+1;Fb(a,h*i+n*s+r,t,3),Fb(a,h*i+n*s+o,t,15),Fb(a,h*i+l*s+r,t,9),Fb(a,h*i+l*s+o,t,21)}class Rb{add(t,e){throw new Error("Not Implemented")}remove(t){throw new Error("Not Implemented")}get sampler(){throw new Error("Not Implemented")}update(){throw new Error("Not Implemented")}}class kb{constructor(){this.patch=null,this.last_use_time=0}}class Bb extends Rb{constructor({atlas:t}){super(),this.__cached_patches=[],this.__atals=t}__find_eviction_target(){let t=Infinity,e=-1;const i=this.__cached_patches,n=i.length;for(let s=0;s<n;s++){const n=i[s].last_use_time;n<t&&(e=s,t=n)}return e}__find_replacement_target(t,e){let i=Infinity,n=Infinity,s=-1;const r=this.__cached_patches,a=r.length;for(let o=0;o<a;o++){const a=r[o],l=a.patch.packing,h=l.x1-l.x0,c=l.y1-l.y0;if(h<t||c<e)continue;const u=h*c;if(u>i)continue;const d=a.last_use_time;d>=n||(i=u,n=d,s=o)}return s}__evict(t){const e=this.__cached_patches,i=e[t];e.splice(t,1),this.__atals.remove(i.patch)}__evict_all(){for(let t=this.__cached_patches.length-1;t>0;t--)this.__evict(t)}__evict_for(t,e){if(this.__cached_patches.length<=0)return!1;const i=this.__find_replacement_target(t,e);if(-1!==i)return this.__evict(i),!0;for(;!this.__atals.can_pack(t,e);){const t=this.__find_eviction_target();if(-1===t)return!1;this.__evict(t)}return!0}update(){try{this.__atals.update()}catch(t){if(!(this.__cached_patches.length>0))throw t;this.__evict_all(),this.__atals.update()}}get atlas(){return this.__atals}get sampler(){return this.__atals.sampler}reset(){this.__cached_patches.splice(0,this.__cached_patches.length),this.__atals.reset()}__find_cache_record_index(t){const e=this.__cached_patches,i=e.length;for(let n=0;n<i;n++)if(e[n].patch.sampler===t)return n;return-1}__find_cache_record_index_by_patch(t){const e=this.__cached_patches,i=e.length;for(let n=0;n<i;n++)if(e[n].patch===t)return n;return-1}add(t,e=4){const i=this.__find_cache_record_index(t),n=this.__cached_patches;if(-1!==i){const t=n[i];return n.splice(i,1),t.patch}const s=t.width+2*e,r=t.height+2*e;return n.length>0&&!this.__atals.can_pack(s,r)&&this.__evict_for(s,r),this.__atals.add(t,e)}remove(t){if(!this.__atals.contains(t))return!1;if(-1!==this.__find_cache_record_index_by_patch(t))return!1;const e=new kb;return e.last_use_time=performance.now(),e.patch=t,this.__cached_patches.push(e),!0}}class Ub extends Rb{constructor(t){super(),this.__atlas=t,this.__patches=new Map,this.__ref_counts=new Map}update(){this.__atlas.update()}__handle_ref_release(t,e){const i=this.__ref_counts,n=i.get(e);i.set(e,n-1),1===n&&(this.__atlas.remove(e),i.delete(e),this.__patches.delete(e.sampler))}acquire(t){let e=this.__patches.get(t);const i=this.__ref_counts,n=this.__atlas;void 0===e?(e=n.add(t),i.set(e,1),this.__patches.set(t,e)):i.set(e,i.get(e)+1);const s=new nv;return s.bind(e),s.onReleased.add(this.__handle_ref_release,this),s}}class Vb extends Gg{data=null;parentNode=null;disconnect(){const t=this.parentNode;if(null===t)return;const e=t.data,i=e.indexOf(this);e.splice(i,1);let n=t;for(;null!==n;)n.treeDataCount--,n=n.parentNode;this.parentNode.balanceBubbleUp(),this.parentNode=null}resize(t,e,i,n){this.x0=t,this.y0=e,this.x1=i,this.y1=n;const s=this.parentNode;if(null===s)return;let r=s;(this.x0<r.x0||this.x1>=r.x1||this.y0<r.y0||this.y1>=r.y1)&&(this.disconnect(),r.insertDatum(this))}move(t,e){const i=this.x0+t,n=this.y0+e,s=this.x1+t,r=this.y1+e;this.resize(i,n,s,r)}}Vb.prototype.isQuadTreeDatum=!0;class Wb extends Gg{constructor(t=0,e=0,i=0,n=0){super(t,e,i,n),this.topLeft=null,this.topRight=null,this.bottomLeft=null,this.bottomRight=null,this.parentNode=null,this.treeDataCount=0,this.data=[]}balance(){const t=this.data.length,e=this.isSplit();return t>16&&!e?(this.split(),1):this.treeDataCount<8&&e?(this.merge(),2):0}balanceBubbleUp(){if(2===this.balance()){let t=this.parentNode;for(;null!==t&&2===t.balance();)t=t.parentNode}}resize(t,e,i,n){this.x0===t&&this.y0===e&&this.x1===i&&this.y1===n||(this.isSplit()&&this.merge(),this.x0=t,this.y0=e,this.x1=i,this.y1=n,this.balance())}add(t,e,i,n,s){const r=new Vb(e,i,n,s);return r.data=t,this.insertDatum(r),r}insertDatum(t){const e=this.x0,i=this.y0,n=this.x1,s=this.y1;if(t.x0<e||t.x1>n||t.y0<i||t.y1>s)null===this.parentNode?(this.resize(Su(e,t.x0),Su(i,t.y0),bu(n,t.x1),bu(s,t.y1)),this.addDatum(t)):this.parentNode.insertDatum(t);else{if(!this.isSplit()){if(!(this.treeDataCount>=16))return void this.addDatum(t);this.split()}const r=.5*(e+n),a=.5*(i+s);t.y1<a?t.x1<r?this.topLeft.insertDatum(t):t.x0>=r?this.topRight.insertDatum(t):this.addDatum(t):t.y0>=a?t.x1<r?this.bottomLeft.insertDatum(t):t.x0>=r?this.bottomRight.insertDatum(t):this.addDatum(t):this.addDatum(t)}}addDatum(t){this.treeDataCount++,this.data.push(t),t.parentNode=this;let e=this.parentNode;for(;null!==e;)e.treeDataCount++,e=e.parentNode}isSplit(){return null!==this.topLeft}split(){const t=this.x0,e=this.y0,i=this.x1,n=this.y1,s=.5*(t+i),r=.5*(e+n);this.topLeft=new Wb(t,e,s,r),this.topLeft.parentNode=this,this.topRight=new Wb(s,e,i,r),this.topRight.parentNode=this,this.bottomLeft=new Wb(t,r,s,n),this.bottomLeft.parentNode=this,this.bottomRight=new Wb(s,r,i,n),this.bottomRight.parentNode=this,this.pushDataDown(),this.topLeft.balance(),this.topRight.balance(),this.bottomLeft.balance(),this.bottomRight.balance()}pullDataUp(){this.topLeft.traversePreOrder(this.absorbDataFrom,this),this.topRight.traversePreOrder(this.absorbDataFrom,this),this.bottomLeft.traversePreOrder(this.absorbDataFrom,this),this.bottomRight.traversePreOrder(this.absorbDataFrom,this)}absorbDataFrom(t){const e=this.data,i=t.data,n=i.length;for(let t=0;t<n;t++){const n=i[t];n.parentNode=this,e.push(n)}t.treeDataCount=0,t.data=[]}pushDataDown(){const t=this.data;let e=t.length,i=0;const n=this.x0,s=this.y0,r=.5*(n+this.x1),a=.5*(s+this.y1);for(;i<e;i++){const n=t[i];let s;if(n.y1<a)if(n.x1<r)s=this.topLeft;else{if(!(n.x0>=r))continue;s=this.topRight}else{if(!(n.y0>=a))continue;if(n.x1<r)s=this.bottomLeft;else{if(!(n.x0>=r))continue;s=this.bottomRight}}s.data.push(n),s.treeDataCount++,t.splice(i,1),n.parentNode=s,i--,e--}}merge(){this.pullDataUp(),this.topLeft=null,this.topRight=null,this.bottomLeft=null,this.bottomRight=null}clear(){this.data=[],this.treeDataCount=0,this.topLeft=null,this.topRight=null,this.bottomLeft=null,this.bottomRight=null}getRawData(t){this.traverseData((e=>{const i=e.data;t.push(i)}))}traverseData(t,e){this.traversePreOrder((i=>{const n=i.data,s=n.length;for(let i=0;i<s;i++){const s=n[i];t.call(e,s)}}))}traversePreOrder(t,e){!1!==t.call(e,this)&&this.isSplit()&&(this.topLeft.traversePreOrder(t,e),this.topRight.traversePreOrder(t,e),this.bottomLeft.traversePreOrder(t,e),this.bottomRight.traversePreOrder(t,e))}traversePointIntersections(t,e,i,n){const s=this.data,r=s.length;for(let a=0;a<r;a++){const r=s[a];if(r.x0<=t&&r.x1>=t&&r.y0<=e&&r.y1>=e&&!1===i.call(n,r,t,e))return}if(this.isSplit()){const s=(this.x0+this.x1)/2,r=(this.y0+this.y1)/2;s>=t&&(r>=e&&this.topLeft.traversePointIntersections(t,e,i,n),r<=e&&this.bottomLeft.traversePointIntersections(t,e,i,n)),s<=t&&(r>=e&&this.topRight.traversePointIntersections(t,e,i,n),r<=e&&this.bottomRight.traversePointIntersections(t,e,i,n))}}requestDatumIntersectionsPoint(t,e,i){let n=0;return this.traversePointIntersections(e,i,(e=>{t[n++]=e})),n}requestDatumIntersectionsRectangle(t,e,i,n,s){let r=0;return this.traverseRectangleIntersections(e,i,n,s,(e=>{t[r++]=e})),r}traverseRectangleIntersections(t,e,i,n,s,r){const a=this.data,o=a.length;for(let l=0;l<o;l++){const o=a[l];if(o.x0<i&&o.x1>t&&o.y0<n&&o.y1>e&&!1===s.call(r,o,t,e,i,n))return}if(this.isSplit()){const a=(this.x0+this.x1)/2,o=(this.y0+this.y1)/2;a>=t&&(o>=e&&this.topLeft.traverseRectangleIntersections(t,e,i,n,s,r),o<=n&&this.bottomLeft.traverseRectangleIntersections(t,e,i,n,s,r)),a<=i&&(o>=e&&this.topRight.traverseRectangleIntersections(t,e,i,n,s,r),o<=n&&this.bottomRight.traverseRectangleIntersections(t,e,i,n,s,r))}}}function Gb(t,e,i,n){return(t-i)*e+(e-n)*i}function Hb(t,e,i,n){let s=null,r=Number.POSITIVE_INFINITY;return i.traversePreOrder((i=>{if(i.getWidth()<t)return!1;if(i.getHeight()<e)return!1;const a=i.data,o=a.length;for(let i=0;i<o;i++){const o=a[i],l=o.getWidth();if(l<t)continue;const h=o.getHeight();if(h<e)continue;const c=n(l,h,t,e);c<r&&(r=c,s=o)}return!0})),s}function jb(t,e){const i=t.getWidth(),n=t.getHeight(),s=Hb(i,n,e,Gb);if(null===s)return!1;s.disconnect();const r=s.y0,a=s.x0;if(t.set(a,r,a+i,r+n),function(t,e){const i=[],n=[];let s,r;for(e.traverseRectangleIntersections(t.x0,t.y0,t.x1,t.y1,(function(e){n.push(e);const s=bu(t.x0,e.x0),r=Su(t.x1,e.x1),a=bu(t.y0,e.y0),o=Su(t.y1,e.y1);s>e.x0&&i.push(new Vb(e.x0,e.y0,s,e.y1)),r<e.x1&&i.push(new Vb(r,e.y0,e.x1,e.y1)),a>e.y0&&i.push(new Vb(e.x0,e.y0,e.x1,a)),o<e.y1&&i.push(new Vb(e.x0,o,e.x1,e.y1))})),s=0,r=n.length;s<r;s++)n[s].disconnect();for(function(t){let e,i,n=t.length;t:for(e=0;e<n;e++){const s=t[e],r=s.x0,a=s.y0,o=s.x1,l=s.y1;for(i=e+1;i<n;i++){const s=t[i],h=s.x0,c=s.y0,u=s.x1,d=s.y1;if(r>=h&&o<=u&&a>=c&&l<=d){t.splice(e,1),e--,n--;continue t}h>=r&&u<=o&&c>=a&&d<=l&&(t.splice(i,1),i--,n--)}}}(i),s=0,r=i.length;s<r;s++){const t=i[s];e.insertDatum(t)}}(t,e),t.y1!==s.y1){const i=new Vb(s.x0,t.y1,s.x1,s.y1);e.insertDatum(i)}if(t.x1!==s.x1){const i=new Vb(t.x1,s.y0,s.x1,s.y1);e.insertDatum(i)}return!0}function qb(t){const e=[];let i;function n(t){if(i===t)return;const n=t.x0,s=t.y0,r=t.x1,a=t.y1,o=i.x0,l=i.y0,h=i.x1,c=i.y1;if(n>=o&&r<=h&&s>=l&&a<=c)e.push(t);else if(o>=n&&h<=r&&l>=s&&c<=a)return e.push(i),!1}t.traversePreOrder((function(t){const e=t.data,s=e.length;for(let r=0;r<s;r++)i=e[r],t.traverseRectangleIntersections(i.x0,i.y0,i.x1,i.y1,n)}));for(let t=0;t<e.length;t++)e[t].disconnect()}class Jb{constructor(t,e){this.size=new Eu(t,e),this.free=new Wb(0,0,t,e),this.free.add(null,0,0,t,e),this.boxes=[]}remove(t){const e=this.boxes.indexOf(t);return-1!==e&&(this.boxes.splice(e,1),this.free.insertDatum(new Vb(t.x0,t.y0,t.x1,t.y1)),!0)}removeMany(t){let e=0;const i=t.length;for(let n=0;n<i;n++){const i=t[n];this.remove(i)||e++}return e}add(t){const e=jb(t,this.free);return e&&(this.boxes.push(t),qb(this.free)),e}canAdd(t,e){return null!==Hb(t,e,this.free,Gb)}addMany(t){const e=t.length,i=[],n=new Ey((function(e){const i=t[e];return-Math.min(i.getWidth(),i.getHeight())}));for(let t=0;t<e;t++)n.push(t);for(let s=0;s<e;s++){const e=n.pop(),s=t[e];if(!jb(s,this.free))return this.removeMany(i),!1;this.boxes.push(s),i.push(s)}return qb(this.free),!0}repack(){const t=this.boxes;return this.clear(),this.addMany(t)}clear(){this.free.clear(),this.free.insertDatum(new Vb(0,0,this.size.x,this.size.y)),this.boxes=[]}resize(t,e){const i=this.size.x,n=this.size.y;return this.size.set(t,e),i>t||n>e?this.repack():(t>i&&this.free.insertDatum(new Vb(i,0,t,e)),e>n&&this.free.insertDatum(new Vb(0,n,t,e)),!0)}validate(){const t=this.boxes,e=t.length;let i,n;for(i=0;i<e;i++){const s=t[i];for(n=i+1;n<e;n++){const e=t[n];if(s.computeOverlap(e,new Gg))return!1}}return!0}}class $b{#Ut=new e_;peek(){return this.#Ut.nextClearBit(0)}get(){const t=this.peek();return this.#Ut.set(t,!0),t}getSpecific(t){return!this.isUsed(t)&&(this.#Ut.set(t,!0),!0)}isUsed(t){return this.#Ut.get(t)}traverseUsed(t){const e=this.#Ut;for(let i=e.nextSetBit(0);-1!==i;i=e.nextSetBit(i+1))t(i)}release(t){this.#Ut.clear(t)}reset(){this.#Ut.reset()}}function Yb(t){return t.clone()}class Xb{constructor(){this.position=new Eu(0,0),this.size=new Eu(0,0),this.padding=4,this.id=-1,this.sampler=null,this.uv=new dw(0,0,0,0),this.packing=new Gg,this.flags=0,this.last_painted_version=-1}updateUV(t,e){const i=this.position,n=this.size,s=this.uv,r=i.x,a=i.y,o=n.x,l=n.y;s.set(r/t,a/e,o/t,l/e)}updatePositionFromPacking(t,e){const i=this,n=this.packing,s=n.x0+i.padding,r=n.y0+i.padding;i.position.set(s,r),this.updateUV(t,e)}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}}Xb.prototype.isAtlasPatch=!0;class Zb extends Rb{constructor(t=16,e=ju.Uint8,i=4){super(),this.idPool=new $b,this.patches=[],this.size=new Eu(t,t);const n=qu[e];this.__sampler=new Zu(new n(t*t*i),i,t,t),this.packer=new Jb(t,t),this.on={painted:new _,removed:new _},this.__needsUpdate=!1}get sampler(){return this.__sampler}getPatch(t){const e=this.patches,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i.sampler===t)return i}}needsUpdate(){return this.__needsUpdate}contains(t){return this.patches.includes(t)}erase(){const t=this.patches,e=t.length;for(let i=0;i<e;i++)t[i].clearFlag(2);this.__sampler.data.fill(0),this.__needsUpdate=!0}resize(t,e){const i=this.patches,n=i.length;for(let s=0;s<n;s++){const n=i[s];if(n.getFlag(1)){const i=n.packing.x1,s=n.packing.y1;if(i>t||s>e)return!1}}for(let s=0;s<n;s++){const n=i[s];n.getFlag(1)&&n.updateUV(t,e)}return this.size.set(t,e),this.packer.resize(t,e),this.__sampler.resize(t,e),!0}paintPatch(t){const e=this.__sampler,i=t.sampler,n=t.position,s=t.size;!function(t,e,i,n,s,r,a,o){const l=t.itemSize;e.itemSize;const h=Math.min(a,e.width-0,t.width-s),c=Math.min(o,e.height-0,t.height-r),u=l*t.width,d=l*e.width,p=e.data,f=t.data,m=h*l;let _,g;for(_=0;_<c;_++){const t=(_+r)*u+s*l,e=(_+0)*d+0*l;for(g=0;g<m;g++)f[t+g]=p[e+g]}t.version++}(e,i,0,0,n.x,n.y,s.x,s.y),t.setFlag(2),t.last_painted_version=i.version}erasePatch(t){const e=t.packing,i=e.x0,n=e.y0,s=e.x1,r=e.y1;this.eraseArea(i,n,s,r),t.clearFlag(2)}eraseArea(t,e,i,n){this.__sampler.zeroFill(t,e,i-t,n-e)}add(t,e=4){const i=new Xb;i.id=this.idPool.get(),i.sampler=t,i.size.set(t.width,t.height),i.padding=e,i.setFlag(4);const n=2*e;return i.packing.set(0,0,t.width+n,t.height+n),this.patches.push(i),this.__needsUpdate=!0,i}can_pack(t,e){return this.packer.canAdd(t,e)}remove(t){const e=this.patches.indexOf(t);return-1!==e&&(this.patches.splice(e,1),this.idPool.release(t.id),t.getFlag(2)&&this.erasePatch(t),t.getFlag(1)&&this.packer.remove(t.packing),t.clearFlag(7),this.on.removed.send2(t,t.sampler),!0)}repack(){const t=this.patches,e=t.length;for(let i=0;i<e;i++){const e=t[i];e.getFlag(1)&&(e.clearFlag(1),this.packer.remove(e.packing))}return this.pack(),this.__needsUpdate=!0,!0}pack(){const t=this.patches,e=t.length;let i,n;const s=[];for(i=0;i<e;i++){const e=t[i];e.getFlag(1)||s.push(e.packing)}if(s.length<=0)return!0;if(this.packer.addMany(s));else{const t=new Jb(this.size.x,this.size.y),e=this.packer.boxes.map(Yb);if(Array.prototype.push.apply(s,this.packer.boxes),!t.addMany(s)){for(i=0,n=e.length;i<n;i++){const t=e[i];this.packer.boxes[i].copy(t)}return!1}for(i=0,n=e.length;i<n;i++){const t=this.packer.boxes[i],n=e[i];if(t.equals(n));else{const e=this.patches.find((e=>e.packing===t));this.eraseArea(n.x0,n.y0,n.x1,n.y1),e.clearFlag(2)}}this.packer=t}for(i=0;i<e;i++){const e=t[i];e.setFlag(1),e.updatePositionFromPacking(this.size.x,this.size.y)}return!0}paint(){const t=this.patches,e=t.length;let i=0;for(let n=0;n<e;n++){const e=t[n];e.getFlag(2)&&e.last_painted_version===e.sampler.version||(this.paintPatch(e),i++)}i>0&&this.on.painted.send0()}update(){if(!this.__needsUpdate)return;const t=bu(0,Math.log2(jd(this.size.x))),e=bu(0,Math.log2(jd(this.size.y)));let i=t,n=e;for(;!this.pack();)for(;;){if(i<n?i++:n++,i>14||n>14)throw new Error(`Packing failed, could not pack ${this.patches.length} into ${Math.pow(2,14)} resolution texture. Initial powers: ${t}, ${e}`);const s=Math.pow(2,i),r=Math.pow(2,n);if(this.resize(s,r))break}this.paint(),this.__needsUpdate=!1}reset(){this.__sampler.data.fill(0),this.patches=[],this.packer.clear(),this.idPool.reset()}}function Kb(t){switch(t){case ju.Uint8:return ee;case ju.Uint16:return se;case ju.Uint32:return ae;case ju.Int8:return ie;case ju.Int16:return ne;case ju.Int32:return re;case ju.Float16:return le;case ju.Float32:case ju.Float64:return oe;default:throw new Error(`Unsupported data type '${t}'`)}}const Qb={[ju.Uint8]:1,[ju.Uint16]:2,[ju.Uint32]:4,[ju.Uint64]:8,[ju.Int8]:1,[ju.Int16]:2,[ju.Int32]:4,[ju.Int64]:8,[ju.Float16]:2,[ju.Float32]:4,[ju.Float64]:8};class tS{constructor(){this.__channel_count=1,this.size=1,this.__precision=8,this.__type=0,this.__texture=new Fl(new Uint8Array(0),0,0),this.__texture.image.width=0,this.__texture.image.height=0,this.__texture.type=ee,this.__texture.format=xe,this.__texture.magFilter=Yt,this.__texture.minFilter=Yt,this.__texture.wrapS=Jt,this.__texture.wrapT=Jt,this.__texture.generateMipmaps=!1,this.needsRebuild=!1,this.__height=0,this.__data_type=ju.Uint8}get concrete_type(){return this.__data_type}set channel_count(t){this.__channel_count!==t&&(this.__channel_count=t,this.needsRebuild=!0)}get channel_count(){return this.__channel_count}update(){this.needsRebuild&&this.build()}set type(t){this.__type=t,this.__update_data_type()}get type(){return this.__type}get precision(){return this.__precision}set precision(t){this.__precision=t,this.__update_data_type()}dispose(){this.__texture.dispose()}__update_data_type(){const t=Nb(this.__type,this.__precision);t!==this.__data_type&&(this.__data_type=t,this.needsRebuild=!0)}build(t=!0){const e=this.__texture,i=e.image.data,n=i.length,s=128*this.__height*this.__channel_count,r=new(0,qu[this.__data_type])(s);e.format=function(t,e){if(0===t||1===t)return function(t){switch(t){case 1:return we;case 2:return Se;case 3:return Me;case 4:return Te;default:throw new Error(`Unsupported channel count '${t}'`)}}(e);if(2===t)return Lp(e);throw new Error(`Unsupported numeric type '${t}'`)}(this.__type,this.__channel_count),e.type=Kb(this.__data_type),e.internalFormat=Np(this.__data_type,this.channel_count),t&&(n<s?r.set(i):r.set(i.slice(0,s))),e.dispose(),e.image.height=this.__height,e.image.width=128,e.image.data=r,e.needsUpdate=!0,this.needsRebuild=!1}getTexture(){return this.__texture}resize(t){this.size=t;const e=bu(Math.ceil(t/128),1),i=this.__texture.image.height;return i<e?(this.__height=Math.ceil(1.05*e),this.needsRebuild=!0,!0):.5*i>e&&(this.__height=e,this.needsRebuild=!0,!0)}getTextureByteSize(){const t=Qb[this.__data_type],e=this.__texture.image;return t*e.width*e.height*this.__channel_count}}const eS=new ArrayBuffer(84),iS=new Uint8Array(eS,0,43);iS[21]=0,iS[37]=1,iS[25]=2,iS[41]=3,iS[22]=4,iS[38]=5,iS[26]=6,iS[42]=7;const nS=new Uint8Array(eS,43,41);function sS(t,e,i,n,s,r){let a=0,o=0,l=0;for(;a<6;a++){const s=4*a,h=r[s]*t+r[s+1]*e+r[s+2]*i+r[s+3];if(h<0){if(!(h>=-n))return!1;o++,l|=1<<a}}return o<2||function(t,e,i,n,s,r,a){const o=t*t;if(3===s){const t=3*iS[r];if(A_(a[t],a[t+1],a[t+2],e,i,n)>o)return!1}else if(2===s){const t=nS[r],s=3*(7&t),l=3*(t>>3&7),h=function(t,e,i,n,s,r,a,o,l){const h=n-t,c=s-e,u=r-i,d=y((h*(a-t)+c*(o-e)+u*(l-i))/(h*h+c*c+u*u));return A_(a,o,l,h*d+t,c*d+e,u*d+i)}(a[s],a[s+1],a[s+2],a[l],a[l+1],a[l+2],e,i,n);if(h>o)return!1}return!0}(n,t,e,i,o,l,s)}nS[5]=8,nS[6]=44,nS[9]=26,nS[10]=62,nS[20]=32,nS[24]=50,nS[36]=41,nS[40]=59,nS[17]=16,nS[18]=52,nS[33]=25,nS[34]=61;const rS=Td;function aS(t,e,i){const n=t[e],s=t[e+1],r=t[e+2],a=t[e+3],o=t[e+4],l=t[e+5];for(let t=0;t<24;t+=4)if(ep(i[t],i[t+1],i[t+2],i[t+3],n,s,r,a,o,l)<=0)return!1;return!0}const oS=new ArrayBuffer(4288),lS=new Float32Array(oS,0,24),hS=new Float32Array(oS,96,24),cS=new Uint32Array(oS,192,1024),uS=[];function dS(t,e,i,n,s,r){const a=function(t,e,i,n,s,r){let a=0;const o=i.binary_node_count;if(o<=0)return 0;const l=rS.pointer++;rS[l]=0;const h=o+i.leaf_node_count,c=i.float32,u=i.uint32;do{rS.pointer--;const e=rS[rS.pointer];if(e<o){if(!aS(c,6*e,s))continue;const t=1+(e<<1),i=t+1;i<h?(rS[rS.pointer++]=i,rS[rS.pointer++]=t):t<h&&(rS[rS.pointer++]=t)}else{const i=7*(e-o)+6*o,l=u[i+6],h=3&l,d=4294967288&l;if(0===h){if(!sS(n[d],n[d+1],n[d+2],n[d+3],r,s))continue}else{if(3!==h)throw new Error(`Unsupported light type ${h}`);if(!aS(c,i,s))continue}t[0+a]=l,a++}}while(rS.pointer>l);return a}(uS,0,e,r,hS,lS);if(s[t+1]=a,0===a)return 0;const o=1023&function(t,e){let i=e;for(let n=0;n<e;n++)i=31*i+t[n];return i>>>0}(uS,a),l=cS[o];if(4294967295!==l){if(function(t,e,i,n){for(let s=0;s<e;s++){const e=i[n+s];if(2*t[s]!==e)return!1}return!0}(uS,a,n,l))return s[t]=l,0}else cS[o]=i;s[t]=i;for(let t=0;t<a;t++){const e=uS[t];n[i+t]=e}return a}const pS=new pr,fS=new Yi,mS=new Yi,_S=new Yi;function gS(t,e,i){const n=3*i,s=e[n],r=e[n+1],a=e[n+2];t.set(s,r,a)}function yS(t,e,i,n,s,r){gS(fS,t,e),gS(mS,t,i),gS(_S,t,n),pS.setFromCoplanarPoints(fS,mS,_S),s[r]=pS.normal.x,s[r+1]=pS.normal.y,s[r+2]=pS.normal.z,s[r+3]=pS.constant}function vS(t,e,i,n){const s=t[e],r=t[e+1],a=t[e+2],o=t[e+3],l=-t[e+4],h=-t[e+5],c=-t[e+6],u=-t[e+7];i[n]=s,i[n+1]=r,i[n+2]=a,i[n+3]=o,i[n+4]=l,i[n+5]=h,i[n+6]=c,i[n+7]=u}function xS(t,e,i,n,s){const r=i.normal,a=n.normal,o=s.normal;return function(t,e,i,n,s,r,a,o,l,h,c,u,d,p){const f=o*d-l*u,m=l*c-a*d,_=a*u-o*c,g=u*s-d*n,y=d*i-c*s,v=c*n-u*i,x=n*l-s*o,w=s*a-i*l,b=i*o-n*a,S=C(i,n,s,f,m,_);if(0===S)return!1;const M=1/S,T=-r,A=(f*T-g*h-x*p)*M,E=(m*T-y*h-w*p)*M,z=(_*T-v*h-b*p)*M;return t[e]=A,t[e+1]=E,t[e+2]=z,!0}(t,e,r.x,r.y,r.z,i.constant,a.x,a.y,a.z,n.constant,o.x,o.y,o.z,s.constant)}class wS{constructor(t){this.light=t,this.address=0,this.bvh_leaf=new vu}compare(t){return this.light.compare(t.light)}update(){const t=this.bvh_leaf;this.light.getAABB(t.bounds),t.write_bounds()}link(t){this.bvh_leaf.link(t,this.light.id),this.update(),this.light.onDimensionChanged(this.update,this)}unlink(){this.light.offDimensionChanged(this.update,this),this.bvh_leaf.unlink()}}let bS=0;class SS{id=bS++;toString(){return`Light#${this.id}`}onDimensionChanged(t,e){throw new Error("Not Implemented")}offDimensionChanged(t,e){throw new Error("Not Implemented")}getCenter(t){throw new Error("Not Implemented")}getAABB(t){throw new Error("Not Implemented")}toArray(t,e){throw new Error("Not Implemented")}compare(t){return this.id-t.id}}SS.prototype.type="Abstract";const MS=[];class TS extends SS{constructor(){super(),this.transform=new Float32Array(16),this.transform_inverse=new Float32Array(16),this.uv=new Float32Array(4),this.color=new Float32Array(4),this.color.fill(1),this.texture_diffuse=null,this.draw_priority=0,this.__signal_transfom_changed=new _}setTransform(t){G(this.transform,t),H(this.transform_inverse,this.transform),this.__signal_transfom_changed.send0()}handleUvPositionChange(t,e){this.uv[0]=t,this.uv[1]=e}handleUvSizeChange(t,e){this.uv[2]=t,this.uv[3]=e}compare(t){if(t.isDecal){const e=this.draw_priority-t.draw_priority;if(0!==e)return e}return super.compare(t)}onDimensionChanged(t,e){this.__signal_transfom_changed.add(t,e)}offDimensionChanged(t,e){this.__signal_transfom_changed.remove(t,e)}getCenter(t){t[0]=this.transform[12],t[1]=this.transform[13],t[2]=this.transform[14]}getAABB(t){tp(MS,0,-.5,-.5,-.5,.5,.5,.5),function(t,e,i){const n=i[0],s=i[1],r=i[2],a=i[3],o=i[4],l=i[5],h=i[6],c=i[7],u=i[8],d=i[9],p=i[10],f=i[11],m=i[12],_=i[13],g=i[14],y=i[15];let v=Number.POSITIVE_INFINITY,x=Number.POSITIVE_INFINITY,w=Number.POSITIVE_INFINITY,b=Number.NEGATIVE_INFINITY,S=Number.NEGATIVE_INFINITY,M=Number.NEGATIVE_INFINITY;for(let t=0;t<24;t+=3){const i=e[t],T=e[t+1],A=e[t+2],C=1/(a*i+c*T+f*A+y),E=(n*i+o*T+u*A+m)*C,z=(s*i+l*T+d*A+_)*C,I=(r*i+h*T+p*A+g)*C;v>E&&(v=E),b<E&&(b=E),x>z&&(x=z),S<z&&(S=z),w>I&&(w=I),M<I&&(M=I)}t[0]=v,t[1]=x,t[2]=w,t[3]=b,t[4]=S,t[5]=M}(t,MS,this.transform)}toArray(t,e){return ed(this.transform_inverse,0,t,e,16),ed(this.uv,0,t,e+16,4),ed(this.color,0,t,e+20,4),24}}function AS(t,e){const i=function(t){if(!0===t.isPointLight)return 0;if(!0===t.isDecal)return 3;throw new Error("Unsupported light type")}(e);return i|t<<2}function CS(t,e){const i=t.elements,n=t.size;e.setLeafCount(n),e.initialize_structure();for(let t=0;t<n;t++){const n=i[t],s=n.bvh_leaf.bounds,r=AS(n.address,n.light);e.setLeafData(t,r,s[0],s[1],s[2],s[3],s[4],s[5])}e.build()}function ES(t,e){return e.light.id-t.light.id}TS.prototype.isDecal=!0,TS.prototype.ENCODED_SLOT_COUNT=24;class zS{#Vt=new Md;#Wt=new Map;constructor(){this.__tiles_resolution=new L(32,16,8),this.__cluster_texture_precision=8,this.__cluster_texture_needs_rebuild=!1,this.__cluster_texture=new oa(new Uint16Array(4),1,1,1),this.__cluster_texture.flipY=!1,this.__cluster_texture.generateMipmaps=!1,this.__cluster_texture.magFilter=Yt,this.__cluster_texture.minFilter=Yt,this.__cluster_texture.type=se,this.__cluster_texture.format=Te,this.__cluster_texture.internalFormat="RGBA16UI",this.__lookup_data=new tS,this.__lookup_data.type=0,this.__lookup_data.channel_count=1,this.__lookup_data.precision=8,this.__lookup_data.resize(1),this.__light_data=new tS,this.__light_data.type=2,this.__light_data.precision=32,this.__light_data.channel_count=4,this.__light_data.resize(8),this.__decal_atlas_texture=new Fl(new Uint8Array(4),1,1,me),this.__decal_atlas_texture.type=ee,this.__decal_atlas_texture.flipY=!1,this.__decal_atlas_texture.wrapS=Jt,this.__decal_atlas_texture.wrapT=Jt,this.__decal_atlas_texture.minFilter=1008,this.__decal_atlas_texture.magFilter=Kt,this.__decal_atlas_texture.generateMipmaps=!0,this.__decal_atlas_texture.anisotropy=8,this.__decal_atlas=new Bb({atlas:new Zb(512)}),this.__decal_patch_references=new Ub(this.__decal_atlas),this.__decal_references=new Map,this.__visible_lights=new _v(ES),this.__visible_decals=new _v(ES),this.__sorted_visible_lights=[],this.__visible_bvh_lights=new Qd,this.__visible_bvh_decals=new Qd,this.__view_frustum=new _r,this.__view_frustum_points=new Float32Array(24),this.__projection_matrix=new Float32Array(16),this.__cluster_planes=new Float32Array(1),this.__cluster_frustum_points=new Float32Array(1),this.setTileMapResolution(32,16,16),this.__visible_lights.onAdded.add(this.__handle_visible_light_added,this),this.__visible_lights.onRemoved.add(this.__handle_visible_light_removed,this),this.__visible_decals.onAdded.add(this.__handle_visible_decal_added,this),this.__visible_decals.onRemoved.add(this.__handle_visible_decal_removed,this),this.__light_data_needs_update=!0,this.__visible_bvh_needs_update=!0}requestDataUpdate(){this.__light_data_needs_update=!0}set decal_filtering_enabled(t){const e=this.__decal_atlas_texture;e.generateMipmaps!==t&&(e.generateMipmaps=t)}get decal_filtering_enabled(){return this.__decal_atlas_texture.generateMipmaps}__update_decal_atlas_texture(){const t=this.__decal_atlas.sampler;t.version!==this.__decal_atlas_texture.version&&(Ap(t,this.__decal_atlas_texture),this.__decal_atlas_texture.version=t.version)}__set_cluster_addressable_bit_range(t){const e=Math.ceil(t);return this.__cluster_texture_precision=e,Kb(Nb(0,e))!==this.__cluster_texture.type&&(this.__cluster_texture_needs_rebuild=!0,!0)}__update_cluster_texture(){this.__cluster_texture_needs_rebuild&&this.__build_cluster_texture()}__build_cluster_texture(){const t=Nb(0,this.__cluster_texture_precision),e=Kb(t),i=this.__cluster_texture;i.dispose();const n=i.image,s=this.__tiles_resolution;n.width=s.x,n.height=s.y,n.depth=s.z,i.type=e,i.internalFormat=Np(t,4);const r=qu[t];n.data=new r(s.x*s.y*s.z*4),i.needsUpdate=!0,this.__cluster_texture_needs_rebuild=!1}__ensure_lookup_size(t){return this.__lookup_data.resize(t)}getTextureLookup(){return this.__lookup_data.getTexture()}getTextureData(){return this.__light_data.getTexture()}getTextureClusters(){return this.__cluster_texture}getTextureDecalAtlas(){return this.__decal_atlas_texture}getResolution(){return this.__tiles_resolution}__handle_light_dimensions_change(){this.__visible_bvh_needs_update=!0,this.__light_data_needs_update=!0}__handle_visible_decal_added(t){this.__light_data_needs_update=!0;const e=t.light;e.onDimensionChanged(this.__handle_light_dimensions_change,this);const i=this.__decal_patch_references.acquire(e.texture_diffuse),n=i.getValue().uv;n.position.onChanged.add(e.handleUvPositionChange,e),n.size.onChanged.add(e.handleUvSizeChange,e),e.uv[0]=n.position.x,e.uv[1]=n.position.y,e.uv[2]=n.size.x,e.uv[3]=n.size.y,this.__decal_references.set(e,i)}__handle_visible_decal_removed(t){this.__light_data_needs_update=!0;const e=t.light;e.offDimensionChanged(this.__handle_light_dimensions_change,this);const i=this.__decal_references.get(e);if(void 0===i)return;const n=i.getValue().uv;n.position.onChanged.remove(e.handleUvPositionChange,e),n.size.onChanged.remove(e.handleUvSizeChange,e),i.release(),this.__decal_references.delete(e)}__handle_visible_light_added(t){this.__light_data_needs_update=!0,t.light.onDimensionChanged(this.__handle_light_dimensions_change,this)}__handle_visible_light_removed(t){this.__light_data_needs_update=!0,t.light.offDimensionChanged(this.__handle_light_dimensions_change,this)}__sort_visible_light_score(t){const e=lS;return t.light.getCenter(e),function(t,e,i,n){const s=n[0]*t+n[4]*e+n[8]*i+n[12],r=n[1]*t+n[5]*e+n[9]*i+n[13],a=n[2]*t+n[6]*e+n[10]*i+n[14],o=511.5/(n[3]*t+n[7]*e+n[11]*i+n[15]),l=r*o,h=a*o,c=g(s*o+511.5,0,1023),u=g(l+511.5,0,1023),d=g(h+511.5,0,1023);return Yd(Math.round(c),Math.round(u),Math.round(d))}(e[0],e[1],e[2],this.__projection_matrix)}__assess_sorting_score(t,e){let i=0;const n=[],s=[];for(let r=0;r<e;r++){const a=t[r],o=this.__sort_visible_light_score(a);a.light.getCenter(n);for(let a=r+1;a<e;a++){const e=t[a],r=this.__sort_visible_light_score(e);e.light.getCenter(s),i+=Math.abs(o-r)/u(s[0]-n[0],s[1]-n[1],s[2]-n[2])}}return i/(e*(e-1)*.5)}__sort_visible_light(){const t=this.__sorted_visible_lights,e=this.__visible_lights,i=e.size,n=this.__visible_decals,s=n.size,r=i+s;r>i&&t.splice(i,r-i),ed(e.elements,0,t,0,i),ed(n.elements,0,t,i,s),function(t,e,i,n=0,s=t.length-1,r=Pb,a){if(n>=s)return;let o,l,h=2;for(Db[0]=n,Db[1]=s;h>0;){h-=2;const n=Db[h+1],s=Db[h];o=s,l=n;const c=s+n>>1,u=e.call(i,t[c]);for(;o<=l;){for(;e.call(i,t[o])<u;)o++;for(;e.call(i,t[l])>u;)l--;o<=l&&(o!==l&&r.call(a,t,o,l),o++,l--)}s<l&&(Db[h++]=s,Db[h++]=l),o<n&&(Db[h++]=o,Db[h++]=n)}}(t,this.__sort_visible_light_score,this,0,r-1)}__update_visible_bvh(){this.__visible_bvh_needs_update=!1,CS(this.__visible_lights,this.__visible_bvh_lights),CS(this.__visible_decals,this.__visible_bvh_decals)}__build_view_frustum(t){Rm(t,this.__view_frustum,!1),Pb(this.__view_frustum.planes,4,5),this.__build_view_frustum_points()}__build_visible_light_list(){const t=this.__visible_lights;t.initializeUpdate();const e=this.__visible_decals;e.initializeUpdate();const i=[];Nf(this.__view_frustum.planes,hS);const n=im(i,0,this.#Vt,hS);for(let s=0;s<n;s++){const n=i[s],r=this.#Wt.get(n),a=r.light;if(!0===a.isDecal)e.push(r);else if(!0===a.isPointLight){const e=a.position;if(!sS(e.x,e.y,e.z,a.radius.getValue(),this.__view_frustum_points,hS))continue;t.push(r)}}t.finalizeUpdate(),e.finalizeUpdate()}__write_light_data_texture(){const t=this.__sorted_visible_lights,e=t.length;let i=0;for(let n=0;n<e;n++)i+=t[n].light.ENCODED_SLOT_COUNT;const n=i,s=this.__light_data;s.resize(Math.ceil(i/4)),s.update(),this.__lookup_data.precision=Math.max(0,Math.ceil(Math.log2(s.size)))+2;const r=s.getTexture(),a=r.image.data;i=0;for(let n=0;n<e;n++){const e=t[n],s=e.light;e.address=i>>2,i+=s.toArray(a,i),0!=(3&i)&&(i=1+(i>>2)<<2)}if(i!==n)throw new Error(`Expected light data size is ${n}, actual written data is size is ${i}`);r.needsUpdate=!0,this.__visible_bvh_needs_update=!0}__assign_lights_to_clusters(){const t=this.__tiles_resolution,e=t.z,i=t.y,n=t.x,s=n+1,r=i+1,a=s*r,o=this.__cluster_planes,l=this.__visible_bvh_lights,h=this.__visible_bvh_decals,c=4*s,u=c+4*r,d=this.__light_data.getTexture().image.data,p=n*i,f=this.__cluster_texture,m=f.image.data,_=this.__lookup_data;_.update();const g=_.getTexture(),y=g.image.data,v=this.__cluster_frustum_points;let x,w,b,S=0;for(cS.fill(4294967295),b=0;b<e;b++){const t=b*p;for(vS(o,u+4*b,hS,16),w=0;w<i;w++)for(vS(o,c+4*w,hS,8),x=0;x<n;x++){vS(o,0+4*x,hS,0),Ob(lS,b,a,w,s,x,v);const e=4*(t+w*n+x);S+=dS(e,l,S,y,m,d),S+=dS(e+2,h,S,y,m,d)}}f.needsUpdate=!0,g.needsUpdate=!0;const M=this.__lookup_data.size,T=this.__ensure_lookup_size(S),A=this.__set_cluster_addressable_bit_range(Math.max(0,Math.log2(S)));(T&&M<S||A)&&(this.__update_cluster_texture(),this.__assign_lights_to_clusters())}__build_cluster_frustum_planes(){const t=this.__tiles_resolution,e=t.z,i=t.y,n=t.x;!function(t,e,i,n,s){let r,a=0;const o=i+1,l=n+1,h=s+1,c=o*l,u=s*c;for(r=0;r<o;r++)yS(e,r,n*o+r,u+r,t,a),a+=4;for(r=0;r<l;r++)yS(e,r*o,u+r*o,r*o+i,t,a),a+=4;for(r=0;r<h;r++)yS(e,r*c,r*c+i,r*c+n*o,t,a),a+=4}(this.__cluster_planes,this.__cluster_frustum_points,n,i,e)}__build_view_frustum_points(){const t=this.__view_frustum;!function(t,e){const i=e[0],n=e[2],s=e[4];xS(t,0,i,n,s);const r=e[5];xS(t,3,i,n,r);const a=e[3];xS(t,6,i,a,s),xS(t,9,i,a,r);const o=e[1];xS(t,12,o,n,s),xS(t,15,o,n,r),xS(t,18,o,a,s),xS(t,21,o,a,r)}(this.__view_frustum_points,t.planes)}__build_cluster_frustum_points(){const t=this.__tiles_resolution,e=t.z,i=t.y,n=t.x;!function(t,e,i,n,s){const r=t[0],a=t[1],o=t[2],l=t[3],h=t[4],c=t[5],u=t[6],d=t[7],p=t[8],f=t[9],m=t[10],_=t[11],g=t[12],y=t[13],v=t[14],x=t[15],w=t[16],b=t[17],S=t[18],M=t[19],T=t[20],A=t[21],C=t[22],E=t[23],z=e+1,I=i+1,L=n+1,N=z*I;for(let t=0;t<L;t++){const L=t/n,P=1-L,D=t*N;for(let t=0;t<I;t++){const n=t/i,I=1-n,N=D+t*z;for(let t=0;t<z;t++){const i=t/e,z=1-i,D=z*I*P,F=z*I*L,O=z*n*P,R=z*n*L,k=i*I*P,B=i*I*L,U=i*n*P,V=i*n*L,W=r*D+l*F+u*O+f*R+g*k+x*B+S*U+A*V,G=a*D+h*F+d*O+m*R+y*k+w*B+M*U+C*V,H=o*D+c*F+p*O+_*R+v*k+b*B+T*U+E*V,j=3*(N+t);s[j]=W,s[j+1]=G,s[j+2]=H}}}}(this.__view_frustum_points,n,i,e,this.__cluster_frustum_points)}buildTiles(t){t.matrixWorldInverse.copy(t.matrixWorld),t.matrixWorldInverse.invert(),function(t,e,i){var n=e[0],s=e[1],r=e[2],a=e[3],o=e[4],l=e[5],h=e[6],c=e[7],u=e[8],d=e[9],p=e[10],f=e[11],m=e[12],_=e[13],g=e[14],y=e[15],v=i[0],x=i[1],w=i[2],b=i[3];t[0]=v*n+x*o+w*u+b*m,t[1]=v*s+x*l+w*d+b*_,t[2]=v*r+x*h+w*p+b*g,t[3]=v*a+x*c+w*f+b*y,v=i[4],x=i[5],w=i[6],b=i[7],t[4]=v*n+x*o+w*u+b*m,t[5]=v*s+x*l+w*d+b*_,t[6]=v*r+x*h+w*p+b*g,t[7]=v*a+x*c+w*f+b*y,v=i[8],x=i[9],w=i[10],b=i[11],t[8]=v*n+x*o+w*u+b*m,t[9]=v*s+x*l+w*d+b*_,t[10]=v*r+x*h+w*p+b*g,t[11]=v*a+x*c+w*f+b*y,v=i[12],x=i[13],w=i[14],b=i[15],t[12]=v*n+x*o+w*u+b*m,t[13]=v*s+x*l+w*d+b*_,t[14]=v*r+x*h+w*p+b*g,t[15]=v*a+x*c+w*f+b*y}(this.__projection_matrix,t.projectionMatrix.elements,t.matrixWorldInverse.elements),this.__build_view_frustum(t),this.__build_visible_light_list(),this.__decal_atlas.update(),this.__update_decal_atlas_texture(),this.__light_data_needs_update&&(this.__sort_visible_light(),this.__write_light_data_texture(),this.__light_data_needs_update=!1),this.__visible_bvh_needs_update&&this.__update_visible_bvh(),this.__build_cluster_frustum_points(),this.__build_cluster_frustum_planes(),this.__assign_lights_to_clusters()}dispose(){this.__cluster_texture.dispose(),this.__light_data.dispose(),this.__lookup_data.dispose(),this.__decal_atlas_texture.dispose()}setTileMapResolution(t,e,i){const n=this.__tiles_resolution;if(t===n.x&&e===n.y&&i===n.z)return;n.set(t,e,i),this.__cluster_texture_needs_rebuild=!0,this.__update_cluster_texture();const s=4*(t+1+(e+1)+(i+1)),r=(t+1)*(e+1)*(i+1)*3,a=new ArrayBuffer(4*(s+r));this.__cluster_planes=new Float32Array(a,0,s),this.__cluster_frustum_points=new Float32Array(a,4*s,r)}hasLight(t){return this.#Wt.has(t.id)}addLight(t){const e=new wS(t);e.link(this.#Vt),this.#Wt.set(t.id,e)}removeLight(t){const e=t.id,i=this.#Wt.get(e);return void 0!==i&&(i.unlink(),this.#Wt.delete(e),!0)}}class IS{transform(t){throw new Error("Not implemented")}}function LS(t,e,i){const n=t.indexOf(e);if(-1===n)return t;const s=n+e.length;return t.slice(0,s)+i+t.slice(s)}function NS(t,e,i,n){const s=t.indexOf(e);if(-1!==s){const i=s+e.length;return t.slice(0,i)+n+t.slice(i)}const r=t.indexOf(i);return-1===r?t:t.slice(0,r)+n+t.slice(r+i.length)}const PS="\n#ifndef FP_SHADER_CHUNK_ACCUMULATION\n #define FP_SHADER_CHUNK_ACCUMULATION\n \n // read light data\n for(uint i=0u; i < fp_cluster_metadata.y; i++){\n uint lookup_index = fp_cluster_metadata.x + i;\n\n uint light_descriptor = texelFetch(fp_t_light_lookup, address_to_data_texture_coordinates(lookup_index), 0 ).r;\n\n uint type = (light_descriptor) & 0x3u;\n uint light_address = light_descriptor >> 2;\n \n\n if(type == 0u){\n // point light\n \n vec4 light_data_0 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address), 0);\n vec4 light_data_1 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+1u), 0);\n \n vec3 light_position = light_data_0.xyz;\n float light_radius = light_data_0.w;\n \n vec3 light_color = light_data_1.xyz;\n float light_intensity = light_data_1.w;\n \n PointLight pointlight;\n \n pointlight.position = light_position;\n pointlight.distance = light_radius;\n pointlight.color = light_color*light_intensity;\n pointlight.decay = 1.0;\n \n fp_getPointDirectLightIrradiance( pointlight, directLight, vViewPosition );\n RE_Direct( directLight, geometry, material, reflectedLight );\n \n }\n }\n#endif\n",DS="\n#ifndef FP_SHADER_CHUNK_DECODE_PARS\n #define FP_SHADER_CHUNK_DECODE_PARS\n\n // don't rely on three.js light number define to ensure that point light calculations are available\n #if NUM_POINT_LIGHTS < 1\n struct PointLight {\n vec3 position;\n vec3 color;\n float distance;\n float decay;\n };\n #endif\n \n // directLight is an out parameter as having it as a return value caused compiler errors on some devices\n void fp_getPointDirectLightIrradiance( const in PointLight pointLight, out IncidentLight directLight, vec3 viewPosition ) {\n \n // TODO consider moving light position transformation to view-space over to CPU\n vec3 lVector = (viewMatrix*vec4(pointLight.position,1.0)).xyz + viewPosition;\n \n directLight.direction = normalize( lVector );\n \n float lightDistance = length( lVector );\n \n directLight.color = pointLight.color;\n directLight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n directLight.visible = ( directLight.color != vec3( 0.0 ) );\n }\n \n float convert_depth_to_linear(in float d){\n float d_n = 2.0*d - 1.0;\n \n float f = fp_f_camera_far;\n float n = fp_f_camera_near;\n \n float fn = f*n;\n \n float z_diff = f - n;\n \n float denominator = (f + n - d_n * z_diff );\n \n float z_view = (2.0*fn) / denominator;\n \n return (z_view - n) / z_diff;\n }\n \n ivec2 address_to_data_texture_coordinates(uint address){\n // Lookup texture has 128 width\n uint lookup_index_x = address % 128u;\n uint lookup_index_y = address >> 7;\n \n return ivec2(int(lookup_index_x),int(lookup_index_y));\n }\n#endif\n",FS="//@injection_point FORWARD_PLUS:accumulation",OS="\n #ifndef FP_SHADER_CHUNK_PREAMBLE\n #define FP_SHADER_CHUNK_PREAMBLE\n \n precision mediump usampler3D;\n precision mediump usampler2D;\n \n uniform usampler3D fp_t_light_tiles;\n \n uniform usampler2D fp_t_light_lookup;\n uniform sampler2D fp_t_light_data;\n uniform sampler2D fp_t_decal_atlas;\n uniform vec2 fp_t_decal_atlas_resolution; \n \n uniform vec3 fp_v3_light_cluster_resolution;\n \n uniform float fp_f_camera_near;\n uniform float fp_f_camera_far;\n \n #define gl_FragDepthEXT gl_FragDepth\n #define texture2D texture\n #define textureCube texture\n #define texture2DProj textureProj\n #define texture2DLodEXT textureLod\n #define texture2DProjLodEXT textureProjLod\n #define textureCubeLodEXT textureLod\n #define texture2DGradEXT textureGrad\n #define texture2DProjGradEXT textureProjGrad\n #define textureCubeGradEXT textureGrad\n \n uniform vec2 fp_resolution; \n \n #endif\n",RS="\n#ifndef FP_SHADER_CHUNK_LOAD_METADATA\n #define FP_SHADER_CHUNK_LOAD_METADATA\n\n ivec3 v3_cluster_resolution = textureSize(fp_t_light_tiles, 0);\n ivec3 v3_cluster_position = ivec3( clip_v.x * float(v3_cluster_resolution.x), clip_v.y*float(v3_cluster_resolution.y), (clip_v.z)*float(v3_cluster_resolution.z) );\n\n uvec4 fp_cluster_metadata = texelFetch( fp_t_light_tiles, v3_cluster_position, 0 ).rgba;\n \n#endif\n",kS=`\n vec3 clip_v = vec3( vec2(gl_FragCoord.x, gl_FragCoord.y) / fp_resolution, convert_depth_to_linear(gl_FragCoord.z));\n clip_v.x = 1.0 - clip_v.x;\n ${RS}\n `,BS=`\n ${OS}\n `,US=`\n vec3 fp_normalized_screen_position = ((gl_Position.xyz / gl_Position.w)+vec3(1.0))*0.5; \n vec3 clip_v = vec3( vec2(fp_normalized_screen_position.x, fp_normalized_screen_position.y), convert_depth_to_linear(fp_normalized_screen_position.z));\n ${RS}\n `,VS="@forward-plus-material-transformer";class WS extends IS{constructor({light_manager:t,resolution:e}){super(),this.__light_manager=t,this.__resolution=e;const i=this.__common_uniforms={fp_t_light_tiles:{type:"t",value:t.getTextureClusters()},fp_t_light_lookup:{type:"t",value:t.getTextureLookup()},fp_t_light_data:{type:"t",value:t.getTextureData()},fp_t_decal_atlas:{type:"t",value:t.getTextureDecalAtlas()},fp_t_decal_atlas_resolution:{type:"t",value:new Ri(1,1)},fp_f_camera_near:{type:"f",value:0},fp_f_camera_far:{type:"f",value:0},fp_resolution:{type:"v2",value:e}};this.__on_before_compile=t=>{Object.assign(t.uniforms,i),t.glslVersion=Ai,!0===t.defines.LIGHTING_VERTEX_ONLY?t.vertexShader=function(t){let e=OS+t;return e=LS(e,"void main() {",US),e=LS(e,"#include <lights_pars_begin>",DS),e=NS(e,"#include <lights_fragment_end>",FS,PS),e}(t.vertexShader):(t.vertexShader=LS("\n #define attribute in\n #define varying out\n #define texture2D texture\n \n varying vec3 v_world_position;\n "+t.vertexShader,"#include <worldpos_vertex>","\n #if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n // worldPosition comes from 'worldpos_vertex' shader chunk\n v_world_position = worldPosition.xyz;\n #else\n v_world_position = ( modelMatrix * vec4( transformed, 1.0 )).xyz;\n #endif\n "),t.fragmentShader=function(t){let e=BS;return-1===t.indexOf("v_world_position")&&(e+="\n varying vec3 v_world_position;\n "),-1===t.indexOf("#define gl_FragColor")&&-1===t.indexOf("pc_fragColor")&&(e+="\n out highp vec4 pc_fragColor;\n #define gl_FragColor pc_fragColor\n "),e+=t,e=LS(e,"void main() {",kS),e=LS(e,"#include <lights_pars_begin>",DS),e=function(t,e,i){const n=t.indexOf("#include <lights_fragment_begin>");if(-1===n)return t;const s=n;return t.slice(0,s)+"\n#ifndef FP_SHADER_CHUNK_APPLY_DECALS\n #define FP_SHADER_CHUNK_APPLY_DECALS\n \n // process decals\n for(uint i=0u; i < fp_cluster_metadata.w; i++){\n uint lookup_index = fp_cluster_metadata.z + i;\n\n uint light_descriptor = texelFetch(fp_t_light_lookup, address_to_data_texture_coordinates(lookup_index), 0 ).r;\n\n uint type = (light_descriptor) & 0x3u;\n uint light_address = light_descriptor >> 2;\n \n // decal\n vec4 light_data_0 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address), 0);\n vec4 light_data_1 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+1u), 0);\n vec4 light_data_2 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+2u), 0);\n vec4 light_data_3 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+3u), 0);\n \n mat4 decal_transform_matrix = mat4(\n light_data_0,\n light_data_1,\n light_data_2,\n light_data_3\n );\n \n vec4 local_position = decal_transform_matrix*vec4(v_world_position, 1.0);\n \n if(max3(abs(local_position.xyz)) < 0.5){\n \n // we're inside decal volume\n vec4 light_data_4 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+4u), 0);\n \n // compute normal of the decal, we get this by extracting rotation matrix and transforming (0,1,0) vector using that \n vec3 decal_normal = normalize(vec3(\n decal_transform_matrix[0][2], decal_transform_matrix[1][2], decal_transform_matrix[2][2]\n )); \n \n // Get geometry normal in world-space\n vec3 g_normal = normalize( ( transpose(viewMatrix) * vec4( normal, 0.0 ) ).xyz );\n \n float decal_surface_dot = dot(decal_normal, g_normal);\n \n // we fade out decals when the projection angle to the surface gets too steep\n // 0.7 is cos(45deg) and 0.5 is cos(60deg), dot returns cos of angle between two normals\n float decal_surface_angle_fade = smoothstep(-0.5,-0.7,decal_surface_dot);\n \n if(decal_surface_angle_fade <= 0.0){\n continue;\n }\n \n vec2 decal_local_uv = (local_position.xy + 0.5);\n vec2 decal_uv = decal_local_uv*light_data_4.zw + light_data_4.xy;\n \n vec4 decal_color = texture2D(fp_t_decal_atlas,decal_uv, -0.2);\n \n vec4 decal_color_tint = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+5u), 0);\n \n decal_color*= decal_color_tint;\n \n // compute decal alpha\n float decal_alpha = decal_color.a * decal_surface_angle_fade;\n \n if(decal_alpha < 0.003){\n continue;\n }\n \n material.diffuseColor = material.diffuseColor*(1.0-decal_alpha) + decal_color.xyz*decal_alpha;\n } \n \n }\n \n#endif\n"+t.slice(s)}(e),e=NS(e,"#include <lights_fragment_begin>",FS,PS),e}(t.fragmentShader))}}updateCamera(t){const e=this.__common_uniforms;e.fp_f_camera_far.value=t.camera.far,e.fp_f_camera_near.value=t.camera.near,e.fp_t_decal_atlas_resolution.value.set(e.fp_t_decal_atlas.value.image.width,e.fp_t_decal_atlas.value.image.height)}transform(t){if(t.hasOwnProperty(VS)){if(t[VS]!==this)throw new Error("The material is already transformed, but is associated with a different transformer instance");return t}let e=t;return function(t){return t.isMeshStandardMaterial||t.isShaderMaterial&&t.lights}(t)&&(e=t.clone(),t.isShaderMaterial&&(e.uniforms=Object.assign({},t.uniforms),e.defines=Object.assign({},t.defines)),e.onBeforeCompile=ug(t.onBeforeCompile,this.__on_before_compile),e[VS]=this),e}}class GS extends Mg{constructor(){super();const t=new zS;t.setTileMapResolution(16,8,8),this.__light_manager=t,this.__resolution=new Ri,this.__material_transformer=new WS({light_manager:this.__light_manager,resolution:this.__resolution})}setClusterResolution(t,e,i){this.__light_manager.setTileMapResolution(t,e,i)}__prepare_for_render(t){this.__material_transformer.updateCamera(t),this.__light_manager.buildTiles(t.camera)}updateResolution(){this.engine.graphics.getResolution(this.__resolution)}async startup(){const t=this.engine.graphics;t.getMaterialManager().addCompileStep(this.__material_transformer),t.viewport.size.onChanged.add(this.updateResolution,this),t.pixelRatio.onChanged.add(this.updateResolution,this),t.main_view.on.preRender.add(this.__prepare_for_render,this),this.updateResolution(),await super.startup()}async shutdown(){const t=this.engine.graphics;t.getMaterialManager().removeCompileStep(this.__material_transformer),t.viewport.size.onChanged.remove(this.updateResolution,this),t.pixelRatio.onChanged.remove(this.updateResolution,this),t.on.preRender.remove(this.__prepare_for_render,this),this.__light_manager.dispose(),await super.shutdown()}getLightManager(){return this.__light_manager}}const HS=[new Yi(-1,-1,0),new Yi(-1,-1,0),new Yi(-1,1,0),new Yi(-1,1,0),new Yi(1,-1,0),new Yi(1,-1,0),new Yi(1,1,0),new Yi(1,1,0)];class jS{entity=-1;system=null;components=[];__is_linked=!1;getDataset(){return this.system.entityManager.dataset}link(){this.__is_linked||(this.__is_linked=!0)}unlink(){this.__is_linked&&(this.__is_linked=!1)}}class qS extends SS{position=new L;radius=new id(1);color=new kd(1,1,1);intensity=new id(1);getCenter(t){this.position.writeToArray(t,0)}getAABB(t){const e=this.radius.getValue(),i=this.position,n=i.x,s=i.y,r=i.z;t[0]=n-e,t[1]=s-e,t[2]=r-e,t[3]=n+e,t[4]=s+e,t[5]=r+e}onDimensionChanged(t,e){this.position.onChanged.add(t,e),this.radius.onChanged.add(t,e)}offDimensionChanged(t,e){this.position.onChanged.remove(t,e),this.radius.onChanged.remove(t,e)}toArray(t,e){const i=this.position;t[e]=i.x,t[e+1]=i.y,t[e+2]=i.z,t[e+3]=this.radius.getValue();const n=this.color;return t[e+4]=n.r,t[e+5]=n.g,t[e+6]=n.b,t[e+7]=this.intensity.getValue(),8}}qS.prototype.isPointLight=!0,qS.prototype.ENCODED_SLOT_COUNT=8;class JS{constructor(){this.__c_transform=null,this.__c_light=null}get scaled_distance(){const t=this.__c_transform.scale,e=Pf(t.x,t.y,t.z);return this.__c_light.distance.getValue()*e}set component_transform(t){this.__c_transform=t}set component_light(t){this.__c_light=t}applySettings(t){}link(t){this.__c_transform.position.onChanged.add(this.__apply_position,this),this.__c_transform.rotation.onChanged.add(this.__apply_rotation,this),this.__c_transform.rotation.onChanged.add(this.__apply_scale,this);const e=this.__c_light;e.intensity.onChanged.add(this.__apply_intensity,this),e.color.onChanged.add(this.__apply_color,this),e.distance.onChanged.add(this.__apply_distance,this),e.angle.onChanged.add(this.__apply_angle,this),e.penumbra.onChanged.add(this.__apply_penumbra,this),e.castShadow.onChanged.add(this.__apply_castShadow,this);const i=e.type.getValue();i===zb.POINT?this.__apply_distance():i===zb.SPOT&&(this.__apply_angle(),this.__apply_penumbra()),this.__apply_intensity(),this.__apply_color(),this.__apply_castShadow(),this.__apply_position(),this.__apply_rotation(),this.__apply_scale(),this.applySettings(t.system.settings)}unlink(t){this.__c_transform.position.onChanged.remove(this.__apply_position,this),this.__c_transform.rotation.onChanged.remove(this.__apply_rotation,this),this.__c_transform.rotation.onChanged.remove(this.__apply_scale,this),this.__c_light.intensity.onChanged.remove(this.__apply_intensity,this),this.__c_light.color.onChanged.remove(this.__apply_color,this),this.__c_light.distance.onChanged.remove(this.__apply_distance,this),this.__c_light.angle.onChanged.remove(this.__apply_angle,this),this.__c_light.penumbra.onChanged.remove(this.__apply_penumbra,this),this.__c_light.castShadow.onChanged.remove(this.__apply_castShadow,this)}__apply_position(){}__apply_rotation(){}__apply_scale(){}__apply_intensity(){}__apply_color(){}__apply_distance(){}__apply_angle(){}__apply_penumbra(){}__apply_castShadow(){}}class $S extends JS{constructor(){super(),this.__light=null,this.bindings=[]}getPlugin(t){return t.system.__plugin.getValue()}#Gt(){this.__light.radius.set(this.scaled_distance)}link(t){const e=this.getPlugin(t).getLightManager(),i=new qS,n=this.__c_light,s=this.__c_transform;this.bindings.push(new Mm(n.distance.onChanged,this.#Gt,this),new Mm(s.scale.onChanged,this.#Gt,this)),i.intensity=n.intensity,i.color=n.color,i.position=s.position,n.__fp_light=i,this.__light=i,this.#Gt(),e.addLight(i);for(let t=0;t<this.bindings.length;t++)this.bindings[t].link()}unlink(t){this.getPlugin(t).getLightManager().removeLight(this.__light);for(let t=0;t<this.bindings.length;t++)this.bindings[t].unlink();this.bindings.splice(0,this.bindings.length)}}class YS{constructor(){this.views=[]}}function XS(t,e){const i=t.__threeObject;if(e.toEulerAnglesXYZ(i.rotation),void 0!==i.target){const t=i.target.position;t.set(0,0,1).applyQuaternion(e),t.set(i.position.x+t.x,i.position.y+t.y,i.position.z+t.z),i.target.updateMatrixWorld(!0)}Lm(t.__threeObject)}const ZS=new cl;ZS.autoUpdate=!1,ZS.matrixAutoUpdate=!1,ZS.matrixWorldNeedsUpdate=!1;const KS=new $o({depthPacking:xi,side:tt});function QS(t){let e;const i=t.customDepthMaterial;return e=void 0!==i?i:KS,e}function tM(t){if(!1===t.castShadow)return!1;if(!1===t.visible)return!1;if(t.isMesh){const e=t.customDepthMaterial?t.customDepthMaterial:t.material;if(e&&!1===e.visible)return!1}return!0}class eM extends JS{constructor(){super(),this.__system=null,this.__shadow_map=null,this.__object_map=new WeakMap}link(t){this.__system=t.system;const e=this.__system.__three_light_cache;(function(t,e){null===t.__threeObject&&(t.__threeObject=function(t,e){const i=t.intensity.getValue(),n=t.color.toUint(),s=t.type.getValue(),r=e.obtain(s);switch(s){case zb.DIRECTION:break;case zb.SPOT:r.angle=t.angle.getValue(),r.penumbra=t.penumbra.getValue(),r.distance=t.distance.getValue();break;case zb.POINT:case zb.AMBIENT:break;default:throw new Error("Unknown light type: "+t.type)}return r.color.setHex(n),r.intensity=i,r.castShadow=t.castShadow.getValue(),r}(t,e))})(this.__c_light,e),super.link(t)}unlink(t){this.__system.__three_light_cache.release(this.__three_getLight()),this.__c_light.__threeObject=null,this.__shadowmap_unlink(),super.unlink(t)}__three_getLight(){return this.__c_light.__threeObject}__apply_intensity(){this.__three_getLight().intensity=this.__c_light.intensity.getValue()}__apply_color(){const t=this.__c_light.color;this.__three_getLight().color.setRGB(t.r,t.g,t.b)}__apply_distance(t){this.__three_getLight().distance=this.scaled_distance}__apply_angle(){this.__three_getLight().angle=this.__c_light.angle.getValue()}__apply_penumbra(){this.__three_getLight().penumbra=this.__c_light.penumbra.getValue()}__shadowmap_link(){this.__shadow_map=new YS;const t=new Av;t.name="Shadow Map",this.__shadow_map.views.push(t),this.__system.__shadows.add(this.__shadow_map),t.on.preVisibilityBuild.add(this.__shadowmap_prepare_view,this),t.on.postVisibilityBuild.add(this.__shadowmap_render,this)}__shadowmap_unlink(){null!==this.__shadow_map&&(this.__system.__shadows.remove(this.__shadow_map),this.__shadow_map=null)}__shadowmap_prepare_view(){const t=this.__shadow_map.views[0],e=this.__three_getLight().shadow.camera;e.updateMatrix(),e.updateMatrixWorld(),t.set_from_camera(e)}__shadowmap_render(){const t=this.__shadow_map.views[0];t.on.preRender.send1(t);const e=this.__system.__graphics,i=this.__three_getLight(),n=i.shadow,s=t.visible_objects,r=s.size;hv.INSTANCE.build_scene({scene:ZS,input:s.elements,input_size:r,material_extractor:QS,object_filter:tM}),e.shadowmap_renderer.update(e.renderer,n,ZS,i)}__apply_castShadow(){const t=this.__c_light.castShadow.getValue();this.__three_getLight().castShadow=t,t&&null===this.__shadow_map?this.__shadowmap_link():t||null===this.__shadow_map||this.__shadowmap_unlink()}__apply_position(){const t=this.__c_transform,e=t.position,i=this.__three_getLight();i.position.set(e.x,e.y,e.z);const n=this.__c_light,s=n.type.getValue();s===zb.SPOT||s===zb.DIRECTION?XS(n,t.rotation):Lm(i)}__apply_rotation(){XS(this.__c_light,this.__c_transform.rotation)}__apply_scale(){this.__three_getLight().distance=this.scaled_distance}applySettings(t){const e=this.__three_getLight().shadow;if(void 0!==e){e.autoUpdate=!1,e.camera.matrixAutoUpdate=!1;const i=parseInt(t.shadowResolution);e.radius=1,e.blurSamples=8,function(t,e){const i=t.mapSize;i.width===e&&i.height===e||(i.width=i.height=e,null!==t.map&&(t.map.dispose(),t.map=null))}(e,i)}}}class iM extends jS{constructor(){super(),this.__binding=null}getLight(){return this.components[0]}getTransform(){return this.components[1]}__rebuild(){this.__binding.unlink(this),this.__build(),this.__binding.link(this)}__build(){this.getLight().type.getValue()===zb.POINT&&this.system.__use_forward_plus?this.__binding=new $S:this.__binding=new eM,this.__binding.component_light=this.getLight(),this.__binding.component_transform=this.getTransform()}applySettings(){this.__binding.applySettings(this.system.settings)}link(){this.__build(),this.__binding.link(this),this.getLight().type.onChanged.add(this.__rebuild,this)}unlink(){this.getLight().type.onChanged.remove(this.__rebuild,this),this.__binding.unlink(this)}}class nM{constructor(){this.__graphics=null,this.__maps=new nf}set graphics(t){this.__graphics=t}add(t){return!this.__maps.contains(t)&&(this.__maps.add(t),t.views.forEach(this.__graphics.views.add,this.__graphics.views),!0)}remove(t){const e=this.__maps.removeOneOf(t);return e&&t.views.forEach(this.__graphics.views.remove,this.__graphics.views),e}}function sM(t,e){let i=t.get(e);return void 0===i&&(i=[],t.set(e,i)),i}class rM{constructor(){this.__used=new Map,this.__available=new Map,this.__scene=null}__getUsed(t){return sM(this.__used,t)}__getAvailable(t){return sM(this.__available,t)}__create(t){const e=function(t){switch(t){case zb.POINT:return new Wc(0,0,0,1);case zb.AMBIENT:return new jc(0,0);case zb.DIRECTION:return new Hc(0,0);case zb.SPOT:return new Oc(0,0,0,0,0,1);default:throw new Error("Unknown light type: "+t)}}(t);return null!==this.__scene&&this.__scene.add(e),e}attach(t){this.__scene!==t&&(null!==this.__scene&&this.detach(),this.__scene=t,this.__traverseAllLight(t.add,t))}detach(){const t=this.__scene;null!==t&&(this.__traverseAllLight(t.remove,t),this.__scene=null)}__traverseAllLight(t,e){for(const[i,n]of this.__used)n.forEach(t,e);for(const[i,n]of this.__available)n.forEach(t,e)}obtain(t){const e=this.__getAvailable(t);let i;return i=e.length<=0?this.__create(t):e.pop(),this.__getUsed(t).push(i),i}release(t){const e=function(t){if(t.isPointLight)return zb.POINT;if(t.isSpotLight)return zb.SPOT;if(t.isDirectionalLight)return zb.DIRECTION;if(t.isAmbientLight)return zb.AMBIENT;throw new Error("Unsupported light type")}(t),i=this.__getUsed(e),n=i.indexOf(t);return-1!==n&&(function(t){t.intensity=0,void 0!==t.castShadow&&(t.castShadow=!1)}(t),i.splice(n,1),this.__getAvailable(e).push(t),!0)}countTotalByType(t){const e=this.__getAvailable(t),i=this.__getUsed(t);return e.length+i.length}reserve(t,e){let i=this.countTotalByType(t);for(;i<e;i++){const e=this.__create(t);this.__getAvailable(t).push(e)}}}class aM extends Lb{constructor(t,e={}){super(iM);const i=t.graphics;this.dependencies=[Ib,B],this.components_used=[Tm.from(Ib,2)],this.engine=t,this.scene=i.scene,this.settings=e,this.__graphics=i,this.__camera_object=null,this.bindings=[],this.__shadows=new nM,this.__shadows.graphics=i,this.__use_forward_plus=!0,this.__plugin=null,this.__three_light_cache=new rM,this.__three_light_cache.attach(this.scene),void 0!==e.preAllocateLightsDirection&&this.__three_light_cache.reserve(zb.DIRECTION,e.preAllocateLightsDirection),void 0!==e.preAllocateLightsSpot&&this.__three_light_cache.reserve(zb.SPOT,e.preAllocateLightsSpot),void 0!==e.preAllocateLightsPoint&&this.__three_light_cache.reserve(zb.POINT,e.preAllocateLightsPoint),void 0!==e.preAllocateLightsAmbient&&this.__three_light_cache.reserve(zb.AMBIENT,e.preAllocateLightsAmbient)}get componentClass(){return Ib}setConfiguration(t,e){this.settings[t]=e;const i=this.entityManager;if(null===i)return;const n=i.dataset;null!==n&&n.traverseComponents(Ib,this.applySettingsOne,this)}applySettingsOne(t,e){this.__getEntityContext(e).applySettings()}async startup(t,e,i){this.__use_forward_plus&&(this.__plugin=await this.engine.plugins.acquire(GS)),this.__graphics.on.visibilityConstructionEnded.add(this.__updateShadowCameraForActiveCamera,this),super.startup(t,e,i)}shutdown(t,e,i){null!==this.__plugin&&(this.__plugin.release(),this.__plugin=null),this.__graphics.on.visibilityConstructionEnded.remove(this.__updateShadowCameraForActiveCamera,this),super.shutdown(t,e,i)}__updateShadowCameraForActiveCamera(){const t=this.entityManager.dataset;null!==t&&t.traverseComponents(Vm,this.__updateShadowCameraForCamera,this)}__visit_entity_to_update_shadow(t,e){const i=t.__threeObject;null!==i&&t.type.getValue()!==zb.AMBIENT&&(t.castShadow.getValue()?(i.castShadow=!0,lM(this.__camera_object,i,this.__graphics)):i.castShadow=!1)}__updateShadowCameraForCamera(t,e){const i=this.entityManager.dataset;return!t.active.getValue()||(this.__camera_object=t.object,null===this.__camera_object||i.traverseComponents(Ib,this.__visit_entity_to_update_shadow,this),!1)}}const oM=new op;function lM(t,e){const i=e.shadow;if(void 0===i)return;const n=i.camera;(function(t,e,i,n,s){HS[0].set(-1,-1,t),HS[1].set(-1,-1,e),HS[2].set(-1,1,t),HS[3].set(-1,1,e),HS[4].set(1,-1,t),HS[5].set(1,-1,e),HS[6].set(1,1,t),HS[7].set(1,1,e);let r=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY,l=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;for(let t=0;t<8;t++){const e=HS[t];e.unproject(i),e.applyMatrix4(n),e.x<r&&(r=e.x),e.x>l&&(l=e.x),e.y<a&&(a=e.y),e.y>h&&(h=e.y),e.z<o&&(o=e.z),e.z>c&&(c=e.z)}s.setBounds(r,a,o,l,h,c)})(-1,1,t,n.matrixWorldInverse,oM),function(t,e,i,n,s,r,a,o){const l=r-i,h=a-n,c=t.x,u=t.y,d=l/c,p=h/u,f=i-i%d-d/2,m=n-n%p-p/2,_=f+l*((c+1)/c),g=m+h*((u+1)/u);e.left=f,e.right=_,e.bottom=m,e.top=g}(i.mapSize,n,oM.x0,oM.y0,oM.z0,oM.x1,oM.y1,oM.z1),n.near=.1,n.far=100,n.updateProjectionMatrix(),i.bias=-1e-4}class hM{level=new id(0);color=new kd(0,.3,.5);shoreDepthTransition=new Wd(.7,2);shoreColor=new kd(.584,.792,.85);waveSpeed=new id(1.8);waveAmplitude=new id(.3);waveFrequency=new id(1);scattering=new id(1.2);bvh=new vu;constructor(t){void 0!==t&&this.fromJSON(t),this.__shader=null,this.__threeObject=null,this.color.onChanged.add(this.writeShaderUniforms,this),this.shoreDepthTransition.onChanged.add(this.writeShaderUniforms,this),this.shoreColor.onChanged.add(this.writeShaderUniforms,this),this.waveSpeed.onChanged.add(this.writeShaderUniforms,this),this.waveAmplitude.onChanged.add(this.writeShaderUniforms,this),this.waveFrequency.onChanged.add(this.writeShaderUniforms,this),this.scattering.onChanged.add(this.writeShaderUniforms,this)}updateTransform(){const t=this.__threeObject;null!==t&&(t.rotation.x=.5*Math.PI,t.position.x=200,t.position.z=200,t.position.y=this.level.getValue(),Lm(t)),this.updateBounds()}updateBounds(){const t=this.level.getValue();this.bvh.resize(-200,t,-200,600,t,600)}updateShaderForTerrain(t,e){const i=this.__shader;if(null===i)return;const n=t.size.x*t.gridScale,s=t.size.y*t.gridScale,r=new Fl(t.samplerHeight.data,t.samplerHeight.width,t.samplerHeight.height,xe,oe);r.wrapS=Jt,r.wrapT=Jt,r.generateMipmaps=!1,r.minFilter=Kt,r.magFilter=Kt,r.flipY=!1,r.internalFormat="R32F",i.uniforms.tHeightTexture.value=r,i.uniforms.vHeightUv.value.set(-.25,-.25,e/n,e/s),i.uniforms.vHeightTextureResolution.value.set(t.samplerHeight.width,t.samplerHeight.height)}writeShaderUniforms(){const t=this.__shader;if(null===t)return;const e=t.uniforms;e.waterColor.value.setRGB(this.color.r,this.color.g,this.color.b),e.shoreColor.value.setRGB(this.shoreColor.r,this.shoreColor.g,this.shoreColor.b),e.fWaveSpeed.value=this.waveSpeed.getValue(),e.fWaveAmplitude.value=this.waveAmplitude.getValue(),e.fWaveFrequency.value=this.waveFrequency.getValue(),e.fScattering.value=this.scattering.getValue(),e.vShoreDepthTransition.value.set(this.shoreDepthTransition.min,this.shoreDepthTransition.max)}fromJSON(t){"number"==typeof t.level&&this.level.fromJSON(t.level),"object"==typeof t.color&&this.color.fromJSON(t.color)}toJSON(){return{level:this.level.toJSON(),color:this.color.toJSON()}}}hM.typeName="Water";class cM extends Cm{dependencies=[hM];bvh=new Md;cleaup=[];updateQueue=[];__time_delta=0;constructor(t){super(),this.graphicsEngine=t,this.renderLayer=null}shutdown(t,e,i){try{this.graphicsEngine.size.onChanged.remove(this.setViewportSize),this.graphicsEngine.layers.remove(this.renderLayer),e()}catch(t){i(t)}}startup(t,e,i){this.entityManager=t;const n=this.graphicsEngine;this.renderLayer=n.layers.create(cM.RENDER_LAYER_NAME);const s=n.viewport.size;this.renderLayer.buildVisibleSet=function(t,e,i,n){const s=[];return function(n,r,a){if(null===t)return 0;const o=t.dataset;if(null===o)return 0;const l=im(s,0,e,a.frustum);let h=0;for(let t=0;t<l;t++)h+=i.call(void 0,n,r+h,s[t],o);return h}}(this.entityManager,this.bvh,((t,e,i,n)=>{const s=n.getComponent(i,hM).__threeObject;return null===s?0:(t[e]=s,1)}));const r=this;n.on.preRender.add((function(t,e,i){const a=r.entityManager.dataset;if(null===a)return;const o=n.computeTotalPixelRatio();a.traverseComponents(hM,(function(t,i){const n=t.__shader;n.uniforms.fCameraNear.value=e.near,n.uniforms.fCameraFar.value=e.far,n.uniforms.vScreenResolution.value.set(s.x*o,s.y*o)}))})),e()}link(t,e){const i=this.graphicsEngine.frameBuffers.getById(kg);let n;if(null===t.__shader?(n=function(){const t={time:{type:"f",value:0},fCameraNear:{type:"f",value:0},fCameraFar:{type:"f",value:0},vHeightUv:{type:"v4",value:new ji},tHeightTexture:{type:"t",value:null},vHeightTextureResolution:{type:"v2",value:new Ri},tDepthTexture:{type:"t",value:null},vScreenResolution:{type:"v2",value:new Ri},waterColor:{type:"c",value:new ys},shoreColor:{type:"c",value:new ys(9816793)},fWaveSpeed:{type:"f",value:1.8},fScattering:{type:"f",value:1.2},fWaveAmplitude:{type:"f",value:.3},fWaveFrequency:{type:"f",value:3},vShoreDepthTransition:{type:"v2",value:new Ri(.7,2)}};return new nr({vertexShader:"\n\nvarying vec2 vUv; \nvarying float level;\n\nvarying vec3 vWorldPosition;\n\nvoid main(){\n\n vUv = uv;\n \n vWorldPosition = (modelMatrix * vec4(position, 1.0)).xyz;\n \n level = vWorldPosition.y;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"\nuniform vec3 waterColor;\nuniform vec3 shoreColor;\n\nuniform float fScattering;\n\nuniform sampler2D tHeightTexture;\nuniform sampler2D tDepthTexture;\n\nuniform vec2 vHeightTextureResolution;\n\nuniform vec2 vScreenResolution;\n\nuniform float fCameraNear;\nuniform float fCameraFar;\n\nuniform vec4 vHeightUv;\n\nuniform float time;\n\nuniform float fWaveAmplitude;\nuniform float fWaveSpeed;\nuniform float fWaveFrequency;\n\nuniform vec2 vShoreDepthTransition;\n\nvarying vec2 vUv;\nvarying float level;\nvarying vec3 vWorldPosition;\n\nfloat depthToLinear( float z, float cameraNear, float cameraFar ) {\n float z_n = 2.0 * z - 1.0;\n \n float z_e = 2.0 * cameraNear * cameraFar / (cameraFar + cameraNear - z_n * (cameraFar - cameraNear));\n\n return z_e;\n}\n\t \nvec4 sampleTextureGaussian( sampler2D tex,vec2 uv, vec2 texelSize){\n float r = 1.0;\n \n float dx0 = - texelSize.x * r;\n float dy0 = - texelSize.y * r;\n float dx1 = + texelSize.x * r;\n float dy1 = + texelSize.y * r;\n \n return (\n texture2D(tex, uv + vec2( dx0, dy0 ) ) +\n texture2D(tex, uv + vec2( 0.0, dy0 ) ) +\n texture2D(tex, uv + vec2( dx1, dy0 ) ) +\n texture2D(tex, uv + vec2( dx0, 0.0 ) ) +\n texture2D(tex, uv) +\n texture2D(tex, uv + vec2( dx1, 0.0 ) ) +\n texture2D(tex, uv + vec2( dx0, dy1 ) ) +\n texture2D(tex, uv + vec2( 0.0, dy1 ) ) +\n texture2D(tex, uv + vec2( dx1, dy1 ) )\n ) * ( 1.0 / 9.0 );\n}\n\nvec4 blur9(sampler2D image, vec2 uv, vec2 texelSize, vec2 direction) {\n vec4 color = vec4(0.0);\n vec2 off1 = vec2(1.3846153846) * direction;\n vec2 off2 = vec2(3.2307692308) * direction;\n color += texture2D(image, uv) * 0.2270270270;\n color += texture2D(image, uv + (off1 * texelSize )) * 0.3162162162;\n color += texture2D(image, uv - (off1 * texelSize )) * 0.3162162162;\n color += texture2D(image, uv + (off2 * texelSize )) * 0.0702702703;\n color += texture2D(image, uv - (off2 * texelSize )) * 0.0702702703;\n return color;\n}\n\nvec4 blur13(sampler2D image, vec2 uv, vec2 texelSize, vec2 direction) {\n vec4 color = vec4(0.0);\n vec2 off1 = vec2(1.411764705882353) * direction;\n vec2 off2 = vec2(3.2941176470588234) * direction;\n vec2 off3 = vec2(5.176470588235294) * direction;\n color += texture2D(image, uv) * 0.1964825501511404;\n color += texture2D(image, uv + (off1 * texelSize)) * 0.2969069646728344;\n color += texture2D(image, uv - (off1 * texelSize)) * 0.2969069646728344;\n color += texture2D(image, uv + (off2 * texelSize)) * 0.09447039785044732;\n color += texture2D(image, uv - (off2 * texelSize)) * 0.09447039785044732;\n color += texture2D(image, uv + (off3 * texelSize)) * 0.010381362401148057;\n color += texture2D(image, uv - (off3 * texelSize)) * 0.010381362401148057;\n return color;\n} \n\nvoid main(){\n\n //compute view depth\n float screenEnvDepth = texture2D(tDepthTexture, gl_FragCoord.xy / vScreenResolution ).x;\n \n float screenEnvDepthLinear = depthToLinear(screenEnvDepth, fCameraNear, fCameraFar);\n \n float objectDepth = gl_FragCoord.z;\n \n float objectDepthLinear = depthToLinear(objectDepth, fCameraNear, fCameraFar);\n\n float viewDepth = screenEnvDepthLinear - objectDepthLinear;\n \n if(viewDepth < 0.0){\n discard;\n }\n \n //sample water depth relative to the sky\n vec2 depthUV = (vUv + vHeightUv.xy) * vHeightUv.zw;\n \n float height = blur13( tHeightTexture, depthUV, 1.0 / vHeightTextureResolution, vec2(1.0) ).r;\n \n float depth = level - height;\n \n float geoHash = (vWorldPosition.x+ vWorldPosition.z)*fWaveFrequency;\n \n float waveHeightModifier = sin(geoHash + time*fWaveSpeed) / 3.14159265359;\n \n float waveHeight = depth + fWaveAmplitude * waveHeightModifier;\n \n float deepColorFactor = smoothstep(vShoreDepthTransition.x, vShoreDepthTransition.y, waveHeight);\n \n vec4 color = mix(\n vec4(shoreColor, 0.8), \n vec4(waterColor, 1.0), \n deepColorFactor\n );\n \n //this simulates scattering under water\n float scatteringFactor = 1.0 - exp( - viewDepth * fScattering );\n \n float fogAmount = scatteringFactor;\n\n gl_FragColor = color;\n \n gl_FragColor.a *= fogAmount;\n}\n",uniforms:t,blending:it,lights:!1,fog:!1,depthTest:!1,depthWrite:!1,transparent:!0,vertexColors:!1})}(),n.uniforms.tDepthTexture.value=i.renderTarget.depthTexture,t.__shader=n,t.writeShaderUniforms()):n=t.__shader,n.side=Q,null===t.__threeObject){const e=new vr(800,800,1,1),i=_p(e,n);t.__threeObject=i}t.updateTransform(),t.level.onChanged.add(t.updateTransform,t),t.bvh.link(this.bvh,e),this.cleaup[e]=function(){t.level.onChanged.remove(t.updateTransform,t)},this.updateQueue.push(t)}unlink(t,e){t.bvh.unlink(),(0,this.cleaup[e])(),delete this.cleaup[e];const i=this.updateQueue.indexOf(t);-1!==i&&this.updateQueue.splice(i,1)}processUpdateQueue(){const t=this.updateQueue;let e=t.length;if(0===e)return;const i=this.entityManager.dataset;if(null===i)return;const n=function(t,e=Mf){const i=t.getAnyComponent(If),n=i.component;return e(n,i.entity),n}(i);if(null!==n)for(let i=0;i<e;i++)t[i].updateShaderForTerrain(n,800),t.splice(i,1),i--,e--}__visit_component(t,e){const i=t.__shader;void 0!==i&&(i.uniforms.time.value+=this.__time_delta)}update(t){this.__time_delta=t;const e=this.entityManager.dataset;null!==e&&(this.processUpdateQueue(),e.traverseComponents(hM,this.__visit_component,this))}}cM.RENDER_LAYER_NAME="water-system";class uM{constructor(t){this.scripts=t instanceof Array?t:"function"==typeof t?[t]:[]}}uM.typeName="Script",uM.serializable=!1;const dM=new L;class pM{constructor(t,e){const i=t.component,n=new Eu(0,0),s={panUp:!1,panDown:!1,panLeft:!1,panRight:!1},r=new fb;function a(i,n,s){i.forEach((i=>{r.bind("keyboard/keys/"+i+"/down",(()=>{n[s]=!0,e.sendEvent(t.entity,"user-input")})),r.bind("keyboard/keys/"+i+"/up",(()=>n[s]=!1))}))}a(["down_arrow","s"],s,"panDown"),a(["up_arrow","w"],s,"panUp"),a(["left_arrow","a"],s,"panLeft"),a(["right_arrow","d"],s,"panRight"),r.on.unlinked.add((function(){s.panDown=!1,s.panUp=!1,s.panLeft=!1,s.panRight=!1}));const o=new uM((function(r){if(n.set(0,0),s.panDown&&(n.y+=1),s.panUp&&(n.y-=1),s.panLeft&&(n.x-=1),s.panRight&&(n.x+=1),n.isZero())return;const a=n.clone().multiplyScalar(10*r),o=e.getComponent(t.entity,B);dM.set(-a.x,0,-a.y),dM.applyQuaternion(o.rotation),i.target.add(dM)})),l=new d_;this.builder=l.add(r).add(Jg.Transient).add(Yg.fromJSON(["Keyboard Camera Controller"])).add(o)}build(t){return this.builder.build(t)}}function fM(t,e){return"function"==typeof t.hasOwnProperty?t.hasOwnProperty(e):void 0!==t[e]}function mM(t){const e=Object.keys(t),i=e.length;return i>10&&(e.splice(0,10),e.push(`[... ${i-10} more options]`)),e}function _M(t,e,i){return function(t,e,i){let n=t;e.length>0&&""===e[0]&&e.shift();const s=e.length;for(let t=0;t<s;t++){const r=e[t];if(!fM(n,r)){if("function"!=typeof i){const i=mM(n);throw new Error(`failed to resolve path [${e.join(",")}] at part ${t} [${r}]. Existing keys: ${i.join(", ")}`)}i(n,r,t,s)}n=n[r]}return n}(t,e.split("/"),i)}function gM(t,e,i){class n{constructor(t){this.signal=t,this.running=!1,this.deferred=[],this.bindings=[]}handler(){const t=this.bindings,e=t.length;for(let i=0;i<e;i++){const e=t[i];if(e.listener.apply(void 0,arguments),e.exclusive)break}this.__processDeferred()}__processDeferred(){const t=this.deferred,e=t.length;for(let i=0;i<e;i++){const e=t[i];this.registerBinding(e)}this.deferred=[]}registerBinding(t){this.bindings.push(t),this.bindings.sort(((t,e)=>t.exclusive&&!e.exclusive?-1:!t.exclusive&&e.exclusive?1:e.priotity-t.priority))}start(){this.signal.add(this.handler,this)}stop(){this.signal.remove(this.handler,this)}add(t){this.registerBinding(t)}remove(t){const e=this.bindings.indexOf(t);if(-1!==e)this.bindings.splice(e,1);else{const e=this.deferred.indexOf(t);this.deferred.splice(e,1)}}}return function(t,e,s){if(t.hasOwnProperty(e))return t[e];{let s=function(){const t=new n(i);return t.start(),t}();return t[e]=s,s}}(t,e)}function yM(t,e,i){t.forEach((function(t){const n=t.path,s=_M(e,n);gM(i,n,s).add(t)}))}function vM(t,e,i){t.forEach((function(t){const n=t.path,s=_M(e,n);gM(i,n,s).remove(t)}))}class xM extends Cm{constructor(t){super(),this.enabled=new Hd(!0),this.dependencies=[fb],this.devices=t;const e=this;this.enabled.onChanged.add((function(t){const i=e.entityManager.dataset;null!==i&&(t?i.traverseComponents(fb,(function(t){yM(t.mapping,e.devices,e.proxies)})):i.traverseComponents(fb,(function(t){vM(t.mapping,e.devices,e.proxies)})))}))}startup(t,e,i){this.entityManager=t,this.proxies={},e()}link(t,e){yM(t.mapping,this.devices,this.proxies)}unlink(t,e){vM(t.mapping,this.devices,this.proxies),t.on.unlinked.send1(e)}}class wM{level=3;getLevel(){return this.level}setLevel(t){this.level=t}log(t,e){throw new Error("Abstract class, method needs to be implemented in the subclass")}}let bM;class SM extends wM{log(t,e){switch(t){case 1:case 0:case 2:return}}static get INSTANCE(){return void 0===bM&&(bM=new SM),bM}}function MM(){const t={};if(void 0===window)return t;const e=window.location.hash,i=/([a-zA-Z0-9\-\_]+)\=([a-zA-Z0-9\-\_]+)/g;let n;for(;null!==(n=i.exec(e));){const e=n[1],i=n[2];t[e]=i}return t}class TM{constructor(){}getUnlocked(){throw new Error("Not implemented")}unlock(t){throw new Error("Not implemented")}}class AM extends TM{constructor(t,e="achievements"){super(),this.storage=t,this.key=e,this.last=Promise.resolve()}getUnlocked(){return new Promise(((t,e)=>{this.storage.load(this.key,(e=>{t(void 0===e?[]:e)}),e,Mf)}))}unlock(t){const e=this.storage,i=this.last.finally((()=>new Promise(((i,n)=>{e.load(this.key,(s=>{let r;if(void 0!==s){if(s.includes(t))return void i();r=s.slice()}else r=[];r.push(t),e.store(this.key,r,i,n,Mf)}),n,Mf)}))));return this.last=i,i}}class CM{storeBinary(t,e,i,n,s){this.store(t,e,i,n,s)}loadBinary(t,e,i,n){this.load(t,e,i,n)}promiseLoadBinary(t,e=Mf){return new Promise(((i,n)=>{this.loadBinary(t,i,n,e)}))}promiseStoreBinary(t,e,i=Mf){return new Promise(((n,s)=>{this.storeBinary(t,e,n,s,i)}))}store(t,e,i,n,s){throw new Error("Not Implemented")}load(t,e,i,n){throw new Error("Not Implemented")}list(t,e){throw new Error("Not Implemented")}promiseList(){return new Promise(((t,e)=>this.list(t,e)))}remove(t,e,i){throw new Error("Not implemented")}promiseRemove(t){return new Promise(((e,i)=>this.remove(t,e,i)))}contains(t,e,i){this.list((function(i){e(-1!==i.indexOf(t))}),i)}promiseContains(t){return new Promise(((e,i)=>this.contains(t,e,i)))}}const EM="readwrite",zM="main";class IM extends CM{constructor(t){super(),this.db=new Promise((function(e,i){const n=indexedDB.open(t,1);n.addEventListener("success",(function(t){e(n.result)})),n.addEventListener("error",i),n.addEventListener("upgradeneeded",(t=>{t.target.result.createObjectStore(zM)}),!0)}))}remove(t,e,i){const n=this.db.then((n=>{const s=n.transaction(zM,EM).objectStore(zM).delete(t);"function"==typeof e&&s.addEventListener("success",(t=>{e(t.target.result)})),"function"==typeof i&&s.addEventListener("error",(t=>{i(t)}))}));"function"==typeof i&&n.catch(i)}load(t,e,i,n){this.db.then((n=>{const s=n.transaction(zM,"readonly").objectStore(zM).get(t);s.addEventListener("success",(t=>{e(t.target.result)})),s.addEventListener("error",(t=>{i(t)}))})).catch(i)}store(t,e,i,n,s){const r=this.db.then((s=>{const r=s.transaction(zM,EM).objectStore(zM).put(e,t);"function"==typeof i&&r.addEventListener("success",(t=>{i(t.target.result)})),"function"==typeof n&&r.addEventListener("error",(t=>{n(t)}))}));"function"==typeof n&&r.catch(n)}list(t,e){this.db.then((i=>{const n=i.transaction(zM,IDBTransaction.READ_ONLY).objectStore(zM).getAllKeys();n.addEventListener("success",(e=>{t(e.target.result)})),n.addEventListener("error",(t=>{e(t)}))})).catch(e)}}class LM{getStorage(){throw new Error("Not implemented")}getAchievementGateway(){throw new Error("Not implemented")}pickDefaultLocale(t){throw new Error("Not implemented")}startup(){return Promise.resolve()}shutdown(){return Promise.resolve()}}class NM extends LM{constructor({storageKey:t="@woosh/meep/app"}={}){super(),this.storage=new IM(t,this.services),this.storage.compressionEnabled=!1,this.achievements=new AM(this.storage)}getStorage(){return this.storage}getAchievementGateway(){return this.achievements}pickDefaultLocale(t){const e=MM();let i;return i=void 0!==e.lang?e.lang:function(){const e=window.navigator.languages;function i(t){const i=e.length,n=e.indexOf(t);if(-1!==n)return 1.1*(i-n);{const n=t.split("-")[0];for(let t=0;t<i;t++){const s=e[t].split("-")[0];if(n.toLowerCase()===s.toLowerCase())return 1*(i-t)}}return 0}const n=function(t,e){let i,n;const s=t.length;if(0!==s){i=t[0],n=e(i);for(let r=1;r<s;r++){const s=t[r],a=e(s);a>n&&(n=a,i=s)}return i}}(t.map((t=>({key:t,score:i(t)}))),(t=>t.score));return 0===n.score?"en-gb":n.key}(),i}}class PM{constructor(){this.prevPosition={x:0,y:0,z:0},this.nodes={listener:null}}toJSON(){return{}}fromJSON(t){}toBinaryBuffer(t){}fromBinaryBuffer(t){}}PM.typeName="SoundListener";let DM=null;function FM(){if(null!==DM)return DM;const t=globalThis.navigator;if(void 0===t)throw new Error("Not a browser, globalThis.navigator is undefined");let e,i=t.userAgent,n=i.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(n[1]))return e=/\brv[ :]+(\d+)/g.exec(i)||[],{name:"IE",version:e[1]||""};if("Chrome"===n[1]&&(e=i.match(/\bOPR|Edge\/(\d+)/),null!=e))return{name:"Opera",version:e[1]};n=n[2]?[n[1],n[2]]:[t.appName,t.appVersion,"-?"],null!=(e=i.match(/version\/(\d+)/i))&&n.splice(1,1,e[1]);const s={name:n[0],version:n[1]};return DM=s,s}const OM=new L,RM=new L;class kM{constructor(){this.listener=null,this.transform=null,this.audioContext=null}link(){this.transform.position.onChanged.add(this.updatePosition,this),this.transform.rotation.onChanged.add(this.updateRotation,this),this.updatePosition(),this.updateRotation()}unlink(){this.transform.position.onChanged.remove(this.updatePosition,this),this.transform.rotation.onChanged.remove(this.updateRotation,this)}updateRotation(){const t=this.transform.rotation;OM.copy(L.forward),OM.applyQuaternion(t),RM.copy(L.up),RM.applyQuaternion(t);const e=this.audioContext.listener;WM(e,OM,RM)}updatePosition(){const t=this.audioContext.listener;VM(t,this.transform.position)}}class BM extends Cm{constructor(t){super(),this.dependencies=[PM,B],this.components_used=[Tm.from(PM,3)],this.webAudioContext=t,this.data=[]}link(t,e,i){const n=new kM;n.transform=e,n.listener=t,n.audioContext=this.webAudioContext,n.link(),this.data[i]=n}unlink(t,e,i){const n=this.data[i];void 0!==n&&(delete this.data[i],n.unlink())}}function UM(t,e){let i,n,s;i=Number.isFinite(e.x)?e.x:0,n=Number.isFinite(e.y)?e.y:0,s=Number.isFinite(e.z)?e.z:0,t.setPosition(i,n,s)}let VM=function(t,e){};if(void 0!==globalThis.navigator){const t=FM();"Chrome"===t.name?VM=t.version>=64?function(t,e){Number.isFinite(e.x)&&t.positionX.setValueAtTime(e.x,0),Number.isFinite(e.y)&&t.positionY.setValueAtTime(e.y,0),Number.isFinite(e.z)&&t.positionZ.setValueAtTime(e.z,0)}:UM:"Firefox"===t.name&&(VM=UM)}let WM=Mf;if(void 0!==globalThis.navigator){const t=FM();"Chrome"===t.name?WM=function(t,e,i){t.forwardX.value=e.x,t.forwardY.value=e.y,t.forwardZ.value=e.z,t.upX.value=i.x,t.upY.value=i.y,t.upZ.value=i.z}:"Firefox"===t.name&&(WM=function(t,e,i){t.setOrientation(e.x,e.y,e.z,i.x,i.y,i.z)})}const GM=Object.freeze(new kd(1,.93,.87));class HM{constructor(){this.engine=new ub(new NM),window.engine=this.engine,ax.addBackend(SM.INSTANCE),this.p=null}static async bootstrap({configuration:t}={}){return(new HM).initialize({configuration:t})}static addFpsCounter(t){const e=new Ug;t.graphics.on.postRender.add(e.update,e);const i=new jg({el:e.domElement});t.viewStack.addChild(i)}initialize({configuration:t=Mf,enable_localization:e=!1}={}){if(null!==this.p)return this.p;const i=this.engine,n=new Promise((async function(n,s){const r=new db;if(t(r,i),r.hasLoader("json")||r.addLoader("json",new qg),await r.apply(i),await i.start(),e)try{await function(t){const e=MM();let i;return i=void 0!==e.lang?e.lang:"en-gb",t.localization.loadLocale(i)}(i)}catch(t){}i.sceneManager.create("test"),i.sceneManager.set("test"),document.body.appendChild(i.viewStack.el),i.viewStack.link(),document.body.style.margin="0",document.body.style.overflow="hidden",window.addEventListener(jv,(function t(){window.removeEventListener(jv,t),i.sound.resumeContext()})),n(i)}));return this.p=n,n}static buildCamera({engine:t,ecd:e=t.entityManager.dataset,target:i=new L,distance:n=10,pitch:s=1.4,yaw:r=0,autoClip:a=!1,distanceMin:o=.01,distanceMax:l=1e3,fieldOfView:h=45}){const c=t.entityManager;null===c.getSystem(Eb)&&c.addSystem(new Eb),null===c.getSystem(Jm)&&c.addSystem(new Jm(t.graphics)),null===c.getSystem(BM)&&c.addSystem(new BM(t.sound.context)),e.isComponentTypeRegistered(Yg)||e.registerComponentType(Yg);const u=new B,d=new Ab;d.pitch=s,d.yaw=r,d.distance=n,d.distanceMin=o,d.distanceMax=l,d.target.copy(i);const p=new Vm;p.active.set(!0),p.autoClip=a,p.clip_far=l,p.fov.set(h);const f=new d_;return f.add(u).add(d).add(p).add(new PM).add(Yg.fromJSON(["Camera"])).build(e),f}static async buildBasics({engine:t,focus:e=new L(10,0,10),heightMap:i,heightRange:n,pitch:s=.7,yaw:r=-1.2,distance:a=10,terrainSize:o=new Eu(10,10),terrainResolution:l=10,enableWater:h=!0,enableTerrain:c=!0,enableLights:u=!0,cameraFieldOfView:d,cameraFarDistance:p,cameraController:f=!0,cameraAutoClip:m=!1,shadowmapResolution:_,showFps:g=!0}){g&&HM.addFpsCounter(t),u&&await HM.buildLights({engine:t,shadowmapResolution:_});const y=HM.buildCamera({engine:t,target:e,pitch:s,yaw:r,distance:a,fieldOfView:d,distanceMax:p,autoClip:m}).id;if(c&&await HM.buildTerrain({engine:t,heightMap:i,heightRange:n,resolution:l,size:o,enableWater:h}),f){HM.buildOrbitalCameraController({engine:t,cameraEntity:y});const e=t.entityManager.dataset;new pM({component:e.getComponent(y,Ab),entity:y},e).build(e)}}static async buildLights({engine:t,ecd:e=t.entityManager.dataset,shadowmapResolution:i=1024,castShadow:n=!0,sun:s=GM,sunIntensity:r=.9,sunDirection:a=new L(.1,-1,.1),ambient:o=kd.white,ambientIntensity:l=.1}){const h=t.entityManager;h.hasSystem(aM)||await h.addSystem(new aM(t,{shadowResolution:i})),e.isComponentTypeRegistered(Yg)||e.registerComponentType(Yg);const c=new Ib;c.type.set(Ib.Type.DIRECTION),c.color.copy(s),c.intensity.set(r),c.castShadow.set(n);const u=new B;u.position.set(30,70,30),u.rotation.lookRotation(a),(new d_).add(c).add(u).add(Yg.fromJSON(["Light","Key"])).build(e);const d=new Ib;d.type.set(Ib.Type.AMBIENT),d.color.copy(o),d.intensity.set(l),(new d_).add(d).add(new B).add(Yg.fromJSON(["Light","Ambient"])).build(e)}static async buildOrbitalCameraController({cameraEntity:t,engine:e,ecd:i=e.entityManager.dataset,sensitivity:n=.01}){void 0===t&&(t=i.getAnyComponent(Vm).entity);const s=e.entityManager;null===s.getSystem(xM)&&await s.addSystem(new xM(e.devices)),i.isComponentTypeRegistered(Jg)||i.registerComponentType(Jg);const r=e.graphics.domElement;r.addEventListener("contextmenu",(t=>{t.preventDefault()}));const a=function({camera_entity:t,ecd:e,dom_element:i,sensitivity:n=.01}){function s(){return e.getComponent(t,Ab)}const r=new fb([{path:"pointer/on/tap",listener(t,e){}},{path:"pointer/on/down",listener(t,e){}},{path:"pointer/on/drag",listener:function(r,a,o,l){const h=o.clone().sub(r);!function(t,e=[]){for(let i=0;i<32;i++){const n=t>>i;e[i]=0!=(1&n)}return e}(l.buttons)[0]?function(t){const e=s();Mb(t.x*n,t.y*n,e,e)}(h):function(n){const r=n.clone(),a=s(),o=e.getComponent(t,Vm);Ab.pan(r,o.object,i,a.distance,o.object.fov,a.target)}(h),l.preventDefault()}},{path:"pointer/on/wheel",listener(t,e){!function(t){const e=s(),i=e.distance+t;e.distance=g(i,e.distanceMin,e.distanceMax)}(t.y)}}]),a=new d_;return a.add(r),a}({camera_entity:t,ecd:i,dom_element:r,sensitivity:n});return a.add(Yg.fromJSON(["CameraController"])),a.add(Jg.Transient),a.build(i),a}static async buildTerrain({engine:t,size:e=new Eu(10,10),diffuse0:i="data/textures/utility/checkers_dark_grey_256x256.png",heightRange:n=0,resolution:s=10,waterLevel:r=0,enableWater:a=!0}){const o=t.entityManager;null===o.getSystem(Ym)&&await o.addSystem(new Ym(t.graphics,t.assetManager));const l=new If;l.size.copy(e),l.resolution=s,l.gridScale=2,l.layers.addLayer(lf.from(i,5,5)),l.splat.resize(1,1,1),l.splat.fillLayerWeights(0,255);const h=new d_;if(h.add(new B),h.add(l),a){null===o.getSystem(cM)&&o.addSystem(new cM(t.graphics));const e=new hM;e.level.set(r),h.add(e)}return h.build(t.entityManager.dataset),l}}let jM=null;HM.getSingleton=function(){return null===jM&&(jM=new HM),jM};class qM extends Ow{constructor(){super(),this.__currentBehaviour=null,this.__currentBehaviourIndex=-1}static from(t){const e=new qM;return t.forEach(e.addChild,e),e}tick(t){if(this.__children.length<1)return Lw.Failed;for(;;){const e=this.__currentBehaviour.tick(t);if(e!==Lw.Failed)return e;this.__currentBehaviour.finalize();const i=this.__children;if(this.__currentBehaviourIndex++,this.__currentBehaviourIndex>=i.length)return this.__currentBehaviour=null,Lw.Failed;this.__currentBehaviour=i[this.__currentBehaviourIndex],this.__currentBehaviour.initialize(this.context)}}finalize(){null!==this.__currentBehaviour&&(this.__currentBehaviour.finalize(),this.__currentBehaviour=null),super.finalize()}initialize(t){const e=this.__children;e.length>0?(this.__currentBehaviourIndex=0,this.__currentBehaviour=e[0],this.__currentBehaviour.initialize(t)):(this.__currentBehaviourIndex=-1,this.__currentBehaviour=null),super.initialize(t)}}const JM={RequireOne:0,RequireAll:1};class $M extends Ow{constructor(t,e){super(),this.successPolicy=t,this.failurePolicy=e,this.activeSet=new e_,this.successCount=0,this.failureCount=0}getSuccessPolicy(){return this.successPolicy}setSuccessPolicy(t){this.successPolicy=t}getFailurePolicy(){return this.failurePolicy}setFailurePolicy(t){this.failurePolicy=t}tick(t){const e=this.activeSet,i=this.__children,n=i.length;let s;for(s=0;s<n;s++){if(!e.get(s))continue;const n=i[s],r=n.tick(t);if(r===Lw.Succeeded){if(e.set(s,!1),this.successCount++,n.finalize(),this.successPolicy===JM.RequireOne)return this.__finalizeActiveChildren(),Lw.Succeeded}else if(r===Lw.Failed){if(e.set(s,!1),this.failureCount++,n.finalize(),this.failurePolicy===JM.RequireOne)return this.__finalizeActiveChildren(),Lw.Failed;if(this.successPolicy===JM.RequireAll)return this.__finalizeActiveChildren(),Lw.Failed}}return this.successCount===n&&this.successPolicy===JM.RequireAll?Lw.Succeeded:this.failureCount===n&&this.failurePolicy===JM.RequireAll||this.failureCount+this.successCount===n?Lw.Failed:Lw.Running}initialize(t){this.successCount=0,this.failureCount=0;const e=this.__children,i=e.length;for(let n=0;n<i;n++)e[n].initialize(t),this.activeSet.set(n,!0);super.initialize(t)}__finalizeActiveChildren(){const t=this.__children,e=this.activeSet;for(let i=e.nextSetBit(0);-1!==i;i=e.nextSetBit(i+1))t[i].finalize()}finalize(){this.__finalizeActiveChildren(),super.finalize()}static from(t,e=JM.RequireAll,i=JM.RequireOne){const n=new $M(e,i);return n.addChildren(t),n}}$M.prototype.isParallelBehavior=!0,$M.typeName="ParallelBehavior";class YM{constructor(t){this.referenceCount=0,this.type=t,this.value=function(t){let e;switch(t){case ey.Number:e=new id(0);break;case ey.Boolean:e=new Dm(!1);break;case ey.String:e=new ad("");break;default:throw new TypeError(`Unsupported data type '${t}'`)}return e}(t)}}class XM{contains(t,e){throw new Error("Not implemented")}getKeys(){throw new Error("Not implemented")}acquire(t,e,i){throw new Error("Not implemented")}release(t){throw new Error("Not implemented")}acquireBoolean(t,e=!1){return this.acquire(t,ey.Boolean,e)}acquireNumber(t,e=0){return this.acquire(t,ey.Number,e)}incrementNumber(t,e=1){this.acquireNumber(t)._add(e),this.release(t)}acquireString(t,e=""){return this.acquire(t,ey.String,e)}}class ZM extends XM{constructor(){super(),this.on={added:new _},this.data={},this.proxy=new Proxy(this,{get(t,e,i){if(t.contains(e,ey.Any))return t.acquire(e,ey.Any).getValue()},set(t,e,i,n){const s=function(t){switch(typeof t){case"number":return ey.Number;case"string":return ey.String;case"boolean":return ey.Boolean;default:if(Array.isArray(t))return ey.Array;throw new Error(`Unsupported value type for value '${t}'`)}}(i);return t.acquire(e,s,i).set(i),!0},ownKeys:t=>t.getKeys()})}getKeys(){return Reflect.ownKeys(this.data)}getValueProxy(){return this.proxy}contains(t,e){const i=this.data[t];return void 0!==i&&(e===ey.Any||i.type===e)}traverse(t,e){for(let i in this.data){if(!this.data.hasOwnProperty(i))continue;const n=this.data[i];t.call(e,i,n.value,n.type)}}traverseWithPattern(t,e){this.traverse((function(i,n,s){t.test(i)&&e(i,n,s)}))}acquire(t,e,i){let n;if(this.data.hasOwnProperty(t)){if(n=this.data[t],e!==ey.Any&&n.type!==e)throw new TypeError(`Value '${t}' exists, but is type(='${n.type}'), expected type '${e}'`)}else{n=new YM(e);const s=n.value;void 0!==i&&s.set(i),this.data[t]=n,this.on.added.send4(t,s.getValue(),e,this)}return n.referenceCount++,n.value}release(t){this.data[t].referenceCount--}reset(){this.data={}}copy(t){const e=this.data;t.traverse(((t,i,n)=>{const s=e[t],r=i.getValue();void 0===s?this.acquire(t,n,r):s.type!==n?(delete e[t],this.acquire(t,n,r)):s.value.set(r)}));const i=[];for(const n in e){const s=e[n];t.contains(n,s.type)||i.push(n)}for(let t=0;t<i.length;t++){const n=i[t];delete e[n]}}clone(){const t=new ZM;return t.copy(this),t}toJSON(){const t={};return this.traverse(((e,i,n)=>{t[e]=i.toJSON()})),t}fromJSON(t){this.reset();for(let e in t){const i=t[e],n=typeof i;"number"===n?this.acquireNumber(e,i).set(i):"boolean"===n?this.acquireBoolean(e,i).set(i):"string"===n&&this.acquireString(e,i).set(i)}}static fromJSON(t){const e=new ZM;return e.fromJSON(t),e}}function KM(t){return t-1>>1}ZM.typeName="Blackboard";const QM=new Uint32Array(4);function tT(t,e,i){const n=e%i,s=e/i|0;t.set(n,s)}function eT(t,e,i,n){const s=e%i,r=e/i|0;let a=0;return r>0&&(t[a]=e-i,a++),s>0&&(t[a]=e-1,a++),s<i-1&&(t[a]=e+1,a++),r<n-1&&(t[a]=e+i,a++),a}function iT(t,e,i,n){let s=new Eu(-1,-1),r=new Eu,a=1,o=1,l=0,h=0;const c=[];let u=t,d=u,p=e[u];for(;-1!==u;){tT(r,u,i),l=r.x-s.x,h=r.y-s.y,0!==l&&(l=E(l)),0!==h&&(h=E(h)),(a!==l||o!==h)&&(a=l,o=h,c.push(d)),d=u;const t=s;s=r,r=t;const f=eT(QM,u,i,n);u=-1;for(let t=0;t<f;t++){const n=QM[t],c=e[n];c<p?(u=n,p=c):c===p&&(tT(r,n,i),l=r.x-s.x,h=r.y-s.y,l===a&&h===o&&(u=n,p=c))}}return c[c.length-1]!==d&&c.push(d),c.reverse(),c}function nT(t,e,i){const n=e%i-t%i,s=(e/i|0)-(t/i|0);return n*n+s*s}const sT=new class{constructor(t=64){this.__data_buffer=new ArrayBuffer(8*t),this.__data_uint32=new Uint32Array(this.__data_buffer),this.__data_float32=new Float32Array(this.__data_buffer),this.__capacity=t,this.__size=0}__capacity_grow(){const t=this.__capacity,e=Math.ceil(bu(1.2*t,t+16)),i=new ArrayBuffer(8*e),n=new Uint32Array(i);n.set(this.__data_uint32),this.__data_buffer=i,this.__data_uint32=n,this.__data_float32=new Float32Array(i),this.__capacity=e}compare(t,e){const i=this.__data_float32,n=e<<1;return i[t<<1]<i[n]}swap(t,e){const i=t<<1,n=e<<1,s=this.__data_uint32,r=s[i];s[i]=s[n],s[n]=r;const a=i+1,o=n+1,l=s[a];s[a]=s[o],s[o]=l}heap_down(t){let e=t;const i=this.__size;for(;;){const t=1+(e<<1),n=t+1;let s=e;if(t<i&&this.compare(t,s)&&(s=t),n<i&&this.compare(n,s)&&(s=n),s===e)break;this.swap(e,s),e=s}}heap_up(t){let e=t;for(;e>0;){const t=e-1>>1;if(this.compare(t,e))break;this.swap(t,e),e=t}}get size(){return this.__size}get capacity(){return this.__capacity}get top_id(){return this.__data_uint32[1]}is_empty(){return 0===this.__size}peek_min(){return this.top_id}pop_min(){const t=this.__size-1;this.__size=t;const e=this.__data_uint32,i=e[1],n=t<<1;return e[0]=e[n],e[1]=e[n+1],this.heap_down(0),i}find_index_by_id(t){const e=this.__size<<1,i=this.__data_uint32;for(let n=1;n<e;n+=2)if(i[n]===t)return n>>>1;return-1}contains(t){return-1!==this.find_index_by_id(t)}clear(){this.__size=0}remove(t){const e=this.find_index_by_id(t);return-1!==e&&(this.__remove_by_index(e),!0)}__remove_by_index(t){let e=t;for(;e>0;){const t=KM(e);this.swap(t,e),e=t}this.pop_min()}update_score(t,e){const i=this.find_index_by_id(t);if(-1===i)throw new Error("Not found");this.__update_score_by_index(i,e)}__update_score_by_index(t,e){const i=this.__data_float32,n=t<<1,s=i[n];e<s?(i[n]=e,this.heap_up(t)):e>s&&(i[n]=e,this.heap_down(t))}get_score(t){const e=this.find_index_by_id(t);if(-1===e)return Number.NaN;const i=e<<1;return this.__data_float32[i]}insert_or_update(t,e){const i=this.find_index_by_id(t);-1===i?this.insert(t,e):this.__update_score_by_index(i,e)}insert(t,e){const i=this.__size;i>=this.__capacity&&this.__capacity_grow();const n=i,s=n<<1;this.__data_float32[s]=e,this.__data_uint32[s+1]=t,this.__size=i+1,this.heap_up(n)}},rT=new e_;rT.preventShrink();let aT=new Float32Array(1024);t.AmbientOcclusionPostProcessEffect=class extends Mg{constructor(){super(),this.id="ambient-occlusion-post-process";const t=Object.assign({},Tg.defines);this.__material=new nr({defines:t,fragmentShader:Tg.fragmentShader,vertexShader:Tg.vertexShader,uniforms:ir.clone(Tg.uniforms),glslVersion:Ai,depthWrite:!1,depthTest:!1});const e=this.__material.uniforms;e.bias.value=.5,e.intensity.value=2,e.kernelRadius.value=30,e.minResolution.value=0,this.__material.blending=et,this.__material.extensions.derivatives=!0,t.DEPTH_PACKING=0,t.NORMAL_TEXTURE=0,t.PERSPECTIVE_CAMERA=1,t.NUM_SAMPLES=13,t.NUM_RINGS=5,this.__use_normals=!1,this.__resolution_scale=.5,this.__composit_layer=null,this.__render_camera=null,this.__render_target=new Ji(1,1,{minFilter:Kt,magFilter:Kt,format:xe,type:ee,internalFormat:"R8",depthBuffer:!1,stencilBuffer:!1,generateMipmaps:!1}),this.__used_buffers=[],this.__blur=new Rg({format:xe,clear_color:16777215})}set intensity(t){this.__material.uniforms.intensity.value=t}get intensity(){return this.__material.uniforms.intensity.value}__setCamera(t){this.__render_camera=t;const e=this.__material,i=e.defines;!0===t.isPerspectiveCamera&&1!==i.PERSPECTIVE_CAMERA?(i.PERSPECTIVE_CAMERA=1,e.needsUpdate=!0):!0!==t.isPerspectiveCamera&&0!==i.PERSPECTIVE_CAMERA&&(i.PERSPECTIVE_CAMERA=0,e.needsUpdate=!0),this.__blur.setRenderCamera(t)}initialize(t){this.__blur.configureMaterials(),super.initialize(t)}finalize(){super.finalize()}__prepare_uniforms(){const t=this.__material,e=t.uniforms,i=this.__render_camera;e.size.value.set(this.__render_target.width,this.__render_target.height);const n=i.near,s=i.far;e.cameraNear.value=n,e.cameraFar.value=s,e.cameraInverseProjectionMatrix.value.copy(i.projectionMatrixInverse),e.cameraProjectionMatrix.value.copy(i.projectionMatrix),t.uniformsNeedUpdate=!0}__prepare_draw(){const t=this.engine.graphics.camera;this.__setCamera(t),this.__prepare_uniforms()}__render(){const t=this.engine.graphics.renderer;this.__prepare_draw();const e=t.getRenderTarget();t.setRenderTarget(this.__render_target),t.clearColor(),Fg(t,this.__material),t.setRenderTarget(e),this.__blur.execute(t)}setNormalBufferUsage(t){if(t===this.__use_normals)return;this.__use_normals=t;const e=this.__material,i=e.uniforms,n=e.defines,s=this.engine.graphics.frameBuffers.getById(Bg);t?(i.tNormal.value=s.getRenderTarget().texture,this.__add_used_frame_buffer(s),n.NORMAL_TEXTURE=1):(i.tNormal.value=null,this.__remove_used_frame_buffer(s),n.NORMAL_TEXTURE=0),e.needsUpdate=!0}__add_used_frame_buffer(t){this.__used_buffers.includes(t)||(t.referenceCount++,this.__used_buffers.push(t))}__remove_used_frame_buffer(t){const e=this.__used_buffers.indexOf(t);-1!==e&&(t.referenceCount--,this.__used_buffers.splice(e,1))}__update_render_target_size(){const t=this.engine.graphics.viewport.size,e=Math.ceil(t.x*this.__resolution_scale),i=Math.ceil(t.y*this.__resolution_scale);this.__render_target.setSize(e,i)}async startup(){const t=this.engine.graphics;this.__composit_layer=t.layerComposer.createLayer({format:xe,type:ee,internalFormat:"R8"},3),this.__composit_layer.name="Ambient Occlusion",this.__composit_layer.stage=1;const e=this.__material.uniforms,i=t.frameBuffers.getById(kg).getRenderTarget().depthTexture;return e.tDepth.value=i,this.__use_normals&&(this.__use_normals=!1,this.setNormalBufferUsage(!0)),this.__composit_layer.on.preRender.add(this.__render,this),t.viewport.size.onChanged.add(this.__update_render_target_size,this),this.__update_render_target_size(),this.__blur.setDepthBuffer(i),this.__blur.setInput(this.__render_target),this.__blur.setOutput(this.__composit_layer.renderTarget),super.startup()}async shutdown(){const t=this.engine.graphics;return t.layerComposer.remove(this.__composit_layer),this.__composit_layer.on.preRender.remove(this.__render,this),t.viewport.size.onChanged.add(this.__update_render_target_size,this),this.__blur.dispose(),this.__render_target.dispose(),super.shutdown()}},t.Behavior=Nw,t.BehaviorStatus=Lw,t.Blackboard=ZM,t.Cache=Zp,t.EngineConfiguration=db,t.EngineHarness=HM,t.ForwardPlusRenderingPlugin=GS,t.HashMap=qp,t.Light=Ib,t.ParallelBehavior=$M,t.ParallelBehaviorPolicy=JM,t.SGMesh=Xf,t.SGMeshSystem=class extends Cm{constructor(t){super(),this.__engine=t,this.__assetManager=t.assetManager,this.dependencies=[Xf,B],this.components_used=[Tm.from(Xf,3),Tm.from(B,1),Tm.from(qf,4),Tm.from(p_,4)],this.__wait_queue=[],this.__wait_queue_process_index=0}async startup(t,e,i){t.hasSystem(g_)||await t.addSystem(new g_),super.startup(t,e,i)}async process(t,e,i){const n=this.__assetManager,s=this.entityManager.dataset,r=function(t){const e=t.lastIndexOf(".");if(-1===e)return null;switch(t.substring(e+1)){case"json":return"three.js";case"glb":return"model/gltf";case"gltf":return"model/gltf+json";default:return null}}(e.url);let a,o;try{a=await n.promise(e.url,r)}catch(e){return void s.sendEvent(t,"@ecd-component-SGMesh/asset-failed")}if(!s.entityExists(t))return;if(s.getComponent(t,Xf)!==e)return;void 0!==a.boundingBox&&(e.__initial_bounds.copy(a.boundingBox),a.has_root_transform&&e.__initial_bounds.applyMatrix4(a.root_transform.matrix));const l=Xm.get(a);null!==l?o=l:(o=a.create(),Xm.set(a,o));let h=v_(o);if(a.has_root_transform){const t=new m_;t.entity.add(new B),h.transform.copy(a.root_transform),t.addChild(h),h=t}function c(){h.transform.copy(i)}h.entity.add(f_.from(t)),e.__node=h,c(),h.build(s),i.subscribe(c),h.on.destroyed.addOne((()=>{i.unsubscribe(c)}));const u=e.materialOverride;h.traverse((t=>{const i=t.entity.getComponent(qf);null!==i&&(i.writeFlag(2,e.castShadow),i.writeFlag(4,e.receiveShadow),null!==u&&(i.material=u))})),s.sendEvent(t,"@ecd-component-SGMesh/asset-attached")}link(t,e,i){const n=e.position;t.__initial_bounds.setBounds(n.x,n.y,n.z,n.x,n.y,n.z),null!==t.url?this.process(i,t,e):this.__wait_queue.push(i)}unlink(t,e,i){null!==t.__node&&(t.__node.destroy(),t.__node=null);const n=this.__wait_queue.indexOf(i);-1!==n&&this.__wait_queue.splice(n,1)}update(t){const e=this.entityManager.dataset;if(null===e)return;const i=this.__wait_queue;let n=i.length;if(n>0){const t=performance.now();let s=this.__wait_queue_process_index;const r=s+Su(n,128);for(;s<r;){const r=s%n;s++;const a=i[r],o=e.getComponent(a,Xf);if(null===o.url)continue;i.splice(r,1);const l=e.getComponent(a,B);if(this.process(a,o,l),performance.now()-t>40)break}this.__wait_queue_process_index=s}}},t.SelectorBehavior=qM,t.SequenceBehavior=Rw,t.ShadedGeometry=qf,t.ShadedGeometrySystem=class extends Cm{constructor(t){super(),this.dependencies=[qf,B],this.__engine=t,this.__render_layer=null,this.__view_contexts=new Map,this.__adapter_suppliers=new Map,this.__geometry_usage_counters=new Map,this.__bvh_binary=new Md;const e=new E_;this.__optimization_task=new Cf({name:"ShadedGeometry Draw Method optimizer",initializer:()=>{e.__system=this},cycleFunction:()=>e.step()?2:3}),this.__maintenance_task=function(t,e,i=2){return new Cf({name:t,cycleFunction:()=>e.next().done?0:i})}("Maintenance",function*(t){for(;;){const e=t.__view_contexts;for(const[t,i]of e)void 0!==i&&(yield*i.maintain());yield}}(this),3)}get bvh(){return this.__bvh_binary}getGeometryUsageCounters(){return this.__geometry_usage_counters}register_render_adapter(t,e){this.__adapter_suppliers.has(t)&&this.unregister_render_adapter(t),this.__adapter_suppliers.set(t,e),this.__view_contexts.forEach(((i,n)=>{i.setAdapter(t,e())}))}unregister_render_adapter(t){return void 0!==this.__adapter_suppliers.get(t)&&(this.__adapter_suppliers.delete(t),this.__view_contexts.forEach(((e,i)=>{e.removeAdapter(t)})),!0)}__handle_view_added(t){const e=new vg;this.__adapter_suppliers.forEach(((t,i)=>{e.setAdapter(i,t())})),this.__view_contexts.set(t,e)}__handle_view_removed(t){const e=this.__view_contexts.get(t);this.__view_contexts.delete(t),e.dispose()}async startup(t,e,i){this.entityManager=t;const n=this.__engine,s=n.graphics,r=s.views.elements;r.forEach(this.__handle_view_added,this),r.on.added.add(this.__handle_view_added,this),r.on.removed.add(this.__handle_view_removed,this),this.__render_layer=s.layers.create("shaded-geometry"),this.__render_layer.buildVisibleSet=(e,i,n)=>{const r=this.__view_contexts.get(n),a=t.dataset;return null===a?0:r.collect(e,i,s.renderer,n,this.__bvh_binary,a)},this.__optimization_task.state.set(Tf.INITIAL),n.executor.run(this.__optimization_task),this.__maintenance_task.state.set(Tf.INITIAL),n.executor.run(this.__maintenance_task),e()}async shutdown(t,e,i){const n=this.__engine,s=n.graphics.views.elements;n.executor.removeTask(this.__optimization_task),n.executor.removeTask(this.__maintenance_task),s.forEach(this.__handle_view_removed,this),s.on.added.remove(this.__handle_view_added,this),s.on.removed.remove(this.__handle_view_removed,this),e()}link(t,e,i){t.__c_transform=e,t.update_bounds(),e.subscribe(t.updateTransform,t),t.__entity=i,t.__bvh_leaf.link(this.__bvh_binary,i);const n=t.geometry.id,s=this.__geometry_usage_counters.get(n),r=void 0!==s?s+1:1;this.__geometry_usage_counters.set(n,r)}unlink(t,e,i){e.unsubscribe(t.updateTransform,t),t.__bvh_leaf.unlink();const n=t.geometry.id,s=this.__geometry_usage_counters.get(n);1===s?(this.__geometry_usage_counters.delete(n),t.geometry.dispose()):this.__geometry_usage_counters.set(n,s-1)}queryOverlapFrustum(t,e,i){return im(t,e,this.__bvh_binary,i)}raycast(t,e,i,n,s,r,a=T_,o){const l=[],h=[],c=this.__bvh_binary,u=w_(h,0,c,c.root,M_.from([t,e,i,n,s,r])),d=this.entityManager.dataset;if(null===d)return l;const p=d.computeComponentTypeIndex(qf);for(let f=0;f<u;f++){const u=h[f],m=c.node_get_user_data(u),_=d.getComponentByIndex(m,p);if(!a.call(o,m,_))continue;const g=_.transform;hp(wg,t,e,i,n,s,r),_.query_raycast_nearest(xg,wg,g)&&l.push({entity:m,mesh:_,contact:xg.clone()})}return l}raycastNearest(t,e,i,n,s,r,a,o=T_,l){let h=Infinity,c=!1,u=null;const d=[],p=this.__bvh_binary,f=w_(d,0,p,p.root,M_.from([e,i,n,s,r,a])),m=this.entityManager.dataset;if(null===m)return;const _=m.computeComponentTypeIndex(qf);for(let g=0;g<f;g++){const f=d[g],y=p.node_get_user_data(f),v=m.getComponentByIndex(y,_);if(!o.call(l,y,v))continue;const x=v.transform;if(hp(wg,e,i,n,s,r,a),!v.query_raycast_nearest(xg,wg,x))continue;c=!0;const w=xg.position,b=A_(w.x,w.y,w.z,e,i,n);b<h&&(t.copy(xg),u=v,h=b)}return c?{entity:u.__entity,mesh:u}:void 0}},t.Signal=_,t.SignalBinding=Mm,t.Transform=B,t.find_path_on_grid_astar=function(t,e,i,n,s,r){sT.clear(),rT.reset();const a=e*i;for(aT.length<a&&(aT=new Float32Array(a)),aT.fill(Infinity,0,a),aT[n]=0,sT.insert(n,nT(n,s,e));!sT.is_empty();){const n=sT.pop_min();if(n===s)return iT(n,aT,e,i);rT.set(n,!0);const a=eT(QM,n,e,i);for(let i=0;i<a;++i){const a=QM[i];if(rT.get(a))continue;const o=t[a];if(o===r){rT.set(a,!0);continue}const l=o+1,h=aT[n]+l;if(h<aT[a]){aT[a]=h;const t=h+nT(a,s,e);sT.insert_or_update(a,t)}}}return[]},t.quat3_createFromAxisAngle=function(t,e,i){const n=.5*e,s=Math.sin(n);i.set(t.x*s,t.y*s,t.z*s,Math.cos(n))},t.three_update_shadow_camera_extents=lM,t.v2_angle_between=function(t,e,i,n){const s=g(Cu(t,e,i,n)/(Tu(t,e)*Tu(i,n)),-1,1);return Math.acos(s)},t.v2_bearing_angle_towards=function(t,e,i,n){let s=Math.atan2(i-t,e-n);return s<0&&(s+=6.283185307179586),s},t.v2_distance=Au,t.v2_dot=Cu,t.v2_length_sqr=Mu,t.v2_magnitude=Tu,t.v4_distance_sqr=function(t,e,i,n,s,r,a,o){return T(t-s,e-r,i-a,n-o)},t.v4_dot=function(t,e,i,n,s,r,a,o){return t*s+e*r+i*a+n*o},t.v4_length_sqr=T,t.v4_multiply_mat4=function(t,e,i){const n=i[0],s=i[1],r=i[2],a=i[3],o=i[4],l=i[5],h=i[6],c=i[7],u=i[8],d=i[9],p=i[10],f=i[11],m=i[12],_=i[13],g=i[14],y=i[15],v=e[0],x=e[1],w=e[2],b=e[3],S=n*v+o*x+u*w+m*b,M=s*v+l*x+d*w+_*b,T=r*v+h*x+p*w+g*b,A=a*v+c*x+f*w+y*b;t[0]=S,t[1]=M,t[2]=T,t[3]=A}}));