@needle-tools/engine 5.0.0 → 5.1.0-experimental.0

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 (183) hide show
  1. package/components.needle.json +1 -1
  2. package/dist/generateMeshBVH.worker-DT9A2Hrc.js +1 -0
  3. package/dist/gltf-progressive-3BwW4ETO.min.js +10 -0
  4. package/dist/gltf-progressive-ByD1UX0A.umd.cjs +10 -0
  5. package/dist/{gltf-progressive-Cl167Vjx.js → gltf-progressive-DwWaVr0o.js} +412 -394
  6. package/dist/gltf-progressive.worker-DpfUjn1n.js +3 -0
  7. package/dist/{materialx-qPScBWhj.min.js → materialx-9KHBidZa.min.js} +1 -1
  8. package/dist/{materialx-4ApD6Vz5.js → materialx-BBDu8W5P.js} +1 -1
  9. package/dist/{materialx-D0XUnhBY.umd.cjs → materialx-hLP3E8AA.umd.cjs} +2 -2
  10. package/dist/{needle-engine.bundle-BAYLGumK.umd.cjs → needle-engine.bundle-BOAJ6UPK.umd.cjs} +123 -123
  11. package/dist/{needle-engine.bundle-CoEvMwYM.min.js → needle-engine.bundle-CVsBkUR2.min.js} +110 -110
  12. package/dist/{needle-engine.bundle-BDIyvCV6.js → needle-engine.bundle-TgPY0fGG.js} +2143 -2088
  13. package/dist/needle-engine.d.ts +80 -22
  14. package/dist/needle-engine.js +480 -476
  15. package/dist/needle-engine.min.js +1 -1
  16. package/dist/needle-engine.umd.cjs +1 -1
  17. package/dist/{postprocessing-B_9sKVU7.min.js → postprocessing-BZfyAdCY.min.js} +1 -1
  18. package/dist/{postprocessing-WDc9WwI3.js → postprocessing-CXlA3QA6.js} +1 -1
  19. package/dist/{postprocessing-B2wb6pzI.umd.cjs → postprocessing-Dwy7Hz_T.umd.cjs} +38 -38
  20. package/dist/three-examples.js +4760 -3641
  21. package/dist/three-examples.min.js +17 -35
  22. package/dist/three-examples.umd.cjs +16 -34
  23. package/dist/three.js +48533 -28562
  24. package/dist/three.min.js +716 -502
  25. package/dist/three.umd.cjs +720 -506
  26. package/dist/{vendor-CntUvmJu.umd.cjs → vendor-BI4TX0aC.umd.cjs} +9 -9
  27. package/dist/{vendor-DPbfJJ4d.min.js → vendor-BgzAK9of.min.js} +1 -1
  28. package/dist/{vendor-vHLk8sXu.js → vendor-CwL-uvVy.js} +1 -1
  29. package/lib/engine/engine_animation.js +1 -1
  30. package/lib/engine/engine_animation.js.map +1 -1
  31. package/lib/engine/engine_audio.js.map +1 -1
  32. package/lib/engine/engine_context.js +3 -6
  33. package/lib/engine/engine_context.js.map +1 -1
  34. package/lib/engine/engine_create_objects.js +0 -1
  35. package/lib/engine/engine_create_objects.js.map +1 -1
  36. package/lib/engine/engine_element.d.ts +113 -0
  37. package/lib/engine/engine_element.js +833 -0
  38. package/lib/engine/engine_element.js.map +1 -0
  39. package/lib/engine/engine_element_attributes.d.ts +72 -0
  40. package/lib/engine/engine_element_attributes.js +2 -0
  41. package/lib/engine/engine_element_attributes.js.map +1 -0
  42. package/lib/engine/engine_element_extras.d.ts +6 -0
  43. package/lib/engine/engine_element_extras.js +14 -0
  44. package/lib/engine/engine_element_extras.js.map +1 -0
  45. package/lib/engine/engine_element_loading.d.ts +44 -0
  46. package/lib/engine/engine_element_loading.js +350 -0
  47. package/lib/engine/engine_element_loading.js.map +1 -0
  48. package/lib/engine/engine_element_overlay.d.ts +21 -0
  49. package/lib/engine/engine_element_overlay.js +167 -0
  50. package/lib/engine/engine_element_overlay.js.map +1 -0
  51. package/lib/engine/engine_license.js.map +1 -1
  52. package/lib/engine/engine_pmrem.js +2 -2
  53. package/lib/engine/engine_pmrem.js.map +1 -1
  54. package/lib/engine/engine_scenetools.d.ts +62 -0
  55. package/lib/engine/engine_scenetools.js +337 -0
  56. package/lib/engine/engine_scenetools.js.map +1 -0
  57. package/lib/engine/engine_serialization_builtin_serializer.d.ts +1 -1
  58. package/lib/engine/engine_test_utils.d.ts +39 -0
  59. package/lib/engine/engine_test_utils.js +84 -0
  60. package/lib/engine/engine_test_utils.js.map +1 -0
  61. package/lib/engine/engine_three_utils.js.map +1 -1
  62. package/lib/engine/engine_time.js +4 -3
  63. package/lib/engine/engine_time.js.map +1 -1
  64. package/lib/engine/engine_ui.d.ts +25 -0
  65. package/lib/engine/engine_ui.dummy_canvas.d.ts +2 -0
  66. package/lib/engine/engine_ui.dummy_canvas.js +55 -0
  67. package/lib/engine/engine_ui.dummy_canvas.js.map +1 -0
  68. package/lib/engine/engine_ui.js +168 -0
  69. package/lib/engine/engine_ui.js.map +1 -0
  70. package/lib/engine/extensions/NEEDLE_lightmaps.js +2 -2
  71. package/lib/engine/extensions/NEEDLE_lightmaps.js.map +1 -1
  72. package/lib/engine/extensions/NEEDLE_pmrem.d.ts +1 -1
  73. package/lib/engine/webcomponents/icons.js +3 -2
  74. package/lib/engine/webcomponents/icons.js.map +1 -1
  75. package/lib/engine/webcomponents/needle-engine.attributes.d.ts +69 -0
  76. package/lib/engine/webcomponents/needle-engine.attributes.js +2 -0
  77. package/lib/engine/webcomponents/needle-engine.attributes.js.map +1 -0
  78. package/lib/engine-components/AudioSource.js +1 -1
  79. package/lib/engine-components/AudioSource.js.map +1 -1
  80. package/lib/engine-components/Light.d.ts +3 -0
  81. package/lib/engine-components/Light.js +39 -31
  82. package/lib/engine-components/Light.js.map +1 -1
  83. package/lib/engine-components/OrbitControls.js +2 -1
  84. package/lib/engine-components/OrbitControls.js.map +1 -1
  85. package/lib/engine-components/SpriteRenderer.d.ts +1 -1
  86. package/lib/engine-components/VideoPlayer.d.ts +1 -1
  87. package/lib/engine-components/export/usdz/ThreeUSDZExporter.js.map +1 -1
  88. package/lib/engine-components/export/usdz/extensions/Animation.js +1 -0
  89. package/lib/engine-components/export/usdz/extensions/Animation.js.map +1 -1
  90. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.d.ts +1 -1
  91. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js.map +1 -1
  92. package/lib/engine-components/particlesystem/ParticleSystem.d.ts +1 -1
  93. package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.d.ts +1 -1
  94. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
  95. package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
  96. package/lib/engine-components/ui/BaseUIComponent_Uikit.d.ts +54 -0
  97. package/lib/engine-components/ui/BaseUIComponent_Uikit.js +114 -0
  98. package/lib/engine-components/ui/BaseUIComponent_Uikit.js.map +1 -0
  99. package/lib/engine-components/ui/BaseUikitComponent.d.ts +54 -0
  100. package/lib/engine-components/ui/BaseUikitComponent.js +114 -0
  101. package/lib/engine-components/ui/BaseUikitComponent.js.map +1 -0
  102. package/lib/engine-components/ui/Button.legacy.d.ts +68 -0
  103. package/lib/engine-components/ui/Button.legacy.js +320 -0
  104. package/lib/engine-components/ui/Button.legacy.js.map +1 -0
  105. package/lib/engine-components/ui/ButtonUikit.d.ts +51 -0
  106. package/lib/engine-components/ui/ButtonUikit.js +187 -0
  107. package/lib/engine-components/ui/ButtonUikit.js.map +1 -0
  108. package/lib/engine-components/ui/Canvas.js +2 -2
  109. package/lib/engine-components/ui/Canvas.js.map +1 -1
  110. package/lib/engine-components/ui/Canvas.legacy.d.ts +76 -0
  111. package/lib/engine-components/ui/Canvas.legacy.js +409 -0
  112. package/lib/engine-components/ui/Canvas.legacy.js.map +1 -0
  113. package/lib/engine-components/ui/CanvasUikit.d.ts +68 -0
  114. package/lib/engine-components/ui/CanvasUikit.js +289 -0
  115. package/lib/engine-components/ui/CanvasUikit.js.map +1 -0
  116. package/lib/engine-components/ui/Graphic.d.ts +3 -3
  117. package/lib/engine-components/ui/Graphic.js +6 -2
  118. package/lib/engine-components/ui/Graphic.js.map +1 -1
  119. package/lib/engine-components/ui/Graphic.legacy.d.ts +55 -0
  120. package/lib/engine-components/ui/Graphic.legacy.js +268 -0
  121. package/lib/engine-components/ui/Graphic.legacy.js.map +1 -0
  122. package/lib/engine-components/ui/GraphicUikit.d.ts +21 -0
  123. package/lib/engine-components/ui/GraphicUikit.js +65 -0
  124. package/lib/engine-components/ui/GraphicUikit.js.map +1 -0
  125. package/lib/engine-components/ui/Image.js.map +1 -1
  126. package/lib/engine-components/ui/Image.legacy.d.ts +39 -0
  127. package/lib/engine-components/ui/Image.legacy.js +121 -0
  128. package/lib/engine-components/ui/Image.legacy.js.map +1 -0
  129. package/lib/engine-components/ui/ImageUikit.d.ts +22 -0
  130. package/lib/engine-components/ui/ImageUikit.js +97 -0
  131. package/lib/engine-components/ui/ImageUikit.js.map +1 -0
  132. package/lib/engine-components/ui/RenderMode.d.ts +14 -0
  133. package/lib/engine-components/ui/RenderMode.js +16 -0
  134. package/lib/engine-components/ui/RenderMode.js.map +1 -0
  135. package/lib/engine-components/ui/Text.d.ts +64 -11
  136. package/lib/engine-components/ui/Text.js +154 -45
  137. package/lib/engine-components/ui/Text.js.map +1 -1
  138. package/lib/engine-components/ui/Text.legacy.d.ts +81 -0
  139. package/lib/engine-components/ui/Text.legacy.js +548 -0
  140. package/lib/engine-components/ui/Text.legacy.js.map +1 -0
  141. package/lib/engine-components/ui/TextUikit.d.ts +42 -0
  142. package/lib/engine-components/ui/TextUikit.js +164 -0
  143. package/lib/engine-components/ui/TextUikit.js.map +1 -0
  144. package/lib/engine-components/ui/index.d.ts +1 -0
  145. package/lib/engine-components/ui/index.js +1 -0
  146. package/lib/engine-components/ui/index.js.map +1 -1
  147. package/lib/engine-components/webxr/WebARCameraBackground.d.ts +1 -1
  148. package/lib/include/three/EXT_mesh_gpu_instancing_exporter.d.ts +6 -0
  149. package/lib/include/three/EXT_mesh_gpu_instancing_exporter.js +46 -0
  150. package/lib/include/three/EXT_mesh_gpu_instancing_exporter.js.map +1 -0
  151. package/package.json +4 -4
  152. package/plugins/common/buildinfo.d.ts +6 -0
  153. package/plugins/vite/ai.d.ts +7 -8
  154. package/plugins/vite/ai.js +95 -20
  155. package/plugins/vite/alias.js +6 -0
  156. package/plugins/vite/dependencies.js +7 -0
  157. package/src/engine/engine_animation.ts +1 -1
  158. package/src/engine/engine_audio.ts +1 -1
  159. package/src/engine/engine_context.ts +3 -6
  160. package/src/engine/engine_create_objects.ts +0 -1
  161. package/src/engine/engine_license.ts +0 -2
  162. package/src/engine/engine_pmrem.ts +3 -3
  163. package/src/engine/engine_three_utils.ts +2 -2
  164. package/src/engine/engine_time.ts +4 -3
  165. package/src/engine/extensions/NEEDLE_lightmaps.ts +3 -3
  166. package/src/engine/webcomponents/icons.ts +3 -2
  167. package/src/engine-components/AudioSource.ts +1 -1
  168. package/src/engine-components/Light.ts +39 -31
  169. package/src/engine-components/OrbitControls.ts +2 -2
  170. package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +2 -2
  171. package/src/engine-components/export/usdz/extensions/Animation.ts +6 -5
  172. package/src/engine-components/export/usdz/extensions/behavior/BehaviourComponents.ts +1 -1
  173. package/src/engine-components/postprocessing/PostProcessingHandler.ts +3 -3
  174. package/src/engine-components/timeline/TimelineTracks.ts +2 -2
  175. package/src/engine-components/ui/Canvas.ts +2 -2
  176. package/src/engine-components/ui/Graphic.ts +7 -3
  177. package/src/engine-components/ui/Image.ts +1 -1
  178. package/src/engine-components/ui/Text.ts +170 -52
  179. package/src/engine-components/ui/index.ts +2 -1
  180. package/dist/generateMeshBVH.worker-DiCnZlf3.js +0 -21
  181. package/dist/gltf-progressive-BryRjllq.min.js +0 -10
  182. package/dist/gltf-progressive-DJBMx-zB.umd.cjs +0 -10
  183. package/dist/gltf-progressive.worker-BqODMeeW.js +0 -23
@@ -0,0 +1 @@
1
+ (function(){"use strict";const Wt="183.2";function Ls(f){for(let t=f.length-1;t>=0;--t)if(f[t]>=65535)return!0;return!1}function es(f){return document.createElementNS("http://www.w3.org/1999/xhtml",f)}function is(f){const t=f[0];if(typeof t=="string"&&t.startsWith("TSL:")){const e=f[1];e&&e.isStackTrace?f[0]+=" "+e.getLocation():f[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return f}function ut(...f){f=is(f);const t="THREE."+f.shift();{const e=f[0];e&&e.isStackTrace?console.warn(e.getError(t)):console.warn(t,...f)}}function Rt(...f){f=is(f);const t="THREE."+f.shift();{const e=f[0];e&&e.isStackTrace?console.error(e.getError(t)):console.error(t,...f)}}class ri{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return i===void 0?!1:i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){const i=this._listeners;if(i===void 0)return;const s=i[t];if(s!==void 0){const n=s.indexOf(e);n!==-1&&s.splice(n,1)}}dispatchEvent(t){const e=this._listeners;if(e===void 0)return;const i=e[t.type];if(i!==void 0){t.target=this;const s=i.slice(0);for(let n=0,r=s.length;n<r;n++)s[n].call(this,t);t.target=null}}}const Z=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];function Pe(){const f=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(Z[f&255]+Z[f>>8&255]+Z[f>>16&255]+Z[f>>24&255]+"-"+Z[t&255]+Z[t>>8&255]+"-"+Z[t>>16&15|64]+Z[t>>24&255]+"-"+Z[e&63|128]+Z[e>>8&255]+"-"+Z[e>>16&255]+Z[e>>24&255]+Z[i&255]+Z[i>>8&255]+Z[i>>16&255]+Z[i>>24&255]).toLowerCase()}function R(f,t,e){return Math.max(t,Math.min(e,f))}function fe(f,t){switch(t.constructor){case Float32Array:return f;case Uint32Array:return f/4294967295;case Uint16Array:return f/65535;case Uint8Array:return f/255;case Int32Array:return Math.max(f/2147483647,-1);case Int16Array:return Math.max(f/32767,-1);case Int8Array:return Math.max(f/127,-1);default:throw new Error("Invalid component type.")}}function j(f,t){switch(t.constructor){case Float32Array:return f;case Uint32Array:return Math.round(f*4294967295);case Uint16Array:return Math.round(f*65535);case Uint8Array:return Math.round(f*255);case Int32Array:return Math.round(f*2147483647);case Int16Array:return Math.round(f*32767);case Int8Array:return Math.round(f*127);default:throw new Error("Invalid component type.")}}class Y{constructor(t=0,e=0){Y.prototype.isVector2=!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){return 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){return 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,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6],this.y=s[1]*e+s[4]*i+s[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=R(this.x,t.x,e.x),this.y=R(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=R(this.x,t,e),this.y=R(this.y,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(R(i,t,e))}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=Math.trunc(this.x),this.y=Math.trunc(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}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(R(i,-1,1))}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){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const i=Math.cos(e),s=Math.sin(e),n=this.x-t.x,r=this.y-t.y;return this.x=n*i-r*s+t.x,this.y=n*s+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class de{constructor(t=0,e=0,i=0,s=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=i,this._w=s}static slerpFlat(t,e,i,s,n,r,a){let o=i[s+0],c=i[s+1],h=i[s+2],u=i[s+3],l=n[r+0],d=n[r+1],y=n[r+2],m=n[r+3];if(u!==m||o!==l||c!==d||h!==y){let _=o*l+c*d+h*y+u*m;_<0&&(l=-l,d=-d,y=-y,m=-m,_=-_);let g=1-a;if(_<.9995){const p=Math.acos(_),x=Math.sin(p);g=Math.sin(g*p)/x,a=Math.sin(a*p)/x,o=o*g+l*a,c=c*g+d*a,h=h*g+y*a,u=u*g+m*a}else{o=o*g+l*a,c=c*g+d*a,h=h*g+y*a,u=u*g+m*a;const p=1/Math.sqrt(o*o+c*c+h*h+u*u);o*=p,c*=p,h*=p,u*=p}}t[e]=o,t[e+1]=c,t[e+2]=h,t[e+3]=u}static multiplyQuaternionsFlat(t,e,i,s,n,r){const a=i[s],o=i[s+1],c=i[s+2],h=i[s+3],u=n[r],l=n[r+1],d=n[r+2],y=n[r+3];return t[e]=a*y+h*u+o*d-c*l,t[e+1]=o*y+h*l+c*u-a*d,t[e+2]=c*y+h*d+a*l-o*u,t[e+3]=h*y-a*u-o*l-c*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,s){return this._x=t,this._y=e,this._z=i,this._w=s,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=!0){const i=t._x,s=t._y,n=t._z,r=t._order,a=Math.cos,o=Math.sin,c=a(i/2),h=a(s/2),u=a(n/2),l=o(i/2),d=o(s/2),y=o(n/2);switch(r){case"XYZ":this._x=l*h*u+c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u-l*d*y;break;case"YXZ":this._x=l*h*u+c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u+l*d*y;break;case"ZXY":this._x=l*h*u-c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u-l*d*y;break;case"ZYX":this._x=l*h*u-c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u+l*d*y;break;case"YZX":this._x=l*h*u+c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u-l*d*y;break;case"XZY":this._x=l*h*u-c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u+l*d*y;break;default:ut("Quaternion: .setFromEuler() encountered an unknown order: "+r)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,s=Math.sin(i);return this._x=t.x*s,this._y=t.y*s,this._z=t.z*s,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],s=e[4],n=e[8],r=e[1],a=e[5],o=e[9],c=e[2],h=e[6],u=e[10],l=i+a+u;if(l>0){const d=.5/Math.sqrt(l+1);this._w=.25/d,this._x=(h-o)*d,this._y=(n-c)*d,this._z=(r-s)*d}else if(i>a&&i>u){const d=2*Math.sqrt(1+i-a-u);this._w=(h-o)/d,this._x=.25*d,this._y=(s+r)/d,this._z=(n+c)/d}else if(a>u){const d=2*Math.sqrt(1+a-i-u);this._w=(n-c)/d,this._x=(s+r)/d,this._y=.25*d,this._z=(o+h)/d}else{const d=2*Math.sqrt(1+u-i-a);this._w=(r-s)/d,this._x=(n+c)/d,this._y=(o+h)/d,this._z=.25*d}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<1e-8?(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(R(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(i===0)return this;const s=Math.min(1,e/i);return this.slerp(t,s),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 t===0?(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){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const i=t._x,s=t._y,n=t._z,r=t._w,a=e._x,o=e._y,c=e._z,h=e._w;return this._x=i*h+r*a+s*c-n*o,this._y=s*h+r*o+n*a-i*c,this._z=n*h+r*c+i*o-s*a,this._w=r*h-i*a-s*o-n*c,this._onChangeCallback(),this}slerp(t,e){let i=t._x,s=t._y,n=t._z,r=t._w,a=this.dot(t);a<0&&(i=-i,s=-s,n=-n,r=-r,a=-a);let o=1-e;if(a<.9995){const c=Math.acos(a),h=Math.sin(c);o=Math.sin(o*c)/h,e=Math.sin(e*c)/h,this._x=this._x*o+i*e,this._y=this._y*o+s*e,this._z=this._z*o+n*e,this._w=this._w*o+r*e,this._onChangeCallback()}else this._x=this._x*o+i*e,this._y=this._y*o+s*e,this._z=this._z*o+n*e,this._w=this._w*o+r*e,this.normalize();return this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),i=Math.random(),s=Math.sqrt(1-i),n=Math.sqrt(i);return this.set(s*Math.sin(t),s*Math.cos(t),n*Math.sin(e),n*Math.cos(e))}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._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class M{constructor(t=0,e=0,i=0){M.prototype.isVector3=!0,this.x=t,this.y=e,this.z=i}set(t,e,i){return i===void 0&&(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){return 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){return 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){return 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 this.applyQuaternion(ss.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(ss.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6]*s,this.y=n[1]*e+n[4]*i+n[7]*s,this.z=n[2]*e+n[5]*i+n[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=t.elements,r=1/(n[3]*e+n[7]*i+n[11]*s+n[15]);return this.x=(n[0]*e+n[4]*i+n[8]*s+n[12])*r,this.y=(n[1]*e+n[5]*i+n[9]*s+n[13])*r,this.z=(n[2]*e+n[6]*i+n[10]*s+n[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,s=this.z,n=t.x,r=t.y,a=t.z,o=t.w,c=2*(r*s-a*i),h=2*(a*e-n*s),u=2*(n*i-r*e);return this.x=e+o*c+r*u-a*h,this.y=i+o*h+a*c-n*u,this.z=s+o*u+n*h-r*c,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,s=this.z,n=t.elements;return this.x=n[0]*e+n[4]*i+n[8]*s,this.y=n[1]*e+n[5]*i+n[9]*s,this.z=n[2]*e+n[6]*i+n[10]*s,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=R(this.x,t.x,e.x),this.y=R(this.y,t.y,e.y),this.z=R(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=R(this.x,t,e),this.y=R(this.y,t,e),this.z=R(this.z,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(R(i,t,e))}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=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(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){return this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,s=t.y,n=t.z,r=e.x,a=e.y,o=e.z;return this.x=s*o-n*a,this.y=n*r-i*o,this.z=i*a-s*r,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return oi.copy(this).projectOnVector(t),this.sub(oi)}reflect(t){return this.sub(oi.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(R(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,s=this.z-t.z;return e*e+i*i+s*s}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 s=Math.sin(e)*t;return this.x=s*Math.sin(i),this.y=Math.cos(e)*t,this.z=s*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(),s=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=s,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}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){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=Math.random()*Math.PI*2,e=Math.random()*2-1,i=Math.sqrt(1-e*e);return this.x=i*Math.cos(t),this.y=e,this.z=i*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const oi=new M,ss=new de;class Vt{constructor(t,e,i,s,n,r,a,o,c){Vt.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,c)}set(t,e,i,s,n,r,a,o,c){const h=this.elements;return h[0]=t,h[1]=s,h[2]=a,h[3]=e,h[4]=n,h[5]=o,h[6]=i,h[7]=r,h[8]=c,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,s=e.elements,n=this.elements,r=i[0],a=i[3],o=i[6],c=i[1],h=i[4],u=i[7],l=i[2],d=i[5],y=i[8],m=s[0],_=s[3],g=s[6],p=s[1],x=s[4],b=s[7],w=s[2],S=s[5],z=s[8];return n[0]=r*m+a*p+o*w,n[3]=r*_+a*x+o*S,n[6]=r*g+a*b+o*z,n[1]=c*m+h*p+u*w,n[4]=c*_+h*x+u*S,n[7]=c*g+h*b+u*z,n[2]=l*m+d*p+y*w,n[5]=l*_+d*x+y*S,n[8]=l*g+d*b+y*z,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],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8];return e*r*h-e*a*c-i*n*h+i*a*o+s*n*c-s*r*o}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8],u=h*r-a*c,l=a*o-h*n,d=c*n-r*o,y=e*u+i*l+s*d;if(y===0)return this.set(0,0,0,0,0,0,0,0,0);const m=1/y;return t[0]=u*m,t[1]=(s*c-h*i)*m,t[2]=(a*i-s*r)*m,t[3]=l*m,t[4]=(h*e-s*o)*m,t[5]=(s*n-a*e)*m,t[6]=d*m,t[7]=(i*o-c*e)*m,t[8]=(r*e-i*n)*m,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,s,n,r,a){const o=Math.cos(n),c=Math.sin(n);return this.set(i*o,i*c,-i*(o*r+c*a)+r+t,-s*c,s*o,-s*(-c*r+o*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(ai.makeScale(t,e)),this}rotate(t){return this.premultiply(ai.makeRotation(-t)),this}translate(t,e){return this.premultiply(ai.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,i,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<9;s++)if(e[s]!==i[s])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)}}const ai=new Vt;function ci(f){return f<.04045?f*.0773993808:Math.pow(f*.9478672986+.0521327014,2.4)}let Xt;class qs{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let i;if(t instanceof HTMLCanvasElement)i=t;else{Xt===void 0&&(Xt=es("canvas")),Xt.width=t.width,Xt.height=t.height;const s=Xt.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),i=Xt}return i.toDataURL(e)}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=es("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.drawImage(t,0,0,t.width,t.height);const s=i.getImageData(0,0,t.width,t.height),n=s.data;for(let r=0;r<n.length;r++)n[r]=ci(n[r]/255)*255;return i.putImageData(s,0,0),e}else if(t.data){const e=t.data.slice(0);for(let i=0;i<e.length;i++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[i]=Math.floor(ci(e[i]/255)*255):e[i]=ci(e[i]);return{data:e,width:t.width,height:t.height}}else return ut("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let Os=0;class vs{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:Os++}),this.uuid=Pe(),this.data=t,this.dataReady=!0,this.version=0}getSize(t){const e=this.data;return typeof HTMLVideoElement<"u"&&e instanceof HTMLVideoElement?t.set(e.videoWidth,e.videoHeight,0):typeof VideoFrame<"u"&&e instanceof VideoFrame?t.set(e.displayHeight,e.displayWidth,0):e!==null?t.set(e.width,e.height,e.depth||0):t.set(0,0,0),t}set needsUpdate(t){t===!0&&this.version++}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.images[this.uuid];const i={uuid:this.uuid,url:""},s=this.data;if(s!==null){let n;if(Array.isArray(s)){n=[];for(let r=0,a=s.length;r<a;r++)s[r].isDataTexture?n.push(hi(s[r].image)):n.push(hi(s[r]))}else n=hi(s);i.url=n}return e||(t.images[this.uuid]=i),i}}function hi(f){return typeof HTMLImageElement<"u"&&f instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&f instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&f instanceof ImageBitmap?qs.getDataURL(f):f.data?{data:Array.from(f.data),width:f.width,height:f.height,type:f.data.constructor.name}:(ut("Texture: Unable to serialize Texture."),{})}let Ws=0;const li=new M;class Ut extends ri{constructor(t=Ut.DEFAULT_IMAGE,e=Ut.DEFAULT_MAPPING,i=1001,s=1001,n=1006,r=1008,a=1023,o=1009,c=Ut.DEFAULT_ANISOTROPY,h=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:Ws++}),this.uuid=Pe(),this.name="",this.source=new vs(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=i,this.wrapT=s,this.magFilter=n,this.minFilter=r,this.anisotropy=c,this.format=a,this.internalFormat=null,this.type=o,this.offset=new Y(0,0),this.repeat=new Y(1,1),this.center=new Y(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Vt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0}get width(){return this.source.getSize(li).x}get height(){return this.source.getSize(li).y}get depth(){return this.source.getSize(li).z}get image(){return this.source.data}set image(t=null){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,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.colorSpace=t.colorSpace,this.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(const e in t){const i=t[e];if(i===void 0){ut(`Texture.setValues(): parameter '${e}' has value of undefined.`);continue}const s=this[e];if(s===void 0){ut(`Texture.setValues(): property '${e}' does not exist.`);continue}s&&i&&s.isVector2&&i.isVector2||s&&i&&s.isVector3&&i.isVector3||s&&i&&s.isMatrix3&&i.isMatrix3?s.copy(i):this[e]=i}}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const i={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,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,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(i.userData=this.userData),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==300)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case 1e3:t.x=t.x-Math.floor(t.x);break;case 1001:t.x=t.x<0?0:1;break;case 1002:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case 1e3:t.y=t.y-Math.floor(t.y);break;case 1001:t.y=t.y<0?0:1;break;case 1002:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}Ut.DEFAULT_IMAGE=null,Ut.DEFAULT_MAPPING=300,Ut.DEFAULT_ANISOTROPY=4;class ye{constructor(t=0,e=0,i=0,s=1){ye.prototype.isVector4=!0,this.x=t,this.y=e,this.z=i,this.w=s}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,s){return this.x=t,this.y=e,this.z=i,this.w=s,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=t.w!==void 0?t.w:1,this}add(t){return 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){return 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,s=this.z,n=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*s+r[12]*n,this.y=r[1]*e+r[5]*i+r[9]*s+r[13]*n,this.z=r[2]*e+r[6]*i+r[10]*s+r[14]*n,this.w=r[3]*e+r[7]*i+r[11]*s+r[15]*n,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,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,s,n;const o=t.elements,c=o[0],h=o[4],u=o[8],l=o[1],d=o[5],y=o[9],m=o[2],_=o[6],g=o[10];if(Math.abs(h-l)<.01&&Math.abs(u-m)<.01&&Math.abs(y-_)<.01){if(Math.abs(h+l)<.1&&Math.abs(u+m)<.1&&Math.abs(y+_)<.1&&Math.abs(c+d+g-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const x=(c+1)/2,b=(d+1)/2,w=(g+1)/2,S=(h+l)/4,z=(u+m)/4,A=(y+_)/4;return x>b&&x>w?x<.01?(i=0,s=.707106781,n=.707106781):(i=Math.sqrt(x),s=S/i,n=z/i):b>w?b<.01?(i=.707106781,s=0,n=.707106781):(s=Math.sqrt(b),i=S/s,n=A/s):w<.01?(i=.707106781,s=.707106781,n=0):(n=Math.sqrt(w),i=z/n,s=A/n),this.set(i,s,n,e),this}let p=Math.sqrt((_-y)*(_-y)+(u-m)*(u-m)+(l-h)*(l-h));return Math.abs(p)<.001&&(p=1),this.x=(_-y)/p,this.y=(u-m)/p,this.z=(l-h)/p,this.w=Math.acos((c+d+g-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],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=R(this.x,t.x,e.x),this.y=R(this.y,t.y,e.y),this.z=R(this.z,t.z,e.z),this.w=R(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=R(this.x,t,e),this.y=R(this.y,t,e),this.z=R(this.z,t,e),this.w=R(this.w,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(R(i,t,e))}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=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(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){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}}class O{constructor(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,_){O.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,_)}set(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,_){const g=this.elements;return g[0]=t,g[4]=e,g[8]=i,g[12]=s,g[1]=n,g[5]=r,g[9]=a,g[13]=o,g[2]=c,g[6]=h,g[10]=u,g[14]=l,g[3]=d,g[7]=y,g[11]=m,g[15]=_,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 O().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 this.determinant()===0?(t.set(1,0,0),e.set(0,1,0),i.set(0,0,1),this):(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){if(t.determinant()===0)return this.identity();const e=this.elements,i=t.elements,s=1/Yt.setFromMatrixColumn(t,0).length(),n=1/Yt.setFromMatrixColumn(t,1).length(),r=1/Yt.setFromMatrixColumn(t,2).length();return e[0]=i[0]*s,e[1]=i[1]*s,e[2]=i[2]*s,e[3]=0,e[4]=i[4]*n,e[5]=i[5]*n,e[6]=i[6]*n,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){const e=this.elements,i=t.x,s=t.y,n=t.z,r=Math.cos(i),a=Math.sin(i),o=Math.cos(s),c=Math.sin(s),h=Math.cos(n),u=Math.sin(n);if(t.order==="XYZ"){const l=r*h,d=r*u,y=a*h,m=a*u;e[0]=o*h,e[4]=-o*u,e[8]=c,e[1]=d+y*c,e[5]=l-m*c,e[9]=-a*o,e[2]=m-l*c,e[6]=y+d*c,e[10]=r*o}else if(t.order==="YXZ"){const l=o*h,d=o*u,y=c*h,m=c*u;e[0]=l+m*a,e[4]=y*a-d,e[8]=r*c,e[1]=r*u,e[5]=r*h,e[9]=-a,e[2]=d*a-y,e[6]=m+l*a,e[10]=r*o}else if(t.order==="ZXY"){const l=o*h,d=o*u,y=c*h,m=c*u;e[0]=l-m*a,e[4]=-r*u,e[8]=y+d*a,e[1]=d+y*a,e[5]=r*h,e[9]=m-l*a,e[2]=-r*c,e[6]=a,e[10]=r*o}else if(t.order==="ZYX"){const l=r*h,d=r*u,y=a*h,m=a*u;e[0]=o*h,e[4]=y*c-d,e[8]=l*c+m,e[1]=o*u,e[5]=m*c+l,e[9]=d*c-y,e[2]=-c,e[6]=a*o,e[10]=r*o}else if(t.order==="YZX"){const l=r*o,d=r*c,y=a*o,m=a*c;e[0]=o*h,e[4]=m-l*u,e[8]=y*u+d,e[1]=u,e[5]=r*h,e[9]=-a*h,e[2]=-c*h,e[6]=d*u+y,e[10]=l-m*u}else if(t.order==="XZY"){const l=r*o,d=r*c,y=a*o,m=a*c;e[0]=o*h,e[4]=-u,e[8]=c*h,e[1]=l*u+m,e[5]=r*h,e[9]=d*u-y,e[2]=y*u-d,e[6]=a*h,e[10]=m*u+l}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(Xs,t,Ys)}lookAt(t,e,i){const s=this.elements;return K.subVectors(t,e),K.lengthSq()===0&&(K.z=1),K.normalize(),Mt.crossVectors(i,K),Mt.lengthSq()===0&&(Math.abs(i.z)===1?K.x+=1e-4:K.z+=1e-4,K.normalize(),Mt.crossVectors(i,K)),Mt.normalize(),Ce.crossVectors(K,Mt),s[0]=Mt.x,s[4]=Ce.x,s[8]=K.x,s[1]=Mt.y,s[5]=Ce.y,s[9]=K.y,s[2]=Mt.z,s[6]=Ce.z,s[10]=K.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[4],o=i[8],c=i[12],h=i[1],u=i[5],l=i[9],d=i[13],y=i[2],m=i[6],_=i[10],g=i[14],p=i[3],x=i[7],b=i[11],w=i[15],S=s[0],z=s[4],A=s[8],P=s[12],B=s[1],C=s[5],T=s[9],E=s[13],I=s[2],F=s[6],U=s[10],_t=s[14],Ot=s[3],vt=s[7],It=s[11],Ft=s[15];return n[0]=r*S+a*B+o*I+c*Ot,n[4]=r*z+a*C+o*F+c*vt,n[8]=r*A+a*T+o*U+c*It,n[12]=r*P+a*E+o*_t+c*Ft,n[1]=h*S+u*B+l*I+d*Ot,n[5]=h*z+u*C+l*F+d*vt,n[9]=h*A+u*T+l*U+d*It,n[13]=h*P+u*E+l*_t+d*Ft,n[2]=y*S+m*B+_*I+g*Ot,n[6]=y*z+m*C+_*F+g*vt,n[10]=y*A+m*T+_*U+g*It,n[14]=y*P+m*E+_*_t+g*Ft,n[3]=p*S+x*B+b*I+w*Ot,n[7]=p*z+x*C+b*F+w*vt,n[11]=p*A+x*T+b*U+w*It,n[15]=p*P+x*E+b*_t+w*Ft,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],s=t[8],n=t[12],r=t[1],a=t[5],o=t[9],c=t[13],h=t[2],u=t[6],l=t[10],d=t[14],y=t[3],m=t[7],_=t[11],g=t[15],p=o*d-c*l,x=a*d-c*u,b=a*l-o*u,w=r*d-c*h,S=r*l-o*h,z=r*u-a*h;return e*(m*p-_*x+g*b)-i*(y*p-_*w+g*S)+s*(y*x-m*w+g*z)-n*(y*b-m*S+_*z)}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 s=this.elements;return t.isVector3?(s[12]=t.x,s[13]=t.y,s[14]=t.z):(s[12]=t,s[13]=e,s[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8],u=t[9],l=t[10],d=t[11],y=t[12],m=t[13],_=t[14],g=t[15],p=e*a-i*r,x=e*o-s*r,b=e*c-n*r,w=i*o-s*a,S=i*c-n*a,z=s*c-n*o,A=h*m-u*y,P=h*_-l*y,B=h*g-d*y,C=u*_-l*m,T=u*g-d*m,E=l*g-d*_,I=p*E-x*T+b*C+w*B-S*P+z*A;if(I===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const F=1/I;return t[0]=(a*E-o*T+c*C)*F,t[1]=(s*T-i*E-n*C)*F,t[2]=(m*z-_*S+g*w)*F,t[3]=(l*S-u*z-d*w)*F,t[4]=(o*B-r*E-c*P)*F,t[5]=(e*E-s*B+n*P)*F,t[6]=(_*b-y*z-g*x)*F,t[7]=(h*z-l*b+d*x)*F,t[8]=(r*T-a*B+c*A)*F,t[9]=(i*B-e*T-n*A)*F,t[10]=(y*S-m*b+g*p)*F,t[11]=(u*b-h*S-d*p)*F,t[12]=(a*P-r*C-o*A)*F,t[13]=(e*C-i*P+s*A)*F,t[14]=(m*x-y*w-_*p)*F,t[15]=(h*w-u*x+l*p)*F,this}scale(t){const e=this.elements,i=t.x,s=t.y,n=t.z;return e[0]*=i,e[4]*=s,e[8]*=n,e[1]*=i,e[5]*=s,e[9]*=n,e[2]*=i,e[6]*=s,e[10]*=n,e[3]*=i,e[7]*=s,e[11]*=n,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],s=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,s))}makeTranslation(t,e,i){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):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),s=Math.sin(e),n=1-i,r=t.x,a=t.y,o=t.z,c=n*r,h=n*a;return this.set(c*r+i,c*a-s*o,c*o+s*a,0,c*a+s*o,h*a+i,h*o-s*r,0,c*o-s*a,h*o+s*r,n*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,s,n,r){return this.set(1,i,n,0,t,1,r,0,e,s,1,0,0,0,0,1),this}compose(t,e,i){const s=this.elements,n=e._x,r=e._y,a=e._z,o=e._w,c=n+n,h=r+r,u=a+a,l=n*c,d=n*h,y=n*u,m=r*h,_=r*u,g=a*u,p=o*c,x=o*h,b=o*u,w=i.x,S=i.y,z=i.z;return s[0]=(1-(m+g))*w,s[1]=(d+b)*w,s[2]=(y-x)*w,s[3]=0,s[4]=(d-b)*S,s[5]=(1-(l+g))*S,s[6]=(_+p)*S,s[7]=0,s[8]=(y+x)*z,s[9]=(_-p)*z,s[10]=(1-(l+m))*z,s[11]=0,s[12]=t.x,s[13]=t.y,s[14]=t.z,s[15]=1,this}decompose(t,e,i){const s=this.elements;t.x=s[12],t.y=s[13],t.z=s[14];const n=this.determinant();if(n===0)return i.set(1,1,1),e.identity(),this;let r=Yt.set(s[0],s[1],s[2]).length();const a=Yt.set(s[4],s[5],s[6]).length(),o=Yt.set(s[8],s[9],s[10]).length();n<0&&(r=-r),rt.copy(this);const c=1/r,h=1/a,u=1/o;return rt.elements[0]*=c,rt.elements[1]*=c,rt.elements[2]*=c,rt.elements[4]*=h,rt.elements[5]*=h,rt.elements[6]*=h,rt.elements[8]*=u,rt.elements[9]*=u,rt.elements[10]*=u,e.setFromRotationMatrix(rt),i.x=r,i.y=a,i.z=o,this}makePerspective(t,e,i,s,n,r,a=2e3,o=!1){const c=this.elements,h=2*n/(e-t),u=2*n/(i-s),l=(e+t)/(e-t),d=(i+s)/(i-s);let y,m;if(o)y=n/(r-n),m=r*n/(r-n);else if(a===2e3)y=-(r+n)/(r-n),m=-2*r*n/(r-n);else if(a===2001)y=-r/(r-n),m=-r*n/(r-n);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=l,c[12]=0,c[1]=0,c[5]=u,c[9]=d,c[13]=0,c[2]=0,c[6]=0,c[10]=y,c[14]=m,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(t,e,i,s,n,r,a=2e3,o=!1){const c=this.elements,h=2/(e-t),u=2/(i-s),l=-(e+t)/(e-t),d=-(i+s)/(i-s);let y,m;if(o)y=1/(r-n),m=r/(r-n);else if(a===2e3)y=-2/(r-n),m=-(r+n)/(r-n);else if(a===2001)y=-1/(r-n),m=-n/(r-n);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=0,c[12]=l,c[1]=0,c[5]=u,c[9]=0,c[13]=d,c[2]=0,c[6]=0,c[10]=y,c[14]=m,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<16;s++)if(e[s]!==i[s])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}}const Yt=new M,rt=new O,Xs=new M(0,0,0),Ys=new M(1,1,1),Mt=new M,Ce=new M,K=new M,ns=new O,rs=new de;class Ee{constructor(t=0,e=0,i=0,s=Ee.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=i,this._order=s}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,s=this._order){return this._x=t,this._y=e,this._z=i,this._order=s,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 s=t.elements,n=s[0],r=s[4],a=s[8],o=s[1],c=s[5],h=s[9],u=s[2],l=s[6],d=s[10];switch(e){case"XYZ":this._y=Math.asin(R(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,d),this._z=Math.atan2(-r,n)):(this._x=Math.atan2(l,c),this._z=0);break;case"YXZ":this._x=Math.asin(-R(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,c)):(this._y=Math.atan2(-u,n),this._z=0);break;case"ZXY":this._x=Math.asin(R(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(-u,d),this._z=Math.atan2(-r,c)):(this._y=0,this._z=Math.atan2(o,n));break;case"ZYX":this._y=Math.asin(-R(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(l,d),this._z=Math.atan2(o,n)):(this._x=0,this._z=Math.atan2(-r,c));break;case"YZX":this._z=Math.asin(R(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,c),this._y=Math.atan2(-u,n)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-R(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(l,c),this._y=Math.atan2(a,n)):(this._x=Math.atan2(-h,d),this._y=0);break;default:ut("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,i===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return ns.makeRotationFromQuaternion(t),this.setFromRotationMatrix(ns,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return rs.setFromEuler(this),this.setFromQuaternion(rs,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],t[3]!==void 0&&(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}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Ee.DEFAULT_ORDER="XYZ";class Zs{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(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}}let $s=0;const os=new M,Zt=new de,ft=new O,Ie=new M,me=new M,Hs=new M,Js=new de,as=new M(1,0,0),cs=new M(0,1,0),hs=new M(0,0,1),ls={type:"added"},Gs={type:"removed"},$t={type:"childadded",child:null},ui={type:"childremoved",child:null};class zt extends ri{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:$s++}),this.uuid=Pe(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=zt.DEFAULT_UP.clone();const t=new M,e=new Ee,i=new de,s=new M(1,1,1);function n(){i.setFromEuler(e,!1)}function r(){e.setFromQuaternion(i,void 0,!1)}e._onChange(n),i._onChange(r),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:s},modelViewMatrix:{value:new O},normalMatrix:{value:new Vt}}),this.matrix=new O,this.matrixWorld=new O,this.matrixAutoUpdate=zt.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=zt.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new Zs,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}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 Zt.setFromAxisAngle(t,e),this.quaternion.multiply(Zt),this}rotateOnWorldAxis(t,e){return Zt.setFromAxisAngle(t,e),this.quaternion.premultiply(Zt),this}rotateX(t){return this.rotateOnAxis(as,t)}rotateY(t){return this.rotateOnAxis(cs,t)}rotateZ(t){return this.rotateOnAxis(hs,t)}translateOnAxis(t,e){return os.copy(t).applyQuaternion(this.quaternion),this.position.add(os.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(as,t)}translateY(t){return this.translateOnAxis(cs,t)}translateZ(t){return this.translateOnAxis(hs,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(ft.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?Ie.copy(t):Ie.set(t,e,i);const s=this.parent;this.updateWorldMatrix(!0,!1),me.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?ft.lookAt(me,Ie,this.up):ft.lookAt(Ie,me,this.up),this.quaternion.setFromRotationMatrix(ft),s&&(ft.extractRotation(s.matrixWorld),Zt.setFromRotationMatrix(ft),this.quaternion.premultiply(Zt.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(Rt("Object3D.add: object can't be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(ls),$t.child=t,this.dispatchEvent($t),$t.child=null):Rt("Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(Gs),ui.child=t,this.dispatchEvent(ui),ui.child=null),this}removeFromParent(){const t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),ft.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),ft.multiply(t.parent.matrixWorld)),t.applyMatrix4(ft),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(ls),$t.child=t,this.dispatchEvent($t),$t.child=null,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,s=this.children.length;i<s;i++){const r=this.children[i].getObjectByProperty(t,e);if(r!==void 0)return r}}getObjectsByProperty(t,e,i=[]){this[t]===e&&i.push(this);const s=this.children;for(let n=0,r=s.length;n<r;n++)s[n].getObjectsByProperty(t,e,i);return i}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(me,t,Hs),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(me,Js,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,s=e.length;i<s;i++)e[i].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverseVisible(t)}traverseAncestors(t){const e=this.parent;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const t=this.pivot;if(t!==null){const e=t.x,i=t.y,s=t.z,n=this.matrix.elements;n[12]+=e-n[0]*e-n[4]*i-n[8]*s,n[13]+=i-n[1]*e-n[5]*i-n[9]*s,n[14]+=s-n[2]*e-n[6]*i-n[10]*s}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?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,s=e.length;i<s;i++)e[i].updateMatrixWorld(t)}updateWorldMatrix(t,e){const i=this.parent;if(t===!0&&i!==null&&i.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),e===!0){const s=this.children;for(let n=0,r=s.length;n<r;n++)s[n].updateWorldMatrix(!1,!0)}}toJSON(t){const e=t===void 0||typeof t=="string",i={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const s={};s.uuid=this.uuid,s.type=this.type,this.name!==""&&(s.name=this.name),this.castShadow===!0&&(s.castShadow=!0),this.receiveShadow===!0&&(s.receiveShadow=!0),this.visible===!1&&(s.visible=!1),this.frustumCulled===!1&&(s.frustumCulled=!1),this.renderOrder!==0&&(s.renderOrder=this.renderOrder),this.static!==!1&&(s.static=this.static),Object.keys(this.userData).length>0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),this.pivot!==null&&(s.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(s.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(s.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(s.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(s.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(s.type="BatchedMesh",s.perObjectFrustumCulled=this.perObjectFrustumCulled,s.sortObjects=this.sortObjects,s.drawRanges=this._drawRanges,s.reservedRanges=this._reservedRanges,s.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),s.instanceInfo=this._instanceInfo.map(a=>({...a})),s.availableInstanceIds=this._availableInstanceIds.slice(),s.availableGeometryIds=this._availableGeometryIds.slice(),s.nextIndexStart=this._nextIndexStart,s.nextVertexStart=this._nextVertexStart,s.geometryCount=this._geometryCount,s.maxInstanceCount=this._maxInstanceCount,s.maxVertexCount=this._maxVertexCount,s.maxIndexCount=this._maxIndexCount,s.geometryInitialized=this._geometryInitialized,s.matricesTexture=this._matricesTexture.toJSON(t),s.indirectTexture=this._indirectTexture.toJSON(t),this._colorsTexture!==null&&(s.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(s.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(s.boundingBox=this.boundingBox.toJSON()));function n(a,o){return a[o.uuid]===void 0&&(a[o.uuid]=o.toJSON(t)),o.uuid}if(this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(s.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=n(t.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const o=a.shapes;if(Array.isArray(o))for(let c=0,h=o.length;c<h;c++){const u=o[c];n(t.shapes,u)}else n(t.shapes,o)}}if(this.isSkinnedMesh&&(s.bindMode=this.bindMode,s.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(n(t.skeletons,this.skeleton),s.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const a=[];for(let o=0,c=this.material.length;o<c;o++)a.push(n(t.materials,this.material[o]));s.material=a}else s.material=n(t.materials,this.material);if(this.children.length>0){s.children=[];for(let a=0;a<this.children.length;a++)s.children.push(this.children[a].toJSON(t).object)}if(this.animations.length>0){s.animations=[];for(let a=0;a<this.animations.length;a++){const o=this.animations[a];s.animations.push(n(t.animations,o))}}if(e){const a=r(t.geometries),o=r(t.materials),c=r(t.textures),h=r(t.images),u=r(t.shapes),l=r(t.skeletons),d=r(t.animations),y=r(t.nodes);a.length>0&&(i.geometries=a),o.length>0&&(i.materials=o),c.length>0&&(i.textures=c),h.length>0&&(i.images=h),u.length>0&&(i.shapes=u),l.length>0&&(i.skeletons=l),d.length>0&&(i.animations=d),y.length>0&&(i.nodes=y)}return i.object=s,i;function r(a){const o=[];for(const c in a){const h=a[c];delete h.metadata,o.push(h)}return o}}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),t.pivot!==null&&(this.pivot=t.pivot.clone()),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,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.static=t.static,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let i=0;i<t.children.length;i++){const s=t.children[i];this.add(s.clone())}return this}}zt.DEFAULT_UP=new M(0,1,0),zt.DEFAULT_MATRIX_AUTO_UPDATE=!0,zt.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const ot=new M,dt=new M,fi=new M,yt=new M,Ht=new M,Jt=new M,us=new M,di=new M,yi=new M,mi=new M,pi=new ye,xi=new ye,gi=new ye;class et{constructor(t=new M,e=new M,i=new M){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,s){s.subVectors(i,e),ot.subVectors(t,e),s.cross(ot);const n=s.lengthSq();return n>0?s.multiplyScalar(1/Math.sqrt(n)):s.set(0,0,0)}static getBarycoord(t,e,i,s,n){ot.subVectors(s,e),dt.subVectors(i,e),fi.subVectors(t,e);const r=ot.dot(ot),a=ot.dot(dt),o=ot.dot(fi),c=dt.dot(dt),h=dt.dot(fi),u=r*c-a*a;if(u===0)return n.set(0,0,0),null;const l=1/u,d=(c*o-a*h)*l,y=(r*h-a*o)*l;return n.set(1-d-y,y,d)}static containsPoint(t,e,i,s){return this.getBarycoord(t,e,i,s,yt)===null?!1:yt.x>=0&&yt.y>=0&&yt.x+yt.y<=1}static getInterpolation(t,e,i,s,n,r,a,o){return this.getBarycoord(t,e,i,s,yt)===null?(o.x=0,o.y=0,"z"in o&&(o.z=0),"w"in o&&(o.w=0),null):(o.setScalar(0),o.addScaledVector(n,yt.x),o.addScaledVector(r,yt.y),o.addScaledVector(a,yt.z),o)}static getInterpolatedAttribute(t,e,i,s,n,r){return pi.setScalar(0),xi.setScalar(0),gi.setScalar(0),pi.fromBufferAttribute(t,e),xi.fromBufferAttribute(t,i),gi.fromBufferAttribute(t,s),r.setScalar(0),r.addScaledVector(pi,n.x),r.addScaledVector(xi,n.y),r.addScaledVector(gi,n.z),r}static isFrontFacing(t,e,i,s){return ot.subVectors(i,e),dt.subVectors(t,e),ot.cross(dt).dot(s)<0}set(t,e,i){return this.a.copy(t),this.b.copy(e),this.c.copy(i),this}setFromPointsAndIndices(t,e,i,s){return this.a.copy(t[e]),this.b.copy(t[i]),this.c.copy(t[s]),this}setFromAttributeAndIndices(t,e,i,s){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,s),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 ot.subVectors(this.c,this.b),dt.subVectors(this.a,this.b),ot.cross(dt).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return et.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return et.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,i,s,n){return et.getInterpolation(t,this.a,this.b,this.c,e,i,s,n)}containsPoint(t){return et.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return et.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const i=this.a,s=this.b,n=this.c;let r,a;Ht.subVectors(s,i),Jt.subVectors(n,i),di.subVectors(t,i);const o=Ht.dot(di),c=Jt.dot(di);if(o<=0&&c<=0)return e.copy(i);yi.subVectors(t,s);const h=Ht.dot(yi),u=Jt.dot(yi);if(h>=0&&u<=h)return e.copy(s);const l=o*u-h*c;if(l<=0&&o>=0&&h<=0)return r=o/(o-h),e.copy(i).addScaledVector(Ht,r);mi.subVectors(t,n);const d=Ht.dot(mi),y=Jt.dot(mi);if(y>=0&&d<=y)return e.copy(n);const m=d*c-o*y;if(m<=0&&c>=0&&y<=0)return a=c/(c-y),e.copy(i).addScaledVector(Jt,a);const _=h*y-d*u;if(_<=0&&u-h>=0&&d-y>=0)return us.subVectors(n,s),a=(u-h)/(u-h+(d-y)),e.copy(s).addScaledVector(us,a);const g=1/(_+m+l);return r=m*g,a=l*g,e.copy(i).addScaledVector(Ht,r).addScaledVector(Jt,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}class J{constructor(t=new M(1/0,1/0,1/0),e=new M(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e+=3)this.expandByPoint(at.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,i=t.count;e<i;e++)this.expandByPoint(at.fromBufferAttribute(t,e));return 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=at.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}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=1/0,this.max.x=this.max.y=this.max.z=-1/0,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,e=!1){t.updateWorldMatrix(!1,!1);const i=t.geometry;if(i!==void 0){const n=i.getAttribute("position");if(e===!0&&n!==void 0&&t.isInstancedMesh!==!0)for(let r=0,a=n.count;r<a;r++)t.isMesh===!0?t.getVertexPosition(r,at):at.fromBufferAttribute(n,r),at.applyMatrix4(t.matrixWorld),this.expandByPoint(at);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),Fe.copy(t.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),Fe.copy(i.boundingBox)),Fe.applyMatrix4(t.matrixWorld),this.union(Fe)}const s=t.children;for(let n=0,r=s.length;n<r;n++)this.expandByObject(s[n],e);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,at),at.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(pe),Re.subVectors(this.max,pe),Gt.subVectors(t.a,pe),Qt.subVectors(t.b,pe),jt.subVectors(t.c,pe),At.subVectors(Qt,Gt),St.subVectors(jt,Qt),kt.subVectors(Gt,jt);let e=[0,-At.z,At.y,0,-St.z,St.y,0,-kt.z,kt.y,At.z,0,-At.x,St.z,0,-St.x,kt.z,0,-kt.x,-At.y,At.x,0,-St.y,St.x,0,-kt.y,kt.x,0];return!wi(e,Gt,Qt,jt,Re)||(e=[1,0,0,0,1,0,0,0,1],!wi(e,Gt,Qt,jt,Re))?!1:(Ve.crossVectors(At,St),e=[Ve.x,Ve.y,Ve.z],wi(e,Gt,Qt,jt,Re))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,at).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(at).length()*.5),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()?this:(mt[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),mt[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),mt[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),mt[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),mt[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),mt[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),mt[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),mt[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(mt),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)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}}const mt=[new M,new M,new M,new M,new M,new M,new M,new M],at=new M,Fe=new J,Gt=new M,Qt=new M,jt=new M,At=new M,St=new M,kt=new M,pe=new M,Re=new M,Ve=new M,Nt=new M;function wi(f,t,e,i,s){for(let n=0,r=f.length-3;n<=r;n+=3){Nt.fromArray(f,n);const a=s.x*Math.abs(Nt.x)+s.y*Math.abs(Nt.y)+s.z*Math.abs(Nt.z),o=t.dot(Nt),c=e.dot(Nt),h=i.dot(Nt);if(Math.max(-Math.max(o,c,h),Math.min(o,c,h))>a)return!1}return!0}const N=new M,Ue=new Y;let Qs=0;class lt{constructor(t,e,i=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:Qs++}),this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=i,this.usage=35044,this.updateRanges=[],this.gpuType=1015,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}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.gpuType=t.gpuType,this}copyAt(t,e,i){t*=this.itemSize,i*=e.itemSize;for(let s=0,n=this.itemSize;s<n;s++)this.array[t+s]=e.array[i+s];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,i=this.count;e<i;e++)Ue.fromBufferAttribute(this,e),Ue.applyMatrix3(t),this.setXY(e,Ue.x,Ue.y);else if(this.itemSize===3)for(let e=0,i=this.count;e<i;e++)N.fromBufferAttribute(this,e),N.applyMatrix3(t),this.setXYZ(e,N.x,N.y,N.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)N.fromBufferAttribute(this,e),N.applyMatrix4(t),this.setXYZ(e,N.x,N.y,N.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)N.fromBufferAttribute(this,e),N.applyNormalMatrix(t),this.setXYZ(e,N.x,N.y,N.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)N.fromBufferAttribute(this,e),N.transformDirection(t),this.setXYZ(e,N.x,N.y,N.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let i=this.array[t*this.itemSize+e];return this.normalized&&(i=fe(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=j(i,this.array)),this.array[t*this.itemSize+e]=i,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=fe(e,this.array)),e}setX(t,e){return this.normalized&&(e=j(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=fe(e,this.array)),e}setY(t,e){return this.normalized&&(e=j(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=fe(e,this.array)),e}setZ(t,e){return this.normalized&&(e=j(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=fe(e,this.array)),e}setW(t,e){return this.normalized&&(e=j(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=j(e,this.array),i=j(i,this.array)),this.array[t+0]=e,this.array[t+1]=i,this}setXYZ(t,e,i,s){return t*=this.itemSize,this.normalized&&(e=j(e,this.array),i=j(i,this.array),s=j(s,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this}setXYZW(t,e,i,s,n){return t*=this.itemSize,this.normalized&&(e=j(e,this.array),i=j(i,this.array),s=j(s,this.array),n=j(n,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this.array[t+3]=n,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.from(this.array),normalized:this.normalized};return this.name!==""&&(t.name=this.name),this.usage!==35044&&(t.usage=this.usage),t}}class js extends lt{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class Ks extends lt{constructor(t,e,i){super(new Uint32Array(t),e,i)}}class tn extends lt{constructor(t,e,i){super(new Float32Array(t),e,i)}}const en=new J,xe=new M,bi=new M;class sn{constructor(t=new M,e=-1){this.isSphere=!0,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;e!==void 0?i.copy(e):en.setFromPoints(t).getCenter(i);let s=0;for(let n=0,r=t.length;n<r;n++)s=Math.max(s,i.distanceToSquared(t[n]));return this.radius=Math.sqrt(s),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){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;xe.subVectors(t,this.center);const e=xe.lengthSq();if(e>this.radius*this.radius){const i=Math.sqrt(e),s=(i-this.radius)*.5;this.center.addScaledVector(xe,s/i),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(bi.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(xe.copy(t.center).add(bi)),this.expandByPoint(xe.copy(t.center).sub(bi))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}}let nn=0;const it=new O,_i=new zt,Kt=new M,tt=new J,ge=new J,v=new M;class Mi extends ri{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:nn++}),this.uuid=Pe(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(Ls(t)?Ks:js)(t,1):this.index=t,this}setIndirect(t,e=0){return this.indirect=t,this.indirectOffset=e,this}getIndirect(){return this.indirect}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 this.attributes[t]!==void 0}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;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);const i=this.attributes.normal;if(i!==void 0){const n=new Vt().getNormalMatrix(t);i.applyNormalMatrix(n),i.needsUpdate=!0}const s=this.attributes.tangent;return s!==void 0&&(s.transformDirection(t),s.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(t){return it.makeRotationFromQuaternion(t),this.applyMatrix4(it),this}rotateX(t){return it.makeRotationX(t),this.applyMatrix4(it),this}rotateY(t){return it.makeRotationY(t),this.applyMatrix4(it),this}rotateZ(t){return it.makeRotationZ(t),this.applyMatrix4(it),this}translate(t,e,i){return it.makeTranslation(t,e,i),this.applyMatrix4(it),this}scale(t,e,i){return it.makeScale(t,e,i),this.applyMatrix4(it),this}lookAt(t){return _i.lookAt(t),_i.updateMatrix(),this.applyMatrix4(_i.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Kt).negate(),this.translate(Kt.x,Kt.y,Kt.z),this}setFromPoints(t){const e=this.getAttribute("position");if(e===void 0){const i=[];for(let s=0,n=t.length;s<n;s++){const r=t[s];i.push(r.x,r.y,r.z||0)}this.setAttribute("position",new tn(i,3))}else{const i=Math.min(t.length,e.count);for(let s=0;s<i;s++){const n=t[s];e.setXYZ(s,n.x,n.y,n.z||0)}t.length>e.count&&ut("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new J);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Rt("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new M(-1/0,-1/0,-1/0),new M(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let i=0,s=e.length;i<s;i++){const n=e[i];tt.setFromBufferAttribute(n),this.morphTargetsRelative?(v.addVectors(this.boundingBox.min,tt.min),this.boundingBox.expandByPoint(v),v.addVectors(this.boundingBox.max,tt.max),this.boundingBox.expandByPoint(v)):(this.boundingBox.expandByPoint(tt.min),this.boundingBox.expandByPoint(tt.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&Rt('BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new sn);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Rt("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new M,1/0);return}if(t){const i=this.boundingSphere.center;if(tt.setFromBufferAttribute(t),e)for(let n=0,r=e.length;n<r;n++){const a=e[n];ge.setFromBufferAttribute(a),this.morphTargetsRelative?(v.addVectors(tt.min,ge.min),tt.expandByPoint(v),v.addVectors(tt.max,ge.max),tt.expandByPoint(v)):(tt.expandByPoint(ge.min),tt.expandByPoint(ge.max))}tt.getCenter(i);let s=0;for(let n=0,r=t.count;n<r;n++)v.fromBufferAttribute(t,n),s=Math.max(s,i.distanceToSquared(v));if(e)for(let n=0,r=e.length;n<r;n++){const a=e[n],o=this.morphTargetsRelative;for(let c=0,h=a.count;c<h;c++)v.fromBufferAttribute(a,c),o&&(Kt.fromBufferAttribute(t,c),v.add(Kt)),s=Math.max(s,i.distanceToSquared(v))}this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)&&Rt('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const t=this.index,e=this.attributes;if(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){Rt("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=e.position,s=e.normal,n=e.uv;this.hasAttribute("tangent")===!1&&this.setAttribute("tangent",new lt(new Float32Array(4*i.count),4));const r=this.getAttribute("tangent"),a=[],o=[];for(let A=0;A<i.count;A++)a[A]=new M,o[A]=new M;const c=new M,h=new M,u=new M,l=new Y,d=new Y,y=new Y,m=new M,_=new M;function g(A,P,B){c.fromBufferAttribute(i,A),h.fromBufferAttribute(i,P),u.fromBufferAttribute(i,B),l.fromBufferAttribute(n,A),d.fromBufferAttribute(n,P),y.fromBufferAttribute(n,B),h.sub(c),u.sub(c),d.sub(l),y.sub(l);const C=1/(d.x*y.y-y.x*d.y);isFinite(C)&&(m.copy(h).multiplyScalar(y.y).addScaledVector(u,-d.y).multiplyScalar(C),_.copy(u).multiplyScalar(d.x).addScaledVector(h,-y.x).multiplyScalar(C),a[A].add(m),a[P].add(m),a[B].add(m),o[A].add(_),o[P].add(_),o[B].add(_))}let p=this.groups;p.length===0&&(p=[{start:0,count:t.count}]);for(let A=0,P=p.length;A<P;++A){const B=p[A],C=B.start,T=B.count;for(let E=C,I=C+T;E<I;E+=3)g(t.getX(E+0),t.getX(E+1),t.getX(E+2))}const x=new M,b=new M,w=new M,S=new M;function z(A){w.fromBufferAttribute(s,A),S.copy(w);const P=a[A];x.copy(P),x.sub(w.multiplyScalar(w.dot(P))).normalize(),b.crossVectors(S,P);const C=b.dot(o[A])<0?-1:1;r.setXYZW(A,x.x,x.y,x.z,C)}for(let A=0,P=p.length;A<P;++A){const B=p[A],C=B.start,T=B.count;for(let E=C,I=C+T;E<I;E+=3)z(t.getX(E+0)),z(t.getX(E+1)),z(t.getX(E+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let i=this.getAttribute("normal");if(i===void 0)i=new lt(new Float32Array(e.count*3),3),this.setAttribute("normal",i);else for(let l=0,d=i.count;l<d;l++)i.setXYZ(l,0,0,0);const s=new M,n=new M,r=new M,a=new M,o=new M,c=new M,h=new M,u=new M;if(t)for(let l=0,d=t.count;l<d;l+=3){const y=t.getX(l+0),m=t.getX(l+1),_=t.getX(l+2);s.fromBufferAttribute(e,y),n.fromBufferAttribute(e,m),r.fromBufferAttribute(e,_),h.subVectors(r,n),u.subVectors(s,n),h.cross(u),a.fromBufferAttribute(i,y),o.fromBufferAttribute(i,m),c.fromBufferAttribute(i,_),a.add(h),o.add(h),c.add(h),i.setXYZ(y,a.x,a.y,a.z),i.setXYZ(m,o.x,o.y,o.z),i.setXYZ(_,c.x,c.y,c.z)}else for(let l=0,d=e.count;l<d;l+=3)s.fromBufferAttribute(e,l+0),n.fromBufferAttribute(e,l+1),r.fromBufferAttribute(e,l+2),h.subVectors(r,n),u.subVectors(s,n),h.cross(u),i.setXYZ(l+0,h.x,h.y,h.z),i.setXYZ(l+1,h.x,h.y,h.z),i.setXYZ(l+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,i=t.count;e<i;e++)v.fromBufferAttribute(t,e),v.normalize(),t.setXYZ(e,v.x,v.y,v.z)}toNonIndexed(){function t(a,o){const c=a.array,h=a.itemSize,u=a.normalized,l=new c.constructor(o.length*h);let d=0,y=0;for(let m=0,_=o.length;m<_;m++){a.isInterleavedBufferAttribute?d=o[m]*a.data.stride+a.offset:d=o[m]*h;for(let g=0;g<h;g++)l[y++]=c[d++]}return new lt(l,h,u)}if(this.index===null)return ut("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Mi,i=this.index.array,s=this.attributes;for(const a in s){const o=s[a],c=t(o,i);e.setAttribute(a,c)}const n=this.morphAttributes;for(const a in n){const o=[],c=n[a];for(let h=0,u=c.length;h<u;h++){const l=c[h],d=t(l,i);o.push(d)}e.morphAttributes[a]=o}e.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let a=0,o=r.length;a<o;a++){const c=r[a];e.addGroup(c.start,c.count,c.materialIndex)}return e}toJSON(){const t={metadata:{version:4.7,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),this.parameters!==void 0){const o=this.parameters;for(const c in o)o[c]!==void 0&&(t[c]=o[c]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const i=this.attributes;for(const o in i){const c=i[o];t.data.attributes[o]=c.toJSON(t.data)}const s={};let n=!1;for(const o in this.morphAttributes){const c=this.morphAttributes[o],h=[];for(let u=0,l=c.length;u<l;u++){const d=c[u];h.push(d.toJSON(t.data))}h.length>0&&(s[o]=h,n=!0)}n&&(t.data.morphAttributes=s,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 a!==null&&(t.data.boundingSphere=a.toJSON()),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;i!==null&&this.setIndex(i.clone());const s=t.attributes;for(const c in s){const h=s[c];this.setAttribute(c,h.clone(e))}const n=t.morphAttributes;for(const c in n){const h=[],u=n[c];for(let l=0,d=u.length;l<d;l++)h.push(u[l].clone(e));this.morphAttributes[c]=h}this.morphTargetsRelative=t.morphTargetsRelative;const r=t.groups;for(let c=0,h=r.length;c<h;c++){const u=r[c];this.addGroup(u.start,u.count,u.materialIndex)}const a=t.boundingBox;a!==null&&(this.boundingBox=a.clone());const o=t.boundingSphere;return o!==null&&(this.boundingSphere=o.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}const pt=new M,zi=new M,ke=new M,Bt=new M,Ai=new M,Ne=new M,Si=new M;class rn{constructor(t=new M,e=new M(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.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,pt)),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.origin).addScaledVector(this.direction,i)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=pt.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(pt.copy(this.origin).addScaledVector(this.direction,e),pt.distanceToSquared(t))}distanceSqToSegment(t,e,i,s){zi.copy(t).add(e).multiplyScalar(.5),ke.copy(e).sub(t).normalize(),Bt.copy(this.origin).sub(zi);const n=t.distanceTo(e)*.5,r=-this.direction.dot(ke),a=Bt.dot(this.direction),o=-Bt.dot(ke),c=Bt.lengthSq(),h=Math.abs(1-r*r);let u,l,d,y;if(h>0)if(u=r*o-a,l=r*a-o,y=n*h,u>=0)if(l>=-y)if(l<=y){const m=1/h;u*=m,l*=m,d=u*(u+r*l+2*a)+l*(r*u+l+2*o)+c}else l=n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;else l=-n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;else l<=-y?(u=Math.max(0,-(-r*n+a)),l=u>0?-n:Math.min(Math.max(-n,-o),n),d=-u*u+l*(l+2*o)+c):l<=y?(u=0,l=Math.min(Math.max(-n,-o),n),d=l*(l+2*o)+c):(u=Math.max(0,-(r*n+a)),l=u>0?n:Math.min(Math.max(-n,-o),n),d=-u*u+l*(l+2*o)+c);else l=r>0?-n:n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;return i&&i.copy(this.origin).addScaledVector(this.direction,u),s&&s.copy(zi).addScaledVector(ke,l),d}intersectSphere(t,e){pt.subVectors(t.center,this.origin);const i=pt.dot(this.direction),s=pt.dot(pt)-i*i,n=t.radius*t.radius;if(s>n)return null;const r=Math.sqrt(n-s),a=i-r,o=i+r;return o<0?null:a<0?this.at(o,e):this.at(a,e)}intersectsSphere(t){return t.radius<0?!1:this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?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 i===null?null:this.at(i,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let i,s,n,r,a,o;const c=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,l=this.origin;return c>=0?(i=(t.min.x-l.x)*c,s=(t.max.x-l.x)*c):(i=(t.max.x-l.x)*c,s=(t.min.x-l.x)*c),h>=0?(n=(t.min.y-l.y)*h,r=(t.max.y-l.y)*h):(n=(t.max.y-l.y)*h,r=(t.min.y-l.y)*h),i>r||n>s||((n>i||isNaN(i))&&(i=n),(r<s||isNaN(s))&&(s=r),u>=0?(a=(t.min.z-l.z)*u,o=(t.max.z-l.z)*u):(a=(t.max.z-l.z)*u,o=(t.min.z-l.z)*u),i>o||a>s)||((a>i||i!==i)&&(i=a),(o<s||s!==s)&&(s=o),s<0)?null:this.at(i>=0?i:s,e)}intersectsBox(t){return this.intersectBox(t,pt)!==null}intersectTriangle(t,e,i,s,n){Ai.subVectors(e,t),Ne.subVectors(i,t),Si.crossVectors(Ai,Ne);let r=this.direction.dot(Si),a;if(r>0){if(s)return null;a=1}else if(r<0)a=-1,r=-r;else return null;Bt.subVectors(this.origin,t);const o=a*this.direction.dot(Ne.crossVectors(Bt,Ne));if(o<0)return null;const c=a*this.direction.dot(Ai.cross(Bt));if(c<0||o+c>r)return null;const h=-a*Bt.dot(Si);return h<0?null:this.at(h/r,n)}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)}}const Bi=new M,on=new M,an=new Vt;class fs{constructor(t=new M(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,i,s){return this.normal.set(t,e,i),this.constant=s,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,i){const s=Bi.subVectors(i,e).cross(on.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(s,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(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const i=t.delta(Bi),s=this.normal.dot(i);if(s===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const n=-(t.start.dot(this.normal)+this.constant)/s;return n<0||n>1?null:e.copy(t.start).addScaledVector(i,n)}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||an.getNormalMatrix(t),s=this.coplanarPoint(Bi).applyMatrix4(t),n=this.normal.applyMatrix3(i).normalize();return this.constant=-s.dot(n),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)}}const ds=new M,De=new M,te=new M,ee=new M,Ti=new M,cn=new M,hn=new M;class xt{constructor(t=new M,e=new M){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){ds.subVectors(t,this.start),De.subVectors(this.end,this.start);const i=De.dot(De);let n=De.dot(ds)/i;return e&&(n=R(n,0,1)),n}closestPointToPoint(t,e,i){const s=this.closestPointToPointParameter(t,e);return this.delta(i).multiplyScalar(s).add(this.start)}distanceSqToLine3(t,e=cn,i=hn){const s=10000000000000001e-32;let n,r;const a=this.start,o=t.start,c=this.end,h=t.end;te.subVectors(c,a),ee.subVectors(h,o),Ti.subVectors(a,o);const u=te.dot(te),l=ee.dot(ee),d=ee.dot(Ti);if(u<=s&&l<=s)return e.copy(a),i.copy(o),e.sub(i),e.dot(e);if(u<=s)n=0,r=d/l,r=R(r,0,1);else{const y=te.dot(Ti);if(l<=s)r=0,n=R(-y/u,0,1);else{const m=te.dot(ee),_=u*l-m*m;_!==0?n=R((m*d-y*l)/_,0,1):n=0,r=(m*n+d)/l,r<0?(r=0,n=R(-y/u,0,1)):r>1&&(r=1,n=R((m-y)/u,0,1))}}return e.copy(a).addScaledVector(te,n),i.copy(o).addScaledVector(ee,r),e.distanceToSquared(i)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return new this.constructor().copy(this)}}if(typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:Wt}})),typeof window<"u"){try{self.location.href,window.__THREE__IMPORTS__||(window.__THREE__IMPORTS__=[]),window.__THREE__IMPORTS__.push({url:self.location.href,revision:Wt})}catch{}window.__THREE__?(ut("WARNING: Multiple instances of Three.js being imported. Existing: "+window.__THREE__+", new: "+Wt),console.warn("THREE imports:",window.__THREE__IMPORTS__)):window.__THREE__=Wt}const ys=0,ln=1,un=2,ms=2,Pi=1.25,ps=1,$=32,L=$/4,xs=65535,Le=Math.pow(2,-24),Ci=Symbol("SKIP_GENERATION"),gs={strategy:ys,maxDepth:40,maxLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Ci]:!1};class gt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,s=-1/0;for(let n=0,r=t.length;n<r;n++){const o=t[n][e];i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}setFromPoints(t,e){let i=1/0,s=-1/0;for(let n=0,r=e.length;n<r;n++){const a=e[n],o=t.dot(a);i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}isSeparated(t){return this.min>t.max||t.min>this.max}}gt.prototype.setFromBox=(function(){const f=new M;return function(e,i){const s=i.min,n=i.max;let r=1/0,a=-1/0;for(let o=0;o<=1;o++)for(let c=0;c<=1;c++)for(let h=0;h<=1;h++){f.x=s.x*o+n.x*(1-o),f.y=s.y*c+n.y*(1-c),f.z=s.z*h+n.z*(1-h);const u=e.dot(f);r=Math.min(u,r),a=Math.max(u,a)}this.min=r,this.max=a}})();const fn=(function(){const f=new M,t=new M,e=new M;return function(s,n,r){const a=s.start,o=f,c=n.start,h=t;e.subVectors(a,c),f.subVectors(s.end,s.start),t.subVectors(n.end,n.start);const u=e.dot(h),l=h.dot(o),d=h.dot(h),y=e.dot(o),_=o.dot(o)*d-l*l;let g,p;_!==0?g=(u*l-y*d)/_:g=0,p=(u+g*l)/d,r.x=g,r.y=p}})(),Ei=(function(){const f=new Y,t=new M,e=new M;return function(s,n,r,a){fn(s,n,f);let o=f.x,c=f.y;if(o>=0&&o<=1&&c>=0&&c<=1){s.at(o,r),n.at(c,a);return}else if(o>=0&&o<=1){c<0?n.at(0,a):n.at(1,a),s.closestPointToPoint(a,!0,r);return}else if(c>=0&&c<=1){o<0?s.at(0,r):s.at(1,r),n.closestPointToPoint(r,!0,a);return}else{let h;o<0?h=s.start:h=s.end;let u;c<0?u=n.start:u=n.end;const l=t,d=e;if(s.closestPointToPoint(u,!0,t),n.closestPointToPoint(h,!0,e),l.distanceToSquared(u)<=d.distanceToSquared(h)){r.copy(l),a.copy(u);return}else{r.copy(h),a.copy(d);return}}}})(),dn=(function(){const f=new M,t=new M,e=new fs,i=new xt;return function(n,r){const{radius:a,center:o}=n,{a:c,b:h,c:u}=r;if(i.start=c,i.end=h,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a||(i.start=c,i.end=u,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a)||(i.start=h,i.end=u,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a))return!0;const m=r.getPlane(e);if(Math.abs(m.distanceToPoint(o))<=a){const g=m.projectPoint(o,t);if(r.containsPoint(g))return!0}return!1}})(),yn=["x","y","z"],wt=1e-15,ws=wt*wt;function st(f){return Math.abs(f)<wt}class ct extends et{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new M),this.satBounds=new Array(4).fill().map(()=>new gt),this.points=[this.a,this.b,this.c],this.plane=new fs,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new xt,this.needsUpdate=!0}intersectsSphere(t){return dn(t,this)}update(){const t=this.a,e=this.b,i=this.c,s=this.points,n=this.satAxes,r=this.satBounds,a=n[0],o=r[0];this.getNormal(a),o.setFromPoints(a,s);const c=n[1],h=r[1];c.subVectors(t,e),h.setFromPoints(c,s);const u=n[2],l=r[2];u.subVectors(e,i),l.setFromPoints(u,s);const d=n[3],y=r[3];d.subVectors(i,t),y.setFromPoints(d,s);const m=c.length(),_=u.length(),g=d.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,m<wt?_<wt||g<wt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(i)):_<wt?g<wt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):g<wt&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(i),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}ct.prototype.closestPointToSegment=(function(){const f=new M,t=new M,e=new xt;return function(s,n=null,r=null){const{start:a,end:o}=s,c=this.points;let h,u=1/0;for(let l=0;l<3;l++){const d=(l+1)%3;e.start.copy(c[l]),e.end.copy(c[d]),Ei(e,s,f,t),h=f.distanceToSquared(t),h<u&&(u=h,n&&n.copy(f),r&&r.copy(t))}return this.closestPointToPoint(a,f),h=a.distanceToSquared(f),h<u&&(u=h,n&&n.copy(f),r&&r.copy(a)),this.closestPointToPoint(o,f),h=o.distanceToSquared(f),h<u&&(u=h,n&&n.copy(f),r&&r.copy(o)),Math.sqrt(u)}})(),ct.prototype.intersectsTriangle=(function(){const f=new ct,t=new gt,e=new gt,i=new M,s=new M,n=new M,r=new M,a=new xt,o=new xt,c=new M,h=new Y,u=new Y;function l(x,b,w,S){const z=i;!x.isDegenerateIntoPoint&&!x.isDegenerateIntoSegment?z.copy(x.plane.normal):z.copy(b.plane.normal);const A=x.satBounds,P=x.satAxes;for(let T=1;T<4;T++){const E=A[T],I=P[T];if(t.setFromPoints(I,b.points),E.isSeparated(t)||(r.copy(z).cross(I),t.setFromPoints(r,x.points),e.setFromPoints(r,b.points),t.isSeparated(e)))return!1}const B=b.satBounds,C=b.satAxes;for(let T=1;T<4;T++){const E=B[T],I=C[T];if(t.setFromPoints(I,x.points),E.isSeparated(t)||(r.crossVectors(z,I),t.setFromPoints(r,x.points),e.setFromPoints(r,b.points),t.isSeparated(e)))return!1}return w&&(S||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),w.start.set(0,0,0),w.end.set(0,0,0)),!0}function d(x,b,w,S,z,A,P,B,C,T,E){let I=P/(P-B);T.x=S+(z-S)*I,E.start.subVectors(b,x).multiplyScalar(I).add(x),I=P/(P-C),T.y=S+(A-S)*I,E.end.subVectors(w,x).multiplyScalar(I).add(x)}function y(x,b,w,S,z,A,P,B,C,T,E){if(z>0)d(x.c,x.a,x.b,S,b,w,C,P,B,T,E);else if(A>0)d(x.b,x.a,x.c,w,b,S,B,P,C,T,E);else if(B*C>0||P!=0)d(x.a,x.b,x.c,b,w,S,P,B,C,T,E);else if(B!=0)d(x.b,x.a,x.c,w,b,S,B,P,C,T,E);else if(C!=0)d(x.c,x.a,x.b,S,b,w,C,P,B,T,E);else return!0;return!1}function m(x,b,w,S){const z=b.degenerateSegment,A=x.plane.distanceToPoint(z.start),P=x.plane.distanceToPoint(z.end);return st(A)?st(P)?l(x,b,w,S):(w&&(w.start.copy(z.start),w.end.copy(z.start)),x.containsPoint(z.start)):st(P)?(w&&(w.start.copy(z.end),w.end.copy(z.end)),x.containsPoint(z.end)):x.plane.intersectLine(z,i)!=null?(w&&(w.start.copy(i),w.end.copy(i)),x.containsPoint(i)):!1}function _(x,b,w){const S=b.a;return st(x.plane.distanceToPoint(S))&&x.containsPoint(S)?(w&&(w.start.copy(S),w.end.copy(S)),!0):!1}function g(x,b,w){const S=x.degenerateSegment,z=b.a;return S.closestPointToPoint(z,!0,i),z.distanceToSquared(i)<ws?(w&&(w.start.copy(z),w.end.copy(z)),!0):!1}function p(x,b,w,S){if(x.isDegenerateIntoSegment)if(b.isDegenerateIntoSegment){const z=x.degenerateSegment,A=b.degenerateSegment,P=s,B=n;z.delta(P),A.delta(B);const C=i.subVectors(A.start,z.start),T=P.x*B.y-P.y*B.x;if(st(T))return!1;const E=(C.x*B.y-C.y*B.x)/T,I=-(P.x*C.y-P.y*C.x)/T;if(E<0||E>1||I<0||I>1)return!1;const F=z.start.z+P.z*E,U=A.start.z+B.z*I;return st(F-U)?(w&&(w.start.copy(z.start).addScaledVector(P,E),w.end.copy(z.start).addScaledVector(P,E)),!0):!1}else return b.isDegenerateIntoPoint?g(x,b,w):m(b,x,w,S);else{if(x.isDegenerateIntoPoint)return b.isDegenerateIntoPoint?b.a.distanceToSquared(x.a)<ws?(w&&(w.start.copy(x.a),w.end.copy(x.a)),!0):!1:b.isDegenerateIntoSegment?g(b,x,w):_(b,x,w);if(b.isDegenerateIntoPoint)return _(x,b,w);if(b.isDegenerateIntoSegment)return m(x,b,w,S)}}return function(b,w=null,S=!1){this.needsUpdate&&this.update(),b.isExtendedTriangle?b.needsUpdate&&b.update():(f.copy(b),f.update(),b=f);const z=p(this,b,w,S);if(z!==void 0)return z;const A=this.plane,P=b.plane;let B=P.distanceToPoint(this.a),C=P.distanceToPoint(this.b),T=P.distanceToPoint(this.c);st(B)&&(B=0),st(C)&&(C=0),st(T)&&(T=0);const E=B*C,I=B*T;if(E>0&&I>0)return!1;let F=A.distanceToPoint(b.a),U=A.distanceToPoint(b.b),_t=A.distanceToPoint(b.c);st(F)&&(F=0),st(U)&&(U=0),st(_t)&&(_t=0);const Ot=F*U,vt=F*_t;if(Ot>0&&vt>0)return!1;s.copy(A.normal),n.copy(P.normal);const It=s.cross(n);let Ft=0,Ki=Math.abs(It.x);const Ds=Math.abs(It.y);Ds>Ki&&(Ki=Ds,Ft=1),Math.abs(It.z)>Ki&&(Ft=2);const ue=yn[Ft],lr=this.a[ue],ur=this.b[ue],fr=this.c[ue],dr=b.a[ue],yr=b.b[ue],mr=b.c[ue];if(y(this,lr,ur,fr,E,I,B,C,T,h,a))return l(this,b,w,S);if(y(b,dr,yr,mr,Ot,vt,F,U,_t,u,o))return l(this,b,w,S);if(h.y<h.x){const ts=h.y;h.y=h.x,h.x=ts,c.copy(a.start),a.start.copy(a.end),a.end.copy(c)}if(u.y<u.x){const ts=u.y;u.y=u.x,u.x=ts,c.copy(o.start),o.start.copy(o.end),o.end.copy(c)}return h.y<u.x||u.y<h.x?!1:(w&&(u.x>h.x?w.start.copy(o.start):w.start.copy(a.start),u.y<h.y?w.end.copy(o.end):w.end.copy(a.end)),!0)}})(),ct.prototype.distanceToPoint=(function(){const f=new M;return function(e){return this.closestPointToPoint(e,f),e.distanceTo(f)}})(),ct.prototype.distanceToTriangle=(function(){const f=new M,t=new M,e=["a","b","c"],i=new xt,s=new xt;return function(r,a=null,o=null){const c=a||o?i:null;if(this.intersectsTriangle(r,c))return(a||o)&&(a&&c.getCenter(a),o&&c.getCenter(o)),0;let h=1/0;for(let u=0;u<3;u++){let l;const d=e[u],y=r[d];this.closestPointToPoint(y,f),l=y.distanceToSquared(f),l<h&&(h=l,a&&a.copy(f),o&&o.copy(y));const m=this[d];r.closestPointToPoint(m,f),l=m.distanceToSquared(f),l<h&&(h=l,a&&a.copy(m),o&&o.copy(f))}for(let u=0;u<3;u++){const l=e[u],d=e[(u+1)%3];i.set(this[l],this[d]);for(let y=0;y<3;y++){const m=e[y],_=e[(y+1)%3];s.set(r[m],r[_]),Ei(i,s,f,t);const g=f.distanceToSquared(t);g<h&&(h=g,a&&a.copy(f),o&&o.copy(t))}}return Math.sqrt(h)}})();class G{constructor(t,e,i){this.isOrientedBox=!0,this.min=new M,this.max=new M,this.matrix=new O,this.invMatrix=new O,this.points=new Array(8).fill().map(()=>new M),this.satAxes=new Array(3).fill().map(()=>new M),this.satBounds=new Array(3).fill().map(()=>new gt),this.alignedSatBounds=new Array(3).fill().map(()=>new gt),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}G.prototype.update=(function(){return function(){const t=this.matrix,e=this.min,i=this.max,s=this.points;for(let c=0;c<=1;c++)for(let h=0;h<=1;h++)for(let u=0;u<=1;u++){const l=1*c|2*h|4*u,d=s[l];d.x=c?i.x:e.x,d.y=h?i.y:e.y,d.z=u?i.z:e.z,d.applyMatrix4(t)}const n=this.satBounds,r=this.satAxes,a=s[0];for(let c=0;c<3;c++){const h=r[c],u=n[c],l=1<<c,d=s[l];h.subVectors(a,d),u.setFromPoints(h,s)}const o=this.alignedSatBounds;o[0].setFromPointsField(s,"x"),o[1].setFromPointsField(s,"y"),o[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})(),G.prototype.intersectsBox=(function(){const f=new gt;return function(e){this.needsUpdate&&this.update();const i=e.min,s=e.max,n=this.satBounds,r=this.satAxes,a=this.alignedSatBounds;if(f.min=i.x,f.max=s.x,a[0].isSeparated(f)||(f.min=i.y,f.max=s.y,a[1].isSeparated(f))||(f.min=i.z,f.max=s.z,a[2].isSeparated(f)))return!1;for(let o=0;o<3;o++){const c=r[o],h=n[o];if(f.setFromBox(c,e),h.isSeparated(f))return!1}return!0}})(),G.prototype.intersectsTriangle=(function(){const f=new ct,t=new Array(3),e=new gt,i=new gt,s=new M;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(f.copy(r),f.update(),r=f);const a=this.satBounds,o=this.satAxes;t[0]=r.a,t[1]=r.b,t[2]=r.c;for(let l=0;l<3;l++){const d=a[l],y=o[l];if(e.setFromPoints(y,t),d.isSeparated(e))return!1}const c=r.satBounds,h=r.satAxes,u=this.points;for(let l=0;l<3;l++){const d=c[l],y=h[l];if(e.setFromPoints(y,u),d.isSeparated(e))return!1}for(let l=0;l<3;l++){const d=o[l];for(let y=0;y<4;y++){const m=h[y];if(s.crossVectors(d,m),e.setFromPoints(s,t),i.setFromPoints(s,u),e.isSeparated(i))return!1}}return!0}})(),G.prototype.closestPointToPoint=(function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}})(),G.prototype.distanceToPoint=(function(){const f=new M;return function(e){return this.closestPointToPoint(e,f),e.distanceTo(f)}})(),G.prototype.distanceToBox=(function(){const f=["x","y","z"],t=new Array(12).fill().map(()=>new xt),e=new Array(12).fill().map(()=>new xt),i=new M,s=new M;return function(r,a=0,o=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(o||c)&&(r.getCenter(s),this.closestPointToPoint(s,i),r.closestPointToPoint(i,s),o&&o.copy(i),c&&c.copy(s)),0;const h=a*a,u=r.min,l=r.max,d=this.points;let y=1/0;for(let _=0;_<8;_++){const g=d[_];s.copy(g).clamp(u,l);const p=g.distanceToSquared(s);if(p<y&&(y=p,o&&o.copy(g),c&&c.copy(s),p<h))return Math.sqrt(p)}let m=0;for(let _=0;_<3;_++)for(let g=0;g<=1;g++)for(let p=0;p<=1;p++){const x=(_+1)%3,b=(_+2)%3,w=g<<x|p<<b,S=1<<_|g<<x|p<<b,z=d[w],A=d[S];t[m].set(z,A);const B=f[_],C=f[x],T=f[b],E=e[m],I=E.start,F=E.end;I[B]=u[B],I[C]=g?u[C]:l[C],I[T]=p?u[T]:l[C],F[B]=l[B],F[C]=g?u[C]:l[C],F[T]=p?u[T]:l[C],m++}for(let _=0;_<=1;_++)for(let g=0;g<=1;g++)for(let p=0;p<=1;p++){s.x=_?l.x:u.x,s.y=g?l.y:u.y,s.z=p?l.z:u.z,this.closestPointToPoint(s,i);const x=s.distanceToSquared(i);if(x<y&&(y=x,o&&o.copy(i),c&&c.copy(s),x<h))return Math.sqrt(x)}for(let _=0;_<12;_++){const g=t[_];for(let p=0;p<12;p++){const x=e[p];Ei(g,x,i,s);const b=i.distanceToSquared(s);if(b<y&&(y=b,o&&o.copy(i),c&&c.copy(s),b<h))return Math.sqrt(b)}}return Math.sqrt(y)}})();class Ii{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class mn extends Ii{constructor(){super(()=>new ct)}}const nt=new mn,we=new M,Fi=new M;function pn(f,t,e={},i=0,s=1/0){const n=i*i,r=s*s;let a=1/0,o=null;if(f.shapecast({boundsTraverseOrder:h=>(we.copy(t).clamp(h.min,h.max),we.distanceToSquared(t)),intersectsBounds:(h,u,l)=>l<a&&l<r,intersectsTriangle:(h,u)=>{h.closestPointToPoint(t,we);const l=t.distanceToSquared(we);return l<a&&(Fi.copy(we),a=l,o=u),l<n}}),a===1/0)return null;const c=Math.sqrt(a);return e.point?e.point.copy(Fi):e.point=Fi.clone(),e.distance=c,e.faceIndex=o,e}function q(f,t){return t[f+15]===xs}function H(f,t){return t[f+6]}function Q(f,t){return t[f+14]}function W(f){return f+L}function X(f,t){const e=t[f+6];return f+e*L}function Ri(f,t){return t[f+7]}function Fr(f){return f}const qe=parseInt(Wt)>=169,xn=parseInt(Wt)<=161,Dt=new M,Lt=new M,qt=new M,Oe=new Y,ve=new Y,We=new Y,bs=new M,_s=new M,Ms=new M,be=new M;function gn(f,t,e,i,s,n,r,a){let o;if(n===1?o=f.intersectTriangle(i,e,t,!0,s):o=f.intersectTriangle(t,e,i,n!==2,s),o===null)return null;const c=f.origin.distanceTo(s);return c<r||c>a?null:{distance:c,point:s.clone()}}function zs(f,t,e,i,s,n,r,a,o,c,h){Dt.fromBufferAttribute(t,n),Lt.fromBufferAttribute(t,r),qt.fromBufferAttribute(t,a);const u=gn(f,Dt,Lt,qt,be,o,c,h);if(u){if(i){Oe.fromBufferAttribute(i,n),ve.fromBufferAttribute(i,r),We.fromBufferAttribute(i,a),u.uv=new Y;const d=et.getInterpolation(be,Dt,Lt,qt,Oe,ve,We,u.uv);qe||(u.uv=d)}if(s){Oe.fromBufferAttribute(s,n),ve.fromBufferAttribute(s,r),We.fromBufferAttribute(s,a),u.uv1=new Y;const d=et.getInterpolation(be,Dt,Lt,qt,Oe,ve,We,u.uv1);qe||(u.uv1=d),xn&&(u.uv2=u.uv1)}if(e){bs.fromBufferAttribute(e,n),_s.fromBufferAttribute(e,r),Ms.fromBufferAttribute(e,a),u.normal=new M;const d=et.getInterpolation(be,Dt,Lt,qt,bs,_s,Ms,u.normal);u.normal.dot(f.direction)>0&&u.normal.multiplyScalar(-1),qe||(u.normal=d)}const l={a:n,b:r,c:a,normal:new M,materialIndex:0};if(et.getNormal(Dt,Lt,qt,l.normal),u.face=l,u.faceIndex=n,qe){const d=new M;et.getBarycoord(be,Dt,Lt,qt,d),u.barycoord=d}}return u}function As(f){return f&&f.isMaterial?f.side:f}function Xe(f,t,e,i,s,n,r){const a=i*3;let o=a+0,c=a+1,h=a+2;const{index:u,groups:l}=f;f.index&&(o=u.getX(o),c=u.getX(c),h=u.getX(h));const{position:d,normal:y,uv:m,uv1:_}=f.attributes;if(Array.isArray(t)){const g=i*3;for(let p=0,x=l.length;p<x;p++){const{start:b,count:w,materialIndex:S}=l[p];if(g>=b&&g<b+w){const z=As(t[S]),A=zs(e,d,y,m,_,o,c,h,z,n,r);if(A)if(A.faceIndex=i,A.face.materialIndex=S,s)s.push(A);else return A}}}else{const g=As(t),p=zs(e,d,y,m,_,o,c,h,g,n,r);if(p)if(p.faceIndex=i,p.face.materialIndex=0,s)s.push(p);else return p}return null}function D(f,t,e,i){const s=f.a,n=f.b,r=f.c;let a=t,o=t+1,c=t+2;e&&(a=e.getX(a),o=e.getX(o),c=e.getX(c)),s.x=i.getX(a),s.y=i.getY(a),s.z=i.getZ(a),n.x=i.getX(o),n.y=i.getY(o),n.z=i.getZ(o),r.x=i.getX(c),r.y=i.getY(c),r.z=i.getZ(c)}function wn(f,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:c}=f;for(let h=i,u=i+s;h<u;h++)Xe(o,t,e,h,n,r,a)}function bn(f,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=f;let c=1/0,h=null;for(let u=i,l=i+s;u<l;u++){let d;d=Xe(a,t,e,u,null,n,r),d&&d.distance<c&&(h=d,c=d.distance)}return h}function _n(f,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,c=a.attributes.position;for(let h=f,u=t+f;h<u;h++){let l;if(l=h,D(r,l*3,o,c),r.needsUpdate=!0,i(r,l,s,n))return!0}return!1}function Mn(f,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=f.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,c=0;const h=f._roots;for(let l=0,d=h.length;l<d;l++)n=h[l],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),u(0,c),c+=n.byteLength;function u(l,d,y=!1){const m=l*2;if(q(m,a)){const _=H(l,r),g=Q(m,a);let p=1/0,x=1/0,b=1/0,w=-1/0,S=-1/0,z=-1/0;for(let A=3*_,P=3*(_+g);A<P;A++){let B=i[A];const C=s.getX(B),T=s.getY(B),E=s.getZ(B);C<p&&(p=C),C>w&&(w=C),T<x&&(x=T),T>S&&(S=T),E<b&&(b=E),E>z&&(z=E)}return o[l+0]!==p||o[l+1]!==x||o[l+2]!==b||o[l+3]!==w||o[l+4]!==S||o[l+5]!==z?(o[l+0]=p,o[l+1]=x,o[l+2]=b,o[l+3]=w,o[l+4]=S,o[l+5]=z,!0):!1}else{const _=W(l),g=X(l,r);let p=y,x=!1,b=!1;if(t){if(!p){const B=_/L+d/$,C=g/L+d/$;x=t.has(B),b=t.has(C),p=!x&&!b}}else x=!0,b=!0;const w=p||x,S=p||b;let z=!1;w&&(z=u(_,d,p));let A=!1;S&&(A=u(g,d,p));const P=z||A;if(P)for(let B=0;B<3;B++){const C=_+B,T=g+B,E=o[C],I=o[C+3],F=o[T],U=o[T+3];o[l+B]=E<F?E:F,o[l+B+3]=I>U?I:U}return P}}}function Tt(f,t,e,i,s){let n,r,a,o,c,h;const u=1/e.direction.x,l=1/e.direction.y,d=1/e.direction.z,y=e.origin.x,m=e.origin.y,_=e.origin.z;let g=t[f],p=t[f+3],x=t[f+1],b=t[f+3+1],w=t[f+2],S=t[f+3+2];return u>=0?(n=(g-y)*u,r=(p-y)*u):(n=(p-y)*u,r=(g-y)*u),l>=0?(a=(x-m)*l,o=(b-m)*l):(a=(b-m)*l,o=(x-m)*l),n>o||a>r||((a>n||isNaN(n))&&(n=a),(o<r||isNaN(r))&&(r=o),d>=0?(c=(w-_)*d,h=(S-_)*d):(c=(S-_)*d,h=(w-_)*d),n>h||c>r)?!1:((c>n||n!==n)&&(n=c),(h<r||r!==r)&&(r=h),n<=s&&r>=i)}class zn{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const V=new zn;function An(f,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:c}=f;for(let h=i,u=i+s;h<u;h++){let l=c?c[h]:h;Xe(o,t,e,l,n,r,a)}}function Sn(f,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=f;let c=1/0,h=null;for(let u=i,l=i+s;u<l;u++){let d;d=Xe(a,t,e,o?o[u]:u,null,n,r),d&&d.distance<c&&(h=d,c=d.distance)}return h}function Bn(f,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,c=a.attributes.position;for(let h=f,u=t+f;h<u;h++){let l;if(l=e.resolveTriangleIndex(h),D(r,l*3,o,c),r.needsUpdate=!0,i(r,l,s,n))return!0}return!1}function Tn(f,t,e,i,s,n,r){V.setBuffer(f._roots[t]),Vi(0,f,e,i,s,n,r),V.clearBuffer()}function Vi(f,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:c}=V,h=f*2;if(q(h,o)){const l=H(f,c),d=Q(h,o);wn(t,e,i,l,d,s,n,r)}else{const l=W(f);Tt(l,a,i,n,r)&&Vi(l,t,e,i,s,n,r);const d=X(f,c);Tt(d,a,i,n,r)&&Vi(d,t,e,i,s,n,r)}}const Pn=["x","y","z"];function Cn(f,t,e,i,s,n){V.setBuffer(f._roots[t]);const r=Ui(0,f,e,i,s,n);return V.clearBuffer(),r}function Ui(f,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=V;let c=f*2;if(q(c,a)){const u=H(f,o),l=Q(c,a);return bn(t,e,i,u,l,s,n)}else{const u=Ri(f,o),l=Pn[u],y=i.direction[l]>=0;let m,_;y?(m=W(f),_=X(f,o)):(m=X(f,o),_=W(f));const p=Tt(m,r,i,s,n)?Ui(m,t,e,i,s,n):null;if(p){const w=p.point[l];if(y?w<=r[_+u]:w>=r[_+u+3])return p}const b=Tt(_,r,i,s,n)?Ui(_,t,e,i,s,n):null;return p&&b?p.distance<=b.distance?p:b:p||b||null}}function k(f,t,e){return e.min.x=t[f],e.min.y=t[f+1],e.min.z=t[f+2],e.max.x=t[f+3],e.max.y=t[f+4],e.max.z=t[f+5],e}function Ss(f){let t=-1,e=-1/0;for(let i=0;i<3;i++){const s=f[i+3]-f[i];s>e&&(e=s,t=i)}return t}function Bs(f,t){t.set(f)}function Ts(f,t,e){let i,s;for(let n=0;n<3;n++){const r=n+3;i=f[n],s=t[n],e[n]=i<s?i:s,i=f[r],s=t[r],e[r]=i>s?i:s}}function Ye(f,t,e){for(let i=0;i<3;i++){const s=t[f+2*i],n=t[f+2*i+1],r=s-n,a=s+n;r<e[i]&&(e[i]=r),a>e[i+3]&&(e[i+3]=a)}}function _e(f){const t=f[3]-f[0],e=f[4]-f[1],i=f[5]-f[2];return 2*(t*e+e*i+i*t)}function ki(f){return f.index?f.index.count:f.attributes.position.count}function Ze(f){return ki(f)/3}function En(f,t=ArrayBuffer){return f>65535?new Uint32Array(new t(4*f)):new Uint16Array(new t(2*f))}function In(f,t){if(!f.index){const e=f.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=En(e,i);f.setIndex(new lt(s,1));for(let n=0;n<e;n++)s[n]=n}}function Fn(f,t,e){const i=ki(f)/e,s=t||f.drawRange,n=s.start/e,r=(s.start+s.count)/e,a=Math.max(0,n),o=Math.min(i,r)-a;return{offset:Math.floor(a),count:Math.floor(o)}}function Rn(f,t){return f.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function Ps(f,t,e){const i=Fn(f,t,e),s=Rn(f,e);if(!s.length)return[i];const n=[],r=i.offset,a=i.offset+i.count,o=ki(f)/e,c=[];for(const l of s){const{offset:d,count:y}=l,m=d,_=isFinite(y)?y:o-d,g=d+_;m<a&&g>r&&(c.push({pos:Math.max(r,m),isStart:!0}),c.push({pos:Math.min(a,g),isStart:!1}))}c.sort((l,d)=>l.pos!==d.pos?l.pos-d.pos:l.type==="end"?-1:1);let h=0,u=null;for(const l of c){const d=l.pos;h!==0&&d!==u&&n.push({offset:u,count:d-u}),h+=l.isStart?1:-1,u=d}return n}const $e=new J,ie=new ct,se=new ct,Me=new O,Cs=new G,He=new G;function Vn(f,t,e,i){V.setBuffer(f._roots[t]);const s=Ni(0,f,e,i);return V.clearBuffer(),s}function Ni(f,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=V;let o=f*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),Cs.set(e.boundingBox.min,e.boundingBox.max,i),s=Cs),q(o,r)){const h=t.geometry,u=h.index,l=h.attributes.position,d=e.index,y=e.attributes.position,m=H(f,a),_=Q(o,r);if(Me.copy(i).invert(),e.boundsTree)return k(f,n,He),He.matrix.copy(Me),He.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:p=>He.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let x=m*3,b=(_+m)*3;x<b;x+=3)if(D(se,x,u,l),se.needsUpdate=!0,p.intersectsTriangle(se))return!0;return!1}});{const g=Ze(e);for(let p=m*3,x=(_+m)*3;p<x;p+=3){D(ie,p,u,l),ie.a.applyMatrix4(Me),ie.b.applyMatrix4(Me),ie.c.applyMatrix4(Me),ie.needsUpdate=!0;for(let b=0,w=g*3;b<w;b+=3)if(D(se,b,d,y),se.needsUpdate=!0,ie.intersectsTriangle(se))return!0}}}else{const h=W(f),u=X(f,a);return k(h,n,$e),!!(s.intersectsBox($e)&&Ni(h,t,e,i,s)||(k(u,n,$e),s.intersectsBox($e)&&Ni(u,t,e,i,s)))}}const Je=new O,Di=new G,ze=new G,Un=new M,kn=new M,Nn=new M,Dn=new M;function Ln(f,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),Di.set(t.boundingBox.min,t.boundingBox.max,e),Di.needsUpdate=!0;const a=f.geometry,o=a.attributes.position,c=a.index,h=t.attributes.position,u=t.index,l=nt.getPrimitive(),d=nt.getPrimitive();let y=Un,m=kn,_=null,g=null;s&&(_=Nn,g=Dn);let p=1/0,x=null,b=null;return Je.copy(e).invert(),ze.matrix.copy(Je),f.shapecast({boundsTraverseOrder:w=>Di.distanceToBox(w),intersectsBounds:(w,S,z)=>z<p&&z<r?(S&&(ze.min.copy(w.min),ze.max.copy(w.max),ze.needsUpdate=!0),!0):!1,intersectsRange:(w,S)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:A=>ze.distanceToBox(A),intersectsBounds:(A,P,B)=>B<p&&B<r,intersectsRange:(A,P)=>{for(let B=A,C=A+P;B<C;B++){D(d,3*B,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let T=w,E=w+S;T<E;T++){D(l,3*T,c,o),l.needsUpdate=!0;const I=l.distanceToTriangle(d,y,_);if(I<p&&(m.copy(y),g&&g.copy(_),p=I,x=T,b=B),I<n)return!0}}}});{const z=Ze(t);for(let A=0,P=z;A<P;A++){D(d,3*A,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let B=w,C=w+S;B<C;B++){D(l,3*B,c,o),l.needsUpdate=!0;const T=l.distanceToTriangle(d,y,_);if(T<p&&(m.copy(y),g&&g.copy(_),p=T,x=B,b=A),T<n)return!0}}}}}),nt.releasePrimitive(l),nt.releasePrimitive(d),p===1/0?null:(i.point?i.point.copy(m):i.point=m.clone(),i.distance=p,i.faceIndex=x,s&&(s.point?s.point.copy(g):s.point=g.clone(),s.point.applyMatrix4(Je),m.applyMatrix4(Je),s.distance=m.sub(s.point).length(),s.faceIndex=b),i)}function qn(f,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=f.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,c=0;const h=f._roots;for(let l=0,d=h.length;l<d;l++)n=h[l],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),u(0,c),c+=n.byteLength;function u(l,d,y=!1){const m=l*2;if(q(m,a)){const _=H(l,r),g=Q(m,a);let p=1/0,x=1/0,b=1/0,w=-1/0,S=-1/0,z=-1/0;for(let A=_,P=_+g;A<P;A++){const B=3*f.resolveTriangleIndex(A);for(let C=0;C<3;C++){let T=B+C;T=i?i[T]:T;const E=s.getX(T),I=s.getY(T),F=s.getZ(T);E<p&&(p=E),E>w&&(w=E),I<x&&(x=I),I>S&&(S=I),F<b&&(b=F),F>z&&(z=F)}}return o[l+0]!==p||o[l+1]!==x||o[l+2]!==b||o[l+3]!==w||o[l+4]!==S||o[l+5]!==z?(o[l+0]=p,o[l+1]=x,o[l+2]=b,o[l+3]=w,o[l+4]=S,o[l+5]=z,!0):!1}else{const _=W(l),g=X(l,r);let p=y,x=!1,b=!1;if(t){if(!p){const B=_/L+d/$,C=g/L+d/$;x=t.has(B),b=t.has(C),p=!x&&!b}}else x=!0,b=!0;const w=p||x,S=p||b;let z=!1;w&&(z=u(_,d,p));let A=!1;S&&(A=u(g,d,p));const P=z||A;if(P)for(let B=0;B<3;B++){const C=_+B,T=g+B,E=o[C],I=o[C+3],F=o[T],U=o[T+3];o[l+B]=E<F?E:F,o[l+B+3]=I>U?I:U}return P}}}function On(f,t,e,i,s,n,r){V.setBuffer(f._roots[t]),Li(0,f,e,i,s,n,r),V.clearBuffer()}function Li(f,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:c}=V,h=f*2;if(q(h,o)){const l=H(f,c),d=Q(h,o);An(t,e,i,l,d,s,n,r)}else{const l=W(f);Tt(l,a,i,n,r)&&Li(l,t,e,i,s,n,r);const d=X(f,c);Tt(d,a,i,n,r)&&Li(d,t,e,i,s,n,r)}}const vn=["x","y","z"];function Wn(f,t,e,i,s,n){V.setBuffer(f._roots[t]);const r=qi(0,f,e,i,s,n);return V.clearBuffer(),r}function qi(f,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=V;let c=f*2;if(q(c,a)){const u=H(f,o),l=Q(c,a);return Sn(t,e,i,u,l,s,n)}else{const u=Ri(f,o),l=vn[u],y=i.direction[l]>=0;let m,_;y?(m=W(f),_=X(f,o)):(m=X(f,o),_=W(f));const p=Tt(m,r,i,s,n)?qi(m,t,e,i,s,n):null;if(p){const w=p.point[l];if(y?w<=r[_+u]:w>=r[_+u+3])return p}const b=Tt(_,r,i,s,n)?qi(_,t,e,i,s,n):null;return p&&b?p.distance<=b.distance?p:b:p||b||null}}const Ge=new J,ne=new ct,re=new ct,Ae=new O,Es=new G,Qe=new G;function Xn(f,t,e,i){V.setBuffer(f._roots[t]);const s=Oi(0,f,e,i);return V.clearBuffer(),s}function Oi(f,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=V;let o=f*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),Es.set(e.boundingBox.min,e.boundingBox.max,i),s=Es),q(o,r)){const h=t.geometry,u=h.index,l=h.attributes.position,d=e.index,y=e.attributes.position,m=H(f,a),_=Q(o,r);if(Ae.copy(i).invert(),e.boundsTree)return k(f,n,Qe),Qe.matrix.copy(Ae),Qe.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:p=>Qe.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let x=m,b=_+m;x<b;x++)if(D(re,3*t.resolveTriangleIndex(x),u,l),re.needsUpdate=!0,p.intersectsTriangle(re))return!0;return!1}});{const g=Ze(e);for(let p=m,x=_+m;p<x;p++){const b=t.resolveTriangleIndex(p);D(ne,3*b,u,l),ne.a.applyMatrix4(Ae),ne.b.applyMatrix4(Ae),ne.c.applyMatrix4(Ae),ne.needsUpdate=!0;for(let w=0,S=g*3;w<S;w+=3)if(D(re,w,d,y),re.needsUpdate=!0,ne.intersectsTriangle(re))return!0}}}else{const h=W(f),u=X(f,a);return k(h,n,Ge),!!(s.intersectsBox(Ge)&&Oi(h,t,e,i,s)||(k(u,n,Ge),s.intersectsBox(Ge)&&Oi(u,t,e,i,s)))}}const je=new O,vi=new G,Se=new G,Yn=new M,Zn=new M,$n=new M,Hn=new M;function Jn(f,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),vi.set(t.boundingBox.min,t.boundingBox.max,e),vi.needsUpdate=!0;const a=f.geometry,o=a.attributes.position,c=a.index,h=t.attributes.position,u=t.index,l=nt.getPrimitive(),d=nt.getPrimitive();let y=Yn,m=Zn,_=null,g=null;s&&(_=$n,g=Hn);let p=1/0,x=null,b=null;return je.copy(e).invert(),Se.matrix.copy(je),f.shapecast({boundsTraverseOrder:w=>vi.distanceToBox(w),intersectsBounds:(w,S,z)=>z<p&&z<r?(S&&(Se.min.copy(w.min),Se.max.copy(w.max),Se.needsUpdate=!0),!0):!1,intersectsRange:(w,S)=>{if(t.boundsTree){const z=t.boundsTree;return z.shapecast({boundsTraverseOrder:A=>Se.distanceToBox(A),intersectsBounds:(A,P,B)=>B<p&&B<r,intersectsRange:(A,P)=>{for(let B=A,C=A+P;B<C;B++){const T=z.resolveTriangleIndex(B);D(d,3*T,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let E=w,I=w+S;E<I;E++){const F=f.resolveTriangleIndex(E);D(l,3*F,c,o),l.needsUpdate=!0;const U=l.distanceToTriangle(d,y,_);if(U<p&&(m.copy(y),g&&g.copy(_),p=U,x=E,b=B),U<n)return!0}}}})}else{const z=Ze(t);for(let A=0,P=z;A<P;A++){D(d,3*A,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let B=w,C=w+S;B<C;B++){const T=f.resolveTriangleIndex(B);D(l,3*T,c,o),l.needsUpdate=!0;const E=l.distanceToTriangle(d,y,_);if(E<p&&(m.copy(y),g&&g.copy(_),p=E,x=B,b=A),E<n)return!0}}}}}),nt.releasePrimitive(l),nt.releasePrimitive(d),p===1/0?null:(i.point?i.point.copy(m):i.point=m.clone(),i.distance=p,i.faceIndex=x,s&&(s.point?s.point.copy(g):s.point=g.clone(),s.point.applyMatrix4(je),m.applyMatrix4(je),s.distance=m.sub(s.point).length(),s.faceIndex=b),i)}function Is(f,t,e){return f===null?null:(f.point.applyMatrix4(t.matrixWorld),f.distance=f.point.distanceTo(e.ray.origin),f.object=t,f)}function Gn(){return typeof SharedArrayBuffer<"u"}function Wi(f,t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,c=-1/0,h=-1/0,u=1/0,l=1/0,d=1/0,y=-1/0,m=-1/0,_=-1/0;const g=f.offset||0;for(let p=(t-g)*6,x=(t+e-g)*6;p<x;p+=6){const b=f[p+0],w=f[p+1],S=b-w,z=b+w;S<n&&(n=S),z>o&&(o=z),b<u&&(u=b),b>y&&(y=b);const A=f[p+2],P=f[p+3],B=A-P,C=A+P;B<r&&(r=B),C>c&&(c=C),A<l&&(l=A),A>m&&(m=A);const T=f[p+4],E=f[p+5],I=T-E,F=T+E;I<a&&(a=I),F>h&&(h=F),T<d&&(d=T),T>_&&(_=T)}i[0]=n,i[1]=r,i[2]=a,i[3]=o,i[4]=c,i[5]=h,s[0]=u,s[1]=l,s[2]=d,s[3]=y,s[4]=m,s[5]=_}const bt=32,Qn=(f,t)=>f.candidate-t.candidate,Pt=new Array(bt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ke=new Float32Array(6);function jn(f,t,e,i,s,n){let r=-1,a=0;if(n===ys)r=Ss(t),r!==-1&&(a=(t[r]+t[r+3])/2);else if(n===ln)r=Ss(f),r!==-1&&(a=Kn(e,i,s,r));else if(n===un){const o=_e(f);let c=Pi*s;const h=e.offset||0,u=(i-h)*6,l=(i+s-h)*6;for(let d=0;d<3;d++){const y=t[d],g=(t[d+3]-y)/bt;if(s<bt/4){const p=[...Pt];p.length=s;let x=0;for(let w=u;w<l;w+=6,x++){const S=p[x];S.candidate=e[w+2*d],S.count=0;const{bounds:z,leftCacheBounds:A,rightCacheBounds:P}=S;for(let B=0;B<3;B++)P[B]=1/0,P[B+3]=-1/0,A[B]=1/0,A[B+3]=-1/0,z[B]=1/0,z[B+3]=-1/0;Ye(w,e,z)}p.sort(Qn);let b=s;for(let w=0;w<b;w++){const S=p[w];for(;w+1<b&&p[w+1].candidate===S.candidate;)p.splice(w+1,1),b--}for(let w=u;w<l;w+=6){const S=e[w+2*d];for(let z=0;z<b;z++){const A=p[z];S>=A.candidate?Ye(w,e,A.rightCacheBounds):(Ye(w,e,A.leftCacheBounds),A.count++)}}for(let w=0;w<b;w++){const S=p[w],z=S.count,A=s-S.count,P=S.leftCacheBounds,B=S.rightCacheBounds;let C=0;z!==0&&(C=_e(P)/o);let T=0;A!==0&&(T=_e(B)/o);const E=ps+Pi*(C*z+T*A);E<c&&(r=d,c=E,a=S.candidate)}}else{for(let b=0;b<bt;b++){const w=Pt[b];w.count=0,w.candidate=y+g+b*g;const S=w.bounds;for(let z=0;z<3;z++)S[z]=1/0,S[z+3]=-1/0}for(let b=u;b<l;b+=6){let z=~~((e[b+2*d]-y)/g);z>=bt&&(z=bt-1);const A=Pt[z];A.count++,Ye(b,e,A.bounds)}const p=Pt[bt-1];Bs(p.bounds,p.rightCacheBounds);for(let b=bt-2;b>=0;b--){const w=Pt[b],S=Pt[b+1];Ts(w.bounds,S.rightCacheBounds,w.rightCacheBounds)}let x=0;for(let b=0;b<bt-1;b++){const w=Pt[b],S=w.count,z=w.bounds,P=Pt[b+1].rightCacheBounds;S!==0&&(x===0?Bs(z,Ke):Ts(z,Ke,Ke)),x+=S;let B=0,C=0;x!==0&&(B=_e(Ke)/o);const T=s-x;T!==0&&(C=_e(P)/o);const E=ps+Pi*(B*x+C*T);E<c&&(r=d,c=E,a=w.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${n} used.`);return{axis:r,pos:a}}function Kn(f,t,e,i){let s=0;const n=f.offset;for(let r=t,a=t+e;r<a;r++)s+=f[(r-n)*6+i*2];return s/e}class Xi{constructor(){this.boundingData=new Float32Array(6)}}function tr(f,t,e,i,s,n){let r=i,a=i+s-1;const o=n.pos,c=n.axis*2,h=e.offset||0;for(;;){for(;r<=a&&e[(r-h)*6+c]<o;)r++;for(;r<=a&&e[(a-h)*6+c]>=o;)a--;if(r<a){for(let u=0;u<t;u++){let l=f[r*t+u];f[r*t+u]=f[a*t+u],f[a*t+u]=l}for(let u=0;u<6;u++){const l=r-h,d=a-h,y=e[l*6+u];e[l*6+u]=e[d*6+u],e[d*6+u]=y}r++,a--}else return r}}let Fs,ti,Yi,Rs;const er=Math.pow(2,32);function Zi(f){return"count"in f?1:1+Zi(f.left)+Zi(f.right)}function ir(f,t,e){return Fs=new Float32Array(e),ti=new Uint32Array(e),Yi=new Uint16Array(e),Rs=new Uint8Array(e),$i(f,t)}function $i(f,t){const e=f/4,i=f/2,s="count"in t,n=t.boundingData;for(let r=0;r<6;r++)Fs[e+r]=n[r];if(s)return t.buffer?(Rs.set(new Uint8Array(t.buffer),f),f+t.buffer.byteLength):(ti[e+6]=t.offset,Yi[i+14]=t.count,Yi[i+15]=xs,f+$);{const{left:r,right:a,splitAxis:o}=t,c=f+$;let h=$i(c,r);const u=f/$,d=h/$-u;if(d>er)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return ti[e+6]=d,ti[e+7]=o,$i(h,a)}}function sr(f,t,e,i,s){const{maxDepth:n,verbose:r,maxLeafSize:a,strategy:o,onProgress:c}=s,h=f.primitiveBuffer,u=f.primitiveBufferStride,l=new Float32Array(6);let d=!1;const y=new Xi;return Wi(t,e,i,y.boundingData,l),_(y,e,i,l),y;function m(g){c&&c(g/i)}function _(g,p,x,b=null,w=0){if(!d&&w>=n&&(d=!0,r&&console.warn(`BVH: Max depth of ${n} reached when generating BVH. Consider increasing maxDepth.`)),x<=a||w>=n)return m(p+x),g.offset=p,g.count=x,g;const S=jn(g.boundingData,b,t,p,x,o);if(S.axis===-1)return m(p+x),g.offset=p,g.count=x,g;const z=tr(h,u,t,p,x,S);if(z===p||z===p+x)m(p+x),g.offset=p,g.count=x;else{g.splitAxis=S.axis;const A=new Xi,P=p,B=z-p;g.left=A,Wi(t,P,B,A.boundingData,l),_(A,P,B,l,w+1);const C=new Xi,T=z,E=x-B;g.right=C,Wi(t,T,E,C.boundingData,l),_(C,T,E,l,w+1)}return g}}function nr(f,t){const e=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=f.getRootRanges(t.range),s=i[0],n=i[i.length-1],r={offset:s.offset,count:n.offset+n.count-s.offset},a=new Float32Array(6*r.count);a.offset=r.offset,f.computePrimitiveBounds(r.offset,r.count,a),f._roots=i.map(o=>{const c=sr(f,a,o.offset,o.count,t),h=Zi(c),u=new e($*h);return ir(0,c,u),u})}let Ct,oe;const ae=[],ei=new Ii(()=>new J);function rr(f,t,e,i,s,n){Ct=ei.getPrimitive(),oe=ei.getPrimitive(),ae.push(Ct,oe),V.setBuffer(f._roots[t]);const r=Hi(0,f.geometry,e,i,s,n);V.clearBuffer(),ei.releasePrimitive(Ct),ei.releasePrimitive(oe),ae.pop(),ae.pop();const a=ae.length;return a>0&&(oe=ae[a-1],Ct=ae[a-2]),r}function Hi(f,t,e,i,s=null,n=0,r=0){const{float32Array:a,uint16Array:o,uint32Array:c}=V;let h=f*2;if(q(h,o)){const l=H(f,c),d=Q(h,o);return k(f,a,Ct),i(l,d,!1,r,n+f/L,Ct)}else{let B=function(T){const{uint16Array:E,uint32Array:I}=V;let F=T*2;for(;!q(F,E);)T=W(T),F=T*2;return H(T,I)},C=function(T){const{uint16Array:E,uint32Array:I}=V;let F=T*2;for(;!q(F,E);)T=X(T,I),F=T*2;return H(T,I)+Q(F,E)};const l=W(f),d=X(f,c);let y=l,m=d,_,g,p,x;if(s&&(p=Ct,x=oe,k(y,a,p),k(m,a,x),_=s(p),g=s(x),g<_)){y=d,m=l;const T=_;_=g,g=T,p=x}p||(p=Ct,k(y,a,p));const b=q(y*2,o),w=e(p,b,_,r+1,n+y/L);let S;if(w===ms){const T=B(y),I=C(y)-T;S=i(T,I,!0,r+1,n+y/L,p)}else S=w&&Hi(y,t,e,i,s,n,r+1);if(S)return!0;x=oe,k(m,a,x);const z=q(m*2,o),A=e(x,z,g,r+1,n+m/L);let P;if(A===ms){const T=B(m),I=C(m)-T;P=i(T,I,!0,r+1,n+m/L,x)}else P=A&&Hi(m,t,e,i,s,n,r+1);return!!P}}const Be=new V.constructor,ii=new V.constructor,Et=new Ii(()=>new J),ce=new J,he=new J,Ji=new J,Gi=new J;let Qi=!1;function or(f,t,e,i){if(Qi)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Qi=!0;const s=f._roots,n=t._roots;let r,a=0,o=0;const c=new O().copy(e).invert();for(let h=0,u=s.length;h<u;h++){Be.setBuffer(s[h]),o=0;const l=Et.getPrimitive();k(0,Be.float32Array,l),l.applyMatrix4(c);for(let d=0,y=n.length;d<y&&(ii.setBuffer(n[d]),r=ht(0,0,e,c,i,a,o,0,0,l),ii.clearBuffer(),o+=n[d].byteLength/$,!r);d++);if(Et.releasePrimitive(l),Be.clearBuffer(),a+=s[h].byteLength/$,r)break}return Qi=!1,r}function ht(f,t,e,i,s,n=0,r=0,a=0,o=0,c=null,h=!1){let u,l;h?(u=ii,l=Be):(u=Be,l=ii);const d=u.float32Array,y=u.uint32Array,m=u.uint16Array,_=l.float32Array,g=l.uint32Array,p=l.uint16Array,x=f*2,b=t*2,w=q(x,m),S=q(b,p);let z=!1;if(S&&w)h?z=s(H(t,g),Q(t*2,p),H(f,y),Q(f*2,m),o,r+t/L,a,n+f/L):z=s(H(f,y),Q(f*2,m),H(t,g),Q(t*2,p),a,n+f/L,o,r+t/L);else if(S){const A=Et.getPrimitive();k(t,_,A),A.applyMatrix4(e);const P=W(f),B=X(f,y);k(P,d,ce),k(B,d,he);const C=A.intersectsBox(ce),T=A.intersectsBox(he);z=C&&ht(t,P,i,e,s,r,n,o,a+1,A,!h)||T&&ht(t,B,i,e,s,r,n,o,a+1,A,!h),Et.releasePrimitive(A)}else{const A=W(t),P=X(t,g);k(A,_,Ji),k(P,_,Gi);const B=c.intersectsBox(Ji),C=c.intersectsBox(Gi);if(B&&C)z=ht(f,A,e,i,s,n,r,a,o+1,c,h)||ht(f,P,e,i,s,n,r,a,o+1,c,h);else if(B)if(w)z=ht(f,A,e,i,s,n,r,a,o+1,c,h);else{const T=Et.getPrimitive();T.copy(Ji).applyMatrix4(e);const E=W(f),I=X(f,y);k(E,d,ce),k(I,d,he);const F=T.intersectsBox(ce),U=T.intersectsBox(he);z=F&&ht(A,E,i,e,s,r,n,o,a+1,T,!h)||U&&ht(A,I,i,e,s,r,n,o,a+1,T,!h),Et.releasePrimitive(T)}else if(C)if(w)z=ht(f,P,e,i,s,n,r,a,o+1,c,h);else{const T=Et.getPrimitive();T.copy(Gi).applyMatrix4(e);const E=W(f),I=X(f,y);k(E,d,ce),k(I,d,he);const F=T.intersectsBox(ce),U=T.intersectsBox(he);z=F&&ht(P,E,i,e,s,r,n,o,a+1,T,!h)||U&&ht(P,I,i,e,s,r,n,o,a+1,T,!h),Et.releasePrimitive(T)}}return z}const Vs=new J,le=new Float32Array(6);class ar{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(t){t={...gs,...t},nr(this,t)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,c=-1/0,h=-1/0;for(let u=t,l=t+e;u<l;u++){this.writePrimitiveBounds(u,le,0);const[d,y,m,_,g,p]=le;d<n&&(n=d),_>o&&(o=_),y<r&&(r=y),g>c&&(c=g),m<a&&(a=m),p>h&&(h=p)}return i[s+0]=n,i[s+1]=r,i[s+2]=a,i[s+3]=o,i[s+4]=c,i[s+5]=h,i}computePrimitiveBounds(t,e,i){const s=i.offset||0;for(let n=t,r=t+e;n<r;n++){this.writePrimitiveBounds(n,le,0);const[a,o,c,h,u,l]=le,d=(a+h)/2,y=(o+u)/2,m=(c+l)/2,_=(h-a)/2,g=(u-o)/2,p=(l-c)/2,x=(n-s)*6;i[x+0]=d,i[x+1]=_+(Math.abs(d)+_)*Le,i[x+2]=y,i[x+3]=g+(Math.abs(y)+g)*Le,i[x+4]=m,i[x+5]=p+(Math.abs(m)+p)*Le}return i}shiftPrimitiveOffsets(t){const e=this._indirectBuffer;if(e)for(let i=0,s=e.length;i<s;i++)e[i]+=t;else{const i=this._roots;for(let s=0;s<i.length;s++){const n=i[s],r=new Uint32Array(n),a=new Uint16Array(n),o=n.byteLength/$;for(let c=0;c<o;c++){const h=L*c,u=2*h;q(u,a)&&(r[h+6]+=t)}}}}traverse(t,e=0){const i=this._roots[e],s=new Uint32Array(i),n=new Uint16Array(i);r(0);function r(a,o=0){const c=a*2,h=q(c,n);if(h){const u=s[a+6],l=n[c+14];t(o,h,new Float32Array(i,a*4,6),u,l)}else{const u=W(a),l=X(a,s),d=Ri(a,s);t(o,h,new Float32Array(i,a*4,6),d)||(r(u,o+1),r(l,o+1))}}}refit(){const t=this._roots;for(let e=0,i=t.length;e<i;e++){const s=t[e],n=new Uint32Array(s),r=new Uint16Array(s),a=new Float32Array(s),o=s.byteLength/$;for(let c=o-1;c>=0;c--){const h=c*L,u=h*2;if(q(u,r)){const d=H(h,n),y=Q(u,r);this.writePrimitiveRangeBounds(d,y,le,0),a.set(le,h)}else{const d=W(h),y=X(h,n);for(let m=0;m<3;m++){const _=a[d+m],g=a[d+m+3],p=a[y+m],x=a[y+m+3];a[h+m]=_<p?_:p,a[h+m+3]=g>x?g:x}}}}}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(i=>{k(0,new Float32Array(i),Vs),t.union(Vs)}),t}shapecast(t){let{boundsTraverseOrder:e,intersectsBounds:i,intersectsRange:s,intersectsPrimitive:n,scratchPrimitive:r,iterate:a}=t;if(s&&n){const u=s;s=(l,d,y,m,_)=>u(l,d,y,m,_)?!0:a(l,d,this,n,y,m,r)}else s||(n?s=(u,l,d,y)=>a(u,l,this,n,d,y,r):s=(u,l,d)=>d);let o=!1,c=0;const h=this._roots;for(let u=0,l=h.length;u<l;u++){const d=h[u];if(o=rr(this,u,i,s,e,c),o)break;c+=d.byteLength/$}return o}bvhcast(t,e,i){let{intersectsRanges:s}=i;return or(this,t,e,s)}}function cr(f,t){const e=f[f.length-1],i=e.offset+e.count>2**16,s=f.reduce((c,h)=>c+h.count,0),n=i?4:2,r=t?new SharedArrayBuffer(s*n):new ArrayBuffer(s*n),a=i?new Uint32Array(r):new Uint16Array(r);let o=0;for(let c=0;c<f.length;c++){const{offset:h,count:u}=f[c];for(let l=0;l<u;l++)a[o+l]=h+l;o+=u}return a}class hr extends ar{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(t){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(t){}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("BVH: Only BufferGeometries are supported.");if(e.useSharedArrayBuffer&&!Gn())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=t,this.resolvePrimitiveIndex=e.indirect?i=>this._indirectBuffer[i]:i=>i,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,e={...gs,...e},e[Ci]||this.init(e)}init(t){const{geometry:e,primitiveStride:i}=this;if(t.indirect){const s=Ps(e,t.range,i),n=cr(s,t.useSharedArrayBuffer);this._indirectBuffer=n}else In(e,t);super.init(t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new J))}getRootRanges(t){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Ps(this.geometry,t,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}const si=new G,ni=new rn,Us=new M,ks=new O,Ns=new M,ji=["getX","getY","getZ"];class Te extends hr{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,s=t._roots,n=t._indirectBuffer,r=i.getIndex(),a={version:1,roots:null,index:null,indirectBuffer:null};return e.cloneBuffers?(a.roots=s.map(o=>o.slice()),a.index=r?r.array.slice():null,a.indirectBuffer=n?n.slice():null):(a.roots=s,a.index=r?r.array:null,a.indirectBuffer=n),a}static deserialize(t,e,i={}){i={setIndex:!0,indirect:!!t.indirectBuffer,...i};const{index:s,roots:n,indirectBuffer:r}=t;t.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),o(n));const a=new Te(e,{...i,[Ci]:!0});if(a._roots=n,a._indirectBuffer=r||null,i.setIndex){const c=e.getIndex();if(c===null){const h=new lt(t.index,1,!1);e.setIndex(h)}else c.array!==s&&(c.array.set(s),c.needsUpdate=!0)}return a;function o(c){for(let h=0;h<c.length;h++){const u=c[h],l=new Uint32Array(u),d=new Uint16Array(u);for(let y=0,m=u.byteLength/$;y<m;y++){const _=L*y,g=2*_;q(g,d)||(l[_+6]=l[_+6]/L-y)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(t,e={}){e.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use maxLeafSize, instead.'),e={...e,maxLeafSize:e.maxLeafTris}),super(t,e)}shiftTriangleOffsets(t){return super.shiftPrimitiveOffsets(t)}writePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,c=(n?n[t]:t)*3;let h=c+0,u=c+1,l=c+2;a&&(h=a[h],u=a[u],l=a[l]);for(let d=0;d<3;d++){const y=r[ji[d]](h),m=r[ji[d]](u),_=r[ji[d]](l);let g=y;m<g&&(g=m),_<g&&(g=_);let p=y;m>p&&(p=m),_>p&&(p=_),e[i+d]=g,e[i+d+3]=p}return e}computePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,o=r.normalized;if(t<0||e+t-i.offset>i.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const c=r.array,h=r.offset||0;let u=3;r.isInterleavedBufferAttribute&&(u=r.data.stride);const l=["getX","getY","getZ"],d=i.offset;for(let y=t,m=t+e;y<m;y++){const g=(n?n[y]:y)*3,p=(y-d)*6;let x=g+0,b=g+1,w=g+2;a&&(x=a[x],b=a[b],w=a[w]),o||(x=x*u+h,b=b*u+h,w=w*u+h);for(let S=0;S<3;S++){let z,A,P;o?(z=r[l[S]](x),A=r[l[S]](b),P=r[l[S]](w)):(z=c[x+S],A=c[b+S],P=c[w+S]);let B=z;A<B&&(B=A),P<B&&(B=P);let C=z;A>C&&(C=A),P>C&&(C=P);const T=(C-B)/2,E=S*2;i[p+E+0]=B+T,i[p+E+1]=T+(Math.abs(B)+T)*Le}}return i}raycastObject3D(t,e,i=[]){const{material:s}=t;if(s===void 0)return;ks.copy(t.matrixWorld).invert(),ni.copy(e.ray).applyMatrix4(ks),Ns.setFromMatrixScale(t.matrixWorld),Us.copy(ni.direction).multiply(Ns);const n=Us.length(),r=e.near/n,a=e.far/n;if(e.firstHitOnly===!0){let o=this.raycastFirst(ni,s,r,a);o=Is(o,t,e),o&&i.push(o)}else{const o=this.raycast(ni,s,r,a);for(let c=0,h=o.length;c<h;c++){const u=Is(o[c],t,e);u&&i.push(u)}}return i}refit(t=null){return(this.indirect?qn:Mn)(this,t)}raycast(t,e=0,i=0,s=1/0){const n=this._roots,r=[],a=this.indirect?On:Tn;for(let o=0,c=n.length;o<c;o++)a(this,o,e,t,r,i,s);return r}raycastFirst(t,e=0,i=0,s=1/0){const n=this._roots;let r=null;const a=this.indirect?Wn:Cn;for(let o=0,c=n.length;o<c;o++){const h=a(this,o,e,t,i,s);h!=null&&(r==null||h.distance<r.distance)&&(r=h)}return r}intersectsGeometry(t,e){let i=!1;const s=this._roots,n=this.indirect?Xn:Vn;for(let r=0,a=s.length;r<a&&(i=n(this,r,t,e),!i);r++);return i}shapecast(t){const e=nt.getPrimitive(),i=super.shapecast({...t,intersectsPrimitive:t.intersectsTriangle,scratchPrimitive:e,iterate:this.indirect?Bn:_n});return nt.releasePrimitive(e),i}bvhcast(t,e,i){let{intersectsRanges:s,intersectsTriangles:n}=i;const r=nt.getPrimitive(),a=this.geometry.index,o=this.geometry.attributes.position,c=this.indirect?y=>{const m=this.resolveTriangleIndex(y);D(r,m*3,a,o)}:y=>{D(r,y*3,a,o)},h=nt.getPrimitive(),u=t.geometry.index,l=t.geometry.attributes.position,d=t.indirect?y=>{const m=t.resolveTriangleIndex(y);D(h,m*3,u,l)}:y=>{D(h,y*3,u,l)};if(n){if(!(t instanceof Te))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const y=(m,_,g,p,x,b,w,S)=>{for(let z=g,A=g+p;z<A;z++){d(z),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let P=m,B=m+_;P<B;P++)if(c(P),r.needsUpdate=!0,n(r,h,P,z,x,b,w,S))return!0}return!1};if(s){const m=s;s=function(_,g,p,x,b,w,S,z){return m(_,g,p,x,b,w,S,z)?!0:y(_,g,p,x,b,w,S,z)}}else s=y}return super.bvhcast(t,e,{intersectsRanges:s})}intersectsBox(t,e){return si.set(t.min,t.max,e),si.needsUpdate=!0,this.shapecast({intersectsBounds:i=>si.intersectsBox(i),intersectsTriangle:i=>si.intersectsTriangle(i)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},s={},n=0,r=1/0){return(this.indirect?Jn:Ln)(this,t,e,i,s,n,r)}closestPointToPoint(t,e={},i=0,s=1/0){return pn(this,t,e,i,s)}}self.onmessage=({data:f})=>{let t=performance.now();function e(r){r=Math.min(r,1);const a=performance.now();a-t>=10&&r!==1&&(self.postMessage({error:null,serialized:null,position:null,progress:r}),t=a)}const{index:i,position:s,options:n}=f;try{const r=new Mi;if(r.setAttribute("position",new lt(s,3,!1)),i&&r.setIndex(new lt(i,1,!1)),n.includedProgressCallback&&(n.onProgress=e),n.groups){const h=n.groups;for(const u in h){const l=h[u];r.addGroup(l.start,l.count,l.materialIndex)}}const a=new Te(r,n),o=Te.serialize(a,{copyIndexBuffer:!1});let c=[s.buffer,...o.roots];o.index&&c.push(o.index.buffer),c=c.filter(h=>typeof SharedArrayBuffer>"u"||!(h instanceof SharedArrayBuffer)),a._indirectBuffer&&c.push(o.indirectBuffer.buffer),self.postMessage({error:null,serialized:o,position:s,progress:1},c)}catch(r){self.postMessage({error:r,serialized:null,position:null,progress:1})}}})();
@@ -0,0 +1,10 @@
1
+ import{RedFormat as Fe,RedIntegerFormat as Ne,RGFormat as Ue,RGIntegerFormat as We,RGBFormat as ze,RGBAFormat as qe,RGBAIntegerFormat as Ve,BufferGeometry as U,Mesh as W,Box3 as ae,Vector3 as A,Sphere as Me,CompressedTexture as Xe,Texture as $,Matrix3 as He,InterleavedBuffer as Ke,InterleavedBufferAttribute as Ye,BufferAttribute as Qe,TextureLoader as Je,Matrix4 as De,Timer as Ze,MeshStandardMaterial as et}from"./three.min.js";import{DRACOLoader as tt,KTX2Loader as rt,MeshoptDecoder as st,GLTFLoader as le}from"./three-examples.min.js";const ot="";globalThis.GLTF_PROGRESSIVE_VERSION=ot,console.debug("[gltf-progressive] version -");let k="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",z="https://cdn.needle.tools/static/three/0.179.1/basis2/";const nt=k,it=z,Oe=new URL(k+"draco_decoder.js");Oe.searchParams.append("range","true"),fetch(Oe,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(i=>{console.debug(`Failed to fetch remote Draco decoder from ${k} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),k===nt&&Se("./include/draco/"),z===it&&Te("./include/ktx2/")}).finally(()=>{Pe()});const at=()=>({dracoDecoderPath:k,ktx2TranscoderPath:z});function Se(i){k=i,T&&T[ce]!=k?(console.debug("Updating Draco decoder path to "+i),T[ce]=k,T.setDecoderPath(k),T.preload()):console.debug("Setting Draco decoder path to "+i)}function Te(i){z=i,R&&R.transcoderPath!=z?(console.debug("Updating KTX2 transcoder path to "+i),R.setTranscoderPath(z),R.init()):console.debug("Setting KTX2 transcoder path to "+i)}function te(i){return Pe(),i?R.detectSupport(i):i!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:T,ktx2Loader:R,meshoptDecoder:re}}function ue(i){i.dracoLoader||i.setDRACOLoader(T),i.ktx2Loader||i.setKTX2Loader(R),i.meshoptDecoder||i.setMeshoptDecoder(re)}const ce=Symbol("dracoDecoderPath");let T,re,R;function Pe(){T||(T=new tt,T[ce]=k,T.setDecoderPath(k),T.setDecoderConfig({type:"js"}),T.preload()),R||(R=new rt,R.setTranscoderPath(z),R.init()),re||(re=st)}const de=new WeakMap;function he(i,t){let e=de.get(i);e?e=Object.assign(e,t):e=t,de.set(i,e)}const lt=le.prototype.load;function ut(...i){const t=de.get(this);let e=i[0];const r=new URL(e,window.location.href);if(r.hostname.endsWith("needle.tools")){const s=t?.progressive!==void 0?t.progressive:!0,o=t?.usecase?t.usecase:"default";s?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${o}`:this.requestHeader.Accept=`*/*;usecase=${o}`,e=r.toString()}return i[0]=e,lt?.call(this,...i)}le.prototype.load=ut;function Ce(i){return i!=null&&i.data!=null}function ge(i){const t=i.source?.data;return t!=null&&typeof t=="object"?t:null}function ct(i){const t=i.image;return t!=null&&typeof t=="object"?t:null}function fe(i){const t=ct(i),e=ge(i);return{width:t?.width||e?.width||0,height:t?.height||e?.height||0}}j("debugprogressive");function j(i){if(typeof window>"u")return!1;const t=new URL(window.location.href).searchParams.get(i);return t==null||t==="0"||t==="false"?!1:t===""?!0:t}function dt(i,t){if(t===void 0||i===void 0||t.startsWith("./")||t.startsWith("http")||t.startsWith("data:")||t.startsWith("blob:"))return t;const e=i.lastIndexOf("/");if(e>=0){const r=i.substring(0,e+1);for(;r.endsWith("/")&&t.startsWith("/");)t=t.substring(1);return r+t}return t}function me(){return se!==void 0||(se=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),j("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",se)),se}let se;function Ae(){if(typeof window>"u")return!1;const i=new URL(window.location.href),t=i.hostname==="localhost"||/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(i.hostname);return i.hostname==="127.0.0.1"||t}class ht{constructor(t,e={}){this.maxConcurrent=t,this.debug=e.debug??!1,window.requestAnimationFrame(this.tick)}_running=new Map;_queue=[];debug=!1;tick=()=>{this.internalUpdate(),setTimeout(this.tick,10)};slot(t){return this.debug&&console.debug(`[PromiseQueue]: Requesting slot for key ${t}, running: ${this._running.size}, waiting: ${this._queue.length}`),new Promise(e=>{this._queue.push({key:t,resolve:e})})}add(t,e){this._running.has(t)||(this._running.set(t,e),e.finally(()=>{this._running.delete(t),this.debug&&console.debug(`[PromiseQueue]: Promise finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${t})`)}),this.debug&&console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${t})`))}internalUpdate(){const t=this.maxConcurrent-this._running.size;for(let e=0;e<t&&this._queue.length>0;e++){this.debug&&console.debug(`[PromiseQueue]: Running ${this._running.size} promises, waiting for ${this._queue.length} more.`);const{key:r,resolve:s}=this._queue.shift();s({use:o=>this.add(r,o)})}}}function gt(i){const t=i.image,e=t?.width??0,r=t?.height??0,s=t?.depth??1,o=Math.floor(Math.log2(Math.max(e,r,s)))+1,n=ft(i);return e*r*s*n*(1-Math.pow(.25,o))/(1-.25)}function ft(i){let t=4;const e=i.format;e===Fe||e===Ne?t=1:e===Ue||e===We?t=2:e===ze||e===1029?t=3:(e===qe||e===Ve)&&(t=4);let r=1;const s=i.type;return s===1009||s===1010?r=1:s===1011||s===1012?r=2:s===1013||s===1014||s===1015?r=4:s===1016&&(r=2),t*r}const mt=typeof window>"u"&&typeof document>"u",pe=Symbol("needle:raycast-mesh");function V(i){return i?.[pe]instanceof U?i[pe]:null}function pt(i,t){if((i.type==="Mesh"||i.type==="SkinnedMesh")&&!V(i)){const e=yt(t);e.userData={isRaycastMesh:!0},i[pe]=e}}function xt(i=!0){if(i){if(H)return;const t=H=W.prototype.raycast;W.prototype.raycast=function(e,r){const s=this,o=V(s);let n;o&&s.isMesh&&(n=s.geometry,s.geometry=o),t.call(this,e,r),n&&(s.geometry=n)}}else{if(!H)return;W.prototype.raycast=H,H=null}}let H=null;function yt(i){const t=new U;for(const e in i.attributes)t.setAttribute(e,i.getAttribute(e));return t.setIndex(i.getIndex()),t}const F=new Array,h=j("debugprogressive");let K,q=-1;if(h){let i=function(){q+=1,q>=t&&(q=-1),console.log(`Toggle LOD level [${q}]`)},t=6;window.addEventListener("keyup",e=>{e.key==="p"&&i(),e.key==="w"&&(K=!K,console.log(`Toggle wireframe [${K}]`));const r=parseInt(e.key);!isNaN(r)&&r>=0&&(q=r,console.log(`Set LOD level to [${q}]`))})}function ke(i){if(h&&K!==void 0)if(Array.isArray(i))for(const t of i)ke(t);else i&&"wireframe"in i&&(i.wireframe=K===!0)}const Y=new Array;let wt=0;const vt=me()?2:10;function Lt(i){if(Y.length<vt){const e=Y.length;h&&console.warn(`[Worker] Creating new worker #${e}`);const r=be.createWorker(i||{});return Y.push(r),r}const t=wt++%Y.length;return Y[t]}class be{constructor(t,e){this.worker=t,this._debug=e.debug??!1,t.onmessage=r=>{const s=r.data;switch(this._debug&&console.log("[Worker] EVENT",s),s.type){case"loaded-gltf":for(const o of this._running)if(o.url===s.result.url){_t(s.result),o.resolve(s.result);const n=o.url;n.startsWith("blob:")&&URL.revokeObjectURL(n)}}},t.onerror=r=>{console.error("[Worker] Error in gltf-progressive worker:",r)},t.postMessage({type:"init"})}static async createWorker(t){const e=new Worker(URL.createObjectURL(new Blob([`import '${new URL("./gltf-progressive.worker-DpfUjn1n.js",import.meta.url).toString()}';`],{type:"text/javascript"})),{type:"module"});return new be(e,t)}_running=[];_webglRenderer=null;async load(t,e){const r=at();let s=e?.renderer;s||(this._webglRenderer??=(async()=>{const{WebGLRenderer:l}=await import("./three.min.js").then(a=>a.THREE);return new l})(),s=await this._webglRenderer);const o=te(s).ktx2Loader.workerConfig;t instanceof URL?t=t.toString():t.startsWith("file:")?t=URL.createObjectURL(new Blob([t])):!t.startsWith("blob:")&&!t.startsWith("http:")&&!t.startsWith("https:")&&(t=new URL(t,window.location.href).toString());const n={type:"load",url:t,dracoDecoderPath:r.dracoDecoderPath,ktx2TranscoderPath:r.ktx2TranscoderPath,ktx2LoaderConfig:o};return this._debug&&console.debug("[Worker] Sending load request",n),this.worker.postMessage(n),new Promise(l=>{this._running.push({url:t.toString(),resolve:l})})}_debug=!1}function _t(i){for(const t of i.geometries){const e=t.geometry,r=new U;if(r.name=e.name||"",e.index){const s=e.index;r.setIndex(xe(s))}for(const s in e.attributes){const o=e.attributes[s],n=xe(o);r.setAttribute(s,n)}if(e.morphAttributes)for(const s in e.morphAttributes){const o=e.morphAttributes[s].map(n=>xe(n));r.morphAttributes[s]=o}if(r.morphTargetsRelative=e.morphTargetsRelative??!1,r.boundingBox=new ae,r.boundingBox.min=new A(e.boundingBox?.min.x,e.boundingBox?.min.y,e.boundingBox?.min.z),r.boundingBox.max=new A(e.boundingBox?.max.x,e.boundingBox?.max.y,e.boundingBox?.max.z),r.boundingSphere=new Me(new A(e.boundingSphere?.center.x,e.boundingSphere?.center.y,e.boundingSphere?.center.z),e.boundingSphere?.radius),e.groups)for(const s of e.groups)r.addGroup(s.start,s.count,s.materialIndex);e.userData&&(r.userData=e.userData),t.geometry=r}for(const t of i.textures){const e=t.texture;let r=null;if(e.isCompressedTexture){const s=e.mipmaps,{width:o,height:n}=fe(e);r=new Xe(s,o,n,e.format,e.type,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.anisotropy,e.colorSpace)}else r=new $(e.image,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),r.mipmaps=e.mipmaps,r.channel=e.channel,r.source.data=e.source.data,r.flipY=e.flipY,r.premultiplyAlpha=e.premultiplyAlpha,r.unpackAlignment=e.unpackAlignment,r.matrix=new He(...e.matrix.elements);if(!r){console.error("[Worker] Failed to create new texture from received data. Texture is not a CompressedTexture or Texture.");continue}t.texture=r}return i}function xe(i){let t=i;if("isInterleavedBufferAttribute"in i&&i.isInterleavedBufferAttribute){const e=i.data,r=e.array,s=new Ke(r,e.stride);t=new Ye(s,i.itemSize,r.byteOffset,i.normalized),t.offset=i.offset}else"isBufferAttribute"in i&&i.isBufferAttribute&&(t=new Qe(i.array,i.itemSize,i.normalized),t.usage=i.usage,t.gpuType=i.gpuType,t.updateRanges=i.updateRanges);return t}const bt=j("gltf-progressive-worker");j("gltf-progressive-reduce-mipmaps");const X=j("gltf-progressive-gc"),ye=Symbol("needle-progressive-texture"),B="NEEDLE_progressive";class f{get name(){return B}static getMeshLODExtension(t){const e=this.getAssignedLODInformation(t);return e?.key?this.lodInfos.get(e.key):null}static getPrimitiveIndex(t){return this.getAssignedLODInformation(t)?.index??-1}static getMaterialMinMaxLODsCount(t,e){const r=this,s="LODS:minmax",o=t[s];if(o!=null)return o;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const l of t)this.getMaterialMinMaxLODsCount(l,e);return t[s]=e,e}if(h==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const l=t;for(const a of Object.keys(l.uniforms)){const u=l.uniforms[a].value;u?.isTexture===!0&&n(u,e)}}else if(t.isMaterial)for(const l of Object.keys(t)){const a=t[l];a?.isTexture===!0&&n(a,e)}else h&&console.warn(`[getMaterialMinMaxLODsCount] Unsupported material type: ${t.type}`);return t[s]=e,e;function n(l,a){const u=r.getAssignedLODInformation(l);if(u){const y=r.lodInfos.get(u.key);if(y&&y.lods){a.min_count=Math.min(a.min_count,y.lods.length),a.max_count=Math.max(a.max_count,y.lods.length);for(let p=0;p<y.lods.length;p++){const w=y.lods[p];w.width&&(a.lods[p]=a.lods[p]||{min_height:1/0,max_height:0},a.lods[p].min_height=Math.min(a.lods[p].min_height,w.height),a.lods[p].max_height=Math.max(a.lods[p].max_height,w.height))}}}}}static hasLODLevelAvailable(t,e){if(Array.isArray(t)){for(const o of t)if(this.hasLODLevelAvailable(o,e))return!0;return!1}if(t.isMaterial===!0){for(const o of Object.keys(t)){const n=t[o];if(n&&n.isTexture&&this.hasLODLevelAvailable(n,e))return!0}return!1}else if(t.isGroup===!0){for(const o of t.children)if(o.isMesh===!0&&this.hasLODLevelAvailable(o,e))return!0}let r,s;if(t.isMesh?r=t.geometry:(t.isBufferGeometry||t.isTexture)&&(r=t),r&&r?.userData?.LODS){const o=r.userData.LODS;if(s=this.lodInfos.get(o.key),e===void 0)return s!=null;if(s)return Array.isArray(s.lods)?e<s.lods.length:e===0}return!1}static assignMeshLOD(t,e){if(!t)return Promise.resolve(null);if(t instanceof W||t.isMesh===!0){const r=t.geometry,s=this.getAssignedLODInformation(r);if(!s)return Promise.resolve(null);for(const o of F)o.onBeforeGetLODMesh?.(t,e);return t["LOD:requested level"]=e,f.getOrLoadLOD(r,e).then(o=>{if(Array.isArray(o)){const n=s.index||0;o=o[n]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],o&&r!=o&&(o?.isBufferGeometry?t.geometry=o:h&&console.error("Invalid LOD geometry",o))),o}).catch(o=>(console.error("Error loading mesh LOD",t,o),null))}else h&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const r=t;if(Array.isArray(r.material)){const s=new Array;for(const o of r.material){const n=this.assignTextureLOD(o,e);s.push(n)}return Promise.all(s).then(o=>{const n=new Array;for(const l of o)Array.isArray(l)&&n.push(...l);return n})}else return this.assignTextureLOD(r.material,e)}if(t.isMaterial===!0){const r=t,s=[],o=new Array;if(r.uniforms&&(r.isRawShaderMaterial||r.isShaderMaterial===!0)){const n=r;for(const l of Object.keys(n.uniforms)){const a=n.uniforms[l].value;if(a?.isTexture===!0){const u=this.assignTextureLODForSlot(a,e,r,l).then(y=>(y&&n.uniforms[l].value!=y&&(n.uniforms[l].value=y,n.uniformsNeedUpdate=!0),y));s.push(u),o.push(l)}}}else for(const n of Object.keys(r)){const l=r[n];if(l?.isTexture===!0){const a=this.assignTextureLODForSlot(l,e,r,n);s.push(a),o.push(n)}}return Promise.all(s).then(n=>{const l=new Array;for(let a=0;a<n.length;a++){const u=n[a],y=o[a];u&&u.isTexture===!0?l.push({material:r,slot:y,texture:u,level:e}):l.push({material:r,slot:y,texture:null,level:e})}return l})}if(t instanceof $||t.isTexture===!0){const r=t;return this.assignTextureLODForSlot(r,e,null,null)}return Promise.resolve(null)}static set maxConcurrentLoadingTasks(t){f.queue.maxConcurrent=t}static get maxConcurrentLoadingTasks(){return f.queue.maxConcurrent}static assignTextureLODForSlot(t,e,r,s){return t?.isTexture!==!0?Promise.resolve(null):s==="glyphMap"?Promise.resolve(t):f.getOrLoadLOD(t,e).then(o=>{if(Array.isArray(o))return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."),null;if(o?.isTexture===!0){if(o!=t&&r&&s){const n=r[s];if(n&&!h){const l=this.getAssignedLODInformation(n);if(l&&l?.level<e)return h==="verbose"&&console.warn("Assigned texture level is already higher: ",l.level,e,r,n,o),o&&o!==n&&((h||X)&&console.log(`[gltf-progressive] Disposing rejected lower-quality texture LOD ${e} (assigned is ${l.level})`,o.uuid),o.dispose()),null}if(this.trackTextureUsage(o),n&&n!==o&&this.untrackTextureUsage(n)&&(h||X)){const l=this.getAssignedLODInformation(n);console.log(`[gltf-progressive] Disposed old texture LOD ${l?.level??"?"} \u2192 ${e} for ${r.name||r.type}.${s}`,n.uuid)}r[s]=o}return o}else h=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(o=>(console.error("Error loading LOD",t,o),null))}parser;url;constructor(t){const e=t.options.path;h&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}_isLoadingMesh;loadMesh=t=>{if(this._isLoadingMesh)return null;const e=this.parser.json.meshes[t]?.extensions?.[B];return e?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",t).then(r=>(this._isLoadingMesh=!1,r&&f.registerMesh(this.url,e.guid,r,e.lods?.length,0,e),r))):null};afterRoot(t){return h&&console.log("AFTER",this.url,t),this.parser.json.textures?.forEach((e,r)=>{if(e?.extensions){const s=e?.extensions[B];if(s){if(!s.lods){h&&console.warn("Texture has no LODs",s);return}let o=!1;for(const n of this.parser.associations.keys())n.isTexture===!0&&this.parser.associations.get(n)?.textures===r&&(o=!0,f.registerTexture(this.url,n,s.lods?.length,r,s));o||this.parser.getDependency("texture",r).then(n=>{n&&f.registerTexture(this.url,n,s.lods?.length,r,s)})}}}),this.parser.json.meshes?.forEach((e,r)=>{if(e?.extensions){const s=e?.extensions[B];if(s&&s.lods){for(const o of this.parser.associations.keys())if(o.isMesh){const n=this.parser.associations.get(o);n?.meshes===r&&f.registerMesh(this.url,s.guid,o,s.lods.length,n.primitives,s)}}}}),null}static registerTexture=(t,e,r,s,o)=>{if(!e){h&&console.error("!! gltf-progressive: Called register texture without texture");return}if(h){const{width:l,height:a}=fe(e);console.log(`> gltf-progressive: register texture[${s}] "${e.name||e.uuid}", Current: ${l}x${a}, Max: ${o.lods[0]?.width}x${o.lods[0]?.height}, uuid: ${e.uuid}`,o,e)}e.source&&(e.source[ye]=o);const n=o.guid;f.assignLODInformation(t,e,n,r,s),f.lodInfos.set(n,o),f.lowresCache.set(n,new WeakRef(e))};static registerMesh=(t,e,r,s,o,n)=>{const l=r.geometry;if(!l){h&&console.warn("gltf-progressive: Register mesh without geometry");return}l.userData||(l.userData={}),h&&console.log("> Progressive: register mesh "+r.name,{index:o,uuid:r.uuid},n,r),f.assignLODInformation(t,l,e,s,o),f.lodInfos.set(e,n);let a=f.lowresCache.get(e)?.deref();a?a.push(r.geometry):a=[r.geometry],f.lowresCache.set(e,new WeakRef(a)),s>0&&!V(r)&&pt(r,l);for(const u of F)u.onRegisteredNewMesh?.(r,n)};static dispose(t){if(t){this.lodInfos.delete(t);const e=this.lowresCache.get(t);if(e){const r=e.deref();if(r){if(r.isTexture){const s=r;this.textureRefCounts.delete(s.uuid),s.dispose()}else if(Array.isArray(r))for(const s of r)s.dispose()}this.lowresCache.delete(t)}for(const[r,s]of this.cache)r.includes(t)&&(this._disposeCacheEntry(s),this.cache.delete(r))}else{this.lodInfos.clear();for(const[,e]of this.lowresCache){const r=e.deref();if(r){if(r.isTexture){const s=r;this.textureRefCounts.delete(s.uuid),s.dispose()}else if(Array.isArray(r))for(const s of r)s.dispose()}}this.lowresCache.clear();for(const[,e]of this.cache)this._disposeCacheEntry(e);this.cache.clear(),this.textureRefCounts.clear()}}static _disposeCacheEntry(t){if(t instanceof WeakRef){const e=t.deref();e&&(e.isTexture&&this.textureRefCounts.delete(e.uuid),e.dispose())}else t.then(e=>{if(e)if(Array.isArray(e))for(const r of e)r.dispose();else e.isTexture&&this.textureRefCounts.delete(e.uuid),e.dispose()}).catch(()=>{})}static lodInfos=new Map;static cache=new Map;static lowresCache=new Map;static textureRefCounts=new Map;static _resourceRegistry=new FinalizationRegistry(t=>{const e=f.cache.get(t);(h||X)&&console.debug(`[gltf-progressive] Memory: Resource GC'd
2
+ ${t}`),e instanceof WeakRef&&(e.deref()||(f.cache.delete(t),(h||X)&&console.log("[gltf-progressive] \u21AA Cache entry deleted (GC)")))});static trackTextureUsage(t){const e=t.uuid,r=this.textureRefCounts.get(e)||0;this.textureRefCounts.set(e,r+1),h==="verbose"&&console.log(`[gltf-progressive] Track texture ${e}, refCount: ${r} \u2192 ${r+1}`)}static untrackTextureUsage(t){const e=t.uuid,r=this.textureRefCounts.get(e);if(!r)return(h==="verbose"||X)&&o("[gltf-progressive] Memory: Untrack untracked texture (dispose immediately)",0),t.dispose(),!0;const s=r-1;if(s<=0)return this.textureRefCounts.delete(e),(h||X)&&o("[gltf-progressive] Memory: Dispose texture",s),t.dispose(),!0;return this.textureRefCounts.set(e,s),h==="verbose"&&o("[gltf-progressive] Memory: Untrack texture",s),!1;function o(n,l){let{width:a,height:u}=fe(t);const y=a&&u?`${a}x${u}`:"N/A";let p="N/A";a&&u&&(p=`~${(gt(t)/(1024*1024)).toFixed(2)} MB`),console.log(`${n} \u2014 ${t.name} ${y} (${p}), refCount: ${r} \u2192 ${l}
3
+ ${e}`)}}static workers=[];static _workersIndex=0;static async getOrLoadLOD(t,e){const r=h=="verbose",s=this.getAssignedLODInformation(t);if(!s)return h&&console.warn(`[gltf-progressive] No LOD information found: ${t.name}, uuid: ${t.uuid}, type: ${t.type}`,t),null;const o=s?.key;let n;if(t.isTexture===!0){const l=t;l.source&&l.source[ye]&&(n=l.source[ye])}if(n||(n=f.lodInfos.get(o)),!n)h&&console.warn(`Can not load LOD ${e}: no LOD info found for "${o}" ${t.name}`,t.type,f.lodInfos);else{if(e>0){let u=!1;const y=Array.isArray(n.lods);if(y&&e>=n.lods.length?u=!0:y||(u=!0),u){const p=this.lowresCache.get(o);if(p){const w=p.deref();if(w)return w;this.lowresCache.delete(o),h&&console.log(`[gltf-progressive] Lowres cache entry was GC'd: ${o}`)}return null}}const l=Array.isArray(n.lods)?n.lods[e]?.path:n.lods;if(!l)return h&&!n["missing:uri"]&&(n["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,n)),null;const a=dt(s.url,l);if(a.endsWith(".glb")||a.endsWith(".gltf")){if(!n.guid)return console.warn("missing pointer for glb/gltf texture",n),null;const u=a+"_"+n.guid,y=await this.queue.slot(a),p=this.cache.get(u);if(p!==void 0)if(r&&console.log(`LOD ${e} was already loading/loaded: ${u}`),p instanceof WeakRef){const c=p.deref();if(c){let x=c,v=!1;if(x instanceof $&&t instanceof $?Ce(x.image)||ge(x)?x=this.copySettings(t,x):v=!0:x instanceof U&&t instanceof U&&(x.attributes.position?.array||(v=!0)),!v)return x}this.cache.delete(u),h&&console.log(`[gltf-progressive] Re-loading GC'd/disposed resource: ${u}`)}else{let c=await p.catch(v=>(console.error(`Error loading LOD ${e} from ${a}
4
+ `,v),null)),x=!1;if(c==null||(c instanceof $&&t instanceof $?Ce(c.image)||ge(c)?c=this.copySettings(t,c):(x=!0,this.cache.delete(u)):c instanceof U&&t instanceof U&&(c.attributes.position?.array||(x=!0,this.cache.delete(u)))),!x)return c}if(!y.use)return h&&console.log(`LOD ${e} was aborted: ${a}`),null;const w=n,P=new Promise(async(c,x)=>{if(bt){const g=await(await Lt({})).load(a);if(g.textures.length>0)for(const d of g.textures){let m=d.texture;return f.assignLODInformation(s.url,m,o,e,void 0),t instanceof $&&(m=this.copySettings(t,m)),m&&(m.guid=w.guid),c(m)}if(g.geometries.length>0){const d=new Array;for(const m of g.geometries){const L=m.geometry;f.assignLODInformation(s.url,L,o,e,m.primitiveIndex),d.push(L)}return c(d)}return c(null)}const v=new le;ue(v),h&&(await new Promise(g=>setTimeout(g,1e3)),r&&console.warn("Start loading (delayed) "+a,w.guid));let C=a;if(w&&Array.isArray(w.lods)){const g=w.lods[e];g.hash&&(C+="?v="+g.hash)}const b=await v.loadAsync(C).catch(g=>(console.error(`Error loading LOD ${e} from ${a}
5
+ `,g),c(null)));if(!b)return c(null);const E=b.parser;r&&console.log("Loading finished "+a,w.guid);let M=0;if(b.parser.json.textures){let g=!1;for(const d of b.parser.json.textures){if(d?.extensions){const m=d?.extensions[B];if(m?.guid&&m.guid===w.guid){g=!0;break}}M++}if(g){let d=await E.getDependency("texture",M);return d&&f.assignLODInformation(s.url,d,o,e,void 0),r&&console.log('change "'+t.name+'" \u2192 "'+d.name+'"',a,M,d,u),t instanceof $&&(d=this.copySettings(t,d)),d&&(d.guid=w.guid),c(d)}else h&&console.warn("Could not find texture with guid",w.guid,b.parser.json)}if(M=0,b.parser.json.meshes){let g=!1;for(const d of b.parser.json.meshes){if(d?.extensions){const m=d?.extensions[B];if(m?.guid&&m.guid===w.guid){g=!0;break}}M++}if(g){const d=await E.getDependency("mesh",M);if(r&&console.log(`Loaded Mesh "${d.name}"`,a,M,d,u),d.isMesh===!0){const m=d.geometry;return f.assignLODInformation(s.url,m,o,e,0),c(m)}else{const m=new Array;for(let L=0;L<d.children.length;L++){const S=d.children[L];if(S.isMesh===!0){const G=S.geometry;f.assignLODInformation(s.url,G,o,e,L),m.push(G)}}return c(m)}}else h&&console.warn("Could not find mesh with guid",w.guid,b.parser.json)}return c(null)});this.cache.set(u,P),y.use(P);const _=await P;return _!=null?_ instanceof $?(this.cache.set(u,new WeakRef(_)),f._resourceRegistry.register(_,u)):Array.isArray(_)?this.cache.set(u,Promise.resolve(_)):this.cache.set(u,Promise.resolve(_)):this.cache.set(u,Promise.resolve(null)),_}else if(t instanceof $){r&&console.log("Load texture from uri: "+a);const u=await new Je().loadAsync(a);return u?(u.guid=n.guid,u.flipY=!1,u.needsUpdate=!0,u.colorSpace=t.colorSpace,r&&console.log(n,u)):h&&console.warn("failed loading",a),u}}return null}static queue=new ht(me()?20:50,{debug:h!=!1});static assignLODInformation(t,e,r,s,o){if(!e)return;e.userData||(e.userData={});const n=new Mt(t,r,s,o);e.userData.LODS=n,"source"in e&&typeof e.source=="object"&&(e.source.LODS=n)}static getAssignedLODInformation(t){return t?t.userData?.LODS?t.userData.LODS:"source"in t&&t.source?.LODS?t.source.LODS:null:null}static copySettings(t,e){return e?(h==="verbose"&&console.debug(`Copy texture settings
6
+ `,t.uuid,`
7
+ `,e.uuid),e=e.clone(),e.offset=t.offset,e.repeat=t.repeat,e.colorSpace=t.colorSpace,e.magFilter=t.magFilter,e.minFilter=t.minFilter,e.wrapS=t.wrapS,e.wrapT=t.wrapT,e.flipY=t.flipY,e.anisotropy=t.anisotropy,e.mipmaps||(e.generateMipmaps=t.generateMipmaps),e):t}}class Mt{url;key;level;index;constructor(t,e,r,s){this.url=t,this.key=e,this.level=r,s!=null&&(this.index=s)}}class we{static addPromise=(t,e,r,s)=>{s.forEach(o=>{o.add(t,e,r)})};ready;get awaitedCount(){return this._addedCount}get resolvedCount(){return this._resolvedCount}get currentlyAwaiting(){return this._awaiting.length}_resolve;_signal;_frame_start;_frames_to_capture;_resolved=!1;_addedCount=0;_resolvedCount=0;_awaiting=[];_maxPromisesPerObject=1;constructor(t,e){const r=Math.max(e.frames??2,2);this._frame_start=e.waitForFirstCapture?void 0:t,this._frames_to_capture=r,this.ready=new Promise(s=>{this._resolve=s}),this.ready.finally(()=>{this._resolved=!0,this._awaiting.length=0}),this._signal=e.signal,this._signal?.addEventListener("abort",()=>{this.resolveNow()}),this._maxPromisesPerObject=Math.max(1,e.maxPromisesPerObject??1)}_currentFrame=0;update(t){this._currentFrame=t,this._frame_start===void 0&&this._addedCount>0&&(this._frame_start=t),(this._signal?.aborted||this._awaiting.length===0&&this._frame_start!==void 0&&t>this._frame_start+this._frames_to_capture)&&this.resolveNow()}_seen=new WeakMap;add(t,e,r){if(this._resolved){h&&console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");return}if(!(this._frame_start!==void 0&&this._currentFrame>this._frame_start+this._frames_to_capture)){if(this._maxPromisesPerObject>=1)if(this._seen.has(e)){let s=this._seen.get(e);if(s>=this._maxPromisesPerObject){h&&console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");return}this._seen.set(e,s+1)}else this._seen.set(e,1);this._awaiting.push(r),this._addedCount++,r.finally(()=>{this._resolvedCount++,this._awaiting.splice(this._awaiting.indexOf(r),1)})}}resolveNow(){this._resolved||this._resolve?.({awaited_count:this._addedCount,resolved_count:this._resolvedCount,cancelled:this._signal?.aborted??!1})}}const I=j("debugprogressive"),Dt=j("noprogressive"),ve=Symbol("Needle:LODSManager"),Le=Symbol("Needle:LODState"),N=Symbol("Needle:CurrentLOD"),O={mesh_lod:-1,texture_lod:-1};let Q=class D{static debugDrawLine;static getObjectLODState(t){return t[Le]}static addPlugin(t){F.push(t)}static removePlugin(t){const e=F.indexOf(t);e>=0&&F.splice(e,1)}static get(t,e){if(t[ve])return console.debug("[gltf-progressive] LODsManager already exists for this renderer"),t[ve];const r=new D(t,{engine:"unknown",...e});return t[ve]=r,r}renderer;context;projectionScreenMatrix=new De;get plugins(){return F}overrideLodLevel=void 0;targetTriangleDensity=2e5;skinnedMeshAutoUpdateBoundsInterval=30;updateInterval="auto";#e=1;pause=!1;manual=!1;_newPromiseGroups=[];_promiseGroupIds=0;awaitLoading(t){const e=this._promiseGroupIds++,r=new we(this.#s,{...t});this._newPromiseGroups.push(r);const s=performance.now();return r.ready.finally(()=>{const o=this._newPromiseGroups.indexOf(r);o>=0&&(this._newPromiseGroups.splice(o,1),Ae()&&performance.measure("LODsManager:awaitLoading",{start:s,detail:{id:e,name:t?.name,awaited:r.awaitedCount,resolved:r.resolvedCount}}))}),r.ready}_postprocessPromiseGroups(){if(this._newPromiseGroups.length!==0)for(let t=this._newPromiseGroups.length-1;t>=0;t--)this._newPromiseGroups[t].update(this.#s)}_lodchangedlisteners=[];addEventListener(t,e){t==="changed"&&this._lodchangedlisteners.push(e)}removeEventListener(t,e){if(t==="changed"){const r=this._lodchangedlisteners.indexOf(e);r>=0&&this._lodchangedlisteners.splice(r,1)}}constructor(t,e){this.renderer=t,this.context={...e}}#t;#n=new Ze;#s=0;#o=0;#i=0;#r=0;_fpsBuffer=[60,60,60,60,60];enable(){if(this.#t)return;console.debug("[gltf-progressive] Enabling LODsManager for renderer");let t=0;this.#t=this.renderer.render;const e=this;te(this.renderer),this.renderer.render=function(r,s){const o=e.renderer.getRenderTarget();(o==null||"isXRRenderTarget"in o&&o.isXRRenderTarget)&&(t=0,e.#s+=1,e.#n.update(),e.#o=e.#n.getDelta(),e.#i+=e.#o,e._fpsBuffer.shift(),e._fpsBuffer.push(1/e.#o),e.#r=e._fpsBuffer.reduce((l,a)=>l+a)/e._fpsBuffer.length,I&&e.#s%200===0&&console.log("FPS",Math.round(e.#r),"Interval:",e.#e));const n=t++;e.#t.call(this,r,s),e.onAfterRender(r,s,n)}}disable(){this.#t&&(console.debug("[gltf-progressive] Disabling LODsManager for renderer"),this.renderer.render=this.#t,this.#t=void 0)}update(t,e){this.internalUpdate(t,e)}onAfterRender(t,e,r){if(this.pause)return;const s=this.renderer.renderLists.get(t,0).opaque;let o=!0;if(s.length===1){const n=s[0].material;(n.name==="EffectMaterial"||n.name==="CopyShader")&&(o=!1)}if((e.parent&&e.parent.type==="CubeCamera"||r>=1&&e.type==="OrthographicCamera")&&(o=!1),o){if(Dt||(this.updateInterval==="auto"?this.#r<40&&this.#e<10?(this.#e+=1,I&&console.warn("\u2193 Reducing LOD updates",this.#e,this.#r.toFixed(0))):this.#r>=60&&this.#e>1&&(this.#e-=1,I&&console.warn("\u2191 Increasing LOD updates",this.#e,this.#r.toFixed(0))):this.#e=this.updateInterval,this.#e>0&&this.#s%this.#e!=0))return;this.internalUpdate(t,e),this._postprocessPromiseGroups()}}internalUpdate(t,e){const r=this.renderer.renderLists.get(t,0),s=r.opaque;this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse);const o=this.targetTriangleDensity;for(const a of s){if(a.material&&(a.geometry?.type==="BoxGeometry"||a.geometry?.type==="BufferGeometry")&&(a.material.name==="SphericalGaussianBlur"||a.material.name=="BackgroundCubeMaterial"||a.material.name==="CubemapFromEquirect"||a.material.name==="EquirectangularToCubeUV")){I&&(a.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]||(a.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]=!0,console.warn("Ignoring skybox or BLIT object",a,a.material.name,a.material.type)));continue}switch(a.material.type){case"LineBasicMaterial":case"LineDashedMaterial":case"PointsMaterial":case"ShadowMaterial":case"MeshDistanceMaterial":case"MeshDepthMaterial":continue}if(I==="color"&&a.material&&!a.object.progressive_debug_color){a.object.progressive_debug_color=!0;const y=Math.random()*16777215,p=new et({color:y});a.object.material=p}const u=a.object;(u instanceof W||u.isMesh)&&this.updateLODs(t,e,u,o)}const n=r.transparent;for(const a of n){const u=a.object;(u instanceof W||u.isMesh)&&this.updateLODs(t,e,u,o)}const l=r.transmissive;for(const a of l){const u=a.object;(u instanceof W||u.isMesh)&&this.updateLODs(t,e,u,o)}}updateLODs(t,e,r,s){r.userData||(r.userData={});let o=r[Le];if(o||(o=new Ot,r[Le]=o),o.frames++<2)return;for(const l of F)l.onBeforeUpdateLOD?.(this.renderer,t,e,r);const n=this.overrideLodLevel!==void 0?this.overrideLodLevel:q;n>=0?(O.mesh_lod=n,O.texture_lod=n):(this.calculateLodLevel(e,r,o,s,O),O.mesh_lod=Math.round(O.mesh_lod),O.texture_lod=Math.round(O.texture_lod)),O.mesh_lod>=0&&this.loadProgressiveMeshes(r,O.mesh_lod),r.material&&O.texture_lod>=0&&this.loadProgressiveTextures(r.material,O.texture_lod,n),h&&r.material&&!r.isGizmo&&ke(r.material);for(const l of F)l.onAfterUpdatedLOD?.(this.renderer,t,e,r,O);o.lastLodLevel_Mesh=O.mesh_lod,o.lastLodLevel_Texture=O.texture_lod}loadProgressiveTextures(t,e,r){if(!t)return;if(Array.isArray(t)){for(const o of t)this.loadProgressiveTextures(o,e);return}let s=!1;if((t[N]===void 0||e<t[N])&&(s=!0),r!==void 0&&r>=0&&(s=t[N]!=r,e=r),s){t[N]=e;const o=f.assignTextureLOD(t,e).then(n=>{this._lodchangedlisteners.forEach(l=>l({type:"texture",level:e,object:t}))});we.addPromise("texture",t,o,this._newPromiseGroups)}}loadProgressiveMeshes(t,e){if(!t)return Promise.resolve(null);let r=t[N]!==e;const s=t["DEBUG:LOD"];if(s!=null&&(r=t[N]!=s,e=s),r){t[N]=e;const o=t.geometry,n=f.assignMeshLOD(t,e).then(l=>(l&&t[N]==e&&o!=t.geometry&&this._lodchangedlisteners.forEach(a=>a({type:"mesh",level:e,object:t})),l));return we.addPromise("mesh",t,n,this._newPromiseGroups),n}return Promise.resolve(null)}_sphere=new Me;_tempBox=new ae;_tempBox2=new ae;tempMatrix=new De;_tempWorldPosition=new A;_tempBoxSize=new A;_tempBox2Size=new A;static corner0=new A;static corner1=new A;static corner2=new A;static corner3=new A;static _tempPtInside=new A;static isInside(t,e){const r=t.min,s=t.max,o=(r.x+s.x)*.5,n=(r.y+s.y)*.5;return this._tempPtInside.set(o,n,r.z).applyMatrix4(e).z<0}static skinnedMeshBoundsFrameOffsetCounter=0;static $skinnedMeshBoundsOffset=Symbol("gltf-progressive-skinnedMeshBoundsOffset");calculateLodLevel(t,e,r,s,o){if(!e){o.mesh_lod=-1,o.texture_lod=-1;return}if(!t){o.mesh_lod=-1,o.texture_lod=-1;return}let n=10+1,l=!1;if(I&&e["DEBUG:LOD"]!=null)return e["DEBUG:LOD"];const a=f.getMeshLODExtension(e.geometry)?.lods,u=f.getPrimitiveIndex(e.geometry),y=a&&a.length>0,p=f.getMaterialMinMaxLODsCount(e.material),w=p.min_count!==1/0&&p.min_count>=0&&p.max_count>=0;if(!y&&!w){o.mesh_lod=0,o.texture_lod=0;return}y||(l=!0,n=0);const P=this.renderer.domElement.clientHeight||this.renderer.domElement.height;let _=e.geometry.boundingBox;if(e.type==="SkinnedMesh"){const c=e;if(!c.boundingBox)c.computeBoundingBox();else if(this.skinnedMeshAutoUpdateBoundsInterval>0){if(!c[D.$skinnedMeshBoundsOffset]){const v=D.skinnedMeshBoundsFrameOffsetCounter++;c[D.$skinnedMeshBoundsOffset]=v}const x=c[D.$skinnedMeshBoundsOffset];if((r.frames+x)%this.skinnedMeshAutoUpdateBoundsInterval===0){const v=V(c),C=c.geometry;v&&(c.geometry=v),c.computeBoundingBox(),c.geometry=C}}_=c.boundingBox}if(_){const c=t;if(e.geometry.attributes.color&&e.geometry.attributes.color.count<100&&e.geometry.boundingSphere){this._sphere.copy(e.geometry.boundingSphere),this._sphere.applyMatrix4(e.matrixWorld);const g=t.getWorldPosition(this._tempWorldPosition);if(this._sphere.containsPoint(g)){o.mesh_lod=0,o.texture_lod=0;return}}if(this._tempBox.copy(_),this._tempBox.applyMatrix4(e.matrixWorld),c.isPerspectiveCamera&&D.isInside(this._tempBox,this.projectionScreenMatrix)){o.mesh_lod=0,o.texture_lod=0;return}if(this._tempBox.applyMatrix4(this.projectionScreenMatrix),this.renderer.xr.enabled&&c.isPerspectiveCamera&&c.fov>70){const g=this._tempBox.min,d=this._tempBox.max;let m=g.x,L=g.y,S=d.x,G=d.y;const J=2,ne=1.5,Z=(g.x+d.x)*.5,ee=(g.y+d.y)*.5;m=(m-Z)*J+Z,L=(L-ee)*J+ee,S=(S-Z)*J+Z,G=(G-ee)*J+ee;const Ge=m<0&&S>0?0:Math.min(Math.abs(g.x),Math.abs(d.x)),je=L<0&&G>0?0:Math.min(Math.abs(g.y),Math.abs(d.y)),ie=Math.max(Ge,je);r.lastCentrality=(ne-ie)*(ne-ie)*(ne-ie)}else r.lastCentrality=1;const x=this._tempBox.getSize(this._tempBoxSize);x.multiplyScalar(.5),screen.availHeight>0&&P>0&&x.multiplyScalar(P/screen.availHeight),t.isPerspectiveCamera?x.x*=t.aspect:t.isOrthographicCamera;const v=t.matrixWorldInverse,C=this._tempBox2;C.copy(_),C.applyMatrix4(e.matrixWorld),C.applyMatrix4(v);const b=C.getSize(this._tempBox2Size),E=Math.max(b.x,b.y);if(Math.max(x.x,x.y)!=0&&E!=0&&(x.z=b.z/Math.max(b.x,b.y)*Math.max(x.x,x.y)),r.lastScreenCoverage=Math.max(x.x,x.y,x.z),r.lastScreenspaceVolume.copy(x),r.lastScreenCoverage*=r.lastCentrality,I&&D.debugDrawLine){const g=this.tempMatrix.copy(this.projectionScreenMatrix);g.invert();const d=D.corner0,m=D.corner1,L=D.corner2,S=D.corner3;d.copy(this._tempBox.min),m.copy(this._tempBox.max),m.x=d.x,L.copy(this._tempBox.max),L.y=d.y,S.copy(this._tempBox.max);const G=(d.z+S.z)*.5;d.z=m.z=L.z=S.z=G,d.applyMatrix4(g),m.applyMatrix4(g),L.applyMatrix4(g),S.applyMatrix4(g),D.debugDrawLine(d,m,255),D.debugDrawLine(d,L,255),D.debugDrawLine(m,S,255),D.debugDrawLine(L,S,255)}let M=999;if(a&&r.lastScreenCoverage>0)for(let g=0;g<a.length;g++){const d=a[g],m=(d.densities?.[u]||d.density||1e-5)/r.lastScreenCoverage;if(u>0&&Ae()&&!d.densities&&!globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]&&(window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]=!0,console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")),m<s){M=g;break}}M<n&&(n=M,l=!0)}if(l?o.mesh_lod=n:o.mesh_lod=r.lastLodLevel_Mesh,I&&o.mesh_lod!=r.lastLodLevel_Mesh){const c=a?.[o.mesh_lod];c&&console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} \u2192 ${o.mesh_lod} (density: ${c.densities?.[u].toFixed(0)}) | ${e.name}`)}if(w){const c="saveData"in globalThis.navigator&&globalThis.navigator.saveData===!0;if(r.lastLodLevel_Texture<0){if(o.texture_lod=p.max_count-1,I){const x=p.lods[p.max_count-1];I&&console.log(`First Texture LOD ${o.texture_lod} (${x.max_height}px) - ${e.name}`)}}else{const x=r.lastScreenspaceVolume.x+r.lastScreenspaceVolume.y+r.lastScreenspaceVolume.z;let v=r.lastScreenCoverage*4;this.context?.engine==="model-viewer"&&(v*=1.5);const C=P/window.devicePixelRatio*v;let b=!1;for(let E=p.lods.length-1;E>=0;E--){const M=p.lods[E];if(!(c&&M.max_height>=2048)&&!(me()&&M.max_height>4096)&&(M.max_height>C||!b&&E===0)){if(b=!0,o.texture_lod=E,I&&o.texture_lod<r.lastLodLevel_Texture){const g=M.max_height;console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} \u2192 ${o.texture_lod} = ${g}px
8
+ Screensize: ${C.toFixed(0)}px, Coverage: ${(100*r.lastScreenCoverage).toFixed(2)}%, Volume ${x.toFixed(1)}
9
+ ${e.name}`)}break}}}}else o.texture_lod=0}};class Ot{frames=0;lastLodLevel_Mesh=-1;lastLodLevel_Texture=-1;lastScreenCoverage=0;lastScreenspaceVolume=new A;lastCentrality=0}const Re=Symbol("NEEDLE_mesh_lod"),oe=Symbol("NEEDLE_texture_lod");let _e=null;function Ie(){const i=St();i&&(i.mapURLs(function(t){return Ee(),t}),Ee(),_e?.disconnect(),_e=new MutationObserver(t=>{t.forEach(e=>{e.addedNodes.forEach(r=>{r instanceof HTMLElement&&r.tagName.toLowerCase()==="model-viewer"&&Be(r)})})}),_e.observe(document,{childList:!0,subtree:!0}))}function St(){return typeof customElements>"u"?null:customElements.get("model-viewer")||(customElements.whenDefined("model-viewer").then(()=>{console.debug("[gltf-progressive] model-viewer defined"),Ie()}),null)}function Ee(){typeof document>"u"||document.querySelectorAll("model-viewer").forEach(i=>{Be(i)})}const $e=new WeakSet;let Tt=0;function Be(i){if(!i||$e.has(i))return null;$e.add(i),console.debug("[gltf-progressive] found new model-viewer..."+ ++Tt+`
10
+ `,i.getAttribute("src"));let t=null,e=null,r=null;for(let s=i;s!=null;s=Object.getPrototypeOf(s)){const o=Object.getOwnPropertySymbols(s),n=o.find(u=>u.toString()=="Symbol(renderer)"),l=o.find(u=>u.toString()=="Symbol(scene)"),a=o.find(u=>u.toString()=="Symbol(needsRender)");!t&&n!=null&&(t=i[n].threeRenderer),!e&&l!=null&&(e=i[l]),!r&&a!=null&&(r=i[a])}if(t&&e){let s=function(){if(r){let n=0,l=setInterval(()=>{if(n++>5){clearInterval(l);return}r?.call(i)},300)}};console.debug("[gltf-progressive] setup model-viewer");const o=Q.get(t,{engine:"model-viewer"});return Q.addPlugin(new Pt),o.enable(),o.addEventListener("changed",()=>{r?.call(i)}),i.addEventListener("model-visibility",n=>{n.detail.visible&&r?.call(i)}),i.addEventListener("load",()=>{s()}),()=>{o.disable()}}return null}class Pt{_didWarnAboutMissingUrl=!1;onBeforeUpdateLOD(t,e,r,s){this.tryParseMeshLOD(e,s),this.tryParseTextureLOD(e,s)}getUrl(t){if(!t)return null;let e=t.getAttribute("src");return e||(e=t.src),e||(this._didWarnAboutMissingUrl||console.warn("No url found in modelviewer",t),this._didWarnAboutMissingUrl=!0),e}tryGetCurrentGLTF(t){return t._currentGLTF}tryGetCurrentModelViewer(t){return t.element}tryParseTextureLOD(t,e){if(e[oe]==!0)return;e[oe]=!0;const r=this.tryGetCurrentGLTF(t),s=this.tryGetCurrentModelViewer(t),o=this.getUrl(s);if(o&&r&&e.material){let n=function(a){if(a[oe]==!0)return;a[oe]=!0,a.userData&&(a.userData.LOD=-1);const u=Object.keys(a);for(let y=0;y<u.length;y++){const p=u[y],w=a[p];if(w?.isTexture===!0){const P=w.userData?.associations?.textures;if(P==null)continue;const _=r.parser.json.textures[P];if(!_){console.warn("Texture data not found for texture index "+P);continue}if(_?.extensions?.[B]){const c=_.extensions[B];c&&o&&f.registerTexture(o,w,c.lods.length,P,c)}}}};const l=e.material;if(Array.isArray(l))for(const a of l)n(a);else n(l)}}tryParseMeshLOD(t,e){if(e[Re]==!0)return;e[Re]=!0;const r=this.tryGetCurrentModelViewer(t),s=this.getUrl(r);if(!s)return;const o=e.userData?.gltfExtensions?.[B];if(o&&s){const n=e.uuid;f.registerMesh(s,n,e,0,o.lods.length,o)}}}function Ct(...i){let t,e,r,s;switch(i.length){case 2:[r,e]=i,s={};break;case 3:[r,e,s]=i;break;case 4:[t,e,r,s]=i;break;default:throw new Error("Invalid arguments")}te(e),ue(r),he(r,{progressive:!0,...s?.hints}),r.register(n=>new f(n));const o=Q.get(e);return s?.enableLODsManager!==!1&&o.enable(),o}if(Ie(),!mt){const i={gltfProgressive:{useNeedleProgressive:Ct,LODsManager:Q,configureLoader:he,getRaycastMesh:V,useRaycastMeshes:xt}};if(!globalThis.Needle)globalThis.Needle=i;else for(const t in i)globalThis.Needle[t]=i[t]}export{Q as LODsManager,f as NEEDLE_progressive,ue as addDracoAndKTX2Loaders,he as configureLoader,te as createLoaders,V as getRaycastMesh,Se as setDracoDecoderLocation,Te as setKTX2TranscoderLocation};
@@ -0,0 +1,10 @@
1
+ "use strict";const c=require("./three.umd.cjs"),j=require("./three-examples.umd.cjs");var le=typeof document<"u"?document.currentScript:null;const Fe="";globalThis.GLTF_PROGRESSIVE_VERSION=Fe;console.debug("[gltf-progressive] version -");let I="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",N="https://cdn.needle.tools/static/three/0.179.1/basis2/";const Ue=I,We=N,Pe=new URL(I+"draco_decoder.js");Pe.searchParams.append("range","true");fetch(Pe,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(i=>{console.debug(`Failed to fetch remote Draco decoder from ${I} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),I===Ue&&Ce("./include/draco/"),N===We&&Ae("./include/ktx2/")}).finally(()=>{Re()});const ze=()=>({dracoDecoderPath:I,ktx2TranscoderPath:N});function Ce(i){I=i,A&&A[pe]!=I?(console.debug("Updating Draco decoder path to "+i),A[pe]=I,A.setDecoderPath(I),A.preload()):console.debug("Setting Draco decoder path to "+i)}function Ae(i){N=i,$&&$.transcoderPath!=N?(console.debug("Updating KTX2 transcoder path to "+i),$.setTranscoderPath(N),$.init()):console.debug("Setting KTX2 transcoder path to "+i)}function oe(i){return Re(),i?$.detectSupport(i):i!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:A,ktx2Loader:$,meshoptDecoder:ne}}function Le(i){i.dracoLoader||i.setDRACOLoader(A),i.ktx2Loader||i.setKTX2Loader($),i.meshoptDecoder||i.setMeshoptDecoder(ne)}const pe=Symbol("dracoDecoderPath");let A,ne,$;function Re(){A||(A=new j.DRACOLoader,A[pe]=I,A.setDecoderPath(I),A.setDecoderConfig({type:"js"}),A.preload()),$||($=new j.KTX2Loader,$.setTranscoderPath(N),$.init()),ne||(ne=j.MeshoptDecoder)}const me=new WeakMap;function _e(i,t){let e=me.get(i);e?e=Object.assign(e,t):e=t,me.set(i,e)}const Ve=j.GLTFLoader.prototype.load;function qe(...i){const t=me.get(this);let e=i[0];const s=new URL(e,window.location.href);if(s.hostname.endsWith("needle.tools")){const n=t?.progressive!==void 0?t.progressive:!0,o=t?.usecase?t.usecase:"default";n?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${o}`:this.requestHeader.Accept=`*/*;usecase=${o}`,e=s.toString()}return i[0]=e,Ve?.call(this,...i)}j.GLTFLoader.prototype.load=qe;function De(i){return i!=null&&i.data!=null}function ye(i){const t=i.source?.data;return t!=null&&typeof t=="object"?t:null}function Ne(i){const t=i.image;return t!=null&&typeof t=="object"?t:null}function xe(i){const t=Ne(i),e=ye(i);return{width:t?.width||e?.width||0,height:t?.height||e?.height||0}}z("debugprogressive");function z(i){if(typeof window>"u")return!1;const e=new URL(window.location.href).searchParams.get(i);return e==null||e==="0"||e==="false"?!1:e===""?!0:e}function Ee(i,t){if(t===void 0||i===void 0||t.startsWith("./")||t.startsWith("http")||t.startsWith("data:")||t.startsWith("blob:"))return t;const e=i.lastIndexOf("/");if(e>=0){const s=i.substring(0,e+1);for(;s.endsWith("/")&&t.startsWith("/");)t=t.substring(1);return s+t}return t}function Me(){return Y!==void 0||(Y=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),z("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",Y)),Y}let Y;function be(){if(typeof window>"u")return!1;const i=new URL(window.location.href),t=i.hostname==="localhost"||/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(i.hostname);return i.hostname==="127.0.0.1"||t}class je{constructor(t,e={}){this.maxConcurrent=t,this.debug=e.debug??!1,window.requestAnimationFrame(this.tick)}_running=new Map;_queue=[];debug=!1;tick=()=>{this.internalUpdate(),setTimeout(this.tick,10)};slot(t){return this.debug&&console.debug(`[PromiseQueue]: Requesting slot for key ${t}, running: ${this._running.size}, waiting: ${this._queue.length}`),new Promise(e=>{this._queue.push({key:t,resolve:e})})}add(t,e){this._running.has(t)||(this._running.set(t,e),e.finally(()=>{this._running.delete(t),this.debug&&console.debug(`[PromiseQueue]: Promise finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${t})`)}),this.debug&&console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${t})`))}internalUpdate(){const t=this.maxConcurrent-this._running.size;for(let e=0;e<t&&this._queue.length>0;e++){this.debug&&console.debug(`[PromiseQueue]: Running ${this._running.size} promises, waiting for ${this._queue.length} more.`);const{key:s,resolve:r}=this._queue.shift();r({use:n=>this.add(s,n)})}}}function Xe(i){const t=i.image,e=t?.width??0,s=t?.height??0,r=t?.depth??1,n=Math.floor(Math.log2(Math.max(e,s,r)))+1,o=Ke(i);return e*s*r*o*(1-Math.pow(.25,n))/(1-.25)}function Ke(i){let t=4;const e=i.format;e===c.RedFormat||e===c.RedIntegerFormat?t=1:e===c.RGFormat||e===c.RGIntegerFormat?t=2:e===c.RGBFormat||e===1029?t=3:(e===c.RGBAFormat||e===c.RGBAIntegerFormat)&&(t=4);let s=1;const r=i.type;return r===1009||r===1010?s=1:r===1011||r===1012?s=2:r===1013||r===1014||r===1015?s=4:r===1016&&(s=2),t*s}const Ye=typeof window>"u"&&typeof document>"u",we=Symbol("needle:raycast-mesh");function X(i){return i?.[we]instanceof c.BufferGeometry?i[we]:null}function He(i,t){if((i.type==="Mesh"||i.type==="SkinnedMesh")&&!X(i)){const s=Je(t);s.userData={isRaycastMesh:!0},i[we]=s}}function Qe(i=!0){if(i){if(H)return;const t=H=c.Mesh.prototype.raycast;c.Mesh.prototype.raycast=function(e,s){const r=this,n=X(r);let o;n&&r.isMesh&&(o=r.geometry,r.geometry=n),t.call(this,e,s),o&&(r.geometry=o)}}else{if(!H)return;c.Mesh.prototype.raycast=H,H=null}}let H=null;function Je(i){const t=new c.BufferGeometry;for(const e in i.attributes)t.setAttribute(e,i.getAttribute(e));return t.setIndex(i.getIndex()),t}const W=new Array,h=z("debugprogressive");let J,q=-1;if(h){let i=function(){q+=1,q>=t&&(q=-1),console.log(`Toggle LOD level [${q}]`)},t=6;window.addEventListener("keyup",e=>{e.key==="p"&&i(),e.key==="w"&&(J=!J,console.log(`Toggle wireframe [${J}]`));const s=parseInt(e.key);!isNaN(s)&&s>=0&&(q=s,console.log(`Set LOD level to [${q}]`))})}function ke(i){if(h&&J!==void 0)if(Array.isArray(i))for(const t of i)ke(t);else i&&"wireframe"in i&&(i.wireframe=J===!0)}const Q=new Array;let Ze=0;const et=Me()?2:10;function tt(i){if(Q.length<et){const s=Q.length;h&&console.warn(`[Worker] Creating new worker #${s}`);const r=ve.createWorker(i||{});return Q.push(r),r}const t=Ze++%Q.length;return Q[t]}class ve{constructor(t,e){this.worker=t,this._debug=e.debug??!1,t.onmessage=s=>{const r=s.data;switch(this._debug&&console.log("[Worker] EVENT",r),r.type){case"loaded-gltf":for(const n of this._running)if(n.url===r.result.url){st(r.result),n.resolve(r.result);const o=n.url;o.startsWith("blob:")&&URL.revokeObjectURL(o)}}},t.onerror=s=>{console.error("[Worker] Error in gltf-progressive worker:",s)},t.postMessage({type:"init"})}static async createWorker(t){const e=new Worker(new URL("/gltf-progressive.worker-DpfUjn1n.js",typeof document>"u"?require("url").pathToFileURL(__filename).href:le&&le.tagName.toUpperCase()==="SCRIPT"&&le.src||new URL("gltf-progressive-ByD1UX0A.umd.cjs",document.baseURI).href),{type:"module"});return new ve(e,t)}_running=[];_webglRenderer=null;async load(t,e){const s=ze();let r=e?.renderer;r||(this._webglRenderer??=(async()=>{const{WebGLRenderer:u}=await Promise.resolve().then(()=>require("./three.umd.cjs")).then(d=>d.THREE);return new u})(),r=await this._webglRenderer);const l=oe(r).ktx2Loader.workerConfig;t instanceof URL?t=t.toString():t.startsWith("file:")?t=URL.createObjectURL(new Blob([t])):!t.startsWith("blob:")&&!t.startsWith("http:")&&!t.startsWith("https:")&&(t=new URL(t,window.location.href).toString());const a={type:"load",url:t,dracoDecoderPath:s.dracoDecoderPath,ktx2TranscoderPath:s.ktx2TranscoderPath,ktx2LoaderConfig:l};return this._debug&&console.debug("[Worker] Sending load request",a),this.worker.postMessage(a),new Promise(u=>{this._running.push({url:t.toString(),resolve:u})})}_debug=!1}function st(i){for(const t of i.geometries){const e=t.geometry,s=new c.BufferGeometry;if(s.name=e.name||"",e.index){const r=e.index;s.setIndex(ue(r))}for(const r in e.attributes){const n=e.attributes[r],o=ue(n);s.setAttribute(r,o)}if(e.morphAttributes)for(const r in e.morphAttributes){const o=e.morphAttributes[r].map(l=>ue(l));s.morphAttributes[r]=o}if(s.morphTargetsRelative=e.morphTargetsRelative??!1,s.boundingBox=new c.Box3,s.boundingBox.min=new c.Vector3(e.boundingBox?.min.x,e.boundingBox?.min.y,e.boundingBox?.min.z),s.boundingBox.max=new c.Vector3(e.boundingBox?.max.x,e.boundingBox?.max.y,e.boundingBox?.max.z),s.boundingSphere=new c.Sphere(new c.Vector3(e.boundingSphere?.center.x,e.boundingSphere?.center.y,e.boundingSphere?.center.z),e.boundingSphere?.radius),e.groups)for(const r of e.groups)s.addGroup(r.start,r.count,r.materialIndex);e.userData&&(s.userData=e.userData),t.geometry=s}for(const t of i.textures){const e=t.texture;let s=null;if(e.isCompressedTexture){const r=e.mipmaps,{width:n,height:o}=xe(e);s=new c.CompressedTexture(r,n,o,e.format,e.type,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.anisotropy,e.colorSpace)}else s=new c.Texture(e.image,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),s.mipmaps=e.mipmaps,s.channel=e.channel,s.source.data=e.source.data,s.flipY=e.flipY,s.premultiplyAlpha=e.premultiplyAlpha,s.unpackAlignment=e.unpackAlignment,s.matrix=new c.Matrix3(...e.matrix.elements);if(!s){console.error("[Worker] Failed to create new texture from received data. Texture is not a CompressedTexture or Texture.");continue}t.texture=s}return i}function ue(i){let t=i;if("isInterleavedBufferAttribute"in i&&i.isInterleavedBufferAttribute){const e=i.data,s=e.array,r=new c.InterleavedBuffer(s,e.stride);t=new c.InterleavedBufferAttribute(r,i.itemSize,s.byteOffset,i.normalized),t.offset=i.offset}else"isBufferAttribute"in i&&i.isBufferAttribute&&(t=new c.BufferAttribute(i.array,i.itemSize,i.normalized),t.usage=i.usage,t.gpuType=i.gpuType,t.updateRanges=i.updateRanges);return t}const rt=z("gltf-progressive-worker");z("gltf-progressive-reduce-mipmaps");const E=z("gltf-progressive-gc"),ce=Symbol("needle-progressive-texture"),F="NEEDLE_progressive";class m{get name(){return F}static getMeshLODExtension(t){const e=this.getAssignedLODInformation(t);return e?.key?this.lodInfos.get(e.key):null}static getPrimitiveIndex(t){const e=this.getAssignedLODInformation(t)?.index;return e??-1}static getMaterialMinMaxLODsCount(t,e){const s=this,r="LODS:minmax",n=t[r];if(n!=null)return n;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const l of t)this.getMaterialMinMaxLODsCount(l,e);return t[r]=e,e}if(h==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const l=t;for(const a of Object.keys(l.uniforms)){const u=l.uniforms[a].value;u?.isTexture===!0&&o(u,e)}}else if(t.isMaterial)for(const l of Object.keys(t)){const a=t[l];a?.isTexture===!0&&o(a,e)}else h&&console.warn(`[getMaterialMinMaxLODsCount] Unsupported material type: ${t.type}`);return t[r]=e,e;function o(l,a){const u=s.getAssignedLODInformation(l);if(u){const d=s.lodInfos.get(u.key);if(d&&d.lods){a.min_count=Math.min(a.min_count,d.lods.length),a.max_count=Math.max(a.max_count,d.lods.length);for(let x=0;x<d.lods.length;x++){const L=d.lods[x];L.width&&(a.lods[x]=a.lods[x]||{min_height:1/0,max_height:0},a.lods[x].min_height=Math.min(a.lods[x].min_height,L.height),a.lods[x].max_height=Math.max(a.lods[x].max_height,L.height))}}}}}static hasLODLevelAvailable(t,e){if(Array.isArray(t)){for(const n of t)if(this.hasLODLevelAvailable(n,e))return!0;return!1}if(t.isMaterial===!0){for(const n of Object.keys(t)){const o=t[n];if(o&&o.isTexture&&this.hasLODLevelAvailable(o,e))return!0}return!1}else if(t.isGroup===!0){for(const n of t.children)if(n.isMesh===!0&&this.hasLODLevelAvailable(n,e))return!0}let s,r;if(t.isMesh?s=t.geometry:(t.isBufferGeometry||t.isTexture)&&(s=t),s&&s?.userData?.LODS){const n=s.userData.LODS;if(r=this.lodInfos.get(n.key),e===void 0)return r!=null;if(r)return Array.isArray(r.lods)?e<r.lods.length:e===0}return!1}static assignMeshLOD(t,e){if(!t)return Promise.resolve(null);if(t instanceof c.Mesh||t.isMesh===!0){const s=t.geometry,r=this.getAssignedLODInformation(s);if(!r)return Promise.resolve(null);for(const n of W)n.onBeforeGetLODMesh?.(t,e);return t["LOD:requested level"]=e,m.getOrLoadLOD(s,e).then(n=>{if(Array.isArray(n)){const o=r.index||0;n=n[o]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],n&&s!=n&&(n?.isBufferGeometry?t.geometry=n:h&&console.error("Invalid LOD geometry",n))),n}).catch(n=>(console.error("Error loading mesh LOD",t,n),null))}else h&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const s=t;if(Array.isArray(s.material)){const r=new Array;for(const n of s.material){const o=this.assignTextureLOD(n,e);r.push(o)}return Promise.all(r).then(n=>{const o=new Array;for(const l of n)Array.isArray(l)&&o.push(...l);return o})}else return this.assignTextureLOD(s.material,e)}if(t.isMaterial===!0){const s=t,r=[],n=new Array;if(s.uniforms&&(s.isRawShaderMaterial||s.isShaderMaterial===!0)){const o=s;for(const l of Object.keys(o.uniforms)){const a=o.uniforms[l].value;if(a?.isTexture===!0){const u=this.assignTextureLODForSlot(a,e,s,l).then(d=>(d&&o.uniforms[l].value!=d&&(o.uniforms[l].value=d,o.uniformsNeedUpdate=!0),d));r.push(u),n.push(l)}}}else for(const o of Object.keys(s)){const l=s[o];if(l?.isTexture===!0){const a=this.assignTextureLODForSlot(l,e,s,o);r.push(a),n.push(o)}}return Promise.all(r).then(o=>{const l=new Array;for(let a=0;a<o.length;a++){const u=o[a],d=n[a];u&&u.isTexture===!0?l.push({material:s,slot:d,texture:u,level:e}):l.push({material:s,slot:d,texture:null,level:e})}return l})}if(t instanceof c.Texture||t.isTexture===!0){const s=t;return this.assignTextureLODForSlot(s,e,null,null)}return Promise.resolve(null)}static set maxConcurrentLoadingTasks(t){m.queue.maxConcurrent=t}static get maxConcurrentLoadingTasks(){return m.queue.maxConcurrent}static assignTextureLODForSlot(t,e,s,r){return t?.isTexture!==!0?Promise.resolve(null):r==="glyphMap"?Promise.resolve(t):m.getOrLoadLOD(t,e).then(n=>{if(Array.isArray(n))return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."),null;if(n?.isTexture===!0){if(n!=t&&s&&r){const o=s[r];if(o&&!h){const l=this.getAssignedLODInformation(o);if(l&&l?.level<e)return h==="verbose"&&console.warn("Assigned texture level is already higher: ",l.level,e,s,o,n),n&&n!==o&&((h||E)&&console.log(`[gltf-progressive] Disposing rejected lower-quality texture LOD ${e} (assigned is ${l.level})`,n.uuid),n.dispose()),null}if(this.trackTextureUsage(n),o&&o!==n&&this.untrackTextureUsage(o)&&(h||E)){const a=this.getAssignedLODInformation(o);console.log(`[gltf-progressive] Disposed old texture LOD ${a?.level??"?"} → ${e} for ${s.name||s.type}.${r}`,o.uuid)}s[r]=n}return n}else h=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(n=>(console.error("Error loading LOD",t,n),null))}parser;url;constructor(t){const e=t.options.path;h&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}_isLoadingMesh;loadMesh=t=>{if(this._isLoadingMesh)return null;const e=this.parser.json.meshes[t]?.extensions?.[F];return e?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",t).then(s=>(this._isLoadingMesh=!1,s&&m.registerMesh(this.url,e.guid,s,e.lods?.length,0,e),s))):null};afterRoot(t){return h&&console.log("AFTER",this.url,t),this.parser.json.textures?.forEach((e,s)=>{if(e?.extensions){const r=e?.extensions[F];if(r){if(!r.lods){h&&console.warn("Texture has no LODs",r);return}let n=!1;for(const o of this.parser.associations.keys())o.isTexture===!0&&this.parser.associations.get(o)?.textures===s&&(n=!0,m.registerTexture(this.url,o,r.lods?.length,s,r));n||this.parser.getDependency("texture",s).then(o=>{o&&m.registerTexture(this.url,o,r.lods?.length,s,r)})}}}),this.parser.json.meshes?.forEach((e,s)=>{if(e?.extensions){const r=e?.extensions[F];if(r&&r.lods){for(const n of this.parser.associations.keys())if(n.isMesh){const o=this.parser.associations.get(n);o?.meshes===s&&m.registerMesh(this.url,r.guid,n,r.lods.length,o.primitives,r)}}}}),null}static registerTexture=(t,e,s,r,n)=>{if(!e){h&&console.error("!! gltf-progressive: Called register texture without texture");return}if(h){const{width:l,height:a}=xe(e);console.log(`> gltf-progressive: register texture[${r}] "${e.name||e.uuid}", Current: ${l}x${a}, Max: ${n.lods[0]?.width}x${n.lods[0]?.height}, uuid: ${e.uuid}`,n,e)}e.source&&(e.source[ce]=n);const o=n.guid;m.assignLODInformation(t,e,o,s,r),m.lodInfos.set(o,n),m.lowresCache.set(o,new WeakRef(e))};static registerMesh=(t,e,s,r,n,o)=>{const l=s.geometry;if(!l){h&&console.warn("gltf-progressive: Register mesh without geometry");return}l.userData||(l.userData={}),h&&console.log("> Progressive: register mesh "+s.name,{index:n,uuid:s.uuid},o,s),m.assignLODInformation(t,l,e,r,n),m.lodInfos.set(e,o);let u=m.lowresCache.get(e)?.deref();u?u.push(s.geometry):u=[s.geometry],m.lowresCache.set(e,new WeakRef(u)),r>0&&!X(s)&&He(s,l);for(const d of W)d.onRegisteredNewMesh?.(s,o)};static dispose(t){if(t){this.lodInfos.delete(t);const e=this.lowresCache.get(t);if(e){const s=e.deref();if(s){if(s.isTexture){const r=s;this.textureRefCounts.delete(r.uuid),r.dispose()}else if(Array.isArray(s))for(const r of s)r.dispose()}this.lowresCache.delete(t)}for(const[s,r]of this.cache)s.includes(t)&&(this._disposeCacheEntry(r),this.cache.delete(s))}else{this.lodInfos.clear();for(const[,e]of this.lowresCache){const s=e.deref();if(s){if(s.isTexture){const r=s;this.textureRefCounts.delete(r.uuid),r.dispose()}else if(Array.isArray(s))for(const r of s)r.dispose()}}this.lowresCache.clear();for(const[,e]of this.cache)this._disposeCacheEntry(e);this.cache.clear(),this.textureRefCounts.clear()}}static _disposeCacheEntry(t){if(t instanceof WeakRef){const e=t.deref();e&&(e.isTexture&&this.textureRefCounts.delete(e.uuid),e.dispose())}else t.then(e=>{if(e)if(Array.isArray(e))for(const s of e)s.dispose();else e.isTexture&&this.textureRefCounts.delete(e.uuid),e.dispose()}).catch(()=>{})}static lodInfos=new Map;static cache=new Map;static lowresCache=new Map;static textureRefCounts=new Map;static _resourceRegistry=new FinalizationRegistry(t=>{const e=m.cache.get(t);(h||E)&&console.debug(`[gltf-progressive] Memory: Resource GC'd
2
+ ${t}`),e instanceof WeakRef&&(e.deref()||(m.cache.delete(t),(h||E)&&console.log("[gltf-progressive] ↪ Cache entry deleted (GC)")))});static trackTextureUsage(t){const e=t.uuid,s=this.textureRefCounts.get(e)||0;this.textureRefCounts.set(e,s+1),h==="verbose"&&console.log(`[gltf-progressive] Track texture ${e}, refCount: ${s} → ${s+1}`)}static untrackTextureUsage(t){const e=t.uuid,s=this.textureRefCounts.get(e);if(!s)return(h==="verbose"||E)&&n("[gltf-progressive] Memory: Untrack untracked texture (dispose immediately)",0),t.dispose(),!0;const r=s-1;if(r<=0)return this.textureRefCounts.delete(e),(h||E)&&n("[gltf-progressive] Memory: Dispose texture",r),t.dispose(),!0;return this.textureRefCounts.set(e,r),h==="verbose"&&n("[gltf-progressive] Memory: Untrack texture",r),!1;function n(o,l){let{width:a,height:u}=xe(t);const d=a&&u?`${a}x${u}`:"N/A";let x="N/A";a&&u&&(x=`~${(Xe(t)/(1024*1024)).toFixed(2)} MB`),console.log(`${o} — ${t.name} ${d} (${x}), refCount: ${s} → ${l}
3
+ ${e}`)}}static workers=[];static _workersIndex=0;static async getOrLoadLOD(t,e){const s=h=="verbose",r=this.getAssignedLODInformation(t);if(!r)return h&&console.warn(`[gltf-progressive] No LOD information found: ${t.name}, uuid: ${t.uuid}, type: ${t.type}`,t),null;const n=r?.key;let o;if(t.isTexture===!0){const a=t;a.source&&a.source[ce]&&(o=a.source[ce])}if(o||(o=m.lodInfos.get(n)),!o)h&&console.warn(`Can not load LOD ${e}: no LOD info found for "${n}" ${t.name}`,t.type,m.lodInfos);else{if(e>0){let d=!1;const x=Array.isArray(o.lods);if(x&&e>=o.lods.length?d=!0:x||(d=!0),d){const L=this.lowresCache.get(n);if(L){const _=L.deref();if(_)return _;this.lowresCache.delete(n),h&&console.log(`[gltf-progressive] Lowres cache entry was GC'd: ${n}`)}return null}}const a=Array.isArray(o.lods)?o.lods[e]?.path:o.lods;if(!a)return h&&!o["missing:uri"]&&(o["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,o)),null;const u=Ee(r.url,a);if(u.endsWith(".glb")||u.endsWith(".gltf")){if(!o.guid)return console.warn("missing pointer for glb/gltf texture",o),null;const d=u+"_"+o.guid,x=await this.queue.slot(u),L=this.cache.get(d);if(L!==void 0)if(s&&console.log(`LOD ${e} was already loading/loaded: ${d}`),L instanceof WeakRef){const f=L.deref();if(f){let p=f,v=!1;if(p instanceof c.Texture&&t instanceof c.Texture?De(p.image)||ye(p)?p=this.copySettings(t,p):v=!0:p instanceof c.BufferGeometry&&t instanceof c.BufferGeometry&&(p.attributes.position?.array||(v=!0)),!v)return p}this.cache.delete(d),h&&console.log(`[gltf-progressive] Re-loading GC'd/disposed resource: ${d}`)}else{let f=await L.catch(v=>(console.error(`Error loading LOD ${e} from ${u}
4
+ `,v),null)),p=!1;if(f==null||(f instanceof c.Texture&&t instanceof c.Texture?De(f.image)||ye(f)?f=this.copySettings(t,f):(p=!0,this.cache.delete(d)):f instanceof c.BufferGeometry&&t instanceof c.BufferGeometry&&(f.attributes.position?.array||(p=!0,this.cache.delete(d)))),!p)return f}if(!x.use)return h&&console.log(`LOD ${e} was aborted: ${u}`),null;const _=o,R=new Promise(async(f,p)=>{if(rt){const w=await(await tt({})).load(u);if(w.textures.length>0)for(const g of w.textures){let y=g.texture;return m.assignLODInformation(r.url,y,n,e,void 0),t instanceof c.Texture&&(y=this.copySettings(t,y)),y&&(y.guid=_.guid),f(y)}if(w.geometries.length>0){const g=new Array;for(const y of w.geometries){const O=y.geometry;m.assignLODInformation(r.url,O,n,e,y.primitiveIndex),g.push(O)}return f(g)}return f(null)}const v=new j.GLTFLoader;Le(v),h&&(await new Promise(M=>setTimeout(M,1e3)),s&&console.warn("Start loading (delayed) "+u,_.guid));let B=u;if(_&&Array.isArray(_.lods)){const M=_.lods[e];M.hash&&(B+="?v="+M.hash)}const b=await v.loadAsync(B).catch(M=>(console.error(`Error loading LOD ${e} from ${u}
5
+ `,M),f(null)));if(!b)return f(null);const V=b.parser;s&&console.log("Loading finished "+u,_.guid);let P=0;if(b.parser.json.textures){let M=!1;for(const w of b.parser.json.textures){if(w?.extensions){const g=w?.extensions[F];if(g?.guid&&g.guid===_.guid){M=!0;break}}P++}if(M){let w=await V.getDependency("texture",P);return w&&m.assignLODInformation(r.url,w,n,e,void 0),s&&console.log('change "'+t.name+'" → "'+w.name+'"',u,P,w,d),t instanceof c.Texture&&(w=this.copySettings(t,w)),w&&(w.guid=_.guid),f(w)}else h&&console.warn("Could not find texture with guid",_.guid,b.parser.json)}if(P=0,b.parser.json.meshes){let M=!1;for(const w of b.parser.json.meshes){if(w?.extensions){const g=w?.extensions[F];if(g?.guid&&g.guid===_.guid){M=!0;break}}P++}if(M){const w=await V.getDependency("mesh",P);if(s&&console.log(`Loaded Mesh "${w.name}"`,u,P,w,d),w.isMesh===!0){const g=w.geometry;return m.assignLODInformation(r.url,g,n,e,0),f(g)}else{const g=new Array;for(let y=0;y<w.children.length;y++){const O=w.children[y];if(O.isMesh===!0){const S=O.geometry;m.assignLODInformation(r.url,S,n,e,y),g.push(S)}}return f(g)}}else h&&console.warn("Could not find mesh with guid",_.guid,b.parser.json)}return f(null)});this.cache.set(d,R),x.use(R);const D=await R;return D!=null?D instanceof c.Texture?(this.cache.set(d,new WeakRef(D)),m._resourceRegistry.register(D,d)):Array.isArray(D)?this.cache.set(d,Promise.resolve(D)):this.cache.set(d,Promise.resolve(D)):this.cache.set(d,Promise.resolve(null)),D}else if(t instanceof c.Texture){s&&console.log("Load texture from uri: "+u);const x=await new c.TextureLoader().loadAsync(u);return x?(x.guid=o.guid,x.flipY=!1,x.needsUpdate=!0,x.colorSpace=t.colorSpace,s&&console.log(o,x)):h&&console.warn("failed loading",u),x}}return null}static queue=new je(Me()?20:50,{debug:h!=!1});static assignLODInformation(t,e,s,r,n){if(!e)return;e.userData||(e.userData={});const o=new nt(t,s,r,n);e.userData.LODS=o,"source"in e&&typeof e.source=="object"&&(e.source.LODS=o)}static getAssignedLODInformation(t){return t?t.userData?.LODS?t.userData.LODS:"source"in t&&t.source?.LODS?t.source.LODS:null:null}static copySettings(t,e){return e?(h==="verbose"&&console.debug(`Copy texture settings
6
+ `,t.uuid,`
7
+ `,e.uuid),e=e.clone(),e.offset=t.offset,e.repeat=t.repeat,e.colorSpace=t.colorSpace,e.magFilter=t.magFilter,e.minFilter=t.minFilter,e.wrapS=t.wrapS,e.wrapT=t.wrapT,e.flipY=t.flipY,e.anisotropy=t.anisotropy,e.mipmaps||(e.generateMipmaps=t.generateMipmaps),e):t}}class nt{url;key;level;index;constructor(t,e,s,r){this.url=t,this.key=e,this.level=s,r!=null&&(this.index=r)}}class de{static addPromise=(t,e,s,r)=>{r.forEach(n=>{n.add(t,e,s)})};ready;get awaitedCount(){return this._addedCount}get resolvedCount(){return this._resolvedCount}get currentlyAwaiting(){return this._awaiting.length}_resolve;_signal;_frame_start;_frames_to_capture;_resolved=!1;_addedCount=0;_resolvedCount=0;_awaiting=[];_maxPromisesPerObject=1;constructor(t,e){const r=Math.max(e.frames??2,2);this._frame_start=e.waitForFirstCapture?void 0:t,this._frames_to_capture=r,this.ready=new Promise(n=>{this._resolve=n}),this.ready.finally(()=>{this._resolved=!0,this._awaiting.length=0}),this._signal=e.signal,this._signal?.addEventListener("abort",()=>{this.resolveNow()}),this._maxPromisesPerObject=Math.max(1,e.maxPromisesPerObject??1)}_currentFrame=0;update(t){this._currentFrame=t,this._frame_start===void 0&&this._addedCount>0&&(this._frame_start=t),(this._signal?.aborted||this._awaiting.length===0&&this._frame_start!==void 0&&t>this._frame_start+this._frames_to_capture)&&this.resolveNow()}_seen=new WeakMap;add(t,e,s){if(this._resolved){h&&console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");return}if(!(this._frame_start!==void 0&&this._currentFrame>this._frame_start+this._frames_to_capture)){if(this._maxPromisesPerObject>=1)if(this._seen.has(e)){let r=this._seen.get(e);if(r>=this._maxPromisesPerObject){h&&console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");return}this._seen.set(e,r+1)}else this._seen.set(e,1);this._awaiting.push(s),this._addedCount++,s.finally(()=>{this._resolvedCount++,this._awaiting.splice(this._awaiting.indexOf(s),1)})}}resolveNow(){this._resolved||this._resolve?.({awaited_count:this._addedCount,resolved_count:this._resolvedCount,cancelled:this._signal?.aborted??!1})}}const k=z("debugprogressive"),ot=z("noprogressive"),fe=Symbol("Needle:LODSManager"),he=Symbol("Needle:LODState"),U=Symbol("Needle:CurrentLOD"),C={mesh_lod:-1,texture_lod:-1};let Z=class T{static debugDrawLine;static getObjectLODState(t){return t[he]}static addPlugin(t){W.push(t)}static removePlugin(t){const e=W.indexOf(t);e>=0&&W.splice(e,1)}static get(t,e){if(t[fe])return console.debug("[gltf-progressive] LODsManager already exists for this renderer"),t[fe];const s=new T(t,{engine:"unknown",...e});return t[fe]=s,s}renderer;context;projectionScreenMatrix=new c.Matrix4;get plugins(){return W}overrideLodLevel=void 0;targetTriangleDensity=2e5;skinnedMeshAutoUpdateBoundsInterval=30;updateInterval="auto";#e=1;pause=!1;manual=!1;_newPromiseGroups=[];_promiseGroupIds=0;awaitLoading(t){const e=this._promiseGroupIds++,s=new de(this.#r,{...t});this._newPromiseGroups.push(s);const r=performance.now();return s.ready.finally(()=>{const n=this._newPromiseGroups.indexOf(s);n>=0&&(this._newPromiseGroups.splice(n,1),be()&&performance.measure("LODsManager:awaitLoading",{start:r,detail:{id:e,name:t?.name,awaited:s.awaitedCount,resolved:s.resolvedCount}}))}),s.ready}_postprocessPromiseGroups(){if(this._newPromiseGroups.length!==0)for(let t=this._newPromiseGroups.length-1;t>=0;t--)this._newPromiseGroups[t].update(this.#r)}_lodchangedlisteners=[];addEventListener(t,e){t==="changed"&&this._lodchangedlisteners.push(e)}removeEventListener(t,e){if(t==="changed"){const s=this._lodchangedlisteners.indexOf(e);s>=0&&this._lodchangedlisteners.splice(s,1)}}constructor(t,e){this.renderer=t,this.context={...e}}#t;#o=new c.Timer;#r=0;#n=0;#i=0;#s=0;_fpsBuffer=[60,60,60,60,60];enable(){if(this.#t)return;console.debug("[gltf-progressive] Enabling LODsManager for renderer");let t=0;this.#t=this.renderer.render;const e=this;oe(this.renderer),this.renderer.render=function(s,r){const n=e.renderer.getRenderTarget();(n==null||"isXRRenderTarget"in n&&n.isXRRenderTarget)&&(t=0,e.#r+=1,e.#o.update(),e.#n=e.#o.getDelta(),e.#i+=e.#n,e._fpsBuffer.shift(),e._fpsBuffer.push(1/e.#n),e.#s=e._fpsBuffer.reduce((l,a)=>l+a)/e._fpsBuffer.length,k&&e.#r%200===0&&console.log("FPS",Math.round(e.#s),"Interval:",e.#e));const o=t++;e.#t.call(this,s,r),e.onAfterRender(s,r,o)}}disable(){this.#t&&(console.debug("[gltf-progressive] Disabling LODsManager for renderer"),this.renderer.render=this.#t,this.#t=void 0)}update(t,e){this.internalUpdate(t,e)}onAfterRender(t,e,s){if(this.pause)return;const n=this.renderer.renderLists.get(t,0).opaque;let o=!0;if(n.length===1){const l=n[0].material;(l.name==="EffectMaterial"||l.name==="CopyShader")&&(o=!1)}if((e.parent&&e.parent.type==="CubeCamera"||s>=1&&e.type==="OrthographicCamera")&&(o=!1),o){if(ot||(this.updateInterval==="auto"?this.#s<40&&this.#e<10?(this.#e+=1,k&&console.warn("↓ Reducing LOD updates",this.#e,this.#s.toFixed(0))):this.#s>=60&&this.#e>1&&(this.#e-=1,k&&console.warn("↑ Increasing LOD updates",this.#e,this.#s.toFixed(0))):this.#e=this.updateInterval,this.#e>0&&this.#r%this.#e!=0))return;this.internalUpdate(t,e),this._postprocessPromiseGroups()}}internalUpdate(t,e){const s=this.renderer.renderLists.get(t,0),r=s.opaque;this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse);const n=this.targetTriangleDensity;for(const a of r){if(a.material&&(a.geometry?.type==="BoxGeometry"||a.geometry?.type==="BufferGeometry")&&(a.material.name==="SphericalGaussianBlur"||a.material.name=="BackgroundCubeMaterial"||a.material.name==="CubemapFromEquirect"||a.material.name==="EquirectangularToCubeUV")){k&&(a.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]||(a.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]=!0,console.warn("Ignoring skybox or BLIT object",a,a.material.name,a.material.type)));continue}switch(a.material.type){case"LineBasicMaterial":case"LineDashedMaterial":case"PointsMaterial":case"ShadowMaterial":case"MeshDistanceMaterial":case"MeshDepthMaterial":continue}if(k==="color"&&a.material&&!a.object.progressive_debug_color){a.object.progressive_debug_color=!0;const d=Math.random()*16777215,x=new c.MeshStandardMaterial({color:d});a.object.material=x}const u=a.object;(u instanceof c.Mesh||u.isMesh)&&this.updateLODs(t,e,u,n)}const o=s.transparent;for(const a of o){const u=a.object;(u instanceof c.Mesh||u.isMesh)&&this.updateLODs(t,e,u,n)}const l=s.transmissive;for(const a of l){const u=a.object;(u instanceof c.Mesh||u.isMesh)&&this.updateLODs(t,e,u,n)}}updateLODs(t,e,s,r){s.userData||(s.userData={});let n=s[he];if(n||(n=new it,s[he]=n),n.frames++<2)return;for(const l of W)l.onBeforeUpdateLOD?.(this.renderer,t,e,s);const o=this.overrideLodLevel!==void 0?this.overrideLodLevel:q;o>=0?(C.mesh_lod=o,C.texture_lod=o):(this.calculateLodLevel(e,s,n,r,C),C.mesh_lod=Math.round(C.mesh_lod),C.texture_lod=Math.round(C.texture_lod)),C.mesh_lod>=0&&this.loadProgressiveMeshes(s,C.mesh_lod),s.material&&C.texture_lod>=0&&this.loadProgressiveTextures(s.material,C.texture_lod,o),h&&s.material&&!s.isGizmo&&ke(s.material);for(const l of W)l.onAfterUpdatedLOD?.(this.renderer,t,e,s,C);n.lastLodLevel_Mesh=C.mesh_lod,n.lastLodLevel_Texture=C.texture_lod}loadProgressiveTextures(t,e,s){if(!t)return;if(Array.isArray(t)){for(const n of t)this.loadProgressiveTextures(n,e);return}let r=!1;if((t[U]===void 0||e<t[U])&&(r=!0),s!==void 0&&s>=0&&(r=t[U]!=s,e=s),r){t[U]=e;const n=m.assignTextureLOD(t,e).then(o=>{this._lodchangedlisteners.forEach(l=>l({type:"texture",level:e,object:t}))});de.addPromise("texture",t,n,this._newPromiseGroups)}}loadProgressiveMeshes(t,e){if(!t)return Promise.resolve(null);let s=t[U]!==e;const r=t["DEBUG:LOD"];if(r!=null&&(s=t[U]!=r,e=r),s){t[U]=e;const n=t.geometry,o=m.assignMeshLOD(t,e).then(l=>(l&&t[U]==e&&n!=t.geometry&&this._lodchangedlisteners.forEach(a=>a({type:"mesh",level:e,object:t})),l));return de.addPromise("mesh",t,o,this._newPromiseGroups),o}return Promise.resolve(null)}_sphere=new c.Sphere;_tempBox=new c.Box3;_tempBox2=new c.Box3;tempMatrix=new c.Matrix4;_tempWorldPosition=new c.Vector3;_tempBoxSize=new c.Vector3;_tempBox2Size=new c.Vector3;static corner0=new c.Vector3;static corner1=new c.Vector3;static corner2=new c.Vector3;static corner3=new c.Vector3;static _tempPtInside=new c.Vector3;static isInside(t,e){const s=t.min,r=t.max,n=(s.x+r.x)*.5,o=(s.y+r.y)*.5;return this._tempPtInside.set(n,o,s.z).applyMatrix4(e).z<0}static skinnedMeshBoundsFrameOffsetCounter=0;static $skinnedMeshBoundsOffset=Symbol("gltf-progressive-skinnedMeshBoundsOffset");calculateLodLevel(t,e,s,r,n){if(!e){n.mesh_lod=-1,n.texture_lod=-1;return}if(!t){n.mesh_lod=-1,n.texture_lod=-1;return}let l=10+1,a=!1;if(k&&e["DEBUG:LOD"]!=null)return e["DEBUG:LOD"];const u=m.getMeshLODExtension(e.geometry)?.lods,d=m.getPrimitiveIndex(e.geometry),x=u&&u.length>0,L=m.getMaterialMinMaxLODsCount(e.material),_=L.min_count!==1/0&&L.min_count>=0&&L.max_count>=0;if(!x&&!_){n.mesh_lod=0,n.texture_lod=0;return}x||(a=!0,l=0);const R=this.renderer.domElement.clientHeight||this.renderer.domElement.height;let D=e.geometry.boundingBox;if(e.type==="SkinnedMesh"){const f=e;if(!f.boundingBox)f.computeBoundingBox();else if(this.skinnedMeshAutoUpdateBoundsInterval>0){if(!f[T.$skinnedMeshBoundsOffset]){const v=T.skinnedMeshBoundsFrameOffsetCounter++;f[T.$skinnedMeshBoundsOffset]=v}const p=f[T.$skinnedMeshBoundsOffset];if((s.frames+p)%this.skinnedMeshAutoUpdateBoundsInterval===0){const v=X(f),B=f.geometry;v&&(f.geometry=v),f.computeBoundingBox(),f.geometry=B}}D=f.boundingBox}if(D){const f=t;if(e.geometry.attributes.color&&e.geometry.attributes.color.count<100&&e.geometry.boundingSphere){this._sphere.copy(e.geometry.boundingSphere),this._sphere.applyMatrix4(e.matrixWorld);const g=t.getWorldPosition(this._tempWorldPosition);if(this._sphere.containsPoint(g)){n.mesh_lod=0,n.texture_lod=0;return}}if(this._tempBox.copy(D),this._tempBox.applyMatrix4(e.matrixWorld),f.isPerspectiveCamera&&T.isInside(this._tempBox,this.projectionScreenMatrix)){n.mesh_lod=0,n.texture_lod=0;return}if(this._tempBox.applyMatrix4(this.projectionScreenMatrix),this.renderer.xr.enabled&&f.isPerspectiveCamera&&f.fov>70){const g=this._tempBox.min,y=this._tempBox.max;let O=g.x,S=g.y,G=y.x,K=y.y;const ee=2,ie=1.5,te=(g.x+y.x)*.5,se=(g.y+y.y)*.5;O=(O-te)*ee+te,S=(S-se)*ee+se,G=(G-te)*ee+te,K=(K-se)*ee+se;const Be=O<0&&G>0?0:Math.min(Math.abs(g.x),Math.abs(y.x)),Ge=S<0&&K>0?0:Math.min(Math.abs(g.y),Math.abs(y.y)),ae=Math.max(Be,Ge);s.lastCentrality=(ie-ae)*(ie-ae)*(ie-ae)}else s.lastCentrality=1;const p=this._tempBox.getSize(this._tempBoxSize);p.multiplyScalar(.5),screen.availHeight>0&&R>0&&p.multiplyScalar(R/screen.availHeight),t.isPerspectiveCamera?p.x*=t.aspect:t.isOrthographicCamera;const v=t.matrixWorldInverse,B=this._tempBox2;B.copy(D),B.applyMatrix4(e.matrixWorld),B.applyMatrix4(v);const b=B.getSize(this._tempBox2Size),V=Math.max(b.x,b.y);if(Math.max(p.x,p.y)!=0&&V!=0&&(p.z=b.z/Math.max(b.x,b.y)*Math.max(p.x,p.y)),s.lastScreenCoverage=Math.max(p.x,p.y,p.z),s.lastScreenspaceVolume.copy(p),s.lastScreenCoverage*=s.lastCentrality,k&&T.debugDrawLine){const g=this.tempMatrix.copy(this.projectionScreenMatrix);g.invert();const y=T.corner0,O=T.corner1,S=T.corner2,G=T.corner3;y.copy(this._tempBox.min),O.copy(this._tempBox.max),O.x=y.x,S.copy(this._tempBox.max),S.y=y.y,G.copy(this._tempBox.max);const K=(y.z+G.z)*.5;y.z=O.z=S.z=G.z=K,y.applyMatrix4(g),O.applyMatrix4(g),S.applyMatrix4(g),G.applyMatrix4(g),T.debugDrawLine(y,O,255),T.debugDrawLine(y,S,255),T.debugDrawLine(O,G,255),T.debugDrawLine(S,G,255)}let M=999;if(u&&s.lastScreenCoverage>0)for(let g=0;g<u.length;g++){const y=u[g],S=(y.densities?.[d]||y.density||1e-5)/s.lastScreenCoverage;if(d>0&&be()&&!y.densities&&!globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]&&(window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]=!0,console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")),S<r){M=g;break}}M<l&&(l=M,a=!0)}if(a?n.mesh_lod=l:n.mesh_lod=s.lastLodLevel_Mesh,k&&n.mesh_lod!=s.lastLodLevel_Mesh){const p=u?.[n.mesh_lod];p&&console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${n.mesh_lod} (density: ${p.densities?.[d].toFixed(0)}) | ${e.name}`)}if(_){const f="saveData"in globalThis.navigator&&globalThis.navigator.saveData===!0;if(s.lastLodLevel_Texture<0){if(n.texture_lod=L.max_count-1,k){const p=L.lods[L.max_count-1];k&&console.log(`First Texture LOD ${n.texture_lod} (${p.max_height}px) - ${e.name}`)}}else{const p=s.lastScreenspaceVolume.x+s.lastScreenspaceVolume.y+s.lastScreenspaceVolume.z;let v=s.lastScreenCoverage*4;this.context?.engine==="model-viewer"&&(v*=1.5);const b=R/window.devicePixelRatio*v;let V=!1;for(let P=L.lods.length-1;P>=0;P--){const M=L.lods[P];if(!(f&&M.max_height>=2048)&&!(Me()&&M.max_height>4096)&&(M.max_height>b||!V&&P===0)){if(V=!0,n.texture_lod=P,k&&n.texture_lod<s.lastLodLevel_Texture){const w=M.max_height;console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${n.texture_lod} = ${w}px
8
+ Screensize: ${b.toFixed(0)}px, Coverage: ${(100*s.lastScreenCoverage).toFixed(2)}%, Volume ${p.toFixed(1)}
9
+ ${e.name}`)}break}}}}else n.texture_lod=0}};class it{frames=0;lastLodLevel_Mesh=-1;lastLodLevel_Texture=-1;lastScreenCoverage=0;lastScreenspaceVolume=new c.Vector3;lastCentrality=0}const Oe=Symbol("NEEDLE_mesh_lod"),re=Symbol("NEEDLE_texture_lod");let ge=null;function Ie(){const i=at();i&&(i.mapURLs(function(t){return Te(),t}),Te(),ge?.disconnect(),ge=new MutationObserver(t=>{t.forEach(e=>{e.addedNodes.forEach(s=>{s instanceof HTMLElement&&s.tagName.toLowerCase()==="model-viewer"&&$e(s)})})}),ge.observe(document,{childList:!0,subtree:!0}))}function at(){if(typeof customElements>"u")return null;const i=customElements.get("model-viewer");return i||(customElements.whenDefined("model-viewer").then(()=>{console.debug("[gltf-progressive] model-viewer defined"),Ie()}),null)}function Te(){if(typeof document>"u")return;document.querySelectorAll("model-viewer").forEach(t=>{$e(t)})}const Se=new WeakSet;let lt=0;function $e(i){if(!i||Se.has(i))return null;Se.add(i),console.debug("[gltf-progressive] found new model-viewer..."+ ++lt+`
10
+ `,i.getAttribute("src"));let t=null,e=null,s=null;for(let r=i;r!=null;r=Object.getPrototypeOf(r)){const n=Object.getOwnPropertySymbols(r),o=n.find(u=>u.toString()=="Symbol(renderer)"),l=n.find(u=>u.toString()=="Symbol(scene)"),a=n.find(u=>u.toString()=="Symbol(needsRender)");!t&&o!=null&&(t=i[o].threeRenderer),!e&&l!=null&&(e=i[l]),!s&&a!=null&&(s=i[a])}if(t&&e){let r=function(){if(s){let o=0,l=setInterval(()=>{if(o++>5){clearInterval(l);return}s?.call(i)},300)}};console.debug("[gltf-progressive] setup model-viewer");const n=Z.get(t,{engine:"model-viewer"});return Z.addPlugin(new ut),n.enable(),n.addEventListener("changed",()=>{s?.call(i)}),i.addEventListener("model-visibility",o=>{o.detail.visible&&s?.call(i)}),i.addEventListener("load",()=>{r()}),()=>{n.disable()}}return null}class ut{_didWarnAboutMissingUrl=!1;onBeforeUpdateLOD(t,e,s,r){this.tryParseMeshLOD(e,r),this.tryParseTextureLOD(e,r)}getUrl(t){if(!t)return null;let e=t.getAttribute("src");return e||(e=t.src),e||(this._didWarnAboutMissingUrl||console.warn("No url found in modelviewer",t),this._didWarnAboutMissingUrl=!0),e}tryGetCurrentGLTF(t){return t._currentGLTF}tryGetCurrentModelViewer(t){return t.element}tryParseTextureLOD(t,e){if(e[re]==!0)return;e[re]=!0;const s=this.tryGetCurrentGLTF(t),r=this.tryGetCurrentModelViewer(t),n=this.getUrl(r);if(n&&s&&e.material){let o=function(a){if(a[re]==!0)return;a[re]=!0,a.userData&&(a.userData.LOD=-1);const u=Object.keys(a);for(let d=0;d<u.length;d++){const x=u[d],L=a[x];if(L?.isTexture===!0){const _=L.userData?.associations?.textures;if(_==null)continue;const R=s.parser.json.textures[_];if(!R){console.warn("Texture data not found for texture index "+_);continue}if(R?.extensions?.[F]){const D=R.extensions[F];D&&n&&m.registerTexture(n,L,D.lods.length,_,D)}}}};const l=e.material;if(Array.isArray(l))for(const a of l)o(a);else o(l)}}tryParseMeshLOD(t,e){if(e[Oe]==!0)return;e[Oe]=!0;const s=this.tryGetCurrentModelViewer(t),r=this.getUrl(s);if(!r)return;const n=e.userData?.gltfExtensions?.[F];if(n&&r){const o=e.uuid;m.registerMesh(r,o,e,0,n.lods.length,n)}}}function ct(...i){let t,e,s,r;switch(i.length){case 2:[s,e]=i,r={};break;case 3:[s,e,r]=i;break;case 4:[t,e,s,r]=i;break;default:throw new Error("Invalid arguments")}oe(e),Le(s),_e(s,{progressive:!0,...r?.hints}),s.register(o=>new m(o));const n=Z.get(e);return r?.enableLODsManager!==!1&&n.enable(),n}Ie();if(!Ye){const i={gltfProgressive:{useNeedleProgressive:ct,LODsManager:Z,configureLoader:_e,getRaycastMesh:X,useRaycastMeshes:Qe}};if(!globalThis.Needle)globalThis.Needle=i;else for(const t in i)globalThis.Needle[t]=i[t]}exports.LODsManager=Z;exports.NEEDLE_progressive=m;exports.addDracoAndKTX2Loaders=Le;exports.configureLoader=_e;exports.createLoaders=oe;exports.getRaycastMesh=X;exports.setDracoDecoderLocation=Ce;exports.setKTX2TranscoderLocation=Ae;